From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v9 07/18] efi: Create a function to set up for running EFI code
Date: Wed, 8 Aug 2018 03:54:22 -0600 [thread overview]
Message-ID: <20180808095433.230882-8-sjg@chromium.org> (raw)
In-Reply-To: <20180808095433.230882-1-sjg@chromium.org>
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@chromium.org>
---
Changes in v9: None
Changes in v8: None
Changes in v7: None
Changes in v6: None
Changes in v5:
- Drop call to efi_init_obj_list() which is now done in do_bootefi()
- Introduce load_options_path to specifyc U-Boot env var for load_options_path
Changes in v4:
- Rebase to master
Changes in v3:
- Add patch to create a function to set up for running EFI code
Changes in v2: None
cmd/bootefi.c | 81 ++++++++++++++++++++++++++++-----------------------
1 file changed, 44 insertions(+), 37 deletions(-)
diff --git a/cmd/bootefi.c b/cmd/bootefi.c
index edb7f786a27..54732ba3f37 100644
--- a/cmd/bootefi.c
+++ b/cmd/bootefi.c
@@ -290,6 +290,26 @@ static efi_status_t efi_install_fdt(void *fdt)
return ret;
}
+static efi_status_t bootefi_run_prepare(struct efi_loaded_image *image,
+ struct efi_object *obj,
+ const char *load_options_path,
+ struct efi_device_path *device_path,
+ struct efi_device_path *image_path)
+{
+ efi_setup_loaded_image(image, obj, device_path, 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();
+
+ /* Transfer environment variable as load options */
+ set_load_options(image, load_options_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.
@@ -298,8 +318,8 @@ static efi_status_t do_bootefi_exec(void *efi,
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_object mem_obj = {};
struct efi_device_path *memdp = NULL;
efi_status_t ret;
@@ -327,19 +347,13 @@ static efi_status_t do_bootefi_exec(void *efi,
assert(device_path && image_path);
}
- efi_setup_loaded_image(&loaded_image_info, &loaded_image_info_obj,
- device_path, image_path);
+ ret = bootefi_run_prepare(&image, &obj, "bootargs", device_path,
+ image_path);
+ 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");
/* Load the EFI payload */
- entry = efi_load_pe(efi, &loaded_image_info);
+ entry = efi_load_pe(efi, &image);
if (!entry) {
ret = EFI_LOAD_ERROR;
goto exit;
@@ -347,10 +361,10 @@ static efi_status_t do_bootefi_exec(void *efi,
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: */
@@ -360,8 +374,8 @@ static efi_status_t do_bootefi_exec(void *efi,
/* 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;
}
@@ -373,7 +387,7 @@ static efi_status_t do_bootefi_exec(void *efi,
/* 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);
@@ -390,7 +404,7 @@ static efi_status_t do_bootefi_exec(void *efi,
secure_ram_addr(_do_nonsec_entry)(
efi_run_in_hyp,
(uintptr_t)entry,
- (uintptr_t)loaded_image_info_obj.handle,
+ (uintptr_t)obj.handle,
(uintptr_t)&systab);
/* Should never reach here, efi exits with longjmp */
@@ -398,11 +412,11 @@ static efi_status_t do_bootefi_exec(void *efi,
}
#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);
if (mem_obj.handle)
list_del(&mem_obj.link);
@@ -422,11 +436,13 @@ exit:
* @path: File path to the test being run (often just the test name with a
* backslash before it
* @test_func: Address of the test function that is being run
+ * @load_options_path: U-Boot environment variable to use as load options
* @return 0 if OK, -ve on error
*/
static efi_status_t bootefi_test_prepare(struct efi_loaded_image *image,
struct efi_object *obj,
- const char *path, ulong test_func)
+ const char *path, ulong test_func,
+ const char *load_options_path)
{
/* Zero out the structures since the caller did not */
memset(image, '\0', sizeof(*image));
@@ -437,18 +453,8 @@ static efi_status_t bootefi_test_prepare(struct efi_loaded_image *image,
(uintptr_t)test_func,
(uintptr_t)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();
-
- /* Transfer environment variable efi_selftest as load options */
- set_load_options(image, "efi_selftest");
-
- return 0;
+ return bootefi_run_prepare(image, obj, load_options_path,
+ bootefi_device_path, bootefi_image_path);
}
/**
@@ -549,7 +555,7 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
int ret;
if (bootefi_test_prepare(&image, &obj, "\\test",
- (ulong)&efi_test))
+ (ulong)&efi_test, "efi_test"))
return CMD_RET_FAILURE;
ret = efi_test(&image, &systab);
@@ -565,7 +571,8 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
#ifdef CONFIG_CMD_BOOTEFI_SELFTEST
if (!strcmp(argv[1], "selftest")) {
if (bootefi_test_prepare(&image, &obj, "\\selftest",
- (uintptr_t)&efi_selftest))
+ (uintptr_t)&efi_selftest,
+ "efi_selftest"))
return CMD_RET_FAILURE;
/* Execute the test */
--
2.18.0.597.ga71716f1ad-goog
next prev parent reply other threads:[~2018-08-08 9:54 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-08 9:54 [U-Boot] [PATCH v9 00/18] efi: Enable sandbox support for EFI loader Simon Glass
2018-08-08 9:54 ` [U-Boot] [PATCH v9 01/18] Revert "efi_loader: Rename sections to allow for implicit data" Simon Glass
2018-08-23 20:18 ` [U-Boot] [U-Boot, v9, 01/18] Partially revert " Tom Rini
2018-08-08 9:54 ` [U-Boot] [PATCH v9 02/18] efi: Don't allow CMD_BOOTEFI_SELFTEST on sandbox Simon Glass
2018-08-26 16:53 ` Alexander Graf
2018-09-14 15:46 ` Simon Glass
2018-08-08 9:54 ` [U-Boot] [PATCH v9 03/18] efi: sandbox: Add distroboot support Simon Glass
2018-08-26 16:54 ` Alexander Graf
2018-08-08 9:54 ` [U-Boot] [PATCH v9 04/18] efi: sandbox: Enable EFI loader build for sandbox Simon Glass
2018-08-26 16:55 ` Alexander Graf
2018-09-14 15:46 ` Simon Glass
2018-09-15 8:11 ` Alexander Graf
2018-09-15 8:32 ` Simon Glass
2018-08-08 9:54 ` [U-Boot] [PATCH v9 05/18] efi: Split out test init/uninit into functions Simon Glass
2018-08-08 9:54 ` [U-Boot] [PATCH v9 06/18] efi: sandbox: Add a simple 'bootefi test' command Simon Glass
2018-08-26 16:58 ` Alexander Graf
2018-09-14 15:46 ` Simon Glass
2018-08-08 9:54 ` Simon Glass [this message]
2018-08-08 9:54 ` [U-Boot] [PATCH v9 08/18] efi: Rename bootefi_test_finish() to bootefi_run_finish() Simon Glass
2018-08-08 9:54 ` [U-Boot] [PATCH v9 09/18] sandbox: Align RAM buffer to the machine page size Simon Glass
2018-08-26 17:01 ` Alexander Graf
2018-08-08 9:54 ` [U-Boot] [PATCH v9 10/18] sandbox: Try to start the RAM buffer at a particular address Simon Glass
2018-08-26 17:01 ` Alexander Graf
2018-09-14 15:46 ` Simon Glass
2018-10-15 20:07 ` Simon Glass
2018-08-08 9:54 ` [U-Boot] [PATCH v9 11/18] sandbox: Add support for calling abort() Simon Glass
2018-08-08 9:54 ` [U-Boot] [PATCH v9 12/18] sandbox: Enhance map_to_sysmem() to handle foreign pointers Simon Glass
2018-08-26 17:11 ` Alexander Graf
2018-09-14 15:46 ` Simon Glass
2018-09-15 8:16 ` Alexander Graf
2018-09-15 8:31 ` Simon Glass
2018-08-08 9:54 ` [U-Boot] [PATCH v9 13/18] efi: Add a call to exit() along with why we can't use it Simon Glass
2018-08-23 20:37 ` Heinrich Schuchardt
2018-08-26 17:13 ` Alexander Graf
2018-09-14 15:46 ` Simon Glass
2018-08-08 9:54 ` [U-Boot] [PATCH v9 14/18] efi: Relocate FDT to 127MB instead of 128MB Simon Glass
2018-08-26 17:23 ` [U-Boot] [U-Boot, v9, " Alexander Graf
2018-08-08 9:54 ` [U-Boot] [PATCH v9 15/18] efi: sandbox: Tidy up copy_fdt() to work with sandbox Simon Glass
2018-08-26 17:23 ` [U-Boot] [U-Boot, v9, " Alexander Graf
2018-08-08 9:54 ` [U-Boot] [PATCH v9 16/18] efi: Add more debugging for memory allocations Simon Glass
2018-08-23 20:49 ` Heinrich Schuchardt
2018-08-26 18:27 ` Simon Glass
2018-08-26 17:22 ` Alexander Graf
2018-08-08 9:54 ` [U-Boot] [PATCH v9 17/18] efi_loader: Pass address to fs_read() Simon Glass
2018-08-26 17:23 ` [U-Boot] [U-Boot, v9, " Alexander Graf
2018-08-08 9:54 ` [U-Boot] [PATCH v9 18/18] efi: sandbox: Enable selftest command Simon Glass
2018-08-26 17:28 ` [U-Boot] [PATCH v9 00/18] efi: Enable sandbox support for EFI loader Alexander Graf
2018-09-14 15:46 ` Simon Glass
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180808095433.230882-8-sjg@chromium.org \
--to=sjg@chromium.org \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox