ath79: mikrotik: erase firmware on SPI NOR before install
[openwrt/openwrt.git] / target / linux / bcm63xx / patches-5.4 / 022-v5.8-mtd-rawnand-brcmnand-correctly-verify-erased-pages.patch
1 From dcb351c03f2fa6a599de1061b174167e03ee312b Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= <noltari@gmail.com>
3 Date: Tue, 12 May 2020 10:24:51 +0200
4 Subject: [PATCH] mtd: rawnand: brcmnand: correctly verify erased pages
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 The current code checks that the whole OOB area is erased.
10 This is a problem when JFFS2 cleanmarkers are added to the OOB, since it will
11 fail due to the usable OOB bytes not being 0xff.
12 Correct this by only checking that data and ECC bytes aren't 0xff.
13
14 Fixes: 02b88eea9f9c ("mtd: brcmnand: Add check for erased page bitflips")
15 Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
16 Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
17 Link: https://lore.kernel.org/linux-mtd/20200512082451.771212-1-noltari@gmail.com
18 ---
19 drivers/mtd/nand/raw/brcmnand/brcmnand.c | 19 +++++++++++--------
20 1 file changed, 11 insertions(+), 8 deletions(-)
21
22 --- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c
23 +++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
24 @@ -1787,28 +1787,31 @@ static int brcmnand_read_by_pio(struct m
25 static int brcmstb_nand_verify_erased_page(struct mtd_info *mtd,
26 struct nand_chip *chip, void *buf, u64 addr)
27 {
28 - int i, sas;
29 - void *oob = chip->oob_poi;
30 + struct mtd_oob_region ecc;
31 + int i;
32 int bitflips = 0;
33 int page = addr >> chip->page_shift;
34 int ret;
35 + void *ecc_bytes;
36 void *ecc_chunk;
37
38 if (!buf)
39 buf = nand_get_data_buf(chip);
40
41 - sas = mtd->oobsize / chip->ecc.steps;
42 -
43 /* read without ecc for verification */
44 ret = chip->ecc.read_page_raw(chip, buf, true, page);
45 if (ret)
46 return ret;
47
48 - for (i = 0; i < chip->ecc.steps; i++, oob += sas) {
49 + for (i = 0; i < chip->ecc.steps; i++) {
50 ecc_chunk = buf + chip->ecc.size * i;
51 - ret = nand_check_erased_ecc_chunk(ecc_chunk,
52 - chip->ecc.size,
53 - oob, sas, NULL, 0,
54 +
55 + mtd_ooblayout_ecc(mtd, i, &ecc);
56 + ecc_bytes = chip->oob_poi + ecc.offset;
57 +
58 + ret = nand_check_erased_ecc_chunk(ecc_chunk, chip->ecc.size,
59 + ecc_bytes, ecc.length,
60 + NULL, 0,
61 chip->ecc.strength);
62 if (ret < 0)
63 return ret;