From: Masami Hiramatsu <masami.hiramatsu@linaro.org>
To: u-boot@lists.denx.de
Cc: Masami Hiramatsu <masami.hiramatsu@linaro.org>,
Patrick Delaunay <patrick.delaunay@foss.st.com>,
Patrice Chotard <patrice.chotard@foss.st.com>,
Heinrich Schuchardt <xypron.glpk@gmx.de>,
Alexander Graf <agraf@csgraf.de>,
AKASHI Takahiro <takahiro.akashi@linaro.org>,
Simon Glass <sjg@chromium.org>, Bin Meng <bmeng.cn@gmail.com>,
Ilias Apalodimas <ilias.apalodimas@linaro.org>,
Jose Marinho <jose.marinho@arm.com>,
Grant Likely <grant.likely@arm.com>,
Tom Rini <trini@konsulko.com>,
Etienne Carriere <etienne.carriere@linaro.org>,
Sughosh Ganu <sughosh.ganu@linaro.org>,
Paul Liu <paul.liu@linaro.org>
Subject: [RFC PATCH v2 1/8] FWU: Calculate CRC32 in fwu_update_mdata()
Date: Fri, 18 Feb 2022 00:11:26 +0900 [thread overview]
Message-ID: <164511068645.43219.1148311322212587482.stgit@localhost> (raw)
In-Reply-To: <164511067605.43219.15508992404634142079.stgit@localhost>
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 <masami.hiramatsu@linaro.org>
---
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);
}
next prev parent reply other threads:[~2022-02-17 15:11 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-17 15:11 [RFC PATCH v2 0/8] FWU: Add FWU Multi Bank Update for DeveloerBox Masami Hiramatsu
2022-02-17 15:11 ` Masami Hiramatsu [this message]
2022-02-17 15:11 ` [RFC PATCH v2 2/8] FWU: Free metadata copy if gpt_get_mdata() failed Masami Hiramatsu
2022-02-17 15:11 ` [RFC PATCH v2 3/8] synquacer: Update for TBBR based new FIP layout Masami Hiramatsu
2022-02-17 15:11 ` [RFC PATCH v2 4/8] dt/bindings: firmware: Add FWU metadata on SPI flash binding Masami Hiramatsu
2022-02-17 15:12 ` [RFC PATCH v2 5/8] FWU: Add FWU metadata access driver for SPI flash Masami Hiramatsu
2022-02-17 15:12 ` [RFC PATCH v2 6/8] FWU: synquacer: Add FWU Multi bank update support for DeveloperBox Masami Hiramatsu
2022-02-17 15:12 ` [RFC PATCH v2 7/8] FWU: synquacer: Initialize broken metadata Masami Hiramatsu
2022-02-21 7:04 ` Masami Hiramatsu
2022-02-17 15:12 ` [RFC PATCH v2 8/8] configs: synquacer: Add FWU support for DeveloperBox Masami Hiramatsu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=164511068645.43219.1148311322212587482.stgit@localhost \
--to=masami.hiramatsu@linaro.org \
--cc=agraf@csgraf.de \
--cc=bmeng.cn@gmail.com \
--cc=etienne.carriere@linaro.org \
--cc=grant.likely@arm.com \
--cc=ilias.apalodimas@linaro.org \
--cc=jose.marinho@arm.com \
--cc=patrice.chotard@foss.st.com \
--cc=patrick.delaunay@foss.st.com \
--cc=paul.liu@linaro.org \
--cc=sjg@chromium.org \
--cc=sughosh.ganu@linaro.org \
--cc=takahiro.akashi@linaro.org \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
--cc=xypron.glpk@gmx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox