summaryrefslogtreecommitdiff
path: root/boot
diff options
context:
space:
mode:
authorSafae Ouajih <souajih@baylibre.com>2023-02-06 00:50:17 +0100
committerPraneeth Bajjuri <praneeth@ti.com>2023-04-05 11:41:11 -0500
commit5456cac6eacdd55c5f7379f406b08d24a7285112 (patch)
treef666110694d39e8f2217f61865116c2ae644bac2 /boot
parent0349ecf2f5d4ec227b51a70f95c4e8aff6588c37 (diff)
android: boot: support boot image header version 3 and 4
commit 636da2039aea4ea3a638b14da0a9ec258897a10c upstream. Enable the support for boot image header version 3 and 4 using abootimg command. In order to use version 3 or 4: 1- Vendor boot image address should be given to abootimg cmd. abootimg addr $1 $vendor_boot_load_addr 2- "ramdisk_addr_r" env variable (ramdisk address) should be set to host the ramdisk : generic ramdisk + vendor ramdisk Replace "struct andr_boot_img_hdr_v0*" by "void *" in some functions since v3 and v4 are now supported as well. Signed-off-by: Safae Ouajih <souajih@baylibre.com> Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com> Tested-by: Mattijs Korpershoek <mkorpershoek@baylibre.com> Signed-off-by: Praneeth Bajjuri <praneeth@ti.com>
Diffstat (limited to 'boot')
-rw-r--r--boot/bootm.c37
-rw-r--r--boot/image-android.c16
-rw-r--r--boot/image-board.c18
-rw-r--r--boot/image-fdt.c2
4 files changed, 58 insertions, 15 deletions
diff --git a/boot/bootm.c b/boot/bootm.c
index 28a8fc3261..4144ff3b03 100644
--- a/boot/bootm.c
+++ b/boot/bootm.c
@@ -113,6 +113,10 @@ static int bootm_find_os(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
{
const void *os_hdr;
+#ifdef CONFIG_ANDROID_BOOT_IMAGE
+ const void *vendor_boot_img;
+ const void *boot_img;
+#endif
bool ep_found = false;
int ret;
@@ -181,14 +185,23 @@ static int bootm_find_os(struct cmd_tbl *cmdtp, int flag, int argc,
#endif
#ifdef CONFIG_ANDROID_BOOT_IMAGE
case IMAGE_FORMAT_ANDROID:
+ boot_img = os_hdr;
+ vendor_boot_img = NULL;
+ if (IS_ENABLED(CONFIG_CMD_ABOOTIMG)) {
+ boot_img = map_sysmem(get_abootimg_addr(), 0);
+ vendor_boot_img = map_sysmem(get_avendor_bootimg_addr(), 0);
+ }
images.os.type = IH_TYPE_KERNEL;
- images.os.comp = android_image_get_kcomp(os_hdr, NULL);
+ images.os.comp = android_image_get_kcomp(boot_img, vendor_boot_img);
images.os.os = IH_OS_LINUX;
-
- images.os.end = android_image_get_end(os_hdr, NULL);
- images.os.load = android_image_get_kload(os_hdr, NULL);
+ images.os.end = android_image_get_end(boot_img, vendor_boot_img);
+ images.os.load = android_image_get_kload(boot_img, vendor_boot_img);
images.ep = images.os.load;
ep_found = true;
+ if (IS_ENABLED(CONFIG_CMD_ABOOTIMG)) {
+ unmap_sysmem(vendor_boot_img);
+ unmap_sysmem(boot_img);
+ }
break;
#endif
default:
@@ -889,6 +902,10 @@ static const void *boot_get_kernel(struct cmd_tbl *cmdtp, int flag, int argc,
int os_noffset;
#endif
+#ifdef CONFIG_ANDROID_BOOT_IMAGE
+ const void *boot_img;
+ const void *vendor_boot_img;
+#endif
img_addr = genimg_get_kernel_addr_fit(argc < 1 ? NULL : argv[0],
&fit_uname_config,
&fit_uname_kernel);
@@ -964,10 +981,20 @@ static const void *boot_get_kernel(struct cmd_tbl *cmdtp, int flag, int argc,
#endif
#ifdef CONFIG_ANDROID_BOOT_IMAGE
case IMAGE_FORMAT_ANDROID:
+ boot_img = buf;
+ vendor_boot_img = NULL;
+ if (IS_ENABLED(CONFIG_CMD_ABOOTIMG)) {
+ boot_img = map_sysmem(get_abootimg_addr(), 0);
+ vendor_boot_img = map_sysmem(get_avendor_bootimg_addr(), 0);
+ }
printf("## Booting Android Image at 0x%08lx ...\n", img_addr);
- if (android_image_get_kernel(buf, NULL, images->verify,
+ if (android_image_get_kernel(boot_img, vendor_boot_img, images->verify,
os_data, os_len))
return NULL;
+ if (IS_ENABLED(CONFIG_CMD_ABOOTIMG)) {
+ unmap_sysmem(vendor_boot_img);
+ unmap_sysmem(boot_img);
+ }
break;
#endif
default:
diff --git a/boot/image-android.c b/boot/image-android.c
index 6be439ed12..fb29ff403f 100644
--- a/boot/image-android.c
+++ b/boot/image-android.c
@@ -201,7 +201,7 @@ static ulong android_image_get_kernel_addr(struct andr_image_data *img_data)
* Return: Zero, os start address and length on success,
* otherwise on failure.
*/
-int android_image_get_kernel(const struct andr_boot_img_hdr_v0 *hdr,
+int android_image_get_kernel(const void *hdr,
const void *vendor_boot_img, int verify,
ulong *os_data, ulong *os_len)
{
@@ -286,7 +286,7 @@ bool is_android_vendor_boot_image_header(const void *vendor_boot_img)
return !memcmp(VENDOR_BOOT_MAGIC, vendor_boot_img, ANDR_VENDOR_BOOT_MAGIC_SIZE);
}
-bool is_android_boot_image_header(const struct andr_boot_img_hdr_v0 *hdr)
+bool is_android_boot_image_header(const void *hdr)
{
return !memcmp(ANDR_BOOT_MAGIC, hdr, ANDR_BOOT_MAGIC_SIZE);
}
@@ -305,7 +305,7 @@ ulong android_image_get_end(const struct andr_boot_img_hdr_v0 *hdr,
return img_data.boot_img_total_size;
}
-ulong android_image_get_kload(const struct andr_boot_img_hdr_v0 *hdr,
+ulong android_image_get_kload(const void *hdr,
const void *vendor_boot_img)
{
struct andr_image_data img_data;
@@ -316,7 +316,7 @@ ulong android_image_get_kload(const struct andr_boot_img_hdr_v0 *hdr,
return android_image_get_kernel_addr(&img_data);
}
-ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0 *hdr,
+ulong android_image_get_kcomp(const void *hdr,
const void *vendor_boot_img)
{
struct andr_image_data img_data;
@@ -364,14 +364,18 @@ int android_image_get_ramdisk(const void *hdr, const void *vendor_boot_img,
return 0;
}
-int android_image_get_second(const struct andr_boot_img_hdr_v0 *hdr,
- ulong *second_data, ulong *second_len)
+int android_image_get_second(const void *hdr, ulong *second_data, ulong *second_len)
{
struct andr_image_data img_data;
if (!android_image_get_data(hdr, NULL, &img_data))
return -EINVAL;
+ if (img_data.header_version > 2) {
+ printf("Second stage bootloader is only supported for boot image version <= 2\n");
+ return -EOPNOTSUPP;
+ }
+
if (!img_data.second_size) {
*second_data = *second_len = 0;
return -1;
diff --git a/boot/image-board.c b/boot/image-board.c
index 670658a96c..fd0e438f93 100644
--- a/boot/image-board.c
+++ b/boot/image-board.c
@@ -426,10 +426,22 @@ static int select_ramdisk(struct bootm_headers *images, const char *select, u8 a
break;
case IMAGE_FORMAT_ANDROID:
if (IS_ENABLED(CONFIG_ANDROID_BOOT_IMAGE)) {
- void *ptr = map_sysmem(images->os.start, 0);
int ret;
- ret = android_image_get_ramdisk(ptr, NULL, rd_datap, rd_lenp);
- unmap_sysmem(ptr);
+ if (IS_ENABLED(CONFIG_CMD_ABOOTIMG)) {
+ void *boot_img = map_sysmem(get_abootimg_addr(), 0);
+ void *vendor_boot_img = map_sysmem(get_avendor_bootimg_addr(), 0);
+
+ ret = android_image_get_ramdisk(boot_img, vendor_boot_img,
+ rd_datap, rd_lenp);
+ unmap_sysmem(vendor_boot_img);
+ unmap_sysmem(boot_img);
+ } else {
+ void *ptr = map_sysmem(images->os.start, 0);
+
+ ret = android_image_get_ramdisk(ptr, NULL, rd_datap, rd_lenp);
+ unmap_sysmem(ptr);
+ }
+
if (ret)
return ret;
done = true;
diff --git a/boot/image-fdt.c b/boot/image-fdt.c
index d639f37896..f10200f647 100644
--- a/boot/image-fdt.c
+++ b/boot/image-fdt.c
@@ -529,7 +529,7 @@ int boot_get_fdt(int flag, int argc, char *const argv[], uint8_t arch,
}
#ifdef CONFIG_ANDROID_BOOT_IMAGE
} else if (genimg_get_format(buf) == IMAGE_FORMAT_ANDROID) {
- struct andr_boot_img_hdr_v0 *hdr = buf;
+ void *hdr = buf;
ulong fdt_data, fdt_len;
u32 fdt_size, dtb_idx;
/*