2020-05-04 09:33:34

by Álvaro Fernández Rojas

[permalink] [raw]
Subject: [PATCH 1/2] nand: brcmnand: improve hamming oob layout

The current code generates 8 oob sections:
S1 1-5
ECC 6-8
S2 9-15
S3 16-21
ECC 22-24
S4 25-31
S5 32-37
ECC 38-40
S6 41-47
S7 48-53
ECC 54-56
S8 57-63

Change it by merging continuous sections:
S1 1-5
ECC 6-8
S2 9-21
ECC 22-24
S3 25-37
ECC 38-40
S4 41-53
ECC 54-56
S5 57-63

Signed-off-by: Álvaro Fernández Rojas <[email protected]>
---
drivers/mtd/nand/raw/brcmnand/brcmnand.c | 28 +++++++++---------------
1 file changed, 10 insertions(+), 18 deletions(-)

diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
index e4e3ceeac38f..1bba309c7684 100644
--- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c
+++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
@@ -1100,29 +1100,21 @@ static int brcmnand_hamming_ooblayout_free(struct mtd_info *mtd, int section,
struct brcmnand_cfg *cfg = &host->hwcfg;
int sas = cfg->spare_area_size << cfg->sector_size_1k;
int sectors = cfg->page_size / (512 << cfg->sector_size_1k);
+ u32 next;

- if (section >= sectors * 2)
+ if (section > sectors)
return -ERANGE;

- oobregion->offset = (section / 2) * sas;
+ next = (section * sas);
+ if (section < sectors)
+ next += 6;

- if (section & 1) {
- oobregion->offset += 9;
- oobregion->length = 7;
- } else {
- oobregion->length = 6;
+ if (section)
+ oobregion->offset = ((section - 1) * sas) + 9;
+ else
+ oobregion->offset = 1; /* BBI */

- /* First sector of each page may have BBI */
- if (!section) {
- /*
- * Small-page NAND use byte 6 for BBI while large-page
- * NAND use byte 0.
- */
- if (cfg->page_size > 512)
- oobregion->offset++;
- oobregion->length--;
- }
- }
+ oobregion->length = next - oobregion->offset;

return 0;
}
--
2.26.2


2020-05-04 09:33:38

by Álvaro Fernández Rojas

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

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

Signed-off-by: Álvaro Fernández Rojas <[email protected]>
---
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