Skip to contentSkip to conversation

Add EFI Debug Support Table feature

PATCH Superseded Ying-Chun Liu (PaulLiu) 2 participants 12 messages Jul 1, 2025

v7 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v7 cover Add EFI Debug Support Table feature

From: "Ying-Chun Liu (PaulLiu)" <[email protected]>

I implemented the UEFI Specification version 2.10, specifically focusing on the functionality described in Section 18.4, which details the EFI Debug Support Table feature. This implementation ensures support for hardware-assisted debugging and provides a standardized mechanism for debuggers to discover and interact with system-level debug resources.

V2: add Kconfig options to turn on/off this feature.
V3: Fix the way of removing debug_image_info.
V4: Fix efi_realloc return failure code and efi_alloc_aligned_pages() for
system_table_pointer.
V5: Fix function comments and move the code into a separate module.
V6: Fix error handling. Refine the code.
V7: Add unittest

Ying-Chun Liu (PaulLiu) (6):
efi: add EFI_SYSTEM_TABLE_POINTER for debug
efi: add EFI_DEBUG_IMAGE_INFO_TABLE for debug
lib: efi_loader: efi_memory.c: add efi_realloc() for realloc memory
efi: add EFI_DEBUG_IMAGE_INFO for debug
efi: selftest: add selftest for EFI_DEBUG_SUPPORT
configs: sandbox_defconfig: enable CONFIG_EFI_DEBUG_SUPPORT

 configs/sandbox_defconfig                     |   1 +
 include/efi_api.h                             |  71 +++++++
 include/efi_loader.h                          |  19 ++
 lib/efi_loader/Kconfig                        |   8 +
 lib/efi_loader/Makefile                       |   1 +
 lib/efi_loader/efi_boottime.c                 |   7 +
 lib/efi_loader/efi_debug_support.c            | 183 ++++++++++++++++++
 lib/efi_loader/efi_memory.c                   |  58 ++++++
 lib/efi_loader/efi_setup.c                    |  18 ++
 lib/efi_selftest/Makefile                     |   2 +
 lib/efi_selftest/efi_selftest_debug_support.c |  58 ++++++
 11 files changed, 426 insertions(+)
 create mode 100644 lib/efi_loader/efi_debug_support.c
 create mode 100644 lib/efi_selftest/efi_selftest_debug_support.c
Signature · 1 line
2.39.5
#1 lore raw

PATCH v7 1/6 efi: add EFI_SYSTEM_TABLE_POINTER for debug

From: "Ying-Chun Liu (PaulLiu)" <[email protected]>

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.

---
V2: add Kconfig options to turn on/off this feature.
V3: make efi_initialize_system_table_pointer() do the job as described.
V4: use efi_alloc_aligned_pages() for system_table_pointer.
V5: move the code into a separate module.
V6: Use macros to replace size_4MB
V7: Fix the code based on the review. Update license field.

---
 include/efi_api.h                  | 16 ++++++++++++
 include/efi_loader.h               |  2 ++
 lib/efi_loader/Kconfig             |  8 ++++++
 lib/efi_loader/Makefile            |  1 +
 lib/efi_loader/efi_debug_support.c | 40 ++++++++++++++++++++++++++++++
 lib/efi_loader/efi_setup.c         |  7 ++++++
 6 files changed, 74 insertions(+)
 create mode 100644 lib/efi_loader/efi_debug_support.c
include/efi_api.h +16 -0
index eb61eafa028..6c4c1a0cc7b 100644
@@ -259,6 +259,22 @@ struct efi_capsule_result_variable_header {
 	efi_status_t capsule_status;
 } __packed;
 
+/**
+ * struct efi_system_table_pointer - struct to store the pointer of system
+ * table.
+ * @signature: The signature of this struct.
+ * @efi_system_table_base: The physical address of System Table.
+ * @crc32: CRC32 checksum
+ *
+ * This struct is design for hardware debugger to search through memory to
+ * get the address of EFI System Table.
+ */
+struct efi_system_table_pointer {
+	u64 signature;
+	efi_physical_addr_t efi_system_table_base;
+	u32 crc32;
+};
+
 struct efi_memory_range {
 	efi_physical_addr_t	address;
 	u64			length;
include/efi_loader.h +2 -0
index 8f9f2bcf1cb..8f065244d8e 100644
@@ -646,6 +646,8 @@ efi_status_t efi_tcg2_measure_dtb(void *dtb);
 efi_status_t efi_root_node_register(void);
 /* Called by bootefi to initialize runtime */
 efi_status_t efi_initialize_system_table(void);
+/* Called by bootefi to initialize debug */
+efi_status_t efi_initialize_system_table_pointer(void);
 /* efi_runtime_detach() - detach unimplemented runtime functions */
 void efi_runtime_detach(void);
 /* efi_convert_pointer() - convert pointer to virtual address */
lib/efi_loader/Kconfig +8 -0
index 7f02a83e2a2..f9d75cbc3fd 100644
@@ -71,6 +71,14 @@ config EFI_SECURE_BOOT
 config EFI_SIGNATURE_SUPPORT
 	bool
 
+config EFI_DEBUG_SUPPORT
+	bool "EFI Debug Support"
+	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
lib/efi_loader/Makefile +1 -0
index cf050e5385d..51ccf1cd87e 100644
@@ -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)
lib/efi_loader/efi_debug_support.c new file +40 -0
new file mode 100644
index 00000000000..c9773feaa5b
@@ -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;
+	}
+
+	memset(systab_pointer, 0, sizeof(struct efi_system_table_pointer));
+
+	systab_pointer->signature = EFI_SYSTEM_TABLE_SIGNATURE;
+	systab_pointer->efi_system_table_base = (efi_physical_addr_t)&systab;
+	systab_pointer->crc32 = crc32(0,
+				      (const unsigned char *)systab_pointer,
+				      sizeof(struct efi_system_table_pointer));
+
+	return EFI_SUCCESS;
+}
lib/efi_loader/efi_setup.c +7 -0
index 48f91da5df7..78c5059256a 100644
@@ -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)
Signature · 1 line
2.39.5
Tested-by on v7 1/6
#2 lore raw

Re: [PATCH v7 1/6] efi: add EFI_SYSTEM_TABLE_POINTER for debug

Quoted 157 lines · Ying-Chun Liu (PaulLiu)

From: "Ying-Chun Liu (PaulLiu)" <[email protected]>

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.

---
V2: add Kconfig options to turn on/off this feature.
V3: make efi_initialize_system_table_pointer() do the job as described.
V4: use efi_alloc_aligned_pages() for system_table_pointer.
V5: move the code into a separate module.
V6: Use macros to replace size_4MB
V7: Fix the code based on the review. Update license field.

---
  include/efi_api.h                  | 16 ++++++++++++
  include/efi_loader.h               |  2 ++
  lib/efi_loader/Kconfig             |  8 ++++++
  lib/efi_loader/Makefile            |  1 +
  lib/efi_loader/efi_debug_support.c | 40 ++++++++++++++++++++++++++++++
  lib/efi_loader/efi_setup.c         |  7 ++++++
  6 files changed, 74 insertions(+)

create mode 100644 lib/efi_loader/efi_debug_support.c

include/efi_api.h +16 -0
index eb61eafa028..6c4c1a0cc7b 100644
@@ -259,6 +259,22 @@ struct efi_capsule_result_variable_header {
  	efi_status_t capsule_status;
  } __packed;
 
+/**
+ * struct efi_system_table_pointer - struct to store the pointer of system
+ * table.
+ * @signature: The signature of this struct.
+ * @efi_system_table_base: The physical address of System Table.
+ * @crc32: CRC32 checksum
+ *
+ * This struct is design for hardware debugger to search through memory to
+ * get the address of EFI System Table.
+ */
+struct efi_system_table_pointer {
+	u64 signature;
+	efi_physical_addr_t efi_system_table_base;
+	u32 crc32;
+};
+
  struct efi_memory_range {
  	efi_physical_addr_t	address;
  	u64			length;
include/efi_loader.h +2 -0
index 8f9f2bcf1cb..8f065244d8e 100644
@@ -646,6 +646,8 @@ efi_status_t efi_tcg2_measure_dtb(void *dtb);
  efi_status_t efi_root_node_register(void);
  /* Called by bootefi to initialize runtime */
  efi_status_t efi_initialize_system_table(void);
+/* Called by bootefi to initialize debug */
+efi_status_t efi_initialize_system_table_pointer(void);
  /* efi_runtime_detach() - detach unimplemented runtime functions */
  void efi_runtime_detach(void);
  /* efi_convert_pointer() - convert pointer to virtual address */
lib/efi_loader/Kconfig +8 -0
index 7f02a83e2a2..f9d75cbc3fd 100644
@@ -71,6 +71,14 @@ config EFI_SECURE_BOOT
  config EFI_SIGNATURE_SUPPORT
  	bool
 
+config EFI_DEBUG_SUPPORT
+	bool "EFI Debug Support"
+	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
lib/efi_loader/Makefile +1 -0
index cf050e5385d..51ccf1cd87e 100644
@@ -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)
lib/efi_loader/efi_debug_support.c new file +40 -0
new file mode 100644
index 00000000000..c9773feaa5b
@@ -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;
+	}
+
+	memset(systab_pointer, 0, sizeof(struct efi_system_table_pointer));
+
+	systab_pointer->signature = EFI_SYSTEM_TABLE_SIGNATURE;
+	systab_pointer->efi_system_table_base = (efi_physical_addr_t)&systab;
+	systab_pointer->crc32 = crc32(0,
+				      (const unsigned char *)systab_pointer,
+				      sizeof(struct efi_system_table_pointer));
+
+	return EFI_SUCCESS;
+}
lib/efi_loader/efi_setup.c +0 -0
index 48f91da5df7..78c5059256a 100644
@@ -278,6 +278,13 @@ efi_status_t efi_init_obj_list(void)
  	if (ret != EFI_SUCCESS)
  		goto out;
 

lib/efi_loader/efi_setup.c efi_status_t efi_init_obj_list(void) · line 290

Quoted 10 lines
lib/efi_loader/efi_setup.c +7 -0
+	/* 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)

In the EFI shell I found:

RT_Data 00000000BDC00000-00000000BDC00FFF 0000000000000001 8000000000000008

And in gdb:

(gdb) p/x *(char[80]*)0x00000000bdc00000
$1 = {0x49, 0x42, 0x49, 0x20, 0x53, 0x59, 0x53, 0x54, 0xd0, 0xdf, 0x6b, 0xbf, 0x0, 0x0, 0x0, 0x0, 0x1d, 0x9a, 0x19, 0x33,
0x0 <repeats 60 times>}

(gdb) p/x *(char[16]*)0xbf6bdfd0
$2 = {0x49, 0x42, 0x49, 0x20, 0x53, 0x59, 0x53, 0x54, 0x6e, 0x0, 0x2, 0x0, 0x78, 0x0, 0x0, 0x0} (gdb) p *(char[16]*)0xbf6bdfd0
$3 = "IBI SYSTn\000\002\000x\000\000"

This matches EFI_SYSTEM_TABLE_SIGNATURE 0x5453595320494249.

#3 lore raw

Re: [PATCH v7 1/6] efi: add EFI_SYSTEM_TABLE_POINTER for debug

In reply to Ying-Chun Liu (PaulLiu)
Quoted 133 lines · Ying-Chun Liu (PaulLiu)

From: "Ying-Chun Liu (PaulLiu)" <[email protected]>

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.

---
V2: add Kconfig options to turn on/off this feature.
V3: make efi_initialize_system_table_pointer() do the job as described.
V4: use efi_alloc_aligned_pages() for system_table_pointer.
V5: move the code into a separate module.
V6: Use macros to replace size_4MB
V7: Fix the code based on the review. Update license field.

---
  include/efi_api.h                  | 16 ++++++++++++
  include/efi_loader.h               |  2 ++
  lib/efi_loader/Kconfig             |  8 ++++++
  lib/efi_loader/Makefile            |  1 +
  lib/efi_loader/efi_debug_support.c | 40 ++++++++++++++++++++++++++++++
  lib/efi_loader/efi_setup.c         |  7 ++++++
  6 files changed, 74 insertions(+)

create mode 100644 lib/efi_loader/efi_debug_support.c

include/efi_api.h +16 -0
index eb61eafa028..6c4c1a0cc7b 100644
@@ -259,6 +259,22 @@ struct efi_capsule_result_variable_header {
  	efi_status_t capsule_status;
  } __packed;
 
+/**
+ * struct efi_system_table_pointer - struct to store the pointer of system
+ * table.
+ * @signature: The signature of this struct.
+ * @efi_system_table_base: The physical address of System Table.
+ * @crc32: CRC32 checksum
+ *
+ * This struct is design for hardware debugger to search through memory to
+ * get the address of EFI System Table.
+ */
+struct efi_system_table_pointer {
+	u64 signature;
+	efi_physical_addr_t efi_system_table_base;
+	u32 crc32;
+};
+
  struct efi_memory_range {
  	efi_physical_addr_t	address;
  	u64			length;
include/efi_loader.h +2 -0
index 8f9f2bcf1cb..8f065244d8e 100644
@@ -646,6 +646,8 @@ efi_status_t efi_tcg2_measure_dtb(void *dtb);
  efi_status_t efi_root_node_register(void);
  /* Called by bootefi to initialize runtime */
  efi_status_t efi_initialize_system_table(void);
+/* Called by bootefi to initialize debug */
+efi_status_t efi_initialize_system_table_pointer(void);
  /* efi_runtime_detach() - detach unimplemented runtime functions */
  void efi_runtime_detach(void);
  /* efi_convert_pointer() - convert pointer to virtual address */
lib/efi_loader/Kconfig +8 -0
index 7f02a83e2a2..f9d75cbc3fd 100644
@@ -71,6 +71,14 @@ config EFI_SECURE_BOOT
  config EFI_SIGNATURE_SUPPORT
  	bool
 
+config EFI_DEBUG_SUPPORT
+	bool "EFI Debug Support"
+	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
lib/efi_loader/Makefile +1 -0
index cf050e5385d..51ccf1cd87e 100644
@@ -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)
lib/efi_loader/efi_debug_support.c new file +24 -0
new file mode 100644
index 00000000000..c9773feaa5b
@@ -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);

lib/efi_loader/efi_debug_support.c line 34

Quoted 10 lines
lib/efi_loader/efi_debug_support.c new file +10 -0
+
+	if (!systab_pointer) {
+		log_err("Installing EFI system table pointer failed\n");
+		return EFI_OUT_OF_RESOURCES;
+	}
+
+	memset(systab_pointer, 0, sizeof(struct efi_system_table_pointer));
+
+	systab_pointer->signature = EFI_SYSTEM_TABLE_SIGNATURE;
+	systab_pointer->efi_system_table_base = (efi_physical_addr_t)&systab;

When building with qemu_arm_defconfig:

lib/efi_loader/efi_debug_support.c: In function ‘efi_initialize_system_table_pointer’:
lib/efi_loader/efi_debug_support.c:48:49: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
48 | systab_pointer->efi_system_table_base =

(efi_physical_addr_t)&systab;
      |

You should use (uintptr_t) for the cast.

Best regards

Heinrich

Quoted 24 lines
lib/efi_loader/efi_debug_support.c new file +6 -0
+	systab_pointer->crc32 = crc32(0,
+				      (const unsigned char *)systab_pointer,
+				      sizeof(struct efi_system_table_pointer));
+
+	return EFI_SUCCESS;
+}
lib/efi_loader/efi_setup.c +7 -0
index 48f91da5df7..78c5059256a 100644
@@ -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)
#4 lore raw

PATCH v7 2/6 efi: add EFI_DEBUG_IMAGE_INFO_TABLE for debug

In reply to Ying-Chun Liu (PaulLiu)

From: "Ying-Chun Liu (PaulLiu)" <[email protected]>

EFI_DEBUG_IMAGE_INFO_TABLE is used to store EFI_LOADED_IMAGE for debug purpose. This commit adds the table to the EFI_CONFIGURATION_TABLE.

This feature is described in UEFI Spec version 2.10. Section 18.4. The implementation ensures support for hardware-assisted debugging and provides a standardized mechanism for debuggers to discover and interact with system-level debug resources.

---
V3: Fix the way of installation of configuration table.
V5: move the code into a separate module.
V7: Fix some syntax warnings.

---
 include/efi_api.h                  | 53 ++++++++++++++++++++++++++++++
 include/efi_loader.h               |  2 ++
 lib/efi_loader/efi_debug_support.c |  6 ++++
 lib/efi_loader/efi_setup.c         | 11 +++++++
 4 files changed, 72 insertions(+)
include/efi_api.h +53 -0
index 6c4c1a0cc7b..8da0a350ce3 100644
@@ -238,6 +238,10 @@ enum efi_reset_type {
 	EFI_GUID(0xcce33c35, 0x74ac, 0x4087, 0xbc, 0xe7, \
 		 0x8b, 0x29, 0xb0, 0x2e, 0xeb, 0x27)
 
+#define EFI_DEBUG_IMAGE_INFO_TABLE_GUID \
+	EFI_GUID(0x49152e77, 0x1ada, 0x4764, 0xb7, 0xa2, \
+		 0x7a, 0xfe, 0xfe, 0xd9, 0x5e, 0x8b)
+
 struct efi_conformance_profiles_table {
 	u16 version;
 	u16 number_of_profiles;
@@ -574,6 +578,55 @@ struct efi_loaded_image {
 	efi_status_t (EFIAPI *unload)(efi_handle_t image_handle);
 };
 
+#define EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS 0x01
+#define EFI_DEBUG_IMAGE_INFO_TABLE_MODIFIED     0x02
+
+/**
+ * struct efi_debug_image_info_normal - Store Debug Information for normal
+ * image.
+ * @image_info_type: the type of image info.
+ * @loaded_image_protocol_instance: the pointer to struct efi_loaded_image.
+ * @image_handle: the EFI handle of the image.
+ *
+ * This struct is created by efi_load_image() and store the information
+ * for debugging an normal image.
+ */
+struct efi_debug_image_info_normal {
+	u32 image_info_type;
+	struct efi_loaded_image *loaded_image_protocol_instance;
+	efi_handle_t image_handle;
+};
+
+/**
+ * union efi_debug_image_info - The union to store a pointer for EFI
+ * DEBUG IMAGE INFO.
+ * @image_info_type: the type of the image_info if it is not a normal image.
+ * @normal_image: The pointer to a normal image.
+ *
+ * This union is for a pointer that can point to the struct of normal_image.
+ * Or it points to an image_info_type.
+ */
+union efi_debug_image_info {
+	u32 *image_info_type;
+	struct efi_debug_image_info_normal *normal_image;
+};
+
+/**
+ * struct efi_debug_image_info_table_header - store the array of
+ * struct efi_debug_image_info.
+ * @update_status: Status to notify this struct is ready to use or not.
+ * @table_size: The number of elements of efi_debug_image_info_table.
+ * @efi_debug_image_info_table: The array of efi_debug_image_info.
+ *
+ * This struct stores the array of efi_debug_image_info. The
+ * number of elements is table_size.
+ */
+struct efi_debug_image_info_table_header {
+	volatile u32 update_status;
+	u32 table_size;
+	union efi_debug_image_info *efi_debug_image_info_table;
+};
+
 #define EFI_DEVICE_PATH_PROTOCOL_GUID \
 	EFI_GUID(0x09576e91, 0x6d3f, 0x11d2, \
 		 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
include/efi_loader.h +2 -0
index 8f065244d8e..d0c72d0bc58 100644
@@ -315,6 +315,8 @@ extern const struct efi_hii_config_routing_protocol efi_hii_config_routing;
 extern const struct efi_hii_config_access_protocol efi_hii_config_access;
 extern const struct efi_hii_database_protocol efi_hii_database;
 extern const struct efi_hii_string_protocol efi_hii_string;
+/* structure for EFI_DEBUG_SUPPORT_PROTOCOL */
+extern struct efi_debug_image_info_table_header efi_m_debug_info_table_header;
 
 uint16_t *efi_dp_str(struct efi_device_path *dp);
 
lib/efi_loader/efi_debug_support.c +6 -0
index c9773feaa5b..83fb3d22ad3 100644
@@ -11,6 +11,12 @@
 
 struct efi_system_table_pointer __efi_runtime_data * systab_pointer = NULL;
 
+struct efi_debug_image_info_table_header efi_m_debug_info_table_header = {
+	0,
+	0,
+	NULL
+};
+
 /**
  * efi_initialize_system_table_pointer() - Initialize system table pointer
  *
lib/efi_loader/efi_setup.c +11 -0
index 78c5059256a..f06cf49e443 100644
@@ -18,6 +18,9 @@
 
 efi_status_t efi_obj_list_initialized = OBJ_LIST_NOT_INITIALIZED;
 
+const efi_guid_t efi_debug_image_info_table_guid =
+	EFI_DEBUG_IMAGE_INFO_TABLE_GUID;
+
 /*
  * Allow unaligned memory access.
  *
@@ -280,9 +283,17 @@ efi_status_t efi_init_obj_list(void)
 
 	/* Initialize system table pointer */
 	if (IS_ENABLED(CONFIG_EFI_DEBUG_SUPPORT)) {
+		efi_guid_t debug_image_info_table_guid =
+			efi_debug_image_info_table_guid;
+
 		ret = efi_initialize_system_table_pointer();
 		if (ret != EFI_SUCCESS)
 			goto out;
+
+		ret = efi_install_configuration_table(&debug_image_info_table_guid,
+						      &efi_m_debug_info_table_header);
+		if (ret != EFI_SUCCESS)
+			goto out;
 	}
 
 	if (IS_ENABLED(CONFIG_EFI_ECPT)) {
Signature · 1 line
2.39.5
#5 lore raw

PATCH v7 3/6 lib: efi_loader: efi_memory.c: add efi_realloc() for realloc memory

In reply to Ying-Chun Liu (PaulLiu)

From: "Ying-Chun Liu (PaulLiu)" <[email protected]>

Add efi_realloc() for realloc memory that previously alloc by efi_alloc().

Cc Heinrich Schuchardt <[email protected]>
Cc Ilias Apalodimas <[email protected]>
Cc Peter Robinson <[email protected]>
Cc Simon Glass <[email protected]>

---
V4: Fix efi_realloc return failure code.
V6: Return error status when efi_alloc failed.

---
 include/efi_loader.h        | 10 +++++++
 lib/efi_loader/efi_memory.c | 58 +++++++++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+)
include/efi_loader.h +10 -0
index d0c72d0bc58..13ca2ec9a4e 100644
@@ -878,6 +878,16 @@ efi_status_t efi_next_variable_name(efi_uintn_t *size, u16 **buf,
 #define efi_size_in_pages(size) (((size) + EFI_PAGE_MASK) >> EFI_PAGE_SHIFT)
 /* Allocate boot service data pool memory */
 void *efi_alloc(size_t len);
+/**
+ * efi_realloc() - reallocate boot services data pool memory
+ *
+ * Reallocate memory from pool for a new size and copy the data from old one.
+ *
+ * @ptr:	pointer to the buffer
+ * @size:	number of bytes to allocate
+ * Return:	EFI status to indicate success or not
+ */
+efi_status_t efi_realloc(void **ptr, size_t len);
 /* Allocate pages on the specified alignment */
 void *efi_alloc_aligned_pages(u64 len, int memory_type, size_t align);
 /* More specific EFI memory allocator, called by EFI payloads */
lib/efi_loader/efi_memory.c +58 -0

64 lines not on this page · raw message

Signature · 1 line
2.39.5
#6 lore raw

PATCH v7 4/6 efi: add EFI_DEBUG_IMAGE_INFO for debug

In reply to Ying-Chun Liu (PaulLiu)

From: "Ying-Chun Liu (PaulLiu)" <[email protected]>

This commit adds the functionality of generate EFI_DEBUG_IMAGE_INFO while loading the image.

This feature is described in UEFI Spec 2.10. Section 18.4.3. The implementation ensures support for hardware-assisted debugging and provides a standardized mechanism for debuggers to discover the load address of an EFI application.

Cc Heinrich Schuchardt <[email protected]>
Cc Ilias Apalodimas <[email protected]>
Cc Peter Robinson <[email protected]>
Cc Simon Glass <[email protected]>

---
V2: use Kconfig options to turn on/off this feature.
V3: Use efi_realloc to realloc the tables. Move tables to boot time.
V4: Use new efi_realloc().
V5: Fix function comments and move the code into a separate module.
V6: refine the code. Handling the error of efi_allocate_pool.
V7: Use memmove instead of memcpy. Fix syntax warnings.

---
 include/efi_api.h                  |   2 +
 include/efi_loader.h               |   5 ++
 lib/efi_loader/efi_boottime.c      |   7 ++
 lib/efi_loader/efi_debug_support.c | 137 +++++++++++++++++++++++++++++
 4 files changed, 151 insertions(+)
include/efi_api.h +2 -0
index 8da0a350ce3..77a05f752e5 100644
@@ -581,6 +581,8 @@ struct efi_loaded_image {
 #define EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS 0x01
 #define EFI_DEBUG_IMAGE_INFO_TABLE_MODIFIED     0x02
 
+#define EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL  0x01
+
 /**
  * struct efi_debug_image_info_normal - Store Debug Information for normal
  * image.
include/efi_loader.h +5 -0
index 13ca2ec9a4e..22440b842e3 100644
@@ -650,6 +650,11 @@ efi_status_t efi_root_node_register(void);
 efi_status_t efi_initialize_system_table(void);
 /* Called by bootefi to initialize debug */
 efi_status_t efi_initialize_system_table_pointer(void);
+/* Called by efi_load_image for register debug info */
+efi_status_t efi_core_new_debug_image_info_entry(u32 image_info_type,
+						 struct efi_loaded_image *loaded_image,
+						 efi_handle_t image_handle);
+void efi_core_remove_debug_image_info_entry(efi_handle_t image_handle);
 /* efi_runtime_detach() - detach unimplemented runtime functions */
 void efi_runtime_detach(void);
 /* efi_convert_pointer() - convert pointer to virtual address */
lib/efi_loader/efi_boottime.c +7 -0
index dbebb37dc04..8c83040ac48 100644
@@ -2129,6 +2129,11 @@ efi_status_t EFIAPI efi_load_image(bool boot_policy,
 		*image_handle = NULL;
 		free(info);
 	}
+
+	if (IS_ENABLED(CONFIG_EFI_DEBUG_SUPPORT) && *image_handle)
+		efi_core_new_debug_image_info_entry(EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL,
+						    info,
+						    *image_handle);
 error:
 	return EFI_EXIT(ret);
 }
@@ -3359,6 +3364,8 @@ efi_status_t EFIAPI efi_unload_image(efi_handle_t image_handle)
 		ret = EFI_INVALID_PARAMETER;
 		goto out;
 	}
+	if (IS_ENABLED(CONFIG_EFI_DEBUG_SUPPORT))
+		efi_core_remove_debug_image_info_entry(image_handle);
 	switch (efiobj->type) {
 	case EFI_OBJECT_TYPE_STARTED_IMAGE:
 		/* Call the unload function */
lib/efi_loader/efi_debug_support.c +137 -0

146 lines not on this page · raw message

Signature · 1 line
2.39.5
Tested-by on v7 4/6
#7 lore raw

Re: [PATCH v7 4/6] efi: add EFI_DEBUG_IMAGE_INFO for debug

Quoted 10 lines · Ying-Chun Liu (PaulLiu)

From: "Ying-Chun Liu (PaulLiu)" <[email protected]>

This commit adds the functionality of generate EFI_DEBUG_IMAGE_INFO while loading the image.

This feature is described in UEFI Spec 2.10. Section 18.4.3. The implementation ensures support for hardware-assisted debugging and provides a standardized mechanism for debuggers to discover the load address of an EFI application.

Quoted 5 lines
Cc Heinrich Schuchardt <[email protected]>
Cc Ilias Apalodimas <[email protected]>
Cc Peter Robinson <[email protected]>
Cc Simon Glass <[email protected]>

Hello Paul,

with
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
I got this output:

Debug Info Table Dump
=====================

=> dump
Modified
Number of entries: 0x00000002
Info type 0x00000001
Address: [0x00000000bdd47000, 0x00000000bde5aabf]
File: /shellriscv64.efi
Handle: 0x00000000beeb17a0
Info type 0x00000001
Address: [0x00000000bdbeb000, 0x00000000bdbee1ff]
File: /\dbginfodump.efi
Handle: 0x00000000bef12890
=>

I found the PE-COFF headers of the EFI binaries in the provided locations:

(gdb) p *(char[0x44]*)0xbdbeb000
$1 = "MZ", '\000' <repeats 46 times>, "RISCV\000\000\000RSC\005@\000\000\000PE\000" (gdb) p *(char[0x84]*)0xbdd47000
$2 = "MZ", '\000' <repeats 58 times>, "\200", '\000' <repeats 67 times>, "PE\000"

This looks good.

#8 lore raw

PATCH v7 5/6 efi: selftest: add selftest for EFI_DEBUG_SUPPORT

In reply to Ying-Chun Liu (PaulLiu)

From: "Ying-Chun Liu (PaulLiu)" <[email protected]>

Add selftest to check the installed configuration table that has the correct GUID.

Cc Heinrich Schuchardt <[email protected]>
Cc Ilias Apalodimas <[email protected]>

---
V7: add selftest for EFI_DEBUG_SUPPORT

---
 lib/efi_selftest/Makefile                     |  2 +
 lib/efi_selftest/efi_selftest_debug_support.c | 58 +++++++++++++++++++
 2 files changed, 60 insertions(+)
 create mode 100644 lib/efi_selftest/efi_selftest_debug_support.c
lib/efi_selftest/Makefile +2 -0
index d78bf7d6191..842433f68aa 100644
@@ -78,6 +78,8 @@ endif
 
 obj-$(CONFIG_EFI_ESRT) += efi_selftest_esrt.o
 
+obj-$(CONFIG_EFI_DEBUG_SUPPORT) += efi_selftest_debug_support.o
+
 targets += \
 efi_miniapp_file_image_exception.h \
 efi_miniapp_file_image_exit.h \
lib/efi_selftest/efi_selftest_debug_support.c new file +58 -0

58 lines not on this page · raw message

Signature · 1 line
2.39.5
#9 lore raw

Re: [PATCH v7 5/6] efi: selftest: add selftest for EFI_DEBUG_SUPPORT

Quoted 53 lines · Ying-Chun Liu (PaulLiu)

From: "Ying-Chun Liu (PaulLiu)" <[email protected]>

Add selftest to check the installed configuration table that has the correct GUID.

Cc Heinrich Schuchardt <[email protected]>
Cc Ilias Apalodimas <[email protected]>

---
V7: add selftest for EFI_DEBUG_SUPPORT

---
  lib/efi_selftest/Makefile                     |  2 +
  lib/efi_selftest/efi_selftest_debug_support.c | 58 +++++++++++++++++++
  2 files changed, 60 insertions(+)

create mode 100644 lib/efi_selftest/efi_selftest_debug_support.c

lib/efi_selftest/Makefile +2 -0
index d78bf7d6191..842433f68aa 100644
@@ -78,6 +78,8 @@ endif
 
  obj-$(CONFIG_EFI_ESRT) += efi_selftest_esrt.o
 
+obj-$(CONFIG_EFI_DEBUG_SUPPORT) += efi_selftest_debug_support.o
+
  targets += \
  efi_miniapp_file_image_exception.h \
  efi_miniapp_file_image_exit.h \
lib/efi_selftest/efi_selftest_debug_support.c new file +18 -0
new file mode 100644
index 00000000000..9cfa44c05a2
@@ -0,0 +1,58 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * efi_selftest_debug_support
+ *
+ * Copyright (c) 2025 Ying-Chun Liu, Linaro Ltd. <[email protected]>
+ *
+ * Test the EFI_DEBUG_SUPPORT
+ */
+
+#include <efi_loader.h>
+#include <efi_selftest.h>
+
+static const struct efi_system_table *local_systable;
+
+/**
+ * efi_st_debug_support_setup() - setup test
+ *
+ * @handle:	handle of the loaded image

lib/efi_selftest/efi_selftest_debug_support.c line 28

Quoted 10 lines
lib/efi_selftest/efi_selftest_debug_support.c new file +10 -0
+ * @systable:	system table
+ * Return:	status code
+ */
+static int efi_st_debug_support_setup(const efi_handle_t img_handle,
+				      const struct efi_system_table *systable)
+{
+	local_systable = systable;
+
+	return EFI_ST_SUCCESS;
+}

Thanks for adding a unit test.

The setup function is not needed. You can access st_systable in the execute function. The variable is set here:

lib/efi_selftest/efi_selftest.c:260: st_systable = systab;

Quoted 4 lines
lib/efi_selftest/efi_selftest_debug_support.c new file +4 -0
+
+/**
+ * efi_st_debug_support_execute() - execute test
+ *

lib/efi_selftest/efi_selftest_debug_support.c line 42

Quoted 10 lines
lib/efi_selftest/efi_selftest_debug_support.c new file +10 -0
+ * Test EFI_DEBUG_SUPPORT tables.
+ *
+ * Return:	status code
+ */
+static int efi_st_debug_support_execute(void)
+{
+	struct efi_debug_image_info_table_header *efi_st_debug_info_table_header = NULL;
+	efi_guid_t efi_debug_image_info_table_guid = EFI_DEBUG_IMAGE_INFO_TABLE_GUID;
+
+	/* find EFI_DEBUG_IMAGE_INFO_TABLE */

Please, use efi_st_get_config_table().

lib/efi_selftest/efi_selftest_debug_support.c line 47

Quoted 5 lines
lib/efi_selftest/efi_selftest_debug_support.c new file +5 -0
+	for (int idx = 0; idx < local_systable->nr_tables; idx++)
+		if (!guidcmp(&efi_debug_image_info_table_guid, &local_systable->tables[idx].guid))
+			efi_st_debug_info_table_header = local_systable->tables[idx].table;
+
+	if (!efi_st_debug_info_table_header)

Please, add an error message, e.g.

efi_st_error("Missing EFI_DEBUG_IMAGE_INFO_TABLE\n");

If we would load EFI binaries like efi_selftest_miniapp_exit.efi here, we could check that the table is correctly updated. But that can be added later. My testing using dbginfodump.efi showed a reasonable content.

Best regards

Heinrich

Quoted 11 lines
lib/efi_selftest/efi_selftest_debug_support.c new file +11 -0
+		return EFI_ST_FAILURE;
+
+	return EFI_ST_SUCCESS;
+}
+
+EFI_UNIT_TEST(debug_support) = {
+	.name = "debug_support",
+	.phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT,
+	.execute = efi_st_debug_support_execute,
+	.setup = efi_st_debug_support_setup,
+};
#10 lore raw

PATCH v7 6/6 configs: sandbox_defconfig: enable CONFIG_EFI_DEBUG_SUPPORT

In reply to Ying-Chun Liu (PaulLiu)

From: "Ying-Chun Liu (PaulLiu)" <[email protected]>

Enable CONFIG_EFI_DEBUG_SUPPORT so that we can run a build test for this config.

Cc Simon Glass <[email protected]>
Cc Heinrich Schuchardt <[email protected]>
Cc Ilias Apalodimas <[email protected]>

---
V7: enable CONFIG_EFI_DEBUG_SUPPORT for sandbox_defconfig

---
 configs/sandbox_defconfig | 1 +
 1 file changed, 1 insertion(+)
configs/sandbox_defconfig +1 -0
index 4f6943d1a4b..c50746d3dbc 100644
@@ -10,6 +10,7 @@ CONFIG_PCI=y
 CONFIG_DEBUG_UART=y
 CONFIG_SYS_MEMTEST_START=0x00100000
 CONFIG_SYS_MEMTEST_END=0x00101000
+CONFIG_EFI_DEBUG_SUPPORT=y
 CONFIG_EFI_SECURE_BOOT=y
 CONFIG_EFI_RT_VOLATILE_STORE=y
 CONFIG_EFI_RUNTIME_UPDATE_CAPSULE=y
Signature · 1 line
2.39.5
#11 lore raw

Re: [PATCH v7 6/6] configs: sandbox_defconfig: enable CONFIG_EFI_DEBUG_SUPPORT

Quoted 4 lines · Ying-Chun Liu (PaulLiu)

From: "Ying-Chun Liu (PaulLiu)" <[email protected]>

Enable CONFIG_EFI_DEBUG_SUPPORT so that we can run a build test for this config.

It is not enough to build only on 64bit. qemu_arm_defconfig showed this problem:

lib/efi_loader/efi_debug_support.c: In function ‘efi_initialize_system_table_pointer’:
lib/efi_loader/efi_debug_support.c:48:49: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
48 | systab_pointer->efi_system_table_base =

(efi_physical_addr_t)&systab;
      |

Either enable in multiple defconfigs or maybe use

default y if !HAS_BOARD_SIZE_LIMIT

in the Kconfig file.

Best regards

Heinrich

Quoted 23 lines
Cc Simon Glass <[email protected]>
Cc Heinrich Schuchardt <[email protected]>
Cc Ilias Apalodimas <[email protected]>

---
V7: enable CONFIG_EFI_DEBUG_SUPPORT for sandbox_defconfig

---
  configs/sandbox_defconfig | 1 +
  1 file changed, 1 insertion(+)
configs/sandbox_defconfig +1 -0
index 4f6943d1a4b..c50746d3dbc 100644
@@ -10,6 +10,7 @@ CONFIG_PCI=y
  CONFIG_DEBUG_UART=y
  CONFIG_SYS_MEMTEST_START=0x00100000
  CONFIG_SYS_MEMTEST_END=0x00101000
+CONFIG_EFI_DEBUG_SUPPORT=y
  CONFIG_EFI_SECURE_BOOT=y
  CONFIG_EFI_RT_VOLATILE_STORE=y
  CONFIG_EFI_RUNTIME_UPDATE_CAPSULE=y