Skip to contentSkip to conversation

Add full flash erase support in mtd-utils

PATCH New Larisa Ileana Grigore 3 participants 4 messages Apr 23, 2021 – May 5, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add full flash erase support in mtd-utils

Some flash types support full erase chip command but there was no support for it in mtd-utils. The full erase chip command can reduce the flash erase time significantly. The patch will try first to erase the entire flash and fall back to the old method if the operation fails.

Larisa Ileana Grigore (1):
mtd-utils: flash_erase: Add flash erase chip

 include/libmtd.h         | 15 +++++++
 lib/libmtd.c             | 26 ++++++++---
 misc-utils/flash_erase.c | 95 ++++++++++++++++++++++++++++++----------
 3 files changed, 106 insertions(+), 30 deletions(-)
Signature · 6 lines
2.17.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
#1 lore raw

PATCH 1/1 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.

---
 include/libmtd.h         | 15 +++++++
 lib/libmtd.c             | 26 ++++++++---
 misc-utils/flash_erase.c | 95 ++++++++++++++++++++++++++++++----------
 3 files changed, 106 insertions(+), 30 deletions(-)
include/libmtd.h +15 -0
index cc24af8..6ab0de5 100644
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2008, 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
@@ -174,6 +175,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_unlock_multi - unlock eraseblocks.
+ * @desc: MTD library descriptor
+ * @mtd: MTD device description object
+ * @fd: MTD device node file descriptor
+ * @eb: index of first eraseblock to unlock
+ * @blocks: the number of eraseblocks to unlock
+ *
+ * This function unlocks @blocks starting at eraseblock @eb.
+ * Returns %0 in case of success and %-1 in case of failure.
+ */
+int mtd_unlock_multi(const struct mtd_dev_info *mtd, int fd, int eb,
+		     int blocks);
+
 /**
  * mtd_erase - erase multiple eraseblocks.
  * @desc: MTD library descriptor
lib/libmtd.c +20 -6
index 9d8d0e8..c1022cf 100644
@@ -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
@@ -831,8 +832,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;
@@ -841,8 +842,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)
@@ -850,16 +857,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,
misc-utils/flash_erase.c +71 -24

140 lines not on this page · raw message

Signature · 6 lines
2.17.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
#2 lore raw

Re: [PATCH 1/1] mtd-utils: flash_erase: Add flash erase chip

Hi,

Am 2021-04-23 17:07, schrieb Larisa Ileana Grigore:

Quoted 16 lines

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.

---
 include/libmtd.h         | 15 +++++++
 lib/libmtd.c             | 26 ++++++++---
 misc-utils/flash_erase.c | 95 ++++++++++++++++++++++++++++++----------
 3 files changed, 106 insertions(+), 30 deletions(-)
include/libmtd.h +0 -0
index cc24af8..6ab0de5 100644

include/libmtd.h line 3

Quoted 3 lines
include/libmtd.h +1 -0
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2008, 2009 Nokia Corporation
+ * Copyright 2021 NXP

really? because of one prototype?

Just out of curiousity, is there any incentive that you NXP guys add these copyrights all over the place, even for one line changes.

Quoted 14 lines
include/libmtd.h +0 -0
  *
  * 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

include/libmtd.h +4 -0
@@ -174,6 +175,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_unlock_multi - unlock eraseblocks.
+ * @desc: MTD library descriptor
+ * @mtd: MTD device description object

include/libmtd.h int mtd_lock(const struct mtd_dev_info *mtd, int · line 192

Quoted 10 lines
include/libmtd.h +10 -0
+ * @fd: MTD device node file descriptor
+ * @eb: index of first eraseblock to unlock
+ * @blocks: the number of eraseblocks to unlock
+ *
+ * This function unlocks @blocks starting at eraseblock @eb.
+ * Returns %0 in case of success and %-1 in case of failure.
+ */
+int mtd_unlock_multi(const struct mtd_dev_info *mtd, int fd, int eb,
+		     int blocks);
+

-michael

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/