flash_info and MEMGETREGIONCOUNT
Hi,
I would like to know some info about the flash chip present on the board. I found flash_info utility and can't seem to get information about the region count with MEMGETREGIONCOUNT.
# /flash_info /dev/mtd0 Device /dev/mtd0 has 0 erase regions # /flash_info /dev/mtd1 Device /dev/mtd1 has 0 erase regions # /flash_info /dev/mtd2 Device /dev/mtd2 has 0 erase regions
Although during boot these messages are shown (with CFI debug on):
...
[42949374.037212] Probing cse0 at physical address 0x00000000 (16-bit bankwidth) [42949374.044444] Number of erase regions: 4 [42949374.054706] Primary Vendor Command Set: 0002 (AMD/Fujitsu Standard) [42949374.064951] Primary Algorithm Table at 0040 [42949374.069392] Alternative Vendor Command Set: 0000 (None) [42949374.079548] No Alternate Algorithm Table [42949374.083729] Vcc Minimum: 2.7 V [42949374.087113] Vcc Maximum: 3.6 V [42949374.097284] Vpp Minimum: 11.5 V [42949374.100662] Vpp Maximum: 12.5 V [42949374.104043] Typical byte/word write timeout: 16 µs [42949374.114211] Maximum byte/word write timeout: 512 µs [42949374.119413] Full buffer write not supported [42949374.129580] Typical block erase timeout: 1024 ms [42949374.134452] Maximum block erase timeout: 16384 ms [42949374.144596] Chip erase not supported [42949374.148426] Device size: 0x400000 bytes (4 MiB) [42949374.158590] Flash Device Interface description: 0x0002 [42949374.163975] - supports x8 and x16 via BYTE# with asynchronous interface [42949374.174140] Max. bytes in buffer write: 0x1 [42949374.178570] Number of Erase Block Regions: 4 [42949374.188759] Erase Region #0: BlockSize 0x4000 bytes, 1 blocks [42949374.198948] Erase Region #1: BlockSize 0x2000 bytes, 2 blocks [42949374.205157] Erase Region #2: BlockSize 0x8000 bytes, 1 blocks [42949374.215347] Erase Region #3: BlockSize 0x10000 bytes, 63 blocks [42949374.221744] cse0: Found 1 x16 devices at 0x0 in 16-bit bank [42949374.235520] Amd/Fujitsu Extended Query Table at 0x0040 [42949374.245764] number of CFI chips: 1 [42949374.249441] cfi_cmdset_0002: Disabling erase-suspend-program due to code brokenness. [42949374.259647] Probing cse1 at physical address 0x04000000 (16-bit bankwidth) [42949374.270098] Using static partitions on cse0 [42949374.274538] NOR flash size: 4194304 b (4 Mb) [42949374.284722] Creating 3 MTD partitions on "cse0": [42949374.289640] 0x00000000-0x00010000 : "Rescue" [42949374.310538] 0x00010000-0x00130000 : "Kernel" [42949374.329690] 0x00130000-0x00400000 : "Filesystem" [42949374.350519] cse1 is absent. Skipping
...
It is clearly seen that there are four regions reported by the kernel, but the userspace does not agree with the kernel !?
Thank you,
Hinko
Signature · 7 lines
ČETRTA POT, d.o.o., Kranj Planina 3 4000 Kranj Slovenia, Europe Tel. +386 (0) 4 280 66 03 E-mail: [email protected] Http: www.cetrtapot.si
Quoted 11 lines · Hinko Kocevar
Hi,
I would like to know some info about the flash chip present on the board. I found
flash_infoutility and can't seem to get information about the region count with MEMGETREGIONCOUNT.# /flash_info /dev/mtd0 Device /dev/mtd0 has 0 erase regions # /flash_info /dev/mtd1 Device /dev/mtd1 has 0 erase regions # /flash_info /dev/mtd2 Device /dev/mtd2 has 0 erase regions
I get the same results on my system. I'm not sure what "flash_info" is actually meant for.
Try the mtd_debug utility instead and see if that information is more helpful. Here's a sample output from one of my mtd partitions:
/ # mtd_debug info /dev/mtd0
mtd.type = MTD_NORFLASH
mtd.flags = MTD_WRITEABLE | MTD_BIT_WRITEABLE
mtd.size = 262144 (256K)
mtd.erasesize = 131072 (128K)
mtd.writesize = 1
mtd.oobsize = 0
regions = 0
BTW, the regions = 0 is why the flash_info utility reports 0 erase regions.
Hartley
Quoted 28 lines · hartleys
Quoted 11 lines · Hinko Kocevar
Hi,
I would like to know some info about the flash chip present on the board. I found
flash_infoutility and can't seem to get information about the region count with MEMGETREGIONCOUNT.# /flash_info /dev/mtd0 Device /dev/mtd0 has 0 erase regions # /flash_info /dev/mtd1 Device /dev/mtd1 has 0 erase regions # /flash_info /dev/mtd2 Device /dev/mtd2 has 0 erase regionsI get the same results on my system. I'm not sure what "
flash_info" is actually meant for.Try the
mtd_debugutility instead and see if that information is more helpful. Here's a sample output from one of my mtd partitions:/ #
mtd_debuginfo/dev/mtd0
mtd.type =MTD_NORFLASH
mtd.flags =MTD_WRITEABLE|MTD_BIT_WRITEABLE
mtd.size = 262144 (256K)
mtd.erasesize = 131072 (128K)
mtd.writesize = 1
mtd.oobsize = 0
regions = 0
Quoted 3 lines
BTW, the regions = 0 is why the
flash_infoutility reports 0 erase regions.
[Just a side note, patch is inlined just for evaluation, yesterdays reply with attached patch didn't go through the MTD maintainer/mail server]
Same here...
# /mtd_debug info /dev/mtd0 mtd.type = MTD_NORFLASH mtd.flags = MTD_CAP_NORFLASH mtd.size = 65536 (64K) mtd.erasesize = 32768 (32K) mtd.writesize = 1 mtd.oobsize = 0 regions = 0
# /mtd_debug info /dev/mtd1 mtd.type = MTD_NORFLASH mtd.flags = MTD_CAP_NORFLASH mtd.size = 1179648 (1M) mtd.erasesize = 65536 (64K) mtd.writesize = 1 mtd.oobsize = 0 regions = 0
Looking at the code I see that cfi_amdstd_setup() sets the erase region parameters to detected values. The same info can be also dumped in my flash map driver.
My investigation lead to add_mtd_partitions() that creates slave partitions out of master mtd partition - and where erase regions are not set for each slave partition.
Attached is a *dirty* patch that makes each slave partition hold the erase region info in addition to just erasesize. Patch is just a proof of concept and should be rewritten, thus any pointers on how to improve it are welcomed!
And here are some of the results (lines with [xxxx..] are from kernel log):
# ./flash_info /dev/mtd0 [42949395.891554] Nr erase regions 3 [42949395.894925] 0: offset=0x0,size=0x4000,blocks=1 [42949395.905162] 1: offset=0x4000,size=0x2000,blocks=2 [42949395.910202] 2: offset=0x8000,size=0x8000,blocks=1 Device /dev/mtd0 has 3 erase regions Region 0 is at 0x0 with size 0x4000 and has 0x1 blocks Region 1 is at 0x4000 with size 0x2000 and has 0x2 blocks Region 2 is at 0x8000 with size 0x8000 and has 0x1 blocks
# ./mtd_debug info /dev/mtd0 [42949414.642758] Nr erase regions 3 [42949414.646124] 0: offset=0x0,size=0x4000,blocks=1 [42949414.656363] 1: offset=0x4000,size=0x2000,blocks=2 [42949414.661395] 2: offset=0x8000,size=0x8000,blocks=1 mtd.type = MTD_NORFLASH mtd.flags = MTD_CAP_NORFLASH mtd.size = 65536 (64K) mtd.erasesize = 32768 (32K) mtd.writesize = 1 mtd.oobsize = 0 regions = 3
region[0].offset = 0x00000000
region[0].erasesize = 16384 (16K)
region[0].numblocks = 1
region[0].regionindex = 0
region[1].offset = 0x00004000
region[1].erasesize = 8192 (8K)
region[1].numblocks = 2
region[1].regionindex = 0
region[2].offset = 0x00008000
region[2].erasesize = 32768 (32K)
region[2].numblocks = 1
region[2].regionindex = 0
# flash_erase /dev/mtd0 0 1 Erase Total 1 Units [42949452.398375] Nr erase regions 3 [42949452.408603] 0: offset=0x0,size=0x4000,blocks=1 [42949452.413376] 1: offset=0x4000,size=0x2000,blocks=2 [42949452.423585] 2: offset=0x8000,size=0x8000,blocks=1 Region 0 is at 0 of 1 sector and with sector size 4000 Region 1 is at 16384 of 2 sector and with sector size 2000 Region 2 is at 32768 of 1 sector and with sector size 8000 Performing Flash Erase of length 16384 at offset 0x0 Moving to region 1 done # flash_erase /dev/mtd0 0 2 Erase Total 2 Units [42949458.054011] Nr erase regions 3 [42949458.057376] 0: offset=0x0,size=0x4000,blocks=1 [42949458.062136] 1: offset=0x4000,size=0x2000,blocks=2 [42949458.072363] 2: offset=0x8000,size=0x8000,blocks=1 Region 0 is at 0 of 1 sector and with sector size 4000 Region 1 is at 16384 of 2 sector and with sector size 2000 Region 2 is at 32768 of 1 sector and with sector size 8000 Performing Flash Erase of length 16384 at offset 0x0 Moving to region 1 Performing Flash Erase of length 8192 at offset 0x4000 done # flash_erase /dev/mtd0 0 3 Erase Total 3 Units [42949465.054067] Nr erase regions 3 [42949465.057435] 0: offset=0x0,size=0x4000,blocks=1 [42949465.062193] 1: offset=0x4000,size=0x2000,blocks=2 [42949465.072413] 2: offset=0x8000,size=0x8000,blocks=1 Region 0 is at 0 of 1 sector and with sector size 4000 Region 1 is at 16384 of 2 sector and with sector size 2000 Region 2 is at 32768 of 1 sector and with sector size 8000 Performing Flash Erase of length 16384 at offset 0x0 Moving to region 1 Performing Flash Erase of length 8192 at offset 0x6000 Moving to region 2 done # flash_erase /dev/mtd0 0 4 Erase Total 4 Units [42949474.454087] Nr erase regions 3 [42949474.457454] 0: offset=0x0,size=0x4000,blocks=1 [42949474.462212] 1: offset=0x4000,size=0x2000,blocks=2 [42949474.472429] 2: offset=0x8000,size=0x8000,blocks=1 Region 0 is at 0 of 1 sector and with sector size 4000 Region 1 is at 16384 of 2 sector and with sector size 2000 Region 2 is at 32768 of 1 sector and with sector size 8000 Performing Flash Erase of length 16384 at offset 0x0 Moving to region 1 Performing Flash Erase of length 8192 at offset 0x6000 Moving to region 2 Performing Flash Erase of length 32768 at offset 0x8000 Moving to region 3 done
PATCH:
------
drivers/mtd/mtdpart.c +28 -0
@@ -339,6 +339,14 @@printk (KERN_NOTICE "Creating %d MTD partitions on \"%s\":\n" , nbparts, master->name); +printk ("Nr master erase regions %d\n" , master->numeraseregions); +for (i=0 ; i<master->numeraseregions;i++){ +printk ("%d: offset=0x%x,size=0x%x,blocks=%d\n" , + i,master->eraseregions[i].offset, + master->eraseregions[i].erasesize, + master->eraseregions[i].numblocks); + } +for (i =0 ; i < nbparts; i++) {/* allocate the partition structure */
@@ -443,6 +451,7 @@printk ("mtd: partition \"%s\" extends beyond the end of device \"%s\" -- size truncated to %#x\n" , parts[i].name, master->name, slave->mtd.size); } +if (master->numeraseregions>1 ) {/* Deal with variable erase size stuff */ int i;
@@ -451,12 +460,31 @@/* Find the first erase regions which is part of this partition. */ for (i=0 ; i < master->numeraseregions && slave->offset >= regions[i].offset; i++) ; +printk ("first erase region %d for slave @ %d\n" , i-1 , slave->offset); + slave->mtd.eraseregions =kzalloc (sizeof (struct mtd_erase_region_info ) * +4 ,GFP_KERNEL ); + +int j =0 ;for (i--; i < master->numeraseregions && slave->offset + slave->mtd.size > regions[i].offset; i++) {if (slave->mtd.erasesize < regions[i].erasesize) { slave->mtd.erasesize = regions[i].erasesize; } + slave->mtd.eraseregions[j].offset = regions[i].offset; + slave->mtd.eraseregions[j].erasesize = regions[i].erasesize; + slave->mtd.eraseregions[j].numblocks = regions[i].numblocks; + j++; } + slave->mtd.numeraseregions = j; + +printk ("Nr slave erase regions %d\n" , slave->mtd.numeraseregions); +for (i=0 ; i<slave->mtd.numeraseregions;i++){ +printk ("%d: offset=0x%x,size=0x%x,blocks=%d\n" , + i,slave->mtd.eraseregions[i].offset, + slave->mtd.eraseregions[i].erasesize, + slave->mtd.eraseregions[i].numblocks); + } + }else {/* Single erase size */ slave->mtd.erasesize = master->erasesize;
------
Thanks,
Hinko
Signature · 7 lines
ČETRTA POT, d.o.o., Kranj Planina 3 4000 Kranj Slovenia, Europe Tel. +386 (0) 4 280 66 03 E-mail: [email protected] Http: www.cetrtapot.si