From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hErQF-0005yx-HI for barebox@lists.infradead.org; Fri, 12 Apr 2019 08:20:32 +0000 From: Sascha Hauer Date: Fri, 12 Apr 2019 10:20:27 +0200 Message-Id: <20190412082028.6195-1-s.hauer@pengutronix.de> MIME-Version: 1.0 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "barebox" Errors-To: barebox-bounces+u.kleine-koenig=pengutronix.de@lists.infradead.org Subject: [PATCH 1/2] mtd: peb: Add function to test for an empty block To: Barebox List 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 --- 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 #include #include +#include #include #include #include @@ -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