mirror of
https://github.com/mariusgreuel/avrdude.git
synced 2025-09-28 06:55:27 +00:00
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:
155
src/avr.c
155
src/avr.c
@@ -58,8 +58,7 @@ int avr_tpi_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) {
|
||||
/* Set Pointer Register */
|
||||
mem = avr_locate_mem(p, "flash");
|
||||
if (mem == NULL) {
|
||||
avrdude_message(MSG_INFO, "No flash memory to erase for part %s\n",
|
||||
p->desc);
|
||||
pmsg_error("no flash memory to erase for part %s\n", p->desc);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -91,9 +90,9 @@ int avr_tpi_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) {
|
||||
|
||||
return 0;
|
||||
} else {
|
||||
avrdude_message(MSG_INFO, "%s called for a part that has no TPI\n", __func__);
|
||||
return -1;
|
||||
}
|
||||
pmsg_error("part has no TPI\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* TPI program enable sequence */
|
||||
@@ -115,7 +114,7 @@ int avr_tpi_program_enable(const PROGRAMMER *pgm, const AVRPART *p, unsigned cha
|
||||
cmd[0] = (TPI_CMD_SLDCS | TPI_REG_TPIIR);
|
||||
err = pgm->cmd_tpi(pgm, cmd, 1, &response, sizeof(response));
|
||||
if (err || response != TPI_IDENT_CODE) {
|
||||
avrdude_message(MSG_INFO, "TPIIR not correct\n");
|
||||
pmsg_error("TPIIR not correct\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -135,12 +134,11 @@ int avr_tpi_program_enable(const PROGRAMMER *pgm, const AVRPART *p, unsigned cha
|
||||
return 0;
|
||||
}
|
||||
|
||||
avrdude_message(MSG_INFO, "Error enabling TPI external programming mode:");
|
||||
avrdude_message(MSG_INFO, "Target does not reply\n");
|
||||
pmsg_error("target does not reply when enabling TPI external programming mode\n");
|
||||
return -1;
|
||||
|
||||
} else {
|
||||
avrdude_message(MSG_INFO, "%s called for a part that has no TPI\n", __func__);
|
||||
pmsg_error("part has no TPI\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -185,9 +183,8 @@ int avr_read_byte_default(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM
|
||||
OPCODE * readop, * lext;
|
||||
|
||||
if (pgm->cmd == NULL) {
|
||||
avrdude_message(MSG_INFO, "%s: Error: %s programmer uses avr_read_byte_default() but does not\n"
|
||||
"provide a cmd() method.\n",
|
||||
progname, pgm->type);
|
||||
pmsg_error("%s programmer uses avr_read_byte_default() but does not\n", pgm->type);
|
||||
imsg_error("provide a cmd() method\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -196,8 +193,7 @@ int avr_read_byte_default(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM
|
||||
|
||||
if (p->prog_modes & PM_TPI) {
|
||||
if (pgm->cmd_tpi == NULL) {
|
||||
avrdude_message(MSG_INFO, "%s: Error: %s programmer does not support TPI\n",
|
||||
progname, pgm->type);
|
||||
pmsg_error("%s programmer does not support TPI\n", pgm->type);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -231,8 +227,7 @@ int avr_read_byte_default(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM
|
||||
|
||||
if (readop == NULL) {
|
||||
#if DEBUG
|
||||
avrdude_message(MSG_INFO, "avr_read_byte_default(): operation not supported on memory type \"%s\"\n",
|
||||
mem->desc);
|
||||
pmsg_error("operation not supported on memory type %s\n", mem->desc);
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
@@ -322,7 +317,7 @@ int avr_mem_hiaddr(const AVRMEM * mem)
|
||||
int avr_read(const PROGRAMMER *pgm, const AVRPART *p, const char *memtype, const AVRPART *v) {
|
||||
AVRMEM *mem = avr_locate_mem(p, memtype);
|
||||
if (mem == NULL) {
|
||||
avrdude_message(MSG_INFO, "No %s memory for part %s\n", memtype, p->desc);
|
||||
pmsg_error("no %s memory for part %s\n", memtype, p->desc);
|
||||
return LIBAVRDUDE_GENERAL_FAILURE;
|
||||
}
|
||||
|
||||
@@ -373,7 +368,7 @@ int avr_read_mem(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem, con
|
||||
rc = pgm->cmd_tpi(pgm, cmd, 1, mem->buf + i, 1);
|
||||
lastaddr++;
|
||||
if (rc == -1) {
|
||||
avrdude_message(MSG_INFO, "avr_read_mem(): error reading address 0x%04lx\n", i);
|
||||
pmsg_error("unable to read address 0x%04lx\n", i);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -431,8 +426,7 @@ int avr_read_mem(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem, con
|
||||
/* paged load failed, fall back to byte-at-a-time read below */
|
||||
failure = 1;
|
||||
} else {
|
||||
avrdude_message(MSG_DEBUG, "%s: avr_read_mem(): skipping page %u: no interesting data\n",
|
||||
progname, pageaddr / mem->page_size);
|
||||
pmsg_debug("avr_read_mem(): skipping page %u: no interesting data\n", pageaddr / mem->page_size);
|
||||
}
|
||||
nread++;
|
||||
report_progress(nread, npages, NULL);
|
||||
@@ -454,13 +448,12 @@ int avr_read_mem(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem, con
|
||||
{
|
||||
rc = pgm->read_byte(pgm, p, mem, i, mem->buf + i);
|
||||
if (rc != LIBAVRDUDE_SUCCESS) {
|
||||
avrdude_message(MSG_INFO, "avr_read_mem(): error reading address 0x%04lx\n", i);
|
||||
pmsg_error("unable to read byte at address 0x%04lx\n", i);
|
||||
if (rc == LIBAVRDUDE_GENERAL_FAILURE) {
|
||||
avrdude_message(MSG_INFO, " read operation not supported for memory %s\n",
|
||||
mem->desc);
|
||||
pmsg_error("read operation not supported for memory %s\n", mem->desc);
|
||||
return LIBAVRDUDE_NOTSUPPORTED;
|
||||
}
|
||||
avrdude_message(MSG_INFO, " read operation failed for memory %s\n", mem->desc);
|
||||
pmsg_error("read operation failed for memory %s\n", mem->desc);
|
||||
return LIBAVRDUDE_SOFTFAIL;
|
||||
}
|
||||
}
|
||||
@@ -483,16 +476,14 @@ int avr_write_page(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem,
|
||||
OPCODE * wp, * lext;
|
||||
|
||||
if (pgm->cmd == NULL) {
|
||||
avrdude_message(MSG_INFO, "%s: Error: %s programmer uses avr_write_page() but does not\n"
|
||||
"provide a cmd() method.\n",
|
||||
progname, pgm->type);
|
||||
pmsg_error("%s programmer uses avr_write_page() but does not\n", pgm->type);
|
||||
imsg_error("provide a cmd() method\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
wp = mem->op[AVR_OP_WRITEPAGE];
|
||||
if (wp == NULL) {
|
||||
avrdude_message(MSG_INFO, "avr_write_page(): memory \"%s\" not configured for page writes\n",
|
||||
mem->desc);
|
||||
pmsg_error("memory %s not configured for page writes\n", mem->desc);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -553,24 +544,22 @@ int avr_write_byte_default(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM
|
||||
struct timeval tv;
|
||||
|
||||
if (pgm->cmd == NULL) {
|
||||
avrdude_message(MSG_INFO, "%s: Error: %s programmer uses avr_write_byte_default() but does not\n"
|
||||
"provide a cmd() method.\n",
|
||||
progname, pgm->type);
|
||||
pmsg_error("%s programmer uses avr_write_byte_default() but does not\n", pgm->type);
|
||||
imsg_error("provide a cmd() method\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (p->prog_modes & PM_TPI) {
|
||||
if (pgm->cmd_tpi == NULL) {
|
||||
avrdude_message(MSG_INFO, "%s: Error: %s programmer does not support TPI\n",
|
||||
progname, pgm->type);
|
||||
pmsg_error("%s programmer does not support TPI\n", pgm->type);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (strcmp(mem->desc, "flash") == 0) {
|
||||
avrdude_message(MSG_INFO, "Writing a byte to flash is not supported for %s\n", p->desc);
|
||||
pmsg_error("writing a byte to flash is not supported for %s\n", p->desc);
|
||||
return -1;
|
||||
} else if ((mem->offset + addr) & 1) {
|
||||
avrdude_message(MSG_INFO, "Writing a byte to an odd location is not supported for %s\n", p->desc);
|
||||
pmsg_error("writing a byte to an odd location is not supported for %s\n", p->desc);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -657,8 +646,7 @@ int avr_write_byte_default(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM
|
||||
|
||||
if (writeop == NULL) {
|
||||
#if DEBUG
|
||||
avrdude_message(MSG_INFO, "avr_write_byte_default(): write not supported for memory type \"%s\"\n",
|
||||
mem->desc);
|
||||
pmsg_error("write not supported for memory type %s\n", mem->desc);
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
@@ -750,25 +738,20 @@ int avr_write_byte_default(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM
|
||||
* device if the data read back does not match what we wrote.
|
||||
*/
|
||||
pgm->pgm_led(pgm, OFF);
|
||||
avrdude_message(MSG_INFO, "%s: this device must be powered off and back on to continue\n",
|
||||
progname);
|
||||
pmsg_info("this device must be powered off and back on to continue\n");
|
||||
if (pgm->pinno[PPI_AVR_VCC]) {
|
||||
avrdude_message(MSG_INFO, "%s: attempting to do this now ...\n", progname);
|
||||
pmsg_info("attempting to do this now ...\n");
|
||||
pgm->powerdown(pgm);
|
||||
usleep(250000);
|
||||
rc = pgm->initialize(pgm, p);
|
||||
if (rc < 0) {
|
||||
avrdude_message(MSG_INFO, "%s: initialization failed, rc=%d\n", progname, rc);
|
||||
avrdude_message(MSG_INFO, "%s: can't re-initialize device after programming the "
|
||||
"%s bits\n", progname, mem->desc);
|
||||
avrdude_message(MSG_INFO, "%s: you must manually power-down the device and restart\n"
|
||||
"%s: %s to continue.\n",
|
||||
progname, progname, progname);
|
||||
pmsg_error("initialization failed, rc=%d\n", rc);
|
||||
imsg_error("cannot re-initialize device after programming the %s bits\n", mem->desc);
|
||||
imsg_error("you must manually power-down the device and restart %s to continue\n", progname);
|
||||
return -3;
|
||||
}
|
||||
|
||||
avrdude_message(MSG_INFO, "%s: device was successfully re-initialized\n",
|
||||
progname);
|
||||
pmsg_info("device was successfully re-initialized\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -813,8 +796,7 @@ int avr_write_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem,
|
||||
int avr_write(const PROGRAMMER *pgm, const AVRPART *p, const char *memtype, int size, int auto_erase) {
|
||||
AVRMEM *m = avr_locate_mem(p, memtype);
|
||||
if (m == NULL) {
|
||||
avrdude_message(MSG_INFO, "No \"%s\" memory for part %s\n",
|
||||
memtype, p->desc);
|
||||
pmsg_error("no %s memory for part %s\n", memtype, p->desc);
|
||||
return LIBAVRDUDE_GENERAL_FAILURE;
|
||||
}
|
||||
|
||||
@@ -847,11 +829,8 @@ int avr_write_mem(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m, int
|
||||
wsize = size;
|
||||
}
|
||||
else if (size > wsize) {
|
||||
avrdude_message(MSG_INFO, "%s: WARNING: %d bytes requested, but memory region is only %d"
|
||||
"bytes\n"
|
||||
"%sOnly %d bytes will actually be written\n",
|
||||
progname, size, wsize,
|
||||
progbuf, wsize);
|
||||
pmsg_warning("%d bytes requested, but memory region is only %d bytes\n", size, wsize);
|
||||
imsg_warning("Only %d bytes will actually be written\n", wsize);
|
||||
}
|
||||
|
||||
|
||||
@@ -959,8 +938,7 @@ int avr_write_mem(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m, int
|
||||
/* paged write failed, fall back to byte-at-a-time write below */
|
||||
failure = 1;
|
||||
} else {
|
||||
avrdude_message(MSG_DEBUG, "%s: avr_write_mem(): skipping page %u: no interesting data\n",
|
||||
progname, pageaddr / m->page_size);
|
||||
pmsg_debug("avr_write_mem(): skipping page %u: no interesting data\n", pageaddr / m->page_size);
|
||||
}
|
||||
nwritten++;
|
||||
report_progress(nwritten, npages, NULL);
|
||||
@@ -1019,8 +997,7 @@ int avr_write_mem(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m, int
|
||||
if (do_write) {
|
||||
rc = avr_write_byte(pgm, p, m, i, data);
|
||||
if (rc) {
|
||||
avrdude_message(MSG_INFO, " ***failed; ");
|
||||
avrdude_message(MSG_INFO, "\n");
|
||||
msg_error(" ***failed;\n");
|
||||
pgm->err_led(pgm, ON);
|
||||
werror = 1;
|
||||
}
|
||||
@@ -1033,11 +1010,8 @@ int avr_write_mem(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m, int
|
||||
if (flush_page) {
|
||||
rc = avr_write_page(pgm, p, m, i);
|
||||
if (rc) {
|
||||
avrdude_message(MSG_INFO, " *** page %d (addresses 0x%04x - 0x%04x) failed "
|
||||
"to write\n",
|
||||
i % m->page_size,
|
||||
i - m->page_size + 1, i);
|
||||
avrdude_message(MSG_INFO, "\n");
|
||||
msg_error(" *** page %d (addresses 0x%04x - 0x%04x) failed to write\n\n",
|
||||
i / m->page_size, i - m->page_size + 1, i);
|
||||
pgm->err_led(pgm, ON);
|
||||
werror = 1;
|
||||
}
|
||||
@@ -1066,8 +1040,7 @@ int avr_signature(const PROGRAMMER *pgm, const AVRPART *p) {
|
||||
report_progress (0,1,"Reading");
|
||||
rc = avr_read(pgm, p, "signature", 0);
|
||||
if (rc < LIBAVRDUDE_SUCCESS) {
|
||||
avrdude_message(MSG_INFO, "%s: error reading signature data for part \"%s\", rc=%d\n",
|
||||
progname, p->desc, rc);
|
||||
pmsg_error("unable to read signature data for part %s, rc=%d\n", p->desc, rc);
|
||||
return rc;
|
||||
}
|
||||
report_progress (1,1,NULL);
|
||||
@@ -1121,15 +1094,13 @@ int avr_verify(const AVRPART * p, const AVRPART * v, const char * memtype, int s
|
||||
|
||||
a = avr_locate_mem(p, memtype);
|
||||
if (a == NULL) {
|
||||
avrdude_message(MSG_INFO, "avr_verify(): memory type \"%s\" not defined for part %s\n",
|
||||
memtype, p->desc);
|
||||
pmsg_error("memory type %s not defined for part %s\n", memtype, p->desc);
|
||||
return -1;
|
||||
}
|
||||
|
||||
b = avr_locate_mem(v, memtype);
|
||||
if (b == NULL) {
|
||||
avrdude_message(MSG_INFO, "avr_verify(): memory type \"%s\" not defined for part %s\n",
|
||||
memtype, v->desc);
|
||||
pmsg_error("memory type %s not defined for part %s\n", memtype, v->desc);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -1138,40 +1109,32 @@ int avr_verify(const AVRPART * p, const AVRPART * v, const char * memtype, int s
|
||||
vsize = a->size;
|
||||
|
||||
if (vsize < size) {
|
||||
avrdude_message(MSG_INFO, "%s: WARNING: requested verification for %d bytes\n"
|
||||
"%s%s memory region only contains %d bytes\n"
|
||||
"%sOnly %d bytes will be verified.\n",
|
||||
progname, size,
|
||||
progbuf, memtype, vsize,
|
||||
progbuf, vsize);
|
||||
pmsg_warning("requested verification for %d bytes\n", size);
|
||||
imsg_warning("%s memory region only contains %d bytes\n", memtype, vsize);
|
||||
imsg_warning("only %d bytes will be verified\n", vsize);
|
||||
size = vsize;
|
||||
}
|
||||
|
||||
for (i=0; i<size; i++) {
|
||||
if ((b->tags[i] & TAG_ALLOCATED) != 0 &&
|
||||
buf1[i] != buf2[i]) {
|
||||
if ((b->tags[i] & TAG_ALLOCATED) != 0 && buf1[i] != buf2[i]) {
|
||||
uint8_t bitmask = get_fuse_bitmask(a);
|
||||
if((buf1[i] & bitmask) != (buf2[i] & bitmask)) {
|
||||
// Mismatch is not just in unused bits
|
||||
avrdude_message(MSG_INFO, "%s: verification error, first mismatch at byte 0x%04x\n"
|
||||
"%s0x%02x != 0x%02x\n",
|
||||
progname, i,
|
||||
progbuf, buf1[i], buf2[i]);
|
||||
pmsg_error("verification mismatch, first encountered at addr 0x%04x\n", i);
|
||||
imsg_error("device 0x%02x != input 0x%02x\n", buf1[i], buf2[i]);
|
||||
return -1;
|
||||
} else {
|
||||
// Mismatch is only in unused bits
|
||||
if ((buf1[i] | bitmask) != 0xff) {
|
||||
// Programmer returned unused bits as 0, must be the part/programmer
|
||||
avrdude_message(MSG_INFO, "%s: WARNING: ignoring mismatch in unused bits of \"%s\"\n"
|
||||
"%s(0x%02x != 0x%02x). To prevent this warning fix the part\n"
|
||||
"%sor programmer definition in the config file.\n",
|
||||
progname, memtype, progbuf, buf1[i], buf2[i], progbuf);
|
||||
pmsg_warning("ignoring mismatch in unused bits of %s\n", memtype);
|
||||
imsg_warning("(device 0x%02x != input 0x%02x); to prevent this warning fix\n", buf1[i], buf2[i]);
|
||||
imsg_warning("the part or programmer definition in the config file\n");
|
||||
} else {
|
||||
// Programmer returned unused bits as 1, must be the user
|
||||
avrdude_message(MSG_INFO, "%s: WARNING: ignoring mismatch in unused bits of \"%s\"\n"
|
||||
"%s(0x%02x != 0x%02x). To prevent this warning set unused bits\n"
|
||||
"%sto 1 when writing (double check with your datasheet first).\n",
|
||||
progname, memtype, progbuf, buf1[i], buf2[i], progbuf);
|
||||
pmsg_warning("ignoring mismatch in unused bits of %s\n", memtype);
|
||||
imsg_warning("(device 0x%02x != input 0x%02x); to prevent this warning set\n", buf1[i], buf2[i]);
|
||||
imsg_warning("unused bits to 1 when writing (double check with datasheet)\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1196,8 +1159,7 @@ int avr_get_cycle_count(const PROGRAMMER *pgm, const AVRPART *p, int *cycles) {
|
||||
for (i=4; i>0; i--) {
|
||||
rc = pgm->read_byte(pgm, p, a, a->size-i, &v1);
|
||||
if (rc < 0) {
|
||||
avrdude_message(MSG_INFO, "%s: WARNING: can't read memory for cycle count, rc=%d\n",
|
||||
progname, rc);
|
||||
pmsg_warning("cannot read memory for cycle count, rc=%d\n", rc);
|
||||
return -1;
|
||||
}
|
||||
cycle_count = (cycle_count << 8) | v1;
|
||||
@@ -1236,8 +1198,7 @@ int avr_put_cycle_count(const PROGRAMMER *pgm, const AVRPART *p, int cycles) {
|
||||
|
||||
rc = avr_write_byte(pgm, p, a, a->size-i, v1);
|
||||
if (rc < 0) {
|
||||
avrdude_message(MSG_INFO, "%s: WARNING: can't write memory for cycle count, rc=%d\n",
|
||||
progname, rc);
|
||||
pmsg_warning("cannot write memory for cycle count, rc=%d\n", rc);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -1270,9 +1231,7 @@ void avr_add_mem_order(const char *str) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
avrdude_message(MSG_INFO,
|
||||
"%s: avr_mem_order[] under-dimensioned in avr.c; increase and recompile\n",
|
||||
progname);
|
||||
pmsg_error("avr_mem_order[] under-dimensioned in avr.c; increase and recompile\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user