From: David Jander <da...@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 <da...@protonic.nl>
Signed-off-by: Sascha Hauer <s.ha...@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 via email to