All of lore.kernel.org
 help / color / mirror / Atom feed
From: roman.stratiienko at globallogic.com <roman.stratiienko@globallogic.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] image: android: allow to wrap uImage into the Android boot image
Date: Mon,  3 Jun 2019 15:38:13 +0300	[thread overview]
Message-ID: <20190603123813.48903-1-roman.stratiienko@globallogic.com> (raw)

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

             reply	other threads:[~2019-06-03 12:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-03 12:38 roman.stratiienko at globallogic.com [this message]
2019-07-24 20:05 ` [U-Boot] [PATCH] image: android: allow to wrap uImage into the Android boot image Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190603123813.48903-1-roman.stratiienko@globallogic.com \
    --to=roman.stratiienko@globallogic.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.