diff mbox series

[V2,2/2] flash: allow to erase just a part of device

Message ID 20210826114908.330246-2-sbabic@denx.de
State Accepted
Headers show
Series [V2,1/2] mtd: add flash_erase_sector | expand

Commit Message

Stefano Babic Aug. 26, 2021, 11:49 a.m. UTC
Signed-off-by: Stefano Babic <sbabic@denx.de>
---

Changes since V1:
	- fix coverity issue introduced by patch

 handlers/flash_handler.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/handlers/flash_handler.c b/handlers/flash_handler.c
index c5a5d3a..5c11ff6 100644
--- a/handlers/flash_handler.c
+++ b/handlers/flash_handler.c
@@ -119,6 +119,12 @@  static int flash_write_nand(int mtdnum, struct img_type *img)
 		return -EINVAL;
 	}
 
+	if(flash_erase_sector(mtdnum, img->offset, img->size)) {
+		ERROR("I cannot erasing %s",
+			img->device);
+		return -1;
+	}
+
 	if ((fd = open(mtd_device, O_RDWR)) < 0) {
 		ERROR( "%s: %s: %s", __func__, mtd_device, strerror(errno));
 		return -ENODEV;
@@ -295,6 +301,12 @@  static int flash_write_nor(int mtdnum, struct img_type *img)
 		return -ENODEV;
 	}
 
+	if(flash_erase_sector(mtdnum, img->offset, img->size)) {
+		ERROR("I cannot erasing %s",
+			img->device);
+		return -1;
+	}
+
 	snprintf(mtd_device, sizeof(mtd_device), "/dev/mtd%d", mtdnum);
 	if ((fdout = open(mtd_device, O_RDWR)) < 0) {
 		ERROR( "%s: %s: %s", __func__, mtd_device, strerror(errno));
@@ -337,11 +349,6 @@  static int install_flash_image(struct img_type *img,
 		return -1;
 	}
 
-	if(flash_erase(mtdnum)) {
-		ERROR("I cannot erasing %s",
-			img->device);
-		return -1;
-	}
 	TRACE("Copying %s into /dev/mtd%d", img->fname, mtdnum);
 	if (flash_write_image(mtdnum, img)) {
 		ERROR("I cannot copy %s into %s partition",