From patchwork Mon Feb 12 07:47:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 772031 Delivered-To: patch@linaro.org Received: by 2002:adf:9dca:0:b0:33b:4db1:f5b3 with SMTP id q10csp2000591wre; Sun, 11 Feb 2024 23:49:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IHVs+B7fj6CihCnESeWMheK7JSpJdxNQpnqyHIpItwn/3uwjc5mY2291kp5qX1T+onfUmA2 X-Received: by 2002:a17:906:f8da:b0:a3c:a677:fc1e with SMTP id lh26-20020a170906f8da00b00a3ca677fc1emr1032331ejb.40.1707724152606; Sun, 11 Feb 2024 23:49:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1707724152; cv=none; d=google.com; s=arc-20160816; b=GUwWhdBmGmH2WKPwYNvOP9M08EpFMkFlbSykZAaPU919MSjXyEj6a8uQxHxtMsN97w AA7eGlO3AWapSQZD7XQsqRl2VhJcym8xFGi+BEA/+LhSgf8BR6Ox8v1FHoRotc0IV1Sy 9+rD8vHXIWo7H1if036iEpQncLfhx3TlGc9EqjrferVb6NJp6zTzIUV1qMBdry7nSXZO vWd6kzrvHNKTuh4fao/Rh9P/NF0QLH1kG893YuHlCMaeWTaS35NITDT0KCgHTPOi5UhS SvKhX6AGUywer/rph7lm13lmkdqACs0Mp7IsZy0G6T65+x76Z7d+6Lzkm1+Rjg/wzX8W Z3pA== 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; bh=UpFkeafqXTPlpnvruoBbjayea3FtZop1wKuEhkyGybw=; fh=vTY1W+dwg/uYkx8YFYqtKjzkODrNthDN1CctwTadm0I=; b=oheAoB3f/ZJvN6toFDhWrKhxZF1otd+D2NjqbvFCNmsaNPTJzO8MrwPkiLvao+c+Ww lSZAaJNIUnswhLw9gCCvnjx3YXEKAavcXcZ0b6xj2qCYeionDgHUNPv9RdihXHbFTIyJ h2HObqbN8W6j4aJgOUETdsDiQckmKush4/qOz+Yi2UmKlYXeqMdYrXQNN+xw2q1c1Ug9 lqo+ZXvMUMYrdX+HnP2FXwN44uiThbpplA6YdxZ2QXKspPTjBJJqigdG1ipII4AmaPjj LeW1A6cAqYJhISu3KI0+VjLNicVJimP10w4GZ/ATan4K8FyYD+TTJ7XoKJX8E8t8m2b4 sD6A==; darn=linaro.org 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 X-Forwarded-Encrypted: i=1; AJvYcCVzSg9QtSyosXD7lffCcEPHstXjEum6THTR+imBf7qC6qOXHW+iQI55t9yQhIMHnUPOagkOVSPpfd5FdN52ku+vrm8+CEF7uUKToFLSSuxCiRB4M7y6MlI49vNvNMJ5/jnN3B8qrbqZ5Ar/TZGv86+tU0ChVV8QUKBk4Vq1FvChvGL+iCDir12DFTrhwFfrkRzfz8K4sBDaDbbSQXs82mo23Y/PUAgjgYVZyId26TPqu+p5gySB3LPX1JyYuTP+SGOr7zev7wQ5zjpycyp8teI0Gnxyh758cIFzutr9EdY3eBAjPoUkUka4R7uRWLW0gw+DZhq2oZ8NBJgNYhjOpRLDfnpBwRwyB9w0Wi7VwINGV/qrf7zMrSy/nq+h7QdXk0kYseAbOWO8iZXGDCyAX7Mp8iTUipSab8QMBbFaWLESnj4dex+Fm4ZHSwG9q7CMNWtsj1w+g6aU+dTcjGGAb+pYjfP7zXIJVcRYF08bO50o4zrSDO5FR4u0Zi7N3yXjRCPtCXte/SACDloHMIbtch7w52rYB4UyUh8dNuSYa0SckntKUanf3DKnEpIw2EKwzUnWF3GGajJ0HTPdH7gnEk5QFhZkn5CYNDp5TwbWL9o+S6uAvTCPKU0HpDvNEPjLyegpagDUG0Ur5wPYtX/M5RCSrn0toxwl8XOdtv0is6TqCaXj6Z+UQjaPZiq7FV4X8MjLUrYVgZjAZIq/u4+20X/b6uGZXC9IT3OXhy4ZYClQRPDUr4zETH3RnrPA4H1GffhzlQFgadzpvQA8BXYYihhkUCtCj0gki/cbP7xV1EvD3cySCXIsEfLKUpeWHMfQE2/Jny7+UJkj06mreXhrt+vE70ZyYGASZChNDvs8wJi0eV8= 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 u23-20020a1709064ad700b00a352247f161si3571338ejt.545.2024.02.11.23.49.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Feb 2024 23:49:12 -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 9C3E087EE7; Mon, 12 Feb 2024 08:48:11 +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 6BB2887EC9; Mon, 12 Feb 2024 08:48:10 +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,T_SCC_BODY_TEXT_LINE 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 4ABAE87EED for ; Mon, 12 Feb 2024 08:48:08 +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 56FF2DA7; Sun, 11 Feb 2024 23:48:49 -0800 (PST) Received: from a079122.blr.arm.com (a079122.arm.com [10.162.17.48]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8A9753F762; Sun, 11 Feb 2024 23:48:04 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Masahisa Kojima , Patrice Chotard , Patrick Delaunay , Yann Gautier , Etienne Carriere , Michal Simek , Jassi Brar , Sughosh Ganu Subject: [PATCH v2 09/21] fwu: add a function to put a bank in Trial State Date: Mon, 12 Feb 2024 13:17:00 +0530 Message-Id: <20240212074712.3657076-10-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240212074712.3657076-1-sughosh.ganu@linaro.org> References: <20240212074712.3657076-1-sughosh.ganu@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 version 2 of the FWU metadata has a field in the top level structure, called bank_state. This is used to keep the state a given bank is in, either of valid(for trial state), invalid, or accepted. Update this field when putting the platform in Trial State, in addition to starting the TrialStateCtr variable by calling the fwu_trial_state_start() function. Signed-off-by: Sughosh Ganu --- Changes since V1: None include/fwu.h | 12 +++++--- lib/efi_loader/efi_capsule.c | 2 +- lib/fwu_updates/fwu.c | 54 ++++++++++++++++++++++++++++++------ 3 files changed, 54 insertions(+), 14 deletions(-) diff --git a/include/fwu.h b/include/fwu.h index 109ceb2610..1c6a5fcda9 100644 --- a/include/fwu.h +++ b/include/fwu.h @@ -342,15 +342,19 @@ u8 fwu_update_checks_pass(void); u8 fwu_empty_capsule_checks_pass(void); /** - * fwu_trial_state_ctr_start() - Start the Trial State counter + * fwu_trial_state_start() - Put the platform in Trial State + * @update_index: Bank number to which images have been updated * - * Start the counter to identify the platform booting in the - * Trial State. The counter is implemented as an EFI variable. + * Put the platform in Trial State by starting the counter to + * identify the platform booting in the Trial State. The + * counter is implemented as an EFI variable. Secondly, set + * the bank_state in the metadata for the updated bank to Valid + * state. * * Return: 0 if OK, -ve on error * */ -int fwu_trial_state_ctr_start(void); +int fwu_trial_state_start(uint update_index); /** * fwu_gen_alt_info_from_mtd() - Parse dfu_alt_info from metadata in mtd diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c index de0d49ebeb..0e6a38b441 100644 --- a/lib/efi_loader/efi_capsule.c +++ b/lib/efi_loader/efi_capsule.c @@ -522,7 +522,7 @@ static __maybe_unused efi_status_t fwu_post_update_process(bool fw_accept_os) } else { log_debug("Successfully updated the active_index\n"); if (fw_accept_os) { - status = fwu_trial_state_ctr_start(); + status = fwu_trial_state_start(update_index); if (status < 0) ret = EFI_DEVICE_ERROR; } diff --git a/lib/fwu_updates/fwu.c b/lib/fwu_updates/fwu.c index 587ca779d3..a58c42bee2 100644 --- a/lib/fwu_updates/fwu.c +++ b/lib/fwu_updates/fwu.c @@ -672,6 +672,36 @@ out: return ret; } +static int fwu_trial_state_ctr_start(void) +{ + int ret; + u16 trial_state_ctr; + + printf("%s: starting the TrialStateCtr\n", __func__); + trial_state_ctr = 0; + ret = trial_counter_update(&trial_state_ctr); + if (ret) + log_err("Unable to initialise TrialStateCtr\n"); + + return ret; +} + +static int fwu_set_bank_state_trial(uint update_index) +{ + int ret; + struct fwu_mdata *mdata = g_mdata; + + mdata->bank_state[update_index] = FWU_BANK_VALID; + + ret = fwu_sync_mdata(mdata, BOTH_PARTS); + if (ret) { + log_err("Unable to set bank_state for %d bank\n", update_index); + return ret; + } + + return 0; +} + /** * fwu_bank_state_update() - Check and update the bank_state of the metadata * @update_index: Bank for which the bank_state needs to be updated @@ -830,25 +860,31 @@ u8 fwu_empty_capsule_checks_pass(void) } /** - * fwu_trial_state_ctr_start() - Start the Trial State counter + * fwu_trial_state_start() - Put the platform in Trial State + * @update_index: Bank number to which images have been updated * - * Start the counter to identify the platform booting in the - * Trial State. The counter is implemented as an EFI variable. + * Put the platform in Trial State by starting the counter to + * identify the platform booting in the Trial State. The + * counter is implemented as an EFI variable. Secondly, set + * the bank_state in the metadata for the updated bank to Valid + * state. * * Return: 0 if OK, -ve on error * */ -int fwu_trial_state_ctr_start(void) +int fwu_trial_state_start(uint update_index) { int ret; - u16 trial_state_ctr; - trial_state_ctr = 0; - ret = trial_counter_update(&trial_state_ctr); + ret = fwu_trial_state_ctr_start(); if (ret) - log_err("Unable to initialise TrialStateCtr\n"); + return ret; - return ret; + ret = fwu_set_bank_state_trial(update_index); + if (ret) + return ret; + + return 0; } static int fwu_boottime_checks(void)