summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorYing-Chun Liu (PaulLiu) <[email protected]>2025-07-03 07:28:07 +0100
committerIlias Apalodimas <[email protected]>2025-07-03 12:25:47 +0300
commitaaf7be96c2c14aa190d39e50fa3606389eafda8e (patch)
tree5fdd5ee971be982aabad64e39b12d3de0d069dd4 /lib
parent46a564d689b61660919f11be332d47a206ed24d5 (diff)
efi: add EFI_SYSTEM_TABLE_POINTER for debug
Add EFI_SYSTEM_TABLE_POINTER structure for remote debugger to locate the address of EFI_SYSTEM_TABLE. This feature is described in UEFI SPEC version 2.10. Section 18.4.2. The implementation ensures support for hardware-assisted debugging and provides a standardized mechanism for debuggers to discover the EFI system table. Cc: Peter Robinson <[email protected]> Cc: Simon Glass <[email protected]> Signed-off-by: Ying-Chun Liu (PaulLiu) <[email protected]> Reviewed-by: Ilias Apalodimas <[email protected]> Tested-by: Heinrich Schuchardt <[email protected]> Reviewed-by: Heinrich Schuchardt <[email protected]> # change memset(systab_pointer, 0 ...) -> systab_pointer->crc32 = 0; Signed-off-by: Ilias Apalodimas <[email protected]>
Diffstat (limited to 'lib')
-rw-r--r--lib/efi_loader/Kconfig9
-rw-r--r--lib/efi_loader/Makefile1
-rw-r--r--lib/efi_loader/efi_debug_support.c40
-rw-r--r--lib/efi_loader/efi_setup.c7
4 files changed, 57 insertions, 0 deletions
diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index 3dadbc54b58..077466f01f0 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -71,6 +71,15 @@ config EFI_SECURE_BOOT
config EFI_SIGNATURE_SUPPORT
bool
+config EFI_DEBUG_SUPPORT
+ bool "EFI Debug Support"
+ default y if !HAS_BOARD_SIZE_LIMIT
+ help
+ Select this option if you want to setup the EFI Debug Support
+ Table and the EFI_SYSTEM_TABLE_POINTER which is used by the debug
+ agent or an external debugger to determine loaded image information
+ in a quiescent manner.
+
menu "UEFI services"
config EFI_GET_TIME
diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile
index cf050e5385d..51ccf1cd87e 100644
--- a/lib/efi_loader/Makefile
+++ b/lib/efi_loader/Makefile
@@ -70,6 +70,7 @@ obj-$(CONFIG_EFI_RISCV_BOOT_PROTOCOL) += efi_riscv.o
obj-$(CONFIG_EFI_LOAD_FILE2_INITRD) += efi_load_initrd.o
obj-$(CONFIG_EFI_SIGNATURE_SUPPORT) += efi_signature.o
obj-$(CONFIG_EFI_ECPT) += efi_conformance.o
+obj-$(CONFIG_EFI_DEBUG_SUPPORT) += efi_debug_support.o
EFI_VAR_SEED_FILE := $(subst $\",,$(CONFIG_EFI_VAR_SEED_FILE))
$(obj)/efi_var_seed.o: $(srctree)/$(EFI_VAR_SEED_FILE)
diff --git a/lib/efi_loader/efi_debug_support.c b/lib/efi_loader/efi_debug_support.c
new file mode 100644
index 00000000000..649d21ef829
--- /dev/null
+++ b/lib/efi_loader/efi_debug_support.c
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * EFI debug support
+ *
+ * Copyright (c) 2025 Ying-Chun Liu, Linaro Ltd. <[email protected]>
+ */
+
+#include <efi_loader.h>
+#include <linux/sizes.h>
+#include <u-boot/crc.h>
+
+struct efi_system_table_pointer __efi_runtime_data * systab_pointer = NULL;
+
+/**
+ * efi_initialize_system_table_pointer() - Initialize system table pointer
+ *
+ * Return: status code
+ */
+efi_status_t efi_initialize_system_table_pointer(void)
+{
+ /* Allocate efi_system_table_pointer structure with 4MB alignment. */
+ systab_pointer = efi_alloc_aligned_pages(sizeof(struct efi_system_table_pointer),
+ EFI_RUNTIME_SERVICES_DATA,
+ SZ_4M);
+
+ if (!systab_pointer) {
+ log_err("Installing EFI system table pointer failed\n");
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ systab_pointer->crc32 = 0;
+
+ systab_pointer->signature = EFI_SYSTEM_TABLE_SIGNATURE;
+ systab_pointer->efi_system_table_base = (uintptr_t)&systab;
+ systab_pointer->crc32 = crc32(0,
+ (const unsigned char *)systab_pointer,
+ sizeof(struct efi_system_table_pointer));
+
+ return EFI_SUCCESS;
+}
diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c
index 48f91da5df7..78c5059256a 100644
--- a/lib/efi_loader/efi_setup.c
+++ b/lib/efi_loader/efi_setup.c
@@ -278,6 +278,13 @@ efi_status_t efi_init_obj_list(void)
if (ret != EFI_SUCCESS)
goto out;
+ /* Initialize system table pointer */
+ if (IS_ENABLED(CONFIG_EFI_DEBUG_SUPPORT)) {
+ ret = efi_initialize_system_table_pointer();
+ if (ret != EFI_SUCCESS)
+ goto out;
+ }
+
if (IS_ENABLED(CONFIG_EFI_ECPT)) {
ret = efi_ecpt_register();
if (ret != EFI_SUCCESS)