mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/3] scripts: imx-usb-loader: remove unnecessary check
@ 2020-02-13 10:43 Sascha Hauer
  2020-02-13 10:43 ` [PATCH 2/3] scripts: imx-usb-loader: download address is always the header address Sascha Hauer
  2020-02-13 10:43 ` [PATCH 3/3] scripts: imx-usb-loader: dladdr is unused, remove it Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Sascha Hauer @ 2020-02-13 10:43 UTC (permalink / raw)
  To: Barebox List

file_base is the address where the image would be loaded to if we were
not skipping the unused space before the header in the image. I can't
see any reason why this should be higher than the download address.
Drop this superfluous check.

Tested on i.MX51, i.MX53 and i.MX6

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

diff --git a/scripts/imx/imx-usb-loader.c b/scripts/imx/imx-usb-loader.c
index 16df1ec1d5..ebe0eea050 100644
--- a/scripts/imx/imx-usb-loader.c
+++ b/scripts/imx/imx-usb-loader.c
@@ -1401,11 +1401,6 @@ static int do_irom_download(struct usb_work *curr, int verify)
 		dladdr = header_addr;
 	}
 
-	if (file_base > dladdr) {
-		max_length -= (file_base - dladdr);
-		dladdr = file_base;
-	}
-
 	skip = dladdr - file_base;
 
 	image = buf + skip;
-- 
2.25.0


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

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

* [PATCH 2/3] scripts: imx-usb-loader: download address is always the header address
  2020-02-13 10:43 [PATCH 1/3] scripts: imx-usb-loader: remove unnecessary check Sascha Hauer
@ 2020-02-13 10:43 ` Sascha Hauer
  2020-02-13 10:43 ` [PATCH 3/3] scripts: imx-usb-loader: dladdr is unused, remove it Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2020-02-13 10:43 UTC (permalink / raw)
  To: Barebox List

We always have to upload the image beginning with the header, we have
to skip everything that is before the header.
In MODE_BULK this is explicit, but in HID mode this is obfuscated by
doing several calculations with helper variables. Drop this and simplify
code.

Tested on i.MX51, i.MX53 and i.MX6

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

diff --git a/scripts/imx/imx-usb-loader.c b/scripts/imx/imx-usb-loader.c
index ebe0eea050..d6c62820c3 100644
--- a/scripts/imx/imx-usb-loader.c
+++ b/scripts/imx/imx-usb-loader.c
@@ -1359,7 +1359,6 @@ static int do_irom_download(struct usb_work *curr, int verify)
 	unsigned char type;
 	unsigned fsize = 0;
 	unsigned header_offset;
-	unsigned file_base;
 	unsigned char *buf = NULL;
 	unsigned char *image;
 	unsigned char *verify_buffer = NULL;
@@ -1367,7 +1366,6 @@ static int do_irom_download(struct usb_work *curr, int verify)
 	unsigned max_length;
 	unsigned plugin = 0;
 	unsigned header_addr = 0;
-	unsigned skip = 0;
 
 	ret = read_file(curr->filename, &buf, &fsize);
 	if (ret < 0)
@@ -1394,20 +1392,10 @@ static int do_irom_download(struct usb_work *curr, int verify)
 		goto cleanup;
 	}
 
-	file_base = header_addr - header_offset;
+	dladdr = header_addr;
 
-	if (usb_id->mach_id->mode == MODE_BULK) {
-		/* No jump command, dladdr should point to header */
-		dladdr = header_addr;
-	}
-
-	skip = dladdr - file_base;
-
-	image = buf + skip;
-	fsize -= skip;
-
-	if (fsize > max_length)
-		fsize = max_length;
+	image = buf + header_offset;
+	fsize -= header_offset;
 
 	type = FT_APP;
 
@@ -1428,8 +1416,8 @@ static int do_irom_download(struct usb_work *curr, int verify)
 		}
 	}
 
-	printf("loading binary file(%s) to 0x%08x, skip=0x%x, fsize=%u type=%d...\n",
-			curr->filename, dladdr, skip, fsize, type);
+	printf("loading binary file(%s) to 0x%08x, fsize=%u type=%d...\n",
+			curr->filename, dladdr, fsize, type);
 
 	ret = load_file(image, fsize, dladdr, type);
 	if (ret < 0)
-- 
2.25.0


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

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

* [PATCH 3/3] scripts: imx-usb-loader: dladdr is unused, remove it
  2020-02-13 10:43 [PATCH 1/3] scripts: imx-usb-loader: remove unnecessary check Sascha Hauer
  2020-02-13 10:43 ` [PATCH 2/3] scripts: imx-usb-loader: download address is always the header address Sascha Hauer
@ 2020-02-13 10:43 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2020-02-13 10:43 UTC (permalink / raw)
  To: Barebox List

The download address is the same as the place we put the header to, so
we can drop the calculation of dladdr and use header_addr directly.

Tested on i.MX51, i.MX53 and i.MX6

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

diff --git a/scripts/imx/imx-usb-loader.c b/scripts/imx/imx-usb-loader.c
index d6c62820c3..08affe72c7 100644
--- a/scripts/imx/imx-usb-loader.c
+++ b/scripts/imx/imx-usb-loader.c
@@ -1259,7 +1259,7 @@ static int perform_dcd(unsigned char *p, const unsigned char *file_start,
 }
 
 static int get_dl_start(const unsigned char *p, const unsigned char *file_start,
-		unsigned cnt, unsigned *dladdr, unsigned *max_length, unsigned *plugin,
+		unsigned cnt, unsigned *max_length, unsigned *plugin,
 		unsigned *header_addr)
 {
 	const unsigned char *file_end = file_start + cnt;
@@ -1271,7 +1271,6 @@ static int get_dl_start(const unsigned char *p, const unsigned char *file_start,
 		unsigned char* dcd;
 		int err = get_dcd_range_old(ohdr, file_start, cnt, &dcd, &dcd_end);
 
-		*dladdr = ohdr->app_dest;
 		*header_addr = ohdr->dcd_ptr_ptr - offsetof(struct imx_flash_header, dcd);
 		*plugin = 0;
 		if (err >= 0)
@@ -1284,7 +1283,6 @@ static int get_dl_start(const unsigned char *p, const unsigned char *file_start,
 		unsigned char *bd;
 		struct imx_flash_header_v2 *hdr = (struct imx_flash_header_v2 *)p;
 
-		*dladdr = hdr->self;
 		*header_addr = hdr->self;
 		bd = hdr->boot_data_ptr + cvt_dest_to_src;
 		if ((bd < file_start) || ((bd + 4) > file_end)) {
@@ -1292,7 +1290,6 @@ static int get_dl_start(const unsigned char *p, const unsigned char *file_start,
 			return -1;
 		}
 
-		*dladdr = ((struct imx_boot_data *)bd)->start;
 		*max_length = ((struct imx_boot_data *)bd)->size;
 		*plugin = ((struct imx_boot_data *)bd)->plugin;
 		((struct imx_boot_data *)bd)->plugin = 0;
@@ -1304,7 +1301,7 @@ static int get_dl_start(const unsigned char *p, const unsigned char *file_start,
 }
 
 static int process_header(struct usb_work *curr, unsigned char *buf, int cnt,
-		unsigned *p_dladdr, unsigned *p_max_length, unsigned *p_plugin,
+		unsigned *p_max_length, unsigned *p_plugin,
 		unsigned *p_header_addr)
 {
 	int ret;
@@ -1319,7 +1316,7 @@ static int process_header(struct usb_work *curr, unsigned char *buf, int cnt,
 		if (!is_header(p))
 			continue;
 
-		ret = get_dl_start(p, buf, cnt, p_dladdr, p_max_length, p_plugin, p_header_addr);
+		ret = get_dl_start(p, buf, cnt, p_max_length, p_plugin, p_header_addr);
 		if (ret < 0) {
 			printf("!!get_dl_start returned %i\n", ret);
 			return ret;
@@ -1362,7 +1359,6 @@ static int do_irom_download(struct usb_work *curr, int verify)
 	unsigned char *buf = NULL;
 	unsigned char *image;
 	unsigned char *verify_buffer = NULL;
-	unsigned dladdr = 0;
 	unsigned max_length;
 	unsigned plugin = 0;
 	unsigned header_addr = 0;
@@ -1373,8 +1369,7 @@ static int do_irom_download(struct usb_work *curr, int verify)
 
 	max_length = fsize;
 
-	ret = process_header(curr, buf, fsize,
-			&dladdr, &max_length, &plugin, &header_addr);
+	ret = process_header(curr, buf, fsize, &max_length, &plugin, &header_addr);
 	if (ret < 0)
 		goto cleanup;
 
@@ -1386,14 +1381,6 @@ static int do_irom_download(struct usb_work *curr, int verify)
 		goto cleanup;
 	}
 
-	if (!dladdr) {
-		printf("unknown load address\n");
-		ret = -3;
-		goto cleanup;
-	}
-
-	dladdr = header_addr;
-
 	image = buf + header_offset;
 	fsize -= header_offset;
 
@@ -1417,9 +1404,9 @@ static int do_irom_download(struct usb_work *curr, int verify)
 	}
 
 	printf("loading binary file(%s) to 0x%08x, fsize=%u type=%d...\n",
-			curr->filename, dladdr, fsize, type);
+			curr->filename, header_addr, fsize, type);
 
-	ret = load_file(image, fsize, dladdr, type);
+	ret = load_file(image, fsize, header_addr, type);
 	if (ret < 0)
 		goto cleanup;
 
@@ -1428,7 +1415,7 @@ static int do_irom_download(struct usb_work *curr, int verify)
 	if (verify) {
 		printf("verifying file...\n");
 
-		ret = verify_memory(image, fsize, dladdr);
+		ret = verify_memory(image, fsize, header_addr);
 		if (ret < 0) {
 			printf("verifying failed\n");
 			goto cleanup;
@@ -1442,7 +1429,7 @@ static int do_irom_download(struct usb_work *curr, int verify)
 			 * so we load part of the image again with type FT_APP
 			 * this time.
 			 */
-			ret = load_file(verify_buffer, 64, dladdr, FT_APP);
+			ret = load_file(verify_buffer, 64, header_addr, FT_APP);
 			if (ret < 0)
 				goto cleanup;
 
-- 
2.25.0


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

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

end of thread, other threads:[~2020-02-13 10:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-13 10:43 [PATCH 1/3] scripts: imx-usb-loader: remove unnecessary check Sascha Hauer
2020-02-13 10:43 ` [PATCH 2/3] scripts: imx-usb-loader: download address is always the header address Sascha Hauer
2020-02-13 10:43 ` [PATCH 3/3] scripts: imx-usb-loader: dladdr is unused, remove it Sascha Hauer

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