All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] bootm: improve error message when gzip decompression buffer is too small
@ 2025-04-28  6:07 Aristo Chen
  2025-04-28 17:24 ` Tom Rini
  2025-04-30  2:23 ` [PATCH v2 1/1] " Aristo Chen
  0 siblings, 2 replies; 10+ messages in thread
From: Aristo Chen @ 2025-04-28  6:07 UTC (permalink / raw)
  To: u-boot
  Cc: aristo.chen, trini, sjg, ilias.apalodimas, sughosh.ganu,
	mkorpershoek, Zone.Niuzh

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>
---
 boot/bootm.c | 15 +++++++++++++++
 lib/gunzip.c |  2 +-
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/boot/bootm.c b/boot/bootm.c
index f5cbb10f0d1..eae19232487 100644
--- a/boot/bootm.c
+++ b/boot/bootm.c
@@ -34,6 +34,7 @@
 
 #include <bootm.h>
 #include <image.h>
+#include <u-boot/zlib.h>
 
 #define MAX_CMDLINE_SIZE	SZ_4K
 
@@ -573,12 +574,26 @@ static int handle_decomp_error(int comp_type, size_t uncomp_size,
 			       size_t buf_size, int ret)
 {
 	const char *name = genimg_get_comp_name(comp_type);
+	bool likely_buf_too_small = false;
 
 	/* ENOSYS means unimplemented compression type, don't reset. */
 	if (ret == -ENOSYS)
 		return BOOTM_ERR_UNIMPLEMENTED;
 
+	switch (comp_type) {
+	case IH_COMP_GZIP:
+		if (ret == Z_BUF_ERROR) /* -5 */
+			likely_buf_too_small = true;
+		break;
+	// Add more if necessary
+	default:
+		break;
+	}
+
 	if (uncomp_size >= buf_size)
+		likely_buf_too_small = true;
+
+	if (likely_buf_too_small)
 		printf("Image too large: increase CONFIG_SYS_BOOTM_LEN\n");
 	else
 		printf("%s: uncompress error %d\n", name, ret);
diff --git a/lib/gunzip.c b/lib/gunzip.c
index 52007715bda..a05dcde9a75 100644
--- a/lib/gunzip.c
+++ b/lib/gunzip.c
@@ -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);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH] bootm: improve error message when gzip decompression buffer is too small
  2025-04-28  6:07 [PATCH] bootm: improve error message when gzip decompression buffer is too small Aristo Chen
@ 2025-04-28 17:24 ` Tom Rini
  2025-04-29 10:08   ` 陳偉銘
  2025-04-30  2:23 ` [PATCH v2 1/1] " Aristo Chen
  1 sibling, 1 reply; 10+ messages in thread
From: Tom Rini @ 2025-04-28 17:24 UTC (permalink / raw)
  To: Aristo Chen
  Cc: u-boot, aristo.chen, sjg, ilias.apalodimas, sughosh.ganu,
	mkorpershoek, Zone.Niuzh

[-- Attachment #1: Type: text/plain, Size: 1943 bytes --]

On Mon, Apr 28, 2025 at 02:07:57PM +0800, Aristo Chen wrote:

> 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>

I like the concept but:

> @@ -573,12 +574,26 @@ static int handle_decomp_error(int comp_type, size_t uncomp_size,
>  			       size_t buf_size, int ret)
>  {
>  	const char *name = genimg_get_comp_name(comp_type);
> +	bool likely_buf_too_small = false;
>  
>  	/* ENOSYS means unimplemented compression type, don't reset. */
>  	if (ret == -ENOSYS)
>  		return BOOTM_ERR_UNIMPLEMENTED;
>  
> +	switch (comp_type) {
> +	case IH_COMP_GZIP:
> +		if (ret == Z_BUF_ERROR) /* -5 */
> +			likely_buf_too_small = true;
> +		break;
> +	// Add more if necessary
> +	default:
> +		break;
> +	}
> +
>  	if (uncomp_size >= buf_size)
> +		likely_buf_too_small = true;
> +
> +	if (likely_buf_too_small)
>  		printf("Image too large: increase CONFIG_SYS_BOOTM_LEN\n");
>  	else
>  		printf("%s: uncompress error %d\n", name, ret);

This is a lot of code, why not just:
if (comp_type == IH_COMP_GZIP && ret == Z_BUF_ERROR)
  printf("Image too large: increase CONFIG_SYS_BOOTM_LEN\n");

And we can expand the tests for other algorithms either later or in
follow-up. Thanks!

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] bootm: improve error message when gzip decompression buffer is too small
  2025-04-28 17:24 ` Tom Rini
@ 2025-04-29 10:08   ` 陳偉銘
  2025-04-29 14:15     ` Tom Rini
  0 siblings, 1 reply; 10+ messages in thread
From: 陳偉銘 @ 2025-04-29 10:08 UTC (permalink / raw)
  To: Tom Rini
  Cc: u-boot, aristo.chen, sjg, ilias.apalodimas, sughosh.ganu,
	mkorpershoek, Zone.Niuzh

Tom Rini <trini@konsulko.com> 於 2025年4月29日 週二 上午1:24寫道:
>
> On Mon, Apr 28, 2025 at 02:07:57PM +0800, Aristo Chen wrote:
>
> > 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>
>
> I like the concept but:
>
> > @@ -573,12 +574,26 @@ static int handle_decomp_error(int comp_type, size_t uncomp_size,
> >                              size_t buf_size, int ret)
> >  {
> >       const char *name = genimg_get_comp_name(comp_type);
> > +     bool likely_buf_too_small = false;
> >
> >       /* ENOSYS means unimplemented compression type, don't reset. */
> >       if (ret == -ENOSYS)
> >               return BOOTM_ERR_UNIMPLEMENTED;
> >
> > +     switch (comp_type) {
> > +     case IH_COMP_GZIP:
> > +             if (ret == Z_BUF_ERROR) /* -5 */
> > +                     likely_buf_too_small = true;
> > +             break;
> > +     // Add more if necessary
> > +     default:
> > +             break;
> > +     }
> > +
> >       if (uncomp_size >= buf_size)
> > +             likely_buf_too_small = true;
> > +
> > +     if (likely_buf_too_small)
> >               printf("Image too large: increase CONFIG_SYS_BOOTM_LEN\n");
> >       else
> >               printf("%s: uncompress error %d\n", name, ret);
>
> This is a lot of code, why not just:
> if (comp_type == IH_COMP_GZIP && ret == Z_BUF_ERROR)
>   printf("Image too large: increase CONFIG_SYS_BOOTM_LEN\n");
>
Thanks for your suggestion! I am not sure if I get it correctly, do
you mean that we should remove the original if condition( if
(uncomp_size >= buf_size) ) that prints the error message?

> And we can expand the tests for other algorithms either later or in
> follow-up. Thanks!
>
> --
> Tom

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] bootm: improve error message when gzip decompression buffer is too small
  2025-04-29 10:08   ` 陳偉銘
@ 2025-04-29 14:15     ` Tom Rini
  2025-04-29 15:15       ` Aristo Chen
  0 siblings, 1 reply; 10+ messages in thread
From: Tom Rini @ 2025-04-29 14:15 UTC (permalink / raw)
  To: 陳偉銘
  Cc: u-boot, aristo.chen, sjg, ilias.apalodimas, sughosh.ganu,
	mkorpershoek, Zone.Niuzh

[-- Attachment #1: Type: text/plain, Size: 2646 bytes --]

On Tue, Apr 29, 2025 at 06:08:50PM +0800, 陳偉銘 wrote:
> Tom Rini <trini@konsulko.com> 於 2025年4月29日 週二 上午1:24寫道:
> >
> > On Mon, Apr 28, 2025 at 02:07:57PM +0800, Aristo Chen wrote:
> >
> > > 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>
> >
> > I like the concept but:
> >
> > > @@ -573,12 +574,26 @@ static int handle_decomp_error(int comp_type, size_t uncomp_size,
> > >                              size_t buf_size, int ret)
> > >  {
> > >       const char *name = genimg_get_comp_name(comp_type);
> > > +     bool likely_buf_too_small = false;
> > >
> > >       /* ENOSYS means unimplemented compression type, don't reset. */
> > >       if (ret == -ENOSYS)
> > >               return BOOTM_ERR_UNIMPLEMENTED;
> > >
> > > +     switch (comp_type) {
> > > +     case IH_COMP_GZIP:
> > > +             if (ret == Z_BUF_ERROR) /* -5 */
> > > +                     likely_buf_too_small = true;
> > > +             break;
> > > +     // Add more if necessary
> > > +     default:
> > > +             break;
> > > +     }
> > > +
> > >       if (uncomp_size >= buf_size)
> > > +             likely_buf_too_small = true;
> > > +
> > > +     if (likely_buf_too_small)
> > >               printf("Image too large: increase CONFIG_SYS_BOOTM_LEN\n");
> > >       else
> > >               printf("%s: uncompress error %d\n", name, ret);
> >
> > This is a lot of code, why not just:
> > if (comp_type == IH_COMP_GZIP && ret == Z_BUF_ERROR)
> >   printf("Image too large: increase CONFIG_SYS_BOOTM_LEN\n");
> >
> Thanks for your suggestion! I am not sure if I get it correctly, do
> you mean that we should remove the original if condition( if
> (uncomp_size >= buf_size) ) that prints the error message?

Ah sorry for being unclear. I just meant we can handle the new print
more directly.

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] bootm: improve error message when gzip decompression buffer is too small
  2025-04-29 14:15     ` Tom Rini
@ 2025-04-29 15:15       ` Aristo Chen
  2025-04-29 19:17         ` Tom Rini
  0 siblings, 1 reply; 10+ messages in thread
From: Aristo Chen @ 2025-04-29 15:15 UTC (permalink / raw)
  To: Tom Rini
  Cc: u-boot, aristo.chen, sjg, ilias.apalodimas, sughosh.ganu,
	mkorpershoek, Zone.Niuzh

Tom Rini <trini@konsulko.com> 於 2025年4月29日 週二 下午10:15寫道:
>
> On Tue, Apr 29, 2025 at 06:08:50PM +0800, 陳偉銘 wrote:
> > Tom Rini <trini@konsulko.com> 於 2025年4月29日 週二 上午1:24寫道:
> > >
> > > On Mon, Apr 28, 2025 at 02:07:57PM +0800, Aristo Chen wrote:
> > >
> > > > 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>
> > >
> > > I like the concept but:
> > >
> > > > @@ -573,12 +574,26 @@ static int handle_decomp_error(int comp_type, size_t uncomp_size,
> > > >                              size_t buf_size, int ret)
> > > >  {
> > > >       const char *name = genimg_get_comp_name(comp_type);
> > > > +     bool likely_buf_too_small = false;
> > > >
> > > >       /* ENOSYS means unimplemented compression type, don't reset. */
> > > >       if (ret == -ENOSYS)
> > > >               return BOOTM_ERR_UNIMPLEMENTED;
> > > >
> > > > +     switch (comp_type) {
> > > > +     case IH_COMP_GZIP:
> > > > +             if (ret == Z_BUF_ERROR) /* -5 */
> > > > +                     likely_buf_too_small = true;
> > > > +             break;
> > > > +     // Add more if necessary
> > > > +     default:
> > > > +             break;
> > > > +     }
> > > > +
> > > >       if (uncomp_size >= buf_size)
> > > > +             likely_buf_too_small = true;
> > > > +
> > > > +     if (likely_buf_too_small)
> > > >               printf("Image too large: increase CONFIG_SYS_BOOTM_LEN\n");
> > > >       else
> > > >               printf("%s: uncompress error %d\n", name, ret);
> > >
> > > This is a lot of code, why not just:
> > > if (comp_type == IH_COMP_GZIP && ret == Z_BUF_ERROR)
> > >   printf("Image too large: increase CONFIG_SYS_BOOTM_LEN\n");
> > >
> > Thanks for your suggestion! I am not sure if I get it correctly, do
> > you mean that we should remove the original if condition( if
> > (uncomp_size >= buf_size) ) that prints the error message?
>
> Ah sorry for being unclear. I just meant we can handle the new print
> more directly.
No worries, and thanks for your patience.

Just to double confirm, would the following meet your expectation?

if (comp_type == IH_COMP_GZIP && ret == Z_BUF_ERROR)
    printf("Image too large: increase CONFIG_SYS_BOOTM_LEN\n");
else if (uncomp_size >= buf_size)
    printf("Image too large: increase CONFIG_SYS_BOOTM_LEN\n");
else
    printf("%s: uncompress error %d\n", name, ret);

Or would you prefer combining the first two conditions into one?

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);

Thanks again!


>
> --
> Tom

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] bootm: improve error message when gzip decompression buffer is too small
  2025-04-29 15:15       ` Aristo Chen
@ 2025-04-29 19:17         ` Tom Rini
  0 siblings, 0 replies; 10+ messages in thread
From: Tom Rini @ 2025-04-29 19:17 UTC (permalink / raw)
  To: Aristo Chen
  Cc: u-boot, aristo.chen, sjg, ilias.apalodimas, sughosh.ganu,
	mkorpershoek, Zone.Niuzh

[-- Attachment #1: Type: text/plain, Size: 3895 bytes --]

On Tue, Apr 29, 2025 at 11:15:58PM +0800, Aristo Chen wrote:
> Tom Rini <trini@konsulko.com> 於 2025年4月29日 週二 下午10:15寫道:
> >
> > On Tue, Apr 29, 2025 at 06:08:50PM +0800, 陳偉銘 wrote:
> > > Tom Rini <trini@konsulko.com> 於 2025年4月29日 週二 上午1:24寫道:
> > > >
> > > > On Mon, Apr 28, 2025 at 02:07:57PM +0800, Aristo Chen wrote:
> > > >
> > > > > 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>
> > > >
> > > > I like the concept but:
> > > >
> > > > > @@ -573,12 +574,26 @@ static int handle_decomp_error(int comp_type, size_t uncomp_size,
> > > > >                              size_t buf_size, int ret)
> > > > >  {
> > > > >       const char *name = genimg_get_comp_name(comp_type);
> > > > > +     bool likely_buf_too_small = false;
> > > > >
> > > > >       /* ENOSYS means unimplemented compression type, don't reset. */
> > > > >       if (ret == -ENOSYS)
> > > > >               return BOOTM_ERR_UNIMPLEMENTED;
> > > > >
> > > > > +     switch (comp_type) {
> > > > > +     case IH_COMP_GZIP:
> > > > > +             if (ret == Z_BUF_ERROR) /* -5 */
> > > > > +                     likely_buf_too_small = true;
> > > > > +             break;
> > > > > +     // Add more if necessary
> > > > > +     default:
> > > > > +             break;
> > > > > +     }
> > > > > +
> > > > >       if (uncomp_size >= buf_size)
> > > > > +             likely_buf_too_small = true;
> > > > > +
> > > > > +     if (likely_buf_too_small)
> > > > >               printf("Image too large: increase CONFIG_SYS_BOOTM_LEN\n");
> > > > >       else
> > > > >               printf("%s: uncompress error %d\n", name, ret);
> > > >
> > > > This is a lot of code, why not just:
> > > > if (comp_type == IH_COMP_GZIP && ret == Z_BUF_ERROR)
> > > >   printf("Image too large: increase CONFIG_SYS_BOOTM_LEN\n");
> > > >
> > > Thanks for your suggestion! I am not sure if I get it correctly, do
> > > you mean that we should remove the original if condition( if
> > > (uncomp_size >= buf_size) ) that prints the error message?
> >
> > Ah sorry for being unclear. I just meant we can handle the new print
> > more directly.
> No worries, and thanks for your patience.
> 
> Just to double confirm, would the following meet your expectation?
> 
> if (comp_type == IH_COMP_GZIP && ret == Z_BUF_ERROR)
>     printf("Image too large: increase CONFIG_SYS_BOOTM_LEN\n");
> else if (uncomp_size >= buf_size)
>     printf("Image too large: increase CONFIG_SYS_BOOTM_LEN\n");
> else
>     printf("%s: uncompress error %d\n", name, ret);
> 
> Or would you prefer combining the first two conditions into one?
> 
> 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);

The second option yes, and then someone in the future can add
(comp_type == IH_COMP_LZO && ret == LZO_EQUIVALENT_ERROR) ||
and so forth.

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v2 1/1] bootm: improve error message when gzip decompression buffer is too small
  2025-04-28  6:07 [PATCH] bootm: improve error message when gzip decompression buffer is too small Aristo Chen
  2025-04-28 17:24 ` Tom Rini
@ 2025-04-30  2:23 ` Aristo Chen
  2025-04-30 14:36   ` Tom Rini
                     ` (2 more replies)
  1 sibling, 3 replies; 10+ messages in thread
From: Aristo Chen @ 2025-04-30  2:23 UTC (permalink / raw)
  To: u-boot
  Cc: aristo.chen, trini, sjg, ilias.apalodimas, sughosh.ganu,
	mkorpershoek, Zone.Niuzh

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>
---
 boot/bootm.c | 4 +++-
 lib/gunzip.c | 2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/boot/bootm.c b/boot/bootm.c
index f5cbb10f0d1..f6aa32746b7 100644
--- a/boot/bootm.c
+++ b/boot/bootm.c
@@ -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);
diff --git a/lib/gunzip.c b/lib/gunzip.c
index 52007715bda..a05dcde9a75 100644
--- a/lib/gunzip.c
+++ b/lib/gunzip.c
@@ -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);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 1/1] bootm: improve error message when gzip decompression buffer is too small
  2025-04-30  2:23 ` [PATCH v2 1/1] " Aristo Chen
@ 2025-04-30 14:36   ` Tom Rini
  2025-04-30 14:56   ` Mattijs Korpershoek
  2025-05-05 23:35   ` Tom Rini
  2 siblings, 0 replies; 10+ messages in thread
From: Tom Rini @ 2025-04-30 14:36 UTC (permalink / raw)
  To: Aristo Chen
  Cc: u-boot, aristo.chen, sjg, ilias.apalodimas, sughosh.ganu,
	mkorpershoek, Zone.Niuzh

[-- Attachment #1: Type: text/plain, Size: 894 bytes --]

On Wed, Apr 30, 2025 at 10:23:25AM +0800, Aristo Chen wrote:

> 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>

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 1/1] bootm: improve error message when gzip decompression buffer is too small
  2025-04-30  2:23 ` [PATCH v2 1/1] " Aristo Chen
  2025-04-30 14:36   ` Tom Rini
@ 2025-04-30 14:56   ` Mattijs Korpershoek
  2025-05-05 23:35   ` Tom Rini
  2 siblings, 0 replies; 10+ messages in thread
From: Mattijs Korpershoek @ 2025-04-30 14:56 UTC (permalink / raw)
  To: Aristo Chen, u-boot
  Cc: aristo.chen, trini, sjg, ilias.apalodimas, sughosh.ganu,
	mkorpershoek, Zone.Niuzh

Hi Aristo,

Thank you for the patch.

On mer., avril 30, 2025 at 10:23, Aristo Chen <jj251510319013@gmail.com> wrote:

> 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: Mattijs Korpershoek <mkorpershoek@kernel.org>

> ---
>  boot/bootm.c | 4 +++-
>  lib/gunzip.c | 2 +-
>  2 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/boot/bootm.c b/boot/bootm.c
> index f5cbb10f0d1..f6aa32746b7 100644
> --- a/boot/bootm.c
> +++ b/boot/bootm.c
> @@ -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);
> diff --git a/lib/gunzip.c b/lib/gunzip.c
> index 52007715bda..a05dcde9a75 100644
> --- a/lib/gunzip.c
> +++ b/lib/gunzip.c
> @@ -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);
> -- 
> 2.34.1

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 1/1] bootm: improve error message when gzip decompression buffer is too small
  2025-04-30  2:23 ` [PATCH v2 1/1] " Aristo Chen
  2025-04-30 14:36   ` Tom Rini
  2025-04-30 14:56   ` Mattijs Korpershoek
@ 2025-05-05 23:35   ` Tom Rini
  2 siblings, 0 replies; 10+ messages in thread
From: Tom Rini @ 2025-05-05 23:35 UTC (permalink / raw)
  To: u-boot, Aristo Chen
  Cc: aristo.chen, sjg, ilias.apalodimas, sughosh.ganu, mkorpershoek,
	Zone.Niuzh

On Wed, 30 Apr 2025 10:23:25 +0800, Aristo Chen wrote:

> 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
> 
> [...]

Applied to u-boot/master, thanks!

[1/1] bootm: improve error message when gzip decompression buffer is too small
      commit: f717d798becf2dffd5816484962c350808e98a18
-- 
Tom



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2025-05-05 23:35 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-28  6:07 [PATCH] bootm: improve error message when gzip decompression buffer is too small Aristo Chen
2025-04-28 17:24 ` Tom Rini
2025-04-29 10:08   ` 陳偉銘
2025-04-29 14:15     ` Tom Rini
2025-04-29 15:15       ` Aristo Chen
2025-04-29 19:17         ` Tom Rini
2025-04-30  2:23 ` [PATCH v2 1/1] " Aristo Chen
2025-04-30 14:36   ` Tom Rini
2025-04-30 14:56   ` Mattijs Korpershoek
2025-05-05 23:35   ` Tom Rini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.