mirror of
https://source.denx.de/u-boot/u-boot.git
synced 2026-06-02 09:46:37 +03:00
boot: android: Add sandbox memory mapping support
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. Reviewed-by: Mattijs Korpershoek <mkorpershoek@kernel.org> Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Guillaume La Roque (TI.com) <glaroque@baylibre.com> Link: https://lore.kernel.org/r/20260112-bootconfig-v5-2-79b242159ac7@baylibre.com Signed-off-by: Mattijs Korpershoek <mkorpershoek@kernel.org>
This commit is contained in:
committed by
Mattijs Korpershoek
parent
6b0f079ba2
commit
8f6d435570
@@ -114,7 +114,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;
|
||||
@@ -127,7 +127,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
|
||||
@@ -146,7 +146,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);
|
||||
@@ -167,12 +167,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,
|
||||
@@ -187,7 +191,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
|
||||
@@ -220,7 +224,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)
|
||||
@@ -271,31 +275,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;
|
||||
}
|
||||
|
||||
@@ -724,21 +739,14 @@ bool android_image_get_dtb_by_index(ulong hdr_addr, ulong vendor_boot_img,
|
||||
u32 index, ulong *addr, u32 *size)
|
||||
{
|
||||
struct andr_image_data img_data;
|
||||
const struct andr_boot_img_hdr_v0 *hdr;
|
||||
const struct andr_vnd_boot_img_hdr *vhdr = NULL;
|
||||
const void *vendor_boot_hdr = NULL;
|
||||
|
||||
hdr = map_sysmem(hdr_addr, sizeof(*hdr));
|
||||
if (vendor_boot_img != -1)
|
||||
vhdr = map_sysmem(vendor_boot_img, sizeof(*vhdr));
|
||||
if (!android_image_get_data(hdr, vhdr, &img_data)) {
|
||||
if (vendor_boot_img != -1)
|
||||
unmap_sysmem(vhdr);
|
||||
unmap_sysmem(hdr);
|
||||
vendor_boot_hdr = (const void *)vendor_boot_img;
|
||||
|
||||
if (!android_image_get_data((const void *)hdr_addr, vendor_boot_hdr,
|
||||
&img_data))
|
||||
return false;
|
||||
}
|
||||
if (vendor_boot_img != -1)
|
||||
unmap_sysmem(vhdr);
|
||||
unmap_sysmem(hdr);
|
||||
|
||||
ulong dtb_img_addr; /* address of DTB part in boot image */
|
||||
u32 dtb_img_size; /* size of DTB payload in boot image */
|
||||
|
||||
@@ -92,26 +92,18 @@ static int abootimg_get_recovery_dtbo(int argc, char *const argv[])
|
||||
|
||||
static int abootimg_get_dtb_load_addr(int argc, char *const argv[])
|
||||
{
|
||||
struct andr_image_data img_data = {0};
|
||||
const void *vendor_boot_hdr = NULL;
|
||||
|
||||
if (argc > 1)
|
||||
return CMD_RET_USAGE;
|
||||
struct andr_image_data img_data = {0};
|
||||
const struct andr_boot_img_hdr_v0 *hdr;
|
||||
const struct andr_vnd_boot_img_hdr *vhdr = NULL;
|
||||
|
||||
hdr = map_sysmem(abootimg_addr(), sizeof(*hdr));
|
||||
if (get_avendor_bootimg_addr() != -1)
|
||||
vhdr = map_sysmem(get_avendor_bootimg_addr(), sizeof(*vhdr));
|
||||
vendor_boot_hdr = (const void *)get_avendor_bootimg_addr();
|
||||
|
||||
if (!android_image_get_data(hdr, vhdr, &img_data)) {
|
||||
if (get_avendor_bootimg_addr() != -1)
|
||||
unmap_sysmem(vhdr);
|
||||
unmap_sysmem(hdr);
|
||||
if (!android_image_get_data((const void *)abootimg_addr(),
|
||||
vendor_boot_hdr, &img_data))
|
||||
return CMD_RET_FAILURE;
|
||||
}
|
||||
|
||||
if (get_avendor_bootimg_addr() != -1)
|
||||
unmap_sysmem(vhdr);
|
||||
unmap_sysmem(hdr);
|
||||
|
||||
if (img_data.header_version < 2) {
|
||||
printf("Error: header_version must be >= 2 for this\n");
|
||||
|
||||
Reference in New Issue
Block a user