最近在做的项目用到了windond的W25Q64 SPI Flash 芯片, datasheet中提到, erase sector 为4KB, erase block为64KB, Linux Kernel自带设备驱动m25p80可用于W25Q64,但是出现一个问题,W25Q64的默认擦除大小是4KB,但是mkfs.jffs2 -e 选项最低为8KB,使用4KB创建jffs2镜像时报错:
$ mkfs.jffs2 -n -l -e 0x1000 -d /home/root -o /user.jffs2 Erase size 0x1000 too small. Increasing to 8KiB minimum
视而不见,继续挂载,满屏的错误
jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x00022034: 0x5771 instead Further such events for this erase block will not be printed Node at 0x00022f60 with length 0x000000f6 would run over the end of the erase block Perhaps the file system was created with the wrong erase size? jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x00023000: 0x69c2 instead
没办法,只能改驱动,将m25p80设备驱动默认擦除扇区由4KB改为64KB,阅读源码后发现其实很简单,将m25p_ids里面相关的设备的flag改为0即可, 下面是patch内容
diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c index 4eeeb2d..28a9170 100644 --- a/drivers/mtd/devices/m25p80.c +++ b/drivers/mtd/devices/m25p80.c @@ -684,7 +684,7 @@ static const struct spi_device_id m25p_ids[] = { { "s25sl032a", INFO(0x010215, 0, 64 * 1024, 64, 0) }, { "s25sl064a", INFO(0x010216, 0, 64 * 1024, 128, 0) }, { "s25fl016k", INFO(0xef4015, 0, 64 * 1024, 32, SECT_4K) }, - { "s25fl064k", INFO(0xef4017, 0, 64 * 1024, 128, SECT_4K) }, + { "s25fl064k", INFO(0xef4017, 0, 64 * 1024, 128, 0) }, /* SST -- large erase sizes are "overlays", "sectors" are 4K */ { "sst25vf040b", INFO(0xbf258d, 0, 64 * 1024, 8, SECT_4K) }, @@ -741,7 +741,7 @@ static const struct spi_device_id m25p_ids[] = { { "w25q32", INFO(0xef4016, 0, 64 * 1024, 64, SECT_4K) }, { "w25q32dw", INFO(0xef6016, 0, 64 * 1024, 64, SECT_4K) }, { "w25x64", INFO(0xef3017, 0, 64 * 1024, 128, SECT_4K) }, - { "w25q64", INFO(0xef4017, 0, 64 * 1024, 128, SECT_4K) }, + { "w25q64", INFO(0xef4017, 0, 64 * 1024, 128, 0) }, { "w25q80", INFO(0xef5014, 0, 64 * 1024, 16, SECT_4K) }, { "w25q80bl", INFO(0xef4014, 0, 64 * 1024, 16, SECT_4K) }, { "w25q256", INFO(0xef4019, 0, 64 * 1024, 512, SECT_4K) }, -- 1.7.9.5
可以用下面命令查看erasesize已经修改为64KB
$ cat /proc/mtd dev: size erasesize name mtd0: 00800000 00010000 "jffs2"