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.manoj...@amarulasolutions.com>
Signed-off-by: Suniel Mahesh <su...@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))) {
                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),
                                                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

Reply via email to