From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 1/2] mtd: peb: Add function to test for an empty block
Date: Fri, 12 Apr 2019 10:20:27 +0200 [thread overview]
Message-ID: <20190412082028.6195-1-s.hauer@pengutronix.de> (raw)
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@pengutronix.de>
---
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@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next reply other threads:[~2019-04-12 8:20 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-12 8:20 Sascha Hauer [this message]
2019-04-12 8:20 ` [PATCH 2/2] ARM: i.MX: create i.MX25 internal Nand update handler Sascha Hauer
2019-04-12 9:46 ` [PATCH 1/2] mtd: peb: Add function to test for an empty block Roland Hieber
2019-04-12 10:02 ` 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=20190412082028.6195-1-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