
From: Simon Glass <sjg@chromium.org> efi_binary_run_dp() calls efi_init_obj_list() which is specific to the EFI loader. Move this into a new file within lib/efi_loader Similarly, move efi_run_image() since the app will need a different implementation. Signed-off-by: Simon Glass <sjg@chromium.org> --- include/efi.h | 13 +++++++ lib/efi_loader/Makefile | 2 ++ lib/efi_loader/efi_bootbin.c | 68 ------------------------------------ lib/efi_loader/loader_run.c | 67 +++++++++++++++++++++++++++++++++++ 4 files changed, 82 insertions(+), 68 deletions(-) create mode 100644 lib/efi_loader/loader_run.c diff --git a/include/efi.h b/include/efi.h index efdd980fbc3..fb37de38334 100644 --- a/include/efi.h +++ b/include/efi.h @@ -773,4 +773,17 @@ efi_status_t efi_binary_run_dp(void *image, size_t size, void *fdt, struct efi_device_path *dp_dev, struct efi_device_path *dp_img); +/** + * efi_run_image() - run loaded UEFI image + * + * @source_buffer: memory address of the UEFI image + * @source_size: size of the UEFI image + * @dp_dev: EFI device-path + * @dp_img: EFI image-path + * Return: status code + */ +efi_status_t efi_run_image(void *source_buffer, efi_uintn_t source_size, + struct efi_device_path *dp_dev, + struct efi_device_path *dp_img); + #endif /* _LINUX_EFI_H */ diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile index a8e7f83336f..3158fc6da68 100644 --- a/lib/efi_loader/Makefile +++ b/lib/efi_loader/Makefile @@ -56,6 +56,8 @@ obj-y += efi_var_file.o obj-$(CONFIG_EFI_VARIABLES_PRESEED) += efi_var_seed.o endif obj-y += efi_watchdog.o +obj-y += loader_run.o + obj-$(CONFIG_EFI_ESRT) += efi_esrt.o obj-$(CONFIG_VIDEO) += efi_gop.o obj-$(CONFIG_BLK) += efi_disk.o diff --git a/lib/efi_loader/efi_bootbin.c b/lib/efi_loader/efi_bootbin.c index 81df1184834..bd45d775ee6 100644 --- a/lib/efi_loader/efi_bootbin.c +++ b/lib/efi_loader/efi_bootbin.c @@ -111,74 +111,6 @@ void efi_set_bootdev(const char *dev, const char *devnr, const char *path, } } -/** - * efi_run_image() - run loaded UEFI image - * - * @source_buffer: memory address of the UEFI image - * @source_size: size of the UEFI image - * @dp_dev: EFI device-path - * @dp_img: EFI image-path - * Return: status code - */ -static efi_status_t efi_run_image(void *source_buffer, efi_uintn_t source_size, - struct efi_device_path *dp_dev, - struct efi_device_path *dp_img) -{ - efi_handle_t handle; - struct efi_device_path *msg_path, *file_path; - efi_status_t ret; - u16 *load_options; - - file_path = efi_dp_concat(dp_dev, dp_img, 0); - msg_path = dp_img; - - log_info("Booting %pD\n", msg_path); - - ret = EFI_CALL(efi_load_image(false, efi_root, file_path, source_buffer, - source_size, &handle)); - if (ret != EFI_SUCCESS) { - log_err("Loading image failed\n"); - goto out; - } - - /* Transfer environment variable as load options */ - ret = efi_env_set_load_options(handle, "bootargs", &load_options); - if (ret != EFI_SUCCESS) - goto out; - - ret = do_bootefi_exec(handle, load_options); - -out: - - return ret; -} - -efi_status_t efi_binary_run_dp(void *image, size_t size, void *fdt, - void *initrd, size_t initrd_sz, - struct efi_device_path *dp_dev, - struct efi_device_path *dp_img) -{ - efi_status_t ret; - - /* Initialize EFI drivers */ - ret = efi_init_obj_list(); - if (ret != EFI_SUCCESS) { - log_err("Error: Cannot initialize UEFI sub-system, r = %lu\n", - ret & ~EFI_ERROR_MASK); - return -1; - } - - ret = efi_install_fdt(fdt); - if (ret != EFI_SUCCESS) - return ret; - - ret = efi_install_initrd(initrd, initrd_sz); - if (ret != EFI_SUCCESS) - return ret; - - return efi_run_image(image, size, dp_dev, dp_img); -} - /** * efi_binary_run() - run loaded UEFI image * diff --git a/lib/efi_loader/loader_run.c b/lib/efi_loader/loader_run.c new file mode 100644 index 00000000000..300f266ce5b --- /dev/null +++ b/lib/efi_loader/loader_run.c @@ -0,0 +1,67 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2024 Linaro Limited + * Copyright 2024 Canonical Ltd + */ + +#include <efi.h> +#include <efi_loader.h> + +efi_status_t efi_run_image(void *source_buffer, efi_uintn_t source_size, + struct efi_device_path *dp_dev, + struct efi_device_path *dp_img) +{ + efi_handle_t handle; + struct efi_device_path *msg_path, *file_path; + efi_status_t ret; + u16 *load_options; + + file_path = efi_dp_concat(dp_dev, dp_img, 0); + msg_path = dp_img; + + log_info("Booting %pD\n", msg_path); + + ret = EFI_CALL(efi_load_image(false, efi_root, file_path, source_buffer, + source_size, &handle)); + if (ret != EFI_SUCCESS) { + log_err("Loading image failed\n"); + goto out; + } + + /* Transfer environment variable as load options */ + ret = efi_env_set_load_options(handle, "bootargs", &load_options); + if (ret != EFI_SUCCESS) + goto out; + + ret = do_bootefi_exec(handle, load_options); + +out: + + return ret; +} + +efi_status_t efi_binary_run_dp(void *image, size_t size, void *fdt, + void *initrd, size_t initrd_sz, + struct efi_device_path *dp_dev, + struct efi_device_path *dp_img) +{ + efi_status_t ret; + + /* Initialize EFI drivers */ + ret = efi_init_obj_list(); + if (ret != EFI_SUCCESS) { + log_err("Error: Cannot initialize UEFI sub-system, r = %lu\n", + ret & ~EFI_ERROR_MASK); + return -1; + } + + ret = efi_install_fdt(fdt); + if (ret != EFI_SUCCESS) + return ret; + + ret = efi_install_initrd(initrd, initrd_sz); + if (ret != EFI_SUCCESS) + return ret; + + return efi_run_image(image, size, dp_dev, dp_img); +} -- 2.43.0