diff mbox series

[v2,11/17] android: boot: ramdisk: support vendor ramdisk

Message ID 20230126160506.1026643-12-souajih@baylibre.com
State Changes Requested
Delegated to: Simon Glass
Headers show
Series Support android boot image v3/v4 | expand

Commit Message

Safae Ouajih Jan. 26, 2023, 4:05 p.m. UTC
Version 3 and 4 of boot image header introduced
vendor boot ramdisk: Please check include/android_image.h
for details.

The ramdisk is now split into a generic ramdisk in boot image
and a vendor ramdisk in vendor boot image.

Signed-off-by: Safae Ouajih <souajih@baylibre.com>
---
 boot/image-android.c | 13 +++++++++++--
 include/image.h      |  4 ++--
 2 files changed, 13 insertions(+), 4 deletions(-)

Comments

Simon Glass Jan. 27, 2023, 12:54 a.m. UTC | #1
On Thu, 26 Jan 2023 at 09:05, Safae Ouajih <souajih@baylibre.com> wrote:
>
> Version 3 and 4 of boot image header introduced
> vendor boot ramdisk: Please check include/android_image.h
> for details.
>
> The ramdisk is now split into a generic ramdisk in boot image
> and a vendor ramdisk in vendor boot image.
>
> Signed-off-by: Safae Ouajih <souajih@baylibre.com>
> ---
>  boot/image-android.c | 13 +++++++++++--
>  include/image.h      |  4 ++--
>  2 files changed, 13 insertions(+), 4 deletions(-)
>

Some comment re comments

With that:

Reviewed-by: Simon Glass <sjg@chromium.org>
diff mbox series

Patch

diff --git a/boot/image-android.c b/boot/image-android.c
index 0e78ca0dac..5b270e4417 100644
--- a/boot/image-android.c
+++ b/boot/image-android.c
@@ -25,6 +25,7 @@  static void android_boot_image_v3_v4_parse_hdr(const struct andr_boot_img_hdr_v3
 
 	data->kcmdline = hdr->cmdline;
 	data->header_version = hdr->header_version;
+	data->ramdisk_ptr = env_get_ulong("ramdisk_addr_r", 16, 0);
 
 	/*
 	 * The header takes a full page, the remaining components are aligned
@@ -322,10 +323,11 @@  ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0 *hdr,
 		return image_decomp_type(p, sizeof(u32));
 }
 
-int android_image_get_ramdisk(const struct andr_boot_img_hdr_v0 *hdr,
-			      const void *vendor_boot_img, ulong *rd_data, ulong *rd_len)
+int android_image_get_ramdisk(const void *hdr, const void *vendor_boot_img,
+			      ulong *rd_data, ulong *rd_len)
 {
 	struct andr_image_data img_data = {0};
+	ulong ramdisk_ptr;
 
 	if (!android_image_get_data(hdr, vendor_boot_img, &img_data))
 		return -EINVAL;
@@ -334,6 +336,13 @@  int android_image_get_ramdisk(const struct andr_boot_img_hdr_v0 *hdr,
 		*rd_data = *rd_len = 0;
 		return -1;
 	}
+	if (img_data.header_version > 2) {
+		ramdisk_ptr = img_data.ramdisk_ptr;
+		memcpy((void *)(ramdisk_ptr), (void *)img_data.vendor_ramdisk_ptr,
+		       img_data.vendor_ramdisk_size);
+		memcpy((void *)(ramdisk_ptr + img_data.vendor_ramdisk_size),
+		       (void *)img_data.ramdisk_ptr, img_data.boot_ramdisk_size);
+	}
 
 	printf("RAM disk load addr 0x%08lx size %u KiB\n",
 	       img_data.ramdisk_ptr, DIV_ROUND_UP(img_data.ramdisk_size, 1024));
diff --git a/include/image.h b/include/image.h
index a1a14403d5..ac94ecaa14 100644
--- a/include/image.h
+++ b/include/image.h
@@ -1742,8 +1742,8 @@  struct andr_boot_img_hdr_v0;
 int android_image_get_kernel(const struct andr_boot_img_hdr_v0 *hdr,
 			     const void *vendor_boot_img, int verify,
 			     ulong *os_data, ulong *os_len);
-int android_image_get_ramdisk(const struct andr_boot_img_hdr_v0 *hdr,
-			      const void *vendor_boot_img, ulong *rd_data, ulong *rd_len);
+int android_image_get_ramdisk(const void *hdr, const void *vendor_boot_img,
+			      ulong *rd_data, ulong *rd_len);
 int android_image_get_second(const struct andr_boot_img_hdr_v0 *hdr,
 			      ulong *second_data, ulong *second_len);
 bool android_image_get_dtbo(ulong hdr_addr, ulong *addr, u32 *size);