[PATCH 2/3] efi_loader: binary_run: register an initrd
Adriano Cordova
adrianox at gmail.com
Tue Mar 18 14:23:46 CET 2025
Add support to install an initrd when running an EFI binary
with efi_binary_run
Signed-off-by: Adriano Cordova <adriano.cordova at canonical.com>
---
boot/bootm_os.c | 3 ++-
cmd/bootefi.c | 2 +-
include/efi_loader.h | 2 +-
lib/efi_loader/efi_bootbin.c | 20 +++++++++++++++++---
4 files changed, 21 insertions(+), 6 deletions(-)
diff --git a/boot/bootm_os.c b/boot/bootm_os.c
index e9522cd3299..f403f352be1 100644
--- a/boot/bootm_os.c
+++ b/boot/bootm_os.c
@@ -507,7 +507,8 @@ static int do_bootm_efi(int flag, struct bootm_info *bmi)
ret = efi_binary_run(image_buf, images->os.image_len,
images->ft_len
- ? images->ft_addr : EFI_FDT_USE_INTERNAL);
+ ? images->ft_addr : EFI_FDT_USE_INTERNAL,
+ NULL, 0);
return ret;
}
diff --git a/cmd/bootefi.c b/cmd/bootefi.c
index c1454ffb948..dce8285b047 100644
--- a/cmd/bootefi.c
+++ b/cmd/bootefi.c
@@ -211,7 +211,7 @@ static int do_bootefi(struct cmd_tbl *cmdtp, int flag, int argc,
}
}
- ret = efi_binary_run(image_buf, size, fdt);
+ ret = efi_binary_run(image_buf, size, fdt, NULL, 0);
if (ret != EFI_SUCCESS)
return CMD_RET_FAILURE;
diff --git a/include/efi_loader.h b/include/efi_loader.h
index cc732dc4807..ad60805ae4f 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -600,7 +600,7 @@ efi_status_t efi_install_fdt(void *fdt);
/* Execute loaded UEFI image */
efi_status_t do_bootefi_exec(efi_handle_t handle, void *load_options);
/* Run loaded UEFI image with given fdt */
-efi_status_t efi_binary_run(void *image, size_t size, void *fdt);
+efi_status_t efi_binary_run(void *image, size_t size, void *fdt, void *initrd, size_t initrd_sz);
/**
* efi_bootflow_run() - Run a bootflow containing an EFI application
diff --git a/lib/efi_loader/efi_bootbin.c b/lib/efi_loader/efi_bootbin.c
index deafb2ce1c2..8c1850296ad 100644
--- a/lib/efi_loader/efi_bootbin.c
+++ b/lib/efi_loader/efi_bootbin.c
@@ -204,6 +204,8 @@ out:
* @image: memory address of the UEFI image
* @size: size of the UEFI image
* @fdt: device-tree
+ * @initrd: initrd
+ * @initrd_sz: initrd size
* @dp_dev: EFI device-path
* @dp_img: EFI image-path
*
@@ -213,10 +215,12 @@ out:
* Return: status code
*/
static efi_status_t efi_binary_run_dp(void *image, size_t size, void *fdt,
+ void *initrd, size_t initd_sz,
struct efi_device_path *dp_dev,
struct efi_device_path *dp_img)
{
efi_status_t ret;
+ struct efi_device_path *dp_initrd;
/* Initialize EFI drivers */
ret = efi_init_obj_list();
@@ -230,6 +234,14 @@ static efi_status_t efi_binary_run_dp(void *image, size_t size, void *fdt,
if (ret != EFI_SUCCESS)
return ret;
+ dp_initrd = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE, (uintptr_t)initrd, initd_sz);
+ if (!dp_initrd)
+ return EFI_OUT_OF_RESOURCES;
+
+ ret = efi_initrd_register(dp_initrd);
+ if (ret != EFI_SUCCESS)
+ return ret;
+
return efi_run_image(image, size, dp_dev, dp_img);
}
@@ -239,13 +251,15 @@ static efi_status_t efi_binary_run_dp(void *image, size_t size, void *fdt,
* @image: memory address of the UEFI image
* @size: size of the UEFI image
* @fdt: device-tree
+ * @initrd: initrd
+ * @initrd_sz: initrd size
*
* Execute an EFI binary image loaded at @image.
* @size may be zero if the binary is loaded with U-Boot load command.
*
* Return: status code
*/
-efi_status_t efi_binary_run(void *image, size_t size, void *fdt)
+efi_status_t efi_binary_run(void *image, size_t size, void *fdt, void *initrd, size_t initrd_sz)
{
efi_handle_t mem_handle = NULL;
struct efi_device_path *file_path = NULL;
@@ -273,7 +287,7 @@ efi_status_t efi_binary_run(void *image, size_t size, void *fdt)
log_debug("Loaded from disk\n");
}
- ret = efi_binary_run_dp(image, size, fdt, bootefi_device_path,
+ ret = efi_binary_run_dp(image, size, fdt, initrd, initrd_sz, bootefi_device_path,
bootefi_image_path);
out:
if (mem_handle) {
@@ -355,7 +369,7 @@ efi_status_t efi_bootflow_run(struct bootflow *bflow)
log_debug("Booting with external fdt\n");
fdt = map_sysmem(bflow->fdt_addr, 0);
}
- ret = efi_binary_run_dp(bflow->buf, bflow->size, fdt, device, image);
+ ret = efi_binary_run_dp(bflow->buf, bflow->size, fdt, NULL, 0, device, image);
return ret;
}
--
2.48.1
More information about the U-Boot
mailing list