[PATCH 2/2] nand: brcmnand: fix BBI in hamming oob layout

Álvaro Fernández Rojas
2020-05-04T09:30:49Z

Small Page NAND uses byte 6 for BBI and Large Page NAND uses first 2 bytes.

Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
---
drivers/mtd/nand/raw/brcmnand/brcmnand.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
index 1bba309c7684..59c3241f4ea5 100644
--- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c
+++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
@@ -1109,10 +1109,18 @@ static int brcmnand_hamming_ooblayout_free(struct mtd_info *mtd, int section,
if (section < sectors)
next += 6;

- if (section)
+ if (section) {
oobregion->offset = ((section - 1) * sas) + 9;
- else
- oobregion->offset = 1; /* BBI */
+ } else {
+ if (cfg->page_size == 512) {
+ /* small page uses byte 6 for BBI */
+ oobregion->offset = 0;
+ next--;
+ } else {
+ /* large page uses first 2 bytes for BBI */
+ oobregion->offset = 2;
+ }
+ }

oobregion->length = next - oobregion->offset;

--
2.26.2