diff options
| author | Keith Packard <keithp@keithp.com> | 2013-12-08 11:10:00 -0800 | 
|---|---|---|
| committer | Keith Packard <keithp@keithp.com> | 2013-12-08 11:10:00 -0800 | 
| commit | 25aaf6122cbddcbc6a80460dac8ccb9f45743ae0 (patch) | |
| tree | 51b38a84af2130863f2fe864ab8b0c942dcbe3ad | |
| parent | ebb36d56c732ffe9cdb8d2ea53d00e1d4ece8f97 (diff) | |
ao-tools: Clean up ao-stmload and ao-usbload options. Add --raw
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>
| -rw-r--r-- | ao-tools/ao-stmload/ao-stmload.c | 75 | ||||
| -rw-r--r-- | ao-tools/ao-usbload/ao-usbload.c | 63 | 
2 files changed, 76 insertions, 62 deletions
| diff --git a/ao-tools/ao-stmload/ao-stmload.c b/ao-tools/ao-stmload/ao-stmload.c index b6b4abc6..4210a111 100644 --- a/ao-tools/ao-stmload/ao-stmload.c +++ b/ao-tools/ao-stmload/ao-stmload.c @@ -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  	 */ diff --git a/ao-tools/ao-usbload/ao-usbload.c b/ao-tools/ao-usbload/ao-usbload.c index 860eb8a5..0c8a23df 100644 --- a/ao-tools/ao-usbload/ao-usbload.c +++ b/ao-tools/ao-usbload/ao-usbload.c @@ -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); | 
