From: Keith Packard Date: Sat, 27 Apr 2013 07:26:11 +0000 (-0700) Subject: ao-tools/ao-stmload: Add --verbose flag X-Git-Tag: 1.2.1~23 X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=commitdiff_plain;h=1695f6af46ea647119d651fc09c97d604d08c736 ao-tools/ao-stmload: Add --verbose flag This dumps out the serial communication so you can see where things go wrong. Signed-off-by: Keith Packard --- diff --git a/ao-tools/ao-stmload/ao-selfload.c b/ao-tools/ao-stmload/ao-selfload.c index b3105b21..95667dca 100644 --- a/ao-tools/ao-stmload/ao-selfload.c +++ b/ao-tools/ao-stmload/ao-selfload.c @@ -26,18 +26,24 @@ #include "ccdbg.h" #include "ao-stmload.h" +int ao_self_verbose; + +#define TRACE(...) if (ao_self_verbose) printf (__VA_ARGS__) + void ao_self_block_read(struct cc_usb *cc, uint32_t address, uint8_t block[256]) { int byte; cc_usb_sync(cc); cc_usb_printf(cc, "R %x\n", address); -// printf ("read %08x\n", address); for (byte = 0; byte < 0x100; byte++) { block[byte] = cc_usb_getchar(cc); -// printf (" %02x", block[byte]); -// if ((byte & 0xf) == 0xf) -// printf ("\n"); + } + TRACE ("\nread %08x\n", address); + for (byte = 0; byte < 0x100; byte++) { + TRACE (" %02x", block[byte]); + if ((byte & 0xf) == 0xf) + TRACE ("\n"); } } @@ -47,12 +53,14 @@ ao_self_block_write(struct cc_usb *cc, uint32_t address, uint8_t block[256]) int byte; cc_usb_sync(cc); cc_usb_printf(cc, "W %x\n", address); -// printf ("write %08x\n", address); + TRACE ("write %08x\n", address); + for (byte = 0; byte < 0x100; byte++) { + TRACE (" %02x", block[byte]); + if ((byte & 0xf) == 0xf) + TRACE ("\n"); + } for (byte = 0; byte < 0x100; byte++) { cc_usb_printf(cc, "%c", block[byte]); -// printf (" %02x", block[byte]); -// if ((byte & 0xf) == 0xf) -// printf ("\n"); } } @@ -114,5 +122,6 @@ ao_self_write(struct cc_usb *cc, struct hex_image *image) putchar('.'); fflush(stdout); } printf("done\n"); + cc_usb_printf(cc,"a\n"); return 1; } diff --git a/ao-tools/ao-stmload/ao-stmload.c b/ao-tools/ao-stmload/ao-stmload.c index 130f8707..dd25f07f 100644 --- a/ao-tools/ao-stmload/ao-stmload.c +++ b/ao-tools/ao-stmload/ao-stmload.c @@ -224,12 +224,13 @@ static const struct option options[] = { { .name = "device", .has_arg = 1, .val = 'D' }, { .name = "cal", .has_arg = 1, .val = 'c' }, { .name = "serial", .has_arg = 1, .val = 's' }, + { .name = "verbose", .has_arg = 0, .val = 'v' }, { 0, 0, 0, 0}, }; static void usage(char *program) { - fprintf(stderr, "usage: %s [--stlink] [--device=] [-tty=] [--cal=] [--serial=] file.{elf,ihx}\n", program); + fprintf(stderr, "usage: %s [--stlink] [--verbose] [--device=] [-tty=] [--cal=] [--serial=] file.{elf,ihx}\n", program); exit(1); } @@ -286,8 +287,9 @@ main (int argc, char **argv) int use_stlink = 0; char *tty = NULL; int success; + int verbose = 0; - while ((c = getopt_long(argc, argv, "T:D:c:s:S", options, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "T:D:c:s:Sv", options, NULL)) != -1) { switch (c) { case 'T': tty = optarg; @@ -308,12 +310,20 @@ main (int argc, char **argv) case 'S': use_stlink = 1; break; + case 'v': + verbose++; + break; default: usage(argv[0]); break; } } + ao_self_verbose = verbose; + + if (verbose > 1) + ccdbg_add_debug(CC_DEBUG_BITBANG); + filename = argv[optind]; if (filename == NULL) usage(argv[0]); @@ -412,6 +422,7 @@ main (int argc, char **argv) fprintf(stderr, "Cannot switch to boot loader\n"); exit(1); } +#if 0 { uint8_t check[256]; int i = 0; @@ -433,6 +444,7 @@ main (int argc, char **argv) } } } +#endif } /* Go fetch existing config values diff --git a/ao-tools/ao-stmload/ao-stmload.h b/ao-tools/ao-stmload/ao-stmload.h index 754c1c5b..98884535 100644 --- a/ao-tools/ao-stmload/ao-stmload.h +++ b/ao-tools/ao-stmload/ao-stmload.h @@ -44,4 +44,6 @@ ao_self_read(struct cc_usb *cc, uint32_t address, uint32_t length); int ao_self_write(struct cc_usb *cc, struct hex_image *image); +extern int ao_self_verbose; + #endif /* _AO_STMLOAD_H_ */ diff --git a/ao-tools/lib/cc-usb.c b/ao-tools/lib/cc-usb.c index 485583f9..d7ac138c 100644 --- a/ao-tools/lib/cc-usb.c +++ b/ao-tools/lib/cc-usb.c @@ -123,9 +123,10 @@ cc_handle_hex_read(struct cc_usb *cc) static void cc_usb_dbg(int indent, uint8_t *bytes, int len) { - int eol = 1; + static int eol = 1; int i; uint8_t c; + ccdbg_debug(CC_DEBUG_BITBANG, "<<<%d bytes>>>", len); while (len--) { c = *bytes++; if (eol) { @@ -135,10 +136,12 @@ cc_usb_dbg(int indent, uint8_t *bytes, int len) } switch (c) { case '\r': - ccdbg_debug(CC_DEBUG_BITBANG, "^M"); + ccdbg_debug(CC_DEBUG_BITBANG, "\\r"); break; case '\n': eol = 1; + ccdbg_debug(CC_DEBUG_BITBANG, "\\n\n"); + break; default: if (c < ' ' || c > '~') ccdbg_debug(CC_DEBUG_BITBANG, "\\%02x", c); @@ -193,7 +196,6 @@ _cc_usb_sync(struct cc_usb *cc, int wait_for_input) ret = read(cc->fd, cc->in_buf + cc->in_count, CC_IN_BUF - cc->in_count); if (ret > 0) { - int i; cc_usb_dbg(24, cc->in_buf + cc->in_count, ret); cc->in_count += ret; if (cc->hex_count)