Intel protection register read
I sent the patch below to this list a few days ago but had no response. Has anyone had a chance to look at it? If its ok, could someone apply it? (its against 2.3.13-ac4-rmk1)
Thanks,
Clive
drivers/mtd/chips/cfi_cmdset_0001.c +42 -0
@@ -31,6 +31,7 @@#include <linux/mtd/compatmac.h> static int cfi_intelext_read (struct mtd_info *,loff_t ,size_t ,size_t *,u_char *); +static int cfi_intelext_read_prot_reg (struct mtd_info *,loff_t ,size_t ,size_t *,u_char *);static int cfi_intelext_write_words (struct mtd_info *,loff_t ,size_t ,size_t *,const u_char *);static int cfi_intelext_write_buffers (struct mtd_info *,loff_t ,size_t ,size_t *,const u_char *);static int cfi_intelext_erase_varsize (struct mtd_info *,struct erase_info *);
@@ -151,7 +152,23 @@ struct mtd_info *cfi_cmdset_0001(struct/* Do some byteswapping if necessary */ extp->FeatureSupport =cfi32_to_cpu (extp->FeatureSupport); extp->BlkStatusRegMask =cfi32_to_cpu (extp->BlkStatusRegMask); + extp->ProtRegAddr =cfi32_to_cpu (extp->ProtRegAddr); + +/* Read the protection register area from flash */ +if (extp->NumProtectionFields){ +cfi_send_gen_cmd (0x90 ,0x55 , base, map, cfi, cfi->device_type,NULL ); + cfi->ProtRegData=kmalloc ((1 <<extp->FactProtRegSize)+(1 <<extp->UserProtRegSize),GFP_KERNEL ); +if (!cfi->ProtRegData){ +printk (KERN_ERR "Failed to allocate memory\n" ); +return 0 ; + } +for (i=0 ; i<((1 <<extp->FactProtRegSize)+(1 <<extp->UserProtRegSize));i++){ + cfi->ProtRegData[i]= + map->read8 (map,(base+(extp->ProtRegAddr*ofs_factor)+i)); + } + } +#ifdef DEBUG_CFI_FEATURES /* Tell the user about it in lots of lovely detail */ cfi_tell_features (extp);
@@ -247,6 +264,7 @@ static struct mtd_info *cfi_intelext_set//printk(KERN_INFO "Using word write method\n" ); mtd->write = cfi_intelext_write_words; } + mtd->read_prot_reg = cfi_intelext_read_prot_reg; mtd->sync = cfi_intelext_sync; mtd->lock = cfi_intelext_lock; mtd->unlock = cfi_intelext_unlock;
@@ -432,6 +450,30 @@ static int cfi_intelext_read (struct mtd }return ret; } + +static int cfi_intelext_read_prot_reg (struct mtd_info *mtd,loff_t from,size_t len,size_t *retlen,u_char *buf) +{ +struct map_info *map = mtd->priv; +struct cfi_private *cfi = map->fldrv_priv; +struct cfi_pri_intelext *extp=cfi->cmdset_priv; +unsigned char * data=cfi->ProtRegData+from; +int count=len; + +while (count){ +if (data>=cfi->ProtRegData + + (1 <<extp->FactProtRegSize)+(1 <<extp->UserProtRegSize)){ +return len-count; + } + *buf=*data; + buf++; + data++; + count--; + } +return len-count; +} + + +static int do_write_oneword (struct map_info *map,struct flchip *chip,unsigned long adr,__u32 datum) {
drivers/mtd/maps/Makefile +1 -0
@@ -31,6 +31,7 @@ obj-$(CONFIG_MTD_SUN_UFLASH) += sun_u obj-$(CONFIG_MTD_VMAX) += vmax301.o obj-$(CONFIG_MTD_DBOX2) += dbox2-flash.o obj-$(CONFIG_MTD_OCELOT) += ocelot.o +obj-$(CONFIG_MTD_EPXA10DB) += epxa10db-flash.o obj-$(CONFIG_MTD_SOLUTIONENGINE)+= solutionengine.o obj-$(CONFIG_MTD_PCI) += pci.o
include/linux/mtd/mtd.h +6 -0
@@ -180,6 +180,12 @@ struct mtd_info {int (*read_oob) (struct mtd_info *mtd,loff_t from,size_t len,size_t *retlen,u_char *buf);int (*write_oob) (struct mtd_info *mtd,loff_t to,size_t len,size_t *retlen,const u_char *buf); +/* +* Method to access the protection register or OTP area, +* present in some flash devices +*/ +int (*read_prot_reg) (struct mtd_info *mtd,loff_t from,size_t len,size_t *retlen,u_char *buf); +/* iovec-based read/write methods. We need these especially for NAND flash, with its limited number of write cycles per erase. NB: The 'count' parameter is the number of _vectors_, each of
drivers/mtd/mtdpart.c +1 -0
@@ -195,6 +195,7 @@ int add_mtd_partitions(struct mtd_info * slave->mtd.oobsize = master->oobsize; slave->mtd.ecctype = master->ecctype; slave->mtd.eccsize = master->eccsize; + slave->mtd.read_prot_reg = master->read_prot_reg; slave->mtd.name = parts[i].name; slave->mtd.bank_size = master->bank_size;
include/linux/mtd/cfi.h +5 -0
@@ -206,6 +206,10 @@ struct cfi_pri_intelext {__u16 BlkStatusRegMask;__u8 VccOptimal;__u8 VppOptimal; +__u8 NumProtectionFields; +__u16 ProtRegAddr; +__u8 FactProtRegSize; +__u8 UserProtRegSize; } __attribute__((packed));struct cfi_pri_query {
@@ -248,6 +252,7 @@ struct cfi_private {int numchips;unsigned long chipshift;/* Because they're of the same type */ const char *im_name;/* inter_module name for cmdset_setup */ +unsigned char *ProtRegData;/* Protection register data bytes */ struct flchip chips[0 ];/* per-chip data structure for each chip */ };
Quoted 3 lines · [email protected] said:
I sent the patch below to this list a few days ago but had no response. Has anyone had a chance to look at it? If its ok, could someone apply it?
Sorry. Thanks for retrying :)
Quoted 2 lines
include/linux/mtd/cfi.h +1
-0+unsigned char *ProtRegData;/* Protection register data bytes */ struct flchip chips[0]; /* per-chip data structure for each chip */
The ProtRegData are per-chip, but you've only left space for one pointer. What happens when people have arrays of multiple chips side-by-side and/or consecutively mapped?
Also, isn't it possible to _write_ to the user areas of the chips?
Is this present in all versions of the Intel command sets, or do you need to check the version number?
--
dwmw2