From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 60045C433F5 for ; Thu, 20 Jan 2022 15:30:39 +0000 (UTC) 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) 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-Google-Smtp-Source: ABdhPJxgf/q7PO8cDIC6kjGLdY919hFsET16sZuVRhF6+YV3aHedrqvsWKa22ZCI7sHI0dVnm6wlWg== 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit 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; }