aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2016-04-26 00:13:23 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2016-11-17 11:36:55 +0100
commit5d524111adc549ec80e577dd3d9045a4c589fa7b (patch)
tree413e9b4560af154d29589f335a96a35304015977
parent3516b8b7558a69dfd06410b0c997d096a78221c9 (diff)
mtd-utils: Add multi-block erase function
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at> Signed-off-by: Richard Weinberger <richard@nod.at>
-rw-r--r--include/libmtd.h14
-rw-r--r--lib/libmtd.c14
2 files changed, 26 insertions, 2 deletions
diff --git a/include/libmtd.h b/include/libmtd.h
index a6ff050..f9f3164 100644
--- a/include/libmtd.h
+++ b/include/libmtd.h
@@ -174,6 +174,20 @@ int mtd_lock(const struct mtd_dev_info *mtd, int fd, int eb);
int mtd_unlock(const struct mtd_dev_info *mtd, int fd, int eb);
/**
+ * mtd_erase - erase multiple eraseblocks.
+ * @desc: MTD library descriptor
+ * @mtd: MTD device description object
+ * @fd: MTD device node file descriptor
+ * @eb: index of first eraseblock to erase
+ * @blocks: the number of eraseblocks to erase
+ *
+ * This function erases @blocks starting at eraseblock @eb of MTD device
+ * described by @fd. Returns %0 in case of success and %-1 in case of failure.
+ */
+int mtd_erase_multi(libmtd_t desc, const struct mtd_dev_info *mtd,
+ int fd, int eb, int blocks);
+
+/**
* mtd_erase - erase an eraseblock.
* @desc: MTD library descriptor
* @mtd: MTD device description object
diff --git a/lib/libmtd.c b/lib/libmtd.c
index 1d162c7..ff11806 100644
--- a/lib/libmtd.c
+++ b/lib/libmtd.c
@@ -845,7 +845,8 @@ int mtd_unlock(const struct mtd_dev_info *mtd, int fd, int eb)
return mtd_xlock(mtd, fd, eb, MEMUNLOCK);
}
-int mtd_erase(libmtd_t desc, const struct mtd_dev_info *mtd, int fd, int eb)
+int mtd_erase_multi(libmtd_t desc, const struct mtd_dev_info *mtd,
+ int fd, int eb, int blocks)
{
int ret;
struct libmtd *lib = (struct libmtd *)desc;
@@ -856,8 +857,12 @@ int mtd_erase(libmtd_t desc, const struct mtd_dev_info *mtd, int fd, int eb)
if (ret)
return ret;
+ ret = mtd_valid_erase_block(mtd, eb + blocks - 1);
+ if (ret)
+ return ret;
+
ei64.start = (__u64)eb * mtd->eb_size;
- ei64.length = mtd->eb_size;
+ ei64.length = (__u64)mtd->eb_size * blocks;
if (lib->offs64_ioctls == OFFS64_IOCTLS_SUPPORTED ||
lib->offs64_ioctls == OFFS64_IOCTLS_UNKNOWN) {
@@ -892,6 +897,11 @@ int mtd_erase(libmtd_t desc, const struct mtd_dev_info *mtd, int fd, int eb)
return 0;
}
+int mtd_erase(libmtd_t desc, const struct mtd_dev_info *mtd, int fd, int eb)
+{
+ return mtd_erase_multi(desc, mtd, fd, eb, 1);
+}
+
int mtd_regioninfo(int fd, int regidx, struct region_info_user *reginfo)
{
int ret;