diff options
author | Mathias Kresin <dev@kresin.me> | 2018-07-08 01:47:28 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2018-12-18 09:50:51 +0100 |
commit | e6945262642a3c83c4f9593286e0c7b794c211f0 (patch) | |
tree | 24fdee144e6113c4026fdc5d2a2caa7ae92cb9ef /target | |
parent | edc2af2be931c43a1ee111800737b08bacc60126 (diff) | |
download | upstream-e6945262642a3c83c4f9593286e0c7b794c211f0.tar.gz upstream-e6945262642a3c83c4f9593286e0c7b794c211f0.tar.bz2 upstream-e6945262642a3c83c4f9593286e0c7b794c211f0.zip |
kernel: handle bad blocks in ubi auto attach code
The first block(s) of the ubi mtd device might be bad. We need to take
care on our own to skip the bad block(s) and read the next one(s).
Don't treat recoverable read errors as fatal and check for the UBI magic
if the data of a block could be recovered using ECC or similar.
Signed-off-by: Mathias Kresin <dev@kresin.me>
(backported from 0ac91d82ed4d077150db902eb12d383c2be44fb2)
(rebased patches)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'target')
2 files changed, 36 insertions, 8 deletions
diff --git a/target/linux/generic/pending-4.14/490-ubi-auto-attach-mtd-device-named-ubi-or-data-on-boot.patch b/target/linux/generic/pending-4.14/490-ubi-auto-attach-mtd-device-named-ubi-or-data-on-boot.patch index 89bac64830..ff3490bf9e 100644 --- a/target/linux/generic/pending-4.14/490-ubi-auto-attach-mtd-device-named-ubi-or-data-on-boot.patch +++ b/target/linux/generic/pending-4.14/490-ubi-auto-attach-mtd-device-named-ubi-or-data-on-boot.patch @@ -8,7 +8,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org> --- a/drivers/mtd/ubi/build.c +++ b/drivers/mtd/ubi/build.c -@@ -1172,6 +1172,54 @@ static struct mtd_info * __init open_mtd +@@ -1172,6 +1172,68 @@ static struct mtd_info * __init open_mtd return mtd; } @@ -20,6 +20,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org> +{ + int err; + struct mtd_info *mtd; ++ loff_t offset = 0; + size_t len; + char magic[4]; + @@ -31,9 +32,22 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org> + if (IS_ERR(mtd)) + return; + ++ /* get the first not bad block */ ++ if (mtd_can_have_bb(mtd)) ++ while (mtd_block_isbad(mtd, offset)) { ++ offset += mtd->erasesize; ++ ++ if (offset > mtd->size) { ++ pr_err("UBI error: Failed to find a non-bad " ++ "block on mtd%d\n", mtd->index); ++ goto cleanup; ++ } ++ } ++ + /* check for a valid ubi magic if read from flash was successful */ -+ err = mtd_read(mtd, 0, 4, &len, (void *) magic); -+ if (!err && len == 4 && strncmp(magic, "UBI#", 4)) { ++ err = mtd_read(mtd, offset, 4, &len, (void *) magic); ++ if ((!err || mtd_is_bitflip(err)) && ++ len == 4 && strncmp(magic, "UBI#", 4)) { + pr_err("UBI error: no valid UBI magic found inside mtd%d\n", mtd->index); + goto cleanup; + } @@ -63,7 +77,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org> static int __init ubi_init(void) { int err, i, k; -@@ -1255,6 +1303,12 @@ static int __init ubi_init(void) +@@ -1255,6 +1317,12 @@ static int __init ubi_init(void) } } diff --git a/target/linux/generic/pending-4.9/490-ubi-auto-attach-mtd-device-named-ubi-or-data-on-boot.patch b/target/linux/generic/pending-4.9/490-ubi-auto-attach-mtd-device-named-ubi-or-data-on-boot.patch index 1436e486dd..8b923d17d6 100644 --- a/target/linux/generic/pending-4.9/490-ubi-auto-attach-mtd-device-named-ubi-or-data-on-boot.patch +++ b/target/linux/generic/pending-4.9/490-ubi-auto-attach-mtd-device-named-ubi-or-data-on-boot.patch @@ -8,7 +8,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org> --- a/drivers/mtd/ubi/build.c +++ b/drivers/mtd/ubi/build.c -@@ -1226,6 +1226,54 @@ static struct mtd_info * __init open_mtd +@@ -1226,6 +1226,68 @@ static struct mtd_info * __init open_mtd return mtd; } @@ -20,6 +20,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org> +{ + int err; + struct mtd_info *mtd; ++ loff_t offset = 0; + size_t len; + char magic[4]; + @@ -31,9 +32,22 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org> + if (IS_ERR(mtd)) + return; + ++ /* get the first not bad block */ ++ if (mtd_can_have_bb(mtd)) ++ while (mtd_block_isbad(mtd, offset)) { ++ offset += mtd->erasesize; ++ ++ if (offset > mtd->size) { ++ pr_err("UBI error: Failed to find a non-bad " ++ "block on mtd%d\n", mtd->index); ++ goto cleanup; ++ } ++ } ++ + /* check for a valid ubi magic if read from flash was successful */ -+ err = mtd_read(mtd, 0, 4, &len, (void *) magic); -+ if (!err && len == 4 && strncmp(magic, "UBI#", 4)) { ++ err = mtd_read(mtd, offset, 4, &len, (void *) magic); ++ if ((!err || mtd_is_bitflip(err)) && ++ len == 4 && strncmp(magic, "UBI#", 4)) { + pr_err("UBI error: no valid UBI magic found inside mtd%d\n", mtd->index); + goto cleanup; + } @@ -63,7 +77,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org> static int __init ubi_init(void) { int err, i, k; -@@ -1309,6 +1357,12 @@ static int __init ubi_init(void) +@@ -1309,6 +1371,12 @@ static int __init ubi_init(void) } } |