diff mbox series

[1/2] mtd: add flash_erase_sector

Message ID 20210809093303.28103-1-sbabic@denx.de
State Changes Requested
Headers show
Series [1/2] mtd: add flash_erase_sector | expand

Commit Message

Stefano Babic Aug. 9, 2021, 9:33 a.m. UTC
This is used to erase just a part of the flash and reuse the code of
flash_erase.

Signed-off-by: Stefano Babic <sbabic@denx.de>
---
 corelib/mtd-interface.c | 10 +++++++---
 include/flash.h         |  1 +
 2 files changed, 8 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/corelib/mtd-interface.c b/corelib/mtd-interface.c
index 1e6267e..100bda7 100644
--- a/corelib/mtd-interface.c
+++ b/corelib/mtd-interface.c
@@ -28,7 +28,7 @@  static char mtd_ubi_blacklist[100] = { 0 };
  */
 #define EMPTY_BYTE	0xFF
 
-int flash_erase(int mtdnum)
+int flash_erase_sector(int mtdnum, off_t start, size_t size)
 {
 	int fd;
 	char mtd_device[80];
@@ -62,8 +62,8 @@  int flash_erase(int mtdnum)
 		return -ENOMEM;
 	}
 
-	eb_start = 0;
-	eb_cnt = (mtd->size / mtd->eb_size) - eb_start;
+	eb_start = start;
+	eb_cnt = ((size ? size : mtd->size) / mtd->eb_size) - eb_start;
 	for (eb = 0; eb < eb_start + eb_cnt; eb++) {
 
 		/* Always skip bad sectors */
@@ -134,6 +134,10 @@  erase_out:
 	return ret;
 }
 
+int flash_erase(int mtdnum)
+{
+	return flash_erase_sector(mtdnum, 0, 0);
+}
 
 void mtd_init(void)
 {
diff --git a/include/flash.h b/include/flash.h
index 3894845..3f73079 100644
--- a/include/flash.h
+++ b/include/flash.h
@@ -52,6 +52,7 @@  void mtd_cleanup (void);
 int get_mtd_from_device(char *s);
 int get_mtd_from_name(const char *s);
 int flash_erase(int mtdnum);
+int flash_erase_sector(int mtdnum, off_t start, size_t size);
 
 struct flash_description *get_flash_info(void);
 #define isNand(flash, index) \