[PATCH 06/10] spl: fit: support for booting a LZMA-compressed U-boot raw binary
Simon Glass
sjg at chromium.org
Sun Jul 2 17:34:35 CEST 2023
Hi Manoj,
On Fri, 30 Jun 2023 at 13:12, Manoj Sai
<abbaraju.manojsai at amarulasolutions.com> wrote:
>
> If LZMA Compression support is enabled, LZMA compressed U-Boot
> raw binary will be at a specified RAM location which is defined
> at UBOOT_COMPRESSED_BINARY_FIT_USER_DEF_ADDR and will be assign it as
> the source address.
>
> lzmaBuffToBuffDecompress function in spl_load_fit_image ,will decompress
> the LZMA compressed U-Boot raw binary which is placed at source address
> to the default CONFIG_SYS_TEXT_BASE location.
>
> spl_load_fit_image function will load the decompressed U-Boot
> raw binary, which is placed at the CONFIG_SYS_TEXT_BASE location.
>
> Signed-off-by: Manoj Sai <abbaraju.manojsai at amarulasolutions.com>
> Signed-off-by: Suniel Mahesh <sunil at amarulasolutions.com>
> ---
> common/spl/spl_fit.c | 20 ++++++++++++++++----
> 1 file changed, 16 insertions(+), 4 deletions(-)
>
> diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
> index e2101099ef..b4e95d3fb5 100644
> --- a/common/spl/spl_fit.c
> +++ b/common/spl/spl_fit.c
> @@ -17,6 +17,9 @@
> #include <asm/cache.h>
> #include <asm/global_data.h>
> #include <linux/libfdt.h>
> +#include <lzma/LzmaTypes.h>
> +#include <lzma/LzmaDec.h>
> +#include <lzma/LzmaTools.h>
>
> DECLARE_GLOBAL_DATA_PTR;
>
> @@ -239,14 +242,15 @@ 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) && IS_ENABLED(CONFIG_SPL_GZIP)) ||
> + (IS_ENABLED(CONFIG_SPL_OS_BOOT) && IS_ENABLED(CONFIG_SPL_LZMA))) {
This needs a refactor. You could do:
if (IS_ENABLED(CONFIG_SPL_FPGA) ||
(IS_ENABLED(CONFIG_SPL_OS_BOOT) &&
(IS_ENABLED(CONFIG_SPL_GZIP) || IS_ENABLED(CONFIG_SPL_LZMA))
But I think it is better to creating a static inline functoin in spl.h, like:
static bool spl_compress_enabled()
{
return IS_ENABLED(CONFIG_SPL_GZIP) || IS_ENABLED(CONFIG_SPL_LZMA);
}
and then use that in this patch.
> if (fit_image_get_type(fit, node, &type))
> puts("Cannot get image type.\n");
> else
> debug("%s ", genimg_get_type_name(type));
> }
>
> - if (IS_ENABLED(CONFIG_SPL_GZIP)) {
> + if (IS_ENABLED(CONFIG_SPL_GZIP) || IS_ENABLED(CONFIG_SPL_LZMA)) {
> fit_image_get_comp(fit, node, &image_comp);
> debug("%s ", genimg_get_comp_name(image_comp));
> }
> @@ -281,7 +285,8 @@ static int spl_load_fit_image(struct spl_load_info *info, ulong sector,
> return 0;
> }
>
> - if ((IS_ENABLED(CONFIG_SPL_GZIP) && image_comp == IH_COMP_GZIP)) {
> + if ((IS_ENABLED(CONFIG_SPL_GZIP) && image_comp == IH_COMP_GZIP) ||
> + (IS_ENABLED(CONFIG_SPL_LZMA) && image_comp == IH_COMP_LZMA)) {
> src_ptr = map_sysmem(ALIGN(CONFIG_VAL(UBOOT_COMPRESSED_BINARY_FIT_USER_DEF_ADDR),
I think you should drop the ALIGN() and tell the user that the address
must be cached-aligned, in the Kconfig help, since it will be
confusing if it uses a different request from what was requested.
> ARCH_DMA_MINALIGN), len);
> } else {
> @@ -325,13 +330,20 @@ static int spl_load_fit_image(struct spl_load_info *info, ulong sector,
>
> load_ptr = map_sysmem(load_addr, length);
>
> - if ((IS_ENABLED(CONFIG_SPL_GZIP) && image_comp == IH_COMP_GZIP)) {
> + if ((IS_ENABLED(CONFIG_SPL_GZIP) && image_comp == IH_COMP_GZIP) ||
> + (IS_ENABLED(CONFIG_SPL_LZMA) && image_comp == IH_COMP_LZMA)) {
> if ((IS_ENABLED(CONFIG_SPL_GZIP) && image_comp == IH_COMP_GZIP)) {
> size = length;
> if (gunzip(load_ptr, CONFIG_SYS_BOOTM_LEN, src, &size)) {
> puts("Uncompressing error\n");
> return -EIO;
> }
> + } else if ((IS_ENABLED(CONFIG_SPL_LZMA) && image_comp == IH_COMP_LZMA)) {
> + size = CONFIG_SYS_BOOTM_LEN;
> + if (lzmaBuffToBuffDecompress(load_ptr, &size, src, length)) {
> + puts("Uncompressing error\n");
> + return -EIO;
> + }
> }
> length = size;
> } else {
> --
> 2.25.1
>
Can you use the existing image_decomp() instead?
Regards,
Simon
More information about the U-Boot
mailing list