diff options
author | Sean Anderson <seanga2@gmail.com> | 2023-11-08 11:48:45 -0500 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2023-11-16 13:49:14 -0500 |
commit | efe92cd2f9eff3699d4a6b5e1c3d261c4b88b342 (patch) | |
tree | 09df25920278c27a1244e1ea19a707a2a86ce5c0 /common/spl | |
parent | 0ddfa868ba45903babf19039c80dfeb1503f9001 (diff) | |
download | u-boot-efe92cd2f9eff3699d4a6b5e1c3d261c4b88b342.zip u-boot-efe92cd2f9eff3699d4a6b5e1c3d261c4b88b342.tar.gz u-boot-efe92cd2f9eff3699d4a6b5e1c3d261c4b88b342.tar.bz2 |
spl: legacy: Split off LZMA decompression into its own function
To allow for easier reuse of this functionality, split it off into its
own function.
Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'common/spl')
-rw-r--r-- | common/spl/spl_legacy.c | 75 |
1 files changed, 40 insertions, 35 deletions
diff --git a/common/spl/spl_legacy.c b/common/spl/spl_legacy.c index 75d9d82..a561939 100644 --- a/common/spl/spl_legacy.c +++ b/common/spl/spl_legacy.c @@ -82,6 +82,43 @@ int spl_parse_legacy_header(struct spl_image_info *spl_image, return 0; } +int spl_load_legacy_lzma(struct spl_image_info *spl_image, + struct spl_load_info *load, ulong offset) +{ + SizeT lzma_len = LZMA_LEN; + void *src; + ulong dataptr, overhead, size; + int ret; + + /* dataptr points to compressed payload */ + dataptr = ALIGN_DOWN(sizeof(struct legacy_img_hdr), + spl_get_bl_len(load)); + overhead = sizeof(struct legacy_img_hdr) - dataptr; + size = ALIGN(spl_image->size + overhead, spl_get_bl_len(load)); + dataptr += offset; + + debug("LZMA: Decompressing %08lx to %08lx\n", + dataptr, spl_image->load_addr); + src = malloc(size); + if (!src) { + printf("Unable to allocate %d bytes for LZMA\n", + spl_image->size); + return -ENOMEM; + } + + load->read(load, dataptr, size, src); + ret = lzmaBuffToBuffDecompress(map_sysmem(spl_image->load_addr, + spl_image->size), &lzma_len, + src + overhead, spl_image->size); + if (ret) { + printf("LZMA decompression error: %d\n", ret); + return ret; + } + + spl_image->size = lzma_len; + return 0; +} + /* * This function is added explicitly to avoid code size increase, when * no compression method is enabled. The compiler will optimize the @@ -101,8 +138,6 @@ int spl_load_legacy_img(struct spl_image_info *spl_image, struct spl_load_info *load, ulong offset, struct legacy_img_hdr *hdr) { - __maybe_unused SizeT lzma_len; - __maybe_unused void *src; ulong dataptr; int ret; @@ -133,39 +168,9 @@ int spl_load_legacy_img(struct spl_image_info *spl_image, map_sysmem(spl_image->load_addr, spl_image->size)); break; - case IH_COMP_LZMA: { - ulong overhead, size; - - lzma_len = LZMA_LEN; - - /* dataptr points to compressed payload */ - dataptr = ALIGN_DOWN(sizeof(*hdr), spl_get_bl_len(load)); - overhead = sizeof(*hdr) - dataptr; - size = ALIGN(spl_image->size + overhead, spl_get_bl_len(load)); - dataptr += offset; - - debug("LZMA: Decompressing %08lx to %08lx\n", - dataptr, spl_image->load_addr); - src = malloc(size); - if (!src) { - printf("Unable to allocate %d bytes for LZMA\n", - spl_image->size); - return -ENOMEM; - } - - load->read(load, dataptr, size, src); - ret = lzmaBuffToBuffDecompress(map_sysmem(spl_image->load_addr, - spl_image->size), - &lzma_len, src + overhead, - spl_image->size); - if (ret) { - printf("LZMA decompression error: %d\n", ret); - return ret; - } - - spl_image->size = lzma_len; - break; - } + case IH_COMP_LZMA: + return spl_load_legacy_lzma(spl_image, load, offset); + default: debug("Compression method %s is not supported\n", genimg_get_comp_short_name(image_get_comp(hdr))); |