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;