[PATCH v4 06/11] stm32mp1: Populate ImageTypeId values in EFI_FIRMWARE_IMAGE_DESCRIPTOR array

Sughosh Ganu sughosh.ganu at linaro.org
Mon Feb 7 19:19:56 CET 2022


The EFI_FIRMWARE_IMAGE_DESCRIPTOR array is returned by the Firmware
Management Protocol's(FMP) GetImageInfo function. The image descriptor
array contains the ImageTypeId which is a GUID identifying the
firmware images that are supported by the instance of the FMP. These
ImageTypeId values are compared against the value in the capsule to
identify the FMP instance to be used for the capsule.

Add a function for the GPT partitioned device based ST platforms for
filling up the image descriptor array with the ImageTypeId values. For
the GPT partitioned devices, the array can be populated by reading the
GPT header which contains the Partition Entry Array, where each entry
contains the PartitionTypeGUID for the corresponding image.

Signed-off-by: Sughosh Ganu <sughosh.ganu at linaro.org>
---

Changes since V3:
* Define the function fill_image_type_guid_array for the ST DK2 board
  for GPT partitioned devices.

 board/st/stm32mp1/stm32mp1.c | 94 ++++++++++++++++++++++++++++++++++++
 1 file changed, 94 insertions(+)

diff --git a/board/st/stm32mp1/stm32mp1.c b/board/st/stm32mp1/stm32mp1.c
index 5525b69392..fc14c9808b 100644
--- a/board/st/stm32mp1/stm32mp1.c
+++ b/board/st/stm32mp1/stm32mp1.c
@@ -1021,4 +1021,98 @@ void fwu_plat_get_bootidx(void *boot_idx)
 
 	*bootidx = readl(TAMP_BOOTCOUNT);
 }
+
+static int fill_gpt_partition_guids(struct blk_desc *desc,
+				    efi_guid_t **part_guid_arr)
+{
+	int i;
+	u32 part;
+	int alt_num;
+	struct dfu_entity *dfu;
+	struct disk_partition info;
+	efi_guid_t part_type_guid;
+	efi_guid_t null_guid = NULL_GUID;
+	efi_status_t ret = EFI_SUCCESS;
+
+	dfu_init_env_entities(NULL, NULL);
+
+	alt_num = 0;
+	list_for_each_entry(dfu, &dfu_list, list) {
+		++alt_num;
+	}
+
+	if (!alt_num) {
+		log_warning("Probably dfu_alt_info not defined\n");
+		ret = EFI_NOT_READY;
+		goto out;
+	}
+
+	*part_guid_arr = malloc(sizeof(efi_guid_t) * alt_num);
+	if (!*part_guid_arr) {
+		ret = EFI_OUT_OF_RESOURCES;
+		goto out;
+	}
+
+	for (i = 0; i < alt_num; i++)
+		guidcpy((*part_guid_arr + i), &null_guid);
+
+	for (i = 0, part = 1; i < alt_num; i++) {
+		dfu = dfu_get_entity(i);
+
+		if (!dfu)
+			continue;
+
+		/*
+		 * Currently, Multi Bank update
+		 * feature is being supported
+		 * only on GPT partitioned
+		 * MMC/SD devices.
+		 */
+		if (dfu->dev_type != DFU_DEV_MMC)
+			continue;
+
+		if (part_get_info(desc, part, &info)) {
+			part++;
+			continue;
+		}
+
+		uuid_str_to_bin(info.type_guid, part_type_guid.b,
+				UUID_STR_FORMAT_GUID);
+		guidcpy((*part_guid_arr + i), &part_type_guid);
+		part++;
+	}
+
+out:
+	dfu_free_entities();
+
+	return ret;
+}
+
+efi_status_t fill_image_type_guid_array(const efi_guid_t __always_unused
+					*default_guid,
+					efi_guid_t **part_guid_arr)
+{
+	int ret;
+	struct udevice *dev;
+	struct blk_desc *desc;
+
+	/*
+	 * Get the storage device on which the
+	 * FWU metadata has been stored
+	 */
+	ret = fwu_get_mdata_device(&dev);
+	if (ret) {
+		log_err("Unable to get FWU metadata device\n");
+		return EFI_DEVICE_ERROR;
+	}
+
+	desc = dev_get_uclass_plat(dev);
+	if (!desc) {
+		log_err("Block device not found\n");
+		return EFI_DEVICE_ERROR;
+	}
+
+	return fill_gpt_partition_guids(desc, part_guid_arr);
+}
+
 #endif /* CONFIG_FWU_MULTI_BANK_UPDATE */
-- 
2.17.1



More information about the U-Boot mailing list