From patchwork Fri Aug 30 11:40:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 823980 Delivered-To: patch@linaro.org Received: by 2002:a5d:48c1:0:b0:367:895a:4699 with SMTP id p1csp730596wrs; Fri, 30 Aug 2024 04:41:25 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXMgfoX4InYi+6bW38OR+GShaoC3FpwPKhc+hKA8QN6m67fOBE5E00Pzat6eAPHuit3O1DpVA==@linaro.org X-Google-Smtp-Source: AGHT+IGmKOTwSZUmPXfIOu1MnDkiSDoKScCk/BmTZLC9mGTbAtPy1SlVqVkE8+wiIJKkorETJUwu X-Received: by 2002:a17:907:3f1b:b0:a86:9fc2:8395 with SMTP id a640c23a62f3a-a897f777ab0mr482585366b.11.1725018084994; Fri, 30 Aug 2024 04:41:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1725018084; cv=none; d=google.com; s=arc-20240605; b=I4on6/92bQaNYlanqJsQ/UFOSN9/d/nNBwD3gpDawNChJEEjj/qiHIiTWOD/iAVzRy 115U/UF6ja3DqNQalN61bQfj0t3vz+wgGoAepwRfdI/PSiFDSvxIFxFqIT/1ceDe+AiD MSHQaNEKc4uRzae9DjfAuLT5kPKDW8T+k6wJZpFD3n3UV7Bx5hnb736a6qp/Kwr7u3R+ WAUDHOIU/I5o84ij2U/7luZ4IsijK4fVnPt3sz3cgFfJ95AJjP87+ONSommAQxWU1dFS MIbHD6wI8tcfPkTFoHaceN3+m8wNGiLdKjYIruTJiVoW54ks4uy1Pm2xABOTFpjPQHdi lUVw== 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=QAzf1nCy4Y09rGg+Tq+z7Pdj0KQ30qjHa3VT8t+GPFM=; fh=2L6lzFTxXJKn0sJyMiGOHr75auJVv+HSnsI1uFLsQPk=; b=edB8etYuJCu6oC+uo5va4STmYX3C95m2yxQPj4BXk7+7gd9mtidEGTGePeTCvQqBh7 V4d48M2I/+UQRdQcmoZgloEmQpmJAjdP9IaiimGzJJdMCNJ5QXEwxB1pwxlx7c4pAXXi 53IeEAYHzV+ssiaPeNY2QmXzmYZiWF2MOBbbFakTuylJ6Xk7Q+ImrYisMYqSA9iNGTxm MhJwkB5kVDRx29xSW70RUEmKJNfAGuysAJ+HlAh9LWfhbOQzvSkk+HghwEg5KU+eqgAk /Xyk47iTky6h5CwthYHFWDt0807Bz33qd0uOQDiLwszCZuAuoaCjCMfzgO9IugbIKOgw R8IQ==; 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 a640c23a62f3a-a8988f4222esi301057766b.10.2024.08.30.04.41.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Aug 2024 04:41:24 -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 698D688A9B; Fri, 30 Aug 2024 13:41:16 +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 B74A888AFA; Fri, 30 Aug 2024 13:41:14 +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_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, 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 B59C088A92 for ; Fri, 30 Aug 2024 13:41:12 +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 70E73339; Fri, 30 Aug 2024 04:41:38 -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 60D8D3F66E; Fri, 30 Aug 2024 04:41:10 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Michal Simek , Ilias Apalodimas , Heinrich Schuchardt , Sughosh Ganu Subject: [PATCH 1/6] fwu: v2: perform some checks before reading metadata Date: Fri, 30 Aug 2024 17:10:52 +0530 Message-Id: <20240830114057.891069-2-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240830114057.891069-1-sughosh.ganu@linaro.org> References: <20240830114057.891069-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 top level structure, followed by optional information on the updatable images. Perform some sanity checks on some of the fields in the top level structure to determine if the rest of the structure has to be read. Signed-off-by: Sughosh Ganu --- lib/fwu_updates/fwu_v2.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/fwu_updates/fwu_v2.c b/lib/fwu_updates/fwu_v2.c index 108bc9bb4a..d0d8a25929 100644 --- a/lib/fwu_updates/fwu_v2.c +++ b/lib/fwu_updates/fwu_v2.c @@ -58,24 +58,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; @@ -238,6 +220,24 @@ int fwu_init(void) return ret; } + 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; + } + ret = fwu_mdata_copies_allocate(mdata.metadata_size); if (ret) return ret; From patchwork Fri Aug 30 11:40:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 823981 Delivered-To: patch@linaro.org Received: by 2002:a5d:48c1:0:b0:367:895a:4699 with SMTP id p1csp730672wrs; Fri, 30 Aug 2024 04:41:34 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCX61FLOUwn0eCWUP31lqOIMVaUI4qm0JqxzG1PlsyeWZCttPc5PJwmTlemHB3gtYJO8EGaWLA==@linaro.org X-Google-Smtp-Source: AGHT+IHoeXlAXmkqIntQj9RwlMzht0nBJmna0re7wW9dEh7QaL+idq6FGa6aqFXSMTpSMmp3NbsY X-Received: by 2002:a17:907:3ea2:b0:a7a:cc10:667c with SMTP id a640c23a62f3a-a897f835ca1mr411171566b.16.1725018094774; Fri, 30 Aug 2024 04:41:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1725018094; cv=none; d=google.com; s=arc-20240605; b=ILLskJq07rNuQvm3VM6EhJVZAdg4LpcDba9RniUZhs4JI8GW5UTi35mcfLaKap9gxV rW8Es6kV9cL2c+FRU3hnkiCgGyWb4ZQBhLmhStnBHV3KnP6flMNoFoQW1kdecBNwdfWw /hXw18iZc5Nf2Fm1pPMPr0qf/9cUpQCSLtmBgHpEjjDg2PhTau4tX3gt5j/3RqoI1il2 PN4LUyT7gW3F/964sl2V8NO/tDVn6muJw/+nZNmhOhO/omgeDljL2F39chPrsCSlMquZ hq8cvilHQ17QI5SLB0hPYpcZjM6lpcN8VGF4g6uf4dO8IK+sWVVZJYL/lVnBLxIKlcfH OtfA== 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=eWtfQ2lFDfU6A8DoMDODMR66kg8+/IQ1zJDjoCInE/o=; fh=2L6lzFTxXJKn0sJyMiGOHr75auJVv+HSnsI1uFLsQPk=; b=V8wPtvmtDAU1L2omXV6SNz6eFTEblVf9ubtF2ikzwMwymqQFBkycox1ZyuRkqPEHjw P6EQNNzeur9pKE6qKi+8kM7dPHI7yGT65siQklmfEuOog+/Jcwosu0UMfgGXHrUdNpQj z8WkRQINFEjq3ePC+5obhLa18rGGFGyhSHuuBNC0jjemvvpoIwD+WHAb4vL45iGkPURS SWtscrxBkckpiHhi2xB6FKbO8jtxaWMd+/4Yo8udjXYgAt0hwJjPtb6paQ5XBXTzAFUg bE8Wv5naKKdRqxJ677CKPar3t0IVKob6lS6Q57fSQOLFt8l0cGrsZjRFWIZHR3TkBycS /Hkg==; 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 a640c23a62f3a-a8988f40946si283478466b.4.2024.08.30.04.41.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Aug 2024 04:41:34 -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 C606088AA4; Fri, 30 Aug 2024 13:41:17 +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 4961988A5B; Fri, 30 Aug 2024 13:41:17 +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_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, 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 189DF88A10 for ; Fri, 30 Aug 2024 13:41:15 +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 C54BA339; Fri, 30 Aug 2024 04:41:40 -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 B4D4E3F66E; Fri, 30 Aug 2024 04:41:12 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Michal Simek , Ilias Apalodimas , Heinrich Schuchardt , Sughosh Ganu Subject: [PATCH 2/6] fwu: v2: try reading both copies of metadata Date: Fri, 30 Aug 2024 17:10:53 +0530 Message-Id: <20240830114057.891069-3-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240830114057.891069-1-sughosh.ganu@linaro.org> References: <20240830114057.891069-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 --- lib/fwu_updates/fwu_v2.c | 77 +++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 36 deletions(-) diff --git a/lib/fwu_updates/fwu_v2.c b/lib/fwu_updates/fwu_v2.c index d0d8a25929..69306282aa 100644 --- a/lib/fwu_updates/fwu_v2.c +++ b/lib/fwu_updates/fwu_v2.c @@ -10,6 +10,12 @@ #include #define FWU_MDATA_VERSION 0x2U +#define FWU_IMG_DESC_OFFSET 0x20U + +static struct fwu_mdata g_mdata; + +#define PRI_PART 0x1U +#define SEC_PART 0x2U static inline struct fwu_fw_store_desc *fwu_get_fw_desc(struct fwu_mdata *mdata) { @@ -109,6 +115,31 @@ 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 == PRI_PART ? true : false, + sizeof(struct fwu_mdata)); + if (ret) + return false; + + if (g_mdata.version != FWU_MDATA_VERSION) + return false; + + if (!g_mdata.desc_offset) + return false; + + if (g_mdata.desc_offset != FWU_IMG_DESC_OFFSET) + return false; + + return true; +} + /** * fwu_populate_mdata_image_info() - Populate the image information * of the metadata @@ -169,24 +200,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; @@ -206,39 +227,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(PRI_PART) && + !fwu_get_mdata_mandatory(SEC_PART)) { log_err("FWU metadata read failed\n"); - return ret; - } - - 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; + 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 Fri Aug 30 11:40:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 823982 Delivered-To: patch@linaro.org Received: by 2002:a5d:48c1:0:b0:367:895a:4699 with SMTP id p1csp730725wrs; Fri, 30 Aug 2024 04:41:44 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWrbxJNop9soLsNx6+ybmXHRcVmZmY2lvYU0nKy5f7GqWLhUG31BIybpSxS6FL1PQ7zQBvkWA==@linaro.org X-Google-Smtp-Source: AGHT+IFFAm95DcbUQQ2ul/agGlGZXVOtddygIznm1UVTy8V28IbRntO5E2vfyQSid/SME4DioqOg X-Received: by 2002:a05:651c:551:b0:2f5:ce9:14df with SMTP id 38308e7fff4ca-2f6108a77ebmr42559751fa.40.1725018104397; Fri, 30 Aug 2024 04:41:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1725018104; cv=none; d=google.com; s=arc-20240605; b=YT8fS3O4PoFvPChdU1L2auPepZdmaIjI8vKhhXpwsg92vZAq3nWGdCaBANVzsx0oId S6SUQXBgrHFqCle3cbnN7jf04dZqarqNVitOMtn/DfSH3Wo5aXJo+GkCTTt3bqyUq3cj 5rhM8lOa2BnutaA3DfnUhJy5JMPSKgclE3RTFKuKlWl4Pb9ptgMCRUUUGje03feNHRkl ybeF4k9F1uANQRcE3QIwzT+Tue6X/xPjvJbXUmbKqdnS9M8RGzvT9um/+rcwxsJxIHNR YZ+obAsfbiWTbF3hkUZboFBz9Bok3rzSwfXC8jgccNdhsbDBSOhpULpowamimhx52uuX U9/g== 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=FpIKIeCZGHYlnsHoGK847YUmob1BkfmGgpoznuxSDG4=; fh=2L6lzFTxXJKn0sJyMiGOHr75auJVv+HSnsI1uFLsQPk=; b=UdNFXvLi3EGWMM+R44cQfttYW8hpVQWN80gjvrsohxCanaNxJefz1WCwqxq1Y8K4sS p+ou7Sze8EY6R9os2WYFxwQxBQTWQd+fmFB5qFkhER9J+wIpyrRbqknGFSL/tbcko0Tl DGQ4cVcrBGuRxzURdkO0SEmGIPUd8A8rBIyszAUfjZXJrgkibFroa/TFeUfCqE445xNr +mhuhLQupasVct+iILJdNxkyCVCBgMfpC/irVz8OERlBKhm+nnpvDv1yFqueBxMa3TUe eMS8IDwgOAxTOBJbHJDzu7Jaz5gVFRY8bqBKcfVVDVU9xdVmjHiL/qLO38LwKiMTLyPT VMYw==; 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 4fb4d7f45d1cf-5c226ce604asi2780239a12.341.2024.08.30.04.41.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Aug 2024 04:41:44 -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 2DDF088B1F; Fri, 30 Aug 2024 13:41:21 +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 73C4A88B40; Fri, 30 Aug 2024 13:41:19 +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_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, 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 7BFD688A10 for ; Fri, 30 Aug 2024 13:41:17 +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 25100339; Fri, 30 Aug 2024 04:41:43 -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 148023F66E; Fri, 30 Aug 2024 04:41:14 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Michal Simek , Ilias Apalodimas , Heinrich Schuchardt , Sughosh Ganu Subject: [PATCH 3/6] fwu: v1: do a version check for the metadata Date: Fri, 30 Aug 2024 17:10:54 +0530 Message-Id: <20240830114057.891069-4-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240830114057.891069-1-sughosh.ganu@linaro.org> References: <20240830114057.891069-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 --- 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 Fri Aug 30 11:40:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 823983 Delivered-To: patch@linaro.org Received: by 2002:a5d:48c1:0:b0:367:895a:4699 with SMTP id p1csp730792wrs; Fri, 30 Aug 2024 04:41:54 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWlZK0h04yKJ2DEhx2fFGSGQTU401CJLBfyZzrr6uITYTLcFDmwuSO/KPCDOfDIx0iR6w3l1g==@linaro.org X-Google-Smtp-Source: AGHT+IGODkLjEsQrQa7/Ee85iBElLAjSRFd6w7gGY3yvqEgv11+Yh5/9r7byF50U454IxwhIDZL6 X-Received: by 2002:a05:6402:5207:b0:5c0:a8cb:ff58 with SMTP id 4fb4d7f45d1cf-5c21ed8c3a8mr5201883a12.27.1725018114723; Fri, 30 Aug 2024 04:41:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1725018114; cv=none; d=google.com; s=arc-20240605; b=LxxLZjfD77qcK0k9UNdv9p/FRViObtkrjOLzJfes6QzWDUyOOfg4dFZYzTLv2xaXU0 YdU+aDzPiEi0QgpgH45YCHPTb0bcz6akSdqpUGcFNjkYi3OPDFkLQ+jXZm+ZJtB6gs3u lX64j/ZmphmMdtCYrE256jR7LMVQpZJoy7QvKAK5ENpLw1WGQuk10gD3u2Cos9vH8qfD Ou1XZA2xCobo94qN4E289ESu0gSh8gJ6issJkM11iPLF3eG4+j2RwyE3tCDUp+56CES/ gR5OUguqLDnkQ9AKQ4s8yVo7QmgDWtHE0XapPRANtq0e7M0rryWcrf4w9IeLZWOvLaoB eG0g== 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=p5lu1Yk5An6J2Uf6diuDXctu7ffGAslNL3Q81kFSc2E=; fh=2L6lzFTxXJKn0sJyMiGOHr75auJVv+HSnsI1uFLsQPk=; b=CVUbYYudohIQcq6Amfwej2eh9c+dguz7lnkf6OwfngGyEB8zTXy3n3zOfLEQECHrPx 2uYys5Foh5693aSVYvYgIOuA/H8RvziL4RKZ2OuW8Anhal2iGzxi1V2iq5NTE7TtrXLa D80PsaM6uxdOb8iTcaCUOn9Q/RV2vR+G/ZJ5OZwioka8tEHPHqf7ghU5CMX3R0VbG1Gg SjPCeHYFAS2IoYXTpmgYuG0hV6Uj8Su87Fq0kyVdKOuat/gOK54yv6/MNvgYikiZcAzW BJb7JKMLarlfFIHFU/71BYBUeBm5Q/Vjbf3UVzApeaJGxrias26W5eWRHwQa3pbjzgDT mP+g==; 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 4fb4d7f45d1cf-5c226cfab9dsi2793813a12.345.2024.08.30.04.41.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Aug 2024 04:41:54 -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 8CAF488B27; Fri, 30 Aug 2024 13:41:23 +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 279AC88A5B; Fri, 30 Aug 2024 13:41:22 +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_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, 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 E3DEF88B40 for ; Fri, 30 Aug 2024 13:41:19 +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 789ED339; Fri, 30 Aug 2024 04:41:45 -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 689063F66E; Fri, 30 Aug 2024 04:41:17 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Michal Simek , Ilias Apalodimas , Heinrich Schuchardt , Sughosh Ganu Subject: [PATCH 4/6] fwu: check all images for transitioning out of Trial State Date: Fri, 30 Aug 2024 17:10:55 +0530 Message-Id: <20240830114057.891069-5-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240830114057.891069-1-sughosh.ganu@linaro.org> References: <20240830114057.891069-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 --- 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 69306282aa..9c696952ed 100644 --- a/lib/fwu_updates/fwu_v2.c +++ b/lib/fwu_updates/fwu_v2.c @@ -88,6 +88,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 Fri Aug 30 11:40:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 823984 Delivered-To: patch@linaro.org Received: by 2002:a5d:48c1:0:b0:367:895a:4699 with SMTP id p1csp730856wrs; Fri, 30 Aug 2024 04:42:05 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUhidVvDmbV5IC8qfWYssqBca6G4Uo+G3+iF+w7TdZPYPSK00d03ZwNFzCGgbu//nq5QI5yEg==@linaro.org X-Google-Smtp-Source: AGHT+IEuK5jSqzi6z6fjtbp0G7VSvSiRp3vUXqjct5Gs6OnOnyi8vEDZU4m892iGxC+74Mmwf9lX X-Received: by 2002:a05:6512:e83:b0:52e:be2c:4b05 with SMTP id 2adb3069b0e04-53546aff49emr1265227e87.21.1725018125467; Fri, 30 Aug 2024 04:42:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1725018125; cv=none; d=google.com; s=arc-20240605; b=hyKCfBq0yo9cwyxsLls0OEiDoUYcLesUPwCh9z3wsH3WQa1DjxDnO/kgLliqMl21c0 DQKr4D2oQ3OQInxjHp4HEJwbyDG+KeOcUN4or/GShT5Z9GCr8Dwtw8Ab0a7Uy6aZCdvl vjRIihklJmRVX5dhmxNGKtShGkVeQ71h8IwD2tT/64oNLU8Wfqbny1L1ucrZjHcgshkx 8C89bRX6BHX22KuP3+jaKxbpc6M3T16EjQQzgUGtBZ8ZyHZSl76Eo9fAmodpfxvKEfdO H6COmWHz+fQzIfotmLsg51cqxpGRTCkrQsPtCIWekITxI0E/tNweorAZATLOW2y998zH RI7w== 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=FMnhbWmKlutE1PjXYi6lNod6gZPUgt/SbWX+ZjSZZUo=; fh=2L6lzFTxXJKn0sJyMiGOHr75auJVv+HSnsI1uFLsQPk=; b=CszPNg4X5woBB+cK4v9gA+LvaRjzFJbo1WAvggXmIuvEu9Rd3JrDTxgt51BkKdavER B7WSHwCYFBBf0TCaxqjJ/FpuJytBGPtGwHxTxGTXPyebOrSQOGLvxO0RTkfQeP6dwowO 7Q0DPEQQRp3vYlu64S5WW6Gh6JOjlnKVm6Ic4ODJlFEQ3FhuYCmGQW4fFAEmy5Z70ute VrutgCIM8TEDQcqwx16v1onSNzB8KpVjwWTc1+7LIGzKgbxKASHQxYRSOanJmobwwZ5q eqba7dMZFg9fBYM83ktLZfceYHJKZunH3uPCEaWQ20V2ZWoKEDzXYheFYfukDncYUbEK 9bug==; 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 a640c23a62f3a-a89891cbd09si290250266b.778.2024.08.30.04.42.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Aug 2024 04:42:05 -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 04A4F88B40; Fri, 30 Aug 2024 13:41:25 +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 06DC388B39; Fri, 30 Aug 2024 13:41:24 +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_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, 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 153B688A10 for ; Fri, 30 Aug 2024 13:41:22 +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 CC9E5339; Fri, 30 Aug 2024 04:41:47 -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 BBFE43F66E; Fri, 30 Aug 2024 04:41:19 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Michal Simek , Ilias Apalodimas , Heinrich Schuchardt , Sughosh Ganu Subject: [PATCH 5/6] fwu: add dependency checks for selecting FWU metadata version Date: Fri, 30 Aug 2024 17:10:56 +0530 Message-Id: <20240830114057.891069-6-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240830114057.891069-1-sughosh.ganu@linaro.org> References: <20240830114057.891069-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 --- 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 Fri Aug 30 11:40:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 823985 Delivered-To: patch@linaro.org Received: by 2002:a5d:48c1:0:b0:367:895a:4699 with SMTP id p1csp730897wrs; Fri, 30 Aug 2024 04:42:15 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCV5haXBMlRdsV5mE++xCQ3uJK4U0eUArtz+NWH3JT3DFm1YG/W1epRJaiOV9FA4uDttxcUe8g==@linaro.org X-Google-Smtp-Source: AGHT+IHZmaswAdcHMymwBIh27ytonz+tXH54oGTwynl4mz2M4HlDyux9aY5oZkw1dEQyX30UQ6w7 X-Received: by 2002:a17:907:7254:b0:a7a:ab8a:386 with SMTP id a640c23a62f3a-a897fab75d9mr468077166b.63.1725018134797; Fri, 30 Aug 2024 04:42:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1725018134; cv=none; d=google.com; s=arc-20240605; b=DPgvmqt5wP45tQU/ZKpiyvg56xA0ACQZEyR8szOK7murwFSFdm+WfFZIBPgN6mFJNT YN3ig7TeTSjzIhYuRDQ2zQsvvylDty2QyosBimYcCnukulI+xBtwN9P87L297u1TvQhd iH9/ttUWsdfmUd/kqwJaRowMkj/ksIf2GyLKxP1pF/6ZJw7F3Y0IfOZ7WD5wrTX+5fHc pXCXqvFKEEx193LByhWSvdXtDFX2OCZfwOdo+/oklbmVVjDBU9zB1zjnYcjw2zJtytSv 75/lCtlXc+MyOloL8p8h6ROUtNHm2hf0xtBH5JGkrbcgyp762IDFnWzrLKmECiiU2y1T ghuw== 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=+X4vqvF/psgQKFvtpoJWbCRn0bCCEBo+3Paq81cuLu0=; fh=2L6lzFTxXJKn0sJyMiGOHr75auJVv+HSnsI1uFLsQPk=; b=d5HE3d6Nw9kWZlElRUsl3F+B+GA5o8NN1IJUh9rrMWgyvDVQjpJmtgunqVSiCWWeV4 3SjzV/5thKGbqXVWw49+zcb2CwBrjuuvyPtMtPgySV9IJuVkQQjkAgzdL4Xu2hiAIImj XtlijGwvAPcPTJE1Pr1Lmwtt+DGfysIDozZA6lnV2FEMw4v5Ff1tPE53jZxM7COrPIi3 UMjN9tsTpEj9rLIs5ZWLPR+Qsz3qyoX/vvYswXVUQ0iatYLeoRZD2qtOLYE7817tiKAo Fc7DgEbJE4eIY+KiyHHNrYur2sXMl7Obsw11dE2l/s0KuGIBESrdfqYqkB8TLmVBLPks 47Zg==; 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 a640c23a62f3a-a89891cc503si279470866b.743.2024.08.30.04.42.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Aug 2024 04:42:14 -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 623DD88A8B; Fri, 30 Aug 2024 13:41:27 +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 6331688A92; Fri, 30 Aug 2024 13:41:26 +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_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, 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 69BFF88A10 for ; Fri, 30 Aug 2024 13:41:24 +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 2BD31339; Fri, 30 Aug 2024 04:41:50 -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 1BBDC3F66E; Fri, 30 Aug 2024 04:41:21 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Michal Simek , Ilias Apalodimas , Heinrich Schuchardt , Sughosh Ganu Subject: [PATCH 6/6] fwu: do not allow capsule processing on exceeding Trial Counter threshold Date: Fri, 30 Aug 2024 17:10:57 +0530 Message-Id: <20240830114057.891069-7-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240830114057.891069-1-sughosh.ganu@linaro.org> References: <20240830114057.891069-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 --- 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;