All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/17] Support android boot image v3/v4
@ 2022-11-26 16:59 Safae Ouajih
  2022-11-26 16:59 ` [PATCH 01/17] android: boot: rename andr_img_hdr -> andr_boot_img_hdr_v0_v1_v2 Safae Ouajih
                   ` (19 more replies)
  0 siblings, 20 replies; 28+ messages in thread
From: Safae Ouajih @ 2022-11-26 16:59 UTC (permalink / raw)
  To: sjg; +Cc: u-boot, sean.anderson, r.stratiienko, mkorpershoek, glaroque, khilman

Hello everyone,

* This is based on Roman Stratiienko's work to support boot image header version 3 and 4.

* This supports the new boot image headers v3, v4 and bootconfig feature.
https://source.android.com/docs/core/architecture/bootloader/boot-image-header
https://source.android.com/docs/core/architecture/bootloader/implementing-bootconfig

- Tested on Amlogic Khadas vim3l, a reference board for Android Open Source Project
  https://www.khadas.com/vim3l

  And on AM625 Texas Instruments board with 5.10 linux kernel

Main changes :
- New partition : vendor boot, with a specific vendor ramdisk
- DTB is stored in the vendor boot partition
- The generic ramdisk is placed after the vendor ramdisk
- Bootconfig feature support


Here is a link to see the related android boot flow changes on KHADAS vim3l as an example:
https://gitlab.baylibre.com/baylibre/amlogic/atv/u-boot/-/commits/souajih/BootImagev4/

Safae Ouajih (17):
  android: boot: rename andr_img_hdr -> andr_boot_img_hdr_v0_v1_v2
  android: boot: support vendor boot image in abootimg
  android: boot: replace android_image_check_header
  android: boot: add boot image header v3 and v4 structures
  android: boot: add documentation for boot image header v3/v4 structure
  android: boot: kcomp: support andr_image_data
  android: boot: move to andr_image_data structure
  android: boot: content print is not supported for v3,v4 header version
  android: boot: boot image header v3,v4 do not support recovery DTBO
  android: boot: add vendor boot image to prepare for v3,v4 support
  android: boot: update android_image_get_data to support v3,v4
  android: boot: ramdisk: support vendor ramdisk
  android: boot: support extra command line
  drivers: fastboot: zImage flashing is not supported for v3,v4
  android: boot: support boot image header version 3 and 4
  lib: support libxbc
  android: boot: support bootconfig

 boot/bootm.c              |  29 ++-
 boot/image-android.c      | 367 ++++++++++++++++++++++++++++++--------
 boot/image-board.c        |  15 +-
 boot/image-fdt.c          |   5 +-
 cmd/abootimg.c            |  66 ++++---
 drivers/fastboot/fb_mmc.c |  19 +-
 include/android_image.h   | 220 ++++++++++++++++++++++-
 include/image.h           |  37 ++--
 include/xbc.h             |   1 +
 lib/Kconfig               |  12 ++
 lib/Makefile              |   1 +
 lib/libxbc/Makefile       |   1 +
 lib/libxbc/libxbc.c       | 112 ++++++++++++
 lib/libxbc/libxbc.h       |  54 ++++++
 14 files changed, 806 insertions(+), 133 deletions(-)
 create mode 100644 include/xbc.h
 create mode 100644 lib/libxbc/Makefile
 create mode 100644 lib/libxbc/libxbc.c
 create mode 100644 lib/libxbc/libxbc.h

--
2.25.1


^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 01/17] android: boot: rename andr_img_hdr -> andr_boot_img_hdr_v0_v1_v2
  2022-11-26 16:59 [PATCH 00/17] Support android boot image v3/v4 Safae Ouajih
@ 2022-11-26 16:59 ` Safae Ouajih
  2022-11-28 16:08   ` Sean Anderson
  2022-11-26 16:59 ` [PATCH 02/17] android: boot: support vendor boot image in abootimg Safae Ouajih
                   ` (18 subsequent siblings)
  19 siblings, 1 reply; 28+ messages in thread
From: Safae Ouajih @ 2022-11-26 16:59 UTC (permalink / raw)
  To: sjg; +Cc: u-boot, sean.anderson, r.stratiienko, mkorpershoek, glaroque, khilman

Android introduced boot header version 3 or 4.
The header structure change with version 3 and 4 to support
the new updates such as:
- Introducing Vendor boot image: with a vendor ramdisk
- Bootconfig feature (v4)

To maintain support for version v0, v1 and v2 while introducing
version 3 and 4, this struct name must change to refer to the header
structure before v3.

Signed-off-by: Safae Ouajih <souajih@baylibre.com>
---
 boot/image-android.c      | 26 +++++++++++++-------------
 boot/image-fdt.c          |  2 +-
 cmd/abootimg.c            |  4 ++--
 drivers/fastboot/fb_mmc.c |  8 ++++----
 include/android_image.h   |  4 ++--
 include/image.h           | 18 +++++++++---------
 6 files changed, 31 insertions(+), 31 deletions(-)

diff --git a/boot/image-android.c b/boot/image-android.c
index 2628db374121..926d94ecbe8e 100644
--- a/boot/image-android.c
+++ b/boot/image-android.c
@@ -18,7 +18,7 @@
 
 static char andr_tmp_str[ANDR_BOOT_ARGS_SIZE + 1];
 
-static ulong android_image_get_kernel_addr(const struct andr_img_hdr *hdr)
+static ulong android_image_get_kernel_addr(const struct andr_boot_img_hdr_v0_v1_v2 *hdr)
 {
 	/*
 	 * All the Android tools that generate a boot.img use this
@@ -59,7 +59,7 @@ static ulong android_image_get_kernel_addr(const struct andr_img_hdr *hdr)
  * Return: Zero, os start address and length on success,
  *		otherwise on failure.
  */
-int android_image_get_kernel(const struct andr_img_hdr *hdr, int verify,
+int android_image_get_kernel(const struct andr_boot_img_hdr_v0_v1_v2 *hdr, int verify,
 			     ulong *os_data, ulong *os_len)
 {
 	u32 kernel_addr = android_image_get_kernel_addr(hdr);
@@ -122,12 +122,12 @@ int android_image_get_kernel(const struct andr_img_hdr *hdr, int verify,
 	return 0;
 }
 
-int android_image_check_header(const struct andr_img_hdr *hdr)
+int android_image_check_header(const struct andr_boot_img_hdr_v0_v1_v2 *hdr)
 {
 	return memcmp(ANDR_BOOT_MAGIC, hdr->magic, ANDR_BOOT_MAGIC_SIZE);
 }
 
-ulong android_image_get_end(const struct andr_img_hdr *hdr)
+ulong android_image_get_end(const struct andr_boot_img_hdr_v0_v1_v2 *hdr)
 {
 	ulong end;
 
@@ -150,12 +150,12 @@ ulong android_image_get_end(const struct andr_img_hdr *hdr)
 	return end;
 }
 
-ulong android_image_get_kload(const struct andr_img_hdr *hdr)
+ulong android_image_get_kload(const struct andr_boot_img_hdr_v0_v1_v2 *hdr)
 {
 	return android_image_get_kernel_addr(hdr);
 }
 
-ulong android_image_get_kcomp(const struct andr_img_hdr *hdr)
+ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0_v1_v2 *hdr)
 {
 	const void *p = (void *)((uintptr_t)hdr + hdr->page_size);
 
@@ -167,7 +167,7 @@ ulong android_image_get_kcomp(const struct andr_img_hdr *hdr)
 		return image_decomp_type(p, sizeof(u32));
 }
 
-int android_image_get_ramdisk(const struct andr_img_hdr *hdr,
+int android_image_get_ramdisk(const struct andr_boot_img_hdr_v0_v1_v2 *hdr,
 			      ulong *rd_data, ulong *rd_len)
 {
 	if (!hdr->ramdisk_size) {
@@ -186,7 +186,7 @@ int android_image_get_ramdisk(const struct andr_img_hdr *hdr,
 	return 0;
 }
 
-int android_image_get_second(const struct andr_img_hdr *hdr,
+int android_image_get_second(const struct andr_boot_img_hdr_v0_v1_v2 *hdr,
 			      ulong *second_data, ulong *second_len)
 {
 	if (!hdr->second_size) {
@@ -226,7 +226,7 @@ int android_image_get_second(const struct andr_img_hdr *hdr,
  */
 bool android_image_get_dtbo(ulong hdr_addr, ulong *addr, u32 *size)
 {
-	const struct andr_img_hdr *hdr;
+	const struct andr_boot_img_hdr_v0_v1_v2 *hdr;
 	ulong dtbo_img_addr;
 	bool ret = true;
 
@@ -275,7 +275,7 @@ exit:
  */
 static bool android_image_get_dtb_img_addr(ulong hdr_addr, ulong *addr)
 {
-	const struct andr_img_hdr *hdr;
+	const struct andr_boot_img_hdr_v0_v1_v2 *hdr;
 	ulong dtb_img_addr;
 	bool ret = true;
 
@@ -328,7 +328,7 @@ exit:
 bool android_image_get_dtb_by_index(ulong hdr_addr, u32 index, ulong *addr,
 				    u32 *size)
 {
-	const struct andr_img_hdr *hdr;
+	const struct andr_boot_img_hdr_v0_v1_v2 *hdr;
 	bool res;
 	ulong dtb_img_addr;	/* address of DTB part in boot image */
 	u32 dtb_img_size;	/* size of DTB payload in boot image */
@@ -393,7 +393,7 @@ bool android_image_get_dtb_by_index(ulong hdr_addr, u32 index, ulong *addr,
  * returns:
  *     no returned results
  */
-void android_print_contents(const struct andr_img_hdr *hdr)
+void android_print_contents(const struct andr_boot_img_hdr_v0_v1_v2 *hdr)
 {
 	const char * const p = IMAGE_INDENT_STRING;
 	/* os_version = ver << 11 | lvl */
@@ -485,7 +485,7 @@ static bool android_image_print_dtb_info(const struct fdt_header *fdt,
  */
 bool android_image_print_dtb_contents(ulong hdr_addr)
 {
-	const struct andr_img_hdr *hdr;
+	const struct andr_boot_img_hdr_v0_v1_v2 *hdr;
 	bool res;
 	ulong dtb_img_addr;	/* address of DTB part in boot image */
 	u32 dtb_img_size;	/* size of DTB payload in boot image */
diff --git a/boot/image-fdt.c b/boot/image-fdt.c
index b830a0ab4187..b7cc9bfd538f 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_img_hdr *hdr = buf;
+		struct andr_boot_img_hdr_v0_v1_v2 *hdr = buf;
 		ulong		fdt_data, fdt_len;
 		u32			fdt_size, dtb_idx;
 		/*
diff --git a/cmd/abootimg.c b/cmd/abootimg.c
index f48a9dcb021d..de2aa3307d9a 100644
--- a/cmd/abootimg.c
+++ b/cmd/abootimg.c
@@ -18,7 +18,7 @@ static ulong _abootimg_addr = -1;
 
 static int abootimg_get_ver(int argc, char *const argv[])
 {
-	const struct andr_img_hdr *hdr;
+	const struct andr_boot_img_hdr_v0_v1_v2 *hdr;
 	int res = CMD_RET_SUCCESS;
 
 	if (argc > 1)
@@ -65,7 +65,7 @@ static int abootimg_get_recovery_dtbo(int argc, char *const argv[])
 
 static int abootimg_get_dtb_load_addr(int argc, char *const argv[])
 {
-	const struct andr_img_hdr *hdr;
+	const struct andr_boot_img_hdr_v0_v1_v2 *hdr;
 	int res = CMD_RET_SUCCESS;
 
 	if (argc > 1)
diff --git a/drivers/fastboot/fb_mmc.c b/drivers/fastboot/fb_mmc.c
index 033c510bc096..7b2f964b4c72 100644
--- a/drivers/fastboot/fb_mmc.c
+++ b/drivers/fastboot/fb_mmc.c
@@ -287,7 +287,7 @@ static void fb_mmc_boot_ops(struct blk_desc *dev_desc, void *buffer,
  */
 static lbaint_t fb_mmc_get_boot_header(struct blk_desc *dev_desc,
 				       struct disk_partition *info,
-				       struct andr_img_hdr *hdr,
+				       struct andr_boot_img_hdr_v0_v1_v2 *hdr,
 				       char *response)
 {
 	ulong sector_size;		/* boot partition sector size */
@@ -296,7 +296,7 @@ static lbaint_t fb_mmc_get_boot_header(struct blk_desc *dev_desc,
 
 	/* Calculate boot image sectors count */
 	sector_size = info->blksz;
-	hdr_sectors = DIV_ROUND_UP(sizeof(struct andr_img_hdr), sector_size);
+	hdr_sectors = DIV_ROUND_UP(sizeof(struct andr_boot_img_hdr_v0_v1_v2), sector_size);
 	if (hdr_sectors == 0) {
 		pr_err("invalid number of boot sectors: 0\n");
 		fastboot_fail("invalid number of boot sectors: 0", response);
@@ -338,7 +338,7 @@ static int fb_mmc_update_zimage(struct blk_desc *dev_desc,
 				char *response)
 {
 	uintptr_t hdr_addr;			/* boot image header address */
-	struct andr_img_hdr *hdr;		/* boot image header */
+	struct andr_boot_img_hdr_v0_v1_v2 *hdr;		/* boot image header */
 	lbaint_t hdr_sectors;			/* boot image header sectors */
 	u8 *ramdisk_buffer;
 	u32 ramdisk_sector_start;
@@ -361,7 +361,7 @@ static int fb_mmc_update_zimage(struct blk_desc *dev_desc,
 
 	/* Put boot image header in fastboot buffer after downloaded zImage */
 	hdr_addr = (uintptr_t)download_buffer + ALIGN(download_bytes, PAGE_SIZE);
-	hdr = (struct andr_img_hdr *)hdr_addr;
+	hdr = (struct andr_boot_img_hdr_v0_v1_v2 *)hdr_addr;
 
 	/* Read boot image header */
 	hdr_sectors = fb_mmc_get_boot_header(dev_desc, &info, hdr, response);
diff --git a/include/android_image.h b/include/android_image.h
index 54d25af0684a..bf9b8c6f0955 100644
--- a/include/android_image.h
+++ b/include/android_image.h
@@ -20,9 +20,9 @@
 #define ANDR_BOOT_ARGS_SIZE 512
 #define ANDR_BOOT_EXTRA_ARGS_SIZE 1024
 
-/* The bootloader expects the structure of andr_img_hdr with header
+/* The bootloader expects the structure of andr_boot_img_hdr_v0_v1_v2 with header
  * version 0 to be as follows: */
-struct andr_img_hdr {
+struct andr_boot_img_hdr_v0_v1_v2 {
     /* Must be ANDR_BOOT_MAGIC. */
     char magic[ANDR_BOOT_MAGIC_SIZE];
 
diff --git a/include/image.h b/include/image.h
index 6f21dafba8ce..931cf18c7e82 100644
--- a/include/image.h
+++ b/include/image.h
@@ -1723,21 +1723,21 @@ int fit_image_cipher_get_algo(const void *fit, int noffset, char **algo);
 
 struct cipher_algo *image_get_cipher_algo(const char *full_name);
 
-struct andr_img_hdr;
-int android_image_check_header(const struct andr_img_hdr *hdr);
-int android_image_get_kernel(const struct andr_img_hdr *hdr, int verify,
+struct andr_boot_img_hdr_v0_v1_v2;
+int android_image_check_header(const struct andr_boot_img_hdr_v0_v1_v2 *hdr);
+int android_image_get_kernel(const struct andr_boot_img_hdr_v0_v1_v2 *hdr, int verify,
 			     ulong *os_data, ulong *os_len);
-int android_image_get_ramdisk(const struct andr_img_hdr *hdr,
+int android_image_get_ramdisk(const struct andr_boot_img_hdr_v0_v1_v2 *hdr,
 			      ulong *rd_data, ulong *rd_len);
-int android_image_get_second(const struct andr_img_hdr *hdr,
+int android_image_get_second(const struct andr_boot_img_hdr_v0_v1_v2 *hdr,
 			      ulong *second_data, ulong *second_len);
 bool android_image_get_dtbo(ulong hdr_addr, ulong *addr, u32 *size);
 bool android_image_get_dtb_by_index(ulong hdr_addr, u32 index, ulong *addr,
 				    u32 *size);
-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);
+ulong android_image_get_end(const struct andr_boot_img_hdr_v0_v1_v2 *hdr);
+ulong android_image_get_kload(const struct andr_boot_img_hdr_v0_v1_v2 *hdr);
+ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0_v1_v2 *hdr);
+void android_print_contents(const struct andr_boot_img_hdr_v0_v1_v2 *hdr);
 bool android_image_print_dtb_contents(ulong hdr_addr);
 
 /**
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 02/17] android: boot: support vendor boot image in abootimg
  2022-11-26 16:59 [PATCH 00/17] Support android boot image v3/v4 Safae Ouajih
  2022-11-26 16:59 ` [PATCH 01/17] android: boot: rename andr_img_hdr -> andr_boot_img_hdr_v0_v1_v2 Safae Ouajih
@ 2022-11-26 16:59 ` Safae Ouajih
  2022-11-26 16:59 ` [PATCH 03/17] android: boot: replace android_image_check_header Safae Ouajih
                   ` (17 subsequent siblings)
  19 siblings, 0 replies; 28+ messages in thread
From: Safae Ouajih @ 2022-11-26 16:59 UTC (permalink / raw)
  To: sjg; +Cc: u-boot, sean.anderson, r.stratiienko, mkorpershoek, glaroque, khilman

Vendor boot image is introduced in boot image header
version 3 and 4. Please check [1] for more details.

To prepare for boot image v3/v4 support, allow the abootimg command
to store the vendor_boot image address.

Full support for this new format will be done in a future patch.

[1] https://source.android.com/docs/core/architecture/bootloader/partitions/vendor-boot-partitions

Signed-off-by: Safae Ouajih <souajih@baylibre.com>
---
 cmd/abootimg.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/cmd/abootimg.c b/cmd/abootimg.c
index de2aa3307d9a..ad61cce7588d 100644
--- a/cmd/abootimg.c
+++ b/cmd/abootimg.c
@@ -15,6 +15,7 @@
 
 /* Please use abootimg_addr() macro to obtain the boot image address */
 static ulong _abootimg_addr = -1;
+static ulong _avendor_bootimg_addr = -1;
 
 static int abootimg_get_ver(int argc, char *const argv[])
 {
@@ -158,7 +159,7 @@ static int do_abootimg_addr(struct cmd_tbl *cmdtp, int flag, int argc,
 	char *endp;
 	ulong img_addr;
 
-	if (argc != 2)
+	if (argc < 2 || argc > 3)
 		return CMD_RET_USAGE;
 
 	img_addr = hextoul(argv[1], &endp);
@@ -168,6 +169,17 @@ static int do_abootimg_addr(struct cmd_tbl *cmdtp, int flag, int argc,
 	}
 
 	_abootimg_addr = img_addr;
+
+	if (argc == 3) {
+		img_addr = simple_strtoul(argv[2], &endp, 16);
+		if (*endp != '\0') {
+			printf("Error: Wrong vendor image address\n");
+			return CMD_RET_FAILURE;
+		}
+
+		_avendor_bootimg_addr = img_addr;
+	}
+
 	return CMD_RET_SUCCESS;
 }
 
@@ -211,7 +223,7 @@ static int do_abootimg_dump(struct cmd_tbl *cmdtp, int flag, int argc,
 }
 
 static struct cmd_tbl cmd_abootimg_sub[] = {
-	U_BOOT_CMD_MKENT(addr, 2, 1, do_abootimg_addr, "", ""),
+	U_BOOT_CMD_MKENT(addr, 3, 1, do_abootimg_addr, "", ""),
 	U_BOOT_CMD_MKENT(dump, 2, 1, do_abootimg_dump, "", ""),
 	U_BOOT_CMD_MKENT(get, 5, 1, do_abootimg_get, "", ""),
 };
@@ -239,7 +251,7 @@ static int do_abootimg(struct cmd_tbl *cmdtp, int flag, int argc,
 U_BOOT_CMD(
 	abootimg, CONFIG_SYS_MAXARGS, 0, do_abootimg,
 	"manipulate Android Boot Image",
-	"addr <addr>\n"
+	"addr <boot_img_addr> [<vendor_boot_img_addr>]>\n"
 	"    - set the address in RAM where boot image is located\n"
 	"      ($loadaddr is used by default)\n"
 	"abootimg dump dtb\n"
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 03/17] android: boot: replace android_image_check_header
  2022-11-26 16:59 [PATCH 00/17] Support android boot image v3/v4 Safae Ouajih
  2022-11-26 16:59 ` [PATCH 01/17] android: boot: rename andr_img_hdr -> andr_boot_img_hdr_v0_v1_v2 Safae Ouajih
  2022-11-26 16:59 ` [PATCH 02/17] android: boot: support vendor boot image in abootimg Safae Ouajih
@ 2022-11-26 16:59 ` Safae Ouajih
  2022-11-26 16:59 ` [PATCH 04/17] android: boot: add boot image header v3 and v4 structures Safae Ouajih
                   ` (16 subsequent siblings)
  19 siblings, 0 replies; 28+ messages in thread
From: Safae Ouajih @ 2022-11-26 16:59 UTC (permalink / raw)
  To: sjg; +Cc: u-boot, sean.anderson, r.stratiienko, mkorpershoek, glaroque, khilman

With the new vendor boot image introduced in versions 3 and 4
of boot image header, the header check must be done for both boot
image and vendor boot image. Thus, android_image_check_header() is
being replaced by is_android_boot_image_header() to only refer to
boot image header check.

Signed-off-by: Safae Ouajih <souajih@baylibre.com>
---
 boot/image-android.c      | 8 ++++----
 boot/image-board.c        | 2 +-
 cmd/abootimg.c            | 4 ++--
 drivers/fastboot/fb_mmc.c | 3 +--
 include/image.h           | 2 +-
 5 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/boot/image-android.c b/boot/image-android.c
index 926d94ecbe8e..c67949b8b563 100644
--- a/boot/image-android.c
+++ b/boot/image-android.c
@@ -122,9 +122,9 @@ int android_image_get_kernel(const struct andr_boot_img_hdr_v0_v1_v2 *hdr, int v
 	return 0;
 }
 
-int android_image_check_header(const struct andr_boot_img_hdr_v0_v1_v2 *hdr)
+bool is_android_boot_image_header(const struct andr_boot_img_hdr_v0_v1_v2 *hdr)
 {
-	return memcmp(ANDR_BOOT_MAGIC, hdr->magic, ANDR_BOOT_MAGIC_SIZE);
+	return !memcmp(ANDR_BOOT_MAGIC, hdr, ANDR_BOOT_MAGIC_SIZE);
 }
 
 ulong android_image_get_end(const struct andr_boot_img_hdr_v0_v1_v2 *hdr)
@@ -231,7 +231,7 @@ bool android_image_get_dtbo(ulong hdr_addr, ulong *addr, u32 *size)
 	bool ret = true;
 
 	hdr = map_sysmem(hdr_addr, sizeof(*hdr));
-	if (android_image_check_header(hdr)) {
+	if (!is_android_boot_image_header(hdr)) {
 		printf("Error: Boot Image header is incorrect\n");
 		ret = false;
 		goto exit;
@@ -280,7 +280,7 @@ static bool android_image_get_dtb_img_addr(ulong hdr_addr, ulong *addr)
 	bool ret = true;
 
 	hdr = map_sysmem(hdr_addr, sizeof(*hdr));
-	if (android_image_check_header(hdr)) {
+	if (!is_android_boot_image_header(hdr)) {
 		printf("Error: Boot Image header is incorrect\n");
 		ret = false;
 		goto exit;
diff --git a/boot/image-board.c b/boot/image-board.c
index 34d1e5f18bef..acbaafc1b12e 100644
--- a/boot/image-board.c
+++ b/boot/image-board.c
@@ -284,7 +284,7 @@ int genimg_get_format(const void *img_addr)
 			return IMAGE_FORMAT_FIT;
 	}
 	if (IS_ENABLED(CONFIG_ANDROID_BOOT_IMAGE) &&
-	    !android_image_check_header(img_addr))
+	    is_android_boot_image_header(img_addr))
 		return IMAGE_FORMAT_ANDROID;
 
 	return IMAGE_FORMAT_INVALID;
diff --git a/cmd/abootimg.c b/cmd/abootimg.c
index ad61cce7588d..3c344b6c0367 100644
--- a/cmd/abootimg.c
+++ b/cmd/abootimg.c
@@ -26,7 +26,7 @@ static int abootimg_get_ver(int argc, char *const argv[])
 		return CMD_RET_USAGE;
 
 	hdr = map_sysmem(abootimg_addr(), sizeof(*hdr));
-	if (android_image_check_header(hdr)) {
+	if (!is_android_boot_image_header(hdr)) {
 		printf("Error: Boot Image header is incorrect\n");
 		res = CMD_RET_FAILURE;
 		goto exit;
@@ -73,7 +73,7 @@ static int abootimg_get_dtb_load_addr(int argc, char *const argv[])
 		return CMD_RET_USAGE;
 
 	hdr = map_sysmem(abootimg_addr(), sizeof(*hdr));
-	if (android_image_check_header(hdr)) {
+	if (!is_android_boot_image_header(hdr)) {
 		printf("Error: Boot Image header is incorrect\n");
 		res = CMD_RET_FAILURE;
 		goto exit;
diff --git a/drivers/fastboot/fb_mmc.c b/drivers/fastboot/fb_mmc.c
index 7b2f964b4c72..4cfdc108e8f7 100644
--- a/drivers/fastboot/fb_mmc.c
+++ b/drivers/fastboot/fb_mmc.c
@@ -313,8 +313,7 @@ static lbaint_t fb_mmc_get_boot_header(struct blk_desc *dev_desc,
 	}
 
 	/* Check boot header magic string */
-	res = android_image_check_header(hdr);
-	if (res != 0) {
+	if (!is_android_boot_image_header(hdr)) {
 		pr_err("bad boot image magic\n");
 		fastboot_fail("boot partition not initialized", response);
 		return 0;
diff --git a/include/image.h b/include/image.h
index 931cf18c7e82..e175c920d3fb 100644
--- a/include/image.h
+++ b/include/image.h
@@ -1724,7 +1724,6 @@ int fit_image_cipher_get_algo(const void *fit, int noffset, char **algo);
 struct cipher_algo *image_get_cipher_algo(const char *full_name);
 
 struct andr_boot_img_hdr_v0_v1_v2;
-int android_image_check_header(const struct andr_boot_img_hdr_v0_v1_v2 *hdr);
 int android_image_get_kernel(const struct andr_boot_img_hdr_v0_v1_v2 *hdr, int verify,
 			     ulong *os_data, ulong *os_len);
 int android_image_get_ramdisk(const struct andr_boot_img_hdr_v0_v1_v2 *hdr,
@@ -1739,6 +1738,7 @@ ulong android_image_get_kload(const struct andr_boot_img_hdr_v0_v1_v2 *hdr);
 ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0_v1_v2 *hdr);
 void android_print_contents(const struct andr_boot_img_hdr_v0_v1_v2 *hdr);
 bool android_image_print_dtb_contents(ulong hdr_addr);
+bool is_android_boot_image_header(const struct andr_boot_img_hdr_v0_v1_v2 *hdr);
 
 /**
  * board_fit_config_name_match() - Check for a matching board name
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 04/17] android: boot: add boot image header v3 and v4 structures
  2022-11-26 16:59 [PATCH 00/17] Support android boot image v3/v4 Safae Ouajih
                   ` (2 preceding siblings ...)
  2022-11-26 16:59 ` [PATCH 03/17] android: boot: replace android_image_check_header Safae Ouajih
@ 2022-11-26 16:59 ` Safae Ouajih
  2022-11-26 16:59 ` [PATCH 05/17] android: boot: add documentation for boot image header v3/v4 structure Safae Ouajih
                   ` (15 subsequent siblings)
  19 siblings, 0 replies; 28+ messages in thread
From: Safae Ouajih @ 2022-11-26 16:59 UTC (permalink / raw)
  To: sjg; +Cc: u-boot, sean.anderson, r.stratiienko, mkorpershoek, glaroque, khilman

This adds support for v3/v4 boot image format by adding
the following structures:

- andr_boot_img_hdr_v3_v4 : describes boot image header
- andr_vendor_boot_img_hdr_v3_v4 : describes vendor boot image header

These definitions have been copied over from the AOSP documentation at
[1] and [2]

Boot arg sizes are taken from [3]:
`35fb6262bc3fe2280c37047a92d79953789760e5`

[1] https://source.android.com/docs/core/architecture/bootloader/boot-image-header
[2] https://source.android.com/docs/core/architecture/bootloader/partitions/vendor-boot-partitions#vendor-boot-header
[3] https://android.googlesource.com/platform/external/u-boot

Signed-off-by: Safae Ouajih <souajih@baylibre.com>
---
 include/android_image.h | 47 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/include/android_image.h b/include/android_image.h
index bf9b8c6f0955..ec36e6512ad6 100644
--- a/include/android_image.h
+++ b/include/android_image.h
@@ -14,11 +14,58 @@
 #include <linux/compiler.h>
 #include <linux/types.h>
 
+#define ANDR_GKI_PAGE_SIZE 4096
 #define ANDR_BOOT_MAGIC "ANDROID!"
 #define ANDR_BOOT_MAGIC_SIZE 8
 #define ANDR_BOOT_NAME_SIZE 16
 #define ANDR_BOOT_ARGS_SIZE 512
 #define ANDR_BOOT_EXTRA_ARGS_SIZE 1024
+#define VENDOR_BOOT_MAGIC "VNDRBOOT"
+#define ANDR_VENDOR_BOOT_MAGIC_SIZE 8
+#define ANDR_VENDOR_BOOT_ARGS_SIZE 2048
+#define ANDR_VENDOR_BOOT_NAME_SIZE 16
+
+struct andr_boot_img_hdr_v3_v4 {
+	u8 magic[ANDR_BOOT_MAGIC_SIZE];
+
+	u32 kernel_size;    /* size in bytes */
+	u32 ramdisk_size;   /* size in bytes */
+
+	u32 os_version;
+
+	u32 header_size;    /* size of boot image header in bytes */
+	u32 reserved[4];
+	u32 header_version; /* offset remains constant for version check */
+
+	u8 cmdline[ANDR_BOOT_ARGS_SIZE + ANDR_BOOT_EXTRA_ARGS_SIZE];
+	/* for boot image header v4 only */
+	u32 signature_size; /* size in bytes */
+};
+
+struct andr_vendor_boot_img_hdr_v3_v4 {
+	u8 magic[ANDR_VENDOR_BOOT_MAGIC_SIZE];
+	u32 header_version;
+	u32 page_size;           /* flash page size we assume */
+
+	u32 kernel_addr;         /* physical load addr */
+	u32 ramdisk_addr;        /* physical load addr */
+
+	u32 vendor_ramdisk_size; /* size in bytes */
+
+	u8 cmdline[ANDR_VENDOR_BOOT_ARGS_SIZE];
+
+	u32 tags_addr;           /* physical addr for kernel tags */
+
+	u8 name[ANDR_VENDOR_BOOT_NAME_SIZE]; /* asciiz product name */
+	u32 header_size;         /* size of vendor boot image header in bytes */
+	u32 dtb_size;            /* size of dtb image */
+	u64 dtb_addr;            /* physical load address */
+	/* for boot image header v4 only */
+	u32 vendor_ramdisk_table_size; /* size in bytes for the vendor ramdisk table */
+	u32 vendor_ramdisk_table_entry_num; /* number of entries in the vendor ramdisk table */
+	u32 vendor_ramdisk_table_entry_size; /* size in bytes for a vendor ramdisk table entry */
+	u32 bootconfig_size; /* size in bytes for the bootconfig section */
+};
 
 /* The bootloader expects the structure of andr_boot_img_hdr_v0_v1_v2 with header
  * version 0 to be as follows: */
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 05/17] android: boot: add documentation for boot image header v3/v4 structure
  2022-11-26 16:59 [PATCH 00/17] Support android boot image v3/v4 Safae Ouajih
                   ` (3 preceding siblings ...)
  2022-11-26 16:59 ` [PATCH 04/17] android: boot: add boot image header v3 and v4 structures Safae Ouajih
@ 2022-11-26 16:59 ` Safae Ouajih
  2022-11-28 16:12   ` Sean Anderson
  2022-11-26 16:59 ` [PATCH 06/17] android: boot: kcomp: support andr_image_data Safae Ouajih
                   ` (14 subsequent siblings)
  19 siblings, 1 reply; 28+ messages in thread
From: Safae Ouajih @ 2022-11-26 16:59 UTC (permalink / raw)
  To: sjg; +Cc: u-boot, sean.anderson, r.stratiienko, mkorpershoek, glaroque, khilman

This was imported from [1], commit [2], file: include/bootimg/bootimg.h
[1] https://android.googlesource.com/platform/system/tools/mkbootimg
[2] cce5b1923e3cd2fcb765b512610bdc5c42bc501d

Signed-off-by: Safae Ouajih <souajih@baylibre.com>
---
 include/android_image.h | 136 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 135 insertions(+), 1 deletion(-)

diff --git a/include/android_image.h b/include/android_image.h
index ec36e6512ad6..62121e2a109b 100644
--- a/include/android_image.h
+++ b/include/android_image.h
@@ -3,7 +3,7 @@
  * This is from the Android Project,
  * Repository: https://android.googlesource.com/platform/system/tools/mkbootimg
  * File: include/bootimg/bootimg.h
- * Commit: e55998a0f2b61b685d5eb4a486ca3a0c680b1a2f
+ * Commit: cce5b1923e3cd2fcb765b512610bdc5c42bc501d
  *
  * Copyright (C) 2007 The Android Open Source Project
  */
@@ -183,4 +183,138 @@ struct andr_boot_img_hdr_v0_v1_v2 {
  *    else: jump to kernel_addr
  */
 
+/* When the boot image header has a version of 3, the structure of the boot
+ * image is as follows:
+ *
+ * +---------------------+
+ * | boot header         | 4096 bytes
+ * +---------------------+
+ * | kernel              | m pages
+ * +---------------------+
+ * | ramdisk             | n pages
+ * +---------------------+
+ *
+ * m = (kernel_size + 4096 - 1) / 4096
+ * n = (ramdisk_size + 4096 - 1) / 4096
+ *
+ * Note that in version 3 of the boot image header, page size is fixed at 4096 bytes.
+ *
+ * The structure of the vendor boot image (introduced with version 3 and
+ * required to be present when a v3 boot image is used) is as follows:
+ *
+ * +---------------------+
+ * | vendor boot header  | o pages
+ * +---------------------+
+ * | vendor ramdisk      | p pages
+ * +---------------------+
+ * | dtb                 | q pages
+ * +---------------------+
+ * o = (2112 + page_size - 1) / page_size
+ * p = (vendor_ramdisk_size + page_size - 1) / page_size
+ * q = (dtb_size + page_size - 1) / page_size
+ *
+ * 0. all entities in the boot image are 4096-byte aligned in flash, all
+ *    entities in the vendor boot image are page_size (determined by the vendor
+ *    and specified in the vendor boot image header) aligned in flash
+ * 1. kernel, ramdisk, vendor ramdisk, and DTB are required (size != 0)
+ * 2. load the kernel and DTB at the specified physical address (kernel_addr,
+ *    dtb_addr)
+ * 3. load the vendor ramdisk at ramdisk_addr
+ * 4. load the generic ramdisk immediately following the vendor ramdisk in
+ *    memory
+ * 5. set up registers for kernel entry as required by your architecture
+ * 6. if the platform has a second stage bootloader jump to it (must be
+ *    contained outside boot and vendor boot partitions), otherwise
+ *    jump to kernel_addr
+ */
+
+/* When the boot image header has a version of 4, the structure of the boot
+ * image is as follows:
+ *
+ * +---------------------+
+ * | boot header         | 4096 bytes
+ * +---------------------+
+ * | kernel              | m pages
+ * +---------------------+
+ * | ramdisk             | n pages
+ * +---------------------+
+ * | boot signature      | g pages
+ * +---------------------+
+ *
+ * m = (kernel_size + 4096 - 1) / 4096
+ * n = (ramdisk_size + 4096 - 1) / 4096
+ * g = (signature_size + 4096 - 1) / 4096
+ *
+ * Note that in version 4 of the boot image header, page size is fixed at 4096
+ * bytes.
+ *
+ * The structure of the vendor boot image version 4, which is required to be
+ * present when a version 4 boot image is used, is as follows:
+ *
+ * +------------------------+
+ * | vendor boot header     | o pages
+ * +------------------------+
+ * | vendor ramdisk section | p pages
+ * +------------------------+
+ * | dtb                    | q pages
+ * +------------------------+
+ * | vendor ramdisk table   | r pages
+ * +------------------------+
+ * | bootconfig             | s pages
+ * +------------------------+
+ *
+ * o = (2128 + page_size - 1) / page_size
+ * p = (vendor_ramdisk_size + page_size - 1) / page_size
+ * q = (dtb_size + page_size - 1) / page_size
+ * r = (vendor_ramdisk_table_size + page_size - 1) / page_size
+ * s = (vendor_bootconfig_size + page_size - 1) / page_size
+ *
+ * Note that in version 4 of the vendor boot image, multiple vendor ramdisks can
+ * be included in the vendor boot image. The bootloader can select a subset of
+ * ramdisks to load at runtime. To help the bootloader select the ramdisks, each
+ * ramdisk is tagged with a type tag and a set of hardware identifiers
+ * describing the board, soc or platform that this ramdisk is intended for.
+ *
+ * The vendor ramdisk section is consist of multiple ramdisk images concatenated
+ * one after another, and vendor_ramdisk_size is the size of the section, which
+ * is the total size of all the ramdisks included in the vendor boot image.
+ *
+ * The vendor ramdisk table holds the size, offset, type, name and hardware
+ * identifiers of each ramdisk. The type field denotes the type of its content.
+ * The vendor ramdisk names are unique. The hardware identifiers are specified
+ * in the board_id field in each table entry. The board_id field is consist of a
+ * vector of unsigned integer words, and the encoding scheme is defined by the
+ * hardware vendor.
+ *
+ * For the different type of ramdisks, there are:
+ *    - VENDOR_RAMDISK_TYPE_NONE indicates the value is unspecified.
+ *    - VENDOR_RAMDISK_TYPE_PLATFORM ramdisks contain platform specific bits, so
+ *      the bootloader should always load these into memory.
+ *    - VENDOR_RAMDISK_TYPE_RECOVERY ramdisks contain recovery resources, so
+ *      the bootloader should load these when booting into recovery.
+ *    - VENDOR_RAMDISK_TYPE_DLKM ramdisks contain dynamic loadable kernel
+ *      modules.
+ *
+ * Version 4 of the vendor boot image also adds a bootconfig section to the end
+ * of the image. This section contains Boot Configuration parameters known at
+ * build time. The bootloader is responsible for placing this section directly
+ * after the generic ramdisk, followed by the bootconfig trailer, before
+ * entering the kernel.
+ *
+ * 0. all entities in the boot image are 4096-byte aligned in flash, all
+ *    entities in the vendor boot image are page_size (determined by the vendor
+ *    and specified in the vendor boot image header) aligned in flash
+ * 1. kernel, ramdisk, and DTB are required (size != 0)
+ * 2. load the kernel and DTB at the specified physical address (kernel_addr,
+ *    dtb_addr)
+ * 3. load the vendor ramdisks at ramdisk_addr
+ * 4. load the generic ramdisk immediately following the vendor ramdisk in
+ *    memory
+ * 5. load the bootconfig immediately following the generic ramdisk. Add
+ *    additional bootconfig parameters followed by the bootconfig trailer.
+ * 6. set up registers for kernel entry as required by your architecture
+ * 7. if the platform has a second stage bootloader jump to it (must be
+ *    contained outside boot and vendor boot partitions), otherwise
+ *    jump to kernel_addr
+ */
 #endif
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 06/17] android: boot: kcomp: support andr_image_data
  2022-11-26 16:59 [PATCH 00/17] Support android boot image v3/v4 Safae Ouajih
                   ` (4 preceding siblings ...)
  2022-11-26 16:59 ` [PATCH 05/17] android: boot: add documentation for boot image header v3/v4 structure Safae Ouajih
@ 2022-11-26 16:59 ` Safae Ouajih
  2022-11-26 16:59 ` [PATCH 07/17] android: boot: move to andr_image_data structure Safae Ouajih
                   ` (13 subsequent siblings)
  19 siblings, 0 replies; 28+ messages in thread
From: Safae Ouajih @ 2022-11-26 16:59 UTC (permalink / raw)
  To: sjg; +Cc: u-boot, sean.anderson, r.stratiienko, mkorpershoek, glaroque, khilman

andr_image_data structure is used as a global representation of
boot image header structure. This new structure is introduced to
support all boot header versions : v0,v1.v2.v3.v4 and will be used
to support v3 and v4 while maitaining support for v0,v1,v2. The need
of using andr_image_data comes from the change of header structure in
both version 3 and 4.

android_image_get_kcomp() is reworked to support this new struct.

Signed-off-by: Safae Ouajih <souajih@baylibre.com>
---
 boot/image-android.c    | 74 ++++++++++++++++++++++++++++++++++++++++-
 include/android_image.h | 27 +++++++++++++++
 include/image.h         |  2 ++
 3 files changed, 102 insertions(+), 1 deletion(-)

diff --git a/boot/image-android.c b/boot/image-android.c
index c67949b8b563..79d987a3b044 100644
--- a/boot/image-android.c
+++ b/boot/image-android.c
@@ -18,6 +18,73 @@
 
 static char andr_tmp_str[ANDR_BOOT_ARGS_SIZE + 1];
 
+static void android_boot_image_v0_v1_v2_parse_hdr(const struct andr_boot_img_hdr_v0_v1_v2 *hdr,
+						  struct andr_image_data *data)
+{
+	ulong end;
+
+	data->image_name = hdr->name;
+	data->kcmdline = hdr->cmdline;
+	data->kernel_addr = hdr->kernel_addr;
+	data->ramdisk_addr = hdr->ramdisk_addr;
+	data->header_version = hdr->header_version;
+
+	end = (ulong)hdr;
+
+	/*
+	 * The header takes a full page, the remaining components are aligned
+	 * on page boundary
+	 */
+
+	end += hdr->page_size;
+
+	data->kernel_ptr = end;
+	data->kernel_size = hdr->kernel_size;
+	end += ALIGN(hdr->kernel_size, hdr->page_size);
+
+	data->ramdisk_ptr = end;
+	data->ramdisk_size = hdr->ramdisk_size;
+	end += ALIGN(hdr->ramdisk_size, hdr->page_size);
+
+	data->second_ptr = end;
+	data->second_size = hdr->second_size;
+	end += ALIGN(hdr->second_size, hdr->page_size);
+
+	if (hdr->header_version >= 1) {
+		data->recovery_dtbo_ptr = end;
+		data->recovery_dtbo_size = hdr->recovery_dtbo_size;
+		end += ALIGN(hdr->recovery_dtbo_size, hdr->page_size);
+	}
+
+	if (hdr->header_version >= 2) {
+		data->dtb_ptr = end;
+		data->dtb_size = hdr->dtb_size;
+		end += ALIGN(hdr->dtb_size, hdr->page_size);
+	}
+
+	data->boot_img_total_size = end - (ulong)hdr;
+}
+
+bool android_image_get_data(const void *boot_hdr, struct andr_image_data *data)
+{
+	if (!boot_hdr || !data) {
+		printf("boot_hdr or data params can't be NULL\n");
+		return false;
+	}
+
+	if (!is_android_boot_image_header(boot_hdr)) {
+		printf("Incorrect boot image header\n");
+		return false;
+	}
+
+	if (((struct andr_boot_img_hdr_v0_v1_v2 *)boot_hdr)->header_version > 2)
+		printf("Only boot image header version 2 and below are supported\n");
+	else
+		android_boot_image_v0_v1_v2_parse_hdr(boot_hdr, data);
+
+	return true;
+}
+
 static ulong android_image_get_kernel_addr(const struct andr_boot_img_hdr_v0_v1_v2 *hdr)
 {
 	/*
@@ -157,8 +224,13 @@ ulong android_image_get_kload(const struct andr_boot_img_hdr_v0_v1_v2 *hdr)
 
 ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0_v1_v2 *hdr)
 {
-	const void *p = (void *)((uintptr_t)hdr + hdr->page_size);
+	struct andr_image_data img_data;
+	const void *p;
+
+	if (!android_image_get_data(hdr, &img_data))
+		return -EINVAL;
 
+	p = (const void *)img_data.kernel_ptr;
 	if (image_get_magic((struct legacy_img_hdr *)p) == IH_MAGIC)
 		return image_get_comp((struct legacy_img_hdr *)p);
 	else if (get_unaligned_le32(p) == LZ4F_MAGIC)
diff --git a/include/android_image.h b/include/android_image.h
index 62121e2a109b..98a91cbf2f9c 100644
--- a/include/android_image.h
+++ b/include/android_image.h
@@ -317,4 +317,31 @@ struct andr_boot_img_hdr_v0_v1_v2 {
  *    contained outside boot and vendor boot partitions), otherwise
  *    jump to kernel_addr
  */
+
+/* Private struct */
+struct andr_image_data {
+	ulong kernel_ptr;
+	u32 kernel_size;
+	u32 ramdisk_size;
+	u32 boot_ramdisk_size;
+	ulong second_ptr;
+	u32 second_size;
+	ulong dtb_ptr;
+	u32 dtb_size;
+	ulong recovery_dtbo_ptr;
+	u32 recovery_dtbo_size;
+
+	const char *kcmdline;
+	const char *kcmdline_extra;
+	const char *image_name;
+
+	u32 kernel_addr;
+	ulong ramdisk_addr;
+	ulong ramdisk_ptr;
+	ulong dtb_load_addr;
+	ulong tags_addr;
+	u32 header_version;
+	u32 boot_img_total_size;
+};
+
 #endif
diff --git a/include/image.h b/include/image.h
index e175c920d3fb..738ef54ce6d5 100644
--- a/include/image.h
+++ b/include/image.h
@@ -1722,7 +1722,9 @@ struct cipher_algo {
 int fit_image_cipher_get_algo(const void *fit, int noffset, char **algo);
 
 struct cipher_algo *image_get_cipher_algo(const char *full_name);
+struct andr_image_data;
 
+bool android_image_get_data(const void *boot_hdr, struct andr_image_data *data);
 struct andr_boot_img_hdr_v0_v1_v2;
 int android_image_get_kernel(const struct andr_boot_img_hdr_v0_v1_v2 *hdr, int verify,
 			     ulong *os_data, ulong *os_len);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 07/17] android: boot: move to andr_image_data structure
  2022-11-26 16:59 [PATCH 00/17] Support android boot image v3/v4 Safae Ouajih
                   ` (5 preceding siblings ...)
  2022-11-26 16:59 ` [PATCH 06/17] android: boot: kcomp: support andr_image_data Safae Ouajih
@ 2022-11-26 16:59 ` Safae Ouajih
  2022-11-26 16:59 ` [PATCH 08/17] android: boot: content print is not supported for v3, v4 header version Safae Ouajih
                   ` (12 subsequent siblings)
  19 siblings, 0 replies; 28+ messages in thread
From: Safae Ouajih @ 2022-11-26 16:59 UTC (permalink / raw)
  To: sjg; +Cc: u-boot, sean.anderson, r.stratiienko, mkorpershoek, glaroque, khilman

Move from andr_boot_img_hdr_v0_v1_v2 to andr_image_data
structure to prepare for boot image header
version 3 and 4.

Signed-off-by: Safae Ouajih <souajih@baylibre.com>
---
 boot/image-android.c | 124 +++++++++++++++++++++++--------------------
 cmd/abootimg.c       |  30 +++++------
 include/image.h      |   2 +
 3 files changed, 82 insertions(+), 74 deletions(-)

diff --git a/boot/image-android.c b/boot/image-android.c
index 79d987a3b044..d0cb8615c28c 100644
--- a/boot/image-android.c
+++ b/boot/image-android.c
@@ -85,7 +85,7 @@ bool android_image_get_data(const void *boot_hdr, struct andr_image_data *data)
 	return true;
 }
 
-static ulong android_image_get_kernel_addr(const struct andr_boot_img_hdr_v0_v1_v2 *hdr)
+static ulong android_image_get_kernel_addr(struct andr_image_data *img_data)
 {
 	/*
 	 * All the Android tools that generate a boot.img use this
@@ -98,17 +98,17 @@ static ulong android_image_get_kernel_addr(const struct andr_boot_img_hdr_v0_v1_
 	 *
 	 * Otherwise, we will return the actual value set by the user.
 	 */
-	if (hdr->kernel_addr == ANDROID_IMAGE_DEFAULT_KERNEL_ADDR)
-		return (ulong)hdr + hdr->page_size;
+	if (img_data->kernel_addr  == ANDROID_IMAGE_DEFAULT_KERNEL_ADDR)
+		return img_data->kernel_ptr;
 
 	/*
 	 * abootimg creates images where all load addresses are 0
 	 * and we need to fix them.
 	 */
-	if (hdr->kernel_addr == 0 && hdr->ramdisk_addr == 0)
+	if (img_data->kernel_addr == 0 && img_data->ramdisk_addr == 0)
 		return env_get_ulong("kernel_addr_r", 16, 0);
 
-	return hdr->kernel_addr;
+	return img_data->kernel_addr;
 }
 
 /**
@@ -129,27 +129,33 @@ static ulong android_image_get_kernel_addr(const struct andr_boot_img_hdr_v0_v1_
 int android_image_get_kernel(const struct andr_boot_img_hdr_v0_v1_v2 *hdr, int verify,
 			     ulong *os_data, ulong *os_len)
 {
-	u32 kernel_addr = android_image_get_kernel_addr(hdr);
-	const struct legacy_img_hdr *ihdr = (const struct legacy_img_hdr *)
-		((uintptr_t)hdr + hdr->page_size);
+	struct andr_image_data img_data = {0};
+	u32 kernel_addr;
+	const struct legacy_img_hdr *ihdr;
+
+	if (!android_image_get_data(hdr, &img_data))
+		return -EINVAL;
+
+	kernel_addr = android_image_get_kernel_addr(&img_data);
+	ihdr = (const struct legacy_img_hdr *)img_data.kernel_ptr;
 
 	/*
 	 * Not all Android tools use the id field for signing the image with
 	 * sha1 (or anything) so we don't check it. It is not obvious that the
 	 * string is null terminated so we take care of this.
 	 */
-	strncpy(andr_tmp_str, hdr->name, ANDR_BOOT_NAME_SIZE);
+	strncpy(andr_tmp_str, img_data.image_name, ANDR_BOOT_NAME_SIZE);
 	andr_tmp_str[ANDR_BOOT_NAME_SIZE] = '\0';
 	if (strlen(andr_tmp_str))
 		printf("Android's image name: %s\n", andr_tmp_str);
 
 	printf("Kernel load addr 0x%08x size %u KiB\n",
-	       kernel_addr, DIV_ROUND_UP(hdr->kernel_size, 1024));
+	       kernel_addr, DIV_ROUND_UP(img_data.kernel_size, 1024));
 
 	int len = 0;
-	if (*hdr->cmdline) {
-		printf("Kernel command line: %s\n", hdr->cmdline);
-		len += strlen(hdr->cmdline);
+	if (*img_data.kcmdline) {
+		printf("Kernel command line: %s\n", img_data.kcmdline);
+		len += strlen(img_data.kcmdline);
 	}
 
 	char *bootargs = env_get("bootargs");
@@ -167,8 +173,9 @@ int android_image_get_kernel(const struct andr_boot_img_hdr_v0_v1_v2 *hdr, int v
 		strcpy(newbootargs, bootargs);
 		strcat(newbootargs, " ");
 	}
-	if (*hdr->cmdline)
-		strcat(newbootargs, hdr->cmdline);
+
+	if (*img_data.kcmdline)
+		strcat(newbootargs, img_data.kcmdline);
 
 	env_set("bootargs", newbootargs);
 
@@ -176,15 +183,14 @@ int android_image_get_kernel(const struct andr_boot_img_hdr_v0_v1_v2 *hdr, int v
 		if (image_get_magic(ihdr) == IH_MAGIC) {
 			*os_data = image_get_data(ihdr);
 		} else {
-			*os_data = (ulong)hdr;
-			*os_data += hdr->page_size;
+			*os_data = img_data.kernel_ptr;
 		}
 	}
 	if (os_len) {
 		if (image_get_magic(ihdr) == IH_MAGIC)
 			*os_len = image_get_data_size(ihdr);
 		else
-			*os_len = hdr->kernel_size;
+			*os_len = img_data.kernel_size;
 	}
 	return 0;
 }
@@ -196,30 +202,25 @@ bool is_android_boot_image_header(const struct andr_boot_img_hdr_v0_v1_v2 *hdr)
 
 ulong android_image_get_end(const struct andr_boot_img_hdr_v0_v1_v2 *hdr)
 {
-	ulong end;
-
-	/*
-	 * The header takes a full page, the remaining components are aligned
-	 * on page boundary
-	 */
-	end = (ulong)hdr;
-	end += hdr->page_size;
-	end += ALIGN(hdr->kernel_size, hdr->page_size);
-	end += ALIGN(hdr->ramdisk_size, hdr->page_size);
-	end += ALIGN(hdr->second_size, hdr->page_size);
+	struct andr_image_data img_data;
 
-	if (hdr->header_version >= 1)
-		end += ALIGN(hdr->recovery_dtbo_size, hdr->page_size);
+	if (!android_image_get_data(hdr, &img_data))
+		return -EINVAL;
 
-	if (hdr->header_version >= 2)
-		end += ALIGN(hdr->dtb_size, hdr->page_size);
+	if (img_data.header_version > 2)
+		return 0;
 
-	return end;
+	return img_data.boot_img_total_size;
 }
 
 ulong android_image_get_kload(const struct andr_boot_img_hdr_v0_v1_v2 *hdr)
 {
-	return android_image_get_kernel_addr(hdr);
+	struct andr_image_data img_data;
+
+	if (!android_image_get_data(hdr, &img_data))
+		return -EINVAL;
+
+	return android_image_get_kernel_addr(&img_data);
 }
 
 ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0_v1_v2 *hdr)
@@ -242,38 +243,43 @@ ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0_v1_v2 *hdr)
 int android_image_get_ramdisk(const struct andr_boot_img_hdr_v0_v1_v2 *hdr,
 			      ulong *rd_data, ulong *rd_len)
 {
-	if (!hdr->ramdisk_size) {
+	struct andr_image_data img_data = {0};
+
+	if (!android_image_get_data(hdr, &img_data))
+		return -EINVAL;
+
+	if (!img_data.ramdisk_size) {
 		*rd_data = *rd_len = 0;
 		return -1;
 	}
 
-	printf("RAM disk load addr 0x%08x size %u KiB\n",
-	       hdr->ramdisk_addr, DIV_ROUND_UP(hdr->ramdisk_size, 1024));
+	printf("RAM disk load addr 0x%08lx size %u KiB\n",
+	       img_data.ramdisk_ptr, DIV_ROUND_UP(img_data.ramdisk_size, 1024));
 
-	*rd_data = (unsigned long)hdr;
-	*rd_data += hdr->page_size;
-	*rd_data += ALIGN(hdr->kernel_size, hdr->page_size);
+	*rd_data = img_data.ramdisk_ptr;
 
-	*rd_len = hdr->ramdisk_size;
+	*rd_len = img_data.ramdisk_size;
 	return 0;
 }
 
 int android_image_get_second(const struct andr_boot_img_hdr_v0_v1_v2 *hdr,
 			      ulong *second_data, ulong *second_len)
 {
-	if (!hdr->second_size) {
+	struct andr_image_data img_data;
+
+	if (!android_image_get_data(hdr, &img_data))
+		return -EINVAL;
+
+	if (!img_data.second_size) {
 		*second_data = *second_len = 0;
 		return -1;
 	}
 
-	*second_data = (unsigned long)hdr;
-	*second_data += hdr->page_size;
-	*second_data += ALIGN(hdr->kernel_size, hdr->page_size);
-	*second_data += ALIGN(hdr->ramdisk_size, hdr->page_size);
+	*second_data = img_data.second_ptr;
 
 	printf("second address is 0x%lx\n",*second_data);
 
-	*second_len = hdr->second_size;
+	*second_len = img_data.second_size;
 	return 0;
 }
 
@@ -338,6 +344,8 @@ exit:
 	return ret;
 }
 
+#if !defined(CONFIG_SPL_BUILD)
+#ifdef CONFIG_CMD_ABOOTIMG
 /**
  * android_image_get_dtb_img_addr() - Get the address of DTB area in boot image.
  * @hdr_addr: Boot image header address
@@ -384,6 +392,8 @@ exit:
 	unmap_sysmem(hdr);
 	return ret;
 }
+#endif
+#endif
 
 /**
  * android_image_get_dtb_by_index() - Get address and size of blob in DTB area.
@@ -400,17 +410,17 @@ exit:
 bool android_image_get_dtb_by_index(ulong hdr_addr, u32 index, ulong *addr,
 				    u32 *size)
 {
-	const struct andr_boot_img_hdr_v0_v1_v2 *hdr;
-	bool res;
+	struct andr_image_data img_data;
+
+	if (!android_image_get_data((void *)hdr_addr, &img_data))
+		return false;
+
 	ulong dtb_img_addr;	/* address of DTB part in boot image */
 	u32 dtb_img_size;	/* size of DTB payload in boot image */
 	ulong dtb_addr;		/* address of DTB blob with specified index  */
 	u32 i;			/* index iterator */
 
-	res = android_image_get_dtb_img_addr(hdr_addr, &dtb_img_addr);
-	if (!res)
-		return false;
-
+	dtb_img_addr = img_data.dtb_ptr;
 	/* Check if DTB area of boot image is in DTBO format */
 	if (android_dt_check_header(dtb_img_addr)) {
 		return android_dt_get_fdt_by_index(dtb_img_addr, index, addr,
@@ -418,9 +428,7 @@ bool android_image_get_dtb_by_index(ulong hdr_addr, u32 index, ulong *addr,
 	}
 
 	/* Find out the address of DTB with specified index in concat blobs */
-	hdr = map_sysmem(hdr_addr, sizeof(*hdr));
-	dtb_img_size = hdr->dtb_size;
-	unmap_sysmem(hdr);
+	dtb_img_size = img_data.dtb_size;
 	i = 0;
 	dtb_addr = dtb_img_addr;
 	while (dtb_addr < dtb_img_addr + dtb_img_size) {
@@ -505,6 +513,7 @@ void android_print_contents(const struct andr_boot_img_hdr_v0_v1_v2 *hdr)
 	}
 }
 
+#ifdef CONFIG_CMD_ABOOTIMG
 /**
  * android_image_print_dtb_info - Print info for one DTB blob in DTB area.
  * @fdt: DTB header
@@ -609,3 +618,4 @@ bool android_image_print_dtb_contents(ulong hdr_addr)
 	return true;
 }
 #endif
+#endif
diff --git a/cmd/abootimg.c b/cmd/abootimg.c
index 3c344b6c0367..41b733f7713b 100644
--- a/cmd/abootimg.c
+++ b/cmd/abootimg.c
@@ -66,33 +66,29 @@ static int abootimg_get_recovery_dtbo(int argc, char *const argv[])
 
 static int abootimg_get_dtb_load_addr(int argc, char *const argv[])
 {
-	const struct andr_boot_img_hdr_v0_v1_v2 *hdr;
-	int res = CMD_RET_SUCCESS;
-
 	if (argc > 1)
 		return CMD_RET_USAGE;
+	struct andr_image_data img_data = {0};
 
-	hdr = map_sysmem(abootimg_addr(), sizeof(*hdr));
-	if (!is_android_boot_image_header(hdr)) {
-		printf("Error: Boot Image header is incorrect\n");
-		res = CMD_RET_FAILURE;
-		goto exit;
-	}
+	if (!android_image_get_data((void *)abootimg_addr(), &img_data))
+		return CMD_RET_FAILURE;
 
-	if (hdr->header_version < 2) {
+	if (img_data.header_version < 2) {
 		printf("Error: header_version must be >= 2 for this\n");
-		res = CMD_RET_FAILURE;
-		goto exit;
+		return CMD_RET_FAILURE;
+	}
+
+	if (!img_data.dtb_load_addr) {
+		printf("Error: failed to read dtb_load_addr\n");
+		return CMD_RET_FAILURE;
 	}
 
 	if (argc == 0)
-		printf("%lx\n", (ulong)hdr->dtb_addr);
+		printf("%lx\n", (ulong)img_data.dtb_load_addr);
 	else
-		env_set_hex(argv[0], (ulong)hdr->dtb_addr);
+		env_set_hex(argv[0], (ulong)img_data.dtb_load_addr);
 
-exit:
-	unmap_sysmem(hdr);
-	return res;
+	return CMD_RET_SUCCESS;
 }
 
 static int abootimg_get_dtb_by_index(int argc, char *const argv[])
diff --git a/include/image.h b/include/image.h
index 738ef54ce6d5..3b5742104cf7 100644
--- a/include/image.h
+++ b/include/image.h
@@ -1739,7 +1739,9 @@ ulong android_image_get_end(const struct andr_boot_img_hdr_v0_v1_v2 *hdr);
 ulong android_image_get_kload(const struct andr_boot_img_hdr_v0_v1_v2 *hdr);
 ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0_v1_v2 *hdr);
 void android_print_contents(const struct andr_boot_img_hdr_v0_v1_v2 *hdr);
+#ifdef CONFIG_CMD_ABOOTIMG
 bool android_image_print_dtb_contents(ulong hdr_addr);
+#endif
 bool is_android_boot_image_header(const struct andr_boot_img_hdr_v0_v1_v2 *hdr);
 
 /**
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 08/17] android: boot: content print is not supported for v3, v4 header version
  2022-11-26 16:59 [PATCH 00/17] Support android boot image v3/v4 Safae Ouajih
                   ` (6 preceding siblings ...)
  2022-11-26 16:59 ` [PATCH 07/17] android: boot: move to andr_image_data structure Safae Ouajih
@ 2022-11-26 16:59 ` Safae Ouajih
  2022-11-26 16:59 ` [PATCH 09/17] android: boot: boot image header v3, v4 do not support recovery DTBO Safae Ouajih
                   ` (11 subsequent siblings)
  19 siblings, 0 replies; 28+ messages in thread
From: Safae Ouajih @ 2022-11-26 16:59 UTC (permalink / raw)
  To: sjg; +Cc: u-boot, sean.anderson, r.stratiienko, mkorpershoek, glaroque, khilman

Content print is not supported for version 3 and 4 of boot image header.
Thus, only print that content when v2 is used.

Update android_print_contents() to print an error message
when trying to print boot image header version 3 or 4 content.

Signed-off-by: Safae Ouajih <souajih@baylibre.com>
---
 boot/image-android.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/boot/image-android.c b/boot/image-android.c
index d0cb8615c28c..d6476904f35e 100644
--- a/boot/image-android.c
+++ b/boot/image-android.c
@@ -475,6 +475,10 @@ bool android_image_get_dtb_by_index(ulong hdr_addr, u32 index, ulong *addr,
  */
 void android_print_contents(const struct andr_boot_img_hdr_v0_v1_v2 *hdr)
 {
+	if (hdr->header_version >= 3) {
+		printf("Content print is not supported for boot image header version > 2");
+		return;
+	}
 	const char * const p = IMAGE_INDENT_STRING;
 	/* os_version = ver << 11 | lvl */
 	u32 os_ver = hdr->os_version >> 11;
@@ -507,7 +511,7 @@ void android_print_contents(const struct andr_boot_img_hdr_v0_v1_v2 *hdr)
 		       hdr->header_size);
 	}
 
-	if (hdr->header_version >= 2) {
+	if (hdr->header_version == 2) {
 		printf("%sdtb size:             %x\n", p, hdr->dtb_size);
 		printf("%sdtb addr:             %llx\n", p, hdr->dtb_addr);
 	}
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 09/17] android: boot: boot image header v3, v4 do not support recovery DTBO
  2022-11-26 16:59 [PATCH 00/17] Support android boot image v3/v4 Safae Ouajih
                   ` (7 preceding siblings ...)
  2022-11-26 16:59 ` [PATCH 08/17] android: boot: content print is not supported for v3, v4 header version Safae Ouajih
@ 2022-11-26 16:59 ` Safae Ouajih
  2022-11-26 16:59 ` [PATCH 10/17] android: boot: add vendor boot image to prepare for v3, v4 support Safae Ouajih
                   ` (10 subsequent siblings)
  19 siblings, 0 replies; 28+ messages in thread
From: Safae Ouajih @ 2022-11-26 16:59 UTC (permalink / raw)
  To: sjg; +Cc: u-boot, sean.anderson, r.stratiienko, mkorpershoek, glaroque, khilman

android_image_get_dtbo() is used to get recovery DTBO via abootimg cmd.
This is not supported in boot image header v3 and v4. Thus, we print an
error message when v1,v2 header version are not used.

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

diff --git a/boot/image-android.c b/boot/image-android.c
index d6476904f35e..daf51a7e3b8b 100644
--- a/boot/image-android.c
+++ b/boot/image-android.c
@@ -315,8 +315,8 @@ bool android_image_get_dtbo(ulong hdr_addr, ulong *addr, u32 *size)
 		goto exit;
 	}
 
-	if (hdr->header_version < 1) {
-		printf("Error: header_version must be >= 1 to get dtbo\n");
+	if (hdr->header_version != 1 && hdr->header_version != 2) {
+		printf("Error: header version must be >= 1 and <= 2 to get dtbo\n");
 		ret = false;
 		goto exit;
 	}
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 10/17] android: boot: add vendor boot image to prepare for v3, v4 support
  2022-11-26 16:59 [PATCH 00/17] Support android boot image v3/v4 Safae Ouajih
                   ` (8 preceding siblings ...)
  2022-11-26 16:59 ` [PATCH 09/17] android: boot: boot image header v3, v4 do not support recovery DTBO Safae Ouajih
@ 2022-11-26 16:59 ` Safae Ouajih
  2022-11-26 16:59 ` [PATCH 11/17] android: boot: update android_image_get_data to support v3, v4 Safae Ouajih
                   ` (9 subsequent siblings)
  19 siblings, 0 replies; 28+ messages in thread
From: Safae Ouajih @ 2022-11-26 16:59 UTC (permalink / raw)
  To: sjg; +Cc: u-boot, sean.anderson, r.stratiienko, mkorpershoek, glaroque, khilman

This is done to prepare for boot image version 3 and 4 support.

Signed-off-by: Safae Ouajih <souajih@baylibre.com>
---
 boot/bootm.c         |  8 ++++----
 boot/image-android.c | 40 ++++++++++++++++++++++++----------------
 boot/image-board.c   |  3 +--
 boot/image-fdt.c     |  3 ++-
 cmd/abootimg.c       |  4 ++--
 include/image.h      | 22 ++++++++++++++--------
 6 files changed, 47 insertions(+), 33 deletions(-)

diff --git a/boot/bootm.c b/boot/bootm.c
index a4c0870c0fea..e44dc550077d 100644
--- a/boot/bootm.c
+++ b/boot/bootm.c
@@ -182,11 +182,11 @@ static int bootm_find_os(struct cmd_tbl *cmdtp, int flag, int argc,
 #ifdef CONFIG_ANDROID_BOOT_IMAGE
 	case IMAGE_FORMAT_ANDROID:
 		images.os.type = IH_TYPE_KERNEL;
-		images.os.comp = android_image_get_kcomp(os_hdr);
+		images.os.comp = android_image_get_kcomp(os_hdr, NULL);
 		images.os.os = IH_OS_LINUX;
 
-		images.os.end = android_image_get_end(os_hdr);
-		images.os.load = android_image_get_kload(os_hdr);
+		images.os.end = android_image_get_end(os_hdr, NULL);
+		images.os.load = android_image_get_kload(os_hdr, NULL);
 		images.ep = images.os.load;
 		ep_found = true;
 		break;
@@ -968,7 +968,7 @@ static const void *boot_get_kernel(struct cmd_tbl *cmdtp, int flag, int argc,
 #ifdef CONFIG_ANDROID_BOOT_IMAGE
 	case IMAGE_FORMAT_ANDROID:
 		printf("## Booting Android Image at 0x%08lx ...\n", img_addr);
-		if (android_image_get_kernel(buf, images->verify,
+		if (android_image_get_kernel(buf, NULL, images->verify,
 					     os_data, os_len))
 			return NULL;
 		break;
diff --git a/boot/image-android.c b/boot/image-android.c
index daf51a7e3b8b..eb821b08ccf4 100644
--- a/boot/image-android.c
+++ b/boot/image-android.c
@@ -65,7 +65,8 @@ static void android_boot_image_v0_v1_v2_parse_hdr(const struct andr_boot_img_hdr
 	data->boot_img_total_size = end - (ulong)hdr;
 }
 
-bool android_image_get_data(const void *boot_hdr, struct andr_image_data *data)
+bool android_image_get_data(const void *boot_hdr, const void *vendor_boot_hdr,
+			    struct andr_image_data *data)
 {
 	if (!boot_hdr || !data) {
 		printf("boot_hdr or data params can't be NULL\n");
@@ -113,8 +114,10 @@ static ulong android_image_get_kernel_addr(struct andr_image_data *img_data)
 
 /**
  * android_image_get_kernel() - processes kernel part of Android boot images
- * @hdr:	Pointer to image header, which is at the start
+ * @hdr:	Pointer to boot image header, which is at the start
  *			of the image.
+ * @vendor_boot_img:	Pointer to vendor boot image header, which is at the
+ *				start of the image.
  * @verify:	Checksum verification flag. Currently unimplemented.
  * @os_data:	Pointer to a ulong variable, will hold os data start
  *			address.
@@ -126,14 +129,15 @@ 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_v1_v2 *hdr, int verify,
+int android_image_get_kernel(const struct andr_boot_img_hdr_v0_v1_v2 *hdr,
+			     const void *vendor_boot_img, int verify,
 			     ulong *os_data, ulong *os_len)
 {
 	struct andr_image_data img_data = {0};
 	u32 kernel_addr;
 	const struct legacy_img_hdr *ihdr;
 
-	if (!android_image_get_data(hdr, &img_data))
+	if (!android_image_get_data(hdr, vendor_boot_img, &img_data))
 		return -EINVAL;
 
 	kernel_addr = android_image_get_kernel_addr(&img_data);
@@ -200,11 +204,12 @@ bool is_android_boot_image_header(const struct andr_boot_img_hdr_v0_v1_v2 *hdr)
 	return !memcmp(ANDR_BOOT_MAGIC, hdr, ANDR_BOOT_MAGIC_SIZE);
 }
 
-ulong android_image_get_end(const struct andr_boot_img_hdr_v0_v1_v2 *hdr)
+ulong android_image_get_end(const struct andr_boot_img_hdr_v0_v1_v2 *hdr,
+			    const void *vendor_boot_img)
 {
 	struct andr_image_data img_data;
 
-	if (!android_image_get_data(hdr, &img_data))
+	if (!android_image_get_data(hdr, vendor_boot_img, &img_data))
 		return -EINVAL;
 
 	if (img_data.header_version > 2)
@@ -213,22 +218,24 @@ ulong android_image_get_end(const struct andr_boot_img_hdr_v0_v1_v2 *hdr)
 	return img_data.boot_img_total_size;
 }
 
-ulong android_image_get_kload(const struct andr_boot_img_hdr_v0_v1_v2 *hdr)
+ulong android_image_get_kload(const struct andr_boot_img_hdr_v0_v1_v2 *hdr,
+			      const void *vendor_boot_img)
 {
 	struct andr_image_data img_data;
 
-	if (!android_image_get_data(hdr, &img_data))
+	if (!android_image_get_data(hdr, vendor_boot_img, &img_data))
 		return -EINVAL;
 
 	return android_image_get_kernel_addr(&img_data);
 }
 
-ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0_v1_v2 *hdr)
+ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0_v1_v2 *hdr,
+			      const void *vendor_boot_img)
 {
 	struct andr_image_data img_data;
 	const void *p;
 
-	if (!android_image_get_data(hdr, &img_data))
+	if (!android_image_get_data(hdr, vendor_boot_img, &img_data))
 		return -EINVAL;
 
 	p = (const void *)img_data.kernel_ptr;
@@ -241,11 +248,11 @@ ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0_v1_v2 *hdr)
 }
 
 int android_image_get_ramdisk(const struct andr_boot_img_hdr_v0_v1_v2 *hdr,
-			      ulong *rd_data, ulong *rd_len)
+			      const void *vendor_boot_img, ulong *rd_data, ulong *rd_len)
 {
 	struct andr_image_data img_data = {0};
 
-	if (!android_image_get_data(hdr, &img_data))
+	if (!android_image_get_data(hdr, vendor_boot_img, &img_data))
 		return -EINVAL;
 
 	if (!img_data.ramdisk_size) {
@@ -267,7 +274,7 @@ int android_image_get_second(const struct andr_boot_img_hdr_v0_v1_v2 *hdr,
 {
 	struct andr_image_data img_data;
 
-	if (!android_image_get_data(hdr, &img_data))
+	if (!android_image_get_data(hdr, NULL, &img_data))
 		return -EINVAL;
 
 	if (!img_data.second_size) {
@@ -398,6 +405,7 @@ exit:
 /**
  * android_image_get_dtb_by_index() - Get address and size of blob in DTB area.
  * @hdr_addr: Boot image header address
+ * @vendor_boot_img: Pointer to vendor boot image header, which is at the start of the image.
  * @index: Index of desired DTB in DTB area (starting from 0)
  * @addr: If not NULL, will contain address to specified DTB
  * @size: If not NULL, will contain size of specified DTB
@@ -407,12 +415,12 @@ exit:
  *
  * Return: true on success or false on error.
  */
-bool android_image_get_dtb_by_index(ulong hdr_addr, u32 index, ulong *addr,
-				    u32 *size)
+bool android_image_get_dtb_by_index(ulong hdr_addr, const void *vendor_boot_img,
+				    u32 index, ulong *addr, u32 *size)
 {
 	struct andr_image_data img_data;
 
-	if (!android_image_get_data((void *)hdr_addr, &img_data))
+	if (!android_image_get_data((void *)hdr_addr, vendor_boot_img, &img_data))
 		return false;
 
 	ulong dtb_img_addr;	/* address of DTB part in boot image */
diff --git a/boot/image-board.c b/boot/image-board.c
index acbaafc1b12e..c8e41cc8706f 100644
--- a/boot/image-board.c
+++ b/boot/image-board.c
@@ -428,8 +428,7 @@ static int select_ramdisk(struct bootm_headers *images, const char *select, u8 a
 		if (IS_ENABLED(CONFIG_ANDROID_BOOT_IMAGE)) {
 			void *ptr = map_sysmem(images->os.start, 0);
 			int ret;
-
-			ret = android_image_get_ramdisk(ptr, rd_datap, rd_lenp);
+			ret = android_image_get_ramdisk(ptr, NULL, rd_datap, rd_lenp);
 			unmap_sysmem(ptr);
 			if (ret)
 				return ret;
diff --git a/boot/image-fdt.c b/boot/image-fdt.c
index b7cc9bfd538f..6a08e8a07ed7 100644
--- a/boot/image-fdt.c
+++ b/boot/image-fdt.c
@@ -536,7 +536,8 @@ int boot_get_fdt(int flag, int argc, char *const argv[], uint8_t arch,
 		 * Firstly check if this android boot image has dtb field.
 		 */
 		dtb_idx = (u32)env_get_ulong("adtb_idx", 10, 0);
-		if (android_image_get_dtb_by_index((ulong)hdr, dtb_idx, &fdt_addr, &fdt_size)) {
+		if (android_image_get_dtb_by_index((ulong)hdr, NULL,
+						   dtb_idx, &fdt_addr, &fdt_size)) {
 			fdt_blob = (char *)map_sysmem(fdt_addr, 0);
 			if (fdt_check_header(fdt_blob))
 				goto no_fdt;
diff --git a/cmd/abootimg.c b/cmd/abootimg.c
index 41b733f7713b..e8c70a93cbf4 100644
--- a/cmd/abootimg.c
+++ b/cmd/abootimg.c
@@ -70,7 +70,7 @@ static int abootimg_get_dtb_load_addr(int argc, char *const argv[])
 		return CMD_RET_USAGE;
 	struct andr_image_data img_data = {0};
 
-	if (!android_image_get_data((void *)abootimg_addr(), &img_data))
+	if (!android_image_get_data((void *)abootimg_addr(), NULL, &img_data))
 		return CMD_RET_FAILURE;
 
 	if (img_data.header_version < 2) {
@@ -114,7 +114,7 @@ static int abootimg_get_dtb_by_index(int argc, char *const argv[])
 		return CMD_RET_FAILURE;
 	}
 
-	if (!android_image_get_dtb_by_index(abootimg_addr(), num,
+	if (!android_image_get_dtb_by_index(abootimg_addr(), NULL, num,
 					    &addr, &size)) {
 		return CMD_RET_FAILURE;
 	}
diff --git a/include/image.h b/include/image.h
index 3b5742104cf7..a0affc514a5d 100644
--- a/include/image.h
+++ b/include/image.h
@@ -1724,20 +1724,26 @@ int fit_image_cipher_get_algo(const void *fit, int noffset, char **algo);
 struct cipher_algo *image_get_cipher_algo(const char *full_name);
 struct andr_image_data;
 
-bool android_image_get_data(const void *boot_hdr, struct andr_image_data *data);
+bool android_image_get_data(const void *boot_hdr, const void *vendor_boot_hdr,
+			    struct andr_image_data *data);
+
 struct andr_boot_img_hdr_v0_v1_v2;
-int android_image_get_kernel(const struct andr_boot_img_hdr_v0_v1_v2 *hdr, int verify,
+int android_image_get_kernel(const struct andr_boot_img_hdr_v0_v1_v2 *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_v1_v2 *hdr,
-			      ulong *rd_data, ulong *rd_len);
+			      const void *vendor_boot_img, ulong *rd_data, ulong *rd_len);
 int android_image_get_second(const struct andr_boot_img_hdr_v0_v1_v2 *hdr,
 			      ulong *second_data, ulong *second_len);
 bool android_image_get_dtbo(ulong hdr_addr, ulong *addr, u32 *size);
-bool android_image_get_dtb_by_index(ulong hdr_addr, u32 index, ulong *addr,
-				    u32 *size);
-ulong android_image_get_end(const struct andr_boot_img_hdr_v0_v1_v2 *hdr);
-ulong android_image_get_kload(const struct andr_boot_img_hdr_v0_v1_v2 *hdr);
-ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0_v1_v2 *hdr);
+bool android_image_get_dtb_by_index(ulong hdr_addr, const void *vendor_boot_img,
+				    u32 index, ulong *addr, u32 *size);
+ulong android_image_get_end(const struct andr_boot_img_hdr_v0_v1_v2 *hdr,
+			    const void *vendor_boot_img);
+ulong android_image_get_kload(const struct andr_boot_img_hdr_v0_v1_v2 *hdr,
+			      const void *vendor_boot_img);
+ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0_v1_v2 *hdr,
+			      const void *vendor_boot_img);
 void android_print_contents(const struct andr_boot_img_hdr_v0_v1_v2 *hdr);
 #ifdef CONFIG_CMD_ABOOTIMG
 bool android_image_print_dtb_contents(ulong hdr_addr);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 11/17] android: boot: update android_image_get_data to support v3, v4
  2022-11-26 16:59 [PATCH 00/17] Support android boot image v3/v4 Safae Ouajih
                   ` (9 preceding siblings ...)
  2022-11-26 16:59 ` [PATCH 10/17] android: boot: add vendor boot image to prepare for v3, v4 support Safae Ouajih
@ 2022-11-26 16:59 ` Safae Ouajih
  2022-11-26 16:59 ` [PATCH 12/17] android: boot: ramdisk: support vendor ramdisk Safae Ouajih
                   ` (8 subsequent siblings)
  19 siblings, 0 replies; 28+ messages in thread
From: Safae Ouajih @ 2022-11-26 16:59 UTC (permalink / raw)
  To: sjg; +Cc: u-boot, sean.anderson, r.stratiienko, mkorpershoek, glaroque, khilman

Since boot image header version 3 and 4 introduced vendor boot image,
the following functions are used to fill the generic android
structure : andr_image_data:

 - android_boot_image_v3_v4_parse_hdr()
 - android_vendor_boot_image_v3_v4_parse_hdr()

android_image_get_data() is then updated to support v3 and v4

Signed-off-by: Safae Ouajih <souajih@baylibre.com>
---
 boot/image-android.c    | 79 +++++++++++++++++++++++++++++++++++++++--
 include/android_image.h |  3 ++
 include/image.h         |  1 +
 3 files changed, 80 insertions(+), 3 deletions(-)

diff --git a/boot/image-android.c b/boot/image-android.c
index eb821b08ccf4..5001b088f0fb 100644
--- a/boot/image-android.c
+++ b/boot/image-android.c
@@ -18,6 +18,64 @@
 
 static char andr_tmp_str[ANDR_BOOT_ARGS_SIZE + 1];
 
+static void android_boot_image_v3_v4_parse_hdr(const struct andr_boot_img_hdr_v3_v4 *hdr,
+					       struct andr_image_data *data)
+{
+	ulong end;
+
+	data->kcmdline = hdr->cmdline;
+	data->header_version = hdr->header_version;
+
+	/*
+	 * The header takes a full page, the remaining components are aligned
+	 * on page boundary.
+	 */
+	end = (ulong)hdr;
+	end += ANDR_GKI_PAGE_SIZE;
+	data->kernel_ptr = end;
+	data->kernel_size = hdr->kernel_size;
+	end += ALIGN(hdr->kernel_size, ANDR_GKI_PAGE_SIZE);
+	data->ramdisk_size = hdr->ramdisk_size;
+	data->boot_ramdisk_size = hdr->ramdisk_size;
+	end += ALIGN(hdr->ramdisk_size, ANDR_GKI_PAGE_SIZE);
+
+	if (hdr->header_version > 3)
+		end += ALIGN(hdr->signature_size, ANDR_GKI_PAGE_SIZE);
+
+	data->boot_img_total_size = end - (ulong)hdr;
+}
+
+static void android_vendor_boot_image_v3_v4_parse_hdr(const struct andr_vendor_boot_img_hdr_v3_v4
+						      *hdr, struct andr_image_data *data)
+{
+	ulong end;
+
+	/*
+	 * The header takes a full page, the remaining components are aligned
+	 * on page boundary.
+	 */
+	data->tags_addr = hdr->tags_addr;
+	data->image_name = hdr->name;
+	data->kernel_addr = hdr->kernel_addr;
+	data->ramdisk_addr = hdr->ramdisk_addr;
+	end = (ulong)hdr;
+	end += hdr->page_size;
+	if (hdr->vendor_ramdisk_size) {
+		data->vendor_ramdisk_ptr = end;
+		data->vendor_ramdisk_size = hdr->vendor_ramdisk_size;
+		data->ramdisk_size += hdr->vendor_ramdisk_size;
+		end += ALIGN(hdr->vendor_ramdisk_size, hdr->page_size);
+	}
+
+	data->dtb_ptr = end;
+	data->dtb_size = hdr->dtb_size;
+
+	end += ALIGN(hdr->dtb_size, hdr->page_size);
+	end += ALIGN(hdr->vendor_ramdisk_table_size, hdr->page_size);
+	end += ALIGN(hdr->bootconfig_size, hdr->page_size);
+	data->vendor_boot_img_total_size = end - (ulong)hdr;
+}
+
 static void android_boot_image_v0_v1_v2_parse_hdr(const struct andr_boot_img_hdr_v0_v1_v2 *hdr,
 						  struct andr_image_data *data)
 {
@@ -78,10 +136,20 @@ bool android_image_get_data(const void *boot_hdr, const void *vendor_boot_hdr,
 		return false;
 	}
 
-	if (((struct andr_boot_img_hdr_v0_v1_v2 *)boot_hdr)->header_version > 2)
-		printf("Only boot image header version 2 and below are supported\n");
-	else
+	if (((struct andr_boot_img_hdr_v0_v1_v2 *)boot_hdr)->header_version > 2) {
+		if (!vendor_boot_hdr) {
+			printf("For boot header v3+ vendor boot image has to be provided\n");
+			return false;
+		}
+		if (!is_android_vendor_boot_image_header(vendor_boot_hdr)) {
+			printf("Incorrect vendor boot image header\n");
+			return false;
+		}
+		android_boot_image_v3_v4_parse_hdr(boot_hdr, data);
+		android_vendor_boot_image_v3_v4_parse_hdr(vendor_boot_hdr, data);
+	} else {
 		android_boot_image_v0_v1_v2_parse_hdr(boot_hdr, data);
+	}
 
 	return true;
 }
@@ -199,6 +267,11 @@ int android_image_get_kernel(const struct andr_boot_img_hdr_v0_v1_v2 *hdr,
 	return 0;
 }
 
+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_v1_v2 *hdr)
 {
 	return !memcmp(ANDR_BOOT_MAGIC, hdr, ANDR_BOOT_MAGIC_SIZE);
diff --git a/include/android_image.h b/include/android_image.h
index 98a91cbf2f9c..b9591633c9f7 100644
--- a/include/android_image.h
+++ b/include/android_image.h
@@ -323,6 +323,8 @@ struct andr_image_data {
 	ulong kernel_ptr;
 	u32 kernel_size;
 	u32 ramdisk_size;
+	ulong vendor_ramdisk_ptr;
+	u32 vendor_ramdisk_size;
 	u32 boot_ramdisk_size;
 	ulong second_ptr;
 	u32 second_size;
@@ -342,6 +344,7 @@ struct andr_image_data {
 	ulong tags_addr;
 	u32 header_version;
 	u32 boot_img_total_size;
+	u32 vendor_boot_img_total_size;
 };
 
 #endif
diff --git a/include/image.h b/include/image.h
index a0affc514a5d..c91502011500 100644
--- a/include/image.h
+++ b/include/image.h
@@ -1749,6 +1749,7 @@ void android_print_contents(const struct andr_boot_img_hdr_v0_v1_v2 *hdr);
 bool android_image_print_dtb_contents(ulong hdr_addr);
 #endif
 bool is_android_boot_image_header(const struct andr_boot_img_hdr_v0_v1_v2 *hdr);
+bool is_android_vendor_boot_image_header(const void *vendor_boot_img);
 
 /**
  * board_fit_config_name_match() - Check for a matching board name
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 12/17] android: boot: ramdisk: support vendor ramdisk
  2022-11-26 16:59 [PATCH 00/17] Support android boot image v3/v4 Safae Ouajih
                   ` (10 preceding siblings ...)
  2022-11-26 16:59 ` [PATCH 11/17] android: boot: update android_image_get_data to support v3, v4 Safae Ouajih
@ 2022-11-26 16:59 ` Safae Ouajih
  2022-11-26 16:59 ` [PATCH 13/17] android: boot: support extra command line Safae Ouajih
                   ` (7 subsequent siblings)
  19 siblings, 0 replies; 28+ messages in thread
From: Safae Ouajih @ 2022-11-26 16:59 UTC (permalink / raw)
  To: sjg; +Cc: u-boot, sean.anderson, r.stratiienko, mkorpershoek, glaroque, khilman

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(-)

diff --git a/boot/image-android.c b/boot/image-android.c
index 5001b088f0fb..78bf708fed9f 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
@@ -320,10 +321,11 @@ ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0_v1_v2 *hdr,
 		return image_decomp_type(p, sizeof(u32));
 }
 
-int android_image_get_ramdisk(const struct andr_boot_img_hdr_v0_v1_v2 *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;
@@ -332,6 +334,13 @@ int android_image_get_ramdisk(const struct andr_boot_img_hdr_v0_v1_v2 *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 c91502011500..461e30ae2ac8 100644
--- a/include/image.h
+++ b/include/image.h
@@ -1731,8 +1731,8 @@ struct andr_boot_img_hdr_v0_v1_v2;
 int android_image_get_kernel(const struct andr_boot_img_hdr_v0_v1_v2 *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_v1_v2 *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_v1_v2 *hdr,
 			      ulong *second_data, ulong *second_len);
 bool android_image_get_dtbo(ulong hdr_addr, ulong *addr, u32 *size);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 13/17] android: boot: support extra command line
  2022-11-26 16:59 [PATCH 00/17] Support android boot image v3/v4 Safae Ouajih
                   ` (11 preceding siblings ...)
  2022-11-26 16:59 ` [PATCH 12/17] android: boot: ramdisk: support vendor ramdisk Safae Ouajih
@ 2022-11-26 16:59 ` Safae Ouajih
  2022-11-26 16:59 ` [PATCH 14/17] drivers: fastboot: zImage flashing is not supported for v3, v4 Safae Ouajih
                   ` (6 subsequent siblings)
  19 siblings, 0 replies; 28+ messages in thread
From: Safae Ouajih @ 2022-11-26 16:59 UTC (permalink / raw)
  To: sjg; +Cc: u-boot, sean.anderson, r.stratiienko, mkorpershoek, glaroque, khilman

In version 3 and 4 of boot image header, the vendor specific
command line are located in vendor boot image. Thus, using
extra command line to add those cmd to bootargs.

Signed-off-by: Safae Ouajih <souajih@baylibre.com>
---
 boot/image-android.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/boot/image-android.c b/boot/image-android.c
index 78bf708fed9f..291911ea1852 100644
--- a/boot/image-android.c
+++ b/boot/image-android.c
@@ -55,6 +55,7 @@ static void android_vendor_boot_image_v3_v4_parse_hdr(const struct andr_vendor_b
 	 * The header takes a full page, the remaining components are aligned
 	 * on page boundary.
 	 */
+	data->kcmdline_extra = hdr->cmdline;
 	data->tags_addr = hdr->tags_addr;
 	data->image_name = hdr->name;
 	data->kernel_addr = hdr->kernel_addr;
@@ -231,6 +232,11 @@ int android_image_get_kernel(const struct andr_boot_img_hdr_v0_v1_v2 *hdr,
 		len += strlen(img_data.kcmdline);
 	}
 
+	if (img_data.kcmdline_extra) {
+		printf("Kernel extra command line: %s\n", img_data.kcmdline_extra);
+		len += strlen(img_data.kcmdline_extra);
+	}
+
 	char *bootargs = env_get("bootargs");
 	if (bootargs)
 		len += strlen(bootargs);
@@ -250,6 +256,11 @@ int android_image_get_kernel(const struct andr_boot_img_hdr_v0_v1_v2 *hdr,
 	if (*img_data.kcmdline)
 		strcat(newbootargs, img_data.kcmdline);
 
+	if (img_data.kcmdline_extra) {
+		strcat(newbootargs, " ");
+		strcat(newbootargs, img_data.kcmdline_extra);
+	}
+
 	env_set("bootargs", newbootargs);
 
 	if (os_data) {
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 14/17] drivers: fastboot: zImage flashing is not supported for v3, v4
  2022-11-26 16:59 [PATCH 00/17] Support android boot image v3/v4 Safae Ouajih
                   ` (12 preceding siblings ...)
  2022-11-26 16:59 ` [PATCH 13/17] android: boot: support extra command line Safae Ouajih
@ 2022-11-26 16:59 ` Safae Ouajih
  2022-11-26 16:59 ` [PATCH 15/17] android: boot: support boot image header version 3 and 4 Safae Ouajih
                   ` (5 subsequent siblings)
  19 siblings, 0 replies; 28+ messages in thread
From: Safae Ouajih @ 2022-11-26 16:59 UTC (permalink / raw)
  To: sjg; +Cc: u-boot, sean.anderson, r.stratiienko, mkorpershoek, glaroque, khilman

Print an error message when the boot image header version is
greater than 2 as this is not supported for v3 and v4.

Signed-off-by: Safae Ouajih <souajih@baylibre.com>
---
 drivers/fastboot/fb_mmc.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/fastboot/fb_mmc.c b/drivers/fastboot/fb_mmc.c
index 4cfdc108e8f7..0f0a5d93cbb4 100644
--- a/drivers/fastboot/fb_mmc.c
+++ b/drivers/fastboot/fb_mmc.c
@@ -370,6 +370,14 @@ static int fb_mmc_update_zimage(struct blk_desc *dev_desc,
 		return -1;
 	}
 
+	/* Check if boot image header version is 2 or less */
+	if (hdr->header_version > 2) {
+		pr_err("zImage flashing supported only for boot images v2 and less\n");
+		fastboot_fail("zImage flashing supported only for boot images v2 and less",
+			      response);
+		return -1;
+	}
+
 	/* Check if boot image has second stage in it (we don't support it) */
 	if (hdr->second_size > 0) {
 		pr_err("moving second stage is not supported yet\n");
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 15/17] android: boot: support boot image header version 3 and 4
  2022-11-26 16:59 [PATCH 00/17] Support android boot image v3/v4 Safae Ouajih
                   ` (13 preceding siblings ...)
  2022-11-26 16:59 ` [PATCH 14/17] drivers: fastboot: zImage flashing is not supported for v3, v4 Safae Ouajih
@ 2022-11-26 16:59 ` Safae Ouajih
  2022-11-26 16:59 ` [PATCH 16/17] lib: support libxbc Safae Ouajih
                   ` (4 subsequent siblings)
  19 siblings, 0 replies; 28+ messages in thread
From: Safae Ouajih @ 2022-11-26 16:59 UTC (permalink / raw)
  To: sjg; +Cc: u-boot, sean.anderson, r.stratiienko, mkorpershoek, glaroque, khilman

This enables 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

"struct andr_boot_img_hdr_v0_v1_v2*" is replaced by "void *" in
some functions since v3 and v4 are now supported as well.

Signed-off-by: Safae Ouajih <souajih@baylibre.com>
---
 boot/bootm.c         | 29 ++++++++++++++++++++++++-----
 boot/image-android.c | 16 ++++++++++------
 boot/image-board.c   | 14 +++++++++++---
 boot/image-fdt.c     |  2 +-
 cmd/abootimg.c       | 16 ++++++++++++++--
 include/image.h      | 14 ++++++++------
 6 files changed, 68 insertions(+), 23 deletions(-)

diff --git a/boot/bootm.c b/boot/bootm.c
index e44dc550077d..c0f9b2722d1f 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,12 +185,17 @@ 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 = (void *)get_abootimg_addr();
+			vendor_boot_img = (void *)get_avendor_bootimg_addr();
+		}
 		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;
 		break;
@@ -892,6 +901,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);
@@ -967,8 +980,14 @@ 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 = (void *)get_abootimg_addr();
+			vendor_boot_img = (void *)get_avendor_bootimg_addr();
+		}
 		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;
 		break;
diff --git a/boot/image-android.c b/boot/image-android.c
index 291911ea1852..557047660bc3 100644
--- a/boot/image-android.c
+++ b/boot/image-android.c
@@ -199,7 +199,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_v1_v2 *hdr,
+int android_image_get_kernel(const void *hdr,
 			     const void *vendor_boot_img, int verify,
 			     ulong *os_data, ulong *os_len)
 {
@@ -284,7 +284,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_v1_v2 *hdr)
+bool is_android_boot_image_header(const void *hdr)
 {
 	return !memcmp(ANDR_BOOT_MAGIC, hdr, ANDR_BOOT_MAGIC_SIZE);
 }
@@ -303,7 +303,7 @@ ulong android_image_get_end(const struct andr_boot_img_hdr_v0_v1_v2 *hdr,
 	return img_data.boot_img_total_size;
 }
 
-ulong android_image_get_kload(const struct andr_boot_img_hdr_v0_v1_v2 *hdr,
+ulong android_image_get_kload(const void *hdr,
 			      const void *vendor_boot_img)
 {
 	struct andr_image_data img_data;
@@ -314,7 +314,7 @@ ulong android_image_get_kload(const struct andr_boot_img_hdr_v0_v1_v2 *hdr,
 	return android_image_get_kernel_addr(&img_data);
 }
 
-ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0_v1_v2 *hdr,
+ulong android_image_get_kcomp(const void *hdr,
 			      const void *vendor_boot_img)
 {
 	struct andr_image_data img_data;
@@ -362,14 +362,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_v1_v2 *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 -1;
+	}
+
 	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 c8e41cc8706f..03ce2fb8093a 100644
--- a/boot/image-board.c
+++ b/boot/image-board.c
@@ -426,10 +426,18 @@ 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)) {
+				ret = android_image_get_ramdisk((void *)get_abootimg_addr(),
+								(void *)get_avendor_bootimg_addr(),
+								rd_datap, rd_lenp);
+			} 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 6a08e8a07ed7..a1c122d9768a 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_v1_v2 *hdr = buf;
+		void *hdr = buf;
 		ulong		fdt_data, fdt_len;
 		u32			fdt_size, dtb_idx;
 		/*
diff --git a/cmd/abootimg.c b/cmd/abootimg.c
index e8c70a93cbf4..1e7d22b0da09 100644
--- a/cmd/abootimg.c
+++ b/cmd/abootimg.c
@@ -17,6 +17,16 @@
 static ulong _abootimg_addr = -1;
 static ulong _avendor_bootimg_addr = -1;
 
+ulong get_abootimg_addr(void)
+{
+	return (_abootimg_addr == -1 ? image_load_addr : _abootimg_addr);
+}
+
+ulong get_avendor_bootimg_addr(void)
+{
+	return _avendor_bootimg_addr;
+}
+
 static int abootimg_get_ver(int argc, char *const argv[])
 {
 	const struct andr_boot_img_hdr_v0_v1_v2 *hdr;
@@ -70,7 +80,8 @@ static int abootimg_get_dtb_load_addr(int argc, char *const argv[])
 		return CMD_RET_USAGE;
 	struct andr_image_data img_data = {0};
 
-	if (!android_image_get_data((void *)abootimg_addr(), NULL, &img_data))
+	if (!android_image_get_data((void *)abootimg_addr(),
+				    (void *)get_avendor_bootimg_addr(), &img_data))
 		return CMD_RET_FAILURE;
 
 	if (img_data.header_version < 2) {
@@ -114,7 +125,8 @@ static int abootimg_get_dtb_by_index(int argc, char *const argv[])
 		return CMD_RET_FAILURE;
 	}
 
-	if (!android_image_get_dtb_by_index(abootimg_addr(), NULL, num,
+	if (!android_image_get_dtb_by_index(abootimg_addr(),
+					    (void *)get_avendor_bootimg_addr(), num,
 					    &addr, &size)) {
 		return CMD_RET_FAILURE;
 	}
diff --git a/include/image.h b/include/image.h
index 461e30ae2ac8..f3ffbfffaf88 100644
--- a/include/image.h
+++ b/include/image.h
@@ -1728,29 +1728,31 @@ bool android_image_get_data(const void *boot_hdr, const void *vendor_boot_hdr,
 			    struct andr_image_data *data);
 
 struct andr_boot_img_hdr_v0_v1_v2;
-int android_image_get_kernel(const struct andr_boot_img_hdr_v0_v1_v2 *hdr,
+int android_image_get_kernel(const void *hdr,
 			     const void *vendor_boot_img, int verify,
 			     ulong *os_data, ulong *os_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_v1_v2 *hdr,
-			      ulong *second_data, ulong *second_len);
+int android_image_get_second(const void *hdr, ulong *second_data, ulong *second_len);
 bool android_image_get_dtbo(ulong hdr_addr, ulong *addr, u32 *size);
 bool android_image_get_dtb_by_index(ulong hdr_addr, const void *vendor_boot_img,
 				    u32 index, ulong *addr, u32 *size);
 ulong android_image_get_end(const struct andr_boot_img_hdr_v0_v1_v2 *hdr,
 			    const void *vendor_boot_img);
-ulong android_image_get_kload(const struct andr_boot_img_hdr_v0_v1_v2 *hdr,
+ulong android_image_get_kload(const void *hdr,
 			      const void *vendor_boot_img);
-ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0_v1_v2 *hdr,
+ulong android_image_get_kcomp(const void *hdr,
 			      const void *vendor_boot_img);
 void android_print_contents(const struct andr_boot_img_hdr_v0_v1_v2 *hdr);
 #ifdef CONFIG_CMD_ABOOTIMG
 bool android_image_print_dtb_contents(ulong hdr_addr);
 #endif
-bool is_android_boot_image_header(const struct andr_boot_img_hdr_v0_v1_v2 *hdr);
+bool is_android_boot_image_header(const void *hdr);
 bool is_android_vendor_boot_image_header(const void *vendor_boot_img);
 
+ulong get_abootimg_addr(void);
+ulong get_avendor_bootimg_addr(void);
+
 /**
  * board_fit_config_name_match() - Check for a matching board name
  *
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 16/17] lib: support libxbc
  2022-11-26 16:59 [PATCH 00/17] Support android boot image v3/v4 Safae Ouajih
                   ` (14 preceding siblings ...)
  2022-11-26 16:59 ` [PATCH 15/17] android: boot: support boot image header version 3 and 4 Safae Ouajih
@ 2022-11-26 16:59 ` Safae Ouajih
  2022-11-28 16:02   ` Sean Anderson
  2022-11-26 16:59 ` [PATCH 17/17] android: boot: support bootconfig Safae Ouajih
                   ` (3 subsequent siblings)
  19 siblings, 1 reply; 28+ messages in thread
From: Safae Ouajih @ 2022-11-26 16:59 UTC (permalink / raw)
  To: sjg; +Cc: u-boot, sean.anderson, r.stratiienko, mkorpershoek, glaroque, khilman

This adds support for libxbc used to support Bootconfig feature.
Bootconfig documentation : [1]
This was imported from [2], commit [3]

[1] https://source.android.com/docs/core/architecture/bootloader/implementing-bootconfig
[2] https://android.googlesource.com/platform/external/u-boot/
[3] `7af0a0506d4de6f5ea147d10fb0664a8af07d326`

Signed-off-by: Safae Ouajih <souajih@baylibre.com>
---
 include/xbc.h       |   1 +
 lib/Kconfig         |  12 +++++
 lib/Makefile        |   1 +
 lib/libxbc/Makefile |   1 +
 lib/libxbc/libxbc.c | 112 ++++++++++++++++++++++++++++++++++++++++++++
 lib/libxbc/libxbc.h |  54 +++++++++++++++++++++
 6 files changed, 181 insertions(+)
 create mode 100644 include/xbc.h
 create mode 100644 lib/libxbc/Makefile
 create mode 100644 lib/libxbc/libxbc.c
 create mode 100644 lib/libxbc/libxbc.h

diff --git a/include/xbc.h b/include/xbc.h
new file mode 100644
index 000000000000..725e65ff6ad8
--- /dev/null
+++ b/include/xbc.h
@@ -0,0 +1 @@
+#include <../lib/libxbc/libxbc.h>
diff --git a/lib/Kconfig b/lib/Kconfig
index 6abe1d0a863b..eca752b7db79 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -417,6 +417,18 @@ config LIBAVB
 
 endmenu
 
+menu "Android Boot Configuration"
+config LIBXBC
+	bool "Android Boot Configuration support"
+	depends on ANDROID_BOOT_IMAGE
+	default n
+	help
+	  This enables support of Boot Configuration which can be used
+	  to pass boot configuration parameters to user space. These
+	  parameters will show up in /proc/bootconfig similar to the kernel
+	  parameters that show up in /proc/cmdline
+endmenu
+
 menu "Hashing Support"
 
 config BLAKE2
diff --git a/lib/Makefile b/lib/Makefile
index f2cfd1e42892..b0ad522ac116 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -87,6 +87,7 @@ obj-$(CONFIG_$(SPL_)LZ4) += lz4_wrapper.o
 obj-$(CONFIG_$(SPL_)LIB_RATIONAL) += rational.o
 
 obj-$(CONFIG_LIBAVB) += libavb/
+obj-$(CONFIG_LIBXBC) += libxbc/
 
 obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += libfdt/
 obj-$(CONFIG_$(SPL_TPL_)OF_REAL) += fdtdec_common.o fdtdec.o
diff --git a/lib/libxbc/Makefile b/lib/libxbc/Makefile
new file mode 100644
index 000000000000..7ac4cde05666
--- /dev/null
+++ b/lib/libxbc/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_LIBXBC) += libxbc.o
diff --git a/lib/libxbc/libxbc.c b/lib/libxbc/libxbc.c
new file mode 100644
index 000000000000..129bffc7c628
--- /dev/null
+++ b/lib/libxbc/libxbc.c
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "libxbc.h"
+#define BOOTCONFIG_MAGIC "#BOOTCONFIG\n"
+#define BOOTCONFIG_MAGIC_SIZE 12
+#define BOOTCONFIG_SIZE_SIZE 4
+#define BOOTCONFIG_CHECKSUM_SIZE 4
+#define BOOTCONFIG_TRAILER_SIZE BOOTCONFIG_MAGIC_SIZE + \
+                                BOOTCONFIG_SIZE_SIZE + \
+                                BOOTCONFIG_CHECKSUM_SIZE
+
+/*
+ * Simple checksum for a buffer.
+ *
+ * @param addr pointer to the start of the buffer.
+ * @param size size of the buffer in bytes.
+ * @return check sum result.
+ */
+static uint32_t checksum(const unsigned char* const buffer, uint32_t size) {
+    uint32_t sum = 0;
+    for (uint32_t i = 0; i < size; i++) {
+        sum += buffer[i];
+    }
+    return sum;
+}
+
+/*
+ * Check if the bootconfig trailer is present within the bootconfig section.
+ *
+ * @param bootconfig_end_addr address of the end of the bootconfig section. If
+ *        the trailer is present, it will be directly preceding this address.
+ * @return true if the trailer is present, false if not.
+ */
+static bool isTrailerPresent(uint64_t bootconfig_end_addr) {
+    return !strncmp((char*)(bootconfig_end_addr - BOOTCONFIG_MAGIC_SIZE),
+                    BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_SIZE);
+}
+
+/*
+ * Add a string of boot config parameters to memory appended by the trailer.
+ */
+int32_t addBootConfigParameters(char* params, uint32_t params_size,
+    uint64_t bootconfig_start_addr, uint32_t bootconfig_size) {
+    if (!params || !bootconfig_start_addr) {
+        return -1;
+    }
+    if (params_size == 0) {
+        return 0;
+    }
+    int32_t applied_bytes = 0;
+    int32_t new_size = 0;
+    uint64_t end = bootconfig_start_addr + bootconfig_size;
+    if (isTrailerPresent(end)) {
+      end -= BOOTCONFIG_TRAILER_SIZE;
+      applied_bytes -= BOOTCONFIG_TRAILER_SIZE;
+      memcpy(&new_size, (void *)end, BOOTCONFIG_SIZE_SIZE);
+    } else {
+      new_size = bootconfig_size;
+    }
+    // params
+    memcpy((void*)end, params, params_size);
+    applied_bytes += params_size;
+    applied_bytes += addBootConfigTrailer(bootconfig_start_addr,
+        bootconfig_size + applied_bytes);
+    return applied_bytes;
+}
+
+/*
+ * Add boot config trailer.
+ */
+
+int32_t addBootConfigTrailer(uint64_t bootconfig_start_addr,
+                            uint32_t bootconfig_size) {
+    if (!bootconfig_start_addr) {
+        return -1;
+    }
+
+    if (bootconfig_size == 0) {
+        return 0;
+    }
+
+    uint64_t end = bootconfig_start_addr + bootconfig_size;
+    if (isTrailerPresent(end)) {
+        return 0;
+    }
+
+    // size
+    memcpy((void *)(end), &bootconfig_size, BOOTCONFIG_SIZE_SIZE);
+
+    // checksum
+    uint32_t sum = checksum((unsigned char*)bootconfig_start_addr, bootconfig_size);
+    memcpy((void *)(end + BOOTCONFIG_SIZE_SIZE), &sum, BOOTCONFIG_CHECKSUM_SIZE);
+
+    // magic
+    memcpy((void *)(end + BOOTCONFIG_SIZE_SIZE + BOOTCONFIG_CHECKSUM_SIZE),
+           BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_SIZE);
+
+    return BOOTCONFIG_TRAILER_SIZE;
+}
diff --git a/lib/libxbc/libxbc.h b/lib/libxbc/libxbc.h
new file mode 100644
index 000000000000..0b6ba4960905
--- /dev/null
+++ b/lib/libxbc/libxbc.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef LIBXBC_H_
+#define LIBXBC_H_
+
+#include <common.h>
+/*
+ * Add a string of boot config parameters to memory appended by the trailer.
+ * This memory needs to be immediately following the end of the ramdisks.
+ * The new boot config trailer will be written to the end of the entire
+ * parameter section(previous + new). The trailer contains a 4 byte size of the
+ * parameters, followed by a 4 byte checksum of the parameters, followed by a 12
+ * byte magic string.
+ *
+ * @param params pointer to string of boot config parameters
+ * @param params_size size of params string in bytes
+ * @param bootconfig_start_addr address that the boot config section is starting
+ *        at in memory.
+ * @param bootconfig_size size of the current bootconfig section in bytes.
+ * @return number of bytes added to the boot config section. -1 for error.
+ */
+int addBootConfigParameters(char *params, uint32_t params_size,
+                            uint64_t bootconfig_start_addr,
+                            uint32_t bootconfig_size);
+/*
+ * Add the boot config trailer to the end of the boot config parameter section.
+ * This can be used after the vendor bootconfig section has been placed into
+ * memory if there are no additional parameters that need to be added.
+ * The new boot config trailer will be written to the end of the entire
+ * parameter section at (bootconfig_start_addr + bootconfig_size).
+ * The trailer contains a 4 byte size of the parameters, followed by a 4 byte
+ * checksum of the parameters, followed by a 12 byte magic string.
+ *
+ * @param bootconfig_start_addr address that the boot config section is starting
+ *        at in memory.
+ * @param bootconfig_size size of the current bootconfig section in bytes.
+ * @return number of bytes added to the boot config section. -1 for error.
+ */
+int addBootConfigTrailer(uint64_t bootconfig_start_addr,
+                         uint32_t bootconfig_size);
+#endif /* LIBXBC_H_ */
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 17/17] android: boot: support bootconfig
  2022-11-26 16:59 [PATCH 00/17] Support android boot image v3/v4 Safae Ouajih
                   ` (15 preceding siblings ...)
  2022-11-26 16:59 ` [PATCH 16/17] lib: support libxbc Safae Ouajih
@ 2022-11-26 16:59 ` Safae Ouajih
  2022-11-28  9:43 ` [PATCH 00/17] Support android boot image v3/v4 Mattijs Korpershoek
                   ` (2 subsequent siblings)
  19 siblings, 0 replies; 28+ messages in thread
From: Safae Ouajih @ 2022-11-26 16:59 UTC (permalink / raw)
  To: sjg; +Cc: u-boot, sean.anderson, r.stratiienko, mkorpershoek, glaroque, khilman

This adds support for Bootconfig feature.
- The bootconfig feature replaces the androidboot.*
  kernel cmdline options.
- CONFIG_LIBXBC must be enabled

Signed-off-by: Safae Ouajih <souajih@baylibre.com>
---
 boot/image-android.c    | 22 +++++++++++++++++++++-
 include/android_image.h |  3 +++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/boot/image-android.c b/boot/image-android.c
index 557047660bc3..1c4d21e945a1 100644
--- a/boot/image-android.c
+++ b/boot/image-android.c
@@ -14,6 +14,10 @@
 #include <mapmem.h>
 #include <linux/libfdt.h>
 
+#ifdef CONFIG_LIBXB
+#include <xbc.h>
+#endif
+
 #define ANDROID_IMAGE_DEFAULT_KERNEL_ADDR	0x10008000
 
 static char andr_tmp_str[ANDR_BOOT_ARGS_SIZE + 1];
@@ -60,6 +64,7 @@ static void android_vendor_boot_image_v3_v4_parse_hdr(const struct andr_vendor_b
 	data->image_name = hdr->name;
 	data->kernel_addr = hdr->kernel_addr;
 	data->ramdisk_addr = hdr->ramdisk_addr;
+	data->bootconfig_size = hdr->bootconfig_size;
 	end = (ulong)hdr;
 	end += hdr->page_size;
 	if (hdr->vendor_ramdisk_size) {
@@ -74,7 +79,15 @@ static void android_vendor_boot_image_v3_v4_parse_hdr(const struct andr_vendor_b
 
 	end += ALIGN(hdr->dtb_size, hdr->page_size);
 	end += ALIGN(hdr->vendor_ramdisk_table_size, hdr->page_size);
-	end += ALIGN(hdr->bootconfig_size, hdr->page_size);
+#ifdef CONFIG_LIBXB
+	data->bootconfig_addr = end;
+	if (hdr->bootconfig_size) {
+		data->bootconfig_size += addBootConfigTrailer(data->bootconfig_addr,
+							      data->bootconfig_size);
+		data->ramdisk_size += data->bootconfig_size;
+	}
+#endif
+	end += ALIGN(data->bootconfig_size, hdr->page_size);
 	data->vendor_boot_img_total_size = end - (ulong)hdr;
 }
 
@@ -351,6 +364,13 @@ int android_image_get_ramdisk(const void *hdr, const void *vendor_boot_img,
 		       img_data.vendor_ramdisk_size);
 		memcpy((void *)(ramdisk_ptr + img_data.vendor_ramdisk_size),
 		       (void *)img_data.ramdisk_ptr, img_data.boot_ramdisk_size);
+#ifdef CONFIG_LIBXB
+		if (img_data.bootconfig_size) {
+			memcpy((void *)(ramdisk_ptr + img_data.vendor_ramdisk_size +
+			       img_data.boot_ramdisk_size), (void *)img_data.bootconfig_addr,
+			       img_data.bootconfig_size);
+		}
+#endif
 	}
 
 	printf("RAM disk load addr 0x%08lx size %u KiB\n",
diff --git a/include/android_image.h b/include/android_image.h
index b9591633c9f7..17412a609320 100644
--- a/include/android_image.h
+++ b/include/android_image.h
@@ -333,6 +333,9 @@ struct andr_image_data {
 	ulong recovery_dtbo_ptr;
 	u32 recovery_dtbo_size;
 
+	ulong bootconfig_addr;
+	ulong bootconfig_size;
+
 	const char *kcmdline;
 	const char *kcmdline_extra;
 	const char *image_name;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* Re: [PATCH 00/17] Support android boot image v3/v4
  2022-11-26 16:59 [PATCH 00/17] Support android boot image v3/v4 Safae Ouajih
                   ` (16 preceding siblings ...)
  2022-11-26 16:59 ` [PATCH 17/17] android: boot: support bootconfig Safae Ouajih
@ 2022-11-28  9:43 ` Mattijs Korpershoek
  2022-12-04 21:16 ` Simon Glass
  2022-12-30  1:48 ` Tom Rini
  19 siblings, 0 replies; 28+ messages in thread
From: Mattijs Korpershoek @ 2022-11-28  9:43 UTC (permalink / raw)
  To: Safae Ouajih, sjg; +Cc: u-boot, sean.anderson, r.stratiienko, glaroque, khilman

On Sat, Nov 26, 2022 at 17:59, Safae Ouajih <souajih@baylibre.com> wrote:

> Hello everyone,
>
> * This is based on Roman Stratiienko's work to support boot image header version 3 and 4.
>
> * This supports the new boot image headers v3, v4 and bootconfig feature.
> https://source.android.com/docs/core/architecture/bootloader/boot-image-header
> https://source.android.com/docs/core/architecture/bootloader/implementing-bootconfig
>
> - Tested on Amlogic Khadas vim3l, a reference board for Android Open Source Project
>   https://www.khadas.com/vim3l
>
>   And on AM625 Texas Instruments board with 5.10 linux kernel
>
> Main changes :
> - New partition : vendor boot, with a specific vendor ramdisk
> - DTB is stored in the vendor boot partition
> - The generic ramdisk is placed after the vendor ramdisk
> - Bootconfig feature support
>
>
> Here is a link to see the related android boot flow changes on KHADAS vim3l as an example:
> https://gitlab.baylibre.com/baylibre/amlogic/atv/u-boot/-/commits/souajih/BootImagev4/

Tested the whole series on Khadas vim3l board with boot header v2.

Tested-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>

>
> Safae Ouajih (17):
>   android: boot: rename andr_img_hdr -> andr_boot_img_hdr_v0_v1_v2
>   android: boot: support vendor boot image in abootimg
>   android: boot: replace android_image_check_header
>   android: boot: add boot image header v3 and v4 structures
>   android: boot: add documentation for boot image header v3/v4 structure
>   android: boot: kcomp: support andr_image_data
>   android: boot: move to andr_image_data structure
>   android: boot: content print is not supported for v3,v4 header version
>   android: boot: boot image header v3,v4 do not support recovery DTBO
>   android: boot: add vendor boot image to prepare for v3,v4 support
>   android: boot: update android_image_get_data to support v3,v4
>   android: boot: ramdisk: support vendor ramdisk
>   android: boot: support extra command line
>   drivers: fastboot: zImage flashing is not supported for v3,v4
>   android: boot: support boot image header version 3 and 4
>   lib: support libxbc
>   android: boot: support bootconfig
>
>  boot/bootm.c              |  29 ++-
>  boot/image-android.c      | 367 ++++++++++++++++++++++++++++++--------
>  boot/image-board.c        |  15 +-
>  boot/image-fdt.c          |   5 +-
>  cmd/abootimg.c            |  66 ++++---
>  drivers/fastboot/fb_mmc.c |  19 +-
>  include/android_image.h   | 220 ++++++++++++++++++++++-
>  include/image.h           |  37 ++--
>  include/xbc.h             |   1 +
>  lib/Kconfig               |  12 ++
>  lib/Makefile              |   1 +
>  lib/libxbc/Makefile       |   1 +
>  lib/libxbc/libxbc.c       | 112 ++++++++++++
>  lib/libxbc/libxbc.h       |  54 ++++++
>  14 files changed, 806 insertions(+), 133 deletions(-)
>  create mode 100644 include/xbc.h
>  create mode 100644 lib/libxbc/Makefile
>  create mode 100644 lib/libxbc/libxbc.c
>  create mode 100644 lib/libxbc/libxbc.h
>
> --
> 2.25.1

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 16/17] lib: support libxbc
  2022-11-26 16:59 ` [PATCH 16/17] lib: support libxbc Safae Ouajih
@ 2022-11-28 16:02   ` Sean Anderson
  0 siblings, 0 replies; 28+ messages in thread
From: Sean Anderson @ 2022-11-28 16:02 UTC (permalink / raw)
  To: Safae Ouajih, sjg; +Cc: u-boot, r.stratiienko, mkorpershoek, glaroque, khilman

On 11/26/22 11:59, Safae Ouajih wrote:
> [You don't often get email from souajih@baylibre.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
> 
> This adds support for libxbc used to support Bootconfig feature.
> Bootconfig documentation : [1]
> This was imported from [2], commit [3]

This should be written something like

This was adapted from downstream [2] commit 7af0a0506d4 ("shortlog
summary").

> 
> [1] https://source.android.com/docs/core/architecture/bootloader/implementing-bootconfig
> [2] https://android.googlesource.com/platform/external/u-boot/
> [3] `7af0a0506d4de6f5ea147d10fb0664a8af07d326`
> 
> Signed-off-by: Safae Ouajih <souajih@baylibre.com>
> ---
>  include/xbc.h       |   1 +
>  lib/Kconfig         |  12 +++++
>  lib/Makefile        |   1 +
>  lib/libxbc/Makefile |   1 +
>  lib/libxbc/libxbc.c | 112 ++++++++++++++++++++++++++++++++++++++++++++
>  lib/libxbc/libxbc.h |  54 +++++++++++++++++++++
>  6 files changed, 181 insertions(+)
>  create mode 100644 include/xbc.h
>  create mode 100644 lib/libxbc/Makefile
>  create mode 100644 lib/libxbc/libxbc.c
>  create mode 100644 lib/libxbc/libxbc.h

I understand that you may want to import this "library" directly, but it
is really so short that I question the virtue of this. I think it would
be better to convert this to U-Boot style.

--Sean

> diff --git a/include/xbc.h b/include/xbc.h
> new file mode 100644
> index 000000000000..725e65ff6ad8
> --- /dev/null
> +++ b/include/xbc.h
> @@ -0,0 +1 @@
> +#include <../lib/libxbc/libxbc.h>
> diff --git a/lib/Kconfig b/lib/Kconfig
> index 6abe1d0a863b..eca752b7db79 100644
> --- a/lib/Kconfig
> +++ b/lib/Kconfig
> @@ -417,6 +417,18 @@ config LIBAVB
> 
>  endmenu
> 
> +menu "Android Boot Configuration"
> +config LIBXBC
> +       bool "Android Boot Configuration support"
> +       depends on ANDROID_BOOT_IMAGE
> +       default n
> +       help
> +         This enables support of Boot Configuration which can be used
> +         to pass boot configuration parameters to user space. These
> +         parameters will show up in /proc/bootconfig similar to the kernel
> +         parameters that show up in /proc/cmdline
> +endmenu
> +
>  menu "Hashing Support"
> 
>  config BLAKE2
> diff --git a/lib/Makefile b/lib/Makefile
> index f2cfd1e42892..b0ad522ac116 100644
> --- a/lib/Makefile
> +++ b/lib/Makefile
> @@ -87,6 +87,7 @@ obj-$(CONFIG_$(SPL_)LZ4) += lz4_wrapper.o
>  obj-$(CONFIG_$(SPL_)LIB_RATIONAL) += rational.o
> 
>  obj-$(CONFIG_LIBAVB) += libavb/
> +obj-$(CONFIG_LIBXBC) += libxbc/
> 
>  obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += libfdt/
>  obj-$(CONFIG_$(SPL_TPL_)OF_REAL) += fdtdec_common.o fdtdec.o
> diff --git a/lib/libxbc/Makefile b/lib/libxbc/Makefile
> new file mode 100644
> index 000000000000..7ac4cde05666
> --- /dev/null
> +++ b/lib/libxbc/Makefile
> @@ -0,0 +1 @@
> +obj-$(CONFIG_LIBXBC) += libxbc.o
> diff --git a/lib/libxbc/libxbc.c b/lib/libxbc/libxbc.c
> new file mode 100644
> index 000000000000..129bffc7c628
> --- /dev/null
> +++ b/lib/libxbc/libxbc.c
> @@ -0,0 +1,112 @@
> +/*
> + * Copyright (C) 2021 The Android Open Source Project
> + *
> + * Licensed under the Apache License, Version 2.0 (the "License");
> + * you may not use this file except in compliance with the License.
> + * You may obtain a copy of the License at
> + *
> + *      http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + */
> +#include "libxbc.h"
> +#define BOOTCONFIG_MAGIC "#BOOTCONFIG\n"
> +#define BOOTCONFIG_MAGIC_SIZE 12
> +#define BOOTCONFIG_SIZE_SIZE 4
> +#define BOOTCONFIG_CHECKSUM_SIZE 4
> +#define BOOTCONFIG_TRAILER_SIZE BOOTCONFIG_MAGIC_SIZE + \
> +                                BOOTCONFIG_SIZE_SIZE + \
> +                                BOOTCONFIG_CHECKSUM_SIZE
> +
> +/*
> + * Simple checksum for a buffer.
> + *
> + * @param addr pointer to the start of the buffer.
> + * @param size size of the buffer in bytes.
> + * @return check sum result.
> + */
> +static uint32_t checksum(const unsigned char* const buffer, uint32_t size) {
> +    uint32_t sum = 0;
> +    for (uint32_t i = 0; i < size; i++) {
> +        sum += buffer[i];
> +    }
> +    return sum;
> +}
> +
> +/*
> + * Check if the bootconfig trailer is present within the bootconfig section.
> + *
> + * @param bootconfig_end_addr address of the end of the bootconfig section. If
> + *        the trailer is present, it will be directly preceding this address.
> + * @return true if the trailer is present, false if not.
> + */
> +static bool isTrailerPresent(uint64_t bootconfig_end_addr) {
> +    return !strncmp((char*)(bootconfig_end_addr - BOOTCONFIG_MAGIC_SIZE),
> +                    BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_SIZE);
> +}
> +
> +/*
> + * Add a string of boot config parameters to memory appended by the trailer.
> + */
> +int32_t addBootConfigParameters(char* params, uint32_t params_size,
> +    uint64_t bootconfig_start_addr, uint32_t bootconfig_size) {
> +    if (!params || !bootconfig_start_addr) {
> +        return -1;
> +    }
> +    if (params_size == 0) {
> +        return 0;
> +    }
> +    int32_t applied_bytes = 0;
> +    int32_t new_size = 0;
> +    uint64_t end = bootconfig_start_addr + bootconfig_size;
> +    if (isTrailerPresent(end)) {
> +      end -= BOOTCONFIG_TRAILER_SIZE;
> +      applied_bytes -= BOOTCONFIG_TRAILER_SIZE;
> +      memcpy(&new_size, (void *)end, BOOTCONFIG_SIZE_SIZE);
> +    } else {
> +      new_size = bootconfig_size;
> +    }
> +    // params
> +    memcpy((void*)end, params, params_size);
> +    applied_bytes += params_size;
> +    applied_bytes += addBootConfigTrailer(bootconfig_start_addr,
> +        bootconfig_size + applied_bytes);
> +    return applied_bytes;
> +}
> +
> +/*
> + * Add boot config trailer.
> + */
> +
> +int32_t addBootConfigTrailer(uint64_t bootconfig_start_addr,
> +                            uint32_t bootconfig_size) {
> +    if (!bootconfig_start_addr) {
> +        return -1;
> +    }
> +
> +    if (bootconfig_size == 0) {
> +        return 0;
> +    }
> +
> +    uint64_t end = bootconfig_start_addr + bootconfig_size;
> +    if (isTrailerPresent(end)) {
> +        return 0;
> +    }
> +
> +    // size
> +    memcpy((void *)(end), &bootconfig_size, BOOTCONFIG_SIZE_SIZE);
> +
> +    // checksum
> +    uint32_t sum = checksum((unsigned char*)bootconfig_start_addr, bootconfig_size);
> +    memcpy((void *)(end + BOOTCONFIG_SIZE_SIZE), &sum, BOOTCONFIG_CHECKSUM_SIZE);
> +
> +    // magic
> +    memcpy((void *)(end + BOOTCONFIG_SIZE_SIZE + BOOTCONFIG_CHECKSUM_SIZE),
> +           BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_SIZE);
> +
> +    return BOOTCONFIG_TRAILER_SIZE;
> +}
> diff --git a/lib/libxbc/libxbc.h b/lib/libxbc/libxbc.h
> new file mode 100644
> index 000000000000..0b6ba4960905
> --- /dev/null
> +++ b/lib/libxbc/libxbc.h
> @@ -0,0 +1,54 @@
> +/*
> + * Copyright (C) 2021 The Android Open Source Project
> + *
> + * Licensed under the Apache License, Version 2.0 (the "License");
> + * you may not use this file except in compliance with the License.
> + * You may obtain a copy of the License at
> + *
> + *      http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + */
> +#ifndef LIBXBC_H_
> +#define LIBXBC_H_
> +
> +#include <common.h>
> +/*
> + * Add a string of boot config parameters to memory appended by the trailer.
> + * This memory needs to be immediately following the end of the ramdisks.
> + * The new boot config trailer will be written to the end of the entire
> + * parameter section(previous + new). The trailer contains a 4 byte size of the
> + * parameters, followed by a 4 byte checksum of the parameters, followed by a 12
> + * byte magic string.
> + *
> + * @param params pointer to string of boot config parameters
> + * @param params_size size of params string in bytes
> + * @param bootconfig_start_addr address that the boot config section is starting
> + *        at in memory.
> + * @param bootconfig_size size of the current bootconfig section in bytes.
> + * @return number of bytes added to the boot config section. -1 for error.
> + */
> +int addBootConfigParameters(char *params, uint32_t params_size,
> +                            uint64_t bootconfig_start_addr,
> +                            uint32_t bootconfig_size);
> +/*
> + * Add the boot config trailer to the end of the boot config parameter section.
> + * This can be used after the vendor bootconfig section has been placed into
> + * memory if there are no additional parameters that need to be added.
> + * The new boot config trailer will be written to the end of the entire
> + * parameter section at (bootconfig_start_addr + bootconfig_size).
> + * The trailer contains a 4 byte size of the parameters, followed by a 4 byte
> + * checksum of the parameters, followed by a 12 byte magic string.
> + *
> + * @param bootconfig_start_addr address that the boot config section is starting
> + *        at in memory.
> + * @param bootconfig_size size of the current bootconfig section in bytes.
> + * @return number of bytes added to the boot config section. -1 for error.
> + */
> +int addBootConfigTrailer(uint64_t bootconfig_start_addr,
> +                         uint32_t bootconfig_size);
> +#endif /* LIBXBC_H_ */
> --
> 2.25.1
> 

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 01/17] android: boot: rename andr_img_hdr -> andr_boot_img_hdr_v0_v1_v2
  2022-11-26 16:59 ` [PATCH 01/17] android: boot: rename andr_img_hdr -> andr_boot_img_hdr_v0_v1_v2 Safae Ouajih
@ 2022-11-28 16:08   ` Sean Anderson
  2022-11-29 11:07     ` Safae Ouajih
  0 siblings, 1 reply; 28+ messages in thread
From: Sean Anderson @ 2022-11-28 16:08 UTC (permalink / raw)
  To: Safae Ouajih, sjg; +Cc: u-boot, r.stratiienko, mkorpershoek, glaroque, khilman

On 11/26/22 11:59, Safae Ouajih wrote:
> [You don't often get email from souajih@baylibre.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
> 
> Android introduced boot header version 3 or 4.
> The header structure change with version 3 and 4 to support
> the new updates such as:
> - Introducing Vendor boot image: with a vendor ramdisk
> - Bootconfig feature (v4)
> 
> To maintain support for version v0, v1 and v2 while introducing
> version 3 and 4, this struct name must change to refer to the header
> structure before v3.
> 
> Signed-off-by: Safae Ouajih <souajih@baylibre.com>
> ---
>  boot/image-android.c      | 26 +++++++++++++-------------
>  boot/image-fdt.c          |  2 +-
>  cmd/abootimg.c            |  4 ++--
>  drivers/fastboot/fb_mmc.c |  8 ++++----
>  include/android_image.h   |  4 ++--
>  include/image.h           | 18 +++++++++---------
>  6 files changed, 31 insertions(+), 31 deletions(-)
> 
> diff --git a/boot/image-android.c b/boot/image-android.c
> index 2628db374121..926d94ecbe8e 100644
> --- a/boot/image-android.c
> +++ b/boot/image-android.c
> @@ -18,7 +18,7 @@
> 
>  static char andr_tmp_str[ANDR_BOOT_ARGS_SIZE + 1];
> 
> -static ulong android_image_get_kernel_addr(const struct andr_img_hdr *hdr)
> +static ulong android_image_get_kernel_addr(const struct andr_boot_img_hdr_v0_v1_v2 *hdr)

This line is too long. You will have to break it like

static ulong 
android_image_get_kernel_addr(const struct andr_boot_img_hdr_v0_v1_v2 *hdr)

But really, this is because your struct name is too long. Can we use
something like andr_img_hdr_v0 instead? I would like to have only one
version in the struct name because then there is no urge to update the
name when e.g. v5 comes out with mostly the same format. And _boot adds
nothing.

--Sean

>  {
>         /*
>          * All the Android tools that generate a boot.img use this
> @@ -59,7 +59,7 @@ static ulong android_image_get_kernel_addr(const struct andr_img_hdr *hdr)
>   * Return: Zero, os start address and length on success,
>   *             otherwise on failure.
>   */
> -int android_image_get_kernel(const struct andr_img_hdr *hdr, int verify,
> +int android_image_get_kernel(const struct andr_boot_img_hdr_v0_v1_v2 *hdr, int verify,
>                              ulong *os_data, ulong *os_len)
>  {
>         u32 kernel_addr = android_image_get_kernel_addr(hdr);
> @@ -122,12 +122,12 @@ int android_image_get_kernel(const struct andr_img_hdr *hdr, int verify,
>         return 0;
>  }
> 
> -int android_image_check_header(const struct andr_img_hdr *hdr)
> +int android_image_check_header(const struct andr_boot_img_hdr_v0_v1_v2 *hdr)
>  {
>         return memcmp(ANDR_BOOT_MAGIC, hdr->magic, ANDR_BOOT_MAGIC_SIZE);
>  }
> 
> -ulong android_image_get_end(const struct andr_img_hdr *hdr)
> +ulong android_image_get_end(const struct andr_boot_img_hdr_v0_v1_v2 *hdr)
>  {
>         ulong end;
> 
> @@ -150,12 +150,12 @@ ulong android_image_get_end(const struct andr_img_hdr *hdr)
>         return end;
>  }
> 
> -ulong android_image_get_kload(const struct andr_img_hdr *hdr)
> +ulong android_image_get_kload(const struct andr_boot_img_hdr_v0_v1_v2 *hdr)
>  {
>         return android_image_get_kernel_addr(hdr);
>  }
> 
> -ulong android_image_get_kcomp(const struct andr_img_hdr *hdr)
> +ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0_v1_v2 *hdr)
>  {
>         const void *p = (void *)((uintptr_t)hdr + hdr->page_size);
> 
> @@ -167,7 +167,7 @@ ulong android_image_get_kcomp(const struct andr_img_hdr *hdr)
>                 return image_decomp_type(p, sizeof(u32));
>  }
> 
> -int android_image_get_ramdisk(const struct andr_img_hdr *hdr,
> +int android_image_get_ramdisk(const struct andr_boot_img_hdr_v0_v1_v2 *hdr,
>                               ulong *rd_data, ulong *rd_len)
>  {
>         if (!hdr->ramdisk_size) {
> @@ -186,7 +186,7 @@ int android_image_get_ramdisk(const struct andr_img_hdr *hdr,
>         return 0;
>  }
> 
> -int android_image_get_second(const struct andr_img_hdr *hdr,
> +int android_image_get_second(const struct andr_boot_img_hdr_v0_v1_v2 *hdr,
>                               ulong *second_data, ulong *second_len)
>  {
>         if (!hdr->second_size) {
> @@ -226,7 +226,7 @@ int android_image_get_second(const struct andr_img_hdr *hdr,
>   */
>  bool android_image_get_dtbo(ulong hdr_addr, ulong *addr, u32 *size)
>  {
> -       const struct andr_img_hdr *hdr;
> +       const struct andr_boot_img_hdr_v0_v1_v2 *hdr;
>         ulong dtbo_img_addr;
>         bool ret = true;
> 
> @@ -275,7 +275,7 @@ exit:
>   */
>  static bool android_image_get_dtb_img_addr(ulong hdr_addr, ulong *addr)
>  {
> -       const struct andr_img_hdr *hdr;
> +       const struct andr_boot_img_hdr_v0_v1_v2 *hdr;
>         ulong dtb_img_addr;
>         bool ret = true;
> 
> @@ -328,7 +328,7 @@ exit:
>  bool android_image_get_dtb_by_index(ulong hdr_addr, u32 index, ulong *addr,
>                                     u32 *size)
>  {
> -       const struct andr_img_hdr *hdr;
> +       const struct andr_boot_img_hdr_v0_v1_v2 *hdr;
>         bool res;
>         ulong dtb_img_addr;     /* address of DTB part in boot image */
>         u32 dtb_img_size;       /* size of DTB payload in boot image */
> @@ -393,7 +393,7 @@ bool android_image_get_dtb_by_index(ulong hdr_addr, u32 index, ulong *addr,
>   * returns:
>   *     no returned results
>   */
> -void android_print_contents(const struct andr_img_hdr *hdr)
> +void android_print_contents(const struct andr_boot_img_hdr_v0_v1_v2 *hdr)
>  {
>         const char * const p = IMAGE_INDENT_STRING;
>         /* os_version = ver << 11 | lvl */
> @@ -485,7 +485,7 @@ static bool android_image_print_dtb_info(const struct fdt_header *fdt,
>   */
>  bool android_image_print_dtb_contents(ulong hdr_addr)
>  {
> -       const struct andr_img_hdr *hdr;
> +       const struct andr_boot_img_hdr_v0_v1_v2 *hdr;
>         bool res;
>         ulong dtb_img_addr;     /* address of DTB part in boot image */
>         u32 dtb_img_size;       /* size of DTB payload in boot image */
> diff --git a/boot/image-fdt.c b/boot/image-fdt.c
> index b830a0ab4187..b7cc9bfd538f 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_img_hdr *hdr = buf;
> +               struct andr_boot_img_hdr_v0_v1_v2 *hdr = buf;
>                 ulong           fdt_data, fdt_len;
>                 u32                     fdt_size, dtb_idx;
>                 /*
> diff --git a/cmd/abootimg.c b/cmd/abootimg.c
> index f48a9dcb021d..de2aa3307d9a 100644
> --- a/cmd/abootimg.c
> +++ b/cmd/abootimg.c
> @@ -18,7 +18,7 @@ static ulong _abootimg_addr = -1;
> 
>  static int abootimg_get_ver(int argc, char *const argv[])
>  {
> -       const struct andr_img_hdr *hdr;
> +       const struct andr_boot_img_hdr_v0_v1_v2 *hdr;
>         int res = CMD_RET_SUCCESS;
> 
>         if (argc > 1)
> @@ -65,7 +65,7 @@ static int abootimg_get_recovery_dtbo(int argc, char *const argv[])
> 
>  static int abootimg_get_dtb_load_addr(int argc, char *const argv[])
>  {
> -       const struct andr_img_hdr *hdr;
> +       const struct andr_boot_img_hdr_v0_v1_v2 *hdr;
>         int res = CMD_RET_SUCCESS;
> 
>         if (argc > 1)
> diff --git a/drivers/fastboot/fb_mmc.c b/drivers/fastboot/fb_mmc.c
> index 033c510bc096..7b2f964b4c72 100644
> --- a/drivers/fastboot/fb_mmc.c
> +++ b/drivers/fastboot/fb_mmc.c
> @@ -287,7 +287,7 @@ static void fb_mmc_boot_ops(struct blk_desc *dev_desc, void *buffer,
>   */
>  static lbaint_t fb_mmc_get_boot_header(struct blk_desc *dev_desc,
>                                        struct disk_partition *info,
> -                                      struct andr_img_hdr *hdr,
> +                                      struct andr_boot_img_hdr_v0_v1_v2 *hdr,
>                                        char *response)
>  {
>         ulong sector_size;              /* boot partition sector size */
> @@ -296,7 +296,7 @@ static lbaint_t fb_mmc_get_boot_header(struct blk_desc *dev_desc,
> 
>         /* Calculate boot image sectors count */
>         sector_size = info->blksz;
> -       hdr_sectors = DIV_ROUND_UP(sizeof(struct andr_img_hdr), sector_size);
> +       hdr_sectors = DIV_ROUND_UP(sizeof(struct andr_boot_img_hdr_v0_v1_v2), sector_size);
>         if (hdr_sectors == 0) {
>                 pr_err("invalid number of boot sectors: 0\n");
>                 fastboot_fail("invalid number of boot sectors: 0", response);
> @@ -338,7 +338,7 @@ static int fb_mmc_update_zimage(struct blk_desc *dev_desc,
>                                 char *response)
>  {
>         uintptr_t hdr_addr;                     /* boot image header address */
> -       struct andr_img_hdr *hdr;               /* boot image header */
> +       struct andr_boot_img_hdr_v0_v1_v2 *hdr;         /* boot image header */
>         lbaint_t hdr_sectors;                   /* boot image header sectors */
>         u8 *ramdisk_buffer;
>         u32 ramdisk_sector_start;
> @@ -361,7 +361,7 @@ static int fb_mmc_update_zimage(struct blk_desc *dev_desc,
> 
>         /* Put boot image header in fastboot buffer after downloaded zImage */
>         hdr_addr = (uintptr_t)download_buffer + ALIGN(download_bytes, PAGE_SIZE);
> -       hdr = (struct andr_img_hdr *)hdr_addr;
> +       hdr = (struct andr_boot_img_hdr_v0_v1_v2 *)hdr_addr;
> 
>         /* Read boot image header */
>         hdr_sectors = fb_mmc_get_boot_header(dev_desc, &info, hdr, response);
> diff --git a/include/android_image.h b/include/android_image.h
> index 54d25af0684a..bf9b8c6f0955 100644
> --- a/include/android_image.h
> +++ b/include/android_image.h
> @@ -20,9 +20,9 @@
>  #define ANDR_BOOT_ARGS_SIZE 512
>  #define ANDR_BOOT_EXTRA_ARGS_SIZE 1024
> 
> -/* The bootloader expects the structure of andr_img_hdr with header
> +/* The bootloader expects the structure of andr_boot_img_hdr_v0_v1_v2 with header
>   * version 0 to be as follows: */
> -struct andr_img_hdr {
> +struct andr_boot_img_hdr_v0_v1_v2 {
>      /* Must be ANDR_BOOT_MAGIC. */
>      char magic[ANDR_BOOT_MAGIC_SIZE];
> 
> diff --git a/include/image.h b/include/image.h
> index 6f21dafba8ce..931cf18c7e82 100644
> --- a/include/image.h
> +++ b/include/image.h
> @@ -1723,21 +1723,21 @@ int fit_image_cipher_get_algo(const void *fit, int noffset, char **algo);
> 
>  struct cipher_algo *image_get_cipher_algo(const char *full_name);
> 
> -struct andr_img_hdr;
> -int android_image_check_header(const struct andr_img_hdr *hdr);
> -int android_image_get_kernel(const struct andr_img_hdr *hdr, int verify,
> +struct andr_boot_img_hdr_v0_v1_v2;
> +int android_image_check_header(const struct andr_boot_img_hdr_v0_v1_v2 *hdr);
> +int android_image_get_kernel(const struct andr_boot_img_hdr_v0_v1_v2 *hdr, int verify,
>                              ulong *os_data, ulong *os_len);
> -int android_image_get_ramdisk(const struct andr_img_hdr *hdr,
> +int android_image_get_ramdisk(const struct andr_boot_img_hdr_v0_v1_v2 *hdr,
>                               ulong *rd_data, ulong *rd_len);
> -int android_image_get_second(const struct andr_img_hdr *hdr,
> +int android_image_get_second(const struct andr_boot_img_hdr_v0_v1_v2 *hdr,
>                               ulong *second_data, ulong *second_len);
>  bool android_image_get_dtbo(ulong hdr_addr, ulong *addr, u32 *size);
>  bool android_image_get_dtb_by_index(ulong hdr_addr, u32 index, ulong *addr,
>                                     u32 *size);
> -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);
> +ulong android_image_get_end(const struct andr_boot_img_hdr_v0_v1_v2 *hdr);
> +ulong android_image_get_kload(const struct andr_boot_img_hdr_v0_v1_v2 *hdr);
> +ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0_v1_v2 *hdr);
> +void android_print_contents(const struct andr_boot_img_hdr_v0_v1_v2 *hdr);
>  bool android_image_print_dtb_contents(ulong hdr_addr);
> 
>  /**
> --
> 2.25.1
> 

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 05/17] android: boot: add documentation for boot image header v3/v4 structure
  2022-11-26 16:59 ` [PATCH 05/17] android: boot: add documentation for boot image header v3/v4 structure Safae Ouajih
@ 2022-11-28 16:12   ` Sean Anderson
  0 siblings, 0 replies; 28+ messages in thread
From: Sean Anderson @ 2022-11-28 16:12 UTC (permalink / raw)
  To: Safae Ouajih, sjg; +Cc: u-boot, r.stratiienko, mkorpershoek, glaroque, khilman

On 11/26/22 11:59, Safae Ouajih wrote:
> [You don't often get email from souajih@baylibre.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
> 
> This was imported from [1], commit [2], file: include/bootimg/bootimg.h
> [1] https://android.googlesource.com/platform/system/tools/mkbootimg
> [2] cce5b1923e3cd2fcb765b512610bdc5c42bc501d

In general, downstream commits are not terribly useful. However, this is just
the current tip of that repo, not even the commit which this is imported from.

Please write your commit messages to describe what you are doing and why.

> Signed-off-by: Safae Ouajih <souajih@baylibre.com>
> ---
>  include/android_image.h | 136 +++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 135 insertions(+), 1 deletion(-)
> 
> diff --git a/include/android_image.h b/include/android_image.h
> index ec36e6512ad6..62121e2a109b 100644
> --- a/include/android_image.h
> +++ b/include/android_image.h
> @@ -3,7 +3,7 @@
>   * This is from the Android Project,
>   * Repository: https://android.googlesource.com/platform/system/tools/mkbootimg
>   * File: include/bootimg/bootimg.h
> - * Commit: e55998a0f2b61b685d5eb4a486ca3a0c680b1a2f
> + * Commit: cce5b1923e3cd2fcb765b512610bdc5c42bc501d
>   *
>   * Copyright (C) 2007 The Android Open Source Project
>   */
> @@ -183,4 +183,138 @@ struct andr_boot_img_hdr_v0_v1_v2 {
>   *    else: jump to kernel_addr
>   */
> 
> +/* When the boot image header has a version of 3, the structure of the boot
> + * image is as follows:
> + *
> + * +---------------------+
> + * | boot header         | 4096 bytes
> + * +---------------------+
> + * | kernel              | m pages
> + * +---------------------+
> + * | ramdisk             | n pages
> + * +---------------------+
> + *
> + * m = (kernel_size + 4096 - 1) / 4096
> + * n = (ramdisk_size + 4096 - 1) / 4096
> + *
> + * Note that in version 3 of the boot image header, page size is fixed at 4096 bytes.
> + *
> + * The structure of the vendor boot image (introduced with version 3 and
> + * required to be present when a v3 boot image is used) is as follows:
> + *
> + * +---------------------+
> + * | vendor boot header  | o pages
> + * +---------------------+
> + * | vendor ramdisk      | p pages
> + * +---------------------+
> + * | dtb                 | q pages
> + * +---------------------+
> + * o = (2112 + page_size - 1) / page_size
> + * p = (vendor_ramdisk_size + page_size - 1) / page_size
> + * q = (dtb_size + page_size - 1) / page_size
> + *
> + * 0. all entities in the boot image are 4096-byte aligned in flash, all
> + *    entities in the vendor boot image are page_size (determined by the vendor
> + *    and specified in the vendor boot image header) aligned in flash
> + * 1. kernel, ramdisk, vendor ramdisk, and DTB are required (size != 0)
> + * 2. load the kernel and DTB at the specified physical address (kernel_addr,
> + *    dtb_addr)
> + * 3. load the vendor ramdisk at ramdisk_addr
> + * 4. load the generic ramdisk immediately following the vendor ramdisk in
> + *    memory
> + * 5. set up registers for kernel entry as required by your architecture
> + * 6. if the platform has a second stage bootloader jump to it (must be
> + *    contained outside boot and vendor boot partitions), otherwise
> + *    jump to kernel_addr
> + */
> +
> +/* When the boot image header has a version of 4, the structure of the boot
> + * image is as follows:
> + *
> + * +---------------------+
> + * | boot header         | 4096 bytes
> + * +---------------------+
> + * | kernel              | m pages
> + * +---------------------+
> + * | ramdisk             | n pages
> + * +---------------------+
> + * | boot signature      | g pages
> + * +---------------------+
> + *
> + * m = (kernel_size + 4096 - 1) / 4096
> + * n = (ramdisk_size + 4096 - 1) / 4096
> + * g = (signature_size + 4096 - 1) / 4096
> + *
> + * Note that in version 4 of the boot image header, page size is fixed at 4096
> + * bytes.
> + *
> + * The structure of the vendor boot image version 4, which is required to be
> + * present when a version 4 boot image is used, is as follows:
> + *
> + * +------------------------+
> + * | vendor boot header     | o pages
> + * +------------------------+
> + * | vendor ramdisk section | p pages
> + * +------------------------+
> + * | dtb                    | q pages
> + * +------------------------+
> + * | vendor ramdisk table   | r pages
> + * +------------------------+
> + * | bootconfig             | s pages
> + * +------------------------+
> + *
> + * o = (2128 + page_size - 1) / page_size
> + * p = (vendor_ramdisk_size + page_size - 1) / page_size
> + * q = (dtb_size + page_size - 1) / page_size
> + * r = (vendor_ramdisk_table_size + page_size - 1) / page_size
> + * s = (vendor_bootconfig_size + page_size - 1) / page_size
> + *
> + * Note that in version 4 of the vendor boot image, multiple vendor ramdisks can
> + * be included in the vendor boot image. The bootloader can select a subset of
> + * ramdisks to load at runtime. To help the bootloader select the ramdisks, each
> + * ramdisk is tagged with a type tag and a set of hardware identifiers
> + * describing the board, soc or platform that this ramdisk is intended for.
> + *
> + * The vendor ramdisk section is consist of multiple ramdisk images concatenated
> + * one after another, and vendor_ramdisk_size is the size of the section, which
> + * is the total size of all the ramdisks included in the vendor boot image.
> + *
> + * The vendor ramdisk table holds the size, offset, type, name and hardware
> + * identifiers of each ramdisk. The type field denotes the type of its content.
> + * The vendor ramdisk names are unique. The hardware identifiers are specified
> + * in the board_id field in each table entry. The board_id field is consist of a
> + * vector of unsigned integer words, and the encoding scheme is defined by the
> + * hardware vendor.
> + *
> + * For the different type of ramdisks, there are:
> + *    - VENDOR_RAMDISK_TYPE_NONE indicates the value is unspecified.
> + *    - VENDOR_RAMDISK_TYPE_PLATFORM ramdisks contain platform specific bits, so
> + *      the bootloader should always load these into memory.
> + *    - VENDOR_RAMDISK_TYPE_RECOVERY ramdisks contain recovery resources, so
> + *      the bootloader should load these when booting into recovery.
> + *    - VENDOR_RAMDISK_TYPE_DLKM ramdisks contain dynamic loadable kernel
> + *      modules.
> + *
> + * Version 4 of the vendor boot image also adds a bootconfig section to the end
> + * of the image. This section contains Boot Configuration parameters known at
> + * build time. The bootloader is responsible for placing this section directly
> + * after the generic ramdisk, followed by the bootconfig trailer, before
> + * entering the kernel.
> + *
> + * 0. all entities in the boot image are 4096-byte aligned in flash, all
> + *    entities in the vendor boot image are page_size (determined by the vendor
> + *    and specified in the vendor boot image header) aligned in flash
> + * 1. kernel, ramdisk, and DTB are required (size != 0)
> + * 2. load the kernel and DTB at the specified physical address (kernel_addr,
> + *    dtb_addr)
> + * 3. load the vendor ramdisks at ramdisk_addr
> + * 4. load the generic ramdisk immediately following the vendor ramdisk in
> + *    memory
> + * 5. load the bootconfig immediately following the generic ramdisk. Add
> + *    additional bootconfig parameters followed by the bootconfig trailer.
> + * 6. set up registers for kernel entry as required by your architecture
> + * 7. if the platform has a second stage bootloader jump to it (must be
> + *    contained outside boot and vendor boot partitions), otherwise
> + *    jump to kernel_addr
> + */
>  #endif
> --
> 2.25.1
> 

Please combine this with the previous commit.

--Sean

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 01/17] android: boot: rename andr_img_hdr -> andr_boot_img_hdr_v0_v1_v2
  2022-11-28 16:08   ` Sean Anderson
@ 2022-11-29 11:07     ` Safae Ouajih
  0 siblings, 0 replies; 28+ messages in thread
From: Safae Ouajih @ 2022-11-29 11:07 UTC (permalink / raw)
  To: Sean Anderson; +Cc: sjg, u-boot, r.stratiienko, mkorpershoek, glaroque, khilman

On Mon, 28 Nov 2022 11:08:20 -0500
Sean Anderson <sean.anderson@seco.com> wrote:

> On 11/26/22 11:59, Safae Ouajih wrote:
> > [You don't often get email from souajih@baylibre.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
> > 
> > Android introduced boot header version 3 or 4.
> > The header structure change with version 3 and 4 to support
> > the new updates such as:
> > - Introducing Vendor boot image: with a vendor ramdisk
> > - Bootconfig feature (v4)
> > 
> > To maintain support for version v0, v1 and v2 while introducing
> > version 3 and 4, this struct name must change to refer to the header
> > structure before v3.
> > 
> > Signed-off-by: Safae Ouajih <souajih@baylibre.com>
> > ---
> >  boot/image-android.c      | 26 +++++++++++++-------------
> >  boot/image-fdt.c          |  2 +-
> >  cmd/abootimg.c            |  4 ++--
> >  drivers/fastboot/fb_mmc.c |  8 ++++----
> >  include/android_image.h   |  4 ++--
> >  include/image.h           | 18 +++++++++---------
> >  6 files changed, 31 insertions(+), 31 deletions(-)
> > 
> > diff --git a/boot/image-android.c b/boot/image-android.c
> > index 2628db374121..926d94ecbe8e 100644
> > --- a/boot/image-android.c
> > +++ b/boot/image-android.c
> > @@ -18,7 +18,7 @@
> > 
> >  static char andr_tmp_str[ANDR_BOOT_ARGS_SIZE + 1];
> > 
> > -static ulong android_image_get_kernel_addr(const struct andr_img_hdr *hdr)
> > +static ulong android_image_get_kernel_addr(const struct andr_boot_img_hdr_v0_v1_v2 *hdr)
> 
> This line is too long. You will have to break it like
> 
> static ulong 
> android_image_get_kernel_addr(const struct andr_boot_img_hdr_v0_v1_v2 *hdr)
> 
> But really, this is because your struct name is too long. Can we use
> something like andr_img_hdr_v0 instead? I would like to have only one
> version in the struct name because then there is no urge to update the
> name when e.g. v5 comes out with mostly the same format. And _boot adds
> nothing.
> 
> --Sean
> 

Hello Sean,

Thank you for your review.

Since vendor boot image is introduced, we need to differentiate it from the boot image. Thus,
I suggest to use :
        andr_boot_img_hdr_v0 and andr_boot_img_hdr_v3 for the boot image
        andr_vendor_img_hdr for the vendor boot image

--Safae

> >  {
> >         /*
> >          * All the Android tools that generate a boot.img use this
> > @@ -59,7 +59,7 @@ static ulong android_image_get_kernel_addr(const struct andr_img_hdr *hdr)
> >   * Return: Zero, os start address and length on success,
> >   *             otherwise on failure.
> >   */
> > -int android_image_get_kernel(const struct andr_img_hdr *hdr, int verify,
> > +int android_image_get_kernel(const struct andr_boot_img_hdr_v0_v1_v2 *hdr, int verify,
> >                              ulong *os_data, ulong *os_len)
> >  {
> >         u32 kernel_addr = android_image_get_kernel_addr(hdr);
> > @@ -122,12 +122,12 @@ int android_image_get_kernel(const struct andr_img_hdr *hdr, int verify,
> >         return 0;
> >  }
> > 
> > -int android_image_check_header(const struct andr_img_hdr *hdr)
> > +int android_image_check_header(const struct andr_boot_img_hdr_v0_v1_v2 *hdr)
> >  {
> >         return memcmp(ANDR_BOOT_MAGIC, hdr->magic, ANDR_BOOT_MAGIC_SIZE);
> >  }
> > 
> > -ulong android_image_get_end(const struct andr_img_hdr *hdr)
> > +ulong android_image_get_end(const struct andr_boot_img_hdr_v0_v1_v2 *hdr)
> >  {
> >         ulong end;
> > 
> > @@ -150,12 +150,12 @@ ulong android_image_get_end(const struct andr_img_hdr *hdr)
> >         return end;
> >  }
> > 
> > -ulong android_image_get_kload(const struct andr_img_hdr *hdr)
> > +ulong android_image_get_kload(const struct andr_boot_img_hdr_v0_v1_v2 *hdr)
> >  {
> >         return android_image_get_kernel_addr(hdr);
> >  }
> > 
> > -ulong android_image_get_kcomp(const struct andr_img_hdr *hdr)
> > +ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0_v1_v2 *hdr)
> >  {
> >         const void *p = (void *)((uintptr_t)hdr + hdr->page_size);
> > 
> > @@ -167,7 +167,7 @@ ulong android_image_get_kcomp(const struct andr_img_hdr *hdr)
> >                 return image_decomp_type(p, sizeof(u32));
> >  }
> > 
> > -int android_image_get_ramdisk(const struct andr_img_hdr *hdr,
> > +int android_image_get_ramdisk(const struct andr_boot_img_hdr_v0_v1_v2 *hdr,
> >                               ulong *rd_data, ulong *rd_len)
> >  {
> >         if (!hdr->ramdisk_size) {
> > @@ -186,7 +186,7 @@ int android_image_get_ramdisk(const struct andr_img_hdr *hdr,
> >         return 0;
> >  }
> > 
> > -int android_image_get_second(const struct andr_img_hdr *hdr,
> > +int android_image_get_second(const struct andr_boot_img_hdr_v0_v1_v2 *hdr,
> >                               ulong *second_data, ulong *second_len)
> >  {
> >         if (!hdr->second_size) {
> > @@ -226,7 +226,7 @@ int android_image_get_second(const struct andr_img_hdr *hdr,
> >   */
> >  bool android_image_get_dtbo(ulong hdr_addr, ulong *addr, u32 *size)
> >  {
> > -       const struct andr_img_hdr *hdr;
> > +       const struct andr_boot_img_hdr_v0_v1_v2 *hdr;
> >         ulong dtbo_img_addr;
> >         bool ret = true;
> > 
> > @@ -275,7 +275,7 @@ exit:
> >   */
> >  static bool android_image_get_dtb_img_addr(ulong hdr_addr, ulong *addr)
> >  {
> > -       const struct andr_img_hdr *hdr;
> > +       const struct andr_boot_img_hdr_v0_v1_v2 *hdr;
> >         ulong dtb_img_addr;
> >         bool ret = true;
> > 
> > @@ -328,7 +328,7 @@ exit:
> >  bool android_image_get_dtb_by_index(ulong hdr_addr, u32 index, ulong *addr,
> >                                     u32 *size)
> >  {
> > -       const struct andr_img_hdr *hdr;
> > +       const struct andr_boot_img_hdr_v0_v1_v2 *hdr;
> >         bool res;
> >         ulong dtb_img_addr;     /* address of DTB part in boot image */
> >         u32 dtb_img_size;       /* size of DTB payload in boot image */
> > @@ -393,7 +393,7 @@ bool android_image_get_dtb_by_index(ulong hdr_addr, u32 index, ulong *addr,
> >   * returns:
> >   *     no returned results
> >   */
> > -void android_print_contents(const struct andr_img_hdr *hdr)
> > +void android_print_contents(const struct andr_boot_img_hdr_v0_v1_v2 *hdr)
> >  {
> >         const char * const p = IMAGE_INDENT_STRING;
> >         /* os_version = ver << 11 | lvl */
> > @@ -485,7 +485,7 @@ static bool android_image_print_dtb_info(const struct fdt_header *fdt,
> >   */
> >  bool android_image_print_dtb_contents(ulong hdr_addr)
> >  {
> > -       const struct andr_img_hdr *hdr;
> > +       const struct andr_boot_img_hdr_v0_v1_v2 *hdr;
> >         bool res;
> >         ulong dtb_img_addr;     /* address of DTB part in boot image */
> >         u32 dtb_img_size;       /* size of DTB payload in boot image */
> > diff --git a/boot/image-fdt.c b/boot/image-fdt.c
> > index b830a0ab4187..b7cc9bfd538f 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_img_hdr *hdr = buf;
> > +               struct andr_boot_img_hdr_v0_v1_v2 *hdr = buf;
> >                 ulong           fdt_data, fdt_len;
> >                 u32                     fdt_size, dtb_idx;
> >                 /*
> > diff --git a/cmd/abootimg.c b/cmd/abootimg.c
> > index f48a9dcb021d..de2aa3307d9a 100644
> > --- a/cmd/abootimg.c
> > +++ b/cmd/abootimg.c
> > @@ -18,7 +18,7 @@ static ulong _abootimg_addr = -1;
> > 
> >  static int abootimg_get_ver(int argc, char *const argv[])
> >  {
> > -       const struct andr_img_hdr *hdr;
> > +       const struct andr_boot_img_hdr_v0_v1_v2 *hdr;
> >         int res = CMD_RET_SUCCESS;
> > 
> >         if (argc > 1)
> > @@ -65,7 +65,7 @@ static int abootimg_get_recovery_dtbo(int argc, char *const argv[])
> > 
> >  static int abootimg_get_dtb_load_addr(int argc, char *const argv[])
> >  {
> > -       const struct andr_img_hdr *hdr;
> > +       const struct andr_boot_img_hdr_v0_v1_v2 *hdr;
> >         int res = CMD_RET_SUCCESS;
> > 
> >         if (argc > 1)
> > diff --git a/drivers/fastboot/fb_mmc.c b/drivers/fastboot/fb_mmc.c
> > index 033c510bc096..7b2f964b4c72 100644
> > --- a/drivers/fastboot/fb_mmc.c
> > +++ b/drivers/fastboot/fb_mmc.c
> > @@ -287,7 +287,7 @@ static void fb_mmc_boot_ops(struct blk_desc *dev_desc, void *buffer,
> >   */
> >  static lbaint_t fb_mmc_get_boot_header(struct blk_desc *dev_desc,
> >                                        struct disk_partition *info,
> > -                                      struct andr_img_hdr *hdr,
> > +                                      struct andr_boot_img_hdr_v0_v1_v2 *hdr,
> >                                        char *response)
> >  {
> >         ulong sector_size;              /* boot partition sector size */
> > @@ -296,7 +296,7 @@ static lbaint_t fb_mmc_get_boot_header(struct blk_desc *dev_desc,
> > 
> >         /* Calculate boot image sectors count */
> >         sector_size = info->blksz;
> > -       hdr_sectors = DIV_ROUND_UP(sizeof(struct andr_img_hdr), sector_size);
> > +       hdr_sectors = DIV_ROUND_UP(sizeof(struct andr_boot_img_hdr_v0_v1_v2), sector_size);
> >         if (hdr_sectors == 0) {
> >                 pr_err("invalid number of boot sectors: 0\n");
> >                 fastboot_fail("invalid number of boot sectors: 0", response);
> > @@ -338,7 +338,7 @@ static int fb_mmc_update_zimage(struct blk_desc *dev_desc,
> >                                 char *response)
> >  {
> >         uintptr_t hdr_addr;                     /* boot image header address */
> > -       struct andr_img_hdr *hdr;               /* boot image header */
> > +       struct andr_boot_img_hdr_v0_v1_v2 *hdr;         /* boot image header */
> >         lbaint_t hdr_sectors;                   /* boot image header sectors */
> >         u8 *ramdisk_buffer;
> >         u32 ramdisk_sector_start;
> > @@ -361,7 +361,7 @@ static int fb_mmc_update_zimage(struct blk_desc *dev_desc,
> > 
> >         /* Put boot image header in fastboot buffer after downloaded zImage */
> >         hdr_addr = (uintptr_t)download_buffer + ALIGN(download_bytes, PAGE_SIZE);
> > -       hdr = (struct andr_img_hdr *)hdr_addr;
> > +       hdr = (struct andr_boot_img_hdr_v0_v1_v2 *)hdr_addr;
> > 
> >         /* Read boot image header */
> >         hdr_sectors = fb_mmc_get_boot_header(dev_desc, &info, hdr, response);
> > diff --git a/include/android_image.h b/include/android_image.h
> > index 54d25af0684a..bf9b8c6f0955 100644
> > --- a/include/android_image.h
> > +++ b/include/android_image.h
> > @@ -20,9 +20,9 @@
> >  #define ANDR_BOOT_ARGS_SIZE 512
> >  #define ANDR_BOOT_EXTRA_ARGS_SIZE 1024
> > 
> > -/* The bootloader expects the structure of andr_img_hdr with header
> > +/* The bootloader expects the structure of andr_boot_img_hdr_v0_v1_v2 with header
> >   * version 0 to be as follows: */
> > -struct andr_img_hdr {
> > +struct andr_boot_img_hdr_v0_v1_v2 {
> >      /* Must be ANDR_BOOT_MAGIC. */
> >      char magic[ANDR_BOOT_MAGIC_SIZE];
> > 
> > diff --git a/include/image.h b/include/image.h
> > index 6f21dafba8ce..931cf18c7e82 100644
> > --- a/include/image.h
> > +++ b/include/image.h
> > @@ -1723,21 +1723,21 @@ int fit_image_cipher_get_algo(const void *fit, int noffset, char **algo);
> > 
> >  struct cipher_algo *image_get_cipher_algo(const char *full_name);
> > 
> > -struct andr_img_hdr;
> > -int android_image_check_header(const struct andr_img_hdr *hdr);
> > -int android_image_get_kernel(const struct andr_img_hdr *hdr, int verify,
> > +struct andr_boot_img_hdr_v0_v1_v2;
> > +int android_image_check_header(const struct andr_boot_img_hdr_v0_v1_v2 *hdr);
> > +int android_image_get_kernel(const struct andr_boot_img_hdr_v0_v1_v2 *hdr, int verify,
> >                              ulong *os_data, ulong *os_len);
> > -int android_image_get_ramdisk(const struct andr_img_hdr *hdr,
> > +int android_image_get_ramdisk(const struct andr_boot_img_hdr_v0_v1_v2 *hdr,
> >                               ulong *rd_data, ulong *rd_len);
> > -int android_image_get_second(const struct andr_img_hdr *hdr,
> > +int android_image_get_second(const struct andr_boot_img_hdr_v0_v1_v2 *hdr,
> >                               ulong *second_data, ulong *second_len);
> >  bool android_image_get_dtbo(ulong hdr_addr, ulong *addr, u32 *size);
> >  bool android_image_get_dtb_by_index(ulong hdr_addr, u32 index, ulong *addr,
> >                                     u32 *size);
> > -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);
> > +ulong android_image_get_end(const struct andr_boot_img_hdr_v0_v1_v2 *hdr);
> > +ulong android_image_get_kload(const struct andr_boot_img_hdr_v0_v1_v2 *hdr);
> > +ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0_v1_v2 *hdr);
> > +void android_print_contents(const struct andr_boot_img_hdr_v0_v1_v2 *hdr);
> >  bool android_image_print_dtb_contents(ulong hdr_addr);
> > 
> >  /**
> > --
> > 2.25.1
> > 


-- 
Safae Ouajih <souajih@baylibre.com>

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 00/17] Support android boot image v3/v4
  2022-11-26 16:59 [PATCH 00/17] Support android boot image v3/v4 Safae Ouajih
                   ` (17 preceding siblings ...)
  2022-11-28  9:43 ` [PATCH 00/17] Support android boot image v3/v4 Mattijs Korpershoek
@ 2022-12-04 21:16 ` Simon Glass
  2022-12-30  1:48 ` Tom Rini
  19 siblings, 0 replies; 28+ messages in thread
From: Simon Glass @ 2022-12-04 21:16 UTC (permalink / raw)
  To: Safae Ouajih
  Cc: u-boot, sean.anderson, r.stratiienko, mkorpershoek, glaroque, khilman

Hi Safae,

On Sun, 27 Nov 2022 at 05:59, Safae Ouajih <souajih@baylibre.com> wrote:
>
> Hello everyone,
>
> * This is based on Roman Stratiienko's work to support boot image header version 3 and 4.
>
> * This supports the new boot image headers v3, v4 and bootconfig feature.
> https://source.android.com/docs/core/architecture/bootloader/boot-image-header
> https://source.android.com/docs/core/architecture/bootloader/implementing-bootconfig
>
> - Tested on Amlogic Khadas vim3l, a reference board for Android Open Source Project
>   https://www.khadas.com/vim3l
>
>   And on AM625 Texas Instruments board with 5.10 linux kernel
>
> Main changes :
> - New partition : vendor boot, with a specific vendor ramdisk
> - DTB is stored in the vendor boot partition
> - The generic ramdisk is placed after the vendor ramdisk
> - Bootconfig feature support
>
>
> Here is a link to see the related android boot flow changes on KHADAS vim3l as an example:
> https://gitlab.baylibre.com/baylibre/amlogic/atv/u-boot/-/commits/souajih/BootImagev4/
>
> Safae Ouajih (17):
>   android: boot: rename andr_img_hdr -> andr_boot_img_hdr_v0_v1_v2
>   android: boot: support vendor boot image in abootimg
>   android: boot: replace android_image_check_header
>   android: boot: add boot image header v3 and v4 structures
>   android: boot: add documentation for boot image header v3/v4 structure
>   android: boot: kcomp: support andr_image_data
>   android: boot: move to andr_image_data structure
>   android: boot: content print is not supported for v3,v4 header version
>   android: boot: boot image header v3,v4 do not support recovery DTBO
>   android: boot: add vendor boot image to prepare for v3,v4 support
>   android: boot: update android_image_get_data to support v3,v4
>   android: boot: ramdisk: support vendor ramdisk
>   android: boot: support extra command line
>   drivers: fastboot: zImage flashing is not supported for v3,v4
>   android: boot: support boot image header version 3 and 4
>   lib: support libxbc
>   android: boot: support bootconfig
>
>  boot/bootm.c              |  29 ++-
>  boot/image-android.c      | 367 ++++++++++++++++++++++++++++++--------
>  boot/image-board.c        |  15 +-
>  boot/image-fdt.c          |   5 +-
>  cmd/abootimg.c            |  66 ++++---
>  drivers/fastboot/fb_mmc.c |  19 +-
>  include/android_image.h   | 220 ++++++++++++++++++++++-
>  include/image.h           |  37 ++--
>  include/xbc.h             |   1 +
>  lib/Kconfig               |  12 ++
>  lib/Makefile              |   1 +
>  lib/libxbc/Makefile       |   1 +
>  lib/libxbc/libxbc.c       | 112 ++++++++++++
>  lib/libxbc/libxbc.h       |  54 ++++++
>  14 files changed, 806 insertions(+), 133 deletions(-)
>  create mode 100644 include/xbc.h
>  create mode 100644 lib/libxbc/Makefile
>  create mode 100644 lib/libxbc/libxbc.c
>  create mode 100644 lib/libxbc/libxbc.h
>
> --
> 2.25.1
>

Please update the tests to cover this new functionality (test_avb.py)

Regards,
Simon

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 00/17] Support android boot image v3/v4
  2022-11-26 16:59 [PATCH 00/17] Support android boot image v3/v4 Safae Ouajih
                   ` (18 preceding siblings ...)
  2022-12-04 21:16 ` Simon Glass
@ 2022-12-30  1:48 ` Tom Rini
  2023-01-04  9:02   ` safae ouajih
  19 siblings, 1 reply; 28+ messages in thread
From: Tom Rini @ 2022-12-30  1:48 UTC (permalink / raw)
  To: u-boot, Safae Ouajih, sjg
  Cc: glaroque, mkorpershoek, khilman, r.stratiienko, sean.anderson

On Sat, 26 Nov 2022 17:59:14 +0100, Safae Ouajih wrote:

> * This is based on Roman Stratiienko's work to support boot image header version 3 and 4.
> 
> * This supports the new boot image headers v3, v4 and bootconfig feature.
> https://source.android.com/docs/core/architecture/bootloader/boot-image-header
> https://source.android.com/docs/core/architecture/bootloader/implementing-bootconfig
> 
> - Tested on Amlogic Khadas vim3l, a reference board for Android Open Source Project
>   https://www.khadas.com/vim3l
> 
> [...]

This series causes the test/py/tests/test_android/test_abootimg.py tests to
fail:
FAILED test/py/tests/test_android/test_abootimg.py::test_abootimg - ValueError: U-Boot exite...
and likely that test needs to be expanded for these new formats too.

-- 
Tom


^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 00/17] Support android boot image v3/v4
  2022-12-30  1:48 ` Tom Rini
@ 2023-01-04  9:02   ` safae ouajih
  2023-01-04 20:01     ` Simon Glass
  0 siblings, 1 reply; 28+ messages in thread
From: safae ouajih @ 2023-01-04  9:02 UTC (permalink / raw)
  To: Tom Rini, u-boot, sjg
  Cc: glaroque, mkorpershoek, khilman, r.stratiienko, sean.anderson

On 30/12/2022 02:48, Tom Rini wrote:
> On Sat, 26 Nov 2022 17:59:14 +0100, Safae Ouajih wrote:
> 
>> * This is based on Roman Stratiienko's work to support boot image header version 3 and 4.
>>
>> * This supports the new boot image headers v3, v4 and bootconfig feature.
>> https://source.android.com/docs/core/architecture/bootloader/boot-image-header
>> https://source.android.com/docs/core/architecture/bootloader/implementing-bootconfig
>>
>> - Tested on Amlogic Khadas vim3l, a reference board for Android Open Source Project
>>    https://www.khadas.com/vim3l
>>
>> [...]
> 
> This series causes the test/py/tests/test_android/test_abootimg.py tests to
> fail:
> FAILED test/py/tests/test_android/test_abootimg.py::test_abootimg - ValueError: U-Boot exite...
> and likely that test needs to be expanded for these new formats too.
> 

Hello Tom,

Thank you for reporting the failure. This will be fixed in a v2.

Best Regards,

--
Safae



^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 00/17] Support android boot image v3/v4
  2023-01-04  9:02   ` safae ouajih
@ 2023-01-04 20:01     ` Simon Glass
  2023-01-06 11:04       ` safae ouajih
  0 siblings, 1 reply; 28+ messages in thread
From: Simon Glass @ 2023-01-04 20:01 UTC (permalink / raw)
  To: safae ouajih
  Cc: Tom Rini, u-boot, glaroque, mkorpershoek, khilman, r.stratiienko,
	sean.anderson

Hi Safae,

On Wed, 4 Jan 2023 at 02:02, safae ouajih <souajih@baylibre.com> wrote:
>
> On 30/12/2022 02:48, Tom Rini wrote:
> > On Sat, 26 Nov 2022 17:59:14 +0100, Safae Ouajih wrote:
> >
> >> * This is based on Roman Stratiienko's work to support boot image header version 3 and 4.
> >>
> >> * This supports the new boot image headers v3, v4 and bootconfig feature.
> >> https://source.android.com/docs/core/architecture/bootloader/boot-image-header
> >> https://source.android.com/docs/core/architecture/bootloader/implementing-bootconfig
> >>
> >> - Tested on Amlogic Khadas vim3l, a reference board for Android Open Source Project
> >>    https://www.khadas.com/vim3l
> >>
> >> [...]
> >
> > This series causes the test/py/tests/test_android/test_abootimg.py tests to
> > fail:
> > FAILED test/py/tests/test_android/test_abootimg.py::test_abootimg - ValueError: U-Boot exite...
> > and likely that test needs to be expanded for these new formats too.
> >
>
> Hello Tom,
>
> Thank you for reporting the failure. This will be fixed in a v2.

Please also update the test as requested.

Regards,
Simon

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 00/17] Support android boot image v3/v4
  2023-01-04 20:01     ` Simon Glass
@ 2023-01-06 11:04       ` safae ouajih
  0 siblings, 0 replies; 28+ messages in thread
From: safae ouajih @ 2023-01-06 11:04 UTC (permalink / raw)
  To: Simon Glass
  Cc: Tom Rini, u-boot, glaroque, mkorpershoek, khilman, r.stratiienko,
	sean.anderson



On 04/01/2023 21:01, Simon Glass wrote:
> Hi Safae,
> 
> On Wed, 4 Jan 2023 at 02:02, safae ouajih <souajih@baylibre.com> wrote:
>>
>> On 30/12/2022 02:48, Tom Rini wrote:
>>> On Sat, 26 Nov 2022 17:59:14 +0100, Safae Ouajih wrote:
>>>
>>>> * This is based on Roman Stratiienko's work to support boot image header version 3 and 4.
>>>>
>>>> * This supports the new boot image headers v3, v4 and bootconfig feature.
>>>> https://source.android.com/docs/core/architecture/bootloader/boot-image-header
>>>> https://source.android.com/docs/core/architecture/bootloader/implementing-bootconfig
>>>>
>>>> - Tested on Amlogic Khadas vim3l, a reference board for Android Open Source Project
>>>>     https://www.khadas.com/vim3l
>>>>
>>>> [...]
>>>
>>> This series causes the test/py/tests/test_android/test_abootimg.py tests to
>>> fail:
>>> FAILED test/py/tests/test_android/test_abootimg.py::test_abootimg - ValueError: U-Boot exite...
>>> and likely that test needs to be expanded for these new formats too.
>>>
>>
>> Hello Tom,
>>
>> Thank you for reporting the failure. This will be fixed in a v2.
> 
> Please also update the test as requested.
> 
> Regards,
> Simon

Hello Simon,

I am working on the test update. This will be in a v2.

Thank you.

Best Regards,

--
Safae


^ permalink raw reply	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2023-01-06 11:04 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-26 16:59 [PATCH 00/17] Support android boot image v3/v4 Safae Ouajih
2022-11-26 16:59 ` [PATCH 01/17] android: boot: rename andr_img_hdr -> andr_boot_img_hdr_v0_v1_v2 Safae Ouajih
2022-11-28 16:08   ` Sean Anderson
2022-11-29 11:07     ` Safae Ouajih
2022-11-26 16:59 ` [PATCH 02/17] android: boot: support vendor boot image in abootimg Safae Ouajih
2022-11-26 16:59 ` [PATCH 03/17] android: boot: replace android_image_check_header Safae Ouajih
2022-11-26 16:59 ` [PATCH 04/17] android: boot: add boot image header v3 and v4 structures Safae Ouajih
2022-11-26 16:59 ` [PATCH 05/17] android: boot: add documentation for boot image header v3/v4 structure Safae Ouajih
2022-11-28 16:12   ` Sean Anderson
2022-11-26 16:59 ` [PATCH 06/17] android: boot: kcomp: support andr_image_data Safae Ouajih
2022-11-26 16:59 ` [PATCH 07/17] android: boot: move to andr_image_data structure Safae Ouajih
2022-11-26 16:59 ` [PATCH 08/17] android: boot: content print is not supported for v3, v4 header version Safae Ouajih
2022-11-26 16:59 ` [PATCH 09/17] android: boot: boot image header v3, v4 do not support recovery DTBO Safae Ouajih
2022-11-26 16:59 ` [PATCH 10/17] android: boot: add vendor boot image to prepare for v3, v4 support Safae Ouajih
2022-11-26 16:59 ` [PATCH 11/17] android: boot: update android_image_get_data to support v3, v4 Safae Ouajih
2022-11-26 16:59 ` [PATCH 12/17] android: boot: ramdisk: support vendor ramdisk Safae Ouajih
2022-11-26 16:59 ` [PATCH 13/17] android: boot: support extra command line Safae Ouajih
2022-11-26 16:59 ` [PATCH 14/17] drivers: fastboot: zImage flashing is not supported for v3, v4 Safae Ouajih
2022-11-26 16:59 ` [PATCH 15/17] android: boot: support boot image header version 3 and 4 Safae Ouajih
2022-11-26 16:59 ` [PATCH 16/17] lib: support libxbc Safae Ouajih
2022-11-28 16:02   ` Sean Anderson
2022-11-26 16:59 ` [PATCH 17/17] android: boot: support bootconfig Safae Ouajih
2022-11-28  9:43 ` [PATCH 00/17] Support android boot image v3/v4 Mattijs Korpershoek
2022-12-04 21:16 ` Simon Glass
2022-12-30  1:48 ` Tom Rini
2023-01-04  9:02   ` safae ouajih
2023-01-04 20:01     ` Simon Glass
2023-01-06 11:04       ` safae ouajih

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.