Add --device/-D support to the command line tools and manuals
[fw/altos] / ao-tools / ao-load / ao-load.c
index 642af2fed7ada02beccf08c2fe4e1fe35c9b1e3a..f5466612c20b9a12b4def5c374008ad543b81a36 100644 (file)
@@ -22,6 +22,7 @@
 #include <unistd.h>
 #include <getopt.h>
 #include "ccdbg.h"
+#include "cc.h"
 
 #define AO_USB_DESC_STRING             3
 
@@ -89,21 +90,18 @@ rewrite(struct hex_image *image, unsigned addr, char *data, int len)
        memcpy(image->data + addr - image->address, data, len);
 }
 
-<<<<<<< HEAD:ao-tools/ao-load/ao-load.c
-static const struct option
-=======
 static const struct option options[] = {
        { .name = "tty", .has_arg = 1, .val = 'T' },
+       { .name = "device", .has_arg = 1, .val = 'D' },
        { 0, 0, 0, 0},
 };
 
 static void usage(char *program)
 {
-       fprintf(stderr, "usage: %s [--tty <tty-name>] file.ihx serial-number\n", program);
+       fprintf(stderr, "usage: %s [--tty <tty-name>] [--device <device-name>] file.ihx serial-number\n", program);
        exit(1);
 }
 
->>>>>>> c29275b72438637d46d7a50742882d2736eb176a:ao-tools/ao-load/ao-load.c
 int
 main (int argc, char **argv)
 {
@@ -126,13 +124,17 @@ main (int argc, char **argv)
        unsigned        usb_descriptors;
        int             string_num;
        char            *tty = NULL;
+       char            *device = NULL;
        int             c;
 
-       while ((c = getopt_long(argc, argv, "T:", options, NULL)) != -1) {
+       while ((c = getopt_long(argc, argv, "T:D:", options, NULL)) != -1) {
                switch (c) {
                case 'T':
                        tty = optarg;
                        break;
+               case 'D':
+                       device = optarg;
+                       break;
                default:
                        usage(argv[0]);
                        break;
@@ -223,6 +225,8 @@ main (int argc, char **argv)
        if (!rewrite(image, usb_descriptors + 2 + image->address, serial_ucs2, serial_ucs2_len))
                usage(argv[0]);
 
+       if (!tty)
+               tty = cc_usbdevs_find_by_arg(device, "TIDongle");
        dbg = ccdbg_open(tty);
        if (!dbg)
                exit (1);