Commit 829ceb28215a1b6178bf690182def5ad56842f49

Authored by Eugeniu Rosca
Committed by Tom Rini
1 parent 0efe2b8f9e

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>

Showing 4 changed files with 15 additions and 3 deletions Side-by-side Diff

... ... @@ -154,7 +154,7 @@
154 154 #ifdef CONFIG_ANDROID_BOOT_IMAGE
155 155 case IMAGE_FORMAT_ANDROID:
156 156 images.os.type = IH_TYPE_KERNEL;
157   - images.os.comp = IH_COMP_NONE;
  157 + images.os.comp = android_image_get_kcomp(os_hdr);
158 158 images.os.os = IH_OS_LINUX;
159 159  
160 160 images.os.end = android_image_get_end(os_hdr);
common/image-android.c
... ... @@ -8,6 +8,7 @@
8 8 #include <android_image.h>
9 9 #include <malloc.h>
10 10 #include <errno.h>
  11 +#include <asm/unaligned.h>
11 12  
12 13 #define ANDROID_IMAGE_DEFAULT_KERNEL_ADDR 0x10008000
13 14  
... ... @@ -124,6 +125,16 @@
124 125 ulong android_image_get_kload(const struct andr_img_hdr *hdr)
125 126 {
126 127 return android_image_get_kernel_addr(hdr);
  128 +}
  129 +
  130 +ulong android_image_get_kcomp(const struct andr_img_hdr *hdr)
  131 +{
  132 + const void *p = (void *)((uintptr_t)hdr + hdr->page_size);
  133 +
  134 + if (get_unaligned_le32(p) == LZ4F_MAGIC)
  135 + return IH_COMP_LZ4;
  136 + else
  137 + return IH_COMP_NONE;
127 138 }
128 139  
129 140 int android_image_get_ramdisk(const struct andr_img_hdr *hdr,
... ... @@ -306,6 +306,7 @@
306 306 IH_COMP_COUNT,
307 307 };
308 308  
  309 +#define LZ4F_MAGIC 0x184D2204 /* LZ4 Magic Number */
309 310 #define IH_MAGIC 0x27051956 /* Image Magic Number */
310 311 #define IH_NMLEN 32 /* Image Name Length */
311 312  
... ... @@ -1312,6 +1313,7 @@
1312 1313 ulong *second_data, ulong *second_len);
1313 1314 ulong android_image_get_end(const struct andr_img_hdr *hdr);
1314 1315 ulong android_image_get_kload(const struct andr_img_hdr *hdr);
  1316 +ulong android_image_get_kcomp(const struct andr_img_hdr *hdr);
1315 1317 void android_print_contents(const struct andr_img_hdr *hdr);
1316 1318  
1317 1319 #endif /* CONFIG_ANDROID_BOOT_IMAGE */
... ... @@ -5,6 +5,7 @@
5 5  
6 6 #include <common.h>
7 7 #include <compiler.h>
  8 +#include <image.h>
8 9 #include <linux/kernel.h>
9 10 #include <linux/types.h>
10 11  
... ... @@ -22,8 +23,6 @@
22 23  
23 24 /* Unaltered (except removing unrelated code) from github.com/Cyan4973/lz4. */
24 25 #include "lz4.c" /* #include for inlining, do not link! */
25   -
26   -#define LZ4F_MAGIC 0x184D2204
27 26  
28 27 struct lz4_frame_header {
29 28 u32 magic;