All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mattijs Korpershoek <mkorpershoek@kernel.org>
To: "Guillaume La Roque (TI.com)" <glaroque@baylibre.com>,
	Tom Rini <trini@konsulko.com>,
	Mattijs Korpershoek <mkorpershoek@kernel.org>
Cc: Julien Masson <jmasson@baylibre.com>,
	Guillaume La Roque <glaroque@baylibre.com>,
	u-boot@lists.denx.de, Simon Glass <sjg@chromium.org>,
	Nicolas Belin <nbelin@baylibre.com>,
	Neil Armstrong <neil.armstrong@linaro.org>,
	Andrew Goodbody <andrew.goodbody@linaro.org>,
	Aaron Kling <webgeek1234@gmail.com>,
	George Chan <gchan9527@gmail.com>, Sam Day <me@samcday.com>,
	Jerome Forissier <jerome.forissier@linaro.org>,
	Maxime Fournier <mfournier@baylibre.com>
Subject: Re: [PATCH v2 3/5] boot: android: Add bootconfig support
Date: Fri, 31 Oct 2025 16:58:16 +0100	[thread overview]
Message-ID: <87cy635ahz.fsf@kernel.org> (raw)
In-Reply-To: <20251017-bootconfig-v2-3-8c7c2f2e5474@baylibre.com>

Hi Guillaume,

Thank you for the patch.

On Fri, Oct 17, 2025 at 15:19, "Guillaume La Roque (TI.com)" <glaroque@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@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

  reply	other threads:[~2025-10-31 15:58 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-17 13:19 [PATCH v2 0/5] android: add bootconfig support Guillaume La Roque (TI.com)
2025-10-17 13:19 ` [PATCH v2 1/5] boot: android: import addBootConfigParameters() from AOSP Guillaume La Roque (TI.com)
2025-10-31 15:39   ` Mattijs Korpershoek
2025-10-17 13:19 ` [PATCH v2 2/5] boot: android: Add sandbox memory mapping support Guillaume La Roque (TI.com)
2025-10-31 15:49   ` Mattijs Korpershoek
2025-10-17 13:19 ` [PATCH v2 3/5] boot: android: Add bootconfig support Guillaume La Roque (TI.com)
2025-10-31 15:58   ` Mattijs Korpershoek [this message]
2025-11-03 18:52     ` Guillaume La Roque
2025-11-07 14:52       ` Mattijs Korpershoek
2025-10-17 13:19 ` [PATCH v2 4/5] cmd: abootimg: Add 'get ramdisk' command Guillaume La Roque (TI.com)
2025-10-31 16:13   ` Mattijs Korpershoek
2025-10-17 13:19 ` [PATCH v2 5/5] test: abootimg: Add test for bootconfig handling Guillaume La Roque (TI.com)
2025-10-19 13:06   ` Simon Glass
2025-10-19 16:01     ` Tom Rini
2025-10-20  5:18       ` Simon Glass
2025-10-24 15:09         ` Guillaume La Roque
2025-10-24 15:20           ` Tom Rini
2025-10-31 16:27   ` Mattijs Korpershoek
2025-11-05 18:14     ` Guillaume La Roque
2025-11-07 14:52       ` Mattijs Korpershoek
2025-10-18  6:07 ` [PATCH v2 0/5] android: add bootconfig support george chan
2025-10-20 13:58   ` Guillaume La Roque
2025-10-20 15:45     ` george chan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87cy635ahz.fsf@kernel.org \
    --to=mkorpershoek@kernel.org \
    --cc=andrew.goodbody@linaro.org \
    --cc=gchan9527@gmail.com \
    --cc=glaroque@baylibre.com \
    --cc=jerome.forissier@linaro.org \
    --cc=jmasson@baylibre.com \
    --cc=me@samcday.com \
    --cc=mfournier@baylibre.com \
    --cc=nbelin@baylibre.com \
    --cc=neil.armstrong@linaro.org \
    --cc=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=webgeek1234@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.