@@ -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();
@@ -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)",
@@ -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);
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