From f4d52c41595b8af1813413020773b5d59f226622 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sat, 15 Oct 2022 13:21:01 +0200 Subject: cmd: simplify efidebug * don't use EFI_CALL() for variable services * don't use runtime pointer to access exported function Signed-off-by: Heinrich Schuchardt --- cmd/efidebug.c | 47 +++++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 26 deletions(-) (limited to 'cmd') diff --git a/cmd/efidebug.c b/cmd/efidebug.c index 4b49f30d937..ef239bb34b4 100644 --- a/cmd/efidebug.c +++ b/cmd/efidebug.c @@ -25,7 +25,6 @@ #include #define BS systab.boottime -#define RT systab.runtime #ifdef CONFIG_EFI_HAVE_CAPSULE_SUPPORT /** @@ -76,7 +75,7 @@ static int do_efi_capsule_update(struct cmd_tbl *cmdtp, int flag, capsule->capsule_image_size); } - ret = EFI_CALL(RT->update_capsule(&capsule, 1, 0)); + ret = EFI_CALL(efi_update_capsule(&capsule, 1, 0)); if (ret) { printf("Cannot handle a capsule at %p\n", capsule); return CMD_RET_FAILURE; @@ -995,17 +994,16 @@ static void show_efi_boot_opt(u16 *varname16) efi_status_t ret; size = 0; - ret = EFI_CALL(efi_get_variable(varname16, &efi_global_variable_guid, - NULL, &size, NULL)); + ret = efi_get_variable_int(varname16, &efi_global_variable_guid, + NULL, &size, NULL, NULL); if (ret == EFI_BUFFER_TOO_SMALL) { data = malloc(size); if (!data) { printf("ERROR: Out of memory\n"); return; } - ret = EFI_CALL(efi_get_variable(varname16, - &efi_global_variable_guid, - NULL, &size, data)); + ret = efi_get_variable_int(varname16, &efi_global_variable_guid, + NULL, &size, data, NULL); if (ret == EFI_SUCCESS) show_efi_boot_opt_data(varname16, data, &size); free(data); @@ -1057,8 +1055,7 @@ static int do_efi_boot_dump(struct cmd_tbl *cmdtp, int flag, var_name16[0] = 0; for (;;) { size = buf_size; - ret = EFI_CALL(efi_get_next_variable_name(&size, var_name16, - &guid)); + ret = efi_get_next_variable_name_int(&size, var_name16, &guid); if (ret == EFI_NOT_FOUND) break; if (ret == EFI_BUFFER_TOO_SMALL) { @@ -1069,9 +1066,8 @@ static int do_efi_boot_dump(struct cmd_tbl *cmdtp, int flag, return CMD_RET_FAILURE; } var_name16 = p; - ret = EFI_CALL(efi_get_next_variable_name(&size, - var_name16, - &guid)); + ret = efi_get_next_variable_name_int(&size, var_name16, + &guid); } if (ret != EFI_SUCCESS) { free(var_name16); @@ -1114,8 +1110,8 @@ static int show_efi_boot_order(void) efi_status_t ret; size = 0; - ret = EFI_CALL(efi_get_variable(u"BootOrder", &efi_global_variable_guid, - NULL, &size, NULL)); + ret = efi_get_variable_int(u"BootOrder", &efi_global_variable_guid, + NULL, &size, NULL, NULL); if (ret != EFI_BUFFER_TOO_SMALL) { if (ret == EFI_NOT_FOUND) { printf("BootOrder not defined\n"); @@ -1129,8 +1125,8 @@ static int show_efi_boot_order(void) printf("ERROR: Out of memory\n"); return CMD_RET_FAILURE; } - ret = EFI_CALL(efi_get_variable(u"BootOrder", &efi_global_variable_guid, - NULL, &size, bootorder)); + ret = efi_get_variable_int(u"BootOrder", &efi_global_variable_guid, + NULL, &size, bootorder, NULL); if (ret != EFI_SUCCESS) { ret = CMD_RET_FAILURE; goto out; @@ -1142,9 +1138,9 @@ static int show_efi_boot_order(void) "Boot", bootorder[i]); size = 0; - ret = EFI_CALL(efi_get_variable(var_name16, - &efi_global_variable_guid, NULL, - &size, NULL)); + ret = efi_get_variable_int(var_name16, + &efi_global_variable_guid, NULL, + &size, NULL, NULL); if (ret != EFI_BUFFER_TOO_SMALL) { printf("%2d: %ls: (not defined)\n", i + 1, var_name16); continue; @@ -1155,9 +1151,9 @@ static int show_efi_boot_order(void) ret = CMD_RET_FAILURE; goto out; } - ret = EFI_CALL(efi_get_variable(var_name16, - &efi_global_variable_guid, NULL, - &size, data)); + ret = efi_get_variable_int(var_name16, + &efi_global_variable_guid, NULL, + &size, data, NULL); if (ret != EFI_SUCCESS) { free(data); ret = CMD_RET_FAILURE; @@ -1444,10 +1440,9 @@ static int do_efi_query_info(struct cmd_tbl *cmdtp, int flag, EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS; } - ret = EFI_CALL(efi_query_variable_info(attr, - &max_variable_storage_size, - &remain_variable_storage_size, - &max_variable_size)); + ret = efi_query_variable_info_int(attr, &max_variable_storage_size, + &remain_variable_storage_size, + &max_variable_size); if (ret != EFI_SUCCESS) { printf("Error: Cannot query UEFI variables, r = %lu\n", ret & ~EFI_ERROR_MASK); -- cgit v1.3.1 From 70089c13a73f58315547982573be2016e7a70958 Mon Sep 17 00:00:00 2001 From: Ilias Apalodimas Date: Sun, 16 Oct 2022 11:36:32 +0300 Subject: efi_loader: remove efi_delete_handle on loadfile2 Loadfile2 code is installing two protocols on it's own handle and uses efi_delete_handle() to clean it up on failure(s). However commit 05c4c9e21ae6 ("efi_loader: define internal implementations of install/uninstallmultiple") prepares the ground for us to clean up efi_delete_handle() used in favor of Install/UninstallMultipleProtocol. While at it clean up the non needed void casts to (void *) on the protolcol installation. Signed-off-by: Ilias Apalodimas Reviewed-by: Heinrich Schuchardt --- cmd/bootefi.c | 6 ++++-- include/efi_loader.h | 2 +- lib/efi_loader/efi_load_initrd.c | 19 +++++++++++++++---- 3 files changed, 20 insertions(+), 7 deletions(-) (limited to 'cmd') diff --git a/cmd/bootefi.c b/cmd/bootefi.c index b93c0d3d4c0..2a7d42925d6 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -394,8 +394,10 @@ static efi_status_t do_bootefi_exec(efi_handle_t handle, void *load_options) out: free(load_options); - if (IS_ENABLED(CONFIG_EFI_LOAD_FILE2_INITRD)) - efi_initrd_deregister(); + if (IS_ENABLED(CONFIG_EFI_LOAD_FILE2_INITRD)) { + if (efi_initrd_deregister() != EFI_SUCCESS) + log_err("Failed to remove loadfile2 for initrd\n"); + } /* Control is returned to U-Boot, disable EFI watchdog */ efi_set_watchdog(0); diff --git a/include/efi_loader.h b/include/efi_loader.h index 1bac3f49a3e..0c6c95ba464 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -570,7 +570,7 @@ efi_status_t efi_net_register(void); /* Called by bootefi to make the watchdog available */ efi_status_t efi_watchdog_register(void); efi_status_t efi_initrd_register(void); -void efi_initrd_deregister(void); +efi_status_t efi_initrd_deregister(void); /* Called by bootefi to make SMBIOS tables available */ /** * efi_acpi_register() - write out ACPI tables diff --git a/lib/efi_loader/efi_load_initrd.c b/lib/efi_loader/efi_load_initrd.c index 87fde3f88c2..193433782c2 100644 --- a/lib/efi_loader/efi_load_initrd.c +++ b/lib/efi_loader/efi_load_initrd.c @@ -213,7 +213,7 @@ efi_status_t efi_initrd_register(void) &efi_guid_device_path, &dp_lf2_handle, /* LOAD_FILE2 */ &efi_guid_load_file2_protocol, - (void *)&efi_lf2_protocol, + &efi_lf2_protocol, NULL); return ret; @@ -227,11 +227,22 @@ efi_status_t efi_initrd_register(void) * * Return: status code */ -void efi_initrd_deregister(void) +efi_status_t efi_initrd_deregister(void) { + efi_status_t ret; + if (!efi_initrd_handle) - return; + return EFI_SUCCESS; - efi_delete_handle(efi_initrd_handle); + ret = efi_uninstall_multiple_protocol_interfaces(efi_initrd_handle, + /* initramfs */ + &efi_guid_device_path, + &dp_lf2_handle, + /* LOAD_FILE2 */ + &efi_guid_load_file2_protocol, + &efi_lf2_protocol, + NULL); efi_initrd_handle = NULL; + + return ret; } -- cgit v1.3.1