diff mbox series

[v2] abootimg: Add init_boot image support

Message ID 20240522212645.87250-1-r.stratiienko@gmail.com
State Superseded
Delegated to: Tom Rini
Headers show
Series [v2] abootimg: Add init_boot image support | expand

Commit Message

Roman Stratiienko May 22, 2024, 9:26 p.m. UTC
Quote from [1]:

"For devices launching with Android 13, the generic ramdisk is removed
from the boot image and placed in a separate init_boot image.
This change leaves the boot image with only the GKI kernel."

While at it, update wrong error handling message when vendor_boot
cannot be loaded.

[1]: https://source.android.com/docs/core/architecture/partitions/generic-boot
Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
---
 boot/image-board.c | 13 ++++++++++---
 cmd/abootimg.c     | 26 +++++++++++++++++++++-----
 include/image.h    |  7 +++++++
 3 files changed, 38 insertions(+), 8 deletions(-)

Comments

Mattijs Korpershoek May 23, 2024, 6:41 a.m. UTC | #1
Hi Roman,

Thank you for the patch.

On mer., mai 22, 2024 at 21:26, Roman Stratiienko <r.stratiienko@gmail.com> wrote:

> Quote from [1]:
>
> "For devices launching with Android 13, the generic ramdisk is removed
> from the boot image and placed in a separate init_boot image.
> This change leaves the boot image with only the GKI kernel."
>
> While at it, update wrong error handling message when vendor_boot
> cannot be loaded.
>
> [1]: https://source.android.com/docs/core/architecture/partitions/generic-boot
> Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>

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

Note: this patch still does not apply on master nor next:

$ ~/work/upstream/u-boot/ git show --pretty='%h ("%s")' HEAD --no-patch
a7f0154c4128 ("Prepare v2024.07-rc3")

$ ~/work/upstream/u-boot/ b4 shazam -s -l 20240522212645.87250-1-r.stratiienko@gmail.com

[...]

Total patches: 1
---
Applying: abootimg: Add init_boot image support
Patch failed at 0001 abootimg: Add init_boot image support
error: sha1 information is lacking or useless (cmd/abootimg.c).
error: could not build fake ancestor
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config advice.mergeConflict false"

- master: a7f0154c4128 ("Prepare v2024.07-rc3")
- next: 377e91c162ab ("Merge patch series "Clean-up patch set for MbedTLS integration"")

Looking further down below, we can see that this patch has the "abootimg
load" command, which is introduced in these series:
https://lore.kernel.org/r/20240519191856.2582174-1-r.stratiienko@gmail.com

Please consider rebasing on either master or next before sending.


> ---
>  boot/image-board.c | 13 ++++++++++---
>  cmd/abootimg.c     | 26 +++++++++++++++++++++-----
>  include/image.h    |  7 +++++++
>  3 files changed, 38 insertions(+), 8 deletions(-)

[...]

>
>  
>  static struct cmd_tbl cmd_abootimg_sub[] = {
> -	U_BOOT_CMD_MKENT(addr, 3, 1, do_abootimg_addr, "", ""),
> +	U_BOOT_CMD_MKENT(addr, 4, 1, do_abootimg_addr, "", ""),
>  	U_BOOT_CMD_MKENT(dump, 2, 1, do_abootimg_dump, "", ""),
>  	U_BOOT_CMD_MKENT(get, 5, 1, do_abootimg_get, "", ""),
>  	U_BOOT_CMD_MKENT(load, 5, 1, do_abootimg_load, "", ""),
> @@ -376,7 +392,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 <boot_img_addr> [<vendor_boot_img_addr>]>\n"
> +	"addr <boot_img_addr> [<vendor_boot_img_addr> [<init_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"

[...]
Roman Stratiienko May 23, 2024, 6:56 a.m. UTC | #2
чт, 23 мая 2024 г. в 09:41, Mattijs Korpershoek <mkorpershoek@baylibre.com>:
>
> Hi Roman,
>
> Thank you for the patch.
>
> On mer., mai 22, 2024 at 21:26, Roman Stratiienko <r.stratiienko@gmail.com> wrote:
>
> > Quote from [1]:
> >
> > "For devices launching with Android 13, the generic ramdisk is removed
> > from the boot image and placed in a separate init_boot image.
> > This change leaves the boot image with only the GKI kernel."
> >
> > While at it, update wrong error handling message when vendor_boot
> > cannot be loaded.
> >
> > [1]: https://source.android.com/docs/core/architecture/partitions/generic-boot
> > Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
>
> Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
>
> Note: this patch still does not apply on master nor next:
>
> $ ~/work/upstream/u-boot/ git show --pretty='%h ("%s")' HEAD --no-patch
> a7f0154c4128 ("Prepare v2024.07-rc3")
>
> $ ~/work/upstream/u-boot/ b4 shazam -s -l 20240522212645.87250-1-r.stratiienko@gmail.com
>
> [...]
>
> Total patches: 1
> ---
> Applying: abootimg: Add init_boot image support
> Patch failed at 0001 abootimg: Add init_boot image support
> error: sha1 information is lacking or useless (cmd/abootimg.c).
> error: could not build fake ancestor
> hint: Use 'git am --show-current-patch=diff' to see the failed patch
> hint: When you have resolved this problem, run "git am --continue".
> hint: If you prefer to skip this patch, run "git am --skip" instead.
> hint: To restore the original branch and stop patching, run "git am --abort".
> hint: Disable this message with "git config advice.mergeConflict false"
>
> - master: a7f0154c4128 ("Prepare v2024.07-rc3")
> - next: 377e91c162ab ("Merge patch series "Clean-up patch set for MbedTLS integration"")
>
> Looking further down below, we can see that this patch has the "abootimg
> load" command, which is introduced in these series:
> https://lore.kernel.org/r/20240519191856.2582174-1-r.stratiienko@gmail.com
>
> Please consider rebasing on either master or next before sending.

Ahh. I see. Sorry for the inconvenience. I will rebase and send v3.

>
>
> > ---
> >  boot/image-board.c | 13 ++++++++++---
> >  cmd/abootimg.c     | 26 +++++++++++++++++++++-----
> >  include/image.h    |  7 +++++++
> >  3 files changed, 38 insertions(+), 8 deletions(-)
>
> [...]
>
> >
> >
> >  static struct cmd_tbl cmd_abootimg_sub[] = {
> > -     U_BOOT_CMD_MKENT(addr, 3, 1, do_abootimg_addr, "", ""),
> > +     U_BOOT_CMD_MKENT(addr, 4, 1, do_abootimg_addr, "", ""),
> >       U_BOOT_CMD_MKENT(dump, 2, 1, do_abootimg_dump, "", ""),
> >       U_BOOT_CMD_MKENT(get, 5, 1, do_abootimg_get, "", ""),
> >       U_BOOT_CMD_MKENT(load, 5, 1, do_abootimg_load, "", ""),
> > @@ -376,7 +392,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 <boot_img_addr> [<vendor_boot_img_addr>]>\n"
> > +     "addr <boot_img_addr> [<vendor_boot_img_addr> [<init_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"
>
> [...]
diff mbox series

Patch

diff --git a/boot/image-board.c b/boot/image-board.c
index b7884b8c5d..f212401304 100644
--- a/boot/image-board.c
+++ b/boot/image-board.c
@@ -406,13 +406,20 @@  static int select_ramdisk(struct bootm_headers *images, const char *select, u8 a
 		if (IS_ENABLED(CONFIG_ANDROID_BOOT_IMAGE)) {
 			int ret;
 			if (IS_ENABLED(CONFIG_CMD_ABOOTIMG)) {
-				void *boot_img = map_sysmem(get_abootimg_addr(), 0);
+				ulong boot_img = get_abootimg_addr();
+				ulong init_boot_img = get_ainit_bootimg_addr();
 				void *vendor_boot_img = map_sysmem(get_avendor_bootimg_addr(), 0);
+				void *ramdisk_img;
 
-				ret = android_image_get_ramdisk(boot_img, vendor_boot_img,
+				if (init_boot_img == -1)
+					ramdisk_img = map_sysmem(boot_img, 0);
+				else
+					ramdisk_img = map_sysmem(init_boot_img, 0);
+
+				ret = android_image_get_ramdisk(ramdisk_img, vendor_boot_img,
 								rd_datap, rd_lenp);
 				unmap_sysmem(vendor_boot_img);
-				unmap_sysmem(boot_img);
+				unmap_sysmem(ramdisk_img);
 			} else {
 				void *ptr = map_sysmem(images->os.start, 0);
 
diff --git a/cmd/abootimg.c b/cmd/abootimg.c
index 69c7390dbe..9e965c1fb7 100644
--- a/cmd/abootimg.c
+++ b/cmd/abootimg.c
@@ -16,6 +16,7 @@ 
 
 /* Please use abootimg_addr() macro to obtain the boot image address */
 static ulong _abootimg_addr = -1;
+static ulong _ainit_bootimg_addr = -1;
 static ulong _avendor_bootimg_addr = -1;
 
 ulong get_abootimg_addr(void)
@@ -23,6 +24,11 @@  ulong get_abootimg_addr(void)
 	return (_abootimg_addr == -1 ? image_load_addr : _abootimg_addr);
 }
 
+ulong get_ainit_bootimg_addr(void)
+{
+	return _ainit_bootimg_addr;
+}
+
 ulong get_avendor_bootimg_addr(void)
 {
 	return _avendor_bootimg_addr;
@@ -210,7 +216,7 @@  static int do_abootimg_addr(struct cmd_tbl *cmdtp, int flag, int argc,
 	char *endp;
 	ulong img_addr;
 
-	if (argc < 2 || argc > 3)
+	if (argc < 2 || argc > 4)
 		return CMD_RET_USAGE;
 
 	img_addr = hextoul(argv[1], &endp);
@@ -221,16 +227,26 @@  static int do_abootimg_addr(struct cmd_tbl *cmdtp, int flag, int argc,
 
 	_abootimg_addr = img_addr;
 
-	if (argc == 3) {
+	if (argc > 2) {
 		img_addr = simple_strtoul(argv[2], &endp, 16);
 		if (*endp != '\0') {
-			printf("Error: Wrong vendor image address\n");
+			printf("Error: Wrong vendor_boot image address\n");
 			return CMD_RET_FAILURE;
 		}
 
 		_avendor_bootimg_addr = img_addr;
 	}
 
+	if (argc == 4) {
+		img_addr = simple_strtoul(argv[3], &endp, 16);
+		if (*endp != '\0') {
+			printf("Error: Wrong init_boot image address\n");
+			return CMD_RET_FAILURE;
+		}
+
+		_ainit_bootimg_addr = img_addr;
+	}
+
 	return CMD_RET_SUCCESS;
 }
 
@@ -347,7 +363,7 @@  fail:
 }
 
 static struct cmd_tbl cmd_abootimg_sub[] = {
-	U_BOOT_CMD_MKENT(addr, 3, 1, do_abootimg_addr, "", ""),
+	U_BOOT_CMD_MKENT(addr, 4, 1, do_abootimg_addr, "", ""),
 	U_BOOT_CMD_MKENT(dump, 2, 1, do_abootimg_dump, "", ""),
 	U_BOOT_CMD_MKENT(get, 5, 1, do_abootimg_get, "", ""),
 	U_BOOT_CMD_MKENT(load, 5, 1, do_abootimg_load, "", ""),
@@ -376,7 +392,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 <boot_img_addr> [<vendor_boot_img_addr>]>\n"
+	"addr <boot_img_addr> [<vendor_boot_img_addr> [<init_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"
diff --git a/include/image.h b/include/image.h
index 96df2b99a7..7d8ff40c3f 100644
--- a/include/image.h
+++ b/include/image.h
@@ -1982,6 +1982,13 @@  bool is_android_vendor_boot_image_header(const void *vendor_boot_img);
  */
 ulong get_abootimg_addr(void);
 
+/**
+ * get_ainit_bootimg_addr() - Get Android init boot image address
+ *
+ * Return: Android init boot image address
+ */
+ulong get_ainit_bootimg_addr(void);
+
 /**
  * get_avendor_bootimg_addr() - Get Android vendor boot image address
  *