Skip to contentSkip to conversation

abootimg: Add init_boot image support

PATCH Superseded Roman Stratiienko 2 participants 4 messages May 19, 2024 – May 23, 2024

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 abootimg: Add init_boot image support

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."

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

---
 boot/image-board.c |  5 ++++-
 cmd/abootimg.c     | 26 +++++++++++++++++++++-----
 include/image.h    |  7 +++++++
 3 files changed, 32 insertions(+), 6 deletions(-)
boot/image-board.c +4 -1
index 75f6906cd5..715654ff01 100644
@@ -414,9 +414,12 @@ static int select_ramdisk(struct bootm_headers *images, const char *select, u8 a
 			int ret;
 			if (IS_ENABLED(CONFIG_CMD_ABOOTIMG)) {
 				void *boot_img = map_sysmem(get_abootimg_addr(), 0);
+				void *init_boot_img = map_sysmem(get_ainit_bootimg_addr(), 0);
 				void *vendor_boot_img = map_sysmem(get_avendor_bootimg_addr(), 0);
+				void *ramdisk_img = (init_boot_img == -1) ? boot_img :
+									    init_boot_img;
 
-				ret = android_image_get_ramdisk(boot_img, vendor_boot_img,
+				ret = android_image_get_ramdisk(ramdisk_img, vendor_boot_img,
 								rd_datap, rd_lenp);
 				unmap_sysmem(vendor_boot_img);
 				unmap_sysmem(boot_img);
cmd/abootimg.c +21 -5
index e68c523705..7c450a3b2d 100644
@@ -17,6 +17,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)
@@ -24,6 +25,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;
@@ -209,7 +215,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);
@@ -220,16 +226,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;
 }
 
@@ -346,7 +362,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, "", ""),
@@ -375,7 +391,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"
include/image.h +7 -0
index be3c73a72e..b1fd6b3149 100644
@@ -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
  *
Signature · 1 line
2.40.1
#1 lore raw

Hi Roman,

Thank you for the patch.

Quoted 6 lines · Roman Stratiienko

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."

Quoted 7 lines

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

---
 boot/image-board.c |  5 ++++-
 cmd/abootimg.c     | 26 +++++++++++++++++++++-----
 include/image.h    |  7 +++++++
 3 files changed, 32 insertions(+), 6 deletions(-)

This patch does not apply on:
- next: 7d24c3e06fa9 ("Merge patch series "scripts/setlocalversion sync with linux 6.9"")
- master: a7f0154c4128 ("Prepare v2024.07-rc3")

Please consider rebasing when resending.

More review below

boot/image-board.c static int select_ramdisk(struct bootm_headers *images, const char *select, u8 a · line 420

Quoted 13 lines
boot/image-board.c +3 -0
index 75f6906cd5..715654ff01 100644
@@ -414,9 +414,12 @@ static int select_ramdisk(struct bootm_headers *images, const char *select, u8 a
 			int ret;
 			if (IS_ENABLED(CONFIG_CMD_ABOOTIMG)) {
 				void *boot_img = map_sysmem(get_abootimg_addr(), 0);
+				void *init_boot_img = map_sysmem(get_ainit_bootimg_addr(), 0);
 				void *vendor_boot_img = map_sysmem(get_avendor_bootimg_addr(), 0);
+				void *ramdisk_img = (init_boot_img == -1) ? boot_img :
+									    init_boot_img;

This line introduces a build warning:

../boot/image-board.c: In function ‘select_ramdisk’:
../boot/image-board.c:412:68: warning: comparison between pointer and integer
412 | void *ramdisk_img = (init_boot_img == -1) ? boot_img :
| ^~

Can we please fix it in v2 ?

boot/image-board.c static int select_ramdisk(struct bootm_headers *images, const char *select, u8 a · line 424

Quoted 5 lines
boot/image-board.c +1 -1
-				ret = android_image_get_ramdisk(boot_img, vendor_boot_img,
+				ret = android_image_get_ramdisk(ramdisk_img, vendor_boot_img,
 								rd_datap, rd_lenp);
 				unmap_sysmem(vendor_boot_img);

Can we please add unmap_sysmem(init_boot_img); here as well ?

Quoted 35 lines
boot/image-board.c +0 -0
 				unmap_sysmem(boot_img);
cmd/abootimg.c +7 -1
index e68c523705..7c450a3b2d 100644
@@ -17,6 +17,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)
@@ -24,6 +25,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;
@@ -209,7 +215,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);

cmd/abootimg.c static int do_abootimg_addr(struct cmd_tbl *cmdtp, int flag, int argc, · line 232

Quoted 9 lines
cmd/abootimg.c +2 -2
@@ -220,16 +226,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");

Nitpick: this seems like a harmless change but could be done in a separate patch.

To me, it's fine to include this hunk, but can we mention it in the commit message?

Something along the lines as "While at it, update wrong error handling message when vendor_boot cannot be loaded".

Quoted 29 lines
cmd/abootimg.c +11 -1
 			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;
 }
 
@@ -346,7 +362,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, "", ""),

cmd/abootimg.c static int do_abootimg(struct cmd_tbl *cmdtp, int flag, int argc, · line 396

Quoted 7 lines
cmd/abootimg.c +1 -1
@@ -375,7 +391,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"

Please include the help text update in the documentation:
doc/android/boot-image.rst

Quoted 21 lines
cmd/abootimg.c +0 -0
 	"abootimg dump dtb\n"
include/image.h +7 -0
index be3c73a72e..b1fd6b3149 100644
@@ -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
  *
Signature · 1 line
2.40.1
#2 lore raw

Hi Mattijs,

Thank you for your review.

ср, 22 мая 2024 г. в 17:43, Mattijs Korpershoek <[email protected]>:

Quoted 21 lines

Hi Roman,

Thank you for the patch.

Quoted 6 lines · Roman Stratiienko

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."

Quoted 7 lines

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

---
 boot/image-board.c |  5 ++++-
 cmd/abootimg.c     | 26 +++++++++++++++++++++-----
 include/image.h    |  7 +++++++
 3 files changed, 32 insertions(+), 6 deletions(-)
Quoted 5 lines

This patch does not apply on:
- next: 7d24c3e06fa9 ("Merge patch series "scripts/setlocalversion sync with linux 6.9"")
- master: a7f0154c4128 ("Prepare v2024.07-rc3")

Please consider rebasing when resending.

V2 Rebased

Quoted 19 lines

More review below

boot/image-board.c static int select_ramdisk(struct bootm_headers *images, const char *select, u8 a · line 420

Quoted 13 lines
boot/image-board.c +3 -0
index 75f6906cd5..715654ff01 100644
@@ -414,9 +414,12 @@ static int select_ramdisk(struct bootm_headers *images, const char *select, u8 a
                      int ret;
                      if (IS_ENABLED(CONFIG_CMD_ABOOTIMG)) {
                              void *boot_img = map_sysmem(get_abootimg_addr(), 0);
+                             void *init_boot_img = map_sysmem(get_ainit_bootimg_addr(), 0);
                              void *vendor_boot_img = map_sysmem(get_avendor_bootimg_addr(), 0);
+                             void *ramdisk_img = (init_boot_img == -1) ? boot_img :
+                                                                         init_boot_img;

This line introduces a build warning:

Quoted 6 lines

../boot/image-board.c: In function ‘select_ramdisk’:
../boot/image-board.c:412:68: warning: comparison between pointer and integer
412 | void *ramdisk_img = (init_boot_img == -1) ? boot_img :
| ^~

Can we please fix it in v2 ?

Fixed

Quoted 8 lines

boot/image-board.c static int select_ramdisk(struct bootm_headers *images, const char *select, u8 a · line 424

Quoted 6 lines
boot/image-board.c +1 -1
-                             ret = android_image_get_ramdisk(boot_img, vendor_boot_img,
+                             ret = android_image_get_ramdisk(ramdisk_img, vendor_boot_img,
                                                              rd_datap, rd_lenp);
                              unmap_sysmem(vendor_boot_img);

Can we please add unmap_sysmem(init_boot_img); here as well ?

Done.

Quoted 49 lines
Quoted 36 lines
boot/image-board.c +0 -0
                              unmap_sysmem(boot_img);
cmd/abootimg.c +7 -1
index e68c523705..7c450a3b2d 100644
@@ -17,6 +17,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)
@@ -24,6 +25,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;
@@ -209,7 +215,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);

cmd/abootimg.c static int do_abootimg_addr(struct cmd_tbl *cmdtp, int flag, int argc, · line 232

Quoted 9 lines
cmd/abootimg.c +2 -2
@@ -220,16 +226,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");

Nitpick: this seems like a harmless change but could be done in a separate patch.

Quoted 5 lines

To me, it's fine to include this hunk, but can we mention it in the commit message?

Something along the lines as "While at it, update wrong error handling message when vendor_boot cannot be loaded".

Added.

Quoted 32 lines
Quoted 32 lines
cmd/abootimg.c +11 -1
                      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;
 }
 
@@ -346,7 +362,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, "", ""),
@@ -375,7 +391,7 @@ static int do_abootimg(struct cmd_tbl *cmdtp, int flag, int argc,
 U_BOOT_CMD(
      abootimg, CONFIG_SYS_MAXARGS, 0, do_abootimg,
Quoted 8 lines

cmd/abootimg.c static int do_abootimg(struct cmd_tbl *cmdtp, int flag, int argc, · line 396

Quoted 5 lines
cmd/abootimg.c +1 -1
      "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"

Please include the help text update in the documentation:
doc/android/boot-image.rst

That documentation does not mention 'abootimg addr' command at the moment. I do not see an easy way to add it in a way that makes sense.

Quoted 22 lines
Quoted 22 lines
cmd/abootimg.c +0 -0
      "abootimg dump dtb\n"
include/image.h +7 -1
index be3c73a72e..b1fd6b3149 100644
@@ -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
  *
--

2.40.1

#3 lore raw

Hi Roman,

On jeu., mai 23, 2024 at 00:35, Roman Stratiienko <[email protected]> wrote:

[...]

Quoted 19 lines
Quoted 10 lines
Quoted 10 lines

static struct cmd_tbl cmd_abootimg_sub[] = {

cmd/abootimg.c +1 -1
-     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, "", ""),
@@ -375,7 +391,7 @@ static int do_abootimg(struct cmd_tbl *cmdtp, int flag, int argc,
 U_BOOT_CMD(
      abootimg, CONFIG_SYS_MAXARGS, 0, do_abootimg,
Quoted 8 lines

cmd/abootimg.c static int do_abootimg(struct cmd_tbl *cmdtp, int flag, int argc, · line 396

Quoted 5 lines
cmd/abootimg.c +1 -1
      "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"

Please include the help text update in the documentation:
doc/android/boot-image.rst

Quoted 3 lines

That documentation does not mention 'abootimg addr' command at the moment. I do not see an easy way to add it in a way that makes sense.

I see. I will send a documentation update later then.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
cmd/abootimg.c +0 -0
      "abootimg dump dtb\n"
include/image.h +0 -0
index be3c73a72e..b1fd6b3149 100644

[...]