Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8A5D1C4332F for ; Mon, 7 Feb 2022 18:22:09 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5BF5783BEC; Mon, 7 Feb 2022 19:21:33 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id F164983BCD; Mon, 7 Feb 2022 19:21:31 +0100 (CET) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id 8E155837E2 for ; Mon, 7 Feb 2022 19:21:28 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sughosh.ganu@linaro.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0054211B3; Mon, 7 Feb 2022 10:21:28 -0800 (PST) Received: from a076522.blr.arm.com (a076522.blr.arm.com [10.162.16.44]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id F3EB33F718; Mon, 7 Feb 2022 10:21:23 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Masami Hiramatsu , Patrick Delaunay , Patrice Chotard , Alexander Graf , AKASHI Takahiro , Simon Glass , Bin Meng , Ilias Apalodimas , Jose Marinho , Grant Likely , Tom Rini , Etienne Carriere , Sughosh Ganu Subject: [PATCH v4 06/11] stm32mp1: Populate ImageTypeId values in EFI_FIRMWARE_IMAGE_DESCRIPTOR array Date: Mon, 7 Feb 2022 23:49:56 +0530 Message-Id: <20220207182001.31270-7-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220207182001.31270-1-sughosh.ganu@linaro.org> References: <20220207182001.31270-1-sughosh.ganu@linaro.org> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean 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 --- 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