public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: "Guillaume La Roque (TI.com)" <glaroque@baylibre.com>
To: 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: [PATCH v2 2/5] boot: android: Add sandbox memory mapping support
Date: Fri, 17 Oct 2025 15:19:18 +0200	[thread overview]
Message-ID: <20251017-bootconfig-v2-2-8c7c2f2e5474@baylibre.com> (raw)
In-Reply-To: <20251017-bootconfig-v2-0-8c7c2f2e5474@baylibre.com>

Use map_to_sysmem() to convert header pointers to physical addresses
in parse_hdr functions, and add proper map_sysmem()/unmap_sysmem()
calls in android_image_get_data() for sandbox compatibility.

Signed-off-by: Guillaume La Roque (TI.com) <glaroque@baylibre.com>
---
 boot/image-android.c | 41 ++++++++++++++++++++++++++++-------------
 1 file changed, 28 insertions(+), 13 deletions(-)

diff --git a/boot/image-android.c b/boot/image-android.c
index 3a0a934acc7..613f2aa4b9e 100644
--- a/boot/image-android.c
+++ b/boot/image-android.c
@@ -112,7 +112,7 @@ static void android_boot_image_v3_v4_parse_hdr(const struct andr_boot_img_hdr_v3
 	 * The header takes a full page, the remaining components are aligned
 	 * on page boundary.
 	 */
-	end = (ulong)hdr;
+	end = map_to_sysmem(hdr);
 	end += ANDR_GKI_PAGE_SIZE;
 	data->kernel_ptr = end;
 	data->kernel_size = hdr->kernel_size;
@@ -125,7 +125,7 @@ static void android_boot_image_v3_v4_parse_hdr(const struct andr_boot_img_hdr_v3
 	if (hdr->header_version > 3)
 		end += ALIGN(hdr->signature_size, ANDR_GKI_PAGE_SIZE);
 
-	data->boot_img_total_size = end - (ulong)hdr;
+	data->boot_img_total_size = end - map_to_sysmem(hdr);
 }
 
 static void android_vendor_boot_image_v3_v4_parse_hdr(const struct andr_vnd_boot_img_hdr
@@ -144,7 +144,7 @@ static void android_vendor_boot_image_v3_v4_parse_hdr(const struct andr_vnd_boot
 	data->ramdisk_addr = hdr->ramdisk_addr;
 	data->dtb_load_addr = hdr->dtb_addr;
 	data->bootconfig_size = hdr->bootconfig_size;
-	end = (ulong)hdr;
+	end = map_to_sysmem(hdr);
 
 	if (hdr->header_version > 3)
 		end += ALIGN(ANDR_VENDOR_BOOT_V4_SIZE, hdr->page_size);
@@ -165,12 +165,16 @@ static void android_vendor_boot_image_v3_v4_parse_hdr(const struct andr_vnd_boot
 	end += ALIGN(hdr->vendor_ramdisk_table_size, hdr->page_size);
 	data->bootconfig_addr = end;
 	if (hdr->bootconfig_size) {
-		data->bootconfig_size += add_trailer(data->bootconfig_addr,
+		void *bootconfig_ptr = map_sysmem(data->bootconfig_addr,
+						  data->bootconfig_size +
+						  BOOTCONFIG_TRAILER_SIZE);
+		data->bootconfig_size += add_trailer((ulong)bootconfig_ptr,
 						     data->bootconfig_size);
+		unmap_sysmem(bootconfig_ptr);
 		data->ramdisk_size += data->bootconfig_size;
 	}
 	end += ALIGN(data->bootconfig_size, hdr->page_size);
-	data->vendor_boot_img_total_size = end - (ulong)hdr;
+	data->vendor_boot_img_total_size = end - map_to_sysmem(hdr);
 }
 
 static void android_boot_image_v0_v1_v2_parse_hdr(const struct andr_boot_img_hdr_v0 *hdr,
@@ -185,7 +189,7 @@ static void android_boot_image_v0_v1_v2_parse_hdr(const struct andr_boot_img_hdr
 	data->header_version = hdr->header_version;
 	data->dtb_load_addr = hdr->dtb_addr;
 
-	end = (ulong)hdr;
+	end = map_to_sysmem(hdr);
 
 	/*
 	 * The header takes a full page, the remaining components are aligned
@@ -218,7 +222,7 @@ static void android_boot_image_v0_v1_v2_parse_hdr(const struct andr_boot_img_hdr
 		end += ALIGN(hdr->dtb_size, hdr->page_size);
 	}
 
-	data->boot_img_total_size = end - (ulong)hdr;
+	data->boot_img_total_size = end - map_to_sysmem(hdr);
 }
 
 bool android_image_get_bootimg_size(const void *hdr, u32 *boot_img_size)
@@ -269,31 +273,42 @@ bool android_image_get_vendor_bootimg_size(const void *hdr, u32 *vendor_boot_img
 bool android_image_get_data(const void *boot_hdr, const void *vendor_boot_hdr,
 			    struct andr_image_data *data)
 {
+	const struct andr_boot_img_hdr_v0 *bhdr;
+	const struct andr_vnd_boot_img_hdr *vhdr;
+
 	if (!boot_hdr || !data) {
 		printf("boot_hdr or data params can't be NULL\n");
 		return false;
 	}
 
-	if (!is_android_boot_image_header(boot_hdr)) {
+	bhdr = map_sysmem((ulong)boot_hdr, sizeof(*bhdr));
+	if (!is_android_boot_image_header(bhdr)) {
 		printf("Incorrect boot image header\n");
+		unmap_sysmem(bhdr);
 		return false;
 	}
 
-	if (((struct andr_boot_img_hdr_v0 *)boot_hdr)->header_version > 2) {
+	if (bhdr->header_version > 2) {
 		if (!vendor_boot_hdr) {
 			printf("For boot header v3+ vendor boot image has to be provided\n");
+			unmap_sysmem(bhdr);
 			return false;
 		}
-		if (!is_android_vendor_boot_image_header(vendor_boot_hdr)) {
+		vhdr = map_sysmem((ulong)vendor_boot_hdr, sizeof(*vhdr));
+		if (!is_android_vendor_boot_image_header(vhdr)) {
 			printf("Incorrect vendor boot image header\n");
+			unmap_sysmem(vhdr);
+			unmap_sysmem(bhdr);
 			return false;
 		}
-		android_boot_image_v3_v4_parse_hdr(boot_hdr, data);
-		android_vendor_boot_image_v3_v4_parse_hdr(vendor_boot_hdr, data);
+		android_boot_image_v3_v4_parse_hdr((const struct andr_boot_img_hdr_v3 *)bhdr, data);
+		android_vendor_boot_image_v3_v4_parse_hdr(vhdr, data);
+		unmap_sysmem(vhdr);
 	} else {
-		android_boot_image_v0_v1_v2_parse_hdr(boot_hdr, data);
+		android_boot_image_v0_v1_v2_parse_hdr(bhdr, data);
 	}
 
+	unmap_sysmem(bhdr);
 	return true;
 }
 

-- 
2.34.1


  parent reply	other threads:[~2025-10-17 13:19 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 ` Guillaume La Roque (TI.com) [this message]
2025-10-31 15:49   ` [PATCH v2 2/5] boot: android: Add sandbox memory mapping support 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
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=20251017-bootconfig-v2-2-8c7c2f2e5474@baylibre.com \
    --to=glaroque@baylibre.com \
    --cc=andrew.goodbody@linaro.org \
    --cc=gchan9527@gmail.com \
    --cc=jerome.forissier@linaro.org \
    --cc=jmasson@baylibre.com \
    --cc=me@samcday.com \
    --cc=mfournier@baylibre.com \
    --cc=mkorpershoek@kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox