diff mbox series

[V3] : Allow flash updates to proceed without decompressed-size set

Message ID 889d91ef08604e9fb6d94ef82679fa92@kumkeo.de
State Accepted
Headers show
Series [V3] : Allow flash updates to proceed without decompressed-size set | expand

Commit Message

Ulrich Teichert Nov. 7, 2023, 4:30 p.m. UTC
For backward compatibility, allow flash updates to proceed without the
decompression-size property set. In that case, the flash device is erased
from the offset until its end.

Signed-off-by: Ulrich Teichert <ulrich.teichert@kumkeo.de>

---


Mit freundlichen Grüßen / Kind regards

Dipl.-Inform. Ulrich Teichert
Senior Software Developer

kumkeo GmbH
Heidenkampsweg 82a
20097 Hamburg
Germany

T: +49 40 2846761-0
F: +49 40 2846761-99

ulrich.teichert@kumkeo.de
www.kumkeo.de

Amtsgericht Hamburg / Hamburg District Court, HRB 108558
Geschäftsführer / Managing Director: Dipl.-Ing. Bernd Sager; Dipl.-Ing. Sven Tanneberger, MBA
diff mbox series

Patch

diff --git a/corelib/mtd-interface.c b/corelib/mtd-interface.c
index 22e86bd..5d9e708 100644
--- a/corelib/mtd-interface.c
+++ b/corelib/mtd-interface.c
@@ -217,6 +217,20 @@  int get_mtd_from_name(const char *s)
        return -1;
 }

+long long get_mtd_size(int mtdnum)
+{
+       struct flash_description *flash = get_flash_info();
+       struct mtd_dev_info dev_info;
+
+       int err = mtd_get_dev_info1(flash->libmtd, mtdnum, &dev_info);
+       if (err != 0) {
+               ERROR("Could not get MTD %d info: %d, %d", mtdnum, err, errno);
+               return -ENODEV;
+       }
+
+       return dev_info.size;
+}
+
 void ubi_init(void)
 {
        struct flash_description *nand = get_flash_info();
diff --git a/handlers/flash_handler.c b/handlers/flash_handler.c
index 3cca02b..2ede6e3 100644
--- a/handlers/flash_handler.c
+++ b/handlers/flash_handler.c
@@ -310,8 +310,14 @@  static int flash_write_nor(int mtdnum, struct img_type *img)

        long long size = get_output_size(img, true);
        if (size < 0) {
-               ERROR("Failed to determine output size, bailing out.");
-               return -1;
+               size = get_mtd_size(mtdnum);
+               if (size < 0) {
+                       ERROR("Could not get MTD %d device size", mtdnum);
+                       return -ENODEV;
+               }
+
+               WARN("decompression-size not set, erasing flash device %s from %lld to %lld",
+                       img->device, img->seek, size);
        }
        if (flash_erase_sector(mtdnum, img->seek, size)) {
                ERROR("Failed to erase sectors on /dev/mtd%d (start: %llu, size: %lld)",
diff --git a/include/flash.h b/include/flash.h
index 9a055a7..69a0e99 100644
--- a/include/flash.h
+++ b/include/flash.h
@@ -50,6 +50,7 @@  int scan_mtd_devices (void);
 void mtd_cleanup (void);
 int get_mtd_from_device(char *s);
 int get_mtd_from_name(const char *s);
+long long get_mtd_size(int mtdnum);
 int flash_erase(int mtdnum);
 int flash_erase_sector(int mtdnum, off_t start, size_t size);