mtd: spinand: core: fix Winbond W25N bad block marker (1 byte BBM)
Subsystems (2)
PATCH 1/2 mtd: spinand: core: fix Winbond W25N bad block marker (1 byte BBM)
According to the Winbond datasheet, the factory Bad Block Marker is strictly a single non-0xFF byte located at spare byte 0. The default spinand core assumes a 2-byte marker (byte 0 and 1).
However, after programming, upper-layer file systems (such as UBI) may utilize byte 1 for metadata. The default 2-byte check leads to false-positive bad block detections on valid blocks. Introduce a manufacturer-specific check (Winbond ID: 0xEF) to strictly evaluate only marker[0].
--- drivers/mtd/nand/spi/core.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/mtd/nand/spi/core.c +11 -0
@@ -676,6 +676,17 @@ static bool spinand_isbad(struct nand_device *nand, const struct nand_pos *pos)if (ret)return ret; +/* +* Winbond W25N (incl. W25N01G/GV): factory BBM is a single non-0xFF +* byte at spare byte 0 (see datasheet). Byte 1 may hold ECC or file +* system markers after programming — do not treat it as BBM. +*/ +if (spinand->id.data[1 ] ==0xEF ) { +if (marker[0 ] !=0xff ) +return true; +return false; + } +if (marker[0 ] !=0xff || marker[1 ] !=0xff )return true;
Signature · 1 line
2.17.1
PATCH 2/2 mtd: spinand: winbond: add support for W25N01G
Add device ID and geometry parameters for the Winbond W25N01G 1G-bit SPI NAND flash memory.
--- drivers/mtd/nand/spi/winbond.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/mtd/nand/spi/winbond.c +8 -0
@@ -96,6 +96,14 @@ static const struct spinand_info winbond_spinand_table[] = { &update_cache_variants), 0, SPINAND_ECCINFO(&w25m02gv_ooblayout, NULL)), +SPINAND_INFO ("W25N01G" ,0xAA , +NAND_MEMORG (1 ,2048 ,64 ,64 ,1024 ,1 ,1 ,1 ), +NAND_ECCREQ (1 ,512 ), +SPINAND_INFO_OP_VARIANTS (&read_cache_variants, + &write_cache_variants, + &update_cache_variants), +0 , + SPINAND_ECCINFO(&w25m02gv_ooblayout, NULL)), };/**
Signature · 1 line
2.17.1
Quoted 5 lines · Zunyi Hu
[Sie erhalten nicht häufig E-Mails von [email protected]. Weitere Informationen, warum dies wichtig ist, finden Sie unter https://aka.ms/LearnAboutSenderIdentification ]
According to the Winbond datasheet, the factory Bad Block Marker is strictly a single non-0xFF byte located at spare byte 0. The default spinand core assumes a 2-byte marker (byte 0 and 1).
When I look at the datasheet for the W25N01GV for example, it says:
A “Bad Block Marker” is a non-FFh data byte stored at Byte 0 of Page 0 for each bad block. An additional marker is also stored in the first two bytes of the 64-Byte spare area.
So checking for the first two bytes in the spare area seems correct.
Quoted 3 lines
However, after programming, upper-layer file systems (such as UBI) may utilize byte 1 for metadata.
The OOB layout excludes the first two bytes from being used by the software. So if UBI uses these bytes something is very wrong.
Quoted 6 lines
The default 2-byte check leads to
false-positive bad block detections on valid blocks. Introduce a manufacturer-specific check (Winbond ID:0xEF) to strictly evaluate only marker[0].Signed-off-by Zunyi Hu <[email protected]>
If you want to submit changes to the logic of the SPI NAND drivers, please also submit them to the Linux kernel driver. We want to stay in sync with the kernel.
Quoted 12 lines
--- drivers/mtd/nand/spi/core.c | 11 +++++++++++ 1 file changed, 11 insertions(+)drivers/mtd/nand/spi/core.c +0
-0@@ -676,6 +676,17 @@ static bool spinand_isbad(struct nand_device *nand, const struct nand_pos *pos)if (ret)return ret;
drivers/mtd/nand/spi/core.c static bool spinand_isbad(struct nand_device *nand, const struct nand_pos *pos) · line 688
Quoted 10 lines
drivers/mtd/nand/spi/core.c +10
-0+/* +* Winbond W25N (incl. W25N01G/GV): factory BBM is a single non-0xFF +* byte at spare byte 0 (see datasheet). Byte 1 may hold ECC or file +* system markers after programming — do not treat it as BBM. +*/ +if (spinand->id.data[1 ] ==0xEF ) { +if (marker[0 ] !=0xff ) +return true; +return false; + }
If this is actually needed (and I dont't think it is), this code should better be put in the manufacturer driver (windbond.c), not in the core.
Quoted 7 lines
drivers/mtd/nand/spi/core.c +1
-1+if (marker[0 ] !=0xff || marker[1 ] !=0xff )return true; --2.17.1