efi_loader: binary_run: register an initrd
authorAdriano Cordova <adrianox@gmail.com>
Wed, 19 Mar 2025 14:45:00 +0000 (11:45 -0300)
committerHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Fri, 11 Apr 2025 11:20:38 +0000 (13:20 +0200)
Add support to install an initrd when running an EFI binary
with efi_binary_run

Signed-off-by: Adriano Cordova <adriano.cordova@canonical.com>
Acked-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
boot/bootm_os.c
cmd/bootefi.c
include/efi_loader.h
lib/efi_loader/efi_bootbin.c

index e9522cd..f403f35 100644 (file)
@@ -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;
 }
index c1454ff..dce8285 100644 (file)
@@ -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;
index 72bee60..144b749 100644 (file)
@@ -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
index deafb2c..2cf9723 100644 (file)
@@ -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_LOADER_DATA, (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;
 }