Skip to contentSkip to conversation

nand: raw: use write_oob_raw for MTD_OPS_AUTO_OOB mode

PATCH In review Álvaro Fernández Rojas 3 participants 7 messages May 4, 2020 – Jun 5, 2020

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

PATCH 1/1 nand: raw: use write_oob_raw for MTD_OPS_AUTO_OOB mode

Some NAND controllers change the ECC bytes when OOB is written with ECC enabled.
This is a problem in brcmnand, since adding JFFS2 cleanmarkers after the page has been erased will change the ECC bytes to 0 and the controller will think the block is bad.
It can be fixed by using write_oob_raw, which ensures ECC is disabled.

---
 drivers/mtd/nand/raw/nand_base.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/raw/nand_base.c +1 -1
index c24e5e2ba130..755d25200520 100644
@@ -488,7 +488,7 @@ static int nand_do_write_oob(struct nand_chip *chip, loff_t to,
 
 	nand_fill_oob(chip, ops->oobbuf, ops->ooblen, ops);
 
-	if (ops->mode == MTD_OPS_RAW)
+	if (ops->mode == MTD_OPS_AUTO_OOB || ops->mode == MTD_OPS_RAW)
 		status = chip->ecc.write_oob_raw(chip, page & chip->pagemask);
 	else
 		status = chip->ecc.write_oob(chip, page & chip->pagemask);
Signature · 1 line
2.26.2
#1 lore raw
Quoted 17 lines · On Mon, 4 May 2020 11:42:53 +0200 Álvaro Fernández Rojas <[email protected]>…

Some NAND controllers change the ECC bytes when OOB is written with ECC enabled.
This is a problem in brcmnand, since adding JFFS2 cleanmarkers after the page has been erased will change the ECC bytes to 0 and the controller will think the block is bad.
It can be fixed by using write_oob_raw, which ensures ECC is disabled.

---
 drivers/mtd/nand/raw/nand_base.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/raw/nand_base.c +0 -0
index c24e5e2ba130..755d25200520 100644

drivers/mtd/nand/raw/nand_base.c static int nand_do_write_oob(struct nand_chip *chip, loff_t to, · line 492

Quoted 6 lines
drivers/mtd/nand/raw/nand_base.c +1 -1
@@ -488,7 +488,7 @@ static int nand_do_write_oob(struct nand_chip *chip, loff_t to,
 
 	nand_fill_oob(chip, ops->oobbuf, ops->ooblen, ops);
 
-	if (ops->mode == MTD_OPS_RAW)
+	if (ops->mode == MTD_OPS_AUTO_OOB || ops->mode == MTD_OPS_RAW)
 		status = chip->ecc.write_oob_raw(chip, page & chip->pagemask);

The doc says:

@MTD_OPS_PLACE_OOB: OOB data are placed at the given offset (default)
@MTD_OPS_AUTO_OOB: OOB data are automatically placed at the free areas
which are defined by the internal ecclayout
@MTD_OPS_RAW: data are transferred as-is, with no error
correction; this mode implies %MTD_OPS_PLACE_OOB

To me, that means MTD_OPS_PLACE_OOB and MTD_OPS_AUTO_OOB do not imply MTD_OPS_RAW. Anyway those modes are just too vague. We really should separate the ECC-disabled/ECC-enabled concept (AKA raw vs non-raw mode) from the OOB placement scheme. IIRC, Miquel had a patchset doing that.

We also should have the concept of protected OOB-region vs unprotected-OOB-region if we want JFFS2 to work with controllers that protect part of the OOB region. Once we have that we can patch JFFS2 to write things with "ECC-disabled"+"auto-OOB-placement-on-unprotected area".

Quoted 2 lines
drivers/mtd/nand/raw/nand_base.c +0 -0
 	else
 		status = chip->ecc.write_oob(chip, page & chip->pagemask);
maintainer
#2 lore raw

Hello,

Boris Brezillon <[email protected]> wrote on Mon, 4 May 2020 12:32:37 +0200:

Quoted 40 lines
Quoted 17 lines · On Mon, 4 May 2020 11:42:53 +0200 Álvaro Fernández Rojas <[email protected]>…

Some NAND controllers change the ECC bytes when OOB is written with ECC enabled.
This is a problem in brcmnand, since adding JFFS2 cleanmarkers after the page has been erased will change the ECC bytes to 0 and the controller will think the block is bad.
It can be fixed by using write_oob_raw, which ensures ECC is disabled.

---
 drivers/mtd/nand/raw/nand_base.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/raw/nand_base.c +0 -0
index c24e5e2ba130..755d25200520 100644

drivers/mtd/nand/raw/nand_base.c static int nand_do_write_oob(struct nand_chip *chip, loff_t to, · line 492

Quoted 6 lines
drivers/mtd/nand/raw/nand_base.c +1 -1
@@ -488,7 +488,7 @@ static int nand_do_write_oob(struct nand_chip *chip, loff_t to,
 
 	nand_fill_oob(chip, ops->oobbuf, ops->ooblen, ops);
 
-	if (ops->mode == MTD_OPS_RAW)
+	if (ops->mode == MTD_OPS_AUTO_OOB || ops->mode == MTD_OPS_RAW)
 		status = chip->ecc.write_oob_raw(chip, page & chip->pagemask);  

The doc says:

@MTD_OPS_PLACE_OOB: OOB data are placed at the given offset (default)
@MTD_OPS_AUTO_OOB: OOB data are automatically placed at the free areas
which are defined by the internal ecclayout
@MTD_OPS_RAW: data are transferred as-is, with no error
correction; this mode implies %MTD_OPS_PLACE_OOB

To me, that means MTD_OPS_PLACE_OOB and MTD_OPS_AUTO_OOB do not imply MTD_OPS_RAW. Anyway those modes are just too vague. We really should separate the ECC-disabled/ECC-enabled concept (AKA raw vs non-raw mode) from the OOB placement scheme. IIRC, Miquel had a patchset doing that.

Quoted 5 lines

We also should have the concept of protected OOB-region vs unprotected-OOB-region if we want JFFS2 to work with controllers that protect part of the OOB region. Once we have that we can patch JFFS2 to write things with "ECC-disabled"+"auto-OOB-placement-on-unprotected area".

I see the problem but as Boris said the fix is not valid as-is. Problem is: I don't have a better proposal yet.

Is forcing JFFS2 to write cleanmarkers in raw mode only an option?

#3 lore raw

Hi,

Quoted 53 lines · Miquel Raynal

Hello,

Boris Brezillon <[email protected]> wrote on Mon, 4 May 2020 12:32:37 +0200:

Quoted 40 lines
Quoted 17 lines · On Mon, 4 May 2020 11:42:53 +0200 Álvaro Fernández Rojas <[email protected]>…

Some NAND controllers change the ECC bytes when OOB is written with ECC enabled.
This is a problem in brcmnand, since adding JFFS2 cleanmarkers after the page has been erased will change the ECC bytes to 0 and the controller will think the block is bad.
It can be fixed by using write_oob_raw, which ensures ECC is disabled.

---
drivers/mtd/nand/raw/nand_base.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/raw/nand_base.c +0 -0
index c24e5e2ba130..755d25200520 100644

drivers/mtd/nand/raw/nand_base.c static int nand_do_write_oob(struct nand_chip *chip, loff_t to, · line 492

Quoted 6 lines
drivers/mtd/nand/raw/nand_base.c +1 -1
@@ -488,7 +488,7 @@ static int nand_do_write_oob(struct nand_chip *chip, loff_t to,
 
 	nand_fill_oob(chip, ops->oobbuf, ops->ooblen, ops);
 
-	if (ops->mode == MTD_OPS_RAW)
+	if (ops->mode == MTD_OPS_AUTO_OOB || ops->mode == MTD_OPS_RAW)
 		status = chip->ecc.write_oob_raw(chip, page & chip->pagemask);  

The doc says:

@MTD_OPS_PLACE_OOB: OOB data are placed at the given offset (default)
@MTD_OPS_AUTO_OOB: OOB data are automatically placed at the free areas
which are defined by the internal ecclayout
@MTD_OPS_RAW: data are transferred as-is, with no error
correction; this mode implies %MTD_OPS_PLACE_OOB

To me, that means MTD_OPS_PLACE_OOB and MTD_OPS_AUTO_OOB do not imply MTD_OPS_RAW. Anyway those modes are just too vague. We really should separate the ECC-disabled/ECC-enabled concept (AKA raw vs non-raw mode) from the OOB placement scheme. IIRC, Miquel had a patchset doing that.

Quoted 5 lines

We also should have the concept of protected OOB-region vs unprotected-OOB-region if we want JFFS2 to work with controllers that protect part of the OOB region. Once we have that we can patch JFFS2 to write things with "ECC-disabled"+"auto-OOB-placement-on-unprotected area".

Quoted 4 lines

I see the problem but as Boris said the fix is not valid as-is. Problem is: I don't have a better proposal yet.

Is forcing JFFS2 to write cleanmarkers in raw mode only an option?

The doc says that for MTD_OPS_AUTO_OOB "the data is automatically placed at the free areas which are defined by the internal ecclayout”.
So, if we’re placing this data in the free OOB area left by the ECC bytes it means that this automatically placed data won’t be error correctable, since it’s in the OOB, and the OOB data isn’t error corrected, right?

The problem is that "flash_erase -j” uses MTD_OPS_AUTO_OOB to write the OOB JFFS2 clean markers and if this is written with ECC enabled the NAND controller will change the ECC bytes to an invalid value (or at least brcmnand controller).

Another option could be adding another mode, something like MTD_OPS_AUTO_OOB_RAW and using it in mtd-utils and JFFS2.

Best regards,
Álvaro.

maintainer
#4 lore raw

Hello,

Richard, maybe you'll have an idea to fix the situation here?

Álvaro Fernández Rojas <[email protected]> wrote on Tue, 12 May 2020 10:36:25 +0200:

Quoted 55 lines

Hi,

Quoted 53 lines · Miquel Raynal

Hello,

Boris Brezillon <[email protected]> wrote on Mon, 4 May 2020 12:32:37 +0200:

Quoted 45 lines
Quoted 17 lines · On Mon, 4 May 2020 11:42:53 +0200 Álvaro Fernández Rojas <[email protected]>…

Some NAND controllers change the ECC bytes when OOB is written with ECC enabled.
This is a problem in brcmnand, since adding JFFS2 cleanmarkers after the page has been erased will change the ECC bytes to 0 and the controller will think the block is bad.
It can be fixed by using write_oob_raw, which ensures ECC is disabled.

---
drivers/mtd/nand/raw/nand_base.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/raw/nand_base.c +0 -0
index c24e5e2ba130..755d25200520 100644

drivers/mtd/nand/raw/nand_base.c static int nand_do_write_oob(struct nand_chip *chip, loff_t to, · line 492

Quoted 6 lines
drivers/mtd/nand/raw/nand_base.c +1 -1
@@ -488,7 +488,7 @@ static int nand_do_write_oob(struct nand_chip *chip, loff_t to,
 
 	nand_fill_oob(chip, ops->oobbuf, ops->ooblen, ops);
 
-	if (ops->mode == MTD_OPS_RAW)
+	if (ops->mode == MTD_OPS_AUTO_OOB || ops->mode == MTD_OPS_RAW)
 		status = chip->ecc.write_oob_raw(chip, page & chip->pagemask);    

The doc says:

@MTD_OPS_PLACE_OOB: OOB data are placed at the given offset (default)
@MTD_OPS_AUTO_OOB: OOB data are automatically placed at the free areas
which are defined by the internal ecclayout
@MTD_OPS_RAW: data are transferred as-is, with no error
correction; this mode implies %MTD_OPS_PLACE_OOB

To me, that means MTD_OPS_PLACE_OOB and MTD_OPS_AUTO_OOB do not imply MTD_OPS_RAW. Anyway those modes are just too vague. We really should separate the ECC-disabled/ECC-enabled concept (AKA raw vs non-raw mode) from the OOB placement scheme. IIRC, Miquel had a patchset doing that.

We also should have the concept of protected OOB-region vs unprotected-OOB-region if we want JFFS2 to work with controllers that protect part of the OOB region. Once we have that we can patch JFFS2 to write things with "ECC-disabled"+"auto-OOB-placement-on-unprotected area".

Quoted 7 lines
Quoted 4 lines

I see the problem but as Boris said the fix is not valid as-is. Problem is: I don't have a better proposal yet.

Is forcing JFFS2 to write cleanmarkers in raw mode only an option?

The doc says that for MTD_OPS_AUTO_OOB "the data is automatically placed at the free areas which are defined by the internal ecclayout”.
So, if we’re placing this data in the free OOB area left by the ECC bytes it means that this automatically placed data won’t be error correctable, since it’s in the OOB, and the OOB data isn’t error corrected, right?

No, free bytes sometimes are and sometimes are not covered by the ECC engine. It depends on the controller.

Quoted 3 lines

The problem is that "flash_erase -j” uses MTD_OPS_AUTO_OOB to write the OOB JFFS2 clean markers and if this is written with ECC enabled the NAND controller will change the ECC bytes to an invalid value (or at least brcmnand controller).

Another option could be adding another mode, something like MTD_OPS_AUTO_OOB_RAW and using it in mtd-utils and JFFS2.

No, these modes already are completely wrong, I must resend my series fixing them.

#5 lore raw
Quoted 73 lines · On Tue, 12 May 2020 10:44:22 +0200 Miquel Raynal <[email protected]>…

Hello,

Richard, maybe you'll have an idea to fix the situation here?

Álvaro Fernández Rojas <[email protected]> wrote on Tue, 12 May 2020 10:36:25 +0200:

Quoted 55 lines

Hi,

Quoted 53 lines · Miquel Raynal

Hello,

Boris Brezillon <[email protected]> wrote on Mon, 4 May 2020 12:32:37 +0200:

Quoted 45 lines
Quoted 17 lines · On Mon, 4 May 2020 11:42:53 +0200 Álvaro Fernández Rojas <[email protected]>…

Some NAND controllers change the ECC bytes when OOB is written with ECC enabled.
This is a problem in brcmnand, since adding JFFS2 cleanmarkers after the page has been erased will change the ECC bytes to 0 and the controller will think the block is bad.
It can be fixed by using write_oob_raw, which ensures ECC is disabled.

---
drivers/mtd/nand/raw/nand_base.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/raw/nand_base.c +0 -0
index c24e5e2ba130..755d25200520 100644

drivers/mtd/nand/raw/nand_base.c static int nand_do_write_oob(struct nand_chip *chip, loff_t to, · line 492

Quoted 6 lines
drivers/mtd/nand/raw/nand_base.c +1 -1
@@ -488,7 +488,7 @@ static int nand_do_write_oob(struct nand_chip *chip, loff_t to,
 
 	nand_fill_oob(chip, ops->oobbuf, ops->ooblen, ops);
 
-	if (ops->mode == MTD_OPS_RAW)
+	if (ops->mode == MTD_OPS_AUTO_OOB || ops->mode == MTD_OPS_RAW)
 		status = chip->ecc.write_oob_raw(chip, page & chip->pagemask);      

The doc says:

@MTD_OPS_PLACE_OOB: OOB data are placed at the given offset (default)
@MTD_OPS_AUTO_OOB: OOB data are automatically placed at the free areas
which are defined by the internal ecclayout
@MTD_OPS_RAW: data are transferred as-is, with no error
correction; this mode implies %MTD_OPS_PLACE_OOB

To me, that means MTD_OPS_PLACE_OOB and MTD_OPS_AUTO_OOB do not imply MTD_OPS_RAW. Anyway those modes are just too vague. We really should separate the ECC-disabled/ECC-enabled concept (AKA raw vs non-raw mode) from the OOB placement scheme. IIRC, Miquel had a patchset doing that.

We also should have the concept of protected OOB-region vs unprotected-OOB-region if we want JFFS2 to work with controllers that protect part of the OOB region. Once we have that we can patch JFFS2 to write things with "ECC-disabled"+"auto-OOB-placement-on-unprotected area".

Quoted 7 lines
Quoted 4 lines

I see the problem but as Boris said the fix is not valid as-is. Problem is: I don't have a better proposal yet.

Is forcing JFFS2 to write cleanmarkers in raw mode only an option?

The doc says that for MTD_OPS_AUTO_OOB "the data is automatically placed at the free areas which are defined by the internal ecclayout”.
So, if we’re placing this data in the free OOB area left by the ECC bytes it means that this automatically placed data won’t be error correctable, since it’s in the OOB, and the OOB data isn’t error corrected, right?

No, free bytes sometimes are and sometimes are not covered by the ECC engine. It depends on the controller.

Quoted 7 lines
Quoted 3 lines

The problem is that "flash_erase -j” uses MTD_OPS_AUTO_OOB to write the OOB JFFS2 clean markers and if this is written with ECC enabled the NAND controller will change the ECC bytes to an invalid value (or at least brcmnand controller).

Another option could be adding another mode, something like MTD_OPS_AUTO_OOB_RAW and using it in mtd-utils and JFFS2.

No, these modes already are completely wrong, I must resend my series fixing them.

Totally agree with Miquel on that one: let's fix the write/read/ecc-layout semantics instead of adding more obscure modes.

#6 lore raw

I’ve now sent another patch “mtd: rawnand: brcmnand: force raw OOB writes” as an alternative solution to this issue.

Best regards,
Álvaro.

Quoted 88 lines · Boris Brezillon
Quoted 73 lines · On Tue, 12 May 2020 10:44:22 +0200 Miquel Raynal <[email protected]>…

Hello,

Richard, maybe you'll have an idea to fix the situation here?

Álvaro Fernández Rojas <[email protected]> wrote on Tue, 12 May 2020 10:36:25 +0200:

Quoted 55 lines

Hi,

Quoted 53 lines · Miquel Raynal

Hello,

Boris Brezillon <[email protected]> wrote on Mon, 4 May 2020 12:32:37 +0200:

Quoted 45 lines
Quoted 17 lines · On Mon, 4 May 2020 11:42:53 +0200 Álvaro Fernández Rojas <[email protected]>…

Some NAND controllers change the ECC bytes when OOB is written with ECC enabled.
This is a problem in brcmnand, since adding JFFS2 cleanmarkers after the page has been erased will change the ECC bytes to 0 and the controller will think the block is bad.
It can be fixed by using write_oob_raw, which ensures ECC is disabled.

---
drivers/mtd/nand/raw/nand_base.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/raw/nand_base.c +0 -0
index c24e5e2ba130..755d25200520 100644

drivers/mtd/nand/raw/nand_base.c static int nand_do_write_oob(struct nand_chip *chip, loff_t to, · line 492

Quoted 6 lines
drivers/mtd/nand/raw/nand_base.c +1 -1
@@ -488,7 +488,7 @@ static int nand_do_write_oob(struct nand_chip *chip, loff_t to,
 
 	nand_fill_oob(chip, ops->oobbuf, ops->ooblen, ops);
 
-	if (ops->mode == MTD_OPS_RAW)
+	if (ops->mode == MTD_OPS_AUTO_OOB || ops->mode == MTD_OPS_RAW)
 		status = chip->ecc.write_oob_raw(chip, page & chip->pagemask);      

The doc says:

@MTD_OPS_PLACE_OOB: OOB data are placed at the given offset (default)
@MTD_OPS_AUTO_OOB: OOB data are automatically placed at the free areas
which are defined by the internal ecclayout
@MTD_OPS_RAW: data are transferred as-is, with no error
correction; this mode implies %MTD_OPS_PLACE_OOB

To me, that means MTD_OPS_PLACE_OOB and MTD_OPS_AUTO_OOB do not imply MTD_OPS_RAW. Anyway those modes are just too vague. We really should separate the ECC-disabled/ECC-enabled concept (AKA raw vs non-raw mode) from the OOB placement scheme. IIRC, Miquel had a patchset doing that.

We also should have the concept of protected OOB-region vs unprotected-OOB-region if we want JFFS2 to work with controllers that protect part of the OOB region. Once we have that we can patch JFFS2 to write things with "ECC-disabled"+"auto-OOB-placement-on-unprotected area".

Quoted 7 lines
Quoted 4 lines

I see the problem but as Boris said the fix is not valid as-is. Problem is: I don't have a better proposal yet.

Is forcing JFFS2 to write cleanmarkers in raw mode only an option?

The doc says that for MTD_OPS_AUTO_OOB "the data is automatically placed at the free areas which are defined by the internal ecclayout”.
So, if we’re placing this data in the free OOB area left by the ECC bytes it means that this automatically placed data won’t be error correctable, since it’s in the OOB, and the OOB data isn’t error corrected, right?

No, free bytes sometimes are and sometimes are not covered by the ECC engine. It depends on the controller.

Quoted 7 lines
Quoted 3 lines

The problem is that "flash_erase -j” uses MTD_OPS_AUTO_OOB to write the OOB JFFS2 clean markers and if this is written with ECC enabled the NAND controller will change the ECC bytes to an invalid value (or at least brcmnand controller).

Another option could be adding another mode, something like MTD_OPS_AUTO_OOB_RAW and using it in mtd-utils and JFFS2.

No, these modes already are completely wrong, I must resend my series fixing them.

Totally agree with Miquel on that one: let's fix the write/read/ecc-layout semantics instead of adding more obscure modes.