Implement -q -q to be very very quiet.

Submitted by: andyw@pobox.com


git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk@503 81a1dc3b-b13d-400b-aceb-764788c761c2
This commit is contained in:
Brian S. Dean 2005-09-16 21:52:42 +00:00
parent 8cb8923eca
commit 17d6c4e14c
2 changed files with 91 additions and 44 deletions

View File

@ -48,6 +48,7 @@ struct ihexrec {
extern char * progname; extern char * progname;
extern char progbuf[]; extern char progbuf[];
extern int quell_progress;
int b2ihex(unsigned char * inbuf, int bufsize, int b2ihex(unsigned char * inbuf, int bufsize,
int recsize, int startaddr, int recsize, int startaddr,
@ -970,9 +971,11 @@ int fileio(int op, char * filename, FILEFMT format,
return -1; return -1;
} }
if (quell_progress < 2) {
fprintf(stderr, "%s: %s file %s auto detected as %s\n", fprintf(stderr, "%s: %s file %s auto detected as %s\n",
progname, fio.iodesc, fname, fmtstr(format)); progname, fio.iodesc, fname, fmtstr(format));
} }
}
if (format != FMT_IMM) { if (format != FMT_IMM) {
if (!using_stdio) { if (!using_stdio) {

View File

@ -75,6 +75,7 @@ typedef struct update_t {
char * version = VERSION; char * version = VERSION;
int verbose; /* verbose output */ int verbose; /* verbose output */
int quell_progress; /* un-verebose output */
char * progname; char * progname;
char progbuf[PATH_MAX]; /* temporary buffer of spaces the same char progbuf[PATH_MAX]; /* temporary buffer of spaces the same
length as progname; used for lining up length as progname; used for lining up
@ -121,7 +122,7 @@ void usage(void)
" -y Count # erase cycles in EEPROM.\n" " -y Count # erase cycles in EEPROM.\n"
" -Y <number> Initialize erase cycle # in EEPROM.\n" " -Y <number> Initialize erase cycle # in EEPROM.\n"
" -v Verbose output. -v -v for more.\n" " -v Verbose output. -v -v for more.\n"
" -q Quell progress output.\n" " -q Quell progress output. -q -q for less.\n"
" -? Display this usage.\n" " -? Display this usage.\n"
"\navrdude project: <URL:http://savannah.nongnu.org/projects/avrdude>\n" "\navrdude project: <URL:http://savannah.nongnu.org/projects/avrdude>\n"
,progname); ,progname);
@ -537,8 +538,10 @@ int do_op(PROGRAMMER * pgm, struct avrpart * p, UPDATE * upd, int nowrite,
/* /*
* read out the specified device memory and write it to a file * read out the specified device memory and write it to a file
*/ */
if (quell_progress < 2) {
fprintf(stderr, "%s: reading %s memory:\n", fprintf(stderr, "%s: reading %s memory:\n",
progname, upd->memtype); progname, upd->memtype);
}
report_progress(0,1,"Reading"); report_progress(0,1,"Reading");
rc = avr_read(pgm, p, upd->memtype, 0, 1); rc = avr_read(pgm, p, upd->memtype, 0, 1);
if (rc < 0) { if (rc < 0) {
@ -549,10 +552,12 @@ int do_op(PROGRAMMER * pgm, struct avrpart * p, UPDATE * upd, int nowrite,
report_progress(1,1,NULL); report_progress(1,1,NULL);
size = rc; size = rc;
if (quell_progress < 2) {
fprintf(stderr, fprintf(stderr,
"%s: writing output file \"%s\"\n", "%s: writing output file \"%s\"\n",
progname, progname,
strcmp(upd->filename, "-")==0 ? "<stdout>" : upd->filename); strcmp(upd->filename, "-")==0 ? "<stdout>" : upd->filename);
}
rc = fileio(FIO_WRITE, upd->filename, upd->format, p, upd->memtype, size); rc = fileio(FIO_WRITE, upd->filename, upd->format, p, upd->memtype, size);
if (rc < 0) { if (rc < 0) {
fprintf(stderr, "%s: write to file '%s' failed\n", fprintf(stderr, "%s: write to file '%s' failed\n",
@ -565,10 +570,12 @@ int do_op(PROGRAMMER * pgm, struct avrpart * p, UPDATE * upd, int nowrite,
* write the selected device memory using data from a file; first * write the selected device memory using data from a file; first
* read the data from the specified file * read the data from the specified file
*/ */
if (quell_progress < 2) {
fprintf(stderr, fprintf(stderr,
"%s: reading input file \"%s\"\n", "%s: reading input file \"%s\"\n",
progname, progname,
strcmp(upd->filename, "-")==0 ? "<stdin>" : upd->filename); strcmp(upd->filename, "-")==0 ? "<stdin>" : upd->filename);
}
rc = fileio(FIO_READ, upd->filename, upd->format, p, upd->memtype, -1); rc = fileio(FIO_READ, upd->filename, upd->format, p, upd->memtype, -1);
if (rc < 0) { if (rc < 0) {
fprintf(stderr, "%s: write to file '%s' failed\n", fprintf(stderr, "%s: write to file '%s' failed\n",
@ -580,8 +587,10 @@ int do_op(PROGRAMMER * pgm, struct avrpart * p, UPDATE * upd, int nowrite,
/* /*
* write the buffer contents to the selected memory type * write the buffer contents to the selected memory type
*/ */
if (quell_progress < 2) {
fprintf(stderr, "%s: writing %s (%d bytes):\n", fprintf(stderr, "%s: writing %s (%d bytes):\n",
progname, upd->memtype, size); progname, upd->memtype, size);
}
if (!nowrite) { if (!nowrite) {
report_progress(0,1,"Writing"); report_progress(0,1,"Writing");
@ -604,8 +613,10 @@ int do_op(PROGRAMMER * pgm, struct avrpart * p, UPDATE * upd, int nowrite,
vsize = rc; vsize = rc;
if (quell_progress < 2) {
fprintf(stderr, "%s: %d bytes of %s written\n", progname, fprintf(stderr, "%s: %d bytes of %s written\n", progname,
vsize, upd->memtype); vsize, upd->memtype);
}
} }
else if (upd->op == DEVICE_VERIFY) { else if (upd->op == DEVICE_VERIFY) {
@ -617,11 +628,13 @@ int do_op(PROGRAMMER * pgm, struct avrpart * p, UPDATE * upd, int nowrite,
v = avr_dup_part(p); v = avr_dup_part(p);
if (quell_progress < 2) {
fprintf(stderr, "%s: verifying %s memory against %s:\n", fprintf(stderr, "%s: verifying %s memory against %s:\n",
progname, upd->memtype, upd->filename); progname, upd->memtype, upd->filename);
fprintf(stderr, "%s: load data %s data from input file %s:\n", fprintf(stderr, "%s: load data %s data from input file %s:\n",
progname, upd->memtype, upd->filename); progname, upd->memtype, upd->filename);
}
rc = fileio(FIO_READ, upd->filename, upd->format, p, upd->memtype, -1); rc = fileio(FIO_READ, upd->filename, upd->format, p, upd->memtype, -1);
if (rc < 0) { if (rc < 0) {
@ -630,13 +643,12 @@ int do_op(PROGRAMMER * pgm, struct avrpart * p, UPDATE * upd, int nowrite,
return -1; return -1;
} }
size = rc; size = rc;
if (quell_progress < 2) {
fprintf(stderr, "%s: input file %s contains %d bytes\n", fprintf(stderr, "%s: input file %s contains %d bytes\n",
progname, upd->filename, size); progname, upd->filename, size);
fprintf(stderr, "%s: reading on-chip %s data:\n", fprintf(stderr, "%s: reading on-chip %s data:\n",
progname, upd->memtype); progname, upd->memtype);
}
report_progress (0,1,"Reading"); report_progress (0,1,"Reading");
rc = avr_read(pgm, v, upd->memtype, size, 1); rc = avr_read(pgm, v, upd->memtype, size, 1);
@ -650,7 +662,9 @@ int do_op(PROGRAMMER * pgm, struct avrpart * p, UPDATE * upd, int nowrite,
if (quell_progress < 2) {
fprintf(stderr, "%s: verifying ...\n", progname); fprintf(stderr, "%s: verifying ...\n", progname);
}
rc = avr_verify(p, v, upd->memtype, size); rc = avr_verify(p, v, upd->memtype, size);
if (rc < 0) { if (rc < 0) {
fprintf(stderr, "%s: verification error; content mismatch\n", fprintf(stderr, "%s: verification error; content mismatch\n",
@ -659,8 +673,10 @@ int do_op(PROGRAMMER * pgm, struct avrpart * p, UPDATE * upd, int nowrite,
return -1; return -1;
} }
if (quell_progress < 2) {
fprintf(stderr, "%s: %d bytes of %s verified\n", fprintf(stderr, "%s: %d bytes of %s verified\n",
progname, rc, upd->memtype); progname, rc, upd->memtype);
}
pgm->vfy_led(pgm, OFF); pgm->vfy_led(pgm, OFF);
} }
@ -710,7 +726,6 @@ int main(int argc, char * argv [])
int cycles; /* erase-rewrite cycles */ int cycles; /* erase-rewrite cycles */
int set_cycles; /* value to set the erase-rewrite cycles to */ int set_cycles; /* value to set the erase-rewrite cycles to */
char * e; /* for strtol() error checking */ char * e; /* for strtol() error checking */
int quell_progress;
int baudrate; /* override default programmer baud rate */ int baudrate; /* override default programmer baud rate */
double bitclock; /* Specify programmer bit clock (JTAG ICE) */ double bitclock; /* Specify programmer bit clock (JTAG ICE) */
int safemode; /* Enable safemode, 1=safemode on, 0=normal */ int safemode; /* Enable safemode, 1=safemode on, 0=normal */
@ -870,7 +885,7 @@ int main(int argc, char * argv [])
break; break;
case 'q' : /* Quell progress output */ case 'q' : /* Quell progress output */
quell_progress = 1; quell_progress++ ;
break; break;
case 't': /* enter terminal mode */ case 't': /* enter terminal mode */
@ -1150,7 +1165,9 @@ int main(int argc, char * argv [])
programmer_display(progbuf); programmer_display(progbuf);
} }
if (quell_progress < 2) {
fprintf(stderr, "\n"); fprintf(stderr, "\n");
}
exitrc = 0; exitrc = 0;
@ -1194,9 +1211,11 @@ int main(int argc, char * argv [])
/* indicate ready */ /* indicate ready */
pgm->rdy_led(pgm, ON); pgm->rdy_led(pgm, ON);
if (quell_progress < 2) {
fprintf(stderr, fprintf(stderr,
"%s: AVR device initialized and ready to accept instructions\n", "%s: AVR device initialized and ready to accept instructions\n",
progname); progname);
}
/* /*
* Let's read the signature bytes to make sure there is at least a * Let's read the signature bytes to make sure there is at least a
@ -1222,14 +1241,20 @@ int main(int argc, char * argv [])
if (sig != NULL) { if (sig != NULL) {
int ff; int ff;
if (quell_progress < 2) {
fprintf(stderr, "%s: Device signature = 0x", progname); fprintf(stderr, "%s: Device signature = 0x", progname);
}
ff = 1; ff = 1;
for (i=0; i<sig->size; i++) { for (i=0; i<sig->size; i++) {
if (quell_progress < 2) {
fprintf(stderr, "%02x", sig->buf[i]); fprintf(stderr, "%02x", sig->buf[i]);
}
if (sig->buf[i] != 0xff) if (sig->buf[i] != 0xff)
ff = 0; ff = 0;
} }
if (quell_progress < 2) {
fprintf(stderr, "\n"); fprintf(stderr, "\n");
}
if (ff) { if (ff) {
fprintf(stderr, fprintf(stderr,
@ -1251,7 +1276,9 @@ int main(int argc, char * argv [])
/* If safemode is enabled, go ahead and read the current low, high, /* If safemode is enabled, go ahead and read the current low, high,
and extended fuse bytes as needed */ and extended fuse bytes as needed */
if (quell_progress < 2) {
fprintf(stderr, "\n"); fprintf(stderr, "\n");
}
if (safemode_readfuses(&safemode_lfuse, &safemode_hfuse, if (safemode_readfuses(&safemode_lfuse, &safemode_hfuse,
&safemode_efuse, pgm, p, verbose) != 0) { &safemode_efuse, pgm, p, verbose) != 0) {
@ -1262,7 +1289,9 @@ int main(int argc, char * argv [])
goto main_exit; goto main_exit;
} }
if (quell_progress < 2) {
fprintf(stderr, "\n"); fprintf(stderr, "\n");
}
//Save the fuses as default //Save the fuses as default
safemode_memfuses(1, &safemode_lfuse, &safemode_hfuse, &safemode_efuse); safemode_memfuses(1, &safemode_lfuse, &safemode_hfuse, &safemode_efuse);
@ -1286,8 +1315,9 @@ int main(int argc, char * argv [])
} }
} }
if (quell_progress < 2) {
fprintf(stderr, "\n"); fprintf(stderr, "\n");
}
} }
@ -1304,11 +1334,13 @@ int main(int argc, char * argv [])
continue; continue;
if ((strcasecmp(m->desc, "flash") == 0) && (upd->op == DEVICE_WRITE)) { if ((strcasecmp(m->desc, "flash") == 0) && (upd->op == DEVICE_WRITE)) {
erase = 1; erase = 1;
if (quell_progress < 2) {
fprintf(stderr, fprintf(stderr,
"%s: NOTE: FLASH memory has been specified, an erase cycle " "%s: NOTE: FLASH memory has been specified, an erase cycle "
"will be performed\n" "will be performed\n"
"%sTo disable this feature, specify the -D option.\n", "%sTo disable this feature, specify the -D option.\n",
progname, progbuf); progname, progbuf);
}
break; break;
} }
} }
@ -1325,6 +1357,7 @@ int main(int argc, char * argv [])
* reasonable * reasonable
*/ */
rc = avr_get_cycle_count(pgm, p, &cycles); rc = avr_get_cycle_count(pgm, p, &cycles);
if (quell_progress < 2) {
if ((rc >= 0) && (cycles != 0)) { if ((rc >= 0) && (cycles != 0)) {
fprintf(stderr, fprintf(stderr,
"%s: current erase-rewrite cycle count is %d%s\n", "%s: current erase-rewrite cycle count is %d%s\n",
@ -1332,6 +1365,7 @@ int main(int argc, char * argv [])
do_cycles ? "" : " (if being tracked)"); do_cycles ? "" : " (if being tracked)");
} }
} }
}
if (set_cycles != -1) { if (set_cycles != -1) {
rc = avr_get_cycle_count(pgm, p, &cycles); rc = avr_get_cycle_count(pgm, p, &cycles);
@ -1341,8 +1375,10 @@ int main(int argc, char * argv [])
* read the old value * read the old value
*/ */
cycles = set_cycles; cycles = set_cycles;
if (quell_progress < 2) {
fprintf(stderr, "%s: setting erase-rewrite cycle count to %d\n", fprintf(stderr, "%s: setting erase-rewrite cycle count to %d\n",
progname, cycles); progname, cycles);
}
rc = avr_put_cycle_count(pgm, p, cycles); rc = avr_put_cycle_count(pgm, p, cycles);
if (rc < 0) { if (rc < 0) {
fprintf(stderr, fprintf(stderr,
@ -1359,7 +1395,9 @@ int main(int argc, char * argv [])
* erase the chip's flash and eeprom memories, this is required * erase the chip's flash and eeprom memories, this is required
* before the chip can accept new programming * before the chip can accept new programming
*/ */
if (quell_progress < 2) {
fprintf(stderr, "%s: erasing chip\n", progname); fprintf(stderr, "%s: erasing chip\n", progname);
}
avr_chip_erase(pgm, p); avr_chip_erase(pgm, p);
} }
@ -1398,7 +1436,9 @@ int main(int argc, char * argv [])
unsigned char safemodeafter_efuse = 0xff; unsigned char safemodeafter_efuse = 0xff;
unsigned char failures = 0; unsigned char failures = 0;
if (quell_progress < 2) {
fprintf(stderr, "\n"); fprintf(stderr, "\n");
}
//Restore the default fuse values //Restore the default fuse values
safemode_memfuses(0, &safemode_lfuse, &safemode_hfuse, &safemode_efuse); safemode_memfuses(0, &safemode_lfuse, &safemode_hfuse, &safemode_efuse);
@ -1469,6 +1509,7 @@ int main(int argc, char * argv [])
} }
} }
if (quell_progress < 2) {
fprintf(stderr, "%s: safemode: ", progname); fprintf(stderr, "%s: safemode: ", progname);
if (failures == 0) { if (failures == 0) {
fprintf(stderr, "Fuses OK\n"); fprintf(stderr, "Fuses OK\n");
@ -1476,6 +1517,7 @@ int main(int argc, char * argv [])
else { else {
fprintf(stderr, "Fuses not recovered, sorry\n"); fprintf(stderr, "Fuses not recovered, sorry\n");
} }
}
if (fuses_updated && fuses_specified) { if (fuses_updated && fuses_specified) {
exitrc = 1; exitrc = 1;
@ -1499,7 +1541,9 @@ main_exit:
pgm->close(pgm); pgm->close(pgm);
if (quell_progress < 2) {
fprintf(stderr, "\n%s done. Thank you.\n\n", progname); fprintf(stderr, "\n%s done. Thank you.\n\n", progname);
}
return exitrc; return exitrc;
} }