mtd: rawnand: brcmnand: fix OOB R/W with Hamming ECC
authorÁlvaro Fernández Rojas <noltari@gmail.com>
Wed, 24 Feb 2021 08:02:10 +0000 (09:02 +0100)
committerMiquel Raynal <miquel.raynal@bootlin.com>
Thu, 11 Mar 2021 08:37:30 +0000 (09:37 +0100)
Hamming ECC doesn't cover the OOB data, so reading or writing OOB shall
always be done without ECC enabled.
This is a problem when adding JFFS2 cleanmarkers to erased blocks. If JFFS2
clenmarkers are added to the OOB with ECC enabled, OOB bytes will be changed
from ff ff ff to 00 00 00, reporting incorrect ECC errors.

Fixes: 27c5b17cd1b1 ("mtd: nand: add NAND driver "library" for Broadcom STB NAND controller")
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
Acked-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20210224080210.23686-1-noltari@gmail.com
drivers/mtd/nand/raw/brcmnand/brcmnand.c

index 659eaa6f0980cb55339e141d3c557adc9c0cd69c..5ff4291380c534b70f9c0b3f1c04cb6cd58304c9 100644 (file)
@@ -2688,6 +2688,12 @@ static int brcmnand_attach_chip(struct nand_chip *chip)
 
        ret = brcmstb_choose_ecc_layout(host);
 
+       /* If OOB is written with ECC enabled it will cause ECC errors */
+       if (is_hamming_ecc(host->ctrl, &host->hwcfg)) {
+               chip->ecc.write_oob = brcmnand_write_oob_raw;
+               chip->ecc.read_oob = brcmnand_read_oob_raw;
+       }
+
        return ret;
 }