Add EFI Debug Support Table feature
v8 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
V8: Fix casting which causes qemu_arm build failure. Fix selftest. Fix Kconfig
to enable building on more targets.
Ying-Chun Liu (PaulLiu) (5):
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
include/efi_api.h | 71 +++++++ include/efi_loader.h | 19 ++ lib/efi_loader/Kconfig | 9 + 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 | 40 ++++ 10 files changed, 408 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
PATCH v8 1/5 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.
V8: Fix pointer casting that causes qemu_arm_defconfig failed. Modify KConfig
so that more defconfigs enabled by default.
--- include/efi_api.h | 16 ++++++++++++ include/efi_loader.h | 2 ++ lib/efi_loader/Kconfig | 9 +++++++ lib/efi_loader/Makefile | 1 + lib/efi_loader/efi_debug_support.c | 40 ++++++++++++++++++++++++++++++ lib/efi_loader/efi_setup.c | 7 ++++++ 6 files changed, 75 insertions(+) create mode 100644 lib/efi_loader/efi_debug_support.c
include/efi_api.h +16 -0
@@ -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
@@ -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 +9 -0
@@ -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
lib/efi_loader/Makefile +1 -0
@@ -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
@@ -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 = (uintptr_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
@@ -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
Re: [PATCH v8 1/5] efi: add EFI_SYSTEM_TABLE_POINTER for debug
Quoted 133 lines · Ying-Chun Liu (PaulLiu)
From: "Ying-Chun Liu (PaulLiu)" <[email protected]>
Add
EFI_SYSTEM_TABLE_POINTERstructure for remote debugger to locate the address ofEFI_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.
Signed-off-by Ying-Chun Liu (PaulLiu) <[email protected]>Reviewed-by Ilias Apalodimas <[email protected]>Tested-by Heinrich Schuchardt <[email protected]>Cc Peter Robinson <[email protected]>Cc Simon Glass <[email protected]>---
V2: addKconfigoptions to turn on/off this feature.
V3: makeefi_initialize_system_table_pointer()do the job as described.
V4: useefi_alloc_aligned_pages()forsystem_table_pointer.
V5: move the code into a separate module.
V6: Use macros to replacesize_4MB
V7: Fix the code based on the review. Update license field.
V8: Fix pointer casting that causesqemu_arm_defconfigfailed. Modify KConfig
so that more defconfigs enabled by default.--- include/efi_api.h | 16 ++++++++++++ include/efi_loader.h | 2 ++ lib/efi_loader/Kconfig | 9 +++++++ lib/efi_loader/Makefile | 1 + lib/efi_loader/efi_debug_support.c | 40 ++++++++++++++++++++++++++++++ lib/efi_loader/efi_setup.c | 7 ++++++ 6 files changed, 75 insertions(+)create mode 100644
lib/efi_loader/efi_debug_support.cinclude/efi_api.h +16
-0@@ -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@@ -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 +9
-0@@ -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_TIMElib/efi_loader/Makefile +1
-0@@ -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 +21
-0@@ -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. */
lib/efi_loader/efi_debug_support.c line 31
Quoted 10 lines
lib/efi_loader/efi_debug_support.c new file +10
-0+ 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->crc32 = 0;
would have been an alternative. Maybe Ilias wants to change that when merging.
Quoted 27 lines
lib/efi_loader/efi_debug_support.c new file +9
-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 ; +}lib/efi_loader/efi_setup.c +7
-0@@ -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 )
Re: [PATCH v8 1/5] efi: add EFI_SYSTEM_TABLE_POINTER for debug
Quoted 27 lines · Heinrich Schuchardt
Quoted 25 lines · Ying-Chun Liu (PaulLiu)
From: "Ying-Chun Liu (PaulLiu)" <[email protected]>
Add
EFI_SYSTEM_TABLE_POINTERstructure for remote debugger to locate the address ofEFI_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.
Signed-off-by Ying-Chun Liu (PaulLiu) <[email protected]>Reviewed-by Ilias Apalodimas <[email protected]>Tested-by Heinrich Schuchardt <[email protected]>Cc Peter Robinson <[email protected]>Cc Simon Glass <[email protected]>---
V2: addKconfigoptions to turn on/off this feature.
V3: makeefi_initialize_system_table_pointer()do the job as described.
V4: useefi_alloc_aligned_pages()forsystem_table_pointer.
V5: move the code into a separate module.
V6: Use macros to replacesize_4MB
V7: Fix the code based on the review. Update license field.
V8: Fix pointer casting that causesqemu_arm_defconfigfailed. Modify KConfig
so that more defconfigs enabled by default.
---
[...]
Quoted 10 lines
lib/efi_loader/efi_debug_support.c line 31
Quoted 7 lines
lib/efi_loader/efi_debug_support.c new file +7
-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->crc32= 0;
Quoted 4 lines
would have been an alternative. Maybe Ilias wants to change that when merging.
Reviewed-by Heinrich Schuchardt <[email protected]>
Thanks Heinrich. I'll have a look at the patches shortly and queue them. I'll change the line above on my PR
/Ilias
Quoted 29 lines
Quoted 28 lines
lib/efi_loader/efi_debug_support.c new file +9
-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 ; +}lib/efi_loader/efi_setup.c +7
-0@@ -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 )
Re: [PATCH v8 1/5] efi: add EFI_SYSTEM_TABLE_POINTER for debug
In reply to Heinrich SchuchardtHi Heinrich, Ilias,
Sorry for the late reply. I'm a bit worried about this change. This structure (efi_system_table_pointer), is not packed.
So its actual size is a bit larger. The crc32 field is not at the end of the structure. Actually there are 4 bytes padding after it. But the CRC32 function is calculating the crc sum on the whole structure. So it might produce random value if we don't zero those padding bytes.
Yours,
Paul
Quoted 192 lines · Heinrich Schuchardt
Quoted 15 lines · Ying-Chun Liu (PaulLiu)
From: "Ying-Chun Liu (PaulLiu)" <[email protected]>
Add
EFI_SYSTEM_TABLE_POINTERstructure for remote debugger to locate the address ofEFI_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.
Signed-off-by Ying-Chun Liu (PaulLiu) <[email protected]>Reviewed-by Ilias Apalodimas <[email protected]>Tested-by Heinrich Schuchardt <[email protected]>Cc Peter Robinson <[email protected]>Cc Simon Glass <[email protected]>Quoted 8 lines
---
V2: addKconfigoptions to turn on/off this feature.
V3: makeefi_initialize_system_table_pointer()do the job as described.
V4: useefi_alloc_aligned_pages()forsystem_table_pointer.
V5: move the code into a separate module.
V6: Use macros to replacesize_4MB
V7: Fix the code based on the review. Update license field.
V8: Fix pointer casting that causesqemu_arm_defconfigfailed. ModifyKConfig
Quoted 16 lines
so that more defconfigs enabled by default.
--- include/efi_api.h | 16 ++++++++++++ include/efi_loader.h | 2 ++ lib/efi_loader/Kconfig | 9 +++++++ lib/efi_loader/Makefile | 1 + lib/efi_loader/efi_debug_support.c | 40 ++++++++++++++++++++++++++++++ lib/efi_loader/efi_setup.c | 7 ++++++ 6 files changed, 75 insertions(+)create mode 100644
lib/efi_loader/efi_debug_support.cinclude/efi_api.h +0
-0include/efi_api.h struct efi_capsule_result_variable_header { · line 263
Quoted 5 lines
include/efi_api.h +2
-0@@ -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
include/efi_api.h struct efi_capsule_result_variable_header {
Quoted 6 lines
include/efi_api.h +6
-0+* 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
Quoted 29 lines
include/efi_api.h +8
-0+* 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@@ -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
-0lib/efi_loader/Kconfig config EFI_SECURE_BOOT · line 80
Quoted 10 lines
lib/efi_loader/Kconfig +7
-0@@ -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 imageinformation
Review
Quoted 18 lines
lib/efi_loader/Kconfig +2
-0+ in a quiescent manner. + menu "UEFI services" config EFI_GET_TIMElib/efi_loader/Makefile +1
-0@@ -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)(quoted diff) +0
-0
b/lib/efi_loader/efi_debug_support.cQuoted 7 lines
new file mode 100644
index 00000000000..7dc5fa93af9lib/efi_loader/efi_debug_support.c new file +2
-0@@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* lib/efi_loader/efi_debug_support.c line 12
Quoted 10 lines
lib/efi_loader/efi_debug_support.c new file +10
-0+* 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;
lib/efi_loader/efi_debug_support.c
Quoted 3 lines
lib/efi_loader/efi_debug_support.c new file +3
-0+ +/** +* efi_initialize_system_table_pointer() - Initialize system table pointer
lib/efi_loader/efi_debug_support.c
Quoted 6 lines
lib/efi_loader/efi_debug_support.c new file +6
-0+* +* Return: status code +*/ +efi_status_t efi_initialize_system_table_pointer (void ) +{ +/* Allocate efi_system_table_pointer structure with 4MB alignment. */
lib/efi_loader/efi_debug_support.c line 22
Quoted 1 line
lib/efi_loader/efi_debug_support.c new file +1
-0+ systab_pointer = efi_alloc_aligned_pages(sizeof(struct
efi_system_table_pointer),lib/efi_loader/efi_debug_support.c line 31
Quoted 9 lines
lib/efi_loader/efi_debug_support.c new file +9
-0+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->crc32= 0;would have been an alternative. Maybe Ilias wants to change that when merging.
Reviewed-by Heinrich Schuchardt <[email protected]>lib/efi_loader/efi_debug_support.c
Quoted 5 lines
lib/efi_loader/efi_debug_support.c new file +5
-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,
lib/efi_loader/efi_debug_support.c line 37
Quoted 1 line
lib/efi_loader/efi_debug_support.c new file +1
-0+ sizeof(struct
efi_system_table_pointer));Quoted 21 lines
lib/efi_loader/efi_debug_support.c new file +3
-0+ +return EFI_SUCCESS ; +}lib/efi_loader/efi_setup.c +7
-0@@ -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 )
Re: [PATCH v8 1/5] efi: add EFI_SYSTEM_TABLE_POINTER for debug
Am 4. Juli 2025 13:59:53 MESZ schrieb Paul Liu <[email protected]>:
Quoted 8 lines
Hi Heinrich, Ilias,
Sorry for the late reply. I'm a bit worried about this change. This structure (
efi_system_table_pointer), is not packed.
So its actual size is a bit larger. The crc32 field is not at the end of the structure. Actually there are 4 bytes padding after it. But the CRC32 function is calculating the crc sum on the whole structure. So it might produce random value if we don't zero those padding bytes.
Thanks for highlighting this.
Structures in UEFI are typically packed.
Should padding bytes really be included in the crc32?
We should add a test of the crc32 to https://github.com/trini/u-boot/blob/master/lib/efi_loader/dbginfodump.c so that we can compare U-Boot to EDK2.
Best regards
Heinrich
Quoted 199 lines
Yours,
PaulQuoted 192 lines · Heinrich Schuchardt
Quoted 15 lines · Ying-Chun Liu (PaulLiu)
From: "Ying-Chun Liu (PaulLiu)" <[email protected]>
Add
EFI_SYSTEM_TABLE_POINTERstructure for remote debugger to locate the address ofEFI_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.
Signed-off-by Ying-Chun Liu (PaulLiu) <[email protected]>Reviewed-by Ilias Apalodimas <[email protected]>Tested-by Heinrich Schuchardt <[email protected]>Cc Peter Robinson <[email protected]>Cc Simon Glass <[email protected]>Quoted 8 lines
---
V2: addKconfigoptions to turn on/off this feature.
V3: makeefi_initialize_system_table_pointer()do the job as described.
V4: useefi_alloc_aligned_pages()forsystem_table_pointer.
V5: move the code into a separate module.
V6: Use macros to replacesize_4MB
V7: Fix the code based on the review. Update license field.
V8: Fix pointer casting that causesqemu_arm_defconfigfailed. ModifyKConfig
Quoted 16 lines
so that more defconfigs enabled by default.
--- include/efi_api.h | 16 ++++++++++++ include/efi_loader.h | 2 ++ lib/efi_loader/Kconfig | 9 +++++++ lib/efi_loader/Makefile | 1 + lib/efi_loader/efi_debug_support.c | 40 ++++++++++++++++++++++++++++++ lib/efi_loader/efi_setup.c | 7 ++++++ 6 files changed, 75 insertions(+)create mode 100644
lib/efi_loader/efi_debug_support.cinclude/efi_api.h +0
-0include/efi_api.h struct efi_capsule_result_variable_header { · line 263
Quoted 5 lines
include/efi_api.h +2
-0@@ -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
include/efi_api.h struct efi_capsule_result_variable_header {
Quoted 6 lines
include/efi_api.h +6
-0+* 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
Quoted 29 lines
include/efi_api.h +8
-0+* 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@@ -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
-0lib/efi_loader/Kconfig config EFI_SECURE_BOOT · line 80
Quoted 10 lines
lib/efi_loader/Kconfig +7
-0@@ -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 imageinformation
Review
Quoted 18 lines
lib/efi_loader/Kconfig +2
-0+ in a quiescent manner. + menu "UEFI services" config EFI_GET_TIMElib/efi_loader/Makefile +1
-0@@ -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)(quoted diff) +0
-0
b/lib/efi_loader/efi_debug_support.cQuoted 7 lines
new file mode 100644
index 00000000000..7dc5fa93af9lib/efi_loader/efi_debug_support.c new file +2
-0@@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* lib/efi_loader/efi_debug_support.c line 12
Quoted 10 lines
lib/efi_loader/efi_debug_support.c new file +10
-0+* 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;
lib/efi_loader/efi_debug_support.c
Quoted 3 lines
lib/efi_loader/efi_debug_support.c new file +3
-0+ +/** +* efi_initialize_system_table_pointer() - Initialize system table pointer
lib/efi_loader/efi_debug_support.c
Quoted 6 lines
lib/efi_loader/efi_debug_support.c new file +6
-0+* +* Return: status code +*/ +efi_status_t efi_initialize_system_table_pointer (void ) +{ +/* Allocate efi_system_table_pointer structure with 4MB alignment. */
lib/efi_loader/efi_debug_support.c line 22
Quoted 1 line
lib/efi_loader/efi_debug_support.c new file +1
-0+ systab_pointer = efi_alloc_aligned_pages(sizeof(struct
efi_system_table_pointer),lib/efi_loader/efi_debug_support.c line 31
Quoted 9 lines
lib/efi_loader/efi_debug_support.c new file +9
-0+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->crc32= 0;would have been an alternative. Maybe Ilias wants to change that when merging.
Reviewed-by Heinrich Schuchardt <[email protected]>lib/efi_loader/efi_debug_support.c
Quoted 5 lines
lib/efi_loader/efi_debug_support.c new file +5
-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,
lib/efi_loader/efi_debug_support.c line 37
Quoted 1 line
lib/efi_loader/efi_debug_support.c new file +1
-0+ sizeof(struct
efi_system_table_pointer));Quoted 21 lines
lib/efi_loader/efi_debug_support.c new file +3
-0+ +return EFI_SUCCESS ; +}lib/efi_loader/efi_setup.c +7
-0@@ -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 )
Re: [PATCH v8 1/5] efi: add EFI_SYSTEM_TABLE_POINTER for debug
Quoted 13 lines · Heinrich Schuchardt
Am 4. Juli 2025 13:59:53 MESZ schrieb Paul Liu<[email protected]>:
Quoted 8 lines
Hi Heinrich, Ilias,
Sorry for the late reply. I'm a bit worried about this change. This structure (
efi_system_table_pointer), is not packed.
So its actual size is a bit larger. The crc32 field is not at the end of the structure. Actually there are 4 bytes padding after it. But the CRC32 function is calculating the crc sum on the whole structure. So it might produce random value if we don't zero those padding bytes.Thanks for highlighting this.
Structures in UEFI are typically packed.
Quoted 7 lines
Should padding bytes really be included in the crc32?
We should add a test of the crc32 tohttps://github.com/trini/u-boot/blob/master/lib/efi_loader/dbginfodump.c so that we can compare U-Boot to EDK2.
Best regards
Heinrich
EDK II only zeros out the crc32 field.
BaseTools/Scripts/efi_debugging.py has this logic:
if system_table_pointer.Signature == efi_system_table_signature:
buf1 = bytearray(system_table_pointer)[:16]
crc32_value = zlib.crc32(buf1)
crc32_value = zlib.crc32(b'\0' * (sizeof(EFI_SYSTEM_TABLE_POINTER)
- len(buf1)), crc32_value)
if crc32_value == system_table_pointer.Crc32:
breaksizeof(EFI_SYSTEM_TABLE_POINTER) evaluates to 24. So it includes padding bytes. The logic calculates the crc32 as if the padding bytes were zero.
In contrast to your contribution EDK II uses BootServicesData for storing the system table pointer.
Here is a dump of what I saw on EDK II:
System Table Pointer @ 0x000000017fc00000
49 42 49 20 53 59 53 54 18 e0 ff 7f 01 00 00 00 56 d8 89 d0 00 00 00 00
The crc32 contains the trailing NULs.
So you are right we should zero out the padding bytes.
Best regards
Heinrich
Re: [PATCH v8 1/5] efi: add EFI_SYSTEM_TABLE_POINTER for debug
Quoted 44 lines · Heinrich Schuchardt
Quoted 13 lines · Heinrich Schuchardt
Am 4. Juli 2025 13:59:53 MESZ schrieb Paul Liu<[email protected]>:
Quoted 8 lines
Hi Heinrich, Ilias,
Sorry for the late reply. I'm a bit worried about this change. This structure (
efi_system_table_pointer), is not packed.
So its actual size is a bit larger. The crc32 field is not at the end of the structure. Actually there are 4 bytes padding after it. But the CRC32 function is calculating the crc sum on the whole structure. So it might produce random value if we don't zero those padding bytes.Thanks for highlighting this.
Structures in UEFI are typically packed.
Quoted 7 lines
Should padding bytes really be included in the crc32?
We should add a test of the crc32 tohttps://github.com/trini/u-boot/
blob/master/lib/efi_loader/dbginfodump.cso that we can compare U-Boot to EDK2.Best regards
Heinrich
EDK II only zeros out the crc32 field.
BaseTools/Scripts/efi_debugging.pyhas this logic:if system_table_pointer.Signature ==
efi_system_table_signature:
buf1 = bytearray(system_table_pointer)[:16]
crc32_value=zlib.crc32(buf1)
crc32_value= zlib.crc32(b'\0' * (sizeof(EFI_SYSTEM_TABLE_POINTER)
- len(buf1)),crc32_value)
ifcrc32_value== system_table_pointer.Crc32:
break
sizeof(EFI_SYSTEM_TABLE_POINTER)evaluates to 24. So it includes padding bytes. The logic calculates the crc32 as if the padding bytes were zero.In contrast to your contribution EDK II uses BootServicesData for storing the system table pointer.
Here is a dump of what I saw on EDK II:
System Table Pointer @
0x000000017fc00000
49 42 49 20 53 59 53 54 18 e0 ff 7f 01 00 00 00 56 d8 89 d0 00 00 00 00
Quoted 7 lines
The crc32 contains the trailing NULs.
So you are right we should zero out the padding bytes.
Best regards
Heinrich
I have opened an issue https://mantis.uefi.org/mantis/view.php?id=2521:
0002521: CRC32 field of System Table Pointer not well defined
The UEFI spec has this sentence concerning structure EFI_SYSTEM_TABLE_POINTER:
"The 32-bit CRC of the entire structure is calculated assuming the Crc32 field is zero. This value is then written to the Crc32 field."
EDK II has implemented the structure as non-packed. Using the GCC compiler this implies on 64-bit systems that sizeof() reports the structure size as 24 bytes including 4 padding bytes after CRC32. These padding bytes are not zeroed out by the EDK II code and could take random values.
MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c hence produces a random Crc32 in CoreUpdateDebugTableCrc32():gBS->CalculateCrc32 ((VOID *)mDebugTable, sizeof (EFI_SYSTEM_TABLE_POINTER), &mDebugTable->Crc32);
BaseTools/Scripts/efi_debugging.py:1824 calculates the CRC32 as if the padding bytes were zero even if they are not non-zero. This may lead to not finding the System Table Pointer at all.
The specification should explicitly state how the Crc32 field is to be calculated in the presence of padding bytes.
My suggestion would be change the specification to define the structure as packed so that we don't have to worry about any padding bytes:
"Eventual padding bytes after the Crc32 field are not considered in the calculation of the Crc32 value."
Best regards
Heinrich
PATCH v8 2/5 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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH v8 3/5 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().
---
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
@@ -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
Re: [PATCH v8 3/5] lib: efi_loader: efi_memory.c: add efi_realloc() for realloc memory
Hi Paul
Quoted 66 lines · Ying-Chun Liu (PaulLiu)
From: "Ying-Chun Liu (PaulLiu)" <[email protected]>
Add
efi_realloc()for realloc memory that previously alloc byefi_alloc().Signed-off-by Ying-Chun Liu (PaulLiu) <[email protected]>Cc Heinrich Schuchardt <[email protected]>Cc Ilias Apalodimas <[email protected]>Cc Peter Robinson <[email protected]>Cc Simon Glass <[email protected]>---
V4: Fixefi_reallocreturn failure code.
V6: Return error status whenefi_allocfailed.--- include/efi_loader.h | 10 +++++++ lib/efi_loader/efi_memory.c | 58 +++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+)include/efi_loader.h +10
-0@@ -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 +19
-0@@ -666,6 +666,64 @@ void *efi_alloc(size_t size)return buf; } +/** +* 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 old buffer +* @size: number of bytes to allocate +* Return: EFI status to indicate success or not +*/ +efi_status_t efi_realloc (void **ptr,size_t size) +{ +efi_status_t ret; +void *new_ptr; +struct efi_pool_allocation *alloc; +u64 num_pages =efi_size_in_pages (size + +sizeof (struct efi_pool_allocation )); +size_t old_size; + +if (!*ptr) {
lib/efi_loader/efi_memory.c void *efi_alloc(size_t size) · line 697
Quoted 10 lines
lib/efi_loader/efi_memory.c +10
-0+ *ptr =efi_alloc (size); +if (*ptr) +return EFI_SUCCESS ; +return EFI_OUT_OF_RESOURCES ; + } + + ret =efi_check_allocated ((uintptr_t )*ptr, true); +if (ret !=EFI_SUCCESS ) +return ret; +
Don't we also need a check here that the memory type you are trying to reallocate is Boot Services Data?
If someone uses this currently to reallocate memory, it will change whatever type he has to BDS.
You either add a check or better don't use efi_alloc(). Use efi_allocate_pool() and preserve the type.
lib/efi_loader/efi_memory.c void *efi_alloc(size_t size) · line 709
Quoted 12 lines
lib/efi_loader/efi_memory.c +12
-0+ alloc = container_of(*ptr, struct efi_pool_allocation, data); + +/* Check that this memory was allocated by efi_allocate_pool() */ +if (((uintptr_t )alloc &EFI_PAGE_MASK ) || + alloc->checksum !=checksum (alloc)) { +printf ("%s: illegal realloc 0x%p\n" , __func__, *ptr); +return EFI_INVALID_PARAMETER ; + } + +/* Don't realloc. The actual size in pages is the same. */ +if (alloc->num_pages == num_pages) +return EFI_SUCCESS ;
What if the size is smaller? Can't we just free the extra pages instead of reallocing?
Quoted 21 lines
lib/efi_loader/efi_memory.c +17
-1+ + old_size = alloc->num_pages *EFI_PAGE_SIZE - +sizeof (struct efi_pool_allocation ); + + new_ptr =efi_alloc (size); + +/* copy old data to new alloced buffer */ +memcpy (new_ptr, *ptr,min (size, old_size)); + +/* free the old buffer */ +efi_free_pool (*ptr); + + *ptr = new_ptr; + +return EFI_SUCCESS ; +} +/** * efi_free_pool() - free memory from pool * --
Quoted 2 lines
2.39.5
Thanks
/Ilias
Ilias Apalodimas
Reviewed-byRe: [PATCH v8 3/5] lib: efi_loader: efi_memory.c: add efi_realloc() for realloc memory
Quoted 87 lines · Ilias Apalodimas
Hi Paul
Quoted 66 lines · Ying-Chun Liu (PaulLiu)
From: "Ying-Chun Liu (PaulLiu)" <[email protected]>
Add
efi_realloc()for realloc memory that previously alloc byefi_alloc().Signed-off-by Ying-Chun Liu (PaulLiu) <[email protected]>Cc Heinrich Schuchardt <[email protected]>Cc Ilias Apalodimas <[email protected]>Cc Peter Robinson <[email protected]>Cc Simon Glass <[email protected]>---
V4: Fixefi_reallocreturn failure code.
V6: Return error status whenefi_allocfailed.--- include/efi_loader.h | 10 +++++++ lib/efi_loader/efi_memory.c | 58 +++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+)include/efi_loader.h +10
-0@@ -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 +19
-0@@ -666,6 +666,64 @@ void *efi_alloc(size_t size)return buf; } +/** +* 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 old buffer +* @size: number of bytes to allocate +* Return: EFI status to indicate success or not +*/ +efi_status_t efi_realloc (void **ptr,size_t size) +{ +efi_status_t ret; +void *new_ptr; +struct efi_pool_allocation *alloc; +u64 num_pages =efi_size_in_pages (size + +sizeof (struct efi_pool_allocation )); +size_t old_size; + +if (!*ptr) {lib/efi_loader/efi_memory.c void *efi_alloc(size_t size) · line 697
Quoted 10 lines
lib/efi_loader/efi_memory.c +10
-0+ *ptr =efi_alloc (size); +if (*ptr) +return EFI_SUCCESS ; +return EFI_OUT_OF_RESOURCES ; + } + + ret =efi_check_allocated ((uintptr_t )*ptr, true); +if (ret !=EFI_SUCCESS ) +return ret; +Don't we also need a check here that the memory type you are trying to reallocate is Boot Services Data?
If someone uses this currently to reallocate memory, it will change whatever type he has to BDS.
Quoted 2 lines
You either add a check or better don't use
efi_alloc(). Useefi_allocate_pool()and preserve the type.
I am fine picking this up as is, since we dont have any consumers yet -- as long as you send a follow up with either the check of conver efi_realloc to efi_allocate_pool and preserve the type
memory is realloced it's explicitly converted to BootServicesData
Quoted 43 lines
lib/efi_loader/efi_memory.c void *efi_alloc(size_t size) · line 709
Quoted 13 lines
lib/efi_loader/efi_memory.c +12
-0+ alloc = container_of(*ptr, struct efi_pool_allocation, data); + +/* Check that this memory was allocated by efi_allocate_pool() */ +if (((uintptr_t )alloc &EFI_PAGE_MASK ) || + alloc->checksum !=checksum (alloc)) { +printf ("%s: illegal realloc 0x%p\n" , __func__, *ptr); +return EFI_INVALID_PARAMETER ; + } + +/* Don't realloc. The actual size in pages is the same. */ +if (alloc->num_pages == num_pages) +return EFI_SUCCESS ;What if the size is smaller? Can't we just free the extra pages instead of reallocing?
Quoted 21 lines
lib/efi_loader/efi_memory.c +17
-1+ + old_size = alloc->num_pages *EFI_PAGE_SIZE - +sizeof (struct efi_pool_allocation ); + + new_ptr =efi_alloc (size); + +/* copy old data to new alloced buffer */ +memcpy (new_ptr, *ptr,min (size, old_size)); + +/* free the old buffer */ +efi_free_pool (*ptr); + + *ptr = new_ptr; + +return EFI_SUCCESS ; +} +/** * efi_free_pool() - free memory from pool * -- Quoted 2 lines
2.39.5
Thanks
/Ilias
PATCH v8 4/5 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.
---
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
@@ -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
@@ -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
@@ -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
Re: [PATCH v8 4/5] efi: add EFI_DEBUG_IMAGE_INFO for debug
Quoted 11 lines · Ying-Chun Liu (PaulLiu)
From: "Ying-Chun Liu (PaulLiu)" <[email protected]>
This commit adds the functionality of generate
EFI_DEBUG_IMAGE_INFOwhile 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 6 lines
Signed-off-by Ying-Chun Liu (PaulLiu) <[email protected]>Tested-by Heinrich Schuchardt <[email protected]>Cc Ilias Apalodimas <[email protected]>Cc Peter Robinson <[email protected]>Cc Simon Glass <[email protected]>---
Quoted 222 lines
V2: use
Kconfigoptions to turn on/off this feature.
V3: Useefi_reallocto realloc the tables. Move tables to boot time.
V4: Use newefi_realloc().
V5: Fix function comments and move the code into a separate module.
V6: refine the code. Handling the error ofefi_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@@ -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@@ -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@@ -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
-1@@ -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 * @@ -44,3 +51,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. +* +* @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 && + 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); + +memmove (&table[index], + &table[index +1 ], + (efi_m_debug_info_table_header.table_size - + index -1 ) *EFI_DEBUG_TABLE_ENTRY_SIZE ); + +/* 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 ; +} --2.39.5
PATCH v8 5/5 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.
---
V7: add selftest for EFI_DEBUG_SUPPORT
V8: refine the selftest.
--- lib/efi_selftest/Makefile | 2 + lib/efi_selftest/efi_selftest_debug_support.c | 40 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 lib/efi_selftest/efi_selftest_debug_support.c
lib/efi_selftest/Makefile +2 -0
@@ -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 +40 -0
@@ -0,0 +1,40 @@ +// 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> + +/** +* efi_st_debug_support_execute() - execute test +* +* 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 ; + +/* get EFI_DEBUG_IMAGE_INFO_TABLE */ + efi_st_debug_info_table_header =efi_st_get_config_table (&efi_debug_image_info_table_guid); + +if (!efi_st_debug_info_table_header) { +efi_st_error ("Missing EFI_DEBUG_IMAGE_INFO_TABLE\n" ); +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, +};
Signature · 1 line
2.39.5
Re: [PATCH v8 5/5] efi: selftest: add selftest for EFI_DEBUG_SUPPORT
Quoted 8 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.
Signed-off-by Ying-Chun Liu (PaulLiu) <[email protected]>Cc Heinrich Schuchardt <[email protected]>Cc Ilias Apalodimas <[email protected]>
Quoted 68 lines
---
V7: add selftest forEFI_DEBUG_SUPPORT
V8: refine the selftest.--- lib/efi_selftest/Makefile | 2 + lib/efi_selftest/efi_selftest_debug_support.c | 40 +++++++++++++++++++ 2 files changed, 42 insertions(+)create mode 100644
lib/efi_selftest/efi_selftest_debug_support.clib/efi_selftest/Makefile +2
-0@@ -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 +40
-0@@ -0,0 +1,40 @@ +// 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> + +/** +* efi_st_debug_support_execute() - execute test +* +* 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 ; + +/* get EFI_DEBUG_IMAGE_INFO_TABLE */ + efi_st_debug_info_table_header =efi_st_get_config_table (&efi_debug_image_info_table_guid); + +if (!efi_st_debug_info_table_header) { +efi_st_error ("Missing EFI_DEBUG_IMAGE_INFO_TABLE\n" ); +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, +};
Re: [PATCH v8 5/5] efi: selftest: add selftest for EFI_DEBUG_SUPPORT
In reply to Ying-Chun Liu (PaulLiu)Quoted 6 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.
Quoted 7 lines
Signed-off-by Ying-Chun Liu (PaulLiu) <[email protected]>Cc Heinrich Schuchardt <[email protected]>Cc Ilias Apalodimas <[email protected]>---
V7: add selftest forEFI_DEBUG_SUPPORT
V8: refine the selftest.
---
Quoted 67 lines
lib/efi_selftest/Makefile | 2 + lib/efi_selftest/efi_selftest_debug_support.c | 40 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 lib/efi_selftest/efi_selftest_debug_support.clib/efi_selftest/Makefile +2
-0@@ -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 +40
-1@@ -0,0 +1,40 @@ +// 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> + +/** +* efi_st_debug_support_execute() - execute test +* +* 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 ; + +/* get EFI_DEBUG_IMAGE_INFO_TABLE */ + efi_st_debug_info_table_header =efi_st_get_config_table (&efi_debug_image_info_table_guid); + +if (!efi_st_debug_info_table_header) { +efi_st_error ("Missing EFI_DEBUG_IMAGE_INFO_TABLE\n" ); +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, +}; --2.39.5