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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
54 changed files with 3024 additions and 4206 deletions

View File

@ -44,7 +44,7 @@ static int arduino_read_sig_bytes(const PROGRAMMER *pgm, const AVRPART *p, const
/* Signature byte reads are always 3 bytes. */ /* Signature byte reads are always 3 bytes. */
if (m->size < 3) { if (m->size < 3) {
avrdude_message(MSG_INFO, "%s: memsize too small for sig byte read", progname); pmsg_error("memsize too small for sig byte read");
return -1; return -1;
} }
@ -56,19 +56,16 @@ static int arduino_read_sig_bytes(const PROGRAMMER *pgm, const AVRPART *p, const
if (serial_recv(&pgm->fd, buf, 5) < 0) if (serial_recv(&pgm->fd, buf, 5) < 0)
return -1; return -1;
if (buf[0] == Resp_STK_NOSYNC) { if (buf[0] == Resp_STK_NOSYNC) {
avrdude_message(MSG_INFO, "%s: stk500_cmd(): programmer is out of sync\n", pmsg_error("programmer is out of sync\n");
progname);
return -1; return -1;
} else if (buf[0] != Resp_STK_INSYNC) { } else if (buf[0] != Resp_STK_INSYNC) {
avrdude_message(MSG_INFO, "\n%s: arduino_read_sig_bytes(): (a) protocol error, " msg_error("\n");
"expect=0x%02x, resp=0x%02x\n", pmsg_error("protocol expects sync byte 0x%02x but got 0x%02x\n", Resp_STK_INSYNC, buf[0]);
progname, Resp_STK_INSYNC, buf[0]); return -2;
return -2;
} }
if (buf[4] != Resp_STK_OK) { if (buf[4] != Resp_STK_OK) {
avrdude_message(MSG_INFO, "\n%s: arduino_read_sig_bytes(): (a) protocol error, " msg_error("\n");
"expect=0x%02x, resp=0x%02x\n", pmsg_error("protocol expects OK byte 0x%02x but got 0x%02x\n", Resp_STK_OK, buf[4]);
progname, Resp_STK_OK, buf[4]);
return -3; return -3;
} }

155
src/avr.c
View File

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

View File

@ -57,8 +57,7 @@ struct pdata
static void avr910_setup(PROGRAMMER * pgm) static void avr910_setup(PROGRAMMER * pgm)
{ {
if ((pgm->cookie = malloc(sizeof(struct pdata))) == 0) { if ((pgm->cookie = malloc(sizeof(struct pdata))) == 0) {
avrdude_message(MSG_INFO, "%s: avr910_setup(): Out of memory allocating private data\n", pmsg_error("out of memory allocating private data\n");
progname);
exit(1); exit(1);
} }
memset(pgm->cookie, 0, sizeof(struct pdata)); memset(pgm->cookie, 0, sizeof(struct pdata));
@ -81,8 +80,7 @@ static int avr910_recv(const PROGRAMMER *pgm, char *buf, size_t len) {
rv = serial_recv(&pgm->fd, (unsigned char *)buf, len); rv = serial_recv(&pgm->fd, (unsigned char *)buf, len);
if (rv < 0) { if (rv < 0) {
avrdude_message(MSG_INFO, "%s: avr910_recv(): programmer is not responding\n", pmsg_error("programmer is not responding\n");
progname);
return 1; return 1;
} }
return 0; return 0;
@ -99,8 +97,7 @@ static int avr910_vfy_cmd_sent(const PROGRAMMER *pgm, char *errmsg) {
avr910_recv(pgm, &c, 1); avr910_recv(pgm, &c, 1);
if (c != '\r') { if (c != '\r') {
avrdude_message(MSG_INFO, "%s: error: programmer did not respond to command: %s\n", pmsg_error("programmer did not respond to command: %s\n", errmsg);
progname, errmsg);
return 1; return 1;
} }
return 0; return 0;
@ -176,16 +173,16 @@ static int avr910_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
avr910_send(pgm, "p", 1); avr910_send(pgm, "p", 1);
avr910_recv(pgm, &type, 1); avr910_recv(pgm, &type, 1);
avrdude_message(MSG_INFO, "Found programmer: Id = \"%s\"; type = %c\n", id, type); msg_notice("Programmer id = %s; type = %c\n", id, type);
avrdude_message(MSG_INFO, " Software Version = %c.%c; ", sw[0], sw[1]); msg_notice("Software version = %c.%c; ", sw[0], sw[1]);
avrdude_message(MSG_INFO, "Hardware Version = %c.%c\n", hw[0], hw[1]); msg_notice("Hardware version = %c.%c\n", hw[0], hw[1]);
/* See if programmer supports autoincrement of address. */ /* See if programmer supports autoincrement of address. */
avr910_send(pgm, "a", 1); avr910_send(pgm, "a", 1);
avr910_recv(pgm, &PDATA(pgm)->has_auto_incr_addr, 1); avr910_recv(pgm, &PDATA(pgm)->has_auto_incr_addr, 1);
if (PDATA(pgm)->has_auto_incr_addr == 'Y') if (PDATA(pgm)->has_auto_incr_addr == 'Y')
avrdude_message(MSG_NOTICE, "Programmer supports auto addr increment.\n"); msg_notice("programmer supports auto addr increment\n");
/* Check support for buffered memory access, ignore if not available */ /* Check support for buffered memory access, ignore if not available */
@ -197,8 +194,8 @@ static int avr910_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
PDATA(pgm)->buffersize = (unsigned int)(unsigned char)c<<8; PDATA(pgm)->buffersize = (unsigned int)(unsigned char)c<<8;
avr910_recv(pgm, &c, 1); avr910_recv(pgm, &c, 1);
PDATA(pgm)->buffersize += (unsigned int)(unsigned char)c; PDATA(pgm)->buffersize += (unsigned int)(unsigned char)c;
avrdude_message(MSG_NOTICE, "Programmer supports buffered memory access with " msg_notice("programmer supports buffered memory access with "
"buffersize = %u bytes.\n", "buffersize = %u bytes\n",
PDATA(pgm)->buffersize); PDATA(pgm)->buffersize);
PDATA(pgm)->use_blockmode = 1; PDATA(pgm)->use_blockmode = 1;
} else { } else {
@ -215,7 +212,7 @@ static int avr910_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
/* Get list of devices that the programmer supports. */ /* Get list of devices that the programmer supports. */
avr910_send(pgm, "t", 1); avr910_send(pgm, "t", 1);
avrdude_message(MSG_NOTICE, "\nProgrammer supports the following devices:\n"); msg_notice2("\nProgrammer supports the following devices:\n");
devtype_1st = 0; devtype_1st = 0;
while (1) { while (1) {
avr910_recv(pgm, &c, 1); avr910_recv(pgm, &c, 1);
@ -225,20 +222,22 @@ static int avr910_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
break; break;
part = locate_part_by_avr910_devcode(part_list, c); part = locate_part_by_avr910_devcode(part_list, c);
avrdude_message(MSG_NOTICE, " Device code: 0x%02x = %s\n", c & 0xff, part? part->desc: "(unknown)"); msg_notice2(" Device code: 0x%02x = %s\n", c & 0xff, part? part->desc: "(unknown)");
/* FIXME: Need to lookup devcode and report the device. */ /* FIXME: Need to lookup devcode and report the device. */
if (p->avr910_devcode == c) if (p->avr910_devcode == c)
dev_supported = 1; dev_supported = 1;
}; };
avrdude_message(MSG_NOTICE, "\n"); msg_notice2("\n");
if (!dev_supported) { if (!dev_supported) {
avrdude_message(MSG_INFO, "%s: %s: selected device is not supported by programmer: %s\n", if(ovsigck)
progname, ovsigck? "warning": "error", p->id); pmsg_warning("selected device is not supported by programmer %s\n", p->id);
if (!ovsigck) else {
pmsg_error("selected device is not supported by programmer %s\n", p->id);
return -1; return -1;
}
} }
/* If the user forced the selection, use the first device /* If the user forced the selection, use the first device
type that is supported by the programmer. */ type that is supported by the programmer. */
@ -255,8 +254,7 @@ static int avr910_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
avr910_send(pgm, buf, 2); avr910_send(pgm, buf, 2);
avr910_vfy_cmd_sent(pgm, "select device"); avr910_vfy_cmd_sent(pgm, "select device");
avrdude_message(MSG_NOTICE, "%s: avr910_devcode selected: 0x%02x\n", pmsg_notice("avr910_devcode selected: 0x%02x\n", (unsigned) buf[1]);
progname, (unsigned)buf[1]);
avr910_enter_prog_mode(pgm); avr910_enter_prog_mode(pgm);
@ -319,27 +317,23 @@ static int avr910_parseextparms(const PROGRAMMER *pgm, const LISTID extparms) {
int devcode; int devcode;
if (sscanf(extended_param, "devcode=%i", &devcode) != 1 || if (sscanf(extended_param, "devcode=%i", &devcode) != 1 ||
devcode <= 0 || devcode > 255) { devcode <= 0 || devcode > 255) {
avrdude_message(MSG_INFO, "%s: avr910_parseextparms(): invalid devcode '%s'\n", pmsg_error("invalid devcode '%s'\n", extended_param);
progname, extended_param);
rv = -1; rv = -1;
continue; continue;
} }
avrdude_message(MSG_NOTICE2, "%s: avr910_parseextparms(): devcode overwritten as 0x%02x\n", pmsg_notice2("avr910_parseextparms(): devcode overwritten as 0x%02x\n", devcode);
progname, devcode);
PDATA(pgm)->devcode = devcode; PDATA(pgm)->devcode = devcode;
continue; continue;
} }
if (strncmp(extended_param, "no_blockmode", strlen("no_blockmode")) == 0) { if (strncmp(extended_param, "no_blockmode", strlen("no_blockmode")) == 0) {
avrdude_message(MSG_NOTICE2, "%s: avr910_parseextparms(-x): no testing for Blockmode\n", pmsg_notice2("avr910_parseextparms(-x): no testing for Blockmode\n");
progname);
PDATA(pgm)->test_blockmode = 0; PDATA(pgm)->test_blockmode = 0;
continue; continue;
} }
avrdude_message(MSG_INFO, "%s: avr910_parseextparms(): invalid extended parameter '%s'\n", pmsg_error("invalid extended parameter '%s'\n", extended_param);
progname, extended_param);
rv = -1; rv = -1;
} }
@ -708,7 +702,7 @@ static int avr910_read_sig_bytes(const PROGRAMMER *pgm, const AVRPART *p, const
unsigned char tmp; unsigned char tmp;
if (m->size < 3) { if (m->size < 3) {
avrdude_message(MSG_INFO, "%s: memsize too small for sig byte read", progname); pmsg_error("memsize too small for sig byte read");
return -1; return -1;
} }

View File

@ -222,14 +222,12 @@ static int cacheAddress(int addr, const AVR_Cache *cp, const AVRMEM *mem) {
int cacheaddr = addr + (int) (mem->offset - cp->offset); int cacheaddr = addr + (int) (mem->offset - cp->offset);
if(cacheaddr < 0 || cacheaddr >= cp->size) { // Should never happen (unless offsets wrong in avrdude.conf) if(cacheaddr < 0 || cacheaddr >= cp->size) { // Should never happen (unless offsets wrong in avrdude.conf)
avrdude_message(MSG_INFO, "%s: cacheAddress() %s cache address 0x%04x out of range [0, 0x%04x]\n", pmsg_error("%s cache address 0x%04x out of range [0, 0x%04x]\n", mem->desc, cacheaddr, cp->size);
progname, mem->desc, cacheaddr, cp->size);
return LIBAVRDUDE_GENERAL_FAILURE; return LIBAVRDUDE_GENERAL_FAILURE;
} }
if(mem->page_size != cp->page_size) { // Should never happen (unless incompatible page sizes in avrdude.conf) if(mem->page_size != cp->page_size) { // Should never happen (unless incompatible page sizes in avrdude.conf)
avrdude_message(MSG_INFO, "%s: cacheAddress() %s page size %d incompatible with cache page size %d\n", pmsg_error("%s page size %d incompatible with cache page size %d\n", mem->desc, mem->page_size, cp->page_size);
progname, mem->desc, mem->page_size, cp->page_size);
return LIBAVRDUDE_GENERAL_FAILURE; return LIBAVRDUDE_GENERAL_FAILURE;
} }
@ -246,8 +244,8 @@ static int loadCachePage(AVR_Cache *cp, const PROGRAMMER *pgm, const AVRPART *p,
if(avr_read_page_default(pgm, p, mem, addr & ~(cp->page_size-1), cp->cont + cachebase) < 0) { if(avr_read_page_default(pgm, p, mem, addr & ~(cp->page_size-1), cp->cont + cachebase) < 0) {
report_progress(1, -1, NULL); report_progress(1, -1, NULL);
if(nlOnErr && quell_progress) if(nlOnErr && quell_progress)
avrdude_message(MSG_INFO, "\n"); msg_info("\n");
avrdude_message(MSG_INFO, "%s: loadCachePage() %s read error at addr 0x%04x\n", progname, mem->desc, addr); pmsg_error("unable to read %s page at addr 0x%04x\n", mem->desc, addr);
return LIBAVRDUDE_GENERAL_FAILURE; return LIBAVRDUDE_GENERAL_FAILURE;
} }
@ -280,8 +278,8 @@ static int writeCachePage(AVR_Cache *cp, const PROGRAMMER *pgm, const AVRPART *p
if(avr_read_page_default(pgm, p, mem, base, cp->copy + base) < 0) { if(avr_read_page_default(pgm, p, mem, base, cp->copy + base) < 0) {
report_progress(1, -1, NULL); report_progress(1, -1, NULL);
if(nlOnErr && quell_progress) if(nlOnErr && quell_progress)
avrdude_message(MSG_INFO, "\n"); msg_info("\n");
avrdude_message(MSG_INFO, "%s: writeCachePage() %s read error at addr 0x%04x\n", progname, mem->desc, base); pmsg_error("unable to read %s page at addr 0x%04x\n", mem->desc, base);
return LIBAVRDUDE_GENERAL_FAILURE; return LIBAVRDUDE_GENERAL_FAILURE;
} }
@ -351,7 +349,7 @@ int avr_flush_cache(const PROGRAMMER *pgm, const AVRPART *p) {
if(!chpages) if(!chpages)
return LIBAVRDUDE_SUCCESS; return LIBAVRDUDE_SUCCESS;
avrdude_message(MSG_INFO, "%s: synching cache to device... ", progname); pmsg_info("synching cache to device ... ");
fflush(stderr); fflush(stderr);
// Check whether page erase needed and working and whether chip erase needed // Check whether page erase needed and working and whether chip erase needed
@ -361,7 +359,9 @@ int avr_flush_cache(const PROGRAMMER *pgm, const AVRPART *p) {
if(!cp->cont) // Ensure cache is initialised from now on if(!cp->cont) // Ensure cache is initialised from now on
if(initCache(cp, pgm, p) < 0) { if(initCache(cp, pgm, p) < 0) {
avrdude_message(MSG_INFO, "%s: initialising the cache failed\n", progname); if(quell_progress)
msg_info("\n");
pmsg_error("unable to initialise the cache\n");
return LIBAVRDUDE_GENERAL_FAILURE; return LIBAVRDUDE_GENERAL_FAILURE;
} }
@ -394,13 +394,13 @@ int avr_flush_cache(const PROGRAMMER *pgm, const AVRPART *p) {
} }
if(!chpages) { if(!chpages) {
avrdude_message(MSG_INFO, "done\n"); msg_info("done\n");
return LIBAVRDUDE_SUCCESS; return LIBAVRDUDE_SUCCESS;
} }
if(chiperase) { if(chiperase) {
if(quell_progress) { if(quell_progress) {
avrdude_message(MSG_INFO, "reading/chip erase/writing cycle needed ... "); msg_info("reading/chip erase/writing cycle needed ... ");
fflush(stderr); fflush(stderr);
} }
@ -441,8 +441,8 @@ int avr_flush_cache(const PROGRAMMER *pgm, const AVRPART *p) {
if(avr_chip_erase(pgm, p) < 0) { if(avr_chip_erase(pgm, p) < 0) {
report_progress(1, -1, NULL); report_progress(1, -1, NULL);
if(quell_progress) if(quell_progress)
avrdude_message(MSG_INFO, "\n"); msg_info("\n");
avrdude_message(MSG_INFO, "%s: avr_flush_cache() chip erase failed\n", progname); pmsg_error("chip erase failed\n");
return LIBAVRDUDE_GENERAL_FAILURE; return LIBAVRDUDE_GENERAL_FAILURE;
} }
@ -465,8 +465,8 @@ int avr_flush_cache(const PROGRAMMER *pgm, const AVRPART *p) {
if(avr_read_page_default(pgm, p, mem, n, cp->copy + n) < 0) { if(avr_read_page_default(pgm, p, mem, n, cp->copy + n) < 0) {
report_progress(1, -1, NULL); report_progress(1, -1, NULL);
if(quell_progress) if(quell_progress)
avrdude_message(MSG_INFO, "\n"); msg_info("\n");
avrdude_message(MSG_INFO, "%s: flash read failed at addr 0x%04x\n", progname, n); pmsg_error("flash read failed at addr 0x%04x\n", n);
return LIBAVRDUDE_GENERAL_FAILURE; return LIBAVRDUDE_GENERAL_FAILURE;
} }
} }
@ -478,8 +478,8 @@ int avr_flush_cache(const PROGRAMMER *pgm, const AVRPART *p) {
if(avr_read_page_default(pgm, p, mem, n, cp->copy + n) < 0) { if(avr_read_page_default(pgm, p, mem, n, cp->copy + n) < 0) {
report_progress(1, -1, NULL); report_progress(1, -1, NULL);
if(quell_progress) if(quell_progress)
avrdude_message(MSG_INFO, "\n"); msg_info("\n");
avrdude_message(MSG_INFO, "%s: EEPROM read failed at addr 0x%04x\n", progname, n); pmsg_error("EEPROM read failed at addr 0x%04x\n", n);
return LIBAVRDUDE_GENERAL_FAILURE; return LIBAVRDUDE_GENERAL_FAILURE;
} }
// EEPROM zapped by chip erase? Set all copy to 0xff // EEPROM zapped by chip erase? Set all copy to 0xff
@ -524,8 +524,8 @@ int avr_flush_cache(const PROGRAMMER *pgm, const AVRPART *p) {
if(memcmp(cp->copy + n, cp->cont + n, cp->page_size)) { if(memcmp(cp->copy + n, cp->cont + n, cp->page_size)) {
report_progress(1, -1, NULL); report_progress(1, -1, NULL);
if(quell_progress) if(quell_progress)
avrdude_message(MSG_INFO, "\n"); msg_info("\n");
avrdude_message(MSG_INFO, "%s: %s verification error at addr 0x%04x\n", progname, mem->desc, n); pmsg_error("verification mismatch at %s page addr 0x%04x\n", mem->desc, n);
return LIBAVRDUDE_GENERAL_FAILURE; return LIBAVRDUDE_GENERAL_FAILURE;
} }
report_progress(iwr++, nwr, NULL); report_progress(iwr++, nwr, NULL);
@ -535,7 +535,7 @@ int avr_flush_cache(const PROGRAMMER *pgm, const AVRPART *p) {
} }
report_progress(1, 0, NULL); report_progress(1, 0, NULL);
avrdude_message(MSG_INFO, quell_progress? "done\n": "\n"); msg_info(quell_progress? "done\n": "\n");
return LIBAVRDUDE_SUCCESS; return LIBAVRDUDE_SUCCESS;
} }

View File

@ -28,20 +28,62 @@
#define USER_CONF_FILE ".avrduderc" #define USER_CONF_FILE ".avrduderc"
#endif #endif
extern char * progname; /* name of program, for messages */ extern char *progname; // name of program, for messages
extern char progbuf[]; /* spaces same length as progname */ extern char progbuf[]; // spaces same length as progname
extern int ovsigck; /* override signature check (-F) */ extern int ovsigck; // override signature check (-F)
extern int verbose; /* verbosity level (-v, -vv, ...) */ extern int verbose; // verbosity level (-v, -vv, ...)
extern int quell_progress; /* quietness level (-q, -qq) */ extern int quell_progress; // quell progress report -q, reduce effective verbosity level (-qq, -qqq)
int avrdude_message(const int msglvl, const char *format, ...); int avrdude_message(int msglvl, const char *format, ...);
int avrdude_message2(const char *fname, int msgmode, int msglvl, const char *format, ...);
#define MSG_INFO (0) /* no -v option, can be suppressed with -qq */ #define MSG_EXT_ERROR (-3) // OS-type error, no -v option, can be suppressed with -qqqqq
#define MSG_NOTICE (1) /* displayed with -v */ #define MSG_ERROR (-2) // Avrdude error, no -v option, can be suppressed with -qqqq
#define MSG_NOTICE2 (2) /* displayed with -vv, used rarely */ #define MSG_WARNING (-1) // Warning, no -v option, can be suppressed with -qqq
#define MSG_DEBUG (3) /* displayed with -vvv */ #define MSG_INFO 0 // Commentary, no -v option, can be suppressed with -qq
#define MSG_TRACE (4) /* displayed with -vvvv, show trace communication */ #define MSG_NOTICE 1 // Displayed with -v
#define MSG_TRACE2 (5) /* displayed with -vvvvv */ #define MSG_NOTICE2 2 // Displayed with -vv
#define MSG_DEBUG 3 // Displayed with -vvv
#define MSG_TRACE 4 // Displayed with -vvvv, show trace communication
#define MSG_TRACE2 5 // Displayed with -vvvvv
#define MSG2_PROGNAME 1 // Start by printing progname
#define MSG2_FUNCTION 2 // Print calling function (1st arg) after progname
#define MSG2_TYPE 4 // Print message type after function or progname
#define MSG2_INDENT1 8 // Start by printing indentation of progname+1 blanks
#define MSG2_INDENT2 16 // Start by printing indentation of progname+2 blanks
#define MSG2_FLUSH 32 // Flush before and after printing
// Shortcuts
#define msg_ext_error(...) avrdude_message2(__func__, 0, MSG_EXT_ERROR, __VA_ARGS__)
#define msg_error(...) avrdude_message2(__func__, 0, MSG_ERROR, __VA_ARGS__)
#define msg_warning(...) avrdude_message2(__func__, 0, MSG_WARNING, __VA_ARGS__)
#define msg_info(...) avrdude_message2(__func__, 0, MSG_INFO, __VA_ARGS__)
#define msg_notice(...) avrdude_message2(__func__, 0, MSG_NOTICE, __VA_ARGS__)
#define msg_notice2(...) avrdude_message2(__func__, 0, MSG_NOTICE2, __VA_ARGS__)
#define msg_debug(...) avrdude_message2(__func__, 0, MSG_DEBUG, __VA_ARGS__)
#define msg_trace(...) avrdude_message2(__func__, 0, MSG_TRACE, __VA_ARGS__)
#define msg_trace2(...) avrdude_message2(__func__, 0, MSG_TRACE2, __VA_ARGS__)
#define pmsg_ext_error(...) avrdude_message2(__func__, MSG2_PROGNAME|MSG2_FUNCTION|MSG2_TYPE|MSG2_FLUSH, MSG_EXT_ERROR, __VA_ARGS__)
#define pmsg_error(...) avrdude_message2(__func__, MSG2_PROGNAME|MSG2_FUNCTION|MSG2_TYPE|MSG2_FLUSH, MSG_ERROR, __VA_ARGS__)
#define pmsg_warning(...) avrdude_message2(__func__, MSG2_PROGNAME|MSG2_FUNCTION|MSG2_TYPE|MSG2_FLUSH, MSG_WARNING, __VA_ARGS__)
#define pmsg_info(...) avrdude_message2(__func__, MSG2_PROGNAME|MSG2_FLUSH, MSG_INFO, __VA_ARGS__)
#define pmsg_notice(...) avrdude_message2(__func__, MSG2_PROGNAME|MSG2_FLUSH, MSG_NOTICE, __VA_ARGS__)
#define pmsg_notice2(...) avrdude_message2(__func__, MSG2_PROGNAME|MSG2_FLUSH, MSG_NOTICE2, __VA_ARGS__)
#define pmsg_debug(...) avrdude_message2(__func__, MSG2_PROGNAME|MSG2_FLUSH, MSG_DEBUG, __VA_ARGS__)
#define pmsg_trace(...) avrdude_message2(__func__, MSG2_PROGNAME|MSG2_FLUSH, MSG_TRACE, __VA_ARGS__)
#define pmsg_trace2(...) avrdude_message2(__func__, MSG2_PROGNAME|MSG2_FLUSH, MSG_TRACE2, __VA_ARGS__)
#define imsg_ext_error(...) avrdude_message2(__func__, MSG2_INDENT1|MSG2_FLUSH, MSG_EXT_ERROR, __VA_ARGS__)
#define imsg_error(...) avrdude_message2(__func__, MSG2_INDENT1|MSG2_FLUSH, MSG_ERROR, __VA_ARGS__)
#define imsg_warning(...) avrdude_message2(__func__, MSG2_INDENT1|MSG2_FLUSH, MSG_WARNING, __VA_ARGS__)
#define imsg_info(...) avrdude_message2(__func__, MSG2_INDENT2|MSG2_FLUSH, MSG_INFO, __VA_ARGS__)
#define imsg_notice(...) avrdude_message2(__func__, MSG2_INDENT2|MSG2_FLUSH, MSG_NOTICE, __VA_ARGS__)
#define imsg_notice2(...) avrdude_message2(__func__, MSG2_INDENT2|MSG2_FLUSH, MSG_NOTICE2, __VA_ARGS__)
#define imsg_debug(...) avrdude_message2(__func__, MSG2_INDENT2|MSG2_FLUSH, MSG_DEBUG, __VA_ARGS__)
#define imsg_trace(...) avrdude_message2(__func__, MSG2_INDENT2|MSG2_FLUSH, MSG_TRACE, __VA_ARGS__)
#define imsg_trace2(...) avrdude_message2(__func__, MSG2_INDENT2|MSG2_FLUSH, MSG_TRACE2, __VA_ARGS__)
#endif #endif

View File

@ -51,9 +51,7 @@
#ifdef DO_NOT_BUILD_AVRFTDI #ifdef DO_NOT_BUILD_AVRFTDI
static int avrftdi_noftdi_open(PROGRAMMER *pgm, const char *name) { static int avrftdi_noftdi_open(PROGRAMMER *pgm, const char *name) {
avrdude_message(MSG_INFO, "%s: Error: no libftdi or libusb support. Install libftdi1/libusb-1.0 or libftdi/libusb and run configure/make again.\n", pmsg_error("no libftdi or libusb support; install libftdi1/libusb-1.0 or libftdi/libusb and run configure/make again\n");
progname);
return -1; return -1;
} }
@ -140,14 +138,14 @@ void avrftdi_log(int level, const char * func, int line,
if(!skip_prefix) if(!skip_prefix)
{ {
switch(level) { switch(level) {
case ERR: avrdude_message(MSG_INFO, "E "); break; case ERR: msg_error("E "); break;
case WARN: avrdude_message(MSG_INFO, "W "); break; case WARN: msg_error("W "); break;
case INFO: avrdude_message(MSG_INFO, "I "); break; case INFO: msg_error("I "); break;
case DEBUG: avrdude_message(MSG_INFO, "D "); break; case DEBUG: msg_error("D "); break;
case TRACE: avrdude_message(MSG_INFO, "T "); break; case TRACE: msg_error("T "); break;
default: avrdude_message(MSG_INFO, " "); break; default: msg_error(" "); break;
} }
avrdude_message(MSG_INFO, "%s(%d): ", func, line); msg_error("%s(%d): ", func, line);
} }
va_start(ap, fmt); va_start(ap, fmt);
vfprintf(stderr, fmt, ap); vfprintf(stderr, fmt, ap);
@ -170,16 +168,16 @@ static void buf_dump(const unsigned char *buf, int len, char *desc,
int offset, int width) int offset, int width)
{ {
int i; int i;
avrdude_message(MSG_INFO, "%s begin:\n", desc); msg_info("%s begin:\n", desc);
for (i = 0; i < offset; i++) for (i = 0; i < offset; i++)
avrdude_message(MSG_INFO, "%02x ", buf[i]); msg_info("%02x ", buf[i]);
avrdude_message(MSG_INFO, "\n"); msg_info("\n");
for (i++; i <= len; i++) { for (i++; i <= len; i++) {
avrdude_message(MSG_INFO, "%02x ", buf[i-1]); msg_info("%02x ", buf[i-1]);
if((i-offset) != 0 && (i-offset)%width == 0) if((i-offset) != 0 && (i-offset)%width == 0)
avrdude_message(MSG_INFO, "\n"); msg_info("\n");
} }
avrdude_message(MSG_INFO, "%s end\n", desc); msg_info("%s end\n", desc);
} }
/* /*
@ -347,7 +345,7 @@ static int avrftdi_transmit_bb(const PROGRAMMER *pgm, unsigned char mode, const
size_t max_size = MIN(pdata->ftdic->max_packet_size, (unsigned int) pdata->tx_buffer_size); size_t max_size = MIN(pdata->ftdic->max_packet_size, (unsigned int) pdata->tx_buffer_size);
// select block size so that resulting commands does not exceed max_size if possible // select block size so that resulting commands does not exceed max_size if possible
blocksize = MAX(1,(max_size-7)/((8*2*6)+(8*1*2))); blocksize = MAX(1,(max_size-7)/((8*2*6)+(8*1*2)));
//avrdude_message(MSG_INFO, "blocksize %d \n",blocksize); // msg_info("blocksize %d \n", blocksize);
unsigned char* send_buffer = alloca((8 * 2 * 6) * blocksize + (8 * 1 * 2) * blocksize + 7); unsigned char* send_buffer = alloca((8 * 2 * 6) * blocksize + (8 * 1 * 2) * blocksize + 7);
unsigned char* recv_buffer = alloca(2 * 16 * blocksize); unsigned char* recv_buffer = alloca(2 * 16 * blocksize);
@ -611,7 +609,8 @@ static int avrftdi_pin_setup(const PROGRAMMER *pgm) {
} }
pdata->use_bitbanging = !pin_check_mpsse; pdata->use_bitbanging = !pin_check_mpsse;
if (pdata->use_bitbanging) log_info("Because of pin configuration fallback to bitbanging mode.\n"); if (pdata->use_bitbanging)
log_info("Because of pin configuration fallback to bitbanging mode.\n");
/* /*
* TODO: No need to fail for a wrongly configured led or something. * TODO: No need to fail for a wrongly configured led or something.
@ -659,8 +658,7 @@ static int avrftdi_open(PROGRAMMER *pgm, const char *port) {
if (usbpid) { if (usbpid) {
pid = *(int *)(ldata(usbpid)); pid = *(int *)(ldata(usbpid));
if (lnext(usbpid)) if (lnext(usbpid))
avrdude_message(MSG_INFO, "%s: Warning: using PID 0x%04x, ignoring remaining PIDs in list\n", pmsg_warning("using PID 0x%04x, ignoring remaining PIDs in list\n", pid);
progname, pid);
} else } else
pid = USB_DEVICE_FT2232; pid = USB_DEVICE_FT2232;

View File

@ -15,6 +15,7 @@
#elif defined(HAVE_LIBFTDI) #elif defined(HAVE_LIBFTDI)
#include <ftdi.h> #include <ftdi.h>
#else #else
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma message("No libftdi or libusb support. Install libftdi1/libusb-1.0 or libftdi/libusb and run configure/make again.") #pragma message("No libftdi or libusb support. Install libftdi1/libusb-1.0 or libftdi/libusb and run configure/make again.")
#else #else
@ -30,7 +31,7 @@ enum { ERR, WARN, INFO, DEBUG, TRACE };
#define __log(lvl, fmt, ...) \ #define __log(lvl, fmt, ...) \
do { \ do { \
avrftdi_log(lvl, __func__, __LINE__, fmt, ##__VA_ARGS__); \ avrftdi_log(lvl, __func__, __LINE__, fmt, ##__VA_ARGS__); \
} while(0) } while(0)
#define log_err(fmt, ...) __log(ERR, fmt, ##__VA_ARGS__) #define log_err(fmt, ...) __log(ERR, fmt, ##__VA_ARGS__)
@ -40,49 +41,49 @@ enum { ERR, WARN, INFO, DEBUG, TRACE };
#define log_trace(fmt, ...) __log(TRACE, fmt, ##__VA_ARGS__) #define log_trace(fmt, ...) __log(TRACE, fmt, ##__VA_ARGS__)
#define E(x, ftdi) \ #define E(x, ftdi) \
do { \ do { \
if ((x)) \ if ((x)) \
{ \ { \
avrdude_message(MSG_INFO, "%s:%d %s() %s: %s (%d)\n\t%s\n", \ msg_error("%s:%d %s() %s: %s (%d)\n\t%s\n", \
__FILE__, __LINE__, __FUNCTION__, \ __FILE__, __LINE__, __FUNCTION__, \
#x, strerror(errno), errno, ftdi_get_error_string(ftdi)); \ #x, strerror(errno), errno, ftdi_get_error_string(ftdi)); \
return -1; \ return -1; \
} \ } \
} while(0) } while(0)
#define E_VOID(x, ftdi) \ #define E_VOID(x, ftdi) \
do { \ do { \
if ((x)) \ if ((x)) \
{ \ { \
avrdude_message(MSG_INFO, "%s:%d %s() %s: %s (%d)\n\t%s\n", \ msg_error("%s:%d %s() %s: %s (%d)\n\t%s\n", \
__FILE__, __LINE__, __FUNCTION__, \ __FILE__, __LINE__, __FUNCTION__, \
#x, strerror(errno), errno, ftdi_get_error_string(ftdi)); \ #x, strerror(errno), errno, ftdi_get_error_string(ftdi)); \
} \ } \
} while(0) } while(0)
#define to_pdata(pgm) \ #define to_pdata(pgm) \
((avrftdi_t *)((pgm)->cookie)) ((avrftdi_t *)((pgm)->cookie))
typedef struct avrftdi_s { typedef struct avrftdi_s {
/* pointer to struct maintained by libftdi to identify the device */ /* pointer to struct maintained by libftdi to identify the device */
struct ftdi_context* ftdic; struct ftdi_context* ftdic;
/* bitmask of values for pins. bit 0 represents pin 0 ([A|B]DBUS0) */ /* bitmask of values for pins. bit 0 represents pin 0 ([A|B]DBUS0) */
uint16_t pin_value; uint16_t pin_value;
/* bitmask of pin direction. a '1' make a pin an output. /* bitmask of pin direction. a '1' make a pin an output.
* bit 0 corresponds to pin 0. */ * bit 0 corresponds to pin 0. */
uint16_t pin_direction; uint16_t pin_direction;
/* don't know. not useful. someone put it in. */ /* don't know. not useful. someone put it in. */
uint16_t led_mask; uint16_t led_mask;
/* total number of pins supported by a programmer. varies with FTDI chips */ /* total number of pins supported by a programmer. varies with FTDI chips */
int pin_limit; int pin_limit;
/* internal RX buffer of the device. needed for INOUT transfers */ /* internal RX buffer of the device. needed for INOUT transfers */
int rx_buffer_size; int rx_buffer_size;
int tx_buffer_size; int tx_buffer_size;
/* use bitbanging instead of mpsse spi */ /* use bitbanging instead of mpsse spi */
bool use_bitbanging; bool use_bitbanging;
/* bits 16-23 of extended 24-bit word flash address for parts with flash > 128k */ /* bits 16-23 of extended 24-bit word flash address for parts with flash > 128k */
uint8_t lext_byte; uint8_t lext_byte;
} avrftdi_t; } avrftdi_t;
void avrftdi_log(int level, const char * func, int line, const char * fmt, ...); void avrftdi_log(int level, const char * func, int line, const char * fmt, ...);

View File

@ -538,7 +538,7 @@ void avr_mem_display(const char *prefix, FILE *f, const AVRMEM *m,
m->readback[1]); m->readback[1]);
} }
if (verbose > 4) { if (verbose > 4) {
avrdude_message(MSG_TRACE2, "%s Memory Ops:\n" msg_trace2("%s Memory Ops:\n"
"%s Oeration Inst Bit Bit Type Bitno Value\n" "%s Oeration Inst Bit Bit Type Bitno Value\n"
"%s ----------- -------- -------- ----- -----\n", "%s ----------- -------- -------- ----- -----\n",
prefix, prefix, prefix); prefix, prefix, prefix);
@ -774,7 +774,7 @@ void avr_display(FILE *f, const AVRPART *p, const char *prefix, int verbose) {
fprintf( f, "%sMemory Detail :\n\n", prefix); fprintf( f, "%sMemory Detail :\n\n", prefix);
px = prefix; px = prefix;
buf = (char *)cfg_malloc("avr_display()", strlen(prefix) + 5); buf = (char *) cfg_malloc("avr_display()", strlen(prefix) + 5);
strcpy(buf, prefix); strcpy(buf, prefix);
strcat(buf, " "); strcat(buf, " ");
px = buf; px = buf;

View File

@ -76,8 +76,7 @@ static void bitbang_calibrate_delay(void)
if (QueryPerformanceFrequency(&freq)) if (QueryPerformanceFrequency(&freq))
{ {
has_perfcount = 1; has_perfcount = 1;
avrdude_message(MSG_NOTICE2, "%s: Using performance counter for bitbang delays\n", pmsg_notice2("using performance counter for bitbang delays\n");
progname);
} }
else else
{ {
@ -90,16 +89,14 @@ static void bitbang_calibrate_delay(void)
* auto-calibration figures seen on various Unix systems on * auto-calibration figures seen on various Unix systems on
* comparable hardware. * comparable hardware.
*/ */
avrdude_message(MSG_NOTICE2, "%s: Using guessed per-microsecond delay count for bitbang delays\n", pmsg_notice2("using guessed per-microsecond delay count for bitbang delays\n");
progname);
delay_decrement = 100; delay_decrement = 100;
} }
#else /* !WIN32 */ #else /* !WIN32 */
struct itimerval itv; struct itimerval itv;
volatile int i; volatile int i;
avrdude_message(MSG_NOTICE2, "%s: Calibrating delay loop...", pmsg_notice2("calibrating delay loop ...");
progname);
i = 0; i = 0;
done = 0; done = 0;
saved_alarmhandler = signal(SIGALRM, alarmhandler); saved_alarmhandler = signal(SIGALRM, alarmhandler);
@ -125,7 +122,7 @@ static void bitbang_calibrate_delay(void)
* Calculate back from 100 ms to 1 us. * Calculate back from 100 ms to 1 us.
*/ */
delay_decrement = -i / 100000; delay_decrement = -i / 100000;
avrdude_message(MSG_NOTICE2, " calibrated to %d cycles per us\n", msg_notice2(" calibrated to %d cycles per us\n",
delay_decrement); delay_decrement);
#endif /* WIN32 */ #endif /* WIN32 */
} }
@ -261,7 +258,7 @@ int bitbang_tpi_rx(const PROGRAMMER *pgm) {
break; break;
} }
if (b != 0) { if (b != 0) {
avrdude_message(MSG_INFO, "bitbang_tpi_rx: start bit not received correctly\n"); pmsg_error("start bit not received correctly\n");
return -1; return -1;
} }
@ -276,7 +273,7 @@ int bitbang_tpi_rx(const PROGRAMMER *pgm) {
/* parity bit */ /* parity bit */
if (bitbang_tpi_clk(pgm) != parity) { if (bitbang_tpi_clk(pgm) != parity) {
avrdude_message(MSG_INFO, "bitbang_tpi_rx: parity bit is wrong\n"); pmsg_error("parity bit is wrong\n");
return -1; return -1;
} }
@ -285,7 +282,7 @@ int bitbang_tpi_rx(const PROGRAMMER *pgm) {
b &= bitbang_tpi_clk(pgm); b &= bitbang_tpi_clk(pgm);
b &= bitbang_tpi_clk(pgm); b &= bitbang_tpi_clk(pgm);
if (b != 1) { if (b != 1) {
avrdude_message(MSG_INFO, "bitbang_tpi_rx: stop bits not received correctly\n"); pmsg_error("stop bits not received correctly\n");
return -1; return -1;
} }
@ -328,15 +325,15 @@ int bitbang_cmd(const PROGRAMMER *pgm, const unsigned char *cmd,
if(verbose >= 2) if(verbose >= 2)
{ {
avrdude_message(MSG_NOTICE2, "bitbang_cmd(): [ "); msg_notice2("bitbang_cmd(): [ ");
for(i = 0; i < 4; i++) for(i = 0; i < 4; i++)
avrdude_message(MSG_NOTICE2, "%02X ", cmd[i]); msg_notice2("%02X ", cmd[i]);
avrdude_message(MSG_NOTICE2, "] [ "); msg_notice2("] [ ");
for(i = 0; i < 4; i++) for(i = 0; i < 4; i++)
{ {
avrdude_message(MSG_NOTICE2, "%02X ", res[i]); msg_notice2("%02X ", res[i]);
} }
avrdude_message(MSG_NOTICE2, "]\n"); msg_notice2("]\n");
} }
return 0; return 0;
@ -363,15 +360,15 @@ int bitbang_cmd_tpi(const PROGRAMMER *pgm, const unsigned char *cmd,
if(verbose >= 2) if(verbose >= 2)
{ {
avrdude_message(MSG_NOTICE2, "bitbang_cmd_tpi(): [ "); msg_notice2("bitbang_cmd_tpi(): [ ");
for(i = 0; i < cmd_len; i++) for(i = 0; i < cmd_len; i++)
avrdude_message(MSG_NOTICE2, "%02X ", cmd[i]); msg_notice2("%02X ", cmd[i]);
avrdude_message(MSG_NOTICE2, "] [ "); msg_notice2("] [ ");
for(i = 0; i < res_len; i++) for(i = 0; i < res_len; i++)
{ {
avrdude_message(MSG_NOTICE2, "%02X ", res[i]); msg_notice2("%02X ", res[i]);
} }
avrdude_message(MSG_NOTICE2, "]\n"); msg_notice2("]\n");
} }
pgm->pgm_led(pgm, OFF); pgm->pgm_led(pgm, OFF);
@ -399,15 +396,15 @@ int bitbang_spi(const PROGRAMMER *pgm, const unsigned char *cmd,
if(verbose >= 2) if(verbose >= 2)
{ {
avrdude_message(MSG_NOTICE2, "bitbang_cmd(): [ "); msg_notice2("bitbang_cmd(): [ ");
for(i = 0; i < count; i++) for(i = 0; i < count; i++)
avrdude_message(MSG_NOTICE2, "%02X ", cmd[i]); msg_notice2("%02X ", cmd[i]);
avrdude_message(MSG_NOTICE2, "] [ "); msg_notice2("] [ ");
for(i = 0; i < count; i++) for(i = 0; i < count; i++)
{ {
avrdude_message(MSG_NOTICE2, "%02X ", res[i]); msg_notice2("%02X ", res[i]);
} }
avrdude_message(MSG_NOTICE2, "]\n"); msg_notice2("]\n");
} }
return 0; return 0;
@ -434,8 +431,7 @@ int bitbang_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) {
/* Set Pointer Register */ /* Set Pointer Register */
mem = avr_locate_mem(p, "flash"); mem = avr_locate_mem(p, "flash");
if (mem == NULL) { if (mem == NULL) {
avrdude_message(MSG_INFO, "No flash memory to erase for part %s\n", pmsg_error("no flash memory to erase for part %s\n", p->desc);
p->desc);
return -1; return -1;
} }
bitbang_tpi_tx(pgm, TPI_CMD_SSTPR | 0); bitbang_tpi_tx(pgm, TPI_CMD_SSTPR | 0);
@ -455,8 +451,7 @@ int bitbang_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) {
} }
if (p->op[AVR_OP_CHIP_ERASE] == NULL) { if (p->op[AVR_OP_CHIP_ERASE] == NULL) {
avrdude_message(MSG_INFO, "chip erase instruction not defined for part \"%s\"\n", pmsg_error("chip erase instruction not defined for part %s\n", p->desc);
p->desc);
return -1; return -1;
} }
@ -495,8 +490,7 @@ int bitbang_program_enable(const PROGRAMMER *pgm, const AVRPART *p) {
} }
if (p->op[AVR_OP_PGM_ENABLE] == NULL) { if (p->op[AVR_OP_PGM_ENABLE] == NULL) {
avrdude_message(MSG_INFO, "program enable instruction not defined for part \"%s\"\n", pmsg_error("program enable instruction not defined for part %s\n", p->desc);
p->desc);
return -1; return -1;
} }
@ -527,8 +521,7 @@ int bitbang_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
if (p->prog_modes & PM_TPI) { if (p->prog_modes & PM_TPI) {
/* make sure cmd_tpi() is defined */ /* make sure cmd_tpi() is defined */
if (pgm->cmd_tpi == NULL) { if (pgm->cmd_tpi == NULL) {
avrdude_message(MSG_INFO, "%s: Error: %s programmer does not support TPI\n", pmsg_error("%s programmer does not support TPI\n", pgm->type);
progname, pgm->type);
return -1; return -1;
} }
@ -539,20 +532,20 @@ int bitbang_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
/* RESET must be LOW in case the existing code is driving the TPI pins: */ /* RESET must be LOW in case the existing code is driving the TPI pins: */
pgm->setpin(pgm, PIN_AVR_RESET, 0); pgm->setpin(pgm, PIN_AVR_RESET, 0);
avrdude_message(MSG_NOTICE2, "doing MOSI-MISO link check\n"); msg_notice2("doing MOSI-MISO link check\n");
pgm->setpin(pgm, PIN_AVR_MOSI, 0); pgm->setpin(pgm, PIN_AVR_MOSI, 0);
if (pgm->getpin(pgm, PIN_AVR_MISO) != 0) { if (pgm->getpin(pgm, PIN_AVR_MISO) != 0) {
avrdude_message(MSG_INFO, "MOSI->MISO 0 failed\n"); pmsg_error("MOSI->MISO 0 failed\n");
return -1; return -1;
} }
pgm->setpin(pgm, PIN_AVR_MOSI, 1); pgm->setpin(pgm, PIN_AVR_MOSI, 1);
if (pgm->getpin(pgm, PIN_AVR_MISO) != 1) { if (pgm->getpin(pgm, PIN_AVR_MISO) != 1) {
avrdude_message(MSG_INFO, "MOSI->MISO 1 failed\n"); pmsg_error("MOSI->MISO 1 failed\n");
return -1; return -1;
} }
avrdude_message(MSG_NOTICE2, "MOSI-MISO link present\n"); msg_notice2("MOSI-MISO link present\n");
} }
pgm->setpin(pgm, PIN_AVR_SCK, 0); pgm->setpin(pgm, PIN_AVR_SCK, 0);
@ -573,7 +566,7 @@ int bitbang_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
bitbang_tpi_tx(pgm, TPI_CMD_SLDCS | TPI_REG_TPIIR); bitbang_tpi_tx(pgm, TPI_CMD_SLDCS | TPI_REG_TPIIR);
rc = bitbang_tpi_rx(pgm); rc = bitbang_tpi_rx(pgm);
if (rc != 0x80) { if (rc != 0x80) {
avrdude_message(MSG_INFO, "TPIIR not correct\n"); pmsg_error("TPIIR not correct\n");
return -1; return -1;
} }
} else { } else {
@ -607,7 +600,7 @@ int bitbang_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
* can't sync with the device, maybe it's not attached? * can't sync with the device, maybe it's not attached?
*/ */
if (rc) { if (rc) {
avrdude_message(MSG_INFO, "%s: AVR device not responding\n", progname); pmsg_error("AVR device not responding\n");
return -1; return -1;
} }
} }
@ -617,8 +610,7 @@ int bitbang_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
static int verify_pin_assigned(const PROGRAMMER *pgm, int pin, char *desc) { static int verify_pin_assigned(const PROGRAMMER *pgm, int pin, char *desc) {
if (pgm->pinno[pin] == 0) { if (pgm->pinno[pin] == 0) {
avrdude_message(MSG_INFO, "%s: error: no pin has been assigned for %s\n", pmsg_error("no pin has been assigned for %s\n", desc);
progname, desc);
return -1; return -1;
} }
return 0; return 0;
@ -640,8 +632,7 @@ int bitbang_check_prerequisites(const PROGRAMMER *pgm) {
return -1; return -1;
if (pgm->cmd == NULL) { if (pgm->cmd == NULL) {
avrdude_message(MSG_INFO, "%s: error: no cmd() method defined for bitbang programmer\n", pmsg_error("no cmd() method defined for bitbang programmer\n");
progname);
return -1; return -1;
} }
return 0; return 0;

View File

@ -88,28 +88,28 @@ buspirate_uses_ascii(const PROGRAMMER *pgm) {
/* ====== Serial talker functions - binmode ====== */ /* ====== Serial talker functions - binmode ====== */
static void dump_mem(const int msglvl, const unsigned char *buf, size_t len) static void dump_mem(const unsigned char *buf, size_t len)
{ {
size_t i; size_t i;
for (i = 0; i<len; i++) { for (i = 0; i<len; i++) {
if (i % 8 == 0) if (i % 8 == 0)
avrdude_message(msglvl, "\t"); msg_debug("\t");
avrdude_message(msglvl, "0x%02x ", buf[i]); msg_debug("0x%02x ", buf[i]);
if (i % 8 == 3) if (i % 8 == 3)
avrdude_message(msglvl, " "); msg_debug(" ");
else if (i % 8 == 7) else if (i % 8 == 7)
avrdude_message(msglvl, "\n"); msg_debug("\n");
} }
if (i % 8 != 7) if (i % 8 != 7)
avrdude_message(msglvl, "\n"); msg_debug("\n");
} }
static int buspirate_send_bin(const PROGRAMMER *pgm, const unsigned char *data, size_t len) { static int buspirate_send_bin(const PROGRAMMER *pgm, const unsigned char *data, size_t len) {
int rc; int rc;
avrdude_message(MSG_DEBUG, "%s: buspirate_send_bin():\n", progname); pmsg_debug("buspirate_send_bin():\n");
dump_mem(MSG_DEBUG, data, len); dump_mem(data, len);
rc = serial_send(&pgm->fd, data, len); rc = serial_send(&pgm->fd, data, len);
@ -123,8 +123,8 @@ static int buspirate_recv_bin(const PROGRAMMER *pgm, unsigned char *buf, size_t
if (rc < 0) if (rc < 0)
return EOF; return EOF;
avrdude_message(MSG_DEBUG, "%s: buspirate_recv_bin():\n", progname); pmsg_debug("buspirate_recv_bin():\n");
dump_mem(MSG_DEBUG, buf, len); dump_mem(buf, len);
return len; return len;
} }
@ -135,7 +135,7 @@ static int buspirate_expect_bin(const PROGRAMMER *pgm,
{ {
unsigned char *recv_buf = alloca(expect_len); unsigned char *recv_buf = alloca(expect_len);
if ((PDATA(pgm)->flag & BP_FLAG_IN_BINMODE) == 0) { if ((PDATA(pgm)->flag & BP_FLAG_IN_BINMODE) == 0) {
avrdude_message(MSG_INFO, "BusPirate: Internal error: buspirate_send_bin() called from ascii mode\n"); pmsg_error("called from ascii mode\n");
return -1; return -1;
} }
@ -159,7 +159,7 @@ static int buspirate_getc(const PROGRAMMER *pgm) {
unsigned char ch = 0; unsigned char ch = 0;
if (PDATA(pgm)->flag & BP_FLAG_IN_BINMODE) { if (PDATA(pgm)->flag & BP_FLAG_IN_BINMODE) {
avrdude_message(MSG_INFO, "BusPirate: Internal error: buspirate_getc() called from binmode\n"); pmsg_error("called from binmode\n");
return EOF; return EOF;
} }
@ -197,9 +197,7 @@ static char *buspirate_readline_noexit(const PROGRAMMER *pgm, char *buf, size_t
serial_recv_timeout = PDATA(pgm)->serial_recv_timeout; serial_recv_timeout = PDATA(pgm)->serial_recv_timeout;
} }
serial_recv_timeout = orig_serial_recv_timeout; serial_recv_timeout = orig_serial_recv_timeout;
avrdude_message(MSG_DEBUG, "%s: buspirate_readline(): %s%s", pmsg_debug("buspirate_readline(): %s%s", buf, *buf && buf[strlen(buf)-1] == '\n'? "": "\n");
progname, buf,
buf[strlen(buf) - 1] == '\n' ? "" : "\n");
if (! buf[0]) if (! buf[0])
return NULL; return NULL;
@ -211,8 +209,7 @@ static char *buspirate_readline(const PROGRAMMER *pgm, char *buf, size_t len) {
ret = buspirate_readline_noexit(pgm, buf, len); ret = buspirate_readline_noexit(pgm, buf, len);
if (! ret) { if (! ret) {
avrdude_message(MSG_INFO, "%s: buspirate_readline(): programmer is not responding\n", pmsg_error("programmer is not responding\n");
progname);
return NULL; return NULL;
} }
return ret; return ret;
@ -221,10 +218,10 @@ static int buspirate_send(const PROGRAMMER *pgm, const char *str) {
int rc; int rc;
const char * readline; const char * readline;
avrdude_message(MSG_DEBUG, "%s: buspirate_send(): %s", progname, str); pmsg_debug("buspirate_send(): %s", str);
if (PDATA(pgm)->flag & BP_FLAG_IN_BINMODE) { if (PDATA(pgm)->flag & BP_FLAG_IN_BINMODE) {
avrdude_message(MSG_INFO, "BusPirate: Internal error: buspirate_send() called from binmode\n"); pmsg_error("called from binmode\n");
return -1; return -1;
} }
@ -303,12 +300,12 @@ buspirate_parseextparms(const PROGRAMMER *pgm, const LISTID extparms) {
if (sscanf(extended_param, "spifreq=%u", &spifreq) == 1) { if (sscanf(extended_param, "spifreq=%u", &spifreq) == 1) {
if (spifreq & (~0x07)) { if (spifreq & (~0x07)) {
avrdude_message(MSG_INFO, "BusPirate: spifreq must be between 0 and 7.\n"); pmsg_error("spifreq must be between 0 and 7\n");
avrdude_message(MSG_INFO, "BusPirate: see BusPirate manual for details.\n"); imsg_error("see BusPirate manual for details\n");
return -1; return -1;
} }
if (PDATA(pgm)->flag & BP_FLAG_XPARM_RAWFREQ) { if (PDATA(pgm)->flag & BP_FLAG_XPARM_RAWFREQ) {
avrdude_message(MSG_INFO, "BusPirate: set either spifreq or rawfreq\n"); pmsg_error("set either spifreq or rawfreq\n");
return -1; return -1;
} }
PDATA(pgm)->flag |= BP_FLAG_XPARM_SPIFREQ; PDATA(pgm)->flag |= BP_FLAG_XPARM_SPIFREQ;
@ -318,12 +315,11 @@ buspirate_parseextparms(const PROGRAMMER *pgm, const LISTID extparms) {
if (sscanf(extended_param, "rawfreq=%u", &rawfreq) == 1) { if (sscanf(extended_param, "rawfreq=%u", &rawfreq) == 1) {
if (rawfreq >= 4) { if (rawfreq >= 4) {
avrdude_message(MSG_INFO, "BusPirate: rawfreq must be " pmsg_error("rawfreq must be between 0 and 3\n");
"between 0 and 3.\n");
return -1; return -1;
} }
if (PDATA(pgm)->flag & BP_FLAG_XPARM_SPIFREQ) { if (PDATA(pgm)->flag & BP_FLAG_XPARM_SPIFREQ) {
avrdude_message(MSG_INFO, "BusPirate: set either spifreq or rawfreq\n"); pmsg_error("set either spifreq or rawfreq\n");
return -1; return -1;
} }
PDATA(pgm)->flag |= BP_FLAG_XPARM_RAWFREQ; PDATA(pgm)->flag |= BP_FLAG_XPARM_RAWFREQ;
@ -334,8 +330,8 @@ buspirate_parseextparms(const PROGRAMMER *pgm, const LISTID extparms) {
if (sscanf(extended_param, "cpufreq=%u", &cpufreq) == 1) { if (sscanf(extended_param, "cpufreq=%u", &cpufreq) == 1) {
/* lower limit comes from 'cpufreq > 4 * spifreq', spifreq in ascii mode is 30kHz. */ /* lower limit comes from 'cpufreq > 4 * spifreq', spifreq in ascii mode is 30kHz. */
if (cpufreq < 125 || cpufreq > 4000) { if (cpufreq < 125 || cpufreq > 4000) {
avrdude_message(MSG_INFO, "BusPirate: cpufreq must be between 125 and 4000 kHz.\n"); pmsg_error("cpufreq must be between 125 and 4000 kHz\n");
avrdude_message(MSG_INFO, "BusPirate: see BusPirate manual for details.\n"); imsg_error("see BusPirate manual for details\n");
return -1; return -1;
} }
PDATA(pgm)->cpufreq = cpufreq; PDATA(pgm)->cpufreq = cpufreq;
@ -354,7 +350,7 @@ buspirate_parseextparms(const PROGRAMMER *pgm, const LISTID extparms) {
else if (strcasecmp(resetpin, "aux2") == 0) else if (strcasecmp(resetpin, "aux2") == 0)
PDATA(pgm)->reset |= BP_RESET_AUX2; PDATA(pgm)->reset |= BP_RESET_AUX2;
else { else {
avrdude_message(MSG_INFO, "BusPirate: reset must be either CS or AUX.\n"); pmsg_error("reset must be either CS or AUX\n");
return -1; return -1;
} }
} }
@ -374,14 +370,14 @@ buspirate_parseextparms(const PROGRAMMER *pgm, const LISTID extparms) {
if (sscanf(extended_param, "serial_recv_timeout=%d", &serial_recv_timeout) == 1) { if (sscanf(extended_param, "serial_recv_timeout=%d", &serial_recv_timeout) == 1) {
if (serial_recv_timeout < 1) { if (serial_recv_timeout < 1) {
avrdude_message(MSG_INFO, "BusPirate: serial_recv_timeout must be greater 0.\n"); pmsg_error("serial_recv_timeout must be greater 0\n");
return -1; return -1;
} }
PDATA(pgm)->serial_recv_timeout = serial_recv_timeout; PDATA(pgm)->serial_recv_timeout = serial_recv_timeout;
continue; continue;
} }
avrdude_message(MSG_INFO, "BusPirate: do not understand extended param '%s'.\n", extended_param); pmsg_error("do not understand extended param '%s'\n", extended_param);
return -1; return -1;
} }
@ -395,13 +391,13 @@ buspirate_verifyconfig(const PROGRAMMER *pgm) {
PDATA(pgm)->reset |= BP_RESET_CS; PDATA(pgm)->reset |= BP_RESET_CS;
if ((PDATA(pgm)->reset != BP_RESET_CS) && buspirate_uses_ascii(pgm)) { if ((PDATA(pgm)->reset != BP_RESET_CS) && buspirate_uses_ascii(pgm)) {
avrdude_message(MSG_INFO, "BusPirate: RESET pin other than CS is not supported in ASCII mode\n"); pmsg_error("RESET pin other than CS is not supported in ASCII mode\n");
return -1; return -1;
} }
if ( ((PDATA(pgm)->flag & BP_FLAG_XPARM_SPIFREQ) || (PDATA(pgm)->flag & BP_FLAG_XPARM_RAWFREQ)) if ( ((PDATA(pgm)->flag & BP_FLAG_XPARM_SPIFREQ) || (PDATA(pgm)->flag & BP_FLAG_XPARM_RAWFREQ))
&& buspirate_uses_ascii(pgm)) { && buspirate_uses_ascii(pgm)) {
avrdude_message(MSG_INFO, "BusPirate: SPI speed selection is not supported in ASCII mode\n"); pmsg_error("SPI speed selection is not supported in ASCII mode\n");
return -1; return -1;
} }
@ -444,13 +440,13 @@ static void buspirate_reset_from_binmode(const PROGRAMMER *pgm) {
if (PDATA(pgm)->flag & BP_FLAG_XPARM_CPUFREQ) { if (PDATA(pgm)->flag & BP_FLAG_XPARM_CPUFREQ) {
/* disable pwm */ /* disable pwm */
if (buspirate_expect_bin_byte(pgm, 0x13, 0x01) != 1) { if (buspirate_expect_bin_byte(pgm, 0x13, 0x01) != 1) {
avrdude_message(MSG_INFO, "%s: warning: did not get a response to stop PWM command.\n", progname); pmsg_error("did not get a response to stop PWM command\n");
} }
} }
/* 0b0100wxyz - Configure peripherals w=power, x=pull-ups, y=AUX, z=CS /* 0b0100wxyz - Configure peripherals w=power, x=pull-ups, y=AUX, z=CS
* we want everything off -- 0b01000000 = 0x40 */ * we want everything off -- 0b01000000 = 0x40 */
if (buspirate_expect_bin_byte(pgm, 0x40, 0x00) == 1) { if (buspirate_expect_bin_byte(pgm, 0x40, 0x00) == 1) {
avrdude_message(MSG_INFO, "%s: warning: did not get a response to power off command.\n", progname); pmsg_error("did not get a response to power off command\n");
} }
buf[0] = 0x0F; /* BinMode: reset */ buf[0] = 0x0F; /* BinMode: reset */
@ -472,11 +468,11 @@ static void buspirate_reset_from_binmode(const PROGRAMMER *pgm) {
} }
if (PDATA(pgm)->flag & BP_FLAG_IN_BINMODE) { if (PDATA(pgm)->flag & BP_FLAG_IN_BINMODE) {
avrdude_message(MSG_INFO, "BusPirate reset failed. You may need to powercycle it.\n"); pmsg_error("reset failed; you may need to powercycle it\n");
return; return;
} }
avrdude_message(MSG_NOTICE, "BusPirate is back in the text mode\n"); msg_notice("BusPirate is back in text mode\n");
} }
static int buspirate_start_mode_bin(PROGRAMMER *pgm) static int buspirate_start_mode_bin(PROGRAMMER *pgm)
@ -517,11 +513,11 @@ static int buspirate_start_mode_bin(PROGRAMMER *pgm)
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
buspirate_recv_bin(pgm, buf, 5); buspirate_recv_bin(pgm, buf, 5);
if (sscanf((const char*)buf, "BBIO%1d", &PDATA(pgm)->binmode_version) != 1) { if (sscanf((const char*)buf, "BBIO%1d", &PDATA(pgm)->binmode_version) != 1) {
avrdude_message(MSG_INFO, "Binary mode not confirmed: '%s'\n", buf); pmsg_error("binary mode not confirmed: '%s'\n", buf);
buspirate_reset_from_binmode(pgm); buspirate_reset_from_binmode(pgm);
return -1; return -1;
} }
avrdude_message(MSG_NOTICE, "BusPirate binmode version: %d\n", msg_notice("BusPirate binmode version: %d\n",
PDATA(pgm)->binmode_version); PDATA(pgm)->binmode_version);
PDATA(pgm)->flag |= BP_FLAG_IN_BINMODE; PDATA(pgm)->flag |= BP_FLAG_IN_BINMODE;
@ -533,8 +529,8 @@ static int buspirate_start_mode_bin(PROGRAMMER *pgm)
pwm_period = 16000/(PDATA(pgm)->cpufreq) - 1; // oscillator runs at 32MHz, we don't use a prescaler pwm_period = 16000/(PDATA(pgm)->cpufreq) - 1; // oscillator runs at 32MHz, we don't use a prescaler
pwm_duty = pwm_period/2; // 50% duty cycle pwm_duty = pwm_period/2; // 50% duty cycle
avrdude_message(MSG_NOTICE, "Setting up PWM for cpufreq\n"); msg_notice("setting up PWM for cpufreq\n");
avrdude_message(MSG_DEBUG, "PWM settings: Prescaler=1, Duty Cycle=%hd, Period=%hd\n", pwm_duty, pwm_period); msg_debug("PWM settings: Prescaler=1, Duty Cycle=%hd, Period=%hd\n", pwm_duty, pwm_period);
buf[0] = 0x12; // pwm setup buf[0] = 0x12; // pwm setup
buf[1] = 0; // prescaler 1 buf[1] = 0; // prescaler 1
@ -546,7 +542,7 @@ static int buspirate_start_mode_bin(PROGRAMMER *pgm)
buspirate_recv_bin(pgm, buf, 1); buspirate_recv_bin(pgm, buf, 1);
if (buf[0] != 0x01) if (buf[0] != 0x01)
avrdude_message(MSG_INFO, "cpufreq (PWM) setup failed\n"); pmsg_error("cpufreq (PWM) setup failed\n");
} }
/* == Set protocol sub-mode of binary mode == */ /* == Set protocol sub-mode of binary mode == */
@ -555,16 +551,14 @@ static int buspirate_start_mode_bin(PROGRAMMER *pgm)
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
buspirate_recv_bin(pgm, buf, 4); buspirate_recv_bin(pgm, buf, 4);
if (sscanf((const char*)buf, submode.entered_format, &PDATA(pgm)->submode_version) != 1) { if (sscanf((const char*)buf, submode.entered_format, &PDATA(pgm)->submode_version) != 1) {
avrdude_message(MSG_INFO, "%s mode not confirmed: '%s'\n", pmsg_error("%s mode not confirmed: '%s'\n", submode.name, buf);
submode.name, buf);
buspirate_reset_from_binmode(pgm); buspirate_reset_from_binmode(pgm);
return -1; return -1;
} }
avrdude_message(MSG_NOTICE, "BusPirate %s version: %d\n", msg_notice("BusPirate %s version: %d\n",
submode.name, PDATA(pgm)->submode_version); submode.name, PDATA(pgm)->submode_version);
if (PDATA(pgm)->flag & BP_FLAG_NOPAGEDWRITE) { if (PDATA(pgm)->flag & BP_FLAG_NOPAGEDWRITE) {
avrdude_message(MSG_NOTICE, "%s: Paged flash write disabled.\n", progname); pmsg_notice("paged flash write disabled\n");
pgm->paged_write = NULL; pgm->paged_write = NULL;
} else { } else {
/* Check for write-then-read without !CS/CS and disable paged_write if absent: */ /* Check for write-then-read without !CS/CS and disable paged_write if absent: */
@ -572,7 +566,6 @@ static int buspirate_start_mode_bin(PROGRAMMER *pgm)
buspirate_send_bin(pgm, buf2, sizeof(buf2)); buspirate_send_bin(pgm, buf2, sizeof(buf2));
buspirate_recv_bin(pgm, buf, 1); buspirate_recv_bin(pgm, buf, 1);
if (buf[0] != 0x01) { if (buf[0] != 0x01) {
/* Disable paged write: */ /* Disable paged write: */
PDATA(pgm)->flag |= BP_FLAG_NOPAGEDWRITE; PDATA(pgm)->flag |= BP_FLAG_NOPAGEDWRITE;
pgm->paged_write = NULL; pgm->paged_write = NULL;
@ -581,12 +574,12 @@ static int buspirate_start_mode_bin(PROGRAMMER *pgm)
buf[0] = 0x1; buf[0] = 0x1;
buspirate_send_bin(pgm, buf, 1); buspirate_send_bin(pgm, buf, 1);
avrdude_message(MSG_NOTICE, "%s: Disabling paged flash write. (Need BusPirate firmware >=v5.10.)\n", progname); pmsg_notice("disabling paged flash write (need BusPirate firmware >= v5.10)\n");
/* Flush serial buffer: */ /* Flush serial buffer: */
serial_drain(&pgm->fd, 0); serial_drain(&pgm->fd, 0);
} else { } else {
avrdude_message(MSG_INFO, "%s: Paged flash write enabled.\n", progname); pmsg_info("paged flash write enabled\n");
} }
} }
@ -607,7 +600,7 @@ static int buspirate_start_mode_bin(PROGRAMMER *pgm)
/* AVR Extended Commands - test for existence */ /* AVR Extended Commands - test for existence */
if (PDATA(pgm)->flag & BP_FLAG_NOPAGEDREAD) { if (PDATA(pgm)->flag & BP_FLAG_NOPAGEDREAD) {
avrdude_message(MSG_NOTICE, "%s: Paged flash read disabled.\n", progname); pmsg_notice("paged flash read disabled\n");
pgm->paged_load = NULL; pgm->paged_load = NULL;
} else { } else {
int rv = buspirate_expect_bin_byte(pgm, 0x06, 0x01); int rv = buspirate_expect_bin_byte(pgm, 0x06, 0x01);
@ -619,9 +612,9 @@ static int buspirate_start_mode_bin(PROGRAMMER *pgm)
buspirate_send_bin(pgm, buf2, sizeof(buf2)); buspirate_send_bin(pgm, buf2, sizeof(buf2));
buspirate_recv_bin(pgm, buf, 3); buspirate_recv_bin(pgm, buf, 3);
ver = buf[1] << 8 | buf[2]; ver = buf[1] << 8 | buf[2];
avrdude_message(MSG_NOTICE, "AVR Extended Commands version %d\n", ver); msg_notice("AVR Extended Commands version %d\n", ver);
} else { } else {
avrdude_message(MSG_NOTICE, "AVR Extended Commands not found.\n"); msg_notice("AVR Extended Commands not found\n");
PDATA(pgm)->flag |= BP_FLAG_NOPAGEDREAD; PDATA(pgm)->flag |= BP_FLAG_NOPAGEDREAD;
pgm->paged_load = NULL; pgm->paged_load = NULL;
} }
@ -651,10 +644,8 @@ static int buspirate_start_spi_mode_ascii(const PROGRAMMER *pgm) {
break; break;
} }
if (spi_cmd == -1) { if (spi_cmd == -1) {
avrdude_message(MSG_INFO, "%s: SPI mode number not found. Does your BusPirate support SPI?\n", pmsg_error("SPI mode number not found; does your BusPirate support SPI?\n");
progname); imsg_error("try powercycling your BusPirate and try again\n");
avrdude_message(MSG_INFO, "%s: Try powercycling your BusPirate and try again.\n",
progname);
return -1; return -1;
} }
snprintf(buf, sizeof(buf), "%d\n", spi_cmd); snprintf(buf, sizeof(buf), "%d\n", spi_cmd);
@ -674,7 +665,7 @@ static int buspirate_start_spi_mode_ascii(const PROGRAMMER *pgm) {
} }
if (buspirate_is_prompt(rcvd)) { if (buspirate_is_prompt(rcvd)) {
if (strncmp(rcvd, "SPI>", 4) == 0) { if (strncmp(rcvd, "SPI>", 4) == 0) {
avrdude_message(MSG_INFO, "BusPirate is now configured for SPI\n"); msg_info("BusPirate is now configured for SPI\n");
break; break;
} }
/* Not yet 'SPI>' prompt */ /* Not yet 'SPI>' prompt */
@ -700,7 +691,7 @@ static void buspirate_enable(PROGRAMMER *pgm, const AVRPART *p) {
/* Attempt to start binary SPI mode unless explicitly told otherwise: */ /* Attempt to start binary SPI mode unless explicitly told otherwise: */
if (!buspirate_uses_ascii(pgm)) { if (!buspirate_uses_ascii(pgm)) {
avrdude_message(MSG_INFO, "Attempting to initiate BusPirate binary mode...\n"); msg_info("attempting to initiate BusPirate binary mode ...\n");
/* Send two CRs to ensure we're not in a sub-menu of the UI if we're in ASCII mode: */ /* Send two CRs to ensure we're not in a sub-menu of the UI if we're in ASCII mode: */
buspirate_send_bin(pgm, (const unsigned char*)"\n\n", 2); buspirate_send_bin(pgm, (const unsigned char*)"\n\n", 2);
@ -712,23 +703,23 @@ static void buspirate_enable(PROGRAMMER *pgm, const AVRPART *p) {
if (buspirate_start_mode_bin(pgm) >= 0) if (buspirate_start_mode_bin(pgm) >= 0)
return; return;
else else
avrdude_message(MSG_INFO, "%s: Failed to start binary mode, falling back to ASCII...\n", progname); pmsg_info("unable to start binary mode, falling back to ASCII ...\n");
} }
avrdude_message(MSG_INFO, "Attempting to initiate BusPirate ASCII mode...\n"); msg_info("attempting to initiate BusPirate ASCII mode ...\n");
/* Call buspirate_send_bin() instead of buspirate_send() /* Call buspirate_send_bin() instead of buspirate_send()
* because we don't know if BP is in text or bin mode */ * because we don't know if BP is in text or bin mode */
rc = buspirate_send_bin(pgm, (const unsigned char*)reset_str, strlen(reset_str)); rc = buspirate_send_bin(pgm, (const unsigned char*)reset_str, strlen(reset_str));
if (rc) { if (rc) {
avrdude_message(MSG_INFO, "BusPirate is not responding. Serial port error: %d\n", rc); pmsg_error("BusPirate is not responding; serial port error code %d\n", rc);
return; return;
} }
while(1) { while(1) {
rcvd = buspirate_readline_noexit(pgm, NULL, 0); rcvd = buspirate_readline_noexit(pgm, NULL, 0);
if (! rcvd) { if (! rcvd) {
avrdude_message(MSG_INFO, "%s: Fatal: Programmer is not responding.\n", progname); pmsg_error("programmer is not responding\n");
return; return;
} }
if (strncmp(rcvd, "Are you sure?", 13) == 0) { if (strncmp(rcvd, "Are you sure?", 13) == 0) {
@ -739,17 +730,17 @@ static void buspirate_enable(PROGRAMMER *pgm, const AVRPART *p) {
continue; continue;
} }
if (buspirate_is_prompt(rcvd)) { if (buspirate_is_prompt(rcvd)) {
avrdude_message(MSG_DEBUG, "**\n"); msg_debug("**\n");
break; break;
} }
if (print_banner) if (print_banner)
avrdude_message(MSG_DEBUG, "** %s", rcvd); msg_debug("** %s", rcvd);
} }
if (!(PDATA(pgm)->flag & BP_FLAG_IN_BINMODE)) { if (!(PDATA(pgm)->flag & BP_FLAG_IN_BINMODE)) {
avrdude_message(MSG_INFO, "BusPirate: using ASCII mode\n"); msg_info("using ASCII mode\n");
if (buspirate_start_spi_mode_ascii(pgm) < 0) { if (buspirate_start_spi_mode_ascii(pgm) < 0) {
avrdude_message(MSG_INFO, "%s: Failed to start ascii SPI mode\n", progname); pmsg_error("unable to start ascii SPI mode\n");
return; return;
} }
} }
@ -788,15 +779,15 @@ static void buspirate_powerup(const PROGRAMMER *pgm) {
} }
} }
if(!ok) { if(!ok) {
avrdude_message(MSG_INFO, "%s: warning: did not get a response to start PWM command.\n", progname); pmsg_error("did not get a response to start PWM command\n");
} }
} }
return; return;
} }
} }
avrdude_message(MSG_INFO, "%s: warning: did not get a response to PowerUp command.\n", progname); pmsg_warning("did not get a response to PowerUp command\n");
avrdude_message(MSG_INFO, "%s: warning: Trying to continue anyway...\n", progname); imsg_warning("trying to continue anyway ...\n");
} }
static void buspirate_powerdown(const PROGRAMMER *pgm) { static void buspirate_powerdown(const PROGRAMMER *pgm) {
@ -806,14 +797,14 @@ static void buspirate_powerdown(const PROGRAMMER *pgm) {
} else { } else {
if (PDATA(pgm)->flag & BP_FLAG_XPARM_CPUFREQ) { if (PDATA(pgm)->flag & BP_FLAG_XPARM_CPUFREQ) {
if (!buspirate_expect(pgm, "g\n", "PWM disabled", 1)) { if (!buspirate_expect(pgm, "g\n", "PWM disabled", 1)) {
avrdude_message(MSG_INFO, "%s: warning: did not get a response to stop PWM command.\n", progname); pmsg_error("did not get a response to stop PWM command\n");
} }
} }
if (buspirate_expect(pgm, "w\n", "POWER SUPPLIES OFF", 1)) if (buspirate_expect(pgm, "w\n", "POWER SUPPLIES OFF", 1))
return; return;
} }
avrdude_message(MSG_INFO, "%s: warning: did not get a response to PowerDown command.\n", progname); pmsg_error("did not get a response to PowerDown command\n");
} }
static int buspirate_cmd_bin(const PROGRAMMER *pgm, static int buspirate_cmd_bin(const PROGRAMMER *pgm,
@ -860,7 +851,7 @@ static int buspirate_cmd_ascii(const PROGRAMMER *pgm,
} }
if (i != 4) { if (i != 4) {
avrdude_message(MSG_INFO, "%s: error: SPI has not read 4 bytes back\n", progname); pmsg_error("SPI has not read 4 bytes back\n");
return -1; return -1;
} }
@ -889,11 +880,11 @@ static int buspirate_paged_load(const PROGRAMMER *pgm, const AVRPART *p, const A
unsigned char buf[275]; unsigned char buf[275];
unsigned int addr = 0; unsigned int addr = 0;
avrdude_message(MSG_NOTICE, "BusPirate: buspirate_paged_load(..,%s,%d,%d,%d)\n",m->desc,m->page_size,address,n_bytes); msg_notice("buspirate_paged_load(..,%s,%d,%d,%d)\n",m->desc,m->page_size,address,n_bytes);
// This should never happen, but still... // This should never happen, but still ...
if (PDATA(pgm)->flag & BP_FLAG_NOPAGEDREAD) { if (PDATA(pgm)->flag & BP_FLAG_NOPAGEDREAD) {
avrdude_message(MSG_INFO, "BusPirate: buspirate_paged_load() called while in nopagedread mode!\n"); pmsg_error("called while in nopagedread mode\n");
return -1; return -1;
} }
@ -923,7 +914,7 @@ static int buspirate_paged_load(const PROGRAMMER *pgm, const AVRPART *p, const A
buspirate_recv_bin(pgm, buf, 1); buspirate_recv_bin(pgm, buf, 1);
if (buf[0] != 0x01) { if (buf[0] != 0x01) {
avrdude_message(MSG_INFO, "BusPirate: Paged Read command returned zero.\n"); pmsg_error("Paged Read command returned zero\n");
return -1; return -1;
} }
@ -966,13 +957,11 @@ static int buspirate_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const
/* pre-check opcodes */ /* pre-check opcodes */
if (m->op[AVR_OP_LOADPAGE_LO] == NULL) { if (m->op[AVR_OP_LOADPAGE_LO] == NULL) {
avrdude_message(MSG_INFO, "%s failure: %s command not defined for %s\n", pmsg_error("AVR_OP_LOADPAGE_LO command not defined for %s\n", p->desc);
progname, "AVR_OP_LOADPAGE_LO", p->desc);
return -1; return -1;
} }
if (m->op[AVR_OP_LOADPAGE_HI] == NULL) { if (m->op[AVR_OP_LOADPAGE_HI] == NULL) {
avrdude_message(MSG_INFO, "%s failure: %s command not defined for %s\n", pmsg_error("AVR_OP_LOADPAGE_HI command not defined for %s\n", p->desc);
progname, "AVR_OP_LOADPAGE_HI", p->desc);
return -1; return -1;
} }
@ -1032,7 +1021,7 @@ static int buspirate_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const
/* Check for write failure: */ /* Check for write failure: */
if ((buspirate_recv_bin(pgm, &recv_byte, 1) == EOF) || (recv_byte != 0x01)) { if ((buspirate_recv_bin(pgm, &recv_byte, 1) == EOF) || (recv_byte != 0x01)) {
avrdude_message(MSG_INFO, "BusPirate: Fatal error: Write Then Read did not succeed.\n"); pmsg_error("write then read did not succeed\n");
pgm->pgm_led(pgm, OFF); pgm->pgm_led(pgm, OFF);
pgm->err_led(pgm, ON); pgm->err_led(pgm, ON);
return -1; return -1;
@ -1062,8 +1051,7 @@ static int buspirate_program_enable(const PROGRAMMER *pgm, const AVRPART *p) {
buspirate_expect(pgm, "{\n", "CS ENABLED", 1); buspirate_expect(pgm, "{\n", "CS ENABLED", 1);
if (p->op[AVR_OP_PGM_ENABLE] == NULL) { if (p->op[AVR_OP_PGM_ENABLE] == NULL) {
avrdude_message(MSG_INFO, "program enable instruction not defined for part \"%s\"\n", pmsg_error("program enable instruction not defined for part %s\n", p->desc);
p->desc);
return -1; return -1;
} }
@ -1082,8 +1070,7 @@ static int buspirate_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) {
unsigned char res[4]; unsigned char res[4];
if (p->op[AVR_OP_CHIP_ERASE] == NULL) { if (p->op[AVR_OP_CHIP_ERASE] == NULL) {
avrdude_message(MSG_INFO, "chip erase instruction not defined for part \"%s\"\n", pmsg_error("chip erase instruction not defined for part %s\n", p->desc);
p->desc);
return -1; return -1;
} }
@ -1106,8 +1093,7 @@ static void buspirate_setup(PROGRAMMER *pgm)
{ {
/* Allocate private data */ /* Allocate private data */
if ((pgm->cookie = calloc(1, sizeof(struct pdata))) == 0) { if ((pgm->cookie = calloc(1, sizeof(struct pdata))) == 0) {
avrdude_message(MSG_INFO, "%s: buspirate_initpgm(): Out of memory allocating private data\n", pmsg_error("out of memory allocating private data\n");
progname);
exit(1); exit(1);
} }
PDATA(pgm)->serial_recv_timeout = 100; PDATA(pgm)->serial_recv_timeout = 100;
@ -1158,7 +1144,7 @@ static void buspirate_bb_enable(PROGRAMMER *pgm, const AVRPART *p) {
if (bitbang_check_prerequisites(pgm) < 0) if (bitbang_check_prerequisites(pgm) < 0)
return; /* XXX should treat as error */ return; /* XXX should treat as error */
avrdude_message(MSG_INFO, "Attempting to initiate BusPirate bitbang binary mode...\n"); pmsg_error("attempting to initiate BusPirate bitbang binary mode ...\n");
/* Send two CRs to ensure we're not in a sub-menu of the UI if we're in ASCII mode: */ /* Send two CRs to ensure we're not in a sub-menu of the UI if we're in ASCII mode: */
buspirate_send_bin(pgm, (const unsigned char*)"\n\n", 2); buspirate_send_bin(pgm, (const unsigned char*)"\n\n", 2);
@ -1173,12 +1159,11 @@ static void buspirate_bb_enable(PROGRAMMER *pgm, const AVRPART *p) {
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
buspirate_recv_bin(pgm, buf, 5); buspirate_recv_bin(pgm, buf, 5);
if (sscanf((char*)buf, "BBIO%1d", &PDATA(pgm)->binmode_version) != 1) { if (sscanf((char*)buf, "BBIO%1d", &PDATA(pgm)->binmode_version) != 1) {
avrdude_message(MSG_INFO, "Binary mode not confirmed: '%s'\n", buf); pmsg_error("binary mode not confirmed: '%s'\n", buf);
buspirate_reset_from_binmode(pgm); buspirate_reset_from_binmode(pgm);
return; return;
} }
avrdude_message(MSG_INFO, "BusPirate binmode version: %d\n", msg_info("BusPirate binmode version: %d\n", PDATA(pgm)->binmode_version);
PDATA(pgm)->binmode_version);
PDATA(pgm)->flag |= BP_FLAG_IN_BINMODE; PDATA(pgm)->flag |= BP_FLAG_IN_BINMODE;
@ -1241,7 +1226,7 @@ static int buspirate_bb_getpin(const PROGRAMMER *pgm, int pinfunc) {
if (buf[0] & (1 << (pin - 1))) if (buf[0] & (1 << (pin - 1)))
value ^= 1; value ^= 1;
avrdude_message(MSG_DEBUG, "get pin %d = %d\n", pin, value); msg_debug("get pin %d = %d\n", pin, value);
return value; return value;
} }
@ -1257,7 +1242,7 @@ static int buspirate_bb_setpin_internal(const PROGRAMMER *pgm, int pin, int valu
if ((pin < 1 || pin > 5) && (pin != 7)) // 7 is POWER if ((pin < 1 || pin > 5) && (pin != 7)) // 7 is POWER
return -1; return -1;
avrdude_message(MSG_DEBUG, "set pin %d = %d\n", pin, value); msg_debug("set pin %d = %d\n", pin, value);
if (value) if (value)
PDATA(pgm)->pin_val |= (1 << (pin - 1)); PDATA(pgm)->pin_val |= (1 << (pin - 1));

View File

@ -63,8 +63,7 @@ struct pdata
static void butterfly_setup(PROGRAMMER * pgm) static void butterfly_setup(PROGRAMMER * pgm)
{ {
if ((pgm->cookie = malloc(sizeof(struct pdata))) == 0) { if ((pgm->cookie = malloc(sizeof(struct pdata))) == 0) {
avrdude_message(MSG_INFO, "%s: butterfly_setup(): Out of memory allocating private data\n", pmsg_error("out of memory allocating private data\n");
progname);
exit(1); exit(1);
} }
memset(pgm->cookie, 0, sizeof(struct pdata)); memset(pgm->cookie, 0, sizeof(struct pdata));
@ -85,8 +84,7 @@ static int butterfly_recv(const PROGRAMMER *pgm, char *buf, size_t len) {
rv = serial_recv(&pgm->fd, (unsigned char *)buf, len); rv = serial_recv(&pgm->fd, (unsigned char *)buf, len);
if (rv < 0) { if (rv < 0) {
avrdude_message(MSG_INFO, "%s: butterfly_recv(): programmer is not responding\n", pmsg_error("programmer is not responding\n");
progname);
return -1; return -1;
} }
return 0; return 0;
@ -103,8 +101,7 @@ static int butterfly_vfy_cmd_sent(const PROGRAMMER *pgm, char *errmsg) {
butterfly_recv(pgm, &c, 1); butterfly_recv(pgm, &c, 1);
if (c != '\r') { if (c != '\r') {
avrdude_message(MSG_INFO, "%s: error: programmer did not respond to command: %s\n", pmsg_error("programmer did not respond to command: %s\n", errmsg);
progname, errmsg);
return -1; return -1;
} }
return 0; return 0;
@ -207,13 +204,13 @@ static int butterfly_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
* Send some ESC to activate butterfly bootloader. This is not needed * Send some ESC to activate butterfly bootloader. This is not needed
* for plain avr109 bootloaders but does not harm there either. * for plain avr109 bootloaders but does not harm there either.
*/ */
avrdude_message(MSG_INFO, "Connecting to programmer: "); msg_notice("connecting to programmer: ");
if (pgm->flag & IS_BUTTERFLY_MK) if (pgm->flag & IS_BUTTERFLY_MK)
{ {
char mk_reset_cmd[6] = {"#aR@S\r"}; char mk_reset_cmd[6] = {"#aR@S\r"};
unsigned char mk_timeout = 0; unsigned char mk_timeout = 0;
putc('.', stderr); msg_notice(".");
butterfly_send(pgm, mk_reset_cmd, sizeof(mk_reset_cmd)); butterfly_send(pgm, mk_reset_cmd, sizeof(mk_reset_cmd));
usleep(20000); usleep(20000);
@ -225,13 +222,15 @@ static int butterfly_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
c = 0xaa; c = 0xaa;
usleep(80000); usleep(80000);
butterfly_send(pgm, &c, 1); butterfly_send(pgm, &c, 1);
if (mk_timeout % 10 == 0) putc('.', stderr); if (mk_timeout % 10 == 0)
msg_notice(".");
} while (mk_timeout++ < 10); } while (mk_timeout++ < 10);
butterfly_recv(pgm, &c, 1); butterfly_recv(pgm, &c, 1);
if ( c != 'M' && c != '?') if ( c != 'M' && c != '?')
{ {
avrdude_message(MSG_INFO, "\nConnection FAILED."); msg_error("\n");
pmsg_error("connection failed");
return -1; return -1;
} }
else else
@ -242,13 +241,13 @@ static int butterfly_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
else else
{ {
do { do {
putc('.', stderr); msg_notice(".");
butterfly_send(pgm, "\033", 1); butterfly_send(pgm, "\033", 1);
butterfly_drain(pgm, 0); butterfly_drain(pgm, 0);
butterfly_send(pgm, "S", 1); butterfly_send(pgm, "S", 1);
butterfly_recv(pgm, &c, 1); butterfly_recv(pgm, &c, 1);
if (c != '?') { if (c != '?') {
putc('\n', stderr); msg_notice("\n");
/* /*
* Got a useful response, continue getting the programmer * Got a useful response, continue getting the programmer
* identifier. Programmer returns exactly 7 chars _without_ * identifier. Programmer returns exactly 7 chars _without_
@ -278,12 +277,12 @@ static int butterfly_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
butterfly_send(pgm, "p", 1); butterfly_send(pgm, "p", 1);
butterfly_recv(pgm, &type, 1); butterfly_recv(pgm, &type, 1);
avrdude_message(MSG_INFO, "Found programmer: Id = \"%s\"; type = %c\n", id, type); msg_notice("Programmer id = %s; type = %c\n", id, type);
avrdude_message(MSG_INFO, " Software Version = %c.%c; ", sw[0], sw[1]); msg_notice("Software version = %c.%c; ", sw[0], sw[1]);
if (hw[0]=='?') { if (hw[0]=='?') {
avrdude_message(MSG_INFO, "No Hardware Version given.\n"); msg_notice("no hardware version given\n");
} else { } else {
avrdude_message(MSG_INFO, "Hardware Version = %c.%c\n", hw[0], hw[1]); msg_notice("Hardware version = %c.%c\n", hw[0], hw[1]);
}; };
/* See if programmer supports autoincrement of address. */ /* See if programmer supports autoincrement of address. */
@ -291,28 +290,28 @@ static int butterfly_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
butterfly_send(pgm, "a", 1); butterfly_send(pgm, "a", 1);
butterfly_recv(pgm, &PDATA(pgm)->has_auto_incr_addr, 1); butterfly_recv(pgm, &PDATA(pgm)->has_auto_incr_addr, 1);
if (PDATA(pgm)->has_auto_incr_addr == 'Y') if (PDATA(pgm)->has_auto_incr_addr == 'Y')
avrdude_message(MSG_INFO, "Programmer supports auto addr increment.\n"); msg_notice("programmer supports auto addr increment\n");
/* Check support for buffered memory access, abort if not available */ /* Check support for buffered memory access, abort if not available */
butterfly_send(pgm, "b", 1); butterfly_send(pgm, "b", 1);
butterfly_recv(pgm, &c, 1); butterfly_recv(pgm, &c, 1);
if (c != 'Y') { if (c != 'Y') {
avrdude_message(MSG_INFO, "%s: error: buffered memory access not supported. Maybe it isn't\n"\ pmsg_notice("buffered memory access not supported; maybe it isn't\n"\
"a butterfly/AVR109 but a AVR910 device?\n", progname); "a butterfly/AVR109 but a AVR910 device?\n");
return -1; return -1;
}; };
butterfly_recv(pgm, &c, 1); butterfly_recv(pgm, &c, 1);
PDATA(pgm)->buffersize = (unsigned int)(unsigned char)c<<8; PDATA(pgm)->buffersize = (unsigned int)(unsigned char)c<<8;
butterfly_recv(pgm, &c, 1); butterfly_recv(pgm, &c, 1);
PDATA(pgm)->buffersize += (unsigned int)(unsigned char)c; PDATA(pgm)->buffersize += (unsigned int)(unsigned char)c;
avrdude_message(MSG_INFO, "Programmer supports buffered memory access with buffersize=%i bytes.\n", msg_notice("programmer supports buffered memory access with buffersize=%i bytes\n",
PDATA(pgm)->buffersize); PDATA(pgm)->buffersize);
/* Get list of devices that the programmer supports. */ /* Get list of devices that the programmer supports. */
butterfly_send(pgm, "t", 1); butterfly_send(pgm, "t", 1);
avrdude_message(MSG_INFO, "\nProgrammer supports the following devices:\n"); msg_notice2("\nProgrammer supports the following devices:\n");
devtype_1st = 0; devtype_1st = 0;
while (1) { while (1) {
butterfly_recv(pgm, &c, 1); butterfly_recv(pgm, &c, 1);
@ -321,9 +320,9 @@ static int butterfly_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
if (c == 0) if (c == 0)
break; break;
avrdude_message(MSG_INFO, " Device code: 0x%02x\n", (unsigned int)(unsigned char)c); msg_notice2(" Device code: 0x%02x\n", (unsigned int) (unsigned char) c);
}; };
avrdude_message(MSG_INFO, "\n"); msg_notice2("\n");
/* Tell the programmer which part we selected. /* Tell the programmer which part we selected.
According to the AVR109 code, this is ignored by the bootloader. As According to the AVR109 code, this is ignored by the bootloader. As
@ -340,9 +339,7 @@ static int butterfly_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
if (butterfly_vfy_cmd_sent(pgm, "select device") < 0) if (butterfly_vfy_cmd_sent(pgm, "select device") < 0)
return -1; return -1;
if (verbose) pmsg_notice("devcode selected: 0x%02x\n", (unsigned) buf[1]);
avrdude_message(MSG_INFO, "%s: devcode selected: 0x%02x\n",
progname, (unsigned)buf[1]);
butterfly_enter_prog_mode(pgm); butterfly_enter_prog_mode(pgm);
butterfly_drain(pgm, 0); butterfly_drain(pgm, 0);
@ -545,8 +542,7 @@ static int butterfly_page_erase(const PROGRAMMER *pgm, const AVRPART *p, const A
return -1; /* not supported */ return -1; /* not supported */
if (strcmp(m->desc, "eeprom") == 0) if (strcmp(m->desc, "eeprom") == 0)
return 0; /* nothing to do */ return 0; /* nothing to do */
avrdude_message(MSG_INFO, "%s: butterfly_page_erase() called on memory type \"%s\"\n", pmsg_warning("called on memory type %s\n", m->desc);
progname, m->desc);
return -1; return -1;
} }
@ -697,7 +693,7 @@ static int butterfly_read_sig_bytes(const PROGRAMMER *pgm, const AVRPART *p, con
unsigned char tmp; unsigned char tmp;
if (m->size < 3) { if (m->size < 3) {
avrdude_message(MSG_INFO, "%s: memsize too small for sig byte read", progname); pmsg_error("memsize too small for sig byte read");
return -1; return -1;
} }

View File

@ -105,7 +105,7 @@ int init_config(void)
void *cfg_malloc(const char *funcname, size_t n) { void *cfg_malloc(const char *funcname, size_t n) {
void *ret = malloc(n); void *ret = malloc(n);
if(!ret) { if(!ret) {
avrdude_message(MSG_INFO, "%s: out of memory in %s (needed %lu bytes)\n", progname, funcname, (unsigned long) n); pmsg_error("out of memory in %s (needed %lu bytes)\n", funcname, (unsigned long) n);
exit(1); exit(1);
} }
memset(ret, 0, n); memset(ret, 0, n);
@ -116,7 +116,7 @@ void *cfg_realloc(const char *funcname, void *p, size_t n) {
void *ret; void *ret;
if(!(ret = p? realloc(p, n): calloc(1, n))) { if(!(ret = p? realloc(p, n): calloc(1, n))) {
avrdude_message(MSG_INFO, "%s: out of memory in %s (needed %lu bytes)\n", progname, funcname, (unsigned long) n); pmsg_error("out of memory in %s (needed %lu bytes)\n", funcname, (unsigned long) n);
exit(1); exit(1);
} }
@ -127,7 +127,7 @@ void *cfg_realloc(const char *funcname, void *p, size_t n) {
char *cfg_strdup(const char *funcname, const char *s) { char *cfg_strdup(const char *funcname, const char *s) {
char *ret = strdup(s); char *ret = strdup(s);
if(!ret) { if(!ret) {
avrdude_message(MSG_INFO, "%s: out of memory in %s\n", progname, funcname); pmsg_error("out of memory in %s\n", funcname);
exit(1); exit(1);
} }
return ret; return ret;
@ -149,7 +149,7 @@ int yyerror(char * errmsg, ...)
va_start(args, errmsg); va_start(args, errmsg);
vsnprintf(message, sizeof(message), errmsg, args); vsnprintf(message, sizeof(message), errmsg, args);
avrdude_message(MSG_INFO, "%s: error at %s:%d: %s\n", progname, cfg_infile, cfg_lineno, message); pmsg_error("%s [%s:%d]\n", message, cfg_infile, cfg_lineno);
va_end(args); va_end(args);
@ -166,7 +166,7 @@ int yywarning(char * errmsg, ...)
va_start(args, errmsg); va_start(args, errmsg);
vsnprintf(message, sizeof(message), errmsg, args); vsnprintf(message, sizeof(message), errmsg, args);
avrdude_message(MSG_INFO, "%s: warning at %s:%d: %s\n", progname, cfg_infile, cfg_lineno, message); pmsg_warning("%s [%s:%d]\n", message, cfg_infile, cfg_lineno);
va_end(args); va_end(args);
@ -218,7 +218,7 @@ TOKEN *new_number(const char *text) {
tkn->value.number = atoi(text); tkn->value.number = atoi(text);
#if DEBUG #if DEBUG
avrdude_message(MSG_INFO, "NUMBER(%d)\n", tkn->value.number); msg_info("NUMBER(%d)\n", tkn->value.number);
#endif #endif
return tkn; return tkn;
@ -230,7 +230,7 @@ TOKEN *new_number_real(const char *text) {
tkn->value.number_real = atof(text); tkn->value.number_real = atof(text);
#if DEBUG #if DEBUG
avrdude_message(MSG_INFO, "NUMBER(%g)\n", tkn->value.number_real); msg_info("NUMBER(%g)\n", tkn->value.number_real);
#endif #endif
return tkn; return tkn;
@ -243,13 +243,13 @@ TOKEN *new_hexnumber(const char *text) {
tkn->value.type = V_NUM; tkn->value.type = V_NUM;
tkn->value.number = strtoul(text, &e, 16); tkn->value.number = strtoul(text, &e, 16);
if ((e == text) || (*e != 0)) { if ((e == text) || (*e != 0)) {
yyerror("can't scan hex number \"%s\"", text); yyerror("cannot scan hex number %s", text);
free_token(tkn); free_token(tkn);
return NULL; return NULL;
} }
#if DEBUG #if DEBUG
avrdude_message(MSG_INFO, "HEXNUMBER(%g)\n", tkn->value.number); msg_info("HEXNUMBER(%d)\n", tkn->value.number);
#endif #endif
return tkn; return tkn;
@ -283,7 +283,7 @@ TOKEN *new_constant(const char *con) {
} }
#if DEBUG #if DEBUG
avrdude_message(MSG_INFO, "CONSTANT(%s=%d)\n", con, tkn->value.number); msg_info("CONSTANT(%s=%d)\n", con, tkn->value.number);
#endif #endif
return tkn; return tkn;
@ -295,7 +295,7 @@ TOKEN *new_string(const char *text) {
tkn->value.string = cfg_strdup("new_string()", text); tkn->value.string = cfg_strdup("new_string()", text);
#if DEBUG #if DEBUG
avrdude_message(MSG_INFO, "STRING(%s)\n", tkn->value.string); msg_info("STRING(%s)\n", tkn->value.string);
#endif #endif
return tkn; return tkn;
@ -312,33 +312,33 @@ void print_token(TOKEN * tkn)
if (!tkn) if (!tkn)
return; return;
avrdude_message(MSG_INFO, "token = %d = ", tkn->primary); msg_info("token = %d = ", tkn->primary);
switch (tkn->value.type) { switch (tkn->value.type) {
case V_NUM: case V_NUM:
avrdude_message(MSG_INFO, "NUMBER, value=%d", tkn->value.number); msg_info("NUMBER, value=%d", tkn->value.number);
break; break;
case V_NUM_REAL: case V_NUM_REAL:
avrdude_message(MSG_INFO, "NUMBER, value=%g", tkn->value.number_real); msg_info("NUMBER, value=%g", tkn->value.number_real);
break; break;
case V_STR: case V_STR:
avrdude_message(MSG_INFO, "STRING, value=%s", tkn->value.string); msg_info("STRING, value=%s", tkn->value.string);
break; break;
default: default:
avrdude_message(MSG_INFO, "<other>"); msg_info("<other>");
break; break;
} }
avrdude_message(MSG_INFO, "\n"); msg_info("\n");
} }
void pyytext(void) void pyytext(void)
{ {
#if DEBUG #if DEBUG
avrdude_message(MSG_INFO, "TOKEN: \"%s\"\n", yytext); msg_info("TOKEN: %s\n", yytext);
#endif #endif
} }
@ -354,15 +354,13 @@ int read_config(const char * file)
int r; int r;
if(!(cfg_infile = realpath(file, NULL))) { if(!(cfg_infile = realpath(file, NULL))) {
avrdude_message(MSG_INFO, "%s: can't determine realpath() of config file \"%s\": %s\n", pmsg_ext_error("cannot determine realpath() of config file %s: %s\n", file, strerror(errno));
progname, file, strerror(errno));
return -1; return -1;
} }
f = fopen(cfg_infile, "r"); f = fopen(cfg_infile, "r");
if (f == NULL) { if (f == NULL) {
avrdude_message(MSG_INFO, "%s: can't open config file \"%s\": %s\n", pmsg_ext_error("cannot open config file %s: %s\n", cfg_infile, strerror(errno));
progname, cfg_infile, strerror(errno));
free(cfg_infile); free(cfg_infile);
cfg_infile = NULL; cfg_infile = NULL;
return -1; return -1;

View File

@ -1410,9 +1410,7 @@ mem_spec :
{ {
int ps = $3->value.number; int ps = $3->value.number;
if (ps <= 0) if (ps <= 0)
avrdude_message(MSG_INFO, pmsg_warning("invalid page size %d, ignored [%s:%d]\n", ps, cfg_infile, cfg_lineno);
"%s, line %d: invalid page size %d, ignored\n",
cfg_infile, cfg_lineno, ps);
else else
current_mem->page_size = ps; current_mem->page_size = ps;
free_token($3); free_token($3);
@ -1755,7 +1753,7 @@ static int parse_cmdbits(OPCODE * op, int opnum)
op->bit[bitno].value = 0; op->bit[bitno].value = 0;
} }
else { else {
yyerror("invalid bit specifier \"%s\"", s); yyerror("invalid bit specifier %s", s);
rv = -1; rv = -1;
break; break;
} }

View File

@ -528,7 +528,7 @@ static int avrpart_deep_copy(AVRPARTdeep *d, const AVRPART *p) {
m = p->mem? avr_locate_mem_noalias(p, avr_mem_order[mi]): NULL; m = p->mem? avr_locate_mem_noalias(p, avr_mem_order[mi]): NULL;
if(m) { if(m) {
if(di >= sizeof d->mems/sizeof *d->mems) { if(di >= sizeof d->mems/sizeof *d->mems) {
avrdude_message(MSG_INFO, "%s: ran out of mems[] space, increase size in AVRMEMdeep of developer_opts.c and recompile\n", progname); pmsg_error("ran out of mems[] space, increase size in AVRMEMdeep of developer_opts.c and recompile\n");
exit(1); exit(1);
} }
avrmem_deep_copy(d->mems+di, m); avrmem_deep_copy(d->mems+di, m);
@ -615,7 +615,7 @@ static void dev_part_strct(const AVRPART *p, bool tsv, const AVRPART *base, bool
dev_print_comment(cp->comms); dev_print_comment(cp->comms);
if(p->parent_id && *p->parent_id) if(p->parent_id && *p->parent_id)
dev_info("part parent \"%s\"\n", p->parent_id); dev_info("part parent %s\n", p->parent_id);
else else
dev_info("part\n"); dev_info("part\n");
} }

107
src/dfu.c
View File

@ -39,8 +39,7 @@
#ifndef HAVE_LIBUSB #ifndef HAVE_LIBUSB
struct dfu_dev *dfu_open(const char *port_name) { struct dfu_dev *dfu_open(const char *port_name) {
avrdude_message(MSG_INFO, "%s: Error: No USB support in this compile of avrdude\n", pmsg_error("no USB support compiled for avrdude\n");
progname);
return NULL; return NULL;
} }
@ -111,16 +110,14 @@ struct dfu_dev *dfu_open(const char *port_spec) {
*/ */
if (strncmp(port_spec, "usb", 3) != 0) { if (strncmp(port_spec, "usb", 3) != 0) {
avrdude_message(MSG_INFO, "%s: Error: " pmsg_error("invalid port specification %s for USB device\n", port_spec);
"Invalid port specification \"%s\" for USB device\n",
progname, port_spec);
return NULL; return NULL;
} }
if(':' == port_spec[3]) { if(':' == port_spec[3]) {
bus_name = strdup(port_spec + 3 + 1); bus_name = strdup(port_spec + 3 + 1);
if (bus_name == NULL) { if (bus_name == NULL) {
avrdude_message(MSG_INFO, "%s: Out of memory in strdup\n", progname); pmsg_error("out of memory in strdup\n");
return NULL; return NULL;
} }
@ -137,7 +134,7 @@ struct dfu_dev *dfu_open(const char *port_spec) {
if (dfu == NULL) if (dfu == NULL)
{ {
avrdude_message(MSG_INFO, "%s: out of memory\n", progname); pmsg_error("out of memory\n");
free(bus_name); free(bus_name);
return NULL; return NULL;
} }
@ -171,9 +168,7 @@ int dfu_init(struct dfu_dev *dfu, unsigned short vid, unsigned short pid)
*/ */
if (pid == 0 && dfu->dev_name == NULL) { if (pid == 0 && dfu->dev_name == NULL) {
avrdude_message(MSG_INFO, "%s: Error: No DFU support for part; " pmsg_error("no DFU support for part; specify PID in config or USB address (via -P) to override\n");
"specify PID in config or USB address (via -P) to override.\n",
progname);
return -1; return -1;
} }
@ -208,20 +203,18 @@ int dfu_init(struct dfu_dev *dfu, unsigned short vid, unsigned short pid)
* why the match failed, and if we came across another DFU-capable part. * why the match failed, and if we came across another DFU-capable part.
*/ */
avrdude_message(MSG_INFO, "%s: Error: No matching USB device found\n", progname); pmsg_error("no matching USB device found\n");
return -1; return -1;
} }
if(verbose) pmsg_notice("found VID=0x%04x PID=0x%04x at %s:%s\n",
avrdude_message(MSG_INFO, "%s: Found VID=0x%04x PID=0x%04x at %s:%s\n", found->descriptor.idVendor, found->descriptor.idProduct,
progname, found->descriptor.idVendor, found->descriptor.idProduct, found->bus->dirname, found->filename);
found->bus->dirname, found->filename);
dfu->dev_handle = usb_open(found); dfu->dev_handle = usb_open(found);
if (dfu->dev_handle == NULL) { if (dfu->dev_handle == NULL) {
avrdude_message(MSG_INFO, "%s: Error: USB device at %s:%s: %s\n", pmsg_error("USB device at %s:%s: %s\n", found->bus->dirname, found->filename, usb_strerror());
progname, found->bus->dirname, found->filename, usb_strerror());
return -1; return -1;
} }
@ -271,37 +264,32 @@ int dfu_getstatus(struct dfu_dev *dfu, struct dfu_status *status)
{ {
int result; int result;
avrdude_message(MSG_TRACE, "%s: dfu_getstatus(): issuing control IN message\n", pmsg_trace("dfu_getstatus(): issuing control IN message\n");
progname);
result = usb_control_msg(dfu->dev_handle, result = usb_control_msg(dfu->dev_handle,
0x80 | USB_TYPE_CLASS | USB_RECIP_INTERFACE, DFU_GETSTATUS, 0, 0, 0x80 | USB_TYPE_CLASS | USB_RECIP_INTERFACE, DFU_GETSTATUS, 0, 0,
(char*) status, sizeof(struct dfu_status), dfu->timeout); (char*) status, sizeof(struct dfu_status), dfu->timeout);
if (result < 0) { if (result < 0) {
avrdude_message(MSG_INFO, "%s: Error: Failed to get DFU status: %s\n", pmsg_error("unable to get DFU status: %s\n", usb_strerror());
progname, usb_strerror());
return -1; return -1;
} }
if (result < sizeof(struct dfu_status)) { if (result < sizeof(struct dfu_status)) {
avrdude_message(MSG_INFO, "%s: Error: Failed to get DFU status: %s\n", pmsg_error("unable to get DFU status: %s\n", "short read");
progname, "short read");
return -1; return -1;
} }
if (result > sizeof(struct dfu_status)) { if (result > sizeof(struct dfu_status)) {
avrdude_message(MSG_INFO, "%s: Error: Oversize read (should not happen); " pmsg_error("oversize read (should not happen); exiting\n");
"exiting\n", progname);
exit(1); exit(1);
} }
avrdude_message(MSG_TRACE, "%s: dfu_getstatus(): bStatus 0x%02x, bwPollTimeout %d, bState 0x%02x, iString %d\n", pmsg_trace("dfu_getstatus(): bStatus 0x%02x, bwPollTimeout %d, bState 0x%02x, iString %d\n",
progname, status->bStatus,
status->bStatus, status->bwPollTimeout[0] | (status->bwPollTimeout[1] << 8) | (status->bwPollTimeout[2] << 16),
status->bwPollTimeout[0] | (status->bwPollTimeout[1] << 8) | (status->bwPollTimeout[2] << 16), status->bState,
status->bState, status->iString);
status->iString);
return 0; return 0;
} }
@ -310,16 +298,14 @@ int dfu_clrstatus(struct dfu_dev *dfu)
{ {
int result; int result;
avrdude_message(MSG_TRACE, "%s: dfu_clrstatus(): issuing control OUT message\n", pmsg_trace("dfu_clrstatus(): issuing control OUT message\n");
progname);
result = usb_control_msg(dfu->dev_handle, result = usb_control_msg(dfu->dev_handle,
USB_TYPE_CLASS | USB_RECIP_INTERFACE, DFU_CLRSTATUS, 0, 0, USB_TYPE_CLASS | USB_RECIP_INTERFACE, DFU_CLRSTATUS, 0, 0,
NULL, 0, dfu->timeout); NULL, 0, dfu->timeout);
if (result < 0) { if (result < 0) {
avrdude_message(MSG_INFO, "%s: Error: Failed to clear DFU status: %s\n", pmsg_error("unable to clear DFU status: %s\n", usb_strerror());
progname, usb_strerror());
return -1; return -1;
} }
@ -330,16 +316,14 @@ int dfu_abort(struct dfu_dev *dfu)
{ {
int result; int result;
avrdude_message(MSG_TRACE, "%s: dfu_abort(): issuing control OUT message\n", pmsg_trace("dfu_abort(): issuing control OUT message\n");
progname);
result = usb_control_msg(dfu->dev_handle, result = usb_control_msg(dfu->dev_handle,
USB_TYPE_CLASS | USB_RECIP_INTERFACE, DFU_ABORT, 0, 0, USB_TYPE_CLASS | USB_RECIP_INTERFACE, DFU_ABORT, 0, 0,
NULL, 0, dfu->timeout); NULL, 0, dfu->timeout);
if (result < 0) { if (result < 0) {
avrdude_message(MSG_INFO, "%s: Error: Failed to reset DFU state: %s\n", pmsg_error("unable to reset DFU state: %s\n", usb_strerror());
progname, usb_strerror());
return -1; return -1;
} }
@ -351,29 +335,26 @@ int dfu_dnload(struct dfu_dev *dfu, void *ptr, int size)
{ {
int result; int result;
avrdude_message(MSG_TRACE, "%s: dfu_dnload(): issuing control OUT message, wIndex = %d, ptr = %p, size = %d\n", pmsg_trace("dfu_dnload(): issuing control OUT message, wIndex = %d, ptr = %p, size = %d\n",
progname, wIndex, ptr, size); wIndex, ptr, size);
result = usb_control_msg(dfu->dev_handle, result = usb_control_msg(dfu->dev_handle,
USB_TYPE_CLASS | USB_RECIP_INTERFACE, DFU_DNLOAD, wIndex++, 0, USB_TYPE_CLASS | USB_RECIP_INTERFACE, DFU_DNLOAD, wIndex++, 0,
ptr, size, dfu->timeout); ptr, size, dfu->timeout);
if (result < 0) { if (result < 0) {
avrdude_message(MSG_INFO, "%s: Error: DFU_DNLOAD failed: %s\n", pmsg_error("DFU_DNLOAD failed: %s\n", usb_strerror());
progname, usb_strerror());
return -1; return -1;
} }
if (result < size) { if (result < size) {
avrdude_message(MSG_INFO, "%s: Error: DFU_DNLOAD failed: %s\n", pmsg_error("DFU_DNLOAD failed: short write\n");
progname, "short write");
return -1; return -1;
} }
if (result > size) { if (result > size) {
avrdude_message(MSG_INFO, "%s: Error: Oversize write (should not happen); " \ pmsg_error("DFU_DNLOAD failed: oversize write (should not happen)\n");
"exiting\n", progname); return -1;
exit(1);
} }
return 0; return 0;
@ -383,28 +364,25 @@ int dfu_upload(struct dfu_dev *dfu, void *ptr, int size)
{ {
int result; int result;
avrdude_message(MSG_TRACE, "%s: dfu_upload(): issuing control IN message, wIndex = %d, ptr = %p, size = %d\n", pmsg_trace("dfu_upload(): issuing control IN message, wIndex = %d, ptr = %p, size = %d\n",
progname, wIndex, ptr, size); wIndex, ptr, size);
result = usb_control_msg(dfu->dev_handle, result = usb_control_msg(dfu->dev_handle,
0x80 | USB_TYPE_CLASS | USB_RECIP_INTERFACE, DFU_UPLOAD, wIndex++, 0, 0x80 | USB_TYPE_CLASS | USB_RECIP_INTERFACE, DFU_UPLOAD, wIndex++, 0,
ptr, size, dfu->timeout); ptr, size, dfu->timeout);
if (result < 0) { if (result < 0) {
avrdude_message(MSG_INFO, "%s: Error: DFU_UPLOAD failed: %s\n", pmsg_error("DFU_UPLOAD failed: %s\n", usb_strerror());
progname, usb_strerror());
return -1; return -1;
} }
if (result < size) { if (result < size) {
avrdude_message(MSG_INFO, "%s: Error: DFU_UPLOAD failed: %s\n", pmsg_error("DFU_UPLOAD failed: %s\n", "short read");
progname, "short read");
return -1; return -1;
} }
if (result > size) { if (result > size) {
avrdude_message(MSG_INFO, "%s: Error: Oversize read (should not happen); " pmsg_error("oversize read (should not happen); exiting\n");
"exiting\n", progname);
exit(1); exit(1);
} }
@ -414,26 +392,26 @@ int dfu_upload(struct dfu_dev *dfu, void *ptr, int size)
void dfu_show_info(struct dfu_dev *dfu) void dfu_show_info(struct dfu_dev *dfu)
{ {
if (dfu->manf_str != NULL) if (dfu->manf_str != NULL)
avrdude_message(MSG_INFO, " USB Vendor : %s (0x%04hX)\n", msg_info(" USB Vendor : %s (0x%04hX)\n",
dfu->manf_str, (unsigned short) dfu->dev_desc.idVendor); dfu->manf_str, (unsigned short) dfu->dev_desc.idVendor);
else else
avrdude_message(MSG_INFO, " USB Vendor : 0x%04hX\n", msg_info(" USB Vendor : 0x%04hX\n",
(unsigned short) dfu->dev_desc.idVendor); (unsigned short) dfu->dev_desc.idVendor);
if (dfu->prod_str != NULL) if (dfu->prod_str != NULL)
avrdude_message(MSG_INFO, " USB Product : %s (0x%04hX)\n", msg_info(" USB Product : %s (0x%04hX)\n",
dfu->prod_str, (unsigned short) dfu->dev_desc.idProduct); dfu->prod_str, (unsigned short) dfu->dev_desc.idProduct);
else else
avrdude_message(MSG_INFO, " USB Product : 0x%04hX\n", msg_info(" USB Product : 0x%04hX\n",
(unsigned short) dfu->dev_desc.idProduct); (unsigned short) dfu->dev_desc.idProduct);
avrdude_message(MSG_INFO, " USB Release : %hu.%hu.%hu\n", msg_info(" USB Release : %hu.%hu.%hu\n",
((unsigned short) dfu->dev_desc.bcdDevice >> 8) & 0xFF, ((unsigned short) dfu->dev_desc.bcdDevice >> 8) & 0xFF,
((unsigned short) dfu->dev_desc.bcdDevice >> 4) & 0xF, ((unsigned short) dfu->dev_desc.bcdDevice >> 4) & 0xF,
((unsigned short) dfu->dev_desc.bcdDevice >> 0) & 0xF); ((unsigned short) dfu->dev_desc.bcdDevice >> 0) & 0xF);
if (dfu->serno_str != NULL) if (dfu->serno_str != NULL)
avrdude_message(MSG_INFO, " USB Serial No : %s\n", dfu->serno_str); msg_info(" USB Serial No : %s\n", dfu->serno_str);
} }
/* INTERNAL FUNCTION DEFINITIONS /* INTERNAL FUNCTION DEFINITIONS
@ -450,15 +428,14 @@ char * get_usb_string(usb_dev_handle * dev_handle, int index) {
result = usb_get_string_simple(dev_handle, index, buffer, sizeof(buffer)-1); result = usb_get_string_simple(dev_handle, index, buffer, sizeof(buffer)-1);
if (result < 0) { if (result < 0) {
avrdude_message(MSG_INFO, "%s: Warning: Failed to read USB device string %d: %s\n", pmsg_error("unable to read USB device string %d: %s\n", index, usb_strerror());
progname, index, usb_strerror());
return NULL; return NULL;
} }
str = malloc(result+1); str = malloc(result+1);
if (str == NULL) { if (str == NULL) {
avrdude_message(MSG_INFO, "%s: Out of memory allocating a string\n", progname); pmsg_error("out of memory allocating a string\n");
return 0; return 0;
} }

View File

@ -126,8 +126,7 @@ static int b2ihex(unsigned char * inbuf, int bufsize,
unsigned char cksum; unsigned char cksum;
if (recsize > 255) { if (recsize > 255) {
avrdude_message(MSG_INFO, "%s: recsize=%d, must be < 256\n", pmsg_error("recsize=%d, must be < 256\n", recsize);
progname, recsize);
return -1; return -1;
} }
@ -319,36 +318,31 @@ static int ihex2b(char * infile, FILE * inf,
continue; continue;
rc = ihex_readrec(&ihex, buffer); rc = ihex_readrec(&ihex, buffer);
if (rc < 0) { if (rc < 0) {
avrdude_message(MSG_INFO, "%s: invalid record at line %d of \"%s\"\n", pmsg_error("invalid record at line %d of %s\n", lineno, infile);
progname, lineno, infile);
return -1; return -1;
} }
else if (rc != ihex.cksum) { else if (rc != ihex.cksum) {
if(ffmt == FMT_IHEX) { if(ffmt == FMT_IHEX) {
avrdude_message(MSG_INFO, "%s: ERROR: checksum mismatch at line %d of \"%s\"\n", pmsg_error("checksum mismatch at line %d of %s\n", lineno, infile);
progname, lineno, infile); imsg_error("checksum=0x%02x, computed checksum=0x%02x\n", ihex.cksum, rc);
avrdude_message(MSG_INFO, "%s: checksum=0x%02x, computed checksum=0x%02x\n",
progname, ihex.cksum, rc);
return -1; return -1;
} else { /* Just warn with more permissive format FMT_IHXC */ } else { /* Just warn with more permissive format FMT_IHXC */
avrdude_message(MSG_NOTICE, "%s: warning: checksum mismatch at line %d of \"%s\"\n", pmsg_notice("checksum mismatch at line %d of %s\n", lineno, infile);
progname, lineno, infile); imsg_notice("checksum=0x%02x, computed checksum=0x%02x\n", ihex.cksum, rc);
avrdude_message(MSG_NOTICE, "%s: checksum=0x%02x, computed checksum=0x%02x\n",
progname, ihex.cksum, rc);
} }
} }
switch (ihex.rectyp) { switch (ihex.rectyp) {
case 0: /* data record */ case 0: /* data record */
if (fileoffset != 0 && baseaddr < fileoffset) { if (fileoffset != 0 && baseaddr < fileoffset) {
avrdude_message(MSG_INFO, "%s: ERROR: address 0x%04x out of range (below fileoffset 0x%x) at line %d of %s\n", pmsg_error("address 0x%04x out of range (below fileoffset 0x%x) at line %d of %s\n",
progname, baseaddr, fileoffset, lineno, infile); baseaddr, fileoffset, lineno, infile);
return -1; return -1;
} }
nextaddr = ihex.loadofs + baseaddr - fileoffset; nextaddr = ihex.loadofs + baseaddr - fileoffset;
if (nextaddr + ihex.reclen > (unsigned) bufsize) { if (nextaddr + ihex.reclen > (unsigned) bufsize) {
avrdude_message(MSG_INFO, "%s: ERROR: address 0x%04x out of range at line %d of %s\n", pmsg_error("address 0x%04x out of range at line %d of %s\n",
progname, nextaddr+ihex.reclen, lineno, infile); nextaddr+ihex.reclen, lineno, infile);
return -1; return -1;
} }
for (i=0; i<ihex.reclen; i++) { for (i=0; i<ihex.reclen; i++) {
@ -380,9 +374,8 @@ static int ihex2b(char * infile, FILE * inf,
break; break;
default: default:
avrdude_message(MSG_INFO, "%s: don't know how to deal with rectype=%d " pmsg_error("do not know how to deal with rectype=%d "
"at line %d of %s\n", "at line %d of %s\n", ihex.rectyp, lineno, infile);
progname, ihex.rectyp, lineno, infile);
return -1; return -1;
break; break;
} }
@ -390,16 +383,12 @@ static int ihex2b(char * infile, FILE * inf,
} /* while */ } /* while */
if (maxaddr == 0) { if (maxaddr == 0) {
avrdude_message(MSG_INFO, "%s: ERROR: No valid record found in Intel Hex " pmsg_error("no valid record found in Intel Hex file %s\n", infile);
"file \"%s\"\n",
progname, infile);
return -1; return -1;
} }
else { else {
avrdude_message(MSG_INFO, "%s: WARNING: no end of file record found for Intel Hex " pmsg_warning("no end of file record found for Intel Hex file %s\n", infile);
"file \"%s\"\n",
progname, infile);
return maxaddr; return maxaddr;
} }
@ -417,8 +406,7 @@ static int b2srec(unsigned char * inbuf, int bufsize,
char * tmpl=0; char * tmpl=0;
if (recsize > 255) { if (recsize > 255) {
avrdude_message(MSG_INFO, "%s: ERROR: recsize=%d, must be < 256\n", pmsg_error("recsize=%d, must be < 256\n", recsize);
progname, recsize);
return -1; return -1;
} }
@ -450,8 +438,7 @@ static int b2srec(unsigned char * inbuf, int bufsize,
tmpl="S3%02X%08X"; tmpl="S3%02X%08X";
} }
else { else {
avrdude_message(MSG_INFO, "%s: ERROR: address=%d, out of range\n", pmsg_error("address=%d, out of range\n", nextaddr);
progname, nextaddr);
return -1; return -1;
} }
@ -599,7 +586,7 @@ static int srec2b(char * infile, FILE * inf,
unsigned int reccount; unsigned int reccount;
unsigned char datarec; unsigned char datarec;
char * msg = 0; char * msg = "";
lineno = 0; lineno = 0;
maxaddr = 0; maxaddr = 0;
@ -615,15 +602,12 @@ static int srec2b(char * infile, FILE * inf,
rc = srec_readrec(&srec, buffer); rc = srec_readrec(&srec, buffer);
if (rc < 0) { if (rc < 0) {
avrdude_message(MSG_INFO, "%s: ERROR: invalid record at line %d of \"%s\"\n", pmsg_error("invalid record at line %d of %s\n", lineno, infile);
progname, lineno, infile);
return -1; return -1;
} }
else if (rc != srec.cksum) { else if (rc != srec.cksum) {
avrdude_message(MSG_INFO, "%s: ERROR: checksum mismatch at line %d of \"%s\"\n", pmsg_error("checksum mismatch at line %d of %s\n", lineno, infile);
progname, lineno, infile); imsg_error("checksum=0x%02x, computed checksum=0x%02x\n", srec.cksum, rc);
avrdude_message(MSG_INFO, "%s: checksum=0x%02x, computed checksum=0x%02x\n",
progname, srec.cksum, rc);
return -1; return -1;
} }
@ -635,32 +619,27 @@ static int srec2b(char * infile, FILE * inf,
case 0x31: /* S1 - 16 bit address data record */ case 0x31: /* S1 - 16 bit address data record */
datarec=1; datarec=1;
msg="%s: ERROR: address 0x%04x out of range %sat line %d of %s\n"; msg="address 0x%04x out of range %sat line %d of %s\n";
break; break;
case 0x32: /* S2 - 24 bit address data record */ case 0x32: /* S2 - 24 bit address data record */
datarec=1; datarec=1;
msg="%s: ERROR: address 0x%06x out of range %sat line %d of %s\n"; msg="address 0x%06x out of range %sat line %d of %s\n";
break; break;
case 0x33: /* S3 - 32 bit address data record */ case 0x33: /* S3 - 32 bit address data record */
datarec=1; datarec=1;
msg="%s: ERROR: address 0x%08x out of range %sat line %d of %s\n"; msg="address 0x%08x out of range %sat line %d of %s\n";
break; break;
case 0x34: /* S4 - symbol record (LSI extension) */ case 0x34: /* S4 - symbol record (LSI extension) */
avrdude_message(MSG_INFO, "%s: ERROR: not supported record at line %d of %s\n", pmsg_error("not supported record at line %d of %s\n", lineno, infile);
progname, lineno, infile);
return -1; return -1;
case 0x35: /* S5 - count of S1,S2 and S3 records previously tx'd */ case 0x35: /* S5 - count of S1,S2 and S3 records previously tx'd */
if (srec.loadofs != reccount){ if (srec.loadofs != reccount){
avrdude_message(MSG_INFO, "%s: ERROR: count of transmitted data records mismatch " pmsg_error("count of transmitted data records mismatch at line %d of %s\n", lineno, infile);
"at line %d of \"%s\"\n", imsg_error("transmitted data records= %d, expected value= %d\n", reccount, srec.loadofs);
progname, lineno, infile);
avrdude_message(MSG_INFO, "%s: transmitted data records= %d, expected "
"value= %d\n",
progname, reccount, srec.loadofs);
return -1; return -1;
} }
break; break;
@ -671,24 +650,20 @@ static int srec2b(char * infile, FILE * inf,
return maxaddr; return maxaddr;
default: default:
avrdude_message(MSG_INFO, "%s: ERROR: don't know how to deal with rectype S%d " pmsg_error("do not know how to deal with rectype S%d at line %d of %s\n",
"at line %d of %s\n", srec.rectyp, lineno, infile);
progname, srec.rectyp, lineno, infile);
return -1; return -1;
} }
if (datarec == 1) { if (datarec == 1) {
nextaddr = srec.loadofs; nextaddr = srec.loadofs;
if (nextaddr < fileoffset) { if (nextaddr < fileoffset) {
avrdude_message(MSG_INFO, msg, progname, nextaddr, pmsg_error(msg, nextaddr, "(below fileoffset) ", lineno, infile);
"(below fileoffset) ",
lineno, infile);
return -1; return -1;
} }
nextaddr -= fileoffset; nextaddr -= fileoffset;
if (nextaddr + srec.reclen > (unsigned) bufsize) { if (nextaddr + srec.reclen > (unsigned) bufsize) {
avrdude_message(MSG_INFO, msg, progname, nextaddr+srec.reclen, "", pmsg_error(msg, nextaddr+srec.reclen, "", lineno, infile);
lineno, infile);
return -1; return -1;
} }
for (i=0; i<srec.reclen; i++) { for (i=0; i<srec.reclen; i++) {
@ -702,9 +677,7 @@ static int srec2b(char * infile, FILE * inf,
} }
avrdude_message(MSG_INFO, "%s: WARNING: no end of file record found for Motorola S-Records " pmsg_warning("no end of file record found for Motorola S-Records file %s\n", infile);
"file \"%s\"\n",
progname, infile);
return maxaddr; return maxaddr;
} }
@ -747,8 +720,7 @@ static Elf_Scn *elf_get_scn(Elf *e, Elf32_Phdr *ph, Elf32_Shdr **shptr)
Elf32_Shdr *sh; Elf32_Shdr *sh;
size_t ndx = elf_ndxscn(s); size_t ndx = elf_ndxscn(s);
if ((sh = elf32_getshdr(s)) == NULL) { if ((sh = elf32_getshdr(s)) == NULL) {
avrdude_message(MSG_INFO, "%s: ERROR: Error reading section #%u header: %s\n", pmsg_error("unable to read section #%u header: %s\n", (unsigned int)ndx, elf_errmsg(-1));
progname, (unsigned int)ndx, elf_errmsg(-1));
continue; continue;
} }
if ((sh->sh_flags & SHF_ALLOC) == 0 || if ((sh->sh_flags & SHF_ALLOC) == 0 ||
@ -765,9 +737,7 @@ static Elf_Scn *elf_get_scn(Elf *e, Elf32_Phdr *ph, Elf32_Shdr **shptr)
} }
} }
avrdude_message(MSG_INFO, "%s: ERROR: Cannot find a matching section for " pmsg_error("cannot find a matching section for program header entry @p_vaddr 0x%x\n", ph->p_vaddr);
"program header entry @p_vaddr 0x%x\n",
progname, ph->p_vaddr);
return NULL; return NULL;
} }
@ -838,8 +808,7 @@ static int elf2b(char * infile, FILE * inf,
unsigned int low, high, foff; unsigned int low, high, foff;
if (elf_mem_limits(mem, p, &low, &high, &foff) != 0) { if (elf_mem_limits(mem, p, &low, &high, &foff) != 0) {
avrdude_message(MSG_INFO, "%s: ERROR: Cannot handle \"%s\" memory region from ELF file\n", pmsg_error("cannot handle %s memory region from ELF file\n", mem->desc);
progname, mem->desc);
return -1; return -1;
} }
@ -856,9 +825,7 @@ static int elf2b(char * infile, FILE * inf,
strcmp(mem->desc, "apptable") == 0)) { strcmp(mem->desc, "apptable") == 0)) {
AVRMEM *flashmem = avr_locate_mem(p, "flash"); AVRMEM *flashmem = avr_locate_mem(p, "flash");
if (flashmem == NULL) { if (flashmem == NULL) {
avrdude_message(MSG_INFO, "%s: ERROR: No \"flash\" memory region found, " pmsg_error("no flash memory region found, cannot compute bounds of %s sub-region\n", mem->desc);
"cannot compute bounds of \"%s\" sub-region.\n",
progname, mem->desc);
return -1; return -1;
} }
/* The config file offsets are PDI offsets, rebase to 0. */ /* The config file offsets are PDI offsets, rebase to 0. */
@ -867,18 +834,15 @@ static int elf2b(char * infile, FILE * inf,
} }
if (elf_version(EV_CURRENT) == EV_NONE) { if (elf_version(EV_CURRENT) == EV_NONE) {
avrdude_message(MSG_INFO, "%s: ERROR: ELF library initialization failed: %s\n", pmsg_error("ELF library initialization failed: %s\n", elf_errmsg(-1));
progname, elf_errmsg(-1));
return -1; return -1;
} }
if ((e = elf_begin(fileno(inf), ELF_C_READ, NULL)) == NULL) { if ((e = elf_begin(fileno(inf), ELF_C_READ, NULL)) == NULL) {
avrdude_message(MSG_INFO, "%s: ERROR: Cannot open \"%s\" as an ELF file: %s\n", pmsg_error("cannot open %s as an ELF file: %s\n", infile, elf_errmsg(-1));
progname, infile, elf_errmsg(-1));
return -1; return -1;
} }
if (elf_kind(e) != ELF_K_ELF) { if (elf_kind(e) != ELF_K_ELF) {
avrdude_message(MSG_INFO, "%s: ERROR: Cannot use \"%s\" as an ELF input file\n", pmsg_error("cannot use %s as an ELF input file\n", infile);
progname, infile);
goto done; goto done;
} }
@ -886,8 +850,7 @@ static int elf2b(char * infile, FILE * inf,
const char *id = elf_getident(e, &isize); const char *id = elf_getident(e, &isize);
if (id == NULL) { if (id == NULL) {
avrdude_message(MSG_INFO, "%s: ERROR: Error reading ident area of \"%s\": %s\n", pmsg_error("unable to read ident area of %s: %s\n", infile, elf_errmsg(-1));
progname, infile, elf_errmsg(-1));
goto done; goto done;
} }
@ -902,22 +865,19 @@ static int elf2b(char * infile, FILE * inf,
} }
if (id[EI_CLASS] != ELFCLASS32 || if (id[EI_CLASS] != ELFCLASS32 ||
id[EI_DATA] != endianess) { id[EI_DATA] != endianess) {
avrdude_message(MSG_INFO, "%s: ERROR: ELF file \"%s\" is not a " pmsg_error("ELF file %s is not a 32-bit, %s-endian file that was expected\n",
"32-bit, %s-endian file that was expected\n", infile, endianname);
progname, infile, endianname);
goto done; goto done;
} }
Elf32_Ehdr *eh; Elf32_Ehdr *eh;
if ((eh = elf32_getehdr(e)) == NULL) { if ((eh = elf32_getehdr(e)) == NULL) {
avrdude_message(MSG_INFO, "%s: ERROR: Error reading ehdr of \"%s\": %s\n", pmsg_error("unable to read ehdr of %s: %s\n", infile, elf_errmsg(-1));
progname, infile, elf_errmsg(-1));
goto done; goto done;
} }
if (eh->e_type != ET_EXEC) { if (eh->e_type != ET_EXEC) {
avrdude_message(MSG_INFO, "%s: ERROR: ELF file \"%s\" is not an executable file\n", pmsg_error("ELF file %s is not an executable file\n", infile);
progname, infile);
goto done; goto done;
} }
@ -931,28 +891,23 @@ static int elf2b(char * infile, FILE * inf,
mname = "AVR"; mname = "AVR";
} }
if (eh->e_machine != machine) { if (eh->e_machine != machine) {
avrdude_message(MSG_INFO, "%s: ERROR: ELF file \"%s\" is not for machine %s\n", pmsg_error("ELF file %s is not for machine %s\n", infile, mname);
progname, infile, mname);
goto done; goto done;
} }
if (eh->e_phnum == 0xffff /* PN_XNUM */) { if (eh->e_phnum == 0xffff /* PN_XNUM */) {
avrdude_message(MSG_INFO, "%s: ERROR: ELF file \"%s\" uses extended " pmsg_error("ELF file %s uses extended program header numbers which are not expected\n", infile);
"program header numbers which are not expected\n",
progname, infile);
goto done; goto done;
} }
Elf32_Phdr *ph; Elf32_Phdr *ph;
if ((ph = elf32_getphdr(e)) == NULL) { if ((ph = elf32_getphdr(e)) == NULL) {
avrdude_message(MSG_INFO, "%s: ERROR: Error reading program header table of \"%s\": %s\n", pmsg_error("unable to read program header table of %s: %s\n", infile, elf_errmsg(-1));
progname, infile, elf_errmsg(-1));
goto done; goto done;
} }
size_t sndx; size_t sndx;
if (elf_getshdrstrndx(e, &sndx) != 0) { if (elf_getshdrstrndx(e, &sndx) != 0) {
avrdude_message(MSG_INFO, "%s: ERROR: Error obtaining section name string table: %s\n", pmsg_error("unable to obtain section name string table: %s\n", elf_errmsg(-1));
progname, elf_errmsg(-1));
sndx = 0; sndx = 0;
} }
@ -965,9 +920,8 @@ static int elf2b(char * infile, FILE * inf,
ph[i].p_filesz == 0) ph[i].p_filesz == 0)
continue; continue;
avrdude_message(MSG_NOTICE2, "%s: Considering PT_LOAD program header entry #%d:\n" pmsg_notice2("considering PT_LOAD program header entry #%d:\n"
" p_vaddr 0x%x, p_paddr 0x%x, p_filesz %d\n", " p_vaddr 0x%x, p_paddr 0x%x, p_filesz %d\n", (int) i, ph[i].p_vaddr, ph[i].p_paddr, ph[i].p_filesz);
progname, i, ph[i].p_vaddr, ph[i].p_paddr, ph[i].p_filesz);
Elf32_Shdr *sh; Elf32_Shdr *sh;
Elf_Scn *s = elf_get_scn(e, ph + i, &sh); Elf_Scn *s = elf_get_scn(e, ph + i, &sh);
@ -986,15 +940,13 @@ static int elf2b(char * infile, FILE * inf,
unsigned int lma; unsigned int lma;
lma = ph[i].p_paddr + sh->sh_offset - ph[i].p_offset; lma = ph[i].p_paddr + sh->sh_offset - ph[i].p_offset;
avrdude_message(MSG_NOTICE2, "%s: Found section \"%s\", LMA 0x%x, sh_size %u\n", pmsg_notice2("found section %s, LMA 0x%x, sh_size %u\n", sname, lma, sh->sh_size);
progname, sname, lma, sh->sh_size);
if (lma >= low && if (lma >= low &&
lma + sh->sh_size < high) { lma + sh->sh_size < high) {
/* OK */ /* OK */
} else { } else {
avrdude_message(MSG_NOTICE2, " => skipping, inappropriate for \"%s\" memory region\n", msg_notice2(" => skipping, inappropriate for %s memory region\n", mem->desc);
mem->desc);
continue; continue;
} }
/* /*
@ -1006,26 +958,22 @@ static int elf2b(char * infile, FILE * inf,
* from it, using the "foff" offset obtained above. * from it, using the "foff" offset obtained above.
*/ */
if (mem->size != 1 && sh->sh_size > (unsigned) mem->size) { if (mem->size != 1 && sh->sh_size > (unsigned) mem->size) {
avrdude_message(MSG_INFO, "%s: ERROR: section \"%s\" does not fit into \"%s\" memory:\n" pmsg_error("section %s does not fit into %s memory:\n"
" 0x%x + %u > %u\n", " 0x%x + %u > %u\n", sname, mem->desc, lma, sh->sh_size, mem->size);
progname, sname, mem->desc,
lma, sh->sh_size, mem->size);
continue; continue;
} }
Elf_Data *d = NULL; Elf_Data *d = NULL;
while ((d = elf_getdata(s, d)) != NULL) { while ((d = elf_getdata(s, d)) != NULL) {
avrdude_message(MSG_NOTICE2, " Data block: d_buf %p, d_off 0x%x, d_size %d\n", msg_notice2(" Data block: d_buf %p, d_off 0x%x, d_size %ld\n",
d->d_buf, (unsigned int)d->d_off, d->d_size); d->d_buf, (unsigned int)d->d_off, (long) d->d_size);
if (mem->size == 1) { if (mem->size == 1) {
if (d->d_off != 0) { if (d->d_off != 0) {
avrdude_message(MSG_INFO, "%s: ERROR: unexpected data block at offset != 0\n", pmsg_error("unexpected data block at offset != 0\n");
progname);
} else if (foff >= d->d_size) { } else if (foff >= d->d_size) {
avrdude_message(MSG_INFO, "%s: ERROR: ELF file section does not contain byte at offset %d\n", pmsg_error("ELF file section does not contain byte at offset %d\n", foff);
progname, foff);
} else { } else {
avrdude_message(MSG_NOTICE2, " Extracting one byte from file offset %d\n", msg_notice2(" Extracting one byte from file offset %d\n",
foff); foff);
mem->buf[0] = ((unsigned char *)d->d_buf)[foff]; mem->buf[0] = ((unsigned char *)d->d_buf)[foff];
mem->tags[0] = TAG_ALLOCATED; mem->tags[0] = TAG_ALLOCATED;
@ -1037,8 +985,8 @@ static int elf2b(char * infile, FILE * inf,
idx = lma - low + d->d_off; idx = lma - low + d->d_off;
if ((int)(idx + d->d_size) > rv) if ((int)(idx + d->d_size) > rv)
rv = idx + d->d_size; rv = idx + d->d_size;
avrdude_message(MSG_DEBUG, " Writing %d bytes to mem offset 0x%x\n", msg_debug(" Writing %ld bytes to mem offset 0x%x\n",
d->d_size, idx); (long) d->d_size, idx);
memcpy(mem->buf + idx, d->d_buf, d->d_size); memcpy(mem->buf + idx, d->d_buf, d->d_size);
memset(mem->tags + idx, TAG_ALLOCATED, d->d_size); memset(mem->tags + idx, TAG_ALLOCATED, d->d_size);
} }
@ -1107,15 +1055,13 @@ static int fileio_rbin(struct fioparms * fio,
rc = fwrite(buf, 1, size, f); rc = fwrite(buf, 1, size, f);
break; break;
default: default:
avrdude_message(MSG_INFO, "%s: fileio: invalid operation=%d\n", pmsg_error("invalid fileio operation=%d\n", fio->op);
progname, fio->op);
return -1; return -1;
} }
if (rc < 0 || (fio->op == FIO_WRITE && rc < size)) { if (rc < 0 || (fio->op == FIO_WRITE && rc < size)) {
avrdude_message(MSG_INFO, "%s: %s error %s %s: %s; %s %d of the expected %d bytes\n", pmsg_ext_error("%s error %s %s: %s; %s %d of the expected %d bytes\n",
progname, fio->iodesc, fio->dir, filename, strerror(errno), fio->iodesc, fio->dir, filename, strerror(errno), fio->rw, rc, size);
fio->rw, rc, size);
return -1; return -1;
} }
@ -1142,8 +1088,7 @@ static int fileio_imm(struct fioparms * fio,
strtoul (p, &e, 0): strtoul (p, &e, 0):
strtoul (p + 2, &e, 2); strtoul (p + 2, &e, 2);
if (*e != 0) { if (*e != 0) {
avrdude_message(MSG_INFO, "%s: invalid byte value (%s) specified for immediate mode\n", pmsg_error("invalid byte value (%s) specified for immediate mode\n", p);
progname, p);
return -1; return -1;
} }
mem->buf[loc] = b; mem->buf[loc] = b;
@ -1154,21 +1099,17 @@ static int fileio_imm(struct fioparms * fio,
break; break;
case FIO_WRITE: case FIO_WRITE:
avrdude_message(MSG_INFO, pmsg_error("invalid file format 'immediate' for output\n");
"%s: Invalid file format 'immediate' for output\n",
progname);
return -1; return -1;
default: default:
avrdude_message(MSG_INFO, "%s: fileio: invalid operation=%d\n", pmsg_error("invalid operation=%d\n", fio->op);
progname, fio->op);
return -1; return -1;
} }
if (rc < 0 || (fio->op == FIO_WRITE && rc < size)) { if (rc < 0 || (fio->op == FIO_WRITE && rc < size)) {
avrdude_message(MSG_INFO, "%s: %s error %s %s: %s; %s %d of the expected %d bytes\n", pmsg_ext_error("%s error %s %s: %s; %s %d of the expected %d bytes\n",
progname, fio->iodesc, fio->dir, filename, strerror(errno), fio->iodesc, fio->dir, filename, strerror(errno), fio->rw, rc, size);
fio->rw, rc, size);
return -1; return -1;
} }
@ -1197,8 +1138,7 @@ static int fileio_ihex(struct fioparms * fio,
break; break;
default: default:
avrdude_message(MSG_INFO, "%s: invalid Intel Hex file I/O operation=%d\n", pmsg_error("invalid Intel Hex file I/O operation=%d\n", fio->op);
progname, fio->op);
return -1; return -1;
break; break;
} }
@ -1227,9 +1167,7 @@ static int fileio_srec(struct fioparms * fio,
break; break;
default: default:
avrdude_message(MSG_INFO, "%s: ERROR: invalid Motorola S-Records file I/O " pmsg_error("invalid Motorola S-Records file I/O operation=%d\n", fio->op);
"operation=%d\n",
progname, fio->op);
return -1; return -1;
break; break;
} }
@ -1247,9 +1185,7 @@ static int fileio_elf(struct fioparms * fio,
switch (fio->op) { switch (fio->op) {
case FIO_WRITE: case FIO_WRITE:
avrdude_message(MSG_INFO, "%s: ERROR: write operation not (yet) " pmsg_error("write operation not supported for ELF\n");
"supported for ELF\n",
progname);
return -1; return -1;
break; break;
@ -1258,9 +1194,7 @@ static int fileio_elf(struct fioparms * fio,
return rc; return rc;
default: default:
avrdude_message(MSG_INFO, "%s: ERROR: invalid ELF file I/O " pmsg_error("invalid ELF file I/O operation=%d\n", fio->op);
"operation=%d\n",
progname, fio->op);
return -1; return -1;
break; break;
} }
@ -1310,14 +1244,11 @@ static int fileio_num(struct fioparms * fio,
break; break;
case FIO_READ: case FIO_READ:
avrdude_message(MSG_INFO, pmsg_error("invalid file format '%s' for input\n", name);
"%s: Invalid file format '%s' for input\n",
progname, name);
return -1; return -1;
default: default:
avrdude_message(MSG_INFO, "%s: fileio: invalid operation=%d\n", pmsg_error("invalid operation=%d\n", fio->op);
progname, fio->op);
return -1; return -1;
} }
@ -1346,8 +1277,7 @@ static int fileio_num(struct fioparms * fio,
return 0; return 0;
writeerr: writeerr:
avrdude_message(MSG_INFO, "%s: error writing to %s: %s\n", pmsg_ext_error("unable to write to %s: %s\n", filename, strerror(errno));
progname, filename, strerror(errno));
return -1; return -1;
} }
@ -1373,8 +1303,7 @@ int fileio_setparms(int op, struct fioparms * fp,
break; break;
default: default:
avrdude_message(MSG_INFO, "%s: invalid I/O operation %d\n", pmsg_error("invalid I/O operation %d\n", op);
progname, op);
return -1; return -1;
break; break;
} }
@ -1405,8 +1334,7 @@ int fileio_fmt_autodetect(const char * fname)
f = fopen(fname, "rb"); f = fopen(fname, "rb");
#endif #endif
if (f == NULL) { if (f == NULL) {
avrdude_message(MSG_INFO, "%s: error opening %s: %s\n", pmsg_ext_error("unable to open %s: %s\n", fname, strerror(errno));
progname, fname, strerror(errno));
return -1; return -1;
} }
@ -1489,8 +1417,7 @@ int fileio(int oprwv, char * filename, FILEFMT format,
op = oprwv == FIO_READ_FOR_VERIFY? FIO_READ: oprwv; op = oprwv == FIO_READ_FOR_VERIFY? FIO_READ: oprwv;
mem = avr_locate_mem(p, memtype); mem = avr_locate_mem(p, memtype);
if (mem == NULL) { if (mem == NULL) {
avrdude_message(MSG_INFO, "fileio(): memory type \"%s\" not configured for device \"%s\"\n", pmsg_error("memory type %s not configured for device %s\n", memtype, p->desc);
memtype, p->desc);
return -1; return -1;
} }
@ -1529,24 +1456,21 @@ int fileio(int oprwv, char * filename, FILEFMT format,
int format_detect; int format_detect;
if (using_stdio) { if (using_stdio) {
avrdude_message(MSG_INFO, "%s: can't auto detect file format when using stdin/out.\n" pmsg_error("cannot auto detect file format when using stdin/out\n");
"%s Please specify a file format and try again.\n", imsg_error("please specify a file format and try again\n");
progname, progbuf);
return -1; return -1;
} }
format_detect = fileio_fmt_autodetect(fname); format_detect = fileio_fmt_autodetect(fname);
if (format_detect < 0) { if (format_detect < 0) {
avrdude_message(MSG_INFO, "%s: can't determine file format for %s, specify explicitly\n", pmsg_error("cannot determine file format for %s, specify explicitly\n", fname);
progname, fname);
return -1; return -1;
} }
format = format_detect; format = format_detect;
if (quell_progress < 2) { if (quell_progress < 2)
avrdude_message(MSG_NOTICE, "%s: %s file %s auto detected as %s\n", pmsg_notice("%s file %s auto detected as %s\n",
progname, fio.iodesc, fname, fileio_fmtstr(format)); fio.iodesc, fname, fileio_fmtstr(format));
}
} }
#if defined(WIN32) #if defined(WIN32)
@ -1568,8 +1492,7 @@ int fileio(int oprwv, char * filename, FILEFMT format,
if (!using_stdio) { if (!using_stdio) {
f = fopen(fname, fio.mode); f = fopen(fname, fio.mode);
if (f == NULL) { if (f == NULL) {
avrdude_message(MSG_INFO, "%s: can't open %s file %s: %s\n", pmsg_ext_error("cannot open %s file %s: %s\n", fio.iodesc, fname, strerror(errno));
progname, fio.iodesc, fname, strerror(errno));
return -1; return -1;
} }
} }
@ -1593,9 +1516,7 @@ int fileio(int oprwv, char * filename, FILEFMT format,
#ifdef HAVE_LIBELF #ifdef HAVE_LIBELF
rc = fileio_elf(&fio, fname, f, mem, p, size); rc = fileio_elf(&fio, fname, f, mem, p, size);
#else #else
avrdude_message(MSG_INFO, "%s: can't handle ELF file %s, " pmsg_error("cannot handle ELF file %s, ELF file support was not compiled in\n", fname);
"ELF file support was not compiled in\n",
progname, fname);
rc = -1; rc = -1;
#endif #endif
break; break;
@ -1612,8 +1533,7 @@ int fileio(int oprwv, char * filename, FILEFMT format,
break; break;
default: default:
avrdude_message(MSG_INFO, "%s: invalid %s file format: %d\n", pmsg_error("invalid %s file format: %d\n", fio.iodesc, format);
progname, fio.iodesc, format);
return -1; return -1;
} }

View File

@ -234,16 +234,13 @@ int flip1_initialize(const PROGRAMMER *pgm, const AVRPART *part) {
if (usbpid) { if (usbpid) {
pid = *(int *)(ldata(usbpid)); pid = *(int *)(ldata(usbpid));
if (lnext(usbpid)) if (lnext(usbpid))
avrdude_message(MSG_INFO, "%s: Warning: using PID 0x%04x, ignoring remaining PIDs in list\n", pmsg_warning("using PID 0x%04x, ignoring remaining PIDs in list\n", pid);
progname, pid);
} else { } else {
pid = part->usbpid; pid = part->usbpid;
} }
if (!ovsigck && (part->prog_modes & PM_PDI)) { if (!ovsigck && (part->prog_modes & PM_PDI)) {
avrdude_message(MSG_INFO, "%s: \"flip1\" (FLIP protocol version 1) is for AT90USB* and ATmega*U* devices.\n" pmsg_error("flip1 (FLIP protocol version 1) is for AT90USB* and ATmega*U* devices\n");
"%s For Xmega devices, use \"flip2\".\n" imsg_error("for Xmega devices, use flip2 (or use -F to bypass this check)\n");
"%s (Use -F to bypass this check.)\n",
progname, progbuf, progbuf);
return -1; return -1;
} }
@ -255,32 +252,25 @@ int flip1_initialize(const PROGRAMMER *pgm, const AVRPART *part) {
/* Check if descriptor values are what we expect. */ /* Check if descriptor values are what we expect. */
if (dfu->dev_desc.idVendor != vid) if (dfu->dev_desc.idVendor != vid)
avrdude_message(MSG_INFO, "%s: Warning: USB idVendor = 0x%04X (expected 0x%04X)\n", pmsg_warning("USB idVendor = 0x%04X (expected 0x%04X)\n", dfu->dev_desc.idVendor, vid);
progname, dfu->dev_desc.idVendor, vid);
if (pid != 0 && dfu->dev_desc.idProduct != pid) if (pid != 0 && dfu->dev_desc.idProduct != pid)
avrdude_message(MSG_INFO, "%s: Warning: USB idProduct = 0x%04X (expected 0x%04X)\n", pmsg_warning("USB idProduct = 0x%04X (expected 0x%04X)\n", dfu->dev_desc.idProduct, pid);
progname, dfu->dev_desc.idProduct, pid);
if (dfu->dev_desc.bNumConfigurations != 1) if (dfu->dev_desc.bNumConfigurations != 1)
avrdude_message(MSG_INFO, "%s: Warning: USB bNumConfigurations = %d (expected 1)\n", pmsg_warning("USB bNumConfigurations = %d (expected 1)\n", (int) dfu->dev_desc.bNumConfigurations);
progname, (int) dfu->dev_desc.bNumConfigurations);
if (dfu->conf_desc.bNumInterfaces != 1) if (dfu->conf_desc.bNumInterfaces != 1)
avrdude_message(MSG_INFO, "%s: Warning: USB bNumInterfaces = %d (expected 1)\n", pmsg_warning("USB bNumInterfaces = %d (expected 1)\n", (int) dfu->conf_desc.bNumInterfaces);
progname, (int) dfu->conf_desc.bNumInterfaces);
if (dfu->dev_desc.bDeviceClass != 254) if (dfu->dev_desc.bDeviceClass != 254)
avrdude_message(MSG_INFO, "%s: Warning: USB bDeviceClass = %d (expected 254)\n", pmsg_warning("USB bDeviceClass = %d (expected 254)\n", (int) dfu->dev_desc.bDeviceClass);
progname, (int) dfu->dev_desc.bDeviceClass);
if (dfu->dev_desc.bDeviceSubClass != 1) if (dfu->dev_desc.bDeviceSubClass != 1)
avrdude_message(MSG_INFO, "%s: Warning: USB bDeviceSubClass = %d (expected 1)\n", pmsg_warning("USB bDeviceSubClass = %d (expected 1)\n", (int) dfu->dev_desc.bDeviceSubClass);
progname, (int) dfu->dev_desc.bDeviceSubClass);
if (dfu->dev_desc.bDeviceProtocol != 0) if (dfu->dev_desc.bDeviceProtocol != 0)
avrdude_message(MSG_INFO, "%s: Warning: USB bDeviceProtocol = %d (expected 0)\n", pmsg_warning("USB bDeviceProtocol = %d (expected 0)\n", (int) dfu->dev_desc.bDeviceProtocol);
progname, (int) dfu->dev_desc.bDeviceProtocol);
/* /*
* doc7618 claims an interface class of FEh and a subclas 01h. * doc7618 claims an interface class of FEh and a subclas 01h.
@ -290,21 +280,17 @@ int flip1_initialize(const PROGRAMMER *pgm, const AVRPART *part) {
*/ */
if (0) { if (0) {
if (dfu->intf_desc.bInterfaceClass != 254) if (dfu->intf_desc.bInterfaceClass != 254)
avrdude_message(MSG_INFO, "%s: Warning: USB bInterfaceClass = %d (expected 254)\n", pmsg_warning("USB bInterfaceClass = %d (expected 254)\n", (int) dfu->intf_desc.bInterfaceClass);
progname, (int) dfu->intf_desc.bInterfaceClass);
if (dfu->intf_desc.bInterfaceSubClass != 1) if (dfu->intf_desc.bInterfaceSubClass != 1)
avrdude_message(MSG_INFO, "%s: Warning: USB bInterfaceSubClass = %d (expected 1)\n", pmsg_warning("USB bInterfaceSubClass = %d (expected 1)\n", (int) dfu->intf_desc.bInterfaceSubClass);
progname, (int) dfu->intf_desc.bInterfaceSubClass);
if (dfu->intf_desc.bInterfaceProtocol != 0) if (dfu->intf_desc.bInterfaceProtocol != 0)
avrdude_message(MSG_INFO, "%s: Warning: USB bInterfaceSubClass = %d (expected 0)\n", pmsg_warning("USB bInterfaceSubClass = %d (expected 0)\n", (int) dfu->intf_desc.bInterfaceProtocol);
progname, (int) dfu->intf_desc.bInterfaceProtocol);
} }
if (dfu->dev_desc.bMaxPacketSize0 != 32) if (dfu->dev_desc.bMaxPacketSize0 != 32)
avrdude_message(MSG_INFO, "%s: Warning: bMaxPacketSize0 (%d) != 32, things might go wrong\n", pmsg_warning("bMaxPacketSize0 (%d) != 32, things might go wrong\n", dfu->dev_desc.bMaxPacketSize0);
progname, dfu->dev_desc.bMaxPacketSize0);
if (verbose) if (verbose)
flip1_show_info(FLIP1(pgm)); flip1_show_info(FLIP1(pgm));
@ -353,7 +339,7 @@ int flip1_chip_erase(const PROGRAMMER *pgm, const AVRPART *part) {
int aux_result; int aux_result;
unsigned int default_timeout = FLIP1(pgm)->dfu->timeout; unsigned int default_timeout = FLIP1(pgm)->dfu->timeout;
avrdude_message(MSG_NOTICE2, "%s: flip_chip_erase()\n", progname); pmsg_notice2("flip_chip_erase()\n");
struct flip1_cmd cmd = { struct flip1_cmd cmd = {
FLIP1_CMD_WRITE_COMMAND, { 0, 0xff } FLIP1_CMD_WRITE_COMMAND, { 0, 0xff }
@ -368,8 +354,7 @@ int flip1_chip_erase(const PROGRAMMER *pgm, const AVRPART *part) {
return -1; return -1;
if (status.bStatus != DFU_STATUS_OK) { if (status.bStatus != DFU_STATUS_OK) {
avrdude_message(MSG_INFO, "%s: failed to send chip erase command: %s\n", pmsg_error("unable to send chip erase command: %s\n", flip1_status_str(&status));
progname, flip1_status_str(&status));
if (status.bState == STATE_dfuERROR) if (status.bState == STATE_dfuERROR)
dfu_clrstatus(FLIP1(pgm)->dfu); dfu_clrstatus(FLIP1(pgm)->dfu);
return -1; return -1;
@ -389,9 +374,8 @@ int flip1_read_byte(const PROGRAMMER *pgm, const AVRPART *part, const AVRMEM *me
if (strcmp(mem->desc, "signature") == 0) { if (strcmp(mem->desc, "signature") == 0) {
if (flip1_read_sig_bytes(pgm, part, mem) < 0) if (flip1_read_sig_bytes(pgm, part, mem) < 0)
return -1; return -1;
if (addr > mem->size) { if (addr >= mem->size) {
avrdude_message(MSG_INFO, "%s: flip1_read_byte(signature): address %lu out of range\n", pmsg_error("signature address %lu out of range [0, %d]\n", addr, mem->size-1);
progname, addr);
return -1; return -1;
} }
*value = mem->buf[addr]; *value = mem->buf[addr];
@ -401,10 +385,7 @@ int flip1_read_byte(const PROGRAMMER *pgm, const AVRPART *part, const AVRMEM *me
mem_unit = flip1_mem_unit(mem->desc); mem_unit = flip1_mem_unit(mem->desc);
if (mem_unit == FLIP1_MEM_UNIT_UNKNOWN) { if (mem_unit == FLIP1_MEM_UNIT_UNKNOWN) {
avrdude_message(MSG_INFO, "%s: Error: " pmsg_error("%s memory not accessible using FLIP\n", mem->desc);
"\"%s\" memory not accessible using FLIP",
progname, mem->desc);
avrdude_message(MSG_INFO, "\n");
return -1; return -1;
} }
@ -426,10 +407,7 @@ int flip1_write_byte(const PROGRAMMER *pgm, const AVRPART *part, const AVRMEM *m
mem_unit = flip1_mem_unit(mem->desc); mem_unit = flip1_mem_unit(mem->desc);
if (mem_unit == FLIP1_MEM_UNIT_UNKNOWN) { if (mem_unit == FLIP1_MEM_UNIT_UNKNOWN) {
avrdude_message(MSG_INFO, "%s: Error: " pmsg_error("%s memory not accessible using FLIP\n", mem->desc);
"\"%s\" memory not accessible using FLIP",
progname, mem->desc);
avrdude_message(MSG_INFO, "\n");
return -1; return -1;
} }
@ -447,10 +425,7 @@ int flip1_paged_load(const PROGRAMMER *pgm, const AVRPART *part, const AVRMEM *m
mem_unit = flip1_mem_unit(mem->desc); mem_unit = flip1_mem_unit(mem->desc);
if (mem_unit == FLIP1_MEM_UNIT_UNKNOWN) { if (mem_unit == FLIP1_MEM_UNIT_UNKNOWN) {
avrdude_message(MSG_INFO, "%s: Error: " pmsg_error("%s memory not accessible using FLIP\n", mem->desc);
"\"%s\" memory not accessible using FLIP",
progname, mem->desc);
avrdude_message(MSG_INFO, "\n");
return -1; return -1;
} }
@ -473,17 +448,13 @@ int flip1_paged_write(const PROGRAMMER *pgm, const AVRPART *part, const AVRMEM *
mem_unit = flip1_mem_unit(mem->desc); mem_unit = flip1_mem_unit(mem->desc);
if (mem_unit == FLIP1_MEM_UNIT_UNKNOWN) { if (mem_unit == FLIP1_MEM_UNIT_UNKNOWN) {
avrdude_message(MSG_INFO, "%s: Error: " pmsg_error("%s memory not accessible using FLIP\n", mem->desc);
"\"%s\" memory not accessible using FLIP",
progname, mem->desc);
avrdude_message(MSG_INFO, "\n");
return -1; return -1;
} }
if (n_bytes > INT_MAX) { if (n_bytes > INT_MAX) {
/* This should never happen, unless the int type is only 16 bits. */ /* This should never happen, unless the int type is only 16 bits. */
avrdude_message(MSG_INFO, "%s: Error: Attempting to read more than %d bytes\n", pmsg_error("attempting to read more than %d bytes\n", INT_MAX);
progname, INT_MAX);
exit(1); exit(1);
} }
@ -494,14 +465,13 @@ int flip1_paged_write(const PROGRAMMER *pgm, const AVRPART *part, const AVRMEM *
} }
int flip1_read_sig_bytes(const PROGRAMMER *pgm, const AVRPART *part, const AVRMEM *mem) { int flip1_read_sig_bytes(const PROGRAMMER *pgm, const AVRPART *part, const AVRMEM *mem) {
avrdude_message(MSG_NOTICE2, "%s: flip1_read_sig_bytes(): ", progname); pmsg_notice2("flip1_read_sig_bytes(): ");
if (FLIP1(pgm)->dfu == NULL) if (FLIP1(pgm)->dfu == NULL)
return -1; return -1;
if (mem->size < sizeof(FLIP1(pgm)->part_sig)) { if (mem->size < sizeof(FLIP1(pgm)->part_sig)) {
avrdude_message(MSG_INFO, "%s: Error: Signature read must be at least %u bytes\n", pmsg_error("signature read must be at least %u bytes\n", (unsigned int) sizeof(FLIP1(pgm)->part_sig));
progname, (unsigned int) sizeof(FLIP1(pgm)->part_sig));
return -1; return -1;
} }
@ -518,7 +488,7 @@ int flip1_read_sig_bytes(const PROGRAMMER *pgm, const AVRPART *part, const AVRME
FLIP1_CMD_READ_COMMAND, FLIP1_READ_FAMILY_CODE FLIP1_CMD_READ_COMMAND, FLIP1_READ_FAMILY_CODE
}; };
avrdude_message(MSG_NOTICE2, "from device\n"); msg_notice2("from device\n");
for (i = 0; i < 3; i++) for (i = 0; i < 3; i++)
{ {
@ -535,8 +505,7 @@ int flip1_read_sig_bytes(const PROGRAMMER *pgm, const AVRPART *part, const AVRME
if (status.bStatus != DFU_STATUS_OK) if (status.bStatus != DFU_STATUS_OK)
{ {
avrdude_message(MSG_INFO, "%s: failed to send cmd for signature byte %d: %s\n", pmsg_error("unable to send cmd for signature byte %d: %s\n", i, flip1_status_str(&status));
progname, i, flip1_status_str(&status));
if (status.bState == STATE_dfuERROR) if (status.bState == STATE_dfuERROR)
dfu_clrstatus(FLIP1(pgm)->dfu); dfu_clrstatus(FLIP1(pgm)->dfu);
return -1; return -1;
@ -550,8 +519,7 @@ int flip1_read_sig_bytes(const PROGRAMMER *pgm, const AVRPART *part, const AVRME
if (status.bStatus != DFU_STATUS_OK) if (status.bStatus != DFU_STATUS_OK)
{ {
avrdude_message(MSG_INFO, "%s: failed to read signature byte %d: %s\n", pmsg_error("unable to read signature byte %d: %s\n", i, flip1_status_str(&status));
progname, i, flip1_status_str(&status));
if (status.bState == STATE_dfuERROR) if (status.bState == STATE_dfuERROR)
dfu_clrstatus(FLIP1(pgm)->dfu); dfu_clrstatus(FLIP1(pgm)->dfu);
return -1; return -1;
@ -560,7 +528,7 @@ int flip1_read_sig_bytes(const PROGRAMMER *pgm, const AVRPART *part, const AVRME
} }
else else
{ {
avrdude_message(MSG_NOTICE2, "cached\n"); msg_notice2("cached\n");
} }
memcpy(mem->buf, FLIP1(pgm)->part_sig, sizeof(FLIP1(pgm)->part_sig)); memcpy(mem->buf, FLIP1(pgm)->part_sig, sizeof(FLIP1(pgm)->part_sig));
@ -573,8 +541,7 @@ void flip1_setup(PROGRAMMER * pgm)
pgm->cookie = calloc(1, sizeof(struct flip1)); pgm->cookie = calloc(1, sizeof(struct flip1));
if (pgm->cookie == NULL) { if (pgm->cookie == NULL) {
avrdude_message(MSG_INFO, "%s: Out of memory allocating private data structure\n", pmsg_error("out of memory allocating private data structure\n");
progname);
exit(1); exit(1);
} }
} }
@ -591,8 +558,7 @@ void flip1_teardown(PROGRAMMER * pgm)
void flip1_show_info(struct flip1 *flip1) void flip1_show_info(struct flip1 *flip1)
{ {
dfu_show_info(flip1->dfu); dfu_show_info(flip1->dfu);
avrdude_message(MSG_INFO, " USB max packet size : %hu\n", msg_info(" USB max packet size : %hu\n", (unsigned short) flip1->dfu->dev_desc.bMaxPacketSize0);
(unsigned short) flip1->dfu->dev_desc.bMaxPacketSize0);
} }
int flip1_read_memory(const PROGRAMMER *pgm, int flip1_read_memory(const PROGRAMMER *pgm,
@ -609,8 +575,7 @@ int flip1_read_memory(const PROGRAMMER *pgm,
unsigned int default_timeout = dfu->timeout; unsigned int default_timeout = dfu->timeout;
avrdude_message(MSG_NOTICE2, "%s: flip_read_memory(%s, 0x%04x, %d)\n", pmsg_notice2("flip_read_memory(%s, 0x%04x, %d)\n", flip1_mem_unit_str(mem_unit), addr, size);
progname, flip1_mem_unit_str(mem_unit), addr, size);
/* /*
* As this function is called once per page, no need to handle 64 * As this function is called once per page, no need to handle 64
@ -640,9 +605,8 @@ int flip1_read_memory(const PROGRAMMER *pgm,
if (status.bStatus != DFU_STATUS_OK) if (status.bStatus != DFU_STATUS_OK)
{ {
avrdude_message(MSG_INFO, "%s: failed to read %u bytes of %s memory @%u: %s\n", pmsg_error("unable to read %u bytes of %s memory @%u: %s\n", size,
progname, size, flip1_mem_unit_str(mem_unit), addr, flip1_mem_unit_str(mem_unit), addr, flip1_status_str(&status));
flip1_status_str(&status));
if (status.bState == STATE_dfuERROR) if (status.bState == STATE_dfuERROR)
dfu_clrstatus(dfu); dfu_clrstatus(dfu);
return -1; return -1;
@ -653,13 +617,14 @@ int flip1_read_memory(const PROGRAMMER *pgm,
if (cmd_result < 0 && aux_result == 0 && if (cmd_result < 0 && aux_result == 0 &&
status.bStatus == DFU_STATUS_ERR_WRITE) { status.bStatus == DFU_STATUS_ERR_WRITE) {
if (FLIP1(pgm)->security_mode_flag == 0) if (FLIP1(pgm)->security_mode_flag == 0) {
avrdude_message(MSG_INFO, "\n%s:\n" msg_error("\n");
"%s***********************************************************************\n" pmsg_error("\n");
"%sMaybe the device is in ``security mode´´, and needs a chip erase first?\n" imsg_error("***********************************************************************\n");
"%s***********************************************************************\n" imsg_error("Maybe the device is in ``security mode´´, and needs a chip erase first?\n");
"\n", imsg_error("***********************************************************************\n");
progname, progbuf, progbuf, progbuf); msg_error("\n");
}
FLIP1(pgm)->security_mode_flag = 1; FLIP1(pgm)->security_mode_flag = 1;
} }
@ -668,9 +633,8 @@ int flip1_read_memory(const PROGRAMMER *pgm,
if (status.bStatus != DFU_STATUS_OK) if (status.bStatus != DFU_STATUS_OK)
{ {
avrdude_message(MSG_INFO, "%s: failed to read %u bytes of %s memory @%u: %s\n", pmsg_error("unable to read %u bytes of %s memory @%u: %s\n", size,
progname, size, flip1_mem_unit_str(mem_unit), addr, flip1_mem_unit_str(mem_unit), addr, flip1_status_str(&status));
flip1_status_str(&status));
if (status.bState == STATE_dfuERROR) if (status.bState == STATE_dfuERROR)
dfu_clrstatus(dfu); dfu_clrstatus(dfu);
return -1; return -1;
@ -702,14 +666,14 @@ int flip1_write_memory(struct dfu_dev *dfu,
unsigned int default_timeout = dfu->timeout; unsigned int default_timeout = dfu->timeout;
unsigned char *buf; unsigned char *buf;
avrdude_message(MSG_NOTICE2, "%s: flip_write_memory(%s, 0x%04x, %d)\n", pmsg_notice2("flip_write_memory(%s, 0x%04x, %d)\n",
progname, flip1_mem_unit_str(mem_unit), addr, size); flip1_mem_unit_str(mem_unit), addr, size);
if (size < 32) { if (size < 32) {
/* presumably single-byte updates; must be padded to USB endpoint size */ /* presumably single-byte updates; must be padded to USB endpoint size */
if ((addr + size - 1) / 32 != addr / 32) { if ((addr + size - 1) / 32 != addr / 32) {
avrdude_message(MSG_INFO, "%s: flip_write_memory(): begin (0x%x) and end (0x%x) not within same 32-byte block\n", pmsg_error("begin 0x%x and end 0x%x not within same 32-byte block\n",
progname, addr, addr + size - 1); addr, addr + size - 1);
return -1; return -1;
} }
write_size = 32; write_size = 32;
@ -720,7 +684,7 @@ int flip1_write_memory(struct dfu_dev *dfu,
if ((buf = malloc(sizeof(struct flip1_cmd_header) + if ((buf = malloc(sizeof(struct flip1_cmd_header) +
write_size + write_size +
sizeof(struct flip1_prog_footer))) == 0) { sizeof(struct flip1_prog_footer))) == 0) {
avrdude_message(MSG_INFO, "%s: Out of memory\n", progname); pmsg_error("out of memory\n");
return -1; return -1;
} }
@ -769,9 +733,8 @@ int flip1_write_memory(struct dfu_dev *dfu,
if (status.bStatus != DFU_STATUS_OK) if (status.bStatus != DFU_STATUS_OK)
{ {
avrdude_message(MSG_INFO, "%s: failed to write %u bytes of %s memory @%u: %s\n", pmsg_error("unable to write %u bytes of %s memory @%u: %s\n", size,
progname, size, flip1_mem_unit_str(mem_unit), addr, flip1_mem_unit_str(mem_unit), addr, flip1_status_str(&status));
flip1_status_str(&status));
if (status.bState == STATE_dfuERROR) if (status.bState == STATE_dfuERROR)
dfu_clrstatus(dfu); dfu_clrstatus(dfu);
return -1; return -1;
@ -800,8 +763,7 @@ int flip1_set_mem_page(struct dfu_dev *dfu,
if (status.bStatus != DFU_STATUS_OK) if (status.bStatus != DFU_STATUS_OK)
{ {
avrdude_message(MSG_INFO, "%s: failed to set memory page: %s\n", pmsg_error("unable to set memory page: %s\n", flip1_status_str(&status));
progname, flip1_status_str(&status));
if (status.bState == STATE_dfuERROR) if (status.bState == STATE_dfuERROR)
dfu_clrstatus(dfu); dfu_clrstatus(dfu);
return -1; return -1;
@ -855,8 +817,7 @@ enum flip1_mem_unit flip1_mem_unit(const char *name) {
#else /* HAVE_LIBUSB */ #else /* HAVE_LIBUSB */
// Dummy functions // Dummy functions
int flip1_open(PROGRAMMER *pgm, const char *port_spec) { int flip1_open(PROGRAMMER *pgm, const char *port_spec) {
fprintf(stderr, "%s: Error: No USB support in this compile of avrdude\n", pmsg_error("no USB support compiled for avrdude\n");
progname);
return -1; return -1;
} }

View File

@ -226,17 +226,15 @@ int flip2_initialize(const PROGRAMMER *pgm, const AVRPART *part) {
if (usbpid) { if (usbpid) {
pid = *(int *)(ldata(usbpid)); pid = *(int *)(ldata(usbpid));
if (lnext(usbpid)) if (lnext(usbpid))
avrdude_message(MSG_INFO, "%s: Warning: using PID 0x%04x, ignoring remaining PIDs in list\n", pmsg_warning("using PID 0x%04x, ignoring remaining PIDs in list\n", pid);
progname, pid);
} else { } else {
pid = part->usbpid; pid = part->usbpid;
} }
if (!ovsigck && !(part->prog_modes & PM_PDI)) { if (!ovsigck && !(part->prog_modes & PM_PDI)) {
avrdude_message(MSG_INFO, "%s: \"flip2\" (FLIP protocol version 2) is for Xmega devices.\n" pmsg_error("flip2 (FLIP protocol version 2) is for Xmega devices\n");
"%s For AT90USB* or ATmega*U* devices, use \"flip1\".\n" imsg_error("for AT90USB* or ATmega*U* devices, use flip1\n");
"%s (Use -F to bypass this check.)\n", imsg_error("(or use -F to bypass this check)\n");
progname, progbuf, progbuf);
return -1; return -1;
} }
@ -248,44 +246,44 @@ int flip2_initialize(const PROGRAMMER *pgm, const AVRPART *part) {
/* Check if descriptor values are what we expect. */ /* Check if descriptor values are what we expect. */
if (dfu->dev_desc.idVendor != vid) if (dfu->dev_desc.idVendor != vid)
avrdude_message(MSG_INFO, "%s: Warning: USB idVendor = 0x%04X (expected 0x%04X)\n", pmsg_warning("USB idVendor = 0x%04X (expected 0x%04X)\n",
progname, dfu->dev_desc.idVendor, vid); dfu->dev_desc.idVendor, vid);
if (pid != 0 && dfu->dev_desc.idProduct != pid) if (pid != 0 && dfu->dev_desc.idProduct != pid)
avrdude_message(MSG_INFO, "%s: Warning: USB idProduct = 0x%04X (expected 0x%04X)\n", pmsg_warning("USB idProduct = 0x%04X (expected 0x%04X)\n",
progname, dfu->dev_desc.idProduct, pid); dfu->dev_desc.idProduct, pid);
if (dfu->dev_desc.bNumConfigurations != 1) if (dfu->dev_desc.bNumConfigurations != 1)
avrdude_message(MSG_INFO, "%s: Warning: USB bNumConfigurations = %d (expected 1)\n", pmsg_error("USB bNumConfigurations = %d (expected 1)\n",
progname, (int) dfu->dev_desc.bNumConfigurations); (int) dfu->dev_desc.bNumConfigurations);
if (dfu->conf_desc.bNumInterfaces != 1) if (dfu->conf_desc.bNumInterfaces != 1)
avrdude_message(MSG_INFO, "%s: Warning: USB bNumInterfaces = %d (expected 1)\n", pmsg_error("USB bNumInterfaces = %d (expected 1)\n",
progname, (int) dfu->conf_desc.bNumInterfaces); (int) dfu->conf_desc.bNumInterfaces);
if (dfu->dev_desc.bDeviceClass != 0) if (dfu->dev_desc.bDeviceClass != 0)
avrdude_message(MSG_INFO, "%s: Warning: USB bDeviceClass = %d (expected 0)\n", pmsg_error("USB bDeviceClass = %d (expected 0)\n",
progname, (int) dfu->dev_desc.bDeviceClass); (int) dfu->dev_desc.bDeviceClass);
if (dfu->dev_desc.bDeviceSubClass != 0) if (dfu->dev_desc.bDeviceSubClass != 0)
avrdude_message(MSG_INFO, "%s: Warning: USB bDeviceSubClass = %d (expected 0)\n", pmsg_error("USB bDeviceSubClass = %d (expected 0)\n",
progname, (int) dfu->dev_desc.bDeviceSubClass); (int) dfu->dev_desc.bDeviceSubClass);
if (dfu->dev_desc.bDeviceProtocol != 0) if (dfu->dev_desc.bDeviceProtocol != 0)
avrdude_message(MSG_INFO, "%s: Warning: USB bDeviceProtocol = %d (expected 0)\n", pmsg_error("USB bDeviceProtocol = %d (expected 0)\n",
progname, (int) dfu->dev_desc.bDeviceProtocol); (int) dfu->dev_desc.bDeviceProtocol);
if (dfu->intf_desc.bInterfaceClass != 0xFF) if (dfu->intf_desc.bInterfaceClass != 0xFF)
avrdude_message(MSG_INFO, "%s: Warning: USB bInterfaceClass = %d (expected 255)\n", pmsg_error("USB bInterfaceClass = %d (expected 255)\n",
progname, (int) dfu->intf_desc.bInterfaceClass); (int) dfu->intf_desc.bInterfaceClass);
if (dfu->intf_desc.bInterfaceSubClass != 0) if (dfu->intf_desc.bInterfaceSubClass != 0)
avrdude_message(MSG_INFO, "%s: Warning: USB bInterfaceSubClass = %d (expected 0)\n", pmsg_error("USB bInterfaceSubClass = %d (expected 0)\n",
progname, (int) dfu->intf_desc.bInterfaceSubClass); (int) dfu->intf_desc.bInterfaceSubClass);
if (dfu->intf_desc.bInterfaceProtocol != 0) if (dfu->intf_desc.bInterfaceProtocol != 0)
avrdude_message(MSG_INFO, "%s: Warning: USB bInterfaceSubClass = %d (expected 0)\n", pmsg_error("USB bInterfaceSubClass = %d (expected 0)\n",
progname, (int) dfu->intf_desc.bInterfaceProtocol); (int) dfu->intf_desc.bInterfaceProtocol);
result = flip2_read_memory(FLIP2(pgm)->dfu, result = flip2_read_memory(FLIP2(pgm)->dfu,
FLIP2_MEM_UNIT_SIGNATURE, 0, FLIP2(pgm)->part_sig, 4); FLIP2_MEM_UNIT_SIGNATURE, 0, FLIP2(pgm)->part_sig, 4);
@ -347,7 +345,7 @@ int flip2_chip_erase(const PROGRAMMER *pgm, const AVRPART *part) {
int cmd_result = 0; int cmd_result = 0;
int aux_result; int aux_result;
avrdude_message(MSG_NOTICE2, "%s: flip_chip_erase()\n", progname); pmsg_notice2("flip_chip_erase()\n");
struct flip2_cmd cmd = { struct flip2_cmd cmd = {
FLIP2_CMD_GROUP_EXEC, FLIP2_CMD_CHIP_ERASE, { 0xFF, 0, 0, 0 } FLIP2_CMD_GROUP_EXEC, FLIP2_CMD_CHIP_ERASE, { 0xFF, 0, 0, 0 }
@ -365,9 +363,8 @@ int flip2_chip_erase(const PROGRAMMER *pgm, const AVRPART *part) {
status.bState == ((FLIP2_STATUS_ERASE_ONGOING >> 0) & 0xFF)) status.bState == ((FLIP2_STATUS_ERASE_ONGOING >> 0) & 0xFF))
{ {
continue; continue;
} else }
avrdude_message(MSG_INFO, "%s: Error: DFU status %s\n", progname, pmsg_error("DFU status %s\n", flip2_status_str(&status));
flip2_status_str(&status));
dfu_clrstatus(FLIP2(pgm)->dfu); dfu_clrstatus(FLIP2(pgm)->dfu);
} else } else
break; break;
@ -377,7 +374,7 @@ int flip2_chip_erase(const PROGRAMMER *pgm, const AVRPART *part) {
} }
int flip2_start_app(const PROGRAMMER *pgm) { int flip2_start_app(const PROGRAMMER *pgm) {
avrdude_message(MSG_INFO, "%s: Starting application\n", progname); pmsg_info("starting application\n");
struct flip2_cmd cmd = { struct flip2_cmd cmd = {
FLIP2_CMD_GROUP_EXEC, FLIP2_CMD_START_APP, { 0x00, 0, 0, 0 } FLIP2_CMD_GROUP_EXEC, FLIP2_CMD_START_APP, { 0x00, 0, 0, 0 }
@ -403,12 +400,10 @@ int flip2_read_byte(const PROGRAMMER *pgm, const AVRPART *part, const AVRMEM *me
mem_unit = flip2_mem_unit(mem->desc); mem_unit = flip2_mem_unit(mem->desc);
if (mem_unit == FLIP2_MEM_UNIT_UNKNOWN) { if (mem_unit == FLIP2_MEM_UNIT_UNKNOWN) {
avrdude_message(MSG_INFO, "%s: Error: " pmsg_error("%s memory not accessible using FLIP", mem->desc);
"\"%s\" memory not accessible using FLIP",
progname, mem->desc);
if (strcmp(mem->desc, "flash") == 0) if (strcmp(mem->desc, "flash") == 0)
avrdude_message(MSG_INFO, " (did you mean \"application\"?)"); msg_error(" (did you mean \"application\"?)");
avrdude_message(MSG_INFO, "\n"); msg_error("\n");
return -1; return -1;
} }
@ -426,12 +421,10 @@ int flip2_write_byte(const PROGRAMMER *pgm, const AVRPART *part, const AVRMEM *m
mem_unit = flip2_mem_unit(mem->desc); mem_unit = flip2_mem_unit(mem->desc);
if (mem_unit == FLIP2_MEM_UNIT_UNKNOWN) { if (mem_unit == FLIP2_MEM_UNIT_UNKNOWN) {
avrdude_message(MSG_INFO, "%s: Error: " pmsg_error("%s memory not accessible using FLIP", mem->desc);
"\"%s\" memory not accessible using FLIP",
progname, mem->desc);
if (strcmp(mem->desc, "flash") == 0) if (strcmp(mem->desc, "flash") == 0)
avrdude_message(MSG_INFO, " (did you mean \"application\"?)"); msg_error(" (did you mean \"application\"?)");
avrdude_message(MSG_INFO, "\n"); msg_error("\n");
return -1; return -1;
} }
@ -450,19 +443,16 @@ int flip2_paged_load(const PROGRAMMER *pgm, const AVRPART *part, const AVRMEM *m
mem_unit = flip2_mem_unit(mem->desc); mem_unit = flip2_mem_unit(mem->desc);
if (mem_unit == FLIP2_MEM_UNIT_UNKNOWN) { if (mem_unit == FLIP2_MEM_UNIT_UNKNOWN) {
avrdude_message(MSG_INFO, "%s: Error: " pmsg_error("%s memory not accessible using FLIP", mem->desc);
"\"%s\" memory not accessible using FLIP",
progname, mem->desc);
if (strcmp(mem->desc, "flash") == 0) if (strcmp(mem->desc, "flash") == 0)
avrdude_message(MSG_INFO, " (did you mean \"application\"?)"); msg_error(" (did you mean \"application\"?)");
avrdude_message(MSG_INFO, "\n"); msg_error("\n");
return -1; return -1;
} }
if (n_bytes > INT_MAX) { if (n_bytes > INT_MAX) {
/* This should never happen, unless the int type is only 16 bits. */ /* This should never happen, unless the int type is only 16 bits. */
avrdude_message(MSG_INFO, "%s: Error: Attempting to read more than %d bytes\n", pmsg_error("attempting to read more than %d bytes\n", INT_MAX);
progname, INT_MAX);
exit(1); exit(1);
} }
@ -484,19 +474,16 @@ int flip2_paged_write(const PROGRAMMER *pgm, const AVRPART *part, const AVRMEM *
mem_unit = flip2_mem_unit(mem->desc); mem_unit = flip2_mem_unit(mem->desc);
if (mem_unit == FLIP2_MEM_UNIT_UNKNOWN) { if (mem_unit == FLIP2_MEM_UNIT_UNKNOWN) {
avrdude_message(MSG_INFO, "%s: Error: " pmsg_error("%s memory not accessible using FLIP", mem->desc);
"\"%s\" memory not accessible using FLIP",
progname, mem->desc);
if (strcmp(mem->desc, "flash") == 0) if (strcmp(mem->desc, "flash") == 0)
avrdude_message(MSG_INFO, " (did you mean \"application\"?)"); msg_error(" (did you mean \"application\"?)");
avrdude_message(MSG_INFO, "\n"); msg_error("\n");
return -1; return -1;
} }
if (n_bytes > INT_MAX) { if (n_bytes > INT_MAX) {
/* This should never happen, unless the int type is only 16 bits. */ /* This should never happen, unless the int type is only 16 bits. */
avrdude_message(MSG_INFO, "%s: Error: Attempting to read more than %d bytes\n", pmsg_error("attempting to read more than %d bytes\n", INT_MAX);
progname, INT_MAX);
exit(1); exit(1);
} }
@ -534,8 +521,7 @@ int flip2_read_sig_bytes(const PROGRAMMER *pgm, const AVRPART *part, const AVRME
return -1; return -1;
if (mem->size < sizeof(FLIP2(pgm)->part_sig)) { if (mem->size < sizeof(FLIP2(pgm)->part_sig)) {
avrdude_message(MSG_INFO, "%s: Error: Signature read must be at least %u bytes\n", pmsg_error("signature read must be at least %u bytes\n", (unsigned int) sizeof(FLIP2(pgm)->part_sig));
progname, (unsigned int) sizeof(FLIP2(pgm)->part_sig));
return -1; return -1;
} }
@ -548,8 +534,7 @@ void flip2_setup(PROGRAMMER * pgm)
pgm->cookie = calloc(1, sizeof(struct flip2)); pgm->cookie = calloc(1, sizeof(struct flip2));
if (pgm->cookie == NULL) { if (pgm->cookie == NULL) {
avrdude_message(MSG_INFO, "%s: Out of memory allocating private data structure\n", pmsg_error("out of memory allocating private data structure\n");
progname);
exit(1); exit(1);
} }
} }
@ -567,24 +552,24 @@ void flip2_show_info(struct flip2 *flip2)
{ {
dfu_show_info(flip2->dfu); dfu_show_info(flip2->dfu);
avrdude_message(MSG_INFO, " Part signature : 0x%02X%02X%02X\n", msg_info(" Part signature : 0x%02X%02X%02X\n",
(int) flip2->part_sig[0], (int) flip2->part_sig[0],
(int) flip2->part_sig[1], (int) flip2->part_sig[1],
(int) flip2->part_sig[2]); (int) flip2->part_sig[2]);
if (flip2->part_rev < 26) if (flip2->part_rev < 26)
avrdude_message(MSG_INFO, " Part revision : %c\n", msg_info(" Part revision : %c\n",
(char) (flip2->part_rev + 'A')); (char) (flip2->part_rev + 'A'));
else else
avrdude_message(MSG_INFO, " Part revision : %c%c\n", msg_info(" Part revision : %c%c\n",
(char) (flip2->part_rev / 26 - 1 + 'A'), (char) (flip2->part_rev / 26 - 1 + 'A'),
(char) (flip2->part_rev % 26 + 'A')); (char) (flip2->part_rev % 26 + 'A'));
avrdude_message(MSG_INFO, " Bootloader version : 2.%hu.%hu\n", msg_info(" Bootloader version : 2.%hu.%hu\n",
((unsigned short) flip2->boot_ver >> 4) & 0xF, ((unsigned short) flip2->boot_ver >> 4) & 0xF,
((unsigned short) flip2->boot_ver >> 0) & 0xF); ((unsigned short) flip2->boot_ver >> 0) & 0xF);
avrdude_message(MSG_INFO, " USB max packet size : %hu\n", msg_info(" USB max packet size : %hu\n",
(unsigned short) flip2->dfu->dev_desc.bMaxPacketSize0); (unsigned short) flip2->dfu->dev_desc.bMaxPacketSize0);
} }
@ -597,18 +582,15 @@ int flip2_read_memory(struct dfu_dev *dfu,
int read_size; int read_size;
int result; int result;
avrdude_message(MSG_NOTICE2, "%s: flip_read_memory(%s, 0x%04x, %d)\n", pmsg_notice2("flip_read_memory(%s, 0x%04x, %d)\n", flip2_mem_unit_str(mem_unit), addr, size);
progname, flip2_mem_unit_str(mem_unit), addr, size);
result = flip2_set_mem_unit(dfu, mem_unit); result = flip2_set_mem_unit(dfu, mem_unit);
if (result != 0) { if (result != 0) {
if ((mem_name = flip2_mem_unit_str(mem_unit)) != NULL) if ((mem_name = flip2_mem_unit_str(mem_unit)) != NULL)
avrdude_message(MSG_INFO, "%s: Error: Failed to set memory unit 0x%02X (%s)\n", pmsg_error("unable to set memory unit 0x%02X (%s)\n", (int) mem_unit, mem_name);
progname, (int) mem_unit, mem_name);
else else
avrdude_message(MSG_INFO, "%s: Error: Failed to set memory unit 0x%02X\n", pmsg_error("unable to set memory unit 0x%02X\n", (int) mem_unit);
progname, (int) mem_unit);
return -1; return -1;
} }
@ -616,8 +598,7 @@ int flip2_read_memory(struct dfu_dev *dfu,
result = flip2_set_mem_page(dfu, page_addr); result = flip2_set_mem_page(dfu, page_addr);
if (result != 0) { if (result != 0) {
avrdude_message(MSG_INFO, "%s: Error: Failed to set memory page 0x%04hX\n", pmsg_error("unable to set memory page 0x%04hX\n", page_addr);
progname, page_addr);
return -1; return -1;
} }
@ -628,8 +609,7 @@ int flip2_read_memory(struct dfu_dev *dfu,
if (page_addr != prev_page_addr) { if (page_addr != prev_page_addr) {
result = flip2_set_mem_page(dfu, page_addr); result = flip2_set_mem_page(dfu, page_addr);
if (result != 0) { if (result != 0) {
avrdude_message(MSG_INFO, "%s: Error: Failed to set memory page 0x%04hX\n", pmsg_error("unable to set memory page 0x%04hX\n", page_addr);
progname, page_addr);
return -1; return -1;
} }
} }
@ -638,8 +618,7 @@ int flip2_read_memory(struct dfu_dev *dfu,
result = flip2_read_max1k(dfu, addr & 0xFFFF, ptr, read_size); result = flip2_read_max1k(dfu, addr & 0xFFFF, ptr, read_size);
if (result != 0) { if (result != 0) {
avrdude_message(MSG_INFO, "%s: Error: Failed to read 0x%04X bytes at 0x%04lX\n", pmsg_error("unable to read 0x%04X bytes at 0x%04lX\n", read_size, (unsigned long) addr);
progname, read_size, (unsigned long) addr);
return -1; return -1;
} }
@ -660,18 +639,15 @@ int flip2_write_memory(struct dfu_dev *dfu,
int write_size; int write_size;
int result; int result;
avrdude_message(MSG_NOTICE2, "%s: flip_write_memory(%s, 0x%04x, %d)\n", pmsg_notice2("flip_write_memory(%s, 0x%04x, %d)\n", flip2_mem_unit_str(mem_unit), addr, size);
progname, flip2_mem_unit_str(mem_unit), addr, size);
result = flip2_set_mem_unit(dfu, mem_unit); result = flip2_set_mem_unit(dfu, mem_unit);
if (result != 0) { if (result != 0) {
if ((mem_name = flip2_mem_unit_str(mem_unit)) != NULL) if ((mem_name = flip2_mem_unit_str(mem_unit)) != NULL)
avrdude_message(MSG_INFO, "%s: Error: Failed to set memory unit 0x%02X (%s)\n", pmsg_error("unable to set memory unit 0x%02X (%s)\n", (int) mem_unit, mem_name);
progname, (int) mem_unit, mem_name);
else else
avrdude_message(MSG_INFO, "%s: Error: Failed to set memory unit 0x%02X\n", pmsg_error("unable to set memory unit 0x%02X\n", (int) mem_unit);
progname, (int) mem_unit);
return -1; return -1;
} }
@ -679,8 +655,7 @@ int flip2_write_memory(struct dfu_dev *dfu,
result = flip2_set_mem_page(dfu, page_addr); result = flip2_set_mem_page(dfu, page_addr);
if (result != 0) { if (result != 0) {
avrdude_message(MSG_INFO, "%s: Error: Failed to set memory page 0x%04hX\n", pmsg_error("unable to set memory page 0x%04hX\n", page_addr);
progname, page_addr);
return -1; return -1;
} }
@ -691,8 +666,7 @@ int flip2_write_memory(struct dfu_dev *dfu,
if (page_addr != prev_page_addr) { if (page_addr != prev_page_addr) {
result = flip2_set_mem_page(dfu, page_addr); result = flip2_set_mem_page(dfu, page_addr);
if (result != 0) { if (result != 0) {
avrdude_message(MSG_INFO, "%s: Error: Failed to set memory page 0x%04hX\n", pmsg_error("unable to set memory page 0x%04hX\n", page_addr);
progname, page_addr);
return -1; return -1;
} }
} }
@ -701,8 +675,7 @@ int flip2_write_memory(struct dfu_dev *dfu,
result = flip2_write_max1k(dfu, addr & 0xFFFF, ptr, write_size); result = flip2_write_max1k(dfu, addr & 0xFFFF, ptr, write_size);
if (result != 0) { if (result != 0) {
avrdude_message(MSG_INFO, "%s: Error: Failed to write 0x%04X bytes at 0x%04lX\n", pmsg_error("unable to write 0x%04X bytes at 0x%04lX\n", write_size, (unsigned long) addr);
progname, write_size, (unsigned long) addr);
return -1; return -1;
} }
@ -738,11 +711,9 @@ int flip2_set_mem_unit(struct dfu_dev *dfu, enum flip2_mem_unit mem_unit)
if (status.bStatus == ((FLIP2_STATUS_OUTOFRANGE >> 8) & 0xFF) && if (status.bStatus == ((FLIP2_STATUS_OUTOFRANGE >> 8) & 0xFF) &&
status.bState == ((FLIP2_STATUS_OUTOFRANGE >> 0) & 0xFF)) status.bState == ((FLIP2_STATUS_OUTOFRANGE >> 0) & 0xFF))
{ {
avrdude_message(MSG_INFO, "%s: Error: Unknown memory unit (0x%02x)\n", pmsg_error("unknown memory unit (0x%02x)\n", (unsigned int) mem_unit);
progname, (unsigned int) mem_unit);
} else } else
avrdude_message(MSG_INFO, "%s: Error: DFU status %s\n", progname, pmsg_error("DFU status %s\n", flip2_status_str(&status));
flip2_status_str(&status));
dfu_clrstatus(dfu); dfu_clrstatus(dfu);
} }
@ -775,11 +746,9 @@ int flip2_set_mem_page(struct dfu_dev *dfu,
if (status.bStatus == ((FLIP2_STATUS_OUTOFRANGE >> 8) & 0xFF) && if (status.bStatus == ((FLIP2_STATUS_OUTOFRANGE >> 8) & 0xFF) &&
status.bState == ((FLIP2_STATUS_OUTOFRANGE >> 0) & 0xFF)) status.bState == ((FLIP2_STATUS_OUTOFRANGE >> 0) & 0xFF))
{ {
avrdude_message(MSG_INFO, "%s: Error: Page address out of range (0x%04hx)\n", pmsg_error("page address out of range (0x%04hx)\n", page_addr);
progname, page_addr);
} else } else
avrdude_message(MSG_INFO, "%s: Error: DFU status %s\n", progname, pmsg_error("DFU status %s\n", flip2_status_str(&status));
flip2_status_str(&status));
dfu_clrstatus(dfu); dfu_clrstatus(dfu);
} }
@ -820,11 +789,9 @@ flip2_read_max1k_status:
if (status.bStatus == ((FLIP2_STATUS_OUTOFRANGE >> 8) & 0xFF) && if (status.bStatus == ((FLIP2_STATUS_OUTOFRANGE >> 8) & 0xFF) &&
status.bState == ((FLIP2_STATUS_OUTOFRANGE >> 0) & 0xFF)) status.bState == ((FLIP2_STATUS_OUTOFRANGE >> 0) & 0xFF))
{ {
avrdude_message(MSG_INFO, "%s: Error: Address out of range [0x%04hX,0x%04hX]\n", pmsg_error("address out of range [0x%04hX,0x%04hX]\n", offset, offset+size-1);
progname, offset, offset+size-1);
} else } else
avrdude_message(MSG_INFO, "%s: Error: DFU status %s\n", progname, pmsg_error("DFU status %s\n", flip2_status_str(&status));
flip2_status_str(&status));
dfu_clrstatus(dfu); dfu_clrstatus(dfu);
} }
@ -850,8 +817,7 @@ int flip2_write_max1k(struct dfu_dev *dfu,
cmd.args[3] = ((offset+size-1) >> 0) & 0xFF; cmd.args[3] = ((offset+size-1) >> 0) & 0xFF;
if (size > 0x400) { if (size > 0x400) {
avrdude_message(MSG_INFO, "%s: Error: Write block too large (%hu > 1024)\n", pmsg_error("erite block too large (%hu > 1024)\n", size);
progname, size);
return -1; return -1;
} }
@ -881,11 +847,9 @@ int flip2_write_max1k(struct dfu_dev *dfu,
if (status.bStatus == ((FLIP2_STATUS_OUTOFRANGE >> 8) & 0xFF) && if (status.bStatus == ((FLIP2_STATUS_OUTOFRANGE >> 8) & 0xFF) &&
status.bState == ((FLIP2_STATUS_OUTOFRANGE >> 0) & 0xFF)) status.bState == ((FLIP2_STATUS_OUTOFRANGE >> 0) & 0xFF))
{ {
avrdude_message(MSG_INFO, "%s: Error: Address out of range [0x%04hX,0x%04hX]\n", pmsg_error("address out of range [0x%04hX,0x%04hX]\n", offset, offset+size-1);
progname, offset, offset+size-1);
} else } else
avrdude_message(MSG_INFO, "%s: Error: DFU status %s\n", progname, pmsg_error("DFU status %s\n", flip2_status_str(&status));
flip2_status_str(&status));
dfu_clrstatus(dfu); dfu_clrstatus(dfu);
} }
@ -949,7 +913,7 @@ enum flip2_mem_unit flip2_mem_unit(const char *name) {
// Give a proper error if we were not compiled with libusb // Give a proper error if we were not compiled with libusb
static int flip2_nousb_open(PROGRAMMER* pgm, const char* name) { static int flip2_nousb_open(PROGRAMMER* pgm, const char* name) {
avrdude_message(MSG_INFO, "%s: error, no USB support; please compile with libusb installed\n", progname); pmsg_error("no USB support; please compile with libusb installed\n");
return -1; return -1;
} }

View File

@ -94,8 +94,7 @@
#if defined(DO_NOT_BUILD_FT245R) #if defined(DO_NOT_BUILD_FT245R)
static int ft245r_noftdi_open(PROGRAMMER *pgm, const char *name) { static int ft245r_noftdi_open(PROGRAMMER *pgm, const char *name) {
avrdude_message(MSG_INFO, "%s: error: no libftdi or libusb support. Install libftdi1/libusb-1.0 or libftdi/libusb and run configure/make again.\n", pmsg_error("no libftdi or libusb support; install libftdi1/libusb-1.0 or libftdi/libusb and run configure/make\n");
progname);
return -1; return -1;
} }
@ -189,8 +188,7 @@ static int ft245r_fill(const PROGRAMMER *pgm) {
return -1; return -1;
rx.pending -= nread; rx.pending -= nread;
#if FT245R_DEBUG #if FT245R_DEBUG
avrdude_message(MSG_INFO, "%s: read %d bytes (pending=%d)\n", msg_info("%s: read %d bytes (pending=%d)\n", __func__, nread, rx.pending);
__func__, nread, rx.pending);
#endif #endif
for (i = 0; i < nread; ++i) for (i = 0; i < nread; ++i)
ft245r_rx_buf_put(pgm, raw[i]); ft245r_rx_buf_put(pgm, raw[i]);
@ -223,9 +221,7 @@ static int ft245r_flush(const PROGRAMMER *pgm) {
if (avail <= 0) { if (avail <= 0) {
avail = ft245r_fill(pgm); avail = ft245r_fill(pgm);
if (avail < 0) { if (avail < 0) {
avrdude_message(MSG_INFO, pmsg_error("fill returned %d: %s\n", avail, ftdi_get_error_string(handle));
"%s: fill returned %d: %s\n",
__func__, avail, ftdi_get_error_string(handle));
return -1; return -1;
} }
} }
@ -233,13 +229,11 @@ static int ft245r_flush(const PROGRAMMER *pgm) {
avail = len; avail = len;
#if FT245R_DEBUG #if FT245R_DEBUG
avrdude_message(MSG_INFO, "%s: writing %d bytes\n", __func__, avail); msg_info("%s: writing %d bytes\n", __func__, avail);
#endif #endif
rv = ftdi_write_data(handle, src, avail); rv = ftdi_write_data(handle, src, avail);
if (rv != avail) { if (rv != avail) {
avrdude_message(MSG_INFO, msg_error("write returned %d (expected %d): %s\n", rv, avail, ftdi_get_error_string(handle));
"%s: write returned %d (expected %d): %s\n",
__func__, rv, avail, ftdi_get_error_string(handle));
return -1; return -1;
} }
src += avail; src += avail;
@ -282,8 +276,7 @@ static int ft245r_recv(const PROGRAMMER *pgm, unsigned char *buf, size_t len) {
ft245r_fill(pgm); ft245r_fill(pgm);
#if FT245R_DEBUG #if FT245R_DEBUG
avrdude_message(MSG_INFO, "%s: discarding %d, consuming %zu bytes\n", msg_info("%s: discarding %d, consuming %zu bytes\n", __func__, rx.discard, len);
__func__, rx.discard, len);
#endif #endif
while (rx.discard > 0) { while (rx.discard > 0) {
int result = ft245r_rx_buf_fill_and_get(pgm); int result = ft245r_rx_buf_fill_and_get(pgm);
@ -320,7 +313,7 @@ static int ft245r_recv(const PROGRAMMER *pgm, unsigned char *buf, size_t len) {
static int ft245r_drain(const PROGRAMMER *pgm, int display) { static int ft245r_drain(const PROGRAMMER *pgm, int display) {
int r; int r;
// flush the buffer in the chip by changing the mode..... // flush the buffer in the chip by changing the mode ...
r = ftdi_set_bitmode(handle, 0, BITMODE_RESET); // reset r = ftdi_set_bitmode(handle, 0, BITMODE_RESET); // reset
if (r) return -1; if (r) return -1;
r = ftdi_set_bitmode(handle, ft245r_ddr, BITMODE_SYNCBB); // set Synchronuse BitBang r = ftdi_set_bitmode(handle, ft245r_ddr, BITMODE_SYNCBB); // set Synchronuse BitBang
@ -347,8 +340,7 @@ static int ft245r_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) {
return avr_tpi_chip_erase(pgm, p); return avr_tpi_chip_erase(pgm, p);
if (p->op[AVR_OP_CHIP_ERASE] == NULL) { if (p->op[AVR_OP_CHIP_ERASE] == NULL) {
avrdude_message(MSG_INFO, "chip erase instruction not defined for part \"%s\"\n", msg_error("chip erase instruction not defined for part %s\n", p->desc);
p->desc);
return -1; return -1;
} }
@ -381,14 +373,12 @@ static int ft245r_set_bitclock(const PROGRAMMER *pgm) {
ftdi_rate = rate; ftdi_rate = rate;
#endif #endif
avrdude_message(MSG_NOTICE2, msg_notice2("%s: bitclk %d -> FTDI rate %d, baud multiplier %d\n",
"%s: bitclk %d -> FTDI rate %d, baud multiplier %d\n", __func__, rate, ftdi_rate, baud_multiplier);
__func__, rate, ftdi_rate, baud_multiplier);
r = ftdi_set_baudrate(handle, ftdi_rate); r = ftdi_set_baudrate(handle, ftdi_rate);
if (r) { if (r) {
avrdude_message(MSG_INFO, "Set baudrate (%d) failed with error '%s'.\n", msg_error("set baudrate %d failed with error '%s'\n", rate, ftdi_get_error_string (handle));
rate, ftdi_get_error_string (handle));
return -1; return -1;
} }
return 0; return 0;
@ -402,7 +392,7 @@ static int get_pin(const PROGRAMMER *pgm, int pinname) {
if (ftdi_read_pins(handle, &byte) != 0) if (ftdi_read_pins(handle, &byte) != 0)
return -1; return -1;
if (FT245R_DEBUG) if (FT245R_DEBUG)
avrdude_message(MSG_INFO, "%s: in 0x%02x\n", __func__, byte); msg_info("%s: in 0x%02x\n", __func__, byte);
return GET_BITS_0(byte, pgm, pinname) != 0; return GET_BITS_0(byte, pgm, pinname) != 0;
} }
@ -506,8 +496,7 @@ static int ft245r_program_enable(const PROGRAMMER *pgm, const AVRPART *p) {
return avr_tpi_program_enable(pgm, p, TPIPCR_GT_0b); return avr_tpi_program_enable(pgm, p, TPIPCR_GT_0b);
if (p->op[AVR_OP_PGM_ENABLE] == NULL) { if (p->op[AVR_OP_PGM_ENABLE] == NULL) {
avrdude_message(MSG_INFO, "%s: AVR_OP_PGM_ENABLE command not defined for %s\n", pmsg_error("AVR_OP_PGM_ENABLE command not defined for %s\n", p->desc);
progname, p->desc);
fflush(stderr); fflush(stderr);
return -1; return -1;
} }
@ -520,8 +509,7 @@ static int ft245r_program_enable(const PROGRAMMER *pgm, const AVRPART *p) {
if (res[p->pollindex-1] == p->pollvalue) return 0; if (res[p->pollindex-1] == p->pollvalue) return 0;
if (FT245R_DEBUG) { if (FT245R_DEBUG) {
avrdude_message(MSG_NOTICE, "%s: Program enable command not successful. Retrying.\n", pmsg_notice("program enable command not successful, retrying\n");
progname);
fflush(stderr); fflush(stderr);
} }
set_pin(pgm, PIN_AVR_RESET, ON); set_pin(pgm, PIN_AVR_RESET, ON);
@ -534,8 +522,7 @@ static int ft245r_program_enable(const PROGRAMMER *pgm, const AVRPART *p) {
} }
} }
avrdude_message(MSG_INFO, "%s: Device is not responding to program enable. Check connection.\n", pmsg_error("device is not responding to program enable; check connection\n");
progname);
fflush(stderr); fflush(stderr);
return -1; return -1;
@ -576,20 +563,26 @@ static int ft245r_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
set_pin(pgm, PIN_AVR_MOSI, 0); set_pin(pgm, PIN_AVR_MOSI, 0);
if (get_pin(pgm, PIN_AVR_MISO) != 0) { if (get_pin(pgm, PIN_AVR_MISO) != 0) {
io_link_ok = false; io_link_ok = false;
avrdude_message(MSG_INFO, "MOSI->MISO 0 failed\n"); if(ovsigck) {
if (!ovsigck) pmsg_warning("MOSI->MISO 0 failed\n");
} else {
pmsg_error("MOSI->MISO 0 failed\n");
return -1; return -1;
}
} }
set_pin(pgm, PIN_AVR_MOSI, 1); set_pin(pgm, PIN_AVR_MOSI, 1);
if (get_pin(pgm, PIN_AVR_MISO) != 1) { if (get_pin(pgm, PIN_AVR_MISO) != 1) {
io_link_ok = false; io_link_ok = false;
avrdude_message(MSG_INFO, "MOSI->MISO 1 failed\n"); if(ovsigck) {
if (!ovsigck) pmsg_warning("MOSI->MISO 1 failed\n");
} else {
pmsg_error("MOSI->MISO 1 failed\n");
return -1; return -1;
}
} }
if (io_link_ok) if (io_link_ok)
avrdude_message(MSG_NOTICE2, "MOSI-MISO link present\n"); msg_notice2("MOSI-MISO link present\n");
/* keep TPIDATA high for 16 clock cycles */ /* keep TPIDATA high for 16 clock cycles */
set_pin(pgm, PIN_AVR_MOSI, 1); set_pin(pgm, PIN_AVR_MOSI, 1);
@ -606,7 +599,7 @@ static int ft245r_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
ft245r_tpi_tx(pgm, TPI_CMD_SLDCS | TPI_REG_TPIIR); ft245r_tpi_tx(pgm, TPI_CMD_SLDCS | TPI_REG_TPIIR);
ft245r_tpi_rx(pgm, &byte); ft245r_tpi_rx(pgm, &byte);
if (byte != 0x80) { if (byte != 0x80) {
avrdude_message(MSG_INFO, "TPIIR 0x%02x not correct\n", byte); msg_error("TPIIR 0x%02x not correct\n", byte);
return -1; return -1;
} }
} }
@ -769,8 +762,7 @@ static int ft245r_tpi_rx(const PROGRAMMER *pgm, uint8_t *bytep) {
while (m & res) while (m & res)
m <<= 1; m <<= 1;
if (m >= 0x10) { if (m >= 0x10) {
avrdude_message(MSG_INFO, "%s: start bit missing (res=0x%04x)\n", pmsg_error("start bit missing (res=0x%04x)\n", res);
__func__, res);
return -1; return -1;
} }
byte = parity = 0; byte = parity = 0;
@ -782,11 +774,11 @@ static int ft245r_tpi_rx(const PROGRAMMER *pgm, uint8_t *bytep) {
} }
m <<= 1; m <<= 1;
if (((res & m) != 0) != parity) { if (((res & m) != 0) != parity) {
avrdude_message(MSG_INFO, "%s: parity bit wrong\n", __func__); pmsg_error("parity bit wrong\n");
return -1; return -1;
} }
if (((res & (m << 1)) == 0) || ((res & (m << 2))) == 0) { if (((res & (m << 1)) == 0) || ((res & (m << 2))) == 0) {
avrdude_message(MSG_INFO, "%s: stop bits wrong\n", __func__); pmsg_error("stop bits wrong\n");
return -1; return -1;
} }
*bytep = (uint8_t) byte; *bytep = (uint8_t) byte;
@ -805,13 +797,13 @@ static int ft245r_cmd_tpi(const PROGRAMMER *pgm, const unsigned char *cmd,
if ((ret = ft245r_tpi_rx(pgm, &res[i])) < 0) if ((ret = ft245r_tpi_rx(pgm, &res[i])) < 0)
break; break;
if (verbose >= 2) { if (verbose >= 2) {
avrdude_message(MSG_NOTICE2, "%s: [ ", __func__); msg_notice2("%s: [ ", __func__);
for (i = 0; i < cmd_len; i++) for (i = 0; i < cmd_len; i++)
avrdude_message(MSG_NOTICE2, "%02X ", cmd[i]); msg_notice2("%02X ", cmd[i]);
avrdude_message(MSG_NOTICE2, "] [ "); msg_notice2("] [ ");
for(i = 0; i < res_len; i++) for(i = 0; i < res_len; i++)
avrdude_message(MSG_NOTICE2, "%02X ", res[i]); msg_notice2("%02X ", res[i]);
avrdude_message(MSG_NOTICE2, "]\n"); msg_notice2("]\n");
} }
pgm->pgm_led(pgm, OFF); pgm->pgm_led(pgm, OFF);
@ -845,20 +837,12 @@ static int ft245r_open(PROGRAMMER *pgm, const char *port) {
// read device string cut after 8 chars (max. length of serial number) // read device string cut after 8 chars (max. length of serial number)
if ((sscanf(port, "usb:%8s", device) != 1)) { if ((sscanf(port, "usb:%8s", device) != 1)) {
avrdude_message(MSG_NOTICE, pmsg_notice("ft245r_open(): no device identifier in portname, using default\n");
"%s: ft245r_open(): no device identifier in portname, using default\n",
progname);
pgm->usbsn = cache_string(""); pgm->usbsn = cache_string("");
devnum = 0; devnum = 0;
} else { } else {
if (strlen(device) == 8 ){ // serial number if (strlen(device) == 8 ){ // serial number
if (verbose >= 2) { pmsg_notice2("ft245r_open(): serial number parsed as: %s\n", device);
avrdude_message(MSG_INFO,
"%s: ft245r_open(): serial number parsed as: "
"%s\n",
progname,
device);
}
// copy serial number to pgm struct // copy serial number to pgm struct
pgm->usbsn = cache_string(device); pgm->usbsn = cache_string(device);
// and use first device with matching serial (should be unique) // and use first device with matching serial (should be unique)
@ -871,18 +855,13 @@ static int ft245r_open(PROGRAMMER *pgm, const char *port) {
if ((startptr==endptr) || (*endptr != '\0')) { if ((startptr==endptr) || (*endptr != '\0')) {
devnum = -1; devnum = -1;
} }
avrdude_message(MSG_INFO, pmsg_notice2("ft245r_open(): device number parsed as: %d\n", devnum);
"%s: ft245r_open(): device number parsed as: "
"%d\n",
progname,
devnum);
} }
} }
// if something went wrong before abort with helpful message // if something went wrong before abort with helpful message
if (devnum < 0) { if (devnum < 0) {
avrdude_message(MSG_INFO, "%s: ft245r_open(): invalid portname '%s': use^ 'ft[0-9]+' or serial number\n", pmsg_error("invalid portname '%s': use^ 'ft[0-9]+' or serial number\n", port);
progname,port);
return -1; return -1;
} }
@ -893,8 +872,7 @@ static int ft245r_open(PROGRAMMER *pgm, const char *port) {
if (usbpid) { if (usbpid) {
pid = *(int *)(ldata(usbpid)); pid = *(int *)(ldata(usbpid));
if (lnext(usbpid)) if (lnext(usbpid))
avrdude_message(MSG_INFO, "%s: Warning: using PID 0x%04x, ignoring remaining PIDs in list\n", pmsg_warning("using PID 0x%04x, ignoring remaining PIDs in list\n", pid);
progname, pid);
} else { } else {
pid = USB_DEVICE_FT245; pid = USB_DEVICE_FT245;
} }
@ -905,8 +883,7 @@ static int ft245r_open(PROGRAMMER *pgm, const char *port) {
pgm->usbsn[0]?pgm->usbsn:NULL, pgm->usbsn[0]?pgm->usbsn:NULL,
devnum); devnum);
if (rv) { if (rv) {
avrdude_message(MSG_INFO, "%s: can't open ftdi device: %s\n", pmsg_error("cannot open ftdi device: %s\n", ftdi_get_error_string(handle));
progname, ftdi_get_error_string(handle));
goto cleanup_no_usb; goto cleanup_no_usb;
} }
@ -936,15 +913,13 @@ static int ft245r_open(PROGRAMMER *pgm, const char *port) {
rv = ftdi_set_latency_timer(handle, 1); rv = ftdi_set_latency_timer(handle, 1);
if (rv) { if (rv) {
avrdude_message(MSG_INFO, "%s: unable to set latency timer to 1 (%s)\n", pmsg_error("unable to set latency timer to 1 (%s)\n", ftdi_get_error_string(handle));
progname, ftdi_get_error_string(handle));
goto cleanup; goto cleanup;
} }
rv = ftdi_set_bitmode(handle, ft245r_ddr, BITMODE_SYNCBB); // set Synchronous BitBang rv = ftdi_set_bitmode(handle, ft245r_ddr, BITMODE_SYNCBB); // set Synchronous BitBang
if (rv) { if (rv) {
avrdude_message(MSG_INFO, "%s: Synchronous BitBangMode is not supported (%s)\n", pmsg_error("synchronous BitBangMode is not supported (%s)\n", ftdi_get_error_string(handle));
progname, ftdi_get_error_string(handle));
goto cleanup; goto cleanup;
} }
@ -985,7 +960,7 @@ static void ft245r_close(PROGRAMMER * pgm) {
} }
static void ft245r_display(const PROGRAMMER *pgm, const char *p) { static void ft245r_display(const PROGRAMMER *pgm, const char *p) {
avrdude_message(MSG_INFO, "%sPin assignment : 0..7 = DBUS0..7\n",p);/* , 8..11 = GPIO0..3\n",p);*/ msg_info("%sPin assignment : 0..7 = DBUS0..7\n", p); // , 8..11 = GPIO0..3\n",p);
pgm_display_generic_mask(pgm, p, SHOW_ALL_PINS); pgm_display_generic_mask(pgm, p, SHOW_ALL_PINS);
} }
@ -1016,7 +991,7 @@ static void put_request(int addr, int bytes, int n) {
} else { } else {
p = malloc(sizeof(struct ft245r_request)); p = malloc(sizeof(struct ft245r_request));
if (!p) { if (!p) {
avrdude_message(MSG_INFO, "can't alloc memory\n"); msg_error("cannot alloc memory\n");
exit(1); exit(1);
} }
} }
@ -1065,7 +1040,7 @@ static int ft245r_paged_write_flash(const PROGRAMMER *pgm, const AVRPART *p, con
unsigned char cmd[4]; unsigned char cmd[4];
if(m->op[AVR_OP_LOADPAGE_LO] == NULL || m->op[AVR_OP_LOADPAGE_HI] == NULL) { if(m->op[AVR_OP_LOADPAGE_LO] == NULL || m->op[AVR_OP_LOADPAGE_HI] == NULL) {
avrdude_message(MSG_INFO, "AVR_OP_LOADPAGE_HI/LO command not defined for %s\n", p->desc); msg_error("AVR_OP_LOADPAGE_HI/LO command not defined for %s\n", p->desc);
return -1; return -1;
} }
@ -1163,7 +1138,7 @@ static int ft245r_paged_load_flash(const PROGRAMMER *pgm, const AVRPART *p, cons
unsigned char cmd[4]; unsigned char cmd[4];
if(m->op[AVR_OP_READ_LO] == NULL || m->op[AVR_OP_READ_HI] == NULL) { if(m->op[AVR_OP_READ_LO] == NULL || m->op[AVR_OP_READ_HI] == NULL) {
avrdude_message(MSG_INFO, "AVR_OP_READ_HI/LO command not defined for %s\n", p->desc); msg_error("AVR_OP_READ_HI/LO command not defined for %s\n", p->desc);
return -1; return -1;
} }

File diff suppressed because it is too large Load Diff

View File

@ -111,8 +111,7 @@ static int jtagmkI_resync(const PROGRAMMER *pgm, int maxtries, int signon);
static void jtagmkI_setup(PROGRAMMER * pgm) static void jtagmkI_setup(PROGRAMMER * pgm)
{ {
if ((pgm->cookie = malloc(sizeof(struct pdata))) == 0) { if ((pgm->cookie = malloc(sizeof(struct pdata))) == 0) {
avrdude_message(MSG_INFO, "%s: jtagmkI_setup(): Out of memory allocating private data\n", pmsg_error("out of memory allocating private data\n");
progname);
exit(1); exit(1);
} }
memset(pgm->cookie, 0, sizeof(struct pdata)); memset(pgm->cookie, 0, sizeof(struct pdata));
@ -143,65 +142,64 @@ static void jtagmkI_prmsg(const PROGRAMMER *pgm, unsigned char *data, size_t len
int i; int i;
if (verbose >= 4) { if (verbose >= 4) {
avrdude_message(MSG_TRACE, "Raw message:\n"); msg_trace("Raw message:\n");
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
avrdude_message(MSG_TRACE, "0x%02x ", data[i]); msg_trace("0x%02x ", data[i]);
if (i % 16 == 15) if (i % 16 == 15)
putc('\n', stderr); msg_trace("\n");
else else
putc(' ', stderr); msg_trace(" ");
} }
if (i % 16 != 0) if (i % 16 != 0)
putc('\n', stderr); msg_trace("\n");
} }
switch (data[0]) { switch (data[0]) {
case RESP_OK: case RESP_OK:
avrdude_message(MSG_INFO, "OK\n"); msg_info("OK\n");
break; break;
case RESP_FAILED: case RESP_FAILED:
avrdude_message(MSG_INFO, "FAILED\n"); msg_info("FAILED\n");
break; break;
case RESP_BREAK: case RESP_BREAK:
avrdude_message(MSG_INFO, "breakpoint hit\n"); msg_info("breakpoint hit\n");
break; break;
case RESP_INFO: case RESP_INFO:
avrdude_message(MSG_INFO, "IDR dirty\n"); msg_info("IDR dirty\n");
break; break;
case RESP_SYNC_ERROR: case RESP_SYNC_ERROR:
avrdude_message(MSG_INFO, "Synchronization lost\n"); msg_info("Synchronization lost\n");
break; break;
case RESP_SLEEP: case RESP_SLEEP:
avrdude_message(MSG_INFO, "sleep instruction hit\n"); msg_info("sleep instruction hit\n");
break; break;
case RESP_POWER: case RESP_POWER:
avrdude_message(MSG_INFO, "target power lost\n"); msg_info("target power lost\n");
default: default:
avrdude_message(MSG_INFO, "unknown message 0x%02x\n", data[0]); msg_info("unknown message 0x%02x\n", data[0]);
} }
putc('\n', stderr); msg_info("\n");
} }
static int jtagmkI_send(const PROGRAMMER *pgm, unsigned char *data, size_t len) { static int jtagmkI_send(const PROGRAMMER *pgm, unsigned char *data, size_t len) {
unsigned char *buf; unsigned char *buf;
avrdude_message(MSG_DEBUG, "\n%s: jtagmkI_send(): sending %u bytes\n", msg_debug("\n");
progname, (unsigned int)len); pmsg_debug("jtagmkI_send(): sending %u bytes\n", (unsigned int) len);
if ((buf = malloc(len + 2)) == NULL) if ((buf = malloc(len + 2)) == NULL)
{ {
avrdude_message(MSG_INFO, "%s: jtagmkI_send(): out of memory", pmsg_error("out of memory");
progname);
exit(1); exit(1);
} }
@ -210,8 +208,7 @@ static int jtagmkI_send(const PROGRAMMER *pgm, unsigned char *data, size_t len)
buf[len + 1] = ' '; /* EOP */ buf[len + 1] = ' '; /* EOP */
if (serial_send(&pgm->fd, buf, len + 2) != 0) { if (serial_send(&pgm->fd, buf, len + 2) != 0) {
avrdude_message(MSG_INFO, "%s: jtagmkI_send(): failed to send command to serial port\n", pmsg_error("unable to send command to serial port\n");
progname);
free(buf); free(buf);
return -1; return -1;
} }
@ -223,12 +220,12 @@ static int jtagmkI_send(const PROGRAMMER *pgm, unsigned char *data, size_t len)
static int jtagmkI_recv(const PROGRAMMER *pgm, unsigned char *buf, size_t len) { static int jtagmkI_recv(const PROGRAMMER *pgm, unsigned char *buf, size_t len) {
if (serial_recv(&pgm->fd, buf, len) != 0) { if (serial_recv(&pgm->fd, buf, len) != 0) {
avrdude_message(MSG_INFO, "\n%s: jtagmkI_recv(): failed to send command to serial port\n", msg_error("\n");
progname); pmsg_error("unable to send command to serial port\n");
return -1; return -1;
} }
if (verbose >= 3) { if (verbose >= 3) {
putc('\n', stderr); msg_debug("\n");
jtagmkI_prmsg(pgm, buf, len); jtagmkI_prmsg(pgm, buf, len);
} }
return 0; return 0;
@ -247,7 +244,7 @@ static int jtagmkI_resync(const PROGRAMMER *pgm, int maxtries, int signon) {
serial_recv_timeout = 200; serial_recv_timeout = 200;
avrdude_message(MSG_TRACE, "%s: jtagmkI_resync()\n", progname); pmsg_trace("jtagmkI_resync()\n");
jtagmkI_drain(pgm, 0); jtagmkI_drain(pgm, 0);
@ -255,17 +252,16 @@ static int jtagmkI_resync(const PROGRAMMER *pgm, int maxtries, int signon) {
/* Get the sign-on information. */ /* Get the sign-on information. */
buf[0] = CMD_GET_SYNC; buf[0] = CMD_GET_SYNC;
avrdude_message(MSG_NOTICE2, "%s: jtagmkI_resync(): Sending sync command: ", pmsg_notice2("jtagmkI_resync(): sending sync command: ");
progname);
if (serial_send(&pgm->fd, buf, 1) != 0) { if (serial_send(&pgm->fd, buf, 1) != 0) {
avrdude_message(MSG_INFO, "\n%s: jtagmkI_resync(): failed to send command to serial port\n", msg_error("\n");
progname); pmsg_error("unable to send command to serial port\n");
serial_recv_timeout = otimeout; serial_recv_timeout = otimeout;
return -1; return -1;
} }
if (serial_recv(&pgm->fd, resp, 1) == 0 && resp[0] == RESP_OK) { if (serial_recv(&pgm->fd, resp, 1) == 0 && resp[0] == RESP_OK) {
avrdude_message(MSG_NOTICE2, "got RESP_OK\n"); msg_notice2("got RESP_OK\n");
break; break;
} }
@ -284,25 +280,23 @@ static int jtagmkI_resync(const PROGRAMMER *pgm, int maxtries, int signon) {
buf[1] = 'E'; buf[1] = 'E';
buf[2] = ' '; buf[2] = ' ';
buf[3] = ' '; buf[3] = ' ';
avrdude_message(MSG_NOTICE2, "%s: jtagmkI_resync(): Sending sign-on command: ", pmsg_notice2("jtagmkI_resync(): sending sign-on command: ");
progname);
if (serial_send(&pgm->fd, buf, 4) != 0) { if (serial_send(&pgm->fd, buf, 4) != 0) {
avrdude_message(MSG_INFO, "\n%s: jtagmkI_resync(): failed to send command to serial port\n", msg_error("\n");
progname); pmsg_error("unable to send command to serial port\n");
serial_recv_timeout = otimeout; serial_recv_timeout = otimeout;
return -1; return -1;
} }
if (serial_recv(&pgm->fd, resp, 9) == 0 && resp[0] == RESP_OK) { if (serial_recv(&pgm->fd, resp, 9) == 0 && resp[0] == RESP_OK) {
avrdude_message(MSG_NOTICE2, "got RESP_OK\n"); msg_notice2("got RESP_OK\n");
break; break;
} }
} }
} }
if (tries >= maxtries) { if (tries >= maxtries) {
avrdude_message(MSG_NOTICE2, "%s: jtagmkI_resync(): " pmsg_notice2("jtagmkI_resync(): "
"timeout/error communicating with programmer\n", "timeout/error communicating with programmer\n");
progname);
serial_recv_timeout = otimeout; serial_recv_timeout = otimeout;
return -1; return -1;
} }
@ -321,17 +315,14 @@ static int jtagmkI_getsync(const PROGRAMMER *pgm) {
jtagmkI_drain(pgm, 0); jtagmkI_drain(pgm, 0);
avrdude_message(MSG_NOTICE2, "%s: jtagmkI_getsync(): Sending sign-on command: ", pmsg_notice2("jtagmkI_getsync(): sending sign-on command; ");
progname);
buf[0] = CMD_GET_SIGNON; buf[0] = CMD_GET_SIGNON;
jtagmkI_send(pgm, buf, 1); jtagmkI_send(pgm, buf, 1);
if (jtagmkI_recv(pgm, resp, 9) < 0) if (jtagmkI_recv(pgm, resp, 9) < 0)
return -1; return -1;
if (verbose >= 2) { resp[8] = '\0';
resp[8] = '\0'; msg_notice2("got %s\n", resp + 1);
avrdude_message(MSG_NOTICE2, "got %s\n", resp + 1);
}
return 0; return 0;
} }
@ -343,21 +334,16 @@ static int jtagmkI_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) {
unsigned char buf[1], resp[2]; unsigned char buf[1], resp[2];
buf[0] = CMD_CHIP_ERASE; buf[0] = CMD_CHIP_ERASE;
avrdude_message(MSG_NOTICE2, "%s: jtagmkI_chip_erase(): Sending chip erase command: ", pmsg_notice2("jtagmkI_chip_erase(): sending chip erase command: ");
progname);
jtagmkI_send(pgm, buf, 1); jtagmkI_send(pgm, buf, 1);
if (jtagmkI_recv(pgm, resp, 2) < 0) if (jtagmkI_recv(pgm, resp, 2) < 0)
return -1; return -1;
if (resp[0] != RESP_OK) { if (resp[0] != RESP_OK) {
if (verbose >= 2) msg_notice2("\n");
putc('\n', stderr); pmsg_error("timeout/error communicating with programmer (resp %c)\n", resp[0]);
avrdude_message(MSG_INFO, "%s: jtagmkI_chip_erase(): "
"timeout/error communicating with programmer (resp %c)\n",
progname, resp[0]);
return -1; return -1;
} else { } else {
if (verbose == 2) msg_notice2("OK\n");
avrdude_message(MSG_NOTICE2, "OK\n");
} }
pgm->initialize(pgm, p); pgm->initialize(pgm, p);
@ -389,22 +375,17 @@ static void jtagmkI_set_devdescr(const PROGRAMMER *pgm, const AVRPART *p) {
} }
} }
avrdude_message(MSG_NOTICE2, "%s: jtagmkI_set_devdescr(): " pmsg_notice2("jtagmkI_set_devdescr(): "
"Sending set device descriptor command: ", "Sending set device descriptor command: ");
progname);
jtagmkI_send(pgm, (unsigned char *)&sendbuf, sizeof(sendbuf)); jtagmkI_send(pgm, (unsigned char *)&sendbuf, sizeof(sendbuf));
if (jtagmkI_recv(pgm, resp, 2) < 0) if (jtagmkI_recv(pgm, resp, 2) < 0)
return; return;
if (resp[0] != RESP_OK) { if (resp[0] != RESP_OK) {
if (verbose >= 2) msg_notice2("\n");
putc('\n', stderr); pmsg_error("timeout/error communicating with programmer (resp %c)\n", resp[0]);
avrdude_message(MSG_INFO, "%s: jtagmkI_set_devdescr(): "
"timeout/error communicating with programmer (resp %c)\n",
progname, resp[0]);
} else { } else {
if (verbose == 2) msg_notice2("OK\n");
avrdude_message(MSG_NOTICE2, "OK\n");
} }
} }
@ -415,22 +396,17 @@ static int jtagmkI_reset(const PROGRAMMER *pgm) {
unsigned char buf[1], resp[2]; unsigned char buf[1], resp[2];
buf[0] = CMD_RESET; buf[0] = CMD_RESET;
avrdude_message(MSG_NOTICE2, "%s: jtagmkI_reset(): Sending reset command: ", pmsg_notice2("jtagmkI_reset(): sending reset command: ");
progname);
jtagmkI_send(pgm, buf, 1); jtagmkI_send(pgm, buf, 1);
if (jtagmkI_recv(pgm, resp, 2) < 0) if (jtagmkI_recv(pgm, resp, 2) < 0)
return -1; return -1;
if (resp[0] != RESP_OK) { if (resp[0] != RESP_OK) {
if (verbose >= 2) msg_notice2("\n");
putc('\n', stderr); pmsg_error("timeout/error communicating with programmer (resp %c)\n", resp[0]);
avrdude_message(MSG_INFO, "%s: jtagmkI_reset(): "
"timeout/error communicating with programmer (resp %c)\n",
progname, resp[0]);
return -1; return -1;
} else { } else {
if (verbose == 2) msg_notice2("OK\n");
avrdude_message(MSG_NOTICE2, "OK\n");
} }
return 0; return 0;
@ -448,23 +424,18 @@ static int jtagmkI_program_enable(const PROGRAMMER *pgm) {
return 0; return 0;
buf[0] = CMD_ENTER_PROGMODE; buf[0] = CMD_ENTER_PROGMODE;
avrdude_message(MSG_NOTICE2, "%s: jtagmkI_program_enable(): " pmsg_notice2("jtagmkI_program_enable(): "
"Sending enter progmode command: ", "Sending enter progmode command: ");
progname);
jtagmkI_send(pgm, buf, 1); jtagmkI_send(pgm, buf, 1);
if (jtagmkI_recv(pgm, resp, 2) < 0) if (jtagmkI_recv(pgm, resp, 2) < 0)
return -1; return -1;
if (resp[0] != RESP_OK) { if (resp[0] != RESP_OK) {
if (verbose >= 2) msg_notice2("\n");
putc('\n', stderr); pmsg_error("timeout/error communicating with programmer (resp %c)\n", resp[0]);
avrdude_message(MSG_INFO, "%s: jtagmkI_program_enable(): "
"timeout/error communicating with programmer (resp %c)\n",
progname, resp[0]);
return -1; return -1;
} else { } else {
if (verbose == 2) msg_notice2("OK\n");
avrdude_message(MSG_NOTICE2, "OK\n");
} }
PDATA(pgm)->prog_enabled = 1; PDATA(pgm)->prog_enabled = 1;
@ -480,23 +451,17 @@ static int jtagmkI_program_disable(const PROGRAMMER *pgm) {
if (pgm->fd.ifd != -1) { if (pgm->fd.ifd != -1) {
buf[0] = CMD_LEAVE_PROGMODE; buf[0] = CMD_LEAVE_PROGMODE;
avrdude_message(MSG_NOTICE2, "%s: jtagmkI_program_disable(): " pmsg_notice2("jtagmkI_program_disable(): sending leave progmode command: ");
"Sending leave progmode command: ",
progname);
jtagmkI_send(pgm, buf, 1); jtagmkI_send(pgm, buf, 1);
if (jtagmkI_recv(pgm, resp, 2) < 0) if (jtagmkI_recv(pgm, resp, 2) < 0)
return -1; return -1;
if (resp[0] != RESP_OK) { if (resp[0] != RESP_OK) {
if (verbose >= 2) msg_notice2("\n");
putc('\n', stderr); pmsg_error("timeout/error communicating with programmer (resp %c)\n", resp[0]);
avrdude_message(MSG_INFO, "%s: jtagmkI_program_disable(): "
"timeout/error communicating with programmer (resp %c)\n",
progname, resp[0]);
return -1; return -1;
} else { } else {
if (verbose == 2) msg_notice2("OK\n");
avrdude_message(MSG_NOTICE2, "OK\n");
} }
} }
PDATA(pgm)->prog_enabled = 0; PDATA(pgm)->prog_enabled = 0;
@ -524,24 +489,20 @@ static int jtagmkI_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
unsigned char b; unsigned char b;
if (!(p->prog_modes & (PM_JTAGmkI | PM_JTAG))) { if (!(p->prog_modes & (PM_JTAGmkI | PM_JTAG))) {
avrdude_message(MSG_INFO, "%s: jtagmkI_initialize(): part %s has no JTAG interface\n", pmsg_error("part %s has no JTAG interface\n", p->desc);
progname, p->desc);
return -1; return -1;
} }
if (!(p->prog_modes & PM_JTAGmkI)) if (!(p->prog_modes & PM_JTAGmkI))
avrdude_message(MSG_INFO, "%s: jtagmkI_initialize(): warning part %s has JTAG interface, but may be too new\n", pmsg_warning("part %s has JTAG interface, but may be too new\n", p->desc);
progname, p->desc);
jtagmkI_drain(pgm, 0); jtagmkI_drain(pgm, 0);
if ((serdev->flags & SERDEV_FL_CANSETSPEED) && PDATA(pgm)->initial_baudrate != pgm->baudrate) { if ((serdev->flags & SERDEV_FL_CANSETSPEED) && PDATA(pgm)->initial_baudrate != pgm->baudrate) {
if ((b = jtagmkI_get_baud(pgm->baudrate)) == 0) { if ((b = jtagmkI_get_baud(pgm->baudrate)) == 0) {
avrdude_message(MSG_INFO, "%s: jtagmkI_initialize(): unsupported baudrate %d\n", pmsg_error("unsupported baudrate %d\n", pgm->baudrate);
progname, pgm->baudrate);
} else { } else {
avrdude_message(MSG_NOTICE2, "%s: jtagmkI_initialize(): " pmsg_notice2("jtagmkI_initialize(): "
"trying to set baudrate to %d\n", "trying to set baudrate to %d\n", pgm->baudrate);
progname, pgm->baudrate);
if (jtagmkI_setparm(pgm, PARM_BITRATE, b) == 0) { if (jtagmkI_setparm(pgm, PARM_BITRATE, b) == 0) {
PDATA(pgm)->initial_baudrate = pgm->baudrate; /* don't adjust again later */ PDATA(pgm)->initial_baudrate = pgm->baudrate; /* don't adjust again later */
serial_setparams(&pgm->fd, pgm->baudrate, SERIAL_8N1); serial_setparams(&pgm->fd, pgm->baudrate, SERIAL_8N1);
@ -550,9 +511,8 @@ static int jtagmkI_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
} }
if (pgm->bitclock != 0.0) { if (pgm->bitclock != 0.0) {
avrdude_message(MSG_NOTICE2, "%s: jtagmkI_initialize(): " pmsg_notice2("jtagmkI_initialize(): "
"trying to set JTAG clock period to %.1f us\n", "trying to set JTAG clock period to %.1f us\n", pgm->bitclock);
progname, pgm->bitclock);
if (jtagmkI_set_sck_period(pgm, pgm->bitclock) != 0) if (jtagmkI_set_sck_period(pgm, pgm->bitclock) != 0)
return -1; return -1;
} }
@ -562,14 +522,10 @@ static int jtagmkI_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
if (jtagmkI_recv(pgm, resp, 5) < 0) if (jtagmkI_recv(pgm, resp, 5) < 0)
return -1; return -1;
if (resp[0] != RESP_OK) { if (resp[0] != RESP_OK) {
if (verbose >= 2) msg_notice2("\n");
putc('\n', stderr); pmsg_warning("timeout/error communicating with programmer (resp %c)\n", resp[0]);
avrdude_message(MSG_INFO, "%s: jtagmkI_initialize(): "
"timeout/error communicating with programmer (resp %c)\n",
progname, resp[0]);
} else { } else {
if (verbose == 2) msg_notice2("OK\n");
avrdude_message(MSG_NOTICE2, "OK\n");
} }
/* /*
@ -584,13 +540,11 @@ static int jtagmkI_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
free(PDATA(pgm)->flash_pagecache); free(PDATA(pgm)->flash_pagecache);
free(PDATA(pgm)->eeprom_pagecache); free(PDATA(pgm)->eeprom_pagecache);
if ((PDATA(pgm)->flash_pagecache = malloc(PDATA(pgm)->flash_pagesize)) == NULL) { if ((PDATA(pgm)->flash_pagecache = malloc(PDATA(pgm)->flash_pagesize)) == NULL) {
avrdude_message(MSG_INFO, "%s: jtagmkI_initialize(): Out of memory\n", pmsg_error("out of memory\n");
progname);
return -1; return -1;
} }
if ((PDATA(pgm)->eeprom_pagecache = malloc(PDATA(pgm)->eeprom_pagesize)) == NULL) { if ((PDATA(pgm)->eeprom_pagecache = malloc(PDATA(pgm)->eeprom_pagesize)) == NULL) {
avrdude_message(MSG_INFO, "%s: jtagmkI_initialize(): Out of memory\n", pmsg_error("out of memory\n");
progname);
free(PDATA(pgm)->flash_pagecache); free(PDATA(pgm)->flash_pagecache);
return -1; return -1;
} }
@ -603,9 +557,8 @@ static int jtagmkI_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
if (jtagmkI_read_byte(pgm, p, &hfuse, 1, &b) < 0) if (jtagmkI_read_byte(pgm, p, &hfuse, 1, &b) < 0)
return -1; return -1;
if ((b & OCDEN) != 0) if ((b & OCDEN) != 0)
avrdude_message(MSG_INFO, "%s: jtagmkI_initialize(): warning: OCDEN fuse not programmed, " pmsg_warning("OCDEN fuse not programmed, "
"single-byte EEPROM updates not possible\n", "single-byte EEPROM updates not possible\n");
progname);
return 0; return 0;
} }
@ -630,7 +583,7 @@ static int jtagmkI_open(PROGRAMMER *pgm, const char *port)
{ {
size_t i; size_t i;
avrdude_message(MSG_NOTICE2, "%s: jtagmkI_open()\n", progname); pmsg_notice2("jtagmkI_open()\n");
strcpy(pgm->port, port); strcpy(pgm->port, port);
PDATA(pgm)->initial_baudrate = -1L; PDATA(pgm)->initial_baudrate = -1L;
@ -639,8 +592,7 @@ static int jtagmkI_open(PROGRAMMER *pgm, const char *port)
union pinfo pinfo; union pinfo pinfo;
pinfo.serialinfo.baud = baudtab[i].baud; pinfo.serialinfo.baud = baudtab[i].baud;
pinfo.serialinfo.cflags = SERIAL_8N1; pinfo.serialinfo.cflags = SERIAL_8N1;
avrdude_message(MSG_NOTICE2, "%s: jtagmkI_open(): trying to sync at baud rate %ld:\n", pmsg_notice2("jtagmkI_open(): trying to sync at baud rate %ld:\n", pinfo.serialinfo.baud);
progname, pinfo.serialinfo.baud);
if (serial_open(port, pinfo, &pgm->fd)==-1) { if (serial_open(port, pinfo, &pgm->fd)==-1) {
return -1; return -1;
} }
@ -652,15 +604,14 @@ static int jtagmkI_open(PROGRAMMER *pgm, const char *port)
if (jtagmkI_getsync(pgm) == 0) { if (jtagmkI_getsync(pgm) == 0) {
PDATA(pgm)->initial_baudrate = baudtab[i].baud; PDATA(pgm)->initial_baudrate = baudtab[i].baud;
avrdude_message(MSG_NOTICE2, "%s: jtagmkI_open(): succeeded\n", progname); pmsg_notice2("jtagmkI_open(): succeeded\n");
return 0; return 0;
} }
serial_close(&pgm->fd); serial_close(&pgm->fd);
} }
avrdude_message(MSG_INFO, "%s: jtagmkI_open(): failed to synchronize to ICE\n", pmsg_error("unable to synchronize to ICE\n");
progname);
pgm->fd.ifd = -1; pgm->fd.ifd = -1;
return -1; return -1;
@ -671,7 +622,7 @@ static void jtagmkI_close(PROGRAMMER * pgm)
{ {
unsigned char b; unsigned char b;
avrdude_message(MSG_NOTICE2, "%s: jtagmkI_close()\n", progname); pmsg_notice2("jtagmkI_close()\n");
/* /*
* Revert baud rate to what it used to be when we started. This * Revert baud rate to what it used to be when we started. This
@ -680,12 +631,10 @@ static void jtagmkI_close(PROGRAMMER * pgm)
*/ */
if ((serdev->flags & SERDEV_FL_CANSETSPEED) && PDATA(pgm)->initial_baudrate != pgm->baudrate) { if ((serdev->flags & SERDEV_FL_CANSETSPEED) && PDATA(pgm)->initial_baudrate != pgm->baudrate) {
if ((b = jtagmkI_get_baud(PDATA(pgm)->initial_baudrate)) == 0) { if ((b = jtagmkI_get_baud(PDATA(pgm)->initial_baudrate)) == 0) {
avrdude_message(MSG_INFO, "%s: jtagmkI_close(): unsupported baudrate %d\n", pmsg_error("unsupported baudrate %d\n", PDATA(pgm)->initial_baudrate);
progname, PDATA(pgm)->initial_baudrate);
} else { } else {
avrdude_message(MSG_NOTICE2, "%s: jtagmkI_close(): " pmsg_notice2("jtagmkI_close(): "
"trying to set baudrate to %d\n", "trying to set baudrate to %d\n", PDATA(pgm)->initial_baudrate);
progname, PDATA(pgm)->initial_baudrate);
if (jtagmkI_setparm(pgm, PARM_BITRATE, b) == 0) { if (jtagmkI_setparm(pgm, PARM_BITRATE, b) == 0) {
serial_setparams(&pgm->fd, pgm->baudrate, SERIAL_8N1); serial_setparams(&pgm->fd, pgm->baudrate, SERIAL_8N1);
} }
@ -712,23 +661,21 @@ static int jtagmkI_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const AV
long otimeout = serial_recv_timeout; long otimeout = serial_recv_timeout;
#define MAXTRIES 3 #define MAXTRIES 3
avrdude_message(MSG_NOTICE2, "%s: jtagmkI_paged_write(.., %s, %d, %d)\n", pmsg_notice2("jtagmkI_paged_write(.., %s, %d, %d)\n", m->desc, page_size, n_bytes);
progname, m->desc, page_size, n_bytes);
if (jtagmkI_program_enable(pgm) < 0) if (jtagmkI_program_enable(pgm) < 0)
return -1; return -1;
if (page_size == 0) page_size = 256; if (page_size == 0)
page_size = 256;
if (page_size > 256) { if (page_size > 256) {
avrdude_message(MSG_INFO, "%s: jtagmkI_paged_write(): page size %d too large\n", pmsg_error("page size %d too large\n", page_size);
progname, page_size);
return -1; return -1;
} }
if ((datacmd = malloc(page_size + 1)) == NULL) { if ((datacmd = malloc(page_size + 1)) == NULL) {
avrdude_message(MSG_INFO, "%s: jtagmkI_paged_write(): Out of memory\n", pmsg_error("out of memory\n");
progname);
return -1; return -1;
} }
@ -751,8 +698,7 @@ static int jtagmkI_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const AV
again: again:
if (tries != 0 && jtagmkI_resync(pgm, 2000, 0) < 0) { if (tries != 0 && jtagmkI_resync(pgm, 2000, 0) < 0) {
avrdude_message(MSG_INFO, "%s: jtagmkI_paged_write(): sync loss, retries exhausted\n", pmsg_error("sync loss, retries exhausted\n");
progname);
return -1; return -1;
} }
@ -760,9 +706,8 @@ static int jtagmkI_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const AV
block_size = n_bytes; block_size = n_bytes;
else else
block_size = page_size; block_size = page_size;
avrdude_message(MSG_DEBUG, "%s: jtagmkI_paged_write(): " pmsg_debug("jtagmkI_paged_write(): "
"block_size at addr %d is %d\n", "block_size at addr %d is %d\n", addr, block_size);
progname, addr, block_size);
/* We always write full pages. */ /* We always write full pages. */
send_size = page_size; send_size = page_size;
@ -774,27 +719,22 @@ static int jtagmkI_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const AV
u32_to_b3(cmd + 3, addr); u32_to_b3(cmd + 3, addr);
} }
avrdude_message(MSG_NOTICE2, "%s: jtagmkI_paged_write(): " pmsg_notice2("jtagmkI_paged_write(): "
"Sending write memory command: ", "sending write memory command: ");
progname);
/* First part, send the write command. */ /* First part, send the write command. */
jtagmkI_send(pgm, cmd, 6); jtagmkI_send(pgm, cmd, 6);
if (jtagmkI_recv(pgm, resp, 1) < 0) if (jtagmkI_recv(pgm, resp, 1) < 0)
return -1; return -1;
if (resp[0] != RESP_OK) { if (resp[0] != RESP_OK) {
if (verbose >= 2) msg_notice2("\n");
putc('\n', stderr); pmsg_warning("timeout/error communicating with programmer (resp %c)\n", resp[0]);
avrdude_message(MSG_INFO, "%s: jtagmkI_paged_write(): "
"timeout/error communicating with programmer (resp %c)\n",
progname, resp[0]);
if (tries++ < MAXTRIES) if (tries++ < MAXTRIES)
goto again; goto again;
serial_recv_timeout = otimeout; serial_recv_timeout = otimeout;
return -1; return -1;
} else { } else {
if (verbose == 2) msg_notice2("OK\n");
avrdude_message(MSG_NOTICE2, "OK\n");
} }
/* /*
@ -812,18 +752,14 @@ static int jtagmkI_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const AV
if (jtagmkI_recv(pgm, resp, 2) < 0) if (jtagmkI_recv(pgm, resp, 2) < 0)
return -1; return -1;
if (resp[1] != RESP_OK) { if (resp[1] != RESP_OK) {
if (verbose >= 2) msg_notice2("\n");
putc('\n', stderr); pmsg_warning("timeout/error communicating with programmer (resp %c)\n", resp[0]);
avrdude_message(MSG_INFO, "%s: jtagmkI_paged_write(): "
"timeout/error communicating with programmer (resp %c)\n",
progname, resp[0]);
if (tries++ < MAXTRIES) if (tries++ < MAXTRIES)
goto again; goto again;
serial_recv_timeout = otimeout; serial_recv_timeout = otimeout;
return -1; return -1;
} else { } else {
if (verbose == 2) msg_notice2("OK\n");
avrdude_message(MSG_NOTICE2, "OK\n");
} }
} }
@ -844,8 +780,7 @@ static int jtagmkI_paged_load(const PROGRAMMER *pgm, const AVRPART *p, const AVR
long otimeout = serial_recv_timeout; long otimeout = serial_recv_timeout;
#define MAXTRIES 3 #define MAXTRIES 3
avrdude_message(MSG_NOTICE2, "%s: jtagmkI_paged_load(.., %s, %d, %d)\n", pmsg_notice2("jtagmkI_paged_load(.., %s, %d, %d)\n", m->desc, page_size, n_bytes);
progname, m->desc, page_size, n_bytes);
if (jtagmkI_program_enable(pgm) < 0) if (jtagmkI_program_enable(pgm) < 0)
return -1; return -1;
@ -861,8 +796,7 @@ static int jtagmkI_paged_load(const PROGRAMMER *pgm, const AVRPART *p, const AVR
} }
if (page_size > (is_flash? 512: 256)) { if (page_size > (is_flash? 512: 256)) {
avrdude_message(MSG_INFO, "%s: jtagmkI_paged_load(): page size %d too large\n", pmsg_error("page size %d too large\n", page_size);
progname, page_size);
return -1; return -1;
} }
@ -871,8 +805,7 @@ static int jtagmkI_paged_load(const PROGRAMMER *pgm, const AVRPART *p, const AVR
tries = 0; tries = 0;
again: again:
if (tries != 0 && jtagmkI_resync(pgm, 2000, 0) < 0) { if (tries != 0 && jtagmkI_resync(pgm, 2000, 0) < 0) {
avrdude_message(MSG_INFO, "%s: jtagmkI_paged_load(): sync loss, retries exhausted\n", pmsg_error("sync loss, retries exhausted\n");
progname);
return -1; return -1;
} }
@ -880,9 +813,8 @@ static int jtagmkI_paged_load(const PROGRAMMER *pgm, const AVRPART *p, const AVR
block_size = n_bytes; block_size = n_bytes;
else else
block_size = page_size; block_size = page_size;
avrdude_message(MSG_DEBUG, "%s: jtagmkI_paged_load(): " pmsg_debug("jtagmkI_paged_load(): "
"block_size at addr %d is %d\n", "block_size at addr %d is %d\n", addr, block_size);
progname, addr, block_size);
if (is_flash) { if (is_flash) {
read_size = 2 * ((block_size + 1) / 2); /* round up */ read_size = 2 * ((block_size + 1) / 2); /* round up */
@ -894,27 +826,22 @@ static int jtagmkI_paged_load(const PROGRAMMER *pgm, const AVRPART *p, const AVR
u32_to_b3(cmd + 3, addr); u32_to_b3(cmd + 3, addr);
} }
avrdude_message(MSG_NOTICE2, "%s: jtagmkI_paged_load(): Sending read memory command: ", pmsg_notice2("jtagmkI_paged_load(): sending read memory command: ");
progname);
jtagmkI_send(pgm, cmd, 6); jtagmkI_send(pgm, cmd, 6);
if (jtagmkI_recv(pgm, resp, read_size + 3) < 0) if (jtagmkI_recv(pgm, resp, read_size + 3) < 0)
return -1; return -1;
if (resp[read_size + 3 - 1] != RESP_OK) { if (resp[read_size + 3 - 1] != RESP_OK) {
if (verbose >= 2) msg_notice2("\n");
putc('\n', stderr); pmsg_warning("timeout/error communicating with programmer (resp %c)\n", resp[read_size + 3 - 1]);
avrdude_message(MSG_INFO, "%s: jtagmkI_paged_load(): "
"timeout/error communicating with programmer (resp %c)\n",
progname, resp[read_size + 3 - 1]);
if (tries++ < MAXTRIES) if (tries++ < MAXTRIES)
goto again; goto again;
serial_recv_timeout = otimeout; serial_recv_timeout = otimeout;
return -1; return -1;
} else { } else {
if (verbose == 2) msg_notice2("OK\n");
avrdude_message(MSG_NOTICE2, "OK\n");
} }
memcpy(m->buf + addr, resp + 1, block_size); memcpy(m->buf + addr, resp + 1, block_size);
@ -935,8 +862,7 @@ static int jtagmkI_read_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVRM
int respsize = 3 + 1; int respsize = 3 + 1;
int is_flash = 0; int is_flash = 0;
avrdude_message(MSG_NOTICE2, "%s: jtagmkI_read_byte(.., %s, 0x%lx, ...)\n", pmsg_notice2("jtagmkI_read_byte(.., %s, 0x%lx, ...)\n", mem->desc, addr);
progname, mem->desc, addr);
if (jtagmkI_program_enable(pgm) < 0) if (jtagmkI_program_enable(pgm) < 0)
return -1; return -1;
@ -1017,15 +943,11 @@ static int jtagmkI_read_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVRM
return -1; return -1;
if (resp[respsize - 1] != RESP_OK) { if (resp[respsize - 1] != RESP_OK) {
if (verbose >= 2) msg_notice2("\n");
putc('\n', stderr); pmsg_error("timeout/error communicating with programmer (resp %c)\n", resp[respsize - 1]);
avrdude_message(MSG_INFO, "%s: jtagmkI_read_byte(): "
"timeout/error communicating with programmer (resp %c)\n",
progname, resp[respsize - 1]);
return -1; return -1;
} else { } else {
if (verbose == 2) msg_notice2("OK\n");
avrdude_message(MSG_NOTICE2, "OK\n");
} }
if (pagesize) { if (pagesize) {
@ -1048,8 +970,7 @@ static int jtagmkI_write_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVR
unsigned char resp[1], writedata; unsigned char resp[1], writedata;
int len, need_progmode = 1, need_dummy_read = 0; int len, need_progmode = 1, need_dummy_read = 0;
avrdude_message(MSG_NOTICE2, "%s: jtagmkI_write_byte(.., %s, 0x%lx, ...)\n", pmsg_notice2("jtagmkI_write_byte(.., %s, 0x%lx, ...)\n", mem->desc, addr);
progname, mem->desc, addr);
writedata = data; writedata = data;
cmd[0] = CMD_WRITE_MEM; cmd[0] = CMD_WRITE_MEM;
@ -1096,7 +1017,7 @@ static int jtagmkI_write_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVR
if (cmd[1] == MTYPE_SPM) { if (cmd[1] == MTYPE_SPM) {
/* /*
* Flash is word-addressed, but we cannot handle flash anyway * Flash is word-addressed, but we cannot handle flash anyway
* here, as it needs to be written one page at a time... * here, as it needs to be written one page at a time ...
*/ */
u32_to_b3(cmd + 3, addr / 2); u32_to_b3(cmd + 3, addr / 2);
} else { } else {
@ -1107,15 +1028,11 @@ static int jtagmkI_write_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVR
if (jtagmkI_recv(pgm, resp, 1) < 0) if (jtagmkI_recv(pgm, resp, 1) < 0)
return -1; return -1;
if (resp[0] != RESP_OK) { if (resp[0] != RESP_OK) {
if (verbose >= 2) msg_notice2("\n");
putc('\n', stderr); pmsg_error("timeout/error communicating with programmer (resp %c)\n", resp[0]);
avrdude_message(MSG_INFO, "%s: jtagmkI_write_byte(): "
"timeout/error communicating with programmer (resp %c)\n",
progname, resp[0]);
return -1; return -1;
} else { } else {
if (verbose == 2) msg_notice2("OK\n");
avrdude_message(MSG_NOTICE2, "OK\n");
} }
/* Now, send the data buffer. */ /* Now, send the data buffer. */
@ -1137,15 +1054,11 @@ static int jtagmkI_write_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVR
if (jtagmkI_recv(pgm, resp, 1) < 0) if (jtagmkI_recv(pgm, resp, 1) < 0)
return -1; return -1;
if (resp[0] != RESP_OK) { if (resp[0] != RESP_OK) {
if (verbose >= 2) msg_notice2("\n");
putc('\n', stderr); pmsg_error("timeout/error communicating with programmer (resp %c)\n", resp[0]);
avrdude_message(MSG_INFO, "%s: jtagmkI_write_byte(): "
"timeout/error communicating with programmer (resp %c)\n",
progname, resp[0]);
return -1; return -1;
} else { } else {
if (verbose == 2) msg_notice2("OK\n");
avrdude_message(MSG_NOTICE2, "OK\n");
} }
if(need_dummy_read) if(need_dummy_read)
@ -1190,35 +1103,26 @@ static int jtagmkI_getparm(const PROGRAMMER *pgm, const unsigned char parm,
{ {
unsigned char buf[2], resp[3]; unsigned char buf[2], resp[3];
avrdude_message(MSG_NOTICE2, "%s: jtagmkI_getparm()\n", progname); pmsg_notice2("jtagmkI_getparm()\n");
buf[0] = CMD_GET_PARAM; buf[0] = CMD_GET_PARAM;
buf[1] = parm; buf[1] = parm;
if (verbose >= 2) pmsg_notice2("jtagmkI_getparm(): "
avrdude_message(MSG_NOTICE2, "%s: jtagmkI_getparm(): " "Sending get parameter command (parm 0x%02x): ", parm);
"Sending get parameter command (parm 0x%02x): ",
progname, parm);
jtagmkI_send(pgm, buf, 2); jtagmkI_send(pgm, buf, 2);
if (jtagmkI_recv(pgm, resp, 3) < 0) if (jtagmkI_recv(pgm, resp, 3) < 0)
return -1; return -1;
if (resp[0] != RESP_OK) { if (resp[0] != RESP_OK) {
if (verbose >= 2) msg_notice2("\n");
putc('\n', stderr); pmsg_error("timeout/error communicating with programmer (resp %c)\n", resp[0]);
avrdude_message(MSG_INFO, "%s: jtagmkI_getparm(): "
"timeout/error communicating with programmer (resp %c)\n",
progname, resp[0]);
return -1; return -1;
} else if (resp[2] != RESP_OK) { } else if (resp[2] != RESP_OK) {
if (verbose >= 2) msg_notice2("\n");
putc('\n', stderr); pmsg_error("unknown parameter 0x%02x\n", parm);
avrdude_message(MSG_INFO, "%s: jtagmkI_getparm(): "
"unknown parameter 0x%02x\n",
progname, parm);
return -1; return -1;
} else { } else {
if (verbose == 2) msg_notice2("OK, value 0x%02x\n", resp[1]);
avrdude_message(MSG_NOTICE2, "OK, value 0x%02x\n", resp[1]);
} }
*value = resp[1]; *value = resp[1];
@ -1234,27 +1138,22 @@ static int jtagmkI_setparm(const PROGRAMMER *pgm, unsigned char parm,
{ {
unsigned char buf[3], resp[2]; unsigned char buf[3], resp[2];
avrdude_message(MSG_NOTICE2, "%s: jtagmkI_setparm()\n", progname); pmsg_notice2("jtagmkI_setparm()\n");
buf[0] = CMD_SET_PARAM; buf[0] = CMD_SET_PARAM;
buf[1] = parm; buf[1] = parm;
buf[2] = value; buf[2] = value;
avrdude_message(MSG_NOTICE2, "%s: jtagmkI_setparm(): " pmsg_notice2("jtagmkI_setparm(): "
"Sending set parameter command (parm 0x%02x): ", "Sending set parameter command (parm 0x%02x): ", parm);
progname, parm);
jtagmkI_send(pgm, buf, 3); jtagmkI_send(pgm, buf, 3);
if (jtagmkI_recv(pgm, resp, 2) < 0) if (jtagmkI_recv(pgm, resp, 2) < 0)
return -1; return -1;
if (resp[0] != RESP_OK) { if (resp[0] != RESP_OK) {
if (verbose >= 2) msg_notice2("\n");
putc('\n', stderr); pmsg_error("timeout/error communicating with programmer (resp %c)\n", resp[0]);
avrdude_message(MSG_INFO, "%s: jtagmkI_setparm(): "
"timeout/error communicating with programmer (resp %c)\n",
progname, resp[0]);
return -1; return -1;
} else { } else {
if (verbose == 2) msg_notice2("OK\n");
avrdude_message(MSG_NOTICE2, "OK\n");
} }
return 0; return 0;
@ -1268,8 +1167,8 @@ static void jtagmkI_display(const PROGRAMMER *pgm, const char *p) {
jtagmkI_getparm(pgm, PARM_SW_VERSION, &fw) < 0) jtagmkI_getparm(pgm, PARM_SW_VERSION, &fw) < 0)
return; return;
avrdude_message(MSG_INFO, "%sICE HW version: 0x%02x\n", p, hw); msg_info("%sICE HW version: 0x%02x\n", p, hw);
avrdude_message(MSG_INFO, "%sICE FW version: 0x%02x\n", p, fw); msg_info("%sICE FW version: 0x%02x\n", p, fw);
jtagmkI_print_parms1(pgm, p); jtagmkI_print_parms1(pgm, p);
@ -1312,10 +1211,8 @@ static void jtagmkI_print_parms1(const PROGRAMMER *pgm, const char *p) {
clk = 1e6; clk = 1e6;
} }
avrdude_message(MSG_INFO, "%sVtarget : %.1f V\n", p, msg_info("%sVtarget : %.1f V\n", p, 6.25 * (unsigned)vtarget / 255.0);
6.25 * (unsigned)vtarget / 255.0); msg_info("%sJTAG clock : %s (%.1f us)\n", p, clkstr, 1.0e6 / clk);
avrdude_message(MSG_INFO, "%sJTAG clock : %s (%.1f us)\n", p, clkstr,
1.0e6 / clk);
return; return;
} }

File diff suppressed because it is too large Load Diff

View File

@ -31,18 +31,18 @@
#include <stdlib.h> #include <stdlib.h>
#define ppi_claim(fd) \ #define ppi_claim(fd) \
if (ioctl(fd, PPCLAIM)) { \ if (ioctl(fd, PPCLAIM)) { \
avrdude_message(MSG_INFO, "%s: can't claim device \"%s\": %s\n\n", \ pmsg_ext_error("cannot claim port %s: %s\n\n", \
progname, port, strerror(errno)); \ port, strerror(errno)); \
close(fd); \ close(fd); \
return; \ return; \
} }
#define ppi_release(fd) \ #define ppi_release(fd) \
if (ioctl(fd, PPRELEASE)) { \ if (ioctl(fd, PPRELEASE)) { \
avrdude_message(MSG_INFO, "%s: can't release device: %s\n\n", \ pmsg_ext_error("cannot release device: %s\n\n", \
progname, strerror(errno)); \ strerror(errno)); \
} }
#define DO_PPI_READ(fd, reg, valp) \ #define DO_PPI_READ(fd, reg, valp) \

View File

@ -63,7 +63,7 @@ static int linuxgpio_export(unsigned int gpio)
fd = open("/sys/class/gpio/export", O_WRONLY); fd = open("/sys/class/gpio/export", O_WRONLY);
if (fd < 0) { if (fd < 0) {
perror("Can't open /sys/class/gpio/export"); pmsg_ext_error("cannot open /sys/class/gpio/export: %s\n", strerror(errno));
return fd; return fd;
} }
@ -81,7 +81,7 @@ static int linuxgpio_unexport(unsigned int gpio)
fd = open("/sys/class/gpio/unexport", O_WRONLY); fd = open("/sys/class/gpio/unexport", O_WRONLY);
if (fd < 0) { if (fd < 0) {
perror("Can't open /sys/class/gpio/unexport"); pmsg_ext_error("cannot open /sys/class/gpio/unexport: %s\n", strerror(errno));
return fd; return fd;
} }
@ -109,8 +109,7 @@ static int linuxgpio_dir(unsigned int gpio, unsigned int dir)
fd = open(buf, O_WRONLY); fd = open(buf, O_WRONLY);
if (fd < 0) { if (fd < 0) {
snprintf(buf, sizeof(buf), "Can't open gpio%u/direction", gpio); pmsg_ext_error("cannot open %s: %s\n", buf, strerror(errno));
perror(buf);
return fd; return fd;
} }
@ -220,7 +219,7 @@ static int linuxgpio_highpulsepin(const PROGRAMMER *pgm, int pinfunc) {
static void linuxgpio_display(const PROGRAMMER *pgm, const char *p) { static void linuxgpio_display(const PROGRAMMER *pgm, const char *p) {
avrdude_message(MSG_INFO, "%sPin assignment : /sys/class/gpio/gpio{n}\n",p); msg_info("%sPin assignment : /sys/class/gpio/gpio{n}\n",p);
pgm_display_generic_mask(pgm, p, SHOW_AVR_PINS); pgm_display_generic_mask(pgm, p, SHOW_AVR_PINS);
} }
@ -267,7 +266,7 @@ static int linuxgpio_open(PROGRAMMER *pgm, const char *port) {
i == PIN_AVR_MISO ) { i == PIN_AVR_MISO ) {
pin = pgm->pinno[i] & PIN_MASK; pin = pgm->pinno[i] & PIN_MASK;
if ((r=linuxgpio_export(pin)) < 0) { if ((r=linuxgpio_export(pin)) < 0) {
avrdude_message(MSG_INFO, "Can't export GPIO %d, already exported/busy?: %s", pmsg_ext_error("cannot export GPIO %d, already exported/busy?: %s",
pin, strerror(errno)); pin, strerror(errno));
return r; return r;
} }
@ -306,9 +305,9 @@ static int linuxgpio_open(PROGRAMMER *pgm, const char *port) {
} }
if (retry_count) if (retry_count)
avrdude_message(MSG_NOTICE2, "%s: needed %d retr%s for linuxgpio_dir_%s(%s)\n", pmsg_notice2("needed %d retr%s for linuxgpio_dir_%s(%s)\n",
progname, retry_count, retry_count > 1? "ies": "y", retry_count, retry_count > 1? "ies": "y",
i == PIN_AVR_MISO? "in": "out", avr_pin_name(pin)); i == PIN_AVR_MISO? "in": "out", avr_pin_name(pin));
if (r < 0) { if (r < 0) {
linuxgpio_unexport(pin); linuxgpio_unexport(pin);
@ -379,8 +378,7 @@ const char linuxgpio_desc[] = "GPIO bitbanging using the Linux sysfs interface";
#else /* !HAVE_LINUXGPIO */ #else /* !HAVE_LINUXGPIO */
void linuxgpio_initpgm(PROGRAMMER *pgm) { void linuxgpio_initpgm(PROGRAMMER *pgm) {
avrdude_message(MSG_INFO, "%s: Linux sysfs GPIO support not available in this configuration\n", pmsg_error("Linux sysfs GPIO support not available in this configuration\n");
progname);
} }
const char linuxgpio_desc[] = "GPIO bitbanging using the Linux sysfs interface (not available)"; const char linuxgpio_desc[] = "GPIO bitbanging using the Linux sysfs interface (not available)";

View File

@ -94,10 +94,11 @@ static int linuxspi_spi_duplex(const PROGRAMMER *pgm, const unsigned char *tx, u
ret = ioctl(fd_spidev, SPI_IOC_MESSAGE(1), &tr); ret = ioctl(fd_spidev, SPI_IOC_MESSAGE(1), &tr);
if (ret != len) { if (ret != len) {
int ioctl_errno = errno; int ioctl_errno = errno;
avrdude_message(MSG_INFO, "\n%s: unable to send SPI message", progname); msg_error("\n");
pmsg_error("unable to send SPI message");
if (ioctl_errno) if (ioctl_errno)
avrdude_message(MSG_INFO, ". %s", strerror(ioctl_errno)); msg_error("%s", strerror(ioctl_errno));
avrdude_message(MSG_INFO, "\n"); msg_error("\n");
} }
return ret == -1? -1: 0; return ret == -1? -1: 0;
@ -133,8 +134,7 @@ static int linuxspi_reset_mcu(const PROGRAMMER *pgm, bool active) {
#endif #endif
if (ret == -1) { if (ret == -1) {
ret = -errno; ret = -errno;
avrdude_message(MSG_INFO, "%s: unable to set GPIO line %d value. %s\n", pmsg_ext_error("unable to set GPIO line %d value: %s\n", pgm->pinno[PIN_AVR_RESET] & ~PIN_INVERSE, strerror(errno));
progname, pgm->pinno[PIN_AVR_RESET] & ~PIN_INVERSE, strerror(errno));
return ret; return ret;
} }
@ -143,7 +143,7 @@ static int linuxspi_reset_mcu(const PROGRAMMER *pgm, bool active) {
static int linuxspi_open(PROGRAMMER *pgm, const char *pt) { static int linuxspi_open(PROGRAMMER *pgm, const char *pt) {
const char *port_error = const char *port_error =
"%s: error, unknown port specification; " "unknown port specification, "
"please use the format /dev/spidev:/dev/gpiochip[:resetno]\n"; "please use the format /dev/spidev:/dev/gpiochip[:resetno]\n";
char port_default[] = "/dev/spidev0.0:/dev/gpiochip0"; char port_default[] = "/dev/spidev0.0:/dev/gpiochip0";
char *spidev, *gpiochip, *reset_pin; char *spidev, *gpiochip, *reset_pin;
@ -157,13 +157,13 @@ static int linuxspi_open(PROGRAMMER *pgm, const char *pt) {
spidev = strtok(port, ":"); spidev = strtok(port, ":");
if (!spidev) { if (!spidev) {
avrdude_message(MSG_INFO, port_error, progname); pmsg_error("%s", port_error);
return -1; return -1;
} }
gpiochip = strtok(NULL, ":"); gpiochip = strtok(NULL, ":");
if (!gpiochip) { if (!gpiochip) {
avrdude_message(MSG_INFO, port_error, progname); pmsg_error("%s", port_error);
return -1; return -1;
} }
@ -175,8 +175,7 @@ static int linuxspi_open(PROGRAMMER *pgm, const char *pt) {
strcpy(pgm->port, port); strcpy(pgm->port, port);
fd_spidev = open(pgm->port, O_RDWR); fd_spidev = open(pgm->port, O_RDWR);
if (fd_spidev < 0) { if (fd_spidev < 0) {
avrdude_message(MSG_INFO, "\n%s: unable to open the spidev device %s. %s", pmsg_ext_error("unable to open the spidev device %s: %s\n", pgm->port, strerror(errno));
progname, pgm->port, strerror(errno));
return -1; return -1;
} }
@ -187,16 +186,14 @@ static int linuxspi_open(PROGRAMMER *pgm, const char *pt) {
ret = ioctl(fd_spidev, SPI_IOC_WR_MODE32, &mode); ret = ioctl(fd_spidev, SPI_IOC_WR_MODE32, &mode);
if (ret == -1) { if (ret == -1) {
int ioctl_errno = errno; int ioctl_errno = errno;
avrdude_message(MSG_INFO, "%s: unable to set SPI mode %02X on %s. %s\n", pmsg_ext_error("unable to set SPI mode %02X on %s: %s\n", mode, spidev, strerror(errno));
progname, mode, spidev, strerror(errno));
if(ioctl_errno == EINVAL && !PDATA(pgm)->disable_no_cs) if(ioctl_errno == EINVAL && !PDATA(pgm)->disable_no_cs)
avrdude_message(MSG_INFO, "%s: try -x disable_no_cs\n", progname); pmsg_error("try -x disable_no_cs\n");
goto close_spidev; goto close_spidev;
} }
fd_gpiochip = open(gpiochip, 0); fd_gpiochip = open(gpiochip, 0);
if (fd_gpiochip < 0) { if (fd_gpiochip < 0) {
avrdude_message(MSG_INFO, "\n%s: unable to open the gpiochip %s. %s\n", pmsg_ext_error("unable to open the gpiochip %s: %s\n", gpiochip, strerror(errno));
progname, gpiochip, strerror(errno));
ret = -1; ret = -1;
goto close_spidev; goto close_spidev;
} }
@ -231,8 +228,7 @@ static int linuxspi_open(PROGRAMMER *pgm, const char *pt) {
#endif #endif
if (ret == -1) { if (ret == -1) {
ret = -errno; ret = -errno;
avrdude_message(MSG_INFO, "%s: unable to get GPIO line %d. %s\n", pmsg_ext_error("unable to get GPIO line %d. %s\n", pgm->pinno[PIN_AVR_RESET] & ~PIN_INVERSE, strerror(errno));
progname, pgm->pinno[PIN_AVR_RESET] & ~PIN_INVERSE, strerror(errno));
goto close_gpiochip; goto close_gpiochip;
} }
@ -241,14 +237,11 @@ static int linuxspi_open(PROGRAMMER *pgm, const char *pt) {
goto close_out; goto close_out;
if (pgm->baudrate != 0) { if (pgm->baudrate != 0) {
avrdude_message(MSG_INFO, pmsg_warning("obsolete use of -b <clock> option for bit clock; use -B <clock>\n");
"%s: obsolete use of -b <clock> option for bit clock; use -B <clock>\n", pgm->bitclock = 1.0 / pgm->baudrate;
progname);
pgm->bitclock = 1.0 / pgm->baudrate;
} }
if (pgm->bitclock == 0) { if (pgm->bitclock == 0) {
avrdude_message(MSG_NOTICE, pmsg_notice("defaulting bit clock to 200 kHz\n");
"%s: defaulting bit clock to 200 kHz\n", progname);
pgm->bitclock = 5E-6; // 200 kHz - 5 µs pgm->bitclock = 5E-6; // 200 kHz - 5 µs
} }
@ -296,7 +289,7 @@ static int linuxspi_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
if (p->prog_modes & PM_TPI) { if (p->prog_modes & PM_TPI) {
/* We do not support TPI. This is a dedicated SPI thing */ /* We do not support TPI. This is a dedicated SPI thing */
avrdude_message(MSG_INFO, "%s: error, programmer " LINUXSPI " does not support TPI\n", progname); pmsg_error("programmer " LINUXSPI " does not support TPI\n");
return -1; return -1;
} }
@ -310,7 +303,7 @@ static int linuxspi_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
} while(tries++ < 65); } while(tries++ < 65);
if (ret) if (ret)
avrdude_message(MSG_INFO, "%s: error, AVR device not responding\n", progname); pmsg_error("AVR device not responding\n");
return ret; return ret;
} }
@ -324,7 +317,7 @@ static int linuxspi_program_enable(const PROGRAMMER *pgm, const AVRPART *p) {
unsigned char cmd[4], res[4]; unsigned char cmd[4], res[4];
if (!p->op[AVR_OP_PGM_ENABLE]) { if (!p->op[AVR_OP_PGM_ENABLE]) {
avrdude_message(MSG_INFO, "%s: error, program enable instruction not defined for part %s\n", progname, p->desc); pmsg_error("program enable instruction not defined for part %s\n", p->desc);
return -1; return -1;
} }
@ -367,7 +360,7 @@ static int linuxspi_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) {
unsigned char cmd[4], res[4]; unsigned char cmd[4], res[4];
if (!p->op[AVR_OP_CHIP_ERASE]) { if (!p->op[AVR_OP_CHIP_ERASE]) {
avrdude_message(MSG_INFO, "%s: error, chip erase instruction not defined for part %s\n", progname, p->desc); pmsg_error("chip erase instruction not defined for part %s\n", p->desc);
return -1; return -1;
} }
@ -415,8 +408,7 @@ static int linuxspi_parseextparams(const PROGRAMMER *pgm, const LISTID extparms)
continue; continue;
} }
avrdude_message(MSG_INFO, "%s: linuxspi_parseextparams(): " pmsg_error("invalid extended parameter '%s'\n", extended_param);
"invalid extended parameter '%s'\n", progname, extended_param);
rc = -1; rc = -1;
} }
@ -453,7 +445,7 @@ const char linuxspi_desc[] = "SPI using Linux spidev driver";
#else /* !HAVE_LINUXSPI */ #else /* !HAVE_LINUXSPI */
void linuxspi_initpgm(PROGRAMMER *pgm) { void linuxspi_initpgm(PROGRAMMER *pgm) {
avrdude_message(MSG_INFO, "%s: Linux SPI driver not available in this configuration\n", progname); pmsg_error("Linux SPI driver not available in this configuration\n");
} }
const char linuxspi_desc[] = "SPI using Linux spidev driver (not available)"; const char linuxspi_desc[] = "SPI using Linux spidev driver (not available)";

View File

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

View File

@ -164,7 +164,7 @@ static int micronucleus_reconnect(pdata_t* pdata)
for (int i = 0; i < 25; i++) for (int i = 0; i < 25; i++)
{ {
avrdude_message(MSG_NOTICE, "%s: Trying to reconnect...\n", progname); pmsg_notice("trying to reconnect ...\n");
pdata->usb_handle = usb_open(device); pdata->usb_handle = usb_open(device);
if (pdata->usb_handle != NULL) if (pdata->usb_handle != NULL)
@ -188,14 +188,12 @@ static int micronucleus_get_bootloader_info_v1(pdata_t* pdata)
MICRONUCLEUS_DEFAULT_TIMEOUT); MICRONUCLEUS_DEFAULT_TIMEOUT);
if (result < 0) if (result < 0)
{ {
avrdude_message(MSG_INFO, "%s: WARNING: Failed to get bootloader info block: %s\n", pmsg_warning("unable to get bootloader info block: %s\n", usb_strerror());
progname, usb_strerror());
return result; return result;
} }
else if (result < sizeof(buffer)) else if (result < sizeof(buffer))
{ {
avrdude_message(MSG_INFO, "%s: WARNING: Received invalid bootloader info block size: %d\n", pmsg_warning("received invalid bootloader info block size: %d\n", result);
progname, result);
return -1; return -1;
} }
@ -257,14 +255,12 @@ static int micronucleus_get_bootloader_info_v2(pdata_t* pdata)
MICRONUCLEUS_DEFAULT_TIMEOUT); MICRONUCLEUS_DEFAULT_TIMEOUT);
if (result < 0) if (result < 0)
{ {
avrdude_message(MSG_INFO, "%s: WARNING: Failed to get bootloader info block: %s\n", pmsg_warning("unable to get bootloader info block: %s\n", usb_strerror());
progname, usb_strerror());
return result; return result;
} }
else if (result < sizeof(buffer)) else if (result < sizeof(buffer))
{ {
avrdude_message(MSG_INFO, "%s: WARNING: Received invalid bootloader info block size: %d\n", pmsg_warning("received invalid bootloader info block size: %d\n", result);
progname, result);
return -1; return -1;
} }
@ -302,19 +298,19 @@ static int micronucleus_get_bootloader_info(pdata_t* pdata)
static void micronucleus_dump_device_info(pdata_t* pdata) static void micronucleus_dump_device_info(pdata_t* pdata)
{ {
avrdude_message(MSG_NOTICE, "%s: Bootloader version: %d.%d\n", progname, pdata->major_version, pdata->minor_version); pmsg_notice("Bootloader version: %d.%d\n", pdata->major_version, pdata->minor_version);
avrdude_message(MSG_NOTICE, "%s: Available flash size: %u\n", progname, pdata->flash_size); imsg_notice("Available flash size: %u\n", pdata->flash_size);
avrdude_message(MSG_NOTICE, "%s: Page size: %u\n", progname, pdata->page_size); imsg_notice("Page size: %u\n", pdata->page_size);
avrdude_message(MSG_NOTICE, "%s: Bootloader start: 0x%04X\n", progname, pdata->bootloader_start); imsg_notice("Bootloader start: 0x%04X\n", pdata->bootloader_start);
avrdude_message(MSG_NOTICE, "%s: Write sleep: %ums\n", progname, pdata->write_sleep); imsg_notice("Write sleep: %ums\n", pdata->write_sleep);
avrdude_message(MSG_NOTICE, "%s: Erase sleep: %ums\n", progname, pdata->erase_sleep); imsg_notice("Erase sleep: %ums\n", pdata->erase_sleep);
avrdude_message(MSG_NOTICE, "%s: Signature1: 0x%02X\n", progname, pdata->signature1); imsg_notice("Signature1: 0x%02X\n", pdata->signature1);
avrdude_message(MSG_NOTICE, "%s: Signature2: 0x%02X\n", progname, pdata->signature2); imsg_notice("Signature2: 0x%02X\n", pdata->signature2);
} }
static int micronucleus_erase_device(pdata_t* pdata) static int micronucleus_erase_device(pdata_t* pdata)
{ {
avrdude_message(MSG_DEBUG, "%s: micronucleus_erase_device()\n", progname); pmsg_debug("micronucleus_erase_device()\n");
int result = usb_control_msg( int result = usb_control_msg(
pdata->usb_handle, pdata->usb_handle,
@ -329,10 +325,10 @@ static int micronucleus_erase_device(pdata_t* pdata)
{ {
case -EIO: case -EIO:
case -EPIPE: case -EPIPE:
avrdude_message(MSG_NOTICE, "%s: Ignoring last error of erase command: %s\n", progname, usb_strerror()); pmsg_notice("ignoring last error of erase command: %s\n", usb_strerror());
break; break;
default: default:
avrdude_message(MSG_INFO, "%s: WARNING: Failed is issue erase command, code %d: %s\n", progname, result, usb_strerror()); pmsg_warning("erase command failed, code %d: %s\n", result, usb_strerror());
return result; return result;
} }
} }
@ -342,12 +338,12 @@ static int micronucleus_erase_device(pdata_t* pdata)
result = micronucleus_check_connection(pdata); result = micronucleus_check_connection(pdata);
if (result < 0) if (result < 0)
{ {
avrdude_message(MSG_NOTICE, "%s: Connection dropped, trying to reconnect...\n", progname); pmsg_notice("connection dropped, trying to reconnect ...\n");
result = micronucleus_reconnect(pdata); result = micronucleus_reconnect(pdata);
if (result < 0) if (result < 0)
{ {
avrdude_message(MSG_INFO, "%s: WARNING: Failed to reconnect USB device: %s\n", progname, usb_strerror()); pmsg_warning("unable to reconnect USB device: %s\n", usb_strerror());
return result; return result;
} }
} }
@ -373,7 +369,7 @@ static int micronucleus_patch_reset_vector(pdata_t* pdata, uint8_t* buffer)
} }
else else
{ {
avrdude_message(MSG_INFO, "%s: The reset vector of the user program does not contain a branch instruction.\n", progname); pmsg_error("the reset vector of the user program does not contain a branch instruction\n");
return -1; return -1;
} }
@ -431,7 +427,7 @@ static int micronucleus_write_page_v1(pdata_t* pdata, uint32_t address, uint8_t*
MICRONUCLEUS_DEFAULT_TIMEOUT); MICRONUCLEUS_DEFAULT_TIMEOUT);
if (result < 0) if (result < 0)
{ {
avrdude_message(MSG_INFO, "%s: Failed to transfer page: %s\n", progname, usb_strerror()); pmsg_error("unable to transfer page: %s\n", usb_strerror());
return result; return result;
} }
@ -449,7 +445,7 @@ static int micronucleus_write_page_v2(pdata_t* pdata, uint32_t address, uint8_t*
MICRONUCLEUS_DEFAULT_TIMEOUT); MICRONUCLEUS_DEFAULT_TIMEOUT);
if (result < 0) if (result < 0)
{ {
avrdude_message(MSG_INFO, "%s: Failed to transfer page: %s\n", progname, usb_strerror()); pmsg_error("unable to transfer page: %s\n", usb_strerror());
return result; return result;
} }
@ -466,7 +462,7 @@ static int micronucleus_write_page_v2(pdata_t* pdata, uint32_t address, uint8_t*
MICRONUCLEUS_DEFAULT_TIMEOUT); MICRONUCLEUS_DEFAULT_TIMEOUT);
if (result < 0) if (result < 0)
{ {
avrdude_message(MSG_INFO, "%s: Failed to transfer page: %s\n", progname, usb_strerror()); pmsg_error("unable to transfer page: %s\n", usb_strerror());
return result; return result;
} }
} }
@ -476,7 +472,7 @@ static int micronucleus_write_page_v2(pdata_t* pdata, uint32_t address, uint8_t*
static int micronucleus_write_page(pdata_t* pdata, uint32_t address, uint8_t* buffer, uint32_t size) static int micronucleus_write_page(pdata_t* pdata, uint32_t address, uint8_t* buffer, uint32_t size)
{ {
avrdude_message(MSG_DEBUG, "%s: micronucleus_write_page(address=0x%04X, size=%d)\n", progname, address, size); pmsg_debug("micronucleus_write_page(address=0x%04X, size=%d)\n", address, size);
if (address == 0) if (address == 0)
{ {
@ -528,7 +524,7 @@ static int micronucleus_write_page(pdata_t* pdata, uint32_t address, uint8_t* bu
static int micronucleus_start(pdata_t* pdata) static int micronucleus_start(pdata_t* pdata)
{ {
avrdude_message(MSG_DEBUG, "%s: micronucleus_start()\n", progname); pmsg_debug("micronucleus_start()\n");
int result = usb_control_msg( int result = usb_control_msg(
pdata->usb_handle, pdata->usb_handle,
@ -539,7 +535,7 @@ static int micronucleus_start(pdata_t* pdata)
MICRONUCLEUS_DEFAULT_TIMEOUT); MICRONUCLEUS_DEFAULT_TIMEOUT);
if (result < 0) if (result < 0)
{ {
avrdude_message(MSG_INFO, "%s: WARNING: Failed is issue start command: %s\n", progname, usb_strerror()); pmsg_warning("start command failed: %s\n", usb_strerror());
return result; return result;
} }
@ -550,11 +546,11 @@ static int micronucleus_start(pdata_t* pdata)
static void micronucleus_setup(PROGRAMMER* pgm) static void micronucleus_setup(PROGRAMMER* pgm)
{ {
avrdude_message(MSG_DEBUG, "%s: micronucleus_setup()\n", progname); pmsg_debug("micronucleus_setup()\n");
if ((pgm->cookie = malloc(sizeof(pdata_t))) == 0) if ((pgm->cookie = malloc(sizeof(pdata_t))) == 0)
{ {
avrdude_message(MSG_INFO, "%s: micronucleus_setup(): Out of memory allocating private data\n", progname); pmsg_error("out of memory allocating private data\n");
exit(1); exit(1);
} }
@ -563,12 +559,12 @@ static void micronucleus_setup(PROGRAMMER* pgm)
static void micronucleus_teardown(PROGRAMMER* pgm) static void micronucleus_teardown(PROGRAMMER* pgm)
{ {
avrdude_message(MSG_DEBUG, "%s: micronucleus_teardown()\n", progname); pmsg_debug("micronucleus_teardown()\n");
free(pgm->cookie); free(pgm->cookie);
} }
static int micronucleus_initialize(const PROGRAMMER *pgm, const AVRPART *p) { static int micronucleus_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
avrdude_message(MSG_DEBUG, "%s: micronucleus_initialize()\n", progname); pmsg_debug("micronucleus_initialize()\n");
pdata_t* pdata = PDATA(pgm); pdata_t* pdata = PDATA(pgm);
@ -582,15 +578,15 @@ static int micronucleus_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
} }
static void micronucleus_display(const PROGRAMMER *pgm, const char *prefix) { static void micronucleus_display(const PROGRAMMER *pgm, const char *prefix) {
avrdude_message(MSG_DEBUG, "%s: micronucleus_display()\n", progname); pmsg_debug("micronucleus_display()\n");
} }
static void micronucleus_powerup(const PROGRAMMER *pgm) { static void micronucleus_powerup(const PROGRAMMER *pgm) {
avrdude_message(MSG_DEBUG, "%s: micronucleus_powerup()\n", progname); pmsg_debug("micronucleus_powerup()\n");
} }
static void micronucleus_powerdown(const PROGRAMMER *pgm) { static void micronucleus_powerdown(const PROGRAMMER *pgm) {
avrdude_message(MSG_DEBUG, "%s: micronucleus_powerdown()\n", progname); pmsg_debug("micronucleus_powerdown()\n");
pdata_t* pdata = PDATA(pgm); pdata_t* pdata = PDATA(pgm);
if (pdata->write_last_page) if (pdata->write_last_page)
@ -615,24 +611,24 @@ static void micronucleus_powerdown(const PROGRAMMER *pgm) {
} }
static void micronucleus_enable(PROGRAMMER *pgm, const AVRPART *p) { static void micronucleus_enable(PROGRAMMER *pgm, const AVRPART *p) {
avrdude_message(MSG_DEBUG, "%s: micronucleus_enable()\n", progname); pmsg_debug("micronucleus_enable()\n");
} }
static void micronucleus_disable(const PROGRAMMER *pgm) { static void micronucleus_disable(const PROGRAMMER *pgm) {
avrdude_message(MSG_DEBUG, "%s: micronucleus_disable()\n", progname); pmsg_debug("micronucleus_disable()\n");
} }
static int micronucleus_program_enable(const PROGRAMMER *pgm, const AVRPART *p) { static int micronucleus_program_enable(const PROGRAMMER *pgm, const AVRPART *p) {
avrdude_message(MSG_DEBUG, "%s: micronucleus_program_enable()\n", progname); pmsg_debug("micronucleus_program_enable()\n");
return 0; return 0;
} }
static int micronucleus_read_sig_bytes(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem) { static int micronucleus_read_sig_bytes(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem) {
avrdude_message(MSG_DEBUG, "%s: micronucleus_read_sig_bytes()\n", progname); pmsg_debug("micronucleus_read_sig_bytes()\n");
if (mem->size < 3) if (mem->size < 3)
{ {
avrdude_message(MSG_INFO, "%s: memory size too small for read_sig_bytes", progname); pmsg_error("memory size %d < 3 too small for read_sig_bytes", mem->size);
return -1; return -1;
} }
@ -644,14 +640,14 @@ static int micronucleus_read_sig_bytes(const PROGRAMMER *pgm, const AVRPART *p,
} }
static int micronucleus_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) { static int micronucleus_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) {
avrdude_message(MSG_DEBUG, "%s: micronucleus_chip_erase()\n", progname); pmsg_debug("micronucleus_chip_erase()\n");
pdata_t* pdata = PDATA(pgm); pdata_t* pdata = PDATA(pgm);
return micronucleus_erase_device(pdata); return micronucleus_erase_device(pdata);
} }
static int micronucleus_open(PROGRAMMER* pgm, const char *port) { static int micronucleus_open(PROGRAMMER* pgm, const char *port) {
avrdude_message(MSG_DEBUG, "%s: micronucleus_open(\"%s\")\n", progname, port); pmsg_debug("micronucleus_open(\"%s\")\n", port);
pdata_t* pdata = PDATA(pgm); pdata_t* pdata = PDATA(pgm);
const char *bus_name = NULL; const char *bus_name = NULL;
@ -679,8 +675,8 @@ static int micronucleus_open(PROGRAMMER* pgm, const char *port) {
if (port != NULL && dev_name == NULL) if (port != NULL && dev_name == NULL)
{ {
avrdude_message(MSG_INFO, "%s: ERROR: Invalid -P value: '%s'\n", progname, port); pmsg_error("invalid -P value %s\n", port);
avrdude_message(MSG_INFO, "%sUse -P usb:bus:device\n", progbuf); imsg_error("use -P usb:bus:device\n");
return -1; return -1;
} }
@ -694,8 +690,7 @@ static int micronucleus_open(PROGRAMMER* pgm, const char *port) {
pid = *(int*)(ldata(usbpid)); pid = *(int*)(ldata(usbpid));
if (lnext(usbpid)) if (lnext(usbpid))
{ {
avrdude_message(MSG_INFO, "%s: WARNING: using PID 0x%04x, ignoring remaining PIDs in list\n", pmsg_warning("using PID 0x%04x, ignoring remaining PIDs in list\n", pid);
progname, pid);
} }
} }
@ -728,8 +723,7 @@ static int micronucleus_open(PROGRAMMER* pgm, const char *port) {
{ {
if (show_unresponsive_device_message) if (show_unresponsive_device_message)
{ {
avrdude_message(MSG_INFO, "%s: WARNING: Unresponsive Micronucleus device detected, please reconnect...\n", pmsg_warning("unresponsive Micronucleus device detected, please reconnect ...\n");
progname);
show_unresponsive_device_message = false; show_unresponsive_device_message = false;
} }
@ -737,8 +731,7 @@ static int micronucleus_open(PROGRAMMER* pgm, const char *port) {
continue; continue;
} }
avrdude_message(MSG_NOTICE, "%s: Found device with Micronucleus V%d.%d, bus:device: %s:%s\n", pmsg_notice("found device with Micronucleus V%d.%d, bus:device: %s:%s\n",
progname,
pdata->major_version, pdata->minor_version, pdata->major_version, pdata->minor_version,
bus->dirname, device->filename); bus->dirname, device->filename);
@ -753,8 +746,7 @@ static int micronucleus_open(PROGRAMMER* pgm, const char *port) {
if (pdata->major_version > MICRONUCLEUS_MAX_MAJOR_VERSION) if (pdata->major_version > MICRONUCLEUS_MAX_MAJOR_VERSION)
{ {
avrdude_message(MSG_INFO, "%s: WARNING: device with unsupported version (V%d.%d) of Micronucleus detected.\n", pmsg_warning("device with unsupported Micronucleus version V%d.%d\n",
progname,
pdata->major_version, pdata->minor_version); pdata->major_version, pdata->minor_version);
continue; continue;
} }
@ -762,7 +754,7 @@ static int micronucleus_open(PROGRAMMER* pgm, const char *port) {
pdata->usb_handle = usb_open(device); pdata->usb_handle = usb_open(device);
if (pdata->usb_handle == NULL) if (pdata->usb_handle == NULL)
{ {
avrdude_message(MSG_INFO, "%s: ERROR: Failed to open USB device: %s\n", progname, usb_strerror()); pmsg_error("unable to open USB device: %s\n", usb_strerror());
} }
} }
} }
@ -774,16 +766,15 @@ static int micronucleus_open(PROGRAMMER* pgm, const char *port) {
{ {
if (pdata->wait_timout < 0) if (pdata->wait_timout < 0)
{ {
avrdude_message(MSG_INFO, "%s: No device found, waiting for device to be plugged in...\n", progname); pmsg_error("no device found, waiting for device to be plugged in ...\n");
} }
else else
{ {
avrdude_message(MSG_INFO, "%s: No device found, waiting %d seconds for device to be plugged in...\n", pmsg_error("no device found, waiting %d seconds for device to be plugged in ...\n",
progname,
pdata->wait_timout); pdata->wait_timout);
} }
avrdude_message(MSG_INFO, "%s: Press CTRL-C to terminate.\n", progname); pmsg_error("press CTRL-C to terminate\n");
show_retry_message = false; show_retry_message = false;
} }
@ -799,8 +790,7 @@ static int micronucleus_open(PROGRAMMER* pgm, const char *port) {
if (!pdata->usb_handle) if (!pdata->usb_handle)
{ {
avrdude_message(MSG_INFO, "%s: ERROR: Could not find device with Micronucleus bootloader (%04X:%04X)\n", pmsg_error("cannot find device with Micronucleus bootloader (%04X:%04X)\n", vid, pid);
progname, vid, pid);
return -1; return -1;
} }
@ -809,7 +799,7 @@ static int micronucleus_open(PROGRAMMER* pgm, const char *port) {
static void micronucleus_close(PROGRAMMER* pgm) static void micronucleus_close(PROGRAMMER* pgm)
{ {
avrdude_message(MSG_DEBUG, "%s: micronucleus_close()\n", progname); pmsg_debug("micronucleus_close()\n");
pdata_t* pdata = PDATA(pgm); pdata_t* pdata = PDATA(pgm);
if (pdata->usb_handle != NULL) if (pdata->usb_handle != NULL)
@ -822,8 +812,7 @@ static void micronucleus_close(PROGRAMMER* pgm)
static int micronucleus_read_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem, static int micronucleus_read_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem,
unsigned long addr, unsigned char* value) unsigned long addr, unsigned char* value)
{ {
avrdude_message(MSG_DEBUG, "%s: micronucleus_read_byte(desc=%s, addr=0x%0X)\n", pmsg_debug("micronucleus_read_byte(desc=%s, addr=0x%04lX)\n", mem->desc, addr);
progname, mem->desc, addr);
if (strcmp(mem->desc, "lfuse") == 0 || if (strcmp(mem->desc, "lfuse") == 0 ||
strcmp(mem->desc, "hfuse") == 0 || strcmp(mem->desc, "hfuse") == 0 ||
@ -835,7 +824,7 @@ static int micronucleus_read_byte(const PROGRAMMER *pgm, const AVRPART *p, const
} }
else else
{ {
avrdude_message(MSG_INFO, "%s: Unsupported memory type: %s\n", progname, mem->desc); pmsg_error("unsupported memory type %s\n", mem->desc);
return -1; return -1;
} }
} }
@ -843,8 +832,7 @@ static int micronucleus_read_byte(const PROGRAMMER *pgm, const AVRPART *p, const
static int micronucleus_write_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem, static int micronucleus_write_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem,
unsigned long addr, unsigned char value) unsigned long addr, unsigned char value)
{ {
avrdude_message(MSG_DEBUG, "%s: micronucleus_write_byte(desc=%s, addr=0x%0X)\n", pmsg_debug("micronucleus_write_byte(desc=%s, addr=0x%04lX)\n", mem->desc, addr);
progname, mem->desc, addr);
return -1; return -1;
} }
@ -852,8 +840,7 @@ static int micronucleus_paged_load(const PROGRAMMER *pgm, const AVRPART *p, cons
unsigned int page_size, unsigned int page_size,
unsigned int addr, unsigned int n_bytes) unsigned int addr, unsigned int n_bytes)
{ {
avrdude_message(MSG_DEBUG, "%s: micronucleus_paged_load(page_size=0x%X, addr=0x%X, n_bytes=0x%X)\n", pmsg_debug("micronucleus_paged_load(page_size=0x%X, addr=0x%X, n_bytes=0x%X)\n", page_size, addr, n_bytes);
progname, page_size, addr, n_bytes);
return -1; return -1;
} }
@ -861,8 +848,7 @@ static int micronucleus_paged_write(const PROGRAMMER *pgm, const AVRPART *p, con
unsigned int page_size, unsigned int page_size,
unsigned int addr, unsigned int n_bytes) unsigned int addr, unsigned int n_bytes)
{ {
avrdude_message(MSG_DEBUG, "%s: micronucleus_paged_write(page_size=0x%X, addr=0x%X, n_bytes=0x%X)\n", pmsg_debug("micronucleus_paged_write(page_size=0x%X, addr=0x%X, n_bytes=0x%X)\n", page_size, addr, n_bytes);
progname, page_size, addr, n_bytes);
if (strcmp(mem->desc, "flash") == 0) if (strcmp(mem->desc, "flash") == 0)
{ {
@ -870,20 +856,20 @@ static int micronucleus_paged_write(const PROGRAMMER *pgm, const AVRPART *p, con
if (n_bytes > page_size) if (n_bytes > page_size)
{ {
avrdude_message(MSG_INFO, "%s: Buffer size (%u) exceeds page size (%u)\n", progname, n_bytes, page_size); pmsg_error("buffer size %u exceeds page size %u\n", n_bytes, page_size);
return -1; return -1;
} }
if (addr + n_bytes > pdata->flash_size) if (addr + n_bytes > pdata->flash_size)
{ {
avrdude_message(MSG_INFO, "%s: Program size (%u) exceeds flash size (%u)\n", progname, addr + n_bytes, pdata->flash_size); pmsg_error("program size %u exceeds flash size %u\n", addr + n_bytes, pdata->flash_size);
return -1; return -1;
} }
uint8_t* page_buffer = (uint8_t*)malloc(pdata->page_size); uint8_t* page_buffer = (uint8_t*)malloc(pdata->page_size);
if (page_buffer == NULL) if (page_buffer == NULL)
{ {
avrdude_message(MSG_INFO, "%s: Failed to allocate memory\n", progname); pmsg_error("unable to allocate memory\n");
return -1; return -1;
} }
@ -911,13 +897,13 @@ static int micronucleus_paged_write(const PROGRAMMER *pgm, const AVRPART *p, con
} }
else else
{ {
avrdude_message(MSG_INFO, "%s: Unsupported memory type: %s\n", progname, mem->desc); pmsg_error("unsupported memory type: %s\n", mem->desc);
return -1; return -1;
} }
} }
static int micronucleus_parseextparams(const PROGRAMMER *pgm, const LISTID xparams) { static int micronucleus_parseextparams(const PROGRAMMER *pgm, const LISTID xparams) {
avrdude_message(MSG_DEBUG, "%s: micronucleus_parseextparams()\n", progname); pmsg_debug("micronucleus_parseextparams()\n");
pdata_t* pdata = PDATA(pgm); pdata_t* pdata = PDATA(pgm);
for (LNODEID node = lfirst(xparams); node != NULL; node = lnext(node)) for (LNODEID node = lfirst(xparams); node != NULL; node = lnext(node))
@ -936,7 +922,7 @@ static int micronucleus_parseextparams(const PROGRAMMER *pgm, const LISTID xpara
} }
else else
{ {
avrdude_message(MSG_INFO, "%s: Invalid extended parameter '%s'\n", progname, param); pmsg_error("invalid extended parameter '%s'\n", param);
return -1; return -1;
} }
} }
@ -972,7 +958,7 @@ void micronucleus_initpgm(PROGRAMMER *pgm) {
// Give a proper error if we were not compiled with libusb // Give a proper error if we were not compiled with libusb
static int micronucleus_nousb_open(PROGRAMMER* pgm, const char* name) { static int micronucleus_nousb_open(PROGRAMMER* pgm, const char* name) {
avrdude_message(MSG_INFO, "%s: error: No usb support. Please compile again with libusb installed.\n", progname); pmsg_error("no usb support; please compile again with libusb installed\n");
return -1; return -1;
} }

View File

@ -231,8 +231,7 @@ static int par_open(PROGRAMMER *pgm, const char *port) {
ppi_open(port, &pgm->fd); ppi_open(port, &pgm->fd);
if (pgm->fd.ifd < 0) { if (pgm->fd.ifd < 0) {
avrdude_message(MSG_INFO, "%s: failed to open parallel port \"%s\"\n\n", pmsg_error("unable to open parallel port %s\n\n", port);
progname, port);
return -1; return -1;
} }
@ -241,14 +240,14 @@ static int par_open(PROGRAMMER *pgm, const char *port) {
*/ */
rc = ppi_getall(&pgm->fd, PPIDATA); rc = ppi_getall(&pgm->fd, PPIDATA);
if (rc < 0) { if (rc < 0) {
avrdude_message(MSG_INFO, "%s: error reading status of ppi data port\n", progname); pmsg_error("unable to read status of ppi data port\n");
return -1; return -1;
} }
pgm->ppidata = rc; pgm->ppidata = rc;
rc = ppi_getall(&pgm->fd, PPICTRL); rc = ppi_getall(&pgm->fd, PPICTRL);
if (rc < 0) { if (rc < 0) {
avrdude_message(MSG_INFO, "%s: error reading status of ppi ctrl port\n", progname); pmsg_error("unable to read status of ppi ctrl port\n");
return -1; return -1;
} }
pgm->ppictrl = rc; pgm->ppictrl = rc;
@ -391,7 +390,7 @@ void par_initpgm(PROGRAMMER *pgm) {
#else /* !HAVE_PARPORT */ #else /* !HAVE_PARPORT */
void par_initpgm(PROGRAMMER *pgm) { void par_initpgm(PROGRAMMER *pgm) {
avrdude_message(MSG_INFO, "%s: parallel port access not available in this configuration\n", progname); pmsg_error("parallel port access not available in this configuration\n");
} }
#endif /* HAVE_PARPORT */ #endif /* HAVE_PARPORT */

View File

@ -39,7 +39,7 @@ static void pgm_default_6(const PROGRAMMER *, const char *);
static int pgm_default_open(PROGRAMMER *pgm, const char *name) { static int pgm_default_open(PROGRAMMER *pgm, const char *name) {
avrdude_message(MSG_INFO, "\n%s: programmer does not support open()", progname); pmsg_error("programmer does not support open()");
return -1; return -1;
} }
@ -220,7 +220,7 @@ PROGRAMMER *pgm_dup(const PROGRAMMER *src) {
static void pgm_default(void) { static void pgm_default(void) {
avrdude_message(MSG_INFO, "%s: programmer operation not supported\n", progname); pmsg_error("programmer operation not supported\n");
} }
@ -251,8 +251,8 @@ static void pgm_default_6 (const PROGRAMMER *pgm, const char *p) {
void programmer_display(PROGRAMMER *pgm, const char * p) { void programmer_display(PROGRAMMER *pgm, const char * p) {
avrdude_message(MSG_INFO, "%sProgrammer Type : %s\n", p, pgm->type); msg_info("%sProgrammer Type : %s\n", p, pgm->type);
avrdude_message(MSG_INFO, "%sDescription : %s\n", p, pgm->desc); msg_info("%sDescription : %s\n", p, pgm->desc);
pgm->display(pgm, p); pgm->display(pgm, p);
} }
@ -260,25 +260,25 @@ void programmer_display(PROGRAMMER *pgm, const char * p) {
void pgm_display_generic_mask(const PROGRAMMER *pgm, const char *p, unsigned int show) { void pgm_display_generic_mask(const PROGRAMMER *pgm, const char *p, unsigned int show) {
if(show & (1<<PPI_AVR_VCC)) if(show & (1<<PPI_AVR_VCC))
avrdude_message(MSG_INFO, "%s VCC = %s\n", p, pins_to_str(&pgm->pin[PPI_AVR_VCC])); msg_info("%s VCC = %s\n", p, pins_to_str(&pgm->pin[PPI_AVR_VCC]));
if(show & (1<<PPI_AVR_BUFF)) if(show & (1<<PPI_AVR_BUFF))
avrdude_message(MSG_INFO, "%s BUFF = %s\n", p, pins_to_str(&pgm->pin[PPI_AVR_BUFF])); msg_info("%s BUFF = %s\n", p, pins_to_str(&pgm->pin[PPI_AVR_BUFF]));
if(show & (1<<PIN_AVR_RESET)) if(show & (1<<PIN_AVR_RESET))
avrdude_message(MSG_INFO, "%s RESET = %s\n", p, pins_to_str(&pgm->pin[PIN_AVR_RESET])); msg_info("%s RESET = %s\n", p, pins_to_str(&pgm->pin[PIN_AVR_RESET]));
if(show & (1<<PIN_AVR_SCK)) if(show & (1<<PIN_AVR_SCK))
avrdude_message(MSG_INFO, "%s SCK = %s\n", p, pins_to_str(&pgm->pin[PIN_AVR_SCK])); msg_info("%s SCK = %s\n", p, pins_to_str(&pgm->pin[PIN_AVR_SCK]));
if(show & (1<<PIN_AVR_MOSI)) if(show & (1<<PIN_AVR_MOSI))
avrdude_message(MSG_INFO, "%s MOSI = %s\n", p, pins_to_str(&pgm->pin[PIN_AVR_MOSI])); msg_info("%s MOSI = %s\n", p, pins_to_str(&pgm->pin[PIN_AVR_MOSI]));
if(show & (1<<PIN_AVR_MISO)) if(show & (1<<PIN_AVR_MISO))
avrdude_message(MSG_INFO, "%s MISO = %s\n", p, pins_to_str(&pgm->pin[PIN_AVR_MISO])); msg_info("%s MISO = %s\n", p, pins_to_str(&pgm->pin[PIN_AVR_MISO]));
if(show & (1<<PIN_LED_ERR)) if(show & (1<<PIN_LED_ERR))
avrdude_message(MSG_INFO, "%s ERR LED = %s\n", p, pins_to_str(&pgm->pin[PIN_LED_ERR])); msg_info("%s ERR LED = %s\n", p, pins_to_str(&pgm->pin[PIN_LED_ERR]));
if(show & (1<<PIN_LED_RDY)) if(show & (1<<PIN_LED_RDY))
avrdude_message(MSG_INFO, "%s RDY LED = %s\n", p, pins_to_str(&pgm->pin[PIN_LED_RDY])); msg_info("%s RDY LED = %s\n", p, pins_to_str(&pgm->pin[PIN_LED_RDY]));
if(show & (1<<PIN_LED_PGM)) if(show & (1<<PIN_LED_PGM))
avrdude_message(MSG_INFO, "%s PGM LED = %s\n", p, pins_to_str(&pgm->pin[PIN_LED_PGM])); msg_info("%s PGM LED = %s\n", p, pins_to_str(&pgm->pin[PIN_LED_PGM]));
if(show & (1<<PIN_LED_VFY)) if(show & (1<<PIN_LED_VFY))
avrdude_message(MSG_INFO, "%s VFY LED = %s\n", p, pins_to_str(&pgm->pin[PIN_LED_VFY])); msg_info("%s VFY LED = %s\n", p, pins_to_str(&pgm->pin[PIN_LED_VFY]));
} }
void pgm_display_generic(const PROGRAMMER *pgm, const char *p) { void pgm_display_generic(const PROGRAMMER *pgm, const char *p) {

View File

@ -72,13 +72,13 @@
#endif #endif
#if 0 #if 0
#define DEBUG(...) do { avrdude_message(MSG_DEBUG, __VA_ARGS__); } while(0) #define DEBUG(...) do { msg_debug(__VA_ARGS__); } while(0)
#else #else
#define DEBUG(...) ((void)0) #define DEBUG(...) ((void)0)
#endif #endif
#if 0 #if 0
#define DEBUGRECV(...) do { avrdude_message(MSG_DEBUG, __VA_ARGS__); } while(0) #define DEBUGRECV(...) do { msg_debug(__VA_ARGS__); } while(0)
#else #else
#define DEBUGRECV(...) ((void)0) #define DEBUGRECV(...) ((void)0)
#endif #endif
@ -164,8 +164,7 @@ static void pickit2_setup(PROGRAMMER * pgm)
{ {
if ((pgm->cookie = malloc(sizeof(struct pdata))) == 0) if ((pgm->cookie = malloc(sizeof(struct pdata))) == 0)
{ {
avrdude_message(MSG_INFO, "%s: pickit2_setup(): Out of memory allocating private data\n", pmsg_error("out of memory allocating private data\n");
progname);
exit(1); exit(1);
} }
memset(pgm->cookie, 0, sizeof(struct pdata)); memset(pgm->cookie, 0, sizeof(struct pdata));
@ -186,8 +185,7 @@ static int pickit2_open(PROGRAMMER *pgm, const char *port) {
if (PDATA(pgm)->usb_handle == INVALID_HANDLE_VALUE) if (PDATA(pgm)->usb_handle == INVALID_HANDLE_VALUE)
{ {
/* no PICkit2 found */ /* no PICkit2 found */
avrdude_message(MSG_INFO, "%s: error: could not find PICkit2 with vid=0x%x pid=0x%x\n", pmsg_error("cannot find PICkit2 with vid=0x%x pid=0x%x\n", PICKIT2_VID, PICKIT2_PID);
progname, PICKIT2_VID, PICKIT2_PID);
return -1; return -1;
} }
else else
@ -209,8 +207,7 @@ static int pickit2_open(PROGRAMMER *pgm, const char *port) {
if (usb_open_device(&(PDATA(pgm)->usb_handle), PICKIT2_VID, PICKIT2_PID) < 0) if (usb_open_device(&(PDATA(pgm)->usb_handle), PICKIT2_VID, PICKIT2_PID) < 0)
{ {
/* no PICkit2 found */ /* no PICkit2 found */
avrdude_message(MSG_INFO, "%s: error: could not find PICkit2 with vid=0x%x pid=0x%x\n", pmsg_error("cannot find PICkit2 with vid=0x%x pid=0x%x\n", PICKIT2_VID, PICKIT2_PID);
progname, PICKIT2_VID, PICKIT2_PID);
return -1; return -1;
} }
#endif #endif
@ -258,7 +255,7 @@ static int pickit2_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
//memset(report, 0, sizeof(report)); //memset(report, 0, sizeof(report));
if ((errorCode = pickit2_read_report(pgm, report)) >= 4) if ((errorCode = pickit2_read_report(pgm, report)) >= 4)
{ {
avrdude_message(MSG_NOTICE, "%s: %s firmware version %d.%d.%d\n", progname, pgm->desc, (int)report[1], (int)report[2], (int)report[3]); pmsg_notice("%s firmware version %d.%d.%d\n", pgm->desc, (int)report[1], (int)report[2], (int)report[3]);
// set the pins, apply reset, // set the pins, apply reset,
// TO DO: apply vtarget (if requested though -x option) // TO DO: apply vtarget (if requested though -x option)
@ -293,19 +290,19 @@ static int pickit2_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
if (pickit2_write_report(pgm, report) < 0) if (pickit2_write_report(pgm, report) < 0)
{ {
avrdude_message(MSG_INFO, "pickit2_read_report failed (ec %d). %s\n", errorCode, usb_strerror()); pmsg_error("pickit2_read_report failed (ec %d). %s\n", errorCode, usb_strerror());
return -1; return -1;
} }
} }
else else
{ {
avrdude_message(MSG_INFO, "pickit2_read_report failed (ec %d). %s\n", errorCode, usb_strerror()); pmsg_error("pickit2_read_report failed (ec %d). %s\n", errorCode, usb_strerror());
return -1; return -1;
} }
} }
else else
{ {
avrdude_message(MSG_INFO, "pickit2_write_report failed (ec %d). %s\n", errorCode, usb_strerror()); pmsg_error("pickit2_write_report failed (ec %d). %s\n", errorCode, usb_strerror());
return -1; return -1;
} }
@ -341,7 +338,7 @@ static void pickit2_enable(PROGRAMMER *pgm, const AVRPART *p) {
} }
static void pickit2_display(const PROGRAMMER *pgm, const char *p) { static void pickit2_display(const PROGRAMMER *pgm, const char *p) {
DEBUG( "%s: Found \"%s\" version %d.%d.%d\n", progname, p, 1, 1, 1); DEBUG("%s: found %s version %d.%d.%d\n", progname, p, 1, 1, 1);
return; return;
} }
@ -408,8 +405,7 @@ static int pickit2_program_enable(const PROGRAMMER *pgm, const AVRPART *p) {
if (p->op[AVR_OP_PGM_ENABLE] == NULL) if (p->op[AVR_OP_PGM_ENABLE] == NULL)
{ {
avrdude_message(MSG_INFO, "program enable instruction not defined for part \"%s\"\n", pmsg_error("program enable instruction not defined for part %s\n", p->desc);
p->desc);
return -1; return -1;
} }
@ -419,13 +415,13 @@ static int pickit2_program_enable(const PROGRAMMER *pgm, const AVRPART *p) {
{ {
int i; int i;
avrdude_message(MSG_DEBUG, "program_enable(): sending command. Resp = "); msg_debug("program_enable(): sending command. Resp = ");
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
{ {
avrdude_message(MSG_DEBUG, "%x ", (int)res[i]); msg_debug("%x ", (int)res[i]);
} }
avrdude_message(MSG_DEBUG, "\n"); msg_debug("\n");
} }
// check for sync character // check for sync character
@ -441,8 +437,7 @@ static int pickit2_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) {
if (p->op[AVR_OP_CHIP_ERASE] == NULL) if (p->op[AVR_OP_CHIP_ERASE] == NULL)
{ {
avrdude_message(MSG_INFO, "chip erase instruction not defined for part \"%s\"\n", pmsg_error("chip erase instruction not defined for part %s\n", p->desc);
p->desc);
return -1; return -1;
} }
@ -515,7 +510,7 @@ static int pickit2_paged_load(const PROGRAMMER *pgm, const AVRPART *p, const AVR
} }
else else
{ {
avrdude_message(MSG_INFO, "no read command specified\n"); pmsg_error("no read command specified\n");
return -1; return -1;
} }
@ -527,7 +522,7 @@ static int pickit2_paged_load(const PROGRAMMER *pgm, const AVRPART *p, const AVR
if (bytes_read < 0) if (bytes_read < 0)
{ {
avrdude_message(MSG_INFO, "Failed @ pgm->spi()\n"); pmsg_error("failed @ pgm->spi()\n");
pgm->err_led(pgm, ON); pgm->err_led(pgm, ON);
return -1; return -1;
} }
@ -561,8 +556,7 @@ static int pickit2_commit_page(const PROGRAMMER *pgm, const AVRPART *p, const AV
wp = mem->op[AVR_OP_WRITEPAGE]; wp = mem->op[AVR_OP_WRITEPAGE];
if (wp == NULL) if (wp == NULL)
{ {
avrdude_message(MSG_INFO, "pickit2_commit_page(): memory \"%s\" not configured for page writes\n", pmsg_error("memory %s not configured for page writes\n", mem->desc);
mem->desc);
return -1; return -1;
} }
@ -609,7 +603,7 @@ static int pickit2_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const A
// only paged write for flash implemented // only paged write for flash implemented
if (strcmp(mem->desc, "flash") != 0 && strcmp(mem->desc, "eeprom") != 0) if (strcmp(mem->desc, "flash") != 0 && strcmp(mem->desc, "eeprom") != 0)
{ {
avrdude_message(MSG_INFO, "Part does not support %d paged write of %s\n", page_size, mem->desc); pmsg_error("part does not support %d paged write of %s\n", page_size, mem->desc);
return -1; return -1;
} }
@ -666,7 +660,7 @@ static int pickit2_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const A
writeop = mem->op[AVR_OP_WRITE_LO]; writeop = mem->op[AVR_OP_WRITE_LO];
caddr = addr; // maybe this should divide by 2 & use the write_high opcode also caddr = addr; // maybe this should divide by 2 & use the write_high opcode also
avrdude_message(MSG_INFO, "Error AVR_OP_WRITE_LO defined only (where's the HIGH command?)\n"); pmsg_error("%s AVR_OP_WRITE_LO defined only (where is the HIGH command?)\n", mem->desc);
return -1; return -1;
} }
else else
@ -691,7 +685,7 @@ static int pickit2_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const A
if (bytes_read < 0) if (bytes_read < 0)
{ {
avrdude_message(MSG_INFO, "Failed @ pgm->spi()\n"); pmsg_error("failed @ pgm->spi()\n");
pgm->err_led(pgm, ON); pgm->err_led(pgm, ON);
return -1; return -1;
} }
@ -1129,25 +1123,27 @@ static int usb_open_device(struct usb_dev_handle **device, int vendor, int produ
if (handle == NULL) if (handle == NULL)
{ {
errorCode = USB_ERROR_ACCESS; errorCode = USB_ERROR_ACCESS;
avrdude_message(MSG_INFO, "%s: Warning: cannot open USB device: %s\n", progname, usb_strerror()); pmsg_warning("cannot open USB device: %s\n", usb_strerror());
continue; continue;
} }
// return with opened device handle // return with opened device handle
else else
{ {
avrdude_message(MSG_NOTICE, "Device %p seemed to open OK.\n", handle); msg_notice("device %p seemed to open OK\n", handle);
if ((errorCode = usb_set_configuration(handle, 1)) < 0) if ((errorCode = usb_set_configuration(handle, 1)) < 0)
{ {
avrdude_message(MSG_INFO, "Could not set configuration. Error code %d, %s.\n" pmsg_ext_error("cannot set configuration, error code %d, %s\n"
"You may need to run avrdude as root or set up correct usb port permissions.", errorCode, usb_strerror()); "you may need to run avrdude as root or set up correct usb port permissions",
errorCode, usb_strerror());
} }
if ((errorCode = usb_claim_interface(handle, 0)) < 0) if ((errorCode = usb_claim_interface(handle, 0)) < 0)
{ {
avrdude_message(MSG_INFO, "Could not claim interface. Error code %d, %s\n" pmsg_ext_error("cannot claim interface, error code %d, %s\n"
"You may need to run avrdude as root or set up correct usb port permissions.", errorCode, usb_strerror()); "You may need to run avrdude as root or set up correct usb port permissions.",
errorCode, usb_strerror());
} }
errorCode = 0; errorCode = 0;
@ -1186,8 +1182,7 @@ static int pickit2_parseextparams(const PROGRAMMER *pgm, const LISTID extparms)
int clock_rate; int clock_rate;
if (sscanf(extended_param, "clockrate=%i", &clock_rate) != 1 || clock_rate <= 0) if (sscanf(extended_param, "clockrate=%i", &clock_rate) != 1 || clock_rate <= 0)
{ {
avrdude_message(MSG_INFO, "%s: pickit2_parseextparms(): invalid clockrate '%s'\n", pmsg_error("invalid clockrate '%s'\n", extended_param);
progname, extended_param);
rv = -1; rv = -1;
continue; continue;
} }
@ -1195,8 +1190,7 @@ static int pickit2_parseextparams(const PROGRAMMER *pgm, const LISTID extparms)
int clock_period = MIN(1000000 / clock_rate, 255); // max period is 255 int clock_period = MIN(1000000 / clock_rate, 255); // max period is 255
clock_rate = (int)(1000000 / (clock_period + 5e-7)); // assume highest speed is 2MHz - should probably check this clock_rate = (int)(1000000 / (clock_period + 5e-7)); // assume highest speed is 2MHz - should probably check this
avrdude_message(MSG_NOTICE2, "%s: pickit2_parseextparms(): clockrate set to 0x%02x\n", pmsg_notice2("pickit2_parseextparms(): clockrate set to 0x%02x\n", clock_rate);
progname, clock_rate);
PDATA(pgm)->clock_period = clock_period; PDATA(pgm)->clock_period = clock_period;
continue; continue;
@ -1207,21 +1201,18 @@ static int pickit2_parseextparams(const PROGRAMMER *pgm, const LISTID extparms)
int timeout; int timeout;
if (sscanf(extended_param, "timeout=%i", &timeout) != 1 || timeout <= 0) if (sscanf(extended_param, "timeout=%i", &timeout) != 1 || timeout <= 0)
{ {
avrdude_message(MSG_INFO, "%s: pickit2_parseextparms(): invalid timeout '%s'\n", pmsg_error("invalid timeout '%s'\n", extended_param);
progname, extended_param);
rv = -1; rv = -1;
continue; continue;
} }
avrdude_message(MSG_NOTICE2, "%s: pickit2_parseextparms(): usb timeout set to 0x%02x\n", pmsg_notice2("pickit2_parseextparms(): usb timeout set to 0x%02x\n", timeout);
progname, timeout);
PDATA(pgm)->transaction_timeout = timeout; PDATA(pgm)->transaction_timeout = timeout;
continue; continue;
} }
avrdude_message(MSG_INFO, "%s: pickit2_parseextparms(): invalid extended parameter '%s'\n", pmsg_error("invalid extended parameter '%s'\n", extended_param);
progname, extended_param);
rv = -1; rv = -1;
} }
@ -1279,19 +1270,19 @@ void pickit2_initpgm(PROGRAMMER *pgm) {
pgm->setup = pickit2_setup; pgm->setup = pickit2_setup;
pgm->teardown = pickit2_teardown; pgm->teardown = pickit2_teardown;
// pgm->page_size = 256; // not sure what this does... maybe the max page size that the page read/write function can handle // pgm->page_size = 256; // not sure what this does ... maybe the max page size that the page read/write function can handle
strncpy(pgm->type, "pickit2", sizeof(pgm->type)); strncpy(pgm->type, "pickit2", sizeof(pgm->type));
} }
#else #else
static int pickit2_nousb_open(PROGRAMMER *pgm, const char *name) { static int pickit2_nousb_open(PROGRAMMER *pgm, const char *name) {
avrdude_message(MSG_INFO, pmsg_error(
#ifdef WIN32 #ifdef WIN32
"%s: error: no usb or hid support. Please compile again with libusb or HID support from Win32 DDK installed.\n", "no usb or hid support; please compile again with libusb or HID support from Win32 DDK installed\n"
#else #else
"%s: error: no usb support. Please compile again with libusb installed.\n", "no usb support; please compile again with libusb installed\n"
#endif #endif
progname); );
return -1; return -1;
} }

View File

@ -64,7 +64,7 @@ static int pin_fill_old_pinno(const struct pindef_t * const pindef, unsigned int
for(i = 0; i < PIN_MAX; i++) { for(i = 0; i < PIN_MAX; i++) {
if(pindef->mask[i / PIN_FIELD_ELEMENT_SIZE] & (1 << (i % PIN_FIELD_ELEMENT_SIZE))) { if(pindef->mask[i / PIN_FIELD_ELEMENT_SIZE] & (1 << (i % PIN_FIELD_ELEMENT_SIZE))) {
if(found) { if(found) {
avrdude_message(MSG_INFO, "Multiple pins found\n"); //TODO pmsg_error("multiple pins found\n"); // TODO
return -1; return -1;
} }
found = true; found = true;
@ -89,7 +89,7 @@ static int pin_fill_old_pinlist(const struct pindef_t * const pindef, unsigned i
for(i = 0; i < PIN_FIELD_SIZE; i++) { for(i = 0; i < PIN_FIELD_SIZE; i++) {
if(i == 0) { if(i == 0) {
if((pindef->mask[i] & ~PIN_MASK) != 0) { if((pindef->mask[i] & ~PIN_MASK) != 0) {
avrdude_message(MSG_INFO, "Pins of higher index than max field size for old pinno found\n"); pmsg_error("pins of higher index than max field size for old pinno found\n");
return -1; return -1;
} }
if (pindef->mask[i] == 0) { if (pindef->mask[i] == 0) {
@ -101,11 +101,11 @@ static int pin_fill_old_pinlist(const struct pindef_t * const pindef, unsigned i
} else if(pindef->mask[i] == ((~pindef->inverse[i]) & pindef->mask[i])) { /* all set bits in mask are cleared in inverse */ } else if(pindef->mask[i] == ((~pindef->inverse[i]) & pindef->mask[i])) { /* all set bits in mask are cleared in inverse */
*pinno = pindef->mask[i]; *pinno = pindef->mask[i];
} else { } else {
avrdude_message(MSG_INFO, "pins have different polarity set\n"); pmsg_error("pins have different polarity set\n");
return -1; return -1;
} }
} else if(pindef->mask[i] != 0) { } else if(pindef->mask[i] != 0) {
avrdude_message(MSG_INFO, "Pins have higher number than fit in old format\n"); pmsg_error("pins have higher number than fit in old format\n");
return -1; return -1;
} }
} }
@ -271,41 +271,39 @@ int pins_check(const PROGRAMMER *const pgm, const struct pin_checklist_t *const
} }
if(invalid) { if(invalid) {
if(output) { if(output) {
avrdude_message(MSG_INFO, "%s: %s: Following pins are not valid pins for this function: %s\n", pmsg_error("%s: these pins are not valid pins for this function: %s\n",
progname, avr_pin_name(pinname), pinmask_to_str(invalid_used)); avr_pin_name(pinname), pinmask_to_str(invalid_used));
avrdude_message(MSG_NOTICE2, "%s: %s: Valid pins for this function are: %s\n", pmsg_notice("%s: valid pins for this function are: %s\n",
progname, avr_pin_name(pinname), pinmask_to_str(valid_pins->mask)); avr_pin_name(pinname), pinmask_to_str(valid_pins->mask));
} }
is_ok = false; is_ok = false;
} }
if(inverse) { if(inverse) {
if(output) { if(output) {
avrdude_message(MSG_INFO, "%s: %s: Following pins are not usable as inverse pins for this function: %s\n", pmsg_error("%s: these pins are not usable as inverse pins for this function: %s\n",
progname, avr_pin_name(pinname), pinmask_to_str(inverse_used)); avr_pin_name(pinname), pinmask_to_str(inverse_used));
avrdude_message(MSG_NOTICE2, "%s: %s: Valid inverse pins for this function are: %s\n", pmsg_notice("%s: valid inverse pins for this function are: %s\n",
progname, avr_pin_name(pinname), pinmask_to_str(valid_pins->inverse)); avr_pin_name(pinname), pinmask_to_str(valid_pins->inverse));
} }
is_ok = false; is_ok = false;
} }
if(used) { if(used) {
if(output) { if(output) {
avrdude_message(MSG_INFO, "%s: %s: Following pins are set for other functions too: %s\n", pmsg_error("%s: these pins are set for other functions too: %s\n",
progname, avr_pin_name(pinname), pinmask_to_str(already_used)); avr_pin_name(pinname), pinmask_to_str(already_used));
is_ok = false; is_ok = false;
} }
} }
if(!mandatory_used && is_mandatory && !invalid) { if(!mandatory_used && is_mandatory && !invalid) {
if(output) { if(output) {
avrdude_message(MSG_INFO, "%s: %s: Mandatory pin is not defined.\n", pmsg_error("%s: mandatory pin is not defined\n", avr_pin_name(pinname));
progname, avr_pin_name(pinname));
} }
is_ok = false; is_ok = false;
} }
if(!is_ok) { if(!is_ok) {
rv = -1; rv = -1;
} else if(output) { } else if(output) {
avrdude_message(MSG_DEBUG, "%s: %s: Pin is ok.\n", pmsg_debug("%s: pin is OK\n", avr_pin_name(pinname));
progname, avr_pin_name(pinname));
} }
} }
return rv; return rv;

View File

@ -68,8 +68,7 @@ static int ppi_shadow_access(const union filedescriptor *fdp, int reg,
shadow_num = 2; shadow_num = 2;
break; break;
default: default:
avrdude_message(MSG_INFO, "%s: avr_set(): invalid register=%d\n", pmsg_error("invalid register=%d\n", reg);
progname, reg);
return -1; return -1;
break; break;
} }
@ -198,8 +197,7 @@ void ppi_open(const char *port, union filedescriptor *fdp) {
fd = open(port, O_RDWR); fd = open(port, O_RDWR);
if (fd < 0) { if (fd < 0) {
avrdude_message(MSG_INFO, "%s: can't open device \"%s\": %s\n", pmsg_ext_error("cannot open port %s: %s\n", port, strerror(errno));
progname, port, strerror(errno));
fdp->ifd = -1; fdp->ifd = -1;
return; return;
} }

View File

@ -92,7 +92,7 @@ void ppi_open(const char *port, union filedescriptor *fdp) {
if(fd < 0) if(fd < 0)
{ {
avrdude_message(MSG_INFO, "%s: can't open device \"giveio\"\n\n", progname); pmsg_ext_error("cannot open device \"giveio\"\n\n"); // giveio?!? FIXME!
fdp->ifd = -1; fdp->ifd = -1;
return; return;
} }
@ -120,14 +120,13 @@ void ppi_open(const char *port, union filedescriptor *fdp) {
fd = strtol(port, &cp, 0); fd = strtol(port, &cp, 0);
if(*port == '\0' || *cp != '\0') if(*port == '\0' || *cp != '\0')
{ {
avrdude_message(MSG_INFO, "%s: port name \"%s\" is neither lpt1/2/3 nor valid number\n", pmsg_error("port %s is neither lpt1/2/3 nor valid number\n", port);
progname, port);
fd = -1; fd = -1;
} }
} }
if(fd < 0) if(fd < 0)
{ {
avrdude_message(MSG_INFO, "%s: can't open device \"%s\"\n\n", progname, port); pmsg_ext_error("cannot open port %s\n\n", port);
fdp->ifd = -1; fdp->ifd = -1;
return; return;
} }

View File

@ -73,8 +73,7 @@ static int usbOpenDevice(union filedescriptor *fdp, int vendor, const char *vend
dev = hid_open(vendor, product, NULL); dev = hid_open(vendor, product, NULL);
if (dev == NULL) if (dev == NULL)
{ {
avrdude_message(MSG_INFO, "%s: usbOpenDevice(): No device found\n", pmsg_ext_error("no device found\n");
progname);
return USB_ERROR_NOTFOUND; return USB_ERROR_NOTFOUND;
} }
fdp->usb.handle = dev; fdp->usb.handle = dev;
@ -113,7 +112,7 @@ static int usbSetReport(const union filedescriptor *fdp, int reportType, char *b
if(bytesSent != len){ if(bytesSent != len){
if(bytesSent < 0) if(bytesSent < 0)
avrdude_message(MSG_INFO, "Error sending message: %s\n", hid_error(udev)); pmsg_error("unable to send message: %ls\n", hid_error(udev));
return USB_ERROR_IO; return USB_ERROR_IO;
} }
return USB_ERROR_NONE; return USB_ERROR_NONE;
@ -138,7 +137,7 @@ static int usbGetReport(const union filedescriptor *fdp, int reportType, int rep
break; break;
} }
if(bytesReceived < 0){ if(bytesReceived < 0){
avrdude_message(MSG_INFO, "Error sending message: %s\n", hid_error(udev)); pmsg_error("unable to send message: %ls\n", hid_error(udev));
return USB_ERROR_IO; return USB_ERROR_IO;
} }
*len = bytesReceived; *len = bytesReceived;
@ -160,42 +159,30 @@ static void dumpBlock(const char *prefix, const unsigned char *buf, int len)
int i; int i;
if(len <= 8){ /* more compact format for short blocks */ if(len <= 8){ /* more compact format for short blocks */
avrdude_message(MSG_INFO, "%s: %d bytes: ", prefix, len); msg_info("%s: %d bytes: ", prefix, len);
for(i = 0; i < len; i++){ for(i = 0; i < len; i++){
avrdude_message(MSG_INFO, "%02x ", buf[i]); msg_info("%02x ", buf[i]);
} }
avrdude_message(MSG_INFO, " \""); msg_info(" \"");
for(i = 0; i < len; i++){ for(i = 0; i < len; i++)
if(buf[i] >= 0x20 && buf[i] < 0x7f){ msg_info("%c", buf[i] >= 0x20 && buf[i] < 0x7f? buf[i]: '.');
fputc(buf[i], stderr); msg_info("\"\n");
}else{
fputc('.', stderr);
}
}
avrdude_message(MSG_INFO, "\"\n");
}else{ }else{
avrdude_message(MSG_INFO, "%s: %d bytes:\n", prefix, len); msg_info("%s: %d bytes:\n", prefix, len);
while(len > 0){ while(len > 0){
for(i = 0; i < 16; i++){ for(i = 0; i < 16; i++){
if(i < len){ if(i < len){
avrdude_message(MSG_INFO, "%02x ", buf[i]); msg_info("%02x ", buf[i]);
}else{ }else{
avrdude_message(MSG_INFO, " "); msg_info(" ");
} }
if(i == 7) if(i == 7)
fputc(' ', stderr); msg_info(" ");
} }
avrdude_message(MSG_INFO, " \""); msg_info(" \"");
for(i = 0; i < 16; i++){ for(i = 0; i < 16 && i < len; i++)
if(i < len){ msg_info("%c", buf[i] >= 0x20 && buf[i] < 0x7f? buf[i]: '.');
if(buf[i] >= 0x20 && buf[i] < 0x7f){ msg_info("\"\n");
fputc(buf[i], stderr);
}else{
fputc('.', stderr);
}
}
}
avrdude_message(MSG_INFO, "\"\n");
buf += 16; buf += 16;
len -= 16; len -= 16;
} }
@ -207,13 +194,13 @@ static char *usbErrorText(int usbErrno)
static char buffer[32]; static char buffer[32];
switch(usbErrno){ switch(usbErrno){
case USB_ERROR_NONE: return "Success."; case USB_ERROR_NONE: return "Success";
case USB_ERROR_ACCESS: return "Access denied."; case USB_ERROR_ACCESS: return "Access denied";
case USB_ERROR_NOTFOUND:return "Device not found."; case USB_ERROR_NOTFOUND:return "Device not found";
case USB_ERROR_BUSY: return "Device is busy."; case USB_ERROR_BUSY: return "Device is busy";
case USB_ERROR_IO: return "I/O Error."; case USB_ERROR_IO: return "I/O Error";
default: default:
sprintf(buffer, "Unknown error %d.", usbErrno); sprintf(buffer, "Unknown error %d", usbErrno);
return buffer; return buffer;
} }
} }
@ -228,7 +215,7 @@ static int avrdoper_open(const char *port, union pinfo pinfo, union filedescript
rval = usbOpenDevice(fdp, USB_VENDOR_ID, vname, USB_PRODUCT_ID, devname, 1); rval = usbOpenDevice(fdp, USB_VENDOR_ID, vname, USB_PRODUCT_ID, devname, 1);
if(rval != 0){ if(rval != 0){
avrdude_message(MSG_INFO, "%s: avrdoper_open(): %s\n", progname, usbErrorText(rval)); pmsg_ext_error("%s\n", usbErrorText(rval));
return -1; return -1;
} }
return 0; return 0;
@ -266,11 +253,11 @@ static int avrdoper_send(const union filedescriptor *fdp, const unsigned char *b
buffer[0] = lenIndex + 1; /* report ID */ buffer[0] = lenIndex + 1; /* report ID */
buffer[1] = thisLen; buffer[1] = thisLen;
memcpy(buffer + 2, buf, thisLen); memcpy(buffer + 2, buf, thisLen);
avrdude_message(MSG_TRACE, "Sending %d bytes data chunk\n", thisLen); msg_trace("Sending %d bytes data chunk\n", thisLen);
rval = usbSetReport(fdp, USB_HID_REPORT_TYPE_FEATURE, (char *)buffer, rval = usbSetReport(fdp, USB_HID_REPORT_TYPE_FEATURE, (char *)buffer,
reportDataSizes[lenIndex] + 2); reportDataSizes[lenIndex] + 2);
if(rval != 0){ if(rval != 0){
avrdude_message(MSG_INFO, "%s: avrdoper_send(): %s\n", progname, usbErrorText(rval)); pmsg_error("%s\n", usbErrorText(rval));
return -1; return -1;
} }
buflen -= thisLen; buflen -= thisLen;
@ -295,17 +282,16 @@ static int avrdoperFillBuffer(const union filedescriptor *fdp) {
usbErr = usbGetReport(fdp, USB_HID_REPORT_TYPE_FEATURE, lenIndex + 1, usbErr = usbGetReport(fdp, USB_HID_REPORT_TYPE_FEATURE, lenIndex + 1,
(char *)buffer, &len); (char *)buffer, &len);
if(usbErr != 0){ if(usbErr != 0){
avrdude_message(MSG_INFO, "%s: avrdoperFillBuffer(): %s\n", progname, usbErrorText(usbErr)); pmsg_error("%s\n", usbErrorText(usbErr));
return -1; return -1;
} }
avrdude_message(MSG_TRACE, "Received %d bytes data chunk of total %d\n", len - 2, buffer[1]); msg_trace("Received %d bytes data chunk of total %d\n", len - 2, buffer[1]);
len -= 2; /* compensate for report ID and length byte */ len -= 2; /* compensate for report ID and length byte */
bytesPending = buffer[1] - len; /* amount still buffered */ bytesPending = buffer[1] - len; /* amount still buffered */
if(len > buffer[1]) /* cut away padding */ if(len > buffer[1]) /* cut away padding */
len = buffer[1]; len = buffer[1];
if(avrdoperRxLength + len > sizeof(avrdoperRxBuffer)){ if(avrdoperRxLength + len > sizeof(avrdoperRxBuffer)){
avrdude_message(MSG_INFO, "%s: avrdoperFillBuffer(): internal error: buffer overflow\n", pmsg_error("buffer overflow\n");
progname);
return -1; return -1;
} }
memcpy(avrdoperRxBuffer + avrdoperRxLength, buffer + 2, len); memcpy(avrdoperRxBuffer + avrdoperRxLength, buffer + 2, len);
@ -352,7 +338,7 @@ static int avrdoper_drain(const union filedescriptor *fdp, int display)
static int avrdoper_set_dtr_rts(const union filedescriptor *fdp, int is_on) static int avrdoper_set_dtr_rts(const union filedescriptor *fdp, int is_on)
{ {
avrdude_message(MSG_INFO, "%s: AVR-Doper doesn't support DTR/RTS setting\n", progname); pmsg_error("AVR-Doper does not support DTR/RTS setting\n");
return -1; return -1;
} }

View File

@ -137,8 +137,7 @@ static speed_t serial_baud_lookup(long baud, bool *nonstandard) {
* If a non-standard BAUD rate is used, issue * If a non-standard BAUD rate is used, issue
* a warning (if we are verbose) and return the raw rate * a warning (if we are verbose) and return the raw rate
*/ */
avrdude_message(MSG_NOTICE, "%s: serial_baud_lookup(): Using non-standard baud rate: %ld\n", pmsg_notice("serial_baud_lookup(): using non-standard baud rate: %ld\n", baud);
progname, baud);
*nonstandard = true; *nonstandard = true;
@ -159,9 +158,9 @@ static int ser_setparams(const union filedescriptor *fd, long baud, unsigned lon
*/ */
rc = tcgetattr(fd->ifd, &termios); rc = tcgetattr(fd->ifd, &termios);
if (rc < 0) { if (rc < 0) {
avrdude_message(MSG_INFO, "%s: ser_setparams(): tcgetattr() failed", int ret = -errno;
progname); pmsg_ext_error("tcgetattr() failed\n");
return -errno; return ret;
} }
/* /*
@ -254,18 +253,18 @@ static int ser_setparams(const union filedescriptor *fd, long baud, unsigned lon
rc = tcsetattr(fd->ifd, TCSANOW, &termios); rc = tcsetattr(fd->ifd, TCSANOW, &termios);
if (rc < 0) { if (rc < 0) {
avrdude_message(MSG_INFO, "%s: ser_setparams(): tcsetattr() failed\n", int ret = -errno;
progname); pmsg_ext_error("tcsetattr() failed\n");
return -errno; return ret;
} }
#ifdef __APPLE__ #ifdef __APPLE__
// handle nonstandard speed values the MacOS way // handle nonstandard speed values the MacOS way
if (nonstandard) { if (nonstandard) {
if (ioctl(fd->ifd, IOSSIOSPEED, &speed) < 0) { if (ioctl(fd->ifd, IOSSIOSPEED, &speed) < 0) {
avrdude_message(MSG_INFO, "%s: ser_setparams(): ioctrl(IOSSIOSPEED) failed\n", int ret = -errno;
progname); pmsg_ext_error("ioctrl(IOSSIOSPEED) failed\n");
return -errno; return ret;
} }
} }
#endif // __APPLE__ #endif // __APPLE__
@ -288,8 +287,7 @@ static int net_open(const char *port, union filedescriptor *fdp) {
struct addrinfo *result, *rp; struct addrinfo *result, *rp;
if ((hstr = hp = strdup(port)) == NULL) { if ((hstr = hp = strdup(port)) == NULL) {
avrdude_message(MSG_INFO, "%s: net_open(): Out of memory!\n", pmsg_error("out of memory\n");
progname);
return -1; return -1;
} }
@ -299,8 +297,7 @@ static int net_open(const char *port, union filedescriptor *fdp) {
* service name from the host or IP address. * service name from the host or IP address.
*/ */
if (((pstr = strrchr(hstr, ':')) == NULL) || (pstr == hstr)) { if (((pstr = strrchr(hstr, ':')) == NULL) || (pstr == hstr)) {
avrdude_message(MSG_INFO, "%s: net_open(): Mangled host:port string \"%s\"\n", pmsg_error("mangled host:port string %s\n", hstr);
progname, hstr);
goto error; goto error;
} }
@ -323,10 +320,8 @@ static int net_open(const char *port, union filedescriptor *fdp) {
s = getaddrinfo(hstr, pstr, &hints, &result); s = getaddrinfo(hstr, pstr, &hints, &result);
if (s != 0) { if (s != 0) {
avrdude_message(MSG_INFO, pmsg_ext_error("cannot resolve host=\"%s\", port=\"%s\": %s\n",
"%s: net_open(): Cannot resolve " hstr, pstr, gai_strerror(s));
"host=\"%s\", port=\"%s\": %s\n",
progname, hstr, pstr, gai_strerror(s));
goto error; goto error;
} }
for (rp = result; rp != NULL; rp = rp->ai_next) { for (rp = result; rp != NULL; rp = rp->ai_next) {
@ -342,8 +337,7 @@ static int net_open(const char *port, union filedescriptor *fdp) {
close(fd); close(fd);
} }
if (rp == NULL) { if (rp == NULL) {
avrdude_message(MSG_INFO, "%s: net_open(): Cannot connect: %s\n", pmsg_ext_error("cannot connect: %s\n", strerror(errno));
progname, strerror(errno));
} }
else { else {
fdp->ifd = fd; fdp->ifd = fd;
@ -363,7 +357,7 @@ static int ser_set_dtr_rts(const union filedescriptor *fdp, int is_on) {
r = ioctl(fdp->ifd, TIOCMGET, &ctl); r = ioctl(fdp->ifd, TIOCMGET, &ctl);
if (r < 0) { if (r < 0) {
perror("ioctl(\"TIOCMGET\")"); pmsg_ext_error("ioctl(\"TIOCMGET\"): %s\n", strerror(errno));
return -1; return -1;
} }
@ -378,7 +372,7 @@ static int ser_set_dtr_rts(const union filedescriptor *fdp, int is_on) {
r = ioctl(fdp->ifd, TIOCMSET, &ctl); r = ioctl(fdp->ifd, TIOCMSET, &ctl);
if (r < 0) { if (r < 0) {
perror("ioctl(\"TIOCMSET\")"); pmsg_ext_error("ioctl(\"TIOCMSET\"): %s\n", strerror(errno));
return -1; return -1;
} }
@ -402,8 +396,7 @@ static int ser_open(const char *port, union pinfo pinfo, union filedescriptor *f
*/ */
fd = open(port, O_RDWR | O_NOCTTY | O_NONBLOCK); fd = open(port, O_RDWR | O_NOCTTY | O_NONBLOCK);
if (fd < 0) { if (fd < 0) {
avrdude_message(MSG_INFO, "%s: ser_open(): can't open device \"%s\": %s\n", pmsg_ext_error("cannot open port %s: %s\n", port, strerror(errno));
progname, port, strerror(errno));
return -1; return -1;
} }
@ -414,8 +407,7 @@ static int ser_open(const char *port, union pinfo pinfo, union filedescriptor *f
*/ */
rc = ser_setparams(fdp, pinfo.serialinfo.baud, pinfo.serialinfo.cflags); rc = ser_setparams(fdp, pinfo.serialinfo.baud, pinfo.serialinfo.cflags);
if (rc) { if (rc) {
avrdude_message(MSG_INFO, "%s: ser_open(): can't set attributes for device \"%s\": %s\n", pmsg_ext_error("cannot set attributes for port %s: %s\n", port, strerror(-rc));
progname, port, strerror(-rc));
close(fd); close(fd);
return -1; return -1;
} }
@ -429,8 +421,7 @@ static void ser_close(union filedescriptor *fd) {
if (saved_original_termios) { if (saved_original_termios) {
int rc = tcsetattr(fd->ifd, TCSANOW | TCSADRAIN, &original_termios); int rc = tcsetattr(fd->ifd, TCSANOW | TCSADRAIN, &original_termios);
if (rc) { if (rc) {
avrdude_message(MSG_INFO, "%s: ser_close(): can't reset attributes for device: %s\n", pmsg_ext_error("cannot reset attributes for device: %s\n", strerror(errno));
progname, strerror(errno));
} }
saved_original_termios = 0; saved_original_termios = 0;
} }
@ -449,30 +440,29 @@ static int ser_send(const union filedescriptor *fd, const unsigned char * buf, s
if (verbose > 3) if (verbose > 3)
{ {
avrdude_message(MSG_TRACE, "%s: Send: ", progname); pmsg_trace("send: ");
while (buflen) { while (buflen) {
unsigned char c = *buf; unsigned char c = *buf;
if (isprint(c)) { if (isprint(c)) {
avrdude_message(MSG_TRACE, "%c ", c); msg_trace("%c ", c);
} }
else { else {
avrdude_message(MSG_TRACE, ". "); msg_trace(". ");
} }
avrdude_message(MSG_TRACE, "[%02x] ", c); msg_trace("[%02x] ", c);
buf++; buf++;
buflen--; buflen--;
} }
avrdude_message(MSG_TRACE, "\n"); msg_trace("\n");
} }
while (len) { while (len) {
rc = write(fd->ifd, p, (len > 1024) ? 1024 : len); rc = write(fd->ifd, p, (len > 1024) ? 1024 : len);
if (rc < 0) { if (rc < 0) {
avrdude_message(MSG_INFO, "%s: ser_send(): write error: %s\n", pmsg_ext_error("unable to write: %s\n", strerror(errno));
progname, strerror(errno));
return -1; return -1;
} }
p += rc; p += rc;
@ -502,27 +492,23 @@ static int ser_recv(const union filedescriptor *fd, unsigned char * buf, size_t
nfds = select(fd->ifd + 1, &rfds, NULL, NULL, &to2); nfds = select(fd->ifd + 1, &rfds, NULL, NULL, &to2);
if (nfds == 0) { if (nfds == 0) {
avrdude_message(MSG_NOTICE2, "%s: ser_recv(): programmer is not responding\n", pmsg_notice2("ser_recv(): programmer is not responding\n");
progname);
return -1; return -1;
} }
else if (nfds == -1) { else if (nfds == -1) {
if (errno == EINTR || errno == EAGAIN) { if (errno == EINTR || errno == EAGAIN) {
avrdude_message(MSG_INFO, "%s: ser_recv(): programmer is not responding,reselecting\n", pmsg_warning("programmer is not responding, reselecting\n");
progname);
goto reselect; goto reselect;
} }
else { else {
avrdude_message(MSG_INFO, "%s: ser_recv(): select(): %s\n", pmsg_ext_error("select(): %s\n", strerror(errno));
progname, strerror(errno));
return -1; return -1;
} }
} }
rc = read(fd->ifd, p, (buflen - len > 1024) ? 1024 : buflen - len); rc = read(fd->ifd, p, (buflen - len > 1024) ? 1024 : buflen - len);
if (rc < 0) { if (rc < 0) {
avrdude_message(MSG_INFO, "%s: ser_recv(): read error: %s\n", pmsg_ext_error("unable to read: %s\n", strerror(errno));
progname, strerror(errno));
return -1; return -1;
} }
p += rc; p += rc;
@ -533,22 +519,22 @@ static int ser_recv(const union filedescriptor *fd, unsigned char * buf, size_t
if (verbose > 3) if (verbose > 3)
{ {
avrdude_message(MSG_TRACE, "%s: Recv: ", progname); pmsg_trace("recv: ");
while (len) { while (len) {
unsigned char c = *p; unsigned char c = *p;
if (isprint(c)) { if (isprint(c)) {
avrdude_message(MSG_TRACE, "%c ", c); msg_trace("%c ", c);
} }
else { else {
avrdude_message(MSG_TRACE, ". "); msg_trace(". ");
} }
avrdude_message(MSG_TRACE, "[%02x] ", c); msg_trace("[%02x] ", c);
p++; p++;
len--; len--;
} }
avrdude_message(MSG_TRACE, "\n"); msg_trace("\n");
} }
return 0; return 0;
@ -566,7 +552,7 @@ static int ser_drain(const union filedescriptor *fd, int display) {
timeout.tv_usec = 250000; timeout.tv_usec = 250000;
if (display) { if (display) {
avrdude_message(MSG_INFO, "drain>"); msg_info("drain>");
} }
while (1) { while (1) {
@ -577,7 +563,7 @@ static int ser_drain(const union filedescriptor *fd, int display) {
nfds = select(fd->ifd + 1, &rfds, NULL, NULL, &timeout); nfds = select(fd->ifd + 1, &rfds, NULL, NULL, &timeout);
if (nfds == 0) { if (nfds == 0) {
if (display) { if (display) {
avrdude_message(MSG_INFO, "<drain\n"); msg_info("<drain\n");
} }
break; break;
@ -587,20 +573,18 @@ static int ser_drain(const union filedescriptor *fd, int display) {
goto reselect; goto reselect;
} }
else { else {
avrdude_message(MSG_INFO, "%s: ser_drain(): select(): %s\n", pmsg_ext_error("select(): %s\n", strerror(errno));
progname, strerror(errno));
return -1; return -1;
} }
} }
rc = read(fd->ifd, &buf, 1); rc = read(fd->ifd, &buf, 1);
if (rc < 0) { if (rc < 0) {
avrdude_message(MSG_INFO, "%s: ser_drain(): read error: %s\n", pmsg_ext_error("unable to read: %s\n", strerror(errno));
progname, strerror(errno));
return -1; return -1;
} }
if (display) { if (display) {
avrdude_message(MSG_INFO, "%02x ", buf); msg_info("%02x ", buf);
} }
} }

View File

@ -77,8 +77,7 @@ static DWORD serial_baud_lookup(long baud)
* If a non-standard BAUD rate is used, issue * If a non-standard BAUD rate is used, issue
* a warning (if we are verbose) and return the raw rate * a warning (if we are verbose) and return the raw rate
*/ */
avrdude_message(MSG_NOTICE, "%s: serial_baud_lookup(): Using non-standard baud rate: %ld", pmsg_notice("serial_baud_lookup(): using non-standard baud rate: %ld", baud);
progname, baud);
return baud; return baud;
} }
@ -160,17 +159,17 @@ static int net_open(const char *port, union filedescriptor *fdp) {
struct hostent *hp; struct hostent *hp;
if (WSAStartup(MAKEWORD(2, 0), &wsaData) != 0) { if (WSAStartup(MAKEWORD(2, 0), &wsaData) != 0) {
avrdude_message(MSG_INFO, "%s: net_open(): WSAStartup() failed\n", progname); pmsg_error("WSAStartup() failed\n");
return -1; return -1;
} }
if ((hstr = strdup(port)) == NULL) { if ((hstr = strdup(port)) == NULL) {
avrdude_message(MSG_INFO, "%s: net_open(): Out of memory!\n", progname); pmsg_error("out of memory\n");
return -1; return -1;
} }
if (((pstr = strchr(hstr, ':')) == NULL) || (pstr == hstr)) { if (((pstr = strchr(hstr, ':')) == NULL) || (pstr == hstr)) {
avrdude_message(MSG_INFO, "%s: net_open(): Mangled host:port string \"%s\"\n", progname, hstr); pmsg_error("mangled host:port string %s\n", hstr);
free(hstr); free(hstr);
return -1; return -1;
} }
@ -183,13 +182,13 @@ static int net_open(const char *port, union filedescriptor *fdp) {
pnum = strtoul(pstr, &end, 10); pnum = strtoul(pstr, &end, 10);
if ((*pstr == '\0') || (*end != '\0') || (pnum == 0) || (pnum > 65535)) { if ((*pstr == '\0') || (*end != '\0') || (pnum == 0) || (pnum > 65535)) {
avrdude_message(MSG_INFO, "%s: net_open(): Bad port number \"%s\"\n", progname, pstr); pmsg_error("bad port number %s\n", pstr);
free(hstr); free(hstr);
return -1; return -1;
} }
if ((hp = gethostbyname(hstr)) == NULL) { if ((hp = gethostbyname(hstr)) == NULL) {
avrdude_message(MSG_INFO, "%s: net_open(): unknown host \"%s\"\n", progname, hstr); pmsg_error("unknown host %s\n", hstr);
free(hstr); free(hstr);
return -1; return -1;
} }
@ -207,7 +206,7 @@ static int net_open(const char *port, union filedescriptor *fdp) {
(LPTSTR)&lpMsgBuf, (LPTSTR)&lpMsgBuf,
0, 0,
NULL); NULL);
avrdude_message(MSG_INFO, "%s: net_open(): Cannot open socket: %s\n", progname, (char *)lpMsgBuf); pmsg_error("cannot open socket: %s\n", (char *) lpMsgBuf);
LocalFree(lpMsgBuf); LocalFree(lpMsgBuf);
return -1; return -1;
} }
@ -228,7 +227,7 @@ static int net_open(const char *port, union filedescriptor *fdp) {
(LPTSTR)&lpMsgBuf, (LPTSTR)&lpMsgBuf,
0, 0,
NULL); NULL);
avrdude_message(MSG_INFO, "%s: net_open(): Connect failed: %s\n", progname, (char *)lpMsgBuf); pmsg_error("connect failed: %s\n", (char *) lpMsgBuf);
LocalFree(lpMsgBuf); LocalFree(lpMsgBuf);
return -1; return -1;
} }
@ -259,8 +258,7 @@ static int ser_open(const char *port, union pinfo pinfo, union filedescriptor *f
newname = malloc(strlen("\\\\.\\") + strlen(port) + 1); newname = malloc(strlen("\\\\.\\") + strlen(port) + 1);
if (newname == 0) { if (newname == 0) {
avrdude_message(MSG_INFO, "%s: ser_open(): out of memory\n", pmsg_error("out of memory\n");
progname);
exit(1); exit(1);
} }
strcpy(newname, "\\\\.\\"); strcpy(newname, "\\\\.\\");
@ -283,8 +281,7 @@ static int ser_open(const char *port, union pinfo pinfo, union filedescriptor *f
(LPTSTR) &lpMsgBuf, (LPTSTR) &lpMsgBuf,
0, 0,
NULL); NULL);
avrdude_message(MSG_INFO, "%s: ser_open(): can't open device \"%s\": %s\n", pmsg_error("cannot open port %s: %s\n", port, (char*) lpMsgBuf);
progname, port, (char*)lpMsgBuf);
LocalFree( lpMsgBuf ); LocalFree( lpMsgBuf );
return -1; return -1;
} }
@ -292,8 +289,7 @@ static int ser_open(const char *port, union pinfo pinfo, union filedescriptor *f
if (!SetupComm(hComPort, W32SERBUFSIZE, W32SERBUFSIZE)) if (!SetupComm(hComPort, W32SERBUFSIZE, W32SERBUFSIZE))
{ {
CloseHandle(hComPort); CloseHandle(hComPort);
avrdude_message(MSG_INFO, "%s: ser_open(): can't set buffers for \"%s\"\n", pmsg_error("cannot set buffers for %s\n", port);
progname, port);
return -1; return -1;
} }
@ -301,16 +297,14 @@ static int ser_open(const char *port, union pinfo pinfo, union filedescriptor *f
if (ser_setparams(fdp, pinfo.serialinfo.baud, pinfo.serialinfo.cflags) != 0) if (ser_setparams(fdp, pinfo.serialinfo.baud, pinfo.serialinfo.cflags) != 0)
{ {
CloseHandle(hComPort); CloseHandle(hComPort);
avrdude_message(MSG_INFO, "%s: ser_open(): can't set com-state for \"%s\"\n", pmsg_error("cannot set com-state for %s\n", port);
progname, port);
return -1; return -1;
} }
if (!serial_w32SetTimeOut(hComPort,0)) if (!serial_w32SetTimeOut(hComPort,0))
{ {
CloseHandle(hComPort); CloseHandle(hComPort);
avrdude_message(MSG_INFO, "%s: ser_open(): can't set initial timeout for \"%s\"\n", pmsg_error("cannot set initial timeout for %s\n", port);
progname, port);
return -1; return -1;
} }
@ -358,7 +352,7 @@ static int net_send(const union filedescriptor *fd, const unsigned char * buf, s
size_t len = buflen; size_t len = buflen;
if (fd->ifd < 0) { if (fd->ifd < 0) {
avrdude_message(MSG_NOTICE, "%s: net_send(): connection not open\n", progname); pmsg_notice("net_send(): connection not open\n");
exit(1); exit(1);
} }
@ -367,22 +361,22 @@ static int net_send(const union filedescriptor *fd, const unsigned char * buf, s
} }
if (verbose > 3) { if (verbose > 3) {
avrdude_message(MSG_TRACE, "%s: Send: ", progname); pmsg_trace("send: ");
while (buflen) { while (buflen) {
unsigned char c = *buf; unsigned char c = *buf;
if (isprint(c)) { if (isprint(c)) {
avrdude_message(MSG_TRACE, "%c ", c); msg_trace("%c ", c);
} else { } else {
avrdude_message(MSG_TRACE, ". "); msg_trace(". ");
} }
avrdude_message(MSG_TRACE, "[%02x] ", c); msg_trace("[%02x] ", c);
buf++; buf++;
buflen--; buflen--;
} }
avrdude_message(MSG_TRACE, "\n"); msg_trace("\n");
} }
while (len) { while (len) {
@ -398,7 +392,7 @@ static int net_send(const union filedescriptor *fd, const unsigned char * buf, s
(LPTSTR)&lpMsgBuf, (LPTSTR)&lpMsgBuf,
0, 0,
NULL); NULL);
avrdude_message(MSG_INFO, "%s: net_send(): send error: %s\n", progname, (char *)lpMsgBuf); pmsg_error("unable to send: %s\n", (char *) lpMsgBuf);
LocalFree(lpMsgBuf); LocalFree(lpMsgBuf);
exit(1); exit(1);
} }
@ -423,8 +417,7 @@ static int ser_send(const union filedescriptor *fd, const unsigned char * buf, s
HANDLE hComPort=(HANDLE)fd->pfd; HANDLE hComPort=(HANDLE)fd->pfd;
if (hComPort == INVALID_HANDLE_VALUE) { if (hComPort == INVALID_HANDLE_VALUE) {
avrdude_message(MSG_INFO, "%s: ser_send(): port not open\n", pmsg_error("port not open\n");
progname);
return -1; return -1;
} }
@ -433,34 +426,32 @@ static int ser_send(const union filedescriptor *fd, const unsigned char * buf, s
if (verbose > 3) if (verbose > 3)
{ {
avrdude_message(MSG_TRACE, "%s: Send: ", progname); pmsg_trace("send: ");
while (len) { while (len) {
c = *b; c = *b;
if (isprint(c)) { if (isprint(c)) {
avrdude_message(MSG_TRACE, "%c ", c); msg_trace("%c ", c);
} }
else { else {
avrdude_message(MSG_TRACE, ". "); msg_trace(". ");
} }
avrdude_message(MSG_TRACE, "[%02x] ", c); msg_trace("[%02x] ", c);
b++; b++;
len--; len--;
} }
avrdude_message(MSG_INFO, "\n"); msg_trace("\n");
} }
serial_w32SetTimeOut(hComPort,500); serial_w32SetTimeOut(hComPort,500);
if (!WriteFile (hComPort, buf, buflen, &written, NULL)) { if (!WriteFile (hComPort, buf, buflen, &written, NULL)) {
avrdude_message(MSG_INFO, "%s: ser_send(): write error: %s\n", pmsg_error("unable to write: %s\n", "sorry no info avail"); // TODO
progname, "sorry no info avail"); // TODO
return -1; return -1;
} }
if (written != buflen) { if (written != buflen) {
avrdude_message(MSG_INFO, "%s: ser_send(): size/send mismatch\n", pmsg_error("size/send mismatch\n");
progname);
return -1; return -1;
} }
@ -478,7 +469,7 @@ static int net_recv(const union filedescriptor *fd, unsigned char * buf, size_t
size_t len = 0; size_t len = 0;
if (fd->ifd < 0) { if (fd->ifd < 0) {
avrdude_message(MSG_INFO, "%s: net_recv(): connection not open\n", progname); pmsg_error("connection not open\n");
exit(1); exit(1);
} }
@ -494,12 +485,12 @@ reselect:
nfds = select(fd->ifd + 1, &rfds, NULL, NULL, &to2); nfds = select(fd->ifd + 1, &rfds, NULL, NULL, &to2);
if (nfds == 0) { if (nfds == 0) {
if (verbose > 1) { if (verbose > 1) {
avrdude_message(MSG_NOTICE, "%s: ser_recv(): programmer is not responding\n", progname); pmsg_notice("ser_recv(): programmer is not responding\n");
} }
return -1; return -1;
} else if (nfds == -1) { } else if (nfds == -1) {
if (WSAGetLastError() == WSAEINTR || WSAGetLastError() == WSAEINPROGRESS) { if (WSAGetLastError() == WSAEINTR || WSAGetLastError() == WSAEINPROGRESS) {
avrdude_message(MSG_NOTICE, "%s: ser_recv(): programmer is not responding, reselecting\n", progname); pmsg_notice("ser_recv(): programmer is not responding, reselecting\n");
goto reselect; goto reselect;
} else { } else {
FormatMessage( FormatMessage(
@ -512,7 +503,7 @@ reselect:
(LPTSTR)&lpMsgBuf, (LPTSTR)&lpMsgBuf,
0, 0,
NULL); NULL);
avrdude_message(MSG_INFO, "%s: ser_recv(): select(): %s\n", progname, (char *)lpMsgBuf); pmsg_error("select(): %s\n", (char *) lpMsgBuf);
LocalFree(lpMsgBuf); LocalFree(lpMsgBuf);
exit(1); exit(1);
} }
@ -530,7 +521,7 @@ reselect:
(LPTSTR)&lpMsgBuf, (LPTSTR)&lpMsgBuf,
0, 0,
NULL); NULL);
avrdude_message(MSG_INFO, "%s: ser_recv(): read error: %s\n", progname, (char *)lpMsgBuf); pmsg_error("unable to read: %s\n", (char *) lpMsgBuf);
LocalFree(lpMsgBuf); LocalFree(lpMsgBuf);
exit(1); exit(1);
} }
@ -541,21 +532,21 @@ reselect:
p = buf; p = buf;
if (verbose > 3) { if (verbose > 3) {
avrdude_message(MSG_TRACE, "%s: Recv: ", progname); pmsg_trace("Recv: ");
while (len) { while (len) {
unsigned char c = *p; unsigned char c = *p;
if (isprint(c)) { if (isprint(c)) {
avrdude_message(MSG_TRACE, "%c ", c); msg_trace("%c ", c);
} else { } else {
avrdude_message(MSG_TRACE, ". "); msg_trace(". ");
} }
avrdude_message(MSG_TRACE, "[%02x] ", c); msg_trace("[%02x] ", c);
p++; p++;
len--; len--;
} }
avrdude_message(MSG_TRACE, "\n"); msg_trace("\n");
} }
return 0; return 0;
@ -573,8 +564,7 @@ static int ser_recv(const union filedescriptor *fd, unsigned char * buf, size_t
HANDLE hComPort=(HANDLE)fd->pfd; HANDLE hComPort=(HANDLE)fd->pfd;
if (hComPort == INVALID_HANDLE_VALUE) { if (hComPort == INVALID_HANDLE_VALUE) {
avrdude_message(MSG_INFO, "%s: ser_read(): port not open\n", pmsg_error("port not open\n");
progname);
return -1; return -1;
} }
@ -592,16 +582,14 @@ static int ser_recv(const union filedescriptor *fd, unsigned char * buf, size_t
(LPTSTR) &lpMsgBuf, (LPTSTR) &lpMsgBuf,
0, 0,
NULL ); NULL );
avrdude_message(MSG_INFO, "%s: ser_recv(): read error: %s\n", pmsg_error("unable to read: %s\n", (char*) lpMsgBuf);
progname, (char*)lpMsgBuf);
LocalFree( lpMsgBuf ); LocalFree( lpMsgBuf );
return -1; return -1;
} }
/* time out detected */ /* time out detected */
if (read == 0) { if (read == 0) {
avrdude_message(MSG_NOTICE2, "%s: ser_recv(): programmer is not responding\n", pmsg_notice2("ser_recv(): programmer is not responding\n");
progname);
return -1; return -1;
} }
@ -609,22 +597,22 @@ static int ser_recv(const union filedescriptor *fd, unsigned char * buf, size_t
if (verbose > 3) if (verbose > 3)
{ {
avrdude_message(MSG_TRACE, "%s: Recv: ", progname); pmsg_trace("recv: ");
while (read) { while (read) {
c = *p; c = *p;
if (isprint(c)) { if (isprint(c)) {
avrdude_message(MSG_TRACE, "%c ", c); msg_trace("%c ", c);
} }
else { else {
avrdude_message(MSG_TRACE, ". "); msg_trace(". ");
} }
avrdude_message(MSG_TRACE, "[%02x] ", c); msg_trace("[%02x] ", c);
p++; p++;
read--; read--;
} }
avrdude_message(MSG_INFO, "\n"); msg_trace("\n");
} }
return 0; return 0;
} }
@ -638,12 +626,12 @@ static int net_drain(const union filedescriptor *fd, int display) {
int rc; int rc;
if (fd->ifd < 0) { if (fd->ifd < 0) {
avrdude_message(MSG_INFO, "%s: ser_drain(): connection not open\n", progname); pmsg_error("connection not open\n");
exit(1); exit(1);
} }
if (display) { if (display) {
avrdude_message(MSG_INFO, "drain>"); msg_info("drain>");
} }
timeout.tv_sec = 0; timeout.tv_sec = 0;
@ -657,13 +645,13 @@ static int net_drain(const union filedescriptor *fd, int display) {
nfds = select(fd->ifd + 1, &rfds, NULL, NULL, &timeout); nfds = select(fd->ifd + 1, &rfds, NULL, NULL, &timeout);
if (nfds == 0) { if (nfds == 0) {
if (display) { if (display) {
avrdude_message(MSG_INFO, "<drain\n"); msg_info("<drain\n");
} }
break; break;
} }
else if (nfds == -1) { else if (nfds == -1) {
if (WSAGetLastError() == WSAEINTR || WSAGetLastError() == WSAEINPROGRESS) { if (WSAGetLastError() == WSAEINTR || WSAGetLastError() == WSAEINPROGRESS) {
avrdude_message(MSG_NOTICE, "%s: ser_drain(): programmer is not responding, reselecting\n", progname); pmsg_notice("ser_drain(): programmer is not responding, reselecting\n");
goto reselect; goto reselect;
} else { } else {
FormatMessage( FormatMessage(
@ -676,7 +664,7 @@ static int net_drain(const union filedescriptor *fd, int display) {
(LPTSTR)&lpMsgBuf, (LPTSTR)&lpMsgBuf,
0, 0,
NULL); NULL);
avrdude_message(MSG_INFO, "%s: ser_drain(): select(): %s\n", progname, (char *)lpMsgBuf); pmsg_error("select(): %s\n", (char *) lpMsgBuf);
LocalFree(lpMsgBuf); LocalFree(lpMsgBuf);
exit(1); exit(1);
} }
@ -694,13 +682,13 @@ static int net_drain(const union filedescriptor *fd, int display) {
(LPTSTR)&lpMsgBuf, (LPTSTR)&lpMsgBuf,
0, 0,
NULL); NULL);
avrdude_message(MSG_INFO, "%s: ser_drain(): read error: %s\n", progname, (char *)lpMsgBuf); pmsg_error("unable to read: %s\n", (char *) lpMsgBuf);
LocalFree(lpMsgBuf); LocalFree(lpMsgBuf);
exit(1); exit(1);
} }
if (display) { if (display) {
avrdude_message(MSG_INFO, "%02x ", buf); msg_info("%02x ", buf);
} }
} }
@ -720,15 +708,14 @@ static int ser_drain(const union filedescriptor *fd, int display) {
HANDLE hComPort=(HANDLE)fd->pfd; HANDLE hComPort=(HANDLE)fd->pfd;
if (hComPort == INVALID_HANDLE_VALUE) { if (hComPort == INVALID_HANDLE_VALUE) {
avrdude_message(MSG_INFO, "%s: ser_drain(): port not open\n", pmsg_error("port not open\n");
progname);
return -1; return -1;
} }
serial_w32SetTimeOut(hComPort,250); serial_w32SetTimeOut(hComPort,250);
if (display) { if (display) {
avrdude_message(MSG_INFO, "drain>"); msg_info("drain>");
} }
while (1) { while (1) {
@ -745,17 +732,18 @@ static int ser_drain(const union filedescriptor *fd, int display) {
(LPTSTR) &lpMsgBuf, (LPTSTR) &lpMsgBuf,
0, 0,
NULL ); NULL );
avrdude_message(MSG_INFO, "%s: ser_drain(): read error: %s\n", pmsg_error("unable to read: %s\n", (char*) lpMsgBuf);
progname, (char*)lpMsgBuf);
LocalFree( lpMsgBuf ); LocalFree( lpMsgBuf );
return -1; return -1;
} }
if (read) { // data avail if (read) { // data avail
if (display) avrdude_message(MSG_INFO, "%02x ", buf[0]); if (display)
msg_info("%02x ", buf[0]);
} }
else { // no more data else { // no more data
if (display) avrdude_message(MSG_INFO, "<drain\n"); if (display)
msg_info("<drain\n");
break; break;
} }
} // while } // while

View File

@ -85,39 +85,39 @@ static int serbb_setpin(const PROGRAMMER *pgm, int pinfunc, int value) {
return -1; return -1;
#ifdef DEBUG #ifdef DEBUG
printf("%s to %d\n",serpins[pin],value); msg_info("%s to %d\n", serpins[pin], value);
#endif #endif
switch ( pin ) switch ( pin )
{ {
case 3: /* txd */ case 3: /* txd */
r = ioctl(pgm->fd.ifd, value ? TIOCSBRK : TIOCCBRK, 0); r = ioctl(pgm->fd.ifd, value ? TIOCSBRK : TIOCCBRK, 0);
if (r < 0) { if (r < 0) {
perror("ioctl(\"TIOCxBRK\")"); pmsg_ext_error("ioctl(\"TIOCxBRK\"): %s\n", strerror(errno));
return -1; return -1;
} }
break; break;
case 4: /* dtr */ case 4: /* dtr */
case 7: /* rts */ case 7: /* rts */
r = ioctl(pgm->fd.ifd, TIOCMGET, &ctl); r = ioctl(pgm->fd.ifd, TIOCMGET, &ctl);
if (r < 0) { if (r < 0) {
perror("ioctl(\"TIOCMGET\")"); pmsg_ext_error("ioctl(\"TIOCMGET\"): %s\n", strerror(errno));
return -1; return -1;
} }
if ( value ) if (value)
ctl |= serregbits[pin]; ctl |= serregbits[pin];
else else
ctl &= ~(serregbits[pin]); ctl &= ~(serregbits[pin]);
r = ioctl(pgm->fd.ifd, TIOCMSET, &ctl); r = ioctl(pgm->fd.ifd, TIOCMSET, &ctl);
if (r < 0) { if (r < 0) {
perror("ioctl(\"TIOCMSET\")"); pmsg_ext_error("ioctl(\"TIOCMSET\"): %s\n", strerror(errno));
return -1; return -1;
} }
break; break;
default: /* impossible */ default: /* impossible */
return -1; return -1;
} }
if (pgm->ispdelay > 1) if (pgm->ispdelay > 1)
@ -145,34 +145,34 @@ static int serbb_getpin(const PROGRAMMER *pgm, int pinfunc) {
switch ( pin ) switch ( pin )
{ {
case 2: /* rxd, currently not implemented, FIXME */ case 2: /* rxd, currently not implemented, FIXME */
return(-1); return(-1);
case 1: /* cd */ case 1: /* cd */
case 6: /* dsr */ case 6: /* dsr */
case 8: /* cts */ case 8: /* cts */
case 9: /* ri */ case 9: /* ri */
r = ioctl(pgm->fd.ifd, TIOCMGET, &ctl); r = ioctl(pgm->fd.ifd, TIOCMGET, &ctl);
if (r < 0) { if (r < 0) {
perror("ioctl(\"TIOCMGET\")"); pmsg_ext_error("ioctl(\"TIOCMGET\"): %s\n", strerror(errno));
return -1; return -1;
} }
if ( !invert ) if ( !invert )
{ {
#ifdef DEBUG #ifdef DEBUG
printf("%s is %d\n",serpins[pin],(ctl & serregbits[pin]) ? 1 : 0 ); msg_info("%s is %d\n", serpins[pin], ctl & serregbits[pin]? 1: 0);
#endif #endif
return ( (ctl & serregbits[pin]) ? 1 : 0 ); return ctl & serregbits[pin]? 1: 0;
} }
else else
{ {
#ifdef DEBUG #ifdef DEBUG
printf("%s is %d (~)\n",serpins[pin],(ctl & serregbits[pin]) ? 0 : 1 ); msg_info("%s is %d (~)\n", serpins[pin], ctl & serregbits[pin]? 0: 1);
#endif #endif
return (( ctl & serregbits[pin]) ? 0 : 1 ); return ctl & serregbits[pin]? 0: 1;
} }
default: /* impossible */ default: /* impossible */
return(-1); return(-1);
} }
} }
@ -223,14 +223,13 @@ static int serbb_open(PROGRAMMER *pgm, const char *port) {
pgm->fd.ifd = open(port, O_RDWR | O_NOCTTY | O_NONBLOCK); pgm->fd.ifd = open(port, O_RDWR | O_NOCTTY | O_NONBLOCK);
if (pgm->fd.ifd < 0) { if (pgm->fd.ifd < 0) {
perror(port); pmsg_ext_error("%s: %s\n", port, strerror(errno));
return(-1); return(-1);
} }
r = tcgetattr(pgm->fd.ifd, &mode); r = tcgetattr(pgm->fd.ifd, &mode);
if (r < 0) { if (r < 0) {
avrdude_message(MSG_INFO, "%s: ", port); pmsg_ext_error("%s, tcgetattr(): %s\n", port, strerror(errno));
perror("tcgetattr");
return(-1); return(-1);
} }
oldmode = mode; oldmode = mode;
@ -243,8 +242,7 @@ static int serbb_open(PROGRAMMER *pgm, const char *port) {
r = tcsetattr(pgm->fd.ifd, TCSANOW, &mode); r = tcsetattr(pgm->fd.ifd, TCSANOW, &mode);
if (r < 0) { if (r < 0) {
avrdude_message(MSG_INFO, "%s: ", port); pmsg_ext_error("%s, tcsetattr(): %s", port, strerror(errno));
perror("tcsetattr");
return(-1); return(-1);
} }
@ -252,15 +250,13 @@ static int serbb_open(PROGRAMMER *pgm, const char *port) {
flags = fcntl(pgm->fd.ifd, F_GETFL, 0); flags = fcntl(pgm->fd.ifd, F_GETFL, 0);
if (flags == -1) if (flags == -1)
{ {
avrdude_message(MSG_INFO, "%s: Can not get flags: %s\n", pmsg_ext_error("cannot get flags: %s\n", strerror(errno));
progname, strerror(errno));
return(-1); return(-1);
} }
flags &= ~O_NONBLOCK; flags &= ~O_NONBLOCK;
if (fcntl(pgm->fd.ifd, F_SETFL, flags) == -1) if (fcntl(pgm->fd.ifd, F_SETFL, flags) == -1)
{ {
avrdude_message(MSG_INFO, "%s: Can not clear nonblock flag: %s\n", pmsg_ext_error("cannot clear nonblock flag: %s\n", strerror(errno));
progname, strerror(errno));
return(-1); return(-1);
} }

View File

@ -97,12 +97,10 @@ static int serbb_setpin(const PROGRAMMER *pgm, int pinfunc, int value) {
break; break;
default: default:
avrdude_message(MSG_NOTICE, "%s: serbb_setpin(): unknown pin %d\n", pmsg_notice("serbb_setpin(): unknown pin %d\n", pin + 1);
progname, pin + 1);
return -1; return -1;
} }
avrdude_message(MSG_TRACE2, "%s: serbb_setpin(): EscapeCommFunction(%s)\n", pmsg_trace2("serbb_setpin(): EscapeCommFunction(%s)\n", name);
progname, name);
if (!EscapeCommFunction(hComPort, dwFunc)) if (!EscapeCommFunction(hComPort, dwFunc))
{ {
FormatMessage( FormatMessage(
@ -115,8 +113,7 @@ static int serbb_setpin(const PROGRAMMER *pgm, int pinfunc, int value) {
(LPTSTR) &lpMsgBuf, (LPTSTR) &lpMsgBuf,
0, 0,
NULL); NULL);
avrdude_message(MSG_INFO, "%s: serbb_setpin(): SetCommState() failed: %s\n", pmsg_error("SetCommState() failed: %s\n", (char *) lpMsgBuf);
progname, (char *)lpMsgBuf);
CloseHandle(hComPort); CloseHandle(hComPort);
LocalFree(lpMsgBuf); LocalFree(lpMsgBuf);
return -1; return -1;
@ -160,14 +157,12 @@ static int serbb_getpin(const PROGRAMMER *pgm, int pinfunc) {
(LPTSTR) &lpMsgBuf, (LPTSTR) &lpMsgBuf,
0, 0,
NULL); NULL);
avrdude_message(MSG_INFO, "%s: serbb_setpin(): GetCommModemStatus() failed: %s\n", pmsg_error("GetCommModemStatus() failed: %s\n", (char *) lpMsgBuf);
progname, (char *)lpMsgBuf);
CloseHandle(hComPort); CloseHandle(hComPort);
LocalFree(lpMsgBuf); LocalFree(lpMsgBuf);
return -1; return -1;
} }
avrdude_message(MSG_TRACE2, "%s: serbb_getpin(): GetCommState() => 0x%lx\n", pmsg_trace2("serbb_getpin(): GetCommState() => 0x%lx\n", modemstate);
progname, modemstate);
switch (pin) switch (pin)
{ {
case 1: case 1:
@ -202,12 +197,10 @@ static int serbb_getpin(const PROGRAMMER *pgm, int pinfunc) {
name = "RTS"; name = "RTS";
break; break;
default: default:
avrdude_message(MSG_NOTICE, "%s: serbb_getpin(): unknown pin %d\n", pmsg_notice("serbb_getpin(): unknown pin %d\n", pin + 1);
progname, pin + 1);
return -1; return -1;
} }
avrdude_message(MSG_TRACE2, "%s: serbb_getpin(): return cached state for %s\n", pmsg_trace2("serbb_getpin(): return cached state for %s\n", name);
progname, name);
if (invert) if (invert)
rv = !rv; rv = !rv;
@ -268,8 +261,7 @@ static int serbb_open(PROGRAMMER *pgm, const char *port) {
(LPTSTR) &lpMsgBuf, (LPTSTR) &lpMsgBuf,
0, 0,
NULL); NULL);
avrdude_message(MSG_INFO, "%s: ser_open(): can't open device \"%s\": %s\n", pmsg_error("cannot open port %s: %s\n", port, (char*) lpMsgBuf);
progname, port, (char*)lpMsgBuf);
LocalFree(lpMsgBuf); LocalFree(lpMsgBuf);
return -1; return -1;
} }
@ -277,8 +269,7 @@ static int serbb_open(PROGRAMMER *pgm, const char *port) {
if (!SetupComm(hComPort, W32SERBUFSIZE, W32SERBUFSIZE)) if (!SetupComm(hComPort, W32SERBUFSIZE, W32SERBUFSIZE))
{ {
CloseHandle(hComPort); CloseHandle(hComPort);
avrdude_message(MSG_INFO, "%s: ser_open(): can't set buffers for \"%s\"\n", pmsg_error("cannot set buffers for %s\n", port);
progname, port);
return -1; return -1;
} }
@ -296,12 +287,10 @@ static int serbb_open(PROGRAMMER *pgm, const char *port) {
if (!SetCommState(hComPort, &dcb)) if (!SetCommState(hComPort, &dcb))
{ {
CloseHandle(hComPort); CloseHandle(hComPort);
avrdude_message(MSG_INFO, "%s: ser_open(): can't set com-state for \"%s\"\n", pmsg_error("cannot set com-state for %s\n", port);
progname, port);
return -1; return -1;
} }
avrdude_message(MSG_DEBUG, "%s: ser_open(): opened comm port \"%s\", handle 0x%zx\n", pmsg_debug("ser_open(): opened comm port %s, handle 0x%zx\n", port, (INT_PTR) hComPort);
progname, port, (INT_PTR)hComPort);
pgm->fd.pfd = (void *)hComPort; pgm->fd.pfd = (void *)hComPort;
@ -317,8 +306,7 @@ static void serbb_close(PROGRAMMER *pgm) {
pgm->setpin(pgm, PIN_AVR_RESET, 1); pgm->setpin(pgm, PIN_AVR_RESET, 1);
CloseHandle (hComPort); CloseHandle (hComPort);
} }
avrdude_message(MSG_DEBUG, "%s: ser_close(): closed comm port handle 0x%zx\n", pmsg_debug("ser_close(): closed comm port handle 0x%zx\n", (INT_PTR) hComPort);
progname, (INT_PTR)hComPort);
hComPort = INVALID_HANDLE_VALUE; hComPort = INVALID_HANDLE_VALUE;
} }

View File

@ -49,9 +49,7 @@ static int serialupdi_leave_progmode(const PROGRAMMER *pgm);
static void serialupdi_setup(PROGRAMMER * pgm) static void serialupdi_setup(PROGRAMMER * pgm)
{ {
if ((pgm->cookie = malloc(sizeof(updi_state))) == 0) { if ((pgm->cookie = malloc(sizeof(updi_state))) == 0) {
avrdude_message(MSG_INFO, pmsg_error("out of memory allocating private data\n");
"%s: serialupdi_setup(): Out of memory allocating private data\n",
progname);
exit(1); exit(1);
} }
memset(pgm->cookie, 0, sizeof(updi_state)); memset(pgm->cookie, 0, sizeof(updi_state));
@ -91,10 +89,10 @@ static int serialupdi_reset(const PROGRAMMER *pgm, reset_mode mode) {
*/ */
switch (mode) { switch (mode) {
case APPLY_RESET: case APPLY_RESET:
avrdude_message(MSG_DEBUG, "%s: Sending reset request\n", progname); pmsg_debug("sending reset request\n");
return updi_write_cs(pgm, UPDI_ASI_RESET_REQ, UPDI_RESET_REQ_VALUE); return updi_write_cs(pgm, UPDI_ASI_RESET_REQ, UPDI_RESET_REQ_VALUE);
case RELEASE_RESET: case RELEASE_RESET:
avrdude_message(MSG_DEBUG, "%s: Sending release reset request\n", progname); pmsg_debug("sending release reset request\n");
return updi_write_cs(pgm, UPDI_ASI_RESET_REQ, 0x00); return updi_write_cs(pgm, UPDI_ASI_RESET_REQ, 0x00);
} }
return -1; return -1;
@ -102,12 +100,12 @@ static int serialupdi_reset(const PROGRAMMER *pgm, reset_mode mode) {
static int serialupdi_reset_connection(const PROGRAMMER *pgm) { static int serialupdi_reset_connection(const PROGRAMMER *pgm) {
if (serialupdi_reset(pgm, APPLY_RESET) < 0) { if (serialupdi_reset(pgm, APPLY_RESET) < 0) {
avrdude_message(MSG_INFO, "%s: Apply reset operation failed\n", progname); pmsg_error("apply reset operation failed\n");
return -1; return -1;
} }
if (serialupdi_reset(pgm, RELEASE_RESET) < 0) { if (serialupdi_reset(pgm, RELEASE_RESET) < 0) {
avrdude_message(MSG_INFO, "%s: Release reset operation failed\n", progname); pmsg_error("release reset operation failed\n");
return -1; return -1;
} }
@ -118,7 +116,7 @@ static int serialupdi_decode_sib(const PROGRAMMER *pgm, updi_sib_info *sib_info)
char * str_ptr; char * str_ptr;
sib_info->sib_string[SIB_INFO_STRING_LENGTH]=0; sib_info->sib_string[SIB_INFO_STRING_LENGTH]=0;
avrdude_message(MSG_DEBUG, "%s: Received SIB: [%s]\n", progname, sib_info->sib_string); pmsg_debug("received SIB: [%s]\n", sib_info->sib_string);
memset(sib_info->family_string, 0, SIB_INFO_FAMILY_LENGTH+1); memset(sib_info->family_string, 0, SIB_INFO_FAMILY_LENGTH+1);
memset(sib_info->nvm_string, 0, SIB_INFO_NVM_LENGTH+1); memset(sib_info->nvm_string, 0, SIB_INFO_NVM_LENGTH+1);
memset(sib_info->debug_string, 0, SIB_INFO_DEBUG_LENGTH+1); memset(sib_info->debug_string, 0, SIB_INFO_DEBUG_LENGTH+1);
@ -134,41 +132,41 @@ static int serialupdi_decode_sib(const PROGRAMMER *pgm, updi_sib_info *sib_info)
str_ptr = strstr(sib_info->nvm_string, ":"); str_ptr = strstr(sib_info->nvm_string, ":");
if (!str_ptr) { if (!str_ptr) {
avrdude_message(MSG_INFO, "%s: Incorrect format of NVM string\n", progname); pmsg_error("incorrect format of NVM string\n");
return -1; return -1;
} }
sib_info->nvm_version = *(str_ptr+1); sib_info->nvm_version = *(str_ptr+1);
str_ptr = strstr(sib_info->debug_string, ":"); str_ptr = strstr(sib_info->debug_string, ":");
if (!str_ptr) { if (!str_ptr) {
avrdude_message(MSG_INFO, "%s: Incorrect format of DEBUG string\n", progname); pmsg_error("incorrect format of DEBUG string\n");
return -1; return -1;
} }
sib_info->debug_version = *(str_ptr+1); sib_info->debug_version = *(str_ptr+1);
avrdude_message(MSG_DEBUG, "%s: Device family ID: %s\n", progname, sib_info->family_string); pmsg_debug("Device family ID: %s\n", sib_info->family_string);
avrdude_message(MSG_DEBUG, "%s: NVM interface: %s\n", progname, sib_info->nvm_string); pmsg_debug("NVM interface: %s\n", sib_info->nvm_string);
avrdude_message(MSG_DEBUG, "%s: Debug interface: %s\n", progname, sib_info->debug_string); pmsg_debug("Debug interface: %s\n", sib_info->debug_string);
avrdude_message(MSG_DEBUG, "%s: PDI oscillator: %s\n", progname, sib_info->pdi_string); pmsg_debug("PDI oscillator: %s\n", sib_info->pdi_string);
avrdude_message(MSG_DEBUG, "%s: Extra information: %s\n", progname, sib_info->extra_string); pmsg_debug("Extra information: %s\n", sib_info->extra_string);
switch (sib_info->nvm_version) { switch (sib_info->nvm_version) {
case '0': case '0':
avrdude_message(MSG_INFO, "%s: NVM type 0: 16-bit, page oriented write\n", progname); pmsg_notice("NVM type 0: 16-bit, page oriented write\n");
updi_set_nvm_mode(pgm, UPDI_NVM_MODE_V0); updi_set_nvm_mode(pgm, UPDI_NVM_MODE_V0);
updi_set_datalink_mode(pgm, UPDI_LINK_MODE_16BIT); updi_set_datalink_mode(pgm, UPDI_LINK_MODE_16BIT);
break; break;
case '2': case '2':
avrdude_message(MSG_INFO, "%s: NVM type 2: 24-bit, word oriented write\n", progname); pmsg_notice("NVM type 2: 24-bit, word oriented write\n");
updi_set_nvm_mode(pgm, UPDI_NVM_MODE_V2); updi_set_nvm_mode(pgm, UPDI_NVM_MODE_V2);
updi_set_datalink_mode(pgm, UPDI_LINK_MODE_24BIT); updi_set_datalink_mode(pgm, UPDI_LINK_MODE_24BIT);
break; break;
case '3': case '3':
avrdude_message(MSG_INFO, "%s: NVM type 3: 16-bit, page oriented\n", progname); pmsg_notice("NVM type 3: 16-bit, page oriented\n");
updi_set_nvm_mode(pgm, UPDI_NVM_MODE_V3); updi_set_nvm_mode(pgm, UPDI_NVM_MODE_V3);
updi_set_datalink_mode(pgm, UPDI_LINK_MODE_16BIT); updi_set_datalink_mode(pgm, UPDI_LINK_MODE_16BIT);
break; break;
default: default:
avrdude_message(MSG_INFO, "%s: Unsupported NVM type: %c, please update software\n", progname, sib_info->nvm_version); pmsg_warning("unsupported NVM type: %c, please update software\n", sib_info->nvm_version);
return -1; return -1;
} }
return 0; return 0;
@ -176,13 +174,13 @@ static int serialupdi_decode_sib(const PROGRAMMER *pgm, updi_sib_info *sib_info)
static void serialupdi_close(PROGRAMMER * pgm) static void serialupdi_close(PROGRAMMER * pgm)
{ {
avrdude_message(MSG_INFO, "%s: Leaving NVM programming mode\n", progname); pmsg_notice("leaving NVM programming mode\n");
if (serialupdi_leave_progmode(pgm) < 0) { if (serialupdi_leave_progmode(pgm) < 0) {
avrdude_message(MSG_INFO, "%s: Unable to leave NVM programming mode\n", progname); pmsg_error("unable to leave NVM programming mode\n");
} }
if (updi_get_rts_mode(pgm) != RTS_MODE_DEFAULT) { if (updi_get_rts_mode(pgm) != RTS_MODE_DEFAULT) {
avrdude_message(MSG_INFO, "%s: Releasing DTR/RTS handshake lines\n", progname); pmsg_warning("releasing DTR/RTS handshake lines\n");
} }
updi_link_close(pgm); updi_link_close(pgm);
@ -223,7 +221,7 @@ static int serialupdi_wait_for_unlock(const PROGRAMMER *pgm, unsigned int ms) {
current_time = (tv.tv_sec * 1000000) + tv.tv_usec; current_time = (tv.tv_sec * 1000000) + tv.tv_usec;
} while ((current_time - start_time) < (ms * 1000)); } while ((current_time - start_time) < (ms * 1000));
avrdude_message(MSG_INFO, "%s: Timeout waiting for device to unlock\n", progname); pmsg_error("timeout waiting for device to unlock\n");
return -1; return -1;
} }
@ -278,7 +276,7 @@ static int serialupdi_wait_for_urow(const PROGRAMMER *pgm, unsigned int ms, urow
current_time = (tv.tv_sec * 1000000) + tv.tv_usec; current_time = (tv.tv_sec * 1000000) + tv.tv_usec;
} while ((current_time - start_time) < (ms * 1000)); } while ((current_time - start_time) < (ms * 1000));
avrdude_message(MSG_INFO, "%s: Timeout waiting for device to complete UROW WRITE\n", progname); pmsg_error("timeout waiting for device to complete UROW WRITE\n");
return -1; return -1;
} }
@ -298,7 +296,7 @@ static int serialupdi_in_prog_mode(const PROGRAMMER *pgm, uint8_t *in_prog_mode)
rc = updi_read_cs(pgm, UPDI_ASI_SYS_STATUS, &value); rc = updi_read_cs(pgm, UPDI_ASI_SYS_STATUS, &value);
if (rc < 0) { if (rc < 0) {
avrdude_message(MSG_INFO, "%s: Read CS operation failed\n", progname); pmsg_error("read CS operation failed\n");
return rc; return rc;
} }
@ -354,57 +352,57 @@ def enter_progmode(self):
uint8_t key_status; uint8_t key_status;
if (serialupdi_in_prog_mode(pgm, &in_prog_mode) < 0) { if (serialupdi_in_prog_mode(pgm, &in_prog_mode) < 0) {
avrdude_message(MSG_INFO, "%s: Checking UPDI NVM prog mode failed\n", progname); pmsg_error("checking UPDI NVM prog mode failed\n");
return -1; return -1;
} }
if (in_prog_mode) { if (in_prog_mode) {
avrdude_message(MSG_DEBUG, "%s: Already in prog mode\n", progname); pmsg_debug("already in prog mode\n");
return 0; return 0;
} }
memcpy(buffer, UPDI_KEY_NVM, sizeof(buffer)); memcpy(buffer, UPDI_KEY_NVM, sizeof(buffer));
if (updi_write_key(pgm, buffer, UPDI_KEY_64, sizeof(buffer)) < 0) { if (updi_write_key(pgm, buffer, UPDI_KEY_64, sizeof(buffer)) < 0) {
avrdude_message(MSG_INFO, "%s: Writing NVM KEY failed\n", progname); pmsg_error("writing NVM KEY failed\n");
return -1; return -1;
} }
if (updi_read_cs(pgm, UPDI_ASI_KEY_STATUS, &key_status) < 0) { if (updi_read_cs(pgm, UPDI_ASI_KEY_STATUS, &key_status) < 0) {
avrdude_message(MSG_INFO, "%s: Checking KEY status failed\n", progname); pmsg_error("checking KEY status failed\n");
return -1; return -1;
} }
avrdude_message(MSG_DEBUG, "%s: Key status: 0x%02X\n", progname, key_status); pmsg_debug("key status: 0x%02X\n", key_status);
if (!(key_status & (1 << UPDI_ASI_KEY_STATUS_NVMPROG))) { if (!(key_status & (1 << UPDI_ASI_KEY_STATUS_NVMPROG))) {
avrdude_message(MSG_INFO, "%s: Key was not accepted\n", progname); pmsg_error("key was not accepted\n");
return -1; return -1;
} }
if (serialupdi_reset(pgm, APPLY_RESET) < 0) { if (serialupdi_reset(pgm, APPLY_RESET) < 0) {
avrdude_message(MSG_INFO, "%s: Apply reset operation failed\n", progname); pmsg_error("apply reset operation failed\n");
return -1; return -1;
} }
if (serialupdi_reset(pgm, RELEASE_RESET) < 0) { if (serialupdi_reset(pgm, RELEASE_RESET) < 0) {
avrdude_message(MSG_INFO, "%s: Release reset operation failed\n", progname); pmsg_error("release reset operation failed\n");
return -1; return -1;
} }
if (serialupdi_wait_for_unlock(pgm, 100) < 0) { if (serialupdi_wait_for_unlock(pgm, 100) < 0) {
avrdude_message(MSG_INFO, "%s: Failed to enter NVM programming mode: device is locked\n", progname); pmsg_error("unable to enter NVM programming mode: device is locked\n");
return -1; return -1;
} }
if (serialupdi_in_prog_mode(pgm, &in_prog_mode) < 0) { if (serialupdi_in_prog_mode(pgm, &in_prog_mode) < 0) {
avrdude_message(MSG_INFO, "%s: Checking UPDI NVM prog mode failed\n", progname); pmsg_error("checking UPDI NVM prog mode failed\n");
return -1; return -1;
} }
if (!in_prog_mode) { if (!in_prog_mode) {
avrdude_message(MSG_INFO, "%s: Failed to enter NVM programming mode\n", progname); pmsg_error("unable to enter NVM programming mode\n");
return -1; return -1;
} }
avrdude_message(MSG_DEBUG, "%s: Entered NVM programming mode\n", progname); pmsg_debug("entered NVM programming mode\n");
return 0; return 0;
} }
@ -422,12 +420,12 @@ static int serialupdi_leave_progmode(const PROGRAMMER *pgm) {
(1 << constants.UPDI_CTRLB_UPDIDIS_BIT) | (1 << constants.UPDI_CTRLB_CCDETDIS_BIT)) (1 << constants.UPDI_CTRLB_UPDIDIS_BIT) | (1 << constants.UPDI_CTRLB_CCDETDIS_BIT))
*/ */
if (serialupdi_reset(pgm, APPLY_RESET) < 0) { if (serialupdi_reset(pgm, APPLY_RESET) < 0) {
avrdude_message(MSG_INFO, "%s: Apply reset operation failed\n", progname); pmsg_error("apply reset operation failed\n");
return -1; return -1;
} }
if (serialupdi_reset(pgm, RELEASE_RESET) < 0) { if (serialupdi_reset(pgm, RELEASE_RESET) < 0) {
avrdude_message(MSG_INFO, "%s: Release reset operation failed\n", progname); pmsg_error("release reset operation failed\n");
return -1; return -1;
} }
@ -491,74 +489,74 @@ static int serialupdi_write_userrow(const PROGRAMMER *pgm, const AVRPART *p, con
memcpy(buffer, UPDI_KEY_UROW, sizeof(buffer)); memcpy(buffer, UPDI_KEY_UROW, sizeof(buffer));
if (updi_write_key(pgm, buffer, UPDI_KEY_64, sizeof(buffer)) < 0) { if (updi_write_key(pgm, buffer, UPDI_KEY_64, sizeof(buffer)) < 0) {
avrdude_message(MSG_INFO, "%s: Writing USERROW KEY failed\n", progname); pmsg_error("writing USERROW KEY failed\n");
return -1; return -1;
} }
if (updi_read_cs(pgm, UPDI_ASI_KEY_STATUS, &key_status) < 0) { if (updi_read_cs(pgm, UPDI_ASI_KEY_STATUS, &key_status) < 0) {
avrdude_message(MSG_INFO, "%s: Checking KEY status failed\n", progname); pmsg_error("checking KEY status failed\n");
return -1; return -1;
} }
avrdude_message(MSG_DEBUG, "%s: Key status: 0x%02X\n", progname, key_status); pmsg_debug("key status: 0x%02X\n", key_status);
if (!(key_status & (1 << UPDI_ASI_KEY_STATUS_UROWWRITE))) { if (!(key_status & (1 << UPDI_ASI_KEY_STATUS_UROWWRITE))) {
avrdude_message(MSG_INFO, "%s: Key was not accepted\n", progname); pmsg_error("key was not accepted\n");
return -1; return -1;
} }
if (serialupdi_reset(pgm, APPLY_RESET) < 0) { if (serialupdi_reset(pgm, APPLY_RESET) < 0) {
avrdude_message(MSG_INFO, "%s: Apply reset operation failed\n", progname); pmsg_error("apply reset operation failed\n");
return -1; return -1;
} }
if (serialupdi_reset(pgm, RELEASE_RESET) < 0) { if (serialupdi_reset(pgm, RELEASE_RESET) < 0) {
avrdude_message(MSG_INFO, "%s: Release reset operation failed\n", progname); pmsg_error("release reset operation failed\n");
return -1; return -1;
} }
if (serialupdi_wait_for_urow(pgm, 500, WAIT_FOR_UROW_HIGH) < 0) { if (serialupdi_wait_for_urow(pgm, 500, WAIT_FOR_UROW_HIGH) < 0) {
avrdude_message(MSG_INFO, "%s: Failed to enter USERROW programming mode\n", progname); pmsg_error("unable to enter USERROW programming mode\n");
return -1; return -1;
} }
if (updi_write_data(pgm, m->offset+addr, m->buf + addr, n_bytes) < 0) { if (updi_write_data(pgm, m->offset+addr, m->buf + addr, n_bytes) < 0) {
avrdude_message(MSG_INFO, "%s: Writing USER ROW failed\n", progname); pmsg_error("writing USER ROW failed\n");
return -1; return -1;
} }
if (updi_write_cs(pgm, UPDI_ASI_SYS_CTRLA, (1 << UPDI_ASI_SYS_CTRLA_UROW_FINAL) | if (updi_write_cs(pgm, UPDI_ASI_SYS_CTRLA, (1 << UPDI_ASI_SYS_CTRLA_UROW_FINAL) |
(1 << UPDI_CTRLB_CCDETDIS_BIT)) < 0) { (1 << UPDI_CTRLB_CCDETDIS_BIT)) < 0) {
avrdude_message(MSG_INFO, "%s: Failed trying to commit user row write\n", progname); pmsg_error("unable to commit user row write\n");
return -1; return -1;
} }
if (serialupdi_wait_for_urow(pgm, 500, WAIT_FOR_UROW_LOW) < 0) { if (serialupdi_wait_for_urow(pgm, 500, WAIT_FOR_UROW_LOW) < 0) {
avrdude_message(MSG_DEBUG, "%s: Failed to exit USERROW programming mode\n", progname); pmsg_debug("unable to exit USERROW programming mode\n");
if (serialupdi_reset(pgm, APPLY_RESET) < 0) { if (serialupdi_reset(pgm, APPLY_RESET) < 0) {
avrdude_message(MSG_INFO, "%s: Apply reset operation failed\n", progname); pmsg_error("apply reset operation failed\n");
return -1; return -1;
} }
if (serialupdi_reset(pgm, RELEASE_RESET) < 0) { if (serialupdi_reset(pgm, RELEASE_RESET) < 0) {
avrdude_message(MSG_INFO, "%s: Release reset operation failed\n", progname); pmsg_error("release reset operation failed\n");
return -1; return -1;
} }
} }
if (updi_write_cs(pgm, UPDI_ASI_KEY_STATUS, (1 << UPDI_ASI_KEY_STATUS_UROWWRITE) | if (updi_write_cs(pgm, UPDI_ASI_KEY_STATUS, (1 << UPDI_ASI_KEY_STATUS_UROWWRITE) |
(1 << UPDI_CTRLB_CCDETDIS_BIT)) < 0) { (1 << UPDI_CTRLB_CCDETDIS_BIT)) < 0) {
avrdude_message(MSG_INFO, "%s: Failed trying to complete user row write\n", progname); pmsg_error("unable to complete user row write\n");
return -1; return -1;
} }
if (serialupdi_reset(pgm, APPLY_RESET) < 0) { if (serialupdi_reset(pgm, APPLY_RESET) < 0) {
avrdude_message(MSG_INFO, "%s: Apply reset operation failed\n", progname); pmsg_error("apply reset operation failed\n");
return -1; return -1;
} }
if (serialupdi_reset(pgm, RELEASE_RESET) < 0) { if (serialupdi_reset(pgm, RELEASE_RESET) < 0) {
avrdude_message(MSG_INFO, "%s: Release reset operation failed\n", progname); pmsg_error("release reset operation failed\n");
return -1; return -1;
} }
@ -574,13 +572,13 @@ static int serialupdi_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
uint8_t reset_link_required=0; uint8_t reset_link_required=0;
if (updi_link_init(pgm) < 0) { if (updi_link_init(pgm) < 0) {
avrdude_message(MSG_INFO, "%s: UPDI link initialization failed\n", progname); pmsg_error("UPDI link initialization failed\n");
return -1; return -1;
} }
avrdude_message(MSG_INFO, "%s: UPDI link initialization OK\n", progname); pmsg_notice2("UPDI link initialization OK\n");
if (updi_get_rts_mode(pgm) != RTS_MODE_DEFAULT) { if (updi_get_rts_mode(pgm) != RTS_MODE_DEFAULT) {
avrdude_message(MSG_INFO, "%s: Forcing serial DTR/RTS handshake lines %s\n", progname, updi_get_rts_mode(pgm) == RTS_MODE_LOW ? "LOW" : "HIGH"); pmsg_warning("forcing serial DTR/RTS handshake lines %s\n", updi_get_rts_mode(pgm) == RTS_MODE_LOW ? "LOW" : "HIGH");
} }
if (updi_read_cs(pgm, UPDI_ASI_SYS_STATUS, &value)<0) { if (updi_read_cs(pgm, UPDI_ASI_SYS_STATUS, &value)<0) {
@ -591,33 +589,33 @@ static int serialupdi_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
} }
if (updi_read_cs(pgm, UPDI_ASI_SYS_STATUS, &value)<0) { if (updi_read_cs(pgm, UPDI_ASI_SYS_STATUS, &value)<0) {
avrdude_message(MSG_INFO, "%s: Read CS operation during initialization failed\n", progname); pmsg_error("read CS operation during initialization failed\n");
return -1; return -1;
} }
} }
if (value & (1 << UPDI_ASI_SYS_STATUS_LOCKSTATUS)) { if (value & (1 << UPDI_ASI_SYS_STATUS_LOCKSTATUS)) {
avrdude_message(MSG_INFO, "%s: Device is locked\n", progname); pmsg_notice("device is locked\n");
} }
if (value & (1 << UPDI_ASI_SYS_STATUS_UROWPROG)) { if (value & (1 << UPDI_ASI_SYS_STATUS_UROWPROG)) {
avrdude_message(MSG_INFO, "%s: Device in USER ROW programming state, leaving programming mode\n", progname); pmsg_notice("device in USER ROW programming state, leaving programming mode\n");
reset_link_required = 1; reset_link_required = 1;
} }
if (value & (1 << UPDI_ASI_SYS_STATUS_NVMPROG)) { if (value & (1 << UPDI_ASI_SYS_STATUS_NVMPROG)) {
avrdude_message(MSG_INFO, "%s: Device in NVM programming state, leaving programming mode\n", progname); pmsg_notice("device in NVM programming state, leaving programming mode\n");
reset_link_required = 1; reset_link_required = 1;
} }
if (value & (1 << UPDI_ASI_SYS_STATUS_INSLEEP)) { if (value & (1 << UPDI_ASI_SYS_STATUS_INSLEEP)) {
avrdude_message(MSG_INFO, "%s: Device is in SLEEP mode\n", progname); pmsg_notice("device is in SLEEP mode\n");
} }
if (value & (1 << UPDI_ASI_SYS_STATUS_RSTSYS)) { if (value & (1 << UPDI_ASI_SYS_STATUS_RSTSYS)) {
avrdude_message(MSG_INFO, "%s: Device in reset status, trying to release it\n", progname); pmsg_notice("device in reset status, trying to release it\n");
if (serialupdi_reset(pgm, RELEASE_RESET)<0) { if (serialupdi_reset(pgm, RELEASE_RESET) < 0) {
return -1; return -1;
} }
} }
if (reset_link_required) { if (reset_link_required) {
if (serialupdi_reset_connection(pgm) < 0) { if (serialupdi_reset_connection(pgm) < 0) {
avrdude_message(MSG_INFO, "%s: UPDI link reset failed\n", progname); pmsg_error("UPDI link reset failed\n");
return -1; return -1;
} }
} }
@ -627,25 +625,25 @@ static int serialupdi_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
if (updi_read_sib(pgm, sib_info->sib_string, 32) < 0) { if (updi_read_sib(pgm, sib_info->sib_string, 32) < 0) {
/* this should never happen, let's try to reset connection and try again */ /* this should never happen, let's try to reset connection and try again */
if (serialupdi_reset_connection(pgm) < 0) { if (serialupdi_reset_connection(pgm) < 0) {
avrdude_message(MSG_INFO, "%s: SerialUPDI reset connection failed\n", progname); pmsg_error("SerialUPDI reset connection failed\n");
return -1; return -1;
} }
if (updi_read_sib(pgm, sib_info->sib_string, 32) < 0) { if (updi_read_sib(pgm, sib_info->sib_string, 32) < 0) {
avrdude_message(MSG_INFO, "%s: Read SIB operation failed\n", progname); pmsg_error("read SIB operation failed\n");
return -1; return -1;
} }
} }
if (serialupdi_decode_sib(pgm, sib_info) < 0) { if (serialupdi_decode_sib(pgm, sib_info) < 0) {
avrdude_message(MSG_INFO, "%s: Decode SIB_INFO failed\n", progname); pmsg_error("decode SIB_INFO failed\n");
return -1; return -1;
} }
if (updi_link_init(pgm) < 0) { if (updi_link_init(pgm) < 0) {
avrdude_message(MSG_INFO, "%s: UPDI link initialization failed\n", progname); pmsg_error("UPDI link initialization failed\n");
return -1; return -1;
} }
avrdude_message(MSG_INFO, "%s: Entering NVM programming mode\n", progname); pmsg_notice("entering NVM programming mode\n");
/* try, but ignore failure */ /* try, but ignore failure */
serialupdi_enter_progmode(pgm); serialupdi_enter_progmode(pgm);
@ -671,14 +669,12 @@ static void serialupdi_display(const PROGRAMMER *pgm, const char *p) {
static int serialupdi_cmd(const PROGRAMMER *pgm, const unsigned char *cmd, static int serialupdi_cmd(const PROGRAMMER *pgm, const unsigned char *cmd,
unsigned char * res) unsigned char * res)
{ {
avrdude_message(MSG_INFO, "%s: error: cmd %s[%s] not implemented yet\n", pmsg_error("cmd %s[%s] not implemented yet\n", cmd, res);
progname, cmd, res);
return -1; return -1;
} }
static int serialupdi_program_enable(const PROGRAMMER *pgm, const AVRPART *p) { static int serialupdi_program_enable(const PROGRAMMER *pgm, const AVRPART *p) {
avrdude_message(MSG_INFO, "%s: error: program enable not implemented yet\n", pmsg_error("program enable not implemented yet\n");
progname);
return -1; return -1;
} }
@ -724,7 +720,7 @@ static int serialupdi_paged_load(const PROGRAMMER *pgm, const AVRPART *p, const
rc = updi_read_data(pgm, m->offset + read_offset, m->buf + read_offset, rc = updi_read_data(pgm, m->offset + read_offset, m->buf + read_offset,
remaining_bytes > m->readsize ? m->readsize : remaining_bytes); remaining_bytes > m->readsize ? m->readsize : remaining_bytes);
if (rc < 0) { if (rc < 0) {
avrdude_message(MSG_INFO, "%s: Paged load operation failed\n", progname); pmsg_error("paged load operation failed\n");
return rc; return rc;
} else { } else {
read_bytes+=rc; read_bytes+=rc;
@ -759,15 +755,15 @@ static int serialupdi_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const
rc = serialupdi_write_userrow(pgm, p, m, page_size, write_offset, rc = serialupdi_write_userrow(pgm, p, m, page_size, write_offset,
remaining_bytes > m->page_size ? m->page_size : remaining_bytes); remaining_bytes > m->page_size ? m->page_size : remaining_bytes);
} else if (strcmp(m->desc, "fuses")==0) { } else if (strcmp(m->desc, "fuses")==0) {
avrdude_message(MSG_DEBUG, "%s: Page write operation requested for fuses, falling back to byte-level write\n", progname); pmsg_debug("page write operation requested for fuses, falling back to byte-level write\n");
return -1; return -1;
} else { } else {
avrdude_message(MSG_INFO, "%s: Invalid memory type: <%s:%d>, 0x%06X, %d (0x%04X)\n", progname, m->desc, page_size, addr, n_bytes, n_bytes); pmsg_error("invalid memory type: <%s:%d>, 0x%06X, %d (0x%04X)\n", m->desc, page_size, addr, n_bytes, n_bytes);
rc = -1; rc = -1;
} }
if (rc < 0) { if (rc < 0) {
avrdude_message(MSG_INFO, "%s: Paged write operation failed\n", progname); pmsg_error("paged write operation failed\n");
return rc; return rc;
} else { } else {
write_bytes+=rc; write_bytes+=rc;
@ -784,10 +780,10 @@ static int serialupdi_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const
} else if (strcmp(m->desc, "userrow")==0) { } else if (strcmp(m->desc, "userrow")==0) {
rc = serialupdi_write_userrow(pgm, p, m, page_size, addr, n_bytes); rc = serialupdi_write_userrow(pgm, p, m, page_size, addr, n_bytes);
} else if (strcmp(m->desc, "fuses")==0) { } else if (strcmp(m->desc, "fuses")==0) {
avrdude_message(MSG_DEBUG, "%s: Page write operation requested for fuses, falling back to byte-level write\n", progname); pmsg_debug("page write operation requested for fuses, falling back to byte-level write\n");
rc = -1; rc = -1;
} else { } else {
avrdude_message(MSG_INFO, "%s: Invalid memory type: <%s:%d>, 0x%06X, %d (0x%04X)\n", progname, m->desc, page_size, addr, n_bytes, n_bytes); pmsg_error("invalid memory type: <%s:%d>, 0x%06X, %d (0x%04X)\n", m->desc, page_size, addr, n_bytes, n_bytes);
rc = -1; rc = -1;
} }
return rc; return rc;
@ -824,38 +820,38 @@ static int serialupdi_unlock(const PROGRAMMER *pgm, const AVRPART *p) {
memcpy(buffer, UPDI_KEY_CHIPERASE, sizeof(buffer)); memcpy(buffer, UPDI_KEY_CHIPERASE, sizeof(buffer));
if (updi_write_key(pgm, buffer, UPDI_KEY_64, sizeof(buffer)) < 0) { if (updi_write_key(pgm, buffer, UPDI_KEY_64, sizeof(buffer)) < 0) {
avrdude_message(MSG_INFO, "%s: Writing NVM KEY failed\n", progname); pmsg_error("writing NVM KEY failed\n");
return -1; return -1;
} }
if (updi_read_cs(pgm, UPDI_ASI_KEY_STATUS, &key_status) < 0) { if (updi_read_cs(pgm, UPDI_ASI_KEY_STATUS, &key_status) < 0) {
avrdude_message(MSG_INFO, "%s: Checking KEY status failed\n", progname); pmsg_error("checking KEY status failed\n");
return -1; return -1;
} }
avrdude_message(MSG_DEBUG, "%s: Key status: 0x%02X\n", progname, key_status); pmsg_debug("key status: 0x%02X\n", key_status);
if (!(key_status & (1 << UPDI_ASI_KEY_STATUS_CHIPERASE))) { if (!(key_status & (1 << UPDI_ASI_KEY_STATUS_CHIPERASE))) {
avrdude_message(MSG_INFO, "%s: Key not accepted\n", progname); pmsg_error("key not accepted\n");
return -1; return -1;
} }
if (serialupdi_reset(pgm, APPLY_RESET) < 0) { if (serialupdi_reset(pgm, APPLY_RESET) < 0) {
avrdude_message(MSG_INFO, "%s: Apply reset operation failed\n", progname); pmsg_error("apply reset operation failed\n");
return -1; return -1;
} }
if (serialupdi_reset(pgm, RELEASE_RESET) < 0) { if (serialupdi_reset(pgm, RELEASE_RESET) < 0) {
avrdude_message(MSG_INFO, "%s: Release reset operation failed\n", progname); pmsg_error("release reset operation failed\n");
return -1; return -1;
} }
if (serialupdi_wait_for_unlock(pgm, 500) < 0) { if (serialupdi_wait_for_unlock(pgm, 500) < 0) {
avrdude_message(MSG_INFO, "%s: Waiting for unlock failed\n", progname); pmsg_error("waiting for unlock failed\n");
return -1; return -1;
} }
if (updi_link_init(pgm) < 0) { if (updi_link_init(pgm) < 0) {
avrdude_message(MSG_INFO, "%s: UPDI link reinitialization failed\n", progname); pmsg_error("UPDI link reinitialization failed\n");
return -1; return -1;
} }
@ -866,14 +862,14 @@ static int serialupdi_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) {
uint8_t value; uint8_t value;
if (updi_read_cs(pgm, UPDI_ASI_SYS_STATUS, &value)<0) { if (updi_read_cs(pgm, UPDI_ASI_SYS_STATUS, &value)<0) {
avrdude_message(MSG_INFO, "%s: Read CS operation during chip erase failed\n", progname); pmsg_error("read CS operation during chip erase failed\n");
return -1; return -1;
} }
if (value & (1 << UPDI_ASI_SYS_STATUS_LOCKSTATUS)) { if (value & (1 << UPDI_ASI_SYS_STATUS_LOCKSTATUS)) {
avrdude_message(MSG_INFO, "%s: Device is locked\n", progname); pmsg_warning("device is locked\n");
if (ovsigck) { if (ovsigck) {
avrdude_message(MSG_INFO, "%s: Attempting device erase\n", progname); pmsg_warning("attempting device erase\n");
return serialupdi_unlock(pgm, p); return serialupdi_unlock(pgm, p);
} }
} else { } else {
@ -885,8 +881,7 @@ static int serialupdi_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) {
static int serialupdi_page_erase(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m, static int serialupdi_page_erase(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m,
unsigned int baseaddr) unsigned int baseaddr)
{ {
avrdude_message(MSG_INFO, "%s: error: page erase not implemented yet\n", pmsg_error("page erase not implemented yet\n");
progname);
return -1; return -1;
} }
@ -895,7 +890,7 @@ static int serialupdi_read_signature(const PROGRAMMER *pgm, const AVRPART *p, co
uint8_t value; uint8_t value;
if (updi_read_cs(pgm, UPDI_ASI_SYS_STATUS, &value)<0) { if (updi_read_cs(pgm, UPDI_ASI_SYS_STATUS, &value)<0) {
avrdude_message(MSG_INFO, "%s: Read CS operation during signature read failed\n", progname); pmsg_error("read CS operation during signature read failed\n");
return -1; return -1;
} }
@ -937,14 +932,13 @@ static int serialupdi_parseextparms(const PROGRAMMER *pgm, const LISTID extparms
} else if (strcasecmp(rts_mode, "high") == 0) { } else if (strcasecmp(rts_mode, "high") == 0) {
updi_set_rts_mode(pgm, RTS_MODE_HIGH); updi_set_rts_mode(pgm, RTS_MODE_HIGH);
} else { } else {
avrdude_message(MSG_INFO, "%s: RTS/DTR mode must be LOW or HIGH\n", progname); pmsg_error("RTS/DTR mode must be LOW or HIGH\n");
return -1; return -1;
} }
continue; continue;
} }
avrdude_message(MSG_INFO, "%s: serialupdi_parseextparms(): invalid extended parameter '%s'\n", pmsg_error("invalid extended parameter '%s'\n", extended_param);
progname, extended_param);
rv = -1; rv = -1;
} }

View File

@ -60,8 +60,7 @@ static int stk500_recv(const PROGRAMMER *pgm, unsigned char *buf, size_t len) {
rv = serial_recv(&pgm->fd, buf, len); rv = serial_recv(&pgm->fd, buf, len);
if (rv < 0) { if (rv < 0) {
avrdude_message(MSG_INFO, "%s: stk500_recv(): programmer is not responding\n", pmsg_error("programmer is not responding\n");
progname);
return -1; return -1;
} }
return 0; return 0;
@ -110,8 +109,7 @@ int stk500_getsync(const PROGRAMMER *pgm) {
if(stk500_recv(pgm, resp, 1) >= 0 && resp[0] == Resp_STK_INSYNC) if(stk500_recv(pgm, resp, 1) >= 0 && resp[0] == Resp_STK_INSYNC)
break; break;
avrdude_message(MSG_INFO, "%s: stk500_getsync() attempt %d of %d: not in sync: resp=0x%02x\n", pmsg_warning("attempt %d of %d: not in sync: resp=0x%02x\n", attempt + 1, max_sync_attempts, resp[0]);
progname, attempt + 1, max_sync_attempts, resp[0]);
} }
if (attempt == max_sync_attempts) { if (attempt == max_sync_attempts) {
stk500_drain(pgm, 0); stk500_drain(pgm, 0);
@ -121,9 +119,7 @@ int stk500_getsync(const PROGRAMMER *pgm) {
if (stk500_recv(pgm, resp, 1) < 0) if (stk500_recv(pgm, resp, 1) < 0)
return -1; return -1;
if (resp[0] != Resp_STK_OK) { if (resp[0] != Resp_STK_OK) {
avrdude_message(MSG_INFO, "%s: stk500_getsync(): can't communicate with device: " pmsg_error("cannot communicate with device: resp=0x%02x\n", resp[0]);
"resp=0x%02x\n",
progname, resp[0]);
return -1; return -1;
} }
@ -152,7 +148,7 @@ static int stk500_cmd(const PROGRAMMER *pgm, const unsigned char *cmd,
if (stk500_recv(pgm, buf, 1) < 0) if (stk500_recv(pgm, buf, 1) < 0)
return -1; return -1;
if (buf[0] != Resp_STK_INSYNC) { if (buf[0] != Resp_STK_INSYNC) {
avrdude_message(MSG_INFO, "%s: stk500_cmd(): programmer is out of sync\n", progname); pmsg_error("programmer is out of sync\n");
return -1; return -1;
} }
@ -165,7 +161,7 @@ static int stk500_cmd(const PROGRAMMER *pgm, const unsigned char *cmd,
if (stk500_recv(pgm, buf, 1) < 0) if (stk500_recv(pgm, buf, 1) < 0)
return -1; return -1;
if (buf[0] != Resp_STK_OK) { if (buf[0] != Resp_STK_OK) {
avrdude_message(MSG_INFO, "%s: stk500_cmd(): protocol error\n", progname); pmsg_error("protocol expects OK byte 0x%02x but got 0x%02x\n", Resp_STK_OK, buf[0]);
return -1; return -1;
} }
@ -182,15 +178,13 @@ static int stk500_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) {
unsigned char res[4]; unsigned char res[4];
if (pgm->cmd == NULL) { if (pgm->cmd == NULL) {
avrdude_message(MSG_INFO, "%s: Error: %s programmer uses stk500_chip_erase() but does not\n" pmsg_error("%s programmer uses stk500_chip_erase() but does not\n", pgm->type);
"provide a cmd() method.\n", imsg_error("provide a cmd() method\n");
progname, pgm->type);
return -1; return -1;
} }
if (p->op[AVR_OP_CHIP_ERASE] == NULL) { if (p->op[AVR_OP_CHIP_ERASE] == NULL) {
avrdude_message(MSG_INFO, "%s: chip erase instruction not defined for part \"%s\"\n", pmsg_error("chip erase instruction not defined for part %s\n", p->desc);
progname, p->desc);
return -1; return -1;
} }
@ -226,8 +220,7 @@ static int stk500_program_enable(const PROGRAMMER *pgm, const AVRPART *p) {
return -1; return -1;
if (buf[0] == Resp_STK_NOSYNC) { if (buf[0] == Resp_STK_NOSYNC) {
if (tries > 33) { if (tries > 33) {
avrdude_message(MSG_INFO, "%s: stk500_program_enable(): can't get into sync\n", pmsg_error("cannot get into sync\n");
progname);
return -1; return -1;
} }
if (stk500_getsync(pgm) < 0) if (stk500_getsync(pgm) < 0)
@ -235,9 +228,7 @@ static int stk500_program_enable(const PROGRAMMER *pgm, const AVRPART *p) {
goto retry; goto retry;
} }
else if (buf[0] != Resp_STK_INSYNC) { else if (buf[0] != Resp_STK_INSYNC) {
avrdude_message(MSG_INFO, "%s: stk500_program_enable(): protocol error, " pmsg_error("protocol expects sync byte 0x%02x but got 0x%02x\n", Resp_STK_INSYNC, buf[0]);
"expect=0x%02x, resp=0x%02x\n",
progname, Resp_STK_INSYNC, buf[0]);
return -1; return -1;
} }
@ -247,21 +238,18 @@ static int stk500_program_enable(const PROGRAMMER *pgm, const AVRPART *p) {
return 0; return 0;
} }
else if (buf[0] == Resp_STK_NODEVICE) { else if (buf[0] == Resp_STK_NODEVICE) {
avrdude_message(MSG_INFO, "%s: stk500_program_enable(): no device\n", pmsg_error("no device\n");
progname);
return -1; return -1;
} }
if(buf[0] == Resp_STK_FAILED) if(buf[0] == Resp_STK_FAILED)
{ {
avrdude_message(MSG_INFO, "%s: stk500_program_enable(): failed to enter programming mode\n", pmsg_error("unable to enter programming mode\n");
progname); return -1;
return -1;
} }
avrdude_message(MSG_INFO, "%s: stk500_program_enable(): unknown response=0x%02x\n", pmsg_error("unknown response=0x%02x\n", buf[0]);
progname, buf[0]);
return -1; return -1;
} }
@ -291,8 +279,7 @@ static int stk500_set_extended_parms(const PROGRAMMER *pgm, int n,
return -1; return -1;
if (buf[0] == Resp_STK_NOSYNC) { if (buf[0] == Resp_STK_NOSYNC) {
if (tries > 33) { if (tries > 33) {
avrdude_message(MSG_INFO, "%s: stk500_set_extended_parms(): can't get into sync\n", pmsg_error("cannot get into sync\n");
progname);
return -1; return -1;
} }
if (stk500_getsync(pgm) < 0) if (stk500_getsync(pgm) < 0)
@ -300,9 +287,7 @@ static int stk500_set_extended_parms(const PROGRAMMER *pgm, int n,
goto retry; goto retry;
} }
else if (buf[0] != Resp_STK_INSYNC) { else if (buf[0] != Resp_STK_INSYNC) {
avrdude_message(MSG_INFO, "%s: stk500_set_extended_parms(): protocol error, " pmsg_error("protocol expects sync byte 0x%02x but got 0x%02x\n", Resp_STK_INSYNC, buf[0]);
"expect=0x%02x, resp=0x%02x\n",
progname, Resp_STK_INSYNC, buf[0]);
return -1; return -1;
} }
@ -312,22 +297,16 @@ static int stk500_set_extended_parms(const PROGRAMMER *pgm, int n,
return 0; return 0;
} }
else if (buf[0] == Resp_STK_NODEVICE) { else if (buf[0] == Resp_STK_NODEVICE) {
avrdude_message(MSG_INFO, "%s: stk500_set_extended_parms(): no device\n", pmsg_error("no device\n");
progname);
return -1; return -1;
} }
if(buf[0] == Resp_STK_FAILED) if(buf[0] == Resp_STK_FAILED) {
{ pmsg_error("unable to set extended device programming parameters\n");
avrdude_message(MSG_INFO, "%s: stk500_set_extended_parms(): failed to set extended " return -1;
"device programming parameters\n",
progname);
return -1;
} }
pmsg_error("unknown response=0x%02x\n", buf[0]);
avrdude_message(MSG_INFO, "%s: stk500_set_extended_parms(): unknown response=0x%02x\n",
progname, buf[0]);
return -1; return -1;
} }
@ -360,8 +339,7 @@ static int mib510_isp(const PROGRAMMER *pgm, unsigned char cmd) {
return -1; return -1;
if (buf[0] == Resp_STK_NOSYNC) { if (buf[0] == Resp_STK_NOSYNC) {
if (tries > 33) { if (tries > 33) {
avrdude_message(MSG_INFO, "%s: mib510_isp(): can't get into sync\n", pmsg_error("cannot get into sync\n");
progname);
return -1; return -1;
} }
if (stk500_getsync(pgm) < 0) if (stk500_getsync(pgm) < 0)
@ -369,9 +347,7 @@ static int mib510_isp(const PROGRAMMER *pgm, unsigned char cmd) {
goto retry; goto retry;
} }
else if (buf[0] != Resp_STK_INSYNC) { else if (buf[0] != Resp_STK_INSYNC) {
avrdude_message(MSG_INFO, "%s: mib510_isp(): protocol error, " pmsg_error("protocol expects sync byte 0x%02x but got 0x%02x\n", Resp_STK_INSYNC, buf[0]);
"expect=0x%02x, resp=0x%02x\n",
progname, Resp_STK_INSYNC, buf[0]);
return -1; return -1;
} }
@ -381,21 +357,18 @@ static int mib510_isp(const PROGRAMMER *pgm, unsigned char cmd) {
return 0; return 0;
} }
else if (buf[0] == Resp_STK_NODEVICE) { else if (buf[0] == Resp_STK_NODEVICE) {
avrdude_message(MSG_INFO, "%s: mib510_isp(): no device\n", pmsg_error("no device\n");
progname);
return -1; return -1;
} }
if (buf[0] == Resp_STK_FAILED) if (buf[0] == Resp_STK_FAILED)
{ {
avrdude_message(MSG_INFO, "%s: mib510_isp(): command %d failed\n", pmsg_error("command %d failed\n", cmd);
progname, cmd);
return -1; return -1;
} }
avrdude_message(MSG_INFO, "%s: mib510_isp(): unknown response=0x%02x\n", pmsg_error("unknown response=0x%02x\n", buf[0]);
progname, buf[0]);
return -1; return -1;
} }
@ -454,8 +427,7 @@ static int stk500_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
} }
#if 0 #if 0
avrdude_message(MSG_INFO, "%s: stk500_initialize(): n_extparms = %d\n", pmsg_info("stk500_initialize(): n_extparms = %d\n", n_extparms);
progname, n_extparms);
#endif #endif
buf[5] = 1; /* polling supported - XXX need this in config file */ buf[5] = 1; /* polling supported - XXX need this in config file */
@ -528,8 +500,7 @@ static int stk500_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
if (stk500_recv(pgm, buf, 1) < 0) if (stk500_recv(pgm, buf, 1) < 0)
return -1; return -1;
if (buf[0] == Resp_STK_NOSYNC) { if (buf[0] == Resp_STK_NOSYNC) {
avrdude_message(MSG_INFO, "%s: stk500_initialize(): programmer not in sync, resp=0x%02x\n", pmsg_warning("programmer not in sync, resp=0x%02x\n", buf[0]);
progname, buf[0]);
if (tries > 33) if (tries > 33)
return -1; return -1;
if (stk500_getsync(pgm) < 0) if (stk500_getsync(pgm) < 0)
@ -537,26 +508,21 @@ static int stk500_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
goto retry; goto retry;
} }
else if (buf[0] != Resp_STK_INSYNC) { else if (buf[0] != Resp_STK_INSYNC) {
avrdude_message(MSG_INFO, "%s: stk500_initialize(): (a) protocol error, " pmsg_error("protocol expects sync byte 0x%02x but got 0x%02x\n", Resp_STK_INSYNC, buf[0]);
"expect=0x%02x, resp=0x%02x\n",
progname, Resp_STK_INSYNC, buf[0]);
return -1; return -1;
} }
if (stk500_recv(pgm, buf, 1) < 0) if (stk500_recv(pgm, buf, 1) < 0)
return -1; return -1;
if (buf[0] != Resp_STK_OK) { if (buf[0] != Resp_STK_OK) {
avrdude_message(MSG_INFO, "%s: stk500_initialize(): (b) protocol error, " pmsg_error("protocol expects OK byte 0x%02x but got 0x%02x\n", Resp_STK_OK, buf[0]);
"expect=0x%02x, resp=0x%02x\n",
progname, Resp_STK_OK, buf[0]);
return -1; return -1;
} }
if (n_extparms) { if (n_extparms) {
if ((p->pagel == 0) || (p->bs2 == 0)) { if ((p->pagel == 0) || (p->bs2 == 0)) {
avrdude_message(MSG_NOTICE2, "%s: PAGEL and BS2 signals not defined in the configuration " pmsg_notice2("PAGEL and BS2 signals not defined in the configuration "
"file for part %s, using dummy values\n", "file for part %s, using dummy values\n", p->desc);
progname, p->desc);
buf[2] = 0xD7; /* they look somehow possible, */ buf[2] = 0xD7; /* they look somehow possible, */
buf[3] = 0xA0; /* don't they? ;) */ buf[3] = 0xA0; /* don't they? ;) */
} }
@ -584,7 +550,7 @@ static int stk500_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
rc = stk500_set_extended_parms(pgm, n_extparms+1, buf); rc = stk500_set_extended_parms(pgm, n_extparms+1, buf);
if (rc) { if (rc) {
avrdude_message(MSG_INFO, "%s: stk500_initialize(): failed\n", progname); pmsg_error("failed to initialise programmer\n");
return -1; return -1;
} }
} }
@ -604,13 +570,11 @@ static int stk500_parseextparms(const PROGRAMMER *pgm, const LISTID extparms)
if (sscanf(extended_param, "attempts=%2d", &attempts) == 1) { if (sscanf(extended_param, "attempts=%2d", &attempts) == 1) {
PDATA(pgm)->retry_attempts = attempts; PDATA(pgm)->retry_attempts = attempts;
avrdude_message(MSG_INFO, "%s: Setting number of retry attempts to %d\n", pmsg_info("setting number of retry attempts to %d\n", attempts);
progname, attempts);
continue; continue;
} }
avrdude_message(MSG_INFO, "%s: stk500_parseextparms(): invalid extended parameter '%s'\n", pmsg_error("invalid extended parameter '%s'\n", extended_param);
progname, extended_param);
rv = -1; rv = -1;
} }
@ -633,8 +597,7 @@ static void stk500_disable(const PROGRAMMER *pgm) {
return; return;
if (buf[0] == Resp_STK_NOSYNC) { if (buf[0] == Resp_STK_NOSYNC) {
if (tries > 33) { if (tries > 33) {
avrdude_message(MSG_INFO, "%s: stk500_disable(): can't get into sync\n", pmsg_error("cannot get into sync\n");
progname);
return; return;
} }
if (stk500_getsync(pgm) < 0) if (stk500_getsync(pgm) < 0)
@ -642,9 +605,7 @@ static void stk500_disable(const PROGRAMMER *pgm) {
goto retry; goto retry;
} }
else if (buf[0] != Resp_STK_INSYNC) { else if (buf[0] != Resp_STK_INSYNC) {
avrdude_message(MSG_INFO, "%s: stk500_disable(): protocol error, expect=0x%02x, " pmsg_error("protocol expects sync byte 0x%02x but got 0x%02x\n", Resp_STK_INSYNC, buf[0]);
"resp=0x%02x\n",
progname, Resp_STK_INSYNC, buf[0]);
return; return;
} }
@ -654,13 +615,11 @@ static void stk500_disable(const PROGRAMMER *pgm) {
return; return;
} }
else if (buf[0] == Resp_STK_NODEVICE) { else if (buf[0] == Resp_STK_NODEVICE) {
avrdude_message(MSG_INFO, "%s: stk500_disable(): no device\n", pmsg_error("no device\n");
progname);
return; return;
} }
avrdude_message(MSG_INFO, "%s: stk500_disable(): unknown response=0x%02x\n", pmsg_error("unknown response=0x%02x\n", buf[0]);
progname, buf[0]);
return; return;
} }
@ -742,8 +701,7 @@ static int stk500_loadaddr(const PROGRAMMER *pgm, const AVRMEM *mem, const unsig
return -1; return -1;
if (buf[0] == Resp_STK_NOSYNC) { if (buf[0] == Resp_STK_NOSYNC) {
if (tries > 33) { if (tries > 33) {
avrdude_message(MSG_INFO, "%s: stk500_loadaddr(): can't get into sync\n", pmsg_error("cannot get into sync\n");
progname);
return -1; return -1;
} }
if (stk500_getsync(pgm) < 0) if (stk500_getsync(pgm) < 0)
@ -751,9 +709,7 @@ static int stk500_loadaddr(const PROGRAMMER *pgm, const AVRMEM *mem, const unsig
goto retry; goto retry;
} }
else if (buf[0] != Resp_STK_INSYNC) { else if (buf[0] != Resp_STK_INSYNC) {
avrdude_message(MSG_INFO, "%s: stk500_loadaddr(): (a) protocol error, " pmsg_error("protocol expects sync byte 0x%02x but got 0x%02x\n", Resp_STK_INSYNC, buf[0]);
"expect=0x%02x, resp=0x%02x\n",
progname, Resp_STK_INSYNC, buf[0]);
return -1; return -1;
} }
@ -762,9 +718,7 @@ static int stk500_loadaddr(const PROGRAMMER *pgm, const AVRMEM *mem, const unsig
if (buf[0] == Resp_STK_OK) if (buf[0] == Resp_STK_OK)
return 0; return 0;
avrdude_message(MSG_INFO, "%s: stk500_loadaddr(): (b) protocol error, " pmsg_error("protocol expects OK byte 0x%02x but got 0x%02x\n", Resp_STK_OK, buf[0]);
"expect=0x%02x, resp=0x%02x\n",
progname, Resp_STK_OK, buf[0]);
return -1; return -1;
} }
@ -800,11 +754,12 @@ static int stk500_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const AVR
n = addr + n_bytes; n = addr + n_bytes;
#if 0 #if 0
avrdude_message(MSG_INFO, "n_bytes = %d\n" msg_info(
"n = %u\n" "n_bytes = %d\n"
"a_div = %d\n" "n = %u\n"
"page_size = %d\n", "a_div = %d\n"
n_bytes, n, a_div, page_size); "page_size = %d\n",
n_bytes, n, a_div, page_size);
#endif #endif
for (; addr < n; addr += block_size) { for (; addr < n; addr += block_size) {
@ -838,27 +793,25 @@ static int stk500_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const AVR
return -1; return -1;
if (buf[0] == Resp_STK_NOSYNC) { if (buf[0] == Resp_STK_NOSYNC) {
if (tries > 33) { if (tries > 33) {
avrdude_message(MSG_INFO, "\n%s: stk500_paged_write(): can't get into sync\n", msg_error("\n");
progname); pmsg_error("cannot get into sync\n");
return -3; return -3;
} }
if (stk500_getsync(pgm) < 0) if (stk500_getsync(pgm) < 0)
return -1; return -1;
goto retry; goto retry;
} }
else if (buf[0] != Resp_STK_INSYNC) { else if (buf[0] != Resp_STK_INSYNC) {
avrdude_message(MSG_INFO, "\n%s: stk500_paged_write(): (a) protocol error, " msg_error("\n");
"expect=0x%02x, resp=0x%02x\n", pmsg_error("protocol expects sync byte 0x%02x but got 0x%02x\n", Resp_STK_INSYNC, buf[0]);
progname, Resp_STK_INSYNC, buf[0]);
return -4; return -4;
} }
if (stk500_recv(pgm, buf, 1) < 0) if (stk500_recv(pgm, buf, 1) < 0)
return -1; return -1;
if (buf[0] != Resp_STK_OK) { if (buf[0] != Resp_STK_OK) {
avrdude_message(MSG_INFO, "\n%s: stk500_paged_write(): (b) protocol error, " msg_error("\n");
"expect=0x%02x, resp=0x%02x\n", pmsg_error("protocol expects OK byte 0x%02x but got 0x%02x\n", Resp_STK_OK, buf[0]);
progname, Resp_STK_OK, buf[0]);
return -5; return -5;
} }
} }
@ -920,18 +873,17 @@ static int stk500_paged_load(const PROGRAMMER *pgm, const AVRPART *p, const AVRM
return -1; return -1;
if (buf[0] == Resp_STK_NOSYNC) { if (buf[0] == Resp_STK_NOSYNC) {
if (tries > 33) { if (tries > 33) {
avrdude_message(MSG_INFO, "\n%s: stk500_paged_load(): can't get into sync\n", msg_error("\n");
progname); pmsg_error("cannot get into sync\n");
return -3; return -3;
} }
if (stk500_getsync(pgm) < 0) if (stk500_getsync(pgm) < 0)
return -1; return -1;
goto retry; goto retry;
} }
else if (buf[0] != Resp_STK_INSYNC) { else if (buf[0] != Resp_STK_INSYNC) {
avrdude_message(MSG_INFO, "\n%s: stk500_paged_load(): (a) protocol error, " msg_error("\n");
"expect=0x%02x, resp=0x%02x\n", pmsg_error("protocol expects sync byte 0x%02x but got 0x%02x\n", Resp_STK_INSYNC, buf[0]);
progname, Resp_STK_INSYNC, buf[0]);
return -4; return -4;
} }
@ -943,17 +895,15 @@ static int stk500_paged_load(const PROGRAMMER *pgm, const AVRPART *p, const AVRM
if(strcmp(ldata(lfirst(pgm->id)), "mib510") == 0) { if(strcmp(ldata(lfirst(pgm->id)), "mib510") == 0) {
if (buf[0] != Resp_STK_INSYNC) { if (buf[0] != Resp_STK_INSYNC) {
avrdude_message(MSG_INFO, "\n%s: stk500_paged_load(): (a) protocol error, " msg_error("\n");
"expect=0x%02x, resp=0x%02x\n", pmsg_error("protocol expects sync byte 0x%02x but got 0x%02x\n", Resp_STK_INSYNC, buf[0]);
progname, Resp_STK_INSYNC, buf[0]); return -5;
return -5; }
} }
}
else { else {
if (buf[0] != Resp_STK_OK) { if (buf[0] != Resp_STK_OK) {
avrdude_message(MSG_INFO, "\n%s: stk500_paged_load(): (b) protocol error, " msg_error("\n");
"expect=0x%02x, resp=0x%02x\n", pmsg_error("protocol expects OK byte 0x%02x but got 0x%02x\n", Resp_STK_OK, buf[0]);
progname, Resp_STK_OK, buf[0]);
return -5; return -5;
} }
} }
@ -969,16 +919,13 @@ static int stk500_set_vtarget(const PROGRAMMER *pgm, double v) {
utarg = (unsigned)((v + 0.049) * 10); utarg = (unsigned)((v + 0.049) * 10);
if (stk500_getparm(pgm, Parm_STK_VADJUST, &uaref) != 0) { if (stk500_getparm(pgm, Parm_STK_VADJUST, &uaref) != 0) {
avrdude_message(MSG_INFO, "%s: stk500_set_vtarget(): cannot obtain V[aref]\n", pmsg_error("cannot obtain V[aref]\n");
progname);
return -1; return -1;
} }
if (uaref > utarg) { if (uaref > utarg) {
avrdude_message(MSG_INFO, "%s: stk500_set_vtarget(): reducing V[aref] from %.1f to %.1f\n", pmsg_error("reducing V[aref] from %.1f to %.1f\n", uaref / 10.0, v);
progname, uaref / 10.0, v); if (stk500_setparm(pgm, Parm_STK_VADJUST, utarg) != 0)
if (stk500_setparm(pgm, Parm_STK_VADJUST, utarg)
!= 0)
return -1; return -1;
} }
return stk500_setparm(pgm, Parm_STK_VTARGET, utarg); return stk500_setparm(pgm, Parm_STK_VTARGET, utarg);
@ -993,15 +940,13 @@ static int stk500_set_varef(const PROGRAMMER *pgm, unsigned int chan /* unused *
uaref = (unsigned)((v + 0.049) * 10); uaref = (unsigned)((v + 0.049) * 10);
if (stk500_getparm(pgm, Parm_STK_VTARGET, &utarg) != 0) { if (stk500_getparm(pgm, Parm_STK_VTARGET, &utarg) != 0) {
avrdude_message(MSG_INFO, "%s: stk500_set_varef(): cannot obtain V[target]\n", pmsg_error("cannot obtain V[target]\n");
progname);
return -1; return -1;
} }
if (uaref > utarg) { if (uaref > utarg) {
avrdude_message(MSG_INFO, "%s: stk500_set_varef(): V[aref] must not be greater than " pmsg_error("V[aref] must not be greater than "
"V[target] = %.1f\n", "V[target] = %.1f\n", utarg/10.0);
progname, utarg / 10.0);
return -1; return -1;
} }
return stk500_setparm(pgm, Parm_STK_VADJUST, uaref); return stk500_setparm(pgm, Parm_STK_VADJUST, uaref);
@ -1028,11 +973,10 @@ static int stk500_set_fosc(const PROGRAMMER *pgm, double v) {
unit = "kHz"; unit = "kHz";
} else } else
unit = "Hz"; unit = "Hz";
avrdude_message(MSG_INFO, "%s: stk500_set_fosc(): f = %.3f %s too high, using %.3f MHz\n", pmsg_warning("f = %.3f %s too high, using %.3f MHz\n", v, unit, STK500_XTAL/2e6);
progname, v, unit, STK500_XTAL / 2e6);
fosc = STK500_XTAL / 2; fosc = STK500_XTAL / 2;
} else } else
fosc = (unsigned)v; fosc = (unsigned) v;
for (idx = 0; idx < sizeof(ps) / sizeof(ps[0]); idx++) { for (idx = 0; idx < sizeof(ps) / sizeof(ps[0]); idx++) {
if (fosc >= STK500_XTAL / (256 * ps[idx] * 2)) { if (fosc >= STK500_XTAL / (256 * ps[idx] * 2)) {
@ -1043,8 +987,7 @@ static int stk500_set_fosc(const PROGRAMMER *pgm, double v) {
} }
} }
if (idx == sizeof(ps) / sizeof(ps[0])) { if (idx == sizeof(ps) / sizeof(ps[0])) {
avrdude_message(MSG_INFO, "%s: stk500_set_fosc(): f = %u Hz too low, %u Hz min\n", pmsg_warning("f = %u Hz too low, %u Hz min\n", fosc, STK500_XTAL / (256 * 1024 * 2));
progname, fosc, STK500_XTAL / (256 * 1024 * 2));
return -1; return -1;
} }
} }
@ -1074,12 +1017,12 @@ static int stk500_set_sck_period(const PROGRAMMER *pgm, double v) {
if (v < min) { if (v < min) {
dur = 1; dur = 1;
avrdude_message(MSG_INFO, "%s: stk500_set_sck_period(): p = %.1f us too small, using %.1f us\n", pmsg_warning("p = %.1f us too small, using %.1f us\n",
progname, v / 1e-6, dur * min / 1e-6); v/1e-6, dur*min/1e-6);
} else if (v > max) { } else if (v > max) {
dur = 255; dur = 255;
avrdude_message(MSG_INFO, "%s: stk500_set_sck_period(): p = %.1f us too large, using %.1f us\n", pmsg_warning("p = %.1f us too large, using %.1f us\n",
progname, v / 1e-6, dur * min / 1e-6); v/1e-6, dur*min/1e-6);
} }
return stk500_setparm(pgm, Parm_STK_SCK_DURATION, dur); return stk500_setparm(pgm, Parm_STK_SCK_DURATION, dur);
@ -1103,8 +1046,8 @@ static int stk500_getparm(const PROGRAMMER *pgm, unsigned parm, unsigned *value)
return -1; return -1;
if (buf[0] == Resp_STK_NOSYNC) { if (buf[0] == Resp_STK_NOSYNC) {
if (tries > 33) { if (tries > 33) {
avrdude_message(MSG_INFO, "\n%s: stk500_getparm(): can't get into sync\n", msg_error("\n");
progname); pmsg_error("cannot get into sync\n");
return -1; return -1;
} }
if (stk500_getsync(pgm) < 0) if (stk500_getsync(pgm) < 0)
@ -1112,9 +1055,8 @@ static int stk500_getparm(const PROGRAMMER *pgm, unsigned parm, unsigned *value)
goto retry; goto retry;
} }
else if (buf[0] != Resp_STK_INSYNC) { else if (buf[0] != Resp_STK_INSYNC) {
avrdude_message(MSG_INFO, "\n%s: stk500_getparm(): (a) protocol error, " msg_error("\n");
"expect=0x%02x, resp=0x%02x\n", pmsg_error("protocol expects sync byte 0x%02x but got 0x%02x\n", Resp_STK_INSYNC, buf[0]);
progname, Resp_STK_INSYNC, buf[0]);
return -2; return -2;
} }
@ -1125,14 +1067,13 @@ static int stk500_getparm(const PROGRAMMER *pgm, unsigned parm, unsigned *value)
if (stk500_recv(pgm, buf, 1) < 0) if (stk500_recv(pgm, buf, 1) < 0)
return -1; return -1;
if (buf[0] == Resp_STK_FAILED) { if (buf[0] == Resp_STK_FAILED) {
avrdude_message(MSG_INFO, "\n%s: stk500_getparm(): parameter 0x%02x failed\n", msg_error("\n");
progname, v); pmsg_error("parameter 0x%02x failed\n", v);
return -3; return -3;
} }
else if (buf[0] != Resp_STK_OK) { else if (buf[0] != Resp_STK_OK) {
avrdude_message(MSG_INFO, "\n%s: stk500_getparm(): (b) protocol error, " msg_error("\n");
"expect=0x%02x, resp=0x%02x\n", pmsg_error("protocol expects OK byte 0x%02x but got 0x%02x\n", Resp_STK_OK, buf[0]);
progname, Resp_STK_OK, buf[0]);
return -3; return -3;
} }
@ -1159,8 +1100,8 @@ static int stk500_setparm(const PROGRAMMER *pgm, unsigned parm, unsigned value)
return -1; return -1;
if (buf[0] == Resp_STK_NOSYNC) { if (buf[0] == Resp_STK_NOSYNC) {
if (tries > 33) { if (tries > 33) {
avrdude_message(MSG_INFO, "\n%s: stk500_setparm(): can't get into sync\n", msg_error("\n");
progname); pmsg_error("cannot get into sync\n");
return -1; return -1;
} }
if (stk500_getsync(pgm) < 0) if (stk500_getsync(pgm) < 0)
@ -1168,9 +1109,8 @@ static int stk500_setparm(const PROGRAMMER *pgm, unsigned parm, unsigned value)
goto retry; goto retry;
} }
else if (buf[0] != Resp_STK_INSYNC) { else if (buf[0] != Resp_STK_INSYNC) {
avrdude_message(MSG_INFO, "\n%s: stk500_setparm(): (a) protocol error, " msg_error("\n");
"expect=0x%02x, resp=0x%02x\n", pmsg_error("protocol expects sync byte 0x%02x but got 0x%02x\n", Resp_STK_INSYNC, buf[0]);
progname, Resp_STK_INSYNC, buf[0]);
return -2; return -2;
} }
@ -1179,18 +1119,17 @@ static int stk500_setparm(const PROGRAMMER *pgm, unsigned parm, unsigned value)
if (buf[0] == Resp_STK_OK) if (buf[0] == Resp_STK_OK)
return 0; return 0;
parm = buf[0]; /* if not STK_OK, we've been echoed parm here */ parm = buf[0]; /* if not STK_OK, we've been echoed parm here */
if (stk500_recv(pgm, buf, 1) < 0) if (stk500_recv(pgm, buf, 1) < 0)
return -1; return -1;
if (buf[0] == Resp_STK_FAILED) { if (buf[0] == Resp_STK_FAILED) {
avrdude_message(MSG_INFO, "\n%s: stk500_setparm(): parameter 0x%02x failed\n", msg_error("\n");
progname, parm); pmsg_error("parameter 0x%02x failed\n", parm);
return -3; return -3;
} }
else { else {
avrdude_message(MSG_INFO, "\n%s: stk500_setparm(): (b) protocol error, " msg_error("\n");
"expect=0x%02x, resp=0x%02x\n", pmsg_error("protocol expects OK byte 0x%02x but got 0x%02x\n", Resp_STK_OK, buf[0]);
progname, Resp_STK_OK, buf[0]);
return -3; return -3;
} }
} }
@ -1204,21 +1143,21 @@ static void stk500_display(const PROGRAMMER *pgm, const char *p) {
stk500_getparm(pgm, Parm_STK_SW_MINOR, &min); stk500_getparm(pgm, Parm_STK_SW_MINOR, &min);
stk500_getparm(pgm, Param_STK500_TOPCARD_DETECT, &topcard); stk500_getparm(pgm, Param_STK500_TOPCARD_DETECT, &topcard);
avrdude_message(MSG_INFO, "%sHardware Version: %d\n", p, hdw); msg_info("%sHardware Version: %d\n", p, hdw);
avrdude_message(MSG_INFO, "%sFirmware Version: %d.%d\n", p, maj, min); msg_info("%sFirmware Version: %d.%d\n", p, maj, min);
if (topcard < 3) { if (topcard < 3) {
const char *n = "Unknown"; const char *n = "Unknown";
switch (topcard) { switch (topcard) {
case 1: case 1:
n = "STK502"; n = "STK502";
break; break;
case 2: case 2:
n = "STK501"; n = "STK501";
break; break;
} }
avrdude_message(MSG_INFO, "%sTopcard : %s\n", p, n); msg_info("%sTopcard : %s\n", p, n);
} }
if(strcmp(pgm->type, "Arduino") != 0) if(strcmp(pgm->type, "Arduino") != 0)
stk500_print_parms1(pgm, p); stk500_print_parms1(pgm, p);
@ -1236,11 +1175,11 @@ static void stk500_print_parms1(const PROGRAMMER *pgm, const char *p) {
stk500_getparm(pgm, Parm_STK_OSC_CMATCH, &osc_cmatch); stk500_getparm(pgm, Parm_STK_OSC_CMATCH, &osc_cmatch);
stk500_getparm(pgm, Parm_STK_SCK_DURATION, &sck_duration); stk500_getparm(pgm, Parm_STK_SCK_DURATION, &sck_duration);
avrdude_message(MSG_INFO, "%sVtarget : %.1f V\n", p, vtarget / 10.0); msg_info("%sVtarget : %.1f V\n", p, vtarget / 10.0);
avrdude_message(MSG_INFO, "%sVaref : %.1f V\n", p, vadjust / 10.0); msg_info("%sVaref : %.1f V\n", p, vadjust / 10.0);
avrdude_message(MSG_INFO, "%sOscillator : ", p); msg_info("%sOscillator : ", p);
if (osc_pscale == 0) if (osc_pscale == 0)
avrdude_message(MSG_INFO, "Off\n"); msg_info("Off\n");
else { else {
int prescale = 1; int prescale = 1;
double f = STK500_XTAL / 2; double f = STK500_XTAL / 2;
@ -1264,10 +1203,9 @@ static void stk500_print_parms1(const PROGRAMMER *pgm, const char *p) {
unit = "kHz"; unit = "kHz";
} else } else
unit = "Hz"; unit = "Hz";
avrdude_message(MSG_INFO, "%.3f %s\n", f, unit); msg_info("%.3f %s\n", f, unit);
} }
avrdude_message(MSG_INFO, "%sSCK period : %.1f us\n", p, msg_info("%sSCK period : %.1f us\n", p, sck_duration * 8.0e6 / STK500_XTAL + 0.05);
sck_duration * 8.0e6 / STK500_XTAL + 0.05);
return; return;
} }
@ -1280,8 +1218,7 @@ static void stk500_print_parms(const PROGRAMMER *pgm) {
static void stk500_setup(PROGRAMMER * pgm) static void stk500_setup(PROGRAMMER * pgm)
{ {
if ((pgm->cookie = malloc(sizeof(struct pdata))) == 0) { if ((pgm->cookie = malloc(sizeof(struct pdata))) == 0) {
avrdude_message(MSG_INFO, "%s: stk500_setup(): Out of memory allocating private data\n", pmsg_error("out of memory allocating private data\n");
progname);
return; return;
} }
memset(pgm->cookie, 0, sizeof(struct pdata)); memset(pgm->cookie, 0, sizeof(struct pdata));

View File

@ -42,8 +42,7 @@ static int stk500generic_open(PROGRAMMER *pgm, const char *port) {
stk500_initpgm(pgm); stk500_initpgm(pgm);
if (pgm->open(pgm, port) >= 0) if (pgm->open(pgm, port) >= 0)
{ {
avrdude_message(MSG_INFO, "%s: successfully opened stk500v1 device -- please use -c stk500v1\n", pmsg_info("successfully opened stk500v1 device -- please use -c stk500v1\n");
progname);
return 0; return 0;
} }
@ -52,13 +51,11 @@ static int stk500generic_open(PROGRAMMER *pgm, const char *port) {
stk500v2_initpgm(pgm); stk500v2_initpgm(pgm);
if (pgm->open(pgm, port) >= 0) if (pgm->open(pgm, port) >= 0)
{ {
avrdude_message(MSG_INFO, "%s: successfully opened stk500v2 device -- please use -c stk500v2\n", pmsg_info("successfully opened stk500v2 device -- please use -c stk500v2\n");
progname);
return 0; return 0;
} }
avrdude_message(MSG_INFO, "%s: cannot open either stk500v1 or stk500v2 programmer\n", pmsg_error("cannot open either stk500v1 or stk500v2 programmer\n");
progname);
return -1; return -1;
} }

File diff suppressed because it is too large Load Diff

View File

@ -127,12 +127,12 @@ static int teensy_get_bootloader_info(pdata_t* pdata, const AVRPART* p) {
// On Linux, libhidapi does not seem to return the HID usage from the report descriptor. // On Linux, libhidapi does not seem to return the HID usage from the report descriptor.
// We try to infer the board from the part information, until somebody fixes libhidapi. // We try to infer the board from the part information, until somebody fixes libhidapi.
// To use this workaround, the -F option is required. // To use this workaround, the -F option is required.
avrdude_message(MSG_INFO, "%s: WARNING: Cannot detect board type (HID usage is 0)\n", progname); pmsg_error("cannot detect board type (HID usage is 0)\n");
AVRMEM* mem = avr_locate_mem(p, "flash"); AVRMEM* mem = avr_locate_mem(p, "flash");
if (mem == NULL) if (mem == NULL)
{ {
avrdude_message(MSG_INFO, "No flash memory for part %s\n", p->desc); pmsg_error("no flash memory defined for part %s\n", p->desc);
return -1; return -1;
} }
@ -147,8 +147,7 @@ static int teensy_get_bootloader_info(pdata_t* pdata, const AVRPART* p) {
} }
else else
{ {
avrdude_message(MSG_INFO, "%s: ERROR: Teensy board not supported (HID usage 0x%02X)\n", pmsg_error("Teensy board not supported (HID usage 0x%02X)\n", pdata->hid_usage);
progname, pdata->hid_usage);
return -1; return -1;
} }
} }
@ -158,21 +157,21 @@ static int teensy_get_bootloader_info(pdata_t* pdata, const AVRPART* p) {
static void teensy_dump_device_info(pdata_t* pdata) static void teensy_dump_device_info(pdata_t* pdata)
{ {
avrdude_message(MSG_NOTICE, "%s: HID usage: 0x%02X\n", progname, pdata->hid_usage); pmsg_notice("HID usage: 0x%02X\n", pdata->hid_usage);
avrdude_message(MSG_NOTICE, "%s: Board: %s\n", progname, pdata->board); pmsg_notice("Board: %s\n", pdata->board);
avrdude_message(MSG_NOTICE, "%s: Available flash size: %u\n", progname, pdata->flash_size); pmsg_notice("Available flash size: %u\n", pdata->flash_size);
avrdude_message(MSG_NOTICE, "%s: Page size: %u\n", progname, pdata->page_size); pmsg_notice("Page size: %u\n", pdata->page_size);
avrdude_message(MSG_NOTICE, "%s: Signature: 0x%02X%02X%02X\n", progname, pmsg_notice("Signature: 0x%02X%02X%02X\n",
pdata->sig_bytes[0], pdata->sig_bytes[1], pdata->sig_bytes[2]); pdata->sig_bytes[0], pdata->sig_bytes[1], pdata->sig_bytes[2]);
} }
static int teensy_write_page(pdata_t* pdata, uint32_t address, const uint8_t* buffer, uint32_t size, bool suppress_warning) static int teensy_write_page(pdata_t* pdata, uint32_t address, const uint8_t* buffer, uint32_t size, bool suppress_warning)
{ {
avrdude_message(MSG_DEBUG, "%s: teensy_write_page(address=0x%06X, size=%d)\n", progname, address, size); pmsg_debug("teensy_write_page(address=0x%06X, size=%d)\n", address, size);
if (size > pdata->page_size) if (size > pdata->page_size)
{ {
avrdude_message(MSG_INFO, "%s: ERROR: Invalid page size: %u\n", progname, pdata->page_size); pmsg_error("invalid page size: %u\n", pdata->page_size);
return -1; return -1;
} }
@ -180,7 +179,7 @@ static int teensy_write_page(pdata_t* pdata, uint32_t address, const uint8_t* bu
uint8_t* report = (uint8_t*)malloc(report_size); uint8_t* report = (uint8_t*)malloc(report_size);
if (report == NULL) if (report == NULL)
{ {
avrdude_message(MSG_INFO, "%s: ERROR: Failed to allocate memory\n", progname); pmsg_error("unable to allocate memory\n");
return -1; return -1;
} }
@ -208,10 +207,7 @@ static int teensy_write_page(pdata_t* pdata, uint32_t address, const uint8_t* bu
if (result < 0) if (result < 0)
{ {
if (!suppress_warning) if (!suppress_warning)
{ pmsg_error("unable to write page: %ls\n", hid_error(pdata->hid_handle));
avrdude_message(MSG_INFO, "%s: WARNING: Failed to write page: %ls\n",
progname, hid_error(pdata->hid_handle));
}
return result; return result;
} }
@ -221,7 +217,7 @@ static int teensy_write_page(pdata_t* pdata, uint32_t address, const uint8_t* bu
static int teensy_erase_flash(pdata_t* pdata) static int teensy_erase_flash(pdata_t* pdata)
{ {
avrdude_message(MSG_DEBUG, "%s: teensy_erase_flash()\n", progname); pmsg_debug("teensy_erase_flash()\n");
// Write a dummy page at address 0 to explicitly erase the flash. // Write a dummy page at address 0 to explicitly erase the flash.
return teensy_write_page(pdata, 0, NULL, 0, false); return teensy_write_page(pdata, 0, NULL, 0, false);
@ -229,7 +225,7 @@ static int teensy_erase_flash(pdata_t* pdata)
static int teensy_reboot(pdata_t* pdata) static int teensy_reboot(pdata_t* pdata)
{ {
avrdude_message(MSG_DEBUG, "%s: teensy_reboot()\n", progname); pmsg_debug("teensy_reboot()\n");
// Write a dummy page at address -1 to reboot the Teensy. // Write a dummy page at address -1 to reboot the Teensy.
return teensy_write_page(pdata, 0xFFFFFFFF, NULL, 0, true); return teensy_write_page(pdata, 0xFFFFFFFF, NULL, 0, true);
@ -239,11 +235,11 @@ static int teensy_reboot(pdata_t* pdata)
static void teensy_setup(PROGRAMMER* pgm) static void teensy_setup(PROGRAMMER* pgm)
{ {
avrdude_message(MSG_DEBUG, "%s: teensy_setup()\n", progname); pmsg_debug("teensy_setup()\n");
if ((pgm->cookie = malloc(sizeof(pdata_t))) == NULL) if ((pgm->cookie = malloc(sizeof(pdata_t))) == NULL)
{ {
avrdude_message(MSG_INFO, "%s: ERROR: Failed to allocate memory\n", progname); pmsg_error("unable to allocate memory\n");
exit(1); exit(1);
} }
@ -252,12 +248,12 @@ static void teensy_setup(PROGRAMMER* pgm)
static void teensy_teardown(PROGRAMMER* pgm) static void teensy_teardown(PROGRAMMER* pgm)
{ {
avrdude_message(MSG_DEBUG, "%s: teensy_teardown()\n", progname); pmsg_debug("teensy_teardown()\n");
free(pgm->cookie); free(pgm->cookie);
} }
static int teensy_initialize(const PROGRAMMER *pgm, const AVRPART *p) { static int teensy_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
avrdude_message(MSG_DEBUG, "%s: teensy_initialize()\n", progname); pmsg_debug("teensy_initialize()\n");
pdata_t* pdata = PDATA(pgm); pdata_t* pdata = PDATA(pgm);
@ -271,15 +267,15 @@ static int teensy_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
} }
static void teensy_display(const PROGRAMMER *pgm, const char *prefix) { static void teensy_display(const PROGRAMMER *pgm, const char *prefix) {
avrdude_message(MSG_DEBUG, "%s: teensy_display()\n", progname); pmsg_debug("teensy_display()\n");
} }
static void teensy_powerup(const PROGRAMMER *pgm) { static void teensy_powerup(const PROGRAMMER *pgm) {
avrdude_message(MSG_DEBUG, "%s: teensy_powerup()\n", progname); pmsg_debug("teensy_powerup()\n");
} }
static void teensy_powerdown(const PROGRAMMER *pgm) { static void teensy_powerdown(const PROGRAMMER *pgm) {
avrdude_message(MSG_DEBUG, "%s: teensy_powerdown()\n", progname); pmsg_debug("teensy_powerdown()\n");
pdata_t* pdata = PDATA(pgm); pdata_t* pdata = PDATA(pgm);
@ -297,24 +293,24 @@ static void teensy_powerdown(const PROGRAMMER *pgm) {
} }
static void teensy_enable(PROGRAMMER* pgm, const AVRPART *p) { static void teensy_enable(PROGRAMMER* pgm, const AVRPART *p) {
avrdude_message(MSG_DEBUG, "%s: teensy_enable()\n", progname); pmsg_debug("teensy_enable()\n");
} }
static void teensy_disable(const PROGRAMMER *pgm) { static void teensy_disable(const PROGRAMMER *pgm) {
avrdude_message(MSG_DEBUG, "%s: teensy_disable()\n", progname); pmsg_debug("teensy_disable()\n");
} }
static int teensy_program_enable(const PROGRAMMER *pgm, const AVRPART *p) { static int teensy_program_enable(const PROGRAMMER *pgm, const AVRPART *p) {
avrdude_message(MSG_DEBUG, "%s: teensy_program_enable()\n", progname); pmsg_debug("teensy_program_enable()\n");
return 0; return 0;
} }
static int teensy_read_sig_bytes(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem) { static int teensy_read_sig_bytes(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem) {
avrdude_message(MSG_DEBUG, "%s: teensy_read_sig_bytes()\n", progname); pmsg_debug("teensy_read_sig_bytes()\n");
if (mem->size < 3) if (mem->size < 3)
{ {
avrdude_message(MSG_INFO, "%s: memory size too small for read_sig_bytes\n", progname); pmsg_error("memory size too small for read_sig_bytes\n");
return -1; return -1;
} }
@ -325,7 +321,7 @@ static int teensy_read_sig_bytes(const PROGRAMMER *pgm, const AVRPART *p, const
} }
static int teensy_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) { static int teensy_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) {
avrdude_message(MSG_DEBUG, "%s: teensy_chip_erase()\n", progname); pmsg_debug("teensy_chip_erase()\n");
pdata_t* pdata = PDATA(pgm); pdata_t* pdata = PDATA(pgm);
@ -336,7 +332,7 @@ static int teensy_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) {
} }
static int teensy_open(PROGRAMMER *pgm, const char *port) { static int teensy_open(PROGRAMMER *pgm, const char *port) {
avrdude_message(MSG_DEBUG, "%s: teensy_open(\"%s\")\n", progname, port); pmsg_debug("teensy_open(\"%s\")\n", port);
pdata_t* pdata = PDATA(pgm); pdata_t* pdata = PDATA(pgm);
const char *bus_name = NULL; const char *bus_name = NULL;
@ -364,8 +360,8 @@ static int teensy_open(PROGRAMMER *pgm, const char *port) {
if (port != NULL && dev_name == NULL) if (port != NULL && dev_name == NULL)
{ {
avrdude_message(MSG_INFO, "%s: ERROR: Invalid -P value: '%s'\n", progname, port); pmsg_error("invalid -P value: '%s'\n", port);
avrdude_message(MSG_INFO, "%sUse -P usb:bus:device\n", progbuf); imsg_error("Use -P usb:bus:device\n");
return -1; return -1;
} }
@ -379,8 +375,7 @@ static int teensy_open(PROGRAMMER *pgm, const char *port) {
pid = *(int*)(ldata(usbpid)); pid = *(int*)(ldata(usbpid));
if (lnext(usbpid)) if (lnext(usbpid))
{ {
avrdude_message(MSG_INFO, "%s: WARNING: using PID 0x%04x, ignoring remaining PIDs in list\n", pmsg_error("using PID 0x%04x, ignoring remaining PIDs in list\n", pid);
progname, pid);
} }
} }
@ -400,7 +395,7 @@ static int teensy_open(PROGRAMMER *pgm, const char *port) {
pdata->hid_handle = hid_open_path(device->path); pdata->hid_handle = hid_open_path(device->path);
if (pdata->hid_handle == NULL) if (pdata->hid_handle == NULL)
{ {
avrdude_message(MSG_INFO, "%s: ERROR: Found HID device, but hid_open_path() failed.\n", progname); pmsg_error("found HID device, but hid_open_path() failed\n");
} }
else else
{ {
@ -420,16 +415,15 @@ static int teensy_open(PROGRAMMER *pgm, const char *port) {
{ {
if (pdata->wait_timout < 0) if (pdata->wait_timout < 0)
{ {
avrdude_message(MSG_INFO, "%s: No device found, waiting for device to be plugged in...\n", progname); pmsg_error("no device found, waiting for device to be plugged in ...\n");
} }
else else
{ {
avrdude_message(MSG_INFO, "%s: No device found, waiting %d seconds for device to be plugged in...\n", pmsg_error("no device found, waiting %d seconds for device to be plugged in ...\n",
progname,
pdata->wait_timout); pdata->wait_timout);
} }
avrdude_message(MSG_INFO, "%s: Press CTRL-C to terminate.\n", progname); pmsg_error("press CTRL-C to terminate\n");
show_retry_message = false; show_retry_message = false;
} }
@ -445,8 +439,7 @@ static int teensy_open(PROGRAMMER *pgm, const char *port) {
if (!pdata->hid_handle) if (!pdata->hid_handle)
{ {
avrdude_message(MSG_INFO, "%s: ERROR: Could not find device with Teensy bootloader (%04X:%04X)\n", pmsg_error("cannot find device with Teensy bootloader (%04X:%04X)\n", vid, pid);
progname, vid, pid);
return -1; return -1;
} }
@ -455,7 +448,7 @@ static int teensy_open(PROGRAMMER *pgm, const char *port) {
static void teensy_close(PROGRAMMER* pgm) static void teensy_close(PROGRAMMER* pgm)
{ {
avrdude_message(MSG_DEBUG, "%s: teensy_close()\n", progname); pmsg_debug("teensy_close()\n");
pdata_t* pdata = PDATA(pgm); pdata_t* pdata = PDATA(pgm);
if (pdata->hid_handle != NULL) if (pdata->hid_handle != NULL)
@ -468,8 +461,7 @@ static void teensy_close(PROGRAMMER* pgm)
static int teensy_read_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem, static int teensy_read_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem,
unsigned long addr, unsigned char* value) unsigned long addr, unsigned char* value)
{ {
avrdude_message(MSG_DEBUG, "%s: teensy_read_byte(desc=%s, addr=0x%0X)\n", pmsg_debug("teensy_read_byte(desc=%s, addr=0x%04lX)\n", mem->desc, addr);
progname, mem->desc, addr);
if (strcmp(mem->desc, "lfuse") == 0 || if (strcmp(mem->desc, "lfuse") == 0 ||
strcmp(mem->desc, "hfuse") == 0 || strcmp(mem->desc, "hfuse") == 0 ||
@ -481,7 +473,7 @@ static int teensy_read_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVRME
} }
else else
{ {
avrdude_message(MSG_INFO, "%s: Unsupported memory type: %s\n", progname, mem->desc); pmsg_error("unsupported memory type: %s\n", mem->desc);
return -1; return -1;
} }
} }
@ -489,8 +481,7 @@ static int teensy_read_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVRME
static int teensy_write_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem, static int teensy_write_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem,
unsigned long addr, unsigned char value) unsigned long addr, unsigned char value)
{ {
avrdude_message(MSG_DEBUG, "%s: teensy_write_byte(desc=%s, addr=0x%0X)\n", pmsg_debug("teensy_write_byte(desc=%s, addr=0x%04lX)\n", mem->desc, addr);
progname, mem->desc, addr);
return -1; return -1;
} }
@ -498,8 +489,7 @@ static int teensy_paged_load(const PROGRAMMER *pgm, const AVRPART *p, const AVRM
unsigned int page_size, unsigned int page_size,
unsigned int addr, unsigned int n_bytes) unsigned int addr, unsigned int n_bytes)
{ {
avrdude_message(MSG_DEBUG, "%s: teensy_paged_load(page_size=0x%X, addr=0x%X, n_bytes=0x%X)\n", pmsg_debug("teensy_paged_load(page_size=0x%X, addr=0x%X, n_bytes=0x%X)\n", page_size, addr, n_bytes);
progname, page_size, addr, n_bytes);
return -1; return -1;
} }
@ -507,8 +497,7 @@ static int teensy_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const AVR
unsigned int page_size, unsigned int page_size,
unsigned int addr, unsigned int n_bytes) unsigned int addr, unsigned int n_bytes)
{ {
avrdude_message(MSG_DEBUG, "%s: teensy_paged_write(page_size=0x%X, addr=0x%X, n_bytes=0x%X)\n", pmsg_debug("teensy_paged_write(page_size=0x%X, addr=0x%X, n_bytes=0x%X)\n", page_size, addr, n_bytes);
progname, page_size, addr, n_bytes);
if (strcmp(mem->desc, "flash") == 0) if (strcmp(mem->desc, "flash") == 0)
{ {
@ -516,13 +505,13 @@ static int teensy_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const AVR
if (n_bytes > page_size) if (n_bytes > page_size)
{ {
avrdude_message(MSG_INFO, "%s: Buffer size (%u) exceeds page size (%u)\n", progname, n_bytes, page_size); pmsg_error("buffer size %u exceeds page size %u\n", n_bytes, page_size);
return -1; return -1;
} }
if (addr + n_bytes > pdata->flash_size) if (addr + n_bytes > pdata->flash_size)
{ {
avrdude_message(MSG_INFO, "%s: Program size (%u) exceeds flash size (%u)\n", progname, addr + n_bytes, pdata->flash_size); pmsg_error("program size %u exceeds flash size %u\n", addr + n_bytes, pdata->flash_size);
return -1; return -1;
} }
@ -555,13 +544,13 @@ static int teensy_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const AVR
} }
else else
{ {
avrdude_message(MSG_INFO, "%s: Unsupported memory type: %s\n", progname, mem->desc); pmsg_error("unsupported memory type: %s\n", mem->desc);
return -1; return -1;
} }
} }
static int teensy_parseextparams(const PROGRAMMER *pgm, const LISTID xparams) { static int teensy_parseextparams(const PROGRAMMER *pgm, const LISTID xparams) {
avrdude_message(MSG_DEBUG, "%s: teensy_parseextparams()\n", progname); pmsg_debug("teensy_parseextparams()\n");
pdata_t* pdata = PDATA(pgm); pdata_t* pdata = PDATA(pgm);
for (LNODEID node = lfirst(xparams); node != NULL; node = lnext(node)) for (LNODEID node = lfirst(xparams); node != NULL; node = lnext(node))
@ -580,7 +569,7 @@ static int teensy_parseextparams(const PROGRAMMER *pgm, const LISTID xparams) {
} }
else else
{ {
avrdude_message(MSG_INFO, "%s: Invalid extended parameter '%s'\n", progname, param); pmsg_error("invalid extended parameter '%s'\n", param);
return -1; return -1;
} }
} }
@ -616,7 +605,7 @@ void teensy_initpgm(PROGRAMMER *pgm) {
// Give a proper error if we were not compiled with libhidapi // Give a proper error if we were not compiled with libhidapi
static int teensy_nousb_open(PROGRAMMER *pgm, const char *name) { static int teensy_nousb_open(PROGRAMMER *pgm, const char *name) {
avrdude_message(MSG_INFO, "%s: error: No HID support. Please compile again with libhidapi installed.\n", progname); pmsg_error("no HID support; please compile again with libhidapi installed\n");
return -1; return -1;
} }

View File

@ -195,14 +195,14 @@ static int hexdump_buf(FILE *f, int startaddr, unsigned char *buf, int len) {
char dst2[80]; char dst2[80];
int addr = startaddr; int addr = startaddr;
unsigned char *p = (unsigned char *)buf; unsigned char *p = (unsigned char *) buf;
while (len) { while (len) {
int n = 16; int n = 16;
if (n > len) if (n > len)
n = len; n = len;
hexdump_line(dst1, p, n, 48); hexdump_line(dst1, p, n, 48);
chardump_line(dst2, p, n, 16); chardump_line(dst2, p, n, 16);
fprintf(stdout, "%04x %s |%s|\n", addr, dst1, dst2); fprintf(f, "%04x %s |%s|\n", addr, dst1, dst2);
len -= n; len -= n;
addr += n; addr += n;
p += n; p += n;
@ -806,7 +806,7 @@ static int cmd_pgerase(PROGRAMMER *pgm, AVRPART *p, int argc, char *argv[]) {
// terminal_message(MSG_INFO, "%s: %s page erase 0x%05x\n", progname, mem->desc, addr & ~(mem->page_size-1)); // terminal_message(MSG_INFO, "%s: %s page erase 0x%05x\n", progname, mem->desc, addr & ~(mem->page_size-1));
if(pgm->page_erase_cached(pgm, p, mem, (unsigned int) addr) < 0) { if(pgm->page_erase_cached(pgm, p, mem, (unsigned int) addr) < 0) {
terminal_message(MSG_INFO, "%s (pgerase): %s page at 0x%05x could not be erased\n", terminal_message(MSG_INFO, "%s (pgerase): unable to erase %s page at 0x%05x\n",
progname, mem->desc, addr); progname, mem->desc, addr);
return -1; return -1;
} }
@ -883,7 +883,7 @@ static int cmd_vtarg(PROGRAMMER *pgm, AVRPART *p, int argc, char *argv[]) {
return -1; return -1;
} }
if ((rc = pgm->set_vtarget(pgm, v)) != 0) { if ((rc = pgm->set_vtarget(pgm, v)) != 0) {
terminal_message(MSG_INFO, "%s (vtarg): failed to set V[target] (rc = %d)\n", terminal_message(MSG_INFO, "%s (vtarg): unable to set V[target] (rc = %d)\n",
progname, rc); progname, rc);
return -3; return -3;
} }
@ -915,7 +915,7 @@ static int cmd_fosc(PROGRAMMER *pgm, AVRPART *p, int argc, char *argv[]) {
else if (*endp == 'k' || *endp == 'K') else if (*endp == 'k' || *endp == 'K')
v *= 1e3; v *= 1e3;
if ((rc = pgm->set_fosc(pgm, v)) != 0) { if ((rc = pgm->set_fosc(pgm, v)) != 0) {
terminal_message(MSG_INFO, "%s (fosc): failed to set oscillator frequency (rc = %d)\n", terminal_message(MSG_INFO, "%s (fosc): unable to set oscillator frequency (rc = %d)\n",
progname, rc); progname, rc);
return -3; return -3;
} }
@ -940,7 +940,7 @@ static int cmd_sck(PROGRAMMER *pgm, AVRPART *p, int argc, char *argv[]) {
} }
v *= 1e-6; /* Convert from microseconds to seconds. */ v *= 1e-6; /* Convert from microseconds to seconds. */
if ((rc = pgm->set_sck_period(pgm, v)) != 0) { if ((rc = pgm->set_sck_period(pgm, v)) != 0) {
terminal_message(MSG_INFO, "%s (sck): failed to set SCK period (rc = %d)\n", terminal_message(MSG_INFO, "%s (sck): unable to set SCK period (rc = %d)\n",
progname, rc); progname, rc);
return -3; return -3;
} }
@ -981,7 +981,7 @@ static int cmd_varef(PROGRAMMER *pgm, AVRPART *p, int argc, char *argv[]) {
} }
} }
if ((rc = pgm->set_varef(pgm, chan, v)) != 0) { if ((rc = pgm->set_varef(pgm, chan, v)) != 0) {
terminal_message(MSG_INFO, "%s (varef): failed to set V[aref] (rc = %d)\n", terminal_message(MSG_INFO, "%s (varef): unable to set V[aref] (rc = %d)\n",
progname, rc); progname, rc);
return -3; return -3;
} }
@ -1223,7 +1223,7 @@ char *terminal_get_input(const char *prompt) {
return input; return input;
#else #else
char input[256]; char input[256];
printf("%s", prompt); fprintf(stdout, "%s", prompt);
if (fgets(input, sizeof(input), stdin)) if (fgets(input, sizeof(input), stdin))
{ {
/* FIXME: readline strips the '\n', should this too? */ /* FIXME: readline strips the '\n', should this too? */
@ -1309,7 +1309,7 @@ static void update_progress_tty(int percent, double etime, const char *hdr, int
setvbuf(stderr, (char *) NULL, _IONBF, 0); setvbuf(stderr, (char *) NULL, _IONBF, 0);
if(hdr) { if(hdr) {
avrdude_message(MSG_INFO, "\n"); msg_info("\n");
last = done = 0; last = done = 0;
if(header) if(header)
free(header); free(header);
@ -1330,11 +1330,10 @@ static void update_progress_tty(int percent, double etime, const char *hdr, int
hashes[i/2] = '#'; hashes[i/2] = '#';
hashes[50] = 0; hashes[50] = 0;
avrdude_message(MSG_INFO, "\r%s | %s | %d%% %0.2fs", msg_info("\r%s | %s | %d%% %0.2fs", header, hashes, showperc, etime);
header, hashes, showperc, etime);
if(percent == 100) { if(percent == 100) {
if(finish) if(finish)
avrdude_message(MSG_INFO, "\n\n"); msg_info("\n\n");
done = 1; done = 1;
} }
} }
@ -1351,18 +1350,18 @@ static void update_progress_no_tty(int percent, double etime, const char *hdr, i
percent = percent > 100? 100: percent < 0? 0: percent; percent = percent > 100? 100: percent < 0? 0: percent;
if(hdr) { if(hdr) {
avrdude_message(MSG_INFO, "\n%s | ", hdr); msg_info("\n%s | ", hdr);
last = done = 0; last = done = 0;
} }
if(!done) { if(!done) {
for(int cnt = percent/2; cnt > last/2; cnt--) for(int cnt = percent/2; cnt > last/2; cnt--)
avrdude_message(MSG_INFO, finish >= 0? "#": "-"); msg_info(finish >= 0? "#": "-");
if(percent == 100) { if(percent == 100) {
avrdude_message(MSG_INFO, " | %d%% %0.2fs", etime, finish >= 0? 100: last); msg_info(" | %d%% %0.2fs", finish >= 0? 100: last, etime);
if(finish) if(finish)
avrdude_message(MSG_INFO, "\n\n"); msg_info("\n\n");
done = 1; done = 1;
} }
} }

View File

@ -69,12 +69,11 @@ UPDATE * parse_op(char * s)
upd->op = DEVICE_VERIFY; upd->op = DEVICE_VERIFY;
} }
else { else {
avrdude_message(MSG_INFO, "%s: invalid I/O mode '%c' in update specification\n", pmsg_error("invalid I/O mode '%c' in update specification\n", *p);
progname, *p); msg_error(" allowed values are:\n"
avrdude_message(MSG_INFO, " allowed values are:\n" " r = read device\n"
" r = read device\n" " w = write device\n"
" w = write device\n" " v = verify device\n");
" v = verify device\n");
free(upd->memtype); free(upd->memtype);
free(upd); free(upd);
return NULL; return NULL;
@ -83,7 +82,7 @@ UPDATE * parse_op(char * s)
p++; p++;
if (*p != ':') { if (*p != ':') {
avrdude_message(MSG_INFO, "%s: invalid update specification\n", progname); pmsg_error("invalid update specification\n");
free(upd->memtype); free(upd->memtype);
free(upd); free(upd);
return NULL; return NULL;
@ -128,8 +127,7 @@ UPDATE * parse_op(char * s)
case 'h': upd->format = FMT_HEX; break; case 'h': upd->format = FMT_HEX; break;
case 'o': upd->format = FMT_OCT; break; case 'o': upd->format = FMT_OCT; break;
default: default:
avrdude_message(MSG_INFO, "%s: invalid file format '%s' in update specifier\n", pmsg_error("invalid file format '%s' in update specifier\n", p);
progname, p);
free(upd->memtype); free(upd->memtype);
free(upd); free(upd);
return NULL; return NULL;
@ -195,14 +193,12 @@ int memstats(struct avrpart *p, char *memtype, int size, Filestats *fsp) {
AVRMEM *mem = avr_locate_mem(p, memtype); AVRMEM *mem = avr_locate_mem(p, memtype);
if(!mem) { if(!mem) {
avrdude_message(MSG_INFO, "%s: %s %s undefined\n", pmsg_error("%s %s undefined\n", p->desc, memtype);
progname, p->desc, memtype);
return LIBAVRDUDE_GENERAL_FAILURE; return LIBAVRDUDE_GENERAL_FAILURE;
} }
if(!mem->buf || !mem->tags) { if(!mem->buf || !mem->tags) {
avrdude_message(MSG_INFO, "%s: %s %s is not set\n", pmsg_error("%s %s is not set\n", p->desc, memtype);
progname, p->desc, memtype);
return LIBAVRDUDE_GENERAL_FAILURE; return LIBAVRDUDE_GENERAL_FAILURE;
} }
@ -211,8 +207,7 @@ int memstats(struct avrpart *p, char *memtype, int size, Filestats *fsp) {
pgsize = 1; pgsize = 1;
if(size < 0 || size > mem->size) { if(size < 0 || size > mem->size) {
avrdude_message(MSG_INFO, "%s: memstats() size %d at odds with %s %s size %d\n", pmsg_error("size %d at odds with %s %s size %d\n", size, p->desc, memtype, mem->size);
progname, size, p->desc, memtype, mem->size);
return LIBAVRDUDE_GENERAL_FAILURE; return LIBAVRDUDE_GENERAL_FAILURE;
} }
@ -338,13 +333,14 @@ int update_is_readable(const char *fn) {
static void ioerror(const char *iotype, UPDATE *upd) { static void ioerror(const char *iotype, UPDATE *upd) {
avrdude_message(MSG_INFO, "%s: file %s is not %s", int errnocp = errno;
progname, update_outname(upd->filename), iotype);
if(errno) pmsg_ext_error("file %s is not %s", update_outname(upd->filename), iotype);
avrdude_message(MSG_INFO, ". %s", strerror(errno)); if(errnocp)
msg_ext_error("memstats(): %s", strerror(errnocp));
else if(upd->filename && *upd->filename) else if(upd->filename && *upd->filename)
avrdude_message(MSG_INFO, " (not a regular or character file?)"); msg_ext_error(" (not a regular or character file?)");
avrdude_message(MSG_INFO, "\n"); msg_ext_error("\n");
} }
// Basic checks to reveal serious failure before programming // Basic checks to reveal serious failure before programming
@ -359,7 +355,7 @@ int update_dryrun(struct avrpart *p, UPDATE *upd) {
* but accept when the specific part does not have it (allow unifying i/faces) * but accept when the specific part does not have it (allow unifying i/faces)
*/ */
if(!avr_mem_might_be_known(upd->memtype)) { if(!avr_mem_might_be_known(upd->memtype)) {
avrdude_message(MSG_INFO, "%s: unknown memory type %s\n", progname, upd->memtype); pmsg_error("unknown memory type %s\n", upd->memtype);
ret = LIBAVRDUDE_GENERAL_FAILURE; ret = LIBAVRDUDE_GENERAL_FAILURE;
} else if(p && !avr_locate_mem(p, upd->memtype)) } else if(p && !avr_locate_mem(p, upd->memtype))
ret = LIBAVRDUDE_SOFTFAIL; ret = LIBAVRDUDE_SOFTFAIL;
@ -384,28 +380,26 @@ int update_dryrun(struct avrpart *p, UPDATE *upd) {
if(!known && upd->format == FMT_AUTO) { if(!known && upd->format == FMT_AUTO) {
if(!strcmp(upd->filename, "-")) { if(!strcmp(upd->filename, "-")) {
avrdude_message(MSG_INFO, "%s: can't auto detect file format for stdin/out, " pmsg_error("cannot auto detect file format for stdin/out, "
"specify explicitly\n", progname); "specify explicitly\n");
ret = LIBAVRDUDE_GENERAL_FAILURE; ret = LIBAVRDUDE_GENERAL_FAILURE;
} else if((format_detect = fileio_fmt_autodetect(upd->filename)) < 0) { } else if((format_detect = fileio_fmt_autodetect(upd->filename)) < 0) {
avrdude_message(MSG_INFO, "%s: can't determine file format for %s, specify explicitly\n", pmsg_error("cannot determine file format for %s, specify explicitly\n", upd->filename);
progname, upd->filename);
ret = LIBAVRDUDE_GENERAL_FAILURE; ret = LIBAVRDUDE_GENERAL_FAILURE;
} else { } else {
// Set format now, no need to repeat auto detection later // Set format now, no need to repeat auto detection later
upd->format = format_detect; upd->format = format_detect;
if(quell_progress < 2) if(quell_progress < 2)
avrdude_message(MSG_NOTICE, "%s: %s file %s auto detected as %s\n", pmsg_notice("%s file %s auto detected as %s\n",
progname, upd->op == DEVICE_READ? "output": "input", upd->filename, upd->op == DEVICE_READ? "output": "input", upd->filename,
fileio_fmtstr(upd->format)); fileio_fmtstr(upd->format));
} }
} }
switch(upd->op) { switch(upd->op) {
case DEVICE_READ: case DEVICE_READ:
if(upd->format == FMT_IMM) { if(upd->format == FMT_IMM) {
avrdude_message(MSG_INFO, pmsg_error("invalid file format 'immediate' for output\n");
"%s: invalid file format 'immediate' for output\n", progname);
ret = LIBAVRDUDE_GENERAL_FAILURE; ret = LIBAVRDUDE_GENERAL_FAILURE;
} else { } else {
errno = 0; errno = 0;
@ -424,8 +418,7 @@ int update_dryrun(struct avrpart *p, UPDATE *upd) {
break; break;
default: default:
avrdude_message(MSG_INFO, "%s: invalid update operation (%d) requested\n", pmsg_error("invalid update operation (%d) requested\n", upd->op);
progname, upd->op);
ret = LIBAVRDUDE_GENERAL_FAILURE; ret = LIBAVRDUDE_GENERAL_FAILURE;
} }
@ -443,8 +436,7 @@ int do_op(PROGRAMMER * pgm, struct avrpart * p, UPDATE * upd, enum updateflags f
mem = avr_locate_mem(p, upd->memtype); mem = avr_locate_mem(p, upd->memtype);
if (mem == NULL) { if (mem == NULL) {
avrdude_message(MSG_INFO, "%s: skipping -U %s:... as memory not defined for part %s\n", pmsg_warning("skipping -U %s:... as memory not defined for part %s\n", upd->memtype, p->desc);
progname, upd->memtype, p->desc);
return LIBAVRDUDE_SOFTFAIL; return LIBAVRDUDE_SOFTFAIL;
} }
@ -459,36 +451,28 @@ int do_op(PROGRAMMER * pgm, struct avrpart * p, UPDATE * upd, enum updateflags f
case DEVICE_READ: case DEVICE_READ:
// 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 (upd->format == FMT_IMM) { if (upd->format == FMT_IMM) {
avrdude_message(MSG_INFO, pmsg_error("invalid file format 'immediate' for output\n");
"%s: invalid file format 'immediate' for output\n", progname);
return LIBAVRDUDE_GENERAL_FAILURE; return LIBAVRDUDE_GENERAL_FAILURE;
} }
if (quell_progress < 2) pmsg_info("reading %s%s memory ...\n", mem->desc, alias_mem_desc);
avrdude_message(MSG_INFO, "%s: reading %s%s memory ...\n",
progname, mem->desc, alias_mem_desc);
report_progress(0, 1, "Reading"); report_progress(0, 1, "Reading");
rc = avr_read(pgm, p, upd->memtype, 0); rc = avr_read(pgm, p, upd->memtype, 0);
report_progress(1, 1, NULL); report_progress(1, 1, NULL);
if (rc < 0) { if (rc < 0) {
avrdude_message(MSG_INFO, "%s: failed to read all of %s%s memory, rc=%d\n", pmsg_error("unable to read all of %s%s memory, rc=%d\n", mem->desc, alias_mem_desc, rc);
progname, mem->desc, alias_mem_desc, rc);
return LIBAVRDUDE_GENERAL_FAILURE; return LIBAVRDUDE_GENERAL_FAILURE;
} }
size = rc; size = rc;
if (quell_progress < 2) { if (rc == 0)
if (rc == 0) pmsg_notice("flash is empty, resulting file has no contents\n");
avrdude_message(MSG_INFO, "%s: flash is empty, resulting file has no contents\n", pmsg_info("writing output file %s\n", update_outname(upd->filename));
progname);
avrdude_message(MSG_INFO, "%s: writing output file %s\n",
progname, update_outname(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) {
avrdude_message(MSG_INFO, "%s: write to file %s failed\n", pmsg_error("write to file %s failed\n", update_outname(upd->filename));
progname, update_outname(upd->filename));
return LIBAVRDUDE_GENERAL_FAILURE; return LIBAVRDUDE_GENERAL_FAILURE;
} }
break; break;
@ -498,42 +482,33 @@ int do_op(PROGRAMMER * pgm, struct avrpart * p, UPDATE * upd, enum updateflags f
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) {
avrdude_message(MSG_INFO, "%s: read from file %s failed\n", pmsg_error("read from file %s failed\n", update_inname(upd->filename));
progname, update_inname(upd->filename));
return LIBAVRDUDE_GENERAL_FAILURE; return LIBAVRDUDE_GENERAL_FAILURE;
} }
size = rc; size = rc;
if (quell_progress < 2) pmsg_info("reading input file %s for %s%s\n",
avrdude_message(MSG_INFO, "%s: reading input file %s for %s%s\n", update_inname(upd->filename), mem->desc, alias_mem_desc);
progname, update_inname(upd->filename), mem->desc, alias_mem_desc);
if(memstats(p, upd->memtype, size, &fs) < 0) if(memstats(p, upd->memtype, size, &fs) < 0)
return LIBAVRDUDE_GENERAL_FAILURE; return LIBAVRDUDE_GENERAL_FAILURE;
if(quell_progress < 2) { imsg_info("with %d byte%s in %d section%s within %s\n",
int level = fs.nsections > 1 || fs.firstaddr > 0 || fs.ntrailing? MSG_INFO: MSG_NOTICE; fs.nbytes, update_plural(fs.nbytes),
fs.nsections, update_plural(fs.nsections),
avrdude_message(level, "%*s with %d byte%s in %d section%s within %s\n", update_interval(fs.firstaddr, fs.lastaddr));
(int) strlen(progname)+1, "", if(mem->page_size > 1) {
fs.nbytes, update_plural(fs.nbytes), imsg_info("using %d page%s and %d pad byte%s",
fs.nsections, update_plural(fs.nsections), fs.npages, update_plural(fs.npages),
update_interval(fs.firstaddr, fs.lastaddr)); fs.nfill, update_plural(fs.nfill));
if(mem->page_size > 1) { if(fs.ntrailing)
avrdude_message(level, "%*s using %d page%s and %d pad byte%s", msg_info(", cutting off %d trailing 0xff byte%s",
(int) strlen(progname)+1, "", fs.ntrailing, update_plural(fs.ntrailing));
fs.npages, update_plural(fs.npages), msg_info("\n");
fs.nfill, update_plural(fs.nfill));
if(fs.ntrailing)
avrdude_message(level, ", cutting off %d trailing 0xff byte%s",
fs.ntrailing, update_plural(fs.ntrailing));
avrdude_message(level, "\n");
}
} }
// Write the buffer contents to the selected memory type // Write the buffer contents to the selected memory type
if (quell_progress < 2) pmsg_info("writing %d byte%s %s%s ...\n", fs.nbytes,
avrdude_message(MSG_INFO, "%s: writing %d byte%s %s%s ...\n", update_plural(fs.nbytes), mem->desc, alias_mem_desc);
progname, fs.nbytes, update_plural(fs.nbytes), mem->desc, alias_mem_desc);
if (!(flags & UF_NOWRITE)) { if (!(flags & UF_NOWRITE)) {
report_progress(0, 1, "Writing"); report_progress(0, 1, "Writing");
@ -545,14 +520,12 @@ int do_op(PROGRAMMER * pgm, struct avrpart * p, UPDATE * upd, enum updateflags f
} }
if (rc < 0) { if (rc < 0) {
avrdude_message(MSG_INFO, "%s: failed to write %s%s memory, rc=%d\n", pmsg_error("unable to write %s%s memory, rc=%d\n", mem->desc, alias_mem_desc, rc);
progname, mem->desc, alias_mem_desc, rc);
return LIBAVRDUDE_GENERAL_FAILURE; return LIBAVRDUDE_GENERAL_FAILURE;
} }
if (quell_progress < 2) pmsg_info("%d byte%s of %s%s written\n", fs.nbytes,
avrdude_message(MSG_INFO, "%s: %d byte%s of %s%s written\n", update_plural(fs.nbytes), mem->desc, alias_mem_desc);
progname, fs.nbytes, update_plural(fs.nbytes), mem->desc, alias_mem_desc);
// Fall through for (default) auto verify, ie, unless -V was specified // Fall through for (default) auto verify, ie, unless -V was specified
if (!(flags & UF_VERIFY)) if (!(flags & UF_VERIFY))
@ -564,22 +537,18 @@ int do_op(PROGRAMMER * pgm, struct avrpart * p, UPDATE * upd, enum updateflags f
int userverify = upd->op == DEVICE_VERIFY; // Explicit -U :v by user int userverify = upd->op == DEVICE_VERIFY; // Explicit -U :v by user
if (quell_progress < 2) { pmsg_info("verifying %s%s memory against %s\n", mem->desc,
avrdude_message(MSG_INFO, "%s: verifying %s%s memory against %s\n", alias_mem_desc, update_inname(upd->filename));
progname, mem->desc, alias_mem_desc, update_inname(upd->filename));
if (userverify)
avrdude_message(MSG_NOTICE, "%s: load %s%s data from input file %s\n",
progname, mem->desc, alias_mem_desc, update_inname(upd->filename));
}
// No need to read file when fallen through from DEVICE_WRITE // No need to read file when fallen through from DEVICE_WRITE
if (userverify) { if (userverify) {
pmsg_notice("load %s%s data from input file %s\n", mem->desc,
alias_mem_desc, update_inname(upd->filename));
rc = fileio(FIO_READ_FOR_VERIFY, upd->filename, upd->format, p, upd->memtype, -1); rc = fileio(FIO_READ_FOR_VERIFY, upd->filename, upd->format, p, upd->memtype, -1);
if (rc < 0) { if (rc < 0) {
avrdude_message(MSG_INFO, "%s: read from file %s failed\n", pmsg_error("read from file %s failed\n", update_inname(upd->filename));
progname, update_inname(upd->filename));
return LIBAVRDUDE_GENERAL_FAILURE; return LIBAVRDUDE_GENERAL_FAILURE;
} }
size = rc; size = rc;
@ -595,48 +564,41 @@ int do_op(PROGRAMMER * pgm, struct avrpart * p, UPDATE * upd, enum updateflags f
if (quell_progress < 2) { if (quell_progress < 2) {
if (userverify) if (userverify)
avrdude_message(MSG_NOTICE, "%s: input file %s contains %d byte%s\n", pmsg_notice("input file %s contains %d byte%s\n",
progname, update_inname(upd->filename), fs.nbytes, update_plural(fs.nbytes)); update_inname(upd->filename), fs.nbytes, update_plural(fs.nbytes));
avrdude_message(MSG_NOTICE2, "%s: reading on-chip %s%s data ...\n", pmsg_notice2("reading on-chip %s%s data ...\n", mem->desc, alias_mem_desc);
progname, mem->desc, alias_mem_desc);
} }
report_progress (0,1,"Reading"); report_progress (0,1,"Reading");
rc = avr_read(pgm, p, upd->memtype, v); rc = avr_read(pgm, p, upd->memtype, v);
report_progress (1,1,NULL); report_progress (1,1,NULL);
if (rc < 0) { if (rc < 0) {
avrdude_message(MSG_INFO, "%s: failed to read all of %s%s memory, rc=%d\n", pmsg_error("unable to read all of %s%s memory, rc=%d\n", mem->desc, alias_mem_desc, rc);
progname, mem->desc, alias_mem_desc, rc);
pgm->err_led(pgm, ON); pgm->err_led(pgm, ON);
avr_free_part(v); avr_free_part(v);
return LIBAVRDUDE_GENERAL_FAILURE; return LIBAVRDUDE_GENERAL_FAILURE;
} }
if (quell_progress < 2) if (quell_progress < 2)
avrdude_message(MSG_NOTICE2, "%s: verifying ...\n", progname); pmsg_notice2("verifying ...\n");
rc = avr_verify(p, v, upd->memtype, size); rc = avr_verify(p, v, upd->memtype, size);
if (rc < 0) { if (rc < 0) {
avrdude_message(MSG_INFO, "%s: verification error; content mismatch\n", pmsg_error("verification mismatch\n");
progname);
pgm->err_led(pgm, ON); pgm->err_led(pgm, ON);
avr_free_part(v); avr_free_part(v);
return LIBAVRDUDE_GENERAL_FAILURE; return LIBAVRDUDE_GENERAL_FAILURE;
} }
if (quell_progress < 2) { int verified = fs.nbytes+fs.ntrailing;
int verified = fs.nbytes+fs.ntrailing; pmsg_info("%d byte%s of %s%s verified\n", verified, update_plural(verified), mem->desc, alias_mem_desc);
avrdude_message(MSG_INFO, "%s: %d byte%s of %s%s verified\n",
progname, verified, update_plural(verified), mem->desc, alias_mem_desc);
}
pgm->vfy_led(pgm, OFF); pgm->vfy_led(pgm, OFF);
avr_free_part(v); avr_free_part(v);
break; break;
default: default:
avrdude_message(MSG_INFO, "%s: invalid update operation (%d) requested\n", pmsg_error("invalid update operation (%d) requested\n", upd->op);
progname, upd->op);
return LIBAVRDUDE_GENERAL_FAILURE; return LIBAVRDUDE_GENERAL_FAILURE;
} }

View File

@ -58,11 +58,11 @@ static int updi_physical_open(PROGRAMMER* pgm, int baudrate, unsigned long cflag
pinfo.serialinfo.baud = baudrate; pinfo.serialinfo.baud = baudrate;
pinfo.serialinfo.cflags = cflags; pinfo.serialinfo.cflags = cflags;
avrdude_message(MSG_DEBUG, "%s: Opening serial port...\n", progname); pmsg_debug("opening serial port ...\n");
if (serial_open(pgm->port, pinfo, &pgm->fd)==-1) { if (serial_open(pgm->port, pinfo, &pgm->fd)==-1) {
avrdude_message(MSG_DEBUG, "%s: Serial port open failed!\n", progname); pmsg_debug("serial port open failed!\n");
return -1; return -1;
} }
@ -90,14 +90,14 @@ static int updi_physical_send(const PROGRAMMER *pgm, unsigned char *buf, size_t
size_t i; size_t i;
int rv; int rv;
avrdude_message(MSG_DEBUG, "%s: Sending %lu bytes [", progname, len); pmsg_debug("sending %lu bytes [", len);
for (i=0; i<len; i++) { for (i=0; i<len; i++) {
avrdude_message(MSG_DEBUG, "0x%02x", buf[i]); msg_debug("0x%02x", buf[i]);
if (i<len-1) { if (i<len-1) {
avrdude_message(MSG_DEBUG, ", "); msg_debug(", ");
} }
} }
avrdude_message(MSG_DEBUG, "]\n"); msg_debug("]\n");
rv = serial_send(&pgm->fd, buf, len); rv = serial_send(&pgm->fd, buf, len);
serial_recv(&pgm->fd, buf, len); serial_recv(&pgm->fd, buf, len);
@ -110,20 +110,18 @@ static int updi_physical_recv(const PROGRAMMER *pgm, unsigned char *buf, size_t
rv = serial_recv(&pgm->fd, buf, len); rv = serial_recv(&pgm->fd, buf, len);
if (rv < 0) { if (rv < 0) {
avrdude_message(MSG_DEBUG, pmsg_debug("serialupdi_recv(): programmer is not responding\n");
"%s: serialupdi_recv(): programmer is not responding\n",
progname);
return -1; return -1;
} }
avrdude_message(MSG_DEBUG, "%s: Received %lu bytes [", progname, len); pmsg_debug("received %lu bytes [", len);
for (i=0; i<len; i++) { for (i=0; i<len; i++) {
avrdude_message(MSG_DEBUG, "0x%02x", buf[i]); msg_debug("0x%02x", buf[i]);
if (i<len-1) { if (i<len-1) {
avrdude_message(MSG_DEBUG, ", "); msg_debug(", ");
} }
} }
avrdude_message(MSG_DEBUG, "]\n"); msg_debug("]\n");
return len; return len;
} }
@ -131,7 +129,7 @@ static int updi_physical_recv(const PROGRAMMER *pgm, unsigned char *buf, size_t
static int updi_physical_send_double_break(const PROGRAMMER *pgm) { static int updi_physical_send_double_break(const PROGRAMMER *pgm) {
unsigned char buffer[1]; unsigned char buffer[1];
avrdude_message(MSG_DEBUG, "%s: Sending double break\n", progname); pmsg_debug("sending double break\n");
if (serial_setparams(&pgm->fd, 300, SERIAL_8E1) < 0) { if (serial_setparams(&pgm->fd, 300, SERIAL_8E1) < 0) {
return -1; return -1;
@ -184,7 +182,7 @@ int updi_physical_sib(const PROGRAMMER *pgm, unsigned char *buffer, uint8_t size
send_buffer[1] = UPDI_KEY | UPDI_KEY_SIB | UPDI_SIB_32BYTES; send_buffer[1] = UPDI_KEY | UPDI_KEY_SIB | UPDI_SIB_32BYTES;
if (updi_physical_send(pgm, send_buffer, 2) < 0) { if (updi_physical_send(pgm, send_buffer, 2) < 0) {
avrdude_message(MSG_DEBUG, "%s: SIB request send failed\n", progname); pmsg_debug("SIB request send failed\n");
return -1; return -1;
} }
@ -246,14 +244,14 @@ static int updi_link_check(const PROGRAMMER *pgm) {
uint8_t value; uint8_t value;
result = updi_link_ldcs(pgm, UPDI_CS_STATUSA, &value); result = updi_link_ldcs(pgm, UPDI_CS_STATUSA, &value);
if (result < 0) { if (result < 0) {
avrdude_message(MSG_DEBUG, "%s: Check failed\n", progname); pmsg_debug("check failed\n");
return -1; return -1;
} else { } else {
if (value > 0) { if (value > 0) {
avrdude_message(MSG_DEBUG, "%s: UDPI init OK\n", progname); pmsg_debug("UDPI init OK\n");
return 0; return 0;
} else { } else {
avrdude_message(MSG_DEBUG, "%s: UDPI not OK - reinitialisation required\n", progname); pmsg_debug("UDPI not OK - reinitialisation required\n");
return -1; return -1;
} }
} }
@ -276,22 +274,22 @@ int updi_link_init(const PROGRAMMER *pgm) {
raise PymcuprogError("UPDI initialisation failed") raise PymcuprogError("UPDI initialisation failed")
*/ */
if (updi_link_init_session_parameters(pgm) < 0) { if (updi_link_init_session_parameters(pgm) < 0) {
avrdude_message(MSG_DEBUG, "%s: Session initialisation failed\n", progname); pmsg_debug("session initialisation failed\n");
return -1; return -1;
} }
if (updi_link_check(pgm) < 0) { if (updi_link_check(pgm) < 0) {
avrdude_message(MSG_DEBUG, "%s: Datalink not active, resetting...\n", progname); pmsg_debug("datalink not active, resetting ...\n");
if (updi_physical_send_double_break(pgm) < 0) { if (updi_physical_send_double_break(pgm) < 0) {
avrdude_message(MSG_DEBUG, "%s: Datalink initialisation failed\n", progname); pmsg_debug("datalink initialisation failed\n");
return -1; return -1;
} }
if (updi_link_init_session_parameters(pgm) < 0) { if (updi_link_init_session_parameters(pgm) < 0) {
avrdude_message(MSG_DEBUG, "%s: Session initialisation failed\n", progname); pmsg_debug("session initialisation failed\n");
return -1; return -1;
} }
if (updi_link_check(pgm) < 0) { if (updi_link_check(pgm) < 0) {
avrdude_message(MSG_DEBUG, "%s: Restoring datalink failed\n", progname); pmsg_debug("restoring datalink failed\n");
return -1; return -1;
} }
} }
@ -318,17 +316,17 @@ int updi_link_ldcs(const PROGRAMMER *pgm, uint8_t address, uint8_t *value) {
*/ */
unsigned char buffer[2]; unsigned char buffer[2];
int result; int result;
avrdude_message(MSG_DEBUG, "%s: LDCS from 0x%02X\n", progname, address); pmsg_debug("LDCS from 0x%02X\n", address);
buffer[0]=UPDI_PHY_SYNC; buffer[0]=UPDI_PHY_SYNC;
buffer[1]=UPDI_LDCS | (address & 0x0F); buffer[1]=UPDI_LDCS | (address & 0x0F);
if (updi_physical_send(pgm, buffer, 2) < 0) { if (updi_physical_send(pgm, buffer, 2) < 0) {
avrdude_message(MSG_DEBUG, "%s: LDCS send operation failed\n", progname); pmsg_debug("LDCS send operation failed\n");
return -1; return -1;
} }
result = updi_physical_recv(pgm, buffer, 1); result = updi_physical_recv(pgm, buffer, 1);
if (result != 1) { if (result != 1) {
if (result >= 0) { if (result >= 0) {
avrdude_message(MSG_DEBUG, "%s: Incorrect response size, received %d instead of %d bytes\n", progname, result, 1); pmsg_debug("incorrect response size, received %d instead of %d bytes\n", result, 1);
} }
return -1; return -1;
} }
@ -349,7 +347,7 @@ int updi_link_stcs(const PROGRAMMER *pgm, uint8_t address, uint8_t value) {
self.updi_phy.send([constants.UPDI_PHY_SYNC, constants.UPDI_STCS | (address & 0x0F), value]) self.updi_phy.send([constants.UPDI_PHY_SYNC, constants.UPDI_STCS | (address & 0x0F), value])
*/ */
unsigned char buffer[3]; unsigned char buffer[3];
avrdude_message(MSG_DEBUG, "%s: STCS 0x%02X to address 0x%02X\n", progname, value, address); pmsg_debug("STCS 0x%02X to address 0x%02X\n", value, address);
buffer[0] = UPDI_PHY_SYNC; buffer[0] = UPDI_PHY_SYNC;
buffer[1] = UPDI_STCS | (address & 0x0F); buffer[1] = UPDI_STCS | (address & 0x0F);
buffer[2] = value; buffer[2] = value;
@ -371,11 +369,11 @@ int updi_link_ld_ptr_inc(const PROGRAMMER *pgm, unsigned char *buffer, uint16_t
return self.updi_phy.receive(size) return self.updi_phy.receive(size)
*/ */
unsigned char send_buffer[2]; unsigned char send_buffer[2];
avrdude_message(MSG_DEBUG, "%s: LD8 from ptr++\n", progname); pmsg_debug("LD8 from ptr++\n");
send_buffer[0] = UPDI_PHY_SYNC; send_buffer[0] = UPDI_PHY_SYNC;
send_buffer[1] = UPDI_LD | UPDI_PTR_INC | UPDI_DATA_8; send_buffer[1] = UPDI_LD | UPDI_PTR_INC | UPDI_DATA_8;
if (updi_physical_send(pgm, send_buffer, 2) < 0) { if (updi_physical_send(pgm, send_buffer, 2) < 0) {
avrdude_message(MSG_DEBUG, "%s: LD_PTR_INC send operation failed\n", progname); pmsg_debug("LD_PTR_INC send operation failed\n");
return -1; return -1;
} }
return updi_physical_recv(pgm, buffer, size); return updi_physical_recv(pgm, buffer, size);
@ -396,11 +394,11 @@ int updi_link_ld_ptr_inc16(const PROGRAMMER *pgm, unsigned char *buffer, uint16_
return self.updi_phy.receive(words << 1) return self.updi_phy.receive(words << 1)
*/ */
unsigned char send_buffer[2]; unsigned char send_buffer[2];
avrdude_message(MSG_DEBUG, "%s: LD16 from ptr++\n", progname); pmsg_debug("LD16 from ptr++\n");
send_buffer[0] = UPDI_PHY_SYNC; send_buffer[0] = UPDI_PHY_SYNC;
send_buffer[1] = UPDI_LD | UPDI_PTR_INC | UPDI_DATA_16; send_buffer[1] = UPDI_LD | UPDI_PTR_INC | UPDI_DATA_16;
if (updi_physical_send(pgm, send_buffer, 2) < 0) { if (updi_physical_send(pgm, send_buffer, 2) < 0) {
avrdude_message(MSG_DEBUG, "%s: LD_PTR_INC send operation failed\n", progname); pmsg_debug("LD_PTR_INC send operation failed\n");
return -1; return -1;
} }
return updi_physical_recv(pgm, buffer, words << 2); return updi_physical_recv(pgm, buffer, words << 2);
@ -435,32 +433,32 @@ int updi_link_st_ptr_inc(const PROGRAMMER *pgm, unsigned char *buffer, uint16_t
unsigned char recv_buffer[1]; unsigned char recv_buffer[1];
int response; int response;
int num = 1; int num = 1;
avrdude_message(MSG_DEBUG, "%s: ST8 to *ptr++\n", progname); pmsg_debug("ST8 to *ptr++\n");
send_buffer[0] = UPDI_PHY_SYNC; send_buffer[0] = UPDI_PHY_SYNC;
send_buffer[1] = UPDI_ST | UPDI_PTR_INC | UPDI_DATA_8; send_buffer[1] = UPDI_ST | UPDI_PTR_INC | UPDI_DATA_8;
send_buffer[2] = buffer[0]; send_buffer[2] = buffer[0];
if (updi_physical_send(pgm, send_buffer, 3) < 0) { if (updi_physical_send(pgm, send_buffer, 3) < 0) {
avrdude_message(MSG_DEBUG, "%s: ST_PTR_INC send operation failed\n", progname); pmsg_debug("ST_PTR_INC send operation failed\n");
return -1; return -1;
} }
response = updi_physical_recv(pgm, recv_buffer, 1); response = updi_physical_recv(pgm, recv_buffer, 1);
if (response != 1 || recv_buffer[0] != UPDI_PHY_ACK) { if (response != 1 || recv_buffer[0] != UPDI_PHY_ACK) {
avrdude_message(MSG_DEBUG, "%s: ACK was expected but not received\n", progname); pmsg_debug("ACK was expected but not received\n");
return -1; return -1;
} }
while (num < size) { while (num < size) {
send_buffer[0]=buffer[num]; send_buffer[0]=buffer[num];
if (updi_physical_send(pgm, send_buffer, 1) < 0) { if (updi_physical_send(pgm, send_buffer, 1) < 0) {
avrdude_message(MSG_DEBUG, "%s: ST_PTR_INC data send operation failed\n", progname); pmsg_debug("ST_PTR_INC data send operation failed\n");
return -1; return -1;
} }
response = updi_physical_recv(pgm, recv_buffer, 1); response = updi_physical_recv(pgm, recv_buffer, 1);
if (response != 1 || recv_buffer[0] != UPDI_PHY_ACK) { if (response != 1 || recv_buffer[0] != UPDI_PHY_ACK) {
avrdude_message(MSG_DEBUG, "%s: Data ACK was expected but not received\n", progname); pmsg_debug("data ACK was expected but not received\n");
return -1; return -1;
} }
num++; num++;
@ -498,20 +496,20 @@ int updi_link_st_ptr_inc16(const PROGRAMMER *pgm, unsigned char *buffer, uint16_
unsigned char recv_buffer[1]; unsigned char recv_buffer[1];
int response; int response;
int num = 2; int num = 2;
avrdude_message(MSG_DEBUG, "%s: ST16 to *ptr++\n", progname); pmsg_debug("ST16 to *ptr++\n");
send_buffer[0] = UPDI_PHY_SYNC; send_buffer[0] = UPDI_PHY_SYNC;
send_buffer[1] = UPDI_ST | UPDI_PTR_INC | UPDI_DATA_16; send_buffer[1] = UPDI_ST | UPDI_PTR_INC | UPDI_DATA_16;
send_buffer[2] = buffer[0]; send_buffer[2] = buffer[0];
send_buffer[3] = buffer[1]; send_buffer[3] = buffer[1];
if (updi_physical_send(pgm, send_buffer, 4) < 0) { if (updi_physical_send(pgm, send_buffer, 4) < 0) {
avrdude_message(MSG_DEBUG, "%s: ST_PTR_INC16 send operation failed\n", progname); pmsg_debug("ST_PTR_INC16 send operation failed\n");
return -1; return -1;
} }
response = updi_physical_recv(pgm, recv_buffer, 1); response = updi_physical_recv(pgm, recv_buffer, 1);
if (response != 1 || recv_buffer[0] != UPDI_PHY_ACK) { if (response != 1 || recv_buffer[0] != UPDI_PHY_ACK) {
avrdude_message(MSG_DEBUG, "%s: ACK was expected but not received\n", progname); pmsg_debug("ACK was expected but not received\n");
return -1; return -1;
} }
@ -519,13 +517,13 @@ int updi_link_st_ptr_inc16(const PROGRAMMER *pgm, unsigned char *buffer, uint16_
send_buffer[0]=buffer[num]; send_buffer[0]=buffer[num];
send_buffer[1]=buffer[num+1]; send_buffer[1]=buffer[num+1];
if (updi_physical_send(pgm, send_buffer, 2) < 0) { if (updi_physical_send(pgm, send_buffer, 2) < 0) {
avrdude_message(MSG_DEBUG, "%s: ST_PTR_INC data send operation failed\n", progname); pmsg_debug("ST_PTR_INC data send operation failed\n");
return -1; return -1;
} }
response = updi_physical_recv(pgm, recv_buffer, 1); response = updi_physical_recv(pgm, recv_buffer, 1);
if (response != 1 || recv_buffer[0] != UPDI_PHY_ACK) { if (response != 1 || recv_buffer[0] != UPDI_PHY_ACK) {
avrdude_message(MSG_DEBUG, "%s: Data ACK was expected but not received\n", progname); pmsg_debug("data ACK was expected but not received\n");
return -1; return -1;
} }
num+=2; num+=2;
@ -548,7 +546,7 @@ int updi_link_st_ptr_inc16_RSD(const PROGRAMMER *pgm, unsigned char *buffer, uin
""" """
self.logger.debug("ST16 to *ptr++ with RSD, data length: 0x%03X in blocks of: %d", len(data), blocksize) self.logger.debug("ST16 to *ptr++ with RSD, data length: 0x%03X in blocks of: %d", len(data), blocksize)
#for performance we glob everything together into one USB transfer.... #for performance we glob everything together into one USB transfer ...
repnumber= ((len(data) >> 1) -1) repnumber= ((len(data) >> 1) -1)
data = [*data, *[constants.UPDI_PHY_SYNC, constants.UPDI_STCS | constants.UPDI_CS_CTRLA, 0x06]] data = [*data, *[constants.UPDI_PHY_SYNC, constants.UPDI_STCS | constants.UPDI_CS_CTRLA, 0x06]]
@ -577,14 +575,14 @@ int updi_link_st_ptr_inc16_RSD(const PROGRAMMER *pgm, unsigned char *buffer, uin
self.updi_phy.send(data_slice) self.updi_phy.send(data_slice)
num += len(data_slice) num += len(data_slice)
*/ */
avrdude_message(MSG_DEBUG, "%s: ST16 to *ptr++ with RSD, data length: 0x%03X in blocks of: %d\n", progname, words * 2, blocksize); pmsg_debug("ST16 to *ptr++ with RSD, data length: 0x%03X in blocks of: %d\n", words * 2, blocksize);
unsigned int temp_buffer_size = 3 + 3 + 2 + (words * 2) + 3; unsigned int temp_buffer_size = 3 + 3 + 2 + (words * 2) + 3;
unsigned int num=0; unsigned int num=0;
unsigned char* temp_buffer = malloc(temp_buffer_size); unsigned char* temp_buffer = malloc(temp_buffer_size);
if (temp_buffer == 0) { if (temp_buffer == 0) {
avrdude_message(MSG_DEBUG, "%s: Allocating temporary buffer failed\n", progname); pmsg_debug("allocating temporary buffer failed\n");
return -1; return -1;
} }
@ -609,7 +607,7 @@ int updi_link_st_ptr_inc16_RSD(const PROGRAMMER *pgm, unsigned char *buffer, uin
if (blocksize < 10) { if (blocksize < 10) {
if (updi_physical_send(pgm, temp_buffer, 6) < 0) { if (updi_physical_send(pgm, temp_buffer, 6) < 0) {
avrdude_message(MSG_DEBUG, "%s: Failed to send first package\n", progname); pmsg_debug("unable to send first package\n");
free(temp_buffer); free(temp_buffer);
return -1; return -1;
} }
@ -626,7 +624,7 @@ int updi_link_st_ptr_inc16_RSD(const PROGRAMMER *pgm, unsigned char *buffer, uin
} }
if (updi_physical_send(pgm, temp_buffer + num, next_package_size) < 0) { if (updi_physical_send(pgm, temp_buffer + num, next_package_size) < 0) {
avrdude_message(MSG_DEBUG, "%s: Failed to send package\n", progname); pmsg_debug("unable to send package\n");
free(temp_buffer); free(temp_buffer);
return -1; return -1;
} }
@ -654,9 +652,9 @@ int updi_link_repeat(const PROGRAMMER *pgm, uint16_t repeats) {
repeats & 0xFF]) repeats & 0xFF])
*/ */
unsigned char buffer[3]; unsigned char buffer[3];
avrdude_message(MSG_DEBUG, "%s: Repeat %d\n", progname, repeats); pmsg_debug("repeat %d\n", repeats);
if ((repeats - 1) > UPDI_MAX_REPEAT_SIZE) { if ((repeats - 1) > UPDI_MAX_REPEAT_SIZE) {
avrdude_message(MSG_DEBUG, "%s: Invalid repeat count of %d\n", progname, repeats); pmsg_debug("invalid repeat count of %d\n", repeats);
return -1; return -1;
} }
repeats-=1; repeats-=1;
@ -695,15 +693,15 @@ int updi_link_key(const PROGRAMMER *pgm, unsigned char *buffer, uint8_t size_typ
unsigned char send_buffer[2]; unsigned char send_buffer[2];
unsigned char reversed_key[256]; unsigned char reversed_key[256];
int index; int index;
avrdude_message(MSG_DEBUG, "%s: UPDI writing key\n", progname); pmsg_debug("UPDI writing key\n");
if (size != (8 << size_type)) { if (size != (8 << size_type)) {
avrdude_message(MSG_DEBUG, "%s: Invalid key length\n", progname); pmsg_debug("invalid key length\n");
return -1; return -1;
} }
send_buffer[0] = UPDI_PHY_SYNC; send_buffer[0] = UPDI_PHY_SYNC;
send_buffer[1] = UPDI_KEY | UPDI_KEY_KEY | size_type; send_buffer[1] = UPDI_KEY | UPDI_KEY_KEY | size_type;
if (updi_physical_send(pgm, send_buffer, 2) < 0) { if (updi_physical_send(pgm, send_buffer, 2) < 0) {
avrdude_message(MSG_DEBUG, "%s: UPDI key send message failed\n", progname); pmsg_debug("UPDI key send message failed\n");
return -1; return -1;
} }
/* reverse key contents */ /* reverse key contents */
@ -730,18 +728,18 @@ int updi_link_ld(const PROGRAMMER *pgm, uint32_t address, uint8_t *value) {
*/ */
unsigned char send_buffer[5]; unsigned char send_buffer[5];
unsigned char recv_buffer[1]; unsigned char recv_buffer[1];
avrdude_message(MSG_DEBUG, "%s: LD from 0x%06X\n", progname, address); pmsg_debug("LD from 0x%06X\n", address);
send_buffer[0] = UPDI_PHY_SYNC; send_buffer[0] = UPDI_PHY_SYNC;
send_buffer[1] = UPDI_LDS | UPDI_DATA_8 | (updi_get_datalink_mode(pgm) == UPDI_LINK_MODE_24BIT ? UPDI_ADDRESS_24 : UPDI_ADDRESS_16); send_buffer[1] = UPDI_LDS | UPDI_DATA_8 | (updi_get_datalink_mode(pgm) == UPDI_LINK_MODE_24BIT ? UPDI_ADDRESS_24 : UPDI_ADDRESS_16);
send_buffer[2] = address & 0xFF; send_buffer[2] = address & 0xFF;
send_buffer[3] = (address >> 8) & 0xFF; send_buffer[3] = (address >> 8) & 0xFF;
send_buffer[4] = (address >> 16) & 0xFF; send_buffer[4] = (address >> 16) & 0xFF;
if (updi_physical_send(pgm, send_buffer, updi_get_datalink_mode(pgm) == UPDI_LINK_MODE_24BIT ? 5 : 4) < 0) { if (updi_physical_send(pgm, send_buffer, updi_get_datalink_mode(pgm) == UPDI_LINK_MODE_24BIT ? 5 : 4) < 0) {
avrdude_message(MSG_DEBUG, "%s: LD operation send failed\n", progname); pmsg_debug("LD operation send failed\n");
return -1; return -1;
} }
if (updi_physical_recv(pgm, recv_buffer, 1) < 0) { if (updi_physical_recv(pgm, recv_buffer, 1) < 0) {
avrdude_message(MSG_DEBUG, "%s: LD operation recv failed\n", progname); pmsg_debug("LD operation recv failed\n");
return -1; return -1;
} }
* value = recv_buffer[0]; * value = recv_buffer[0];
@ -765,18 +763,18 @@ int updi_link_ld16(const PROGRAMMER *pgm, uint32_t address, uint16_t *value) {
*/ */
unsigned char send_buffer[5]; unsigned char send_buffer[5];
unsigned char recv_buffer[2]; unsigned char recv_buffer[2];
avrdude_message(MSG_DEBUG, "%s: LD16 from 0x%06X\n", progname, address); pmsg_debug("LD16 from 0x%06X\n", address);
send_buffer[0] = UPDI_PHY_SYNC; send_buffer[0] = UPDI_PHY_SYNC;
send_buffer[1] = UPDI_LDS | UPDI_DATA_16 | (updi_get_datalink_mode(pgm) == UPDI_LINK_MODE_24BIT ? UPDI_ADDRESS_24 : UPDI_ADDRESS_16); send_buffer[1] = UPDI_LDS | UPDI_DATA_16 | (updi_get_datalink_mode(pgm) == UPDI_LINK_MODE_24BIT ? UPDI_ADDRESS_24 : UPDI_ADDRESS_16);
send_buffer[2] = address & 0xFF; send_buffer[2] = address & 0xFF;
send_buffer[3] = (address >> 8) & 0xFF; send_buffer[3] = (address >> 8) & 0xFF;
send_buffer[4] = (address >> 16) & 0xFF; send_buffer[4] = (address >> 16) & 0xFF;
if (updi_physical_send(pgm, send_buffer, updi_get_datalink_mode(pgm) == UPDI_LINK_MODE_24BIT ? 5 : 4) < 0) { if (updi_physical_send(pgm, send_buffer, updi_get_datalink_mode(pgm) == UPDI_LINK_MODE_24BIT ? 5 : 4) < 0) {
avrdude_message(MSG_DEBUG, "%s: LD16 operation send failed\n", progname); pmsg_debug("LD16 operation send failed\n");
return -1; return -1;
} }
if (updi_physical_recv(pgm, recv_buffer, 2) < 0) { if (updi_physical_recv(pgm, recv_buffer, 2) < 0) {
avrdude_message(MSG_DEBUG, "%s: LD16 operation recv failed\n", progname); pmsg_debug("LD16 operation recv failed\n");
return -1; return -1;
} }
* value = (recv_buffer[0] << 8 | recv_buffer[1]); * value = (recv_buffer[0] << 8 | recv_buffer[1]);
@ -804,23 +802,23 @@ static int updi_link_st_data_phase(const PROGRAMMER *pgm, unsigned char *buffer,
*/ */
unsigned char recv_buffer[1]; unsigned char recv_buffer[1];
if (updi_physical_recv(pgm, recv_buffer, 1) < 0) { if (updi_physical_recv(pgm, recv_buffer, 1) < 0) {
avrdude_message(MSG_DEBUG, "%s: UPDI data phase recv failed on first ACK\n", progname); pmsg_debug("UPDI data phase recv failed on first ACK\n");
return -1; return -1;
} }
if (recv_buffer[0] != UPDI_PHY_ACK) { if (recv_buffer[0] != UPDI_PHY_ACK) {
avrdude_message(MSG_DEBUG, "%s: UPDI data phase expected first ACK\n", progname); pmsg_debug("UPDI data phase expected first ACK\n");
return -1; return -1;
} }
if (updi_physical_send(pgm, buffer, size) < 0) { if (updi_physical_send(pgm, buffer, size) < 0) {
avrdude_message(MSG_DEBUG, "%s: UPDI data phase send failed\n", progname); pmsg_debug("UPDI data phase send failed\n");
return -1; return -1;
} }
if (updi_physical_recv(pgm, recv_buffer, 1) < 0) { if (updi_physical_recv(pgm, recv_buffer, 1) < 0) {
avrdude_message(MSG_DEBUG, "%s: UPDI data phase recv failed on second ACK\n", progname); pmsg_debug("UPDI data phase recv failed on second ACK\n");
return -1; return -1;
} }
if (recv_buffer[0] != UPDI_PHY_ACK) { if (recv_buffer[0] != UPDI_PHY_ACK) {
avrdude_message(MSG_DEBUG, "%s: UPDI data phase expected second ACK\n", progname); pmsg_debug("UPDI data phase expected second ACK\n");
return -1; return -1;
} }
return 0; return 0;
@ -842,14 +840,14 @@ int updi_link_st(const PROGRAMMER *pgm, uint32_t address, uint8_t value) {
return self._st_data_phase([value & 0xFF]) return self._st_data_phase([value & 0xFF])
*/ */
unsigned char send_buffer[5]; unsigned char send_buffer[5];
avrdude_message(MSG_DEBUG, "%s: ST to 0x%06X\n", progname, address); pmsg_debug("ST to 0x%06X\n", address);
send_buffer[0] = UPDI_PHY_SYNC; send_buffer[0] = UPDI_PHY_SYNC;
send_buffer[1] = UPDI_STS | UPDI_DATA_8 | (updi_get_datalink_mode(pgm) == UPDI_LINK_MODE_24BIT ? UPDI_ADDRESS_24 : UPDI_ADDRESS_16); send_buffer[1] = UPDI_STS | UPDI_DATA_8 | (updi_get_datalink_mode(pgm) == UPDI_LINK_MODE_24BIT ? UPDI_ADDRESS_24 : UPDI_ADDRESS_16);
send_buffer[2] = address & 0xFF; send_buffer[2] = address & 0xFF;
send_buffer[3] = (address >> 8) & 0xFF; send_buffer[3] = (address >> 8) & 0xFF;
send_buffer[4] = (address >> 16) & 0xFF; send_buffer[4] = (address >> 16) & 0xFF;
if (updi_physical_send(pgm, send_buffer, updi_get_datalink_mode(pgm) == UPDI_LINK_MODE_24BIT ? 5 : 4) < 0) { if (updi_physical_send(pgm, send_buffer, updi_get_datalink_mode(pgm) == UPDI_LINK_MODE_24BIT ? 5 : 4) < 0) {
avrdude_message(MSG_DEBUG, "%s: ST operation send failed\n", progname); pmsg_debug("ST operation send failed\n");
return -1; return -1;
} }
send_buffer[0] = value; send_buffer[0] = value;
@ -872,14 +870,14 @@ int updi_link_st16(const PROGRAMMER *pgm, uint32_t address, uint16_t value) {
return self._st_data_phase([value & 0xFF, (value >> 8) & 0xFF]) return self._st_data_phase([value & 0xFF, (value >> 8) & 0xFF])
*/ */
unsigned char send_buffer[5]; unsigned char send_buffer[5];
avrdude_message(MSG_DEBUG, "%s: ST16 to 0x%06X\n", progname, address); pmsg_debug("ST16 to 0x%06X\n", address);
send_buffer[0] = UPDI_PHY_SYNC; send_buffer[0] = UPDI_PHY_SYNC;
send_buffer[1] = UPDI_STS | UPDI_DATA_16 | (updi_get_datalink_mode(pgm) == UPDI_LINK_MODE_24BIT ? UPDI_ADDRESS_24 : UPDI_ADDRESS_16); send_buffer[1] = UPDI_STS | UPDI_DATA_16 | (updi_get_datalink_mode(pgm) == UPDI_LINK_MODE_24BIT ? UPDI_ADDRESS_24 : UPDI_ADDRESS_16);
send_buffer[2] = address & 0xFF; send_buffer[2] = address & 0xFF;
send_buffer[3] = (address >> 8) & 0xFF; send_buffer[3] = (address >> 8) & 0xFF;
send_buffer[4] = (address >> 16) & 0xFF; send_buffer[4] = (address >> 16) & 0xFF;
if (updi_physical_send(pgm, send_buffer, updi_get_datalink_mode(pgm) == UPDI_LINK_MODE_24BIT ? 5 : 4) < 0) { if (updi_physical_send(pgm, send_buffer, updi_get_datalink_mode(pgm) == UPDI_LINK_MODE_24BIT ? 5 : 4) < 0) {
avrdude_message(MSG_DEBUG, "%s: ST16 operation send failed\n", progname); pmsg_debug("ST16 operation send failed\n");
return -1; return -1;
} }
send_buffer[0] = value & 0xFF; send_buffer[0] = value & 0xFF;
@ -905,22 +903,22 @@ int updi_link_st_ptr(const PROGRAMMER *pgm, uint32_t address) {
*/ */
unsigned char send_buffer[5]; unsigned char send_buffer[5];
unsigned char recv_buffer[1]; unsigned char recv_buffer[1];
avrdude_message(MSG_DEBUG, "%s: ST_PTR to 0x%06X\n", progname, address); pmsg_debug("ST_PTR to 0x%06X\n", address);
send_buffer[0] = UPDI_PHY_SYNC; send_buffer[0] = UPDI_PHY_SYNC;
send_buffer[1] = UPDI_STS | UPDI_ST | UPDI_PTR_ADDRESS | (updi_get_datalink_mode(pgm) == UPDI_LINK_MODE_24BIT ? UPDI_DATA_24 : UPDI_DATA_16); send_buffer[1] = UPDI_STS | UPDI_ST | UPDI_PTR_ADDRESS | (updi_get_datalink_mode(pgm) == UPDI_LINK_MODE_24BIT ? UPDI_DATA_24 : UPDI_DATA_16);
send_buffer[2] = address & 0xFF; send_buffer[2] = address & 0xFF;
send_buffer[3] = (address >> 8) & 0xFF; send_buffer[3] = (address >> 8) & 0xFF;
send_buffer[4] = (address >> 16) & 0xFF; send_buffer[4] = (address >> 16) & 0xFF;
if (updi_physical_send(pgm, send_buffer, updi_get_datalink_mode(pgm) == UPDI_LINK_MODE_24BIT ? 5 : 4) < 0) { if (updi_physical_send(pgm, send_buffer, updi_get_datalink_mode(pgm) == UPDI_LINK_MODE_24BIT ? 5 : 4) < 0) {
avrdude_message(MSG_DEBUG, "%s: ST_PTR operation send failed\n", progname); pmsg_debug("ST_PTR operation send failed\n");
return -1; return -1;
} }
if (updi_physical_recv(pgm, recv_buffer, 1) < 0) { if (updi_physical_recv(pgm, recv_buffer, 1) < 0) {
avrdude_message(MSG_DEBUG, "%s: UPDI ST_PTR recv failed on ACK\n", progname); pmsg_debug("UPDI ST_PTR recv failed on ACK\n");
return -1; return -1;
} }
if (recv_buffer[0] != UPDI_PHY_ACK) { if (recv_buffer[0] != UPDI_PHY_ACK) {
avrdude_message(MSG_DEBUG, "%s: UPDI ST_PTR expected ACK\n", progname); pmsg_debug("UPDI ST_PTR expected ACK\n");
return -1; return -1;
} }
return 0; return 0;

View File

@ -71,17 +71,17 @@ static int nvm_chip_erase_V0(const PROGRAMMER *pgm, const AVRPART *p) {
return True return True
*/ */
avrdude_message(MSG_DEBUG, "%s: Chip erase using NVM CTRL\n", progname); pmsg_debug("Chip erase using NVM CTRL\n");
if (updi_nvm_wait_ready(pgm, p) < 0) { if (updi_nvm_wait_ready(pgm, p) < 0) {
avrdude_message(MSG_INFO, "%s: Wait for ready chip failed\n", progname); pmsg_error("updi_nvm_wait_ready() failed\n");
return -1; return -1;
} }
if (updi_nvm_command(pgm, p, UPDI_V0_NVMCTRL_CTRLA_CHIP_ERASE) < 0) { if (updi_nvm_command(pgm, p, UPDI_V0_NVMCTRL_CTRLA_CHIP_ERASE) < 0) {
avrdude_message(MSG_INFO, "%s: Chip erase command failed\n", progname); pmsg_error("UPDI chip erase command failed\n");
return -1; return -1;
} }
if (updi_nvm_wait_ready(pgm, p) < 0) { if (updi_nvm_wait_ready(pgm, p) < 0) {
avrdude_message(MSG_INFO, "%s: Wait for ready chip failed\n", progname); pmsg_error("updi_nvm_wait_ready() failed\n");
return -1; return -1;
} }
return 0; return 0;
@ -113,22 +113,22 @@ static int nvm_erase_flash_page_V0(const PROGRAMMER *pgm, const AVRPART *p, uint
raise IOError("Timeout waiting for NVM controller to be ready after flash page erase") raise IOError("Timeout waiting for NVM controller to be ready after flash page erase")
*/ */
unsigned char data[1]; unsigned char data[1];
avrdude_message(MSG_DEBUG, "%s: Erase flash page at address 0x%06X\n", progname, address); pmsg_debug("erase flash page at address 0x%06X\n", address);
if (updi_nvm_wait_ready(pgm, p) < 0) { if (updi_nvm_wait_ready(pgm, p) < 0) {
avrdude_message(MSG_INFO, "%s: Wait for ready chip failed\n", progname); pmsg_error("updi_nvm_wait_ready() failed\n");
return -1; return -1;
} }
data[0] = 0xFF; data[0] = 0xFF;
if (updi_write_data(pgm, address, data, 1) < 0) { if (updi_write_data(pgm, address, data, 1) < 0) {
avrdude_message(MSG_INFO, "%s: Dummy write operation failed\n", progname); pmsg_error("dummy write operation failed\n");
return -1; return -1;
} }
if (updi_nvm_command(pgm, p, UPDI_V0_NVMCTRL_CTRLA_ERASE_PAGE) < 0) { if (updi_nvm_command(pgm, p, UPDI_V0_NVMCTRL_CTRLA_ERASE_PAGE) < 0) {
avrdude_message(MSG_INFO, "%s: Flash page erase command failed\n", progname); pmsg_error("UPDI flash page erase command failed\n");
return -1; return -1;
} }
if (updi_nvm_wait_ready(pgm, p) < 0) { if (updi_nvm_wait_ready(pgm, p) < 0) {
avrdude_message(MSG_INFO, "%s: Wait for ready chip failed\n", progname); pmsg_error("updi_nvm_wait_ready() failed\n");
return -1; return -1;
} }
return 0; return 0;
@ -153,17 +153,17 @@ static int nvm_erase_eeprom_V0(const PROGRAMMER *pgm, const AVRPART *p) {
if not self.wait_nvm_ready(): if not self.wait_nvm_ready():
raise IOError("Timeout waiting for NVM controller to be ready after EEPROM erase") raise IOError("Timeout waiting for NVM controller to be ready after EEPROM erase")
*/ */
avrdude_message(MSG_DEBUG, "%s: Erase EEPROM\n", progname); pmsg_debug("erase EEPROM\n");
if (updi_nvm_wait_ready(pgm, p) < 0) { if (updi_nvm_wait_ready(pgm, p) < 0) {
avrdude_message(MSG_INFO, "%s: Wait for ready chip failed\n", progname); pmsg_error("updi_nvm_wait_ready() failed\n");
return -1; return -1;
} }
if (updi_nvm_command(pgm, p, UPDI_V0_NVMCTRL_CTRLA_ERASE_EEPROM) < 0) { if (updi_nvm_command(pgm, p, UPDI_V0_NVMCTRL_CTRLA_ERASE_EEPROM) < 0) {
avrdude_message(MSG_INFO, "%s: EEPROM erase command failed\n", progname); pmsg_error("UPDI EEPROM erase command failed\n");
return -1; return -1;
} }
if (updi_nvm_wait_ready(pgm, p) < 0) { if (updi_nvm_wait_ready(pgm, p) < 0) {
avrdude_message(MSG_INFO, "%s: Wait for ready chip failed\n", progname); pmsg_error("updi_nvm_wait_ready() failed\n");
return -1; return -1;
} }
return 0; return 0;
@ -198,25 +198,25 @@ static int nvm_erase_user_row_V0(const PROGRAMMER *pgm, const AVRPART *p, uint32
*/ */
uint16_t offset; uint16_t offset;
unsigned char data[1]; unsigned char data[1];
avrdude_message(MSG_DEBUG, "%s: Erase user row\n", progname); pmsg_debug("erase user row\n");
if (updi_nvm_wait_ready(pgm, p) < 0) { if (updi_nvm_wait_ready(pgm, p) < 0) {
avrdude_message(MSG_INFO, "%s: Wait for ready chip failed\n", progname); pmsg_error("updi_nvm_wait_ready() failed\n");
return -1; return -1;
} }
data[0]=0xFF; data[0]=0xFF;
for (offset = 0; offset<size; offset++) for (offset = 0; offset<size; offset++)
{ {
if (updi_write_data(pgm, address+offset, data, 1) < 0) { if (updi_write_data(pgm, address+offset, data, 1) < 0) {
avrdude_message(MSG_INFO, "%s: Write data operation failed at offset 0x%04x\n", progname, offset); pmsg_error("write data operation failed at offset 0x%04x\n", offset);
return -1; return -1;
} }
} }
if (updi_nvm_command(pgm, p, UPDI_V0_NVMCTRL_CTRLA_ERASE_PAGE) < 0) { if (updi_nvm_command(pgm, p, UPDI_V0_NVMCTRL_CTRLA_ERASE_PAGE) < 0) {
avrdude_message(MSG_INFO, "%s: Erase page operation failed\n", progname); pmsg_error("erase page operation failed\n");
return -1; return -1;
} }
if (updi_nvm_wait_ready(pgm, p) < 0) { if (updi_nvm_wait_ready(pgm, p) < 0) {
avrdude_message(MSG_INFO, "%s: Wait for ready chip failed\n", progname); pmsg_error("updi_nvm_wait_ready() failed\n");
return -1; return -1;
} }
return 0; return 0;
@ -303,30 +303,30 @@ static int nvm_write_fuse_V0(const PROGRAMMER *pgm, const AVRPART *p, uint32_t a
raise PymcuprogError("Timeout waiting for NVM controller to be ready after fuse write") raise PymcuprogError("Timeout waiting for NVM controller to be ready after fuse write")
*/ */
if (updi_nvm_wait_ready(pgm, p) < 0) { if (updi_nvm_wait_ready(pgm, p) < 0) {
avrdude_message(MSG_INFO, "%s: Wait for ready chip failed\n", progname); pmsg_error("updi_nvm_wait_ready() failed\n");
return -1; return -1;
} }
avrdude_message(MSG_DEBUG, "%s: Load NVM address\n", progname); pmsg_debug("load NVM address\n");
if (updi_write_byte(pgm, p->nvm_base + UPDI_NVMCTRL_ADDRL, address & 0xFF) < 0) { if (updi_write_byte(pgm, p->nvm_base + UPDI_NVMCTRL_ADDRL, address & 0xFF) < 0) {
avrdude_message(MSG_INFO, "%s: Write ADDRL operation failed\n", progname); pmsg_error("UPDI write ADDRL operation failed\n");
return -1; return -1;
} }
if (updi_write_byte(pgm, p->nvm_base + UPDI_NVMCTRL_ADDRH, (address >> 8) & 0xFF) < 0) { if (updi_write_byte(pgm, p->nvm_base + UPDI_NVMCTRL_ADDRH, (address >> 8) & 0xFF) < 0) {
avrdude_message(MSG_INFO, "%s: Write ADDRH operation failed\n", progname); pmsg_error("write ADDRH operation failed\n");
return -1; return -1;
} }
avrdude_message(MSG_DEBUG, "%s: Load fuse data\n", progname); pmsg_debug("load fuse data\n");
if (updi_write_byte(pgm, p->nvm_base + UPDI_NVMCTRL_DATAL, value & 0xFF) < 0) { if (updi_write_byte(pgm, p->nvm_base + UPDI_NVMCTRL_DATAL, value & 0xFF) < 0) {
avrdude_message(MSG_INFO, "%s: Write DATAL operation failed\n", progname); pmsg_error("write DATAL operation failed\n");
return -1; return -1;
} }
avrdude_message(MSG_DEBUG, "%s: Execute fuse write\n", progname); pmsg_debug("execute fuse write\n");
if (updi_nvm_command(pgm, p, UPDI_V0_NVMCTRL_CTRLA_WRITE_FUSE) < 0) { if (updi_nvm_command(pgm, p, UPDI_V0_NVMCTRL_CTRLA_WRITE_FUSE) < 0) {
avrdude_message(MSG_INFO, "%s: Write fuse operation failed\n", progname); pmsg_error("write fuse operation failed\n");
return -1; return -1;
} }
if (updi_nvm_wait_ready(pgm, p) < 0) { if (updi_nvm_wait_ready(pgm, p) < 0) {
avrdude_message(MSG_INFO, "%s: Wait for ready chip failed\n", progname); pmsg_error("updi_nvm_wait_ready() failed\n");
return -1; return -1;
} }
return 0; return 0;
@ -377,39 +377,39 @@ static int nvm_write_V0(const PROGRAMMER *pgm, const AVRPART *p, uint32_t addres
raise PymcuprogError("Timeout waiting for NVM controller to be ready after page write") raise PymcuprogError("Timeout waiting for NVM controller to be ready after page write")
*/ */
if (updi_nvm_wait_ready(pgm, p) < 0) { if (updi_nvm_wait_ready(pgm, p) < 0) {
avrdude_message(MSG_INFO, "%s: Wait for ready chip failed\n", progname); pmsg_error("updi_nvm_wait_ready() failed\n");
return -1; return -1;
} }
avrdude_message(MSG_DEBUG, "%s: Clear page buffer\n", progname); pmsg_debug("clear page buffer\n");
if (updi_nvm_command(pgm, p, UPDI_V0_NVMCTRL_CTRLA_PAGE_BUFFER_CLR) < 0) { if (updi_nvm_command(pgm, p, UPDI_V0_NVMCTRL_CTRLA_PAGE_BUFFER_CLR) < 0) {
avrdude_message(MSG_INFO, "%s: Clear page operation failed\n", progname); pmsg_error("clear page operation failed\n");
return -1; return -1;
} }
if (updi_nvm_wait_ready(pgm, p) < 0) { if (updi_nvm_wait_ready(pgm, p) < 0) {
avrdude_message(MSG_INFO, "%s: Wait for ready chip failed\n", progname); pmsg_error("updi_nvm_wait_ready() failed\n");
return -1; return -1;
} }
if (mode == USE_WORD_ACCESS) { if (mode == USE_WORD_ACCESS) {
if (updi_write_data_words(pgm, address, buffer, size) < 0) { if (updi_write_data_words(pgm, address, buffer, size) < 0) {
avrdude_message(MSG_INFO, "%s: Write data words operation failed\n", progname); pmsg_error("write data words operation failed\n");
return -1; return -1;
} }
} else { } else {
if (updi_write_data(pgm, address, buffer, size) < 0) { if (updi_write_data(pgm, address, buffer, size) < 0) {
avrdude_message(MSG_INFO, "%s: Write data operation failed\n", progname); pmsg_error("write data operation failed\n");
return -1; return -1;
} }
} }
avrdude_message(MSG_DEBUG, "%s: Committing data\n", progname); pmsg_debug("committing data\n");
if (nvm_command == USE_DEFAULT_COMMAND) { if (nvm_command == USE_DEFAULT_COMMAND) {
nvm_command = UPDI_V0_NVMCTRL_CTRLA_WRITE_PAGE; nvm_command = UPDI_V0_NVMCTRL_CTRLA_WRITE_PAGE;
} }
if (updi_nvm_command(pgm, p, nvm_command) < 0) { if (updi_nvm_command(pgm, p, nvm_command) < 0) {
avrdude_message(MSG_INFO, "%s: Commit data command failed\n", progname); pmsg_error("commit data command failed\n");
return -1; return -1;
} }
if (updi_nvm_wait_ready(pgm, p) < 0) { if (updi_nvm_wait_ready(pgm, p) < 0) {
avrdude_message(MSG_INFO, "%s: Wait for ready chip failed\n", progname); pmsg_error("updi_nvm_wait_ready() failed\n");
return -1; return -1;
} }
return 0; return 0;
@ -438,17 +438,17 @@ static int nvm_chip_erase_V2(const PROGRAMMER *pgm, const AVRPART *p) {
return True return True
*/ */
avrdude_message(MSG_DEBUG, "%s: Chip erase using NVM CTRL\n", progname); pmsg_debug("chip erase using NVM CTRL\n");
if (updi_nvm_wait_ready(pgm, p) < 0) { if (updi_nvm_wait_ready(pgm, p) < 0) {
avrdude_message(MSG_INFO, "%s: Wait for ready chip failed\n", progname); pmsg_error("updi_nvm_wait_ready() failed\n");
return -1; return -1;
} }
if (updi_nvm_command(pgm, p, UPDI_V2_NVMCTRL_CTRLA_CHIP_ERASE) < 0) { if (updi_nvm_command(pgm, p, UPDI_V2_NVMCTRL_CTRLA_CHIP_ERASE) < 0) {
avrdude_message(MSG_INFO, "%s: Chip erase command failed\n", progname); pmsg_error("chip erase command failed\n");
return -1; return -1;
} }
if (updi_nvm_wait_ready(pgm, p) < 0) { if (updi_nvm_wait_ready(pgm, p) < 0) {
avrdude_message(MSG_INFO, "%s: Wait for ready chip failed\n", progname); pmsg_error("updi_nvm_wait_ready() failed\n");
return -1; return -1;
} }
return 0; return 0;
@ -484,22 +484,22 @@ static int nvm_erase_flash_page_V2(const PROGRAMMER *pgm, const AVRPART *p, uint
self.execute_nvm_command(constants.UPDI_V2_NVMCTRL_CTRLA_NOCMD) self.execute_nvm_command(constants.UPDI_V2_NVMCTRL_CTRLA_NOCMD)
*/ */
unsigned char data[1]; unsigned char data[1];
avrdude_message(MSG_DEBUG, "%s: Erase flash page at address 0x%06X\n", progname, address); pmsg_debug("erase flash page at address 0x%06X\n", address);
if (updi_nvm_wait_ready(pgm, p) < 0) { if (updi_nvm_wait_ready(pgm, p) < 0) {
avrdude_message(MSG_INFO, "%s: Wait for ready chip failed\n", progname); pmsg_error("updi_nvm_wait_ready() failed\n");
return -1; return -1;
} }
data[0] = 0xFF; data[0] = 0xFF;
if (updi_write_data(pgm, address, data, 1) < 0) { if (updi_write_data(pgm, address, data, 1) < 0) {
avrdude_message(MSG_INFO, "%s: Dummy write operation failed\n", progname); pmsg_error("dummy write operation failed\n");
return -1; return -1;
} }
if (updi_nvm_command(pgm, p, UPDI_V2_NVMCTRL_CTRLA_FLASH_PAGE_ERASE) < 0) { if (updi_nvm_command(pgm, p, UPDI_V2_NVMCTRL_CTRLA_FLASH_PAGE_ERASE) < 0) {
avrdude_message(MSG_INFO, "%s: Flash page erase command failed\n", progname); pmsg_error("flash page erase command failed\n");
return -1; return -1;
} }
if (updi_nvm_wait_ready(pgm, p) < 0) { if (updi_nvm_wait_ready(pgm, p) < 0) {
avrdude_message(MSG_INFO, "%s: Wait for ready chip failed\n", progname); pmsg_error("updi_nvm_wait_ready() failed\n");
return -1; return -1;
} }
return 0; return 0;
@ -528,22 +528,22 @@ static int nvm_erase_eeprom_V2(const PROGRAMMER *pgm, const AVRPART *p) {
self.logger.debug("Clear NVM command") self.logger.debug("Clear NVM command")
self.execute_nvm_command(constants.UPDI_V2_NVMCTRL_CTRLA_NOCMD) self.execute_nvm_command(constants.UPDI_V2_NVMCTRL_CTRLA_NOCMD)
*/ */
avrdude_message(MSG_DEBUG, "%s: Erase EEPROM\n", progname); pmsg_debug("erase EEPROM\n");
if (updi_nvm_wait_ready(pgm, p) < 0) { if (updi_nvm_wait_ready(pgm, p) < 0) {
avrdude_message(MSG_INFO, "%s: Wait for ready chip failed\n", progname); pmsg_error("updi_nvm_wait_ready() failed\n");
return -1; return -1;
} }
if (updi_nvm_command(pgm, p, UPDI_V2_NVMCTRL_CTRLA_EEPROM_ERASE) < 0) { if (updi_nvm_command(pgm, p, UPDI_V2_NVMCTRL_CTRLA_EEPROM_ERASE) < 0) {
avrdude_message(MSG_INFO, "%s: EEPROM erase command failed\n", progname); pmsg_error("EEPROM erase command failed\n");
return -1; return -1;
} }
if (updi_nvm_wait_ready(pgm, p) < 0) { if (updi_nvm_wait_ready(pgm, p) < 0) {
avrdude_message(MSG_INFO, "%s: Wait for ready chip failed\n", progname); pmsg_error("updi_nvm_wait_ready() failed\n");
return -1; return -1;
} }
avrdude_message(MSG_DEBUG, "%s: Clear NVM command\n", progname); pmsg_debug("clear NVM command\n");
if (updi_nvm_command(pgm, p, UPDI_V2_NVMCTRL_CTRLA_NOCMD) < 0) { if (updi_nvm_command(pgm, p, UPDI_V2_NVMCTRL_CTRLA_NOCMD) < 0) {
avrdude_message(MSG_INFO, "%s: Sending empty command failed\n", progname); pmsg_error("sending empty command failed\n");
return -1; return -1;
} }
return 0; return 0;
@ -629,25 +629,25 @@ static int nvm_write_eeprom_V2(const PROGRAMMER *pgm, const AVRPART *p, uint32_t
self.execute_nvm_command(constants.UPDI_V2_NVMCTRL_CTRLA_NOCMD) self.execute_nvm_command(constants.UPDI_V2_NVMCTRL_CTRLA_NOCMD)
*/ */
if (updi_nvm_wait_ready(pgm, p) < 0) { if (updi_nvm_wait_ready(pgm, p) < 0) {
avrdude_message(MSG_INFO, "%s: Wait for ready chip failed\n", progname); pmsg_error("updi_nvm_wait_ready() failed\n");
return -1; return -1;
} }
avrdude_message(MSG_DEBUG, "%s: NVM EEPROM erase/write command\n", progname); pmsg_debug("NVM EEPROM erase/write command\n");
if (updi_nvm_command(pgm, p, UPDI_V2_NVMCTRL_CTRLA_EEPROM_ERASE_WRITE) < 0) { if (updi_nvm_command(pgm, p, UPDI_V2_NVMCTRL_CTRLA_EEPROM_ERASE_WRITE) < 0) {
avrdude_message(MSG_INFO, "%s: EEPROM erase command failed\n", progname); pmsg_error("EEPROM erase command failed\n");
return -1; return -1;
} }
if (updi_write_data(pgm, address, buffer, size) < 0) { if (updi_write_data(pgm, address, buffer, size) < 0) {
avrdude_message(MSG_INFO, "%s: Write data operation failed\n", progname); pmsg_error("write data operation failed\n");
return -1; return -1;
} }
if (updi_nvm_wait_ready(pgm, p) < 0) { if (updi_nvm_wait_ready(pgm, p) < 0) {
avrdude_message(MSG_INFO, "%s: Wait for ready chip failed\n", progname); pmsg_error("updi_nvm_wait_ready() failed\n");
return -1; return -1;
} }
avrdude_message(MSG_DEBUG, "%s: Clear NVM command\n", progname); pmsg_debug("clear NVM command\n");
if (updi_nvm_command(pgm, p, UPDI_V2_NVMCTRL_CTRLA_NOCMD) < 0) { if (updi_nvm_command(pgm, p, UPDI_V2_NVMCTRL_CTRLA_NOCMD) < 0) {
avrdude_message(MSG_INFO, "%s: Clear NVM command failed\n", progname); pmsg_error("clear NVM command failed\n");
return -1; return -1;
} }
return 0; return 0;
@ -708,32 +708,32 @@ static int nvm_write_V2(const PROGRAMMER *pgm, const AVRPART *p, uint32_t addres
self.execute_nvm_command(constants.UPDI_V2_NVMCTRL_CTRLA_NOCMD) self.execute_nvm_command(constants.UPDI_V2_NVMCTRL_CTRLA_NOCMD)
*/ */
if (updi_nvm_wait_ready(pgm, p) < 0) { if (updi_nvm_wait_ready(pgm, p) < 0) {
avrdude_message(MSG_INFO, "%s: Wait for ready chip failed\n", progname); pmsg_error("updi_nvm_wait_ready() failed\n");
return -1; return -1;
} }
avrdude_message(MSG_DEBUG, "%s: NVM write command\n", progname); pmsg_debug("NVM write command\n");
if (updi_nvm_command(pgm, p, UPDI_V2_NVMCTRL_CTRLA_FLASH_WRITE) < 0) { if (updi_nvm_command(pgm, p, UPDI_V2_NVMCTRL_CTRLA_FLASH_WRITE) < 0) {
avrdude_message(MSG_INFO, "%s: Clear page operation failed\n", progname); pmsg_error("clear page operation failed\n");
return -1; return -1;
} }
if (mode == USE_WORD_ACCESS) { if (mode == USE_WORD_ACCESS) {
if (updi_write_data_words(pgm, address, buffer, size) < 0) { if (updi_write_data_words(pgm, address, buffer, size) < 0) {
avrdude_message(MSG_INFO, "%s: Write data words operation failed\n", progname); pmsg_error("write data words operation failed\n");
return -1; return -1;
} }
} else { } else {
if (updi_write_data(pgm, address, buffer, size) < 0) { if (updi_write_data(pgm, address, buffer, size) < 0) {
avrdude_message(MSG_INFO, "%s: Write data operation failed\n", progname); pmsg_error("write data operation failed\n");
return -1; return -1;
} }
} }
if (updi_nvm_wait_ready(pgm, p) < 0) { if (updi_nvm_wait_ready(pgm, p) < 0) {
avrdude_message(MSG_INFO, "%s: Wait for ready chip failed\n", progname); pmsg_error("wait for ready chip failed\n");
return -1; return -1;
} }
avrdude_message(MSG_DEBUG, "%s: Clear NVM command\n", progname); pmsg_debug("clear NVM command\n");
if (updi_nvm_command(pgm, p, UPDI_V2_NVMCTRL_CTRLA_NOCMD) < 0) { if (updi_nvm_command(pgm, p, UPDI_V2_NVMCTRL_CTRLA_NOCMD) < 0) {
avrdude_message(MSG_INFO, "%s: Clear NVM command failed\n", progname); pmsg_error("clear NVM command failed\n");
return -1; return -1;
} }
return 0; return 0;
@ -768,21 +768,21 @@ static int nvm_chip_erase_V3(const PROGRAMMER *pgm, const AVRPART *p) {
return True return True
*/ */
avrdude_message(MSG_DEBUG, "%s: Chip erase using NVM CTRL\n", progname); pmsg_debug("Chip erase using NVM CTRL\n");
if (updi_nvm_wait_ready(pgm, p) < 0) { if (updi_nvm_wait_ready(pgm, p) < 0) {
avrdude_message(MSG_INFO, "%s: Wait for ready chip failed\n", progname); pmsg_error("updi_nvm_wait_ready() failed\n");
return -1; return -1;
} }
if (updi_nvm_command(pgm, p, UPDI_V3_NVMCTRL_CTRLA_CHIP_ERASE) < 0) { if (updi_nvm_command(pgm, p, UPDI_V3_NVMCTRL_CTRLA_CHIP_ERASE) < 0) {
avrdude_message(MSG_INFO, "%s: Chip erase command failed\n", progname); pmsg_error("chip erase command failed\n");
return -1; return -1;
} }
if (updi_nvm_wait_ready(pgm, p) < 0) { if (updi_nvm_wait_ready(pgm, p) < 0) {
avrdude_message(MSG_INFO, "%s: Wait for ready chip failed\n", progname); pmsg_error("updi_nvm_wait_ready() failed\n");
return -1; return -1;
} }
if (updi_nvm_command(pgm, p, UPDI_V3_NVMCTRL_CTRLA_NOCMD) < 0) { if (updi_nvm_command(pgm, p, UPDI_V3_NVMCTRL_CTRLA_NOCMD) < 0) {
avrdude_message(MSG_INFO, "%s: Sending empty command failed\n", progname); pmsg_error("sending empty command failed\n");
return -1; return -1;
} }
return 0; return 0;
@ -819,22 +819,22 @@ static int nvm_erase_flash_page_V3(const PROGRAMMER *pgm, const AVRPART *p, uint
raise IOError("Timeout waiting for NVM controller to be ready after flash page erase") raise IOError("Timeout waiting for NVM controller to be ready after flash page erase")
*/ */
unsigned char data[1]; unsigned char data[1];
avrdude_message(MSG_DEBUG, "%s: Erase flash page at address 0x%06X\n", progname, address); pmsg_debug("erase flash page at address 0x%06X\n", address);
if (updi_nvm_wait_ready(pgm, p) < 0) { if (updi_nvm_wait_ready(pgm, p) < 0) {
avrdude_message(MSG_INFO, "%s: Wait for ready chip failed\n", progname); pmsg_error("updi_nvm_wait_ready() failed\n");
return -1; return -1;
} }
data[0] = 0xFF; data[0] = 0xFF;
if (updi_write_data(pgm, address, data, 1) < 0) { if (updi_write_data(pgm, address, data, 1) < 0) {
avrdude_message(MSG_INFO, "%s: Dummy write operation failed\n", progname); pmsg_error("dummy write operation failed\n");
return -1; return -1;
} }
if (updi_nvm_command(pgm, p, UPDI_V3_NVMCTRL_CTRLA_FLASH_PAGE_ERASE) < 0) { if (updi_nvm_command(pgm, p, UPDI_V3_NVMCTRL_CTRLA_FLASH_PAGE_ERASE) < 0) {
avrdude_message(MSG_INFO, "%s: Flash page erase command failed\n", progname); pmsg_error("flash page erase command failed\n");
return -1; return -1;
} }
if (updi_nvm_wait_ready(pgm, p) < 0) { if (updi_nvm_wait_ready(pgm, p) < 0) {
avrdude_message(MSG_INFO, "%s: Wait for ready chip failed\n", progname); pmsg_error("updi_nvm_wait_ready() failed\n");
return -1; return -1;
} }
return 0; return 0;
@ -864,21 +864,21 @@ static int nvm_erase_eeprom_V3(const PROGRAMMER *pgm, const AVRPART *p) {
if not status: if not status:
raise IOError("Timeout waiting for NVM controller to be ready after EEPROM erase") raise IOError("Timeout waiting for NVM controller to be ready after EEPROM erase")
*/ */
avrdude_message(MSG_DEBUG, "%s: Erase EEPROM\n", progname); pmsg_debug("erase EEPROM\n");
if (updi_nvm_wait_ready(pgm, p) < 0) { if (updi_nvm_wait_ready(pgm, p) < 0) {
avrdude_message(MSG_INFO, "%s: Wait for ready chip failed\n", progname); pmsg_error("updi_nvm_wait_ready() failed\n");
return -1; return -1;
} }
if (updi_nvm_command(pgm, p, UPDI_V3_NVMCTRL_CTRLA_EEPROM_ERASE) < 0) { if (updi_nvm_command(pgm, p, UPDI_V3_NVMCTRL_CTRLA_EEPROM_ERASE) < 0) {
avrdude_message(MSG_INFO, "%s: EEPROM erase command failed\n", progname); pmsg_error("EEPROM erase command failed\n");
return -1; return -1;
} }
if (updi_nvm_wait_ready(pgm, p) < 0) { if (updi_nvm_wait_ready(pgm, p) < 0) {
avrdude_message(MSG_INFO, "%s: Wait for ready chip failed\n", progname); pmsg_error("updi_nvm_wait_ready() failed\n");
return -1; return -1;
} }
if (updi_nvm_command(pgm, p, UPDI_V3_NVMCTRL_CTRLA_NOCMD) < 0) { if (updi_nvm_command(pgm, p, UPDI_V3_NVMCTRL_CTRLA_NOCMD) < 0) {
avrdude_message(MSG_INFO, "%s: Sending empty command failed\n", progname); pmsg_error("sending empty command failed\n");
return -1; return -1;
} }
return 0; return 0;
@ -898,7 +898,7 @@ static int nvm_erase_user_row_V3(const PROGRAMMER *pgm, const AVRPART *p, uint32
# On this NVM version user row is implemented as FLASH # On this NVM version user row is implemented as FLASH
return self.erase_flash_page(self, address) return self.erase_flash_page(self, address)
*/ */
avrdude_message(MSG_DEBUG, "%s: Erase user row at address 0x%06X\n", progname, address); pmsg_debug("erase user row at address 0x%06X\n", address);
return nvm_erase_flash_page_V3(pgm, p, address); return nvm_erase_flash_page_V3(pgm, p, address);
} }
@ -1014,43 +1014,43 @@ static int nvm_write_V3(const PROGRAMMER *pgm, const AVRPART *p, uint32_t addres
self.execute_nvm_command(constants.UPDI_V3_NVMCTRL_CTRLA_NOCMD) self.execute_nvm_command(constants.UPDI_V3_NVMCTRL_CTRLA_NOCMD)
*/ */
if (updi_nvm_wait_ready(pgm, p) < 0) { if (updi_nvm_wait_ready(pgm, p) < 0) {
avrdude_message(MSG_INFO, "%s: Wait for ready chip failed\n", progname); pmsg_error("updi_nvm_wait_ready() failed\n");
return -1; return -1;
} }
avrdude_message(MSG_DEBUG, "%s: Clear page buffer\n", progname); pmsg_debug("clear page buffer\n");
if (updi_nvm_command(pgm, p, UPDI_V3_NVMCTRL_CTRLA_FLASH_PAGE_BUFFER_CLEAR) < 0) { if (updi_nvm_command(pgm, p, UPDI_V3_NVMCTRL_CTRLA_FLASH_PAGE_BUFFER_CLEAR) < 0) {
avrdude_message(MSG_INFO, "%s: Clear page operation failed\n", progname); pmsg_error("clear page operation failed\n");
return -1; return -1;
} }
if (updi_nvm_wait_ready(pgm, p) < 0) { if (updi_nvm_wait_ready(pgm, p) < 0) {
avrdude_message(MSG_INFO, "%s: Wait for ready chip failed\n", progname); pmsg_error("updi_nvm_wait_ready() failed\n");
return -1; return -1;
} }
if (mode == USE_WORD_ACCESS) { if (mode == USE_WORD_ACCESS) {
if (updi_write_data_words(pgm, address, buffer, size) < 0) { if (updi_write_data_words(pgm, address, buffer, size) < 0) {
avrdude_message(MSG_INFO, "%s: Write data words operation failed\n", progname); pmsg_error("write data words operation failed\n");
return -1; return -1;
} }
} else { } else {
if (updi_write_data(pgm, address, buffer, size) < 0) { if (updi_write_data(pgm, address, buffer, size) < 0) {
avrdude_message(MSG_INFO, "%s: Write data operation failed\n", progname); pmsg_error("write data operation failed\n");
return -1; return -1;
} }
} }
avrdude_message(MSG_DEBUG, "%s: Committing data\n", progname); pmsg_debug("committing data\n");
if (nvm_command == USE_DEFAULT_COMMAND) { if (nvm_command == USE_DEFAULT_COMMAND) {
nvm_command = UPDI_V3_NVMCTRL_CTRLA_FLASH_PAGE_WRITE; nvm_command = UPDI_V3_NVMCTRL_CTRLA_FLASH_PAGE_WRITE;
} }
if (updi_nvm_command(pgm, p, nvm_command) < 0) { if (updi_nvm_command(pgm, p, nvm_command) < 0) {
avrdude_message(MSG_INFO, "%s: Commit data command failed\n", progname); pmsg_error("commit data command failed\n");
return -1; return -1;
} }
if (updi_nvm_wait_ready(pgm, p) < 0) { if (updi_nvm_wait_ready(pgm, p) < 0) {
avrdude_message(MSG_INFO, "%s: Wait for ready chip failed\n", progname); pmsg_error("updi_nvm_wait_ready() failed\n");
return -1; return -1;
} }
if (updi_nvm_command(pgm, p, UPDI_V3_NVMCTRL_CTRLA_NOCMD) < 0) { if (updi_nvm_command(pgm, p, UPDI_V3_NVMCTRL_CTRLA_NOCMD) < 0) {
avrdude_message(MSG_INFO, "%s: Sending empty command failed\n", progname); pmsg_error("sending empty command failed\n");
return -1; return -1;
} }
return 0; return 0;
@ -1067,7 +1067,7 @@ int updi_nvm_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) {
case UPDI_NVM_MODE_V3: case UPDI_NVM_MODE_V3:
return nvm_chip_erase_V3(pgm, p); return nvm_chip_erase_V3(pgm, p);
default: default:
avrdude_message(MSG_INFO, "%s: Invalid NVM Mode %d\n", progname, updi_get_nvm_mode(pgm)); pmsg_error("invalid NVM Mode %d\n", updi_get_nvm_mode(pgm));
return -1; return -1;
} }
} }
@ -1082,7 +1082,7 @@ int updi_nvm_erase_flash_page(const PROGRAMMER *pgm, const AVRPART *p, uint32_t
case UPDI_NVM_MODE_V3: case UPDI_NVM_MODE_V3:
return nvm_erase_flash_page_V3(pgm, p, address); return nvm_erase_flash_page_V3(pgm, p, address);
default: default:
avrdude_message(MSG_INFO, "%s: Invalid NVM Mode %d\n", progname, updi_get_nvm_mode(pgm)); pmsg_error("invalid NVM Mode %d\n", updi_get_nvm_mode(pgm));
return -1; return -1;
} }
} }
@ -1097,7 +1097,7 @@ int updi_nvm_erase_eeprom(const PROGRAMMER *pgm, const AVRPART *p) {
case UPDI_NVM_MODE_V3: case UPDI_NVM_MODE_V3:
return nvm_erase_eeprom_V3(pgm, p); return nvm_erase_eeprom_V3(pgm, p);
default: default:
avrdude_message(MSG_INFO, "%s: Invalid NVM Mode %d\n", progname, updi_get_nvm_mode(pgm)); pmsg_error("invalid NVM Mode %d\n", updi_get_nvm_mode(pgm));
return -1; return -1;
} }
} }
@ -1112,7 +1112,7 @@ int updi_nvm_erase_user_row(const PROGRAMMER *pgm, const AVRPART *p, uint32_t ad
case UPDI_NVM_MODE_V3: case UPDI_NVM_MODE_V3:
return nvm_erase_user_row_V3(pgm, p, address, size); return nvm_erase_user_row_V3(pgm, p, address, size);
default: default:
avrdude_message(MSG_INFO, "%s: Invalid NVM Mode %d\n", progname, updi_get_nvm_mode(pgm)); pmsg_error("invalid NVM Mode %d\n", updi_get_nvm_mode(pgm));
return -1; return -1;
} }
} }
@ -1127,7 +1127,7 @@ int updi_nvm_write_flash(const PROGRAMMER *pgm, const AVRPART *p, uint32_t addre
case UPDI_NVM_MODE_V3: case UPDI_NVM_MODE_V3:
return nvm_write_flash_V3(pgm, p, address, buffer, size); return nvm_write_flash_V3(pgm, p, address, buffer, size);
default: default:
avrdude_message(MSG_INFO, "%s: Invalid NVM Mode %d\n", progname, updi_get_nvm_mode(pgm)); pmsg_error("invalid NVM Mode %d\n", updi_get_nvm_mode(pgm));
return -1; return -1;
} }
} }
@ -1142,7 +1142,7 @@ int updi_nvm_write_user_row(const PROGRAMMER *pgm, const AVRPART *p, uint32_t ad
case UPDI_NVM_MODE_V3: case UPDI_NVM_MODE_V3:
return nvm_write_user_row_V3(pgm, p, address, buffer, size); return nvm_write_user_row_V3(pgm, p, address, buffer, size);
default: default:
avrdude_message(MSG_INFO, "%s: Invalid NVM Mode %d\n", progname, updi_get_nvm_mode(pgm)); pmsg_error("invalid NVM Mode %d\n", updi_get_nvm_mode(pgm));
return -1; return -1;
} }
} }
@ -1157,7 +1157,7 @@ int updi_nvm_write_eeprom(const PROGRAMMER *pgm, const AVRPART *p, uint32_t addr
case UPDI_NVM_MODE_V3: case UPDI_NVM_MODE_V3:
return nvm_write_eeprom_V3(pgm, p, address, buffer, size); return nvm_write_eeprom_V3(pgm, p, address, buffer, size);
default: default:
avrdude_message(MSG_INFO, "%s: Invalid NVM Mode %d\n", progname, updi_get_nvm_mode(pgm)); pmsg_error("invalid NVM Mode %d\n", updi_get_nvm_mode(pgm));
return -1; return -1;
} }
} }
@ -1172,7 +1172,7 @@ int updi_nvm_write_fuse(const PROGRAMMER *pgm, const AVRPART *p, uint32_t addres
case UPDI_NVM_MODE_V3: case UPDI_NVM_MODE_V3:
return nvm_write_fuse_V3(pgm, p, address, value); return nvm_write_fuse_V3(pgm, p, address, value);
default: default:
avrdude_message(MSG_INFO, "%s: Invalid NVM Mode %d\n", progname, updi_get_nvm_mode(pgm)); pmsg_error("invalid NVM Mode %d\n", updi_get_nvm_mode(pgm));
return -1; return -1;
} }
} }
@ -1208,7 +1208,7 @@ int updi_nvm_wait_ready(const PROGRAMMER *pgm, const AVRPART *p) {
do { do {
if (updi_read_byte(pgm, p->nvm_base + UPDI_NVMCTRL_STATUS, &status) >= 0) { if (updi_read_byte(pgm, p->nvm_base + UPDI_NVMCTRL_STATUS, &status) >= 0) {
if (status & (1 << UPDI_NVM_STATUS_WRITE_ERROR)) { if (status & (1 << UPDI_NVM_STATUS_WRITE_ERROR)) {
avrdude_message(MSG_INFO, "%s: NVM error\n", progname); pmsg_error("unable to write NVM status\n");
return -1; return -1;
} }
if (!(status & ((1 << UPDI_NVM_STATUS_EEPROM_BUSY) | if (!(status & ((1 << UPDI_NVM_STATUS_EEPROM_BUSY) |
@ -1220,7 +1220,7 @@ int updi_nvm_wait_ready(const PROGRAMMER *pgm, const AVRPART *p) {
current_time = (tv.tv_sec * 1000000) + tv.tv_usec; current_time = (tv.tv_sec * 1000000) + tv.tv_usec;
} while ((current_time - start_time) < 10000000); } while ((current_time - start_time) < 10000000);
avrdude_message(MSG_INFO, "%s: Wait NVM ready timed out\n", progname); pmsg_error("wait NVM ready timed out\n");
return -1; return -1;
} }
@ -1235,7 +1235,7 @@ int updi_nvm_command(const PROGRAMMER *pgm, const AVRPART *p, uint8_t command) {
self.logger.debug("NVMCMD %d executing", command) self.logger.debug("NVMCMD %d executing", command)
return self.readwrite.write_byte(self.device.nvmctrl_address + constants.UPDI_NVMCTRL_CTRLA, command) return self.readwrite.write_byte(self.device.nvmctrl_address + constants.UPDI_NVMCTRL_CTRLA, command)
*/ */
avrdude_message(MSG_DEBUG, "%s: NVMCMD %d executing\n", progname, command); pmsg_debug("NVMCMD %d executing\n", command);
return updi_write_byte(pgm, p->nvm_base + UPDI_NVMCTRL_CTRLA, command); return updi_write_byte(pgm, p->nvm_base + UPDI_NVMCTRL_CTRLA, command);
} }

View File

@ -146,21 +146,21 @@ int updi_read_data(const PROGRAMMER *pgm, uint32_t address, uint8_t *buffer, uin
# Do the read(s) # Do the read(s)
return self.datalink.ld_ptr_inc(size) return self.datalink.ld_ptr_inc(size)
*/ */
avrdude_message(MSG_DEBUG, "%s: Reading %d bytes from 0x%06X\n", progname, size, address); pmsg_debug("reading %d bytes from 0x%06X\n", size, address);
if (size > UPDI_MAX_REPEAT_SIZE) { if (size > UPDI_MAX_REPEAT_SIZE) {
avrdude_message(MSG_DEBUG, "%s: Can't read that many bytes in one go\n", progname); pmsg_debug("cannot read that many bytes in one go\n");
return -1; return -1;
} }
if (updi_link_st_ptr(pgm, address) < 0) { if (updi_link_st_ptr(pgm, address) < 0) {
avrdude_message(MSG_DEBUG, "%s: ST_PTR operation failed\n", progname); pmsg_debug("ST_PTR operation failed\n");
return -1; return -1;
} }
if (size > 1) { if (size > 1) {
if (updi_link_repeat(pgm, size) < 0) { if (updi_link_repeat(pgm, size) < 0) {
avrdude_message(MSG_DEBUG, "%s: Repeat operation failed\n", progname); pmsg_debug("repeat operation failed\n");
return -1; return -1;
} }
} }
@ -200,21 +200,21 @@ int updi_write_data(const PROGRAMMER *pgm, uint32_t address, uint8_t *buffer, ui
} }
if (size == 2) { if (size == 2) {
if (updi_link_st(pgm, address, buffer[0]) < 0) { if (updi_link_st(pgm, address, buffer[0]) < 0) {
avrdude_message(MSG_DEBUG, "%s: ST operation failed\n", progname); pmsg_debug("ST operation failed\n");
return -1; return -1;
} }
return updi_link_st(pgm, address+1, buffer[1]); return updi_link_st(pgm, address+1, buffer[1]);
} }
if (size > UPDI_MAX_REPEAT_SIZE) { if (size > UPDI_MAX_REPEAT_SIZE) {
avrdude_message(MSG_DEBUG, "%s: Invalid length\n", progname); pmsg_debug("invalid length\n");
return -1; return -1;
} }
if (updi_link_st_ptr(pgm, address) < 0) { if (updi_link_st_ptr(pgm, address) < 0) {
avrdude_message(MSG_DEBUG, "%s: ST_PTR operation failed\n", progname); pmsg_debug("ST_PTR operation failed\n");
return -1; return -1;
} }
if (updi_link_repeat(pgm, size) < 0) { if (updi_link_repeat(pgm, size) < 0) {
avrdude_message(MSG_DEBUG, "%s: Repeat operation failed\n", progname); pmsg_debug("repeat operation failed\n");
return -1; return -1;
} }
return updi_link_st_ptr_inc(pgm, buffer, size); return updi_link_st_ptr_inc(pgm, buffer, size);
@ -245,21 +245,21 @@ int updi_read_data_words(const PROGRAMMER *pgm, uint32_t address, uint8_t *buffe
# Do the read # Do the read
return self.datalink.ld_ptr_inc16(words) return self.datalink.ld_ptr_inc16(words)
*/ */
avrdude_message(MSG_DEBUG, "%s: Reading %d words from 0x%06X", progname, size, address); pmsg_debug("reading %d words from 0x%06X", size, address);
if (size > (UPDI_MAX_REPEAT_SIZE >> 1)) { if (size > (UPDI_MAX_REPEAT_SIZE >> 1)) {
avrdude_message(MSG_DEBUG, "%s: Can't read that many words in one go\n", progname); pmsg_debug("cannot read that many words in one go\n");
return -1; return -1;
} }
if (updi_link_st_ptr(pgm, address) < 0) { if (updi_link_st_ptr(pgm, address) < 0) {
avrdude_message(MSG_DEBUG, "%s: ST_PTR operation failed\n", progname); pmsg_debug("ST_PTR operation failed\n");
return -1; return -1;
} }
if (size > 1) { if (size > 1) {
if (updi_link_repeat(pgm, size) < 0) { if (updi_link_repeat(pgm, size) < 0) {
avrdude_message(MSG_DEBUG, "%s: Repeat operation failed\n", progname); pmsg_debug("repeat operation failed\n");
return -1; return -1;
} }
} }
@ -295,11 +295,11 @@ int updi_write_data_words(const PROGRAMMER *pgm, uint32_t address, uint8_t *buff
return updi_link_st16(pgm, address, buffer[0] + (buffer[1] << 8)); return updi_link_st16(pgm, address, buffer[0] + (buffer[1] << 8));
} }
if (size > UPDI_MAX_REPEAT_SIZE << 1) { if (size > UPDI_MAX_REPEAT_SIZE << 1) {
avrdude_message(MSG_DEBUG, "%s: Invalid length\n", progname); pmsg_debug("invalid length\n");
return -1; return -1;
} }
if (updi_link_st_ptr(pgm, address) < 0) { if (updi_link_st_ptr(pgm, address) < 0) {
avrdude_message(MSG_DEBUG, "%s: ST_PTR operation failed\n", progname); pmsg_debug("ST_PTR operation failed\n");
return -1; return -1;
} }
return updi_link_st_ptr_inc16_RSD(pgm, buffer, size >> 1, -1); return updi_link_st_ptr_inc16_RSD(pgm, buffer, size >> 1, -1);

View File

@ -79,8 +79,7 @@ static int usbhid_open(const char *port, union pinfo pinfo, union filedescriptor
if (strlen(serno) > 12) if (strlen(serno) > 12)
{ {
avrdude_message(MSG_INFO, "%s: usbhid_open(): invalid serial number \"%s\"\n", pmsg_error("invalid serial number %s\n", serno);
progname, serno);
return -1; return -1;
} }
@ -100,8 +99,7 @@ static int usbhid_open(const char *port, union pinfo pinfo, union filedescriptor
walk = list; walk = list;
while (walk) while (walk)
{ {
avrdude_message(MSG_NOTICE, "%s: usbhid_open(): Found %ls, serno: %ls\n", pmsg_notice("usbhid_open(): found %ls, serno: %ls\n", walk->product_string, walk->serial_number);
progname, walk->product_string, walk->serial_number);
size_t slen = wcslen(walk->serial_number); size_t slen = wcslen(walk->serial_number);
if (slen >= serlen && if (slen >= serlen &&
wcscmp(walk->serial_number + slen - serlen, wserno) == 0) wcscmp(walk->serial_number + slen - serlen, wserno) == 0)
@ -109,26 +107,21 @@ static int usbhid_open(const char *port, union pinfo pinfo, union filedescriptor
/* found matching serial number */ /* found matching serial number */
break; break;
} }
avrdude_message(MSG_DEBUG, "%s: usbhid_open(): serial number doesn't match\n", pmsg_debug("usbhid_open(): serial number does not match\n");
progname);
walk = walk->next; walk = walk->next;
} }
if (walk == NULL) if (walk == NULL)
{ {
avrdude_message(MSG_INFO, "%s: usbhid_open(): No matching device found\n", pmsg_error("no matching device found\n");
progname);
hid_free_enumeration(list); hid_free_enumeration(list);
return -1; return -1;
} }
avrdude_message(MSG_DEBUG, "%s: usbhid_open(): Opening path %s\n", pmsg_debug("usbhid_open(): opening path %s\n", walk->path);
progname, walk->path);
dev = hid_open_path(walk->path); dev = hid_open_path(walk->path);
hid_free_enumeration(list); hid_free_enumeration(list);
if (dev == NULL) if (dev == NULL)
{ {
avrdude_message(MSG_INFO, pmsg_error("found device, but hid_open_path() failed\n");
"%s: usbhid_open(): Found device, but hid_open_path() failed\n",
progname);
return -1; return -1;
} }
} }
@ -140,8 +133,7 @@ static int usbhid_open(const char *port, union pinfo pinfo, union filedescriptor
dev = hid_open(pinfo.usbinfo.vid, pinfo.usbinfo.pid, NULL); dev = hid_open(pinfo.usbinfo.vid, pinfo.usbinfo.pid, NULL);
if (dev == NULL) if (dev == NULL)
{ {
avrdude_message(MSG_INFO, "%s: usbhid_open(): No device found\n", pmsg_error("no device found\n");
progname);
return -1; return -1;
} }
} }
@ -176,8 +168,7 @@ static int usbhid_open(const char *port, union pinfo pinfo, union filedescriptor
*/ */
if (pinfo.usbinfo.vid == USB_VENDOR_ATMEL) if (pinfo.usbinfo.vid == USB_VENDOR_ATMEL)
{ {
avrdude_message(MSG_DEBUG, "%s: usbhid_open(): Probing for max. packet size\n", pmsg_debug("usbhid_open(): probing for max packet size\n");
progname);
memset(usbbuf, 0, sizeof usbbuf); memset(usbbuf, 0, sizeof usbbuf);
usbbuf[0] = 0; /* no HID reports used */ usbbuf[0] = 0; /* no HID reports used */
usbbuf[1] = 0; /* DAP_Info */ usbbuf[1] = 0; /* DAP_Info */
@ -195,26 +186,22 @@ static int usbhid_open(const char *port, union pinfo pinfo, union filedescriptor
res = hid_read_timeout(dev, usbbuf, 10, 50); res = hid_read_timeout(dev, usbbuf, 10, 50);
} }
if (res <= 0) { if (res <= 0) {
avrdude_message(MSG_INFO, "%s: usbhid_open(): No response from device\n", pmsg_error("no response from device\n");
progname);
hid_close(dev); hid_close(dev);
return -1; return -1;
} }
if (usbbuf[0] != 0 || usbbuf[1] != 2) { if (usbbuf[0] != 0 || usbbuf[1] != 2) {
avrdude_message(MSG_INFO, pmsg_error("unexpected reply to DAP_Info: 0x%02x 0x%02x\n",
"%s: usbhid_open(): Unexpected reply to DAP_Info: 0x%02x 0x%02x\n", usbbuf[0], usbbuf[1]);
progname, usbbuf[0], usbbuf[1]);
} else { } else {
fd->usb.max_xfer = usbbuf[2] + (usbbuf[3] << 8); fd->usb.max_xfer = usbbuf[2] + (usbbuf[3] << 8);
avrdude_message(MSG_DEBUG, pmsg_debug("usbhid_open(): setting max_xfer from DAP_Info response to %d\n",
"%s: usbhid_open(): Setting max_xfer from DAP_Info response to %d\n", fd->usb.max_xfer);
progname, fd->usb.max_xfer);
} }
} }
if (fd->usb.max_xfer > USBDEV_MAX_XFER_3) { if (fd->usb.max_xfer > USBDEV_MAX_XFER_3) {
avrdude_message(MSG_INFO, pmsg_error("unexpected max size %d, reducing to %d\n",
"%s: usbhid_open(): Unexpected max size %d, reducing to %d\n", fd->usb.max_xfer, USBDEV_MAX_XFER_3);
progname, fd->usb.max_xfer, USBDEV_MAX_XFER_3);
fd->usb.max_xfer = USBDEV_MAX_XFER_3; fd->usb.max_xfer = USBDEV_MAX_XFER_3;
} }
@ -251,32 +238,30 @@ static int usbhid_send(const union filedescriptor *fd, const unsigned char *bp,
memcpy(usbbuf + 1, bp, tx_size); memcpy(usbbuf + 1, bp, tx_size);
rv = hid_write(udev, usbbuf, tx_size + 1); rv = hid_write(udev, usbbuf, tx_size + 1);
if (rv < 0) { if (rv < 0) {
avrdude_message(MSG_INFO, "%s: Failed to write %d bytes to USB\n", pmsg_error("unable to write %d bytes to USB\n", tx_size);
progname, tx_size);
return -1; return -1;
} }
if (rv != tx_size + 1) if (rv != tx_size + 1)
avrdude_message(MSG_INFO, "%s: Short write to USB: %d bytes out of %d written\n", pmsg_error("short write to USB: %d bytes out of %d written\n", rv, tx_size + 1);
progname, rv, tx_size + 1);
if (verbose > 4) if (verbose > 4)
{ {
avrdude_message(MSG_TRACE2, "%s: Sent: ", progname); pmsg_trace2("sent: ");
while (i) { while (i) {
unsigned char c = *p; unsigned char c = *p;
if (isprint(c)) { if (isprint(c)) {
avrdude_message(MSG_TRACE2, "%c ", c); msg_trace2("%c ", c);
} }
else { else {
avrdude_message(MSG_TRACE2, ". "); msg_trace2(". ");
} }
avrdude_message(MSG_TRACE2, "[%02x] ", c); msg_trace2("[%02x] ", c);
p++; p++;
i--; i--;
} }
avrdude_message(MSG_TRACE2, "\n"); msg_trace2("\n");
} }
return 0; return 0;
} }
@ -292,28 +277,26 @@ static int usbhid_recv(const union filedescriptor *fd, unsigned char *buf, size_
rv = i = hid_read_timeout(udev, buf, nbytes, 10000); rv = i = hid_read_timeout(udev, buf, nbytes, 10000);
if (i != nbytes) if (i != nbytes)
avrdude_message(MSG_INFO, pmsg_error("short read, read only %d out of %lu bytes\n", i, (unsigned long) nbytes);
"%s: Short read, read only %d out of %u bytes\n",
progname, i, nbytes);
if (verbose > 4) if (verbose > 4)
{ {
avrdude_message(MSG_TRACE2, "%s: Recv: ", progname); pmsg_trace2("recv: ");
while (i) { while (i) {
unsigned char c = *p; unsigned char c = *p;
if (isprint(c)) { if (isprint(c)) {
avrdude_message(MSG_TRACE2, "%c ", c); msg_trace2("%c ", c);
} }
else { else {
avrdude_message(MSG_TRACE2, ". "); msg_trace2(". ");
} }
avrdude_message(MSG_TRACE2, "[%02x] ", c); msg_trace2("[%02x] ", c);
p++; p++;
i--; i--;
} }
avrdude_message(MSG_TRACE2, "\n"); msg_trace2("\n");
} }
return rv; return rv;

View File

@ -97,8 +97,7 @@ static int usbdev_open(const char *port, union pinfo pinfo, union filedescriptor
if (strlen(serno) > 12) if (strlen(serno) > 12)
{ {
avrdude_message(MSG_INFO, "%s: usbdev_open(): invalid serial number \"%s\"\n", pmsg_error("invalid serial number %s\n", serno);
progname, serno);
return -1; return -1;
} }
} }
@ -126,8 +125,7 @@ static int usbdev_open(const char *port, union pinfo pinfo, union filedescriptor
dev->descriptor.iSerialNumber, dev->descriptor.iSerialNumber,
string, sizeof(string)) < 0) string, sizeof(string)) < 0)
{ {
avrdude_message(MSG_INFO, "%s: usb_open(): cannot read serial number \"%s\"\n", pmsg_error("cannot read serial number: %s\n", usb_strerror());
progname, usb_strerror());
/* /*
* On some systems, libusb appears to have * On some systems, libusb appears to have
* problems sending control messages. Catch the * problems sending control messages. Catch the
@ -145,8 +143,7 @@ static int usbdev_open(const char *port, union pinfo pinfo, union filedescriptor
dev->descriptor.iProduct, dev->descriptor.iProduct,
product, sizeof(product)) < 0) product, sizeof(product)) < 0)
{ {
avrdude_message(MSG_INFO, "%s: usb_open(): cannot read product name \"%s\"\n", pmsg_error("cannot read product name: %s\n", usb_strerror());
progname, usb_strerror());
strcpy(product, "[unnamed product]"); strcpy(product, "[unnamed product]");
} }
/* /*
@ -172,8 +169,7 @@ static int usbdev_open(const char *port, union pinfo pinfo, union filedescriptor
fd->usb.wep = 0x02; fd->usb.wep = 0x02;
} }
avrdude_message(MSG_NOTICE, "%s: usbdev_open(): Found %s, serno: %s\n", pmsg_notice("usbdev_open(): found %s, serno: %s\n", product, string);
progname, product, string);
if (serno != NULL) if (serno != NULL)
{ {
/* /*
@ -184,8 +180,7 @@ static int usbdev_open(const char *port, union pinfo pinfo, union filedescriptor
x = strlen(string) - strlen(serno); x = strlen(string) - strlen(serno);
if (strcasecmp(string + x, serno) != 0) if (strcasecmp(string + x, serno) != 0)
{ {
avrdude_message(MSG_DEBUG, "%s: usbdev_open(): serial number doesn't match\n", pmsg_debug("usbdev_open(): serial number does not match\n");
progname);
usb_close(udev); usb_close(udev);
continue; continue;
} }
@ -193,16 +188,14 @@ static int usbdev_open(const char *port, union pinfo pinfo, union filedescriptor
if (dev->config == NULL) if (dev->config == NULL)
{ {
avrdude_message(MSG_INFO, "%s: usbdev_open(): USB device has no configuration\n", pmsg_warning("USB device has no configuration\n");
progname);
goto trynext; goto trynext;
} }
if (usb_set_configuration(udev, dev->config[0].bConfigurationValue)) if (usb_set_configuration(udev, dev->config[0].bConfigurationValue))
{ {
avrdude_message(MSG_INFO, "%s: usbdev_open(): WARNING: failed to set configuration %d: %s\n", pmsg_warning("unable to set configuration %d: %s\n",
progname, dev->config[0].bConfigurationValue, dev->config[0].bConfigurationValue, usb_strerror());
usb_strerror());
/* let's hope it has already been configured */ /* let's hope it has already been configured */
// goto trynext; // goto trynext;
} }
@ -221,8 +214,8 @@ static int usbdev_open(const char *port, union pinfo pinfo, union filedescriptor
#endif #endif
if (usb_claim_interface(udev, usb_interface)) if (usb_claim_interface(udev, usb_interface))
{ {
avrdude_message(MSG_INFO, "%s: usbdev_open(): error claiming interface %d: %s\n", pmsg_error("unable to claim interface %d: %s\n",
progname, usb_interface, usb_strerror()); usb_interface, usb_strerror());
} }
else else
{ {
@ -239,8 +232,7 @@ static int usbdev_open(const char *port, union pinfo pinfo, union filedescriptor
} }
if (iface == dev->config[0].bNumInterfaces) if (iface == dev->config[0].bNumInterfaces)
{ {
avrdude_message(MSG_INFO, "%s: usbdev_open(): no usable interface found\n", pmsg_warning("no usable interface found\n");
progname);
goto trynext; goto trynext;
} }
@ -255,16 +247,15 @@ static int usbdev_open(const char *port, union pinfo pinfo, union filedescriptor
if ((possible_ep & USB_ENDPOINT_DIR_MASK) != 0) if ((possible_ep & USB_ENDPOINT_DIR_MASK) != 0)
{ {
avrdude_message(MSG_NOTICE2, "%s: usbdev_open(): using read endpoint 0x%02x\n", pmsg_notice2("usbdev_open(): using read endpoint 0x%02x\n", possible_ep);
progname, possible_ep);
fd->usb.rep = possible_ep; fd->usb.rep = possible_ep;
break; break;
} }
} }
if (fd->usb.rep == 0) if (fd->usb.rep == 0)
{ {
avrdude_message(MSG_INFO, "%s: usbdev_open(): cannot find a read endpoint, using 0x%02x\n", pmsg_error("cannot find a read endpoint, using 0x%02x\n",
progname, USBDEV_BULK_EP_READ_MKII); USBDEV_BULK_EP_READ_MKII);
fd->usb.rep = USBDEV_BULK_EP_READ_MKII; fd->usb.rep = USBDEV_BULK_EP_READ_MKII;
} }
} }
@ -274,34 +265,31 @@ static int usbdev_open(const char *port, union pinfo pinfo, union filedescriptor
dev->config[0].interface[iface].altsetting[0].endpoint[i].bEndpointAddress == fd->usb.wep) && dev->config[0].interface[iface].altsetting[0].endpoint[i].bEndpointAddress == fd->usb.wep) &&
dev->config[0].interface[iface].altsetting[0].endpoint[i].wMaxPacketSize < fd->usb.max_xfer) dev->config[0].interface[iface].altsetting[0].endpoint[i].wMaxPacketSize < fd->usb.max_xfer)
{ {
avrdude_message(MSG_NOTICE, "%s: max packet size expected %d, but found %d due to EP 0x%02x's wMaxPacketSize\n", pmsg_notice("max packet size expected %d, but found %d due to EP 0x%02x's wMaxPacketSize\n",
progname, fd->usb.max_xfer,
fd->usb.max_xfer, dev->config[0].interface[iface].altsetting[0].endpoint[i].wMaxPacketSize,
dev->config[0].interface[iface].altsetting[0].endpoint[i].wMaxPacketSize, dev->config[0].interface[iface].altsetting[0].endpoint[i].bEndpointAddress);
dev->config[0].interface[iface].altsetting[0].endpoint[i].bEndpointAddress); fd->usb.max_xfer = dev->config[0].interface[iface].altsetting[0].endpoint[i].wMaxPacketSize;
fd->usb.max_xfer = dev->config[0].interface[iface].altsetting[0].endpoint[i].wMaxPacketSize;
} }
} }
if (pinfo.usbinfo.flags & PINFO_FL_USEHID) if (pinfo.usbinfo.flags & PINFO_FL_USEHID)
{ {
if (usb_control_msg(udev, 0x21, 0x0a /* SET_IDLE */, 0, 0, NULL, 0, 100) < 0) if (usb_control_msg(udev, 0x21, 0x0a /* SET_IDLE */, 0, 0, NULL, 0, 100) < 0)
avrdude_message(MSG_INFO, "%s: usbdev_open(): SET_IDLE failed\n", progname); pmsg_error("SET_IDLE failed\n");
} }
return 0; return 0;
trynext: trynext:
usb_close(udev); usb_close(udev);
} }
else else
avrdude_message(MSG_INFO, "%s: usbdev_open(): cannot open device: %s\n", pmsg_error("cannot open device: %s\n", usb_strerror());
progname, usb_strerror());
} }
} }
} }
if ((pinfo.usbinfo.flags & PINFO_FL_SILENT) == 0) if ((pinfo.usbinfo.flags & PINFO_FL_SILENT) == 0)
avrdude_message(MSG_NOTICE, "%s: usbdev_open(): did not find any%s USB device \"%s\" (0x%04x:0x%04x)\n", pmsg_notice("usbdev_open(): did not find any%s USB device \"%s\" (0x%04x:0x%04x)\n",
progname, serno? " (matching)": "", port, serno? " (matching)": "", port, (unsigned)pinfo.usbinfo.vid, (unsigned)pinfo.usbinfo.pid);
(unsigned)pinfo.usbinfo.vid, (unsigned)pinfo.usbinfo.pid);
return -1; return -1;
} }
@ -353,8 +341,7 @@ static int usbdev_send(const union filedescriptor *fd, const unsigned char *bp,
rv = usb_bulk_write(udev, fd->usb.wep, (char *)bp, tx_size, 10000); rv = usb_bulk_write(udev, fd->usb.wep, (char *)bp, tx_size, 10000);
if (rv != tx_size) if (rv != tx_size)
{ {
avrdude_message(MSG_INFO, "%s: usbdev_send(): wrote %d out of %d bytes, err = %s\n", pmsg_error("wrote %d out of %d bytes, err = %s\n", rv, tx_size, usb_strerror());
progname, rv, tx_size, usb_strerror());
return -1; return -1;
} }
bp += tx_size; bp += tx_size;
@ -363,22 +350,22 @@ static int usbdev_send(const union filedescriptor *fd, const unsigned char *bp,
if (verbose > 3) if (verbose > 3)
{ {
avrdude_message(MSG_TRACE, "%s: Sent: ", progname); pmsg_trace("sent: ");
while (i) { while (i) {
unsigned char c = *p; unsigned char c = *p;
if (isprint(c)) { if (isprint(c)) {
avrdude_message(MSG_TRACE, "%c ", c); msg_trace("%c ", c);
} }
else { else {
avrdude_message(MSG_TRACE, ". "); msg_trace(". ");
} }
avrdude_message(MSG_TRACE, "[%02x] ", c); msg_trace("[%02x] ", c);
p++; p++;
i--; i--;
} }
avrdude_message(MSG_TRACE, "\n"); msg_trace("\n");
} }
return 0; return 0;
} }
@ -402,9 +389,8 @@ usb_fill_buf(usb_dev_handle *udev, int maxsize, int ep, int use_interrupt_xfer)
rv = usb_bulk_read(udev, ep, usbbuf, maxsize, 10000); rv = usb_bulk_read(udev, ep, usbbuf, maxsize, 10000);
if (rv < 0) if (rv < 0)
{ {
avrdude_message(MSG_NOTICE2, "%s: usb_fill_buf(): usb_%s_read() error %s\n", pmsg_notice2("usb_fill_buf(): usb_%s_read() error: %s\n",
progname, (use_interrupt_xfer? "interrupt": "bulk"), use_interrupt_xfer? "interrupt": "bulk", usb_strerror());
usb_strerror());
return -1; return -1;
} }
@ -439,22 +425,22 @@ static int usbdev_recv(const union filedescriptor *fd, unsigned char *buf, size_
if (verbose > 4) if (verbose > 4)
{ {
avrdude_message(MSG_TRACE2, "%s: Recv: ", progname); pmsg_trace2("recv: ");
while (i) { while (i) {
unsigned char c = *p; unsigned char c = *p;
if (isprint(c)) { if (isprint(c)) {
avrdude_message(MSG_TRACE2, "%c ", c); msg_trace2("%c ", c);
} }
else { else {
avrdude_message(MSG_TRACE2, ". "); msg_trace2(". ");
} }
avrdude_message(MSG_TRACE2, "[%02x] ", c); msg_trace2("[%02x] ", c);
p++; p++;
i--; i--;
} }
avrdude_message(MSG_TRACE2, "\n"); msg_trace2("\n");
} }
return 0; return 0;
@ -493,7 +479,7 @@ static int usbdev_recv_frame(const union filedescriptor *fd, unsigned char *buf,
} }
else if (rv > 0) else if (rv > 0)
{ {
avrdude_message(MSG_INFO, "Short event len = %d, ignored.\n", rv); pmsg_warning("short event len = %d, ignored\n", rv);
/* fallthrough */ /* fallthrough */
} }
} }
@ -509,9 +495,8 @@ static int usbdev_recv_frame(const union filedescriptor *fd, unsigned char *buf,
fd->usb.max_xfer, 10000); fd->usb.max_xfer, 10000);
if (rv < 0) if (rv < 0)
{ {
avrdude_message(MSG_NOTICE2, "%s: usbdev_recv_frame(): usb_%s_read(): %s\n", pmsg_notice2("usbdev_recv_frame(): usb_%s_read(): %s\n",
progname, (fd->usb.use_interrupt_xfer? "interrupt": "bulk"), fd->usb.use_interrupt_xfer? "interrupt": "bulk", usb_strerror());
usb_strerror());
return -1; return -1;
} }
@ -549,22 +534,22 @@ static int usbdev_recv_frame(const union filedescriptor *fd, unsigned char *buf,
if (verbose > 3) if (verbose > 3)
{ {
i = n & USB_RECV_LENGTH_MASK; i = n & USB_RECV_LENGTH_MASK;
avrdude_message(MSG_TRACE, "%s: Recv: ", progname); pmsg_trace("recv: ");
while (i) { while (i) {
unsigned char c = *p; unsigned char c = *p;
if (isprint(c)) { if (isprint(c)) {
avrdude_message(MSG_TRACE, "%c ", c); msg_trace("%c ", c);
} }
else { else {
avrdude_message(MSG_TRACE, ". "); msg_trace(". ");
} }
avrdude_message(MSG_TRACE, "[%02x] ", c); msg_trace("[%02x] ", c);
p++; p++;
i--; i--;
} }
avrdude_message(MSG_TRACE, "\n"); msg_trace("\n");
} }
return n; return n;
} }

View File

@ -119,7 +119,7 @@ static const char *errstr(int result)
n = ENOSYS; n = ENOSYS;
break; break;
default: default:
snprintf(msg, sizeof msg, "Unknown libusb error: %d", result); snprintf(msg, sizeof msg, "Unknown libusb error code %d", result);
return msg; return msg;
} }
return strerror(n); return strerror(n);
@ -263,8 +263,7 @@ static int usbasp_write_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVRM
static void usbasp_setup(PROGRAMMER * pgm) static void usbasp_setup(PROGRAMMER * pgm)
{ {
if ((pgm->cookie = malloc(sizeof(struct pdata))) == 0) { if ((pgm->cookie = malloc(sizeof(struct pdata))) == 0) {
avrdude_message(MSG_INFO, "%s: usbasp_setup(): Out of memory allocating private data\n", pmsg_error(" out of memory allocating private data\n");
progname);
exit(1); exit(1);
} }
memset(pgm->cookie, 0, sizeof(struct pdata)); memset(pgm->cookie, 0, sizeof(struct pdata));
@ -284,14 +283,12 @@ static int usbasp_parseextparms(const PROGRAMMER *pgm, const LISTID extparms) {
extended_param = ldata(ln); extended_param = ldata(ln);
if (strncmp(extended_param, "section_config", strlen("section_config")) == 0) { if (strncmp(extended_param, "section_config", strlen("section_config")) == 0) {
avrdude_message(MSG_NOTICE2, "%s: usbasp_parseextparms(): set section_e to 1 (config section)\n", pmsg_notice2("usbasp_parseextparms(): set section_e to 1 (config section)\n");
progname);
PDATA(pgm)->section_e = 1; PDATA(pgm)->section_e = 1;
continue; continue;
} }
avrdude_message(MSG_INFO, "%s: usbasp_parseextparms(): invalid extended parameter '%s'\n", pmsg_error("invalid extended parameter '%s'\n", extended_param);
progname, extended_param);
rv = -1; rv = -1;
} }
@ -336,15 +333,14 @@ static int usbasp_transmit(const PROGRAMMER *pgm,
int nbytes; int nbytes;
if (verbose > 3) { if (verbose > 3) {
avrdude_message(MSG_TRACE, "%s: usbasp_transmit(\"%s\", 0x%02x, 0x%02x, 0x%02x, 0x%02x)\n", pmsg_trace("usbasp_transmit(\"%s\", 0x%02x, 0x%02x, 0x%02x, 0x%02x)\n",
progname, usbasp_get_funcname(functionid), send[0], send[1], send[2], send[3]);
usbasp_get_funcname(functionid), send[0], send[1], send[2], send[3]);
if (!receive && buffersize > 0) { if (!receive && buffersize > 0) {
int i; int i;
avrdude_message(MSG_TRACE, "%s => ", progbuf); imsg_trace(" => ");
for (i = 0; i < buffersize; i++) for (i = 0; i < buffersize; i++)
avrdude_message(MSG_TRACE, "[%02x] ", buffer[i]); msg_trace("[%02x] ", buffer[i]);
avrdude_message(MSG_TRACE, "\n"); msg_trace("\n");
} }
} }
@ -358,7 +354,7 @@ static int usbasp_transmit(const PROGRAMMER *pgm,
buffersize & 0xffff, buffersize & 0xffff,
5000); 5000);
if(nbytes < 0){ if(nbytes < 0){
avrdude_message(MSG_INFO, "%s: error: usbasp_transmit: %s\n", progname, errstr(nbytes)); pmsg_ext_error("%s\n", errstr(nbytes));
return -1; return -1;
} }
#else #else
@ -370,17 +366,17 @@ static int usbasp_transmit(const PROGRAMMER *pgm,
(char *)buffer, buffersize, (char *)buffer, buffersize,
5000); 5000);
if(nbytes < 0){ if(nbytes < 0){
avrdude_message(MSG_INFO, "%s: error: usbasp_transmit: %s\n", progname, usb_strerror()); pmsg_error("%s\n", usb_strerror());
return -1; return -1;
} }
#endif #endif
if (verbose > 3 && receive && nbytes > 0) { if (verbose > 3 && receive && nbytes > 0) {
int i; int i;
avrdude_message(MSG_TRACE, "%s<= ", progbuf); imsg_trace("<= ");
for (i = 0; i < nbytes; i++) for (i = 0; i < nbytes; i++)
avrdude_message(MSG_TRACE, "[%02x] ", buffer[i]); msg_trace("[%02x] ", buffer[i]);
avrdude_message(MSG_TRACE, "\n"); msg_trace("\n");
} }
return nbytes; return nbytes;
@ -421,9 +417,8 @@ static int usbOpenDevice(libusb_device_handle **device, int vendor,
r = libusb_open(dev, &handle); r = libusb_open(dev, &handle);
if (!handle) { if (!handle) {
errorCode = USB_ERROR_ACCESS; errorCode = USB_ERROR_ACCESS;
avrdude_message(MSG_INFO, "%s: Warning: cannot open USB device: %s\n", pmsg_warning("cannot open USB device: %s\n", errstr(r));
progname, errstr(r)); continue;
continue;
} }
errorCode = 0; errorCode = 0;
/* now check whether the names match: */ /* now check whether the names match: */
@ -432,12 +427,10 @@ static int usbOpenDevice(libusb_device_handle **device, int vendor,
if (r < 0) { if (r < 0) {
if ((vendorName != NULL) && (vendorName[0] != 0)) { if ((vendorName != NULL) && (vendorName[0] != 0)) {
errorCode = USB_ERROR_IO; errorCode = USB_ERROR_IO;
avrdude_message(MSG_INFO, "%s: Warning: cannot query manufacturer for device: %s\n", pmsg_warning("cannot query manufacturer for device: %s\n", errstr(r));
progname, errstr(r));
} }
} else { } else {
avrdude_message(MSG_NOTICE2, "%s: seen device from vendor ->%s<-\n", pmsg_notice2("seen device from vendor >%s<\n", string);
progname, string);
if ((vendorName != NULL) && (vendorName[0] != 0) && (strcmp(string, vendorName) != 0)) if ((vendorName != NULL) && (vendorName[0] != 0) && (strcmp(string, vendorName) != 0))
errorCode = USB_ERROR_NOTFOUND; errorCode = USB_ERROR_NOTFOUND;
} }
@ -446,12 +439,10 @@ static int usbOpenDevice(libusb_device_handle **device, int vendor,
if (r < 0) { if (r < 0) {
if ((productName != NULL) && (productName[0] != 0)) { if ((productName != NULL) && (productName[0] != 0)) {
errorCode = USB_ERROR_IO; errorCode = USB_ERROR_IO;
avrdude_message(MSG_INFO, "%s: Warning: cannot query product for device: %s\n", pmsg_warning("cannot query product for device: %s\n", errstr(r));
progname, errstr(r));
} }
} else { } else {
avrdude_message(MSG_NOTICE2, "%s: seen product ->%s<-\n", pmsg_notice2("seen product >%s<\n", string);
progname, string);
if((productName != NULL) && (productName[0] != 0) && (strcmp(string, productName) != 0)) if((productName != NULL) && (productName[0] != 0) && (strcmp(string, productName) != 0))
errorCode = USB_ERROR_NOTFOUND; errorCode = USB_ERROR_NOTFOUND;
} }
@ -494,8 +485,7 @@ static int didUsbInit = 0;
handle = usb_open(dev); handle = usb_open(dev);
if(!handle){ if(!handle){
errorCode = USB_ERROR_ACCESS; errorCode = USB_ERROR_ACCESS;
avrdude_message(MSG_INFO, "%s: Warning: cannot open USB device: %s\n", pmsg_warning("cannot open USB device: %s\n", usb_strerror());
progname, usb_strerror());
continue; continue;
} }
errorCode = 0; errorCode = 0;
@ -506,12 +496,10 @@ static int didUsbInit = 0;
if(len < 0){ if(len < 0){
if ((vendorName != NULL) && (vendorName[0] != 0)) { if ((vendorName != NULL) && (vendorName[0] != 0)) {
errorCode = USB_ERROR_IO; errorCode = USB_ERROR_IO;
avrdude_message(MSG_INFO, "%s: Warning: cannot query manufacturer for device: %s\n", pmsg_warning("cannot query manufacturer for device: %s\n", usb_strerror());
progname, usb_strerror());
} }
} else { } else {
avrdude_message(MSG_NOTICE2, "%s: seen device from vendor ->%s<-\n", pmsg_notice2("seen device from vendor >%s<\n", string);
progname, string);
if((vendorName != NULL) && (vendorName[0] != 0) && (strcmp(string, vendorName) != 0)) if((vendorName != NULL) && (vendorName[0] != 0) && (strcmp(string, vendorName) != 0))
errorCode = USB_ERROR_NOTFOUND; errorCode = USB_ERROR_NOTFOUND;
} }
@ -521,12 +509,10 @@ static int didUsbInit = 0;
if(len < 0){ if(len < 0){
if ((productName != NULL) && (productName[0] != 0)) { if ((productName != NULL) && (productName[0] != 0)) {
errorCode = USB_ERROR_IO; errorCode = USB_ERROR_IO;
avrdude_message(MSG_INFO, "%s: Warning: cannot query product for device: %s\n", pmsg_warning("cannot query product for device: %s\n", usb_strerror());
progname, usb_strerror());
} }
} else { } else {
avrdude_message(MSG_NOTICE2, "%s: seen product ->%s<-\n", pmsg_notice2("seen product >%s<\n", string);
progname, string);
if((productName != NULL) && (productName[0] != 0) && (strcmp(string, productName) != 0)) if((productName != NULL) && (productName[0] != 0) && (strcmp(string, productName) != 0))
errorCode = USB_ERROR_NOTFOUND; errorCode = USB_ERROR_NOTFOUND;
} }
@ -550,8 +536,7 @@ static int didUsbInit = 0;
/* Interface - prog. */ /* Interface - prog. */
static int usbasp_open(PROGRAMMER *pgm, const char *port) { static int usbasp_open(PROGRAMMER *pgm, const char *port) {
avrdude_message(MSG_DEBUG, "%s: usbasp_open(\"%s\")\n", pmsg_debug("usbasp_open(\"%s\")\n", port);
progname, port);
/* usb_init will be done in usbOpenDevice */ /* usb_init will be done in usbOpenDevice */
LNODEID usbpid = lfirst(pgm->usbpid); LNODEID usbpid = lfirst(pgm->usbpid);
@ -559,8 +544,7 @@ static int usbasp_open(PROGRAMMER *pgm, const char *port) {
if (usbpid) { if (usbpid) {
pid = *(int *)(ldata(usbpid)); pid = *(int *)(ldata(usbpid));
if (lnext(usbpid)) if (lnext(usbpid))
avrdude_message(MSG_INFO, "%s: Warning: using PID 0x%04x, ignoring remaining PIDs in list\n", pmsg_warning("using PID 0x%04x, ignoring remaining PIDs in list\n", pid);
progname, pid);
} else { } else {
pid = USBASP_SHARED_PID; pid = USBASP_SHARED_PID;
} }
@ -570,14 +554,11 @@ static int usbasp_open(PROGRAMMER *pgm, const char *port) {
if(strcasecmp(ldata(lfirst(pgm->id)), "usbasp") == 0) { if(strcasecmp(ldata(lfirst(pgm->id)), "usbasp") == 0) {
/* for id usbasp autodetect some variants */ /* for id usbasp autodetect some variants */
if(strcasecmp(port, "nibobee") == 0) { if(strcasecmp(port, "nibobee") == 0) {
avrdude_message(MSG_INFO, "%s: warning: Using \"-C usbasp -P nibobee\" is deprecated," pmsg_error("using -C usbasp -P nibobee is deprecated, use -C nibobee instead\n");
"use \"-C nibobee\" instead.\n",
progname);
if (usbOpenDevice(&PDATA(pgm)->usbhandle, USBASP_NIBOBEE_VID, "www.nicai-systems.com", if (usbOpenDevice(&PDATA(pgm)->usbhandle, USBASP_NIBOBEE_VID, "www.nicai-systems.com",
USBASP_NIBOBEE_PID, "NIBObee") != 0) { USBASP_NIBOBEE_PID, "NIBObee") != 0) {
avrdude_message(MSG_INFO, "%s: error: could not find USB device " pmsg_error("cannot find USB device NIBObee with vid=0x%x pid=0x%x\n",
"\"NIBObee\" with vid=0x%x pid=0x%x\n", USBASP_NIBOBEE_VID, USBASP_NIBOBEE_PID);
progname, USBASP_NIBOBEE_VID, USBASP_NIBOBEE_PID);
return -1; return -1;
} }
return 0; return 0;
@ -586,24 +567,21 @@ static int usbasp_open(PROGRAMMER *pgm, const char *port) {
if (usbOpenDevice(&PDATA(pgm)->usbhandle, USBASP_OLD_VID, "www.fischl.de", if (usbOpenDevice(&PDATA(pgm)->usbhandle, USBASP_OLD_VID, "www.fischl.de",
USBASP_OLD_PID, "USBasp") == 0) { USBASP_OLD_PID, "USBasp") == 0) {
/* found USBasp with old IDs */ /* found USBasp with old IDs */
avrdude_message(MSG_INFO, "%s: Warning: Found USB device \"USBasp\" with " pmsg_error("found USB device USBasp with old VID/PID; please update firmware of USBasp\n");
"old VID/PID! Please update firmware of USBasp!\n",
progname);
return 0; return 0;
} }
/* original USBasp is specified in config file, so no need to check it again here */ /* original USBasp is specified in config file, so no need to check it again here */
/* no alternative found => fall through to generic error message */ /* no alternative found => fall through to generic error message */
} }
avrdude_message(MSG_INFO, "%s: error: could not find USB device with vid=0x%x pid=0x%x", pmsg_error("cannot find USB device with vid=0x%x pid=0x%x", vid, pid);
progname, vid, pid);
if (pgm->usbvendor[0] != 0) { if (pgm->usbvendor[0] != 0) {
avrdude_message(MSG_INFO, " vendor='%s'", pgm->usbvendor); msg_error(" vendor='%s'", pgm->usbvendor);
} }
if (pgm->usbproduct[0] != 0) { if (pgm->usbproduct[0] != 0) {
avrdude_message(MSG_INFO, " product='%s'", pgm->usbproduct); msg_error(" product='%s'", pgm->usbproduct);
} }
avrdude_message(MSG_INFO, "\n"); msg_error("\n");
return -1; return -1;
} }
@ -612,7 +590,7 @@ static int usbasp_open(PROGRAMMER *pgm, const char *port) {
static void usbasp_close(PROGRAMMER * pgm) static void usbasp_close(PROGRAMMER * pgm)
{ {
avrdude_message(MSG_DEBUG, "%s: usbasp_close()\n", progname); pmsg_debug("usbasp_close()\n");
if (PDATA(pgm)->usbhandle!=NULL) { if (PDATA(pgm)->usbhandle!=NULL) {
unsigned char temp[4]; unsigned char temp[4];
@ -665,7 +643,7 @@ static int usbasp_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
unsigned char res[4]; unsigned char res[4];
IMPORT_PDATA(pgm); IMPORT_PDATA(pgm);
avrdude_message(MSG_DEBUG, "%s: usbasp_initialize()\n", progname); pmsg_debug("usbasp_initialize()\n");
/* get capabilities */ /* get capabilities */
memset(temp, 0, sizeof(temp)); memset(temp, 0, sizeof(temp));
@ -712,23 +690,20 @@ static int usbasp_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
static int usbasp_spi_cmd(const PROGRAMMER *pgm, const unsigned char *cmd, static int usbasp_spi_cmd(const PROGRAMMER *pgm, const unsigned char *cmd,
unsigned char *res) unsigned char *res)
{ {
avrdude_message(MSG_DEBUG, "%s: usbasp_spi_cmd(0x%02x, 0x%02x, 0x%02x, 0x%02x)%s", pmsg_debug("usbasp_spi_cmd(0x%02x, 0x%02x, 0x%02x, 0x%02x)%s",
progname, cmd[0], cmd[1], cmd[2], cmd[3], cmd[0], cmd[1], cmd[2], cmd[3], verbose > 3? " ...\n": "");
verbose > 3? "...\n": "");
int nbytes = int nbytes =
usbasp_transmit(pgm, 1, USBASP_FUNC_TRANSMIT, cmd, res, 4); usbasp_transmit(pgm, 1, USBASP_FUNC_TRANSMIT, cmd, res, 4);
if(nbytes != 4){ if(nbytes != 4){
if (verbose == 3) msg_debug("\n");
putc('\n', stderr);
avrdude_message(MSG_INFO, "%s: error: wrong response size\n", pmsg_error("wrong response size\n");
progname);
return -1; return -1;
} }
avrdude_message(MSG_TRACE, "%s: usbasp_spi_cmd()", progname); pmsg_trace("usbasp_spi_cmd()");
avrdude_message(MSG_DEBUG, " => 0x%02x, 0x%02x, 0x%02x, 0x%02x\n", msg_debug(" => 0x%02x, 0x%02x, 0x%02x, 0x%02x\n",
res[0], res[1], res[2], res[3]); res[0], res[1], res[2], res[3]);
return 0; return 0;
@ -742,15 +717,13 @@ static int usbasp_spi_program_enable(const PROGRAMMER *pgm, const AVRPART *p) {
cmd[0] = 0; cmd[0] = 0;
avrdude_message(MSG_DEBUG, "%s: usbasp_program_enable()\n", pmsg_debug("usbasp_program_enable()\n");
progname);
int nbytes = int nbytes =
usbasp_transmit(pgm, 1, USBASP_FUNC_ENABLEPROG, cmd, res, sizeof(res)); usbasp_transmit(pgm, 1, USBASP_FUNC_ENABLEPROG, cmd, res, sizeof(res));
if ((nbytes != 1) | (res[0] != 0)) { if ((nbytes != 1) | (res[0] != 0)) {
avrdude_message(MSG_INFO, "%s: error: program enable: target doesn't answer. %x \n", pmsg_error("program enable: target does not answer (0x%02x)\n", res[0]);
progname, res[0]);
return -1; return -1;
} }
@ -761,12 +734,10 @@ static int usbasp_spi_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) {
unsigned char cmd[4]; unsigned char cmd[4];
unsigned char res[4]; unsigned char res[4];
avrdude_message(MSG_DEBUG, "%s: usbasp_chip_erase()\n", pmsg_debug("usbasp_chip_erase()\n");
progname);
if (p->op[AVR_OP_CHIP_ERASE] == NULL) { if (p->op[AVR_OP_CHIP_ERASE] == NULL) {
avrdude_message(MSG_INFO, "chip erase instruction not defined for part \"%s\"\n", pmsg_error("chip erase instruction not defined for part %s\n", p->desc);
p->desc);
return -1; return -1;
} }
@ -790,8 +761,7 @@ static int usbasp_spi_paged_load(const PROGRAMMER *pgm, const AVRPART *p, const
unsigned char *buffer = m->buf + address; unsigned char *buffer = m->buf + address;
int function; int function;
avrdude_message(MSG_DEBUG, "%s: usbasp_program_paged_load(\"%s\", 0x%x, %d)\n", pmsg_debug("usbasp_program_paged_load(\"%s\", 0x%x, %d)\n", m->desc, address, n_bytes);
progname, m->desc, address, n_bytes);
if (strcmp(m->desc, "flash") == 0) { if (strcmp(m->desc, "flash") == 0) {
function = USBASP_FUNC_READFLASH; function = USBASP_FUNC_READFLASH;
@ -834,8 +804,7 @@ static int usbasp_spi_paged_load(const PROGRAMMER *pgm, const AVRPART *p, const
n = usbasp_transmit(pgm, 1, function, cmd, buffer, blocksize); n = usbasp_transmit(pgm, 1, function, cmd, buffer, blocksize);
if (n != blocksize) { if (n != blocksize) {
avrdude_message(MSG_INFO, "%s: error: wrong reading bytes %x\n", pmsg_error("wrong reading bytes %x\n", n);
progname, n);
return -3; return -3;
} }
@ -857,8 +826,7 @@ static int usbasp_spi_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const
unsigned char blockflags = USBASP_BLOCKFLAG_FIRST; unsigned char blockflags = USBASP_BLOCKFLAG_FIRST;
int function; int function;
avrdude_message(MSG_DEBUG, "%s: usbasp_program_paged_write(\"%s\", 0x%x, %d)\n", pmsg_debug("usbasp_program_paged_write(\"%s\", 0x%x, %d)\n", m->desc, address, n_bytes);
progname, m->desc, address, n_bytes);
if (strcmp(m->desc, "flash") == 0) { if (strcmp(m->desc, "flash") == 0) {
function = USBASP_FUNC_WRITEFLASH; function = USBASP_FUNC_WRITEFLASH;
@ -905,8 +873,7 @@ static int usbasp_spi_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const
n = usbasp_transmit(pgm, 0, function, cmd, buffer, blocksize); n = usbasp_transmit(pgm, 0, function, cmd, buffer, blocksize);
if (n != blocksize) { if (n != blocksize) {
avrdude_message(MSG_INFO, "%s: error: wrong count at writing %x\n", pmsg_error("wrong count at writing %x\n", n);
progname, n);
return -3; return -3;
} }
@ -944,8 +911,7 @@ static int usbasp_spi_set_sck_period(const PROGRAMMER *pgm, double sckperiod) {
unsigned char res[4]; unsigned char res[4];
unsigned char cmd[4]; unsigned char cmd[4];
avrdude_message(MSG_DEBUG, "%s: usbasp_spi_set_sck_period(%g)\n", pmsg_debug("usbasp_spi_set_sck_period(%g)\n", sckperiod);
progname, sckperiod);
memset(cmd, 0, sizeof(cmd)); memset(cmd, 0, sizeof(cmd));
memset(res, 0, sizeof(res)); memset(res, 0, sizeof(res));
@ -956,22 +922,22 @@ static int usbasp_spi_set_sck_period(const PROGRAMMER *pgm, double sckperiod) {
if (sckperiod == 0) { if (sckperiod == 0) {
/* auto sck set */ /* auto sck set */
avrdude_message(MSG_NOTICE, "%s: auto set sck period (because given equals null)\n", progname); pmsg_notice("auto set sck period (because given equals null)\n");
} else { } else {
int sckfreq = 1 / sckperiod; /* sck in Hz */ int sckfreq = 1 / sckperiod; /* sck in Hz */
int usefreq = 0; int usefreq = 0;
avrdude_message(MSG_NOTICE2, "%s: try to set SCK period to %g s (= %i Hz)\n", progname, sckperiod, sckfreq); pmsg_notice2("try to set SCK period to %g s (= %i Hz)\n", sckperiod, sckfreq);
/* Check if programmer is capable of 3 MHz SCK, if not then ommit 3 MHz setting */ /* Check if programmer is capable of 3 MHz SCK, if not then ommit 3 MHz setting */
int i; int i;
if (PDATA(pgm)->sck_3mhz) { if (PDATA(pgm)->sck_3mhz) {
avrdude_message(MSG_NOTICE2, "%s: connected USBasp is capable of 3 MHz SCK\n",progname); pmsg_notice2("connected USBasp is capable of 3 MHz SCK\n");
i = 0; i = 0;
} else { } else {
avrdude_message(MSG_NOTICE2, "%s: connected USBasp is not cabable of 3 MHz SCK\n",progname); pmsg_notice2("connected USBasp is not cabable of 3 MHz SCK\n");
i = 1; i = 1;
} }
if (sckfreq >= usbaspSCKoptions[i].frequency) { if (sckfreq >= usbaspSCKoptions[i].frequency) {
@ -993,7 +959,7 @@ static int usbasp_spi_set_sck_period(const PROGRAMMER *pgm, double sckperiod) {
/* save used sck frequency */ /* save used sck frequency */
PDATA(pgm)->sckfreq_hz = usefreq; PDATA(pgm)->sckfreq_hz = usefreq;
avrdude_message(MSG_INFO, "%s: set SCK frequency to %i Hz\n", progname, usefreq); pmsg_info("set SCK frequency to %i Hz\n", usefreq);
} }
cmd[0] = clockoption; cmd[0] = clockoption;
@ -1002,8 +968,7 @@ static int usbasp_spi_set_sck_period(const PROGRAMMER *pgm, double sckperiod) {
usbasp_transmit(pgm, 1, USBASP_FUNC_SETISPSCK, cmd, res, sizeof(res)); usbasp_transmit(pgm, 1, USBASP_FUNC_SETISPSCK, cmd, res, sizeof(res));
if ((nbytes != 1) | (res[0] != 0)) { if ((nbytes != 1) | (res[0] != 0)) {
avrdude_message(MSG_INFO, "%s: warning: cannot set sck period. please check for usbasp firmware update.\n", pmsg_error("cannot set sck period; please check for usbasp firmware update\n");
progname);
return -1; return -1;
} }
@ -1027,7 +992,7 @@ static int usbasp_tpi_recv_byte(const PROGRAMMER *pgm) {
if(usbasp_transmit(pgm, 1, USBASP_FUNC_TPI_RAWREAD, temp, temp, sizeof(temp)) != 1) if(usbasp_transmit(pgm, 1, USBASP_FUNC_TPI_RAWREAD, temp, temp, sizeof(temp)) != 1)
{ {
avrdude_message(MSG_INFO, "%s: error: wrong response size\n", progname); pmsg_error("wrong response size\n");
return -1; return -1;
} }
@ -1038,7 +1003,7 @@ static int usbasp_tpi_recv_byte(const PROGRAMMER *pgm) {
static int usbasp_tpi_nvm_waitbusy(const PROGRAMMER *pgm) { static int usbasp_tpi_nvm_waitbusy(const PROGRAMMER *pgm) {
int retry; int retry;
avrdude_message(MSG_DEBUG, "%s: usbasp_tpi_nvm_waitbusy() ...", progname); pmsg_debug("usbasp_tpi_nvm_waitbusy() ...");
for(retry=50; retry>0; retry--) for(retry=50; retry>0; retry--)
{ {
@ -1046,25 +1011,25 @@ static int usbasp_tpi_nvm_waitbusy(const PROGRAMMER *pgm) {
if(usbasp_tpi_recv_byte(pgm) & NVMCSR_BSY) if(usbasp_tpi_recv_byte(pgm) & NVMCSR_BSY)
continue; continue;
avrdude_message(MSG_DEBUG, " ready\n"); msg_debug(" ready\n");
return 0; return 0;
} }
avrdude_message(MSG_DEBUG, " failure\n"); msg_debug(" failure\n");
return -1; return -1;
} }
static int usbasp_tpi_cmd(const PROGRAMMER *pgm, const unsigned char *cmd, unsigned char *res) { static int usbasp_tpi_cmd(const PROGRAMMER *pgm, const unsigned char *cmd, unsigned char *res) {
avrdude_message(MSG_INFO, "%s: error: spi_cmd used in TPI mode: not allowed\n", progname); pmsg_error("spi_cmd used in TPI mode: not allowed\n");
return -1; return -1;
} }
static int usbasp_tpi_program_enable(const PROGRAMMER *pgm, const AVRPART *p) { static int usbasp_tpi_program_enable(const PROGRAMMER *pgm, const AVRPART *p) {
int retry; int retry;
avrdude_message(MSG_DEBUG, "%s: usbasp_tpi_program_enable()\n", progname); pmsg_debug("usbasp_tpi_program_enable()\n");
/* change guard time */ /* change guard time */
usbasp_tpi_send_byte(pgm, TPI_OP_SSTCS(TPIPCR)); usbasp_tpi_send_byte(pgm, TPI_OP_SSTCS(TPIPCR));
@ -1094,7 +1059,7 @@ static int usbasp_tpi_program_enable(const PROGRAMMER *pgm, const AVRPART *p) {
} }
if(retry >= 10) if(retry >= 10)
{ {
avrdude_message(MSG_INFO, "%s: error: program enable: target doesn't answer.\n", progname); pmsg_error("program enable, target does not answer\n");
return -1; return -1;
} }
@ -1112,14 +1077,14 @@ static int usbasp_tpi_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) {
pr_0 = 0x41; pr_0 = 0x41;
pr_1 = 0x3F; pr_1 = 0x3F;
nvm_cmd = NVMCMD_SECTION_ERASE; nvm_cmd = NVMCMD_SECTION_ERASE;
avrdude_message(MSG_DEBUG, "%s: usbasp_tpi_chip_erase() - section erase\n", progname); pmsg_debug("usbasp_tpi_chip_erase() - section erase\n");
break; break;
/* Chip erase (flash only) */ /* Chip erase (flash only) */
default: default:
pr_0 = 0x01; pr_0 = 0x01;
pr_1 = 0x40; pr_1 = 0x40;
nvm_cmd = NVMCMD_CHIP_ERASE; nvm_cmd = NVMCMD_CHIP_ERASE;
avrdude_message(MSG_DEBUG, "%s: usbasp_tpi_chip_erase() - chip erase\n", progname); pmsg_debug("usbasp_tpi_chip_erase() - chip erase\n");
break; break;
} }
@ -1151,8 +1116,7 @@ static int usbasp_tpi_paged_load(const PROGRAMMER *pgm, const AVRPART *p, const
uint16_t pr; uint16_t pr;
avrdude_message(MSG_DEBUG, "%s: usbasp_tpi_paged_load(\"%s\", 0x%0x, %d)\n", pmsg_debug("usbasp_tpi_paged_load(\"%s\", 0x%0x, %d)\n", m->desc, addr, n_bytes);
progname, m->desc, addr, n_bytes);
dptr = addr + m->buf; dptr = addr + m->buf;
pr = addr + m->offset; pr = addr + m->offset;
@ -1172,7 +1136,7 @@ static int usbasp_tpi_paged_load(const PROGRAMMER *pgm, const AVRPART *p, const
n = usbasp_transmit(pgm, 1, USBASP_FUNC_TPI_READBLOCK, cmd, dptr, clen); n = usbasp_transmit(pgm, 1, USBASP_FUNC_TPI_READBLOCK, cmd, dptr, clen);
if(n != clen) if(n != clen)
{ {
avrdude_message(MSG_INFO, "%s: error: wrong reading bytes %x\n", progname, n); pmsg_error("wrong reading bytes %x\n", n);
return -3; return -3;
} }
@ -1193,8 +1157,7 @@ static int usbasp_tpi_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const
uint16_t pr; uint16_t pr;
avrdude_message(MSG_DEBUG, "%s: usbasp_tpi_paged_write(\"%s\", 0x%0x, %d)\n", pmsg_debug("usbasp_tpi_paged_write(\"%s\", 0x%0x, %d)\n", m->desc, addr, n_bytes);
progname, m->desc, addr, n_bytes);
sptr = addr + m->buf; sptr = addr + m->buf;
pr = addr + m->offset; pr = addr + m->offset;
@ -1238,7 +1201,7 @@ static int usbasp_tpi_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const
n = usbasp_transmit(pgm, 0, USBASP_FUNC_TPI_WRITEBLOCK, cmd, sptr, clen); n = usbasp_transmit(pgm, 0, USBASP_FUNC_TPI_WRITEBLOCK, cmd, sptr, clen);
if(n != clen) if(n != clen)
{ {
avrdude_message(MSG_INFO, "%s: error: wrong count at writing %x\n", progname, n); pmsg_error("wrong count at writing %x\n", n);
return -3; return -3;
} }
@ -1260,8 +1223,7 @@ static int usbasp_tpi_read_byte(const PROGRAMMER * pgm, const AVRPART *p, const
uint16_t pr; uint16_t pr;
avrdude_message(MSG_DEBUG, "%s: usbasp_tpi_read_byte(\"%s\", 0x%0lx)\n", pmsg_debug("usbasp_tpi_read_byte(\"%s\", 0x%0lx)\n", m->desc, addr);
progname, m->desc, addr);
pr = m->offset + addr; pr = m->offset + addr;
@ -1273,7 +1235,7 @@ static int usbasp_tpi_read_byte(const PROGRAMMER * pgm, const AVRPART *p, const
n = usbasp_transmit(pgm, 1, USBASP_FUNC_TPI_READBLOCK, cmd, value, 1); n = usbasp_transmit(pgm, 1, USBASP_FUNC_TPI_READBLOCK, cmd, value, 1);
if(n != 1) if(n != 1)
{ {
avrdude_message(MSG_INFO, "%s: error: wrong reading bytes %x\n", progname, n); pmsg_error("wrong reading bytes %x\n", n);
return -3; return -3;
} }
return 0; return 0;
@ -1282,7 +1244,7 @@ static int usbasp_tpi_read_byte(const PROGRAMMER * pgm, const AVRPART *p, const
static int usbasp_tpi_write_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m, static int usbasp_tpi_write_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m,
unsigned long addr, unsigned char data) { // FIXME: use avr_write_byte_cache() when implemented unsigned long addr, unsigned char data) { // FIXME: use avr_write_byte_cache() when implemented
avrdude_message(MSG_INFO, "%s: error: usbasp_write_byte in TPI mode: all writes have to be done at page level\n", progname); pmsg_error("usbasp_write_byte in TPI mode; all writes have to be done at page level\n");
return -1; return -1;
} }
@ -1323,8 +1285,7 @@ void usbasp_initpgm(PROGRAMMER *pgm) {
#else /* HAVE_LIBUSB */ #else /* HAVE_LIBUSB */
static int usbasp_nousb_open(PROGRAMMER *pgm, const char *name) { static int usbasp_nousb_open(PROGRAMMER *pgm, const char *name) {
avrdude_message(MSG_INFO, "%s: error: no usb support. please compile again with libusb installed.\n", pmsg_error("no usb support; please compile again with libusb installed\n");
progname);
return -1; return -1;
} }

View File

@ -79,8 +79,7 @@ struct pdata
static void usbtiny_setup(PROGRAMMER * pgm) static void usbtiny_setup(PROGRAMMER * pgm)
{ {
if ((pgm->cookie = malloc(sizeof(struct pdata))) == 0) { if ((pgm->cookie = malloc(sizeof(struct pdata))) == 0) {
avrdude_message(MSG_INFO, "%s: usbtiny_setup(): Out of memory allocating private data\n", pmsg_error("out of memory allocating private data\n");
progname);
exit(1); exit(1);
} }
memset(pgm->cookie, 0, sizeof(struct pdata)); memset(pgm->cookie, 0, sizeof(struct pdata));
@ -103,7 +102,8 @@ static int usb_control (const PROGRAMMER *pgm,
NULL, 0, // no data buffer in control message NULL, 0, // no data buffer in control message
USB_TIMEOUT ); // default timeout USB_TIMEOUT ); // default timeout
if(nbytes < 0){ if(nbytes < 0){
avrdude_message(MSG_INFO, "\n%s: error: usbtiny_transmit: %s\n", progname, usb_strerror()); msg_error("\n");
pmsg_error("%s\n", usb_strerror());
return -1; return -1;
} }
@ -135,17 +135,15 @@ static int usb_in (const PROGRAMMER *pgm,
} }
PDATA(pgm)->retries++; PDATA(pgm)->retries++;
} }
avrdude_message(MSG_INFO, "\n%s: error: usbtiny_receive: %s (expected %d, got %d)\n", msg_error("\n");
progname, usb_strerror(), buflen, nbytes); pmsg_error("%s (expected %d, got %d)\n", usb_strerror(), buflen, nbytes);
return -1; return -1;
} }
// Report the number of retries, and reset the counter. // Report the number of retries, and reset the counter.
static void check_retries (const PROGRAMMER *pgm, const char *operation) { static void check_retries (const PROGRAMMER *pgm, const char *operation) {
if (PDATA(pgm)->retries > 0 && quell_progress < 2) { if (PDATA(pgm)->retries > 0)
avrdude_message(MSG_INFO, "%s: %d retries during %s\n", progname, pmsg_info("%d retries during %s\n", PDATA(pgm)->retries, operation);
PDATA(pgm)->retries, operation);
}
PDATA(pgm)->retries = 0; PDATA(pgm)->retries = 0;
} }
@ -168,8 +166,8 @@ static int usb_out (const PROGRAMMER *pgm,
(char *)buffer, buflen, (char *)buffer, buflen,
timeout); timeout);
if (nbytes != buflen) { if (nbytes != buflen) {
avrdude_message(MSG_INFO, "\n%s: error: usbtiny_send: %s (expected %d, got %d)\n", msg_error("\n");
progname, usb_strerror(), buflen, nbytes); pmsg_error("%s (expected %d, got %d)\n", usb_strerror(), buflen, nbytes);
return -1; return -1;
} }
@ -223,8 +221,7 @@ static int usbtiny_tpi_tx(const PROGRAMMER *pgm, unsigned char b0) {
if (usb_in(pgm, USBTINY_SPI, tpi_frame(b0), 0xffff, if (usb_in(pgm, USBTINY_SPI, tpi_frame(b0), 0xffff,
res, sizeof(res), 8 * sizeof(res) * PDATA(pgm)->sck_period) < 0) res, sizeof(res), 8 * sizeof(res) * PDATA(pgm)->sck_period) < 0)
return -1; return -1;
if (verbose > 1) msg_notice2("CMD_TPI_TX: [0x%02x]\n", b0);
fprintf(stderr, "CMD_TPI_TX: [0x%02x]\n", b0);
return 1; return 1;
} }
@ -238,8 +235,7 @@ static int usbtiny_tpi_txtx(const PROGRAMMER *pgm,
if (usb_in(pgm, USBTINY_SPI, tpi_frame(b0), tpi_frame(b1), if (usb_in(pgm, USBTINY_SPI, tpi_frame(b0), tpi_frame(b1),
res, sizeof(res), 8 * sizeof(res) * PDATA(pgm)->sck_period) < 0) res, sizeof(res), 8 * sizeof(res) * PDATA(pgm)->sck_period) < 0)
return -1; return -1;
if (verbose > 1) msg_notice2("CMD_TPI_TX_TX: [0x%02x 0x%02x]\n", b0, b1);
fprintf(stderr, "CMD_TPI_TX_TX: [0x%02x 0x%02x]\n", b0, b1);
return 1; return 1;
} }
@ -264,16 +260,15 @@ static int usbtiny_tpi_txrx(const PROGRAMMER *pgm, unsigned char b0) {
bit and the 8 data bits, but the latter in reverse order. */ bit and the 8 data bits, but the latter in reverse order. */
r = reverse(w >> 7); r = reverse(w >> 7);
if (tpi_parity(r) != ((w >> 6) & 1)) { if (tpi_parity(r) != ((w >> 6) & 1)) {
fprintf(stderr, "%s: parity bit is wrong\n", __func__); pmsg_error("parity bit is wrong\n");
return -1; return -1;
} }
if (((w >> 4) & 0x3) != TPI_STOP_BITS) { if (((w >> 4) & 0x3) != TPI_STOP_BITS) {
fprintf(stderr, "%s: stop bits not received correctly\n", __func__); pmsg_error("stop bits not received correctly\n");
return -1; return -1;
} }
if (verbose > 1) msg_notice2("CMD_TPI_TX_RX: [0x%02x -> 0x%02x]\n", b0, r);
fprintf(stderr, "CMD_TPI_TX_RX: [0x%02x -> 0x%02x]\n", b0, r);
return r; return r;
} }
@ -288,7 +283,7 @@ static int usbtiny_avr_op (const PROGRAMMER *pgm, const AVRPART *p,
unsigned char cmd[4]; unsigned char cmd[4];
if (p->op[op] == NULL) { if (p->op[op] == NULL) {
avrdude_message(MSG_INFO, "Operation %d not defined for this chip!\n", op ); pmsg_error("operation %d not defined for this chip\n", op);
return -1; return -1;
} }
memset(cmd, 0, sizeof(cmd)); memset(cmd, 0, sizeof(cmd));
@ -337,8 +332,7 @@ static int usbtiny_open(PROGRAMMER *pgm, const char *name) {
if (usbpid) { if (usbpid) {
pid = *(int *)(ldata(usbpid)); pid = *(int *)(ldata(usbpid));
if (lnext(usbpid)) if (lnext(usbpid))
avrdude_message(MSG_INFO, "%s: Warning: using PID 0x%04x, ignoring remaining PIDs in list\n", pmsg_warning("using PID 0x%04x, ignoring remaining PIDs in list\n", pid);
progname, pid);
} else { } else {
pid = USBTINY_PRODUCT_DEFAULT; pid = USBTINY_PRODUCT_DEFAULT;
} }
@ -349,8 +343,7 @@ static int usbtiny_open(PROGRAMMER *pgm, const char *name) {
for ( dev = bus->devices; dev; dev = dev->next ) { for ( dev = bus->devices; dev; dev = dev->next ) {
if (dev->descriptor.idVendor == vid if (dev->descriptor.idVendor == vid
&& dev->descriptor.idProduct == pid ) { // found match? && dev->descriptor.idProduct == pid ) { // found match?
avrdude_message(MSG_NOTICE, "%s: usbdev_open(): Found USBtinyISP, bus:device: %s:%s\n", pmsg_notice("usbdev_open(): found USBtinyISP, bus:device: %s:%s\n", bus->dirname, dev->filename);
progname, bus->dirname, dev->filename);
// if -P was given, match device by device name and bus name // if -P was given, match device by device name and bus name
if(name != NULL && if(name != NULL &&
(NULL == dev_name || (NULL == dev_name ||
@ -361,8 +354,7 @@ static int usbtiny_open(PROGRAMMER *pgm, const char *name) {
// wrong permissions or something? // wrong permissions or something?
if (!PDATA(pgm)->usb_handle) { if (!PDATA(pgm)->usb_handle) {
avrdude_message(MSG_INFO, "%s: Warning: cannot open USB device: %s\n", pmsg_warning("cannot open USB device: %s\n", usb_strerror());
progname, usb_strerror());
continue; continue;
} }
} }
@ -370,13 +362,12 @@ static int usbtiny_open(PROGRAMMER *pgm, const char *name) {
} }
if(NULL != name && NULL == dev_name) { if(NULL != name && NULL == dev_name) {
avrdude_message(MSG_INFO, "%s: Error: Invalid -P value: '%s'\n", progname, name); pmsg_error("invalid -P value: '%s'\n", name);
avrdude_message(MSG_INFO, "%sUse -P usb:bus:device\n", progbuf); imsg_error("use -P usb:bus:device\n");
return -1; return -1;
} }
if (!PDATA(pgm)->usb_handle) { if (!PDATA(pgm)->usb_handle) {
avrdude_message(MSG_INFO, "%s: Error: Could not find USBtiny device (0x%x/0x%x)\n", pmsg_error("cannot find USBtiny device (0x%x/0x%x)\n", vid, pid );
progname, vid, pid );
return -1; return -1;
} }
@ -418,7 +409,7 @@ static int usbtiny_set_sck_period (const PROGRAMMER *pgm, double v) {
if (PDATA(pgm)->sck_period > SCK_MAX) if (PDATA(pgm)->sck_period > SCK_MAX)
PDATA(pgm)->sck_period = SCK_MAX; PDATA(pgm)->sck_period = SCK_MAX;
avrdude_message(MSG_NOTICE, "%s: Setting SCK period to %d usec\n", progname, pmsg_notice("setting SCK period to %d usec\n",
PDATA(pgm)->sck_period ); PDATA(pgm)->sck_period );
// send the command to the usbtiny device. // send the command to the usbtiny device.
@ -443,8 +434,7 @@ static int usbtiny_initialize (const PROGRAMMER *pgm, const AVRPART *p ) {
} else { } else {
// -B option not specified: use default // -B option not specified: use default
PDATA(pgm)->sck_period = SCK_DEFAULT; PDATA(pgm)->sck_period = SCK_DEFAULT;
avrdude_message(MSG_NOTICE, "%s: Using SCK period of %d usec\n", pmsg_notice("using SCK period of %d usec\n", PDATA(pgm)->sck_period );
progname, PDATA(pgm)->sck_period );
if (usb_control(pgm, USBTINY_POWERUP, if (usb_control(pgm, USBTINY_POWERUP,
PDATA(pgm)->sck_period, RESET_LOW ) < 0) PDATA(pgm)->sck_period, RESET_LOW ) < 0)
return -1; return -1;
@ -458,21 +448,19 @@ static int usbtiny_initialize (const PROGRAMMER *pgm, const AVRPART *p ) {
/* Since there is a single TPIDATA line, MOSI and MISO must be /* Since there is a single TPIDATA line, MOSI and MISO must be
linked together through a 1kOhm resistor. Verify that linked together through a 1kOhm resistor. Verify that
everything we send on MOSI gets mirrored back on MISO. */ everything we send on MOSI gets mirrored back on MISO. */
if (verbose >= 2) msg_notice2("doing MOSI-MISO link check\n");
fprintf(stderr, "doing MOSI-MISO link check\n");
memset(res, 0xaa, sizeof(res)); memset(res, 0xaa, sizeof(res));
if (usb_in(pgm, USBTINY_SPI, LITTLE_TO_BIG_16(0x1234), LITTLE_TO_BIG_16(0x5678), if (usb_in(pgm, USBTINY_SPI, LITTLE_TO_BIG_16(0x1234), LITTLE_TO_BIG_16(0x5678),
res, 4, 32 * PDATA(pgm)->sck_period) < 0) { res, 4, 32 * PDATA(pgm)->sck_period) < 0) {
fprintf(stderr, "usb_in() failed\n"); pmsg_error("usb_in() failed\n");
return -1; return -1;
} }
if (res[0] != 0x12 || res[1] != 0x34 || res[2] != 0x56 || res[3] != 0x78) { if (res[0] != 0x12 || res[1] != 0x34 || res[2] != 0x56 || res[3] != 0x78) {
fprintf(stderr, pmsg_error("MOSI->MISO check failed (got 0x%02x 0x%02x 0x%02x 0x%02x)\n"
"MOSI->MISO check failed (got 0x%02x 0x%02x 0x%02x 0x%02x)\n" "\tplease verify that MISO is connected directly to TPIDATA and\n"
"\tPlease verify that MISO is connected directly to TPIDATA and\n" "\tMOSI is connected to TPIDATA through a 1kOhm resistor\n",
"\tMOSI is connected to TPIDATA through a 1kOhm resistor.\n", res[0], res[1], res[2], res[3]);
res[0], res[1], res[2], res[3]);
return -1; return -1;
} }
@ -480,7 +468,7 @@ static int usbtiny_initialize (const PROGRAMMER *pgm, const AVRPART *p ) {
if (usb_in(pgm, USBTINY_SPI, 0xffff, 0xffff, res, 4, if (usb_in(pgm, USBTINY_SPI, 0xffff, 0xffff, res, 4,
32 * PDATA(pgm)->sck_period) < 0) 32 * PDATA(pgm)->sck_period) < 0)
{ {
fprintf(stderr, "Unable to switch chip into TPI mode\n"); pmsg_error("unable to switch chip into TPI mode\n");
return -1; return -1;
} }
} }
@ -538,7 +526,7 @@ static int usbtiny_cmd(const PROGRAMMER *pgm, const unsigned char *cmd, unsigned
return -1; return -1;
check_retries(pgm, "SPI command"); check_retries(pgm, "SPI command");
// print out the data we sent and received // print out the data we sent and received
avrdude_message(MSG_NOTICE2, "CMD: [%02x %02x %02x %02x] [%02x %02x %02x %02x]\n", msg_notice2("CMD: [%02x %02x %02x %02x] [%02x %02x %02x %02x]\n",
cmd[0], cmd[1], cmd[2], cmd[3], cmd[0], cmd[1], cmd[2], cmd[3],
res[0], res[1], res[2], res[3] ); res[0], res[1], res[2], res[3] );
return ((nbytes == 4) && // should have read 4 bytes return ((nbytes == 4) && // should have read 4 bytes
@ -574,8 +562,7 @@ int usbtiny_cmd_tpi(const PROGRAMMER *pgm, const unsigned char *cmd,
} }
if (rx < res_len) { if (rx < res_len) {
fprintf(stderr, "%s: unexpected cmd_len=%d/res_len=%d\n", pmsg_error("unexpected cmd_len=%d/res_len=%d\n", cmd_len, res_len);
__func__, cmd_len, res_len);
return -1; return -1;
} }
return 0; return 0;
@ -588,8 +575,7 @@ static int usbtiny_spi(const PROGRAMMER *pgm, const unsigned char *cmd, unsigned
memset(res, 0, count); memset(res, 0, count);
if (count % 4) { if (count % 4) {
avrdude_message(MSG_INFO, "Direct SPI write must be a multiple of 4 bytes for %s\n", pmsg_error("direct SPI write must be a multiple of 4 bytes for %s\n", pgm->type);
pgm->type);
return -1; return -1;
} }
@ -609,8 +595,7 @@ static int usbtiny_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) {
return avr_tpi_chip_erase(pgm, p); return avr_tpi_chip_erase(pgm, p);
if (p->op[AVR_OP_CHIP_ERASE] == NULL) { if (p->op[AVR_OP_CHIP_ERASE] == NULL) {
avrdude_message(MSG_INFO, "Chip erase instruction not defined for part \"%s\"\n", pmsg_error("chip erase instruction not defined for part %s\n", p->desc);
p->desc);
return -1; return -1;
} }
@ -818,8 +803,7 @@ void usbtiny_initpgm(PROGRAMMER *pgm) {
// Give a proper error if we were not compiled with libusb // Give a proper error if we were not compiled with libusb
static int usbtiny_nousb_open(PROGRAMMER *pgm, const char *name) { static int usbtiny_nousb_open(PROGRAMMER *pgm, const char *name) {
avrdude_message(MSG_INFO, "%s: error: no usb support. Please compile again with libusb installed.\n", pmsg_error("no usb support; please compile again with libusb installed\n");
progname);
return -1; return -1;
} }

View File

@ -85,8 +85,7 @@ static void wiring_setup(PROGRAMMER * pgm)
* Now prepare our data * Now prepare our data
*/ */
if ((mycookie = malloc(sizeof(struct wiringpdata))) == 0) { if ((mycookie = malloc(sizeof(struct wiringpdata))) == 0) {
avrdude_message(MSG_INFO, "%s: wiring_setup(): Out of memory allocating private data\n", pmsg_error("out of memory allocating private data\n");
progname);
exit(1); exit(1);
} }
memset(mycookie, 0, sizeof(struct wiringpdata)); memset(mycookie, 0, sizeof(struct wiringpdata));
@ -122,20 +121,17 @@ static int wiring_parseextparms(const PROGRAMMER *pgm, const LISTID extparms) {
int newsnooze; int newsnooze;
if (sscanf(extended_param, "snooze=%i", &newsnooze) != 1 || if (sscanf(extended_param, "snooze=%i", &newsnooze) != 1 ||
newsnooze < 0) { newsnooze < 0) {
avrdude_message(MSG_INFO, "%s: wiring_parseextparms(): invalid snooze time '%s'\n", pmsg_error("invalid snooze time '%s'\n", extended_param);
progname, extended_param);
rv = -1; rv = -1;
continue; continue;
} }
avrdude_message(MSG_NOTICE2, "%s: wiring_parseextparms(): snooze time set to %d ms\n", pmsg_notice2("wiring_parseextparms(): snooze time set to %d ms\n", newsnooze);
progname, newsnooze);
WIRINGPDATA(mycookie)->snoozetime = newsnooze; WIRINGPDATA(mycookie)->snoozetime = newsnooze;
continue; continue;
} }
avrdude_message(MSG_INFO, "%s: wiring_parseextparms(): invalid extended parameter '%s'\n", pmsg_error("invalid extended parameter '%s'\n", extended_param);
progname, extended_param);
rv = -1; rv = -1;
} }
@ -157,20 +153,17 @@ static int wiring_open(PROGRAMMER *pgm, const char *port) {
if (WIRINGPDATA(mycookie)->snoozetime > 0) { if (WIRINGPDATA(mycookie)->snoozetime > 0) {
timetosnooze = WIRINGPDATA(mycookie)->snoozetime; timetosnooze = WIRINGPDATA(mycookie)->snoozetime;
avrdude_message(MSG_NOTICE2, "%s: wiring_open(): snoozing for %d ms\n", pmsg_notice2("wiring_open(): snoozing for %d ms\n", timetosnooze);
progname, timetosnooze);
while (timetosnooze--) while (timetosnooze--)
usleep(1000); usleep(1000);
avrdude_message(MSG_NOTICE2, "%s: wiring_open(): done snoozing\n", pmsg_notice2("wiring_open(): done snoozing\n");
progname);
} else { } else {
/* Perform Wiring programming mode RESET. */ /* Perform Wiring programming mode RESET. */
/* This effectively *releases* both DTR and RTS. */ /* This effectively *releases* both DTR and RTS. */
/* i.e. both DTR and RTS rise to a HIGH logic level */ /* i.e. both DTR and RTS rise to a HIGH logic level */
/* since they are active LOW signals. */ /* since they are active LOW signals. */
avrdude_message(MSG_NOTICE2, "%s: wiring_open(): releasing DTR/RTS\n", pmsg_notice2("wiring_open(): releasing DTR/RTS\n");
progname);
serial_set_dtr_rts(&pgm->fd, 0); serial_set_dtr_rts(&pgm->fd, 0);
usleep(50*1000); usleep(50*1000);
@ -178,8 +171,7 @@ static int wiring_open(PROGRAMMER *pgm, const char *port) {
/* After releasing for 50 milliseconds, DTR and RTS */ /* After releasing for 50 milliseconds, DTR and RTS */
/* are asserted (i.e. logic LOW) again. */ /* are asserted (i.e. logic LOW) again. */
avrdude_message(MSG_NOTICE2, "%s: wiring_open(): asserting DTR/RTS\n", pmsg_notice2("wiring_open(): asserting DTR/RTS\n");
progname);
serial_set_dtr_rts(&pgm->fd, 1); serial_set_dtr_rts(&pgm->fd, 1);
usleep(50*1000); usleep(50*1000);

View File

@ -110,8 +110,7 @@ static int xbee_read_sig_bytes(const PROGRAMMER *pgm, const AVRPART *p, const AV
/* Signature byte reads are always 3 bytes. */ /* Signature byte reads are always 3 bytes. */
if (m->size < 3) { if (m->size < 3) {
avrdude_message(MSG_INFO, "%s: memsize too small for sig byte read\n", pmsg_error("memsize too small for sig byte read\n");
progname);
return -1; return -1;
} }
@ -123,21 +122,16 @@ static int xbee_read_sig_bytes(const PROGRAMMER *pgm, const AVRPART *p, const AV
if (serial_recv(&pgm->fd, buf, 5) < 0) if (serial_recv(&pgm->fd, buf, 5) < 0)
return -1; return -1;
if (buf[0] == Resp_STK_NOSYNC) { if (buf[0] == Resp_STK_NOSYNC) {
avrdude_message(MSG_INFO, "%s: stk500_cmd(): programmer is out of sync\n", pmsg_error("programmer is out of sync\n");
progname);
return -1; return -1;
} else if (buf[0] != Resp_STK_INSYNC) { } else if (buf[0] != Resp_STK_INSYNC) {
avrdude_message(MSG_INFO, msg_error("\n");
"\n%s: xbee_read_sig_bytes(): (a) protocol error, " pmsg_error("protocol expects sync byte 0x%02x but got 0x%02x\n", Resp_STK_INSYNC, buf[0]);
"expect=0x%02x, resp=0x%02x\n",
progname, Resp_STK_INSYNC, buf[0]);
return -2; return -2;
} }
if (buf[4] != Resp_STK_OK) { if (buf[4] != Resp_STK_OK) {
avrdude_message(MSG_INFO, msg_error("\n");
"\n%s: xbee_read_sig_bytes(): (a) protocol error, " pmsg_error("protocol expects OK byte 0x%02x but got 0x%02x\n", Resp_STK_OK, buf[4]);
"expect=0x%02x, resp=0x%02x\n",
progname, Resp_STK_OK, buf[4]);
return -3; return -3;
} }
@ -252,10 +246,8 @@ static void xbeeStatsAdd(struct XBeeStaticticsSummary *summary,
static void xbeeStatsSummarise(struct XBeeStaticticsSummary const *summary) static void xbeeStatsSummarise(struct XBeeStaticticsSummary const *summary)
{ {
avrdude_message(MSG_NOTICE, "%s: Minimum response time: %lu.%06lu\n", pmsg_notice(" Minimum response time: %lu.%06lu\n", summary->minimum.tv_sec, summary->minimum.tv_usec);
progname, summary->minimum.tv_sec, summary->minimum.tv_usec); pmsg_notice(" Maximum response time: %lu.%06lu\n", summary->maximum.tv_sec, summary->maximum.tv_usec);
avrdude_message(MSG_NOTICE, "%s: Maximum response time: %lu.%06lu\n",
progname, summary->maximum.tv_sec, summary->maximum.tv_usec);
struct timeval average; struct timeval average;
@ -268,8 +260,7 @@ static void xbeeStatsSummarise(struct XBeeStaticticsSummary const *summary)
average.tv_sec += usecs / 1000000; average.tv_sec += usecs / 1000000;
average.tv_usec = usecs % 1000000; average.tv_usec = usecs % 1000000;
avrdude_message(MSG_NOTICE, "%s: Average response time: %lu.%06lu\n", pmsg_notice(" Average response time: %lu.%06lu\n", average.tv_sec, average.tv_usec);
progname, average.tv_sec, average.tv_usec);
} }
static void XBeeBootSessionInit(struct XBeeBootSession *xbs) { static void XBeeBootSessionInit(struct XBeeBootSession *xbs) {
@ -319,23 +310,21 @@ static void xbeedev_stats_send(struct XBeeBootSession *xbs,
stats->sendTime = *sendTime; stats->sendTime = *sendTime;
if (detailSequence >= 0) { if (detailSequence >= 0) {
avrdude_message(MSG_NOTICE2, pmsg_notice2("stats: send Group %s Sequence %u : "
"%s: Stats: Send Group %s Sequence %u : " "Send %lu.%06lu %s Sequence %d\n",
"Send %lu.%06lu %s Sequence %d\n", groupNames[group],
progname, groupNames[group], (unsigned int) sequence,
(unsigned int)sequence, (unsigned long) sendTime->tv_sec,
(unsigned long)sendTime->tv_sec, (unsigned long) sendTime->tv_usec,
(unsigned long)sendTime->tv_usec, detail, detailSequence);
detail, detailSequence);
} else { } else {
avrdude_message(MSG_NOTICE2, pmsg_notice2("stats: send Group %s Sequence %u : "
"%s: Stats: Send Group %s Sequence %u : " "Send %lu.%06lu %s\n",
"Send %lu.%06lu %s\n", groupNames[group],
progname, groupNames[group], (unsigned int) sequence,
(unsigned int)sequence, (unsigned long) sendTime->tv_sec,
(unsigned long)sendTime->tv_sec, (unsigned long) sendTime->tv_usec,
(unsigned long)sendTime->tv_usec, detail);
detail);
} }
} }
@ -361,18 +350,17 @@ static void xbeedev_stats_receive(struct XBeeBootSession *xbs,
delay.tv_sec = secs; delay.tv_sec = secs;
delay.tv_usec = usecs; delay.tv_usec = usecs;
avrdude_message(MSG_NOTICE2, pmsg_notice2("stats: receive Group %s Sequence %u : "
"%s: Stats: Receive Group %s Sequence %u : " "Send %lu.%06lu Receive %lu.%06lu Delay %lu.%06lu %s\n",
"Send %lu.%06lu Receive %lu.%06lu Delay %lu.%06lu %s\n", groupNames[group],
progname, groupNames[group], (unsigned int) sequence,
(unsigned int)sequence, (unsigned long) stats->sendTime.tv_sec,
(unsigned long)stats->sendTime.tv_sec, (unsigned long) stats->sendTime.tv_usec,
(unsigned long)stats->sendTime.tv_usec, (unsigned long) receiveTime->tv_sec,
(unsigned long)receiveTime->tv_sec, (unsigned long) receiveTime->tv_usec,
(unsigned long)receiveTime->tv_usec, (unsigned long) secs,
(unsigned long)secs, (unsigned long) usecs,
(unsigned long)usecs, detail);
detail);
xbeeStatsAdd(&xbs->groupSummary[group], &delay); xbeeStatsAdd(&xbs->groupSummary[group], &delay);
} }
@ -403,12 +391,11 @@ static int sendAPIRequest(struct XBeeBootSession *xbs,
gettimeofday(&time, NULL); gettimeofday(&time, NULL);
avrdude_message(MSG_NOTICE2, pmsg_notice2("sendAPIRequest(): %lu.%06lu %d, %d, %d, %d %s\n",
"%s: sendAPIRequest(): %lu.%06lu %d, %d, %d, %d %s\n", (unsigned long) time.tv_sec,
progname, (unsigned long)time.tv_sec, (unsigned long) time.tv_usec,
(unsigned long)time.tv_usec, (int) packetType, (int)sequence, appType,
(int)packetType, (int)sequence, appType, data == NULL ? -1 : (int)*data, detail);
data == NULL ? -1 : (int)*data, detail);
#define fpput(x) \ #define fpput(x) \
do { \ do { \
@ -453,9 +440,7 @@ static int sendAPIRequest(struct XBeeBootSession *xbs,
* instructions. * instructions.
*/ */
if (apiType != 0x21 && xbs->sourceRouteChanged) { if (apiType != 0x21 && xbs->sourceRouteChanged) {
avrdude_message(MSG_NOTICE2, "%s: sendAPIRequest(): " pmsg_notice2("sendAPIRequest(): issuing Create Source Route request with %d hops\n", xbs->sourceRouteHops);
"Issuing Create Source Route request with %d hops\n",
progname, xbs->sourceRouteHops);
int rc = sendAPIRequest(xbs, 0x21, /* Create Source Route */ int rc = sendAPIRequest(xbs, 0x21, /* Create Source Route */
0, -1, 0, xbs->sourceRouteHops, 0, -1, 0, xbs->sourceRouteHops,
@ -583,9 +568,7 @@ static void xbeedev_record16Bit(struct XBeeBootSession *xbs,
unsigned char * const tx16Bit = unsigned char * const tx16Bit =
&xbs->xbee_address[XBEE_ADDRESS_64BIT_LEN]; &xbs->xbee_address[XBEE_ADDRESS_64BIT_LEN];
if (memcmp(rx16Bit, tx16Bit, XBEE_ADDRESS_16BIT_LEN) != 0) { if (memcmp(rx16Bit, tx16Bit, XBEE_ADDRESS_16BIT_LEN) != 0) {
avrdude_message(MSG_NOTICE2, "%s: xbeedev_record16Bit(): " pmsg_notice2("xbeedev_record16Bit(): new 16-bit address: %02x%02x\n",
"New 16-bit address: %02x%02x\n",
progname,
(unsigned int)rx16Bit[0], (unsigned int)rx16Bit[0],
(unsigned int)rx16Bit[1]); (unsigned int)rx16Bit[1]);
memcpy(tx16Bit, rx16Bit, XBEE_ADDRESS_16BIT_LEN); memcpy(tx16Bit, rx16Bit, XBEE_ADDRESS_16BIT_LEN);
@ -666,9 +649,7 @@ static int xbeedev_poll(struct XBeeBootSession *xbs,
if (checksum) { if (checksum) {
/* Checksum didn't match */ /* Checksum didn't match */
avrdude_message(MSG_NOTICE2, pmsg_notice2("xbeedev_poll(): bad checksum %d\n", (int) checksum);
"%s: xbeedev_poll(): Bad checksum %d\n",
progname, (int)checksum);
continue; continue;
} }
} }
@ -678,11 +659,10 @@ static int xbeedev_poll(struct XBeeBootSession *xbs,
struct timeval receiveTime; struct timeval receiveTime;
gettimeofday(&receiveTime, NULL); gettimeofday(&receiveTime, NULL);
avrdude_message(MSG_NOTICE2, pmsg_notice2("xbeedev_poll(): %lu.%06lu Received frame type %x\n",
"%s: xbeedev_poll(): %lu.%06lu Received frame type %x\n", (unsigned long) receiveTime.tv_sec,
progname, (unsigned long)receiveTime.tv_sec, (unsigned long) receiveTime.tv_usec,
(unsigned long)receiveTime.tv_usec, (unsigned int) frameType);
(unsigned int)frameType);
if (frameType == 0x97 && frameSize > 16) { if (frameType == 0x97 && frameSize > 16) {
/* Remote command response */ /* Remote command response */
@ -692,9 +672,8 @@ static int xbeedev_poll(struct XBeeBootSession *xbs,
xbeedev_stats_receive(xbs, "Remote AT command response", xbeedev_stats_receive(xbs, "Remote AT command response",
XBEE_STATS_FRAME_REMOTE, txSequence, &receiveTime); XBEE_STATS_FRAME_REMOTE, txSequence, &receiveTime);
avrdude_message(MSG_NOTICE, pmsg_notice("xbeedev_poll(): remote command %d result code %d\n",
"%s: xbeedev_poll(): Remote command %d result code %d\n", (int) txSequence, (int) resultCode);
progname, (int)txSequence, (int)resultCode);
if (waitForSequence >= 0 && waitForSequence == frame[3]) if (waitForSequence >= 0 && waitForSequence == frame[3])
/* Received result for our sequence numbered request */ /* Received result for our sequence numbered request */
@ -706,9 +685,8 @@ static int xbeedev_poll(struct XBeeBootSession *xbs,
xbeedev_stats_receive(xbs, "Local AT command response", xbeedev_stats_receive(xbs, "Local AT command response",
XBEE_STATS_FRAME_LOCAL, txSequence, &receiveTime); XBEE_STATS_FRAME_LOCAL, txSequence, &receiveTime);
avrdude_message(MSG_NOTICE, pmsg_notice("xbeedev_poll(): local command %c%c result code %d\n",
"%s: xbeedev_poll(): Local command %c%c result code %d\n", frame[4], frame[5], (int)frame[6]);
progname, frame[4], frame[5], (int)frame[6]);
if (waitForSequence >= 0 && waitForSequence == txSequence) if (waitForSequence >= 0 && waitForSequence == txSequence)
/* Received result for our sequence numbered request */ /* Received result for our sequence numbered request */
@ -720,9 +698,8 @@ static int xbeedev_poll(struct XBeeBootSession *xbs,
xbeedev_stats_receive(xbs, "Transmit status", XBEE_STATS_FRAME_REMOTE, xbeedev_stats_receive(xbs, "Transmit status", XBEE_STATS_FRAME_REMOTE,
txSequence, &receiveTime); txSequence, &receiveTime);
avrdude_message(MSG_NOTICE2, pmsg_notice2("xbeedev_poll(): transmit status %d result code %d\n",
"%s: xbeedev_poll(): Transmit status %d result code %d\n", (int) frame[3], (int) frame[7]);
progname, (int)frame[3], (int)frame[7]);
} else if (frameType == 0xa1 && } else if (frameType == 0xa1 &&
frameSize >= XBEE_LENGTH_LEN + XBEE_APITYPE_LEN + frameSize >= XBEE_LENGTH_LEN + XBEE_APITYPE_LEN +
XBEE_ADDRESS_64BIT_LEN + XBEE_ADDRESS_64BIT_LEN +
@ -731,8 +708,7 @@ static int xbeedev_poll(struct XBeeBootSession *xbs,
if (memcmp(&frame[XBEE_LENGTH_LEN + XBEE_APITYPE_LEN], if (memcmp(&frame[XBEE_LENGTH_LEN + XBEE_APITYPE_LEN],
xbs->xbee_address, XBEE_ADDRESS_64BIT_LEN) != 0) { xbs->xbee_address, XBEE_ADDRESS_64BIT_LEN) != 0) {
/* Not from our target device */ /* Not from our target device */
avrdude_message(MSG_NOTICE2, "%s: xbeedev_poll(): " pmsg_notice2("xbeedev_poll(): route Record Indicator from other XBee\n");
"Route Record Indicator from other XBee\n");
continue; continue;
} }
@ -755,10 +731,9 @@ static int xbeedev_poll(struct XBeeBootSession *xbs,
const unsigned char receiveOptions = frame[header]; const unsigned char receiveOptions = frame[header];
const unsigned char hops = frame[header + 1]; const unsigned char hops = frame[header + 1];
avrdude_message(MSG_NOTICE2, "%s: xbeedev_poll(): " pmsg_notice2("xbeedev_poll(): "
"Route Record Indicator from target XBee: " "Route Record Indicator from target XBee: "
"hops=%d options=%d\n", "hops=%d options=%d\n", (int)hops, (int)receiveOptions);
progname, (int)hops, (int)receiveOptions);
if (frameSize < header + 2 + hops * 2 + XBEE_CHECKSUM_LEN) if (frameSize < header + 2 + hops * 2 + XBEE_CHECKSUM_LEN)
/* Bounds check: Frame is too small */ /* Bounds check: Frame is too small */
@ -768,11 +743,10 @@ static int xbeedev_poll(struct XBeeBootSession *xbs,
unsigned char index; unsigned char index;
for (index = 0; index < hops; index++) { for (index = 0; index < hops; index++) {
avrdude_message(MSG_NOTICE2, "%s: xbeedev_poll(): " pmsg_notice2("xbeedev_poll(): "
"Route Intermediate Hop %d : %02x%02x\n", "Route Intermediate Hop %d : %02x%02x\n", (int)index,
progname, (int)index, (int)frame[tableOffset + index * 2],
(int)frame[tableOffset + index * 2], (int)frame[tableOffset + index * 2 + 1]);
(int)frame[tableOffset + index * 2 + 1]);
} }
if (hops <= XBEE_MAX_INTERMEDIATE_HOPS) { if (hops <= XBEE_MAX_INTERMEDIATE_HOPS) {
@ -782,9 +756,7 @@ static int xbeedev_poll(struct XBeeBootSession *xbs,
xbs->sourceRouteHops = hops; xbs->sourceRouteHops = hops;
xbs->sourceRouteChanged = 1; xbs->sourceRouteChanged = 1;
avrdude_message(MSG_NOTICE2, "%s: xbeedev_poll(): " pmsg_notice2("xbeedev_poll(): route has changed\n");
"Route has changed\n",
progname);
} }
} }
} else if (frameType == 0x10 || frameType == 0x90) { } else if (frameType == 0x10 || frameType == 0x90) {
@ -844,11 +816,10 @@ static int xbeedev_poll(struct XBeeBootSession *xbs,
const unsigned char protocolType = dataStart[0]; const unsigned char protocolType = dataStart[0];
const unsigned char sequence = dataStart[1]; const unsigned char sequence = dataStart[1];
avrdude_message(MSG_NOTICE2, "%s: xbeedev_poll(): " pmsg_notice2("xbeedev_poll(): "
"%lu.%06lu Packet %d #%d\n", "%lu.%06lu Packet %d #%d\n", (unsigned long)receiveTime.tv_sec,
progname, (unsigned long)receiveTime.tv_sec, (unsigned long)receiveTime.tv_usec,
(unsigned long)receiveTime.tv_usec, (int)protocolType, (int)sequence);
(int)protocolType, (int)sequence);
if (protocolType == XBEEBOOT_PACKET_TYPE_ACK) { if (protocolType == XBEEBOOT_PACKET_TYPE_ACK) {
/* ACK */ /* ACK */
@ -878,7 +849,7 @@ static int xbeedev_poll(struct XBeeBootSession *xbs,
for (index = 0; index < textLength; index++) { for (index = 0; index < textLength; index++) {
const unsigned char data = dataStart[3 + index]; const unsigned char data = dataStart[3 + index];
if (buflen != NULL && *buflen > 0) { if (buflen != NULL && *buflen > 0) {
/* If we are receiving right now, and have a buffer... */ /* If we are receiving right now, and have a buffer ... */
*(*buf)++ = data; *(*buf)++ = data;
(*buflen)--; (*buflen)--;
} else { } else {
@ -887,14 +858,14 @@ static int xbeedev_poll(struct XBeeBootSession *xbs,
xbs->inInIndex = 0; xbs->inInIndex = 0;
if (xbs->inInIndex == xbs->inOutIndex) { if (xbs->inInIndex == xbs->inOutIndex) {
/* Should be impossible */ /* Should be impossible */
avrdude_message(MSG_INFO, "%s: Buffer overrun\n", progname); pmsg_error("buffer overrun\n");
xbs->transportUnusable = 1; xbs->transportUnusable = 1;
return -1; return -1;
} }
} }
} }
/*avrdude_message(MSG_INFO, "ACK %x\n", (unsigned int)sequence);*/ /*msg_error("ACK %x\n", (unsigned int)sequence);*/
sendPacket(xbs, "Transmit Request ACK for RECEIVE", sendPacket(xbs, "Transmit Request ACK for RECEIVE",
XBEEBOOT_PACKET_TYPE_ACK, sequence, XBEEBOOT_PACKET_TYPE_ACK, sequence,
XBEE_STATS_NOT_RETRY, XBEE_STATS_NOT_RETRY,
@ -952,8 +923,7 @@ static int localAsyncAT(struct XBeeBootSession *xbs, char const *detail,
if (value >= 0) if (value >= 0)
buf[length++] = (unsigned char)value; buf[length++] = (unsigned char)value;
avrdude_message(MSG_NOTICE, "%s: Local AT command: %c%c\n", pmsg_notice("local AT command: %c%c\n", at1, at2);
progname, at1, at2);
/* Local AT command 0x08 */ /* Local AT command 0x08 */
int rc = sendAPIRequest(xbs, 0x08, sequence, -1, -1, -1, -1, -1, -1, int rc = sendAPIRequest(xbs, 0x08, sequence, -1, -1, -1, -1, -1, -1,
@ -1016,8 +986,7 @@ static int sendAT(struct XBeeBootSession *xbs, char const *detail,
if (value >= 0) if (value >= 0)
buf[length++] = (unsigned char)value; buf[length++] = (unsigned char)value;
avrdude_message(MSG_NOTICE, pmsg_notice("remote AT command: %c%c\n", at1, at2);
"%s: Remote AT command: %c%c\n", progname, at1, at2);
/* Remote AT command 0x17 with Apply Changes 0x02 */ /* Remote AT command 0x17 with Apply Changes 0x02 */
sendAPIRequest(xbs, 0x17, sequence, -1, sendAPIRequest(xbs, 0x17, sequence, -1,
@ -1042,8 +1011,7 @@ static int sendAT(struct XBeeBootSession *xbs, char const *detail,
} }
/* /*
* Return 0 on no error recognised, 1 if error was detected and * Return 0 on no error recognised, 1 if error was detected and reported
* reported.
*/ */
static int xbeeATError(int rc) { static int xbeeATError(int rc) {
const int xbeeRc = XBEE_AT_RETURN_CODE(rc); const int xbeeRc = XBEE_AT_RETURN_CODE(rc);
@ -1051,23 +1019,15 @@ static int xbeeATError(int rc) {
return 0; return 0;
if (xbeeRc == 1) { if (xbeeRc == 1) {
avrdude_message(MSG_INFO, "%s: Error communicating with Remote XBee\n", pmsg_error("unable to communicate with remote XBee\n");
progname);
} else if (xbeeRc == 2) { } else if (xbeeRc == 2) {
avrdude_message(MSG_INFO, "%s: Remote XBee command error: " pmsg_error("remote XBee: invalid command\n");
"Invalid command\n",
progname);
} else if (xbeeRc == 3) { } else if (xbeeRc == 3) {
avrdude_message(MSG_INFO, "%s: Remote XBee command error: " pmsg_error("remote XBee: invalid command parameter\n");
"Invalid parameter\n",
progname);
} else if (xbeeRc == 4) { } else if (xbeeRc == 4) {
avrdude_message(MSG_INFO, "%s: Remote XBee error: " pmsg_error("remote XBee: transmission failure\n");
"Transmission failure\n",
progname);
} else { } else {
avrdude_message(MSG_INFO, "%s: Unrecognised remote XBee error code %d\n", pmsg_error("unrecognised remote XBee error code %d\n", xbeeRc);
progname, xbeeRc);
} }
return 1; return 1;
} }
@ -1100,17 +1060,13 @@ static int xbeedev_open(const char *port, union pinfo pinfo,
*/ */
char *ttySeparator = strchr(port, '@'); char *ttySeparator = strchr(port, '@');
if (ttySeparator == NULL) { if (ttySeparator == NULL) {
avrdude_message(MSG_INFO, pmsg_error("XBee: bad port syntax, require <xbee-address>@<serial-device>\n");
"%s: XBee: Bad port syntax: "
"require \"<xbee-address>@<serial-device>\"\n",
progname);
return -1; return -1;
} }
struct XBeeBootSession *xbs = malloc(sizeof(struct XBeeBootSession)); struct XBeeBootSession *xbs = malloc(sizeof(struct XBeeBootSession));
if (xbs == NULL) { if (xbs == NULL) {
avrdude_message(MSG_INFO, "%s: xbeedev_open(): out of memory\n", pmsg_error("out of memory\n");
progname);
return -1; return -1;
} }
@ -1149,10 +1105,7 @@ static int xbeedev_open(const char *port, union pinfo pinfo,
} }
if (addrIndex != 8 || address != ttySeparator || nybble != -1) { if (addrIndex != 8 || address != ttySeparator || nybble != -1) {
avrdude_message(MSG_INFO, pmsg_error("XBee: bad XBee address, require 16-character hexadecimal address\n");
"%s: XBee: Bad XBee address: "
"require 16-character hexadecimal address\"\n",
progname);
free(xbs); free(xbs);
return -1; return -1;
} }
@ -1164,17 +1117,15 @@ static int xbeedev_open(const char *port, union pinfo pinfo,
xbs->xbee_address[8] = 0xff; xbs->xbee_address[8] = 0xff;
xbs->xbee_address[9] = 0xfe; xbs->xbee_address[9] = 0xfe;
avrdude_message(MSG_TRACE, pmsg_trace("XBee address: %02x%02x%02x%02x%02x%02x%02x%02x\n",
"%s: XBee address: %02x%02x%02x%02x%02x%02x%02x%02x\n", (unsigned int) xbs->xbee_address[0],
progname, (unsigned int) xbs->xbee_address[1],
(unsigned int)xbs->xbee_address[0], (unsigned int) xbs->xbee_address[2],
(unsigned int)xbs->xbee_address[1], (unsigned int) xbs->xbee_address[3],
(unsigned int)xbs->xbee_address[2], (unsigned int) xbs->xbee_address[4],
(unsigned int)xbs->xbee_address[3], (unsigned int) xbs->xbee_address[5],
(unsigned int)xbs->xbee_address[4], (unsigned int) xbs->xbee_address[6],
(unsigned int)xbs->xbee_address[5], (unsigned int) xbs->xbee_address[7]);
(unsigned int)xbs->xbee_address[6],
(unsigned int)xbs->xbee_address[7]);
if (pinfo.serialinfo.baud) { if (pinfo.serialinfo.baud) {
/* /*
@ -1216,7 +1167,7 @@ static int xbeedev_open(const char *port, union pinfo pinfo,
} }
pinfo.serialinfo.cflags = SERIAL_8N1; pinfo.serialinfo.cflags = SERIAL_8N1;
avrdude_message(MSG_NOTICE, "%s: Baud %ld\n", progname, (long)pinfo.serialinfo.baud); pmsg_notice("baud %ld\n", (long)pinfo.serialinfo.baud);
{ {
const int rc = xbs->serialDevice->open(tty, pinfo, const int rc = xbs->serialDevice->open(tty, pinfo,
@ -1232,8 +1183,7 @@ static int xbeedev_open(const char *port, union pinfo pinfo,
{ {
const int rc = localAT(xbs, "AT AP=2", 'A', 'P', 2); const int rc = localAT(xbs, "AT AP=2", 'A', 'P', 2);
if (rc < 0) { if (rc < 0) {
avrdude_message(MSG_INFO, "%s: Local XBee is not responding.\n", pmsg_error("local XBee is not responding\n");
progname);
xbeedev_free(xbs); xbeedev_free(xbs);
return rc; return rc;
} }
@ -1273,8 +1223,7 @@ static int xbeedev_open(const char *port, union pinfo pinfo,
{ {
const int rc = localAT(xbs, "AT AR=0", 'A', 'R', 0); const int rc = localAT(xbs, "AT AR=0", 'A', 'R', 0);
if (rc < 0) { if (rc < 0) {
avrdude_message(MSG_INFO, "%s: Local XBee is not responding.\n", pmsg_error("local XBee is not responding\n");
progname);
xbeedev_free(xbs); xbeedev_free(xbs);
return rc; return rc;
} }
@ -1296,8 +1245,7 @@ static int xbeedev_open(const char *port, union pinfo pinfo,
if (xbeeATError(rc)) if (xbeeATError(rc))
return -1; return -1;
avrdude_message(MSG_INFO, "%s: Remote XBee is not responding.\n", pmsg_error("remote XBee is not responding\n");
progname);
return rc; return rc;
} }
} }
@ -1515,8 +1463,7 @@ static int xbeedev_drain(const union filedescriptor *fdp, int display)
return -1; return -1;
/* /*
* Flushing the local serial buffer is unhelpful under this * Flushing the local serial buffer is unhelpful under this protocol
* protocol.
*/ */
do { do {
xbs->inOutIndex = xbs->inInIndex = 0; xbs->inOutIndex = xbs->inInIndex = 0;
@ -1544,8 +1491,7 @@ static int xbeedev_set_dtr_rts(const union filedescriptor *fdp, int is_on)
if (xbeeATError(rc)) if (xbeeATError(rc))
return -1; return -1;
avrdude_message(MSG_INFO, pmsg_error("remote XBee is not responding\n");
"%s: Remote XBee is not responding.\n", progname);
return rc; return rc;
} }
@ -1578,10 +1524,7 @@ static int xbee_getsync(const PROGRAMMER *pgm) {
int sendRc = serial_send(&pgm->fd, buf, 2); int sendRc = serial_send(&pgm->fd, buf, 2);
if (sendRc < 0) { if (sendRc < 0) {
avrdude_message(MSG_INFO, pmsg_error("unable to deliver STK_GET_SYNC to the remote XBeeBoot bootloader\n");
"%s: xbee_getsync(): failed to deliver STK_GET_SYNC "
"to the remote XBeeBoot bootloader\n",
progname);
return sendRc; return sendRc;
} }
@ -1591,23 +1534,17 @@ static int xbee_getsync(const PROGRAMMER *pgm) {
*/ */
int recvRc = serial_recv(&pgm->fd, resp, 2); int recvRc = serial_recv(&pgm->fd, resp, 2);
if (recvRc < 0) { if (recvRc < 0) {
avrdude_message(MSG_INFO, pmsg_error("no response to STK_GET_SYNC from the remote XBeeBoot bootloader\n");
"%s: xbee_getsync(): no response to STK_GET_SYNC "
"from the remote XBeeBoot bootloader\n",
progname);
return recvRc; return recvRc;
} }
if (resp[0] != Resp_STK_INSYNC) { if (resp[0] != Resp_STK_INSYNC) {
avrdude_message(MSG_INFO, "%s: xbee_getsync(): not in sync: resp=0x%02x\n", pmsg_error("not in sync, resp=0x%02x\n", (unsigned int) resp[0]);
progname, (unsigned int)resp[0]);
return -1; return -1;
} }
if (resp[1] != Resp_STK_OK) { if (resp[1] != Resp_STK_OK) {
avrdude_message(MSG_INFO, "%s: xbee_getsync(): in sync, not OK: " pmsg_error("in sync, not OK, resp=0x%02x\n", (unsigned int) resp[1]);
"resp=0x%02x\n",
progname, (unsigned int)resp[1]);
return -1; return -1;
} }
@ -1676,16 +1613,16 @@ static void xbee_close(PROGRAMMER *pgm)
xbeeATError(rc); xbeeATError(rc);
} }
avrdude_message(MSG_NOTICE, "%s: Statistics for FRAME_LOCAL requests - %s->XBee(local)\n", progname, progname); pmsg_notice("statistics for FRAME_LOCAL requests - %s->XBee(local)\n", progname);
xbeeStatsSummarise(&xbs->groupSummary[XBEE_STATS_FRAME_LOCAL]); xbeeStatsSummarise(&xbs->groupSummary[XBEE_STATS_FRAME_LOCAL]);
avrdude_message(MSG_NOTICE, "%s: Statistics for FRAME_REMOTE requests - %s->XBee(local)->XBee(target)\n", progname, progname); pmsg_notice("statistics for FRAME_REMOTE requests - %s->XBee(local)->XBee(target)\n", progname);
xbeeStatsSummarise(&xbs->groupSummary[XBEE_STATS_FRAME_REMOTE]); xbeeStatsSummarise(&xbs->groupSummary[XBEE_STATS_FRAME_REMOTE]);
avrdude_message(MSG_NOTICE, "%s: Statistics for TRANSMIT requests - %s->XBee(local)->XBee(target)->XBeeBoot\n", progname, progname); pmsg_notice("statistics for TRANSMIT requests - %s->XBee(local)->XBee(target)->XBeeBoot\n", progname);
xbeeStatsSummarise(&xbs->groupSummary[XBEE_STATS_TRANSMIT]); xbeeStatsSummarise(&xbs->groupSummary[XBEE_STATS_TRANSMIT]);
avrdude_message(MSG_NOTICE, "%s: Statistics for RECEIVE requests - XBeeBoot->XBee(target)->XBee(local)->%s\n", progname, progname); pmsg_notice("statistics for RECEIVE requests - XBeeBoot->XBee(target)->XBee(local)->%s\n", progname);
xbeeStatsSummarise(&xbs->groupSummary[XBEE_STATS_RECEIVE]); xbeeStatsSummarise(&xbs->groupSummary[XBEE_STATS_RECEIVE]);
xbeedev_free(xbs); xbeedev_free(xbs);
@ -1706,9 +1643,7 @@ static int xbee_parseextparms(const PROGRAMMER *pgm, const LISTID extparms) {
int resetpin; int resetpin;
if (sscanf(extended_param, "xbeeresetpin=%i", &resetpin) != 1 || if (sscanf(extended_param, "xbeeresetpin=%i", &resetpin) != 1 ||
resetpin <= 0 || resetpin > 7) { resetpin <= 0 || resetpin > 7) {
avrdude_message(MSG_INFO, "%s: xbee_parseextparms(): " pmsg_error("invalid xbeeresetpin '%s'\n", extended_param);
"invalid xbeeresetpin '%s'\n",
progname, extended_param);
rc = -1; rc = -1;
continue; continue;
} }
@ -1717,9 +1652,7 @@ static int xbee_parseextparms(const PROGRAMMER *pgm, const LISTID extparms) {
continue; continue;
} }
avrdude_message(MSG_INFO, "%s: xbee_parseextparms(): " pmsg_error("invalid extended parameter '%s'\n", extended_param);
"invalid extended parameter '%s'\n",
progname, extended_param);
rc = -1; rc = -1;
} }