mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] scripts: rk-usb-loader.c: Read input file after connecting USB device
@ 2024-04-04 11:09 Sascha Hauer
  0 siblings, 0 replies; only message in thread
From: Sascha Hauer @ 2024-04-04 11:09 UTC (permalink / raw)
  To: Barebox List; +Cc: David Jander

From: David Jander <david@protonic.nl>

This helps in case rk-usb-loader is run in an endless loop waiting for
devices to get connected while the binary file is being modified (i.e.
barebox is being worked on). It avoids the case that an older version of
barebox is being uploaded than what is available a the time of USB
connection.

Signed-off-by: David Jander <david@protonic.nl>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 scripts/rk-usb-loader.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/scripts/rk-usb-loader.c b/scripts/rk-usb-loader.c
index 9c2367ed28..62df7331fb 100644
--- a/scripts/rk-usb-loader.c
+++ b/scripts/rk-usb-loader.c
@@ -212,18 +212,6 @@ static int upload_image(const char *filename)
 	int i, n_files;
 	size_t size;
 
-	buf = read_file(filename, &size);
-	if (!buf)
-		exit(1);
-
-	hdr = buf;
-
-	if (hdr->magic != NEWIDB_MAGIC) {
-		log_error("%s has invalid magic 0x%08x ( != 0x%08x )\n", filename,
-			  hdr->magic, NEWIDB_MAGIC);
-		exit(1);
-	}
-
 	ret = libusb_init(&ctx);
 	if (ret < 0) {
 		log_error("failed to initialize libusb context: %s\n",
@@ -237,6 +225,18 @@ static int upload_image(const char *filename)
 		return 1;
 	}
 
+	buf = read_file(filename, &size);
+	if (!buf)
+		exit(1);
+
+	hdr = buf;
+
+	if (hdr->magic != NEWIDB_MAGIC) {
+		log_error("%s has invalid magic 0x%08x ( != 0x%08x )\n", filename,
+			  hdr->magic, NEWIDB_MAGIC);
+		exit(1);
+	}
+
 	n_files = hdr->n_files >> 16;
 
 	if (n_files > 2) {
-- 
2.39.2




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-04-04 11:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-04 11:09 [PATCH] scripts: rk-usb-loader.c: Read input file after connecting USB device Sascha Hauer

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