From patchwork Mon Sep 9 11:20:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 826578 Delivered-To: patch@linaro.org Received: by 2002:adf:a345:0:b0:367:895a:4699 with SMTP id d5csp1942642wrb; Mon, 9 Sep 2024 04:20:46 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVuMmQWMSYutL4Y26RaTfk66yhhJ5CEzm0TIHK/B7DsSdALS0TSns2Y4UKabxsDoiH0eNnKsQ==@linaro.org X-Google-Smtp-Source: AGHT+IEqlLhWlBuQh7AOcklBFnhnlRht6LNF4BPinkWK6h8vLCmOUDzyRdoTgdClt/yKlHLIWnLf X-Received: by 2002:a5d:4991:0:b0:368:5bb4:169b with SMTP id ffacd0b85a97d-378926858b2mr4009084f8f.4.1725880845857; Mon, 09 Sep 2024 04:20:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1725880845; cv=none; d=google.com; s=arc-20240605; b=cKM6lh5+DnFepMc/Ad8ITR9WK0OFbLC8RALx024g428tr45vWKVpZRfMEF7x063m/B MxMVYBZl/eEOFIo3WUw+zA+3cCu1xrKLC6Jh37pcGhZqV5zRP1JOMCQaKr9PPx47oEHV oAQY1Q9Wi2jjP7hJ/wNIu+uko+nBDu3UFw3BdhiVUtp6ChRFY3UGAbOX+f08dVunYf+P Rb68OWNXhMOD0I8xkWeivVwnq5uTrWarKgP9bcv0ZEUbYtv2NKjKwGFC1nSmBt7NKAmR 41yIP+sjy64yxkYMJGYlX23Fa5FNTrwJmrG/9OGw7dCpfK7FKTVpU94w/GP/5JwE7Q1O +hMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=iqKTT3l3V6Qveps9hcrahgdzGYym4qWVNOgLMFtYK28=; fh=2L6lzFTxXJKn0sJyMiGOHr75auJVv+HSnsI1uFLsQPk=; b=DGjQNZL494GZ6unamaza4UlLKLdp28y6MqMKog1rHnIBfRwk8PjX0eK2J+WNOFMGiJ ibKUY/7ezYXixDoNTrgaQp8HwNbiAhlxRFYhHyxgenORGSnyllcEhvFemiZlqPEJkNQQ Rs4Gab+YDXNLZEy0c4EYYdmVSCT7JCIxNLOquPluicmilMQvHIFHsy17AcHSxTZFs6kW Pd1n1m1858VcQCTmRpY7Eo9+rU62BdmKR0yG7ykhc0fmBKLofeUludzB1fsqCUz8JgnN e13si6IeHBrVRMmS1HmKpLOmEaVaB32NuXl2GtO9ee/qgbGVW4qmnDg3fY/UcrN2c/VI uT+Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; 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=fail (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 ffacd0b85a97d-378956b8deesi2049088f8f.594.2024.09.09.04.20.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Sep 2024 04:20:45 -0700 (PDT) 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; 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=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 5E57188DB3; Mon, 9 Sep 2024 13:20:41 +0200 (CEST) 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 AD99C88DAB; Mon, 9 Sep 2024 13:20:39 +0200 (CEST) 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, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE,SPF_SOFTFAIL 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 821F388CBD for ; Mon, 9 Sep 2024 13:20:37 +0200 (CEST) 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 935F3FEC; Mon, 9 Sep 2024 04:21:05 -0700 (PDT) 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 3628C3F73B; Mon, 9 Sep 2024 04:20:34 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Michal Simek , Ilias Apalodimas , Heinrich Schuchardt , Sughosh Ganu Subject: [PATCH v2 1/6] fwu: v2: try reading both copies of metadata Date: Mon, 9 Sep 2024 16:50:16 +0530 Message-Id: <20240909112021.1962801-2-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240909112021.1962801-1-sughosh.ganu@linaro.org> References: <20240909112021.1962801-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 In the version 2 of the FWU metadata, the metadata is broken into two parts, a top-level structure, which provides information on the total size of the structure among other things. Try reading the primary partition first, and if that fails, try reading the secondary partition. This will help in the scenario where the primary metadata partition has been corrupted, but the secondary partition is intact. Signed-off-by: Sughosh Ganu --- Changes since V1: * Squash patch 1 and 2 in the earlier version into a single patch. * Have a single check for image descriptor offset, and have a log message mention that image descriptor mandatory. * Use a macro FWU_IMG_DESC_OFFSET for the image descriptor offset. * Use the enum names for primary and secondary partitions from fwu.h instead of defining new macros. lib/fwu_updates/fwu_v2.c | 78 +++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 36 deletions(-) diff --git a/lib/fwu_updates/fwu_v2.c b/lib/fwu_updates/fwu_v2.c index 108bc9bb4a..a055a207bf 100644 --- a/lib/fwu_updates/fwu_v2.c +++ b/lib/fwu_updates/fwu_v2.c @@ -10,6 +10,9 @@ #include #define FWU_MDATA_VERSION 0x2U +#define FWU_IMG_DESC_OFFSET 0x20U + +static struct fwu_mdata g_mdata; static inline struct fwu_fw_store_desc *fwu_get_fw_desc(struct fwu_mdata *mdata) { @@ -58,24 +61,6 @@ static int fwu_mdata_sanity_checks(void) struct fwu_data *data = fwu_get_data(); struct fwu_mdata *mdata = data->fwu_mdata; - if (mdata->version != FWU_MDATA_VERSION) { - log_err("FWU metadata version %u. Expected value of %u\n", - mdata->version, FWU_MDATA_VERSION); - return -EINVAL; - } - - if (!mdata->desc_offset) { - log_err("No image information provided with the Metadata. "); - log_err("Image information expected in the metadata\n"); - return -EINVAL; - } - - if (mdata->desc_offset != 0x20) { - log_err("Descriptor Offset(0x%x) in the FWU Metadata not equal to 0x20\n", - mdata->desc_offset); - return -EINVAL; - } - num_banks = fwu_get_fw_desc(mdata)->num_banks; num_images = fwu_get_fw_desc(mdata)->num_images; @@ -127,6 +112,35 @@ static int fwu_trial_state_start(uint update_index) return 0; } +static bool fwu_get_mdata_mandatory(uint part) +{ + int ret = 0; + struct udevice *fwu_dev = fwu_get_dev(); + + memset(&g_mdata, 0, sizeof(struct fwu_mdata)); + + ret = fwu_read_mdata(fwu_dev, &g_mdata, + part == PRIMARY_PART ? true : false, + sizeof(struct fwu_mdata)); + if (ret) + return false; + + if (g_mdata.version != FWU_MDATA_VERSION) { + log_err("FWU partition %u has metadata version %u. Expected value of %u\n", + part, g_mdata.version, FWU_MDATA_VERSION); + return false; + } + + if (g_mdata.desc_offset != FWU_IMG_DESC_OFFSET) { + log_err("Descriptor Offset(0x%x) in the FWU Metadata partition %u not equal to 0x20\n", + g_mdata.desc_offset, part); + log_err("Image information expected in the metadata\n"); + return false; + } + + return true; +} + /** * fwu_populate_mdata_image_info() - Populate the image information * of the metadata @@ -187,24 +201,14 @@ int fwu_state_machine_updates(bool trial_state, uint32_t update_index) */ int fwu_get_mdata_size(uint32_t *mdata_size) { - int ret = 0; - struct fwu_mdata mdata = { 0 }; struct fwu_data *data = fwu_get_data(); - struct udevice *fwu_dev = fwu_get_dev(); if (data->metadata_size) { *mdata_size = data->metadata_size; return 0; } - ret = fwu_read_mdata(fwu_dev, &mdata, 1, - sizeof(struct fwu_mdata)); - if (ret) { - log_err("FWU metadata read failed\n"); - return ret; - } - - *mdata_size = mdata.metadata_size; + *mdata_size = g_mdata.metadata_size; if (!*mdata_size) return -EINVAL; @@ -224,21 +228,23 @@ int fwu_get_mdata_size(uint32_t *mdata_size) int fwu_init(void) { int ret; - struct fwu_mdata mdata = { 0 }; - struct udevice *fwu_dev = fwu_get_dev(); /* * First we read only the top level structure * and get the size of the complete structure. + * Try reading the first partition first, if + * that does not work, try the secondary + * partition. The idea is, if one of the + * partitions is corrupted, it should be restored + * from the intact partition. */ - ret = fwu_read_mdata(fwu_dev, &mdata, 1, - sizeof(struct fwu_mdata)); - if (ret) { + if (!fwu_get_mdata_mandatory(PRIMARY_PART) && + !fwu_get_mdata_mandatory(SECONDARY_PART)) { log_err("FWU metadata read failed\n"); - return ret; + return -1; } - ret = fwu_mdata_copies_allocate(mdata.metadata_size); + ret = fwu_mdata_copies_allocate(g_mdata.metadata_size); if (ret) return ret; From patchwork Mon Sep 9 11:20:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 826579 Delivered-To: patch@linaro.org Received: by 2002:adf:a345:0:b0:367:895a:4699 with SMTP id d5csp1942706wrb; Mon, 9 Sep 2024 04:20:55 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWwc7iM24kx35Om4FW3ylz9i4JECipynlF7mv2rxiUpEOkz9NzOM0WoVDzwaeutX4Tfs+PvEA==@linaro.org X-Google-Smtp-Source: AGHT+IGVBcFx7Ti0YtbK5dLFeUjEkBE6Qcoki3/Xz31BJeYIn8TxuKMkEMO3SWHfe2G5ICMcBf4C X-Received: by 2002:a5d:4447:0:b0:374:c4c2:5ad5 with SMTP id ffacd0b85a97d-37888847f85mr7059180f8f.27.1725880854966; Mon, 09 Sep 2024 04:20:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1725880854; cv=none; d=google.com; s=arc-20240605; b=YZfYEcQT0lbm9fn2040W+vOsYuzZE2BHaq+NgG6Gk1nJsJlxKTpMwmhUNV+voeANMs gGSro5tGmbXztKHMyOiN4v1Qn6jwCDVONP1rjVqFfHgkHBBiymwW4MVedmMsdwUvqupM yh14wW71Vd1XFQ8cQPAfUTbjQ+mLXk/1iXkPItSsA1oC0FwqkzuF3WMr40m0XkWZwnti +FyDDWetE7IcVHFQHN1MS9nrAp50HcpBxmTGJmbpJ5lnLkcLvL9UeB+zqHNn/tzaFcpz o6qUGNRLSBSUJ6P2ooPvLl1li3eP+4ccbZr8OjwW/Tkf8A2ubz0yanqtHyScZ794MkQl 3h7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=VRcGvJCQNqeZ6W70LjicGMC+HksFaaDbdf7/JQwCckk=; fh=2L6lzFTxXJKn0sJyMiGOHr75auJVv+HSnsI1uFLsQPk=; b=AyPNobXB84a6OayOZrwpyq0VCzsm2ymembdIpP27JvFGJSS+GfGJpQRu+Bmy22u3jR WUY1OzsPZvoewtpPFCvTcIz2x3s/XQw5ZPdlwHPxz/CHXEi8aHTpnfLpkeECoS9mjXVg 8eWnqnti6j/xLxex1lOE6lmWkRvlLkGoDzhzHKqa0feObV0N9F0+PAiq3OPAxlG4YBSa 5EgatFZsV0yWTh4diT0VnQjIhqkvwmtknDaVqeuSmgBwmewvIe/xxB3t9fM9hcF2/+BY 5Mp4yfFh9JrQj2TmynXA2TGLRWYeAPGLKQ7TtWQ8s3BJrBrVj72qHnlMEIi+StguoOk9 LhVQ==; dara=google.com 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 ffacd0b85a97d-378956dec4asi2076833f8f.977.2024.09.09.04.20.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Sep 2024 04:20:54 -0700 (PDT) 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 B8AF088DC6; Mon, 9 Sep 2024 13:20:42 +0200 (CEST) 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 C1EEE88DBE; Mon, 9 Sep 2024 13:20:41 +0200 (CEST) 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, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE,SPF_SOFTFAIL 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 D3C5388CBD for ; Mon, 9 Sep 2024 13:20:39 +0200 (CEST) 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 E3E2BFEC; Mon, 9 Sep 2024 04:21:07 -0700 (PDT) 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 85A6A3F73B; Mon, 9 Sep 2024 04:20:37 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Michal Simek , Ilias Apalodimas , Heinrich Schuchardt , Sughosh Ganu Subject: [PATCH v2 2/6] fwu: v1: do a version check for the metadata Date: Mon, 9 Sep 2024 16:50:17 +0530 Message-Id: <20240909112021.1962801-3-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240909112021.1962801-1-sughosh.ganu@linaro.org> References: <20240909112021.1962801-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 Do a sanity check that the version of the FWU metadata that has been read aligns with the version enabled in the image. This allows to indicate an early failure as part of the FWU module initialisation. Signed-off-by: Sughosh Ganu --- Changes since V1: None lib/fwu_updates/fwu_v1.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/fwu_updates/fwu_v1.c b/lib/fwu_updates/fwu_v1.c index efb8d51500..023e43728d 100644 --- a/lib/fwu_updates/fwu_v1.c +++ b/lib/fwu_updates/fwu_v1.c @@ -146,6 +146,7 @@ int fwu_init(void) { int ret; uint32_t mdata_size; + struct fwu_mdata mdata = {0}; fwu_get_mdata_size(&mdata_size); @@ -157,10 +158,16 @@ int fwu_init(void) * Now read the entire structure, both copies, and * validate that the copies. */ - ret = fwu_get_mdata(NULL); + ret = fwu_get_mdata(&mdata); if (ret) return ret; + if (mdata.version != 0x1) { + log_err("FWU metadata version %u. Expected value of %u\n", + mdata.version, FWU_MDATA_VERSION); + return -EINVAL; + } + fwu_data_init(); return 0; From patchwork Mon Sep 9 11:20:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 826580 Delivered-To: patch@linaro.org Received: by 2002:adf:a345:0:b0:367:895a:4699 with SMTP id d5csp1942791wrb; Mon, 9 Sep 2024 04:21:04 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWN6CbfOXfzTSN76vaDMreQwwCj5GVtshEL3PPKIEcQJCy/wnSImwW7ID8tdMPOiXfAGqBb0g==@linaro.org X-Google-Smtp-Source: AGHT+IGOrvWu1bK/lVvgo4Bn9OoM8Xrb66I4zfQYwOvFPDAKPhdEcBgf6YC77d4emgqDfd2vX2pb X-Received: by 2002:a5d:66cd:0:b0:374:c21a:9dd4 with SMTP id ffacd0b85a97d-3788882afcamr7286329f8f.20.1725880864310; Mon, 09 Sep 2024 04:21:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1725880864; cv=none; d=google.com; s=arc-20240605; b=B/V51u/GpakkZ6pOC01Nq7g9NjjvDvSUiUZWtA/Ihrz7bpy/hAifq+i1k5HJhtQ12W AGdlfui3pCb4eFG5m83LAomyuHbkJU2gULxMHg8xkZsjQV1U5wX+xIYP+GgdANPEqrep Bi/yYofkNqSqFFfasG9/ez9+nPBagzYZ6NE1DibXW+qxgep0G1hzH9L+vnWDJsfJLZ/k 8FEKA4Gf3uYmTXgaddFFpAfROSiZAFbeLBvbyaZAJ2k9ko9l9H54+yJnNKA966GJedEu /cpaEBWbqUgbAHT+Oqs0FO2bBDxZsUIG0Z0Sc88BxD/D87JLp67szqBLSNfPwhpX+XAk sXuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=jvCnbYVSHbHxsAHKc+HJCFEIsLGF4XiXVT8IsngNvec=; fh=2L6lzFTxXJKn0sJyMiGOHr75auJVv+HSnsI1uFLsQPk=; b=kNChccLG78pAIYhH77ZszqXtJy9YRgYrlwJ3QYcbuBCZxp/FILNAD467fDuES3otxM 8FGeXGr/08i786yxNcVtfQ2iyTMWbWV7EmYfHAMmMq0rDyW0hfv9YMl3LxY/mSsy12uu eHn6SonQl3wOwinE6fuHGxSw8oVdMTcNDlg558HY/9HcCdtN4IlWg6u3WjWyeDRh/7kd AMSqogoDmqTux91BXSObQ5N18w1LESk1PylTZqGzlcdaUlhlcZ+lEGd/zq7aNJ732z0+ Ta0tt9VJ/UXgODMWRwjGb1mKQ0I+R5HcAdw4hRoy+lcj/C6SBDrSpxyDwUiJRc+aQWMR dpcg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; 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=fail (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 ffacd0b85a97d-378956d8f99si2055625f8f.1052.2024.09.09.04.21.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Sep 2024 04:21:04 -0700 (PDT) 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; 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=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 2173988DAB; Mon, 9 Sep 2024 13:20:47 +0200 (CEST) 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 D6DD788CBD; Mon, 9 Sep 2024 13:20:45 +0200 (CEST) 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, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE,SPF_SOFTFAIL 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 41E5C88DBF for ; Mon, 9 Sep 2024 13:20:42 +0200 (CEST) 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 40FD6FEC; Mon, 9 Sep 2024 04:21:10 -0700 (PDT) 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 D72BA3F73B; Mon, 9 Sep 2024 04:20:39 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Michal Simek , Ilias Apalodimas , Heinrich Schuchardt , Sughosh Ganu Subject: [PATCH v2 3/6] fwu: check all images for transitioning out of Trial State Date: Mon, 9 Sep 2024 16:50:18 +0530 Message-Id: <20240909112021.1962801-4-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240909112021.1962801-1-sughosh.ganu@linaro.org> References: <20240909112021.1962801-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 platform transitions out of Trial State into the Regular State only when all the images in the update bank have been accepted. Check for this condition before transitioning out of Trial State. Signed-off-by: Sughosh Ganu Tested-by: Michal Simek --- Changes since V1: None include/fwu.h | 11 +++++++++++ lib/fwu_updates/fwu.c | 25 +++++++++++++++++++++++++ lib/fwu_updates/fwu_v1.c | 9 ++++++--- lib/fwu_updates/fwu_v2.c | 3 +++ 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/include/fwu.h b/include/fwu.h index 77ec65e618..70a5166f5e 100644 --- a/include/fwu.h +++ b/include/fwu.h @@ -417,4 +417,15 @@ int fwu_state_machine_updates(bool trial_state, uint32_t update_index); */ int fwu_init(void); +/** + * fwu_bank_accepted() - Has the bank been accepted + * @data: Version agnostic FWU metadata information + * @bank: Update bank to check + * + * Check in the given bank if all the images have been accepted. + * + * Return: true if all images accepted, false otherwise + */ +bool fwu_bank_accepted(struct fwu_data *data, uint32_t bank); + #endif /* _FWU_H_ */ diff --git a/lib/fwu_updates/fwu.c b/lib/fwu_updates/fwu.c index c7fc8987be..a94a769a2b 100644 --- a/lib/fwu_updates/fwu.c +++ b/lib/fwu_updates/fwu.c @@ -28,6 +28,31 @@ enum { IMAGE_ACCEPT_CLEAR, }; +/** + * fwu_bank_accepted() - Has the bank been accepted + * @data: Version agnostic FWU metadata information + * @bank: Update bank to check + * + * Check in the given bank if all the images have been accepted. + * + * Return: true if all images accepted, false otherwise + */ +bool fwu_bank_accepted(struct fwu_data *data, uint32_t bank) +{ + u32 i; + struct fwu_image_entry *img_entry; + struct fwu_image_bank_info *img_bank_info; + + img_entry = &data->fwu_images[0]; + for (i = 0; i < CONFIG_FWU_NUM_IMAGES_PER_BANK; i++) { + img_bank_info = &img_entry[i].img_bank_info[bank]; + if (!img_bank_info->accepted) + return false; + } + + return true; +} + static int trial_counter_update(u16 *trial_state_ctr) { bool delete; diff --git a/lib/fwu_updates/fwu_v1.c b/lib/fwu_updates/fwu_v1.c index 023e43728d..c311a8857a 100644 --- a/lib/fwu_updates/fwu_v1.c +++ b/lib/fwu_updates/fwu_v1.c @@ -52,11 +52,14 @@ static void fwu_data_init(void) memcpy(dst_img_info, src_img_info, image_info_size); } -static int fwu_trial_state_update(bool trial_state) +static int fwu_trial_state_update(bool trial_state, uint32_t bank) { int ret; struct fwu_data *data = fwu_get_data(); + if (!trial_state && !fwu_bank_accepted(data, bank)) + return 0; + if (trial_state) { ret = fwu_trial_state_ctr_start(); if (ret) @@ -112,9 +115,9 @@ void fwu_populate_mdata_image_info(struct fwu_data *data) * Return: 0 if OK, -ve on error */ int fwu_state_machine_updates(bool trial_state, - __maybe_unused uint32_t update_index) + uint32_t update_index) { - return fwu_trial_state_update(trial_state); + return fwu_trial_state_update(trial_state, update_index); } /** diff --git a/lib/fwu_updates/fwu_v2.c b/lib/fwu_updates/fwu_v2.c index a055a207bf..ce46904ff2 100644 --- a/lib/fwu_updates/fwu_v2.c +++ b/lib/fwu_updates/fwu_v2.c @@ -85,6 +85,9 @@ static int fwu_bank_state_update(bool trial_state, uint32_t bank) struct fwu_data *data = fwu_get_data(); struct fwu_mdata *mdata = data->fwu_mdata; + if (!trial_state && !fwu_bank_accepted(data, bank)) + return 0; + mdata->bank_state[bank] = data->bank_state[bank] = trial_state ? FWU_BANK_VALID : FWU_BANK_ACCEPTED; From patchwork Mon Sep 9 11:20:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 826581 Delivered-To: patch@linaro.org Received: by 2002:adf:a345:0:b0:367:895a:4699 with SMTP id d5csp1942866wrb; Mon, 9 Sep 2024 04:21:15 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUb/zGErXuSmK6W1uObG/ZbojhFuUqav4xgkM4xC6gnT2F/xGo8xIdyCsfipDmVBARHQCeuzQ==@linaro.org X-Google-Smtp-Source: AGHT+IGN+Nt2gK+QW72ADyPBlnsJLXyixQI44PcYZtC5Cz7OqKSXVqGWvdG6Po6pkkVUknEokkQH X-Received: by 2002:adf:f28a:0:b0:374:c614:73df with SMTP id ffacd0b85a97d-3788968c865mr7808671f8f.57.1725880874618; Mon, 09 Sep 2024 04:21:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1725880874; cv=none; d=google.com; s=arc-20240605; b=ROfyJRvujbxsVvPhKJeVUA5HuK3O8wKAQCZ3MJI3Yb06eArfMdD1ucNd4+T0Cj23a2 wxYxO1j02MOCpa/Xx4YuTk4jjHBVzo7UAd39ibUCyqRdFLoVTe45sTVep1qXI7j+KEUK MSzbPYeVHhicsqpBtNN2mw4CEDr1J6uBQsg4DSrsCxFlJ86idi2oAcKvI+KJcejj5QZw bKKrhMyPQMzhMWa2nrgmXCbZ+DCg+hQVxUlqUL97WpzE5EYeJpQ1BS2w3AbGtLYvveGf If7ZQvp7f7en9KJFIIV2Mkdi6zwHGiDFVgir7G4wP4bdtKsVrNxL9ASYBTbxg656SSab mUww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=PD9RH4rpZvq1V5hNFTV0469OioQV9C6jUU2UZJY4pTg=; fh=2L6lzFTxXJKn0sJyMiGOHr75auJVv+HSnsI1uFLsQPk=; b=I0+mJHU3nS3eTr78idrWLmV3McbeY3kK6v/x2tpiUCwprZfy5ZIJ7sA008J7V6dQ7h PnC1y0Pg8w9tlZesTucqSqb4gDHJ69p9ti8mdognbnY8hDcRqR3wxfz1T0dwzYzT1DNE CLalWaBmTCrRiiUhQgybpzmi3nw+De9vqH784DYD8f9vo3ZBj4ceGy0v+ORMabdifVZ2 QINdThtx3yaQHNPPVueUoLwavOoRWQ2ruzZFqjL5fH4CvNAqhIN2Rp8bKrIEWB+zhwez WSrKt9GX5r3YXxqUYR83bAnaNWEZ3/pHnSNPqLbVJTuPXyu/LK6btgB/CGthlTGW3L/9 jaYQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; 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=fail (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 5b1f17b1804b1-42cbb35b821si2362545e9.95.2024.09.09.04.21.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Sep 2024 04:21:14 -0700 (PDT) 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; 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=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 7B7F688DB7; Mon, 9 Sep 2024 13:20:48 +0200 (CEST) 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 77D8388CBD; Mon, 9 Sep 2024 13:20:46 +0200 (CEST) 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, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE,SPF_SOFTFAIL 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 81BC088CE4 for ; Mon, 9 Sep 2024 13:20:44 +0200 (CEST) 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 9292AFEC; Mon, 9 Sep 2024 04:21:12 -0700 (PDT) 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 348F13F73B; Mon, 9 Sep 2024 04:20:41 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Michal Simek , Ilias Apalodimas , Heinrich Schuchardt , Sughosh Ganu Subject: [PATCH v2 4/6] fwu: add dependency checks for selecting FWU metadata version Date: Mon, 9 Sep 2024 16:50:19 +0530 Message-Id: <20240909112021.1962801-5-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240909112021.1962801-1-sughosh.ganu@linaro.org> References: <20240909112021.1962801-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 FWU code supports both versions of the FWU metadata, i.e. v1 and v2. A platform can then select one of the two versions through a config symbol. Put a dependency in the FWU metadata version selection config symbol to ensure that both versions of the metadata cannot be enabled. Signed-off-by: Sughosh Ganu Reviewed-by: Michal Simek --- Changes since V1: None lib/fwu_updates/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/fwu_updates/Kconfig b/lib/fwu_updates/Kconfig index 51b7fbbefd..a722107c12 100644 --- a/lib/fwu_updates/Kconfig +++ b/lib/fwu_updates/Kconfig @@ -40,6 +40,7 @@ config FWU_MDATA_V1 config FWU_MDATA_V2 bool "Enable support FWU Metadata version 2" + depends on !FWU_MDATA_V1 help The FWU specification supports two versions of the metadata structure. This option enables support for FWU From patchwork Mon Sep 9 11:20:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 826582 Delivered-To: patch@linaro.org Received: by 2002:adf:a345:0:b0:367:895a:4699 with SMTP id d5csp1942926wrb; Mon, 9 Sep 2024 04:21:23 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCX9Wf3uT5MjmDyo1HHhjglAs5wCvJScvhMHLd2ZDA6dqo9X7A3Lej/WUxfClYDBcfX34KsiJA==@linaro.org X-Google-Smtp-Source: AGHT+IGbpByfWvf1e1uYKKRGeUIDgSD4s7HFmtV4KEKPE6F7bWUP47OtcsjVwjJduhJcS2SQm1I+ X-Received: by 2002:a05:600c:1c99:b0:42c:b4a2:a1aa with SMTP id 5b1f17b1804b1-42cb4a2a3a4mr29288095e9.17.1725880883604; Mon, 09 Sep 2024 04:21:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1725880883; cv=none; d=google.com; s=arc-20240605; b=CQqw+1uc2TV6OQRwFsx78W+Mevi62yW4/ow6G6f+47Ru7HInT9ToL2tUlMjrM29YuS QYOO3CAeTHPQQvDMLH/mWVafE0p14QuMImyNtkmylO3b7j/Cc00AOyLtRd76k64x6ARH 6eVLyxa+eHDliCh2f7JQrkFGHvo49NmZj/Q0am2m4VawE+RyOlZZdLhaw4YGTcIFip7i CY52DKY4o2f6uy7ebUc1qR5dKyLcRcDw/8iaV10I2ORtLZRTFEz5Y7kw9jJrDsT84OYi FqoO4YJugN2GYnJG1TNY0xeJzSMOwkK6FiRh4OgvvINd6Hocxy2MI891lIjrHKEYzFUl SBrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=b+rz4FqrBcGHEwj9uREOogNXrvIimAezMiu2jvCGdBU=; fh=2L6lzFTxXJKn0sJyMiGOHr75auJVv+HSnsI1uFLsQPk=; b=GMk8VXbNl6lI1G790/N1AmLZZLZJM9NO5vIoc9TgLvVkaEbWVNWVspodoxZpmtZXM1 pMVMGnn9kZpxNBbTXUc8AP4AHSwTVbDkIpQ72SNZ7xTSzDSWPgVec162NtHJxYerkVdj crmOXPFMXu9mA4doZDK4dK9i7NTZ31mDH+w0nB2kZr0Ww/15dbWycVuR0AwrHWb/uFle tHFcmrgFKDGGZaZ2Km+wF6I6/KsB8W1iS7tUsaaV615KE+tL8R8tVC63LpTlObziK9Gp W7zH5qRBr5e16sY0rNrTfkDcS7U/+0Nriad0cW8DJAmXbXOqEwdjrcoOzk86Ldl7lZ+7 xzlg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; 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=fail (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 5b1f17b1804b1-42cb2274082si17978985e9.169.2024.09.09.04.21.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Sep 2024 04:21:23 -0700 (PDT) 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; 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=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 D703B88DC1; Mon, 9 Sep 2024 13:20:49 +0200 (CEST) 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 CED9D88DBF; Mon, 9 Sep 2024 13:20:48 +0200 (CEST) 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, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE,SPF_SOFTFAIL 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 D9B6E88CBD for ; Mon, 9 Sep 2024 13:20:46 +0200 (CEST) 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 E4C84FEC; Mon, 9 Sep 2024 04:21:14 -0700 (PDT) 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 864F03F73B; Mon, 9 Sep 2024 04:20:44 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Michal Simek , Ilias Apalodimas , Heinrich Schuchardt , Sughosh Ganu Subject: [PATCH v2 5/6] fwu: do not allow capsule processing on exceeding Trial Counter threshold Date: Mon, 9 Sep 2024 16:50:20 +0530 Message-Id: <20240909112021.1962801-6-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240909112021.1962801-1-sughosh.ganu@linaro.org> References: <20240909112021.1962801-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 When in Trial State, the platform keeps a count of the number of times it has booted in the Trial State. Once the threshold of the maximum allowed count exceeds, the platform reverts to boot from a different bank on subsequent boot, thus coming out of the Trial State. It is expected that all the updated images would be accepted or rejected while the platform is in Trial State. Put in checks so that it is not possible to apply an empty capsule once the max Trial Count exceeds. Signed-off-by: Sughosh Ganu Tested-by: Michal Simek --- Changes since V1: None lib/fwu_updates/fwu.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/fwu_updates/fwu.c b/lib/fwu_updates/fwu.c index a94a769a2b..7f085a0211 100644 --- a/lib/fwu_updates/fwu.c +++ b/lib/fwu_updates/fwu.c @@ -113,6 +113,8 @@ static int fwu_trial_count_update(void) ret = fwu_revert_boot_index(); if (ret) log_err("Unable to revert active_index\n"); + + trial_counter_update(NULL); ret = 1; } else { log_info("Trial State count: attempt %d out of %d\n", @@ -762,8 +764,8 @@ static int fwu_boottime_checks(void) return 0; in_trial = in_trial_state(); - if (!in_trial || (ret = fwu_trial_count_update()) > 0) - ret = trial_counter_update(NULL); + + ret = in_trial ? fwu_trial_count_update() : trial_counter_update(NULL); if (!ret) boottime_check = 1; From patchwork Mon Sep 9 11:20:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 826583 Delivered-To: patch@linaro.org Received: by 2002:adf:a345:0:b0:367:895a:4699 with SMTP id d5csp1942999wrb; Mon, 9 Sep 2024 04:21:33 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCX7vR7qFy0v0Hvhp4ofN8GJl5Q76c5PZRLy2NchvShNaZrhfXFJ4HkLIpnaLI4uHvBW29u3BQ==@linaro.org X-Google-Smtp-Source: AGHT+IE+wG4F+6jh8cwZMcBrstx6wn5yueaIjWT3HWOZJyS9UKVQh9L3GQq1ehffMs/5xCuWeJYj X-Received: by 2002:adf:fc88:0:b0:371:8ec6:f2f0 with SMTP id ffacd0b85a97d-378895cb875mr7200997f8f.16.1725880893086; Mon, 09 Sep 2024 04:21:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1725880893; cv=none; d=google.com; s=arc-20240605; b=k8kcrPsO5Pg9M/4oN8Vk0efi5rcdaqIkZsV0WgkVNOgIPaPhZ4yvWxoI2MCZtzfKQI 7T5gByYvWppvpSy6qaQN0AfoKvrfMU6Y98NSECW2nWrBs4O1eTXqoop52H/X1AUYTN+S 4yDNciGHhcv51lV6giutYBU8QD1qtHKQdQfVqukb478/v7AbbI/0BjRFA+GC6W4SmzrG CY+C6I3FGBl8Axr8dnGWVs79fR7ypbTkv/wCdbe0sOM+CtuTGb8MQ/oSqkMwFqQ2qNUJ nppNxRfAiqCh4XniAKYKZwp4KdxjW+pP2jd+tsPrlqvzDJvtfQkbWpQFNuDx6x+0PR7W Lcog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=vOgmLv8HmPDn0W+uQ+79TConf6pnie5tbnIQwwP/h58=; fh=2L6lzFTxXJKn0sJyMiGOHr75auJVv+HSnsI1uFLsQPk=; b=ll9NdzpRjC80ukXq+ROKEcXFrPE8P5a5CzBxbmF2/+8fJrbPiVOWLXCh1c9+4jjNIh WsnhXI3IUaSHhK7Zt7jBumiNHeruiATKL2dGUa8vr/+MeZRY8VOG5qFjfTwTvk48K2HD L5SxFiHV7Yr2hT6jocugDAuqOZxk3oPcziqrAc88kyMrvY49w6JxRcVtaPdVfCPc/nHW yznw/XnH/ZPKA0RaKnj8I4aThVLmQv6ZdgHLJ3oFkjW2/H8lY3blNwYShfRIgzBLLcqZ 0M80X2MTsB/3ILHgW0RI2N2IltDCK21+TD82wySH88MJ1Hj84G/yIweNbPvPBj1qRJhu CkBg==; dara=google.com 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 ffacd0b85a97d-378956b918fsi2069021f8f.697.2024.09.09.04.21.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Sep 2024 04:21:33 -0700 (PDT) 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 406E388DD9; Mon, 9 Sep 2024 13:20:52 +0200 (CEST) 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 48A0288DD9; Mon, 9 Sep 2024 13:20:51 +0200 (CEST) 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, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE,SPF_SOFTFAIL 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 4F48088CBD for ; Mon, 9 Sep 2024 13:20:49 +0200 (CEST) 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 59C2DFEC; Mon, 9 Sep 2024 04:21:17 -0700 (PDT) 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 D81623F73B; Mon, 9 Sep 2024 04:20:46 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Michal Simek , Ilias Apalodimas , Heinrich Schuchardt , Sughosh Ganu Subject: [PATCH v2 6/6] fwu: print a message if empty capsule checks fail Date: Mon, 9 Sep 2024 16:50:21 +0530 Message-Id: <20240909112021.1962801-7-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240909112021.1962801-1-sughosh.ganu@linaro.org> References: <20240909112021.1962801-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 When dealing with processing of the empty capsule, the capsule gets applied only when the checks for the empty capsule pass. Print a message to highlight if empty capsule checks fail, and return an error value, similar to the normal capsules. Signed-off-by: Sughosh Ganu --- Changes since V1: New patch lib/efi_loader/efi_capsule.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c index 635088f25a..22677f395b 100644 --- a/lib/efi_loader/efi_capsule.c +++ b/lib/efi_loader/efi_capsule.c @@ -563,9 +563,14 @@ static efi_status_t efi_capsule_update_firmware( bool fw_accept_os; if (IS_ENABLED(CONFIG_FWU_MULTI_BANK_UPDATE)) { - if (fwu_empty_capsule_checks_pass() && - fwu_empty_capsule(capsule_data)) - return fwu_empty_capsule_process(capsule_data); + if (fwu_empty_capsule(capsule_data)) { + if (fwu_empty_capsule_checks_pass()) { + return fwu_empty_capsule_process(capsule_data); + } else { + log_err("FWU empty capsule checks failed. Cannot start update\n"); + return EFI_INVALID_PARAMETER; + } + } if (!fwu_update_checks_pass()) { log_err("FWU checks failed. Cannot start update\n");