[v2,3/4] spl: fit: support for booting a GZIP-compressed U-boot binary

Message ID 20230725035101.281325-4-abbaraju.manojsai@amarulasolutions.com
State New
Headers show
Series
  • support for booting the compressed U-boot binary on Rockchip based ARM64 SOC's
Related show

Commit Message

Manoj Sai July 25, 2023, 3:51 a.m. UTC
If GZIP Compression support is enabled, GZIP compressed U-Boot binary
will be at a specified RAM location which is defined at
CONFIG_SYS_LOAD_ADDR and will be assign it as the source address.

gunzip function in spl_load_fit_image ,will decompress the GZIP
compressed U-Boot binary which is placed at
source address(CONFIG_SYS_LOAD_ADDR)  to the default
CONFIG_SYS_TEXT_BASE location.

spl_load_fit_image function will load the decompressed U-Boot
binary, which is placed at the CONFIG_SYS_TEXT_BASE location.

Signed-off-by: Manoj Sai <abbaraju.manojsai@amarulasolutions.com>
Signed-off-by: Suniel Mahesh <sunil@amarulasolutions.com>
---
 common/spl/spl_fit.c |  7 +++++--
 include/spl.h        | 10 ++++++++++
 2 files changed, 15 insertions(+), 2 deletions(-)

Comments

Simon Glass July 27, 2023, 12:53 a.m. UTC | #1
On Mon, 24 Jul 2023 at 21:51, Manoj Sai
<abbaraju.manojsai@amarulasolutions.com> wrote:
>
> If GZIP Compression support is enabled, GZIP compressed U-Boot binary
> will be at a specified RAM location which is defined at
> CONFIG_SYS_LOAD_ADDR and will be assign it as the source address.
>
> gunzip function in spl_load_fit_image ,will decompress the GZIP
> compressed U-Boot binary which is placed at
> source address(CONFIG_SYS_LOAD_ADDR)  to the default
> CONFIG_SYS_TEXT_BASE location.
>
> spl_load_fit_image function will load the decompressed U-Boot
> binary, which is placed at the CONFIG_SYS_TEXT_BASE location.
>
> Signed-off-by: Manoj Sai <abbaraju.manojsai@amarulasolutions.com>
> Signed-off-by: Suniel Mahesh <sunil@amarulasolutions.com>
> ---
>  common/spl/spl_fit.c |  7 +++++--
>  include/spl.h        | 10 ++++++++++
>  2 files changed, 15 insertions(+), 2 deletions(-)
>

Reviewed-by: Simon Glass <sjg@chromium.org>

We could really use sandbox_spl test cases for these sorts of thing.
Jonas Karlman July 27, 2023, 11:03 a.m. UTC | #2
On 2023-07-25 05:51, Manoj Sai wrote:
> If GZIP Compression support is enabled, GZIP compressed U-Boot binary
> will be at a specified RAM location which is defined at
> CONFIG_SYS_LOAD_ADDR and will be assign it as the source address.
> 
> gunzip function in spl_load_fit_image ,will decompress the GZIP
> compressed U-Boot binary which is placed at
> source address(CONFIG_SYS_LOAD_ADDR)  to the default
> CONFIG_SYS_TEXT_BASE location.
> 
> spl_load_fit_image function will load the decompressed U-Boot
> binary, which is placed at the CONFIG_SYS_TEXT_BASE location.
> 
> Signed-off-by: Manoj Sai <abbaraju.manojsai@amarulasolutions.com>
> Signed-off-by: Suniel Mahesh <sunil@amarulasolutions.com>
> ---
>  common/spl/spl_fit.c |  7 +++++--
>  include/spl.h        | 10 ++++++++++
>  2 files changed, 15 insertions(+), 2 deletions(-)
> 
> diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
> index 730639f756..d728ac71fc 100644
> --- a/common/spl/spl_fit.c
> +++ b/common/spl/spl_fit.c
> @@ -239,7 +239,7 @@ static int spl_load_fit_image(struct spl_load_info *info, ulong sector,
>  	bool external_data = false;
>  
>  	if (IS_ENABLED(CONFIG_SPL_FPGA) ||
> -	    (IS_ENABLED(CONFIG_SPL_OS_BOOT) && IS_ENABLED(CONFIG_SPL_GZIP))) {
> +	    (IS_ENABLED(CONFIG_SPL_OS_BOOT) && spl_decompression_enabled())) {
>  		if (fit_image_get_type(fit, node, &type))
>  			puts("Cannot get image type.\n");
>  		else
> @@ -281,7 +281,10 @@ static int spl_load_fit_image(struct spl_load_info *info, ulong sector,
>  			return 0;
>  		}
>  
> -		src_ptr = map_sysmem(ALIGN(load_addr, ARCH_DMA_MINALIGN), len);
> +		if ((IS_ENABLED(CONFIG_SPL_GZIP) && image_comp == IH_COMP_GZIP))

Should probably use the new spl_decompression_enabled() instead of
IS_ENABLED(CONFIG_SPL_GZIP) and the extra wrapping parentheses should
not be needed.

> +			src_ptr = map_sysmem(ALIGN(CONFIG_SYS_LOAD_ADDR, ARCH_DMA_MINALIGN), len);
> +		else
> +			src_ptr = map_sysmem(ALIGN(load_addr, ARCH_DMA_MINALIGN), len);
>  		length = len;
>  
>  		overhead = get_aligned_image_overhead(info, offset);
> diff --git a/include/spl.h b/include/spl.h
> index 92bcaa90a4..088479e357 100644
> --- a/include/spl.h
> +++ b/include/spl.h
> @@ -897,4 +897,14 @@ struct legacy_img_hdr *spl_get_load_buffer(ssize_t offset, size_t size);
>  
>  void board_boot_order(u32 *spl_boot_list);
>  void spl_save_restore_data(void);
> +
> +/*
> + * spl_decompression_enabled() - check decompression support is enabled for SPL build
> + *
> + * Returns  true  if decompression support is enabled, else False
> + */
> +static inline bool spl_decompression_enabled(void)
> +{
> +	return (IS_ENABLED(CONFIG_SPL_GZIP) || IS_ENABLED(CONFIG_SPL_LZMA));

IS_ENABLED(CONFIG_SPL_LZMA) should probably be added in the patch that
add support for LZMA and the wrapping parentheses should not be needed.

Regards,
Jonas

> +}
>  #endif
Kever Yang July 28, 2023, 10:09 a.m. UTC | #3
On 2023/7/25 11:51, Manoj Sai wrote:
> If GZIP Compression support is enabled, GZIP compressed U-Boot binary
> will be at a specified RAM location which is defined at
> CONFIG_SYS_LOAD_ADDR and will be assign it as the source address.
>
> gunzip function in spl_load_fit_image ,will decompress the GZIP
> compressed U-Boot binary which is placed at
> source address(CONFIG_SYS_LOAD_ADDR)  to the default
> CONFIG_SYS_TEXT_BASE location.
>
> spl_load_fit_image function will load the decompressed U-Boot
> binary, which is placed at the CONFIG_SYS_TEXT_BASE location.
>
> Signed-off-by: Manoj Sai <abbaraju.manojsai@amarulasolutions.com>
> Signed-off-by: Suniel Mahesh <sunil@amarulasolutions.com>
Reviewed-by: Kever Yang <kever.yang@rock-chips.com>

Thanks,
- Kever
> ---
>   common/spl/spl_fit.c |  7 +++++--
>   include/spl.h        | 10 ++++++++++
>   2 files changed, 15 insertions(+), 2 deletions(-)
>
> diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
> index 730639f756..d728ac71fc 100644
> --- a/common/spl/spl_fit.c
> +++ b/common/spl/spl_fit.c
> @@ -239,7 +239,7 @@ static int spl_load_fit_image(struct spl_load_info *info, ulong sector,
>   	bool external_data = false;
>   
>   	if (IS_ENABLED(CONFIG_SPL_FPGA) ||
> -	    (IS_ENABLED(CONFIG_SPL_OS_BOOT) && IS_ENABLED(CONFIG_SPL_GZIP))) {
> +	    (IS_ENABLED(CONFIG_SPL_OS_BOOT) && spl_decompression_enabled())) {
>   		if (fit_image_get_type(fit, node, &type))
>   			puts("Cannot get image type.\n");
>   		else
> @@ -281,7 +281,10 @@ static int spl_load_fit_image(struct spl_load_info *info, ulong sector,
>   			return 0;
>   		}
>   
> -		src_ptr = map_sysmem(ALIGN(load_addr, ARCH_DMA_MINALIGN), len);
> +		if ((IS_ENABLED(CONFIG_SPL_GZIP) && image_comp == IH_COMP_GZIP))
> +			src_ptr = map_sysmem(ALIGN(CONFIG_SYS_LOAD_ADDR, ARCH_DMA_MINALIGN), len);
> +		else
> +			src_ptr = map_sysmem(ALIGN(load_addr, ARCH_DMA_MINALIGN), len);
>   		length = len;
>   
>   		overhead = get_aligned_image_overhead(info, offset);
> diff --git a/include/spl.h b/include/spl.h
> index 92bcaa90a4..088479e357 100644
> --- a/include/spl.h
> +++ b/include/spl.h
> @@ -897,4 +897,14 @@ struct legacy_img_hdr *spl_get_load_buffer(ssize_t offset, size_t size);
>   
>   void board_boot_order(u32 *spl_boot_list);
>   void spl_save_restore_data(void);
> +
> +/*
> + * spl_decompression_enabled() - check decompression support is enabled for SPL build
> + *
> + * Returns  true  if decompression support is enabled, else False
> + */
> +static inline bool spl_decompression_enabled(void)
> +{
> +	return (IS_ENABLED(CONFIG_SPL_GZIP) || IS_ENABLED(CONFIG_SPL_LZMA));
> +}
>   #endif
Kever Yang July 28, 2023, 10:11 a.m. UTC | #4
Hi Manoj,

     Could update a new patch version and address the comment from Jonas?


Thanks,

- Kever

On 2023/7/27 19:03, Jonas Karlman wrote:
> On 2023-07-25 05:51, Manoj Sai wrote:
>> If GZIP Compression support is enabled, GZIP compressed U-Boot binary
>> will be at a specified RAM location which is defined at
>> CONFIG_SYS_LOAD_ADDR and will be assign it as the source address.
>>
>> gunzip function in spl_load_fit_image ,will decompress the GZIP
>> compressed U-Boot binary which is placed at
>> source address(CONFIG_SYS_LOAD_ADDR)  to the default
>> CONFIG_SYS_TEXT_BASE location.
>>
>> spl_load_fit_image function will load the decompressed U-Boot
>> binary, which is placed at the CONFIG_SYS_TEXT_BASE location.
>>
>> Signed-off-by: Manoj Sai <abbaraju.manojsai@amarulasolutions.com>
>> Signed-off-by: Suniel Mahesh <sunil@amarulasolutions.com>
>> ---
>>   common/spl/spl_fit.c |  7 +++++--
>>   include/spl.h        | 10 ++++++++++
>>   2 files changed, 15 insertions(+), 2 deletions(-)
>>
>> diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
>> index 730639f756..d728ac71fc 100644
>> --- a/common/spl/spl_fit.c
>> +++ b/common/spl/spl_fit.c
>> @@ -239,7 +239,7 @@ static int spl_load_fit_image(struct spl_load_info *info, ulong sector,
>>   	bool external_data = false;
>>   
>>   	if (IS_ENABLED(CONFIG_SPL_FPGA) ||
>> -	    (IS_ENABLED(CONFIG_SPL_OS_BOOT) && IS_ENABLED(CONFIG_SPL_GZIP))) {
>> +	    (IS_ENABLED(CONFIG_SPL_OS_BOOT) && spl_decompression_enabled())) {
>>   		if (fit_image_get_type(fit, node, &type))
>>   			puts("Cannot get image type.\n");
>>   		else
>> @@ -281,7 +281,10 @@ static int spl_load_fit_image(struct spl_load_info *info, ulong sector,
>>   			return 0;
>>   		}
>>   
>> -		src_ptr = map_sysmem(ALIGN(load_addr, ARCH_DMA_MINALIGN), len);
>> +		if ((IS_ENABLED(CONFIG_SPL_GZIP) && image_comp == IH_COMP_GZIP))
> Should probably use the new spl_decompression_enabled() instead of
> IS_ENABLED(CONFIG_SPL_GZIP) and the extra wrapping parentheses should
> not be needed.
>
>> +			src_ptr = map_sysmem(ALIGN(CONFIG_SYS_LOAD_ADDR, ARCH_DMA_MINALIGN), len);
>> +		else
>> +			src_ptr = map_sysmem(ALIGN(load_addr, ARCH_DMA_MINALIGN), len);
>>   		length = len;
>>   
>>   		overhead = get_aligned_image_overhead(info, offset);
>> diff --git a/include/spl.h b/include/spl.h
>> index 92bcaa90a4..088479e357 100644
>> --- a/include/spl.h
>> +++ b/include/spl.h
>> @@ -897,4 +897,14 @@ struct legacy_img_hdr *spl_get_load_buffer(ssize_t offset, size_t size);
>>   
>>   void board_boot_order(u32 *spl_boot_list);
>>   void spl_save_restore_data(void);
>> +
>> +/*
>> + * spl_decompression_enabled() - check decompression support is enabled for SPL build
>> + *
>> + * Returns  true  if decompression support is enabled, else False
>> + */
>> +static inline bool spl_decompression_enabled(void)
>> +{
>> +	return (IS_ENABLED(CONFIG_SPL_GZIP) || IS_ENABLED(CONFIG_SPL_LZMA));
> IS_ENABLED(CONFIG_SPL_LZMA) should probably be added in the patch that
> add support for LZMA and the wrapping parentheses should not be needed.
>
> Regards,
> Jonas
>
>> +}
>>   #endif

Patch

diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
index 730639f756..d728ac71fc 100644
--- a/common/spl/spl_fit.c
+++ b/common/spl/spl_fit.c
@@ -239,7 +239,7 @@  static int spl_load_fit_image(struct spl_load_info *info, ulong sector,
 	bool external_data = false;
 
 	if (IS_ENABLED(CONFIG_SPL_FPGA) ||
-	    (IS_ENABLED(CONFIG_SPL_OS_BOOT) && IS_ENABLED(CONFIG_SPL_GZIP))) {
+	    (IS_ENABLED(CONFIG_SPL_OS_BOOT) && spl_decompression_enabled())) {
 		if (fit_image_get_type(fit, node, &type))
 			puts("Cannot get image type.\n");
 		else
@@ -281,7 +281,10 @@  static int spl_load_fit_image(struct spl_load_info *info, ulong sector,
 			return 0;
 		}
 
-		src_ptr = map_sysmem(ALIGN(load_addr, ARCH_DMA_MINALIGN), len);
+		if ((IS_ENABLED(CONFIG_SPL_GZIP) && image_comp == IH_COMP_GZIP))
+			src_ptr = map_sysmem(ALIGN(CONFIG_SYS_LOAD_ADDR, ARCH_DMA_MINALIGN), len);
+		else
+			src_ptr = map_sysmem(ALIGN(load_addr, ARCH_DMA_MINALIGN), len);
 		length = len;
 
 		overhead = get_aligned_image_overhead(info, offset);
diff --git a/include/spl.h b/include/spl.h
index 92bcaa90a4..088479e357 100644
--- a/include/spl.h
+++ b/include/spl.h
@@ -897,4 +897,14 @@  struct legacy_img_hdr *spl_get_load_buffer(ssize_t offset, size_t size);
 
 void board_boot_order(u32 *spl_boot_list);
 void spl_save_restore_data(void);
+
+/*
+ * spl_decompression_enabled() - check decompression support is enabled for SPL build
+ *
+ * Returns  true  if decompression support is enabled, else False
+ */
+static inline bool spl_decompression_enabled(void)
+{
+	return (IS_ENABLED(CONFIG_SPL_GZIP) || IS_ENABLED(CONFIG_SPL_LZMA));
+}
 #endif