[PATCH 0/2] android: add bootconfig support

This patchset add support of android bootconfig partition[1] in u-boot. With Android boot image v4, all androidboot.* arguments must be passed via bootconfig instead of using the kernel commandline.
[1] https://source.android.com/docs/core/architecture/bootloader/implementing-bo...
Signed-off-by: Guillaume La Roque glaroque@baylibre.com --- Guillaume La Roque (1): boot: android: Add bootconfig support
Mattijs Korpershoek (1): boot: android: import addBootConfigParameters() from AOSP
boot/image-android.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) --- base-commit: 62224280d9e89648ae90346c0aede76f9b7e7610 change-id: 20241128-bootconfig-276e247be992
Best regards,

From: Mattijs Korpershoek mkorpershoek@baylibre.com
To properly implement Android boot image v4, U-Boot must be able to add additional entries to the bootconfig.
Add `add_bootconfig_parameters()` to do so.
This has been imported from Google's U-Boot source[1] The variables/function names have been reworked to be compliant with U-Boot's coding style.
[1] https://android.googlesource.com/platform/external/u-boot/+/7af0a0506d4de6f5... Signed-off-by: Mattijs Korpershoek mkorpershoek@baylibre.com Signed-off-by: Guillaume La Roque glaroque@baylibre.com --- boot/image-android.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
diff --git a/boot/image-android.c b/boot/image-android.c index 93b54bf8d793..05245a0ba918 100644 --- a/boot/image-android.c +++ b/boot/image-android.c @@ -57,6 +57,36 @@ static ulong add_trailer(ulong bootconfig_start_addr, ulong bootconfig_size) return BOOTCONFIG_TRAILER_SIZE; }
+/* + * Add a string of boot config parameters to memory appended by the trailer. + */ +u32 add_bootconfig_parameters(char *params, ulong params_size, + ulong bootconfig_start_addr, u32 bootconfig_size) +{ + if (!params || !bootconfig_start_addr) + return -1; + + if (params_size == 0) + return 0; + + u32 applied_bytes = 0; + u32 new_size = 0; + ulong end = bootconfig_start_addr + bootconfig_size; + + if (is_trailer_present(end)) { + end -= BOOTCONFIG_TRAILER_SIZE; + applied_bytes -= BOOTCONFIG_TRAILER_SIZE; + memcpy(&new_size, (void *)end, BOOTCONFIG_SIZE_SIZE); + } else { + new_size = bootconfig_size; + } + memcpy((void *)end, params, params_size); + applied_bytes += params_size; + applied_bytes += add_trailer(bootconfig_start_addr, + bootconfig_size + applied_bytes); + return applied_bytes; +} + __weak ulong get_avendor_bootimg_addr(void) { return -1;

For android vendor boot image version 4 bootconfig is mandatory.[1]
In the android_image_get_ramdisk function, after copying both vendor and boot ramdisks, we extract all androidboot.* entries from the kernel command line. These entries are added to the bootconfig section. We then update the sizes of the ramdisk and bootconfig. Finally, all androidboot.* entries are removed from the kernel command line.
[1] https://source.android.com/docs/core/architecture/partitions/vendor-boot-par... Co-developed-by: Mattijs Korpershoek mkorpershoek@baylibre.com Signed-off-by: Mattijs Korpershoek mkorpershoek@baylibre.com Signed-off-by: Guillaume La Roque glaroque@baylibre.com --- boot/image-android.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
diff --git a/boot/image-android.c b/boot/image-android.c index 05245a0ba918..66e4c58ab4eb 100644 --- a/boot/image-android.c +++ b/boot/image-android.c @@ -475,6 +475,9 @@ int android_image_get_ramdisk(const void *hdr, const void *vendor_boot_img, { struct andr_image_data img_data = {0}; ulong ramdisk_ptr; + size_t ret, len = 0; + size_t bootconfig_size = 0; + char *bootargs, *androidbootarg, *end;
if (!android_image_get_data(hdr, vendor_boot_img, &img_data)) return -EINVAL; @@ -510,6 +513,32 @@ int android_image_get_ramdisk(const void *hdr, const void *vendor_boot_img, memcpy((void *) (ramdisk_ptr), (void *)img_data.bootconfig_addr, img_data.bootconfig_size); + + bootargs = env_get("bootargs"); + bootconfig_size = img_data.bootconfig_size; + + while (1) { + androidbootarg = strstr(bootargs, "androidboot."); + if (!androidbootarg) + break; + end = strchr(androidbootarg, ' '); + *end = '\0'; + len = strlen(androidbootarg); + *end = '\n'; // bootConfig are new-line terminated + ret = add_bootconfig_parameters(androidbootarg, len + 1, + ramdisk_ptr, bootconfig_size); + if (!ret) + return -EINVAL; + bootconfig_size += ret; + img_data.ramdisk_size += ret; + /* Erase the androidboot.* bootarg from bootargs */ + *end = ' '; + memmove(androidbootarg, androidbootarg + len, + strlen(androidbootarg + len) + 1); + } + + /* Save back the new commandline without androidboot. */ + env_set("bootargs", bootargs); } } else { /* Ramdisk can be used in-place, use current ptr */

Hi Guillaume,
On Thu, 28 Nov 2024 at 03:15, Guillaume La Roque glaroque@baylibre.com wrote:
For android vendor boot image version 4 bootconfig is mandatory.[1]
In the android_image_get_ramdisk function, after copying both vendor and boot ramdisks, we extract all androidboot.* entries from the kernel command line. These entries are added to the bootconfig section. We then update the sizes of the ramdisk and bootconfig. Finally, all androidboot.* entries are removed from the kernel command line.
[1] https://source.android.com/docs/core/architecture/partitions/vendor-boot-par... Co-developed-by: Mattijs Korpershoek mkorpershoek@baylibre.com Signed-off-by: Mattijs Korpershoek mkorpershoek@baylibre.com Signed-off-by: Guillaume La Roque glaroque@baylibre.com
boot/image-android.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
I am not seeing any tests for this code. Can you please update the test to cover this?
Regards, Simon

Hi,
Le 30/11/2024 à 21:24, Simon Glass a écrit :
Hi Guillaume,
On Thu, 28 Nov 2024 at 03:15, Guillaume La Roque glaroque@baylibre.com wrote:
For android vendor boot image version 4 bootconfig is mandatory.[1]
In the android_image_get_ramdisk function, after copying both vendor and boot ramdisks, we extract all androidboot.* entries from the kernel command line. These entries are added to the bootconfig section. We then update the sizes of the ramdisk and bootconfig. Finally, all androidboot.* entries are removed from the kernel command line.
[1] https://source.android.com/docs/core/architecture/partitions/vendor-boot-par... Co-developed-by: Mattijs Korpershoek mkorpershoek@baylibre.com Signed-off-by: Mattijs Korpershoek mkorpershoek@baylibre.com Signed-off-by: Guillaume La Roque glaroque@baylibre.com
boot/image-android.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
I am not seeing any tests for this code. Can you please update the test to cover this?
i don't know if it's possible with test framework in uboot, to validate bootconfig raw partition is reading by android kernel. i don't really know how i can do this , if you can say me if it's something possible or not .
for kernel command line part is it possible to read it in test to check if we find some androidboot.* entry ?
Thanks. Guillaume
Regards, Simon

Hi Guillaume,
On Mon, 2 Dec 2024 at 01:03, Guillaume LA ROQUE glaroque@baylibre.com wrote:
Hi,
Le 30/11/2024 à 21:24, Simon Glass a écrit :
Hi Guillaume,
On Thu, 28 Nov 2024 at 03:15, Guillaume La Roque glaroque@baylibre.com wrote:
For android vendor boot image version 4 bootconfig is mandatory.[1]
In the android_image_get_ramdisk function, after copying both vendor and boot ramdisks, we extract all androidboot.* entries from the kernel command line. These entries are added to the bootconfig section. We then update the sizes of the ramdisk and bootconfig. Finally, all androidboot.* entries are removed from the kernel command line.
[1] https://source.android.com/docs/core/architecture/partitions/vendor-boot-par... Co-developed-by: Mattijs Korpershoek mkorpershoek@baylibre.com Signed-off-by: Mattijs Korpershoek mkorpershoek@baylibre.com Signed-off-by: Guillaume La Roque glaroque@baylibre.com
boot/image-android.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
I am not seeing any tests for this code. Can you please update the test to cover this?
i don't know if it's possible with test framework in uboot, to validate bootconfig raw partition is reading by android kernel. i don't really know how i can do this , if you can say me if it's something possible or not .
We don't have a way to boot a kernel (yet), but we do have tests that check things are correct - e.g. bootflow_android() - and after a 'fake' boot - e.g. bootflow_scan_boot()
for kernel command line part is it possible to read it in test to check if we find some androidboot.* entry ?
There is test/boot/bootm.c which checks the cmdline. A small amount of refactoring was used to allow this.
My suggestion here is to write a sandbox test which 'fake'-boots the Android kernel, similar to bootflow_android() but with a 'bootflow_boot()', then at the end of the test you can check various things.
Regards, Simon

On Mon, Dec 02, 2024 at 05:20:20PM -0700, Simon Glass wrote:
Hi Guillaume,
On Mon, 2 Dec 2024 at 01:03, Guillaume LA ROQUE glaroque@baylibre.com wrote:
Hi,
Le 30/11/2024 à 21:24, Simon Glass a écrit :
Hi Guillaume,
On Thu, 28 Nov 2024 at 03:15, Guillaume La Roque glaroque@baylibre.com wrote:
For android vendor boot image version 4 bootconfig is mandatory.[1]
In the android_image_get_ramdisk function, after copying both vendor and boot ramdisks, we extract all androidboot.* entries from the kernel command line. These entries are added to the bootconfig section. We then update the sizes of the ramdisk and bootconfig. Finally, all androidboot.* entries are removed from the kernel command line.
[1] https://source.android.com/docs/core/architecture/partitions/vendor-boot-par... Co-developed-by: Mattijs Korpershoek mkorpershoek@baylibre.com Signed-off-by: Mattijs Korpershoek mkorpershoek@baylibre.com Signed-off-by: Guillaume La Roque glaroque@baylibre.com
boot/image-android.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
I am not seeing any tests for this code. Can you please update the test to cover this?
i don't know if it's possible with test framework in uboot, to validate bootconfig raw partition is reading by android kernel. i don't really know how i can do this , if you can say me if it's something possible or not .
We don't have a way to boot a kernel (yet), but we do have tests that check things are correct - e.g. bootflow_android() - and after a 'fake' boot - e.g. bootflow_scan_boot()
We already have a test that boots the kernel, test/py/tests/test_net_boot.py

Le 03/12/2024 à 01:34, Tom Rini a écrit :
On Mon, Dec 02, 2024 at 05:20:20PM -0700, Simon Glass wrote:
Hi Guillaume,
On Mon, 2 Dec 2024 at 01:03, Guillaume LA ROQUE glaroque@baylibre.com wrote:
Hi,
Le 30/11/2024 à 21:24, Simon Glass a écrit :
Hi Guillaume,
On Thu, 28 Nov 2024 at 03:15, Guillaume La Roque glaroque@baylibre.com wrote:
For android vendor boot image version 4 bootconfig is mandatory.[1]
In the android_image_get_ramdisk function, after copying both vendor and boot ramdisks, we extract all androidboot.* entries from the kernel command line. These entries are added to the bootconfig section. We then update the sizes of the ramdisk and bootconfig. Finally, all androidboot.* entries are removed from the kernel command line.
[1] https://source.android.com/docs/core/architecture/partitions/vendor-boot-par... Co-developed-by: Mattijs Korpershoek mkorpershoek@baylibre.com Signed-off-by: Mattijs Korpershoek mkorpershoek@baylibre.com Signed-off-by: Guillaume La Roque glaroque@baylibre.com
boot/image-android.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
I am not seeing any tests for this code. Can you please update the test to cover this?
i don't know if it's possible with test framework in uboot, to validate bootconfig raw partition is reading by android kernel. i don't really know how i can do this , if you can say me if it's something possible or not .
We don't have a way to boot a kernel (yet), but we do have tests that check things are correct - e.g. bootflow_android() - and after a 'fake' boot - e.g. bootflow_scan_boot()
We already have a test that boots the kernel, test/py/tests/test_net_boot.py
Thanks for your feedback i will check all of this and will work on test for bootconfig..
Guillaume
participants (4)
-
Guillaume LA ROQUE
-
Guillaume La Roque
-
Simon Glass
-
Tom Rini