mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Cc: David Jander <david@protonic.nl>
Subject: [PATCH] scripts: rk-usb-loader.c: Read input file after connecting USB device
Date: Thu,  4 Apr 2024 13:09:18 +0200	[thread overview]
Message-ID: <20240404110918.1951843-1-s.hauer@pengutronix.de> (raw)

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




                 reply	other threads:[~2024-04-04 11:10 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240404110918.1951843-1-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=david@protonic.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox