efi: Allocate the kernel buffer when running in the app

The app cannot know the address to use in advance, so does not have a
value for kernel_addr_r in its environment, if it even has an
environment.

Allocate memory for the kernel instead. Limit it to 64MB which seems
like plenty for the distros out there. It is enough to load a full
kernel if needed.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass
2025-08-05 16:39:47 -06:00
parent c9dbf55855
commit 0d90733a31

View File

@@ -281,13 +281,34 @@ static int distro_efi_read_bootflow(struct udevice *dev, struct bootflow *bflow)
static int distro_efi_boot(struct udevice *dev, struct bootflow *bflow)
{
int size = SZ_1G;
ulong kernel, fdt;
int ret;
log_debug("distro EFI boot\n");
kernel = env_get_hex("kernel_addr_r", 0);
if (IS_ENABLED(CONFIG_EFI_APP)) {
struct efi_priv *priv = efi_get_priv();
efi_status_t eret;
void *ptr;
/*
* we don't expect the app to be larger than 64M and in fact,
* for Linux, it is typically only a few MB
*/
size = SZ_64M;
ptr = efi_malloc(priv, size, &eret);
if (!ptr) {
log_err("Out of memory for image (%x bytes): err=%lx\n",
size, eret);
return -ENOMEM;
}
kernel = map_to_sysmem(ptr);
} else {
kernel = env_get_hex("kernel_addr_r", 0);
}
if (!bootmeth_uses_network(bflow)) {
ret = efiload_read_file(bflow, kernel, SZ_1G);
ret = efiload_read_file(bflow, kernel, size);
if (ret)
return log_msg_ret("read", ret);