cmd: bootefi: re-organize do_bootefi()

Replicate some code and re-organize do_bootefi() into three cases, which
will be carved out as independent functions in the next two commits.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
This commit is contained in:
AKASHI Takahiro 2023-11-21 10:29:40 +09:00 committed by Heinrich Schuchardt
parent 05e2cade01
commit 296faf4f7e
3 changed files with 69 additions and 31 deletions

View File

@ -362,9 +362,19 @@ config CMD_BOOTEFI
help help
Boot an EFI image from memory. Boot an EFI image from memory.
if CMD_BOOTEFI
config CMD_BOOTEFI_BINARY
bool "Allow booting an EFI binary directly"
depends on BOOTEFI_BOOTMGR
default y
help
Select this option to enable direct execution of binary at 'bootefi'.
This subcommand will allow you to load the UEFI binary using
other U-Boot commands or external methods and then run it.
config CMD_BOOTEFI_BOOTMGR config CMD_BOOTEFI_BOOTMGR
bool "UEFI Boot Manager command" bool "UEFI Boot Manager command"
depends on BOOTEFI_BOOTMGR && CMD_BOOTEFI depends on BOOTEFI_BOOTMGR
default y default y
help help
Select this option to enable the 'bootmgr' subcommand of 'bootefi'. Select this option to enable the 'bootmgr' subcommand of 'bootefi'.
@ -373,7 +383,6 @@ config CMD_BOOTEFI_BOOTMGR
config CMD_BOOTEFI_HELLO_COMPILE config CMD_BOOTEFI_HELLO_COMPILE
bool "Compile a standard EFI hello world binary for testing" bool "Compile a standard EFI hello world binary for testing"
depends on CMD_BOOTEFI && !CPU_V7M
default y default y
help help
This compiles a standard EFI hello world application with U-Boot so This compiles a standard EFI hello world application with U-Boot so
@ -395,6 +404,7 @@ config CMD_BOOTEFI_HELLO
up EFI support on a new architecture. up EFI support on a new architecture.
source lib/efi_selftest/Kconfig source lib/efi_selftest/Kconfig
endif
config CMD_BOOTMENU config CMD_BOOTMENU
bool "bootmenu" bool "bootmenu"

View File

@ -503,7 +503,6 @@ out:
return (ret != EFI_SUCCESS) ? ret : ret2; return (ret != EFI_SUCCESS) ? ret : ret2;
} }
#ifdef CONFIG_CMD_BOOTEFI_SELFTEST
static efi_status_t bootefi_run_prepare(const char *load_options_path, static efi_status_t bootefi_run_prepare(const char *load_options_path,
struct efi_device_path *device_path, struct efi_device_path *device_path,
struct efi_device_path *image_path, struct efi_device_path *image_path,
@ -593,7 +592,6 @@ static int do_efi_selftest(void)
return ret != EFI_SUCCESS; return ret != EFI_SUCCESS;
} }
#endif /* CONFIG_CMD_BOOTEFI_SELFTEST */
/** /**
* do_bootefi() - execute `bootefi` command * do_bootefi() - execute `bootefi` command
@ -615,14 +613,6 @@ static int do_bootefi(struct cmd_tbl *cmdtp, int flag, int argc,
if (argc < 2) if (argc < 2)
return CMD_RET_USAGE; return CMD_RET_USAGE;
/* 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 CMD_RET_FAILURE;
}
if (argc > 2) { if (argc > 2) {
uintptr_t fdt_addr; uintptr_t fdt_addr;
@ -631,29 +621,54 @@ static int do_bootefi(struct cmd_tbl *cmdtp, int flag, int argc,
} else { } else {
fdt = EFI_FDT_USE_INTERNAL; fdt = EFI_FDT_USE_INTERNAL;
} }
ret = efi_install_fdt(fdt);
if (ret == EFI_INVALID_PARAMETER)
return CMD_RET_USAGE;
else if (ret != EFI_SUCCESS)
return CMD_RET_FAILURE;
if (IS_ENABLED(CONFIG_CMD_BOOTEFI_BOOTMGR)) { if (IS_ENABLED(CONFIG_CMD_BOOTEFI_BOOTMGR) &&
if (!strcmp(argv[1], "bootmgr")) !strcmp(argv[1], "bootmgr")) {
return do_efibootmgr(); /* 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 CMD_RET_FAILURE;
}
ret = efi_install_fdt(fdt);
if (ret == EFI_INVALID_PARAMETER)
return CMD_RET_USAGE;
else if (ret != EFI_SUCCESS)
return CMD_RET_FAILURE;
return do_efibootmgr();
} }
#ifdef CONFIG_CMD_BOOTEFI_SELFTEST
if (!strcmp(argv[1], "selftest"))
return do_efi_selftest();
#endif
#ifdef CONFIG_CMD_BOOTEFI_HELLO if (IS_ENABLED(CONFIG_CMD_BOOTEFI_SELFTEST) &&
if (!strcmp(argv[1], "hello")) { !strcmp(argv[1], "selftest")) {
/* 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 CMD_RET_FAILURE;
}
ret = efi_install_fdt(fdt);
if (ret == EFI_INVALID_PARAMETER)
return CMD_RET_USAGE;
else if (ret != EFI_SUCCESS)
return CMD_RET_FAILURE;
return do_efi_selftest();
}
if (!IS_ENABLED(CONFIG_CMD_BOOTEFI_BINARY))
return CMD_RET_SUCCESS;
if (IS_ENABLED(CONFIG_CMD_BOOTEFI_HELLO) &&
!strcmp(argv[1], "hello")) {
image_buf = __efi_helloworld_begin; image_buf = __efi_helloworld_begin;
size = __efi_helloworld_end - __efi_helloworld_begin; size = __efi_helloworld_end - __efi_helloworld_begin;
efi_clear_bootdev(); efi_clear_bootdev();
} else } else {
#endif
{
addr = strtoul(argv[1], NULL, 16); addr = strtoul(argv[1], NULL, 16);
/* Check that a numeric value was passed */ /* Check that a numeric value was passed */
if (!addr) if (!addr)
@ -675,6 +690,21 @@ static int do_bootefi(struct cmd_tbl *cmdtp, int flag, int argc,
size = image_size; size = image_size;
} }
} }
/* 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 CMD_RET_FAILURE;
}
ret = efi_install_fdt(fdt);
if (ret == EFI_INVALID_PARAMETER)
return CMD_RET_USAGE;
else if (ret != EFI_SUCCESS)
return CMD_RET_FAILURE;
ret = efi_run_image(image_buf, size); ret = efi_run_image(image_buf, size);
if (ret != EFI_SUCCESS) if (ret != EFI_SUCCESS)

View File

@ -879,14 +879,12 @@ efi_status_t __efi_runtime EFIAPI efi_get_time(
efi_status_t __efi_runtime EFIAPI efi_set_time(struct efi_time *time); efi_status_t __efi_runtime EFIAPI efi_set_time(struct efi_time *time);
#ifdef CONFIG_CMD_BOOTEFI_SELFTEST
/* /*
* Entry point for the tests of the EFI API. * Entry point for the tests of the EFI API.
* It is called by 'bootefi selftest' * It is called by 'bootefi selftest'
*/ */
efi_status_t EFIAPI efi_selftest(efi_handle_t image_handle, efi_status_t EFIAPI efi_selftest(efi_handle_t image_handle,
struct efi_system_table *systab); struct efi_system_table *systab);
#endif
efi_status_t EFIAPI efi_get_variable(u16 *variable_name, efi_status_t EFIAPI efi_get_variable(u16 *variable_name,
const efi_guid_t *vendor, u32 *attributes, const efi_guid_t *vendor, u32 *attributes,