Skip to contentSkip to conversation

Add ESRT and test ESRT creation

RFC New Jose Marinho 1 participant 3 messages Jan 28, 2021

lore
Share & tools
lore
#0 lore raw

cover Add ESRT and test ESRT creation

The following 2 commits add the ESRT and provide some intial testing.

The first commit adds the ESRT as defined in the UEFI 2.8 specification. The ESRT is created during the execution of the efi_init_obj_list(). The ESRT will, during initialization, look for FMP instances already present in the system and populate the corresponding FW image entries.

When a new FMP is added, via efi_add_protocol(), the
method esrt_add_from_fmp() is called to populate the corresponding ESRT entries.

The second commit creates a fake FMP instance with the intent of testing the code populating the ESRT entries.

CC Heinrich Schuchardt <[email protected]>
CC Sughosh Ganu <[email protected]>
CC AKASHI Takahiro <[email protected]>
CC Andre Przywara <[email protected]>
CC Alexander Graf <[email protected]>
CC nd at arm.com

Jose Marinho (2):
efi: Add ESRT to the EFI system table
efi: Add fake FMP instance to test ESRT creation

 include/efi_api.h             |  21 +++
 include/efi_loader.h          |  22 +++
 lib/efi_loader/Makefile       |   2 +
 lib/efi_loader/efi_boottime.c |  12 ++
 lib/efi_loader/efi_esrt.c     | 294 ++++++++++++++++++++++++++++++++++
 lib/efi_loader/efi_fake_fmp.c | 172 ++++++++++++++++++++
 lib/efi_loader/efi_setup.c    |   4 +
 7 files changed, 527 insertions(+)
 create mode 100644 lib/efi_loader/efi_esrt.c
 create mode 100644 lib/efi_loader/efi_fake_fmp.c
Signature · 1 line
2.17.1
#1 lore raw

RFC 1/2 efi: Add ESRT to the EFI system table

The ESRT is initialised during efi_init_objlist, after efi_initialize_system_table().

In this commit, the ESRT occupies at most one page.
During initialization, the list of all the already existing FMP instances is traversed in order to fill the corresponsing entries.

Later, when any FMP is added, the corresponding ESRT entries are initialized as long as there is available entries in the table.

CC Heinrich Schuchardt <[email protected]>
CC Sughosh Ganu <[email protected]>
CC AKASHI Takahiro <[email protected]>
CC Andre Przywara <[email protected]>
CC Alexander Graf <[email protected]>
CC nd at arm.com
---
 include/efi_api.h             |  21 +++
 include/efi_loader.h          |  22 +++
 lib/efi_loader/Makefile       |   1 +
 lib/efi_loader/efi_boottime.c |  12 ++
 lib/efi_loader/efi_esrt.c     | 294 ++++++++++++++++++++++++++++++++++
 lib/efi_loader/efi_setup.c    |   4 +
 6 files changed, 354 insertions(+)
 create mode 100644 lib/efi_loader/efi_esrt.c
include/efi_api.h +21 -0
index 48e48a6263..f4a88603e9 100644
@@ -1722,6 +1722,23 @@ struct efi_load_file_protocol {
 					 void *buffer);
 };
 
+struct efi_system_resource_entry {
+	efi_guid_t fw_class;
+	uint32_t fw_type;
+	uint32_t fw_version;
+	uint32_t lowest_supported_fw_version;
+	uint32_t capsule_flags;
+	uint32_t last_attempt_version;
+	uint32_t last_attempt_status;
+} __attribute__((__packed__));
+
+struct efi_system_resource_table {
+	uint32_t fw_resource_count;
+	uint32_t fw_resource_count_max;
+	uint64_t fw_resource_version;
+	struct efi_system_resource_entry entries[];
+} __attribute__((__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 +22 -0
index f470bbd636..7b20ec1ad2 100644
@@ -884,4 +884,26 @@ 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);
+
+/**
+ * esrt_add_from_fmp() - Populates a sequence of ESRT entries from the FW
+ * images in the FMP.
+ *
+ * @fmp:        the fmp from which fw images are added to the ESRT
+ * @image_type: the type of the FW image in the ESRT entry
+ * @flags:      the capsule flags to be set in the ESRT entry
+ *
+ * Return:
+ * - EFI_SUCCESS if all the FW images in the FMP are added to the ESRT
+ * - Error status otherwise
+ */
+efi_status_t esrt_add_from_fmp(struct efi_firmware_management_protocol *fmp,
+	u32 image_type, u32 flags);
+
 #endif /* _EFI_LOADER_H */
lib/efi_loader/Makefile +1 -0
index 10b42e8847..dec791b310 100644
@@ -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-y += 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 +12 -0
index ce658a8e73..8077b467c7 100644
@@ -1150,6 +1150,18 @@ efi_status_t efi_add_protocol(const efi_handle_t handle,
 
 	if (!guidcmp(&efi_guid_device_path, protocol))
 		EFI_PRINT("installed device path '%pD'\n", protocol_interface);
+
+	if (!guidcmp(&efi_guid_firmware_management_protocol, protocol)) {
+		EFI_PRINT("installed FMP, updating ESRT entries\n");
+
+		ret = esrt_add_from_fmp((struct efi_firmware_management_protocol *)
+			protocol_interface, ESRT_FW_TYPE_UNKNOWN, 0);
+		if (ret != EFI_SUCCESS) {
+			EFI_PRINT("Failed to update FMP ESRT entries\n");
+			return ret;
+		}
+	}
+
 	return EFI_SUCCESS;
 }
 
lib/efi_loader/efi_esrt.c new file +294 -0

294 lines not on this page · raw message

lib/efi_loader/efi_setup.c +4 -0
index 5800cbf6d4..7660a20822 100644
@@ -231,6 +231,10 @@ efi_status_t efi_init_obj_list(void)
 	if (ret != EFI_SUCCESS)
 		goto out;
 
+	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
#2 lore raw

RFC 2/2 efi: Add fake FMP instance to test ESRT creation

In reply to Jose Marinho

The intent of this commit is to exercise the ESRT creation -- introduced in the previous commit.

The fake FMP overrides the symbol arch_efi_load_capsule_drivers(). The fake FMP only implements the get_image_info FMP method. This get_image_info returns an image descriptor with a single image.

CC Heinrich Schuchardt <[email protected]>
CC Sughosh Ganu <[email protected]>
CC AKASHI Takahiro <[email protected]>
CC Andre Przywara <[email protected]>
CC Alexander Graf <[email protected]>
CC nd at arm.com
---
 lib/efi_loader/Makefile       |   1 +
 lib/efi_loader/efi_fake_fmp.c | 172 ++++++++++++++++++++++++++++++++++
 2 files changed, 173 insertions(+)
 create mode 100644 lib/efi_loader/efi_fake_fmp.c
lib/efi_loader/Makefile +1 -0
index dec791b310..8888ea193d 100644
@@ -53,6 +53,7 @@ obj-$(CONFIG_EFI_VARIABLES_PRESEED) += efi_var_seed.o
 endif
 obj-y += efi_watchdog.o
 obj-y += efi_esrt.o
+obj-y += efi_fake_fmp.o
 obj-$(CONFIG_LCD) += efi_gop.o
 obj-$(CONFIG_DM_VIDEO) += efi_gop.o
 obj-$(CONFIG_PARTITIONS) += efi_disk.o
lib/efi_loader/efi_fake_fmp.c new file +172 -0

172 lines not on this page · raw message

Signature · 1 line
2.17.1