Skip to content

Commit 2c1c5f1

Browse files
baruchsiachDavid Woodhouse
authored and
David Woodhouse
committed
mtd: mxc_nand: fix OOB corruption when page size > 2KiB
When page size is 4KiB, ecc.total is set to 8*9, and this causes nand_write_page_hwecc() to read past the initialized part of the eccpos array, which corrupts chip->oob_poi with bogus values from ecc_calc. Fix this by creating a proper nand_ecclayout for 4KiB flashes. Signed-off-by: Baruch Siach <[email protected]> Acked-by: Sascha Hauer <[email protected]> Signed-off-by: David Woodhouse <[email protected]>
1 parent f43272c commit 2c1c5f1

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

drivers/mtd/nand/mxc_nand.c

+27
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,31 @@ static struct nand_ecclayout nandv2_hw_eccoob_largepage = {
211211
}
212212
};
213213

214+
/* OOB description for 4096 byte pages with 128 byte OOB */
215+
static struct nand_ecclayout nandv2_hw_eccoob_4k = {
216+
.eccbytes = 8 * 9,
217+
.eccpos = {
218+
7, 8, 9, 10, 11, 12, 13, 14, 15,
219+
23, 24, 25, 26, 27, 28, 29, 30, 31,
220+
39, 40, 41, 42, 43, 44, 45, 46, 47,
221+
55, 56, 57, 58, 59, 60, 61, 62, 63,
222+
71, 72, 73, 74, 75, 76, 77, 78, 79,
223+
87, 88, 89, 90, 91, 92, 93, 94, 95,
224+
103, 104, 105, 106, 107, 108, 109, 110, 111,
225+
119, 120, 121, 122, 123, 124, 125, 126, 127,
226+
},
227+
.oobfree = {
228+
{.offset = 2, .length = 4},
229+
{.offset = 16, .length = 7},
230+
{.offset = 32, .length = 7},
231+
{.offset = 48, .length = 7},
232+
{.offset = 64, .length = 7},
233+
{.offset = 80, .length = 7},
234+
{.offset = 96, .length = 7},
235+
{.offset = 112, .length = 7},
236+
}
237+
};
238+
214239
#ifdef CONFIG_MTD_PARTITIONS
215240
static const char *part_probes[] = { "RedBoot", "cmdlinepart", NULL };
216241
#endif
@@ -1186,6 +1211,8 @@ static int __init mxcnd_probe(struct platform_device *pdev)
11861211

11871212
if (mtd->writesize == 2048)
11881213
this->ecc.layout = oob_largepage;
1214+
if (nfc_is_v21() && mtd->writesize == 4096)
1215+
this->ecc.layout = &nandv2_hw_eccoob_4k;
11891216

11901217
/* second phase scan */
11911218
if (nand_scan_tail(mtd)) {

0 commit comments

Comments
 (0)