Add EFI Debug Support Table feature
v4 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.
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 | 7 ++ lib/efi_loader/efi_boottime.c | 174 ++++++++++++++++++++++++++++++++++ lib/efi_loader/efi_memory.c | 56 +++++++++++ lib/efi_loader/efi_setup.c | 25 +++++ 6 files changed, 352 insertions(+)
Signature · 1 line
2.39.5
PATCH v4 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.
--- include/efi_api.h | 16 +++++++++++++++ include/efi_loader.h | 2 ++ lib/efi_loader/Kconfig | 7 +++++++ lib/efi_loader/efi_boottime.c | 37 +++++++++++++++++++++++++++++++++++ lib/efi_loader/efi_setup.c | 8 ++++++++ 5 files changed, 70 insertions(+)
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 +7 -0
@@ -71,6 +71,13 @@ config EFI_SECURE_BOOT config EFI_SIGNATURE_SUPPORT bool +config EFI_DEBUG_SUPPORT_TABLE + bool "EFI Debug Support Table" + help + Select this option if you want to setup the EFI Debug Support + Table 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/efi_boottime.c +37 -0
@@ -4001,6 +4001,8 @@ struct efi_system_table __efi_runtime_data systab = { .tables = NULL, }; +struct efi_system_table_pointer __efi_runtime_data * systab_pointer = NULL; +/** * efi_initialize_system_table() - Initialize system table *
@@ -4035,3 +4037,38 @@ efi_status_t efi_initialize_system_table(void)return ret; } + +/** +* efi_initialize_system_table() - Initialize system table pointer +* +* Return: status code +*/ +efi_status_t efi_initialize_system_table_pointer (void ) +{ +const int size_4MB =0x00400000 ; +u64 addr; +u32 crc32_value; + +/* Allocate configuration table array */ + addr = (u64 )efi_alloc_aligned_pages (sizeof (struct efi_system_table_pointer ), +EFI_RUNTIME_SERVICES_DATA , + size_4MB); + +if (!addr) { +log_err ("Installing EFI system table pointer failed\n" ); +return EFI_OUT_OF_RESOURCES ; + } + + 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; + +return EFI_SUCCESS ; +}
lib/efi_loader/efi_setup.c +8 -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_TABLE )) { + 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 v4 1/4] efi: add EFI_SYSTEM_TABLE_POINTER for debug
Quoted 108 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]>Cc Heinrich Schuchardt <[email protected]>Cc Ilias Apalodimas <[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.--- include/efi_api.h | 16 +++++++++++++++ include/efi_loader.h | 2 ++ lib/efi_loader/Kconfig | 7 +++++++ lib/efi_loader/efi_boottime.c | 37 +++++++++++++++++++++++++++++++++++ lib/efi_loader/efi_setup.c | 8 ++++++++ 5 files changed, 70 insertions(+)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 +7
-0@@ -71,6 +71,13 @@ config EFI_SECURE_BOOT config EFI_SIGNATURE_SUPPORT bool +config EFI_DEBUG_SUPPORT_TABLE + bool "EFI Debug Support Table" + help + Select this option if you want to setup the EFI Debug Support + Table 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/efi_boottime.c +8
-0@@ -4001,6 +4001,8 @@ struct efi_system_table __efi_runtime_data systab = { .tables = NULL, }; +struct efi_system_table_pointer __efi_runtime_data * systab_pointer = NULL; +/** * efi_initialize_system_table() - Initialize system table * @@ -4035,3 +4037,38 @@ efi_status_t efi_initialize_system_table(void)return ret; } + +/** +* efi_initialize_system_table() - Initialize system table pointer +* +* Return: status code +*/
lib/efi_loader/efi_boottime.c efi_status_t efi_initialize_system_table(void) · line 4055
Quoted 10 lines
lib/efi_loader/efi_boottime.c +10
-0+efi_status_t efi_initialize_system_table_pointer (void ) +{ +const int size_4MB =0x00400000 ; +u64 addr; +u32 crc32_value; + +/* Allocate configuration table array */ + addr = (u64 )efi_alloc_aligned_pages (sizeof (struct efi_system_table_pointer ), +EFI_RUNTIME_SERVICES_DATA , + size_4MB);
We expect the code to compile after each individual step. Function efi_alloc_aligned_pages() does not exist when this step is applied.
Even if I apply all patches your code does not compile on 32bit systems:
+lib/efi_loader/efi_boottime.c:4072:16: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
+ 4072 | addr = (u64)efi_alloc_aligned_pages(sizeof(struct efi_system_table_pointer),
+ |
Use (uintptr_t) here.
Best regards
Heinrich
Quoted 38 lines
lib/efi_loader/efi_boottime.c +19
-0+ +if (!addr) { +log_err ("Installing EFI system table pointer failed\n" ); +return EFI_OUT_OF_RESOURCES ; + } + + 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; + +return EFI_SUCCESS ; +}lib/efi_loader/efi_setup.c +8
-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_TABLE )) { + 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 v4 1/4] efi: add EFI_SYSTEM_TABLE_POINTER for debug
Quoted 113 lines · Heinrich Schuchardt
Quoted 112 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]>Cc Heinrich Schuchardt <[email protected]>Cc Ilias Apalodimas <[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.
---
include/efi_api.h | 16 +++++++++++++++ include/efi_loader.h | 2 ++ lib/efi_loader/Kconfig | 7 +++++++lib/efi_loader/efi_boottime.c| 37 +++++++++++++++++++++++++++++++++++ lib/efi_loader/efi_setup.c | 8 ++++++++5 files changed, 70 insertions(+)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
+ * 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.
+ */include/efi_api.h +6
-0+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
-0@@ -71,6 +71,13 @@ config EFI_SECURE_BOOTconfig
EFI_SIGNATURE_SUPPORT
boollib/efi_loader/Kconfig +7
-0+config EFI_DEBUG_SUPPORT_TABLE + bool "EFI Debug Support Table" + help + Select this option if you want to setup the EFI Debug Support + Table which is used by the debug agent or an external debugger to + determine loaded image information in a quiescent manner. +menu "UEFI services"
configEFI_GET_TIMElib/efi_loader/efi_boottime.c +2
-0@@ -4001,6 +4001,8 @@ struct efi_system_table __efi_runtime_data systab = { .tables = NULL, }; +struct efi_system_table_pointer __efi_runtime_data * systab_pointer =NULL ; + /*** efi_initialize_system_table() - Initialize system table *
lib/efi_loader/efi_boottime.c +11
-0@@ -4035,3 +4037,38 @@ efi_status_t efi_initialize_system_table(void) return ret; } + +/** +* efi_initialize_system_table() - Initialize system table pointer +* +* Return: status code +*/ +efi_status_t efi_initialize_system_table_pointer (void ) +{ + const int size_4MB = 0x00400000; + u64 addr; + u32 crc32_value;
Quoted 8 lines
lib/efi_loader/efi_boottime.c efi_status_t efi_initialize_system_table(void) · line 4055
Quoted 6 lines
lib/efi_loader/efi_boottime.c +5
-0+ + /* Allocate configuration table array */ + addr = (u64)efi_alloc_aligned_pages(sizeof(structefi_system_table_pointer ), + EFI_RUNTIME_SERVICES_DATA, + size_4MB);We expect the code to compile after each individual step. Function
efi_alloc_aligned_pages()does not exist when this step is applied.
Sorry this function exits. But it does not work correctly on the sandbox as the LMB memory start is not 4 MiB aligned. I will send a series for this.
Quoted 54 lines
Even if I apply all patches your code does not compile on 32bit systems:
+lib/efi_loader/efi_boottime.c:4072:16: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
+ 4072 | addr = (u64)efi_alloc_aligned_pages(sizeof(structefi_system_table_pointer),
+ |Use (
uintptr_t) here.Best regards
Heinrich
Quoted 38 lines
lib/efi_loader/efi_boottime.c +11
-0+ + if (!addr) { + log_err("Installing EFI system table pointer failed\n"); + return EFI_OUT_OF_RESOURCES; + } + + 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;
lib/efi_loader/efi_boottime.c +8
-0+ + crc32_value = crc32(0, + (const unsigned char *)systab_pointer, + sizeof(struct efi_system_table_pointer)); + systab_pointer->crc32 = crc32_value; + + return EFI_SUCCESS; +}lib/efi_loader/efi_setup.c +8
-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_TABLE)) { + 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 v4 1/4] efi: add EFI_SYSTEM_TABLE_POINTER for debug
In reply to Ying-Chun Liu (PaulLiu)Quoted 72 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]>Cc Heinrich Schuchardt <[email protected]>Cc Ilias Apalodimas <[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.--- include/efi_api.h | 16 +++++++++++++++ include/efi_loader.h | 2 ++ lib/efi_loader/Kconfig | 7 +++++++ lib/efi_loader/efi_boottime.c | 37 +++++++++++++++++++++++++++++++++++ lib/efi_loader/efi_setup.c | 8 ++++++++ 5 files changed, 70 insertions(+)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 +0
-0
lib/efi_loader/Kconfig config EFI_SECURE_BOOT · line 79
Quoted 9 lines
lib/efi_loader/Kconfig +6
-0@@ -71,6 +71,13 @@ config EFI_SECURE_BOOT config EFI_SIGNATURE_SUPPORT bool +config EFI_DEBUG_SUPPORT_TABLE + bool "EFI Debug Support Table" + help + Select this option if you want to setup the EFI Debug Support + Table which is used by the debug agent or an external debugger to + determine loaded image information in a quiescent manner.
Please, mention that this also provides the EFI_SYSTEM_TABLE_POINTER.
The symbol should be called CONFIG_EFI_DEBUG_SUPPORT as it selects more than the EFI Debug Support Table.
Quoted 61 lines
lib/efi_loader/Kconfig +1
-0+ menu "UEFI services" config EFI_GET_TIMElib/efi_loader/efi_boottime.c +37
-0@@ -4001,6 +4001,8 @@ struct efi_system_table __efi_runtime_data systab = { .tables = NULL, }; +struct efi_system_table_pointer __efi_runtime_data * systab_pointer = NULL; +/** * efi_initialize_system_table() - Initialize system table * @@ -4035,3 +4037,38 @@ efi_status_t efi_initialize_system_table(void)return ret; } + +/** +* efi_initialize_system_table() - Initialize system table pointer +* +* Return: status code +*/ +efi_status_t efi_initialize_system_table_pointer (void ) +{ +const int size_4MB =0x00400000 ; +u64 addr; +u32 crc32_value; + +/* Allocate configuration table array */ + addr = (u64 )efi_alloc_aligned_pages (sizeof (struct efi_system_table_pointer ), +EFI_RUNTIME_SERVICES_DATA , + size_4MB); + +if (!addr) { +log_err ("Installing EFI system table pointer failed\n" ); +return EFI_OUT_OF_RESOURCES ; + } + + 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; + +return EFI_SUCCESS ; +}lib/efi_loader/efi_setup.c +0
-0
lib/efi_loader/efi_setup.c efi_status_t efi_init_obj_list(void) · line 282
Quoted 5 lines
lib/efi_loader/efi_setup.c +2
-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_TABLE )) {
Please, put all code that is enabled by CONFIG_EFI_DEBUG_SUPPORT_TABLE into a separate code module as it is not related to EFI boot services.
Best regards
Heinrich
Quoted 9 lines
lib/efi_loader/efi_setup.c +6
-0+ 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 )
PATCH v4 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.
--- include/efi_api.h | 53 ++++++++++++++++++++++++++++++++++++++ include/efi_loader.h | 2 ++ lib/efi_loader/efi_setup.c | 17 ++++++++++++ 3 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_setup.c +17 -0
@@ -18,6 +18,15 @@efi_status_t efi_obj_list_initialized =OBJ_LIST_NOT_INITIALIZED ; +struct efi_debug_image_info_table_header efi_m_debug_info_table_header = { +0 , +0 , +NULL +}; + +const efi_guid_t efi_debug_image_info_table_guid = +EFI_DEBUG_IMAGE_INFO_TABLE_GUID ; +/* * Allow unaligned memory access. *
@@ -280,10 +289,18 @@ efi_status_t efi_init_obj_list(void)/* Initialize system table pointer */ if (IS_ENABLED (CONFIG_EFI_DEBUG_SUPPORT_TABLE )) { +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 v4 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().
---
V4: Fix efi_realloc return failure code.
--- include/efi_loader.h | 10 +++++++ lib/efi_loader/efi_memory.c | 56 +++++++++++++++++++++++++++++++++++++ 2 files changed, 66 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 +56 -0
62 lines not on this page · raw message
Signature · 1 line
2.39.5
PATCH v4 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.
---
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().
--- include/efi_api.h | 2 + include/efi_loader.h | 5 ++ lib/efi_loader/efi_boottime.c | 137 ++++++++++++++++++++++++++++++++++ 3 files changed, 144 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 +137 -0
158 lines not on this page · raw message
Signature · 1 line
2.39.5
Re: [PATCH v4 4/4] efi: add EFI_DEBUG_IMAGE_INFO for debug
Quoted 98 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.
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]>---
V2: useKconfigoptions to turn on/off this feature.
V3: Useefi_reallocto realloc the tables. Move tables to boot time.
V4: Use newefi_realloc().--- include/efi_api.h | 2 + include/efi_loader.h | 5 ++ lib/efi_loader/efi_boottime.c | 137 ++++++++++++++++++++++++++++++++++ 3 files changed, 144 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 +18
-0@@ -2129,6 +2129,14 @@ efi_status_t EFIAPI efi_load_image(bool boot_policy, *image_handle =NULL ;free (info); } + +if (IS_ENABLED (CONFIG_EFI_DEBUG_SUPPORT_TABLE )) { +if (*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 +3367,9 @@ 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_TABLE )) { +efi_core_remove_debug_image_info_entry (image_handle); + }switch (efiobj->type) {case EFI_OBJECT_TYPE_STARTED_IMAGE :/* Call the unload function */ @@ -4038,6 +4049,13 @@ efi_status_t efi_initialize_system_table(void)return ret; } +/* 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() - Initialize system table pointer *
lib/efi_loader/efi_boottime.c efi_status_t efi_initialize_system_table_pointer(void) · line 4094
Quoted 5 lines
lib/efi_loader/efi_boottime.c +2
-0@@ -4072,3 +4090,122 @@ efi_status_t efi_initialize_system_table_pointer(void)return EFI_SUCCESS ; } + +/**
This is not a valid function description. See:
https://docs.kernel.org/doc-guide/kernel-doc.html#function-documentation
Please, run make htmldocs for testing.
Best regards
Heinrich
Quoted 117 lines
lib/efi_loader/efi_boottime.c +117
-0+* Add a new efi_loaded_image structure to the efi_debug_image_info Table. +* Re-Allocates the table if it's not large enough to accomidate another +* entry. +* +* @param image_info_type type of debug image information +* @param loaded_image pointer to the loaded image protocol for the image +* being loaded +* @param image_handle image handle for the image being loaded +* @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. */ +efi_allocate_pool (EFI_BOOT_SERVICES_DATA , +sizeof (union efi_debug_image_info ), + (void **)(&(*table)[index].normal_image)); +if ((*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 ; + } + + efi_m_debug_info_table_header.update_status &= + ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS ; + +return EFI_SUCCESS ; +} + +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); + +memcpy (&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 ; +}