Skip to contentSkip to conversation

scripts: imx-usb-loader: remove unnecessary check

PATCH New Sascha Hauer 1 participant 3 messages Feb 13, 2020 Arm i.MX and Layerscape

lore
Share & tools
lore

Sascha Hauer

author maintainer
#0 lore raw

PATCH 1/3 scripts: imx-usb-loader: remove unnecessary check

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

---
 scripts/imx/imx-usb-loader.c | 5 -----
 1 file changed, 5 deletions(-)
scripts/imx/imx-usb-loader.c +0 -5
index 16df1ec1d5..ebe0eea050 100644
@@ -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;
Signature · 7 lines
2.25.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
author maintainer
#1 lore raw

PATCH 2/3 scripts: imx-usb-loader: download address is always the header address

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

---
 scripts/imx/imx-usb-loader.c | 22 +++++-----------------
 1 file changed, 5 insertions(+), 17 deletions(-)
scripts/imx/imx-usb-loader.c +5 -17
index ebe0eea050..d6c62820c3 100644
@@ -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)
Signature · 7 lines
2.25.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
author maintainer
#2 lore raw

PATCH 3/3 scripts: imx-usb-loader: dladdr is unused, remove it

In reply to Sascha Hauer

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

---
 scripts/imx/imx-usb-loader.c | 29 ++++++++---------------------
 1 file changed, 8 insertions(+), 21 deletions(-)
scripts/imx/imx-usb-loader.c +8 -21
index d6c62820c3..08affe72c7 100644
@@ -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;
 
Signature · 7 lines
2.25.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox