ao-tools: Clean up ao-stmload and ao-usbload options. Add --raw
authorKeith Packard <keithp@keithp.com>
Sun, 8 Dec 2013 19:10:00 +0000 (11:10 -0800)
committerKeith Packard <keithp@keithp.com>
Sun, 8 Dec 2013 19:10:00 +0000 (11:10 -0800)
ao-stmload only uses stlink, ao-usbload only uses self-flashing, so
clear up the options in the two programs. The new --raw option skips
the serial and radio cal rewriting when flashing the boot loader.

Signed-off-by: Keith Packard <keithp@keithp.com>
ao-tools/ao-stmload/ao-stmload.c
ao-tools/ao-usbload/ao-usbload.c

index b6b4abc63720c2be99a518d21f9913ad81a317e2..4210a11150419c0f25bc0028ca123dcc2de5c2c5 100644 (file)
@@ -136,8 +136,8 @@ check_flashed(stlink_t *sl)
 }
 
 static const struct option options[] = {
-       { .name = "tty", .has_arg = 1, .val = 'T' },
-       { .name = "device", .has_arg = 1, .val = 'D' },
+       { .name = "v1", .has_arg = 0, .val = '1' },
+       { .name = "raw", .has_arg = 0, .val = 'r' },
        { .name = "cal", .has_arg = 1, .val = 'c' },
        { .name = "serial", .has_arg = 1, .val = 's' },
        { .name = "verbose", .has_arg = 1, .val = 'v' },
@@ -146,7 +146,7 @@ static const struct option options[] = {
 
 static void usage(char *program)
 {
-       fprintf(stderr, "usage: %s [--verbose=<verbose>] [--device=<device>] [-tty=<tty>] [--cal=<radio-cal>] [--serial=<serial>] file.{elf,ihx}\n", program);
+       fprintf(stderr, "usage: %s [--v1] [--raw] [--verbose=<verbose>] [--cal=<radio-cal>] [--serial=<serial>] file.{elf,ihx}\n", program);
        exit(1);
 }
 
@@ -174,7 +174,8 @@ ends_with(char *whole, char *suffix)
 int
 main (int argc, char **argv)
 {
-       char                    *device = NULL;
+       int                     stlink_v1 = 0;
+       int                     raw = 0;
        char                    *filename;
        Elf                     *e;
        char                    *serial_end;
@@ -193,19 +194,18 @@ main (int argc, char **argv)
        int                     was_flashed = 0;
        struct ao_hex_image     *load;
        int                     tries;
-       char                    *tty = NULL;
        int                     success;
        int                     verbose = 0;
        struct ao_sym           *file_symbols;
        int                     num_file_symbols;
 
-       while ((c = getopt_long(argc, argv, "T:D:c:s:v:", options, NULL)) != -1) {
+       while ((c = getopt_long(argc, argv, "1rc:s:v:", options, NULL)) != -1) {
                switch (c) {
-               case 'T':
-                       tty = optarg;
+               case '1':
+                       stlink_v1 = 1;
                        break;
-               case 'D':
-                       device = optarg;
+               case 'r':
+                       raw = 1;
                        break;
                case 'c':
                        cal = strtoul(optarg, &cal_end, 10);
@@ -242,16 +242,18 @@ main (int argc, char **argv)
        } else
                usage(argv[0]);
 
-       if (!ao_editaltos_find_symbols(file_symbols, num_file_symbols, ao_symbols, ao_num_symbols)) {
-               fprintf(stderr, "Cannot find required symbols\n");
-               usage(argv[0]);
+       if (!raw) {
+               if (!ao_editaltos_find_symbols(file_symbols, num_file_symbols, ao_symbols, ao_num_symbols)) {
+                       fprintf(stderr, "Cannot find required symbols\n");
+                       usage(argv[0]);
+               }
        }
 
        /* Connect to the programming dongle
         */
        
        for (tries = 0; tries < 3; tries++) {
-               if (device) {
+               if (stlink_v1) {
                        sl = stlink_v1_open(50);
                } else {
                        sl = stlink_open_usb(50);
@@ -290,34 +292,37 @@ main (int argc, char **argv)
        if (stlink_current_mode(sl) != STLINK_DEV_DEBUG_MODE)
                stlink_enter_swd_mode(sl);
 
-       /* Go fetch existing config values
-        * if available
-        */
-       was_flashed = check_flashed(sl);
 
-       if (!serial) {
-               if (!was_flashed) {
-                       fprintf (stderr, "Must provide serial number\n");
-                       done(sl, 1);
+       if (!raw) {
+               /* Go fetch existing config values
+                * if available
+                */
+               was_flashed = check_flashed(sl);
+
+               if (!serial) {
+                       if (!was_flashed) {
+                               fprintf (stderr, "Must provide serial number\n");
+                               done(sl, 1);
+                       }
+                       serial = get_uint16(sl, AO_SERIAL_NUMBER);
+                       if (!serial || serial == 0xffff) {
+                               fprintf (stderr, "Invalid existing serial %d\n", serial);
+                               done(sl, 1);
+                       }
                }
-               serial = get_uint16(sl, AO_SERIAL_NUMBER);
-               if (!serial || serial == 0xffff) {
-                       fprintf (stderr, "Invalid existing serial %d\n", serial);
-                       done(sl, 1);
+
+               if (!cal && AO_RADIO_CAL && was_flashed) {
+                       cal = get_uint32(sl, AO_RADIO_CAL);
+                       if (!cal || cal == 0xffffffff) {
+                               fprintf (stderr, "Invalid existing rf cal %d\n", cal);
+                               done(sl, 1);
+                       }
                }
-       }
 
-       if (!cal && AO_RADIO_CAL && was_flashed) {
-               cal = get_uint32(sl, AO_RADIO_CAL);
-               if (!cal || cal == 0xffffffff) {
-                       fprintf (stderr, "Invalid existing rf cal %d\n", cal);
+               if (!ao_editaltos(load, serial, cal))
                        done(sl, 1);
-               }
        }
 
-       if (!ao_editaltos(load, serial, cal))
-               done(sl, 1);
-
        /* And flash the resulting image to the device
         */
 
index 860eb8a5d4778a47f3defdb6d397941bea9c4bed..0c8a23dfc60115786aa0be0c57c243cc6d0c159a 100644 (file)
@@ -82,6 +82,7 @@ check_flashed(struct cc_usb *cc)
 static const struct option options[] = {
        { .name = "tty", .has_arg = 1, .val = 'T' },
        { .name = "device", .has_arg = 1, .val = 'D' },
+       { .name = "raw", .has_arg = 0, .val = 'r' },
        { .name = "cal", .has_arg = 1, .val = 'c' },
        { .name = "serial", .has_arg = 1, .val = 's' },
        { .name = "verbose", .has_arg = 1, .val = 'v' },
@@ -90,7 +91,7 @@ static const struct option options[] = {
 
 static void usage(char *program)
 {
-       fprintf(stderr, "usage: %s [--verbose=<verbose>] [--device=<device>] [-tty=<tty>] [--cal=<radio-cal>] [--serial=<serial>] file.{elf,ihx}\n", program);
+       fprintf(stderr, "usage: %s [--raw] [--verbose=<verbose>] [--device=<device>] [-tty=<tty>] [--cal=<radio-cal>] [--serial=<serial>] file.{elf,ihx}\n", program);
        exit(1);
 }
 
@@ -119,6 +120,7 @@ main (int argc, char **argv)
        char                    *device = NULL;
        char                    *filename;
        Elf                     *e;
+       int                     raw = 0;
        char                    *serial_end;
        unsigned int            serial = 0;
        char                    *serial_ucs2;
@@ -141,7 +143,7 @@ main (int argc, char **argv)
        struct ao_sym           *file_symbols;
        int                     num_file_symbols;
 
-       while ((c = getopt_long(argc, argv, "T:D:c:s:v:", options, NULL)) != -1) {
+       while ((c = getopt_long(argc, argv, "rT:D:c:s:v:", options, NULL)) != -1) {
                switch (c) {
                case 'T':
                        tty = optarg;
@@ -149,6 +151,9 @@ main (int argc, char **argv)
                case 'D':
                        device = optarg;
                        break;
+               case 'r':
+                       raw = 1;
+                       break;
                case 'c':
                        cal = strtoul(optarg, &cal_end, 10);
                        if (cal_end == optarg || *cal_end != '\0')
@@ -184,9 +189,11 @@ main (int argc, char **argv)
        } else
                usage(argv[0]);
 
-       if (!ao_editaltos_find_symbols(file_symbols, num_file_symbols, ao_symbols, ao_num_symbols)) {
-               fprintf(stderr, "Cannot find required symbols\n");
-               usage(argv[0]);
+       if (!raw) {
+               if (!ao_editaltos_find_symbols(file_symbols, num_file_symbols, ao_symbols, ao_num_symbols)) {
+                       fprintf(stderr, "Cannot find required symbols\n");
+                       usage(argv[0]);
+               }
        }
 
        {
@@ -198,7 +205,7 @@ main (int argc, char **argv)
                        if (!this_tty)
                                this_tty = cc_usbdevs_find_by_arg(device, "AltosFlash");
                        if (!this_tty)
-                               this_tty = cc_usbdevs_find_by_arg(device, "MegaMetrum");
+                               this_tty = cc_usbdevs_find_by_arg(device, "TeleMega");
                        if (!this_tty)
                                this_tty = getenv("ALTOS_TTY");
                        if (!this_tty)
@@ -255,34 +262,36 @@ main (int argc, char **argv)
 #endif
        }
 
-       /* Go fetch existing config values
-        * if available
-        */
-       was_flashed = check_flashed(cc);
+       if (!raw) {
+               /* Go fetch existing config values
+                * if available
+                */
+               was_flashed = check_flashed(cc);
 
-       if (!serial) {
-               if (!was_flashed) {
-                       fprintf (stderr, "Must provide serial number\n");
-                       done(cc, 1);
+               if (!serial) {
+                       if (!was_flashed) {
+                               fprintf (stderr, "Must provide serial number\n");
+                               done(cc, 1);
+                       }
+                       serial = get_uint16(cc, AO_SERIAL_NUMBER);
+                       if (!serial || serial == 0xffff) {
+                               fprintf (stderr, "Invalid existing serial %d\n", serial);
+                               done(cc, 1);
+                       }
                }
-               serial = get_uint16(cc, AO_SERIAL_NUMBER);
-               if (!serial || serial == 0xffff) {
-                       fprintf (stderr, "Invalid existing serial %d\n", serial);
-                       done(cc, 1);
+
+               if (!cal && AO_RADIO_CAL && was_flashed) {
+                       cal = get_uint32(cc, AO_RADIO_CAL);
+                       if (!cal || cal == 0xffffffff) {
+                               fprintf (stderr, "Invalid existing rf cal %d\n", cal);
+                               done(cc, 1);
+                       }
                }
-       }
 
-       if (!cal && AO_RADIO_CAL && was_flashed) {
-               cal = get_uint32(cc, AO_RADIO_CAL);
-               if (!cal || cal == 0xffffffff) {
-                       fprintf (stderr, "Invalid existing rf cal %d\n", cal);
+               if (!ao_editaltos(load, serial, cal))
                        done(cc, 1);
-               }
        }
 
-       if (!ao_editaltos(load, serial, cal))
-               done(cc, 1);
-
        /* And flash the resulting image to the device
         */
        success = ao_self_write(cc, load);