summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2024-03-04 20:00:35 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2024-03-05 16:28:06 +0100
commit910bca1d6bc73338992788cdc40aef3cac9d8150 (patch)
tree1ea358447641c16a9806e2335ef3674ec08e87fc
parent19395849543714e4820c0c0dff30e34285aef275 (diff)
downloadbarebox-910bca1d6bc7.tar.gz
barebox-910bca1d6bc7.tar.xz
commands: efi_handle_dump: prepare for supporting EFI loader
For debugging, it can be useful to dump handles from within the loader without having to boot barebox as EFI payload first. Prepare for this by removing implicit dependency on being an EFI payload. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-111-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--commands/efi_handle_dump.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/commands/efi_handle_dump.c b/commands/efi_handle_dump.c
index 43cdb8ac50..1f7b1caa13 100644
--- a/commands/efi_handle_dump.c
+++ b/commands/efi_handle_dump.c
@@ -8,16 +8,16 @@
#include <common.h>
#include <command.h>
#include <efi.h>
-#include <efi/efi-device.h>
#include <efi/efi-mode.h>
+#include <efi/efi-device.h>
-static void efi_devpath(efi_handle_t handle)
+static void efi_devpath(struct efi_boot_services *bs, efi_handle_t handle)
{
efi_status_t efiret;
void *devpath;
char *dev_path_str;
- efiret = BS->open_protocol(handle, &efi_device_path_protocol_guid,
+ efiret = bs->open_protocol(handle, &efi_device_path_protocol_guid,
&devpath, NULL, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
if (EFI_ERROR(efiret))
return;
@@ -29,7 +29,7 @@ static void efi_devpath(efi_handle_t handle)
}
}
-static void efi_dump(efi_handle_t *handles, unsigned long handle_count)
+static void efi_dump(struct efi_boot_services *bs, efi_handle_t *handles, unsigned long handle_count)
{
int i, j;
unsigned long num_guids;
@@ -41,12 +41,12 @@ static void efi_dump(efi_handle_t *handles, unsigned long handle_count)
for (i = 0; i < handle_count; i++) {
printf("handle-%p\n", handles[i]);
- BS->protocols_per_handle(handles[i], &guids, &num_guids);
+ bs->protocols_per_handle(handles[i], &guids, &num_guids);
printf(" Protocols:\n");
for (j = 0; j < num_guids; j++)
printf(" %d: %pUl: %s\n", j, guids[j],
efi_guid_string(guids[j]));
- efi_devpath(handles[i]);
+ efi_devpath(bs, handles[i]);
}
printf("\n");
}
@@ -70,7 +70,7 @@ static unsigned char to_digit(unsigned char c)
dest |= to_digit(*src) << __i; \
} while (0)
-static int do_efi_protocol_dump(int argc, char **argv)
+static int do_efi_protocol_dump(struct efi_boot_services *bs, int argc, char **argv)
{
unsigned long handle_count = 0;
efi_handle_t *handles = NULL;
@@ -145,9 +145,9 @@ static int do_efi_protocol_dump(int argc, char **argv)
printf("Searching for:\n");
printf(" %pUl: %s\n", &guid, efi_guid_string(&guid));
- ret = __efi_locate_handle(BS, BY_PROTOCOL, &guid, NULL, &handle_count, &handles);
+ ret = __efi_locate_handle(bs, BY_PROTOCOL, &guid, NULL, &handle_count, &handles);
if (!ret)
- efi_dump(handles, handle_count);
+ efi_dump(bs, handles, handle_count);
return 0;
}
@@ -156,14 +156,21 @@ static int do_efi_handle_dump(int argc, char *argv[])
{
unsigned long handle_count = 0;
efi_handle_t *handles = NULL;
+ struct efi_boot_services *bs;
int ret;
+ bs = efi_get_boot_services();
+ if (!bs) {
+ printf("EFI not yet initialized\n");
+ return COMMAND_ERROR;
+ }
+
if (argc > 1)
- return do_efi_protocol_dump(--argc, ++argv);
+ return do_efi_protocol_dump(bs, --argc, ++argv);
- ret = __efi_locate_handle(BS, ALL_HANDLES, NULL, NULL, &handle_count, &handles);
+ ret = __efi_locate_handle(bs, ALL_HANDLES, NULL, NULL, &handle_count, &handles);
if (!ret)
- efi_dump(handles, handle_count);
+ efi_dump(bs, handles, handle_count);
return 0;
}