From patchwork Thu Jan 11 05:35:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 761791 Delivered-To: patch@linaro.org Received: by 2002:a5d:6e02:0:b0:337:62d3:c6d5 with SMTP id h2csp2237172wrz; Wed, 10 Jan 2024 21:37:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IGGeY/zIAQNcve+2pwXKMo7wb4hTNa6a8NKZyN7F/po8jQJsYU7c8Z/ZYR0rtbacnqeJIWP X-Received: by 2002:a05:600c:1d0a:b0:40e:47d7:45fe with SMTP id l10-20020a05600c1d0a00b0040e47d745femr50470wms.12.1704951473081; Wed, 10 Jan 2024 21:37:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704951473; cv=none; d=google.com; s=arc-20160816; b=tOePo+se9JO+cwFf5lJIG7GBfgLzojc5e8BvjLgQ1vZCM4p+QLBanYlFqLJ+4m6ndj i2MyGKUHSftBt8SE4v9Ub4sYPGdjthuATB5nSJtP3xS75x19iC4+1/jRpa7Ce2Cr7yD8 AH2t2/Qu2vnrtO8hgqxpgCh03kO2Ut5bjmZzZcbs7MsIS1XIOn5UziAh05irf74S9qoW /BbtTxPJeF34aatARdpd3YV9oXMaV02uPMFLKNy7sA5dYSaYYVCDGuDtWAmCtAluN7/z vMm0A6ZKQgiJcUB4dOXKgtlv9E1IC2O8i40EKYFMwk+94M5XxEPYdHLr3JiKRtZiww9A EGnA== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=dJpAQqKZRU5gCSObJbfKhLiDyhlORb0+CJLUsG0YWwI=; fh=vrqNCSWbrItDl40TMygDgSHof0/XikFdntN3a1zOV74=; b=CsnVB/fQxz1JlbNEb4Ft8TA+J6dwc6dHOmwD4/LZufi6V9E5SrZ1Qj7ZWnEwSvVqRi RvnGfPrPbeEKOW3ldyHextFwAdkK/Yc3N07kHve1ppsWWbndKIzsWV4DZA+TjVlM7FC5 EcXVdzN7qfO9LeV1uZX8s+fi8Mgl2dBgtNQF4/DwK0FEwz6Zltt6fN0zrVmkOX4h/hQD 58pTNd6da20l+n067P1kyAVkce26TxK9vJax/OHZJwoQS/X/Dh9GAdQ1kHmUM7rWfduZ 0OyWS/BrglLcZ8G2Ywvn0vz9sDakinbiB7CufYG9gVzrrr4sUy/sXvlkNjyYdXQWCvoL NLkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mMcgwoQa; 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=pass (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 k3-20020a5d5183000000b0033680e6c4f1si114032wrv.377.2024.01.10.21.37.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 21:37:53 -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; dkim=pass header.i=@linaro.org header.s=google header.b=mMcgwoQa; 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=pass (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 8759D8786C; Thu, 11 Jan 2024 06:37:49 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="mMcgwoQa"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 683F587A8B; Thu, 11 Jan 2024 06:37:48 +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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-oi1-x22a.google.com (mail-oi1-x22a.google.com [IPv6:2607:f8b0:4864:20::22a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id A5C8787823 for ; Thu, 11 Jan 2024 06:37:45 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-oi1-x22a.google.com with SMTP id 5614622812f47-3bc1414b48eso5390090b6e.2 for ; Wed, 10 Jan 2024 21:37:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704951463; x=1705556263; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dJpAQqKZRU5gCSObJbfKhLiDyhlORb0+CJLUsG0YWwI=; b=mMcgwoQa+YzeED0p86qOFdu842qh4V/s7qSGmS+jHlnQd5SIkXEuMI6wBUXWpY0Mcj F8YaeQZC+2MCluoG6Pc/SatOCoDlUKYCr/VHJ0moykp1WNxl1REYZishLnNuCdj1T2W3 zjmcZHKpoTobO0S2V0Eg5UmF/u84JXA0Bw11UmwW6U/Acd63BlQs2W2n4AbTQLFH2vfm kgXoJcO7U3qMSGTougv19DgH9rUX8wXBoVt8EO46D8rxcNUO3xcCcxySf9+Ir4QgCV7s 1k2w8IEBwuPmlUruxg7MKdLQE5wsQjVMuatRf+NJaGSrIVd6n0S5ut3gSTFyw8hFk+2n DAsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704951463; x=1705556263; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dJpAQqKZRU5gCSObJbfKhLiDyhlORb0+CJLUsG0YWwI=; b=VsAYUk57nHqe/5RtrJhOR7yOO/3Lci/8/fCArgVe8qW6JkcLnXmqj3SrkyPtY0ZMsG WDXStnXdOGYBzqcS1rGrcpa7P3Ceo7HL6mthA0EXb8fzSCMX+MPrL5nanc+m3HtFNSSc fXMnQ5txwbr7CkFzr17rIteWhxt2lg1r6bu5QRyeXo/mu5JRyK844qeUaY4drGCxKmlL MyX8upWd1MmUSpoU7O/NG+PJ02hphrmxTmUDPX9RAKPgSZLFtGX2owJNhBIVJE1Rj5ik JqBf2HHvRtNsInWHa3+IDKtx2QsgJVfiCZUnbW7gMxbNXW42BPTxu7AUTylTynmSQfIa 9shw== X-Gm-Message-State: AOJu0YwAFQboOyE37hjG6iABCZcDtv9yL0ly3kpzT3gnWkJ0ZiiSJ97c sy0V0qqfDWltHfgiYT84c635EmvNNPfGyni8ZO0cmrYQT1E= X-Received: by 2002:a05:6808:2120:b0:3bd:534e:f81e with SMTP id r32-20020a056808212000b003bd534ef81emr585007oiw.53.1704951463482; Wed, 10 Jan 2024 21:37:43 -0800 (PST) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id p19-20020aa78613000000b006d93ca7f8f3sm264566pfn.150.2024.01.10.21.37.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 21:37:42 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Sughosh Ganu , Masahisa Kojima Subject: [PATCH v3 1/2] fwu: fix fwu_get_image_index interface Date: Thu, 11 Jan 2024 14:35:39 +0900 Message-Id: <20240111053540.899997-2-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240111053540.899997-1-masahisa.kojima@linaro.org> References: <20240111053540.899997-1-masahisa.kojima@linaro.org> MIME-Version: 1.0 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.8 at phobos.denx.de X-Virus-Status: Clean The capsule update uses the DFU framework for updating storage. fwu_get_image_index() currently returns the image_index calculated by (dfu_alt_num + 1), but this is different from the image_index in UEFI terminology. Since capsule update implementation calls dfu_write_by_alt function, it is better that FWU returns the dfu_alt_num. Signed-off-by: Masahisa Kojima Reviewed-by: Ilias Apalodimas --- include/fwu.h | 13 +++++-------- lib/efi_loader/efi_firmware.c | 11 +++++++++-- lib/fwu_updates/fwu.c | 32 ++++++++++++-------------------- 3 files changed, 26 insertions(+), 30 deletions(-) diff --git a/include/fwu.h b/include/fwu.h index ac5c5de870..eb5638f4f3 100644 --- a/include/fwu.h +++ b/include/fwu.h @@ -122,21 +122,18 @@ int fwu_get_active_index(uint *active_idxp); int fwu_set_active_index(uint active_idx); /** - * fwu_get_image_index() - Get the Image Index to be used for capsule update - * @image_index: The Image Index for the image - * - * The FWU multi bank update feature computes the value of image_index at - * runtime, based on the bank to which the image needs to be written to. - * Derive the image_index value for the image. + * fwu_get_dfu_alt_num() - Get the dfu_alt_num to be used for capsule update + * @image_index: The Image Index for the image + * @alt_num: pointer to store dfu_alt_num * * Currently, the capsule update driver uses the DFU framework for * the updates. This function gets the DFU alt number which is to - * be used as the Image Index + * be used for capsule update. * * Return: 0 if OK, -ve on error * */ -int fwu_get_image_index(u8 *image_index); +int fwu_get_dfu_alt_num(u8 image_index, u8 *alt_num); /** * fwu_revert_boot_index() - Revert the active index in the FWU metadata diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c index 1fde1885e3..e558336bc1 100644 --- a/lib/efi_loader/efi_firmware.c +++ b/lib/efi_loader/efi_firmware.c @@ -610,6 +610,7 @@ efi_status_t EFIAPI efi_firmware_raw_set_image( u16 **abort_reason) { int ret; + u8 dfu_alt_num; efi_status_t status; struct fmp_state state = { 0 }; @@ -624,19 +625,25 @@ efi_status_t EFIAPI efi_firmware_raw_set_image( if (status != EFI_SUCCESS) return EFI_EXIT(status); + /* + * dfu_alt_num is assigned from 0 while image_index starts from 1. + * dfu_alt_num is calculated by (image_index - 1) when multi bank update + * is not used. + */ + dfu_alt_num = image_index - 1; if (IS_ENABLED(CONFIG_FWU_MULTI_BANK_UPDATE)) { /* * Based on the value of update bank, derive the * image index value. */ - ret = fwu_get_image_index(&image_index); + ret = fwu_get_dfu_alt_num(image_index, &dfu_alt_num); if (ret) { log_debug("Unable to get FWU image_index\n"); return EFI_EXIT(EFI_DEVICE_ERROR); } } - if (dfu_write_by_alt(image_index - 1, (void *)image, image_size, + if (dfu_write_by_alt(dfu_alt_num, (void *)image, image_size, NULL, NULL)) return EFI_EXIT(EFI_DEVICE_ERROR); diff --git a/lib/fwu_updates/fwu.c b/lib/fwu_updates/fwu.c index b580574015..86518108c2 100644 --- a/lib/fwu_updates/fwu.c +++ b/lib/fwu_updates/fwu.c @@ -125,16 +125,14 @@ static int in_trial_state(struct fwu_mdata *mdata) return 0; } -static int fwu_get_image_type_id(u8 *image_index, efi_guid_t *image_type_id) +static int fwu_get_image_type_id(u8 image_index, efi_guid_t *image_type_id) { - u8 index; int i; struct efi_fw_image *image; - index = *image_index; image = update_info.images; for (i = 0; i < update_info.num_images; i++) { - if (index == image[i].image_index) { + if (image_index == image[i].image_index) { guidcpy(image_type_id, &image[i].image_type_id); return 0; } @@ -332,24 +330,20 @@ int fwu_set_active_index(uint active_idx) } /** - * fwu_get_image_index() - Get the Image Index to be used for capsule update - * @image_index: The Image Index for the image - * - * The FWU multi bank update feature computes the value of image_index at - * runtime, based on the bank to which the image needs to be written to. - * Derive the image_index value for the image. + * fwu_get_dfu_alt_num() - Get the dfu_alt_num to be used for capsule update + * @image_index: The Image Index for the image + * @alt_num: pointer to store dfu_alt_num * * Currently, the capsule update driver uses the DFU framework for * the updates. This function gets the DFU alt number which is to - * be used as the Image Index + * be used for capsule update. * * Return: 0 if OK, -ve on error * */ -int fwu_get_image_index(u8 *image_index) +int fwu_get_dfu_alt_num(u8 image_index, u8 *alt_num) { int ret, i; - u8 alt_num; uint update_bank; efi_guid_t *image_guid, image_type_id; struct fwu_mdata *mdata = &g_mdata; @@ -365,7 +359,7 @@ int fwu_get_image_index(u8 *image_index) ret = fwu_get_image_type_id(image_index, &image_type_id); if (ret) { log_debug("Unable to get image_type_id for image_index %u\n", - *image_index); + image_index); goto out; } @@ -380,15 +374,13 @@ int fwu_get_image_index(u8 *image_index) img_entry = &mdata->img_entry[i]; img_bank_info = &img_entry->img_bank_info[update_bank]; image_guid = &img_bank_info->image_uuid; - ret = fwu_plat_get_alt_num(g_dev, image_guid, &alt_num); - if (ret) { + ret = fwu_plat_get_alt_num(g_dev, image_guid, alt_num); + if (ret) log_debug("alt_num not found for partition with GUID %pUs\n", image_guid); - } else { + else log_debug("alt_num %d for partition %pUs\n", - alt_num, image_guid); - *image_index = alt_num + 1; - } + *alt_num, image_guid); goto out; }