Hi Simon,

thanks for review.

Le 19/11/2025 à 14:17, Simon Glass a écrit :
Hi Guillaume,

On Fri, 14 Nov 2025 at 08:28, Guillaume La Roque (TI.com)
<[email protected]> 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-partitions#bootloader-support
Signed-off-by: Guillaume La Roque (TI.com) <[email protected]>
---
  boot/image-android.c | 120 ++++++++++++++++++++++++++++++++++++++++++++++-----
  1 file changed, 109 insertions(+), 11 deletions(-)

Reviewed-by: Simon Glass <[email protected]>

diff --git a/boot/image-android.c b/boot/image-android.c
index 613f2aa4b9e..94c2879dcd6 100644
--- a/boot/image-android.c
+++ b/boot/image-android.c
@@ -503,6 +503,112 @@ ulong android_image_get_kcomp(const void *hdr,
                 return image_decomp_type(p, sizeof(u32));
  }

+static u32 android_image_set_bootconfig(const void *hdr,
+                                       const void *vendor_boot_img,
+                                       ulong ramdisk_ptr)
This could use a comment.

Also, ramdisk_ptr is a strange name for an address as it sounds like
it is a pointer. Perhaps use ramdisk_addr ?
i will do

+{
+       /* 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;
As a general comment, some of the args are quite long and this makes
the code harder to read. For example this could be params_len, since
we know this is Android Boot.
agree with you

+       struct andr_image_data img_data;
+       u32 bytes_added = 0;
+
+       if (!android_image_get_data(hdr, vendor_boot_img, &img_data))
+               return 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);
We tend to declare things at the top of the function. You could split
the function if you like.
i will create a sub function for copying data.

+
+       memcpy(ramdisk_dest, vendor_ramdisk_src, img_data.vendor_ramdisk_size);
+       memcpy((char *)ramdisk_dest + img_data.vendor_ramdisk_size, 
boot_ramdisk_src,
+              img_data.boot_ramdisk_size);
+
+       if (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;
+                       bytes_added =
+                               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);
+       return bytes_added;
+}
+
  int android_image_get_ramdisk(const void *hdr, const void *vendor_boot_img,
                               ulong *rd_data, ulong *rd_len)
  {
@@ -534,17 +640,9 @@ 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,
-                      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;
-               if (img_data.bootconfig_size) {
-                       memcpy((void *)
-                              (ramdisk_ptr), (void *)img_data.bootconfig_addr,
-                              img_data.bootconfig_size);
-               }
+               if (img_data.header_version > 3)
+                       img_data.ramdisk_size +=
+                               android_image_set_bootconfig(hdr, 
vendor_boot_img, ramdisk_ptr);
         } else {
                 /* Ramdisk can be used in-place, use current ptr */
                 if (img_data.ramdisk_addr == 0 ||

--
2.34.1

Regards,
Simon


Reply via email to