[PATCH] bootm: improve error message when gzip decompression buffer is too small

Tom Rini trini at konsulko.com
Mon Apr 28 19:24:39 CEST 2025


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 at 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20250428/66299061/attachment.sig>


More information about the U-Boot mailing list