[PATCH 1/2] mtd: peb: Add function to test for an empty block

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



FIXME: Why does this use raw accesses? The test for 16 bitflips
is arbitrary, do this properly. Only a single page of a whole
block is tested, this has at least to be documented.

Signed-off-by: Sascha Hauer <s.hauer@xxxxxxxxxxxxxx>
---
 drivers/mtd/peb.c     | 32 ++++++++++++++++++++++++++++++++
 include/mtd/mtd-peb.h |  1 +
 2 files changed, 33 insertions(+)

diff --git a/drivers/mtd/peb.c b/drivers/mtd/peb.c
index 388db7f587..d9da4797b0 100644
--- a/drivers/mtd/peb.c
+++ b/drivers/mtd/peb.c
@@ -15,6 +15,7 @@
 #include <init.h>
 #include <magicvar.h>
 #include <globalvar.h>
+#include <linux/mtd/nand.h>
 #include <linux/mtd/mtd.h>
 #include <mtd/mtd-peb.h>
 #include <linux/err.h>
@@ -562,6 +563,37 @@ out:
 	return err;
 }
 
+int mtd_peb_is_empty(struct mtd_info *mtd, int block)
+{
+	struct mtd_oob_ops ops;
+	int rawsize = mtd->writesize + mtd->oobsize;
+	void *rawpage = xmalloc(rawsize);
+	int ret;
+	loff_t offset = (loff_t)block * mtd->erasesize;
+
+	ops.mode = MTD_OPS_RAW;
+	ops.ooboffs = 0;
+	ops.datbuf = rawpage;
+	ops.len = mtd->writesize;
+	ops.oobbuf = rawpage + mtd->writesize;
+	ops.ooblen = mtd->oobsize;
+
+	ret = mtd_read_oob(mtd, offset, &ops);
+	if (ret)
+		goto err;
+
+	ret = nand_check_erased_buf(rawpage, rawsize, 16);
+
+	if (ret == -EBADMSG)
+		ret = 0;
+	else if (ret >= 0)
+		ret = 1;
+
+err:
+	free(rawpage);
+	return ret;
+}
+
 /**
  * mtd_peb_create_bitflips - create bitflips on Nand pages
  * @mtd: mtd device
diff --git a/include/mtd/mtd-peb.h b/include/mtd/mtd-peb.h
index 23f89d89a8..6d862499aa 100644
--- a/include/mtd/mtd-peb.h
+++ b/include/mtd/mtd-peb.h
@@ -18,6 +18,7 @@ int mtd_peb_check_all_ff(struct mtd_info *mtd, int pnum, int offset, int len,
 int mtd_peb_verify(struct mtd_info *mtd, const void *buf, int pnum,
 				int offset, int len);
 int mtd_num_pebs(struct mtd_info *mtd);
+int mtd_peb_is_empty(struct mtd_info *mtd, int block);
 int mtd_peb_create_bitflips(struct mtd_info *mtd, int pnum, int offset,
 				   int len, int num_bitflips, int random,
 				   int info);
-- 
2.20.1


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



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux