From patchwork Thu Feb 17 15:11:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masami Hiramatsu X-Patchwork-Id: 543382 Delivered-To: patch@linaro.org Received: by 2002:ac0:e142:0:0:0:0:0 with SMTP id r2csp447907imn; Thu, 17 Feb 2022 07:11:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJzjnCZp1gsOwdtDU2YRV6LkZxyYX4FApaMUJZK5FN3TYQC8BszG0WX5XtLPGkxHWzgty7pZ X-Received: by 2002:a17:906:b887:b0:6ce:36cb:1e18 with SMTP id hb7-20020a170906b88700b006ce36cb1e18mr2752328ejb.95.1645110708922; Thu, 17 Feb 2022 07:11:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645110708; cv=none; d=google.com; s=arc-20160816; b=Zo51nL+znMUGC5/sJapioz1UCtAudMmPP0QgLqHM09WxkcC5eo8kbXdlIIoKkwNm1a OghIjMSS0/RtDO7sUkdwPCfy2GmAbKFXmRgbCPb/4osdl15vQ30aQWQ+ANrc1rk1dpt6 iLfJafMOZvLISGVULa19TkWsxiY8cQS5TImMESNSwXvba1iT9+C6qRJGAajeZ3HqRx51 PutQja1XgREfjZbUjoE5LS2LrkS56U2FBAoJ8UbWLQHcfyi/2CVOIYQf2jxxh4If8AIg IWZ0wDmDzY14d+0opZKOodpNUEz/dIuuOrxU2HnBALq3krB8APv/Uf+taYA6DEBCDUYE ju3Q== 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=60sMsKZb710UxRgT0S/TjHGtVjFrGmP66C0J01sLzcQ=; b=nLyMoJN4eprTtl1dv+PaS5B2dunekT405HAA4jIsfaZOgiJXVjppBTS7RJNPpVCO5T JcBQ8z9mJ0KnUWvk53mcwqAtT7LK88IyrYut6zMZ2wCndM+61QJEk9S/DwPpjfz8DyjF Ih57jwlo//4kkeI/0KYFcSnLBJ3H+KyvvApTXZftIQNahBz84UN/nSIcwSRSjC8RVjON hceqFJi8h44KeEREtDzauWUUosxS7DBlBx1T7mgb4JsSl0ZzyalED9RnqXbFVXvMRpmW mcludlOVPJ9g8V3nwAC+ROwe0GcJ3gmZXGneaeAfOwf9L+2Fw9cC0ljRwrW9ccmfYLgD 9tzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iX8GvpFr; 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=pass (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 oq17si1824745ejb.436.2022.02.17.07.11.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Feb 2022 07:11:48 -0800 (PST) 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; dkim=pass header.i=@linaro.org header.s=google header.b=iX8GvpFr; 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=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 702CF83BAA; Thu, 17 Feb 2022 16:11:47 +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="iX8GvpFr"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 56EE683B7D; Thu, 17 Feb 2022 16:11:43 +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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) (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 2870B83B8D for ; Thu, 17 Feb 2022 16:11:33 +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-x436.google.com with SMTP id y11so2197954pfi.11 for ; Thu, 17 Feb 2022 07:11:33 -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=60sMsKZb710UxRgT0S/TjHGtVjFrGmP66C0J01sLzcQ=; b=iX8GvpFraPxQFn9UsLKdB0bflNwLGsk1RFQho+YQ8fjQqNkZEEtlAZFgCPYoBlJKI9 h8hmzhhCTSRtFDU8ZyhDO0mwb2l/VyLhNOCCzbv/4MpMAF573EkhIzvVhHVY2MpFN85M Xexa2WmKxLikc7YB7GwP+XYqcmoQDFUQiSGcFDudZ8j095BBPrMfvnaiZB6d2JQ/jwbC ksxLG7vw4MwwVMnHN32VN5whlq+ipdc+XfEhtix8DiJr98nTHi6gzN5P5s4Ai8+jnmj1 UobGqw2SGBTBCHgeplk73nQqKFFhNjzsP/6v3p3terdhqAuAScrEnCliZL6eTzMzBerl nn4w== 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=60sMsKZb710UxRgT0S/TjHGtVjFrGmP66C0J01sLzcQ=; b=LcZ9e5qXGprbUDl1Jmrv6w9GWHlU/XrgbIWAQBDOhHsp/OI55tcLTfDZm/MH+zkAyL 1qZp2Xmz8Z4qAG8Z6APvdgWMIzCzFtQ8urLfHtca5Yj/snJB55vtm4MAfQUK8PKKo37A J1KNOK56cyRlLN/XIt+Rd/SvUxmRemCM3LwVCVmd02coz0tXqwqVA1VFp78anLNU7q3A bgL7C8Wt+5yiqPKuvZb+DRSyw4Saaxh9EteTE9xFSKXOpnmaX6lyjNpwuswsFhM1Wx9X prwkTbliZvgmoyzV1GEY5lbc18RRiUBQFtjtE6IeSLr1k6h1oASJmH/u39hjY72Z2rA0 wQog== X-Gm-Message-State: AOAM530SP+OsIS0ohn0ttBcoMht7pO2pqZb6OYk2v8SwuPx1w2G4f6pJ 8CsRKqlxtfGWJdE04l+8/XaXKgvOGq5mDw== X-Received: by 2002:a05:6a00:2391:b0:4a8:d88:9cd with SMTP id f17-20020a056a00239100b004a80d8809cdmr3280679pfc.11.1645110691118; Thu, 17 Feb 2022 07:11:31 -0800 (PST) Received: from localhost.localdomain (113x37x226x201.ap113.ftth.ucom.ne.jp. [113.37.226.201]) by smtp.gmail.com with ESMTPSA id pf14sm2219260pjb.16.2022.02.17.07.11.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Feb 2022 07:11:30 -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 v2 1/8] FWU: Calculate CRC32 in fwu_update_mdata() Date: Fri, 18 Feb 2022 00:11:26 +0900 Message-Id: <164511068645.43219.1148311322212587482.stgit@localhost> X-Mailer: git-send-email 2.25.1 In-Reply-To: <164511067605.43219.15508992404634142079.stgit@localhost> References: <164511067605.43219.15508992404634142079.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.5 at phobos.denx.de X-Virus-Status: Clean To avoid calculating crc32 in several places, do it in fwu_update_mdata(). This also ensures the mdata crc32 is always sane. Signed-off-by: Masami Hiramatsu --- drivers/fwu-mdata/fwu-mdata-uclass.c | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/drivers/fwu-mdata/fwu-mdata-uclass.c b/drivers/fwu-mdata/fwu-mdata-uclass.c index 64b3051ecf..b98eda3789 100644 --- a/drivers/fwu-mdata/fwu-mdata-uclass.c +++ b/drivers/fwu-mdata/fwu-mdata-uclass.c @@ -115,7 +115,6 @@ out: int fwu_update_active_index(u32 active_idx) { int ret; - void *buf; struct fwu_mdata *mdata = NULL; if (active_idx > CONFIG_FWU_NUM_BANKS - 1) { @@ -136,14 +135,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 @@ -233,7 +224,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; @@ -251,14 +241,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 @@ -293,7 +275,6 @@ out: static int fwu_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; @@ -316,10 +297,6 @@ static int fwu_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_update_mdata(mdata); goto out; } @@ -425,6 +402,16 @@ int fwu_update_mdata(struct fwu_mdata *mdata) return -ENOSYS; } + if (!mdata) + return -EINVAL; + /* + * Calculate the crc32 for the updated FWU metadata + * and put the updated value in the FWU metadata crc32 + * field + */ + mdata->crc32 = crc32(0, (const unsigned char *)&mdata->version, + sizeof(*mdata) - sizeof(u32)); + return ops->update_mdata(dev, mdata); }