diff mbox series

image: Set load_end on partial loads

Message ID 20240523-image-partial-decomp-v1-1-af036235963a@baylibre.com
State Accepted
Delegated to: Tom Rini
Headers show
Series image: Set load_end on partial loads | expand

Commit Message

Mattijs Korpershoek May 23, 2024, 9:27 a.m. UTC
When decompressing, it's possible that the algorithm only performs
a partial decompression.
This usually happens when CONFIG_SYS_BOOTM_LEN is too small for
the uncompressed image.

When that happens, image_decomp() returns an error and *load_end == load.
The error is then handled by handle_decomp_error().

handle_decomp_error() expects the number of uncompressed bytes in
uncomp_size but receives *load_end - load == load - load == 0.

Because of this, handle_decomp_error does not report the expected
"Image too large: increase CONFIG_SYS_BOOTM_LEN" error message.

Modify the image_decomp() logic to always report the decompressed size,
even when a partial decompression happened.

Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
---
This has been tested on an AM62X SK EVM board with a big lz4 image and
the default CONFIG_SYS_BOOTM_LEN of 0x800000.

This has also been tested on sandbox using:
=> ut compression
---
 boot/image.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)


---
base-commit: a7f0154c412859323396111dd0c09dbafbc153cb
change-id: 20240523-image-partial-decomp-d6604e998e3a

Best regards,

Comments

Julien Masson June 10, 2024, 9:44 a.m. UTC | #1
On Mon 10 Jun 2024 at 11:43, Mattijs Korpershoek <mkorpershoek@baylibre.com> wrote:

> When decompressing, it's possible that the algorithm only performs
> a partial decompression.
> This usually happens when CONFIG_SYS_BOOTM_LEN is too small for
> the uncompressed image.
> 
> When that happens, image_decomp() returns an error and *load_end == load.
> The error is then handled by handle_decomp_error().
> 
> handle_decomp_error() expects the number of uncompressed bytes in
> uncomp_size but receives *load_end - load == load - load == 0.
> 
> Because of this, handle_decomp_error does not report the expected
> "Image too large: increase CONFIG_SYS_BOOTM_LEN" error message.
> 
> Modify the image_decomp() logic to always report the decompressed size,
> even when a partial decompression happened.
> 
> Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
> ---
> This has been tested on an AM62X SK EVM board with a big lz4 image and
> the default CONFIG_SYS_BOOTM_LEN of 0x800000.
> 
> This has also been tested on sandbox using:
> => ut compression
> ---
>  boot/image.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/boot/image.c b/boot/image.c
> index 073931cd7a3f..4f48e6eb563d 100644
> --- a/boot/image.c
> +++ b/boot/image.c
> @@ -531,10 +531,10 @@ int image_decomp(int comp, ulong load, ulong image_start, int type,
>  		printf("Unimplemented compression type %d\n", comp);
>  		return ret;
>  	}
> -	if (ret)
> -		return ret;
>  
>  	*load_end = load + image_len;
> +	if (ret)
> +		return ret;
>  
>  	return 0;
>  }
> 
> ---
> base-commit: a7f0154c412859323396111dd0c09dbafbc153cb
> change-id: 20240523-image-partial-decomp-d6604e998e3a
> 
> Best regards,
> -- 
> Mattijs Korpershoek <mkorpershoek@baylibre.com>
> 
> 

Reviewed-by: Julien Masson <jmasson@baylibre.com>
Tom Rini June 10, 2024, 4:51 p.m. UTC | #2
On Thu, 23 May 2024 11:27:09 +0200, Mattijs Korpershoek wrote:

> When decompressing, it's possible that the algorithm only performs
> a partial decompression.
> This usually happens when CONFIG_SYS_BOOTM_LEN is too small for
> the uncompressed image.
> 
> When that happens, image_decomp() returns an error and *load_end == load.
> The error is then handled by handle_decomp_error().
> 
> [...]

Applied to u-boot/next, thanks!
diff mbox series

Patch

diff --git a/boot/image.c b/boot/image.c
index 073931cd7a3f..4f48e6eb563d 100644
--- a/boot/image.c
+++ b/boot/image.c
@@ -531,10 +531,10 @@  int image_decomp(int comp, ulong load, ulong image_start, int type,
 		printf("Unimplemented compression type %d\n", comp);
 		return ret;
 	}
-	if (ret)
-		return ret;
 
 	*load_end = load + image_len;
+	if (ret)
+		return ret;
 
 	return 0;
 }