From patchwork Thu Nov 25 07:12:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 519377 Delivered-To: patch@linaro.org Received: by 2002:ac0:c605:0:0:0:0:0 with SMTP id p5csp369260imj; Wed, 24 Nov 2021 23:15:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJyu+FOptuE8ZuMX5hJcW45zR9i1F+Noyj9gaziFw6e7ejTv+tzwIhevds5uCMsw1YAX95DE X-Received: by 2002:a17:906:3e83:: with SMTP id a3mr29246938ejj.383.1637824508650; Wed, 24 Nov 2021 23:15:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1637824508; cv=none; d=google.com; s=arc-20160816; b=HMmeo9Kd9IN70hx/NY3EdlSRY4sjMqON14epH7T1Kj1szn5hwV95Ka8pVATpeJZdQt NcwgifOWNtrMCQ962QILHQecHsR4qZMVaoRWDyUFGNhtHmfc8M4aeYzdTE5b/QaHuCtW dBOhhlPfIz81SNkfwCO5xu9Mjn5HP2irAdDzRoQCPEOrc9yK6eFf5HNosKarsdsMCryG EWY8nY8aRyfoR6CceybgNnml2FnhrSk1UcMwQmtYRylDZtP0Ek+psv8J50ekAaPmYQxo UeDcewGvjEjtzMIx5aATsKdPR5vtUemJKwVEKR6vow+/Cm/pWIlS65XcPcOPEd/1GrLM LbOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:cc:to:from; bh=abU56v1pjQ/E2CNhri4oruoVyOH0Mjlpt/eWEKG1xJI=; b=QUXXvSkPvr7EJa8zn+cwTcOlzosG7l5Y0qO4L/MS5Nv4Gb0rIztBouleWgQ0DuKoSR IC3yQHnoUUrNyeiTA5Ir2W8xkIsI39R8Sk9aAQvQRIYYAw8gr/IvMVprNzFpmc5PoHRK MP13WyPkvwROoV3i0AS2+uGMrewflZYkR9WFx2mtP/uDkpk2l9zxFy2zeOX29Ywb4KZ+ ub2BmmDYOIR8nDY0xNhrhqk+P4U4XcyYd+knWXKEJqQD5+PuBKWZe/XGaCsaWcNZ1EsH 3iwctHavcnH/697bl34k58FyVZGvPZEzdmLc536ZEH2aO1LqMojKDQvMYyF3hmfWxce7 NjzA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id hh12si4719769ejb.335.2021.11.24.23.15.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Nov 2021 23:15:08 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8353C83742; Thu, 25 Nov 2021 08:14:26 +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 E9ABF83767; Thu, 25 Nov 2021 08:14:05 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_SOFTFAIL autolearn=no autolearn_force=no version=3.4.2 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id 6C2448373F for ; Thu, 25 Nov 2021 08:13:58 +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 D3118153B; Wed, 24 Nov 2021 23:13:57 -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 14A353F5A1; Wed, 24 Nov 2021 23:13:53 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Patrick Delaunay , Patrice Chotard , Heinrich Schuchardt , Alexander Graf , Simon Glass , Bin Meng , Peng Fan , AKASHI Takahiro , Ilias Apalodimas , Jose Marinho , Grant Likely , Jason Liu , Sughosh Ganu Subject: [RESEND RFC PATCH 07/10] EFI: FMP: Add provision to update image's ImageTypeId in image descriptor Date: Thu, 25 Nov 2021 12:42:59 +0530 Message-Id: <20211125071302.3644-8-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211125071302.3644-1-sughosh.ganu@linaro.org> References: <20211125071302.3644-1-sughosh.ganu@linaro.org> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.37 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.2 at phobos.denx.de X-Virus-Status: Clean The FWU Multi Banks Update feature allows updating different types of updatable firmware images on the platform. These image types are identified using the ImageTypeId GUID value. Add support in the GetImageInfo function of the FMP protocol to get the GUID values for the individual images and populate these in the image descriptor for the corresponding images. Signed-off-by: Sughosh Ganu --- lib/efi_loader/efi_firmware.c | 76 ++++++++++++++++++++++++++++++++--- 1 file changed, 71 insertions(+), 5 deletions(-) diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c index a1b88dbfc2..a2b639b448 100644 --- a/lib/efi_loader/efi_firmware.c +++ b/lib/efi_loader/efi_firmware.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -106,7 +107,8 @@ efi_status_t EFIAPI efi_firmware_set_package_info_unsupported( * @descriptor_size: Pointer to descriptor size * package_version: Package version * package_version_name: Package version's name - * image_type: Image type GUID + * guid_array: Image type GUID array + * nparts: Number of partions on the storage device * * Return information bout the current firmware image in @image_info. * @image_info will consist of a number of descriptors. @@ -122,7 +124,7 @@ static efi_status_t efi_get_dfu_info( efi_uintn_t *descriptor_size, u32 *package_version, u16 **package_version_name, - const efi_guid_t *image_type) + const efi_guid_t *guid_array, u32 nparts) { struct dfu_entity *dfu; size_t names_len, total_size; @@ -145,6 +147,19 @@ static efi_status_t efi_get_dfu_info( return EFI_SUCCESS; } + if (IS_ENABLED(CONFIG_FWU_MULTI_BANK_UPDATE)) { + /* + * For FWU multi bank updates, the number of partitions + * should at least be same as dfu partitions or less + */ + if (nparts > dfu_num) { + log_err("Number of dfu alt no's less than partitions\n"); + dfu_free_entities(); + + return EFI_INVALID_PARAMETER; + } + } + total_size = sizeof(*image_info) * dfu_num + names_len; /* * we will assume that sizeof(*image_info) * dfu_name @@ -172,7 +187,11 @@ static efi_status_t efi_get_dfu_info( next = name; list_for_each_entry(dfu, &dfu_list, list) { image_info[i].image_index = dfu->alt + 1; - image_info[i].image_type_id = *image_type; + if (IS_ENABLED(CONFIG_FWU_MULTI_BANK_UPDATE)) + image_info[i].image_type_id = guid_array[i]; + else + image_info[i].image_type_id = *guid_array; + image_info[i].image_id = dfu->alt; /* copy the DFU entity name */ @@ -249,7 +268,9 @@ efi_status_t EFIAPI efi_firmware_fit_get_image_info( u32 *package_version, u16 **package_version_name) { + u32 nparts; efi_status_t ret; + efi_guid_t *part_guid_arr; EFI_ENTRY("%p %p %p %p %p %p %p %p\n", this, image_info_size, image_info, @@ -264,12 +285,24 @@ efi_status_t EFIAPI efi_firmware_fit_get_image_info( !descriptor_size || !package_version || !package_version_name)) return EFI_EXIT(EFI_INVALID_PARAMETER); + part_guid_arr = malloc(sizeof(efi_guid_t)); + if (!part_guid_arr) { + log_err("Unable to allocate memory for guid array\n"); + ret = EFI_OUT_OF_RESOURCES; + goto out; + } + + guidcpy(part_guid_arr, &efi_firmware_image_type_uboot_fit); + nparts = 1; + ret = efi_get_dfu_info(image_info_size, image_info, descriptor_version, descriptor_count, descriptor_size, package_version, package_version_name, - &efi_firmware_image_type_uboot_fit); + part_guid_arr, nparts); +out: + free(part_guid_arr); return EFI_EXIT(ret); } @@ -358,7 +391,10 @@ efi_status_t EFIAPI efi_firmware_raw_get_image_info( u32 *package_version, u16 **package_version_name) { + u32 nparts; + int status; efi_status_t ret = EFI_SUCCESS; + efi_guid_t *part_guid_arr; EFI_ENTRY("%p %p %p %p %p %p %p %p\n", this, image_info_size, image_info, @@ -373,12 +409,42 @@ efi_status_t EFIAPI efi_firmware_raw_get_image_info( !descriptor_size || !package_version || !package_version_name)) return EFI_EXIT(EFI_INVALID_PARAMETER); + if (IS_ENABLED(CONFIG_FWU_MULTI_BANK_UPDATE)) { + /* + * Read the ImageType GUID values. Populate the guid array + * with thesevalues. These are the values to be used in the + * capsule for ImageTypeId. + */ + status = fwu_fill_partition_guid_array(&part_guid_arr, + &nparts); + if (status < 0) { + log_err("Unable to get partiion guid's\n"); + if (status == -EIO) + ret = EFI_DEVICE_ERROR; + else if (status == -ENOMEM) + ret = EFI_OUT_OF_RESOURCES; + goto out; + } + } else { + part_guid_arr = malloc(sizeof(efi_guid_t)); + if (!part_guid_arr) { + log_err("Unable to allocate memory for guid array\n"); + ret = EFI_OUT_OF_RESOURCES; + goto out; + } + + guidcpy(part_guid_arr, &efi_firmware_image_type_uboot_raw); + nparts = 1; + } + ret = efi_get_dfu_info(image_info_size, image_info, descriptor_version, descriptor_count, descriptor_size, package_version, package_version_name, - &efi_firmware_image_type_uboot_raw); + part_guid_arr, nparts); +out: + free(part_guid_arr); return EFI_EXIT(ret); }