summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Dickens <christopher.a.dickens@gmail.com>2015-08-04 23:51:12 -0700
committerChris Dickens <christopher.a.dickens@gmail.com>2015-08-04 23:51:12 -0700
commit8c24a1b9302a0b1b921b4ffaefd7bd7c8d0f21e8 (patch)
treef4b671c0a3b3c2455116e9155d08c2baa31ced75
parentefd02e7348d9ac769235377b3d7395ecf1fdd0d9 (diff)
downloadlibusb-8c24a1b9302a0b1b921b4ffaefd7bd7c8d0f21e8.tar.gz
Examples: fxload improvements
* Add two-stage load support * Fix leaks in error-handling paths * Closes #12 Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
-rw-r--r--examples/fxload.c35
-rw-r--r--libusb/version_nano.h2
2 files changed, 29 insertions, 8 deletions
diff --git a/examples/fxload.c b/examples/fxload.c
index f1d973b..5dff736 100644
--- a/examples/fxload.c
+++ b/examples/fxload.c
@@ -65,8 +65,9 @@ void logerror(const char *format, ...)
}
static int print_usage(int error_code) {
- fprintf(stderr, "\nUsage: fxload [-v] [-V] [-t type] [-d vid:pid] [-p bus,addr] -i firmware\n");
+ fprintf(stderr, "\nUsage: fxload [-v] [-V] [-t type] [-d vid:pid] [-p bus,addr] [-s loader] -i firmware\n");
fprintf(stderr, " -i <path> -- Firmware to upload\n");
+ fprintf(stderr, " -s <path> -- Second stage loader\n");
fprintf(stderr, " -t <type> -- Target type: an21, fx, fx2, fx2lp, fx3\n");
fprintf(stderr, " -d <vid:pid> -- Target device, as an USB VID:PID\n");
fprintf(stderr, " -p <bus,addr> -- Target device, as a libusb bus number and device address path\n");
@@ -95,7 +96,7 @@ int main(int argc, char*argv[])
libusb_device_handle *device = NULL;
struct libusb_device_descriptor desc;
- while ((opt = getopt(argc, argv, "qvV?hd:p:i:I:t:")) != EOF)
+ while ((opt = getopt(argc, argv, "qvV?hd:p:i:I:s:S:t:")) != EOF)
switch (opt) {
case 'd':
@@ -119,6 +120,11 @@ int main(int argc, char*argv[])
path[FIRMWARE] = optarg;
break;
+ case 's':
+ case 'S':
+ path[LOADER] = optarg;
+ break;
+
case 'V':
puts(FXLOAD_VERSION);
return 0;
@@ -224,15 +230,16 @@ int main(int argc, char*argv[])
}
if (dev == NULL) {
libusb_free_device_list(devs, 1);
+ libusb_exit(NULL);
logerror("could not find a known device - please specify type and/or vid:pid and/or bus,dev\n");
return print_usage(-1);
}
status = libusb_open(dev, &device);
+ libusb_free_device_list(devs, 1);
if (status < 0) {
logerror("libusb_open() failed: %s\n", libusb_error_name(status));
goto err;
}
- libusb_free_device_list(devs, 1);
} else if (device_id != NULL) {
device = libusb_open_device_with_vid_pid(NULL, (uint16_t)vid, (uint16_t)pid);
if (device == NULL) {
@@ -245,6 +252,7 @@ int main(int argc, char*argv[])
libusb_set_auto_detach_kernel_driver(device, 1);
status = libusb_claim_interface(device, 0);
if (status != LIBUSB_SUCCESS) {
+ libusb_close(device);
logerror("libusb_claim_interface failed: %s\n", libusb_error_name(status));
goto err;
}
@@ -272,10 +280,23 @@ int main(int argc, char*argv[])
logerror("%s: type %s\n", path[i], img_name[img_type[i]]);
}
- /* single stage, put into internal memory */
- if (verbose > 1)
- logerror("single stage: load on-chip memory\n");
- status = ezusb_load_ram(device, path[FIRMWARE], fx_type, img_type[FIRMWARE], 0);
+ if (path[LOADER] == NULL) {
+ /* single stage, put into internal memory */
+ if (verbose > 1)
+ logerror("single stage: load on-chip memory\n");
+ status = ezusb_load_ram(device, path[FIRMWARE], fx_type, img_type[FIRMWARE], 0);
+ } else {
+ /* two-stage, put loader into internal memory */
+ if (verbose > 1)
+ logerror("1st stage: load 2nd stage loader\n");
+ status = ezusb_load_ram(device, path[LOADER], fx_type, img_type[LOADER], 0);
+ if (status == 0) {
+ /* two-stage, put firmware into internal memory */
+ if (verbose > 1)
+ logerror("2nd state: load on-chip memory\n");
+ status = ezusb_load_ram(device, path[FIRMWARE], fx_type, img_type[FIRMWARE], 1);
+ }
+ }
libusb_release_interface(device, 0);
libusb_close(device);
diff --git a/libusb/version_nano.h b/libusb/version_nano.h
index 7f6727f..58b4c88 100644
--- a/libusb/version_nano.h
+++ b/libusb/version_nano.h
@@ -1 +1 @@
-#define LIBUSB_NANO 10996
+#define LIBUSB_NANO 10997