Skip to contentSkip to conversation

mtd: spinand: core: fix Winbond W25N bad block marker (1 byte BBM)

PATCH In review Zunyi Hu 2 participants 3 messages Jun 5 – Jun 8

Subsystems (2)
lore
Share & tools
lore

Zunyi Hu

author
#0 lore raw

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
index e5330958c7e..5395a1bdf68 100644
@@ -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
author
#1 lore raw

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
index c119486efb7..78584e5a1e2 100644
@@ -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
#2 lore raw
In reply to Zunyi Hu
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].

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
index e5330958c7e..5395a1bdf68 100644
@@ -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