Skip to contentSkip to conversation

mtd: Support slc-mode for NTC CHIP

PATCH In review Chris Morgan 3 participants 9 messages Dec 16, 2021 – Mar 28, 2022

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

v4 cover mtd: Support slc-mode for NTC CHIP

From: Chris Morgan <[email protected]>

Add support for slc-mode implemented in Linux for the Toshiba TC58TEG5DCLTA00 NAND and Hynix H27UCG8T2ETR NAND flash found on the NTC CHIP. This requires the addition of a paired-pages scheme, a new parameter for MTD partitions of slc-mode, and setting the correct paired-pages scheme for the TC58TEG5DCLTA00 and H27UCG8T2ETR flash chips.

Changes since V3:
- Rebased against master branch as of 2021-12-16.
- Added slc mode support for mtdparts command.

Changes since V2:
- Copied upstream Linux implementation of mtd_erase to fix an issue with creating new ubi partitions.
- Implemented paired page scheme and added support for Hynix flash chip. Based on a cursory reading of the datasheet it appears to use the same pairing scheme as the Toshiba chip.

Changes since V1:

- Updated mtd_read and mtd_write to match upstream Linux.
- Additional mtd_get_master to match upstream Linux.
- Removed notes about ubifs not working, because it is now.

Chris Morgan (3):
mtd: Add support for Linux slc-mode for MLC NAND
mtd: Add pairing info for Toshiba TC58TEG5DCLTA00 NAND
mtd: Add pairing info for Hynix H27UCG8T2ETR NAND

 cmd/mtdparts.c                   |  20 ++
 drivers/mtd/mtdcore.c            | 563 +++++++++++++++++++++++++------
 drivers/mtd/mtdcore.h            |   1 -
 drivers/mtd/mtdpart.c            |   7 +
 drivers/mtd/nand/raw/nand_base.c |  67 ++++
 include/linux/mtd/mtd.h          | 190 ++++++++++-
 include/linux/mtd/partitions.h   |  24 +-
 include/mtd/mtd-abi.h            |   1 +
 8 files changed, 749 insertions(+), 124 deletions(-)
Signature · 1 line
2.30.2
#2 lore raw

PATCH v4 2/3 mtd: Add pairing info for Toshiba TC58TEG5DCLTA00 NAND

From: Chris Morgan <[email protected]>

Add pairing info for the Toshiba TC58TEG5DCLTA00 NAND so that we may utilize slc-mode emulation for enhanced reliability and compatibility with upstream Linux.

---
 drivers/mtd/nand/raw/nand_base.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/mtd/nand/raw/nand_base.c +9 -0
index 8a148863bd..7fdb08e4df 100644
@@ -4542,6 +4542,15 @@ ident_done:
 			break;
 	}
 
+	/* Enable slc-mode on TC58TEG5DCLTA00 to match upstream Linux */
+	if (id_data[0] == NAND_MFR_TOSHIBA && id_data[1] == 0xd7
+	    && id_data[2] == 0x84 && id_data[3] == 0x93
+	    && id_data[4] == 0x72 && id_data[5] == 0x51
+	    && id_data[6] == 0x08 && id_data[7] == 0x04) {
+		chip->options |= NAND_NEED_SCRAMBLING;
+		mtd_set_pairing_scheme(mtd, &dist3_pairing_scheme);
+	}
+
 	if (chip->options & NAND_BUSWIDTH_AUTO) {
 		WARN_ON(chip->options & NAND_BUSWIDTH_16);
 		chip->options |= busw;
Signature · 1 line
2.30.2
#3 lore raw

PATCH v4 3/3 mtd: Add pairing info for Hynix H27UCG8T2ETR NAND

In reply to Chris Morgan

From: Chris Morgan <[email protected]>

Add pairing info for the Hynix H27UCG8T2ETR NAND so that we may utilize slc-mode emulation for enhanced reliability and compatibility with upstream Linux.

I have checked with the team at #mtd and they can confirm based on a cursory reading of the datasheet for this flash chip it appears to use the same dist3 pairing scheme used by the Toshiba NAND which already supports dist3 today in mainline Linux.

---
 drivers/mtd/nand/raw/nand_base.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/mtd/nand/raw/nand_base.c +8 -0
index 7fdb08e4df..20f54444ef 100644
@@ -4551,6 +4551,14 @@ ident_done:
 		mtd_set_pairing_scheme(mtd, &dist3_pairing_scheme);
 	}
 
+	/* Enable slc-mode on H27UCG8T2ETR to enable upstream Linux */
+	if (id_data[0] == NAND_MFR_HYNIX && id_data[1] == 0xde
+	    && id_data[2] == 0x14 && id_data[3] == 0xa7
+	    && id_data[4] == 0x42 && id_data[5] == 0x4a) {
+		chip->options |= NAND_NEED_SCRAMBLING;
+		mtd_set_pairing_scheme(mtd, &dist3_pairing_scheme);
+	}
+
 	if (chip->options & NAND_BUSWIDTH_AUTO) {
 		WARN_ON(chip->options & NAND_BUSWIDTH_16);
 		chip->options |= busw;
Signature · 1 line
2.30.2
#1 lore raw

PATCH v4 1/3 mtd: Add support for Linux slc-mode for MLC NAND

In reply to Chris Morgan

From: Chris Morgan <[email protected]>

Add support for setting the slc-mode parameter for a given MLC NAND device. This allows a given device to write only to the first set of paried pages to help reduce data corruption and increase reliability of the NAND.

I have tested these patches extensively on the NTC CHIP for both SKHynix and Toshiba MLC NAND versions. I have been able to boot from a ubifs partition from a vmlinuz, initramfs, devicetree, and boot.scr from said partition. I have also been able to create a new empty partition from within U-Boot.

As I am unfamiliar with NAND and have limited experience with the MTD subsystems, please let me know what else I can do to improve the driver.

Thank you.

---
 cmd/mtdparts.c                   |  20 ++
 drivers/mtd/mtdcore.c            | 563 +++++++++++++++++++++++++------
 drivers/mtd/mtdcore.h            |   1 -
 drivers/mtd/mtdpart.c            |   7 +
 drivers/mtd/nand/raw/nand_base.c |  50 +++
 include/linux/mtd/mtd.h          | 190 ++++++++++-
 include/linux/mtd/partitions.h   |  24 +-
 include/mtd/mtd-abi.h            |   1 +
 8 files changed, 732 insertions(+), 124 deletions(-)
cmd/mtdparts.c +20 -0
index 3048700778..5c1ad09bf5 100644
@@ -110,6 +110,10 @@ DECLARE_GLOBAL_DATA_PTR;
  * field for read-only partitions */
 #define MTD_WRITEABLE_CMD		1
 
+/* this flag needs to be set in part_info struct mask_flags
+ * field for slc-emulation partitions */
+#define MTD_SLC_ON_MLC_EMULATION_CMD	1
+
 /* default values for mtdids and mtdparts variables */
 #if !defined(MTDIDS_DEFAULT)
 #ifdef CONFIG_MTDIDS_DEFAULT
@@ -662,6 +666,11 @@ static int part_parse(const char *const partdef, const char **ret, struct part_i
 		p += 2;
 	}
 
+	if (strncmp(p, "slc", 3) == 0) {
+		mask_flags |= MTD_SLC_ON_MLC_EMULATION_CMD;
+		p += 3;
+	}
+
 	/* check for next partition definition */
 	if (*p == ',') {
 		if (size == SIZE_REMAINING) {
@@ -1171,6 +1180,17 @@ static int generate_mtdparts(char *buf, u32 buflen)
 				maxlen -= 2;
 			}
 
+			/* slc mask flag */
+			if (part->mask_flags && MTD_SLC_ON_MLC_EMULATION_CMD) {
+				len = 3;
+				if (len > maxlen)
+					goto cleanup;
+				*(p++) = 's';
+				*(p++) = 'l';
+				*(p++) = 'c';
+				maxlen -= 3;
+			}
+
 			/* print ',' separator if there are other partitions
 			 * following */
 			if (dev->num_parts > part_cnt) {
drivers/mtd/mtdcore.c +451 -112

861 lines not on this page · raw message

drivers/mtd/mtdcore.h +0 -1
index 1d181a1045..73f8f21271 100644
@@ -10,7 +10,6 @@ int del_mtd_device(struct mtd_info *mtd);
 int add_mtd_partitions(struct mtd_info *, const struct mtd_partition *, int);
 int del_mtd_partitions(struct mtd_info *);
 int parse_mtd_partitions(struct mtd_info *master, const char * const *types,
-			 struct mtd_partition **pparts,
 			 struct mtd_part_parser_data *data);
 
 int __init init_mtdchar(void);
drivers/mtd/mtdpart.c +7 -0
index a435ce6d07..092853e872 100644
@@ -148,6 +148,12 @@ static int mtd_parse_partition(const char **_mtdparts,
 		mtdparts += 2;
 	}
 
+	/* if slc is found use emulated SLC mode on this partition*/
+	if (!strncmp(mtdparts, "slc", 3)) {
+		partition->add_flags |= MTD_SLC_ON_MLC_EMULATION;
+		mtdparts += 3;
+	}
+
 	/* Check for a potential next partition definition */
 	if (*mtdparts == ',') {
 		if (partition->size == MTD_SIZE_REMAINING) {
@@ -580,6 +586,7 @@ static struct mtd_info *allocate_partition(struct mtd_info *master,
 	/* set up the MTD object for this partition */
 	slave->type = master->type;
 	slave->flags = master->flags & ~part->mask_flags;
+	slave->flags |= part->add_flags;
 	slave->size = part->size;
 	slave->writesize = master->writesize;
 	slave->writebufsize = master->writebufsize;
drivers/mtd/nand/raw/nand_base.c +50 -0

56 lines not on this page · raw message

include/linux/mtd/mtd.h +183 -7

257 lines not on this page · raw message

include/linux/mtd/partitions.h +20 -4
index 0f5a233266..06b36c6881 100644
@@ -20,6 +20,12 @@
  *
  * For each partition, these fields are available:
  * name: string that will be used to label the partition's MTD device.
+ * types: some partitions can be containers using specific format to describe
+ *	embedded subpartitions / volumes. E.g. many home routers use "firmware"
+ *	partition that contains at least kernel and rootfs. In such case an
+ *	extra parser is needed that will detect these dynamic partitions and
+ *	report them to the MTD subsystem. If set this property stores an array
+ *	of parser names to use when looking for subpartitions.
  * size: the partition size; if defined as MTDPART_SIZ_FULL, the partition
  *	will extend to the end of the master MTD device.
  * offset: absolute starting position within the master MTD device; if
@@ -31,6 +37,7 @@
  *	master MTD flag set for the corresponding MTD partition.
  *	For example, to force a read-only partition, simply adding
  *	MTD_WRITEABLE to the mask_flags will do the trick.
+ * add_flags: contains flags to add to the parent flags
  *
  * Note: writeable partitions require their size and offset be
  * erasesize aligned (e.g. use MTDPART_OFS_NEXTBLK).
@@ -38,9 +45,11 @@
 
 struct mtd_partition {
 	const char *name;		/* identifier string */
+	const char *const *types;	/* names of parsers to use if any */
 	uint64_t size;			/* partition size */
 	uint64_t offset;		/* offset within the master MTD space */
 	uint32_t mask_flags;		/* master MTD flags to mask out for this partition */
+	uint32_t add_flags;		/* flags to add to the partition */
 	struct nand_ecclayout *ecclayout;	/* out of band layout for this partition (NAND only) */
 };
 
@@ -53,7 +62,6 @@ struct mtd_partition {
 struct mtd_info;
 struct device_node;
 
-#ifndef __UBOOT__
 /**
  * struct mtd_part_parser_data - used to pass data to MTD partition parsers.
  * @origin: for RedBoot, start address of MTD device
@@ -64,7 +72,6 @@ struct mtd_part_parser_data {
 	struct device_node *of_node;
 };
 
-
 /*
  * Functions dealing with the various ways of partitioning the space
  */
@@ -73,13 +80,22 @@ struct mtd_part_parser {
 	struct list_head list;
 	struct module *owner;
 	const char *name;
-	int (*parse_fn)(struct mtd_info *, struct mtd_partition **,
+	const struct udevice_id *of_match_table;
+	int (*parse_fn)(struct mtd_info *, const struct mtd_partition **,
 			struct mtd_part_parser_data *);
+	void (*cleanup)(const struct mtd_partition *pparts, int nr_parts);
+};
+
+/* Container for passing around a set of parsed partitions */
+struct mtd_partitions {
+	const struct mtd_partition *parts;
+	int nr_parts;
+	const struct mtd_part_parser *parser;
 };
 
+
 extern void register_mtd_parser(struct mtd_part_parser *parser);
 extern void deregister_mtd_parser(struct mtd_part_parser *parser);
-#endif
 
 int mtd_add_partition(struct mtd_info *master, const char *name,
 		      long long offset, long long length);
include/mtd/mtd-abi.h +1 -0
index ea244fbaeb..96850aff93 100644
@@ -94,6 +94,7 @@ struct mtd_write_req {
 #define MTD_BIT_WRITEABLE	0x800	/* Single bits can be flipped */
 #define MTD_NO_ERASE		0x1000	/* No erase necessary */
 #define MTD_POWERUP_LOCK	0x2000	/* Always locked after reset */
+#define MTD_SLC_ON_MLC_EMULATION 0x4000	/* Emulate SLC behavior on MLC NANDs */
 
 /* Some common devices / combinations of capabilities */
 #define MTD_CAP_ROM		0
Signature · 1 line
2.30.2
#4 lore raw
In reply to Chris Morgan
Quoted 27 lines · Chris Morgan

From: Chris Morgan <[email protected]>

Add support for slc-mode implemented in Linux for the Toshiba TC58TEG5DCLTA00 NAND and Hynix H27UCG8T2ETR NAND flash found on the NTC CHIP. This requires the addition of a paired-pages scheme, a new parameter for MTD partitions of slc-mode, and setting the correct paired-pages scheme for the TC58TEG5DCLTA00 and H27UCG8T2ETR flash chips.

Changes since V3:
- Rebased against master branch as of 2021-12-16.
- Added slc mode support for mtdparts command.

Changes since V2:
- Copied upstream Linux implementation of mtd_erase to fix an issue with creating new ubi partitions.
- Implemented paired page scheme and added support for Hynix flash chip. Based on a cursory reading of the datasheet it appears to use the same pairing scheme as the Toshiba chip.

Changes since V1:

- Updated mtd_read and mtd_write to match upstream Linux.
- Additional mtd_get_master to match upstream Linux.
- Removed notes about ubifs not working, because it is now.

Quoted 6 lines

Chris Morgan (3):
mtd: Add support for Linux slc-mode for MLC NAND
mtd: Add pairing info for Toshiba TC58TEG5DCLTA00 NAND
mtd: Add pairing info for Hynix H27UCG8T2ETR NAND

Patch series updating most of MTD core code, any user from parallel nand or nor can make test or ack would help to merge this code.

Thanks,
Jagan.

#5 lore raw

Hi Chris,

Quoted 29 lines · Jagan Teki
Quoted 27 lines · Chris Morgan

From: Chris Morgan <[email protected]>

Add support for slc-mode implemented in Linux for the Toshiba TC58TEG5DCLTA00 NAND and Hynix H27UCG8T2ETR NAND flash found on the NTC CHIP. This requires the addition of a paired-pages scheme, a new parameter for MTD partitions of slc-mode, and setting the correct paired-pages scheme for the TC58TEG5DCLTA00 and H27UCG8T2ETR flash chips.

Changes since V3:
- Rebased against master branch as of 2021-12-16.
- Added slc mode support for mtdparts command.

Changes since V2:
- Copied upstream Linux implementation of mtd_erase to fix an issue with creating new ubi partitions.
- Implemented paired page scheme and added support for Hynix flash chip. Based on a cursory reading of the datasheet it appears to use the same pairing scheme as the Toshiba chip.

Changes since V1:

- Updated mtd_read and mtd_write to match upstream Linux.
- Additional mtd_get_master to match upstream Linux.
- Removed notes about ubifs not working, because it is now.

Quoted 6 lines
Quoted 6 lines

Chris Morgan (3):
mtd: Add support for Linux slc-mode for MLC NAND
mtd: Add pairing info for Toshiba TC58TEG5DCLTA00 NAND
mtd: Add pairing info for Hynix H27UCG8T2ETR NAND

Do you have any updated version for this or it is final itself?

Thanks,
Jagan,

#6 lore raw
Quoted 32 lines · Jagan Teki

Hi Chris,

Quoted 29 lines · Jagan Teki
Quoted 27 lines · Chris Morgan

From: Chris Morgan <[email protected]>

Add support for slc-mode implemented in Linux for the Toshiba TC58TEG5DCLTA00 NAND and Hynix H27UCG8T2ETR NAND flash found on the NTC CHIP. This requires the addition of a paired-pages scheme, a new parameter for MTD partitions of slc-mode, and setting the correct paired-pages scheme for the TC58TEG5DCLTA00 and H27UCG8T2ETR flash chips.

Changes since V3:
- Rebased against master branch as of 2021-12-16.
- Added slc mode support for mtdparts command.

Changes since V2:
- Copied upstream Linux implementation of mtd_erase to fix an issue with creating new ubi partitions.
- Implemented paired page scheme and added support for Hynix flash chip. Based on a cursory reading of the datasheet it appears to use the same pairing scheme as the Toshiba chip.

Changes since V1:

- Updated mtd_read and mtd_write to match upstream Linux.
- Additional mtd_get_master to match upstream Linux.
- Removed notes about ubifs not working, because it is now.

Quoted 8 lines
Quoted 6 lines
Quoted 6 lines

Chris Morgan (3):
mtd: Add support for Linux slc-mode for MLC NAND
mtd: Add pairing info for Toshiba TC58TEG5DCLTA00 NAND
mtd: Add pairing info for Hynix H27UCG8T2ETR NAND

Do you have any updated version for this or it is final itself?

Should be final, but I can rebase it again if need be. I've been running this successfully for the better part of about 3 months now with no more visible issues on my end. I never got fastboot to talk to the mtd subsystem the way I was hoping, but in the end was able to sidestep the issue with an swupdate based flash tool.

Thank you,
Chris.

Quoted 3 lines

Thanks,
Jagan,

#7 lore raw
Quoted 41 lines · Chris Morgan
Quoted 39 lines · Jagan Teki

Hi Chris,

Quoted 35 lines · Jagan Teki
Quoted 33 lines · Chris Morgan

From: Chris Morgan <[email protected]>

Add support for slc-mode implemented in Linux for the Toshiba TC58TEG5DCLTA00 NAND and Hynix H27UCG8T2ETR NAND flash found on the NTC CHIP. This requires the addition of a paired-pages scheme, a new parameter for MTD partitions of slc-mode, and setting the correct paired-pages scheme for the TC58TEG5DCLTA00 and H27UCG8T2ETR flash chips.

Changes since V3:
- Rebased against master branch as of 2021-12-16.
- Added slc mode support for mtdparts command.

Changes since V2:
- Copied upstream Linux implementation of mtd_erase to fix an issue with creating new ubi partitions.
- Implemented paired page scheme and added support for Hynix flash chip. Based on a cursory reading of the datasheet it appears to use the same pairing scheme as the Toshiba chip.

Changes since V1:

- Updated mtd_read and mtd_write to match upstream Linux.
- Additional mtd_get_master to match upstream Linux.
- Removed notes about ubifs not working, because it is now.

Chris Morgan (3):
mtd: Add support for Linux slc-mode for MLC NAND
mtd: Add pairing info for Toshiba TC58TEG5DCLTA00 NAND
mtd: Add pairing info for Hynix H27UCG8T2ETR NAND

Quoted 7 lines
Quoted 1 line

Do you have any updated version for this or it is final itself?

Should be final, but I can rebase it again if need be. I've been running this successfully for the better part of about 3 months now with no more visible issues on my end. I never got fastboot to talk to the mtd subsystem the way I was hoping, but in the end was able to sidestep the issue with an swupdate based flash tool.

Please rebase and send.

Thanks,
Jagan.

#8 lore raw
Quoted 44 lines · Jagan Teki
Quoted 43 lines · Chris Morgan
Quoted 40 lines · Jagan Teki

Hi Chris,

Quoted 29 lines · Jagan Teki
Quoted 27 lines · Chris Morgan

From: Chris Morgan <[email protected]>

Add support for slc-mode implemented in Linux for the Toshiba TC58TEG5DCLTA00 NAND and Hynix H27UCG8T2ETR NAND flash found on the NTC CHIP. This requires the addition of a paired-pages scheme, a new parameter for MTD partitions of slc-mode, and setting the correct paired-pages scheme for the TC58TEG5DCLTA00 and H27UCG8T2ETR flash chips.

Changes since V3:
- Rebased against master branch as of 2021-12-16.
- Added slc mode support for mtdparts command.

Changes since V2:
- Copied upstream Linux implementation of mtd_erase to fix an issue with creating new ubi partitions.
- Implemented paired page scheme and added support for Hynix flash chip. Based on a cursory reading of the datasheet it appears to use the same pairing scheme as the Toshiba chip.

Changes since V1:

- Updated mtd_read and mtd_write to match upstream Linux.
- Additional mtd_get_master to match upstream Linux.
- Removed notes about ubifs not working, because it is now.

Quoted 6 lines
Quoted 6 lines

Chris Morgan (3):
mtd: Add support for Linux slc-mode for MLC NAND
mtd: Add pairing info for Toshiba TC58TEG5DCLTA00 NAND
mtd: Add pairing info for Hynix H27UCG8T2ETR NAND

Do you have any updated version for this or it is final itself?

Quoted 7 lines
Quoted 5 lines

Should be final, but I can rebase it again if need be. I've been running this successfully for the better part of about 3 months now with no more visible issues on my end. I never got fastboot to talk to the mtd subsystem the way I was hoping, but in the end was able to sidestep the issue with an swupdate based flash tool.

Please rebase and send.

I can confirm the patch series still applies, compiles and works on mainline master as of today, so no rebasing should be necessary. Let me know if you find issues on your end though.

Thank you.

Quoted 3 lines

Thanks,
Jagan.