tools/mktplinkfw2: show exact exceed bytes when the image is to big
authorAlexander Couzens <lynxis@fe80.eu>
Tue, 9 Apr 2019 17:03:34 +0000 (19:03 +0200)
committerAlexander Couzens <lynxis@fe80.eu>
Mon, 5 Aug 2019 12:01:59 +0000 (14:01 +0200)
When an image is too big it's useful to show how many bytes the image
is to big.

Signed-off-by: Alexander Couzens <lynxis@fe80.eu>
tools/firmware-utils/src/mktplinkfw2.c

index 9eb226fba83f25894fbe73185ee66557a8529498..b32996890c324072db8bf7cbea405d9f29294f4a 100644 (file)
@@ -216,6 +216,7 @@ static void usage(int status)
 static int check_options(void)
 {
        int ret;
+       int exceed_bytes;
 
        if (inspect_info.file_name) {
                ret = get_file_stat(&inspect_info);
@@ -309,21 +310,24 @@ static int check_options(void)
 
                        DBG("rootfs offset aligned to 0x%u", rootfs_ofs);
 
-                       if (kernel_len + rootfs_info.file_size >
-                           layout->fw_max_len - sizeof(struct fw_header)) {
-                               ERR("images are too big");
+                       exceed_bytes = (kernel_len + rootfs_info.file_size) -
+                               (layout->fw_max_len - sizeof(struct fw_header));
+                       if (exceed_bytes > 0) {
+                               ERR("images are too big by %i bytes", exceed_bytes);
                                return -1;
                        }
                } else {
-                       if (kernel_info.file_size >
-                           rootfs_ofs - sizeof(struct fw_header)) {
-                               ERR("kernel image is too big");
+                       exceed_bytes = kernel_info.file_size -
+                               (rootfs_ofs - sizeof(struct fw_header));
+                       if (exceed_bytes > 0) {
+                               ERR("images are too big by %i bytes", exceed_bytes);
                                return -1;
                        }
 
-                       if (rootfs_info.file_size >
-                           (layout->fw_max_len - rootfs_ofs)) {
-                               ERR("rootfs image is too big");
+                       exceed_bytes = rootfs_info.file_size -
+                               (layout->fw_max_len - rootfs_ofs);
+                       if (exceed_bytes > 0) {
+                               ERR("images are too big by %i bytes", exceed_bytes);
                                return -1;
                        }
                }