mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 12/16] mtd: ubi: Use mtd_peb_torture
Date: Tue, 15 Mar 2016 12:15:30 +0100	[thread overview]
Message-ID: <1458040534-6171-13-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1458040534-6171-1-git-send-email-s.hauer@pengutronix.de>

The mtd-peb API provides a torture test derived from the UBI torture
test. Use it. Since the mtd-peb variant of the torture test will also
mark a block as bad when the test fails this also makes a separate
ubi_io_mark_bad unnecessary.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mtd/ubi/io.c  | 115 +++-----------------------------------------------
 drivers/mtd/ubi/ubi.h |   1 -
 drivers/mtd/ubi/wl.c  |   5 ---
 3 files changed, 5 insertions(+), 116 deletions(-)

diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c
index 4495996..4031253 100644
--- a/drivers/mtd/ubi/io.c
+++ b/drivers/mtd/ubi/io.c
@@ -376,82 +376,6 @@ retry:
 	return 0;
 }
 
-/* Patterns to write to a physical eraseblock when torturing it */
-static uint8_t patterns[] = {0xa5, 0x5a, 0x0};
-
-/**
- * torture_peb - test a supposedly bad physical eraseblock.
- * @ubi: UBI device description object
- * @pnum: the physical eraseblock number to test
- *
- * This function returns %-EIO if the physical eraseblock did not pass the
- * test, a positive number of erase operations done if the test was
- * successfully passed, and other negative error codes in case of other errors.
- */
-static int torture_peb(struct ubi_device *ubi, int pnum)
-{
-	int err, i, patt_count;
-
-	ubi_msg("run torture test for PEB %d", pnum);
-	patt_count = ARRAY_SIZE(patterns);
-	ubi_assert(patt_count > 0);
-
-	for (i = 0; i < patt_count; i++) {
-		err = do_sync_erase(ubi, pnum);
-		if (err)
-			goto out;
-
-		/* Make sure the PEB contains only 0xFF bytes */
-		err = ubi_io_read(ubi, ubi->peb_buf, pnum, 0, ubi->peb_size);
-		if (err)
-			goto out;
-
-		err = mtd_buf_all_ff(ubi->peb_buf, ubi->peb_size);
-		if (err == 0) {
-			ubi_err("erased PEB %d, but a non-0xFF byte found",
-				pnum);
-			err = -EIO;
-			goto out;
-		}
-
-		/* Write a pattern and check it */
-		memset(ubi->peb_buf, patterns[i], ubi->peb_size);
-		err = ubi_io_write(ubi, ubi->peb_buf, pnum, 0, ubi->peb_size);
-		if (err)
-			goto out;
-
-		memset(ubi->peb_buf, ~patterns[i], ubi->peb_size);
-		err = ubi_io_read(ubi, ubi->peb_buf, pnum, 0, ubi->peb_size);
-		if (err)
-			goto out;
-
-		err = mtd_buf_check_pattern(ubi->peb_buf, patterns[i],
-					ubi->peb_size);
-		if (err == 0) {
-			ubi_err("pattern %x checking failed for PEB %d",
-				patterns[i], pnum);
-			err = -EIO;
-			goto out;
-		}
-	}
-
-	err = patt_count;
-	ubi_msg("PEB %d passed torture test, do not mark it as bad", pnum);
-
-out:
-	if (err == UBI_IO_BITFLIPS || mtd_is_eccerr(err)) {
-		/*
-		 * If a bit-flip or data integrity error was detected, the test
-		 * has not passed because it happened on a freshly erased
-		 * physical eraseblock which means something is wrong with it.
-		 */
-		ubi_err("read problems on freshly erased PEB %d, must be bad",
-			pnum);
-		err = -EIO;
-	}
-	return err;
-}
-
 /**
  * nor_erase_prepare - prepare a NOR flash PEB for erasure.
  * @ubi: UBI device description object
@@ -564,15 +488,15 @@ int ubi_io_sync_erase(struct ubi_device *ubi, int pnum, int torture)
 	}
 
 	if (torture) {
-		ret = torture_peb(ubi, pnum);
+		ret = mtd_peb_torture(ubi->mtd, pnum);
 		if (ret < 0)
 			return ret;
+	} else {
+		err = do_sync_erase(ubi, pnum);
+		if (err)
+			return err;
 	}
 
-	err = do_sync_erase(ubi, pnum);
-	if (err)
-		return err;
-
 	return ret + 1;
 }
 
@@ -606,35 +530,6 @@ 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("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("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 577b35d..03a36d2 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -799,7 +799,6 @@ 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 4c20e90..cb2f9d7 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -1421,11 +1421,6 @@ static int erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk,
 		available_consumed = 1;
 	}
 
-	ubi_msg("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) {
 			/*
-- 
2.7.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2016-03-15 11:16 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-15 11:15 Introduce mtd-peb API Sascha Hauer
2016-03-15 11:15 ` [PATCH 01/16] mtd: Add support for marking blocks as good Sascha Hauer
2016-03-15 11:15 ` [PATCH 02/16] mtd: nand: Add option to print bbt in nand command Sascha Hauer
2016-03-15 11:15 ` [PATCH 03/16] mtd: mtdpart: Add oob_read function Sascha Hauer
2016-03-15 11:15 ` [PATCH 04/16] mtd: Introduce function to get mtd type string Sascha Hauer
2016-03-15 11:15 ` [PATCH 05/16] mtd: rename mtd_all_ff -> mtd_buf_all_ff Sascha Hauer
2016-03-15 11:15 ` [PATCH 06/16] mtd: Introduce mtd_check_pattern Sascha Hauer
2016-03-15 11:15 ` [PATCH 07/16] mtd: Introduce mtd-peb API Sascha Hauer
2016-03-15 11:15 ` [PATCH 08/16] ubiformat: Use " Sascha Hauer
2016-03-15 11:15 ` [PATCH 09/16] remove now unused libmtd Sascha Hauer
2016-03-15 11:15 ` [PATCH 10/16] mtd: ubi: Use mtd_all_ff/mtd_check_pattern Sascha Hauer
2016-03-15 11:15 ` [PATCH 11/16] mtd: ubi: Use mtd_peb_check_all_ff Sascha Hauer
2016-03-15 11:15 ` Sascha Hauer [this message]
2016-03-15 11:15 ` [PATCH 13/16] mtd: ubi: Use mtd_peb_read Sascha Hauer
2016-03-15 11:15 ` [PATCH 14/16] mtd: ubi: Use mtd_peb_write Sascha Hauer
2016-03-15 11:15 ` [PATCH 15/16] mtd: ubi: Use mtd_peb_erase Sascha Hauer
2016-03-15 11:15 ` [PATCH 16/16] mtd: ubi: Make debug options configurable Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1458040534-6171-13-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox