Skip to contentSkip to conversation

Export the ecc step size to user applications

PATCH Superseded Huang Shijie 4 participants 15 messages May 15, 2013 – Aug 11, 2013 1 message not in the archive

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover Export the ecc step size to user applications

In order to implement the NAND boot for some Freescale's chips, such as imx23/imx28/imx50/imx6, we use a tool (called kobs-ng) to burn the uboot and some metadata to nand chip. And the ROM code will use the metadata to configrate the BCH, and to find the uboot.

The ECC information(ecc step size, ecc strength) which is used to configrate the BCH is part of the metadata. The kobs-ng can gets the ecc strength from the sys node /sys/*/mtdX/ecc_strength now. But it can't gets the ecc step size.

This patch set is used to export the ecc step size to user applications. With this patch set, the kobs-ng can gets the ecc step size now.

v1 --> v2:
[1] rename the ecc_size to ecc_step.
[2] rebase on the latest l2-mtd.

Huang Shijie (4):
mtd: add a new field to mtd_info{}
mtd: add a new sys node to show the ecc step size
mtd: set the ecc step size for master/slave mtd_info
mtd: gpmi: update the ecc step size for mtd_info{}

 drivers/mtd/mtdcore.c                  |   11 +++++++++++
 drivers/mtd/mtdpart.c                  |    1 +
 drivers/mtd/nand/gpmi-nand/gpmi-nand.c |    1 +
 drivers/mtd/nand/nand_base.c           |    1 +
 include/linux/mtd/mtd.h                |    3 +++
 5 files changed, 17 insertions(+), 0 deletions(-)
#1 lore raw

PATCH v2 1/4 mtd: add a new field to mtd_info{}

In order to implement the NAND boot for some Freescale's chips, such as imx23/imx28/imx50/imx6, we use a tool (called kobs-ng) to burn the uboot and some metadata to nand chip. And the ROM code will use the metadata to configrate the BCH, and to find the uboot.

The ECC information(ecc step size, ecc strength) which is used to configrate the BCH is part of the metadata. The kobs-ng can gets the ecc strength from the sys node /sys/*/ecc_strength now. But it can not gets the ecc step size.

This patch adds a new field to store the ecc step size in mtd_info{}, and it makes preparation for the next patches.

---
 include/linux/mtd/mtd.h |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
include/linux/mtd/mtd.h +3 -0
index a5cf4e8..effdd41 100644
@@ -173,6 +173,9 @@ struct mtd_info {
 	/* ECC layout structure pointer - read only! */
 	struct nand_ecclayout *ecclayout;
 
+	/* the ecc step size. */
+	unsigned int ecc_step;
+
 	/* max number of correctible bit errors per ecc step */
 	unsigned int ecc_strength;
 
Signature · 1 line
1.7.1
#2 lore raw

PATCH v2 2/4 mtd: add a new sys node to show the ecc step size

In reply to Huang Shijie

Add a new sys node to show the ecc step size.
The application then can uses this node to get the ecc step size.

---
 drivers/mtd/mtdcore.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
drivers/mtd/mtdcore.c +11 -0
index c400c57..63903b9 100644
@@ -285,6 +285,16 @@ static DEVICE_ATTR(bitflip_threshold, S_IRUGO | S_IWUSR,
 		   mtd_bitflip_threshold_show,
 		   mtd_bitflip_threshold_store);
 
+static ssize_t mtd_ecc_step_show(struct device *dev,
+		struct device_attribute *attr, char *buf)
+{
+	struct mtd_info *mtd = dev_get_drvdata(dev);
+
+	return snprintf(buf, PAGE_SIZE, "%lu\n", (unsigned long)mtd->ecc_step);
+
+}
+static DEVICE_ATTR(ecc_step, S_IRUGO, mtd_ecc_step_show, NULL);
+
 static struct attribute *mtd_attrs[] = {
 	&dev_attr_type.attr,
 	&dev_attr_flags.attr,
@@ -296,6 +306,7 @@ static struct attribute *mtd_attrs[] = {
 	&dev_attr_numeraseregions.attr,
 	&dev_attr_name.attr,
 	&dev_attr_ecc_strength.attr,
+	&dev_attr_ecc_step.attr,
 	&dev_attr_bitflip_threshold.attr,
 	NULL,
 };
Signature · 1 line
1.7.1
#3 lore raw

Re: [PATCH v2 2/4] mtd: add a new sys node to show the ecc step size

Quoted 14 lines · Huang Shijie

Add a new sys node to show the ecc step size.
The application then can uses this node to get the ecc step size.

---
 drivers/mtd/mtdcore.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
drivers/mtd/mtdcore.c +0 -0
index c400c57..63903b9 100644

drivers/mtd/mtdcore.c static DEVICE_ATTR(bitflip_threshold, S_IRUGO | S_IWUSR, · line 293

Quoted 9 lines
drivers/mtd/mtdcore.c +6 -0
@@ -285,6 +285,16 @@ static DEVICE_ATTR(bitflip_threshold, S_IRUGO | S_IWUSR,
 		   mtd_bitflip_threshold_show,
 		   mtd_bitflip_threshold_store);
 
+static ssize_t mtd_ecc_step_show(struct device *dev,
+		struct device_attribute *attr, char *buf)
+{
+	struct mtd_info *mtd = dev_get_drvdata(dev);
+
+	return snprintf(buf, PAGE_SIZE, "%lu\n", (unsigned long)mtd->ecc_step);

ecc_step is an unsigned int, so why cast to unsigned long? Just use:

	return snprintf(buf, PAGE_SIZE, "%u\n", mtd->ecc_step);

drivers/mtd/mtdcore.c static DEVICE_ATTR(bitflip_threshold, S_IRUGO | S_IWUSR, · line 300

Quoted 7 lines
drivers/mtd/mtdcore.c +4 -0
+
+}
+static DEVICE_ATTR(ecc_step, S_IRUGO, mtd_ecc_step_show, NULL);
+
 static struct attribute *mtd_attrs[] = {
 	&dev_attr_type.attr,
 	&dev_attr_flags.attr,

...

Brian

#4 lore raw

PATCH v2 3/4 mtd: set the ecc step size for master/slave mtd_info

In reply to Huang Shijie

Set the ecc step size for master/slave mtd_info{}.

---
 drivers/mtd/mtdpart.c        |    1 +
 drivers/mtd/nand/nand_base.c |    1 +
 2 files changed, 2 insertions(+), 0 deletions(-)
drivers/mtd/mtdpart.c +1 -0
index 3014933..63b42a6 100644
@@ -516,6 +516,7 @@ static struct mtd_part *allocate_partition(struct mtd_info *master,
 	}
 
 	slave->mtd.ecclayout = master->ecclayout;
+	slave->mtd.ecc_step = master->ecc_step;
 	slave->mtd.ecc_strength = master->ecc_strength;
 	slave->mtd.bitflip_threshold = master->bitflip_threshold;
 
drivers/mtd/nand/nand_base.c +1 -0
index 359e105..48dfab5 100644
@@ -3747,6 +3747,7 @@ int nand_scan_tail(struct mtd_info *mtd)
 	/* propagate ecc info to mtd_info */
 	mtd->ecclayout = chip->ecc.layout;
 	mtd->ecc_strength = chip->ecc.strength;
+	mtd->ecc_step = chip->ecc.size;
 	/*
 	 * Initialize bitflip_threshold to its default prior scan_bbt() call.
 	 * scan_bbt() might invoke mtd_read(), thus bitflip_threshold must be
Signature · 1 line
1.7.1
#5 lore raw

PATCH v2 4/4 mtd: gpmi: update the ecc step size for mtd_info{}

In reply to Huang Shijie

update the ecc step size when we have already get the right value.

---
 drivers/mtd/nand/gpmi-nand/gpmi-nand.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +1 -0
index 53180da..bc598e6 100644
@@ -1598,6 +1598,7 @@ static int gpmi_pre_bbt_scan(struct gpmi_nand_data  *this)
 	/* Adjust the ECC strength according to the chip. */
 	this->nand.ecc.strength = this->bch_geometry.ecc_strength;
 	this->mtd.ecc_strength = this->bch_geometry.ecc_strength;
+	this->mtd.ecc_step = this->bch_geometry.ecc_chunk_size;
 	this->mtd.bitflip_threshold = this->bch_geometry.ecc_strength;
 
 	/* NAND boot init, depends on the gpmi_set_geometry(). */
Signature · 1 line
1.7.1
#6 lore raw

Re: [PATCH v2 4/4] mtd: gpmi: update the ecc step size for mtd_info{}

Quoted 12 lines · Huang Shijie

update the ecc step size when we have already get the right value.

---
 drivers/mtd/nand/gpmi-nand/gpmi-nand.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +0 -0
index 53180da..bc598e6 100644

drivers/mtd/nand/gpmi-nand/gpmi-nand.c static int gpmi_pre_bbt_scan(struct gpmi_nand_data *this) · line 1601

Quoted 4 lines
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +1 -0
@@ -1598,6 +1598,7 @@ static int gpmi_pre_bbt_scan(struct gpmi_nand_data  *this)
 	/* Adjust the ECC strength according to the chip. */
 	this->nand.ecc.strength = this->bch_geometry.ecc_strength;
 	this->mtd.ecc_strength = this->bch_geometry.ecc_strength;
+	this->mtd.ecc_step = this->bch_geometry.ecc_chunk_size;

Why do you need a special case here for gpmi-nand? GPMI should be initializing nand_ecc_ctrl.size (this->ecc.size) to something meaningful instead of directly setting to 1. Then nand_base will take care of setting mtd.ecc_step.

Along the same line, you shouldn't need to directly override mtd.ecc_strength here; you should be setting this->ecc.strength appropriately.

I see several instances here where gpmi-nand is hacking around nand_base, rather than using its intended infrastructure.

The right way seems to be to avoid nand_scan() directly but instead to use nand_scan_ident() and nand_scan_tail() separately (that's what they're exported for) so that you can initialize any geometry-related options before nand_scan_tail() does the last steps.

In the end, you shouldn't be needing to override this->scan_bbt at all, since you really intend to use the default implementation; you just are doing this to hack around your issues. In fact, I think every use of nand_default_bbt() outside of nand_base is a design mistake.

drivers/mtd/nand/gpmi-nand/gpmi-nand.c static int gpmi_pre_bbt_scan(struct gpmi_nand_data *this) · line 1604

Quoted 4 lines
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +0 -0
 	this->mtd.bitflip_threshold = this->bch_geometry.ecc_strength;
 
 	/* NAND boot init, depends on the gpmi_set_geometry(). */

Brian

#7 lore raw

Re: [PATCH v2 4/4] mtd: gpmi: update the ecc step size for mtd_info{}

Quoted 8 lines · Brian Norris
Quoted 7 lines · Huang Shijie

update the ecc step size when we have already get the right value.

---
 drivers/mtd/nand/gpmi-nand/gpmi-nand.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
Quoted 12 lines

drivers/mtd/nand/gpmi-nand/gpmi-nand.c static int gpmi_pre_bbt_scan(struct gpmi_nand_data *this) · line 1601

Quoted 9 lines
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +1 -0
index 53180da..bc598e6 100644
@@ -1598,6 +1598,7 @@ static int gpmi_pre_bbt_scan(struct gpmi_nand_data  *this)
      /* Adjust the ECC strength according to the chip. */
      this->nand.ecc.strength = this->bch_geometry.ecc_strength;
      this->mtd.ecc_strength = this->bch_geometry.ecc_strength;
+     this->mtd.ecc_step = this->bch_geometry.ecc_chunk_size;

Why do you need a special case here for gpmi-nand? GPMI should be initializing nand_ecc_ctrl.size (this->ecc.size) to something meaningful

Correction: should be this->nand.ecc.size

Quoted 6 lines

instead of directly setting to 1. Then nand_base will take care of setting mtd.ecc_step.

Along the same line, you shouldn't need to directly override mtd.ecc_strength here; you should be setting this->ecc.strength appropriately.

Correction: should be this->nand.ecc.strength. And another correction:
you are already setting this field, but you are doing it in the wrong place.

Quoted 8 lines

I see several instances here where gpmi-nand is hacking around nand_base, rather than using its intended infrastructure.

The right way seems to be to avoid nand_scan() directly but instead to use nand_scan_ident() and nand_scan_tail() separately (that's what they're exported for) so that you can initialize any geometry-related options before nand_scan_tail() does the last steps.

Quoted 9 lines

In the end, you shouldn't be needing to override this->scan_bbt at all, since you really intend to use the default implementation; you just are doing this to hack around your issues. In fact, I think every use of nand_default_bbt() outside of nand_base is a design mistake.

Quoted 4 lines
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +0 -0
      this->mtd.bitflip_threshold = this->bch_geometry.ecc_strength;
 
      /* NAND boot init, depends on the gpmi_set_geometry(). */

Sorry for the above mistakes, but the argument still holds. In fact, it's somewhat stronger, because gpmi-nand has to assign the same information to two different (redundant) fields (this->nand.ecc.strength and this->mtd.ecc_strength) because it is not using the proper layering here.

Brian

#8 lore raw

Re: [PATCH v2 4/4] mtd: gpmi: update the ecc step size for mtd_info{}

Quoted 4 lines · Brian Norris

The right way seems to be to avoid nand_scan() directly but instead to

Quoted 3 lines

use nand_scan_ident() and nand_scan_tail() separately (that's what they're exported for) so that you can initialize any geometry-related options before nand_scan_tail() does the last steps.

i agree with you.
I will create a v3 version tomorrow when i back to office.

thanks for the review.
Huang Shijie

#9 lore raw
In reply to Huang Shijie
Quoted 8 lines · Huang Shijie

In order to implement the NAND boot for some Freescale's chips, such as imx23/imx28/imx50/imx6, we use a tool (called kobs-ng) to burn the uboot and some metadata to nand chip. And the ROM code will use the metadata to configrate the BCH, and to find the uboot.

The ECC information(ecc step size, ecc strength) which is used to configrate the BCH is part of the metadata. The kobs-ng can gets the ecc strength from the sys node /sys/*/mtdX/ecc_strength now. But it can't gets the ecc step size.

Looks good to me. Would you please update Documentation/ABI/testing/sysfs-class-mtd as well?

Signature · 2 lines
Best Regards,
Artem Bityutskiy
#10 lore raw

PATCH v2 1/1 mtd: update the ABI document about the ecc step

We add a new sys node for ecc step. So update the ABI document about it.

---
 Documentation/ABI/testing/sysfs-class-mtd |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
Documentation/ABI/testing/sysfs-class-mtd +11 -0
index 3105644..62a1cda 100644
@@ -173,3 +173,14 @@ Description:
 		This is generally applicable only to NAND flash devices with ECC
 		capability.  It is ignored on devices lacking ECC capability;
 		i.e., devices for which ecc_strength is zero.
+
+What:		/sys/class/mtd/mtdX/ecc_step
+Date:		May 2013
+KernelVersion:	3.10
+Contact:	[email protected]
+Description:
+		The size of ecc step which is used for per ecc correction.
+		See more in the ecc_strength above. This will always be a
+		non-negative integer.
+
+		In the case of devices lacking any ECC capability, it is 0.
Signature · 1 line
1.7.1
#11 lore raw

Re: [PATCH v2 append] mtd: update the ABI document about the ecc step

Quoted 12 lines · Huang Shijie

We add a new sys node for ecc step. So update the ABI document about it.

---
 Documentation/ABI/testing/sysfs-class-mtd |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
Documentation/ABI/testing/sysfs-class-mtd +0 -0
index 3105644..62a1cda 100644

Documentation/ABI/testing/sysfs-class-mtd Description: · line 182

Quoted 10 lines
Documentation/ABI/testing/sysfs-class-mtd +7 -0
@@ -173,3 +173,14 @@ Description:
 		This is generally applicable only to NAND flash devices with ECC
 		capability.  It is ignored on devices lacking ECC capability;
 		i.e., devices for which ecc_strength is zero.
+
+What:		/sys/class/mtd/mtdX/ecc_step
+Date:		May 2013
+KernelVersion:	3.10
+Contact:	[email protected]
+Description:
+		The size of ecc step which is used for per ecc correction.

Despite the usage of lower-case 'ecc' in some places, I would prefer consistent usage of upper-case 'ECC'. And "ECC correction" is redundant.

Also, "...which is used for per ecc correction" doesn't make sense to me. Perhaps you just mean "...which is used for ECC"?

The following note under the current ecc_strength documentation makes more sense here, actually:

"Note that some devices will have multiple ecc steps within each
writesize region."

Maybe just copy-and-paste it here too?

Documentation/ABI/testing/sysfs-class-mtd Description: · line 186

Quoted 4 lines
Documentation/ABI/testing/sysfs-class-mtd +4 -0
+		See more in the ecc_strength above. This will always be a
+		non-negative integer.
+
+		In the case of devices lacking any ECC capability, it is 0.

These wording comments aren't highly important. If I have any more changes, I can just edit before applying when you send v3.

Thanks,
Brian

A message that is not in the archive (sent off-list or not yet received): CAMiH66GygmwvfZrwys7RoeoY4Q_fFkfbiZF_pJN4RxQBPaz0fw@mail.gmail.com

#13 lore raw
Quoted 3 lines · Huang Shijie

ok. can i send a separate patch to fix it?
or a new version patch set?

Just a follow-up patch. I would like to let this patch-set sit in the mailing list for some time before I pick it, in case someone wants to comment.

Also, surely the things you expose are the real ECC step and ECC strength? I think the datasheet ones in your other patch-set should be named differently to make sure the reader of the code understands that they are only the recommended datasheet values, not necessarily the values which are actually in use.

Signature · 2 lines
Best Regards,
Artem Bityutskiy
#14 lore raw
Quoted 2 lines · Artem Bityutskiy

Also, surely the things you expose are the real ECC step and ECC strength? I think the datasheet ones in your other patch-set should be

yes. I am sure of that.
I need the _real_ ECC step and ECC strength.

thanks
Huang Shijie

#15 lore raw
In reply to Huang Shijie

Hi Artem & Brian:

Quoted 22 lines

In order to implement the NAND boot for some Freescale's chips, such as imx23/imx28/imx50/imx6, we use a tool (called kobs-ng) to burn the uboot and some metadata to nand chip. And the ROM code will use the metadata to configrate the BCH, and to find the uboot.

The ECC information(ecc step size, ecc strength) which is used to configrate the BCH is part of the metadata. The kobs-ng can gets the ecc strength from the sys node /sys/*/mtdX/ecc_strength now. But it can't gets the ecc step size.

This patch set is used to export the ecc step size to user applications. With this patch set, the kobs-ng can gets the ecc step size now.

v1 --> v2:
[1] rename the ecc_size to ecc_step.
[2] rebase on the latest l2-mtd.

Huang Shijie (4):
mtd: add a new field to mtd_info{}
mtd: add a new sys node to show the ecc step size
mtd: set the ecc step size for master/slave mtd_info
mtd: gpmi: update the ecc step size for mtd_info{}

Quoted 7 lines
 drivers/mtd/mtdcore.c                  |   11 +++++++++++
 drivers/mtd/mtdpart.c                  |    1 +
 drivers/mtd/nand/gpmi-nand/gpmi-nand.c |    1 +
 drivers/mtd/nand/nand_base.c           |    1 +
 include/linux/mtd/mtd.h                |    3 +++
 5 files changed, 17 insertions(+), 0 deletions(-)

Could you merge this patch set ?

thanks
Huang Shijie