image: android: allow to wrap uImage into the Android boot image

This allows to use any available compression format with Android boot image

Since not all available compression formats have a magic number we should
explicitly specify type of compression.

For this purpose using uImage format becomes very useful, as this format is
well-known by the community and mkimage tool is already available.

Usage example:
mkimage -A ARM64 -T kernel -C lzma -d Image.lzma out/kernel

At this moment only -C option is handled, but specifying -A and -T options
are recommended for compatibility reasons in the future.

Kernel that compressed with LZ4 can be already used without wrapping into
the uImage, but I recommend wrapping it into the uImage in order to avoid
situations when by some mistake legacy LZ4 is used, that is interpreted as
raw Image and causes CPU to enter Exception Handler without providing any
meaningful explanation to the user.

Signed-off-by: Roman Stratiienko <roman.stratiienko@globallogic.com>
This commit is contained in:
Roman Stratiienko 2019-06-03 15:38:13 +03:00 committed by Tom Rini
parent dfaad8208f
commit 39f790b03a

View File

@ -52,6 +52,8 @@ int android_image_get_kernel(const struct andr_img_hdr *hdr, int verify,
ulong *os_data, ulong *os_len)
{
u32 kernel_addr = android_image_get_kernel_addr(hdr);
const struct image_header *ihdr = (const struct image_header *)
((uintptr_t)hdr + hdr->page_size);
/*
* Not all Android tools use the id field for signing the image with
@ -93,11 +95,19 @@ int android_image_get_kernel(const struct andr_img_hdr *hdr, int verify,
env_set("bootargs", newbootargs);
if (os_data) {
*os_data = (ulong)hdr;
*os_data += hdr->page_size;
if (image_get_magic(ihdr) == IH_MAGIC) {
*os_data = image_get_data(ihdr);
} else {
*os_data = (ulong)hdr;
*os_data += hdr->page_size;
}
}
if (os_len) {
if (image_get_magic(ihdr) == IH_MAGIC)
*os_len = image_get_data_size(ihdr);
else
*os_len = hdr->kernel_size;
}
if (os_len)
*os_len = hdr->kernel_size;
return 0;
}
@ -131,7 +141,9 @@ ulong android_image_get_kcomp(const struct andr_img_hdr *hdr)
{
const void *p = (void *)((uintptr_t)hdr + hdr->page_size);
if (get_unaligned_le32(p) == LZ4F_MAGIC)
if (image_get_magic((image_header_t *)p) == IH_MAGIC)
return image_get_comp((image_header_t *)p);
else if (get_unaligned_le32(p) == LZ4F_MAGIC)
return IH_COMP_LZ4;
else
return IH_COMP_NONE;