Skip to contentSkip to conversation

mtd: spinand: micron: add support for MT29F1G01AAADD

PATCH Applied Vít Kazík 3 participants 4 messages Nov 27 – Dec 4

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 mtd: spinand: micron: add support for MT29F1G01AAADD

Add support for the Micron MT29F1G01AAADD (M68A), a 1Gb 3.3V SPI NAND with 2048+64 byte pages, 64 pages per block, two planes and 4-bit on-die ECC.

The 64 spare bytes are split into four 16-byte sections, each with 2 reserved bytes, 2 bytes of unprotected metadata, 4 bytes of ECC protected metadata and 8 ECC bytes. Add a layout that exposes only the ECC protected bytes 4-7 of each section as free OOB space.

Tested on a Motorola NCAP-500 (Atheros AR7242) running OpenWrt with kernel 6.18.64, using UBI with UBIFS.
The chip is detected correctly:

spi-nand spi0.1: Micron SPI NAND was found.
spi-nand spi0.1: 128 MiB, block size: 128 KiB,
page size: 2048, OOB size: 64

---
v2:
- expose only bytes 4-7 of each section as free OOB space

 drivers/mtd/nand/spi/micron.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
drivers/mtd/nand/spi/micron.c +28 -0
index 36f6cbbd7462..34a8ea77c3fe 100644
@@ -134,6 +134,24 @@ static const struct mtd_ooblayout_ops micron_4_ooblayout = {
 	.free = micron_4_ooblayout_free,
 };
 
+static int micron_m68a_ooblayout_free(struct mtd_info *mtd, int section,
+				      struct mtd_oob_region *region)
+{
+	if (section >= 4)
+		return -ERANGE;
+
+	/* 2 bytes for the BBM + 2 bytes of non-ECC protected memory */
+	region->offset = (section * 16) + 4;
+	region->length = 4;
+
+	return 0;
+}
+
+static const struct mtd_ooblayout_ops micron_m68a_ooblayout = {
+	.ecc = micron_4_ooblayout_ecc,
+	.free = micron_m68a_ooblayout_free,
+};
+
 static int micron_select_target(struct spinand_device *spinand,
 				unsigned int target)
 {
@@ -404,6 +422,16 @@ static const struct spinand_info micron_spinand_table[] = {
 		     SPINAND_ECCINFO(&micron_8_ooblayout,
 				     micron_8_ecc_get_status),
 		     SPINAND_SELECT_TARGET(micron_select_target)),
+	/* M68A 1Gb 3.3V */
+	SPINAND_INFO("MT29F1G01AAADD",
+		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x12),
+		     NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 2, 1, 1),
+		     NAND_ECCREQ(4, 512),
+		     SPINAND_INFO_OP_VARIANTS(&x4_read_cache_variants,
+					      &x1_write_cache_variants,
+					      &x1_update_cache_variants),
+		     0,
+		     SPINAND_ECCINFO(&micron_m68a_ooblayout, NULL)),
 	/* M69A 2Gb 3.3V */
 	SPINAND_INFO("MT29F2G01AAAED",
 		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x9F),

base-commit: ec1e844b9486302a488abc03ea918db60709766e

Signature · 1 line
2.56.1
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] mtd: spinand: micron: divide-by-zero in micron_4_ooblayout_ecc() and _free() --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] mtd: spinand: micron: divide-by-zero in micron_4_ooblayout_ecc() and _free()
--

commit 44ca4db24b5a7a324981c1c01700cebe8a1210b0
Author: Vít Kazík <[email protected]>

mtd: spinand: micron: add support for MT29F1G01AAADD

This commit adds support and an OOB layout for the Micron MT29F1G01AAADD (M68A) 1Gb 3.3V SPI NAND flash chip.

Quoted 15 lines
drivers/mtd/nand/spi/micron.c +7 -0
index 36f6cbbd7462c..34a8ea77c3fe9 100644
@@ -134,6 +134,24 @@ static const struct mtd_ooblayout_ops micron_4_ooblayout = {
 	.free = micron_4_ooblayout_free,
 };
 
+static int micron_m68a_ooblayout_free(struct mtd_info *mtd, int section,
+				      struct mtd_oob_region *region)
+{
+	if (section >= 4)
+		return -ERANGE;
+
+	/* 2 bytes for the BBM + 2 bytes of non-ECC protected memory */

drivers/mtd/nand/spi/micron.c static const struct mtd_ooblayout_ops micron_4_ooblayout = { · line 153

Quoted 10 lines
drivers/mtd/nand/spi/micron.c +10 -0
+	region->offset = (section * 16) + 4;
+	region->length = 4;
+
+	return 0;
+}
+
+static const struct mtd_ooblayout_ops micron_m68a_ooblayout = {
+	.ecc = micron_4_ooblayout_ecc,
+	.free = micron_m68a_ooblayout_free,
+};

[Severity: Medium]
Can micron_4_ooblayout_ecc() divide by zero when MT29F1G01AAADD is probed without an ECC engine (e.g. nand-no-ecc-engine in Device Tree)?

micron_4_ooblayout_ecc() bounds section by dividing by mtd->ecc_step_size:

drivers/mtd/nand/spi/micron.c:micron_4_ooblayout_ecc() {
    ...
	if (section >= spinand->base.memorg.pagesize /
			mtd->ecc_step_size)
		return -ERANGE;
    ...
}

In spinand_init(), when nand->ecc.engine is NULL, spinand->eccinfo.ooblayout is still installed on mtd while nanddev_get_ecc_conf(nand)->step_size is 0, leaving mtd->ecc_step_size as 0. During device registration in spinand_probe(), mtd_device_register() -> add_mtd_device() -> mtd_debugfs_populate() calls mtd_ooblayout_ecc(mtd, 0, &region), hitting a divide-by-zero in micron_4_ooblayout_ecc().

(Note that micron_4_ooblayout_free() has the same division by mtd->ecc_step_size, which already divides by zero during spinand_init() because mtd_ooblayout_count_freebytes() runs before mtd->ecc_step_size is populated.)

Signature · 5 lines
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
maintainer
#2 lore raw

Hello,

Quoted 6 lines

In spinand_init(), when nand->ecc.engine is NULL, spinand->eccinfo.ooblayout is still installed on mtd while nanddev_get_ecc_conf(nand)->step_size is 0, leaving mtd->ecc_step_size as 0. During device registration in spinand_probe(), mtd_device_register() -> add_mtd_device() -> mtd_debugfs_populate() calls mtd_ooblayout_ecc(mtd, 0, &region), hitting

This is the chain that is problematic, we shall not attach the hardware ECC layout for the NONE or SW cases. This problem is orthogonal, so I will anyway take the patch.

Miquèl

maintainer Applied
#3 lore raw
In reply to Vít Kazík
Quoted 10 lines · Vít Kazík

Add support for the Micron MT29F1G01AAADD (M68A), a 1Gb 3.3V SPI NAND with 2048+64 byte pages, 64 pages per block, two planes and 4-bit on-die ECC.

The 64 spare bytes are split into four 16-byte sections, each with 2 reserved bytes, 2 bytes of unprotected metadata, 4 bytes of ECC protected metadata and 8 ECC bytes. Add a layout that exposes only the ECC protected bytes 4-7 of each section as free OOB space.

[...]

Applied to nand/next, thanks!

[1/1] mtd: spinand: micron: add support for MT29F1G01AAADD

      commit: 698c62afba5833a3ae20860fce0b22242de658d6

Patche(s) should be available on mtd/linux.git and will be part of the next PR (provided that no robot complains by then).

Kind regards,
Miquèl