summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAristo Chen <jj251510319013@gmail.com>2025-05-08 19:37:24 +0000
committerTom Rini <trini@konsulko.com>2025-05-22 14:26:38 -0600
commitef305ceff9c875a7c16fdffc5e120d8ddf6243b7 (patch)
treed11d70f312774bdd7416fc21eb663a6a30323188
parent86acdce2ba886153f152b924b28e5c040e316c80 (diff)
cmd: ximg: handle Z_BUF_ERROR explicitly in GZIP decompression
When decompressing GZIP-compressed image parts via the `imxtract` command, explicitly handle the `Z_BUF_ERROR` return value from `gunzip()` to provide a clearer diagnostic. This error typically indicates that the destination buffer is too small to hold the uncompressed data. Signed-off-by: Aristo Chen <aristo.chen@canonical.com> [trini: Rework to indent the whole case with { } due to not using the C23 extension] Signed-off-by: Tom Rini <trini@konsulko.com>
-rw-r--r--cmd/ximg.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/cmd/ximg.c b/cmd/ximg.c
index 29d7c3279b3..e97167a79cc 100644
--- a/cmd/ximg.c
+++ b/cmd/ximg.c
@@ -27,6 +27,7 @@
#include <asm/byteorder.h>
#include <asm/cache.h>
#include <asm/io.h>
+#include <u-boot/zlib.h>
static int
do_imgextract(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
@@ -206,11 +207,18 @@ do_imgextract(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
break;
#ifdef CONFIG_GZIP
case IH_COMP_GZIP:
- printf(" Uncompressing part %d ... ", part);
- if (gunzip((void *) dest, unc_len,
- (uchar *) data, &len) != 0) {
- puts("GUNZIP ERROR - image not loaded\n");
- return 1;
+ {
+ int ret = 0;
+ printf(" Uncompressing part %d ... ", part);
+ ret = gunzip((void *)dest, unc_len,
+ (uchar *)data, &len);
+ if (ret == Z_BUF_ERROR) {
+ puts("Image too large: increase CONFIG_SYS_XIMG_LEN\n");
+ return 1;
+ } else if (ret != 0) {
+ puts("GUNZIP ERROR - image not loaded\n");
+ return 1;
+ }
}
break;
#endif