Skip to contentSkip to conversation

Add EFI Debug Support Table feature

PATCH Superseded Ying-Chun Liu (PaulLiu) 3 participants 9 messages Jun 17, 2025 – Jun 18, 2025

v6 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v6 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.

Ying-Chun Liu (PaulLiu) (4):
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

 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      |   8 ++
 lib/efi_loader/efi_debug_support.c | 189 +++++++++++++++++++++++++++++
 lib/efi_loader/efi_memory.c        |  58 +++++++++
 lib/efi_loader/efi_setup.c         |  20 +++
 8 files changed, 374 insertions(+)
 create mode 100644 lib/efi_loader/efi_debug_support.c
Signature · 1 line
2.39.5
#1 lore raw

PATCH v6 1/4 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

---
 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 | 46 ++++++++++++++++++++++++++++++
 lib/efi_loader/efi_setup.c         |  8 ++++++
 6 files changed, 81 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 +46 -0

46 lines not on this page · raw message

lib/efi_loader/efi_setup.c +8 -0
index 48f91da5df7..6193b9f6d0c 100644
@@ -278,6 +278,14 @@ 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
#2 lore raw

Re: [PATCH v6 1/4] efi: add EFI_SYSTEM_TABLE_POINTER for debug

Quoted 76 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

---
  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 | 46 ++++++++++++++++++++++++++++++
  lib/efi_loader/efi_setup.c         |  8 ++++++
  6 files changed, 81 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 +0 -0
index 7f02a83e2a2..f9d75cbc3fd 100644

lib/efi_loader/Kconfig config EFI_SECURE_BOOT · line 75

Quoted 5 lines
lib/efi_loader/Kconfig +2 -0
@@ -71,6 +71,14 @@ config EFI_SECURE_BOOT
  config EFI_SIGNATURE_SUPPORT
  	bool
 
+config EFI_DEBUG_SUPPORT
+	bool "EFI Debug Support"

There should be at least one defconfig using the setting so that we at least compile the new code in our CI.

Quoted 27 lines
lib/efi_loader/Kconfig +6 -0
+	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 +0 -0
new file mode 100644
index 00000000000..3794b31c4cd

lib/efi_loader/efi_debug_support.c line 1

Quoted 1 line
lib/efi_loader/efi_debug_support.c new file +1 -0
@@ -0,0 +1,46 @@
+// SPDX-License-Identifier: GPL-2.0+

GPL-2.0-or-later

see https://spdx.org/licenses/GPL-2.0-or-later.html

Quoted 13 lines
lib/efi_loader/efi_debug_support.c new file +13 -0
+/*
+ * EFI application boot time services
+ *
+ * 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;
+
+/**

lib/efi_loader/efi_debug_support.c line 24

Quoted 10 lines
lib/efi_loader/efi_debug_support.c new file +10 -0
+ * efi_initialize_system_table_pointer() - Initialize system table pointer
+ *
+ * Return:	status code
+ */
+efi_status_t efi_initialize_system_table_pointer(void)
+{
+	uintptr_t addr;
+	u32 crc32_value;
+
+	/* Allocate configuration table array */

This comment does not match the allocated object.

lib/efi_loader/efi_debug_support.c line 27

Quoted 3 lines
lib/efi_loader/efi_debug_support.c new file +3 -0
+	addr = (uintptr_t)efi_alloc_aligned_pages(sizeof(struct efi_system_table_pointer),
+						  EFI_RUNTIME_SERVICES_DATA,
+						  SZ_4M);

Please, assign system_pointer here directly and avoid unnecessary conversions (void *) -> (uintptr_t) -> (struct efi_system_table_pointer *).

Quoted 6 lines
lib/efi_loader/efi_debug_support.c new file +6 -0
+
+	if (!addr) {
+		log_err("Installing EFI system table pointer failed\n");
+		return EFI_OUT_OF_RESOURCES;
+	}
+

lib/efi_loader/efi_debug_support.c line 43

Quoted 10 lines
lib/efi_loader/efi_debug_support.c new file +10 -0
+	systab_pointer = (struct efi_system_table_pointer *)addr;
+	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;
+
+	crc32_value = crc32(0,
+			    (const unsigned char *)systab_pointer,
+			    sizeof(struct efi_system_table_pointer));
+	systab_pointer->crc32 = crc32_value;

You can do that assignment directly without extra variable.

Quoted 8 lines
lib/efi_loader/efi_debug_support.c new file +3 -0
+
+	return EFI_SUCCESS;
+}
lib/efi_loader/efi_setup.c +0 -0
index 48f91da5df7..6193b9f6d0c 100644

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

Quoted 9 lines
lib/efi_loader/efi_setup.c +6 -0
@@ -278,6 +278,14 @@ 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;
+		}

Running scripts/checkpatch.pl will indicated that the braces should be avoided here to achieve adherence to the kernel style.

Best regards

Heinrich

Quoted 5 lines
lib/efi_loader/efi_setup.c +2 -0
+	}
+
  	if (IS_ENABLED(CONFIG_EFI_ECPT)) {
  		ret = efi_ecpt_register();
  		if (ret != EFI_SUCCESS)
#3 lore raw

PATCH v6 2/4 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.

---
 include/efi_api.h                  | 53 ++++++++++++++++++++++++++++++
 include/efi_loader.h               |  2 ++
 lib/efi_loader/efi_debug_support.c |  6 ++++
 lib/efi_loader/efi_setup.c         | 12 +++++++
 4 files changed, 73 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 3794b31c4cd..f2dfcc5e6b2 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 +12 -0
index 6193b9f6d0c..60f3a7e5fbf 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,10 +283,19 @@ 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
#4 lore raw

Re: [PATCH v6 2/4] efi: add EFI_DEBUG_IMAGE_INFO_TABLE for debug

Quoted 141 lines · 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.

---
  include/efi_api.h                  | 53 ++++++++++++++++++++++++++++++
  include/efi_loader.h               |  2 ++
  lib/efi_loader/efi_debug_support.c |  6 ++++
  lib/efi_loader/efi_setup.c         | 12 +++++++
  4 files changed, 73 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 3794b31c4cd..f2dfcc5e6b2 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 +3 -0
index 6193b9f6d0c..60f3a7e5fbf 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.
   *

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

Quoted 4 lines
lib/efi_loader/efi_setup.c +1 -0
@@ -280,10 +283,19 @@ 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 =

This variable shadows the variable defined above.

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

Quoted 1 line
lib/efi_loader/efi_setup.c +1 -0
+			efi_debug_image_info_table_guid;

This self assignment provides a random value from the stack and not the expected GUID.

Please, provide a test in lib/efi_selftest/ verifying that the table is installed with the correct GUID.

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

Quoted 11 lines
lib/efi_loader/efi_setup.c +7 -0
+
  		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;
+		}

No braces here. Please, use scripts/checkpatch.pl before resubmitting.

Best regards

Heinrich

Quoted 3 lines
lib/efi_loader/efi_setup.c +0 -0
  	}
 
  	if (IS_ENABLED(CONFIG_EFI_ECPT)) {
#5 lore raw

Re: [PATCH v6 2/4] efi: add EFI_DEBUG_IMAGE_INFO_TABLE for debug

Quoted 160 lines · Heinrich Schuchardt
Quoted 41 lines · 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.

---
  include/efi_api.h                  | 53 ++++++++++++++++++++++++++++++
  include/efi_loader.h               |  2 ++
  lib/efi_loader/efi_debug_support.c |  6 ++++
  lib/efi_loader/efi_setup.c         | 12 +++++++
  4 files changed, 73 insertions(+)
include/efi_api.h +4 -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;

include/efi_api.h struct efi_loaded_image { · line 585

Quoted 8 lines
include/efi_api.h +5 -0
@@ -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

include/efi_api.h struct efi_loaded_image {

Quoted 3 lines
include/efi_api.h +3 -0
+ * image.
+ * @image_info_type: the type of image info.
+ * @loaded_image_protocol_instance: the pointer to struct

efi_loaded_image.

Quoted 5 lines
include/efi_api.h +5 -0
+ * @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.
+ */

include/efi_api.h struct efi_loaded_image {

Quoted 10 lines
include/efi_api.h +10 -0
+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.

include/efi_api.h struct efi_loaded_image {

Quoted 3 lines
include/efi_api.h +3 -0
+ * @normal_image: The pointer to a normal image.
+ *
+ * This union is for a pointer that can point to the struct of

normal_image.

include/efi_loader.h extern const struct efi_hii_config_routing_protocol

Quoted 31 lines
include/efi_api.h +23 -0
+ * 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 +0 -0
index 8f065244d8e..d0c72d0bc58 100644
@@ -315,6 +315,8 @@ extern const struct efi_hii_config_routing_protocol

efi_hii_config_routing;

include/efi_loader.h extern const struct efi_hii_config_routing_protocol · line 315

Quoted 1 line
include/efi_loader.h +0 -0
  extern const struct efi_hii_config_access_protocol

efi_hii_config_access;

include/efi_loader.h extern const struct efi_hii_config_routing_protocol efi_hii_config_routing;

Quoted 4 lines
include/efi_loader.h +2 -0
  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;

Review

Quoted 4 lines
include/efi_loader.h +0 -0
  uint16_t *efi_dp_str(struct efi_device_path *dp);
 
(quoted diff) +0 -0

b/lib/efi_loader/efi_debug_support.c

lib/efi_loader/efi_debug_support.c line 12

Quoted 6 lines

index 3794b31c4cd..f2dfcc5e6b2 100644

lib/efi_loader/efi_debug_support.c +0 -0
@@ -11,6 +11,12 @@
 
  struct efi_system_table_pointer __efi_runtime_data * systab_pointer =

NULL;

lib/efi_loader/efi_debug_support.c line 13

Quoted 2 lines
lib/efi_loader/efi_debug_support.c +1 -0
+struct efi_debug_image_info_table_header efi_m_debug_info_table_header

= {

lib/efi_loader/efi_debug_support.c

Quoted 7 lines
lib/efi_loader/efi_debug_support.c +5 -0
+     0,
+     0,
+     NULL
+};
+
  /**
   * efi_initialize_system_table_pointer() - Initialize system table

pointer

Quoted 16 lines
lib/efi_loader/efi_debug_support.c +0 -0
   *
lib/efi_loader/efi_setup.c +3 -0
index 6193b9f6d0c..60f3a7e5fbf 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.
   *

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

Quoted 4 lines
lib/efi_loader/efi_setup.c +1 -0
@@ -280,10 +283,19 @@ 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 =

This variable shadows the variable defined above.

Quoted 9 lines

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

Quoted 1 line
lib/efi_loader/efi_setup.c +1 -0
+                     efi_debug_image_info_table_guid;

This self assignment provides a random value from the stack and not the expected GUID.

Please, provide a test in lib/efi_selftest/ verifying that the table is installed with the correct GUID.

Hi Heinrich,

This is not a self assignment. The new variable is called "debug_image_info_table_guid". The global one is called "efi_debug_image_info_table_guid".
I'll implement a selftest anyway to make sure that the GUID is correct.

Quoted 8 lines

lib/efi_loader/efi_setup.c efi_status_t efi_init_obj_list(void)

Quoted 7 lines
lib/efi_loader/efi_setup.c +3 -0
+
              ret = efi_initialize_system_table_pointer();
              if (ret != EFI_SUCCESS) {
                      goto out;
              }
+
+             ret =

efi_install_configuration_table(&debug_image_info_table_guid,

Quoted 9 lines

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

Quoted 1 line
lib/efi_loader/efi_setup.c +1 -0
+

&efi_m_debug_info_table_header);

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

Quoted 3 lines
lib/efi_loader/efi_setup.c +3 -0
+             if (ret != EFI_SUCCESS) {
+                     goto out;
+             }

No braces here. Please, use scripts/checkpatch.pl before resubmitting.

Do you set some parameters of the scripts/checkpatch.pl ?
I'm using ./scripts/checkpatch.pl -g <COMMIT_ID> --u-boot.
But it only gives me a warning about using the volatile.
And for patch 1/4 it only gives me a warning about adding new file and the MAINTAINER stuff.
This is weird. I didn't get the warning about the braces at all.

Yours,
Paul

#6 lore raw

PATCH v6 3/4 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
#7 lore raw

PATCH v6 4/4 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.

---
 include/efi_api.h                  |   2 +
 include/efi_loader.h               |   5 ++
 lib/efi_loader/efi_boottime.c      |   8 ++
 lib/efi_loader/efi_debug_support.c | 137 +++++++++++++++++++++++++++++
 4 files changed, 152 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 +8 -0
index dbebb37dc04..303b7543e16 100644
@@ -2129,6 +2129,12 @@ 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 +3365,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
#8 lore raw

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

Quoted 62 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.

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.

---
  include/efi_api.h                  |   2 +
  include/efi_loader.h               |   5 ++
  lib/efi_loader/efi_boottime.c      |   8 ++
  lib/efi_loader/efi_debug_support.c | 137 +++++++++++++++++++++++++++++
  4 files changed, 152 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 +0 -0
index dbebb37dc04..303b7543e16 100644

lib/efi_loader/efi_boottime.c efi_status_t EFIAPI efi_load_image(bool boot_policy, · line 2137

Quoted 9 lines
lib/efi_loader/efi_boottime.c +6 -0
@@ -2129,6 +2129,12 @@ 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);
+	}

Braces are not needed here.

Quoted 31 lines
lib/efi_loader/efi_boottime.c +2 -0
  error:
  	return EFI_EXIT(ret);
  }
@@ -3359,6 +3365,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 +7 -0
index f2dfcc5e6b2..d8df95abf95 100644
@@ -17,6 +17,13 @@ struct efi_debug_image_info_table_header efi_m_debug_info_table_header = {
  	NULL
  };
 
+/* efi_m_max_table_entries is the maximum entries allocated for
+ * the efi_m_debug_info_table_header.efi_debug_image_info_table.
+ */
+static u32 efi_m_max_table_entries;
+
+#define EFI_DEBUG_TABLE_ENTRY_SIZE  (sizeof(union efi_debug_image_info *))
+
  /**
   * efi_initialize_system_table_pointer() - Initialize system table pointer
   *

lib/efi_loader/efi_debug_support.c efi_status_t efi_initialize_system_table_pointer(void) · line 63

Quoted 7 lines
lib/efi_loader/efi_debug_support.c +4 -0
@@ -50,3 +57,133 @@ efi_status_t efi_initialize_system_table_pointer(void)
 
  	return EFI_SUCCESS;
  }
+
+/**
+ * efi_core_new_debug_image_info_entry() - Add a new efi_loaded_image structure to the
+ *                                         efi_debug_image_info Table.

Nits:
%s/Table/table/

Quoted 99 lines
lib/efi_loader/efi_debug_support.c +99 -0
+ *
+ * @image_info_type: type of debug image information
+ * @loaded_image:    pointer to the loaded image protocol for the image
+ *                   being loaded
+ * @image_handle:    image handle for the image being loaded
+ *
+ * Re-Allocates the table if it's not large enough to accommodate another
+ * entry.
+ *
+ * Return: status code
+ **/
+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)
+{
+	union efi_debug_image_info **table;
+	u32 index;
+	u32 table_size;
+	efi_status_t ret;
+
+	/* Set the flag indicating that we're in the process of updating
+	 * the table.
+	 */
+	efi_m_debug_info_table_header.update_status |=
+		EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;
+
+	table = &efi_m_debug_info_table_header.efi_debug_image_info_table;
+
+	if (efi_m_debug_info_table_header.table_size >= efi_m_max_table_entries) {
+		/* table is full, re-allocate the buffer increasing the size
+		 * by 4 KiB.
+		 */
+		table_size = efi_m_max_table_entries * EFI_DEBUG_TABLE_ENTRY_SIZE;
+
+		ret = efi_realloc((void **)table, table_size + EFI_PAGE_SIZE);
+
+		if (ret != EFI_SUCCESS) {
+			efi_m_debug_info_table_header.update_status &=
+				~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;
+			return ret;
+		}
+
+		/* Enlarge the max table entries and set the first empty
+		 * entry index to be the original max table entries.
+		 */
+		efi_m_max_table_entries +=
+			EFI_PAGE_SIZE / EFI_DEBUG_TABLE_ENTRY_SIZE;
+	}
+
+	/* We always put the next entry at the end of the currently consumed
+	 * table (i.e. first free entry)
+	 */
+	index = efi_m_debug_info_table_header.table_size;
+
+	/* Allocate data for new entry. */
+	ret = efi_allocate_pool(EFI_BOOT_SERVICES_DATA,
+				sizeof(union efi_debug_image_info),
+				(void **)(&(*table)[index].normal_image));
+	if (ret == EFI_SUCCESS && (*table)[index].normal_image) {
+		/* Update the entry. */
+		(*table)[index].normal_image->image_info_type = image_info_type;
+		(*table)[index].normal_image->loaded_image_protocol_instance =
+			loaded_image;
+		(*table)[index].normal_image->image_handle = image_handle;
+
+		/* Increase the number of EFI_DEBUG_IMAGE_INFO elements and
+		 * set the efi_m_debug_info_table_header in modified status.
+		 */
+		efi_m_debug_info_table_header.table_size++;
+		efi_m_debug_info_table_header.update_status |=
+			EFI_DEBUG_IMAGE_INFO_TABLE_MODIFIED;
+	} else {
+		log_err("Adding new efi_debug_image_info failed\n");
+		return ret;
+	}
+
+	efi_m_debug_info_table_header.update_status &=
+		~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;
+
+	return EFI_SUCCESS;
+}
+
+/**
+ * efi_core_remove_debug_image_info_entry() - Remove an efi_debug_image_info entry.
+ *
+ * @image_handle:    image handle for the image being removed
+ **/
+void efi_core_remove_debug_image_info_entry(efi_handle_t image_handle)
+{
+	union efi_debug_image_info *table;
+	u32 index;
+
+	efi_m_debug_info_table_header.update_status |=
+		EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;
+
+	table = efi_m_debug_info_table_header.efi_debug_image_info_table;
+
+	for (index = 0; index < efi_m_max_table_entries; index++) {
+		if (table[index].normal_image &&

lib/efi_loader/efi_debug_support.c efi_status_t efi_initialize_system_table_pointer(void) · line 172

Quoted 10 lines
lib/efi_loader/efi_debug_support.c +10 -0
+		    table[index].normal_image->image_handle == image_handle) {
+			/* Found a match. Free up the table entry.
+			 * Move the tail of the table one slot to the front.
+			 */
+			efi_free_pool(table[index].normal_image);
+
+			memcpy(&table[index],
+			       &table[index + 1],
+			       (efi_m_debug_info_table_header.table_size -
+				index - 1) * EFI_DEBUG_TABLE_ENTRY_SIZE);

You cannot use memcpy() for overlapping memory areas. This is described in the memcpy man page.

Use memmove() instead.

Best regards

Heinrich

Quoted 17 lines
lib/efi_loader/efi_debug_support.c +17 -0
+
+			/* Decrease the number of EFI_DEBUG_IMAGE_INFO
+			 * elements and set the efi_m_debug_info_table_header
+			 * in modified status.
+			 */
+			efi_m_debug_info_table_header.table_size--;
+			table[efi_m_debug_info_table_header.table_size].normal_image =
+				NULL;
+			efi_m_debug_info_table_header.update_status |=
+				EFI_DEBUG_IMAGE_INFO_TABLE_MODIFIED;
+			break;
+		}
+	}
+
+	efi_m_debug_info_table_header.update_status &=
+		~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;
+}