From patchwork Thu Jan 20 15:30:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masami Hiramatsu X-Patchwork-Id: 533545 Delivered-To: patch@linaro.org Received: by 2002:ad5:5d50:0:0:0:0:0 with SMTP id x16csp1676552imu; Thu, 20 Jan 2022 07:30:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJxaU5zWFGeM8xQAbEz0/e3HqNBK+z6LIPcC4gATE4la/Ekx5T9O+zyAk1ecET2ORFq5Yl3d X-Received: by 2002:a17:907:162c:: with SMTP id hb44mr29566012ejc.546.1642692638986; Thu, 20 Jan 2022 07:30:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642692638; cv=none; d=google.com; s=arc-20160816; b=fvHxuoPb5tSp1y6KtY+OomScA1aemXhyjnWYVHJuzyvwA3ycXZP+FyjPH3C7ktuis3 cNz2QU/ErX4Fd0OzxmuQ9X/TpH7EP2YYBiHEmAiKJkL6JZsY8m4i64KONwj2Xr1SQ+f5 IreasrraqWSGgjTba+grf2mgw9WK07YJ7ocA2Bys1S4Gf73O0STftTIIrThWvLheCPAT BzCD0iB+83UcJaGU04oN8kz1/HZMA8bwR/yXIWFMtMVM0XWtmcMbTtrJ3MeX1vpqHCth YUS3TjnFAsIABapHcsAIiAL8ekM/rMWbaPMmRwpeWrNtJL0fJMRg4j85y7/xkoqvZ6/f BD6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:user-agent:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=DSVlRbXB4Gc30pAyBuvP8ULNSVgwj7N6BLNTZ6l0ytg=; b=d5FJh/ULjOr2dzVYW/Un7XmudTBOa4bGuMdlMQllAzIlvmhGqTQjc49gvboCNWKz3y 0gqlcnd1ckqIOY3AHBbtS9qVQv+vqxLw9Vz1uVzAEPOHRJMsT6feGs47QGvFgiLhERjH 0E4DLQdk2/pEUpfVZAM93YZ8ROUunzOoxaxqW9D9wfPND3eVShTiQn31ad2fBApqRPRV /kdMdECNcRX1TEAFA/rVl9XnjqX6Tw6FhjgGMSRvywIzhrkMrn2kLH+riOrF81A+FVpT e2EyjX0W1NybMCERupkdk8QikFotwDPvlYE75t4meQWAepGzPQVqgjmp4+5xTfvfoMcd aMoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BVc19z0j; 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=pass (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 v19si2688571edc.188.2022.01.20.07.30.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jan 2022 07:30:38 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BVc19z0j; 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=pass (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 BA5C3838AE; Thu, 20 Jan 2022 16:30:31 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="BVc19z0j"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id EFF98838BD; Thu, 20 Jan 2022 16:30:29 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id CAE0D8389E for ; Thu, 20 Jan 2022 16:30:26 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masami.hiramatsu@linaro.org Received: by mail-pf1-x434.google.com with SMTP id x16so2404442pfu.13 for ; Thu, 20 Jan 2022 07:30:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=DSVlRbXB4Gc30pAyBuvP8ULNSVgwj7N6BLNTZ6l0ytg=; b=BVc19z0jDlQa+b6U5MyYMtmE3llakFvl2TDWJcoimk5lWFAokv90MMTpN79dJnCWgR XrnBb66brCKhCekC2qEWWfyF80DQ35pbtUEoxloFM9NPf4HGbmUBm+2cs83JZ/QKMMCd 5mE8YewPULc60S8E4ZKhZ13g9+GTqNUlLGGjzrXCm/bl14Rv+BQqI9+FteEL138bF8ku j7/QZPLdhIwR2OvtM4b6a4tVu6osH5bQHM/HGuOz3yugNrSrcD95UJ5Eyxj9YIPfJtzR l4fOVOYxBXQP5/92g2RqP7UQIL32ZubIseWiq3n6SdbeidO0givO5RooxG8ktPp8aEKU JU9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=DSVlRbXB4Gc30pAyBuvP8ULNSVgwj7N6BLNTZ6l0ytg=; b=Xa1l0SMBZ7T5wu1wM85WnBy0Bo8JbMZYjry51FNX9Aij4ICPFGI+Tf5/0QSuOWBDLf a+vMIqvTbhALwaYco+RalmvaCzGB0vaQPYgtWa4m+Es36qQS21jAio+kdBCFg4RnrMyB NSFdkjkrLiiCTHQKQi6mcPUoapDEd9ul0+36bjhYv4Ep3j/APChsRu3uhJzRVCCaiqNR 7ShX+IDzOwlTVZoNT8MoLO2DKh+Z9F1pXtQiucYgZz5ddmK7OTJRkF65dXVUmeAUT5Bj HFk3DKvQeHxHj/OYYF9Xbm5PEc+UlHgtNP+LlH2tcS3fZKjQ+jAb5DhWUWc/AN2IXNGh ri4Q== X-Gm-Message-State: AOAM531rNeeTQFIbvRSeDNhlhUtAvyF98M/oCM60vVv9bHJ2esHTBd9L eTduE6s8hN8h8Lk7lrXM1cTQSZDlAKBMjA== X-Received: by 2002:a05:6a00:1254:b0:4c2:796d:8769 with SMTP id u20-20020a056a00125400b004c2796d8769mr31295378pfi.85.1642692624989; Thu, 20 Jan 2022 07:30:24 -0800 (PST) Received: from localhost.localdomain (113x37x226x201.ap113.ftth.ucom.ne.jp. [113.37.226.201]) by smtp.gmail.com with ESMTPSA id w24sm2637871pgl.11.2022.01.20.07.30.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jan 2022 07:30:24 -0800 (PST) From: Masami Hiramatsu To: u-boot@lists.denx.de Cc: Masami Hiramatsu , Patrick Delaunay , Patrice Chotard , Heinrich Schuchardt , Alexander Graf , AKASHI Takahiro , Simon Glass , Bin Meng , Ilias Apalodimas , Jose Marinho , Grant Likely , Tom Rini , Etienne Carriere , Sughosh Ganu , Paul Liu Subject: [RFC PATCH 06/14] FWU: Calculate CRC32 in gpt_update_mdata() Date: Fri, 21 Jan 2022 00:30:20 +0900 Message-Id: <164269262036.39378.17845071044211742791.stgit@localhost> X-Mailer: git-send-email 2.25.1 In-Reply-To: <164269255955.39378.260729958623102750.stgit@localhost> References: <164269255955.39378.260729958623102750.stgit@localhost> User-Agent: StGit/0.19 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.2 at phobos.denx.de X-Virus-Status: Clean To avoid calculating crc32 in several places, do it in gpt_update_mdata(). This also ensures the mdata crc32 is always sane. Signed-off-by: Masami Hiramatsu --- lib/fwu_updates/fwu_mdata.c | 18 ------------------ lib/fwu_updates/fwu_mdata_gpt_blk.c | 13 ++++++++----- 2 files changed, 8 insertions(+), 23 deletions(-) diff --git a/lib/fwu_updates/fwu_mdata.c b/lib/fwu_updates/fwu_mdata.c index 252fcf50f6..1324771a71 100644 --- a/lib/fwu_updates/fwu_mdata.c +++ b/lib/fwu_updates/fwu_mdata.c @@ -92,7 +92,6 @@ int fwu_get_active_index(u32 *active_idx) int fwu_update_active_index(u32 active_idx) { int ret; - void *buf; struct fwu_mdata *mdata = NULL; if (active_idx > CONFIG_FWU_NUM_BANKS) { @@ -113,14 +112,6 @@ int fwu_update_active_index(u32 active_idx) mdata->previous_active_index = mdata->active_index; mdata->active_index = active_idx; - /* - * Calculate the crc32 for the updated FWU metadata - * and put the updated value in the FWU metadata crc32 - * field - */ - buf = &mdata->version; - mdata->crc32 = crc32(0, buf, sizeof(*mdata) - sizeof(u32)); - /* * Now write this updated FWU metadata to both the * FWU metadata partitions @@ -205,7 +196,6 @@ int fwu_mdata_check(void) int fwu_revert_boot_index(void) { int ret; - void *buf; u32 cur_active_index; struct fwu_mdata *mdata = NULL; @@ -223,14 +213,6 @@ int fwu_revert_boot_index(void) mdata->active_index = mdata->previous_active_index; mdata->previous_active_index = cur_active_index; - /* - * Calculate the crc32 for the updated FWU metadata - * and put the updated value in the FWU metadata crc32 - * field - */ - buf = &mdata->version; - mdata->crc32 = crc32(0, buf, sizeof(*mdata) - sizeof(u32)); - /* * Now write this updated FWU metadata to both the * FWU metadata partitions diff --git a/lib/fwu_updates/fwu_mdata_gpt_blk.c b/lib/fwu_updates/fwu_mdata_gpt_blk.c index 796b08e76f..0259da37c3 100644 --- a/lib/fwu_updates/fwu_mdata_gpt_blk.c +++ b/lib/fwu_updates/fwu_mdata_gpt_blk.c @@ -161,6 +161,14 @@ static int fwu_gpt_update_mdata(struct fwu_mdata *mdata) return -ENODEV; } + /* + * Calculate the crc32 for the updated FWU metadata + * and put the updated value in the FWU metadata crc32 + * field + */ + mdata->crc32 = crc32(0, (void *)&mdata->version, + sizeof(*mdata) - sizeof(u32)); + /* First write the primary partition*/ ret = gpt_write_mdata_partition(desc, mdata, primary_mpart); if (ret < 0) { @@ -457,7 +465,6 @@ int fwu_gpt_get_mdata(struct fwu_mdata **mdata) static int fwu_gpt_set_clear_image_accept(efi_guid_t *img_type_id, u32 bank, u8 action) { - void *buf; int ret, i; u32 nimages; struct fwu_mdata *mdata = NULL; @@ -480,10 +487,6 @@ static int fwu_gpt_set_clear_image_accept(efi_guid_t *img_type_id, else img_bank_info->accepted = 0; - buf = &mdata->version; - mdata->crc32 = crc32(0, buf, sizeof(*mdata) - - sizeof(u32)); - ret = fwu_gpt_update_mdata(mdata); goto out; }