efi_loader: Split out efi_binary_run_dp() et all
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>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
*
|
||||
|
||||
67
lib/efi_loader/loader_run.c
Normal file
67
lib/efi_loader/loader_run.c
Normal file
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user