]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
bootm: improve error message when gzip decompression buffer is too small
authorAristo Chen <jj251510319013@gmail.com>
Wed, 30 Apr 2025 02:23:25 +0000 (10:23 +0800)
committerTom Rini <trini@konsulko.com>
Mon, 5 May 2025 20:16:57 +0000 (14:16 -0600)
Currently, when decompressing a gzip-compressed image during bootm, a
generic error such as "inflate() returned -5" is shown when the buffer is
too small. However, it is not immediately clear that this is caused by
CONFIG_SYS_BOOTM_LEN being too small.

This patch improves error handling by:
- Detecting Z_BUF_ERROR (-5) returned from the inflate() call
- Suggesting the user to increase CONFIG_SYS_BOOTM_LEN when applicable
- Preserving the original return code from zunzip() instead of overwriting
  it with -1

By providing clearer hints when decompression fails due to insufficient
buffer size, this change helps users diagnose and fix boot failures more
easily.

Signed-off-by: Aristo Chen <aristo.chen@canonical.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Mattijs Korpershoek <mkorpershoek@kernel.org>
boot/bootm.c
lib/gunzip.c

index f5cbb10f0d1aae2b62eec3e622de3645186fb2f0..f6aa32746b7e23653045dc13e3a6fc7ca8d6f3be 100644 (file)
@@ -34,6 +34,7 @@
 
 #include <bootm.h>
 #include <image.h>
+#include <u-boot/zlib.h>
 
 #define MAX_CMDLINE_SIZE       SZ_4K
 
@@ -578,7 +579,8 @@ static int handle_decomp_error(int comp_type, size_t uncomp_size,
        if (ret == -ENOSYS)
                return BOOTM_ERR_UNIMPLEMENTED;
 
-       if (uncomp_size >= buf_size)
+       if ((comp_type == IH_COMP_GZIP && ret == Z_BUF_ERROR) ||
+           uncomp_size >= buf_size)
                printf("Image too large: increase CONFIG_SYS_BOOTM_LEN\n");
        else
                printf("%s: uncompress error %d\n", name, ret);
index 52007715bda9ba49a6c7b0ede4a154c655811136..a05dcde9a757c774fb1f6da260bb27ef63351041 100644 (file)
@@ -299,7 +299,7 @@ __rcode int zunzip(void *dst, int dstlen, unsigned char *src,
                if (stoponerr == 1 && r != Z_STREAM_END &&
                    (s.avail_in == 0 || s.avail_out == 0 || r != Z_BUF_ERROR)) {
                        printf("Error: inflate() returned %d\n", r);
-                       err = -1;
+                       err = r;
                        break;
                }
        } while (r == Z_BUF_ERROR);