From patchwork Mon Jan 22 11:54:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 764626 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:10c4:b0:337:62d3:c6d5 with SMTP id b4csp1059212wrx; Mon, 22 Jan 2024 03:56:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IF5/Xf9ouoJvghmninmurPM10M+mZZ2W4oM+cD5PzvAAGhRfBgQj1v4L3dHv3nXvYlwJNSa X-Received: by 2002:a5d:584e:0:b0:339:3591:156 with SMTP id i14-20020a5d584e000000b0033935910156mr808988wrf.202.1705924595161; Mon, 22 Jan 2024 03:56:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705924595; cv=none; d=google.com; s=arc-20160816; b=ivUnzGpQ0brexM9AYTbh3/dWptViKoIIxWzyVFkRO/SgZzWIckHBtY3EcDAdB0AcS9 bcUjQCUkvo3KiVna4CucIDf+y1mGH7JnltnGosGdVQucYpfDHdju9Zbxvz8ks7GhsCQK iA4iAvQSKjVGbopywClTgWtp+yoA1v72zCzhNWYfzoqU1h0KL1gw1q49g8/z3wVboz0i XQ2Pr1fv8NtkS6UF+feFBROetDKbYQR0kbAuZi+4t4DWcZ1vSu6teqIKtKnzncn9W9Dy tUp/THVCDl75rYegAgI7mbb/AuPFqHAmtBOcVKycLiZNNopuw1pA/DE8CPHs7T0fi3tp Skcw== 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=sDrAzBh/4qIgCBQGaSebCZyYOlVRACEdC1O9s1vNJwc=; fh=rhmJ78R78zNUSUA9Nt0a5TbZO4CVsI4vi5GcqSIe+nI=; b=C5BQfMtFsHpbnGfHUKuZ9JBbrcrnYn2lmUb0SwC6HzHLgkrHINA94vf6wT02Yw7qD5 2bS1J+83JeAby5nJiLqHM5IBoMEolcwU2E04AZbtaNeUGvkBRKasOo5K0XG4lNgvFL5i a2Dd2OXF4VJ19POWKxuGvPpE+LRwrAlXTu6i+VVbMmCCgm7RAbcRtrfHVe80V3zaHl1r yFtPIjrtRNCnBgl7F8LU932mw5s0ls3yJE8OU2zORWEenCSfYCBFMqus+nmr3dI8vj3H i3m0MxCsGjXMRJ9nxXIPvtiIKWdEEwbcmJUuoU7oHm4T2eTDaRkOuMmbKDNCzalCR/lB lfHw== 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 i5-20020adffc05000000b0033922987e7asi3532923wrr.802.2024.01.22.03.56.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 03:56:35 -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 E9A0487BE1; Mon, 22 Jan 2024 12:55:43 +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 8FC4987B1D; Mon, 22 Jan 2024 12:55:42 +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 BCF318797C for ; Mon, 22 Jan 2024 12:55:37 +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 378CE1FB; Mon, 22 Jan 2024 03:56:23 -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 847B63F73F; Mon, 22 Jan 2024 03:55:34 -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 , Sughosh Ganu Subject: [PATCH 08/18] fwu: Add a function to put a bank in Trial State Date: Mon, 22 Jan 2024 17:24:29 +0530 Message-Id: <20240122115439.653871-9-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240122115439.653871-1-sughosh.ganu@linaro.org> References: <20240122115439.653871-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 --- 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 3764336952..d0b4e12190 100644 --- a/include/fwu.h +++ b/include/fwu.h @@ -297,15 +297,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 831ff6aa91..0f43cf63b2 100644 --- a/lib/fwu_updates/fwu.c +++ b/lib/fwu_updates/fwu.c @@ -590,6 +590,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 @@ -743,25 +773,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)