summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2019-07-15 14:06:57 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2019-07-15 15:37:33 +0200
commit4c216abb0cf5da6f896298fa875cd7bb80dc76b9 (patch)
tree7c59d04bfdf573349e5db365998473854ad948c7
parenteb135abe5aa13190160ba45fcd5defdc573c24ba (diff)
downloadbarebox-4c216abb0cf5da6f896298fa875cd7bb80dc76b9.tar.gz
barebox-4c216abb0cf5da6f896298fa875cd7bb80dc76b9.tar.xz
mtd: ubi: mark PEBs as bad on erase failure
70542a9c65 converted UBI to use mtd_peb_torture(). It was assumed that a block was marked as bad when it didn't pass the torture test. However, not all possibly bad blocks went through the torture test, so it could happen that a block that could not be erased was still kept as good block. This patch fixes this and explicitly calls ubi_io_mark_bad() when a block cannot be erased. Fixes: 70542a9c65 ("mtd: ubi: Use mtd_peb_torture") Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--drivers/mtd/ubi/io.c29
-rw-r--r--drivers/mtd/ubi/ubi.h1
-rw-r--r--drivers/mtd/ubi/wl.c5
3 files changed, 35 insertions, 0 deletions
diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c
index d0ea23b124..78458b58e1 100644
--- a/drivers/mtd/ubi/io.c
+++ b/drivers/mtd/ubi/io.c
@@ -357,6 +357,35 @@ int ubi_io_is_bad(const struct ubi_device *ubi, int pnum)
}
/**
+ * ubi_io_mark_bad - mark a physical eraseblock as bad.
+ * @ubi: UBI device description object
+ * @pnum: the physical eraseblock number to mark
+ *
+ * This function returns zero in case of success and a negative error code in
+ * case of failure.
+ */
+int ubi_io_mark_bad(const struct ubi_device *ubi, int pnum)
+{
+ int err;
+ struct mtd_info *mtd = ubi->mtd;
+
+ ubi_assert(pnum >= 0 && pnum < ubi->peb_count);
+
+ if (ubi->ro_mode) {
+ ubi_err(ubi, "read-only mode");
+ return -EROFS;
+ }
+
+ if (!ubi->bad_allowed)
+ return 0;
+
+ err = mtd_block_markbad(mtd, (loff_t)pnum * ubi->peb_size);
+ if (err)
+ ubi_err(ubi, "cannot mark PEB %d bad, error %d", pnum, err);
+ return err;
+}
+
+/**
* validate_ec_hdr - validate an erase counter header.
* @ubi: UBI device description object
* @ec_hdr: the erase counter header to check
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
index b85d602055..922c1a3c8b 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -865,6 +865,7 @@ int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset,
int len);
int ubi_io_sync_erase(struct ubi_device *ubi, int pnum, int torture);
int ubi_io_is_bad(const struct ubi_device *ubi, int pnum);
+int ubi_io_mark_bad(const struct ubi_device *ubi, int pnum);
int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum,
struct ubi_ec_hdr *ec_hdr, int verbose);
int ubi_io_write_ec_hdr(struct ubi_device *ubi, int pnum,
diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index fa1b813702..cf90ecfb23 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -1085,6 +1085,11 @@ static int __erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk)
available_consumed = 1;
}
+ ubi_msg(ubi, "mark PEB %d as bad", pnum);
+ err = ubi_io_mark_bad(ubi, pnum);
+ if (err)
+ goto out_ro;
+
if (ubi->beb_rsvd_pebs > 0) {
if (available_consumed) {
/*