All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] image: android: allow to wrap uImage into the Android boot image
@ 2019-06-03 12:38 roman.stratiienko at globallogic.com
  2019-07-24 20:05 ` Tom Rini
  0 siblings, 1 reply; 2+ messages in thread
From: roman.stratiienko at globallogic.com @ 2019-06-03 12:38 UTC (permalink / raw)
  To: u-boot

From: Roman Stratiienko <roman.stratiienko@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@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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [U-Boot] [PATCH] image: android: allow to wrap uImage into the Android boot image
  2019-06-03 12:38 [U-Boot] [PATCH] image: android: allow to wrap uImage into the Android boot image roman.stratiienko at globallogic.com
@ 2019-07-24 20:05 ` Tom Rini
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Rini @ 2019-07-24 20:05 UTC (permalink / raw)
  To: u-boot

On Mon, Jun 03, 2019 at 03:38:13PM +0300, roman.stratiienko at globallogic.com wrote:

> From: Roman Stratiienko <roman.stratiienko@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@globallogic.com>

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190724/648e213c/attachment.sig>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-07-24 20:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-03 12:38 [U-Boot] [PATCH] image: android: allow to wrap uImage into the Android boot image roman.stratiienko at globallogic.com
2019-07-24 20:05 ` Tom Rini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.