Add ESRT and test ESRT creation
v7 cover Add ESRT and test ESRT creation
The following 4 commits add the ESRT and provide tests for the functionality.
The first commit adds the ESRT as defined in the UEFI 2.8 specification. An empty ESRT is created during the execution of the efi_init_obj_list(). The ESRT is updated when:
1) a FMP protocol is installed in the system: this will add the
corresponding entries to the ESRT.
2) a capsule is installed via UpdateCapsule: this should update
entries already present in the ESRT.
This implementation of the ESRT creation takes input from FMP only. It is assumed that the FMP will maintain the following values across reboot:
- LastAttemptVersion.
- LastAttemptStatus.
The second commit introduces a helper cmd function to print the ESRT in the u-boot shell.
The third and forth commits contain two test for the ESRT creation in the sandbox platform.
- Test 1 executes from the u-boot shell with "bootefi selftest".
- Test 2 executes in the pytest environment.
Patch v7:
- Address v6 comments.
Patch v6:
- split the v5 3/3 commit into v6 3/4 (efi selftest) and v6 4/4 (addition to test_efi_capsule_fw3).
- Address v5 comments.
Patch v5:
- Address v4 comments.
- split the v4 2/2 commit into the v5 2/3 (debug print ESRT) and 3/3 (ESRT tests).
Patch v4:
- update stale [Patch 1/2 v3] commit message.
Patch v3:
- Address v2 comments.
Patch v2:
- The ESRT is now regenerated from scratch at every FMP EVT_NOTIFY_SIGNAL and whenever a capsule is updated.
- Extended TestEfiCapsuleFirmwareFit::test_efi_capsule_fw3 to verify that the ESRT is correctly populated after an UpdateCapsule.
- Addressed v1 comments.
Patch v1:
- reworked the ESRT creation code, allowing table to resize as FMPs are installed.
- registered a callback for the FMP protocol install.
- Created a unit test running on the sandbox platform.
rfc: initial patch submission
Jose Marinho (4):
efi: Add ESRT to the EFI system table
cmd: efi: ESRT table debug print
efi: ESRT creation tests
Test the ESRT creation within an existing pytest.
cmd/efidebug.c | 88 +++ include/efi_api.h | 21 + include/efi_loader.h | 24 + lib/efi_loader/Kconfig | 7 + lib/efi_loader/Makefile | 1 + lib/efi_loader/efi_boottime.c | 7 +- lib/efi_loader/efi_capsule.c | 8 + lib/efi_loader/efi_esrt.c | 510 ++++++++++++++++++ lib/efi_loader/efi_setup.c | 6 + lib/efi_selftest/Makefile | 2 + lib/efi_selftest/efi_selftest_esrt.c | 291 ++++++++++ .../test_efi_capsule/test_capsule_firmware.py | 8 + 12 files changed, 969 insertions(+), 4 deletions(-) create mode 100644 lib/efi_loader/efi_esrt.c create mode 100644 lib/efi_selftest/efi_selftest_esrt.c
Signature · 1 line
2.17.1
PATCH v7 1/4 efi: Add ESRT to the EFI system table
The ESRT is initialised during efi_init_objlist after efi_initialize_system_table().
The ESRT is recreated from scratch at the following events:
- successful UpdateCapsule;
- FMP instance install.
The code ensures that every ESRT entry has a unique fw_class value.
Limitations:
- The ESRT is not updated if an FMP instance is uninstalled;
- the fields image_type and flags are in the current implementation left undefined. Setting these values will require a per-platform function that returns the image_type/flags as a function of the image fw_class.
Remove two EFI_CALL() indirections.
Move ESRT GUID in efidebug's list of GUIDs.
--- cmd/efidebug.c | 4 + include/efi_api.h | 21 ++ include/efi_loader.h | 24 ++ lib/efi_loader/Kconfig | 7 + lib/efi_loader/Makefile | 1 + lib/efi_loader/efi_boottime.c | 7 +- lib/efi_loader/efi_capsule.c | 8 + lib/efi_loader/efi_esrt.c | 510 ++++++++++++++++++++++++++++++++++ lib/efi_loader/efi_setup.c | 6 + 9 files changed, 584 insertions(+), 4 deletions(-) create mode 100644 lib/efi_loader/efi_esrt.c
cmd/efidebug.c +4 -0
@@ -516,6 +516,10 @@ static const struct {"ACPI table" ,EFI_ACPI_TABLE_GUID , }, + { +"EFI System Resource Table" , +EFI_SYSTEM_RESOURCE_TABLE_GUID , + }, {"device tree" , EFI_FDT_GUID,
include/efi_api.h +21 -0
@@ -1722,6 +1722,23 @@ struct efi_load_file_protocol { void *buffer); }; +struct efi_system_resource_entry { +efi_guid_t fw_class; +u32 fw_type; +u32 fw_version; +u32 lowest_supported_fw_version; +u32 capsule_flags; +u32 last_attempt_version; +u32 last_attempt_status; +} __packed; + +struct efi_system_resource_table { +u32 fw_resource_count; +u32 fw_resource_count_max; +u64 fw_resource_version; +struct efi_system_resource_entry entries[]; +} __packed; +/* Boot manager load options */ #define LOAD_OPTION_ACTIVE 0x00000001#define LOAD_OPTION_FORCE_RECONNECT 0x00000002
@@ -1740,6 +1757,10 @@ struct efi_load_file_protocol {#define ESRT_FW_TYPE_DEVICEFIRMWARE 0x00000002#define ESRT_FW_TYPE_UEFIDRIVER 0x00000003 +#define EFI_SYSTEM_RESOURCE_TABLE_GUID \ + EFI_GUID(0xb122a263, 0x3661, 0x4f68,\ + 0x99, 0x29, 0x78, 0xf8, 0xb0, 0xd6, 0x21, 0x80) +/* Last Attempt Status Values */ #define LAST_ATTEMPT_STATUS_SUCCESS 0x00000000#define LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL 0x00000001
include/efi_loader.h +24 -0
@@ -214,6 +214,8 @@ extern const efi_guid_t efi_guid_rng_protocol;extern const efi_guid_t efi_guid_capsule_report;/* GUID of firmware management protocol */ extern const efi_guid_t efi_guid_firmware_management_protocol; +/* GUID for the ESRT */ +extern const efi_guid_t efi_esrt_guid;extern unsigned int __efi_runtime_start, __efi_runtime_stop;extern unsigned int __efi_runtime_rel_start, __efi_runtime_rel_stop;
@@ -558,6 +560,10 @@ struct efi_simple_file_system_protocol *efi_simple_file_system(/* open file from device-path: */ struct efi_file_handle *efi_file_from_path (struct efi_device_path *fp); +/* Registers a callback function for a notification event. */ +efi_status_t EFIAPI efi_register_protocol_notify(const efi_guid_t *protocol, +struct efi_event *event, +void **registration);/** * efi_size_in_pages() - convert size in bytes to size in pages *
@@ -890,4 +896,22 @@ static inline efi_status_t efi_launch_capsules(void)#endif /* CONFIG_IS_ENABLED(EFI_LOADER) */ +/** +* Install the ESRT system table. +* +* @return status code +*/ +efi_status_t efi_esrt_register (void ); + +/** +* efi_esrt_populate() - Populates the ESRT entries from the FMP instances +* present in the system. +* If an ESRT already exists, the old ESRT is replaced in the system table. +* The memory of the old ESRT is deallocated. +* +* Return: +* - EFI_SUCCESS if the ESRT is correctly created +* - error code otherwise. +*/ +efi_status_t efi_esrt_populate (void );#endif /* _EFI_LOADER_H */
lib/efi_loader/Kconfig +7 -0
@@ -347,4 +347,11 @@ config EFI_SECURE_BOOT it is signed with a trusted key. To do that, you need to install, at least, PK, KEK and db. +config EFI_ESRT + bool "Enable the UEFI ESRT generation" + depends on EFI_CAPSULE_FIRMWARE_MANAGEMENT + default y + help + Enabling this option creates the ESRT UEFI system table. + endif
lib/efi_loader/Makefile +1 -0
@@ -52,6 +52,7 @@ obj-y += efi_variable.o obj-$(CONFIG_EFI_VARIABLES_PRESEED) += efi_var_seed.o endif obj-y += efi_watchdog.o +obj-$(CONFIG_EFI_ESRT) += efi_esrt.o obj-$(CONFIG_LCD) += efi_gop.o obj-$(CONFIG_DM_VIDEO) += efi_gop.o obj-$(CONFIG_PARTITIONS) += efi_disk.o
lib/efi_loader/efi_boottime.c +3 -4
@@ -1406,10 +1406,9 @@ out:* * Return: status code */ -static efi_status_t EFIAPI efi_register_protocol_notify( -const efi_guid_t *protocol, -struct efi_event *event, -void **registration) +efi_status_t EFIAPI efi_register_protocol_notify(const efi_guid_t *protocol, +struct efi_event *event, +void **registration) {struct efi_register_notify_event *item;efi_status_t ret =EFI_SUCCESS ;
lib/efi_loader/efi_capsule.c +8 -0
@@ -482,6 +482,14 @@ efi_status_t EFIAPI efi_update_capsule( goto out; } out: + +if (IS_ENABLED (CONFIG_EFI_ESRT )) { +/* Rebuild the ESRT to reflect any updated FW images. */ + ret =efi_esrt_populate (); +if (ret !=EFI_SUCCESS ) +log_warning ("EFI Capsule: failed to update ESRT\n" ); + } +return EFI_EXIT (ret); }
lib/efi_loader/efi_esrt.c new file +510 -0
510 lines not on this page · raw message
lib/efi_loader/efi_setup.c +6 -0
@@ -227,6 +227,12 @@ efi_status_t efi_init_obj_list(void)if (ret !=EFI_SUCCESS ) goto out; +if (IS_ENABLED (CONFIG_EFI_ESRT )) { + ret =efi_esrt_register (); +if (ret !=EFI_SUCCESS ) + goto out; + } +if (IS_ENABLED (CONFIG_EFI_TCG2_PROTOCOL )) { ret =efi_tcg2_register ();if (ret !=EFI_SUCCESS )
Signature · 1 line
2.17.1
PATCH v7 2/4 cmd: efi: ESRT table debug print
In reply to Jose MarinhoThis commit enables the ESRT printing from the u-boot shell by invoking:
- efidebug capsule esrt
--- cmd/efidebug.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+)
cmd/efidebug.c +84 -0
@@ -129,6 +129,82 @@ static int do_efi_capsule_show(struct cmd_tbl *cmdtp, int flag,return CMD_RET_SUCCESS ; } +#ifdef CONFIG_EFI_ESRT + +#define EFI_ESRT_FW_TYPE_NUM 4 +char *efi_fw_type_str[EFI_ESRT_FW_TYPE_NUM ] = {"unknown" ,"system FW" ,"device FW" , +"UEFI driver" }; + +#define EFI_ESRT_UPDATE_STATUS_NUM 9 +char *efi_update_status_str[EFI_ESRT_UPDATE_STATUS_NUM ] = {"success" ,"unsuccessful" , +"insufficient resources" ,"incorrect version" ,"invalid format" , +"auth error" ,"power event (AC)" ,"power event (batt)" , +"unsatisfied dependencies" }; + +#define EFI_FW_TYPE_STR_GET (idx) (\ +EFI_ESRT_FW_TYPE_NUM > (idx) ? efi_fw_type_str[(idx)] : "error"\ +) + +#define EFI_FW_STATUS_STR_GET (idx) (\ +EFI_ESRT_UPDATE_STATUS_NUM > (idx) ? efi_update_status_str[(idx)] : "error"\ +) + +/** +* do_efi_capsule_esrt() - manage UEFI capsules +* +* @cmdtp: Command table +* @flag: Command flag +* @argc: Number of arguments +* @argv: Argument array +* Return: CMD_RET_SUCCESS on success, +* CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure +* +* Implement efidebug "capsule esrt" sub-command. +* The prints the current ESRT table. +* +* efidebug capsule esrt +*/ +static int do_efi_capsule_esrt (struct cmd_tbl *cmdtp,int flag, +int argc,char *const argv[]) +{ +struct efi_system_resource_table *esrt =NULL ; + +if (argc !=1 ) +return CMD_RET_USAGE ; + +for (int idx =0 ; idx < systab.nr_tables; idx++) +if (!guidcmp (&efi_esrt_guid, &systab.tables[idx].guid)) + esrt = (struct efi_system_resource_table *)systab.tables[idx].table; + +if (!esrt) { +log_info ("ESRT: table not present\n" ); +return CMD_RET_SUCCESS ; + } + +printf ("========================================\n" ); +printf ("ESRT: fw_resource_count=%d\n" , esrt->fw_resource_count); +printf ("ESRT: fw_resource_count_max=%d\n" , esrt->fw_resource_count_max); +printf ("ESRT: fw_resource_version=%lld\n" , esrt->fw_resource_version); + +for (int idx =0 ; idx < esrt->fw_resource_count; idx++) { +printf ("[entry %d]==============================\n" , idx); +printf ("ESRT: fw_class=%pUL\n" , &esrt->entries[idx].fw_class); +printf ("ESRT: fw_type=%s\n" ,EFI_FW_TYPE_STR_GET (esrt->entries[idx].fw_type)); +printf ("ESRT: fw_version=%d\n" , esrt->entries[idx].fw_version); +printf ("ESRT: lowest_supported_fw_version=%d\n" , + esrt->entries[idx].lowest_supported_fw_version); +printf ("ESRT: capsule_flags=%d\n" , + esrt->entries[idx].capsule_flags); +printf ("ESRT: last_attempt_version=%d\n" , + esrt->entries[idx].last_attempt_version); +printf ("ESRT: last_attempt_status=%s\n" , +EFI_FW_STATUS_STR_GET (esrt->entries[idx].last_attempt_status)); + } +printf ("========================================\n" ); + +return CMD_RET_SUCCESS ; +} +#endif /* CONFIG_EFI_ESRT */ /** * do_efi_capsule_res() - show a capsule update result *
@@ -221,6 +297,10 @@ static struct cmd_tbl cmd_efidebug_capsule_sub[] = { "", ""), U_BOOT_CMD_MKENT(show, CONFIG_SYS_MAXARGS, 1, do_efi_capsule_show, "", ""), +#ifdef CONFIG_EFI_ESRT +U_BOOT_CMD_MKENT (esrt,CONFIG_SYS_MAXARGS ,1 , do_efi_capsule_esrt, +"" ,"" ), +#endifU_BOOT_CMD_MKENT (disk-update,0 ,0 , do_efi_capsule_on_disk_update,"" ,"" ), U_BOOT_CMD_MKENT(result, CONFIG_SYS_MAXARGS, 1, do_efi_capsule_res,
@@ -1584,6 +1664,10 @@ static char efidebug_help_text[] =" - show capsule information\n" "efidebug capsule result [<capsule result var>]\n" " - show a capsule update result\n" +#ifdef CONFIG_EFI_ESRT +"efidebug capsule esrt\n" + " - print the ESRT\n" +#endif "\n" #endif"efidebug devices\n"
Signature · 1 line
2.17.1
PATCH v7 3/4 efi: ESRT creation tests
In reply to Jose MarinhoThis commmit exercises the ESRT creation in a EFI selftest.
A fake FMP, with TEST_ESRT_NUM_ENTRIES FW images, is installed in the system leading to the corresponding ESRT entries being populated. The ESRT entries are checked against the datastructure used to initialize the FMP.
Invocation from the sandbox platform:
add to sandbox_defconfig:
+CONFIG_CMD_BOOTEFI_SELFTEST=y
make sandbox_capsule_defconfig all
./u-boot -d arch/sandbox/dts/test.dtb
bootefi selftest
--- lib/efi_selftest/Makefile | 2 + lib/efi_selftest/efi_selftest_esrt.c | 291 +++++++++++++++++++++++++++ 2 files changed, 293 insertions(+) create mode 100644 lib/efi_selftest/efi_selftest_esrt.c
lib/efi_selftest/Makefile +2 -0
@@ -72,6 +72,8 @@ ifeq ($(CONFIG_BLK)$(CONFIG_DOS_PARTITION),yy) obj-y += efi_selftest_block_device.o endif +obj-$(CONFIG_EFI_ESRT) += efi_selftest_esrt.o + targets += \ efi_miniapp_file_image_exception.h \ efi_miniapp_file_image_exit.h \
lib/efi_selftest/efi_selftest_esrt.c new file +291 -0
291 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v7 4/4 Test the ESRT creation within an existing pytest.
In reply to Jose MarinhoThis commit slightly extends test_efi_capsule_fw3.
In order to run the test the following must be added to sandbox_defconfig:
+CONFIG_CMD_SF=y
+CONFIG_CMD_MEMORY=y
+CONFIG_CMD_FAT=y
+CONFIG_DFU=y
The ESRT is printed in the u-boot shell by calling efidebug esrt. The test ensures that, after the capsule is installed, the ESRT contains entries with the GUIDs:
- EFI_FIRMWARE_IMAGE_TYPE_UBOOT_FIT_GUID;
- EFI_FIRMWARE_IMAGE_TYPE_UBOOT_RAW_GUID;
test invocation:
sudo ./test/py/test.py --bd sandbox -k capsule_fw3 -l --build
--- test/py/tests/test_efi_capsule/test_capsule_firmware.py | 8 ++++++++ 1 file changed, 8 insertions(+)
test/py/tests/test_efi_capsule/test_capsule_firmware.py +8 -0
@@ -229,6 +229,14 @@ class TestEfiCapsuleFirmwareFit(object): output = u_boot_console.run_command( 'env print -e -all Capsule0000') + output = u_boot_console.run_command_list(['efidebug capsule esrt']) + + # ensure that EFI_FIRMWARE_IMAGE_TYPE_UBOOT_FIT_GUID is in the ESRT. + assert 'AE13FF2D-9AD4-4E25-9AC8-6D80B3B22147' in ''.join(output) + + # ensure that EFI_FIRMWARE_IMAGE_TYPE_UBOOT_RAW_GUID is in the ESRT. + assert 'E2BB9C06-70E9-4B14-97A3-5A7913176E3F' in ''.join(output) + output = u_boot_console.run_command_list([ 'host bind 0 %s' % disk_img, 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
Signature · 1 line
2.17.1