aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLarisa Ileana Grigore <larisa.grigore@nxp.com>2021-04-23 18:07:04 +0300
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2021-05-05 08:29:50 +0200
commit2ca0bbf296d6f7ce51b8255347c7fd08afa33651 (patch)
tree3eeaad477971d8bb1764c46be4b3f67e7e87afdb /lib
parent1709a628dfc8983f7718e978676cafc3c0399a70 (diff)
mtd-utils: flash_erase: Add flash erase chip
Some flash types support full erase chip command which can reduce the flash erase time. Try first to erase the entire flash and fall back to the old method if the operation fails. Signed-off-by: Larisa Ileana Grigore <larisa.grigore@nxp.com> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib')
-rw-r--r--lib/libmtd.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/lib/libmtd.c b/lib/libmtd.c
index b581d80..a363e56 100644
--- a/lib/libmtd.c
+++ b/lib/libmtd.c
@@ -1,6 +1,7 @@
/*
* Copyright (c) International Business Machines Corp., 2006
* Copyright (C) 2009 Nokia Corporation
+ * Copyright 2021 NXP
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -834,8 +835,8 @@ static int mtd_valid_erase_block(const struct mtd_dev_info *mtd, int eb)
return 0;
}
-static int mtd_xlock(const struct mtd_dev_info *mtd, int fd, int eb, int req,
- const char *sreq)
+static int mtd_xlock(const struct mtd_dev_info *mtd, int fd, int eb,
+ int blocks, int req, const char *sreq)
{
int ret;
struct erase_info_user ei;
@@ -844,8 +845,14 @@ static int mtd_xlock(const struct mtd_dev_info *mtd, int fd, int eb, int req,
if (ret)
return ret;
+ if (blocks > 1) {
+ ret = mtd_valid_erase_block(mtd, eb + blocks - 1);
+ if (ret)
+ return ret;
+ }
+
ei.start = eb * mtd->eb_size;
- ei.length = mtd->eb_size;
+ ei.length = mtd->eb_size * blocks;
ret = ioctl(fd, req, &ei);
if (ret < 0)
@@ -853,16 +860,23 @@ static int mtd_xlock(const struct mtd_dev_info *mtd, int fd, int eb, int req,
return 0;
}
-#define mtd_xlock(mtd, fd, eb, req) mtd_xlock(mtd, fd, eb, req, #req)
+#define mtd_xlock(mtd, fd, eb, blocks, req) \
+ mtd_xlock(mtd, fd, eb, blocks, req, #req)
int mtd_lock(const struct mtd_dev_info *mtd, int fd, int eb)
{
- return mtd_xlock(mtd, fd, eb, MEMLOCK);
+ return mtd_xlock(mtd, fd, eb, 1, MEMLOCK);
}
int mtd_unlock(const struct mtd_dev_info *mtd, int fd, int eb)
{
- return mtd_xlock(mtd, fd, eb, MEMUNLOCK);
+ return mtd_xlock(mtd, fd, eb, 1, MEMUNLOCK);
+}
+
+int mtd_unlock_multi(const struct mtd_dev_info *mtd, int fd, int eb,
+ int blocks)
+{
+ return mtd_xlock(mtd, fd, eb, blocks, MEMUNLOCK);
}
int mtd_erase_multi(libmtd_t desc, const struct mtd_dev_info *mtd,