From patchwork Thu Dec 21 09:52:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 756982 Delivered-To: patch@linaro.org Received: by 2002:a5d:67c6:0:b0:336:6142:bf13 with SMTP id n6csp799094wrw; Thu, 21 Dec 2023 01:55:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IG4QfpvaEmmUVVFgcJkS1DDrVIyFavMPbDQjTzXK3HpeSTsv/RRRitr5iEAFyCY0MVgwPmJ X-Received: by 2002:a5d:68c6:0:b0:336:8268:4266 with SMTP id p6-20020a5d68c6000000b0033682684266mr532189wrw.78.1703152499949; Thu, 21 Dec 2023 01:54:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703152499; cv=none; d=google.com; s=arc-20160816; b=M8JnDxEK6QEfO0pehs8urFNb9bGPEn3iaFFT0DBLjOiKdNfgdYn0NF9QGkeJDYRbdf GklP3LOvS5RjSGZeKRr63vLVmN89f++PYI6iG/OBFhFXgg9z6qDYxLY1aAGM/+n9Qg4V uWSxqkBjhXv4+FqwK2L1cvmMoT8QIHzQNAFO7LeyHwyPpf5lwAzPgw7USJ+8jKHJIHub IT1NbWge80aJq3op7fzzFCnlGRWAvsO19OMX0Z3jSnNnn/dUgC7VY85rNKiHdUByKbnA Z5OC7xz9tUo+FqYB11hLa9Syb17WM88S4gKJaHDhG4Hz6oG0bdJkdpQSI8HqA302Rbn0 7M3Q== 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=NEsNUREktd4Ceezuc4AmaJ0enT6WLmKAXceoYvSvne8=; fh=vrqNCSWbrItDl40TMygDgSHof0/XikFdntN3a1zOV74=; b=bzhLvD6cCLm4F5AxIJUe+B0EenrEcbBq/pTZCuDsYojkHCis+fOirH1QeVtmvXl+0+ OLbc1ZkFn+L2OHb8lIjKjQDlund/F+JD/UtcIi0NwDpOEMpxNocnU7+SAWyQbWYuNA4U sNBFoVuFoySmlJZjaxJhDl5dQDqWqw2ICmu6vBilkqXACXnlOvT5Zn/I9SbtuEZ4yaP2 W3t/NermUvsXRxXpXohfNt7D508xS05WbcNlXrRTc8fzdYoAp0RxIkt1nBQajFm3/4sH qxGMoXAoZgXocAIIimzXppw/XC7MjgfD5pKvW2dPukNVkJyPn5lqw1G5K3I4wTpY4IY1 xpvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=neu1rAi0; 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 q12-20020adff78c000000b003367660cceesi782675wrp.989.2023.12.21.01.54.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 01:54:59 -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=neu1rAi0; 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 E303687862; Thu, 21 Dec 2023 10:54:54 +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="neu1rAi0"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0BFED8785F; Thu, 21 Dec 2023 10:54:54 +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-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) (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 C104D8785A for ; Thu, 21 Dec 2023 10:54:51 +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-pg1-x534.google.com with SMTP id 41be03b00d2f7-5c6ce4dffb5so229911a12.0 for ; Thu, 21 Dec 2023 01:54:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1703152490; x=1703757290; 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=NEsNUREktd4Ceezuc4AmaJ0enT6WLmKAXceoYvSvne8=; b=neu1rAi0mAJoTiHeCNUZin/a5OZeOozoc9DE9lRZg9TMdlwGrU8MoqHuFrhC0Nvq9k 7WUSX5Fhf+RWgTWvtTMif8y+04Xl+hjUppKhTMQQ0RfOY1qsbF5G1blL9i7jwh95n2nb KGin3kuSwGR+aDN1NML7wMjkFYkxtNhrb3vbD3NHwV60AsfOcF2Euah8wTSFqwN4kw24 5fRRQyvFpQhssNdhaHwXRSbKxRkGx0FMC7ERtr/0aNfqzArqoUEYxGbknuqD3JRiI4WS fJdrLDCSh03KN7YRkzCU8qT2/ljHMl8yJBmVIVNZPUYMSSfxz7QlgS6ptAdAKRbxei1n Q09g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703152490; x=1703757290; 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=NEsNUREktd4Ceezuc4AmaJ0enT6WLmKAXceoYvSvne8=; b=AN+DYSFxhkXO+mroyanwG4lCWVlGlmsNoFoNl3dRhTDaR2KJjJOHIBAbNOiXcn+rRT X0p16wOWq8XPc/v4tviQ/Jn9uM5AqidHV/U3OHL6GgrhIJT8Ly9ZK7k5QAhoJqINSJs1 VehX5kPYvgKQVQopeNaqjk+Oxn7Di2BTgIFTu1qoBISNvhgrfDMxmjPkcCESMJM3naLW Hk4n2FdxDjKjycczRTgErBANBHe7VX48nQV08N9HLAiiY8flxPLhpuFP1EMdDuc+Feag Mwu1PXSwjHXa3TMwdFbIwT/sse9z0+Cup9dGSlMk07DvKg4SoJfIh89fV4ffgiTVTDcF W0wQ== X-Gm-Message-State: AOJu0Yz0WZAS866dKFgqKVkM2M+oWjbqw8JEKFfGyCuYt2jDkUB6zIIk 9uqRu6thgxRHXIdwaXneEvN8EV/oM2s5ACWzUes= X-Received: by 2002:a05:6a20:daa6:b0:195:fce:eeb3 with SMTP id iy38-20020a056a20daa600b001950fceeeb3mr232201pzb.106.1703152489744; Thu, 21 Dec 2023 01:54:49 -0800 (PST) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id sr5-20020a17090b4e8500b0028afd8b1e0bsm772334pjb.57.2023.12.21.01.54.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 01:54:49 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Sughosh Ganu , Masahisa Kojima Subject: [PATCH v2 1/2] fwu: fix fwu_get_image_index interface Date: Thu, 21 Dec 2023 18:52:57 +0900 Message-Id: <20231221095258.592275-2-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231221095258.592275-1-masahisa.kojima@linaro.org> References: <20231221095258.592275-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 9abb29f1df..9b8630625f 100644 --- a/lib/efi_loader/efi_firmware.c +++ b/lib/efi_loader/efi_firmware.c @@ -611,6 +611,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 }; @@ -625,19 +626,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; } From patchwork Thu Dec 21 09:52:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 756983 Delivered-To: patch@linaro.org Received: by 2002:a5d:67c6:0:b0:336:6142:bf13 with SMTP id n6csp799167wrw; Thu, 21 Dec 2023 01:55:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IGCvkzfBRlxWk5hR40SjwkTEfPQMl/X3L2mGZlpCswfc/pQ9r0w0+J3AcAn2k19ds145if0 X-Received: by 2002:a05:600c:1c9a:b0:40b:5e21:dd3b with SMTP id k26-20020a05600c1c9a00b0040b5e21dd3bmr632884wms.105.1703152510181; Thu, 21 Dec 2023 01:55:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703152510; cv=none; d=google.com; s=arc-20160816; b=xurWR6Whll0j19r8IMF7S1gXhsMbuCjf24K12+Z//PzTUSNzVR6EJ6Of71QRuKfGpn V92dr7VEdkSRZ6cGTLiMWOrtTl99iZqyAsh0oCOdUWCNaAeC1D8ZtAEl4qwdlupTWpfI DplvGoOuZSIoa9e2KUfa5AJ6Ti93M8KKujQteGKHUFpHMRFBUEK1/RvgwvicdK+KJuiB 0IlUBdnjk0566OSZGzbkdRe0ITV4XWur+QNsAt1caUn/33Ils5vGqDfsLierSMWN0ffZ bAmPv8G2wTq9kwaWfy479qTd+NkuBjjvwKRYXdxW18Zb+ahK2vZb1JYu1tLf6vb9BeNl RMxA== 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=xv+fGi7LNcnsBebszm2kBJ6oJjfbgAATJGkrRuVzCvk=; fh=vrqNCSWbrItDl40TMygDgSHof0/XikFdntN3a1zOV74=; b=s63NwNDjH0odASEwdJ4i0K7RzEKQawfblhZwi71oRpUnVKh8XljNhojbQ/Ac8ItVX0 3vQ86Co2NPOG5vA/1//v9sZ7NqNmIMXvYHPEdDUCDQBQEW/vN+6/y0R49mu8JmGRMN4B +vWK32x3umCw6Bb0wzJXUumF6CrpwcUp7gYtvpmzfUqPYRjx+rdX2WOCj06yGmDBPJUo FO05PzBxXjU01MCydP3/0G6ZcFxygUcisIupk5jJWDpU58FGkirMz1aTmgP/3yxLI2gK AYbwP1yaYqfcQmrJy/YkoAm7h8Csr5ppw7Oe8DaknLxSo9CHFhQbV+sB9uNB3A2/74Jz ttQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ykYFhmN3; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id fm16-20020a05600c0c1000b0040c39ee2d49si881594wmb.46.2023.12.21.01.55.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 01:55:10 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ykYFhmN3; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 4D87D8785A; Thu, 21 Dec 2023 10:55:01 +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="ykYFhmN3"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3B3E4877A1; Thu, 21 Dec 2023 10:55:00 +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-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) (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 4DB2A8785C for ; Thu, 21 Dec 2023 10:54:57 +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-pg1-x52b.google.com with SMTP id 41be03b00d2f7-5cdc159034eso275571a12.0 for ; Thu, 21 Dec 2023 01:54:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1703152495; x=1703757295; 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=xv+fGi7LNcnsBebszm2kBJ6oJjfbgAATJGkrRuVzCvk=; b=ykYFhmN31vLmzpnDGGVmtZVkGUZvmCDpjuWVx7G2kFQ3c0QtLA4B3IjwrcUB69Hw0g nhPZWBdF5xAZUHn2EbbeLjQO9xuU4gubOBg470xh8TBFT2zubtnSGGHaK23od0Na6yV3 cR0373U6zr+677AmfNM+VwJWqHo0tcOSdbBAH/OUU2P7BotO9r33ZrDw/mcIo3P+2P4z epa5TYMQBfWy0nYHupcy8Ou1stjDzL/siVEq6phjlWzZ0EqyhrwyaqoweMcZUYxo+xZD MBcGH95rbCini2i8gbQiy5eNi5DNtXSDh/dYyihy9/9eytf86vumuSjDc6b0QhrWddQF 9i/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703152495; x=1703757295; 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=xv+fGi7LNcnsBebszm2kBJ6oJjfbgAATJGkrRuVzCvk=; b=RlISXh+ltl13MS6RezcZM3LK5f0nqBtY4LRQaUcSpCSzPibrgHlxP9qEhMUCWOOuvX rA7+XmBtnLaw5S1AgkNlsT3yEkd9Hp31Uo2+kDMg3ysgfYqe4MbtqLj7V68YgHnHag35 SSOgDLUsI0nTTMaZEEvJ3cRqE4r2Uj/GzKKfJpRx8Oh7b4tqUUn/AhZxM/FnG6XO85hI spd0BJ8RQmg+sAzue3T9+L3BvCh2P24JfsM3tPYGqUSYSjxJW4zNdC7OrGfktpDPzc6Z qiyNyrV+cyFposEdFVcUwglDL26yr4YoO7OczgThEvbqwm9Pd5bbpPaiFrYqLRUW9ADf aZfA== X-Gm-Message-State: AOJu0Ywa69VjpHR/MjIwgzxQrhcJPuH3/kZ4jgI+3tczFocmMt5Xe+h+ z0rYQYO/TsjJh5IOLk4Xwc7GQJefJ6JD3BAJrCc= X-Received: by 2002:a05:6a20:7f97:b0:18f:20bf:d855 with SMTP id d23-20020a056a207f9700b0018f20bfd855mr796949pzj.1.1703152495358; Thu, 21 Dec 2023 01:54:55 -0800 (PST) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id jx20-20020a17090b46d400b0028b66796002sm1369417pjb.6.2023.12.21.01.54.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 01:54:54 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Sughosh Ganu , Masahisa Kojima Subject: [PATCH v2 2/2] efi_loader: support fmp versioning for multi bank update Date: Thu, 21 Dec 2023 18:52:58 +0900 Message-Id: <20231221095258.592275-3-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231221095258.592275-1-masahisa.kojima@linaro.org> References: <20231221095258.592275-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 This commit stores the firmware version into the array of fmp_state structure to support the fmp versioning for multi bank update. The index of the array is identified by the bank index. This modification keeps the backward compatibility with the existing versioning feature. Signed-off-by: Masahisa Kojima --- lib/efi_loader/efi_firmware.c | 69 +++++++++++++++++++++++++++-------- 1 file changed, 54 insertions(+), 15 deletions(-) diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c index 9b8630625f..5459f3d38d 100644 --- a/lib/efi_loader/efi_firmware.c +++ b/lib/efi_loader/efi_firmware.c @@ -207,18 +207,10 @@ void efi_firmware_fill_version_info(struct efi_firmware_image_descriptor *image_ { u16 varname[13]; /* u"FmpStateXXXX" */ efi_status_t ret; - efi_uintn_t size; - struct fmp_state var_state = { 0 }; - - efi_create_indexed_name(varname, sizeof(varname), "FmpState", - fw_array->image_index); - size = sizeof(var_state); - ret = efi_get_variable_int(varname, &fw_array->image_type_id, - NULL, &size, &var_state, NULL); - if (ret == EFI_SUCCESS) - image_info->version = var_state.fw_version; - else - image_info->version = 0; + efi_uintn_t size, expected_size; + uint num_banks = 1; + uint active_index = 0; + struct fmp_state *var_state; efi_firmware_get_lsv_from_dtb(fw_array->image_index, &fw_array->image_type_id, @@ -227,6 +219,31 @@ void efi_firmware_fill_version_info(struct efi_firmware_image_descriptor *image_ image_info->version_name = NULL; /* not supported */ image_info->last_attempt_version = 0; image_info->last_attempt_status = LAST_ATTEMPT_STATUS_SUCCESS; + image_info->version = 0; + + /* get the fw_version */ + efi_create_indexed_name(varname, sizeof(varname), "FmpState", + fw_array->image_index); + if (IS_ENABLED(CONFIG_FWU_MULTI_BANK_UPDATE)) { + ret = fwu_get_active_index(&active_index); + if (ret) + return; + + num_banks = CONFIG_FWU_NUM_BANKS; + } + + size = num_banks * sizeof(*var_state); + expected_size = size; + var_state = calloc(1, size); + if (!var_state) + return; + + ret = efi_get_variable_int(varname, &fw_array->image_type_id, + NULL, &size, var_state, NULL); + if (ret == EFI_SUCCESS && expected_size == size) + image_info->version = var_state[active_index].fw_version; + + free(var_state); } /** @@ -362,8 +379,11 @@ efi_status_t efi_firmware_set_fmp_state_var(struct fmp_state *state, u8 image_in { u16 varname[13]; /* u"FmpStateXXXX" */ efi_status_t ret; + uint num_banks = 1; + uint update_bank = 0; + efi_uintn_t size; efi_guid_t *image_type_id; - struct fmp_state var_state = { 0 }; + struct fmp_state *var_state; image_type_id = efi_firmware_get_image_type_id(image_index); if (!image_type_id) @@ -372,19 +392,38 @@ efi_status_t efi_firmware_set_fmp_state_var(struct fmp_state *state, u8 image_in efi_create_indexed_name(varname, sizeof(varname), "FmpState", image_index); + if (IS_ENABLED(CONFIG_FWU_MULTI_BANK_UPDATE)) { + ret = fwu_plat_get_update_index(&update_bank); + if (ret) + return EFI_INVALID_PARAMETER; + + num_banks = CONFIG_FWU_NUM_BANKS; + } + + size = num_banks * sizeof(*var_state); + var_state = calloc(1, size); + if (!var_state) + return EFI_OUT_OF_RESOURCES; + + ret = efi_get_variable_int(varname, image_type_id, NULL, &size, + var_state, NULL); + /* * Only the fw_version is set here. * lowest_supported_version in FmpState variable is ignored since * it can be tampered if the file based EFI variable storage is used. */ - var_state.fw_version = state->fw_version; + var_state[update_bank].fw_version = state->fw_version; + size = num_banks * sizeof(*var_state); ret = efi_set_variable_int(varname, image_type_id, EFI_VARIABLE_READ_ONLY | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, - sizeof(var_state), &var_state, false); + size, var_state, false); + + free(var_state); return ret; }