mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-09-20 14:41:58 +00:00
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>
This commit is contained in:
parent
0ddfa868ba
commit
efe92cd2f9
2 changed files with 52 additions and 34 deletions
|
@ -82,6 +82,43 @@ int spl_parse_legacy_header(struct spl_image_info *spl_image,
|
||||||
return 0;
|
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
|
* This function is added explicitly to avoid code size increase, when
|
||||||
* no compression method is enabled. The compiler will optimize the
|
* 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 spl_load_info *load, ulong offset,
|
||||||
struct legacy_img_hdr *hdr)
|
struct legacy_img_hdr *hdr)
|
||||||
{
|
{
|
||||||
__maybe_unused SizeT lzma_len;
|
|
||||||
__maybe_unused void *src;
|
|
||||||
ulong dataptr;
|
ulong dataptr;
|
||||||
int ret;
|
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));
|
map_sysmem(spl_image->load_addr, spl_image->size));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IH_COMP_LZMA: {
|
case IH_COMP_LZMA:
|
||||||
ulong overhead, size;
|
return spl_load_legacy_lzma(spl_image, load, offset);
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
debug("Compression method %s is not supported\n",
|
debug("Compression method %s is not supported\n",
|
||||||
genimg_get_comp_short_name(image_get_comp(hdr)));
|
genimg_get_comp_short_name(image_get_comp(hdr)));
|
||||||
|
|
|
@ -407,6 +407,19 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
|
||||||
#define SPL_COPY_PAYLOAD_ONLY 1
|
#define SPL_COPY_PAYLOAD_ONLY 1
|
||||||
#define SPL_FIT_FOUND 2
|
#define SPL_FIT_FOUND 2
|
||||||
|
|
||||||
|
/**
|
||||||
|
* spl_load_legacy_lzma() - Load an LZMA-compressed legacy image
|
||||||
|
* @spl_image: Image description (already set up)
|
||||||
|
* @load: Structure containing the information required to load data.
|
||||||
|
* @offset: Pointer to image
|
||||||
|
*
|
||||||
|
* Load/decompress an LZMA-compressed legacy image from the device.
|
||||||
|
*
|
||||||
|
* Return: 0 on success, or a negative error on failure
|
||||||
|
*/
|
||||||
|
int spl_load_legacy_lzma(struct spl_image_info *spl_image,
|
||||||
|
struct spl_load_info *load, ulong offset);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* spl_load_legacy_img() - Loads a legacy image from a device.
|
* spl_load_legacy_img() - Loads a legacy image from a device.
|
||||||
* @spl_image: Image description to set up
|
* @spl_image: Image description to set up
|
||||||
|
|
Loading…
Reference in a new issue