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