From 2bec699e3e412268ead28f2d98adb8b10468be84 Mon Sep 17 00:00:00 2001 From: "Brian S. Dean" Date: Fri, 19 Jan 2001 03:10:53 +0000 Subject: [PATCH] Implement enough state in cmd_dump so that if it is called with no arguments, it successively dumps the next chunk of data of the same previously specified length. git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk@39 81a1dc3b-b13d-400b-aceb-764788c761c2 --- avrdude/term.c | 82 +++++++++++++++++++++++++++----------------------- 1 file changed, 45 insertions(+), 37 deletions(-) diff --git a/avrdude/term.c b/avrdude/term.c index d801ecdc..c5ea1aac 100644 --- a/avrdude/term.c +++ b/avrdude/term.c @@ -197,42 +197,54 @@ int cmd_dump ( int fd, struct avrpart * p, int argc, char * argv[] ) { char * e; int i, j; - int len, maxsize; - AVRMEM memtype; - unsigned short addr, daddr; + unsigned short daddr; char * buf; + int maxsize; + static AVRMEM memtype=AVR_FLASH; + static unsigned short addr=0; + static int len=64; - if (argc != 4) { - fprintf(stderr, "Usage: dump flash|eeprom \n"); - return -1; - } - - if (strcmp(argv[1],"flash")==0) { - memtype = AVR_FLASH; - maxsize = p->flash_size; - } - else if (strcmp(argv[1],"eeprom")==0) { - memtype = AVR_EEPROM; - maxsize = p->eeprom_size; + if (argc == 1) { + addr += len; } else { - fprintf(stderr, "%s (dump): invalid memory type \"%s\"\n", - progname, argv[1]); - return -1; + if (argc != 4) { + fprintf(stderr, "Usage: dump flash|eeprom \n"); + return -1; + } + + if (strcmp(argv[1],"flash")==0) { + memtype = AVR_FLASH; + } + else if (strcmp(argv[1],"eeprom")==0) { + memtype = AVR_EEPROM; + } + else { + fprintf(stderr, "%s (dump): invalid memory type \"%s\"\n", + progname, argv[1]); + return -1; + } + + addr = strtoul(argv[2], &e, 0); + if (*e || (e == argv[2])) { + fprintf(stderr, "%s (dump): can't parse address \"%s\"\n", + progname, argv[2]); + return -1; + } + + len = strtol(argv[3], &e, 0); + if (*e || (e == argv[3])) { + fprintf(stderr, "%s (dump): can't parse length \"%s\"\n", + progname, argv[3]); + return -1; + } } - addr = strtoul(argv[2], &e, 0); - if (*e || (e == argv[2])) { - fprintf(stderr, "%s (dump): can't parse address \"%s\"\n", - progname, argv[2]); - return -1; - } - - len = strtol(argv[3], &e, 0); - if (*e || (e == argv[3])) { - fprintf(stderr, "%s (dump): can't parse length \"%s\"\n", - progname, argv[3]); - return -1; + switch (memtype) { + case AVR_FLASH : maxsize = p->flash_size; break; + case AVR_EEPROM : maxsize = p->eeprom_size; break; + default : return -1; /* this can't happen, but is silences gcc + warnings */ } if (addr > maxsize) { @@ -242,13 +254,9 @@ int cmd_dump ( int fd, struct avrpart * p, int argc, char * argv[] ) return -1; } - if ((addr + len) > maxsize) { - fprintf(stderr, - "%s (dump): selected address and length exceed " - "range for %s memory\n", - progname, avr_memtstr(memtype)); - return -1; - } + /* trim len if nessary to not read past the end of memory */ + if ((addr + len) > maxsize) + len = maxsize - addr; buf = malloc(len); if (buf == NULL) {