Review and overhaul AVRDUDE's messaging system (#1126)

* Change avrdude_message(MSG_XYZ, ...) to msg_xyz(...)
* Define and use pmsg_xyz(...) instead of msg_xyz("%s: ...", progname, ...)
* Review and change avrdude_message() levels
   - Introduce new levels warning, error and ext_error
   - Distribute info level to info, warning, error, ext_error
   - Assign levels (more) consistently
   - Unify grammar, punctuation and style of messages
* Use imsg_xyz() to print indented messages
* Show function name in errors and warnings on -v
* Reduce effective verbosity level by number of -q above one
This commit is contained in:
Stefan Rueger
2022-10-17 15:44:55 +01:00
committed by GitHub
parent 2503ae03ce
commit e172877724
54 changed files with 3024 additions and 4206 deletions

View File

@@ -48,7 +48,7 @@
#include "avrdude.h"
#include "libavrdude.h"
#include "config.h"
#include "term.h"
#include "developer_opts.h"
@@ -60,7 +60,7 @@ char progbuf[PATH_MAX]; /* temporary buffer of spaces the same
length as progname; used for lining up
multiline messages */
int avrdude_message(const int msglvl, const char *format, ...)
int avrdude_message(int msglvl, const char *format, ...)
{
int rc = 0;
va_list ap;
@@ -72,6 +72,55 @@ int avrdude_message(const int msglvl, const char *format, ...)
return rc;
}
static const char *avrdude_message_type(int msglvl) {
switch(msglvl) {
case MSG_EXT_ERROR: return "OS error";
case MSG_ERROR: return "error";
case MSG_WARNING: return "warning";
case MSG_INFO: return "info";
case MSG_NOTICE: return "notice";
case MSG_NOTICE2: return "notice2";
case MSG_DEBUG: return "debug";
case MSG_TRACE: return "trace";
case MSG_TRACE2: return "trace2";
default: return "unknown msglvl";
}
}
int avrdude_message2(const char *fname, int msgmode, int msglvl, const char *format, ...) {
int rc = 0;
va_list ap;
if(msgmode & MSG2_FLUSH) {
fflush(stdout);
fflush(stderr);
}
// Reduce effective verbosity level by number of -q above one
if ((quell_progress < 2? verbose: verbose+1-quell_progress) >= msglvl) {
if(msgmode & MSG2_PROGNAME) {
fprintf(stderr, "%s", progname);
if(verbose >= MSG_NOTICE && (msgmode & MSG2_FUNCTION))
fprintf(stderr, " %s()", fname);
if(msgmode & MSG2_TYPE)
fprintf(stderr, " %s", avrdude_message_type(msglvl));
fprintf(stderr, ": ");
} else if(msgmode & MSG2_INDENT1) {
fprintf(stderr, "%*s", (int) strlen(progname)+1, "");
} else if(msgmode & MSG2_INDENT2) {
fprintf(stderr, "%*s", (int) strlen(progname)+2, "");
}
va_start(ap, format);
rc = vfprintf(stderr, format, ap);
va_end(ap);
}
if(msgmode & MSG2_FLUSH)
fflush(stderr);
return rc;
}
struct list_walk_cookie
{
@@ -96,41 +145,40 @@ int ovsigck; /* 1=override sig check, 0=don't */
/*
* usage message
*/
static void usage(void)
{
avrdude_message(MSG_INFO,
"Usage: %s [options]\n"
"Options:\n"
" -p <partno> Required. Specify AVR device.\n"
" -b <baudrate> Override RS-232 baud rate.\n"
" -B <bitclock> Specify JTAG/STK500v2 bit clock period (us).\n"
" -C <config-file> Specify location of configuration file.\n"
" -c <programmer> Specify programmer type.\n"
" -A Disable trailing-0xff removal from file and AVR read.\n"
" -D Disable auto erase for flash memory; implies -A.\n"
" -i <delay> ISP Clock Delay [in microseconds]\n"
" -P <port> Specify connection port.\n"
" -F Override invalid signature check.\n"
" -e Perform a chip erase.\n"
" -O Perform RC oscillator calibration (see AVR053). \n"
" -U <memtype>:r|w|v:<filename>[:format]\n"
" Memory operation specification.\n"
" Multiple -U options are allowed, each request\n"
" is performed in the order specified.\n"
" -n Do not write anything to the device.\n"
" -V Do not verify.\n"
" -t Enter terminal mode.\n"
" -E <exitspec>[,<exitspec>] List programmer exit specifications.\n"
" -x <extended_param> Pass <extended_param> to programmer.\n"
" -v Verbose output. -v -v for more.\n"
" -q Quell progress output. -q -q for less.\n"
" -l logfile Use logfile rather than stderr for diagnostics.\n"
" -? Display this usage.\n"
"\navrdude version %s, URL: <https://github.com/avrdudes/avrdude>\n",
msg_error(
"Usage: %s [options]\n"
"Options:\n"
" -p <partno> Specify AVR device\n"
" -b <baudrate> Override RS-232 baud rate\n"
" -B <bitclock> Specify JTAG/STK500v2 bit clock period (us)\n"
" -C <config-file> Specify location of configuration file\n"
" -c <programmer> Specify programmer type\n"
" -A Disable trailing-0xff removal from file and AVR read\n"
" -D Disable auto erase for flash memory; implies -A\n"
" -i <delay> ISP Clock Delay [in microseconds]\n"
" -P <port> Specify connection port\n"
" -F Override invalid signature check\n"
" -e Perform a chip erase\n"
" -O Perform RC oscillator calibration (see AVR053)\n"
" -U <memtype>:r|w|v:<filename>[:format]\n"
" Memory operation specification\n"
" Multiple -U options are allowed, each request\n"
" is performed in the order specified\n"
" -n Do not write anything to the device\n"
" -V Do not verify\n"
" -t Enter terminal mode\n"
" -E <exitspec>[,<exitspec>] List programmer exit specifications\n"
" -x <extended_param> Pass <extended_param> to programmer\n"
" -v Verbose output; -v -v for more\n"
" -q Quell progress output; -q -q for less\n"
" -l logfile Use logfile rather than stderr for diagnostics\n"
" -? Display this usage\n"
"\navrdude version %s, URL: <https://github.com/avrdudes/avrdude>\n",
progname, version);
}
@@ -252,8 +300,7 @@ static void list_programmer_types_callback(const char *name, const char *desc,
void *cookie)
{
struct list_walk_cookie *c = (struct list_walk_cookie *)cookie;
fprintf(c->f, "%s%-16s = %-s\n",
c->prefix, name, desc);
fprintf(c->f, "%s%-16s = %-s\n", c->prefix, name, desc);
}
static void list_programmer_types(FILE * f, const char *prefix)
@@ -279,7 +326,7 @@ static void list_parts(FILE *f, const char *prefix, LISTID avrparts, int pm) {
p = ldata(ln1);
// List part if pm or prog_modes uninitialised or if they are compatible otherwise
if(!pm || !p->prog_modes || (pm & p->prog_modes)) {
if((verbose < 2) && (p->id[0] == '.')) // hide ids starting with '.'
if(verbose < 2 && p->id[0] == '.') // hide ids starting with '.'
continue;
if((len = strlen(p->id)) > maxlen)
maxlen = len;
@@ -291,7 +338,7 @@ static void list_parts(FILE *f, const char *prefix, LISTID avrparts, int pm) {
p = ldata(ln1);
// List part if pm or prog_modes uninitialised or if they are compatible otherwise
if(!pm || !p->prog_modes || (pm & p->prog_modes)) {
if((verbose < 2) && (p->id[0] == '.')) // hide ids starting with '.'
if(verbose < 2 && p->id[0] == '.') // hide ids starting with '.'
continue;
if(verbose)
fprintf(f, "%s%-*s = %-18s [%s:%d]", prefix, maxlen, p->id, p->desc, p->config_file, p->lineno);
@@ -348,29 +395,31 @@ static int dev_opt(char *str) {
static void exit_programmer_not_found(const char *programmer) {
msg_error("\n");
if(programmer && *programmer)
avrdude_message(MSG_INFO, "\n%s: cannot find programmer id %s\n", progname, programmer);
else
avrdude_message(MSG_INFO, "\n%s: no programmer has been specified on the command line "
"or in the\n%sconfig file; specify one using the -c option and try again\n",
progname, progbuf);
pmsg_error("cannot find programmer id %s\n", programmer);
else {
pmsg_error("no programmer has been specified on the command line or in the\n");
imsg_error("config file(s); specify one using the -c option and try again\n");
}
avrdude_message(MSG_INFO, "\nValid programmers are:\n");
msg_error("\nValid programmers are:\n");
list_programmers(stderr, " ", programmers, ~0);
avrdude_message(MSG_INFO, "\n");
msg_error("\n");
exit(1);
}
static void exit_part_not_found(const char *partdesc) {
msg_error("\n");
if(partdesc && *partdesc)
avrdude_message(MSG_INFO, "\n%s: AVR part %s not found\n", progname, partdesc);
pmsg_error("AVR part %s not found\n", partdesc);
else
avrdude_message(MSG_INFO, "\n%s: no AVR part has been specified; use -p part\n", progname);
pmsg_error("no AVR part has been specified; use -p part\n");
avrdude_message(MSG_INFO, "\nValid parts are:\n");
msg_error("\nValid parts are:\n");
list_parts(stderr, " ", part_list, ~0);
avrdude_message(MSG_INFO, "\n");
msg_error("\n");
exit(1);
}
@@ -433,11 +482,12 @@ int main(int argc, char * argv [])
sys_config[0] = '\0';
progname = strrchr(argv[0],'/');
progname = strrchr(argv[0], '/');
#if defined (WIN32)
/* take care of backslash as dir sep in W32 */
if (!progname) progname = strrchr(argv[0],'\\');
if (!progname)
progname = strrchr(argv[0], '\\');
#endif /* WIN32 */
if (progname)
@@ -445,6 +495,12 @@ int main(int argc, char * argv [])
else
progname = argv[0];
// Remove trailing .exe
if(strlen(progname) > 4 && strcmp(progname+strlen(progname)-4, ".exe") == 0) {
progname = cfg_strdup("main()", progname); // Don't write to argv[0]
progname[strlen(progname)-4] = 0;
}
default_programmer = "";
default_parallel = "";
default_serial = "";
@@ -457,19 +513,19 @@ int main(int argc, char * argv [])
updates = lcreat(NULL, 0);
if (updates == NULL) {
avrdude_message(MSG_INFO, "%s: cannot initialize updater list\n", progname);
pmsg_error("cannot initialize updater list\n");
exit(1);
}
extended_params = lcreat(NULL, 0);
if (extended_params == NULL) {
avrdude_message(MSG_INFO, "%s: cannot initialize extended parameter list\n", progname);
pmsg_error("cannot initialize extended parameter list\n");
exit(1);
}
additional_config_files = lcreat(NULL, 0);
if (additional_config_files == NULL) {
avrdude_message(MSG_INFO, "%s: cannot initialize additional config files list\n", progname);
pmsg_error("cannot initialize additional config files list\n");
exit(1);
}
@@ -514,8 +570,7 @@ int main(int argc, char * argv [])
case 'b': /* override default programmer baud rate */
baudrate = strtol(optarg, &e, 0);
if ((e == optarg) || (*e != 0)) {
avrdude_message(MSG_INFO, "%s: invalid baud rate specified '%s'\n",
progname, optarg);
pmsg_error("invalid baud rate specified '%s'\n", optarg);
exit(1);
}
break;
@@ -560,12 +615,10 @@ int main(int argc, char * argv [])
break;
}
if (bitclock == 0.0)
avrdude_message(MSG_INFO, "%s: invalid bit clock unit of measure '%s'\n",
progname, e);
pmsg_error("invalid bit clock unit of measure '%s'\n", e);
}
if ((e == optarg) || bitclock == 0.0) {
avrdude_message(MSG_INFO, "%s: invalid bit clock period specified '%s'\n",
progname, optarg);
pmsg_error("invalid bit clock period specified '%s'\n", optarg);
exit(1);
}
break;
@@ -573,8 +626,7 @@ int main(int argc, char * argv [])
case 'i': /* specify isp clock delay */
ispdelay = strtol(optarg, &e,10);
if ((e == optarg) || (*e != 0) || ispdelay == 0) {
avrdude_message(MSG_INFO, "%s: invalid isp clock delay specified '%s'\n",
progname, optarg);
pmsg_error("invalid isp clock delay specified '%s'\n", optarg);
exit(1);
}
break;
@@ -643,15 +695,13 @@ int main(int argc, char * argv [])
case 's':
case 'u':
avrdude_message(MSG_INFO, "%s: \"safemode\" feature no longer supported\n",
progname);
pmsg_error("\"safemode\" feature no longer supported\n");
break;
case 'U':
upd = parse_op(optarg);
if (upd == NULL) {
avrdude_message(MSG_INFO, "%s: error parsing update operation '%s'\n",
progname, optarg);
pmsg_error("unable to parse update operation '%s'\n", optarg);
exit(1);
}
ladd(updates, upd);
@@ -670,13 +720,11 @@ int main(int argc, char * argv [])
break;
case 'y':
avrdude_message(MSG_INFO, "%s: erase cycle counter no longer supported\n",
progname);
pmsg_error("erase cycle counter no longer supported\n");
break;
case 'Y':
avrdude_message(MSG_INFO, "%s: erase cycle counter no longer supported\n",
progname);
pmsg_error("erase cycle counter no longer supported\n");
break;
case '?': /* help */
@@ -685,7 +733,7 @@ int main(int argc, char * argv [])
break;
default:
avrdude_message(MSG_INFO, "%s: invalid option -%c\n\n", progname, ch);
pmsg_error("invalid option -%c\n\n", ch);
usage();
exit(1);
break;
@@ -697,8 +745,7 @@ int main(int argc, char * argv [])
FILE *newstderr = freopen(logfile, "w", stderr);
if (newstderr == NULL) {
/* Help! There's no stderr to complain to anymore now. */
printf("Cannot create logfile \"%s\": %s\n",
logfile, strerror(errno));
printf("Cannot create logfile %s: %s\n", logfile, strerror(errno));
return 1;
}
}
@@ -737,10 +784,10 @@ int main(int argc, char * argv [])
executable_dirpath[executable_dirpath_len] = '\0';
// Debug output
avrdude_message(MSG_DEBUG, "executable_abspath = %s\n", executable_abspath);
avrdude_message(MSG_DEBUG, "executable_abspath_len = %i\n", executable_abspath_len);
avrdude_message(MSG_DEBUG, "executable_dirpath = %s\n", executable_dirpath);
avrdude_message(MSG_DEBUG, "executable_dirpath_len = %i\n", executable_dirpath_len);
msg_debug("executable_abspath = %s\n", executable_abspath);
msg_debug("executable_abspath_len = %i\n", executable_abspath_len);
msg_debug("executable_dirpath = %s\n", executable_dirpath);
msg_debug("executable_dirpath_len = %i\n", executable_dirpath_len);
}
/*
@@ -796,9 +843,9 @@ int main(int argc, char * argv [])
}
}
// Debug output
avrdude_message(MSG_DEBUG, "sys_config = %s\n", sys_config);
avrdude_message(MSG_DEBUG, "sys_config_found = %s\n", sys_config_found ? "true" : "false");
avrdude_message(MSG_DEBUG, "\n");
msg_debug("sys_config = %s\n", sys_config);
msg_debug("sys_config_found = %s\n", sys_config_found ? "true" : "false");
msg_debug("\n");
/*
* USER CONFIG
@@ -826,35 +873,36 @@ int main(int argc, char * argv [])
* Print out an identifying string so folks can tell what version
* they are running
*/
avrdude_message(MSG_NOTICE, "\n%s: Version %s\n"
"%sCopyright (c) Brian Dean, http://www.bdmicro.com/\n"
"%sCopyright (c) Joerg Wunsch\n\n",
progname, version, progbuf, progbuf);
avrdude_message(MSG_NOTICE, "%sSystem wide configuration file is \"%s\"\n",
progbuf, sys_config);
msg_notice("\n");
pmsg_notice("Version %s\n", version);
imsg_notice("Copyright (c) Brian Dean, http://www.bdmicro.com/\n");
imsg_notice("Copyright (c) Joerg Wunsch\n\n");
rc = read_config(sys_config);
if (rc) {
avrdude_message(MSG_INFO, "%s: error reading system wide configuration file \"%s\"\n",
progname, sys_config);
exit(1);
if(*sys_config) {
char *real_sys_config = realpath(sys_config, NULL);
if(real_sys_config) {
imsg_notice("System wide configuration file is %s\n", real_sys_config);
} else
pmsg_warning("cannot determine realpath() of config file %s: %s\n", sys_config, strerror(errno));
rc = read_config(real_sys_config);
if (rc) {
pmsg_error("unable to process system wide configuration file %s\n", real_sys_config);
exit(1);
}
free(real_sys_config);
}
if (usr_config[0] != 0) {
avrdude_message(MSG_NOTICE, "%sUser configuration file is \"%s\"\n",
progbuf, usr_config);
imsg_notice("User configuration file is %s\n", usr_config);
rc = stat(usr_config, &sb);
if ((rc < 0) || ((sb.st_mode & S_IFREG) == 0)) {
avrdude_message(MSG_NOTICE, "%sUser configuration file does not exist or is not a "
"regular file, skipping\n",
progbuf);
}
if ((rc < 0) || ((sb.st_mode & S_IFREG) == 0))
imsg_notice("User configuration file does not exist or is not a regular file, skipping\n");
else {
rc = read_config(usr_config);
if (rc) {
avrdude_message(MSG_INFO, "%s: error reading user configuration file \"%s\"\n",
progname, usr_config);
pmsg_error("unable to process user configuration file %s\n", usr_config);
exit(1);
}
}
@@ -866,13 +914,11 @@ int main(int argc, char * argv [])
for (ln1=lfirst(additional_config_files); ln1; ln1=lnext(ln1)) {
p = ldata(ln1);
avrdude_message(MSG_NOTICE, "%sAdditional configuration file is \"%s\"\n",
progbuf, p);
imsg_notice("additional configuration file is %s\n", p);
rc = read_config(p);
if (rc) {
avrdude_message(MSG_INFO, "%s: error reading additional configuration file \"%s\"\n",
progname, p);
pmsg_error("unable to process additional configuration file %s\n", p);
exit(1);
}
}
@@ -898,8 +944,8 @@ int main(int argc, char * argv [])
PROGRAMMER *pgm = ldata(ln2);
int pm = pgm->prog_modes & p->prog_modes;
if(pm & (pm-1))
avrdude_message(MSG_INFO, "%s warning: %s and %s share multiple modes (%s)\n",
progname, pgm->id? ldata(lfirst(pgm->id)): "???", p->desc, via_prog_modes(pm));
pmsg_warning("%s and %s share multiple modes (%s)\n",
pgm->id? (char *) ldata(lfirst(pgm->id)): "???", p->desc, via_prog_modes(pm));
}
}
@@ -909,13 +955,13 @@ int main(int argc, char * argv [])
PROGRAMMER *pgm = locate_programmer(programmers, programmer);
if(!pgm)
exit_programmer_not_found(programmer);
avrdude_message(MSG_INFO, "\nValid parts for programmer %s are:\n", programmer);
msg_error("\nValid parts for programmer %s are:\n", programmer);
list_parts(stderr, " ", part_list, pgm->prog_modes);
} else {
avrdude_message(MSG_INFO, "\nValid parts are:\n");
msg_error("\nValid parts are:\n");
list_parts(stderr, " ", part_list, ~0);
}
avrdude_message(MSG_INFO, "\n");
msg_error("\n");
exit(1);
}
}
@@ -926,25 +972,25 @@ int main(int argc, char * argv [])
AVRPART *p = locate_part(part_list, partdesc);
if(!p)
exit_part_not_found(partdesc);
avrdude_message(MSG_INFO, "\nValid programmers for part %s are:\n", p->desc);
msg_error("\nValid programmers for part %s are:\n", p->desc);
list_programmers(stderr, " ", programmers, p->prog_modes);
} else {
avrdude_message(MSG_INFO, "\nValid programmers are:\n");
msg_error("\nValid programmers are:\n");
list_programmers(stderr, " ", programmers, ~0);
}
avrdude_message(MSG_INFO, "\n");
msg_error("\n");
exit(1);
}
if (strcmp(programmer, "?type") == 0) {
avrdude_message(MSG_INFO, "\nValid programmer types are:\n");
msg_error("\nValid programmer types are:\n");
list_programmer_types(stderr, " ");
avrdude_message(MSG_INFO, "\n");
msg_error("\n");
exit(1);
}
}
avrdude_message(MSG_NOTICE, "\n");
msg_notice("\n");
if (!programmer || !*programmer)
exit_programmer_not_found(NULL);
@@ -956,7 +1002,8 @@ int main(int argc, char * argv [])
if (pgm->initpgm) {
pgm->initpgm(pgm);
} else {
avrdude_message(MSG_INFO, "\n%s: cannot initialize the programmer\n\n", progname);
msg_error("\n");
pmsg_error("cannot initialize the programmer\n\n");
exit(1);
}
@@ -969,13 +1016,10 @@ int main(int argc, char * argv [])
if (lsize(extended_params) > 0) {
if (pgm->parseextparams == NULL) {
avrdude_message(MSG_INFO, "%s: WARNING: Programmer doesn't support extended parameters,"
" -x option(s) ignored\n",
progname);
pmsg_error("programmer does not support extended parameters, -x option(s) ignored\n");
} else {
if (pgm->parseextparams(pgm, extended_params) < 0) {
avrdude_message(MSG_INFO, "%s: Error parsing extended parameter list\n",
progname);
pmsg_error("unable to parse extended parameter list\n");
exit(1);
}
}
@@ -1014,8 +1058,7 @@ int main(int argc, char * argv [])
if (exitspecs != NULL) {
if (pgm->parseexitspecs == NULL) {
avrdude_message(MSG_INFO, "%s: WARNING: -E option not supported by this programmer type\n",
progname);
pmsg_warning("-E option not supported by this programmer type\n");
exitspecs = NULL;
}
else if (pgm->parseexitspecs(pgm, exitspecs) < 0) {
@@ -1025,8 +1068,8 @@ int main(int argc, char * argv [])
}
if (avr_initmem(p) != 0) {
avrdude_message(MSG_INFO, "\n%s: failed to initialize memories\n",
progname);
msg_error("\n");
pmsg_error("unable to initialize memories\n");
exit(1);
}
@@ -1042,10 +1085,9 @@ int main(int argc, char * argv [])
upd = ldata(ln);
if (upd->memtype == NULL) {
const char *mtype = p->prog_modes & PM_PDI? "application": "flash";
avrdude_message(MSG_NOTICE2, "%s: defaulting memtype in -U %c:%s option to \"%s\"\n",
progname,
(upd->op == DEVICE_READ)? 'r': (upd->op == DEVICE_WRITE)? 'w': 'v',
upd->filename, mtype);
pmsg_notice2("defaulting memtype in -U %c:%s option to \"%s\"\n",
(upd->op == DEVICE_READ)? 'r': (upd->op == DEVICE_WRITE)? 'w': 'v',
upd->filename, mtype);
upd->memtype = cfg_strdup("main()", mtype);
}
@@ -1060,44 +1102,42 @@ int main(int argc, char * argv [])
* open the programmer
*/
if (port[0] == 0) {
avrdude_message(MSG_INFO, "\n%s: no port has been specified on the command line "
"or in the config file\n",
progname);
avrdude_message(MSG_INFO, "%sSpecify a port using the -P option and try again\n\n",
progbuf);
msg_error("\n");
pmsg_error("no port has been specified on the command line or in the config file\n");
imsg_error("specify a port using the -P option and try again\n\n");
exit(1);
}
if (verbose) {
avrdude_message(MSG_NOTICE, "%sUsing Port : %s\n", progbuf, port);
avrdude_message(MSG_NOTICE, "%sUsing Programmer : %s\n", progbuf, programmer);
imsg_notice("Using Port : %s\n", port);
imsg_notice("Using Programmer : %s\n", programmer);
if ((strcmp(pgm->type, "avr910") == 0)) {
avrdude_message(MSG_NOTICE, "%savr910_devcode (avrdude.conf) : ", progbuf);
if(p->avr910_devcode)avrdude_message(MSG_INFO, "0x%x\n", p->avr910_devcode);
else avrdude_message(MSG_NOTICE, "none\n");
imsg_notice("avr910_devcode (avrdude.conf) : ");
if(p->avr910_devcode)
msg_notice("0x%x\n", p->avr910_devcode);
else
msg_notice("none\n");
}
}
if (baudrate != 0) {
avrdude_message(MSG_NOTICE, "%sOverriding Baud Rate : %d\n", progbuf, baudrate);
imsg_notice("Overriding Baud Rate : %d\n", baudrate);
pgm->baudrate = baudrate;
}
if (bitclock != 0.0) {
avrdude_message(MSG_NOTICE, "%sSetting bit clk period : %.1f\n", progbuf, bitclock);
imsg_notice("Setting bit clk period : %.1f\n", bitclock);
pgm->bitclock = bitclock * 1e-6;
}
if (ispdelay != 0) {
avrdude_message(MSG_NOTICE, "%sSetting isp clock delay : %3i\n", progbuf, ispdelay);
imsg_notice("Setting isp clock delay : %3i\n", ispdelay);
pgm->ispdelay = ispdelay;
}
rc = pgm->open(pgm, port);
if (rc < 0) {
avrdude_message(MSG_INFO,
"%s: opening programmer \"%s\" on port \"%s\" failed\n",
progname, programmer, port);
pmsg_error("unable to open programmer %s on port %s\n", programmer, port);
exitrc = 1;
pgm->ppidata = 0; /* clear all bits at exit */
goto main_exit;
@@ -1110,29 +1150,24 @@ int main(int argc, char * argv [])
* as outlined in appnote AVR053
*/
if (pgm->perform_osccal == 0) {
avrdude_message(MSG_INFO, "%s: programmer does not support RC oscillator calibration\n",
progname);
pmsg_error("programmer does not support RC oscillator calibration\n");
exitrc = 1;
} else {
avrdude_message(MSG_INFO, "%s: performing RC oscillator calibration\n", progname);
pmsg_info("performing RC oscillator calibration\n");
exitrc = pgm->perform_osccal(pgm);
}
if (exitrc == 0 && quell_progress < 2) {
avrdude_message(MSG_INFO, "%s: calibration value is now stored in EEPROM at address 0\n",
progname);
}
if (exitrc == 0)
pmsg_info("calibration value is now stored in EEPROM at address 0\n");
goto main_exit;
}
if (verbose) {
if (verbose && quell_progress < 2) {
avr_display(stderr, p, progbuf, verbose);
avrdude_message(MSG_NOTICE, "\n");
msg_notice("\n");
programmer_display(pgm, progbuf);
}
if (quell_progress < 2) {
avrdude_message(MSG_INFO, "\n");
}
msg_info("\n");
exitrc = 0;
@@ -1154,12 +1189,10 @@ int main(int argc, char * argv [])
*/
init_ok = (rc = pgm->initialize(pgm, p)) >= 0;
if (!init_ok) {
avrdude_message(MSG_INFO, "%s: initialization failed, rc=%d\n", progname, rc);
pmsg_error("initialization failed, rc=%d\n", rc);
if (!ovsigck) {
avrdude_message(MSG_INFO, "%sDouble check connections and try again, "
"or use -F to override\n"
"%sthis check.\n\n",
progbuf, progbuf);
imsg_error("double check connections and try again or use -F to override\n");
imsg_error("this check\n\n");
exitrc = 1;
goto main_exit;
}
@@ -1168,10 +1201,7 @@ int main(int argc, char * argv [])
/* indicate ready */
pgm->rdy_led(pgm, ON);
if (quell_progress < 2) {
avrdude_message(MSG_INFO, "%s: AVR device initialized and ready to accept instructions\n",
progname);
}
pmsg_info("AVR device initialized and ready to accept instructions\n");
/*
* Let's read the signature bytes to make sure there is at least a
@@ -1194,54 +1224,46 @@ int main(int argc, char * argv [])
// Read SIB and compare FamilyID
char sib[AVR_SIBLEN + 1];
pgm->read_sib(pgm, p, sib);
avrdude_message(MSG_NOTICE, "%s: System Information Block: \"%s\"\n", progname, sib);
if (quell_progress < 2)
avrdude_message(MSG_INFO, "%s: Received FamilyID: \"%.*s\"\n", progname, AVR_FAMILYIDLEN, sib);
pmsg_notice("System Information Block: %s\n", sib);
pmsg_info("received FamilyID: \"%.*s\"\n", AVR_FAMILYIDLEN, sib);
if (strncmp(p->family_id, sib, AVR_FAMILYIDLEN))
avrdude_message(MSG_INFO, "%s: Expected FamilyID: \"%s\"\n", progname, p->family_id);
pmsg_error("expected FamilyID: \"%s\"\n", p->family_id);
}
if(erase) {
erase = 0;
if (uflags & UF_NOWRITE) {
avrdude_message(MSG_INFO, "%s: conflicting -e and -n options specified, NOT erasing chip\n",
progname);
pmsg_warning("conflicting -e and -n options specified, NOT erasing chip\n");
} else {
if (quell_progress < 2)
avrdude_message(MSG_INFO, "%s: erasing chip\n", progname);
pmsg_info("erasing chip\n");
exitrc = avr_unlock(pgm, p);
if(exitrc) goto main_exit;
if(exitrc)
goto main_exit;
goto sig_again;
}
}
if (!ovsigck) {
avrdude_message(MSG_INFO, "%sDouble check chip, or use -F to override this check.\n",
progbuf);
imsg_error("double check chip or use -F to override this check\n");
exitrc = 1;
goto main_exit;
}
}
avrdude_message(MSG_INFO, "%s: error reading signature data, rc=%d\n",
progname, rc);
pmsg_error("unable to read signature data, rc=%d\n", rc);
exitrc = 1;
goto main_exit;
}
}
sig = avr_locate_mem(p, "signature");
if (sig == NULL) {
avrdude_message(MSG_INFO, "%s: WARNING: signature data not defined for device \"%s\"\n",
progname, p->desc);
} else {
if (sig == NULL)
pmsg_warning("signature memory not defined for device %s\n", p->desc);
if (sig != NULL) {
int ff, zz;
if (quell_progress < 2) {
avrdude_message(MSG_INFO, "%s: Device signature = 0x", progname);
}
pmsg_info("device signature = 0x");
ff = zz = 1;
for (i=0; i<sig->size; i++) {
if (quell_progress < 2) {
avrdude_message(MSG_INFO, "%02x", sig->buf[i]);
}
msg_info("%02x", sig->buf[i]);
if (sig->buf[i] != 0xff)
ff = 0;
if (sig->buf[i] != 0x00)
@@ -1256,46 +1278,35 @@ int main(int argc, char * argv [])
if (quell_progress < 2) {
AVRPART * part;
part = locate_part_by_signature(part_list, sig->buf, sig->size);
if (part) {
avrdude_message(MSG_INFO, " (probably %s)", signature_matches ? p->id : part->id);
}
if((part = locate_part_by_signature(part_list, sig->buf, sig->size)))
msg_info(" (probably %s)", signature_matches ? p->id : part->id);
}
if (ff || zz) {
if (++attempt < 3) {
waittime *= 5;
if (quell_progress < 2) {
avrdude_message(MSG_INFO, " (retrying)\n");
}
msg_info(" (retrying)\n");
goto sig_again;
}
if (quell_progress < 2) {
avrdude_message(MSG_INFO, "\n");
}
avrdude_message(MSG_INFO, "%s: Yikes! Invalid device signature.\n", progname);
msg_info("\n");
pmsg_error("Yikes! Invalid device signature.\n");
if (!ovsigck) {
avrdude_message(MSG_INFO, "%sDouble check connections and try again, "
"or use -F to override\n"
"%sthis check.\n\n",
progbuf, progbuf);
imsg_error("Double check connections and try again, or use -F to override\n");
imsg_error("this check.\n\n");
exitrc = 1;
goto main_exit;
}
} else {
if (quell_progress < 2) {
avrdude_message(MSG_INFO, "\n");
}
msg_info("\n");
}
if (!signature_matches) {
avrdude_message(MSG_INFO, "%s: Expected signature for %s is %02X %02X %02X\n",
progname, p->desc,
p->signature[0], p->signature[1], p->signature[2]);
if (!ovsigck) {
avrdude_message(MSG_INFO, "%sDouble check chip, "
"or use -F to override this check.\n",
progbuf);
if (ovsigck) {
pmsg_warning("expected signature for %s is %02X %02X %02X\n", p->desc,
p->signature[0], p->signature[1], p->signature[2]);
} else {
pmsg_error("expected signature for %s is %02X %02X %02X\n", p->desc,
p->signature[0], p->signature[1], p->signature[2]);
imsg_error("double check chip or use -F to override this check\n");
exitrc = 1;
goto main_exit;
}
@@ -1305,12 +1316,9 @@ int main(int argc, char * argv [])
if (uflags & UF_AUTO_ERASE) {
if ((p->prog_modes & PM_PDI) && pgm->page_erase && lsize(updates) > 0) {
if (quell_progress < 2) {
avrdude_message(MSG_INFO, "%s: NOTE: Programmer supports page erase for Xmega devices.\n"
"%sEach page will be erased before programming it, but no chip erase is performed.\n"
"%sTo disable page erases, specify the -D option; for a chip-erase, use the -e option.\n",
progname, progbuf, progbuf);
}
pmsg_info("Note: programmer supports page erase for Xmega devices.\n");
imsg_info("Each page will be erased before programming it, but no chip erase is performed.\n");
imsg_info("To disable page erases, specify the -D option; for a chip-erase, use the -e option.\n");
} else {
AVRMEM * m;
const char *memname = p->prog_modes & PM_PDI? "application": "flash";
@@ -1323,12 +1331,8 @@ int main(int argc, char * argv [])
continue;
if ((strcmp(m->desc, memname) == 0) && (upd->op == DEVICE_WRITE)) {
erase = 1;
if (quell_progress < 2) {
avrdude_message(MSG_INFO, "%s: NOTE: \"%s\" memory has been specified, an erase cycle "
"will be performed\n"
"%sTo disable this feature, specify the -D option.\n",
progname, memname, progbuf);
}
pmsg_info("Note: %s memory has been specified, an erase cycle will be performed.\n", memname);
imsg_info("To disable this feature, specify the -D option.\n");
break;
}
}
@@ -1341,11 +1345,9 @@ int main(int argc, char * argv [])
* before the chip can accept new programming
*/
if (uflags & UF_NOWRITE) {
avrdude_message(MSG_INFO, "%s: conflicting -e and -n options specified, NOT erasing chip\n",
progname);
pmsg_warning("conflicting -e and -n options specified, NOT erasing chip\n");
} else {
if (quell_progress < 2)
avrdude_message(MSG_INFO, "%s: erasing chip\n", progname);
msg_info("erasing chip\n");
exitrc = avr_chip_erase(pgm, p);
if(exitrc) goto main_exit;
}
@@ -1392,9 +1394,7 @@ main_exit:
pgm->close(pgm);
}
if (quell_progress < 2) {
avrdude_message(MSG_INFO, "\n%s done. Thank you.\n\n", progname);
}
msg_info("\n%s done. Thank you.\n\n", progname);
return exitrc;
}