mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] imx-usb-loader: Fix verify for non word aligned lengths
@ 2018-05-24  5:36 Sascha Hauer
  2018-05-24  5:36 ` [PATCH 2/2] imx-usb-loader: dump memory bytewise on verification mismatch Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Sascha Hauer @ 2018-05-24  5:36 UTC (permalink / raw)
  To: Barebox List

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH 2/2] imx-usb-loader: dump memory bytewise on verification mismatch
  2018-05-24  5:36 [PATCH 1/2] imx-usb-loader: Fix verify for non word aligned lengths Sascha Hauer
@ 2018-05-24  5:36 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2018-05-24  5:36 UTC (permalink / raw)
  To: Barebox List

dump_long only prints the full words and does not print the unaligned
rest. This means that some bytes (and maybe actually the interesting
ones) may not be printed. Use dump_bytes instead which does not have
this problem.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 scripts/imx/imx-usb-loader.c | 26 ++------------------------
 1 file changed, 2 insertions(+), 24 deletions(-)

diff --git a/scripts/imx/imx-usb-loader.c b/scripts/imx/imx-usb-loader.c
index 684e3f8a06..9a690e49c8 100644
--- a/scripts/imx/imx-usb-loader.c
+++ b/scripts/imx/imx-usb-loader.c
@@ -329,28 +329,6 @@ static libusb_device *find_imx_dev(libusb_device **devs, const struct mach_id **
 	return NULL;
 }
 
-static void dump_long(const void *src, unsigned cnt, unsigned addr)
-{
-	const unsigned *p = (unsigned *)src;
-
-	while (cnt >= 32) {
-		printf("%08x: %08x %08x %08x %08x  %08x %08x %08x %08x\n",
-				addr, p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
-		p += 8;
-		cnt -= 32;
-		addr += 32;
-	}
-	if (cnt) {
-		printf("%08x:", addr);
-		while (cnt >= 4) {
-			printf(" %08x", p[0]);
-			p++;
-			cnt -= 4;
-		}
-		printf("\n");
-	}
-}
-
 static void dump_bytes(const void *src, unsigned cnt, unsigned addr)
 {
 	const unsigned char *p = src;
@@ -1177,9 +1155,9 @@ static int verify_memory(const void *buf, unsigned len, unsigned addr)
 
 		if (memcmp(buf + offset, readbuf + offset, now)) {
 			printf("mismatch at offset 0x%08x. expected:\n", offset);
-			dump_long(buf + offset, now, addr + offset);
+			dump_bytes(buf + offset, now, addr + offset);
 			printf("read:\n");
-			dump_long(readbuf + offset, now, addr + offset);
+			dump_bytes(readbuf + offset, now, addr + offset);
 			ret = -EINVAL;
 			mismatch++;
 			if (mismatch > 4)
-- 
2.17.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-05-24  5:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-24  5:36 [PATCH 1/2] imx-usb-loader: Fix verify for non word aligned lengths Sascha Hauer
2018-05-24  5:36 ` [PATCH 2/2] imx-usb-loader: dump memory bytewise on verification mismatch Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox