From patchwork Tue Nov 14 09:25:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 743762 Delivered-To: patch@linaro.org Received: by 2002:a5d:67cf:0:b0:32d:baff:b0ca with SMTP id n15csp2075105wrw; Tue, 14 Nov 2023 01:26:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IEh+HEAYRE/9oR6AkdNfUnKaMjbpJHMgsuXhYTThvgF6nScaidUJq/bookgJfeKwwyPcbuz X-Received: by 2002:a17:906:2556:b0:9ae:699d:8a2a with SMTP id j22-20020a170906255600b009ae699d8a2amr6254757ejb.5.1699954008211; Tue, 14 Nov 2023 01:26:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699954008; cv=none; d=google.com; s=arc-20160816; b=w4K2FZMF/st41VX6/fXINbWNai8H2bm0g4U6s1qxZDnIhwJ0X68evcpbcbmFtoFwZY 8tkiHtZcTd1JTjLihtfRIOGmzvSaAo5EpYM2qcOngszr2jhthEwz54OfTq7+X4h5wRF/ 7bpHQwhNj2oF3x3jxov7nmXtvasXD4qiLGjk+WirbJ07pkMLRzLtcfgefBqbFZD+XgWg /eLtDw2znDH8t3SpUaTY59Lm2guXxhpmD1I2/b04D26yIMtf5KzQFJPV4jm1pvMNp4+b yuOoeqi33UEZj7kQy4c8zqUoFprNtvJtY1kgYTD3cK25D4OS5fYWA7ne2jS+hy7RYMUW T+jw== 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=g3Vyj8zH1wilO2p+N0KC7xECw+I4drVeJwtAwojUGV0=; fh=WO6lTKtGPINN9KZpMhJhgJRkFWf7EvZ6aTaftTHD+5o=; b=pCgRf4HdeRXL0iGDIhv0DrjoLm9PmUtIiW67oT6sn7QJAIBYjuweCsC7YDsTd1UPJy yxN8dF1XFZIMtgRrvhHeSQVMEUzfBC9uCJDYR8NIo0bCypobqpvIDORf8hZ/M7VcHRdw cHHCplPCovX1toSUXNnkYjh9yJewkGhMnwKZHMqie6tewewXNxpoqz2y0R+EYfY2wphK f7slxvB7JHJP+24/oyArIYmJ6+Zsb5E/BUGUBZSiydG0OyfDK1XXecuondkNq1XCzEg2 V4wYlh3Q5m9xybMYteOTm8DQsu2Rg60E10CNEnnm9hg8vZU7bjFXmRJFD3clDjYmCZl0 S61A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zEnpK2sm; 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 gb21-20020a170907961500b009e659d57c15si3405115ejc.541.2023.11.14.01.26.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 01:26:48 -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=zEnpK2sm; 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 1F86687440; Tue, 14 Nov 2023 10:26:43 +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="zEnpK2sm"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5534F86FB2; Tue, 14 Nov 2023 10:26:41 +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-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) (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 2A2C487269 for ; Tue, 14 Nov 2023 10:26:39 +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-pj1-x1035.google.com with SMTP id 98e67ed59e1d1-2800bdf888dso4082425a91.1 for ; Tue, 14 Nov 2023 01:26:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699953997; x=1700558797; 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=g3Vyj8zH1wilO2p+N0KC7xECw+I4drVeJwtAwojUGV0=; b=zEnpK2smXYUWLBFswzipt3JUpoJdlgYWNGInL4SYUhEo10Ni7HTJj3ult51r9BIpIC JZYbHy53jqM1Cv+PVyQuSl5Wy0p+wez+TwcaLNz+R9AeOYLd/l12IsxtFwHDB7gPp6fJ bGzns/pjvn4vQ1pvWwqDz4LYI/o6B9kHd7pr9hYnJdb+E3G6ewqUZE73QStwymEAX6cI O7kKePA9M3CcXd2dkG/bJRuQU4k0LzcMPcncPR0DcX8V9TkoRCQk7k57AJas7uDXdgZZ 56zSKpi8PYa2+aw+mAnYAHpkOZImIbGD+vpB2pHKanr3g0riVtAhZBwZHZPVxtmXNc6h GFgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699953997; x=1700558797; 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=g3Vyj8zH1wilO2p+N0KC7xECw+I4drVeJwtAwojUGV0=; b=h2PeQsvs9OeiqcpLS7Gv2mnJ5d9zdJAY+r1bDWifkZuvHYGfWniX0g7T+GT2yz2VF/ ata96VpTUUBRJpec04tJAAOqNWmk7AZTAzOz+lkpLTKda5JkSQQ3G3gUSxDhcwgKsAmQ zEY0IjTvH4QsJlhhh7hBwZfsIvuHw3Ukbzn5lNST5AyFQW3jdv99xzdp/vH4mv5QRpml Vnov9gjStPriTD4VtFugRGp2gDEAu25MlHzs7tP4+QqMkUpXuI06L3Mh+zXklMiuE8zv 811jJ73AGCMwe8s7oXKQvGdrnnC6i2PCUeY+0YmdMO++JQ9SQZc1SUKIMaspBmuuXNg4 abOg== X-Gm-Message-State: AOJu0YzzFqHVH3wSB/axpQrtt7O5EwGNyZwUIJ7W4vd6KCY4mHoGN2k/ RBuu7+1HQYS1lpsjx0wpsw22FNll5j3dbxCXbmg= X-Received: by 2002:a17:90a:d348:b0:280:6cde:ecc2 with SMTP id i8-20020a17090ad34800b002806cdeecc2mr2936766pjx.11.1699953997049; Tue, 14 Nov 2023 01:26:37 -0800 (PST) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id 22-20020a17090a001600b0027ceac90684sm5526577pja.18.2023.11.14.01.26.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 01:26:36 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Sughosh Ganu , Jassi Brar , Masahisa Kojima Subject: [PATCH 1/2] efi_loader: use original image_index for FMP versioning Date: Tue, 14 Nov 2023 18:25:07 +0900 Message-Id: <20231114092508.3955838-2-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231114092508.3955838-1-masahisa.kojima@linaro.org> References: <20231114092508.3955838-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 FMP versioning uses the image_index argument of EFI_FIRMWARE_MANAGEMENT_PROTOCOL.SetImage() service. When CONFIG_FWU_MULTI_BANK_UPDATE is enabled, image_index is updated by fwu_get_image_index() function. This commit saves the original image_index argument and use it for FMP versioning. Signed-off-by: Masahisa Kojima --- lib/efi_loader/efi_firmware.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c index 9abb29f1df..9c1a273926 100644 --- a/lib/efi_loader/efi_firmware.c +++ b/lib/efi_loader/efi_firmware.c @@ -612,6 +612,8 @@ efi_status_t EFIAPI efi_firmware_raw_set_image( { int ret; efi_status_t status; + u8 original_image_index = image_index; + struct fmp_state state = { 0 }; EFI_ENTRY("%p %d %p %zu %p %p %p\n", this, image_index, image, @@ -641,7 +643,7 @@ efi_status_t EFIAPI efi_firmware_raw_set_image( NULL, NULL)) return EFI_EXIT(EFI_DEVICE_ERROR); - efi_firmware_set_fmp_state_var(&state, image_index); + efi_firmware_set_fmp_state_var(&state, original_image_index); return EFI_EXIT(EFI_SUCCESS); } From patchwork Tue Nov 14 09:25:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 743763 Delivered-To: patch@linaro.org Received: by 2002:a5d:67cf:0:b0:32d:baff:b0ca with SMTP id n15csp2075146wrw; Tue, 14 Nov 2023 01:26:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IGss1vrFhEoetsJCX30EN38N1meQLpEiFzZLN+f4RFw9CXqhwxCF/g0d3EibiJjRHBjJVHQ X-Received: by 2002:a17:906:3c04:b0:9ae:614e:4560 with SMTP id h4-20020a1709063c0400b009ae614e4560mr1823960ejg.29.1699954018132; Tue, 14 Nov 2023 01:26:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699954018; cv=none; d=google.com; s=arc-20160816; b=A8N3yKKlRgY5g6phc7DWUp9bEsy9QOI94RVzStwXgviiiwaZVuJENedmpt0C4LHUYu ORHEr77P00nTGrr0CfzESWp19Ikk6y3STbpC+uFvPfdg3ll6pF1+QJgu13tJWvt3dqZK Hfo5NnTBkXHSH8YHjz8AQ1u9A0GePbC3jtZgPCtfyMsZOdNioUM4wGFoeD83VQaqkpuo /Ght6YV83N5O+KXJCEhsPkFn7RQAu6awwxhYQkjR7nmYrMN7eYxgj5Lj2CjnQK+bcafz j3E4rONnNAT/I8LkAAlLVqlPz6DYbkORi5Nspsltc9568nNv488S8tOtmA1x/AILLrIY yUxw== 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=CkSBtwaeB8jyAuuM+8xPXjQ7oYypGnan+rmjksDicoY=; fh=nFQofaN1q3cd5MKgeI4YX6fK1djzD/RjIn7pHO1hLug=; b=kpQD07YxDkOluhWZzjztzLKF3J1SztjxmVMkbKDAZjzvs5Od1nzveXVRhXU0Rq39ag FP+2Ero4dMSA7KHK1cuteKy71C/sGEJ6CjzL3dydnrr286xjXgB+/C+m3jrPscuso6e+ EXDvxU91qeqk1RfB2QshcWfeih3UXSnWaVzJ/6CnZ0j1jMY9K9kp0nk6T1VnjSvNNlb/ S/WRH8EouGgjslH+z3k8czasvIsEhThqcyBTFr49R4C6852m4vgVlpAikEnzfY6BnpwZ tXpQob8T38oSRyMHLJ7WaahEdi5zsUJ6940fZJ+7P1h05S891gr8RYy3mKkx1s2OwDFp 1PjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hwarLweO; 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 k5-20020a170906a38500b0099bcfd32960si3781936ejz.161.2023.11.14.01.26.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 01:26:58 -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=hwarLweO; 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 98BB88743F; Tue, 14 Nov 2023 10:26:48 +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="hwarLweO"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B9F0E86FB2; Tue, 14 Nov 2023 10:26:46 +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-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) (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 5B12087271 for ; Tue, 14 Nov 2023 10:26:44 +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-pf1-x432.google.com with SMTP id d2e1a72fcca58-6c431b91b2aso4661650b3a.1 for ; Tue, 14 Nov 2023 01:26:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699954002; x=1700558802; 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=CkSBtwaeB8jyAuuM+8xPXjQ7oYypGnan+rmjksDicoY=; b=hwarLweOvcCr/UwTr7E1AK56A0C8KYhjsve0rjXrpJZdBOGsZwLPf5bOAa+nXHhWPj wtmYIolLUMukIsoM7XX/Iz7LccXVXoRD95FCATODDhlwjdFwQN99I8qCDQf57tWbX2b6 vpQjz8rUs4PCKiAbgBGUGBMs6NreasZgYNxH8BHWTrWUiY0qRNETgIVPcZiH26RCSTt5 A2gwMd9kiRLtolMO3uzQ8LBO63E0NhTkeqJMmF97IPziL01wFbmQDY41JoZzdkKsyPLE xkNID8AIhjmSDThxiqwCWIvB7ICoX/vphkKKKtmqjE+0pWS9rz8gFs3QSzPBfguuyECL OmQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699954002; x=1700558802; 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=CkSBtwaeB8jyAuuM+8xPXjQ7oYypGnan+rmjksDicoY=; b=ZF733BTTPK9z+fieTXoT8pCZBQcHMhiBdb+cpOu+fy6WNK7ZRYVoSGNi37rCdbfHXN KG8d5om7plmQndwaffwSWqQIR0YwNHDl7IKKm3sXIHhJ/MQz5dN4BVIv9QJ1wTL/haMW pGmWyH25zAa/dj86Zzzdf0wL/3n1ok3r8nCT54hjAOzzmMlT9EUuW2mRdten/8yneQOM y8QFzONIH60AiwlylCIB0Ff33xX4lNC3VH/mNvki7+8Y/VmEBqXOYpxBUeA9WO44osf2 Z/IZGwds1cRGMUCoBQrMMMhJISAavgmETNDJedpaWWs/r7R0PDyvbpi043HhumBr0XWG By+w== X-Gm-Message-State: AOJu0YzbJMThePK6c5P72/NMVdcr8PTNI2+4vjYvFZVYqvcX3WCcaXhH iAwcRoLEuLx8fEDlhLfepnJOAmnS3VEJ13gQ4+c= X-Received: by 2002:a05:6a00:39a5:b0:6c3:4cac:f9ad with SMTP id fi37-20020a056a0039a500b006c34cacf9admr7930839pfb.19.1699954001826; Tue, 14 Nov 2023 01:26:41 -0800 (PST) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id fh30-20020a056a00391e00b006b8bb35e313sm814457pfb.103.2023.11.14.01.26.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 01:26:41 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Sughosh Ganu , Jassi Brar , Masahisa Kojima , Simon Glass Subject: [PATCH 2/2] efi_loader: support FMP versioning for FWU multi bank update Date: Tue, 14 Nov 2023 18:25:08 +0900 Message-Id: <20231114092508.3955838-3-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231114092508.3955838-1-masahisa.kojima@linaro.org> References: <20231114092508.3955838-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 Current FMP versioning uses the FMPStateXXXX UEFI variables that XXXX indicates image_index. When CONFIG_FWU_MULTI_BANK_UPDATE is enabled, U-Boot instances installed in different banks read the same FMPStateXXXX variable and it ends up with reading wrong fw_version. This commit includes the bank_index in the FMPStateXXYY variable. XX indicates a bank_index, YY indicates an image_index. With this, it keeps backward compatibility for the case that CONFIG_FWU_MULTI_BANK_UPDATE is not enabled, bank_index is always 0 for this case. The bank index size is defined 4 bytes in FWU-PSA-A_DEN0118_1.0ALP3.pdf, but 1-255 range is practically enough big. This commit adds the range for FWU_NUM_BANKS since above XX(bank_index) has 1 byte. Signed-off-by: Masahisa Kojima --- lib/efi_loader/efi_firmware.c | 63 ++++++++++++++++++++++++++--------- lib/fwu_updates/Kconfig | 1 + 2 files changed, 48 insertions(+), 16 deletions(-) diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c index 9c1a273926..6d3620a649 100644 --- a/lib/efi_loader/efi_firmware.c +++ b/lib/efi_loader/efi_firmware.c @@ -205,13 +205,33 @@ static void efi_firmware_fill_version_info(struct efi_firmware_image_descriptor *image_info, struct efi_fw_image *fw_array) { - u16 varname[13]; /* u"FmpStateXXXX" */ + int err; + u16 varname[13]; /* u"FmpStateXXYY" */ efi_status_t ret; efi_uintn_t size; + uint active_bank = 0, var_index; struct fmp_state var_state = { 0 }; + efi_firmware_get_lsv_from_dtb(fw_array->image_index, + &fw_array->image_type_id, + &image_info->lowest_supported_image_version); + + image_info->version_name = NULL; /* not supported */ + image_info->last_attempt_version = 0; + image_info->last_attempt_status = LAST_ATTEMPT_STATUS_SUCCESS; + + if (IS_ENABLED(CONFIG_FWU_MULTI_BANK_UPDATE)) { + err = fwu_get_active_index(&active_bank); + if (err) { + log_debug("Unable to get active index\n"); + image_info->version = 0; + return; + } + } + + var_index = ((active_bank & 0xFF) << 8 | (fw_array->image_index & 0xFF)); efi_create_indexed_name(varname, sizeof(varname), "FmpState", - fw_array->image_index); + var_index); size = sizeof(var_state); ret = efi_get_variable_int(varname, &fw_array->image_type_id, NULL, &size, &var_state, NULL); @@ -219,14 +239,6 @@ void efi_firmware_fill_version_info(struct efi_firmware_image_descriptor *image_ image_info->version = var_state.fw_version; else image_info->version = 0; - - efi_firmware_get_lsv_from_dtb(fw_array->image_index, - &fw_array->image_type_id, - &image_info->lowest_supported_image_version); - - image_info->version_name = NULL; /* not supported */ - image_info->last_attempt_version = 0; - image_info->last_attempt_status = LAST_ATTEMPT_STATUS_SUCCESS; } /** @@ -353,15 +365,20 @@ efi_status_t efi_firmware_capsule_authenticate(const void **p_image, * @state: Pointer to fmp state * @image_index: image index * - * Update the FmpStateXXXX variable with the firmware update state. + * Update the FmpStateXXYY variable with the firmware update state. + * XX is a bank index, YY is an image_index + * When CONFIG_FWU_MULTI_BANK_UPDATE is not enabled, update_bank is always 0. * * Return: status code */ static efi_status_t efi_firmware_set_fmp_state_var(struct fmp_state *state, u8 image_index) { - u16 varname[13]; /* u"FmpStateXXXX" */ + int err; + u16 varname[13]; /* u"FmpStateXXYY" */ efi_status_t ret; + uint update_bank = 0; + unsigned int var_index; efi_guid_t *image_type_id; struct fmp_state var_state = { 0 }; @@ -369,9 +386,15 @@ efi_status_t efi_firmware_set_fmp_state_var(struct fmp_state *state, u8 image_in if (!image_type_id) return EFI_INVALID_PARAMETER; - efi_create_indexed_name(varname, sizeof(varname), "FmpState", - image_index); + if (IS_ENABLED(CONFIG_FWU_MULTI_BANK_UPDATE)) { + err = fwu_plat_get_update_index(&update_bank); + if (err) + return EFI_INVALID_PARAMETER; + } + var_index = ((update_bank & 0xFF) << 8 | (image_index & 0xFF)); + efi_create_indexed_name(varname, sizeof(varname), "FmpState", + var_index); /* * Only the fw_version is set here. * lowest_supported_version in FmpState variable is ignored since @@ -563,7 +586,11 @@ efi_status_t EFIAPI efi_firmware_fit_set_image( if (fit_update(image)) return EFI_EXIT(EFI_DEVICE_ERROR); - efi_firmware_set_fmp_state_var(&state, image_index); + status = efi_firmware_set_fmp_state_var(&state, image_index); + if (status != EFI_SUCCESS) { + log_err("Set FmpState variable failed\n"); + return EFI_EXIT(status); + } return EFI_EXIT(EFI_SUCCESS); } @@ -643,7 +670,11 @@ efi_status_t EFIAPI efi_firmware_raw_set_image( NULL, NULL)) return EFI_EXIT(EFI_DEVICE_ERROR); - efi_firmware_set_fmp_state_var(&state, original_image_index); + status = efi_firmware_set_fmp_state_var(&state, original_image_index); + if (status != EFI_SUCCESS) { + log_err("Set FmpState variable failed\n"); + return EFI_EXIT(status); + } return EFI_EXIT(EFI_SUCCESS); } diff --git a/lib/fwu_updates/Kconfig b/lib/fwu_updates/Kconfig index d35247d0e5..eb42f25fc0 100644 --- a/lib/fwu_updates/Kconfig +++ b/lib/fwu_updates/Kconfig @@ -14,6 +14,7 @@ if FWU_MULTI_BANK_UPDATE config FWU_NUM_BANKS int "Number of Banks defined by the platform" + range 1 255 help Define the number of banks of firmware images on a platform