[PATCH v2 10/12] efi: Split out table-listing code into a new file

Simon Glass sjg at chromium.org
Fri Mar 10 21:49:00 CET 2023


This code is used with EFI_LOADER but is also useful (with some
modifications) for the EFI app and payload. Move it into a shared
file.

Show the address of the table so it can be examined if needed. Also show
the table name as unknown if necessary. Our list of GUIDs is fairly
small.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

Changes in v2:
- Add new patch to split out table-listing code into a new file

 cmd/Makefile     |  2 +-
 cmd/efi_common.c | 26 ++++++++++++++++++++++++++
 cmd/efidebug.c   |  6 +-----
 include/efi.h    |  9 +++++++++
 4 files changed, 37 insertions(+), 6 deletions(-)
 create mode 100644 cmd/efi_common.c

diff --git a/cmd/Makefile b/cmd/Makefile
index 2d8bb4fc052..1c5c6f3c00c 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -63,7 +63,7 @@ obj-$(CONFIG_CMD_ECHO) += echo.o
 obj-$(CONFIG_ENV_IS_IN_EEPROM) += eeprom.o
 obj-$(CONFIG_CMD_EEPROM) += eeprom.o
 obj-$(CONFIG_EFI) += efi.o
-obj-$(CONFIG_CMD_EFIDEBUG) += efidebug.o
+obj-$(CONFIG_CMD_EFIDEBUG) += efidebug.o efi_common.o
 obj-$(CONFIG_CMD_EFICONFIG) += eficonfig.o
 ifdef CONFIG_CMD_EFICONFIG
 ifdef CONFIG_EFI_MM_COMM_TEE
diff --git a/cmd/efi_common.c b/cmd/efi_common.c
new file mode 100644
index 00000000000..7eedf0726a7
--- /dev/null
+++ b/cmd/efi_common.c
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Common code for EFI commands
+ *
+ * Copyright 2023 Google LLC
+ * Written by Simon Glass <sjg at chromium.org>
+ */
+
+#include <common.h>
+#include <efi.h>
+#include <efi_api.h>
+#include <uuid.h>
+
+void efi_show_tables(struct efi_system_table *systab)
+{
+	int i;
+
+	for (i = 0; i < systab->nr_tables; i++) {
+		struct efi_configuration_table *tab = &systab->tables[i];
+		char guid_str[37];
+
+		uuid_bin_to_str(tab->guid.b, guid_str, 1);
+		printf("%p  %s  %s\n", tab->table, guid_str,
+		       uuid_guid_get_str(tab->guid.b) ?: "(unknown)");
+	}
+}
diff --git a/cmd/efidebug.c b/cmd/efidebug.c
index e6959ede930..9622430c475 100644
--- a/cmd/efidebug.c
+++ b/cmd/efidebug.c
@@ -649,11 +649,7 @@ static int do_efi_show_memmap(struct cmd_tbl *cmdtp, int flag,
 static int do_efi_show_tables(struct cmd_tbl *cmdtp, int flag,
 			      int argc, char *const argv[])
 {
-	efi_uintn_t i;
-
-	for (i = 0; i < systab.nr_tables; ++i)
-		printf("%pUl (%pUs)\n",
-		       &systab.tables[i].guid, &systab.tables[i].guid);
+	efi_show_tables(&systab);
 
 	return CMD_RET_SUCCESS;
 }
diff --git a/include/efi.h b/include/efi.h
index c3087d3da28..342dd52fed9 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -637,4 +637,13 @@ int efi_call_exit_boot_services(void);
 int efi_get_mmap(struct efi_mem_desc **descp, int *sizep, uint *keyp,
 		 int *desc_sizep, uint *versionp);
 
+/**
+ * efi_show_tables() - Show a list of available tables
+ *
+ * Shows the address, GUID (and name where known) for each table
+ *
+ * @systab: System table containing the list of tables
+ */
+void efi_show_tables(struct efi_system_table *systab);
+
 #endif /* _LINUX_EFI_H */
-- 
2.40.0.rc1.284.g88254d51c5-goog



More information about the U-Boot mailing list