[U-Boot] [PATCH] image: android: allow to wrap uImage into the Android boot image

roman.stratiienko at globallogic.com roman.stratiienko at globallogic.com
Mon Jun 3 12:38:13 UTC 2019


From: Roman Stratiienko <roman.stratiienko at globallogic.com>

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 at globallogic.com>
---
 common/image-android.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/common/image-android.c b/common/image-android.c
index 8b0f6b3b8b..6c9568a655 100644
--- a/common/image-android.c
+++ b/common/image-android.c
@@ -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;
-- 
2.17.1



More information about the U-Boot mailing list