[PATCH] imx-usb-loader: Don't try to transfer more data than contained in the image

Uwe Kleine-König u.kleine-koenig at pengutronix.de
Wed Mar 15 11:33:38 PDT 2023


On platforms that don't have a 2nd stage (in my case i.MX25) it usually
happens the transfer limit for the first (and only) upload is bigger than
the actual file length. Then it's the right thing to load the complete
image (minus its header), but not more.

This fixes a failure to boot via USB on i.MX25 that ends in

	dl_command err=-1, last_trans=0

Fixes: 3367ebc55ebe ("scripts: imx-usb-loader: simplify code flow for file size calculations")
Signed-off-by: Uwe Kleine-König <u.kleine-koenig at pengutronix.de>
---
 scripts/imx/imx-usb-loader.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/imx/imx-usb-loader.c b/scripts/imx/imx-usb-loader.c
index a98ab0e33f8a..4bcb4cbab6fe 100644
--- a/scripts/imx/imx-usb-loader.c
+++ b/scripts/imx/imx-usb-loader.c
@@ -1403,7 +1403,7 @@ static int do_irom_download(struct usb_work *curr, int verify)
 	printf("loading binary file(%s) to 0x%08x, firststage_len=%zu type=%d, hdroffset=%u...\n",
 			curr->filename, header_addr, firststage_len, type, header_offset);
 
-	ret = load_file(image, firststage_len, header_addr, type, false);
+	ret = load_file(image, min(fsize, firststage_len), header_addr, type, false);
 	if (ret < 0)
 		goto cleanup;
 

base-commit: e3b5c9b60447eb266cb4895ee4662b1b613545b4
-- 
2.39.2




More information about the barebox mailing list