summaryrefslogtreecommitdiff
path: root/common/image.c
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2020-04-20 17:22:47 -0400
committerTom Rini <trini@konsulko.com>2020-04-20 17:22:47 -0400
commita06375805917a5b48c46724ceef4a1cd04935992 (patch)
tree45bba4e4fb8332c55324efaf96e46e6cbd8f4d93 /common/image.c
parente4837da7828293ea49abc579f939c0f5c4b127c3 (diff)
parent48180e15d3eaff51b1da30a90bc64b7acba8fb51 (diff)
Merge branch '2020-04-17-master-imports'
- Further cleanups for 'make refcheckdocs' - Another BTRFS fix. - Support for automatic decompression of images with booti as well as unlz4 command for manual decompression.
Diffstat (limited to 'common/image.c')
-rw-r--r--common/image.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/common/image.c b/common/image.c
index 94873cb6ed5..d8d14e871c6 100644
--- a/common/image.c
+++ b/common/image.c
@@ -202,6 +202,14 @@ struct table_info {
const table_entry_t *table;
};
+static const struct comp_magic_map image_comp[] = {
+ { IH_COMP_BZIP2, "bzip2", {0x42, 0x5a},},
+ { IH_COMP_GZIP, "gzip", {0x1f, 0x8b},},
+ { IH_COMP_LZMA, "lzma", {0x5d, 0x00},},
+ { IH_COMP_LZO, "lzo", {0x89, 0x4c},},
+ { IH_COMP_NONE, "none", {}, },
+};
+
static const struct table_info table_info[IH_COUNT] = {
{ "architecture", IH_ARCH_COUNT, uimage_arch },
{ "compression", IH_COMP_COUNT, uimage_comp },
@@ -407,6 +415,21 @@ static void print_decomp_msg(int comp_type, int type, bool is_xip)
printf(" Uncompressing %s\n", name);
}
+int image_decomp_type(const unsigned char *buf, ulong len)
+{
+ const struct comp_magic_map *cmagic = image_comp;
+
+ if (len < 2)
+ return -EINVAL;
+
+ for (; cmagic->comp_id > 0; cmagic++) {
+ if (!memcmp(buf, cmagic->magic, 2))
+ break;
+ }
+
+ return cmagic->comp_id;
+}
+
int image_decomp(int comp, ulong load, ulong image_start, int type,
void *load_buf, void *image_buf, ulong image_len,
uint unc_len, ulong *load_end)