Skip to contentSkip to conversation

android: add bootconfig support

PATCH Superseded Guillaume La Roque 3 participants 8 messages Nov 28, 2024 – Dec 4, 2024

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

cover 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-bootconfig

---
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,

Signature · 1 line
Guillaume La Roque <[email protected]>
#1 lore raw

PATCH 1/2 boot: android: import addBootConfigParameters() from AOSP

From: Mattijs Korpershoek <[email protected]>

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/+/7af0a0506d4de6f5ea147d10fb0664a8af07d326

---
 boot/image-android.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
boot/image-android.c +30 -0
index 93b54bf8d793..05245a0ba918 100644
@@ -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;
Signature · 1 line
2.34.1
#2 lore raw

PATCH 2/2 boot: android: Add bootconfig support

In reply to Guillaume La Roque

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-partitions#vendor-boot-partition-v4

---
 boot/image-android.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
boot/image-android.c +29 -0
index 05245a0ba918..66e4c58ab4eb 100644
@@ -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 */
Signature · 1 line
2.34.1
#3 lore raw

Re: [PATCH 2/2] boot: android: Add bootconfig support

Hi Guillaume,

Quoted 10 lines · Guillaume La Roque

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.

Quoted 8 lines

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

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

#4 lore raw

Re: [PATCH 2/2] boot: android: Add bootconfig support

Hi,

Le 30/11/2024 à 21:24, Simon Glass a écrit :

Quoted 20 lines

Hi Guillaume,

Quoted 9 lines · Guillaume La Roque

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.

Quoted 8 lines

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

---
  boot/image-android.c | 29 +++++++++++++++++++++++++++++
  1 file changed, 29 insertions(+)
Quoted 2 lines

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

Quoted 3 lines

Regards,
Simon

#5 lore raw

Re: [PATCH 2/2] boot: android: Add bootconfig support

Hi Guillaume,

Quoted 24 lines · Guillaume LA ROQUE

Hi,

Quoted 20 lines · Simon Glass

Hi Guillaume,

Quoted 17 lines · Guillaume La Roque

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-partitions#vendor-boot-partition-v4

---
  boot/image-android.c | 29 +++++++++++++++++++++++++++++
  1 file changed, 29 insertions(+)
Quoted 6 lines
Quoted 2 lines

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

Quoted 3 lines

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

#6 lore raw

Re: [PATCH 2/2] boot: android: Add bootconfig support

Quoted 29 lines · Simon Glass

Hi Guillaume,

Quoted 26 lines · Guillaume LA ROQUE

Hi,

Quoted 22 lines · Simon Glass

Hi Guillaume,

Quoted 9 lines · Guillaume La Roque

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.

Quoted 8 lines

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

---
  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?

Quoted 8 lines
Quoted 4 lines

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

Signature · 1 line
Tom
#7 lore raw

Re: [PATCH 2/2] boot: android: Add bootconfig support

Le 03/12/2024 à 01:34, Tom Rini a écrit :

Quoted 29 lines · Simon Glass
Quoted 28 lines

Hi Guillaume,

Quoted 25 lines · Guillaume LA ROQUE

Hi,

Quoted 22 lines · Simon Glass

Hi Guillaume,

Quoted 9 lines · Guillaume La Roque

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.

Quoted 8 lines

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

---
   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?

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

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

Quoted 1 line