[U-Boot] [PATCH v3 20/21] efi: Create a function to set up for running EFI code
Simon Glass
sjg at chromium.org
Mon Feb 19 15:48:26 UTC 2018
Add a new bootefi_run_prepare() function which holds common code used to
set up U-Boot to run EFI code. Make use of this from the existing
bootefi_test_prepare() function, as well as do_bootefi_exec().
Also shorten a few variable names.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
Changes in v3:
- Add patch to create a function to set up for running EFI code
Changes in v2: None
cmd/bootefi.c | 96 ++++++++++++++++++++++-----------------------------
1 file changed, 42 insertions(+), 54 deletions(-)
diff --git a/cmd/bootefi.c b/cmd/bootefi.c
index cdfa22ee4c..45f2b6c818 100644
--- a/cmd/bootefi.c
+++ b/cmd/bootefi.c
@@ -169,6 +169,33 @@ static efi_status_t efi_run_in_el2(EFIAPI efi_status_t (*entry)(
}
#endif
+static efi_status_t bootefi_run_prepare(struct efi_loaded_image *image,
+ struct efi_object *obj,
+ const char *path,
+ struct efi_device_path *device_path,
+ struct efi_device_path *image_path)
+{
+ efi_status_t ret;
+
+ efi_setup_loaded_image(image, obj, device_path, image_path);
+
+ /* Initialize and populate EFI object list */
+ ret = efi_init_obj_list();
+ if (ret)
+ return ret;
+
+ /*
+ * gd lives in a fixed register which may get clobbered while we execute
+ * the payload. So save it here and restore it on every callback entry
+ */
+ efi_save_gd();
+
+ /* Transfer environment variable bootargs as load options */
+ set_load_options(image, path);
+
+ return 0;
+}
+
/*
* Load an EFI payload into a newly allocated piece of memory, register all
* EFI objects it would want to access and jump to it.
@@ -177,8 +204,8 @@ static efi_status_t do_bootefi_exec(void *efi, void *fdt,
struct efi_device_path *device_path,
struct efi_device_path *image_path)
{
- struct efi_loaded_image loaded_image_info = {};
- struct efi_object loaded_image_info_obj = {};
+ struct efi_loaded_image image;
+ struct efi_object obj;
struct efi_device_path *memdp = NULL;
ulong ret;
@@ -202,23 +229,8 @@ static efi_status_t do_bootefi_exec(void *efi, void *fdt,
assert(device_path && image_path);
}
- efi_setup_loaded_image(&loaded_image_info, &loaded_image_info_obj,
- device_path, image_path);
-
- /* Initialize and populate EFI object list */
- ret = efi_init_obj_list();
- if (ret)
- return ret;
-
- /*
- * gd lives in a fixed register which may get clobbered while we execute
- * the payload. So save it here and restore it on every callback entry
- */
- efi_save_gd();
-
- /* Transfer environment variable bootargs as load options */
- set_load_options(&loaded_image_info, "bootargs");
-
+ ret = bootefi_run_prepare(&image, &obj, "bootargs", device_path,
+ image_path);
if (fdt && !fdt_check_header(fdt)) {
/* Prepare fdt for payload */
fdt = copy_fdt(fdt);
@@ -246,7 +258,7 @@ static efi_status_t do_bootefi_exec(void *efi, void *fdt,
}
/* Load the EFI payload */
- entry = efi_load_pe(efi, &loaded_image_info);
+ entry = efi_load_pe(efi, &image);
if (!entry) {
ret = -ENOENT;
goto exit;
@@ -254,10 +266,10 @@ static efi_status_t do_bootefi_exec(void *efi, void *fdt,
if (memdp) {
struct efi_device_path_memory *mdp = (void *)memdp;
- mdp->memory_type = loaded_image_info.image_code_type;
- mdp->start_address = (uintptr_t)loaded_image_info.image_base;
+ mdp->memory_type = image.image_code_type;
+ mdp->start_address = (uintptr_t)image.image_base;
mdp->end_address = mdp->start_address +
- loaded_image_info.image_size;
+ image.image_size;
}
/* we don't support much: */
@@ -267,8 +279,8 @@ static efi_status_t do_bootefi_exec(void *efi, void *fdt,
/* Call our payload! */
debug("%s:%d Jumping to 0x%lx\n", __func__, __LINE__, (long)entry);
- if (setjmp(&loaded_image_info.exit_jmp)) {
- ret = loaded_image_info.exit_status;
+ if (setjmp(&image.exit_jmp)) {
+ ret = image.exit_status;
goto exit;
}
@@ -280,7 +292,7 @@ static efi_status_t do_bootefi_exec(void *efi, void *fdt,
/* Move into EL2 and keep running there */
armv8_switch_to_el2((ulong)entry,
- (ulong)&loaded_image_info_obj.handle,
+ (ulong)&obj.handle,
(ulong)&systab, 0, (ulong)efi_run_in_el2,
ES_TO_AARCH64);
@@ -289,11 +301,11 @@ static efi_status_t do_bootefi_exec(void *efi, void *fdt,
}
#endif
- ret = efi_do_enter(loaded_image_info_obj.handle, &systab, entry);
+ ret = efi_do_enter(obj.handle, &systab, entry);
exit:
/* image has returned, loaded-image obj goes *poof*: */
- list_del(&loaded_image_info_obj.link);
+ list_del(&obj.link);
return ret;
}
@@ -315,29 +327,14 @@ static efi_status_t bootefi_test_prepare(struct efi_loaded_image *image,
struct efi_object *obj,
const char *path, ulong test_func)
{
- efi_status_t ret;
-
memset(image, '\0', sizeof(*image));
memset(obj, '\0', sizeof(*obj));
/* Construct a dummy device path */
bootefi_device_path = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE,
test_func, test_func);
bootefi_image_path = efi_dp_from_file(NULL, 0, path);
- efi_setup_loaded_image(image, obj, bootefi_device_path,
- bootefi_image_path);
- /*
- * gd lives in a fixed register which may get clobbered while we execute
- * the payload. So save it here and restore it on every callback entry
- */
- efi_save_gd();
- /* Initialize and populate our EFI object list */
- ret = efi_init_obj_list();
- if (ret)
- return ret;
- /* Transfer environment variable efi_selftest as load options */
- set_load_options(image, "efi_selftest");
-
- return 0;
+ return bootefi_run_prepare(image, obj, path, bootefi_device_path,
+ bootefi_image_path);
}
/**
@@ -360,15 +357,6 @@ static int do_bootefi_bootmgr_exec(unsigned long fdt_addr)
void *addr;
efi_status_t r;
- /* Initialize and populate EFI object list */
- efi_init_obj_list();
-
- /*
- * gd lives in a fixed register which may get clobbered while we execute
- * the payload. So save it here and restore it on every callback entry
- */
- efi_save_gd();
-
addr = efi_bootmgr_load(&device_path, &file_path);
if (!addr)
return 1;
--
2.16.1.291.g4437f3f132-goog
More information about the U-Boot
mailing list