From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 1/2] imx-usb-loader: Fix verify for non word aligned lengths
Date: Thu, 24 May 2018 07:36:20 +0200 [thread overview]
Message-ID: <20180524053621.995-1-s.hauer@pengutronix.de> (raw)
Verifying the uploaded image fails when the length is not word aligned.
This is because read_memory reads full words, so the input length must
be word aligned. Align the length up to 4 bytes so that we do not pass
unaligned lengths to read_memory.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
scripts/imx/imx-usb-loader.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/scripts/imx/imx-usb-loader.c b/scripts/imx/imx-usb-loader.c
index 43dde8b7f2..684e3f8a06 100644
--- a/scripts/imx/imx-usb-loader.c
+++ b/scripts/imx/imx-usb-loader.c
@@ -586,6 +586,8 @@ int do_status(void)
return err;
}
+#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
+
static int read_memory(unsigned addr, void *dest, unsigned cnt)
{
static struct sdp_command read_reg_command = {
@@ -1160,12 +1162,13 @@ static int verify_memory(const void *buf, unsigned len, unsigned addr)
int ret, mismatch = 0;
void *readbuf;
unsigned offset = 0, now;
+ unsigned alen = ALIGN(len, 4);
- readbuf = malloc(len);
+ readbuf = malloc(alen);
if (!readbuf)
return -ENOMEM;
- ret = read_memory(addr, readbuf, len);
+ ret = read_memory(addr, readbuf, alen);
if (ret < 0)
goto err;
--
2.17.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next reply other threads:[~2018-05-24 5:36 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-24 5:36 Sascha Hauer [this message]
2018-05-24 5:36 ` [PATCH 2/2] imx-usb-loader: dump memory bytewise on verification mismatch Sascha Hauer
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=20180524053621.995-1-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
/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