[PATCH v2 3/5] boot: android: Add bootconfig support
Mattijs Korpershoek
mkorpershoek at kernel.org
Fri Oct 31 16:58:16 CET 2025
Hi Guillaume,
Thank you for the patch.
On Fri, Oct 17, 2025 at 15:19, "Guillaume La Roque (TI.com)" <glaroque at baylibre.com> wrote:
> For android vendor boot image version 4 bootconfig is mandatory.[1]
There seems to be a link "[1]" here but it's not part of the commit
message.
Can you add it please?
>
> 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.
>
> Signed-off-by: Guillaume La Roque (TI.com) <glaroque at baylibre.com>
> ---
> boot/image-android.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++----
> 1 file changed, 93 insertions(+), 8 deletions(-)
>
> diff --git a/boot/image-android.c b/boot/image-android.c
> index 613f2aa4b9e..cf038a4a62f 100644
> --- a/boot/image-android.c
> +++ b/boot/image-android.c
> @@ -534,17 +534,102 @@ int android_image_get_ramdisk(const void *hdr, const void *vendor_boot_img,
> ramdisk_ptr = img_data.ramdisk_addr;
> }
> *rd_data = ramdisk_ptr;
> - memcpy((void *)(ramdisk_ptr), (void *)img_data.vendor_ramdisk_ptr,
> +
> + /* Extract androidboot.* parameters from bootargs */
> + const char *bootargs = env_get("bootargs");
> + char *androidboot_params = NULL;
> + char *new_bootargs = NULL;
> + size_t androidboot_params_len = 0;
> +
> + if (bootargs && img_data.bootconfig_size) {
> + size_t len = strlen(bootargs);
> +
> + androidboot_params = malloc(len + 1);
> + new_bootargs = malloc(len + 1);
> + if (!androidboot_params || !new_bootargs) {
> + free(androidboot_params);
> + free(new_bootargs);
> + printf("Error: malloc failed\n");
> + return -ENOMEM;
> + }
> +
> + /* Extract androidboot.* and build new bootargs in one pass */
> + const char *src = bootargs;
> + char *bc_dst = androidboot_params;
> + char *args_dst = new_bootargs;
> +
> + while (*src) {
> + /* Skip leading spaces */
> + while (*src == ' ')
> + src++;
> + if (!*src)
> + break;
> +
> + /* Check if this param starts with androidboot. */
> + if (strncmp(src, "androidboot.", 12) == 0) {
> + /* Copy to bootconfig (add newline if not first) */
> + if (bc_dst != androidboot_params)
> + *bc_dst++ = '\n';
> + while (*src && *src != ' ')
> + *bc_dst++ = *src++;
> + } else {
> + /* Copy to new bootargs (add space if not first) */
> + if (args_dst != new_bootargs)
> + *args_dst++ = ' ';
> + while (*src && *src != ' ')
> + *args_dst++ = *src++;
> + }
> + }
> +
> + *bc_dst++ = '\n'; /* Final newline for bootconfig */
> + *bc_dst = '\0';
> + *args_dst = '\0';
> + androidboot_params_len = bc_dst - androidboot_params;
> +
> + /* Update bootargs if we extracted any androidboot params */
> + if (androidboot_params_len > 1)
> + env_set("bootargs", new_bootargs);
> + }
> +
> + /* Map addresses for memcpy operations */
> + void *ramdisk_dest = map_sysmem(ramdisk_ptr, img_data.ramdisk_size);
> + void *vendor_ramdisk_src = map_sysmem(img_data.vendor_ramdisk_ptr,
> + img_data.vendor_ramdisk_size);
> + void *boot_ramdisk_src = map_sysmem(img_data.ramdisk_ptr,
> + img_data.boot_ramdisk_size);
> +
> + memcpy(ramdisk_dest, vendor_ramdisk_src,
> img_data.vendor_ramdisk_size);
> - ramdisk_ptr += img_data.vendor_ramdisk_size;
> - memcpy((void *)(ramdisk_ptr), (void *)img_data.ramdisk_ptr,
> - img_data.boot_ramdisk_size);
> - ramdisk_ptr += img_data.boot_ramdisk_size;
> + memcpy((char *)ramdisk_dest + img_data.vendor_ramdisk_size,
> + boot_ramdisk_src, img_data.boot_ramdisk_size);
> +
> if (img_data.bootconfig_size) {
> - memcpy((void *)
> - (ramdisk_ptr), (void *)img_data.bootconfig_addr,
> - img_data.bootconfig_size);
> + void *bootconfig_src = map_sysmem(img_data.bootconfig_addr,
> + img_data.bootconfig_size);
> + memcpy((char *)ramdisk_dest + img_data.vendor_ramdisk_size +
> + img_data.boot_ramdisk_size,
> + bootconfig_src, img_data.bootconfig_size);
> + unmap_sysmem(bootconfig_src);
> +
> + /* Add androidboot.* parameters to bootconfig */
> + if (androidboot_params && androidboot_params_len > 1) {
> + ulong bootconfig_ptr = (ulong)ramdisk_dest +
> + img_data.vendor_ramdisk_size +
> + img_data.boot_ramdisk_size;
> + img_data.ramdisk_size +=
> + add_bootconfig_parameters(androidboot_params,
> + androidboot_params_len,
> + bootconfig_ptr,
> + img_data.bootconfig_size);
> + }
> }
> +
> + free(androidboot_params);
> + free(new_bootargs);
> +
> + unmap_sysmem(boot_ramdisk_src);
> + unmap_sysmem(vendor_ramdisk_src);
> + unmap_sysmem(ramdisk_dest);
We are here in the "if (img_data.header_version > 2) {" block.
What about boot image v3? Why are we forcing bootconfig upon them?
Also, please move this to a seperate function. It makes
android_image_get_ramdisk() quite long and difficult to read otherwise.
Finally, what happens if a kernel does not have bootconfig enabled ?
I imagine that everything will crash due to this change. Even if
bootconfig is mandatory for boot image v4, I believe we should make this
behaviour optional to avoid breaking existing kernels.
> } else {
> /* Ramdisk can be used in-place, use current ptr */
> if (img_data.ramdisk_addr == 0 ||
>
> --
> 2.34.1
More information about the U-Boot
mailing list