aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugeniu Rosca2019-04-08 17:35:27 +0200
committerTom Rini2019-04-24 07:27:32 -0400
commit829ceb28215a1b6178bf690182def5ad56842f49 (patch)
tree2dbfc2ea6f426284576ca4bb4b0d47c01ceb3a75
parent0efe2b8f9ee2f459a2161e19ae1e66918c9f5c3b (diff)
image: android: allow booting lz4-compressed kernels
According to Android image format [1], kernel image resides at 1 page offset from the boot image address. Grab the magic number from there and allow U-Boot to handle LZ4-compressed KNL binaries instead of hardcoding compression type to IH_COMP_NONE. Other compression types, if needed, can be added later. Tested on H3ULCB-KF using the image detailed in [2]. [1] Excerpt from include/android_image.h +-----------------+ | boot header | 1 page +-----------------+ | kernel | n pages +-----------------+ | ramdisk | m pages +-----------------+ | second stage | o pages +-----------------+ [2] => iminfo 4c000000 ## Checking Image at 4c000000 ... Android image found kernel size: 85b9d1 kernel address: 48080000 ramdisk size: 54ddbc ramdisk addrress: 4a180000 second size: 0 second address: 48000800 tags address: 48000100 page size: 800 os_version: 1200012a (ver: 0.9.0, level: 2018.10) name: cmdline: buildvariant=userdebug Signed-off-by: Eugeniu Rosca <erosca@de.adit-jv.com>
-rw-r--r--common/bootm.c2
-rw-r--r--common/image-android.c11
-rw-r--r--include/image.h2
-rw-r--r--lib/lz4_wrapper.c3
4 files changed, 15 insertions, 3 deletions
diff --git a/common/bootm.c b/common/bootm.c
index 42358b81fc9..b5d37d38db8 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -154,7 +154,7 @@ static int bootm_find_os(cmd_tbl_t *cmdtp, int flag, int argc,
#ifdef CONFIG_ANDROID_BOOT_IMAGE
case IMAGE_FORMAT_ANDROID:
images.os.type = IH_TYPE_KERNEL;
- images.os.comp = IH_COMP_NONE;
+ images.os.comp = android_image_get_kcomp(os_hdr);
images.os.os = IH_OS_LINUX;
images.os.end = android_image_get_end(os_hdr);
diff --git a/common/image-android.c b/common/image-android.c
index 2f38c191e91..c31dcd44652 100644
--- a/common/image-android.c
+++ b/common/image-android.c
@@ -8,6 +8,7 @@
#include <android_image.h>
#include <malloc.h>
#include <errno.h>
+#include <asm/unaligned.h>
#define ANDROID_IMAGE_DEFAULT_KERNEL_ADDR 0x10008000
@@ -126,6 +127,16 @@ ulong android_image_get_kload(const struct andr_img_hdr *hdr)
return android_image_get_kernel_addr(hdr);
}
+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)
+ return IH_COMP_LZ4;
+ else
+ return IH_COMP_NONE;
+}
+
int android_image_get_ramdisk(const struct andr_img_hdr *hdr,
ulong *rd_data, ulong *rd_len)
{
diff --git a/include/image.h b/include/image.h
index 765ffecee0a..889305cbefd 100644
--- a/include/image.h
+++ b/include/image.h
@@ -306,6 +306,7 @@ enum {
IH_COMP_COUNT,
};
+#define LZ4F_MAGIC 0x184D2204 /* LZ4 Magic Number */
#define IH_MAGIC 0x27051956 /* Image Magic Number */
#define IH_NMLEN 32 /* Image Name Length */
@@ -1312,6 +1313,7 @@ int android_image_get_second(const struct andr_img_hdr *hdr,
ulong *second_data, ulong *second_len);
ulong android_image_get_end(const struct andr_img_hdr *hdr);
ulong android_image_get_kload(const struct andr_img_hdr *hdr);
+ulong android_image_get_kcomp(const struct andr_img_hdr *hdr);
void android_print_contents(const struct andr_img_hdr *hdr);
#endif /* CONFIG_ANDROID_BOOT_IMAGE */
diff --git a/lib/lz4_wrapper.c b/lib/lz4_wrapper.c
index 487d39ef024..1c68e67452d 100644
--- a/lib/lz4_wrapper.c
+++ b/lib/lz4_wrapper.c
@@ -5,6 +5,7 @@
#include <common.h>
#include <compiler.h>
+#include <image.h>
#include <linux/kernel.h>
#include <linux/types.h>
@@ -23,8 +24,6 @@ typedef uint64_t U64;
/* Unaltered (except removing unrelated code) from github.com/Cyan4973/lz4. */
#include "lz4.c" /* #include for inlining, do not link! */
-#define LZ4F_MAGIC 0x184D2204
-
struct lz4_frame_header {
u32 magic;
union {