Exchange of fprintf(stderr, ...) with avrdude_message(...).

This change was made for the shared library, since library functions
should not write to std-streams directly. Instead avrdude_message()
has to be implemented by the library user. For the avrdude application
this function is implemented in main.c.



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1305 81a1dc3b-b13d-400b-aceb-764788c761c2
This commit is contained in:
awachtler 2014-05-18 08:41:46 +00:00
parent b9093f88dc
commit 7b43620402
45 changed files with 2380 additions and 2896 deletions

View File

@ -46,7 +46,7 @@ static int arduino_read_sig_bytes(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m)
/* Signature byte reads are always 3 bytes. */ /* Signature byte reads are always 3 bytes. */
if (m->size < 3) { if (m->size < 3) {
fprintf(stderr, "%s: memsize too small for sig byte read", progname); avrdude_message("%s: memsize too small for sig byte read", progname);
return -1; return -1;
} }
@ -58,19 +58,17 @@ static int arduino_read_sig_bytes(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m)
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) {
fprintf(stderr, "%s: stk500_cmd(): programmer is out of sync\n", avrdude_message("%s: stk500_cmd(): programmer is out of sync\n",
progname); progname);
return -1; return -1;
} else if (buf[0] != Resp_STK_INSYNC) { } else if (buf[0] != Resp_STK_INSYNC) {
fprintf(stderr, avrdude_message("\n%s: arduino_read_sig_bytes(): (a) protocol error, "
"\n%s: arduino_read_sig_bytes(): (a) protocol error, "
"expect=0x%02x, resp=0x%02x\n", "expect=0x%02x, resp=0x%02x\n",
progname, 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) {
fprintf(stderr, avrdude_message("\n%s: arduino_read_sig_bytes(): (a) protocol error, "
"\n%s: arduino_read_sig_bytes(): (a) protocol error, "
"expect=0x%02x, resp=0x%02x\n", "expect=0x%02x, resp=0x%02x\n",
progname, Resp_STK_OK, buf[4]); progname, Resp_STK_OK, buf[4]);
return -3; return -3;

101
avr.c
View File

@ -65,7 +65,7 @@ int avr_tpi_chip_erase(PROGRAMMER * pgm, 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) {
fprintf(stderr, "No flash memory to erase for part %s\n", avrdude_message("No flash memory to erase for part %s\n",
p->desc); p->desc);
return -1; return -1;
} }
@ -97,7 +97,7 @@ int avr_tpi_chip_erase(PROGRAMMER * pgm, AVRPART * p)
return 0; return 0;
} else { } else {
fprintf(stderr, "%s called for a part that has no TPI\n", __func__); avrdude_message("%s called for a part that has no TPI\n", __func__);
return -1; return -1;
} }
} }
@ -122,7 +122,7 @@ int avr_tpi_program_enable(PROGRAMMER * pgm, AVRPART * p, unsigned char guard_ti
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) {
fprintf(stderr, "TPIIR not correct\n"); avrdude_message("TPIIR not correct\n");
return -1; return -1;
} }
@ -142,12 +142,12 @@ int avr_tpi_program_enable(PROGRAMMER * pgm, AVRPART * p, unsigned char guard_ti
return 0; return 0;
} }
fprintf(stderr, "Error enabling TPI external programming mode:"); avrdude_message("Error enabling TPI external programming mode:");
fprintf(stderr, "Target does not reply\n"); avrdude_message("Target does not reply\n");
return -1; return -1;
} else { } else {
fprintf(stderr, "%s called for a part that has no TPI\n", __func__); avrdude_message("%s called for a part that has no TPI\n", __func__);
return -1; return -1;
} }
} }
@ -192,8 +192,7 @@ int avr_read_byte_default(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
OPCODE * readop, * lext; OPCODE * readop, * lext;
if (pgm->cmd == NULL) { if (pgm->cmd == NULL) {
fprintf(stderr, avrdude_message("%s: Error: %s programmer uses avr_read_byte_default() but does not\n"
"%s: Error: %s programmer uses avr_read_byte_default() but does not\n"
"provide a cmd() method.\n", "provide a cmd() method.\n",
progname, pgm->type); progname, pgm->type);
return -1; return -1;
@ -204,7 +203,7 @@ int avr_read_byte_default(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
if (p->flags & AVRPART_HAS_TPI) { if (p->flags & AVRPART_HAS_TPI) {
if (pgm->cmd_tpi == NULL) { if (pgm->cmd_tpi == NULL) {
fprintf(stderr, "%s: Error: %s programmer does not support TPI\n", avrdude_message("%s: Error: %s programmer does not support TPI\n",
progname, pgm->type); progname, pgm->type);
return -1; return -1;
} }
@ -239,8 +238,7 @@ int avr_read_byte_default(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
if (readop == NULL) { if (readop == NULL) {
#if DEBUG #if DEBUG
fprintf(stderr, avrdude_message("avr_read_byte(): operation not supported on memory type \"%s\"\n",
"avr_read_byte(): operation not supported on memory type \"%s\"\n",
mem->desc); mem->desc);
#endif #endif
return -1; return -1;
@ -325,7 +323,7 @@ int avr_read(PROGRAMMER * pgm, AVRPART * p, char * memtype,
if (v != NULL) if (v != NULL)
vmem = avr_locate_mem(v, memtype); vmem = avr_locate_mem(v, memtype);
if (mem == NULL) { if (mem == NULL) {
fprintf(stderr, "No \"%s\" memory for part %s\n", avrdude_message("No \"%s\" memory for part %s\n",
memtype, p->desc); memtype, p->desc);
return -1; return -1;
} }
@ -358,7 +356,7 @@ int avr_read(PROGRAMMER * pgm, AVRPART * p, char * memtype,
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) {
fprintf(stderr, "avr_read(): error reading address 0x%04lx\n", i); avrdude_message("avr_read(): error reading address 0x%04lx\n", i);
return -1; return -1;
} }
} }
@ -415,8 +413,7 @@ int avr_read(PROGRAMMER * pgm, AVRPART * p, char * memtype,
/* 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 if (verbose >= 3) { } else if (verbose >= 3) {
fprintf(stderr, avrdude_message("%s: avr_read(): skipping page %u: no interesting data\n",
"%s: avr_read(): skipping page %u: no interesting data\n",
progname, pageaddr / mem->page_size); progname, pageaddr / mem->page_size);
} }
nread++; nread++;
@ -446,10 +443,9 @@ int avr_read(PROGRAMMER * pgm, AVRPART * p, char * memtype,
{ {
rc = pgm->read_byte(pgm, p, mem, i, mem->buf + i); rc = pgm->read_byte(pgm, p, mem, i, mem->buf + i);
if (rc != 0) { if (rc != 0) {
fprintf(stderr, "avr_read(): error reading address 0x%04lx\n", i); avrdude_message("avr_read(): error reading address 0x%04lx\n", i);
if (rc == -1) if (rc == -1)
fprintf(stderr, avrdude_message(" read operation not supported for memory \"%s\"\n",
" read operation not supported for memory \"%s\"\n",
memtype); memtype);
return -2; return -2;
} }
@ -478,8 +474,7 @@ int avr_write_page(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
OPCODE * wp, * lext; OPCODE * wp, * lext;
if (pgm->cmd == NULL) { if (pgm->cmd == NULL) {
fprintf(stderr, avrdude_message("%s: Error: %s programmer uses avr_write_page() but does not\n"
"%s: Error: %s programmer uses avr_write_page() but does not\n"
"provide a cmd() method.\n", "provide a cmd() method.\n",
progname, pgm->type); progname, pgm->type);
return -1; return -1;
@ -487,8 +482,7 @@ int avr_write_page(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
wp = mem->op[AVR_OP_WRITEPAGE]; wp = mem->op[AVR_OP_WRITEPAGE];
if (wp == NULL) { if (wp == NULL) {
fprintf(stderr, avrdude_message("avr_write_page(): memory \"%s\" not configured for page writes\n",
"avr_write_page(): memory \"%s\" not configured for page writes\n",
mem->desc); mem->desc);
return -1; return -1;
} }
@ -550,8 +544,7 @@ int avr_write_byte_default(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
struct timeval tv; struct timeval tv;
if (pgm->cmd == NULL) { if (pgm->cmd == NULL) {
fprintf(stderr, avrdude_message("%s: Error: %s programmer uses avr_write_byte_default() but does not\n"
"%s: Error: %s programmer uses avr_write_byte_default() but does not\n"
"provide a cmd() method.\n", "provide a cmd() method.\n",
progname, pgm->type); progname, pgm->type);
return -1; return -1;
@ -559,16 +552,16 @@ int avr_write_byte_default(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
if (p->flags & AVRPART_HAS_TPI) { if (p->flags & AVRPART_HAS_TPI) {
if (pgm->cmd_tpi == NULL) { if (pgm->cmd_tpi == NULL) {
fprintf(stderr, "%s: Error: %s programmer does not support TPI\n", avrdude_message("%s: Error: %s programmer does not support TPI\n",
progname, pgm->type); progname, pgm->type);
return -1; return -1;
} }
if (strcmp(mem->desc, "flash") == 0) { if (strcmp(mem->desc, "flash") == 0) {
fprintf(stderr, "Writing a byte to flash is not supported for %s\n", p->desc); avrdude_message("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) {
fprintf(stderr, "Writing a byte to an odd location is not supported for %s\n", p->desc); avrdude_message("Writing a byte to an odd location is not supported for %s\n", p->desc);
return -1; return -1;
} }
@ -656,8 +649,7 @@ int avr_write_byte_default(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
if (writeop == NULL) { if (writeop == NULL) {
#if DEBUG #if DEBUG
fprintf(stderr, avrdude_message("avr_write_byte(): write not supported for memory type \"%s\"\n",
"avr_write_byte(): write not supported for memory type \"%s\"\n",
mem->desc); mem->desc);
#endif #endif
return -1; return -1;
@ -750,27 +742,24 @@ int avr_write_byte_default(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
* 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);
fprintf(stderr, avrdude_message("%s: this device must be powered off and back on to continue\n",
"%s: this device must be powered off and back on to continue\n",
progname); progname);
if (pgm->pinno[PPI_AVR_VCC]) { if (pgm->pinno[PPI_AVR_VCC]) {
fprintf(stderr, "%s: attempting to do this now ...\n", progname); avrdude_message("%s: attempting to do this now ...\n", progname);
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) {
fprintf(stderr, "%s: initialization failed, rc=%d\n", progname, rc); avrdude_message("%s: initialization failed, rc=%d\n", progname, rc);
fprintf(stderr, avrdude_message("%s: can't re-initialize device after programming the "
"%s: can't re-initialize device after programming the "
"%s bits\n", progname, mem->desc); "%s bits\n", progname, mem->desc);
fprintf(stderr, avrdude_message("%s: you must manually power-down the device and restart\n"
"%s: you must manually power-down the device and restart\n"
"%s: %s to continue.\n", "%s: %s to continue.\n",
progname, progname, progname); progname, progname, progname);
return -3; return -3;
} }
fprintf(stderr, "%s: device was successfully re-initialized\n", avrdude_message("%s: device was successfully re-initialized\n",
progname); progname);
return 0; return 0;
} }
@ -852,7 +841,7 @@ int avr_write(PROGRAMMER * pgm, AVRPART * p, char * memtype, int size,
m = avr_locate_mem(p, memtype); m = avr_locate_mem(p, memtype);
if (m == NULL) { if (m == NULL) {
fprintf(stderr, "No \"%s\" memory for part %s\n", avrdude_message("No \"%s\" memory for part %s\n",
memtype, p->desc); memtype, p->desc);
return -1; return -1;
} }
@ -866,8 +855,7 @@ int avr_write(PROGRAMMER * pgm, AVRPART * p, char * memtype, int size,
wsize = size; wsize = size;
} }
else if (size > wsize) { else if (size > wsize) {
fprintf(stderr, avrdude_message("%s: WARNING: %d bytes requested, but memory region is only %d"
"%s: WARNING: %d bytes requested, but memory region is only %d"
"bytes\n" "bytes\n"
"%sOnly %d bytes will actually be written\n", "%sOnly %d bytes will actually be written\n",
progname, size, wsize, progname, size, wsize,
@ -958,8 +946,7 @@ int avr_write(PROGRAMMER * pgm, AVRPART * p, char * memtype, int size,
/* 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 if (verbose >= 3) { } else if (verbose >= 3) {
fprintf(stderr, avrdude_message("%s: avr_write(): skipping page %u: no interesting data\n",
"%s: avr_write(): skipping page %u: no interesting data\n",
progname, pageaddr / m->page_size); progname, pageaddr / m->page_size);
} }
nwritten++; nwritten++;
@ -1019,8 +1006,8 @@ int avr_write(PROGRAMMER * pgm, AVRPART * p, char * memtype, int size,
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) {
fprintf(stderr, " ***failed; "); avrdude_message(" ***failed; ");
fprintf(stderr, "\n"); avrdude_message("\n");
pgm->err_led(pgm, ON); pgm->err_led(pgm, ON);
werror = 1; werror = 1;
} }
@ -1033,12 +1020,11 @@ int avr_write(PROGRAMMER * pgm, AVRPART * p, char * memtype, int size,
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) {
fprintf(stderr, avrdude_message(" *** page %d (addresses 0x%04x - 0x%04x) failed "
" *** page %d (addresses 0x%04x - 0x%04x) failed "
"to write\n", "to write\n",
i % m->page_size, i % m->page_size,
i - m->page_size + 1, i); i - m->page_size + 1, i);
fprintf(stderr, "\n"); avrdude_message("\n");
pgm->err_led(pgm, ON); pgm->err_led(pgm, ON);
werror = 1; werror = 1;
} }
@ -1068,8 +1054,7 @@ int avr_signature(PROGRAMMER * pgm, 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 < 0) { if (rc < 0) {
fprintf(stderr, avrdude_message("%s: error reading signature data for part \"%s\", rc=%d\n",
"%s: error reading signature data for part \"%s\", rc=%d\n",
progname, p->desc, rc); progname, p->desc, rc);
return -1; return -1;
} }
@ -1095,16 +1080,14 @@ int avr_verify(AVRPART * p, AVRPART * v, char * memtype, int size)
a = avr_locate_mem(p, memtype); a = avr_locate_mem(p, memtype);
if (a == NULL) { if (a == NULL) {
fprintf(stderr, avrdude_message("avr_verify(): memory type \"%s\" not defined for part %s\n",
"avr_verify(): 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) {
fprintf(stderr, avrdude_message("avr_verify(): memory type \"%s\" not defined for part %s\n",
"avr_verify(): memory type \"%s\" not defined for part %s\n",
memtype, v->desc); memtype, v->desc);
return -1; return -1;
} }
@ -1114,8 +1097,7 @@ int avr_verify(AVRPART * p, AVRPART * v, char * memtype, int size)
vsize = a->size; vsize = a->size;
if (vsize < size) { if (vsize < size) {
fprintf(stderr, avrdude_message("%s: WARNING: requested verification for %d bytes\n"
"%s: WARNING: requested verification for %d bytes\n"
"%s%s memory region only contains %d bytes\n" "%s%s memory region only contains %d bytes\n"
"%sOnly %d bytes will be verified.\n", "%sOnly %d bytes will be verified.\n",
progname, size, progname, size,
@ -1127,8 +1109,7 @@ int avr_verify(AVRPART * p, AVRPART * v, char * memtype, int size)
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]) {
fprintf(stderr, avrdude_message("%s: verification error, first mismatch at byte 0x%04x\n"
"%s: verification error, first mismatch at byte 0x%04x\n"
"%s0x%02x != 0x%02x\n", "%s0x%02x != 0x%02x\n",
progname, i, progname, i,
progbuf, buf1[i], buf2[i]); progbuf, buf1[i], buf2[i]);
@ -1156,7 +1137,7 @@ int avr_get_cycle_count(PROGRAMMER * pgm, 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) {
fprintf(stderr, "%s: WARNING: can't read memory for cycle count, rc=%d\n", avrdude_message("%s: WARNING: can't read memory for cycle count, rc=%d\n",
progname, rc); progname, rc);
return -1; return -1;
} }
@ -1197,7 +1178,7 @@ int avr_put_cycle_count(PROGRAMMER * pgm, 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) {
fprintf(stderr, "%s: WARNING: can't write memory for cycle count, rc=%d\n", avrdude_message("%s: WARNING: can't write memory for cycle count, rc=%d\n",
progname, rc); progname, rc);
return -1; return -1;
} }

View File

@ -59,8 +59,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) {
fprintf(stderr, avrdude_message("%s: avr910_setup(): Out of memory allocating private data\n",
"%s: avr910_setup(): Out of memory allocating private data\n",
progname); progname);
exit(1); exit(1);
} }
@ -86,8 +85,7 @@ static int avr910_recv(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) {
fprintf(stderr, avrdude_message("%s: avr910_recv(): programmer is not responding\n",
"%s: avr910_recv(): programmer is not responding\n",
progname); progname);
return 1; return 1;
} }
@ -107,7 +105,7 @@ static int avr910_vfy_cmd_sent(PROGRAMMER * pgm, char * errmsg)
avr910_recv(pgm, &c, 1); avr910_recv(pgm, &c, 1);
if (c != '\r') { if (c != '\r') {
fprintf(stderr, "%s: error: programmer did not respond to command: %s\n", avrdude_message("%s: error: programmer did not respond to command: %s\n",
progname, errmsg); progname, errmsg);
return 1; return 1;
} }
@ -189,16 +187,16 @@ static int avr910_initialize(PROGRAMMER * pgm, AVRPART * p)
avr910_send(pgm, "p", 1); avr910_send(pgm, "p", 1);
avr910_recv(pgm, &type, 1); avr910_recv(pgm, &type, 1);
fprintf(stderr, "Found programmer: Id = \"%s\"; type = %c\n", id, type); avrdude_message("Found programmer: Id = \"%s\"; type = %c\n", id, type);
fprintf(stderr, " Software Version = %c.%c; ", sw[0], sw[1]); avrdude_message(" Software Version = %c.%c; ", sw[0], sw[1]);
fprintf(stderr, "Hardware Version = %c.%c\n", hw[0], hw[1]); avrdude_message("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')
fprintf(stderr, "Programmer supports auto addr increment.\n"); avrdude_message("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 */
@ -210,8 +208,7 @@ static int avr910_initialize(PROGRAMMER * pgm, 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;
fprintf(stderr, avrdude_message("Programmer supports buffered memory access with "
"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;
@ -229,7 +226,7 @@ static int avr910_initialize(PROGRAMMER * pgm, 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);
fprintf(stderr, "\nProgrammer supports the following devices:\n"); avrdude_message("\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);
@ -239,18 +236,17 @@ static int avr910_initialize(PROGRAMMER * pgm, AVRPART * p)
break; break;
part = locate_part_by_avr910_devcode(part_list, c); part = locate_part_by_avr910_devcode(part_list, c);
fprintf(stderr, " Device code: 0x%02x = %s\n", c, part ? part->desc : "(unknown)"); avrdude_message(" Device code: 0x%02x = %s\n", c, 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;
}; };
fprintf(stderr,"\n"); avrdude_message("\n");
if (!dev_supported) { if (!dev_supported) {
fprintf(stderr, avrdude_message("%s: %s: selected device is not supported by programmer: %s\n",
"%s: %s: selected device is not supported by programmer: %s\n",
progname, ovsigck? "warning": "error", p->id); progname, ovsigck? "warning": "error", p->id);
if (!ovsigck) if (!ovsigck)
return -1; return -1;
@ -271,8 +267,7 @@ static int avr910_initialize(PROGRAMMER * pgm, AVRPART * p)
avr910_vfy_cmd_sent(pgm, "select device"); avr910_vfy_cmd_sent(pgm, "select device");
if (verbose) if (verbose)
fprintf(stderr, avrdude_message("%s: avr910_devcode selected: 0x%02x\n",
"%s: avr910_devcode selected: 0x%02x\n",
progname, (unsigned)buf[1]); progname, (unsigned)buf[1]);
avr910_enter_prog_mode(pgm); avr910_enter_prog_mode(pgm);
@ -339,15 +334,13 @@ static int avr910_parseextparms(PROGRAMMER * pgm, 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) {
fprintf(stderr, avrdude_message("%s: avr910_parseextparms(): invalid devcode '%s'\n",
"%s: avr910_parseextparms(): invalid devcode '%s'\n",
progname, extended_param); progname, extended_param);
rv = -1; rv = -1;
continue; continue;
} }
if (verbose >= 2) { if (verbose >= 2) {
fprintf(stderr, avrdude_message("%s: avr910_parseextparms(): devcode overwritten as 0x%02x\n",
"%s: avr910_parseextparms(): devcode overwritten as 0x%02x\n",
progname, devcode); progname, devcode);
} }
PDATA(pgm)->devcode = devcode; PDATA(pgm)->devcode = devcode;
@ -356,8 +349,7 @@ static int avr910_parseextparms(PROGRAMMER * pgm, LISTID extparms)
} }
if (strncmp(extended_param, "no_blockmode", strlen("no_blockmode")) == 0) { if (strncmp(extended_param, "no_blockmode", strlen("no_blockmode")) == 0) {
if (verbose >= 2) { if (verbose >= 2) {
fprintf(stderr, avrdude_message("%s: avr910_parseextparms(-x): no testing for Blockmode\n",
"%s: avr910_parseextparms(-x): no testing for Blockmode\n",
progname); progname);
} }
PDATA(pgm)->test_blockmode = 0; PDATA(pgm)->test_blockmode = 0;
@ -365,8 +357,7 @@ static int avr910_parseextparms(PROGRAMMER * pgm, LISTID extparms)
continue; continue;
} }
fprintf(stderr, avrdude_message("%s: avr910_parseextparms(): invalid extended parameter '%s'\n",
"%s: avr910_parseextparms(): invalid extended parameter '%s'\n",
progname, extended_param); progname, extended_param);
rv = -1; rv = -1;
} }
@ -739,7 +730,7 @@ static int avr910_read_sig_bytes(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m)
unsigned char tmp; unsigned char tmp;
if (m->size < 3) { if (m->size < 3) {
fprintf(stderr, "%s: memsize too small for sig byte read", progname); avrdude_message("%s: memsize too small for sig byte read", progname);
return -1; return -1;
} }

View File

@ -28,6 +28,8 @@ 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; /* quiteness level (-q, -qq) */ extern int quell_progress; /* quiteness level (-q, -qq) */
int avrdude_message(const char *format, ...);
#if defined(WIN32NATIVE) #if defined(WIN32NATIVE)
#include "ac_cfg.h" #include "ac_cfg.h"

View File

@ -54,8 +54,7 @@
static int avrftdi_noftdi_open (struct programmer_t *pgm, char * name) static int avrftdi_noftdi_open (struct programmer_t *pgm, char * name)
{ {
fprintf(stderr, avrdude_message("%s: Error: no libftdi or libusb support. Install libftdi1/libusb-1.0 or libftdi/libusb and run configure/make again.\n",
"%s: Error: no libftdi or libusb support. Install libftdi1/libusb-1.0 or libftdi/libusb and run configure/make again.\n",
progname); progname);
return -1; return -1;
@ -145,17 +144,17 @@ void avrftdi_log(int level, const char * func, int line,
if(!skip_prefix) if(!skip_prefix)
{ {
switch(level) { switch(level) {
case ERR: fprintf(stderr, "E "); break; case ERR: avrdude_message("E "); break;
case WARN: fprintf(stderr, "W "); break; case WARN: avrdude_message("W "); break;
case INFO: fprintf(stderr, "I "); break; case INFO: avrdude_message("I "); break;
case DEBUG: fprintf(stderr, "D "); break; case DEBUG: avrdude_message("D "); break;
case TRACE: fprintf(stderr, "T "); break; case TRACE: avrdude_message("T "); break;
default: fprintf(stderr, " "); default: avrdude_message(" ");
} }
fprintf(stderr, "%s(%d): ", func, line); avrdude_message("%s(%d): ", func, line);
} }
va_start(ap, fmt); va_start(ap, fmt);
vfprintf(stderr, fmt, ap); vavrdude_message(fmt, ap);
va_end(ap); va_end(ap);
} }
@ -175,16 +174,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;
fprintf(stderr, "%s begin:\n", desc); avrdude_message("%s begin:\n", desc);
for (i = 0; i < offset; i++) for (i = 0; i < offset; i++)
fprintf(stderr, "%02x ", buf[i]); avrdude_message("%02x ", buf[i]);
fprintf(stderr, "\n"); avrdude_message("\n");
for (i++; i <= len; i++) { for (i++; i <= len; i++) {
fprintf(stderr, "%02x ", buf[i-1]); avrdude_message("%02x ", buf[i-1]);
if((i-offset) != 0 && (i-offset)%width == 0) if((i-offset) != 0 && (i-offset)%width == 0)
fprintf(stderr, "\n"); avrdude_message("\n");
} }
fprintf(stderr, "%s end\n", desc); avrdude_message("%s end\n", desc);
} }
/* /*
@ -357,7 +356,7 @@ static int avrftdi_transmit_bb(PROGRAMMER * pgm, unsigned char mode, const unsig
size_t max_size = MIN(pdata->ftdic->max_packet_size,pdata->tx_buffer_size); size_t max_size = MIN(pdata->ftdic->max_packet_size,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)));
//fprintf(stderr,"blocksize %d \n",blocksize); //avrdude_message("blocksize %d \n",blocksize);
while(remaining) while(remaining)
{ {
@ -673,8 +672,7 @@ static int avrftdi_open(PROGRAMMER * pgm, char *port)
if (usbpid) { if (usbpid) {
pid = *(int *)(ldata(usbpid)); pid = *(int *)(ldata(usbpid));
if (lnext(usbpid)) if (lnext(usbpid))
fprintf(stderr, avrdude_message("%s: Warning: using PID 0x%04x, ignoring remaining PIDs in list\n",
"%s: Warning: using PID 0x%04x, ignoring remaining PIDs in list\n",
progname, pid); progname, pid);
} else } else
pid = USB_DEVICE_FT2232; pid = USB_DEVICE_FT2232;

View File

@ -43,7 +43,7 @@ enum { ERR, WARN, INFO, DEBUG, TRACE };
do { \ do { \
if ((x)) \ if ((x)) \
{ \ { \
fprintf(stderr, "%s:%d %s() %s: %s (%d)\n\t%s\n", \ avrdude_message("%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; \
@ -54,7 +54,7 @@ enum { ERR, WARN, INFO, DEBUG, TRACE };
do { \ do { \
if ((x)) \ if ((x)) \
{ \ { \
fprintf(stderr, "%s:%d %s() %s: %s (%d)\n\t%s\n", \ avrdude_message("%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)); \
} \ } \

View File

@ -37,7 +37,7 @@ OPCODE * avr_new_opcode(void)
m = (OPCODE *)malloc(sizeof(*m)); m = (OPCODE *)malloc(sizeof(*m));
if (m == NULL) { if (m == NULL) {
fprintf(stderr, "avr_new_opcode(): out of memory\n"); avrdude_message("avr_new_opcode(): out of memory\n");
exit(1); exit(1);
} }
@ -57,7 +57,7 @@ static OPCODE * avr_dup_opcode(OPCODE * op)
m = (OPCODE *)malloc(sizeof(*m)); m = (OPCODE *)malloc(sizeof(*m));
if (m == NULL) { if (m == NULL) {
fprintf(stderr, "avr_dup_opcode(): out of memory\n"); avrdude_message("avr_dup_opcode(): out of memory\n");
exit(1); exit(1);
} }
@ -250,7 +250,7 @@ AVRMEM * avr_new_memtype(void)
m = (AVRMEM *)malloc(sizeof(*m)); m = (AVRMEM *)malloc(sizeof(*m));
if (m == NULL) { if (m == NULL) {
fprintf(stderr, "avr_new_memtype(): out of memory\n"); avrdude_message("avr_new_memtype(): out of memory\n");
exit(1); exit(1);
} }
@ -273,13 +273,13 @@ int avr_initmem(AVRPART * p)
m = ldata(ln); m = ldata(ln);
m->buf = (unsigned char *) malloc(m->size); m->buf = (unsigned char *) malloc(m->size);
if (m->buf == NULL) { if (m->buf == NULL) {
fprintf(stderr, "%s: can't alloc buffer for %s size of %d bytes\n", avrdude_message("%s: can't alloc buffer for %s size of %d bytes\n",
progname, m->desc, m->size); progname, m->desc, m->size);
return -1; return -1;
} }
m->tags = (unsigned char *) malloc(m->size); m->tags = (unsigned char *) malloc(m->size);
if (m->tags == NULL) { if (m->tags == NULL) {
fprintf(stderr, "%s: can't alloc buffer for %s size of %d bytes\n", avrdude_message("%s: can't alloc buffer for %s size of %d bytes\n",
progname, m->desc, m->size); progname, m->desc, m->size);
return -1; return -1;
} }
@ -301,8 +301,7 @@ AVRMEM * avr_dup_mem(AVRMEM * m)
if (m->buf != NULL) { if (m->buf != NULL) {
n->buf = (unsigned char *)malloc(n->size); n->buf = (unsigned char *)malloc(n->size);
if (n->buf == NULL) { if (n->buf == NULL) {
fprintf(stderr, avrdude_message("avr_dup_mem(): out of memory (memsize=%d)\n",
"avr_dup_mem(): out of memory (memsize=%d)\n",
n->size); n->size);
exit(1); exit(1);
} }
@ -312,8 +311,7 @@ AVRMEM * avr_dup_mem(AVRMEM * m)
if (m->tags != NULL) { if (m->tags != NULL) {
n->tags = (unsigned char *)malloc(n->size); n->tags = (unsigned char *)malloc(n->size);
if (n->tags == NULL) { if (n->tags == NULL) {
fprintf(stderr, avrdude_message("avr_dup_mem(): out of memory (memsize=%d)\n",
"avr_dup_mem(): out of memory (memsize=%d)\n",
n->size); n->size);
exit(1); exit(1);
} }
@ -407,8 +405,7 @@ void avr_mem_display(const char * prefix, FILE * f, AVRMEM * m, int type,
m->readback[0], m->readback[0],
m->readback[1]); m->readback[1]);
if (verbose > 4) { if (verbose > 4) {
fprintf(stderr, avrdude_message("%s Memory Ops:\n"
"%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);
@ -445,7 +442,7 @@ AVRPART * avr_new_part(void)
p = (AVRPART *)malloc(sizeof(AVRPART)); p = (AVRPART *)malloc(sizeof(AVRPART));
if (p == NULL) { if (p == NULL) {
fprintf(stderr, "new_part(): out of memory\n"); avrdude_message("new_part(): out of memory\n");
exit(1); exit(1);
} }

View File

@ -75,8 +75,7 @@ static void bitbang_calibrate_delay(void)
{ {
has_perfcount = 1; has_perfcount = 1;
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, avrdude_message("%s: Using performance counter for bitbang delays\n",
"%s: Using performance counter for bitbang delays\n",
progname); progname);
} }
else else
@ -91,8 +90,7 @@ static void bitbang_calibrate_delay(void)
* comparable hardware. * comparable hardware.
*/ */
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, avrdude_message("%s: Using guessed per-microsecond delay count for bitbang delays\n",
"%s: Using guessed per-microsecond delay count for bitbang delays\n",
progname); progname);
delay_decrement = 100; delay_decrement = 100;
} }
@ -101,8 +99,7 @@ static void bitbang_calibrate_delay(void)
volatile int i; volatile int i;
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, avrdude_message("%s: Calibrating delay loop...",
"%s: Calibrating delay loop...",
progname); progname);
i = 0; i = 0;
done = 0; done = 0;
@ -130,8 +127,7 @@ static void bitbang_calibrate_delay(void)
*/ */
delay_decrement = -i / 100000; delay_decrement = -i / 100000;
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, avrdude_message(" calibrated to %d cycles per us\n",
" calibrated to %d cycles per us\n",
delay_decrement); delay_decrement);
#endif /* WIN32NATIVE */ #endif /* WIN32NATIVE */
} }
@ -271,7 +267,7 @@ int bitbang_tpi_rx(PROGRAMMER * pgm)
break; break;
} }
if (b != 0) { if (b != 0) {
fprintf(stderr, "bitbang_tpi_rx: start bit not received correctly\n"); avrdude_message("bitbang_tpi_rx: start bit not received correctly\n");
return -1; return -1;
} }
@ -286,7 +282,7 @@ int bitbang_tpi_rx(PROGRAMMER * pgm)
/* parity bit */ /* parity bit */
if (bitbang_tpi_clk(pgm) != parity) { if (bitbang_tpi_clk(pgm) != parity) {
fprintf(stderr, "bitbang_tpi_rx: parity bit is wrong\n"); avrdude_message("bitbang_tpi_rx: parity bit is wrong\n");
return -1; return -1;
} }
@ -295,7 +291,7 @@ int bitbang_tpi_rx(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) {
fprintf(stderr, "bitbang_tpi_rx: stop bits not received correctly\n"); avrdude_message("bitbang_tpi_rx: stop bits not received correctly\n");
return -1; return -1;
} }
@ -342,15 +338,15 @@ int bitbang_cmd(PROGRAMMER * pgm, const unsigned char *cmd,
if(verbose >= 2) if(verbose >= 2)
{ {
fprintf(stderr, "bitbang_cmd(): [ "); avrdude_message("bitbang_cmd(): [ ");
for(i = 0; i < 4; i++) for(i = 0; i < 4; i++)
fprintf(stderr, "%02X ", cmd[i]); avrdude_message("%02X ", cmd[i]);
fprintf(stderr, "] [ "); avrdude_message("] [ ");
for(i = 0; i < 4; i++) for(i = 0; i < 4; i++)
{ {
fprintf(stderr, "%02X ", res[i]); avrdude_message("%02X ", res[i]);
} }
fprintf(stderr, "]\n"); avrdude_message("]\n");
} }
return 0; return 0;
@ -377,15 +373,15 @@ int bitbang_cmd_tpi(PROGRAMMER * pgm, const unsigned char *cmd,
if(verbose >= 2) if(verbose >= 2)
{ {
fprintf(stderr, "bitbang_cmd_tpi(): [ "); avrdude_message("bitbang_cmd_tpi(): [ ");
for(i = 0; i < cmd_len; i++) for(i = 0; i < cmd_len; i++)
fprintf(stderr, "%02X ", cmd[i]); avrdude_message("%02X ", cmd[i]);
fprintf(stderr, "] [ "); avrdude_message("] [ ");
for(i = 0; i < res_len; i++) for(i = 0; i < res_len; i++)
{ {
fprintf(stderr, "%02X ", res[i]); avrdude_message("%02X ", res[i]);
} }
fprintf(stderr, "]\n"); avrdude_message("]\n");
} }
pgm->pgm_led(pgm, OFF); pgm->pgm_led(pgm, OFF);
@ -413,15 +409,15 @@ int bitbang_spi(PROGRAMMER * pgm, const unsigned char *cmd,
if(verbose >= 2) if(verbose >= 2)
{ {
fprintf(stderr, "bitbang_cmd(): [ "); avrdude_message("bitbang_cmd(): [ ");
for(i = 0; i < count; i++) for(i = 0; i < count; i++)
fprintf(stderr, "%02X ", cmd[i]); avrdude_message("%02X ", cmd[i]);
fprintf(stderr, "] [ "); avrdude_message("] [ ");
for(i = 0; i < count; i++) for(i = 0; i < count; i++)
{ {
fprintf(stderr, "%02X ", res[i]); avrdude_message("%02X ", res[i]);
} }
fprintf(stderr, "]\n"); avrdude_message("]\n");
} }
return 0; return 0;
@ -449,7 +445,7 @@ int bitbang_chip_erase(PROGRAMMER * pgm, 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) {
fprintf(stderr, "No flash memory to erase for part %s\n", avrdude_message("No flash memory to erase for part %s\n",
p->desc); p->desc);
return -1; return -1;
} }
@ -470,7 +466,7 @@ int bitbang_chip_erase(PROGRAMMER * pgm, AVRPART * p)
} }
if (p->op[AVR_OP_CHIP_ERASE] == NULL) { if (p->op[AVR_OP_CHIP_ERASE] == NULL) {
fprintf(stderr, "chip erase instruction not defined for part \"%s\"\n", avrdude_message("chip erase instruction not defined for part \"%s\"\n",
p->desc); p->desc);
return -1; return -1;
} }
@ -511,7 +507,7 @@ int bitbang_program_enable(PROGRAMMER * pgm, AVRPART * p)
} }
if (p->op[AVR_OP_PGM_ENABLE] == NULL) { if (p->op[AVR_OP_PGM_ENABLE] == NULL) {
fprintf(stderr, "program enable instruction not defined for part \"%s\"\n", avrdude_message("program enable instruction not defined for part \"%s\"\n",
p->desc); p->desc);
return -1; return -1;
} }
@ -544,7 +540,7 @@ int bitbang_initialize(PROGRAMMER * pgm, AVRPART * p)
if (p->flags & AVRPART_HAS_TPI) { if (p->flags & AVRPART_HAS_TPI) {
/* make sure cmd_tpi() is defined */ /* make sure cmd_tpi() is defined */
if (pgm->cmd_tpi == NULL) { if (pgm->cmd_tpi == NULL) {
fprintf(stderr, "%s: Error: %s programmer does not support TPI\n", avrdude_message("%s: Error: %s programmer does not support TPI\n",
progname, pgm->type); progname, pgm->type);
return -1; return -1;
} }
@ -554,21 +550,21 @@ int bitbang_initialize(PROGRAMMER * pgm, AVRPART * p)
usleep(1000); usleep(1000);
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, "doing MOSI-MISO link check\n"); avrdude_message("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) {
fprintf(stderr, "MOSI->MISO 0 failed\n"); avrdude_message("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) {
fprintf(stderr, "MOSI->MISO 1 failed\n"); avrdude_message("MOSI->MISO 1 failed\n");
return -1; return -1;
} }
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, "MOSI-MISO link present\n"); avrdude_message("MOSI-MISO link present\n");
} }
pgm->setpin(pgm, PIN_AVR_SCK, 0); pgm->setpin(pgm, PIN_AVR_SCK, 0);
@ -589,7 +585,7 @@ int bitbang_initialize(PROGRAMMER * pgm, 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) {
fprintf(stderr, "TPIIR not correct\n"); avrdude_message("TPIIR not correct\n");
return -1; return -1;
} }
} else { } else {
@ -623,7 +619,7 @@ int bitbang_initialize(PROGRAMMER * pgm, 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) {
fprintf(stderr, "%s: AVR device not responding\n", progname); avrdude_message("%s: AVR device not responding\n", progname);
return -1; return -1;
} }
} }
@ -634,7 +630,7 @@ int bitbang_initialize(PROGRAMMER * pgm, AVRPART * p)
static int verify_pin_assigned(PROGRAMMER * pgm, int pin, char * desc) static int verify_pin_assigned(PROGRAMMER * pgm, int pin, char * desc)
{ {
if (pgm->pinno[pin] == 0) { if (pgm->pinno[pin] == 0) {
fprintf(stderr, "%s: error: no pin has been assigned for %s\n", avrdude_message("%s: error: no pin has been assigned for %s\n",
progname, desc); progname, desc);
return -1; return -1;
} }
@ -658,7 +654,7 @@ int bitbang_check_prerequisites(PROGRAMMER *pgm)
return -1; return -1;
if (pgm->cmd == NULL) { if (pgm->cmd == NULL) {
fprintf(stderr, "%s: error: no cmd() method defined for bitbang programmer\n", avrdude_message("%s: error: no cmd() method defined for bitbang programmer\n",
progname); progname);
return -1; return -1;
} }

View File

@ -98,15 +98,15 @@ static void dump_mem(char *buf, size_t len)
for (i = 0; i<len; i++) { for (i = 0; i<len; i++) {
if (i % 8 == 0) if (i % 8 == 0)
fprintf(stderr, "\t"); avrdude_message("\t");
fprintf(stderr, "0x%02x ", (unsigned)buf[i] & 0xFF); avrdude_message("0x%02x ", (unsigned)buf[i] & 0xFF);
if (i % 8 == 3) if (i % 8 == 3)
fprintf(stderr, " "); avrdude_message(" ");
else if (i % 8 == 7) else if (i % 8 == 7)
fprintf(stderr, "\n"); avrdude_message("\n");
} }
if (i % 8 != 7) if (i % 8 != 7)
fprintf(stderr, "\n"); avrdude_message("\n");
} }
static int buspirate_send_bin(struct programmer_t *pgm, char *data, size_t len) static int buspirate_send_bin(struct programmer_t *pgm, char *data, size_t len)
@ -114,7 +114,7 @@ static int buspirate_send_bin(struct programmer_t *pgm, char *data, size_t len)
int rc; int rc;
if (verbose > 1) { if (verbose > 1) {
fprintf(stderr, "%s: buspirate_send_bin():\n", progname); avrdude_message("%s: buspirate_send_bin():\n", progname);
dump_mem(data, len); dump_mem(data, len);
} }
@ -131,7 +131,7 @@ static int buspirate_recv_bin(struct programmer_t *pgm, char *buf, size_t len)
if (rc < 0) if (rc < 0)
return EOF; return EOF;
if (verbose > 1) { if (verbose > 1) {
fprintf(stderr, "%s: buspirate_recv_bin():\n", progname); avrdude_message("%s: buspirate_recv_bin():\n", progname);
dump_mem(buf, len); dump_mem(buf, len);
} }
@ -144,7 +144,7 @@ static int buspirate_expect_bin(struct programmer_t *pgm,
{ {
char *recv_buf = alloca(expect_len); char *recv_buf = alloca(expect_len);
if (!pgm->flag & BP_FLAG_IN_BINMODE) { if (!pgm->flag & BP_FLAG_IN_BINMODE) {
fprintf(stderr, "BusPirate: Internal error: buspirate_send_bin() called from ascii mode"); avrdude_message("BusPirate: Internal error: buspirate_send_bin() called from ascii mode");
return -1; return -1;
} }
@ -169,7 +169,7 @@ static int buspirate_getc(struct programmer_t *pgm)
unsigned char ch = 0; unsigned char ch = 0;
if (pgm->flag & BP_FLAG_IN_BINMODE) { if (pgm->flag & BP_FLAG_IN_BINMODE) {
fprintf(stderr, "BusPirate: Internal error: buspirate_getc() called from binmode"); avrdude_message("BusPirate: Internal error: buspirate_getc() called from binmode");
return EOF; return EOF;
} }
@ -208,7 +208,7 @@ static char *buspirate_readline_noexit(struct programmer_t *pgm, char *buf, size
} }
serial_recv_timeout = orig_serial_recv_timeout; serial_recv_timeout = orig_serial_recv_timeout;
if (verbose) if (verbose)
fprintf(stderr, "%s: buspirate_readline(): %s%s", avrdude_message("%s: buspirate_readline(): %s%s",
progname, buf, progname, buf,
buf[strlen(buf) - 1] == '\n' ? "" : "\n"); buf[strlen(buf) - 1] == '\n' ? "" : "\n");
if (! buf[0]) if (! buf[0])
@ -223,8 +223,7 @@ static char *buspirate_readline(struct programmer_t *pgm, char *buf, size_t len)
ret = buspirate_readline_noexit(pgm, buf, len); ret = buspirate_readline_noexit(pgm, buf, len);
if (! ret) { if (! ret) {
fprintf(stderr, avrdude_message("%s: buspirate_readline(): programmer is not responding\n",
"%s: buspirate_readline(): programmer is not responding\n",
progname); progname);
return NULL; return NULL;
} }
@ -235,10 +234,10 @@ static int buspirate_send(struct programmer_t *pgm, char *str)
int rc; int rc;
if (verbose) if (verbose)
fprintf(stderr, "%s: buspirate_send(): %s", progname, str); avrdude_message("%s: buspirate_send(): %s", progname, str);
if (pgm->flag & BP_FLAG_IN_BINMODE) { if (pgm->flag & BP_FLAG_IN_BINMODE) {
fprintf(stderr, "BusPirate: Internal error: buspirate_send() called from binmode"); avrdude_message("BusPirate: Internal error: buspirate_send() called from binmode");
return -1; return -1;
} }
@ -311,8 +310,8 @@ buspirate_parseextparms(struct programmer_t *pgm, LISTID extparms)
} }
if (sscanf(extended_param, "spifreq=%d", &spifreq) == 1) { if (sscanf(extended_param, "spifreq=%d", &spifreq) == 1) {
if (spifreq & (~0x07)) { if (spifreq & (~0x07)) {
fprintf(stderr, "BusPirate: spifreq must be between 0 and 7.\n"); avrdude_message("BusPirate: spifreq must be between 0 and 7.\n");
fprintf(stderr, "BusPirate: see BusPirate manual for details.\n"); avrdude_message("BusPirate: see BusPirate manual for details.\n");
return -1; return -1;
} }
pgm->flag = (pgm->flag & ~BP_FLAG_XPARM_RAWFREQ) | pgm->flag = (pgm->flag & ~BP_FLAG_XPARM_RAWFREQ) |
@ -324,7 +323,7 @@ buspirate_parseextparms(struct programmer_t *pgm, LISTID extparms)
unsigned rawfreq; unsigned rawfreq;
if (sscanf(extended_param, "rawfreq=%u", &rawfreq) == 1) { if (sscanf(extended_param, "rawfreq=%u", &rawfreq) == 1) {
if (rawfreq >= 4) { if (rawfreq >= 4) {
fprintf(stderr, "BusPirate: rawfreq must be " avrdude_message("BusPirate: rawfreq must be "
"between 0 and 3.\n"); "between 0 and 3.\n");
return -1; return -1;
} }
@ -337,8 +336,8 @@ buspirate_parseextparms(struct programmer_t *pgm, LISTID extparms)
if (sscanf(extended_param, "cpufreq=%d", &cpufreq) == 1) { if (sscanf(extended_param, "cpufreq=%d", &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) {
fprintf(stderr, "BusPirate: cpufreq must be between 125 and 4000 kHz.\n"); avrdude_message("BusPirate: cpufreq must be between 125 and 4000 kHz.\n");
fprintf(stderr, "BusPirate: see BusPirate manual for details.\n"); avrdude_message("BusPirate: see BusPirate manual for details.\n");
return -1; return -1;
} }
PDATA(pgm)->cpufreq = cpufreq; PDATA(pgm)->cpufreq = cpufreq;
@ -357,7 +356,7 @@ buspirate_parseextparms(struct programmer_t *pgm, 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 {
fprintf(stderr, "BusPirate: reset must be either CS or AUX.\n"); avrdude_message("BusPirate: reset must be either CS or AUX.\n");
return -1; return -1;
} }
} }
@ -376,7 +375,7 @@ buspirate_parseextparms(struct programmer_t *pgm, 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) {
fprintf(stderr, "BusPirate: serial_recv_timeout must be greater 0.\n"); avrdude_message("BusPirate: 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;
@ -395,18 +394,18 @@ buspirate_verifyconfig(struct programmer_t *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)) {
fprintf(stderr, "BusPirate: RESET pin other than CS is not supported in ASCII mode\n"); avrdude_message("BusPirate: RESET pin other than CS is not supported in ASCII mode\n");
return -1; return -1;
} }
if (( (pgm->flag & BP_FLAG_XPARM_SPIFREQ) || if (( (pgm->flag & BP_FLAG_XPARM_SPIFREQ) ||
(pgm->flag & BP_FLAG_XPARM_RAWFREQ) ) && buspirate_uses_ascii(pgm)) { (pgm->flag & BP_FLAG_XPARM_RAWFREQ) ) && buspirate_uses_ascii(pgm)) {
fprintf(stderr, "BusPirate: SPI speed selection is not supported in ASCII mode\n"); avrdude_message("BusPirate: SPI speed selection is not supported in ASCII mode\n");
return -1; return -1;
} }
if ((pgm->flag & BP_FLAG_XPARM_CPUFREQ) && !buspirate_uses_ascii(pgm)) { if ((pgm->flag & BP_FLAG_XPARM_CPUFREQ) && !buspirate_uses_ascii(pgm)) {
fprintf(stderr, "BusPirate: Setting cpufreq is only supported in ASCII mode\n"); avrdude_message("BusPirate: Setting cpufreq is only supported in ASCII mode\n");
return -1; return -1;
} }
@ -465,12 +464,12 @@ static void buspirate_reset_from_binmode(struct programmer_t *pgm)
} }
if (pgm->flag & BP_FLAG_IN_BINMODE) { if (pgm->flag & BP_FLAG_IN_BINMODE) {
fprintf(stderr, "BusPirate reset failed. You may need to powercycle it.\n"); avrdude_message("BusPirate reset failed. You may need to powercycle it.\n");
return; return;
} }
if (verbose) if (verbose)
fprintf(stderr, "BusPirate is back in the text mode\n"); avrdude_message("BusPirate is back in the text mode\n");
} }
static int buspirate_start_mode_bin(struct programmer_t *pgm) static int buspirate_start_mode_bin(struct programmer_t *pgm)
@ -515,12 +514,12 @@ static int buspirate_start_mode_bin(struct programmer_t *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(buf, "BBIO%d", &PDATA(pgm)->binmode_version) != 1) { if (sscanf(buf, "BBIO%d", &PDATA(pgm)->binmode_version) != 1) {
fprintf(stderr, "Binary mode not confirmed: '%s'\n", buf); avrdude_message("Binary mode not confirmed: '%s'\n", buf);
buspirate_reset_from_binmode(pgm); buspirate_reset_from_binmode(pgm);
return -1; return -1;
} }
if (verbose) if (verbose)
fprintf(stderr, "BusPirate binmode version: %d\n", avrdude_message("BusPirate binmode version: %d\n",
PDATA(pgm)->binmode_version); PDATA(pgm)->binmode_version);
pgm->flag |= BP_FLAG_IN_BINMODE; pgm->flag |= BP_FLAG_IN_BINMODE;
@ -532,18 +531,18 @@ static int buspirate_start_mode_bin(struct programmer_t *pgm)
buspirate_recv_bin(pgm, buf, 4); buspirate_recv_bin(pgm, buf, 4);
if (sscanf(buf, submode->entered_format, if (sscanf(buf, submode->entered_format,
&PDATA(pgm)->submode_version) != 1) { &PDATA(pgm)->submode_version) != 1) {
fprintf(stderr, "%s mode not confirmed: '%s'\n", avrdude_message("%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;
} }
if (verbose) if (verbose)
fprintf(stderr, "BusPirate %s version: %d\n", avrdude_message("BusPirate %s version: %d\n",
submode->name, PDATA(pgm)->submode_version); submode->name, PDATA(pgm)->submode_version);
if (pgm->flag & BP_FLAG_NOPAGEDWRITE) { if (pgm->flag & BP_FLAG_NOPAGEDWRITE) {
if (verbose) if (verbose)
fprintf(stderr, "%s: Paged flash write disabled.\n", progname); avrdude_message("%s: Paged flash write disabled.\n", progname);
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: */
@ -561,13 +560,13 @@ static int buspirate_start_mode_bin(struct programmer_t *pgm)
buspirate_send_bin(pgm, buf, 1); buspirate_send_bin(pgm, buf, 1);
if (verbose) if (verbose)
fprintf(stderr, "%s: Disabling paged flash write. (Need BusPirate firmware >=v5.10.)\n", progname); avrdude_message("%s: Disabling paged flash write. (Need BusPirate firmware >=v5.10.)\n", progname);
/* Flush serial buffer: */ /* Flush serial buffer: */
serial_drain(&pgm->fd, 0); serial_drain(&pgm->fd, 0);
} else { } else {
if (verbose) if (verbose)
fprintf(stderr, "%s: Paged flash write enabled.\n", progname); avrdude_message("%s: Paged flash write enabled.\n", progname);
} }
} }
@ -589,7 +588,7 @@ static int buspirate_start_mode_bin(struct programmer_t *pgm)
/* AVR Extended Commands - test for existence */ /* AVR Extended Commands - test for existence */
if (pgm->flag & BP_FLAG_NOPAGEDREAD) { if (pgm->flag & BP_FLAG_NOPAGEDREAD) {
if (verbose) if (verbose)
fprintf(stderr, "%s: Paged flash read disabled.\n", progname); avrdude_message("%s: Paged flash read disabled.\n", progname);
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);
@ -600,9 +599,9 @@ static int buspirate_start_mode_bin(struct programmer_t *pgm)
buspirate_send_bin(pgm, buf, 1); buspirate_send_bin(pgm, buf, 1);
buspirate_recv_bin(pgm, buf, 3); buspirate_recv_bin(pgm, buf, 3);
ver = buf[1] << 8 | buf[2]; ver = buf[1] << 8 | buf[2];
if (verbose) fprintf(stderr, "AVR Extended Commands version %d\n", ver); if (verbose) avrdude_message("AVR Extended Commands version %d\n", ver);
} else { } else {
if (verbose) fprintf(stderr, "AVR Extended Commands not found.\n"); if (verbose) avrdude_message("AVR Extended Commands not found.\n");
pgm->flag |= BP_FLAG_NOPAGEDREAD; pgm->flag |= BP_FLAG_NOPAGEDREAD;
pgm->paged_load = NULL; pgm->paged_load = NULL;
} }
@ -628,10 +627,9 @@ static int buspirate_start_spi_mode_ascii(struct programmer_t *pgm)
break; break;
} }
if (spi_cmd == -1) { if (spi_cmd == -1) {
fprintf(stderr, avrdude_message("%s: SPI mode number not found. Does your BusPirate support SPI?\n",
"%s: SPI mode number not found. Does your BusPirate support SPI?\n",
progname); progname);
fprintf(stderr, "%s: Try powercycling your BusPirate and try again.\n", avrdude_message("%s: Try powercycling your BusPirate and try again.\n",
progname); progname);
return -1; return -1;
} }
@ -649,7 +647,7 @@ static int buspirate_start_spi_mode_ascii(struct programmer_t *pgm)
} }
if (buspirate_is_prompt(rcvd)) { if (buspirate_is_prompt(rcvd)) {
if (strncmp(rcvd, "SPI>", 4) == 0) { if (strncmp(rcvd, "SPI>", 4) == 0) {
if (verbose) fprintf(stderr, "BusPirate is now configured for SPI\n"); if (verbose) avrdude_message("BusPirate is now configured for SPI\n");
break; break;
} }
/* Not yet 'SPI>' prompt */ /* Not yet 'SPI>' prompt */
@ -676,7 +674,7 @@ static void buspirate_enable(struct programmer_t *pgm)
/* 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)) {
fprintf(stderr, "Attempting to initiate BusPirate binary mode...\n"); avrdude_message("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, "\n\n", 2); buspirate_send_bin(pgm, "\n\n", 2);
@ -688,23 +686,23 @@ static void buspirate_enable(struct programmer_t *pgm)
if (buspirate_start_mode_bin(pgm) >= 0) if (buspirate_start_mode_bin(pgm) >= 0)
return; return;
else else
fprintf(stderr, "%s: Failed to start binary mode, falling back to ASCII...\n", progname); avrdude_message("%s: Failed to start binary mode, falling back to ASCII...\n", progname);
} }
fprintf(stderr, "Attempting to initiate BusPirate ASCII mode...\n"); avrdude_message("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, reset_str, strlen(reset_str)); rc = buspirate_send_bin(pgm, reset_str, strlen(reset_str));
if (rc) { if (rc) {
fprintf(stderr, "BusPirate is not responding. Serial port error: %d\n", rc); avrdude_message("BusPirate is not responding. Serial port error: %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) {
fprintf(stderr, "%s: Fatal: Programmer is not responding.\n", progname); avrdude_message("%s: Fatal: Programmer is not responding.\n", progname);
return; return;
} }
if (strncmp(rcvd, "Are you sure?", 13) == 0) { if (strncmp(rcvd, "Are you sure?", 13) == 0) {
@ -719,13 +717,13 @@ static void buspirate_enable(struct programmer_t *pgm)
break; break;
} }
if (print_banner) if (print_banner)
fprintf(stderr, "** %s", rcvd); avrdude_message("** %s", rcvd);
} }
if (!(pgm->flag & BP_FLAG_IN_BINMODE)) { if (!(pgm->flag & BP_FLAG_IN_BINMODE)) {
fprintf(stderr, "BusPirate: using ASCII mode\n"); avrdude_message("BusPirate: using ASCII mode\n");
if (buspirate_start_spi_mode_ascii(pgm) < 0) { if (buspirate_start_spi_mode_ascii(pgm) < 0) {
fprintf(stderr, "%s: Failed to start ascii SPI mode\n", progname); avrdude_message("%s: Failed to start ascii SPI mode\n", progname);
return; return;
} }
} }
@ -766,15 +764,15 @@ static void buspirate_powerup(struct programmer_t *pgm)
} }
} }
if(!ok) { if(!ok) {
fprintf(stderr, "%s: warning: did not get a response to start PWM command.\n", progname); avrdude_message("%s: warning: did not get a response to start PWM command.\n", progname);
} }
} }
return; return;
} }
} }
fprintf(stderr, "%s: warning: did not get a response to PowerUp command.\n", progname); avrdude_message("%s: warning: did not get a response to PowerUp command.\n", progname);
fprintf(stderr, "%s: warning: Trying to continue anyway...\n", progname); avrdude_message("%s: warning: Trying to continue anyway...\n", progname);
} }
static void buspirate_powerdown(struct programmer_t *pgm) static void buspirate_powerdown(struct programmer_t *pgm)
@ -787,14 +785,14 @@ static void buspirate_powerdown(struct programmer_t *pgm)
} else { } else {
if (pgm->flag & BP_FLAG_XPARM_CPUFREQ) { if (pgm->flag & BP_FLAG_XPARM_CPUFREQ) {
if (!buspirate_expect(pgm, "g\n", "PWM disabled", 1)) { if (!buspirate_expect(pgm, "g\n", "PWM disabled", 1)) {
fprintf(stderr, "%s: warning: did not get a response to stop PWM command.\n", progname); avrdude_message("%s: warning: did not get a response to stop PWM command.\n", progname);
} }
} }
if (buspirate_expect(pgm, "w\n", "Power supplies OFF", 1)) if (buspirate_expect(pgm, "w\n", "Power supplies OFF", 1))
return; return;
} }
fprintf(stderr, "%s: warning: did not get a response to PowerDown command.\n", progname); avrdude_message("%s: warning: did not get a response to PowerDown command.\n", progname);
} }
static int buspirate_cmd_bin(struct programmer_t *pgm, static int buspirate_cmd_bin(struct programmer_t *pgm,
@ -837,7 +835,7 @@ static int buspirate_cmd_ascii(struct programmer_t *pgm,
} }
if (i != 4) { if (i != 4) {
fprintf(stderr, "%s: error: SPI has not read 4 bytes back\n", progname); avrdude_message("%s: error: SPI has not read 4 bytes back\n", progname);
return -1; return -1;
} }
@ -871,11 +869,11 @@ static int buspirate_paged_load(
unsigned char buf[275]; unsigned char buf[275];
unsigned int addr = 0; unsigned int addr = 0;
if (verbose > 1) fprintf(stderr, "BusPirate: buspirate_paged_load(..,%s,%d,%d,%d)\n",m->desc,m->page_size,address,n_bytes); if (verbose > 1) avrdude_message("BusPirate: 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 (pgm->flag & BP_FLAG_NOPAGEDREAD) { if (pgm->flag & BP_FLAG_NOPAGEDREAD) {
fprintf(stderr, "BusPirate: buspirate_paged_load() called while in nopagedread mode!\n"); avrdude_message("BusPirate: buspirate_paged_load() called while in nopagedread mode!\n");
return -1; return -1;
} }
@ -904,7 +902,7 @@ static int buspirate_paged_load(
buspirate_recv_bin(pgm, buf, 1); buspirate_recv_bin(pgm, buf, 1);
if (buf[0] != 0x01) { if (buf[0] != 0x01) {
fprintf(stderr, "BusPirate: Paged Read command returned zero.\n"); avrdude_message("BusPirate: Paged Read command returned zero.\n");
return -1; return -1;
} }
@ -951,14 +949,12 @@ static int buspirate_paged_write(struct programmer_t *pgm,
/* pre-check opcodes */ /* pre-check opcodes */
if (m->op[AVR_OP_LOADPAGE_LO] == NULL) { if (m->op[AVR_OP_LOADPAGE_LO] == NULL) {
fprintf(stderr, avrdude_message("%s failure: %s command not defined for %s\n",
"%s failure: %s command not defined for %s\n",
progname, "AVR_OP_LOADPAGE_LO", 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) {
fprintf(stderr, avrdude_message("%s failure: %s command not defined for %s\n",
"%s failure: %s command not defined for %s\n",
progname, "AVR_OP_LOADPAGE_HI", p->desc); progname, "AVR_OP_LOADPAGE_HI", p->desc);
return -1; return -1;
} }
@ -1019,7 +1015,7 @@ static int buspirate_paged_write(struct programmer_t *pgm,
/* 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)) {
fprintf(stderr, "BusPirate: Fatal error: Write Then Read did not succeed.\n"); avrdude_message("BusPirate: Fatal 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;
@ -1050,8 +1046,7 @@ static int buspirate_program_enable(struct programmer_t *pgm, 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) {
fprintf(stderr, avrdude_message("program enable instruction not defined for part \"%s\"\n",
"program enable instruction not defined for part \"%s\"\n",
p->desc); p->desc);
return -1; return -1;
} }
@ -1072,8 +1067,7 @@ static int buspirate_chip_erase(struct programmer_t *pgm, 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) {
fprintf(stderr, avrdude_message("chip erase instruction not defined for part \"%s\"\n",
"chip erase instruction not defined for part \"%s\"\n",
p->desc); p->desc);
return -1; return -1;
} }
@ -1097,7 +1091,7 @@ static void buspirate_setup(struct programmer_t *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) {
fprintf(stderr, "%s: buspirate_initpgm(): Out of memory allocating private data\n", avrdude_message("%s: buspirate_initpgm(): Out of memory allocating private data\n",
progname); progname);
exit(1); exit(1);
} }
@ -1151,7 +1145,7 @@ static void buspirate_bb_enable(struct programmer_t *pgm)
if (bitbang_check_prerequisites(pgm) < 0) if (bitbang_check_prerequisites(pgm) < 0)
return; /* XXX should treat as error */ return; /* XXX should treat as error */
fprintf(stderr, "Attempting to initiate BusPirate bitbang binary mode...\n"); avrdude_message("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, "\n\n", 2); buspirate_send_bin(pgm, "\n\n", 2);
@ -1166,11 +1160,11 @@ static void buspirate_bb_enable(struct programmer_t *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(buf, "BBIO%d", &PDATA(pgm)->binmode_version) != 1) { if (sscanf(buf, "BBIO%d", &PDATA(pgm)->binmode_version) != 1) {
fprintf(stderr, "Binary mode not confirmed: '%s'\n", buf); avrdude_message("Binary mode not confirmed: '%s'\n", buf);
buspirate_reset_from_binmode(pgm); buspirate_reset_from_binmode(pgm);
return; return;
} }
fprintf(stderr, "BusPirate binmode version: %d\n", avrdude_message("BusPirate binmode version: %d\n",
PDATA(pgm)->binmode_version); PDATA(pgm)->binmode_version);
pgm->flag |= BP_FLAG_IN_BINMODE; pgm->flag |= BP_FLAG_IN_BINMODE;

View File

@ -64,8 +64,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) {
fprintf(stderr, avrdude_message("%s: butterfly_setup(): Out of memory allocating private data\n",
"%s: butterfly_setup(): Out of memory allocating private data\n",
progname); progname);
exit(1); exit(1);
} }
@ -89,8 +88,7 @@ static int butterfly_recv(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) {
fprintf(stderr, avrdude_message("%s: butterfly_recv(): programmer is not responding\n",
"%s: butterfly_recv(): programmer is not responding\n",
progname); progname);
return -1; return -1;
} }
@ -110,7 +108,7 @@ static int butterfly_vfy_cmd_sent(PROGRAMMER * pgm, char * errmsg)
butterfly_recv(pgm, &c, 1); butterfly_recv(pgm, &c, 1);
if (c != '\r') { if (c != '\r') {
fprintf(stderr, "%s: error: programmer did not respond to command: %s\n", avrdude_message("%s: error: programmer did not respond to command: %s\n",
progname, errmsg); progname, errmsg);
return -1; return -1;
} }
@ -225,7 +223,7 @@ static int butterfly_initialize(PROGRAMMER * pgm, 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.
*/ */
fprintf(stderr, "Connecting to programmer: "); avrdude_message("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"};
@ -249,7 +247,7 @@ static int butterfly_initialize(PROGRAMMER * pgm, AVRPART * p)
butterfly_recv(pgm, &c, 1); butterfly_recv(pgm, &c, 1);
if ( c != 'M' && c != '?') if ( c != 'M' && c != '?')
{ {
fprintf(stderr, "\nConnection FAILED."); avrdude_message("\nConnection FAILED.");
return -1; return -1;
} }
else else
@ -296,12 +294,12 @@ static int butterfly_initialize(PROGRAMMER * pgm, AVRPART * p)
butterfly_send(pgm, "p", 1); butterfly_send(pgm, "p", 1);
butterfly_recv(pgm, &type, 1); butterfly_recv(pgm, &type, 1);
fprintf(stderr, "Found programmer: Id = \"%s\"; type = %c\n", id, type); avrdude_message("Found programmer: Id = \"%s\"; type = %c\n", id, type);
fprintf(stderr, " Software Version = %c.%c; ", sw[0], sw[1]); avrdude_message(" Software Version = %c.%c; ", sw[0], sw[1]);
if (hw[0]=='?') { if (hw[0]=='?') {
fprintf(stderr, "No Hardware Version given.\n"); avrdude_message("No Hardware Version given.\n");
} else { } else {
fprintf(stderr, "Hardware Version = %c.%c\n", hw[0], hw[1]); avrdude_message("Hardware Version = %c.%c\n", hw[0], hw[1]);
}; };
/* See if programmer supports autoincrement of address. */ /* See if programmer supports autoincrement of address. */
@ -309,15 +307,14 @@ static int butterfly_initialize(PROGRAMMER * pgm, 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')
fprintf(stderr, "Programmer supports auto addr increment.\n"); avrdude_message("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') {
fprintf(stderr, avrdude_message("%s: error: buffered memory access not supported. Maybe it isn't\n"\
"%s: error: 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", progname);
return -1; return -1;
}; };
@ -325,14 +322,13 @@ static int butterfly_initialize(PROGRAMMER * pgm, AVRPART * p)
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;
fprintf(stderr, avrdude_message("Programmer supports buffered memory access with buffersize=%i bytes.\n",
"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);
fprintf(stderr, "\nProgrammer supports the following devices:\n"); avrdude_message("\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);
@ -341,9 +337,9 @@ static int butterfly_initialize(PROGRAMMER * pgm, AVRPART * p)
if (c == 0) if (c == 0)
break; break;
fprintf(stderr, " Device code: 0x%02x\n", (unsigned int)(unsigned char)c); avrdude_message(" Device code: 0x%02x\n", (unsigned int)(unsigned char)c);
}; };
fprintf(stderr,"\n"); avrdude_message("\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
@ -361,8 +357,7 @@ static int butterfly_initialize(PROGRAMMER * pgm, AVRPART * p)
return -1; return -1;
if (verbose) if (verbose)
fprintf(stderr, avrdude_message("%s: devcode selected: 0x%02x\n",
"%s: devcode selected: 0x%02x\n",
progname, (unsigned)buf[1]); progname, (unsigned)buf[1]);
butterfly_enter_prog_mode(pgm); butterfly_enter_prog_mode(pgm);
@ -556,8 +551,7 @@ static int butterfly_page_erase(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, unsig
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 */
fprintf(stderr, avrdude_message("%s: butterfly_page_erase() called on memory type \"%s\"\n",
"%s: butterfly_page_erase() called on memory type \"%s\"\n",
progname, m->desc); progname, m->desc);
return -1; return -1;
} }
@ -704,7 +698,7 @@ static int butterfly_read_sig_bytes(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m)
unsigned char tmp; unsigned char tmp;
if (m->size < 3) { if (m->size < 3) {
fprintf(stderr, "%s: memsize too small for sig byte read", progname); avrdude_message("%s: memsize too small for sig byte read", progname);
return -1; return -1;
} }

View File

@ -93,7 +93,7 @@ TOKEN * new_token(int primary)
tkn = (TOKEN *)malloc(sizeof(TOKEN)); tkn = (TOKEN *)malloc(sizeof(TOKEN));
if (tkn == NULL) { if (tkn == NULL) {
fprintf(stderr, "new_token(): out of memory\n"); avrdude_message("new_token(): out of memory\n");
exit(1); exit(1);
} }
@ -145,7 +145,7 @@ TOKEN * number(char * text)
tkn->value.number = atoi(text); tkn->value.number = atoi(text);
#if DEBUG #if DEBUG
fprintf(stderr, "NUMBER(%d)\n", tkn->value.number); avrdude_message("NUMBER(%d)\n", tkn->value.number);
#endif #endif
return tkn; return tkn;
@ -160,7 +160,7 @@ TOKEN * number_real(char * text)
tkn->value.number_real = atof(text); tkn->value.number_real = atof(text);
#if DEBUG #if DEBUG
fprintf(stderr, "NUMBER(%g)\n", tkn->value.number_real); avrdude_message("NUMBER(%g)\n", tkn->value.number_real);
#endif #endif
return tkn; return tkn;
@ -175,12 +175,12 @@ TOKEN * hexnumber(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)) {
fprintf(stderr, "error at %s:%d: can't scan hex number \"%s\"\n", avrdude_message("error at %s:%d: can't scan hex number \"%s\"\n",
infile, lineno, text); infile, lineno, text);
} }
#if DEBUG #if DEBUG
fprintf(stderr, "HEXNUMBER(%g)\n", tkn->value.number); avrdude_message("HEXNUMBER(%g)\n", tkn->value.number);
#endif #endif
return tkn; return tkn;
@ -199,13 +199,13 @@ TOKEN * string(char * text)
tkn->value.type = V_STR; tkn->value.type = V_STR;
tkn->value.string = (char *) malloc(len+1); tkn->value.string = (char *) malloc(len+1);
if (tkn->value.string == NULL) { if (tkn->value.string == NULL) {
fprintf(stderr, "id(): out of memory\n"); avrdude_message("id(): out of memory\n");
exit(1); exit(1);
} }
strcpy(tkn->value.string, text); strcpy(tkn->value.string, text);
#if DEBUG #if DEBUG
fprintf(stderr, "STRING(%s)\n", tkn->value.string); avrdude_message("STRING(%s)\n", tkn->value.string);
#endif #endif
return tkn; return tkn;
@ -227,33 +227,33 @@ void print_token(TOKEN * tkn)
if (!tkn) if (!tkn)
return; return;
fprintf(stderr, "token = %d = ", tkn->primary); avrdude_message("token = %d = ", tkn->primary);
switch (tkn->value.type) { switch (tkn->value.type) {
case V_NUM: case V_NUM:
fprintf(stderr, "NUMBER, value=%d", tkn->value.number); avrdude_message("NUMBER, value=%d", tkn->value.number);
break; break;
case V_NUM_REAL: case V_NUM_REAL:
fprintf(stderr, "NUMBER, value=%g", tkn->value.number_real); avrdude_message("NUMBER, value=%g", tkn->value.number_real);
break; break;
case V_STR: case V_STR:
fprintf(stderr, "STRING, value=%s", tkn->value.string); avrdude_message("STRING, value=%s", tkn->value.string);
break; break;
default: default:
fprintf(stderr, "<other>"); avrdude_message("<other>");
break; break;
} }
fprintf(stderr, "\n"); avrdude_message("\n");
} }
void pyytext(void) void pyytext(void)
{ {
#if DEBUG #if DEBUG
fprintf(stderr, "TOKEN: \"%s\"\n", yytext); avrdude_message("TOKEN: \"%s\"\n", yytext);
#endif #endif
} }
@ -264,7 +264,7 @@ char * dup_string(const char * str)
s = strdup(str); s = strdup(str);
if (s == NULL) { if (s == NULL) {
fprintf(stderr, "dup_string(): out of memory\n"); avrdude_message("dup_string(): out of memory\n");
exit(1); exit(1);
} }
@ -282,7 +282,7 @@ int read_config(const char * file)
f = fopen(file, "r"); f = fopen(file, "r");
if (f == NULL) { if (f == NULL) {
fprintf(stderr, "%s: can't open config file \"%s\": %s\n", avrdude_message("%s: can't open config file \"%s\": %s\n",
progname, file, strerror(errno)); progname, file, strerror(errno));
return -1; return -1;
} }

View File

@ -276,20 +276,19 @@ prog_def :
PROGRAMMER * existing_prog; PROGRAMMER * existing_prog;
char * id; char * id;
if (lsize(current_prog->id) == 0) { if (lsize(current_prog->id) == 0) {
fprintf(stderr, avrdude_message("%s: error at %s:%d: required parameter id not specified\n",
"%s: error at %s:%d: required parameter id not specified\n",
progname, infile, lineno); progname, infile, lineno);
exit(1); exit(1);
} }
if (current_prog->initpgm == NULL) { if (current_prog->initpgm == NULL) {
fprintf(stderr, "%s: error at %s:%d: programmer type not specified\n", avrdude_message("%s: error at %s:%d: programmer type not specified\n",
progname, infile, lineno); progname, infile, lineno);
exit(1); exit(1);
} }
id = ldata(lfirst(current_prog->id)); id = ldata(lfirst(current_prog->id));
existing_prog = locate_programmer(programmers, id); existing_prog = locate_programmer(programmers, id);
if (existing_prog) { if (existing_prog) {
fprintf(stderr, "%s: warning at %s:%d: programmer %s overwrites " avrdude_message("%s: warning at %s:%d: programmer %s overwrites "
"previous definition %s:%d.\n", "previous definition %s:%d.\n",
progname, infile, current_prog->lineno, progname, infile, current_prog->lineno,
id, existing_prog->config_file, existing_prog->lineno); id, existing_prog->config_file, existing_prog->lineno);
@ -315,8 +314,7 @@ prog_decl :
{ {
struct programmer_t * pgm = locate_programmer(programmers, $3->value.string); struct programmer_t * pgm = locate_programmer(programmers, $3->value.string);
if (pgm == NULL) { if (pgm == NULL) {
fprintf(stderr, avrdude_message("%s: error at %s:%d: parent programmer %s not found\n",
"%s: error at %s:%d: parent programmer %s not found\n",
progname, infile, lineno, $3->value.string); progname, infile, lineno, $3->value.string);
exit(1); exit(1);
} }
@ -336,8 +334,7 @@ part_def :
AVRPART * existing_part; AVRPART * existing_part;
if (current_part->id[0] == 0) { if (current_part->id[0] == 0) {
fprintf(stderr, avrdude_message("%s: error at %s:%d: required parameter id not specified\n",
"%s: error at %s:%d: required parameter id not specified\n",
progname, infile, lineno); progname, infile, lineno);
exit(1); exit(1);
} }
@ -351,22 +348,19 @@ part_def :
m = ldata(ln); m = ldata(ln);
if (m->paged) { if (m->paged) {
if (m->page_size == 0) { if (m->page_size == 0) {
fprintf(stderr, avrdude_message("%s: error at %s:%d: must specify page_size for paged "
"%s: error at %s:%d: must specify page_size for paged "
"memory\n", "memory\n",
progname, infile, lineno); progname, infile, lineno);
exit(1); exit(1);
} }
if (m->num_pages == 0) { if (m->num_pages == 0) {
fprintf(stderr, avrdude_message("%s: error at %s:%d: must specify num_pages for paged "
"%s: error at %s:%d: must specify num_pages for paged "
"memory\n", "memory\n",
progname, infile, lineno); progname, infile, lineno);
exit(1); exit(1);
} }
if (m->size != m->page_size * m->num_pages) { if (m->size != m->page_size * m->num_pages) {
fprintf(stderr, avrdude_message("%s: error at %s:%d: page size (%u) * num_pages (%u) = "
"%s: error at %s:%d: page size (%u) * num_pages (%u) = "
"%u does not match memory size (%u)\n", "%u does not match memory size (%u)\n",
progname, infile, lineno, progname, infile, lineno,
m->page_size, m->page_size,
@ -381,7 +375,7 @@ part_def :
existing_part = locate_part(part_list, current_part->id); existing_part = locate_part(part_list, current_part->id);
if (existing_part) { if (existing_part) {
fprintf(stderr, "%s: warning at %s:%d: part %s overwrites " avrdude_message("%s: warning at %s:%d: part %s overwrites "
"previous definition %s:%d.\n", "previous definition %s:%d.\n",
progname, infile, current_part->lineno, current_part->id, progname, infile, current_part->lineno, current_part->id,
existing_part->config_file, existing_part->lineno); existing_part->config_file, existing_part->lineno);
@ -404,8 +398,7 @@ part_decl :
{ {
AVRPART * parent_part = locate_part(part_list, $3->value.string); AVRPART * parent_part = locate_part(part_list, $3->value.string);
if (parent_part == NULL) { if (parent_part == NULL) {
fprintf(stderr, avrdude_message("%s: error at %s:%d: can't find parent part",
"%s: error at %s:%d: can't find parent part",
progname, infile, lineno); progname, infile, lineno);
exit(1); exit(1);
} }
@ -474,8 +467,7 @@ prog_parm_type_id:
TKN_STRING { TKN_STRING {
const struct programmer_type_t * pgm_type = locate_programmer_type($1->value.string); const struct programmer_type_t * pgm_type = locate_programmer_type($1->value.string);
if (pgm_type == NULL) { if (pgm_type == NULL) {
fprintf(stderr, avrdude_message("%s: error at %s:%d: programmer type %s not found\n",
"%s: error at %s:%d: programmer type %s not found\n",
progname, infile, lineno, $1->value.string); progname, infile, lineno, $1->value.string);
exit(1); exit(1);
} }
@ -484,8 +476,7 @@ prog_parm_type_id:
} }
| error | error
{ {
fprintf(stderr, avrdude_message("%s: error at %s:%d: programmer type must be written as \"id_type\"\n",
"%s: error at %s:%d: programmer type must be written as \"id_type\"\n",
progname, infile, lineno); progname, infile, lineno);
exit(1); exit(1);
} }
@ -657,8 +648,7 @@ part_parm :
K_DEVICECODE TKN_EQUAL TKN_NUMBER { K_DEVICECODE TKN_EQUAL TKN_NUMBER {
{ {
fprintf(stderr, avrdude_message("%s: error at %s:%d: devicecode is deprecated, use "
"%s: error at %s:%d: devicecode is deprecated, use "
"stk500_devcode instead\n", "stk500_devcode instead\n",
progname, infile, lineno); progname, infile, lineno);
exit(1); exit(1);
@ -723,8 +713,7 @@ part_parm :
} }
if (!ok) if (!ok)
{ {
fprintf(stderr, avrdude_message("%s: Warning: line %d of %s: "
"%s: Warning: line %d of %s: "
"too many bytes in control stack\n", "too many bytes in control stack\n",
progname, lineno, infile); progname, lineno, infile);
} }
@ -757,8 +746,7 @@ part_parm :
} }
if (!ok) if (!ok)
{ {
fprintf(stderr, avrdude_message("%s: Warning: line %d of %s: "
"%s: Warning: line %d of %s: "
"too many bytes in control stack\n", "too many bytes in control stack\n",
progname, lineno, infile); progname, lineno, infile);
} }
@ -790,8 +778,7 @@ part_parm :
} }
if (!ok) if (!ok)
{ {
fprintf(stderr, avrdude_message("%s: Warning: line %d of %s: "
"%s: Warning: line %d of %s: "
"too many bytes in flash instructions\n", "too many bytes in flash instructions\n",
progname, lineno, infile); progname, lineno, infile);
} }
@ -823,8 +810,7 @@ part_parm :
} }
if (!ok) if (!ok)
{ {
fprintf(stderr, avrdude_message("%s: Warning: line %d of %s: "
"%s: Warning: line %d of %s: "
"too many bytes in EEPROM instructions\n", "too many bytes in EEPROM instructions\n",
progname, lineno, infile); progname, lineno, infile);
} }
@ -1230,8 +1216,7 @@ part_parm :
op = avr_new_opcode(); op = avr_new_opcode();
parse_cmdbits(op); parse_cmdbits(op);
if (current_part->op[opnum] != NULL) { if (current_part->op[opnum] != NULL) {
/*fprintf(stderr, /*avrdude_message("%s: warning at %s:%d: operation redefined\n",
"%s: warning at %s:%d: operation redefined\n",
progname, infile, lineno);*/ progname, infile, lineno);*/
avr_free_opcode(current_part->op[opnum]); avr_free_opcode(current_part->op[opnum]);
} }
@ -1357,8 +1342,7 @@ mem_spec :
op = avr_new_opcode(); op = avr_new_opcode();
parse_cmdbits(op); parse_cmdbits(op);
if (current_mem->op[opnum] != NULL) { if (current_mem->op[opnum] != NULL) {
/*fprintf(stderr, /*avrdude_message("%s: warning at %s:%d: operation redefined\n",
"%s: warning at %s:%d: operation redefined\n",
progname, infile, lineno);*/ progname, infile, lineno);*/
avr_free_opcode(current_mem->op[opnum]); avr_free_opcode(current_mem->op[opnum]);
} }
@ -1394,8 +1378,7 @@ static int assign_pin(int pinno, TOKEN * v, int invert)
free_token(v); free_token(v);
if ((value < PIN_MIN) || (value > PIN_MAX)) { if ((value < PIN_MIN) || (value > PIN_MAX)) {
fprintf(stderr, avrdude_message("%s: error at line %d of %s: pin must be in the "
"%s: error at line %d of %s: pin must be in the "
"range %d-%d\n", "range %d-%d\n",
progname, lineno, infile, PIN_MIN, PIN_MAX); progname, lineno, infile, PIN_MIN, PIN_MAX);
exit(1); exit(1);
@ -1416,8 +1399,7 @@ static int assign_pin_list(int invert)
t = lrmv_n(number_list, 1); t = lrmv_n(number_list, 1);
pin = t->value.number; pin = t->value.number;
if ((pin < PIN_MIN) || (pin > PIN_MAX)) { if ((pin < PIN_MIN) || (pin > PIN_MAX)) {
fprintf(stderr, avrdude_message("%s: error at line %d of %s: pin must be in the "
"%s: error at line %d of %s: pin must be in the "
"range %d-%d\n", "range %d-%d\n",
progname, lineno, infile, PIN_MIN, PIN_MAX); progname, lineno, infile, PIN_MIN, PIN_MAX);
exit(1); exit(1);
@ -1446,8 +1428,7 @@ static int which_opcode(TOKEN * opcode)
case K_CHIP_ERASE : return AVR_OP_CHIP_ERASE; break; case K_CHIP_ERASE : return AVR_OP_CHIP_ERASE; break;
case K_PGM_ENABLE : return AVR_OP_PGM_ENABLE; break; case K_PGM_ENABLE : return AVR_OP_PGM_ENABLE; break;
default : default :
fprintf(stderr, avrdude_message("%s: error at %s:%d: invalid opcode\n",
"%s: error at %s:%d: invalid opcode\n",
progname, infile, lineno); progname, infile, lineno);
exit(1); exit(1);
break; break;
@ -1475,8 +1456,7 @@ static int parse_cmdbits(OPCODE * op)
bitno--; bitno--;
if (bitno < 0) { if (bitno < 0) {
fprintf(stderr, avrdude_message("%s: error at %s:%d: too many opcode bits for instruction\n",
"%s: error at %s:%d: too many opcode bits for instruction\n",
progname, infile, lineno); progname, infile, lineno);
exit(1); exit(1);
} }
@ -1484,8 +1464,7 @@ static int parse_cmdbits(OPCODE * op)
len = strlen(s); len = strlen(s);
if (len == 0) { if (len == 0) {
fprintf(stderr, avrdude_message("%s: error at %s:%d: invalid bit specifier \"\"\n",
"%s: error at %s:%d: invalid bit specifier \"\"\n",
progname, infile, lineno); progname, infile, lineno);
exit(1); exit(1);
} }
@ -1525,8 +1504,7 @@ static int parse_cmdbits(OPCODE * op)
op->bit[bitno].bitno = bitno % 8; op->bit[bitno].bitno = bitno % 8;
break; break;
default : default :
fprintf(stderr, avrdude_message("%s: error at %s:%d: invalid bit specifier '%c'\n",
"%s: error at %s:%d: invalid bit specifier '%c'\n",
progname, infile, lineno, ch); progname, infile, lineno, ch);
exit(1); exit(1);
break; break;
@ -1537,8 +1515,7 @@ static int parse_cmdbits(OPCODE * op)
q = &s[1]; q = &s[1];
op->bit[bitno].bitno = strtol(q, &e, 0); op->bit[bitno].bitno = strtol(q, &e, 0);
if ((e == q)||(*e != 0)) { if ((e == q)||(*e != 0)) {
fprintf(stderr, avrdude_message("%s: error at %s:%d: can't parse bit number from \"%s\"\n",
"%s: error at %s:%d: can't parse bit number from \"%s\"\n",
progname, infile, lineno, q); progname, infile, lineno, q);
exit(1); exit(1);
} }
@ -1546,8 +1523,7 @@ static int parse_cmdbits(OPCODE * op)
op->bit[bitno].value = 0; op->bit[bitno].value = 0;
} }
else { else {
fprintf(stderr, avrdude_message("%s: error at %s:%d: invalid bit specifier \"%s\"\n",
"%s: error at %s:%d: invalid bit specifier \"%s\"\n",
progname, infile, lineno, s); progname, infile, lineno, s);
exit(1); exit(1);
} }

70
dfu.c
View File

@ -37,7 +37,7 @@
#ifndef HAVE_LIBUSB #ifndef HAVE_LIBUSB
struct dfu_dev *dfu_open(char *port_name) { struct dfu_dev *dfu_open(char *port_name) {
fprintf(stderr, "%s: Error: No USB support in this compile of avrdude\n", avrdude_message("%s: Error: No USB support in this compile of avrdude\n",
progname); progname);
return NULL; return NULL;
} }
@ -110,7 +110,7 @@ struct dfu_dev * dfu_open(char *port_spec)
*/ */
if (strncmp(port_spec, "usb", 3) != 0) { if (strncmp(port_spec, "usb", 3) != 0) {
fprintf(stderr, "%s: Error: " avrdude_message("%s: Error: "
"Invalid port specification \"%s\" for USB device\n", "Invalid port specification \"%s\" for USB device\n",
progname, port_spec); progname, port_spec);
return NULL; return NULL;
@ -119,7 +119,7 @@ struct dfu_dev * dfu_open(char *port_spec)
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) {
fprintf(stderr, "%s: Out of memory in strdup\n", progname); avrdude_message("%s: Out of memory in strdup\n", progname);
return NULL; return NULL;
} }
@ -136,7 +136,7 @@ struct dfu_dev * dfu_open(char *port_spec)
if (dfu == NULL) if (dfu == NULL)
{ {
fprintf(stderr, "%s: out of memory\n", progname); avrdude_message("%s: out of memory\n", progname);
return 0; return 0;
} }
@ -169,7 +169,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) {
fprintf(stderr, "%s: Error: No DFU support for part; " avrdude_message("%s: 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); progname);
return -1; return -1;
@ -206,20 +206,19 @@ 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.
*/ */
fprintf(stderr, "%s: Error: No matching USB device found\n", progname); avrdude_message("%s: Error: No matching USB device found\n", progname);
return -1; return -1;
} }
if(verbose) if(verbose)
fprintf(stderr, avrdude_message("%s: Found VID=0x%04x PID=0x%04x at %s:%s\n",
"%s: Found VID=0x%04x PID=0x%04x at %s:%s\n",
progname, 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) {
fprintf(stderr, "%s: Error: USB device at %s:%s: %s\n", avrdude_message("%s: Error: USB device at %s:%s: %s\n",
progname, found->bus->dirname, found->filename, usb_strerror()); progname, found->bus->dirname, found->filename, usb_strerror());
return -1; return -1;
} }
@ -271,7 +270,7 @@ int dfu_getstatus(struct dfu_dev *dfu, struct dfu_status *status)
int result; int result;
if (verbose > 3) if (verbose > 3)
fprintf(stderr, "%s: dfu_getstatus(): issuing control IN message\n", avrdude_message("%s: dfu_getstatus(): issuing control IN message\n",
progname); progname);
result = usb_control_msg(dfu->dev_handle, result = usb_control_msg(dfu->dev_handle,
@ -279,26 +278,25 @@ int dfu_getstatus(struct dfu_dev *dfu, struct dfu_status *status)
(char*) status, sizeof(struct dfu_status), dfu->timeout); (char*) status, sizeof(struct dfu_status), dfu->timeout);
if (result < 0) { if (result < 0) {
fprintf(stderr, "%s: Error: Failed to get DFU status: %s\n", avrdude_message("%s: Error: Failed to get DFU status: %s\n",
progname, usb_strerror()); progname, usb_strerror());
return -1; return -1;
} }
if (result < sizeof(struct dfu_status)) { if (result < sizeof(struct dfu_status)) {
fprintf(stderr, "%s: Error: Failed to get DFU status: %s\n", avrdude_message("%s: Error: Failed to get DFU status: %s\n",
progname, "short read"); progname, "short read");
return -1; return -1;
} }
if (result > sizeof(struct dfu_status)) { if (result > sizeof(struct dfu_status)) {
fprintf(stderr, "%s: Error: Oversize read (should not happen); " avrdude_message("%s: Error: Oversize read (should not happen); "
"exiting\n", progname); "exiting\n", progname);
exit(1); exit(1);
} }
if (verbose > 3) if (verbose > 3)
fprintf(stderr, avrdude_message("%s: dfu_getstatus(): bStatus 0x%02x, bwPollTimeout %d, bState 0x%02x, iString %d\n",
"%s: dfu_getstatus(): bStatus 0x%02x, bwPollTimeout %d, bState 0x%02x, iString %d\n",
progname, 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),
@ -313,7 +311,7 @@ int dfu_clrstatus(struct dfu_dev *dfu)
int result; int result;
if (verbose > 3) if (verbose > 3)
fprintf(stderr, "%s: dfu_clrstatus(): issuing control OUT message\n", avrdude_message("%s: dfu_clrstatus(): issuing control OUT message\n",
progname); progname);
result = usb_control_msg(dfu->dev_handle, result = usb_control_msg(dfu->dev_handle,
@ -321,7 +319,7 @@ int dfu_clrstatus(struct dfu_dev *dfu)
NULL, 0, dfu->timeout); NULL, 0, dfu->timeout);
if (result < 0) { if (result < 0) {
fprintf(stderr, "%s: Error: Failed to clear DFU status: %s\n", avrdude_message("%s: Error: Failed to clear DFU status: %s\n",
progname, usb_strerror()); progname, usb_strerror());
return -1; return -1;
} }
@ -334,7 +332,7 @@ int dfu_abort(struct dfu_dev *dfu)
int result; int result;
if (verbose > 3) if (verbose > 3)
fprintf(stderr, "%s: dfu_abort(): issuing control OUT message\n", avrdude_message("%s: dfu_abort(): issuing control OUT message\n",
progname); progname);
result = usb_control_msg(dfu->dev_handle, result = usb_control_msg(dfu->dev_handle,
@ -342,7 +340,7 @@ int dfu_abort(struct dfu_dev *dfu)
NULL, 0, dfu->timeout); NULL, 0, dfu->timeout);
if (result < 0) { if (result < 0) {
fprintf(stderr, "%s: Error: Failed to reset DFU state: %s\n", avrdude_message("%s: Error: Failed to reset DFU state: %s\n",
progname, usb_strerror()); progname, usb_strerror());
return -1; return -1;
} }
@ -356,8 +354,7 @@ int dfu_dnload(struct dfu_dev *dfu, void *ptr, int size)
int result; int result;
if (verbose > 3) if (verbose > 3)
fprintf(stderr, avrdude_message("%s: dfu_dnload(): issuing control OUT message, wIndex = %d, ptr = %p, size = %d\n",
"%s: dfu_dnload(): issuing control OUT message, wIndex = %d, ptr = %p, size = %d\n",
progname, wIndex, ptr, size); progname, wIndex, ptr, size);
result = usb_control_msg(dfu->dev_handle, result = usb_control_msg(dfu->dev_handle,
@ -365,19 +362,19 @@ int dfu_dnload(struct dfu_dev *dfu, void *ptr, int size)
ptr, size, dfu->timeout); ptr, size, dfu->timeout);
if (result < 0) { if (result < 0) {
fprintf(stderr, "%s: Error: DFU_DNLOAD failed: %s\n", avrdude_message("%s: Error: DFU_DNLOAD failed: %s\n",
progname, usb_strerror()); progname, usb_strerror());
return -1; return -1;
} }
if (result < size) { if (result < size) {
fprintf(stderr, "%s: Error: DFU_DNLOAD failed: %s\n", avrdude_message("%s: Error: DFU_DNLOAD failed: %s\n",
progname, "short write"); progname, "short write");
return -1; return -1;
} }
if (result > size) { if (result > size) {
fprintf(stderr, "%s: Error: Oversize write (should not happen); " \ avrdude_message("%s: Error: Oversize write (should not happen); " \
"exiting\n", progname); "exiting\n", progname);
exit(1); exit(1);
} }
@ -390,8 +387,7 @@ int dfu_upload(struct dfu_dev *dfu, void *ptr, int size)
int result; int result;
if (verbose > 3) if (verbose > 3)
fprintf(stderr, avrdude_message("%s: dfu_upload(): issuing control IN message, wIndex = %d, ptr = %p, size = %d\n",
"%s: dfu_upload(): issuing control IN message, wIndex = %d, ptr = %p, size = %d\n",
progname, wIndex, ptr, size); progname, wIndex, ptr, size);
result = usb_control_msg(dfu->dev_handle, result = usb_control_msg(dfu->dev_handle,
@ -399,19 +395,19 @@ int dfu_upload(struct dfu_dev *dfu, void *ptr, int size)
ptr, size, dfu->timeout); ptr, size, dfu->timeout);
if (result < 0) { if (result < 0) {
fprintf(stderr, "%s: Error: DFU_UPLOAD failed: %s\n", avrdude_message("%s: Error: DFU_UPLOAD failed: %s\n",
progname, usb_strerror()); progname, usb_strerror());
return -1; return -1;
} }
if (result < size) { if (result < size) {
fprintf(stderr, "%s: Error: DFU_UPLOAD failed: %s\n", avrdude_message("%s: Error: DFU_UPLOAD failed: %s\n",
progname, "short read"); progname, "short read");
return -1; return -1;
} }
if (result > size) { if (result > size) {
fprintf(stderr, "%s: Error: Oversize read (should not happen); " avrdude_message("%s: Error: Oversize read (should not happen); "
"exiting\n", progname); "exiting\n", progname);
exit(1); exit(1);
} }
@ -422,26 +418,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)
fprintf(stderr, " USB Vendor : %s (0x%04hX)\n", avrdude_message(" 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
fprintf(stderr, " USB Vendor : 0x%04hX\n", avrdude_message(" 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)
fprintf(stderr, " USB Product : %s (0x%04hX)\n", avrdude_message(" 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
fprintf(stderr, " USB Product : 0x%04hX\n", avrdude_message(" USB Product : 0x%04hX\n",
(unsigned short) dfu->dev_desc.idProduct); (unsigned short) dfu->dev_desc.idProduct);
fprintf(stderr, " USB Release : %hu.%hu.%hu\n", avrdude_message(" 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)
fprintf(stderr, " USB Serial No : %s\n", dfu->serno_str); avrdude_message(" USB Serial No : %s\n", dfu->serno_str);
} }
/* INTERNAL FUNCTION DEFINITIONS /* INTERNAL FUNCTION DEFINITIONS
@ -458,7 +454,7 @@ 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) {
fprintf( stderr, "%s: Warning: Failed to read USB device string %d: %s\n", avrdude_message("%s: Warning: Failed to read USB device string %d: %s\n",
progname, index, usb_strerror()); progname, index, usb_strerror());
return NULL; return NULL;
} }
@ -466,7 +462,7 @@ char * get_usb_string(usb_dev_handle * dev_handle, int index) {
str = malloc(result+1); str = malloc(result+1);
if (str == NULL) { if (str == NULL) {
fprintf(stderr, "%s: Out of memory allocating a string\n", progname); avrdude_message("%s: Out of memory allocating a string\n", progname);
return 0; return 0;
} }

170
fileio.c
View File

@ -126,7 +126,7 @@ static int b2ihex(unsigned char * inbuf, int bufsize,
unsigned char cksum; unsigned char cksum;
if (recsize > 255) { if (recsize > 255) {
fprintf(stderr, "%s: recsize=%d, must be < 256\n", avrdude_message("%s: recsize=%d, must be < 256\n",
progname, recsize); progname, recsize);
return -1; return -1;
} }
@ -306,14 +306,14 @@ 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) {
fprintf(stderr, "%s: invalid record at line %d of \"%s\"\n", avrdude_message("%s: invalid record at line %d of \"%s\"\n",
progname, lineno, infile); progname, lineno, infile);
return -1; return -1;
} }
else if (rc != ihex.cksum) { else if (rc != ihex.cksum) {
fprintf(stderr, "%s: ERROR: checksum mismatch at line %d of \"%s\"\n", avrdude_message("%s: ERROR: checksum mismatch at line %d of \"%s\"\n",
progname, lineno, infile); progname, lineno, infile);
fprintf(stderr, "%s: checksum=0x%02x, computed checksum=0x%02x\n", avrdude_message("%s: checksum=0x%02x, computed checksum=0x%02x\n",
progname, ihex.cksum, rc); progname, ihex.cksum, rc);
return -1; return -1;
} }
@ -321,15 +321,13 @@ static int ihex2b(char * infile, FILE * inf,
switch (ihex.rectyp) { switch (ihex.rectyp) {
case 0: /* data record */ case 0: /* data record */
if (fileoffset != 0 && baseaddr < fileoffset) { if (fileoffset != 0 && baseaddr < fileoffset) {
fprintf(stderr, avrdude_message("%s: ERROR: address 0x%04x out of range (below fileoffset 0x%x) at line %d of %s\n",
"%s: ERROR: address 0x%04x out of range (below fileoffset 0x%x) at line %d of %s\n",
progname, baseaddr, fileoffset, lineno, infile); progname, baseaddr, fileoffset, lineno, infile);
return -1; return -1;
} }
nextaddr = ihex.loadofs + baseaddr - fileoffset; nextaddr = ihex.loadofs + baseaddr - fileoffset;
if (nextaddr + ihex.reclen > bufsize) { if (nextaddr + ihex.reclen > bufsize) {
fprintf(stderr, avrdude_message("%s: ERROR: address 0x%04x out of range at line %d of %s\n",
"%s: ERROR: address 0x%04x out of range at line %d of %s\n",
progname, nextaddr+ihex.reclen, lineno, infile); progname, nextaddr+ihex.reclen, lineno, infile);
return -1; return -1;
} }
@ -362,8 +360,7 @@ static int ihex2b(char * infile, FILE * inf,
break; break;
default: default:
fprintf(stderr, avrdude_message("%s: don't know how to deal with rectype=%d "
"%s: don't know how to deal with rectype=%d "
"at line %d of %s\n", "at line %d of %s\n",
progname, ihex.rectyp, lineno, infile); progname, ihex.rectyp, lineno, infile);
return -1; return -1;
@ -373,16 +370,14 @@ static int ihex2b(char * infile, FILE * inf,
} /* while */ } /* while */
if (maxaddr == 0) { if (maxaddr == 0) {
fprintf(stderr, avrdude_message("%s: ERROR: No valid record found in Intel Hex "
"%s: ERROR: No valid record found in Intel Hex "
"file \"%s\"\n", "file \"%s\"\n",
progname, infile); progname, infile);
return -1; return -1;
} }
else { else {
fprintf(stderr, avrdude_message("%s: WARNING: no end of file record found for Intel Hex "
"%s: WARNING: no end of file record found for Intel Hex "
"file \"%s\"\n", "file \"%s\"\n",
progname, infile); progname, infile);
@ -403,7 +398,7 @@ static int b2srec(unsigned char * inbuf, int bufsize,
char * tmpl=0; char * tmpl=0;
if (recsize > 255) { if (recsize > 255) {
fprintf(stderr, "%s: ERROR: recsize=%d, must be < 256\n", avrdude_message("%s: ERROR: recsize=%d, must be < 256\n",
progname, recsize); progname, recsize);
return -1; return -1;
} }
@ -436,7 +431,7 @@ static int b2srec(unsigned char * inbuf, int bufsize,
tmpl="S3%02X%08X"; tmpl="S3%02X%08X";
} }
else { else {
fprintf(stderr, "%s: ERROR: address=%d, out of range\n", avrdude_message("%s: ERROR: address=%d, out of range\n",
progname, nextaddr); progname, nextaddr);
return -1; return -1;
} }
@ -601,14 +596,14 @@ static int srec2b(char * infile, FILE * inf,
rc = srec_readrec(&srec, buffer); rc = srec_readrec(&srec, buffer);
if (rc < 0) { if (rc < 0) {
fprintf(stderr, "%s: ERROR: invalid record at line %d of \"%s\"\n", avrdude_message("%s: ERROR: invalid record at line %d of \"%s\"\n",
progname, lineno, infile); progname, lineno, infile);
return -1; return -1;
} }
else if (rc != srec.cksum) { else if (rc != srec.cksum) {
fprintf(stderr, "%s: ERROR: checksum mismatch at line %d of \"%s\"\n", avrdude_message("%s: ERROR: checksum mismatch at line %d of \"%s\"\n",
progname, lineno, infile); progname, lineno, infile);
fprintf(stderr, "%s: checksum=0x%02x, computed checksum=0x%02x\n", avrdude_message("%s: checksum=0x%02x, computed checksum=0x%02x\n",
progname, srec.cksum, rc); progname, srec.cksum, rc);
return -1; return -1;
} }
@ -635,18 +630,16 @@ static int srec2b(char * infile, FILE * inf,
break; break;
case 0x34: /* S4 - symbol record (LSI extension) */ case 0x34: /* S4 - symbol record (LSI extension) */
fprintf(stderr, avrdude_message("%s: ERROR: not supported record at line %d of %s\n",
"%s: ERROR: not supported record at line %d of %s\n",
progname, 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){
fprintf(stderr, avrdude_message("%s: ERROR: count of transmitted data records mismatch "
"%s: ERROR: count of transmitted data records mismatch "
"at line %d of \"%s\"\n", "at line %d of \"%s\"\n",
progname, lineno, infile); progname, lineno, infile);
fprintf(stderr, "%s: transmitted data records= %d, expected " avrdude_message("%s: transmitted data records= %d, expected "
"value= %d\n", "value= %d\n",
progname, reccount, srec.loadofs); progname, reccount, srec.loadofs);
return -1; return -1;
@ -659,8 +652,7 @@ static int srec2b(char * infile, FILE * inf,
return maxaddr; return maxaddr;
default: default:
fprintf(stderr, avrdude_message("%s: ERROR: don't know how to deal with rectype S%d "
"%s: ERROR: don't know how to deal with rectype S%d "
"at line %d of %s\n", "at line %d of %s\n",
progname, srec.rectyp, lineno, infile); progname, srec.rectyp, lineno, infile);
return -1; return -1;
@ -669,14 +661,14 @@ static int srec2b(char * infile, FILE * inf,
if (datarec == 1) { if (datarec == 1) {
nextaddr = srec.loadofs; nextaddr = srec.loadofs;
if (nextaddr < fileoffset) { if (nextaddr < fileoffset) {
fprintf(stderr, msg, progname, nextaddr, avrdude_message(msg, progname, nextaddr,
"(below fileoffset) ", "(below fileoffset) ",
lineno, infile); lineno, infile);
return -1; return -1;
} }
nextaddr -= fileoffset; nextaddr -= fileoffset;
if (nextaddr + srec.reclen > bufsize) { if (nextaddr + srec.reclen > bufsize) {
fprintf(stderr, msg, progname, nextaddr+srec.reclen, "", avrdude_message(msg, progname, nextaddr+srec.reclen, "",
lineno, infile); lineno, infile);
return -1; return -1;
} }
@ -691,8 +683,7 @@ static int srec2b(char * infile, FILE * inf,
} }
fprintf(stderr, avrdude_message("%s: WARNING: no end of file record found for Motorola S-Records "
"%s: WARNING: no end of file record found for Motorola S-Records "
"file \"%s\"\n", "file \"%s\"\n",
progname, infile); progname, infile);
@ -737,8 +728,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) {
fprintf(stderr, avrdude_message("%s: ERROR: Error reading section #%u header: %s\n",
"%s: ERROR: Error reading section #%u header: %s\n",
progname, (unsigned int)ndx, elf_errmsg(-1)); progname, (unsigned int)ndx, elf_errmsg(-1));
continue; continue;
} }
@ -756,8 +746,7 @@ static Elf_Scn *elf_get_scn(Elf *e, Elf32_Phdr *ph, Elf32_Shdr **shptr)
} }
} }
fprintf(stderr, avrdude_message("%s: ERROR: Cannot find a matching section for "
"%s: ERROR: Cannot find a matching section for "
"program header entry @p_vaddr 0x%x\n", "program header entry @p_vaddr 0x%x\n",
progname, ph->p_vaddr); progname, ph->p_vaddr);
return NULL; return NULL;
@ -830,8 +819,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) {
fprintf(stderr, avrdude_message("%s: ERROR: Cannot handle \"%s\" memory region from ELF file\n",
"%s: ERROR: Cannot handle \"%s\" memory region from ELF file\n",
progname, mem->desc); progname, mem->desc);
return -1; return -1;
} }
@ -849,8 +837,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) {
fprintf(stderr, avrdude_message("%s: ERROR: No \"flash\" memory region found, "
"%s: ERROR: No \"flash\" memory region found, "
"cannot compute bounds of \"%s\" sub-region.\n", "cannot compute bounds of \"%s\" sub-region.\n",
progname, mem->desc); progname, mem->desc);
return -1; return -1;
@ -861,20 +848,17 @@ static int elf2b(char * infile, FILE * inf,
} }
if (elf_version(EV_CURRENT) == EV_NONE) { if (elf_version(EV_CURRENT) == EV_NONE) {
fprintf(stderr, avrdude_message("%s: ERROR: ELF library initialization failed: %s\n",
"%s: ERROR: ELF library initialization failed: %s\n",
progname, 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) {
fprintf(stderr, avrdude_message("%s: ERROR: Cannot open \"%s\" as an ELF file: %s\n",
"%s: ERROR: Cannot open \"%s\" as an ELF file: %s\n",
progname, 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) {
fprintf(stderr, avrdude_message("%s: ERROR: Cannot use \"%s\" as an ELF input file\n",
"%s: ERROR: Cannot use \"%s\" as an ELF input file\n",
progname, infile); progname, infile);
goto done; goto done;
} }
@ -883,8 +867,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) {
fprintf(stderr, avrdude_message("%s: ERROR: Error reading ident area of \"%s\": %s\n",
"%s: ERROR: Error reading ident area of \"%s\": %s\n",
progname, infile, elf_errmsg(-1)); progname, infile, elf_errmsg(-1));
goto done; goto done;
} }
@ -900,8 +883,7 @@ 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) {
fprintf(stderr, avrdude_message("%s: ERROR: ELF file \"%s\" is not a "
"%s: 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",
progname, infile, endianname); progname, infile, endianname);
goto done; goto done;
@ -909,15 +891,13 @@ static int elf2b(char * infile, FILE * inf,
Elf32_Ehdr *eh; Elf32_Ehdr *eh;
if ((eh = elf32_getehdr(e)) == NULL) { if ((eh = elf32_getehdr(e)) == NULL) {
fprintf(stderr, avrdude_message("%s: ERROR: Error reading ehdr of \"%s\": %s\n",
"%s: ERROR: Error reading ehdr of \"%s\": %s\n",
progname, 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) {
fprintf(stderr, avrdude_message("%s: ERROR: ELF file \"%s\" is not an executable file\n",
"%s: ERROR: ELF file \"%s\" is not an executable file\n",
progname, infile); progname, infile);
goto done; goto done;
} }
@ -932,14 +912,12 @@ static int elf2b(char * infile, FILE * inf,
mname = "AVR"; mname = "AVR";
} }
if (eh->e_machine != machine) { if (eh->e_machine != machine) {
fprintf(stderr, avrdude_message("%s: ERROR: ELF file \"%s\" is not for machine %s\n",
"%s: ERROR: ELF file \"%s\" is not for machine %s\n",
progname, infile, mname); progname, infile, mname);
goto done; goto done;
} }
if (eh->e_phnum == 0xffff /* PN_XNUM */) { if (eh->e_phnum == 0xffff /* PN_XNUM */) {
fprintf(stderr, avrdude_message("%s: ERROR: ELF file \"%s\" uses extended "
"%s: ERROR: ELF file \"%s\" uses extended "
"program header numbers which are not expected\n", "program header numbers which are not expected\n",
progname, infile); progname, infile);
goto done; goto done;
@ -947,16 +925,14 @@ static int elf2b(char * infile, FILE * inf,
Elf32_Phdr *ph; Elf32_Phdr *ph;
if ((ph = elf32_getphdr(e)) == NULL) { if ((ph = elf32_getphdr(e)) == NULL) {
fprintf(stderr, avrdude_message("%s: ERROR: Error reading program header table of \"%s\": %s\n",
"%s: ERROR: Error reading program header table of \"%s\": %s\n",
progname, 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) {
fprintf(stderr, avrdude_message("%s: ERROR: Error obtaining section name string table: %s\n",
"%s: ERROR: Error obtaining section name string table: %s\n",
progname, elf_errmsg(-1)); progname, elf_errmsg(-1));
sndx = 0; sndx = 0;
} }
@ -971,8 +947,7 @@ static int elf2b(char * infile, FILE * inf,
continue; continue;
if (verbose >= 2) { if (verbose >= 2) {
fprintf(stderr, avrdude_message("%s: Considering PT_LOAD program header entry #%d:\n"
"%s: 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",
progname, 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);
} }
@ -995,8 +970,7 @@ static int elf2b(char * infile, FILE * inf,
lma = ph[i].p_paddr + sh->sh_offset - ph[i].p_offset; lma = ph[i].p_paddr + sh->sh_offset - ph[i].p_offset;
if (verbose >= 2) { if (verbose >= 2) {
fprintf(stderr, avrdude_message("%s: Found section \"%s\", LMA 0x%x, sh_size %u\n",
"%s: Found section \"%s\", LMA 0x%x, sh_size %u\n",
progname, sname, lma, sh->sh_size); progname, sname, lma, sh->sh_size);
} }
@ -1005,8 +979,7 @@ static int elf2b(char * infile, FILE * inf,
/* OK */ /* OK */
} else { } else {
if (verbose >= 2) { if (verbose >= 2) {
fprintf(stderr, avrdude_message(" => skipping, inappropriate for \"%s\" memory region\n",
" => skipping, inappropriate for \"%s\" memory region\n",
mem->desc); mem->desc);
} }
continue; continue;
@ -1021,8 +994,7 @@ static int elf2b(char * infile, FILE * inf,
*/ */
if (mem->size != 1 && if (mem->size != 1 &&
sh->sh_size > mem->size) { sh->sh_size > mem->size) {
fprintf(stderr, avrdude_message("%s: ERROR: section \"%s\" does not fit into \"%s\" memory:\n"
"%s: ERROR: section \"%s\" does not fit into \"%s\" memory:\n"
" 0x%x + %u > %u\n", " 0x%x + %u > %u\n",
progname, sname, mem->desc, progname, sname, mem->desc,
lma, sh->sh_size, mem->size); lma, sh->sh_size, mem->size);
@ -1032,23 +1004,19 @@ static int elf2b(char * infile, FILE * inf,
Elf_Data *d = NULL; Elf_Data *d = NULL;
while ((d = elf_getdata(s, d)) != NULL) { while ((d = elf_getdata(s, d)) != NULL) {
if (verbose >= 2) { if (verbose >= 2) {
fprintf(stderr, avrdude_message(" Data block: d_buf %p, d_off 0x%x, d_size %d\n",
" Data block: d_buf %p, d_off 0x%x, d_size %d\n",
d->d_buf, (unsigned int)d->d_off, d->d_size); d->d_buf, (unsigned int)d->d_off, d->d_size);
} }
if (mem->size == 1) { if (mem->size == 1) {
if (d->d_off != 0) { if (d->d_off != 0) {
fprintf(stderr, avrdude_message("%s: ERROR: unexpected data block at offset != 0\n",
"%s: ERROR: unexpected data block at offset != 0\n",
progname); progname);
} else if (foff >= d->d_size) { } else if (foff >= d->d_size) {
fprintf(stderr, avrdude_message("%s: ERROR: ELF file section does not contain byte at offset %d\n",
"%s: ERROR: ELF file section does not contain byte at offset %d\n",
progname, foff); progname, foff);
} else { } else {
if (verbose >= 2) { if (verbose >= 2) {
fprintf(stderr, avrdude_message(" Extracting one byte from file offset %d\n",
" 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];
@ -1062,8 +1030,7 @@ static int elf2b(char * infile, FILE * inf,
if ((int)(idx + d->d_size) > rv) if ((int)(idx + d->d_size) > rv)
rv = idx + d->d_size; rv = idx + d->d_size;
if (verbose >= 3) { if (verbose >= 3) {
fprintf(stderr, avrdude_message(" Writing %d bytes to mem offset 0x%x\n",
" Writing %d bytes to mem offset 0x%x\n",
d->d_size, idx); d->d_size, idx);
} }
memcpy(mem->buf + idx, d->d_buf, d->d_size); memcpy(mem->buf + idx, d->d_buf, d->d_size);
@ -1134,14 +1101,13 @@ static int fileio_rbin(struct fioparms * fio,
rc = fwrite(buf, 1, size, f); rc = fwrite(buf, 1, size, f);
break; break;
default: default:
fprintf(stderr, "%s: fileio: invalid operation=%d\n", avrdude_message("%s: fileio: invalid operation=%d\n",
progname, 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)) {
fprintf(stderr, avrdude_message("%s: %s error %s %s: %s; %s %d of the expected %d bytes\n",
"%s: %s error %s %s: %s; %s %d of the expected %d bytes\n",
progname, fio->iodesc, fio->dir, filename, strerror(errno), progname, fio->iodesc, fio->dir, filename, strerror(errno),
fio->rw, rc, size); fio->rw, rc, size);
return -1; return -1;
@ -1170,8 +1136,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) {
fprintf(stderr, avrdude_message("%s: invalid byte value (%s) specified for immediate mode\n",
"%s: invalid byte value (%s) specified for immediate mode\n",
progname, p); progname, p);
return -1; return -1;
} }
@ -1182,14 +1147,13 @@ static int fileio_imm(struct fioparms * fio,
} }
break; break;
default: default:
fprintf(stderr, "%s: fileio: invalid operation=%d\n", avrdude_message("%s: fileio: invalid operation=%d\n",
progname, 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)) {
fprintf(stderr, avrdude_message("%s: %s error %s %s: %s; %s %d of the expected %d bytes\n",
"%s: %s error %s %s: %s; %s %d of the expected %d bytes\n",
progname, fio->iodesc, fio->dir, filename, strerror(errno), progname, fio->iodesc, fio->dir, filename, strerror(errno),
fio->rw, rc, size); fio->rw, rc, size);
return -1; return -1;
@ -1219,7 +1183,7 @@ static int fileio_ihex(struct fioparms * fio,
break; break;
default: default:
fprintf(stderr, "%s: invalid Intex Hex file I/O operation=%d\n", avrdude_message("%s: invalid Intex Hex file I/O operation=%d\n",
progname, fio->op); progname, fio->op);
return -1; return -1;
break; break;
@ -1249,7 +1213,7 @@ static int fileio_srec(struct fioparms * fio,
break; break;
default: default:
fprintf(stderr, "%s: ERROR: invalid Motorola S-Records file I/O " avrdude_message("%s: ERROR: invalid Motorola S-Records file I/O "
"operation=%d\n", "operation=%d\n",
progname, fio->op); progname, fio->op);
return -1; return -1;
@ -1269,7 +1233,7 @@ static int fileio_elf(struct fioparms * fio,
switch (fio->op) { switch (fio->op) {
case FIO_WRITE: case FIO_WRITE:
fprintf(stderr, "%s: ERROR: write operation not (yet) " avrdude_message("%s: ERROR: write operation not (yet) "
"supported for ELF\n", "supported for ELF\n",
progname); progname);
return -1; return -1;
@ -1280,7 +1244,7 @@ static int fileio_elf(struct fioparms * fio,
return rc; return rc;
default: default:
fprintf(stderr, "%s: ERROR: invalid ELF file I/O " avrdude_message("%s: ERROR: invalid ELF file I/O "
"operation=%d\n", "operation=%d\n",
progname, fio->op); progname, fio->op);
return -1; return -1;
@ -1326,7 +1290,7 @@ static int fileio_num(struct fioparms * fio,
case FIO_WRITE: case FIO_WRITE:
break; break;
default: default:
fprintf(stderr, "%s: fileio: invalid operation=%d\n", avrdude_message("%s: fileio: invalid operation=%d\n",
progname, fio->op); progname, fio->op);
return -1; return -1;
} }
@ -1356,7 +1320,7 @@ static int fileio_num(struct fioparms * fio,
return 0; return 0;
writeerr: writeerr:
fprintf(stderr, "%s: error writing to %s: %s\n", avrdude_message("%s: error writing to %s: %s\n",
progname, filename, strerror(errno)); progname, filename, strerror(errno));
return -1; return -1;
} }
@ -1383,7 +1347,7 @@ int fileio_setparms(int op, struct fioparms * fp,
break; break;
default: default:
fprintf(stderr, "%s: invalid I/O operation %d\n", avrdude_message("%s: invalid I/O operation %d\n",
progname, op); progname, op);
return -1; return -1;
break; break;
@ -1422,7 +1386,7 @@ static int fmt_autodetect(char * fname)
f = fopen(fname, "rb"); f = fopen(fname, "rb");
#endif #endif
if (f == NULL) { if (f == NULL) {
fprintf(stderr, "%s: error opening %s: %s\n", avrdude_message("%s: error opening %s: %s\n",
progname, fname, strerror(errno)); progname, fname, strerror(errno));
return -1; return -1;
} }
@ -1505,8 +1469,7 @@ int fileio(int op, char * filename, FILEFMT format,
mem = avr_locate_mem(p, memtype); mem = avr_locate_mem(p, memtype);
if (mem == NULL) { if (mem == NULL) {
fprintf(stderr, avrdude_message("fileio(): memory type \"%s\" not configured for device \"%s\"\n",
"fileio(): memory type \"%s\" not configured for device \"%s\"\n",
memtype, p->desc); memtype, p->desc);
return -1; return -1;
} }
@ -1544,8 +1507,7 @@ int fileio(int op, char * filename, FILEFMT format,
if (format == FMT_AUTO) { if (format == FMT_AUTO) {
if (using_stdio) { if (using_stdio) {
fprintf(stderr, avrdude_message("%s: can't auto detect file format when using stdin/out.\n"
"%s: can't auto detect file format when using stdin/out.\n"
"%s Please specify a file format and try again.\n", "%s Please specify a file format and try again.\n",
progname, progbuf); progname, progbuf);
return -1; return -1;
@ -1553,14 +1515,13 @@ int fileio(int op, char * filename, FILEFMT format,
format = fmt_autodetect(fname); format = fmt_autodetect(fname);
if (format < 0) { if (format < 0) {
fprintf(stderr, avrdude_message("%s: can't determine file format for %s, specify explicitly\n",
"%s: can't determine file format for %s, specify explicitly\n",
progname, fname); progname, fname);
return -1; return -1;
} }
if (quell_progress < 2) { if (quell_progress < 2) {
fprintf(stderr, "%s: %s file %s auto detected as %s\n", avrdude_message("%s: %s file %s auto detected as %s\n",
progname, fio.iodesc, fname, fmtstr(format)); progname, fio.iodesc, fname, fmtstr(format));
} }
} }
@ -1584,7 +1545,7 @@ int fileio(int op, 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) {
fprintf(stderr, "%s: can't open %s file %s: %s\n", avrdude_message("%s: can't open %s file %s: %s\n",
progname, fio.iodesc, fname, strerror(errno)); progname, fio.iodesc, fname, strerror(errno));
return -1; return -1;
} }
@ -1608,8 +1569,7 @@ int fileio(int op, 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
fprintf(stderr, avrdude_message("%s: can't handle ELF file %s, "
"%s: can't handle ELF file %s, "
"ELF file support was not compiled in\n", "ELF file support was not compiled in\n",
progname, fname); progname, fname);
rc = -1; rc = -1;
@ -1628,7 +1588,7 @@ int fileio(int op, char * filename, FILEFMT format,
break; break;
default: default:
fprintf(stderr, "%s: invalid %s file format: %d\n", avrdude_message("%s: invalid %s file format: %d\n",
progname, fio.iodesc, format); progname, fio.iodesc, format);
return -1; return -1;
} }

90
flip1.c
View File

@ -239,15 +239,13 @@ int flip1_initialize(PROGRAMMER* pgm, AVRPART *part)
if (usbpid) { if (usbpid) {
pid = *(int *)(ldata(usbpid)); pid = *(int *)(ldata(usbpid));
if (lnext(usbpid)) if (lnext(usbpid))
fprintf(stderr, avrdude_message("%s: Warning: using PID 0x%04x, ignoring remaining PIDs in list\n",
"%s: Warning: using PID 0x%04x, ignoring remaining PIDs in list\n",
progname, pid); progname, pid);
} else { } else {
pid = part->usbpid; pid = part->usbpid;
} }
if (!ovsigck && (part->flags & AVRPART_HAS_PDI)) { if (!ovsigck && (part->flags & AVRPART_HAS_PDI)) {
fprintf(stderr, avrdude_message("%s: \"flip1\" (FLIP protocol version 1) is for AT90USB* and ATmega*U* devices.\n"
"%s: \"flip1\" (FLIP protocol version 1) is for AT90USB* and ATmega*U* devices.\n"
"%s For Xmega devices, use \"flip2\".\n" "%s For Xmega devices, use \"flip2\".\n"
"%s (Use -F to bypass this check.)\n", "%s (Use -F to bypass this check.)\n",
progname, progbuf, progbuf); progname, progbuf, progbuf);
@ -262,31 +260,31 @@ int flip1_initialize(PROGRAMMER* pgm, 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)
fprintf( stderr, "%s: Warning: USB idVendor = 0x%04X (expected 0x%04X)\n", avrdude_message("%s: Warning: USB idVendor = 0x%04X (expected 0x%04X)\n",
progname, 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)
fprintf( stderr, "%s: Warning: USB idProduct = 0x%04X (expected 0x%04X)\n", avrdude_message("%s: Warning: USB idProduct = 0x%04X (expected 0x%04X)\n",
progname, dfu->dev_desc.idProduct, pid); progname, dfu->dev_desc.idProduct, pid);
if (dfu->dev_desc.bNumConfigurations != 1) if (dfu->dev_desc.bNumConfigurations != 1)
fprintf( stderr, "%s: Warning: USB bNumConfigurations = %d (expected 1)\n", avrdude_message("%s: Warning: USB bNumConfigurations = %d (expected 1)\n",
progname, (int) dfu->dev_desc.bNumConfigurations); progname, (int) dfu->dev_desc.bNumConfigurations);
if (dfu->conf_desc.bNumInterfaces != 1) if (dfu->conf_desc.bNumInterfaces != 1)
fprintf( stderr, "%s: Warning: USB bNumInterfaces = %d (expected 1)\n", avrdude_message("%s: Warning: USB bNumInterfaces = %d (expected 1)\n",
progname, (int) dfu->conf_desc.bNumInterfaces); progname, (int) dfu->conf_desc.bNumInterfaces);
if (dfu->dev_desc.bDeviceClass != 254) if (dfu->dev_desc.bDeviceClass != 254)
fprintf( stderr, "%s: Warning: USB bDeviceClass = %d (expected 254)\n", avrdude_message("%s: Warning: USB bDeviceClass = %d (expected 254)\n",
progname, (int) dfu->dev_desc.bDeviceClass); progname, (int) dfu->dev_desc.bDeviceClass);
if (dfu->dev_desc.bDeviceSubClass != 1) if (dfu->dev_desc.bDeviceSubClass != 1)
fprintf( stderr, "%s: Warning: USB bDeviceSubClass = %d (expected 1)\n", avrdude_message("%s: Warning: USB bDeviceSubClass = %d (expected 1)\n",
progname, (int) dfu->dev_desc.bDeviceSubClass); progname, (int) dfu->dev_desc.bDeviceSubClass);
if (dfu->dev_desc.bDeviceProtocol != 0) if (dfu->dev_desc.bDeviceProtocol != 0)
fprintf( stderr, "%s: Warning: USB bDeviceProtocol = %d (expected 0)\n", avrdude_message("%s: Warning: USB bDeviceProtocol = %d (expected 0)\n",
progname, (int) dfu->dev_desc.bDeviceProtocol); progname, (int) dfu->dev_desc.bDeviceProtocol);
/* /*
@ -297,20 +295,20 @@ int flip1_initialize(PROGRAMMER* pgm, AVRPART *part)
*/ */
if (0) { if (0) {
if (dfu->intf_desc.bInterfaceClass != 254) if (dfu->intf_desc.bInterfaceClass != 254)
fprintf( stderr, "%s: Warning: USB bInterfaceClass = %d (expected 254)\n", avrdude_message("%s: Warning: USB bInterfaceClass = %d (expected 254)\n",
progname, (int) dfu->intf_desc.bInterfaceClass); progname, (int) dfu->intf_desc.bInterfaceClass);
if (dfu->intf_desc.bInterfaceSubClass != 1) if (dfu->intf_desc.bInterfaceSubClass != 1)
fprintf( stderr, "%s: Warning: USB bInterfaceSubClass = %d (expected 1)\n", avrdude_message("%s: Warning: USB bInterfaceSubClass = %d (expected 1)\n",
progname, (int) dfu->intf_desc.bInterfaceSubClass); progname, (int) dfu->intf_desc.bInterfaceSubClass);
if (dfu->intf_desc.bInterfaceProtocol != 0) if (dfu->intf_desc.bInterfaceProtocol != 0)
fprintf( stderr, "%s: Warning: USB bInterfaceSubClass = %d (expected 0)\n", avrdude_message("%s: Warning: USB bInterfaceSubClass = %d (expected 0)\n",
progname, (int) dfu->intf_desc.bInterfaceProtocol); progname, (int) dfu->intf_desc.bInterfaceProtocol);
} }
if (dfu->dev_desc.bMaxPacketSize0 != 32) if (dfu->dev_desc.bMaxPacketSize0 != 32)
fprintf( stderr, "%s: Warning: bMaxPacketSize0 (%d) != 32, things might go wrong\n", avrdude_message("%s: Warning: bMaxPacketSize0 (%d) != 32, things might go wrong\n",
progname, dfu->dev_desc.bMaxPacketSize0); progname, dfu->dev_desc.bMaxPacketSize0);
if (verbose) if (verbose)
@ -367,7 +365,7 @@ int flip1_chip_erase(PROGRAMMER* pgm, AVRPART *part)
unsigned int default_timeout = FLIP1(pgm)->dfu->timeout; unsigned int default_timeout = FLIP1(pgm)->dfu->timeout;
if (verbose > 1) if (verbose > 1)
fprintf(stderr, "%s: flip_chip_erase()\n", progname); avrdude_message("%s: flip_chip_erase()\n", progname);
struct flip1_cmd cmd = { struct flip1_cmd cmd = {
FLIP1_CMD_WRITE_COMMAND, { 0, 0xff } FLIP1_CMD_WRITE_COMMAND, { 0, 0xff }
@ -382,7 +380,7 @@ int flip1_chip_erase(PROGRAMMER* pgm, AVRPART *part)
return -1; return -1;
if (status.bStatus != DFU_STATUS_OK) { if (status.bStatus != DFU_STATUS_OK) {
fprintf(stderr, "%s: failed to send chip erase command: %s\n", avrdude_message("%s: failed to send chip erase command: %s\n",
progname, 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);
@ -404,7 +402,7 @@ int flip1_read_byte(PROGRAMMER* pgm, AVRPART *part, AVRMEM *mem,
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) {
fprintf(stderr, "%s: flip1_read_byte(signature): address %lu out of range\n", avrdude_message("%s: flip1_read_byte(signature): address %lu out of range\n",
progname, addr); progname, addr);
return -1; return -1;
} }
@ -415,10 +413,10 @@ int flip1_read_byte(PROGRAMMER* pgm, AVRPART *part, AVRMEM *mem,
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) {
fprintf(stderr, "%s: Error: " avrdude_message("%s: Error: "
"\"%s\" memory not accessible using FLIP", "\"%s\" memory not accessible using FLIP",
progname, mem->desc); progname, mem->desc);
fprintf(stderr, "\n"); avrdude_message("\n");
return -1; return -1;
} }
@ -440,10 +438,10 @@ int flip1_write_byte(PROGRAMMER* pgm, AVRPART *part, AVRMEM *mem,
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) {
fprintf(stderr, "%s: Error: " avrdude_message("%s: Error: "
"\"%s\" memory not accessible using FLIP", "\"%s\" memory not accessible using FLIP",
progname, mem->desc); progname, mem->desc);
fprintf(stderr, "\n"); avrdude_message("\n");
return -1; return -1;
} }
@ -461,10 +459,10 @@ int flip1_paged_load(PROGRAMMER* pgm, AVRPART *part, AVRMEM *mem,
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) {
fprintf(stderr, "%s: Error: " avrdude_message("%s: Error: "
"\"%s\" memory not accessible using FLIP", "\"%s\" memory not accessible using FLIP",
progname, mem->desc); progname, mem->desc);
fprintf(stderr, "\n"); avrdude_message("\n");
return -1; return -1;
} }
@ -487,16 +485,16 @@ int flip1_paged_write(PROGRAMMER* pgm, AVRPART *part, AVRMEM *mem,
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) {
fprintf(stderr, "%s: Error: " avrdude_message("%s: Error: "
"\"%s\" memory not accessible using FLIP", "\"%s\" memory not accessible using FLIP",
progname, mem->desc); progname, mem->desc);
fprintf(stderr, "\n"); avrdude_message("\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. */
fprintf(stderr, "%s: Error: Attempting to read more than %d bytes\n", avrdude_message("%s: Error: Attempting to read more than %d bytes\n",
progname, INT_MAX); progname, INT_MAX);
exit(1); exit(1);
} }
@ -510,13 +508,13 @@ int flip1_paged_write(PROGRAMMER* pgm, AVRPART *part, AVRMEM *mem,
int flip1_read_sig_bytes(PROGRAMMER* pgm, AVRPART *part, AVRMEM *mem) int flip1_read_sig_bytes(PROGRAMMER* pgm, AVRPART *part, AVRMEM *mem)
{ {
if (verbose > 1) if (verbose > 1)
fprintf(stderr, "%s: flip1_read_sig_bytes(): ", progname); avrdude_message("%s: flip1_read_sig_bytes(): ", progname);
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)) {
fprintf(stderr, "%s: Error: Signature read must be at least %u bytes\n", avrdude_message("%s: Error: Signature read must be at least %u bytes\n",
progname, (unsigned int) sizeof(FLIP1(pgm)->part_sig)); progname, (unsigned int) sizeof(FLIP1(pgm)->part_sig));
return -1; return -1;
} }
@ -535,7 +533,7 @@ int flip1_read_sig_bytes(PROGRAMMER* pgm, AVRPART *part, AVRMEM *mem)
}; };
if (verbose > 1) if (verbose > 1)
fprintf(stderr, "from device\n"); avrdude_message("from device\n");
for (i = 0; i < 3; i++) for (i = 0; i < 3; i++)
{ {
@ -552,7 +550,7 @@ int flip1_read_sig_bytes(PROGRAMMER* pgm, AVRPART *part, AVRMEM *mem)
if (status.bStatus != DFU_STATUS_OK) if (status.bStatus != DFU_STATUS_OK)
{ {
fprintf(stderr, "%s: failed to send cmd for signature byte %d: %s\n", avrdude_message("%s: failed to send cmd for signature byte %d: %s\n",
progname, 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);
@ -567,7 +565,7 @@ int flip1_read_sig_bytes(PROGRAMMER* pgm, AVRPART *part, AVRMEM *mem)
if (status.bStatus != DFU_STATUS_OK) if (status.bStatus != DFU_STATUS_OK)
{ {
fprintf(stderr, "%s: failed to read signature byte %d: %s\n", avrdude_message("%s: failed to read signature byte %d: %s\n",
progname, 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);
@ -578,7 +576,7 @@ int flip1_read_sig_bytes(PROGRAMMER* pgm, AVRPART *part, AVRMEM *mem)
else else
{ {
if (verbose > 1) if (verbose > 1)
fprintf(stderr, "cached\n"); avrdude_message("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));
@ -591,7 +589,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) {
fprintf(stderr, "%s: Out of memory allocating private data structure\n", avrdude_message("%s: Out of memory allocating private data structure\n",
progname); progname);
exit(1); exit(1);
} }
@ -609,7 +607,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);
fprintf(stderr, " USB max packet size : %hu\n", avrdude_message(" USB max packet size : %hu\n",
(unsigned short) flip1->dfu->dev_desc.bMaxPacketSize0); (unsigned short) flip1->dfu->dev_desc.bMaxPacketSize0);
} }
@ -628,8 +626,7 @@ int flip1_read_memory(PROGRAMMER * pgm,
if (verbose > 1) if (verbose > 1)
fprintf(stderr, avrdude_message("%s: flip_read_memory(%s, 0x%04x, %d)\n",
"%s: flip_read_memory(%s, 0x%04x, %d)\n",
progname, flip1_mem_unit_str(mem_unit), addr, size); progname, flip1_mem_unit_str(mem_unit), addr, size);
/* /*
@ -660,7 +657,7 @@ int flip1_read_memory(PROGRAMMER * pgm,
if (status.bStatus != DFU_STATUS_OK) if (status.bStatus != DFU_STATUS_OK)
{ {
fprintf(stderr, "%s: failed to read %u bytes of %s memory @%u: %s\n", avrdude_message("%s: failed to read %u bytes of %s memory @%u: %s\n",
progname, size, flip1_mem_unit_str(mem_unit), addr, progname, size, 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)
@ -674,8 +671,7 @@ int flip1_read_memory(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)
fprintf(stderr, avrdude_message("\n%s:\n"
"\n%s:\n"
"%s***********************************************************************\n" "%s***********************************************************************\n"
"%sMaybe the device is in ``security mode´´, and needs a chip erase first?\n" "%sMaybe the device is in ``security mode´´, and needs a chip erase first?\n"
"%s***********************************************************************\n" "%s***********************************************************************\n"
@ -689,7 +685,7 @@ int flip1_read_memory(PROGRAMMER * pgm,
if (status.bStatus != DFU_STATUS_OK) if (status.bStatus != DFU_STATUS_OK)
{ {
fprintf(stderr, "%s: failed to read %u bytes of %s memory @%u: %s\n", avrdude_message("%s: failed to read %u bytes of %s memory @%u: %s\n",
progname, size, flip1_mem_unit_str(mem_unit), addr, progname, size, 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)
@ -724,15 +720,13 @@ int flip1_write_memory(struct dfu_dev *dfu,
unsigned char *buf; unsigned char *buf;
if (verbose > 1) if (verbose > 1)
fprintf(stderr, avrdude_message("%s: flip_write_memory(%s, 0x%04x, %d)\n",
"%s: flip_write_memory(%s, 0x%04x, %d)\n",
progname, flip1_mem_unit_str(mem_unit), addr, size); progname, 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) {
fprintf(stderr, avrdude_message("%s: flip_write_memory(): begin (0x%x) and end (0x%x) not within same 32-byte block\n",
"%s: flip_write_memory(): begin (0x%x) and end (0x%x) not within same 32-byte block\n",
progname, addr, addr + size - 1); progname, addr, addr + size - 1);
return -1; return -1;
} }
@ -744,7 +738,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) {
fprintf(stderr, "%s: Out of memory\n", progname); avrdude_message("%s: Out of memory\n", progname);
return -1; return -1;
} }
@ -793,7 +787,7 @@ int flip1_write_memory(struct dfu_dev *dfu,
if (status.bStatus != DFU_STATUS_OK) if (status.bStatus != DFU_STATUS_OK)
{ {
fprintf(stderr, "%s: failed to write %u bytes of %s memory @%u: %s\n", avrdude_message("%s: failed to write %u bytes of %s memory @%u: %s\n",
progname, size, flip1_mem_unit_str(mem_unit), addr, progname, size, 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)
@ -824,7 +818,7 @@ int flip1_set_mem_page(struct dfu_dev *dfu,
if (status.bStatus != DFU_STATUS_OK) if (status.bStatus != DFU_STATUS_OK)
{ {
fprintf(stderr, "%s: failed to set memory page: %s\n", avrdude_message("%s: failed to set memory page: %s\n",
progname, 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);

116
flip2.c
View File

@ -233,16 +233,14 @@ int flip2_initialize(PROGRAMMER* pgm, AVRPART *part)
if (usbpid) { if (usbpid) {
pid = *(int *)(ldata(usbpid)); pid = *(int *)(ldata(usbpid));
if (lnext(usbpid)) if (lnext(usbpid))
fprintf(stderr, avrdude_message("%s: Warning: using PID 0x%04x, ignoring remaining PIDs in list\n",
"%s: Warning: using PID 0x%04x, ignoring remaining PIDs in list\n",
progname, pid); progname, pid);
} else { } else {
pid = part->usbpid; pid = part->usbpid;
} }
if (!ovsigck && !(part->flags & AVRPART_HAS_PDI)) { if (!ovsigck && !(part->flags & AVRPART_HAS_PDI)) {
fprintf(stderr, avrdude_message("%s: \"flip2\" (FLIP protocol version 2) is for Xmega devices.\n"
"%s: \"flip2\" (FLIP protocol version 2) is for Xmega devices.\n"
"%s For AT90USB* or ATmega*U* devices, use \"flip1\".\n" "%s For AT90USB* or ATmega*U* devices, use \"flip1\".\n"
"%s (Use -F to bypass this check.)\n", "%s (Use -F to bypass this check.)\n",
progname, progbuf, progbuf); progname, progbuf, progbuf);
@ -257,43 +255,43 @@ int flip2_initialize(PROGRAMMER* pgm, 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)
fprintf( stderr, "%s: Warning: USB idVendor = 0x%04X (expected 0x%04X)\n", avrdude_message("%s: Warning: USB idVendor = 0x%04X (expected 0x%04X)\n",
progname, 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)
fprintf( stderr, "%s: Warning: USB idProduct = 0x%04X (expected 0x%04X)\n", avrdude_message("%s: Warning: USB idProduct = 0x%04X (expected 0x%04X)\n",
progname, dfu->dev_desc.idProduct, pid); progname, dfu->dev_desc.idProduct, pid);
if (dfu->dev_desc.bNumConfigurations != 1) if (dfu->dev_desc.bNumConfigurations != 1)
fprintf( stderr, "%s: Warning: USB bNumConfigurations = %d (expected 1)\n", avrdude_message("%s: Warning: USB bNumConfigurations = %d (expected 1)\n",
progname, (int) dfu->dev_desc.bNumConfigurations); progname, (int) dfu->dev_desc.bNumConfigurations);
if (dfu->conf_desc.bNumInterfaces != 1) if (dfu->conf_desc.bNumInterfaces != 1)
fprintf( stderr, "%s: Warning: USB bNumInterfaces = %d (expected 1)\n", avrdude_message("%s: Warning: USB bNumInterfaces = %d (expected 1)\n",
progname, (int) dfu->conf_desc.bNumInterfaces); progname, (int) dfu->conf_desc.bNumInterfaces);
if (dfu->dev_desc.bDeviceClass != 0) if (dfu->dev_desc.bDeviceClass != 0)
fprintf( stderr, "%s: Warning: USB bDeviceClass = %d (expected 0)\n", avrdude_message("%s: Warning: USB bDeviceClass = %d (expected 0)\n",
progname, (int) dfu->dev_desc.bDeviceClass); progname, (int) dfu->dev_desc.bDeviceClass);
if (dfu->dev_desc.bDeviceSubClass != 0) if (dfu->dev_desc.bDeviceSubClass != 0)
fprintf( stderr, "%s: Warning: USB bDeviceSubClass = %d (expected 0)\n", avrdude_message("%s: Warning: USB bDeviceSubClass = %d (expected 0)\n",
progname, (int) dfu->dev_desc.bDeviceSubClass); progname, (int) dfu->dev_desc.bDeviceSubClass);
if (dfu->dev_desc.bDeviceProtocol != 0) if (dfu->dev_desc.bDeviceProtocol != 0)
fprintf( stderr, "%s: Warning: USB bDeviceProtocol = %d (expected 0)\n", avrdude_message("%s: Warning: USB bDeviceProtocol = %d (expected 0)\n",
progname, (int) dfu->dev_desc.bDeviceProtocol); progname, (int) dfu->dev_desc.bDeviceProtocol);
if (dfu->intf_desc.bInterfaceClass != 0xFF) if (dfu->intf_desc.bInterfaceClass != 0xFF)
fprintf( stderr, "%s: Warning: USB bInterfaceClass = %d (expected 255)\n", avrdude_message("%s: Warning: USB bInterfaceClass = %d (expected 255)\n",
progname, (int) dfu->intf_desc.bInterfaceClass); progname, (int) dfu->intf_desc.bInterfaceClass);
if (dfu->intf_desc.bInterfaceSubClass != 0) if (dfu->intf_desc.bInterfaceSubClass != 0)
fprintf( stderr, "%s: Warning: USB bInterfaceSubClass = %d (expected 0)\n", avrdude_message("%s: Warning: USB bInterfaceSubClass = %d (expected 0)\n",
progname, (int) dfu->intf_desc.bInterfaceSubClass); progname, (int) dfu->intf_desc.bInterfaceSubClass);
if (dfu->intf_desc.bInterfaceProtocol != 0) if (dfu->intf_desc.bInterfaceProtocol != 0)
fprintf( stderr, "%s: Warning: USB bInterfaceSubClass = %d (expected 0)\n", avrdude_message("%s: Warning: USB bInterfaceSubClass = %d (expected 0)\n",
progname, (int) dfu->intf_desc.bInterfaceProtocol); progname, (int) dfu->intf_desc.bInterfaceProtocol);
result = flip2_read_memory(FLIP2(pgm)->dfu, result = flip2_read_memory(FLIP2(pgm)->dfu,
@ -359,7 +357,7 @@ int flip2_chip_erase(PROGRAMMER* pgm, AVRPART *part)
int aux_result; int aux_result;
if (verbose > 1) if (verbose > 1)
fprintf(stderr, "%s: flip_chip_erase()\n", progname); avrdude_message("%s: flip_chip_erase()\n", progname);
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 }
@ -378,7 +376,7 @@ int flip2_chip_erase(PROGRAMMER* pgm, AVRPART *part)
{ {
continue; continue;
} else } else
fprintf(stderr, "%s: Error: DFU status %s\n", progname, avrdude_message("%s: Error: DFU status %s\n", progname,
flip2_status_str(&status)); flip2_status_str(&status));
dfu_clrstatus(FLIP2(pgm)->dfu); dfu_clrstatus(FLIP2(pgm)->dfu);
} else } else
@ -399,12 +397,12 @@ int flip2_read_byte(PROGRAMMER* pgm, AVRPART *part, AVRMEM *mem,
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) {
fprintf(stderr, "%s: Error: " avrdude_message("%s: Error: "
"\"%s\" memory not accessible using FLIP", "\"%s\" memory not accessible using FLIP",
progname, mem->desc); progname, mem->desc);
if (strcmp(mem->desc, "flash") == 0) if (strcmp(mem->desc, "flash") == 0)
fprintf(stderr, " (did you mean \"application\"?)"); avrdude_message(" (did you mean \"application\"?)");
fprintf(stderr, "\n"); avrdude_message("\n");
return -1; return -1;
} }
@ -422,12 +420,12 @@ int flip2_write_byte(PROGRAMMER* pgm, AVRPART *part, AVRMEM *mem,
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) {
fprintf(stderr, "%s: Error: " avrdude_message("%s: Error: "
"\"%s\" memory not accessible using FLIP", "\"%s\" memory not accessible using FLIP",
progname, mem->desc); progname, mem->desc);
if (strcmp(mem->desc, "flash") == 0) if (strcmp(mem->desc, "flash") == 0)
fprintf(stderr, " (did you mean \"application\"?)"); avrdude_message(" (did you mean \"application\"?)");
fprintf(stderr, "\n"); avrdude_message("\n");
return -1; return -1;
} }
@ -446,18 +444,18 @@ int flip2_paged_load(PROGRAMMER* pgm, AVRPART *part, AVRMEM *mem,
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) {
fprintf(stderr, "%s: Error: " avrdude_message("%s: Error: "
"\"%s\" memory not accessible using FLIP", "\"%s\" memory not accessible using FLIP",
progname, mem->desc); progname, mem->desc);
if (strcmp(mem->desc, "flash") == 0) if (strcmp(mem->desc, "flash") == 0)
fprintf(stderr, " (did you mean \"application\"?)"); avrdude_message(" (did you mean \"application\"?)");
fprintf(stderr, "\n"); avrdude_message("\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. */
fprintf(stderr, "%s: Error: Attempting to read more than %d bytes\n", avrdude_message("%s: Error: Attempting to read more than %d bytes\n",
progname, INT_MAX); progname, INT_MAX);
exit(1); exit(1);
} }
@ -480,18 +478,18 @@ int flip2_paged_write(PROGRAMMER* pgm, AVRPART *part, AVRMEM *mem,
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) {
fprintf(stderr, "%s: Error: " avrdude_message("%s: Error: "
"\"%s\" memory not accessible using FLIP", "\"%s\" memory not accessible using FLIP",
progname, mem->desc); progname, mem->desc);
if (strcmp(mem->desc, "flash") == 0) if (strcmp(mem->desc, "flash") == 0)
fprintf(stderr, " (did you mean \"application\"?)"); avrdude_message(" (did you mean \"application\"?)");
fprintf(stderr, "\n"); avrdude_message("\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. */
fprintf(stderr, "%s: Error: Attempting to read more than %d bytes\n", avrdude_message("%s: Error: Attempting to read more than %d bytes\n",
progname, INT_MAX); progname, INT_MAX);
exit(1); exit(1);
} }
@ -508,7 +506,7 @@ int flip2_read_sig_bytes(PROGRAMMER* pgm, AVRPART *part, AVRMEM *mem)
return -1; return -1;
if (mem->size < sizeof(FLIP2(pgm)->part_sig)) { if (mem->size < sizeof(FLIP2(pgm)->part_sig)) {
fprintf(stderr, "%s: Error: Signature read must be at least %u bytes\n", avrdude_message("%s: Error: Signature read must be at least %u bytes\n",
progname, (unsigned int) sizeof(FLIP2(pgm)->part_sig)); progname, (unsigned int) sizeof(FLIP2(pgm)->part_sig));
return -1; return -1;
} }
@ -522,7 +520,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) {
fprintf(stderr, "%s: Out of memory allocating private data structure\n", avrdude_message("%s: Out of memory allocating private data structure\n",
progname); progname);
exit(1); exit(1);
} }
@ -541,24 +539,24 @@ void flip2_show_info(struct flip2 *flip2)
{ {
dfu_show_info(flip2->dfu); dfu_show_info(flip2->dfu);
fprintf(stderr, " Part signature : 0x%02X%02X%02X\n", avrdude_message(" 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)
fprintf(stderr, " Part revision : %c\n", avrdude_message(" Part revision : %c\n",
(char) (flip2->part_rev + 'A')); (char) (flip2->part_rev + 'A'));
else else
fprintf(stderr, " Part revision : %c%c\n", avrdude_message(" 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'));
fprintf(stderr, " Bootloader version : 2.%hu.%hu\n", avrdude_message(" 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);
fprintf(stderr, " USB max packet size : %hu\n", avrdude_message(" USB max packet size : %hu\n",
(unsigned short) flip2->dfu->dev_desc.bMaxPacketSize0); (unsigned short) flip2->dfu->dev_desc.bMaxPacketSize0);
} }
@ -572,18 +570,17 @@ int flip2_read_memory(struct dfu_dev *dfu,
int result; int result;
if (verbose > 1) if (verbose > 1)
fprintf(stderr, avrdude_message("%s: flip_read_memory(%s, 0x%04x, %d)\n",
"%s: flip_read_memory(%s, 0x%04x, %d)\n",
progname, 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)
fprintf(stderr, "%s: Error: Failed to set memory unit 0x%02X (%s)\n", avrdude_message("%s: Error: Failed to set memory unit 0x%02X (%s)\n",
progname, (int) mem_unit, mem_name); progname, (int) mem_unit, mem_name);
else else
fprintf(stderr, "%s: Error: Failed to set memory unit 0x%02X\n", avrdude_message("%s: Error: Failed to set memory unit 0x%02X\n",
progname, (int) mem_unit); progname, (int) mem_unit);
return -1; return -1;
} }
@ -592,7 +589,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) {
fprintf(stderr, "%s: Error: Failed to set memory page 0x%04hX\n", avrdude_message("%s: Error: Failed to set memory page 0x%04hX\n",
progname, page_addr); progname, page_addr);
return -1; return -1;
} }
@ -604,7 +601,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) {
fprintf(stderr, "%s: Error: Failed to set memory page 0x%04hX\n", avrdude_message("%s: Error: Failed to set memory page 0x%04hX\n",
progname, page_addr); progname, page_addr);
return -1; return -1;
} }
@ -614,7 +611,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) {
fprintf(stderr, "%s: Error: Failed to read 0x%04X bytes at 0x%04lX\n", avrdude_message("%s: Error: Failed to read 0x%04X bytes at 0x%04lX\n",
progname, read_size, (unsigned long) addr); progname, read_size, (unsigned long) addr);
return -1; return -1;
} }
@ -637,18 +634,17 @@ int flip2_write_memory(struct dfu_dev *dfu,
int result; int result;
if (verbose > 1) if (verbose > 1)
fprintf(stderr, avrdude_message("%s: flip_write_memory(%s, 0x%04x, %d)\n",
"%s: flip_write_memory(%s, 0x%04x, %d)\n",
progname, 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)
fprintf(stderr, "%s: Error: Failed to set memory unit 0x%02X (%s)\n", avrdude_message("%s: Error: Failed to set memory unit 0x%02X (%s)\n",
progname, (int) mem_unit, mem_name); progname, (int) mem_unit, mem_name);
else else
fprintf(stderr, "%s: Error: Failed to set memory unit 0x%02X\n", avrdude_message("%s: Error: Failed to set memory unit 0x%02X\n",
progname, (int) mem_unit); progname, (int) mem_unit);
return -1; return -1;
} }
@ -657,7 +653,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) {
fprintf(stderr, "%s: Error: Failed to set memory page 0x%04hX\n", avrdude_message("%s: Error: Failed to set memory page 0x%04hX\n",
progname, page_addr); progname, page_addr);
return -1; return -1;
} }
@ -669,7 +665,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) {
fprintf(stderr, "%s: Error: Failed to set memory page 0x%04hX\n", avrdude_message("%s: Error: Failed to set memory page 0x%04hX\n",
progname, page_addr); progname, page_addr);
return -1; return -1;
} }
@ -679,7 +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) {
fprintf(stderr, "%s: Error: Failed to write 0x%04X bytes at 0x%04lX\n", avrdude_message("%s: Error: Failed to write 0x%04X bytes at 0x%04lX\n",
progname, write_size, (unsigned long) addr); progname, write_size, (unsigned long) addr);
return -1; return -1;
} }
@ -716,10 +712,10 @@ 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))
{ {
fprintf(stderr, "%s: Error: Unknown memory unit (0x%02x)\n", avrdude_message("%s: Error: Unknown memory unit (0x%02x)\n",
progname, (unsigned int) mem_unit); progname, (unsigned int) mem_unit);
} else } else
fprintf(stderr, "%s: Error: DFU status %s\n", progname, avrdude_message("%s: Error: DFU status %s\n", progname,
flip2_status_str(&status)); flip2_status_str(&status));
dfu_clrstatus(dfu); dfu_clrstatus(dfu);
} }
@ -753,10 +749,10 @@ 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))
{ {
fprintf(stderr, "%s: Error: Page address out of range (0x%04hx)\n", avrdude_message("%s: Error: Page address out of range (0x%04hx)\n",
progname, page_addr); progname, page_addr);
} else } else
fprintf(stderr, "%s: Error: DFU status %s\n", progname, avrdude_message("%s: Error: DFU status %s\n", progname,
flip2_status_str(&status)); flip2_status_str(&status));
dfu_clrstatus(dfu); dfu_clrstatus(dfu);
} }
@ -798,10 +794,10 @@ 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))
{ {
fprintf(stderr, "%s: Error: Address out of range [0x%04hX,0x%04hX]\n", avrdude_message("%s: Error: Address out of range [0x%04hX,0x%04hX]\n",
progname, offset, offset+size-1); progname, offset, offset+size-1);
} else } else
fprintf(stderr, "%s: Error: DFU status %s\n", progname, avrdude_message("%s: Error: DFU status %s\n", progname,
flip2_status_str(&status)); flip2_status_str(&status));
dfu_clrstatus(dfu); dfu_clrstatus(dfu);
} }
@ -828,7 +824,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) {
fprintf(stderr, "%s: Error: Write block too large (%hu > 1024)\n", avrdude_message("%s: Error: Write block too large (%hu > 1024)\n",
progname, size); progname, size);
return -1; return -1;
} }
@ -859,10 +855,10 @@ 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))
{ {
fprintf(stderr, "%s: Error: Address out of range [0x%04hX,0x%04hX]\n", avrdude_message("%s: Error: Address out of range [0x%04hX,0x%04hX]\n",
progname, offset, offset+size-1); progname, offset, offset+size-1);
} else } else
fprintf(stderr, "%s: Error: DFU status %s\n", progname, avrdude_message("%s: Error: DFU status %s\n", progname,
flip2_status_str(&status)); flip2_status_str(&status));
dfu_clrstatus(dfu); dfu_clrstatus(dfu);
} }

View File

@ -92,8 +92,7 @@
#ifndef HAVE_PTHREAD_H #ifndef HAVE_PTHREAD_H
static int ft245r_nopthread_open (struct programmer_t *pgm, char * name) { static int ft245r_nopthread_open (struct programmer_t *pgm, char * name) {
fprintf(stderr, avrdude_message("%s: error: no pthread support. Please compile again with pthread installed."
"%s: error: no pthread support. Please compile again with pthread installed."
#if defined(_WIN32) #if defined(_WIN32)
" See http://sourceware.org/pthreads-win32/." " See http://sourceware.org/pthreads-win32/."
#endif #endif
@ -111,8 +110,7 @@ void ft245r_initpgm(PROGRAMMER * pgm) {
#elif defined(DO_NOT_BUILD_FT245R) #elif defined(DO_NOT_BUILD_FT245R)
static int ft245r_noftdi_open (struct programmer_t *pgm, char * name) { static int ft245r_noftdi_open (struct programmer_t *pgm, char * name) {
fprintf(stderr, avrdude_message("%s: error: no libftdi or libusb support. Install libftdi1/libusb-1.0 or libftdi/libusb and run configure/make again.\n",
"%s: error: no libftdi or libusb support. Install libftdi1/libusb-1.0 or libftdi/libusb and run configure/make again.\n",
progname); progname);
return -1; return -1;
@ -170,7 +168,7 @@ static void add_to_buf (unsigned char c) {
else nh = head + 1; else nh = head + 1;
if (nh == tail) { if (nh == tail) {
fprintf (stderr, "buffer overflow. Cannot happen!\n"); avrdude_message("buffer overflow. Cannot happen!\n");
} }
buffer[head] = c; buffer[head] = c;
head = nh; head = nh;
@ -240,7 +238,7 @@ static int ft245r_chip_erase(PROGRAMMER * pgm, 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) {
fprintf(stderr, "chip erase instruction not defined for part \"%s\"\n", avrdude_message("chip erase instruction not defined for part \"%s\"\n",
p->desc); p->desc);
return -1; return -1;
} }
@ -266,12 +264,12 @@ static int ft245r_set_bitclock(PROGRAMMER * pgm) {
} }
if ((verbose>1) || FT245R_DEBUG) { if ((verbose>1) || FT245R_DEBUG) {
fprintf(stderr," ft245r: spi bitclk %d -> ft baudrate %d\n", avrdude_message(" ft245r: spi bitclk %d -> ft baudrate %d\n",
rate / 2, rate); rate / 2, rate);
} }
r = ftdi_set_baudrate(handle, rate); r = ftdi_set_baudrate(handle, rate);
if (r) { if (r) {
fprintf(stderr, "Set baudrate (%d) failed with error '%s'.\n", avrdude_message("Set baudrate (%d) failed with error '%s'.\n",
rate, ftdi_get_error_string (handle)); rate, ftdi_get_error_string (handle));
return -1; return -1;
} }
@ -378,8 +376,8 @@ static int ft245r_program_enable(PROGRAMMER * pgm, AVRPART * p) {
int i; int i;
if (p->op[AVR_OP_PGM_ENABLE] == NULL) { if (p->op[AVR_OP_PGM_ENABLE] == NULL) {
fprintf(stderr, avrdude_message("%s: AVR_OP_PGM_ENABLE command not defined for %s\n",
"%s: AVR_OP_PGM_ENABLE command not defined for %s\n", progname, p->desc); progname, p->desc);
fflush(stderr); fflush(stderr);
return -1; return -1;
} }
@ -392,8 +390,8 @@ static int ft245r_program_enable(PROGRAMMER * pgm, AVRPART * p) {
if (res[p->pollindex-1] == p->pollvalue) return 0; if (res[p->pollindex-1] == p->pollvalue) return 0;
if ((verbose>=1) || FT245R_DEBUG) { if ((verbose>=1) || FT245R_DEBUG) {
fprintf(stderr, avrdude_message("%s: Program enable command not successful. Retrying.\n",
"%s: Program enable command not successful. Retrying.\n", progname); progname);
fflush(stderr); fflush(stderr);
} }
set_pin(pgm, PIN_AVR_RESET, ON); set_pin(pgm, PIN_AVR_RESET, ON);
@ -406,8 +404,8 @@ static int ft245r_program_enable(PROGRAMMER * pgm, AVRPART * p) {
} }
} }
fprintf(stderr, avrdude_message("%s: Device is not responding to program enable. Check connection.\n",
"%s: Device is not responding to program enable. Check connection.\n", progname); progname);
fflush(stderr); fflush(stderr);
return -1; return -1;
@ -546,8 +544,7 @@ static int ft245r_open(PROGRAMMER * pgm, char * port) {
} }
} }
if (devnum < 0) { if (devnum < 0) {
fprintf(stderr, avrdude_message("%s: invalid portname '%s': use 'ft[0-9]+'\n",
"%s: invalid portname '%s': use 'ft[0-9]+'\n",
progname,port); progname,port);
return -1; return -1;
} }
@ -562,8 +559,7 @@ static int ft245r_open(PROGRAMMER * pgm, char * port) {
if (usbpid) { if (usbpid) {
pid = *(int *)(ldata(usbpid)); pid = *(int *)(ldata(usbpid));
if (lnext(usbpid)) if (lnext(usbpid))
fprintf(stderr, avrdude_message("%s: Warning: using PID 0x%04x, ignoring remaining PIDs in list\n",
"%s: Warning: using PID 0x%04x, ignoring remaining PIDs in list\n",
progname, pid); progname, pid);
} else { } else {
pid = USB_DEVICE_FT245; pid = USB_DEVICE_FT245;
@ -575,7 +571,7 @@ static int ft245r_open(PROGRAMMER * pgm, char * port) {
pgm->usbsn[0]?pgm->usbsn:NULL, pgm->usbsn[0]?pgm->usbsn:NULL,
devnum); devnum);
if (rv) { if (rv) {
fprintf (stderr, "can't open ftdi device %d. (%s)\n", devnum, ftdi_get_error_string(handle)); avrdude_message("can't open ftdi device %d. (%s)\n", devnum, ftdi_get_error_string(handle));
goto cleanup_no_usb; goto cleanup_no_usb;
} }
@ -605,8 +601,7 @@ static int ft245r_open(PROGRAMMER * pgm, char * port) {
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) {
fprintf(stderr, avrdude_message("%s: Synchronous BitBangMode is not supported (%s)\n",
"%s: Synchronous BitBangMode is not supported (%s)\n",
progname, ftdi_get_error_string(handle)); progname, ftdi_get_error_string(handle));
goto cleanup; goto cleanup;
} }
@ -660,7 +655,7 @@ static void ft245r_close(PROGRAMMER * pgm) {
} }
static void ft245r_display(PROGRAMMER * pgm, const char * p) { static void ft245r_display(PROGRAMMER * pgm, const char * p) {
fprintf(stderr, "%sPin assignment : 0..7 = DBUS0..7\n",p);/* , 8..11 = GPIO0..3\n",p);*/ avrdude_message("%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);
} }
@ -713,7 +708,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) {
fprintf(stderr, "can't alloc memory\n"); avrdude_message("can't alloc memory\n");
exit(1); exit(1);
} }
} }
@ -807,7 +802,7 @@ static int ft245r_paged_write_flash(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
put_request(addr_save, buf_pos, 0); put_request(addr_save, buf_pos, 0);
//ft245r_sync(pgm); //ft245r_sync(pgm);
#if 0 #if 0
fprintf(stderr, "send addr 0x%04x bufsize %d [%02x %02x] page_write %d\n", avrdude_message("send addr 0x%04x bufsize %d [%02x %02x] page_write %d\n",
addr_save,buf_pos, addr_save,buf_pos,
extract_data_out(pgm, buf , (0*4 + 3) ), extract_data_out(pgm, buf , (0*4 + 3) ),
extract_data_out(pgm, buf , (1*4 + 3) ), extract_data_out(pgm, buf , (1*4 + 3) ),

299
jtag3.c
View File

@ -110,8 +110,7 @@ static unsigned int jtag3_memaddr(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, uns
void jtag3_setup(PROGRAMMER * pgm) void jtag3_setup(PROGRAMMER * pgm)
{ {
if ((pgm->cookie = malloc(sizeof(struct pdata))) == 0) { if ((pgm->cookie = malloc(sizeof(struct pdata))) == 0) {
fprintf(stderr, avrdude_message("%s: jtag3_setup(): Out of memory allocating private data\n",
"%s: jtag3_setup(): Out of memory allocating private data\n",
progname); progname);
exit(1); exit(1);
} }
@ -170,7 +169,7 @@ static void jtag3_print_data(unsigned char *b, size_t s)
return; return;
for (i = 0; i < s; i++) { for (i = 0; i < s; i++) {
fprintf(stderr, "0x%02x", b[i]); avrdude_message("0x%02x", b[i]);
if (i % 16 == 15) if (i % 16 == 15)
putc('\n', stderr); putc('\n', stderr);
else else
@ -185,10 +184,10 @@ static void jtag3_prmsg(PROGRAMMER * pgm, unsigned char * data, size_t len)
int i; int i;
if (verbose >= 4) { if (verbose >= 4) {
fprintf(stderr, "Raw message:\n"); avrdude_message("Raw message:\n");
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
fprintf(stderr, "%02x ", data[i]); avrdude_message("%02x ", data[i]);
if (i % 16 == 15) if (i % 16 == 15)
putc('\n', stderr); putc('\n', stderr);
else else
@ -200,34 +199,34 @@ static void jtag3_prmsg(PROGRAMMER * pgm, unsigned char * data, size_t len)
switch (data[0]) { switch (data[0]) {
case SCOPE_INFO: case SCOPE_INFO:
fprintf(stderr, "[info] "); avrdude_message("[info] ");
break; break;
case SCOPE_GENERAL: case SCOPE_GENERAL:
fprintf(stderr, "[general] "); avrdude_message("[general] ");
break; break;
case SCOPE_AVR_ISP: case SCOPE_AVR_ISP:
fprintf(stderr, "[AVRISP] "); avrdude_message("[AVRISP] ");
jtag3_print_data(data + 1, len - 1); jtag3_print_data(data + 1, len - 1);
return; return;
case SCOPE_AVR: case SCOPE_AVR:
fprintf(stderr, "[AVR] "); avrdude_message("[AVR] ");
break; break;
default: default:
fprintf(stderr, "[scope 0x%02x] ", data[0]); avrdude_message("[scope 0x%02x] ", data[0]);
break; break;
} }
switch (data[1]) { switch (data[1]) {
case RSP3_OK: case RSP3_OK:
fprintf(stderr, "OK\n"); avrdude_message("OK\n");
break; break;
case RSP3_FAILED: case RSP3_FAILED:
fprintf(stderr, "FAILED"); avrdude_message("FAILED");
if (len > 3) if (len > 3)
{ {
char reason[50]; char reason[50];
@ -266,26 +265,26 @@ static void jtag3_prmsg(PROGRAMMER * pgm, unsigned char * data, size_t len)
strcpy(reason, "debugWIRE communication failed"); strcpy(reason, "debugWIRE communication failed");
break; break;
} }
fprintf(stderr, ", reason: %s\n", reason); avrdude_message(", reason: %s\n", reason);
} }
else else
{ {
fprintf(stderr, ", unspecified reason\n"); avrdude_message(", unspecified reason\n");
} }
break; break;
case RSP3_DATA: case RSP3_DATA:
fprintf(stderr, "Data returned:\n"); avrdude_message("Data returned:\n");
jtag3_print_data(data + 2, len - 2); jtag3_print_data(data + 2, len - 2);
break; break;
case RSP3_INFO: case RSP3_INFO:
fprintf(stderr, "Info returned:\n"); avrdude_message("Info returned:\n");
for (i = 2; i < len; i++) { for (i = 2; i < len; i++) {
if (isprint(data[i])) if (isprint(data[i]))
putc(data[i], stderr); putc(data[i], stderr);
else else
fprintf(stderr, "\\%03o", data[i]); avrdude_message("\\%03o", data[i]);
} }
putc('\n', stderr); putc('\n', stderr);
break; break;
@ -293,18 +292,18 @@ static void jtag3_prmsg(PROGRAMMER * pgm, unsigned char * data, size_t len)
case RSP3_PC: case RSP3_PC:
if (len < 7) if (len < 7)
{ {
fprintf(stderr, "PC reply too short\n"); avrdude_message("PC reply too short\n");
} }
else else
{ {
unsigned long pc = (data[6] << 24) | (data[5] << 16) unsigned long pc = (data[6] << 24) | (data[5] << 16)
| (data[4] << 8) | data[3]; | (data[4] << 8) | data[3];
fprintf(stderr, "PC 0x%0lx\n", pc); avrdude_message("PC 0x%0lx\n", pc);
} }
break; break;
default: default:
fprintf(stderr, "unknown message 0x%02x\n", data[1]); avrdude_message("unknown message 0x%02x\n", data[1]);
} }
} }
@ -313,10 +312,10 @@ static void jtag3_prevent(PROGRAMMER * pgm, unsigned char * data, size_t len)
int i; int i;
if (verbose >= 4) { if (verbose >= 4) {
fprintf(stderr, "Raw event:\n"); avrdude_message("Raw event:\n");
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
fprintf(stderr, "%02x ", data[i]); avrdude_message("%02x ", data[i]);
if (i % 16 == 15) if (i % 16 == 15)
putc('\n', stderr); putc('\n', stderr);
else else
@ -326,47 +325,47 @@ static void jtag3_prevent(PROGRAMMER * pgm, unsigned char * data, size_t len)
putc('\n', stderr); putc('\n', stderr);
} }
fprintf(stderr, "Event serial 0x%04x, ", avrdude_message("Event serial 0x%04x, ",
(data[3] << 8) | data[2]); (data[3] << 8) | data[2]);
switch (data[4]) { switch (data[4]) {
case SCOPE_INFO: case SCOPE_INFO:
fprintf(stderr, "[info] "); avrdude_message("[info] ");
break; break;
case SCOPE_GENERAL: case SCOPE_GENERAL:
fprintf(stderr, "[general] "); avrdude_message("[general] ");
break; break;
case SCOPE_AVR: case SCOPE_AVR:
fprintf(stderr, "[AVR] "); avrdude_message("[AVR] ");
break; break;
default: default:
fprintf(stderr, "[scope 0x%02x] ", data[0]); avrdude_message("[scope 0x%02x] ", data[0]);
break; break;
} }
switch (data[5]) { switch (data[5]) {
case EVT3_BREAK: case EVT3_BREAK:
fprintf(stderr, "BREAK"); avrdude_message("BREAK");
if (len >= 11) { if (len >= 11) {
fprintf(stderr, ", PC = 0x%lx, reason ", b4_to_u32(data + 6)); avrdude_message(", PC = 0x%lx, reason ", b4_to_u32(data + 6));
switch (data[10]) { switch (data[10]) {
case 0x00: case 0x00:
fprintf(stderr, "unspecified"); avrdude_message("unspecified");
break; break;
case 0x01: case 0x01:
fprintf(stderr, "program break"); avrdude_message("program break");
break; break;
case 0x02: case 0x02:
fprintf(stderr, "data break PDSB"); avrdude_message("data break PDSB");
break; break;
case 0x03: case 0x03:
fprintf(stderr, "data break PDMSB"); avrdude_message("data break PDMSB");
break; break;
default: default:
fprintf(stderr, "unknown: 0x%02x", data[10]); avrdude_message("unknown: 0x%02x", data[10]);
} }
/* There are two more bytes of data which always appear to be /* There are two more bytes of data which always appear to be
* 0x01, 0x00. Purpose unknown. */ * 0x01, 0x00. Purpose unknown. */
@ -375,24 +374,24 @@ static void jtag3_prevent(PROGRAMMER * pgm, unsigned char * data, size_t len)
case EVT3_SLEEP: case EVT3_SLEEP:
if (len >= 8 && data[7] == 0) if (len >= 8 && data[7] == 0)
fprintf(stderr, "sleeping"); avrdude_message("sleeping");
else if (len >= 8 && data[7] == 1) else if (len >= 8 && data[7] == 1)
fprintf(stderr, "wakeup"); avrdude_message("wakeup");
else else
fprintf(stderr, "unknown SLEEP event"); avrdude_message("unknown SLEEP event");
break; break;
case EVT3_POWER: case EVT3_POWER:
if (len >= 8 && data[7] == 0) if (len >= 8 && data[7] == 0)
fprintf(stderr, "power-down"); avrdude_message("power-down");
else if (len >= 8 && data[7] == 1) else if (len >= 8 && data[7] == 1)
fprintf(stderr, "power-up"); avrdude_message("power-up");
else else
fprintf(stderr, "unknown POWER event"); avrdude_message("unknown POWER event");
break; break;
default: default:
fprintf(stderr, "UNKNOWN 0x%02x", data[5]); avrdude_message("UNKNOWN 0x%02x", data[5]);
break; break;
} }
putc('\n', stderr); putc('\n', stderr);
@ -408,12 +407,12 @@ int jtag3_send(PROGRAMMER * pgm, unsigned char * data, size_t len)
return jtag3_edbg_send(pgm, data, len); return jtag3_edbg_send(pgm, data, len);
if (verbose >= 3) if (verbose >= 3)
fprintf(stderr, "\n%s: jtag3_send(): sending %lu bytes\n", avrdude_message("\n%s: jtag3_send(): sending %lu bytes\n",
progname, (unsigned long)len); progname, (unsigned long)len);
if ((buf = malloc(len + 4)) == NULL) if ((buf = malloc(len + 4)) == NULL)
{ {
fprintf(stderr, "%s: jtag3_send(): out of memory", avrdude_message("%s: jtag3_send(): out of memory",
progname); progname);
return -1; return -1;
} }
@ -424,8 +423,7 @@ int jtag3_send(PROGRAMMER * pgm, unsigned char * data, size_t len)
memcpy(buf + 4, data, len); memcpy(buf + 4, data, len);
if (serial_send(&pgm->fd, buf, len + 4) != 0) { if (serial_send(&pgm->fd, buf, len + 4) != 0) {
fprintf(stderr, avrdude_message("%s: jtag3_send(): failed to send command to serial port\n",
"%s: jtag3_send(): failed to send command to serial port\n",
progname); progname);
return -1; return -1;
} }
@ -448,13 +446,12 @@ static int jtag3_edbg_send(PROGRAMMER * pgm, unsigned char * data, size_t len)
} }
if (verbose >= 3) if (verbose >= 3)
fprintf(stderr, "\n%s: jtag3_edbg_send(): sending %lu bytes\n", avrdude_message("\n%s: jtag3_edbg_send(): sending %lu bytes\n",
progname, (unsigned long)len); progname, (unsigned long)len);
if (len + 8 > USBDEV_MAX_XFER_3) if (len + 8 > USBDEV_MAX_XFER_3)
{ {
fprintf(stderr, avrdude_message("%s: jtag3_edbg_send(): Fragmentation not (yet) implemented!\n",
"%s: jtag3_edbg_send(): Fragmentation not (yet) implemented!\n",
progname); progname);
return -1; return -1;
} }
@ -468,8 +465,7 @@ static int jtag3_edbg_send(PROGRAMMER * pgm, unsigned char * data, size_t len)
memcpy(buf + 8, data, len); memcpy(buf + 8, data, len);
if (serial_send(&pgm->fd, buf, USBDEV_MAX_XFER_3) != 0) { if (serial_send(&pgm->fd, buf, USBDEV_MAX_XFER_3) != 0) {
fprintf(stderr, avrdude_message("%s: jtag3_edbg_send(): failed to send command to serial port\n",
"%s: jtag3_edbg_send(): failed to send command to serial port\n",
progname); progname);
return -1; return -1;
} }
@ -478,16 +474,14 @@ static int jtag3_edbg_send(PROGRAMMER * pgm, unsigned char * data, size_t len)
if (rv < 0) { if (rv < 0) {
/* timeout in receive */ /* timeout in receive */
if (verbose > 1) if (verbose > 1)
fprintf(stderr, avrdude_message("%s: jtag3_edbg_send(): Timeout receiving packet\n",
"%s: jtag3_edbg_send(): Timeout receiving packet\n",
progname); progname);
return -1; return -1;
} }
if (status[0] != EDBG_VENDOR_AVR_CMD || status[1] != 0x01) if (status[0] != EDBG_VENDOR_AVR_CMD || status[1] != 0x01)
{ {
/* what to do in this case? */ /* what to do in this case? */
fprintf(stderr, avrdude_message("%s: jtag3_edbg_send(): Unexpected response 0x%02x, 0x%02x\n",
"%s: jtag3_edbg_send(): Unexpected response 0x%02x, 0x%02x\n",
progname, status[0], status[1]); progname, status[0], status[1]);
} }
@ -504,7 +498,7 @@ static int jtag3_edbg_prepare(PROGRAMMER * pgm)
int rv; int rv;
if (verbose >= 3) if (verbose >= 3)
fprintf(stderr, "\n%s: jtag3_edbg_prepare()\n", avrdude_message("\n%s: jtag3_edbg_prepare()\n",
progname); progname);
if (verbose >= 4) if (verbose >= 4)
@ -513,48 +507,41 @@ static int jtag3_edbg_prepare(PROGRAMMER * pgm)
buf[0] = CMSISDAP_CMD_CONNECT; buf[0] = CMSISDAP_CMD_CONNECT;
buf[1] = CMSISDAP_CONN_SWD; buf[1] = CMSISDAP_CONN_SWD;
if (serial_send(&pgm->fd, buf, USBDEV_MAX_XFER_3) != 0) { if (serial_send(&pgm->fd, buf, USBDEV_MAX_XFER_3) != 0) {
fprintf(stderr, avrdude_message("%s: jtag3_edbg_prepare(): failed to send command to serial port\n",
"%s: jtag3_edbg_prepare(): failed to send command to serial port\n",
progname); progname);
return -1; return -1;
} }
rv = serial_recv(&pgm->fd, status, USBDEV_MAX_XFER_3); rv = serial_recv(&pgm->fd, status, USBDEV_MAX_XFER_3);
if (rv != USBDEV_MAX_XFER_3) { if (rv != USBDEV_MAX_XFER_3) {
fprintf(stderr, avrdude_message("%s: jtag3_edbg_prepare(): failed to read from serial port (%d)\n",
"%s: jtag3_edbg_prepare(): failed to read from serial port (%d)\n",
progname, rv); progname, rv);
return -1; return -1;
} }
if (status[0] != CMSISDAP_CMD_CONNECT || if (status[0] != CMSISDAP_CMD_CONNECT ||
status[1] == 0) status[1] == 0)
fprintf(stderr, avrdude_message("%s: jtag3_edbg_prepare(): unexpected response 0x%02x, 0x%02x\n",
"%s: jtag3_edbg_prepare(): unexpected response 0x%02x, 0x%02x\n",
progname, status[0], status[1]); progname, status[0], status[1]);
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, avrdude_message("%s: jtag3_edbg_prepare(): connection status 0x%02x\n",
"%s: jtag3_edbg_prepare(): connection status 0x%02x\n",
progname, status[1]); progname, status[1]);
buf[0] = CMSISDAP_CMD_LED; buf[0] = CMSISDAP_CMD_LED;
buf[1] = CMSISDAP_LED_CONNECT; buf[1] = CMSISDAP_LED_CONNECT;
buf[2] = 1; buf[2] = 1;
if (serial_send(&pgm->fd, buf, USBDEV_MAX_XFER_3) != 0) { if (serial_send(&pgm->fd, buf, USBDEV_MAX_XFER_3) != 0) {
fprintf(stderr, avrdude_message("%s: jtag3_edbg_prepare(): failed to send command to serial port\n",
"%s: jtag3_edbg_prepare(): failed to send command to serial port\n",
progname); progname);
return -1; return -1;
} }
rv = serial_recv(&pgm->fd, status, USBDEV_MAX_XFER_3); rv = serial_recv(&pgm->fd, status, USBDEV_MAX_XFER_3);
if (rv != USBDEV_MAX_XFER_3) { if (rv != USBDEV_MAX_XFER_3) {
fprintf(stderr, avrdude_message("%s: jtag3_edbg_prepare(): failed to read from serial port (%d)\n",
"%s: jtag3_edbg_prepare(): failed to read from serial port (%d)\n",
progname, rv); progname, rv);
return -1; return -1;
} }
if (status[0] != CMSISDAP_CMD_LED || if (status[0] != CMSISDAP_CMD_LED ||
status[1] != 0) status[1] != 0)
fprintf(stderr, avrdude_message("%s: jtag3_edbg_prepare(): unexpected response 0x%02x, 0x%02x\n",
"%s: jtag3_edbg_prepare(): unexpected response 0x%02x, 0x%02x\n",
progname, status[0], status[1]); progname, status[0], status[1]);
return 0; return 0;
@ -571,7 +558,7 @@ static int jtag3_edbg_signoff(PROGRAMMER * pgm)
int rv; int rv;
if (verbose >= 3) if (verbose >= 3)
fprintf(stderr, "\n%s: jtag3_edbg_signoff()\n", avrdude_message("\n%s: jtag3_edbg_signoff()\n",
progname); progname);
if (verbose >= 4) if (verbose >= 4)
@ -581,42 +568,36 @@ static int jtag3_edbg_signoff(PROGRAMMER * pgm)
buf[1] = CMSISDAP_LED_CONNECT; buf[1] = CMSISDAP_LED_CONNECT;
buf[2] = 0; buf[2] = 0;
if (serial_send(&pgm->fd, buf, USBDEV_MAX_XFER_3) != 0) { if (serial_send(&pgm->fd, buf, USBDEV_MAX_XFER_3) != 0) {
fprintf(stderr, avrdude_message("%s: jtag3_edbg_signoff(): failed to send command to serial port\n",
"%s: jtag3_edbg_signoff(): failed to send command to serial port\n",
progname); progname);
return -1; return -1;
} }
rv = serial_recv(&pgm->fd, status, USBDEV_MAX_XFER_3); rv = serial_recv(&pgm->fd, status, USBDEV_MAX_XFER_3);
if (rv != USBDEV_MAX_XFER_3) { if (rv != USBDEV_MAX_XFER_3) {
fprintf(stderr, avrdude_message("%s: jtag3_edbg_signoff(): failed to read from serial port (%d)\n",
"%s: jtag3_edbg_signoff(): failed to read from serial port (%d)\n",
progname, rv); progname, rv);
return -1; return -1;
} }
if (status[0] != CMSISDAP_CMD_LED || if (status[0] != CMSISDAP_CMD_LED ||
status[1] != 0) status[1] != 0)
fprintf(stderr, avrdude_message("%s: jtag3_edbg_signoff(): unexpected response 0x%02x, 0x%02x\n",
"%s: jtag3_edbg_signoff(): unexpected response 0x%02x, 0x%02x\n",
progname, status[0], status[1]); progname, status[0], status[1]);
buf[0] = CMSISDAP_CMD_DISCONNECT; buf[0] = CMSISDAP_CMD_DISCONNECT;
if (serial_send(&pgm->fd, buf, USBDEV_MAX_XFER_3) != 0) { if (serial_send(&pgm->fd, buf, USBDEV_MAX_XFER_3) != 0) {
fprintf(stderr, avrdude_message("%s: jtag3_edbg_signoff(): failed to send command to serial port\n",
"%s: jtag3_edbg_signoff(): failed to send command to serial port\n",
progname); progname);
return -1; return -1;
} }
rv = serial_recv(&pgm->fd, status, USBDEV_MAX_XFER_3); rv = serial_recv(&pgm->fd, status, USBDEV_MAX_XFER_3);
if (rv != USBDEV_MAX_XFER_3) { if (rv != USBDEV_MAX_XFER_3) {
fprintf(stderr, avrdude_message("%s: jtag3_edbg_signoff(): failed to read from serial port (%d)\n",
"%s: jtag3_edbg_signoff(): failed to read from serial port (%d)\n",
progname, rv); progname, rv);
return -1; return -1;
} }
if (status[0] != CMSISDAP_CMD_DISCONNECT || if (status[0] != CMSISDAP_CMD_DISCONNECT ||
status[1] != 0) status[1] != 0)
fprintf(stderr, avrdude_message("%s: jtag3_edbg_signoff(): unexpected response 0x%02x, 0x%02x\n",
"%s: jtag3_edbg_signoff(): unexpected response 0x%02x, 0x%02x\n",
progname, status[0], status[1]); progname, status[0], status[1]);
return 0; return 0;
@ -645,10 +626,10 @@ static int jtag3_recv_frame(PROGRAMMER * pgm, unsigned char **msg) {
return jtag3_edbg_recv_frame(pgm, msg); return jtag3_edbg_recv_frame(pgm, msg);
if (verbose >= 4) if (verbose >= 4)
fprintf(stderr, "%s: jtag3_recv():\n", progname); avrdude_message("%s: jtag3_recv():\n", progname);
if ((buf = malloc(pgm->fd.usb.max_xfer)) == NULL) { if ((buf = malloc(pgm->fd.usb.max_xfer)) == NULL) {
fprintf(stderr, "%s: jtag3_recv(): out of memory\n", avrdude_message("%s: jtag3_recv(): out of memory\n",
progname); progname);
return -1; return -1;
} }
@ -660,8 +641,7 @@ static int jtag3_recv_frame(PROGRAMMER * pgm, unsigned char **msg) {
if (rv < 0) { if (rv < 0) {
/* timeout in receive */ /* timeout in receive */
if (verbose > 1) if (verbose > 1)
fprintf(stderr, avrdude_message("%s: jtag3_recv(): Timeout receiving packet\n",
"%s: jtag3_recv(): Timeout receiving packet\n",
progname); progname);
free(buf); free(buf);
return -1; return -1;
@ -677,10 +657,10 @@ static int jtag3_edbg_recv_frame(PROGRAMMER * pgm, unsigned char **msg) {
unsigned char *buf = NULL; unsigned char *buf = NULL;
if (verbose >= 4) if (verbose >= 4)
fprintf(stderr, "%s: jtag3_edbg_recv():\n", progname); avrdude_message("%s: jtag3_edbg_recv():\n", progname);
if ((buf = malloc(USBDEV_MAX_XFER_3)) == NULL) { if ((buf = malloc(USBDEV_MAX_XFER_3)) == NULL) {
fprintf(stderr, "%s: jtag3_edbg_recv(): out of memory\n", avrdude_message("%s: jtag3_edbg_recv(): out of memory\n",
progname); progname);
return -1; return -1;
} }
@ -688,8 +668,7 @@ static int jtag3_edbg_recv_frame(PROGRAMMER * pgm, unsigned char **msg) {
buf[0] = EDBG_VENDOR_AVR_RSP; buf[0] = EDBG_VENDOR_AVR_RSP;
if (serial_send(&pgm->fd, buf, USBDEV_MAX_XFER_3) != 0) { if (serial_send(&pgm->fd, buf, USBDEV_MAX_XFER_3) != 0) {
fprintf(stderr, avrdude_message("%s: jtag3_edbg_recv(): error sending CMSIS-DAP vendor command\n",
"%s: jtag3_edbg_recv(): error sending CMSIS-DAP vendor command\n",
progname); progname);
return -1; return -1;
} }
@ -699,8 +678,7 @@ static int jtag3_edbg_recv_frame(PROGRAMMER * pgm, unsigned char **msg) {
if (rv < 0) { if (rv < 0) {
/* timeout in receive */ /* timeout in receive */
if (verbose > 1) if (verbose > 1)
fprintf(stderr, avrdude_message("%s: jtag3_edbg_recv(): Timeout receiving packet\n",
"%s: jtag3_edbg_recv(): Timeout receiving packet\n",
progname); progname);
free(buf); free(buf);
return -1; return -1;
@ -708,16 +686,14 @@ static int jtag3_edbg_recv_frame(PROGRAMMER * pgm, unsigned char **msg) {
if (buf[0] != EDBG_VENDOR_AVR_RSP || if (buf[0] != EDBG_VENDOR_AVR_RSP ||
buf[1] != ((1 << 4) | 1)) { buf[1] != ((1 << 4) | 1)) {
fprintf(stderr, avrdude_message("%s: jtag3_edbg_recv(): Unexpected response 0x%02x, 0x%02x\n",
"%s: jtag3_edbg_recv(): Unexpected response 0x%02x, 0x%02x\n",
progname, buf[0], buf[1]); progname, buf[0], buf[1]);
return -1; return -1;
} }
/* calculate length from response; CMSIS-DAP response might be larger */ /* calculate length from response; CMSIS-DAP response might be larger */
len = (buf[2] << 8) | buf[3]; len = (buf[2] << 8) | buf[3];
if (len > rv + 4) { if (len > rv + 4) {
fprintf(stderr, avrdude_message("%s: jtag3_edbg_recv(): Unexpected length value (%d > %d)\n",
"%s: jtag3_edbg_recv(): Unexpected length value (%d > %d)\n",
progname, len, rv + 4); progname, len, rv + 4);
len = rv + 4; len = rv + 4;
} }
@ -747,7 +723,7 @@ int jtag3_recv(PROGRAMMER * pgm, unsigned char **msg) {
rv &= USB_RECV_LENGTH_MASK; rv &= USB_RECV_LENGTH_MASK;
r_seqno = ((*msg)[2] << 8) | (*msg)[1]; r_seqno = ((*msg)[2] << 8) | (*msg)[1];
if (verbose >= 3) if (verbose >= 3)
fprintf(stderr, "%s: jtag3_recv(): " avrdude_message("%s: jtag3_recv(): "
"Got message seqno %d (command_sequence == %d)\n", "Got message seqno %d (command_sequence == %d)\n",
progname, r_seqno, PDATA(pgm)->command_sequence); progname, r_seqno, PDATA(pgm)->command_sequence);
if (r_seqno == PDATA(pgm)->command_sequence) { if (r_seqno == PDATA(pgm)->command_sequence) {
@ -764,7 +740,7 @@ int jtag3_recv(PROGRAMMER * pgm, unsigned char **msg) {
return rv; return rv;
} }
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, "%s: jtag3_recv(): " avrdude_message("%s: jtag3_recv(): "
"got wrong sequence number, %u != %u\n", "got wrong sequence number, %u != %u\n",
progname, r_seqno, PDATA(pgm)->command_sequence); progname, r_seqno, PDATA(pgm)->command_sequence);
@ -779,7 +755,7 @@ int jtag3_recv(PROGRAMMER * pgm, unsigned char **msg) {
unsigned char c; unsigned char c;
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, "%s: Sending %s command: ", avrdude_message("%s: Sending %s command: ",
progname, descr); progname, descr);
jtag3_send(pgm, cmd, cmdlen); jtag3_send(pgm, cmd, cmdlen);
@ -787,20 +763,18 @@ int jtag3_recv(PROGRAMMER * pgm, unsigned char **msg) {
if (status <= 0) { if (status <= 0) {
if (verbose >= 2) if (verbose >= 2)
putc('\n', stderr); putc('\n', stderr);
fprintf(stderr, avrdude_message("%s: %s command: timeout/error communicating with programmer (status %d)\n",
"%s: %s command: timeout/error communicating with programmer (status %d)\n",
progname, descr, status); progname, descr, status);
return -1; return -1;
} else if (verbose >= 3) { } else if (verbose >= 3) {
putc('\n', stderr); putc('\n', stderr);
jtag3_prmsg(pgm, *resp, status); jtag3_prmsg(pgm, *resp, status);
} else if (verbose == 2) } else if (verbose == 2)
fprintf(stderr, "0x%02x (%d bytes msg)\n", (*resp)[1], status); avrdude_message("0x%02x (%d bytes msg)\n", (*resp)[1], status);
c = (*resp)[1]; c = (*resp)[1];
if ((c & RSP3_STATUS_MASK) != RSP3_OK) { if ((c & RSP3_STATUS_MASK) != RSP3_OK) {
fprintf(stderr, avrdude_message("%s: bad response to %s command: 0x%02x\n",
"%s: bad response to %s command: 0x%02x\n",
progname, descr, c); progname, descr, c);
free(*resp); free(*resp);
resp = 0; resp = 0;
@ -816,7 +790,7 @@ int jtag3_getsync(PROGRAMMER * pgm, int mode) {
unsigned char buf[3], *resp; unsigned char buf[3], *resp;
if (verbose >= 3) if (verbose >= 3)
fprintf(stderr, "%s: jtag3_getsync()\n", progname); avrdude_message("%s: jtag3_getsync()\n", progname);
if (pgm->flag & PGM_FL_IS_EDBG) { if (pgm->flag & PGM_FL_IS_EDBG) {
if (jtag3_edbg_prepare(pgm) < 0) if (jtag3_edbg_prepare(pgm) < 0)
@ -862,7 +836,7 @@ static int jtag3_chip_erase(PROGRAMMER * pgm, AVRPART * p)
static int jtag3_chip_erase_dw(PROGRAMMER * pgm, AVRPART * p) static int jtag3_chip_erase_dw(PROGRAMMER * pgm, AVRPART * p)
{ {
fprintf(stderr, "%s: Chip erase not supported in debugWire mode\n", avrdude_message("%s: Chip erase not supported in debugWire mode\n",
progname); progname);
return 0; return 0;
@ -893,8 +867,7 @@ static int jtag3_program_enable(PROGRAMMER * pgm)
/* XXX activate external reset here */ /* XXX activate external reset here */
if (verbose > 0) if (verbose > 0)
fprintf(stderr, avrdude_message("%s: retrying with external reset applied\n",
"%s: retrying with external reset applied\n",
progname); progname);
} }
@ -967,12 +940,10 @@ static int jtag3_initialize(PROGRAMMER * pgm, AVRPART * p)
if (jtag3_getparm(pgm, SCOPE_GENERAL, 0, PARM3_FW_MAJOR, parm, 2) < 0) if (jtag3_getparm(pgm, SCOPE_GENERAL, 0, PARM3_FW_MAJOR, parm, 2) < 0)
return -1; return -1;
if (pgm->fd.usb.max_xfer < USBDEV_MAX_XFER_3 && (pgm->flag & PGM_FL_IS_EDBG) == 0) { if (pgm->fd.usb.max_xfer < USBDEV_MAX_XFER_3 && (pgm->flag & PGM_FL_IS_EDBG) == 0) {
fprintf(stderr, avrdude_message("%s: the JTAGICE3's firmware %d.%d is broken on USB 1.1 connections, sorry\n",
"%s: the JTAGICE3's firmware %d.%d is broken on USB 1.1 connections, sorry\n",
progname, parm[0], parm[1]); progname, parm[0], parm[1]);
if (ovsigck) { if (ovsigck) {
fprintf(stderr, avrdude_message("%s: forced to continue by option -F; THIS PUTS THE DEVICE'S DATA INTEGRITY AT RISK!\n",
"%s: forced to continue by option -F; THIS PUTS THE DEVICE'S DATA INTEGRITY AT RISK!\n",
progname); progname);
} else { } else {
return -1; return -1;
@ -994,7 +965,7 @@ static int jtag3_initialize(PROGRAMMER * pgm, AVRPART * p)
} }
if (conn == 0) { if (conn == 0) {
fprintf(stderr, "%s: jtag3_initialize(): part %s has no %s interface\n", avrdude_message("%s: jtag3_initialize(): part %s has no %s interface\n",
progname, p->desc, ifname); progname, p->desc, ifname);
return -1; return -1;
} }
@ -1028,7 +999,7 @@ static int jtag3_initialize(PROGRAMMER * pgm, AVRPART * p)
{ {
unsigned int clock = 1E-3 / pgm->bitclock; /* kHz */ unsigned int clock = 1E-3 / pgm->bitclock; /* kHz */
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, "%s: jtag3_initialize(): " avrdude_message("%s: jtag3_initialize(): "
"trying to set JTAG clock to %u kHz\n", "trying to set JTAG clock to %u kHz\n",
progname, clock); progname, clock);
parm[0] = clock & 0xff; parm[0] = clock & 0xff;
@ -1040,7 +1011,7 @@ static int jtag3_initialize(PROGRAMMER * pgm, AVRPART * p)
if (conn == PARM3_CONN_JTAG) if (conn == PARM3_CONN_JTAG)
{ {
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, "%s: jtag3_initialize(): " avrdude_message("%s: jtag3_initialize(): "
"trying to set JTAG daisy-chain info to %d,%d,%d,%d\n", "trying to set JTAG daisy-chain info to %d,%d,%d,%d\n",
progname, progname,
PDATA(pgm)->jtagchain[0], PDATA(pgm)->jtagchain[1], PDATA(pgm)->jtagchain[0], PDATA(pgm)->jtagchain[1],
@ -1132,8 +1103,7 @@ static int jtag3_initialize(PROGRAMMER * pgm, AVRPART * p)
ocdrev = 4; ocdrev = 4;
else else
ocdrev = 3; /* many exceptions from that, actually */ ocdrev = 3; /* many exceptions from that, actually */
fprintf(stderr, avrdude_message("%s: part definition for %s lacks \"ocdrev\"; guessing %d\n",
"%s: part definition for %s lacks \"ocdrev\"; guessing %d\n",
progname, p->desc, ocdrev); progname, p->desc, ocdrev);
md.ocd_revision = ocdrev; md.ocd_revision = ocdrev;
} else { } else {
@ -1174,7 +1144,7 @@ static int jtag3_initialize(PROGRAMMER * pgm, AVRPART * p)
*/ */
if (resp[1] == RSP3_DATA && status >= 7 && verbose >= 1) if (resp[1] == RSP3_DATA && status >= 7 && verbose >= 1)
/* JTAG ID has been returned */ /* JTAG ID has been returned */
fprintf(stderr, "%s: JTAG ID returned: 0x%02x 0x%02x 0x%02x 0x%02x\n", avrdude_message("%s: JTAG ID returned: 0x%02x 0x%02x 0x%02x 0x%02x\n",
progname, resp[3], resp[4], resp[5], resp[6]); progname, resp[3], resp[4], resp[5], resp[6]);
free(resp); free(resp);
@ -1188,8 +1158,7 @@ static int jtag3_initialize(PROGRAMMER * pgm, AVRPART * p)
AVRMEM *bootmem = avr_locate_mem(p, "boot"); AVRMEM *bootmem = avr_locate_mem(p, "boot");
AVRMEM *flashmem = avr_locate_mem(p, "flash"); AVRMEM *flashmem = avr_locate_mem(p, "flash");
if (bootmem == NULL || flashmem == NULL) { if (bootmem == NULL || flashmem == NULL) {
fprintf(stderr, avrdude_message("%s: jtagmk3_initialize(): Cannot locate \"flash\" and \"boot\" memories in description\n",
"%s: jtagmk3_initialize(): Cannot locate \"flash\" and \"boot\" memories in description\n",
progname); progname);
} else { } else {
PDATA(pgm)->boot_start = bootmem->offset - flashmem->offset; PDATA(pgm)->boot_start = bootmem->offset - flashmem->offset;
@ -1199,12 +1168,12 @@ static int jtag3_initialize(PROGRAMMER * pgm, 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) {
fprintf(stderr, "%s: jtag3_initialize(): Out of memory\n", avrdude_message("%s: jtag3_initialize(): Out of memory\n",
progname); 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) {
fprintf(stderr, "%s: jtag3_initialize(): Out of memory\n", avrdude_message("%s: jtag3_initialize(): Out of memory\n",
progname); progname);
free(PDATA(pgm)->flash_pagecache); free(PDATA(pgm)->flash_pagecache);
return -1; return -1;
@ -1248,15 +1217,13 @@ static int jtag3_parseextparms(PROGRAMMER * pgm, LISTID extparms)
unsigned int ub, ua, bb, ba; unsigned int ub, ua, bb, ba;
if (sscanf(extended_param, "jtagchain=%u,%u,%u,%u", &ub, &ua, &bb, &ba) if (sscanf(extended_param, "jtagchain=%u,%u,%u,%u", &ub, &ua, &bb, &ba)
!= 4) { != 4) {
fprintf(stderr, avrdude_message("%s: jtag3_parseextparms(): invalid JTAG chain '%s'\n",
"%s: jtag3_parseextparms(): invalid JTAG chain '%s'\n",
progname, extended_param); progname, extended_param);
rv = -1; rv = -1;
continue; continue;
} }
if (verbose >= 2) { if (verbose >= 2) {
fprintf(stderr, avrdude_message("%s: jtag3_parseextparms(): JTAG chain parsed as:\n"
"%s: jtag3_parseextparms(): JTAG chain parsed as:\n"
"%s %u units before, %u units after, %u bits before, %u bits after\n", "%s %u units before, %u units after, %u bits before, %u bits after\n",
progname, progname,
progbuf, ub, ua, bb, ba); progbuf, ub, ua, bb, ba);
@ -1269,8 +1236,7 @@ static int jtag3_parseextparms(PROGRAMMER * pgm, LISTID extparms)
continue; continue;
} }
fprintf(stderr, avrdude_message("%s: jtag3_parseextparms(): invalid extended parameter '%s'\n",
"%s: jtag3_parseextparms(): invalid extended parameter '%s'\n",
progname, extended_param); progname, extended_param);
rv = -1; rv = -1;
} }
@ -1285,13 +1251,12 @@ int jtag3_open_common(PROGRAMMER * pgm, char * port)
int rv = -1; int rv = -1;
#if !defined(HAVE_LIBUSB) #if !defined(HAVE_LIBUSB)
fprintf(stderr, "avrdude was compiled without usb support.\n"); avrdude_message("avrdude was compiled without usb support.\n");
return -1; return -1;
#endif #endif
if (strncmp(port, "usb", 3) != 0) { if (strncmp(port, "usb", 3) != 0) {
fprintf(stderr, avrdude_message("%s: jtag3_open_common(): JTAGICE3/EDBG port names must start with \"usb\"\n",
"%s: jtag3_open_common(): JTAGICE3/EDBG port names must start with \"usb\"\n",
progname); progname);
return -1; return -1;
} }
@ -1318,14 +1283,13 @@ int jtag3_open_common(PROGRAMMER * pgm, char * port)
rv = serial_open(port, pinfo, &pgm->fd); rv = serial_open(port, pinfo, &pgm->fd);
} }
if (rv < 0) { if (rv < 0) {
fprintf(stderr, avrdude_message("%s: jtag3_open_common(): Did not find any device matching VID 0x%04x and PID list: ",
"%s: jtag3_open_common(): Did not find any device matching VID 0x%04x and PID list: ",
progname, (unsigned)pinfo.usbinfo.vid); progname, (unsigned)pinfo.usbinfo.vid);
int notfirst = 0; int notfirst = 0;
for (usbpid = lfirst(pgm->usbpid); usbpid != NULL; usbpid = lnext(usbpid)) { for (usbpid = lfirst(pgm->usbpid); usbpid != NULL; usbpid = lnext(usbpid)) {
if (notfirst) if (notfirst)
fprintf(stderr, ", "); avrdude_message(", ");
fprintf(stderr, "0x%04x", (unsigned int)(*(int *)(ldata(usbpid)))); avrdude_message("0x%04x", (unsigned int)(*(int *)(ldata(usbpid))));
notfirst = 1; notfirst = 1;
} }
fputc('\n', stderr); fputc('\n', stderr);
@ -1339,8 +1303,7 @@ int jtag3_open_common(PROGRAMMER * pgm, char * port)
running on a CMSIS-DAP device, using EDBG protocol */ running on a CMSIS-DAP device, using EDBG protocol */
pgm->flag |= PGM_FL_IS_EDBG; pgm->flag |= PGM_FL_IS_EDBG;
if (verbose) if (verbose)
fprintf(stderr, avrdude_message("%s: Found CMSIS-DAP compliant device, using EDBG protocol\n",
"%s: Found CMSIS-DAP compliant device, using EDBG protocol\n",
progname); progname);
} }
@ -1357,7 +1320,7 @@ int jtag3_open_common(PROGRAMMER * pgm, char * port)
static int jtag3_open(PROGRAMMER * pgm, char * port) static int jtag3_open(PROGRAMMER * pgm, char * port)
{ {
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, "%s: jtag3_open()\n", progname); avrdude_message("%s: jtag3_open()\n", progname);
if (jtag3_open_common(pgm, port) < 0) if (jtag3_open_common(pgm, port) < 0)
return -1; return -1;
@ -1371,7 +1334,7 @@ static int jtag3_open(PROGRAMMER * pgm, char * port)
static int jtag3_open_dw(PROGRAMMER * pgm, char * port) static int jtag3_open_dw(PROGRAMMER * pgm, char * port)
{ {
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, "%s: jtag3_open_dw()\n", progname); avrdude_message("%s: jtag3_open_dw()\n", progname);
if (jtag3_open_common(pgm, port) < 0) if (jtag3_open_common(pgm, port) < 0)
return -1; return -1;
@ -1385,7 +1348,7 @@ static int jtag3_open_dw(PROGRAMMER * pgm, char * port)
static int jtag3_open_pdi(PROGRAMMER * pgm, char * port) static int jtag3_open_pdi(PROGRAMMER * pgm, char * port)
{ {
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, "%s: jtag3_open_pdi()\n", progname); avrdude_message("%s: jtag3_open_pdi()\n", progname);
if (jtag3_open_common(pgm, port) < 0) if (jtag3_open_common(pgm, port) < 0)
return -1; return -1;
@ -1402,7 +1365,7 @@ void jtag3_close(PROGRAMMER * pgm)
unsigned char buf[4], *resp; unsigned char buf[4], *resp;
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, "%s: jtag3_close()\n", progname); avrdude_message("%s: jtag3_close()\n", progname);
buf[0] = SCOPE_AVR; buf[0] = SCOPE_AVR;
buf[1] = CMD3_SIGN_OFF; buf[1] = CMD3_SIGN_OFF;
@ -1430,11 +1393,11 @@ static int jtag3_page_erase(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
unsigned char cmd[8], *resp; unsigned char cmd[8], *resp;
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, "%s: jtag3_page_erase(.., %s, 0x%x)\n", avrdude_message("%s: jtag3_page_erase(.., %s, 0x%x)\n",
progname, m->desc, addr); progname, m->desc, addr);
if (!(p->flags & AVRPART_HAS_PDI)) { if (!(p->flags & AVRPART_HAS_PDI)) {
fprintf(stderr, "%s: jtag3_page_erase: not an Xmega device\n", avrdude_message("%s: jtag3_page_erase: not an Xmega device\n",
progname); progname);
return -1; return -1;
} }
@ -1482,7 +1445,7 @@ static int jtag3_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
long otimeout = serial_recv_timeout; long otimeout = serial_recv_timeout;
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, "%s: jtag3_paged_write(.., %s, %d, %d)\n", avrdude_message("%s: jtag3_paged_write(.., %s, %d, %d)\n",
progname, m->desc, page_size, n_bytes); progname, m->desc, page_size, n_bytes);
if (!(pgm->flag & PGM_FL_IS_DW) && jtag3_program_enable(pgm) < 0) if (!(pgm->flag & PGM_FL_IS_DW) && jtag3_program_enable(pgm) < 0)
@ -1491,7 +1454,7 @@ static int jtag3_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
if (page_size == 0) page_size = 256; if (page_size == 0) page_size = 256;
if ((cmd = malloc(page_size + 13)) == NULL) { if ((cmd = malloc(page_size + 13)) == NULL) {
fprintf(stderr, "%s: jtag3_paged_write(): Out of memory\n", avrdude_message("%s: jtag3_paged_write(): Out of memory\n",
progname); progname);
return -1; return -1;
} }
@ -1539,7 +1502,7 @@ static int jtag3_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
else else
block_size = page_size; block_size = page_size;
if (verbose >= 3) if (verbose >= 3)
fprintf(stderr, "%s: jtag3_paged_write(): " avrdude_message("%s: jtag3_paged_write(): "
"block_size at addr %d is %d\n", "block_size at addr %d is %d\n",
progname, addr, block_size); progname, addr, block_size);
@ -1588,7 +1551,7 @@ static int jtag3_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
long otimeout = serial_recv_timeout; long otimeout = serial_recv_timeout;
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, "%s: jtag3_paged_load(.., %s, %d, %d)\n", avrdude_message("%s: jtag3_paged_load(.., %s, %d, %d)\n",
progname, m->desc, page_size, n_bytes); progname, m->desc, page_size, n_bytes);
if (!(pgm->flag & PGM_FL_IS_DW) && jtag3_program_enable(pgm) < 0) if (!(pgm->flag & PGM_FL_IS_DW) && jtag3_program_enable(pgm) < 0)
@ -1627,7 +1590,7 @@ static int jtag3_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
else else
block_size = page_size; block_size = page_size;
if (verbose >= 3) if (verbose >= 3)
fprintf(stderr, "%s: jtag3_paged_load(): " avrdude_message("%s: jtag3_paged_load(): "
"block_size at addr %d is %d\n", "block_size at addr %d is %d\n",
progname, addr, block_size); progname, addr, block_size);
@ -1642,7 +1605,7 @@ static int jtag3_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
if (resp[1] != RSP3_DATA || if (resp[1] != RSP3_DATA ||
status < block_size + 4) { status < block_size + 4) {
fprintf(stderr, "%s: wrong/short reply to read memory command\n", avrdude_message("%s: wrong/short reply to read memory command\n",
progname); progname);
serial_recv_timeout = otimeout; serial_recv_timeout = otimeout;
free(resp); free(resp);
@ -1666,7 +1629,7 @@ static int jtag3_read_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
unsigned int pagesize = 0; unsigned int pagesize = 0;
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, "%s: jtag3_read_byte(.., %s, 0x%lx, ...)\n", avrdude_message("%s: jtag3_read_byte(.., %s, 0x%lx, ...)\n",
progname, mem->desc, addr); progname, mem->desc, addr);
if (!(pgm->flag & PGM_FL_IS_DW) && jtag3_program_enable(pgm) < 0) if (!(pgm->flag & PGM_FL_IS_DW) && jtag3_program_enable(pgm) < 0)
@ -1754,7 +1717,7 @@ static int jtag3_read_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
return 0; return 0;
} else { } else {
/* should not happen */ /* should not happen */
fprintf(stderr, "address out of range for signature memory: %lu\n", addr); avrdude_message("address out of range for signature memory: %lu\n", addr);
return -1; return -1;
} }
} }
@ -1795,7 +1758,7 @@ static int jtag3_read_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
if (resp[1] != RSP3_DATA || if (resp[1] != RSP3_DATA ||
status < (pagesize? pagesize: 1) + 4) { status < (pagesize? pagesize: 1) + 4) {
fprintf(stderr, "%s: wrong/short reply to read memory command\n", avrdude_message("%s: wrong/short reply to read memory command\n",
progname); progname);
free(resp); free(resp);
return -1; return -1;
@ -1822,7 +1785,7 @@ static int jtag3_write_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
unsigned int pagesize = 0; unsigned int pagesize = 0;
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, "%s: jtag3_write_byte(.., %s, 0x%lx, ...)\n", avrdude_message("%s: jtag3_write_byte(.., %s, 0x%lx, ...)\n",
progname, mem->desc, addr); progname, mem->desc, addr);
cmd[0] = SCOPE_AVR; cmd[0] = SCOPE_AVR;
@ -1939,7 +1902,7 @@ static int jtag3_set_sck_period(PROGRAMMER * pgm, double v)
parm[1] = (clock >> 8) & 0xff; parm[1] = (clock >> 8) & 0xff;
if (PDATA(pgm)->set_sck == NULL) { if (PDATA(pgm)->set_sck == NULL) {
fprintf(stderr, "%s: No backend to set the SCK period for\n", avrdude_message("%s: No backend to set the SCK period for\n",
progname); progname);
return -1; return -1;
} }
@ -1960,7 +1923,7 @@ int jtag3_getparm(PROGRAMMER * pgm, unsigned char scope,
char descr[60]; char descr[60];
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, "%s: jtag3_getparm()\n", progname); avrdude_message("%s: jtag3_getparm()\n", progname);
buf[0] = scope; buf[0] = scope;
buf[1] = CMD3_GET_PARAMETER; buf[1] = CMD3_GET_PARAMETER;
@ -1977,8 +1940,7 @@ int jtag3_getparm(PROGRAMMER * pgm, unsigned char scope,
c = resp[1]; c = resp[1];
if (c != RSP3_DATA || status < 3) { if (c != RSP3_DATA || status < 3) {
fprintf(stderr, avrdude_message("%s: jtag3_getparm(): "
"%s: jtag3_getparm(): "
"bad response to %s\n", "bad response to %s\n",
progname, descr); progname, descr);
free(resp); free(resp);
@ -2004,14 +1966,14 @@ int jtag3_setparm(PROGRAMMER * pgm, unsigned char scope,
char descr[60]; char descr[60];
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, "%s: jtag3_setparm()\n", progname); avrdude_message("%s: jtag3_setparm()\n", progname);
sprintf(descr, "set parameter (scope 0x%02x, section %d, parm %d)", sprintf(descr, "set parameter (scope 0x%02x, section %d, parm %d)",
scope, section, parm); scope, section, parm);
if ((buf = malloc(6 + length)) == NULL) if ((buf = malloc(6 + length)) == NULL)
{ {
fprintf(stderr, "%s: jtag3_setparm(): Out of memory\n", avrdude_message("%s: jtag3_setparm(): Out of memory\n",
progname); progname);
return -1; return -1;
} }
@ -2060,8 +2022,7 @@ static void jtag3_display(PROGRAMMER * pgm, const char * p)
c = resp[1]; c = resp[1];
if (c != RSP3_INFO) { if (c != RSP3_INFO) {
fprintf(stderr, avrdude_message("%s: jtag3_display(): response is not RSP3_INFO\n",
"%s: jtag3_display(): response is not RSP3_INFO\n",
progname); progname);
free(resp); free(resp);
return; return;
@ -2069,11 +2030,11 @@ static void jtag3_display(PROGRAMMER * pgm, const char * p)
memmove(resp, resp + 3, status - 3); memmove(resp, resp + 3, status - 3);
resp[status - 3] = 0; resp[status - 3] = 0;
fprintf(stderr, "%sICE hardware version: %d\n", p, parms[0]); avrdude_message("%sICE hardware version: %d\n", p, parms[0]);
fprintf(stderr, "%sICE firmware version: %d.%02d (rel. %d)\n", p, avrdude_message("%sICE firmware version: %d.%02d (rel. %d)\n", p,
parms[1], parms[2], parms[1], parms[2],
(parms[3] | (parms[4] << 8))); (parms[3] | (parms[4] << 8)));
fprintf(stderr, "%sSerial number : %s\n", p, resp); avrdude_message("%sSerial number : %s\n", p, resp);
free(resp); free(resp);
jtag3_print_parms1(pgm, p); jtag3_print_parms1(pgm, p);
@ -2087,27 +2048,27 @@ static void jtag3_print_parms1(PROGRAMMER * pgm, const char * p)
if (jtag3_getparm(pgm, SCOPE_GENERAL, 1, PARM3_VTARGET, buf, 2) < 0) if (jtag3_getparm(pgm, SCOPE_GENERAL, 1, PARM3_VTARGET, buf, 2) < 0)
return; return;
fprintf(stderr, "%sVtarget : %.2f V\n", p, avrdude_message("%sVtarget : %.2f V\n", p,
b2_to_u16(buf) / 1000.0); b2_to_u16(buf) / 1000.0);
if (jtag3_getparm(pgm, SCOPE_AVR, 1, PARM3_CLK_MEGA_PROG, buf, 2) < 0) if (jtag3_getparm(pgm, SCOPE_AVR, 1, PARM3_CLK_MEGA_PROG, buf, 2) < 0)
return; return;
fprintf(stderr, "%sJTAG clock megaAVR/program: %u kHz\n", p, avrdude_message("%sJTAG clock megaAVR/program: %u kHz\n", p,
b2_to_u16(buf)); b2_to_u16(buf));
if (jtag3_getparm(pgm, SCOPE_AVR, 1, PARM3_CLK_MEGA_DEBUG, buf, 2) < 0) if (jtag3_getparm(pgm, SCOPE_AVR, 1, PARM3_CLK_MEGA_DEBUG, buf, 2) < 0)
return; return;
fprintf(stderr, "%sJTAG clock megaAVR/debug: %u kHz\n", p, avrdude_message("%sJTAG clock megaAVR/debug: %u kHz\n", p,
b2_to_u16(buf)); b2_to_u16(buf));
if (jtag3_getparm(pgm, SCOPE_AVR, 1, PARM3_CLK_XMEGA_JTAG, buf, 2) < 0) if (jtag3_getparm(pgm, SCOPE_AVR, 1, PARM3_CLK_XMEGA_JTAG, buf, 2) < 0)
return; return;
fprintf(stderr, "%sJTAG clock Xmega: %u kHz\n", p, avrdude_message("%sJTAG clock Xmega: %u kHz\n", p,
b2_to_u16(buf)); b2_to_u16(buf));
if (jtag3_getparm(pgm, SCOPE_AVR, 1, PARM3_CLK_XMEGA_PDI, buf, 2) < 0) if (jtag3_getparm(pgm, SCOPE_AVR, 1, PARM3_CLK_XMEGA_PDI, buf, 2) < 0)
return; return;
fprintf(stderr, "%sPDI clock Xmega : %u kHz\n", p, avrdude_message("%sPDI clock Xmega : %u kHz\n", p,
b2_to_u16(buf)); b2_to_u16(buf));
} }

214
jtagmkI.c
View File

@ -112,8 +112,7 @@ static int jtagmkI_resync(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) {
fprintf(stderr, avrdude_message("%s: jtagmkI_setup(): Out of memory allocating private data\n",
"%s: jtagmkI_setup(): Out of memory allocating private data\n",
progname); progname);
exit(1); exit(1);
} }
@ -146,10 +145,10 @@ static void jtagmkI_prmsg(PROGRAMMER * pgm, unsigned char * data, size_t len)
int i; int i;
if (verbose >= 4) { if (verbose >= 4) {
fprintf(stderr, "Raw message:\n"); avrdude_message("Raw message:\n");
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
fprintf(stderr, "0x%02x ", data[i]); avrdude_message("0x%02x ", data[i]);
if (i % 16 == 15) if (i % 16 == 15)
putc('\n', stderr); putc('\n', stderr);
else else
@ -161,34 +160,34 @@ static void jtagmkI_prmsg(PROGRAMMER * pgm, unsigned char * data, size_t len)
switch (data[0]) { switch (data[0]) {
case RESP_OK: case RESP_OK:
fprintf(stderr, "OK\n"); avrdude_message("OK\n");
break; break;
case RESP_FAILED: case RESP_FAILED:
fprintf(stderr, "FAILED\n"); avrdude_message("FAILED\n");
break; break;
case RESP_BREAK: case RESP_BREAK:
fprintf(stderr, "breakpoint hit\n"); avrdude_message("breakpoint hit\n");
break; break;
case RESP_INFO: case RESP_INFO:
fprintf(stderr, "IDR dirty\n"); avrdude_message("IDR dirty\n");
break; break;
case RESP_SYNC_ERROR: case RESP_SYNC_ERROR:
fprintf(stderr, "Synchronization lost\n"); avrdude_message("Synchronization lost\n");
break; break;
case RESP_SLEEP: case RESP_SLEEP:
fprintf(stderr, "sleep instruction hit\n"); avrdude_message("sleep instruction hit\n");
break; break;
case RESP_POWER: case RESP_POWER:
fprintf(stderr, "target power lost\n"); avrdude_message("target power lost\n");
default: default:
fprintf(stderr, "unknown message 0x%02x\n", data[0]); avrdude_message("unknown message 0x%02x\n", data[0]);
} }
putc('\n', stderr); putc('\n', stderr);
@ -200,12 +199,12 @@ static int jtagmkI_send(PROGRAMMER * pgm, unsigned char * data, size_t len)
unsigned char *buf; unsigned char *buf;
if (verbose >= 3) if (verbose >= 3)
fprintf(stderr, "\n%s: jtagmkI_send(): sending %u bytes\n", avrdude_message("\n%s: jtagmkI_send(): sending %u bytes\n",
progname, (unsigned int)len); progname, (unsigned int)len);
if ((buf = malloc(len + 2)) == NULL) if ((buf = malloc(len + 2)) == NULL)
{ {
fprintf(stderr, "%s: jtagmkI_send(): out of memory", avrdude_message("%s: jtagmkI_send(): out of memory",
progname); progname);
exit(1); exit(1);
} }
@ -215,8 +214,7 @@ static int jtagmkI_send(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) {
fprintf(stderr, avrdude_message("%s: jtagmkI_send(): failed to send command to serial port\n",
"%s: jtagmkI_send(): failed to send command to serial port\n",
progname); progname);
return -1; return -1;
} }
@ -229,8 +227,7 @@ static int jtagmkI_send(PROGRAMMER * pgm, unsigned char * data, size_t len)
static int jtagmkI_recv(PROGRAMMER * pgm, unsigned char * buf, size_t len) static int jtagmkI_recv(PROGRAMMER * pgm, unsigned char * buf, size_t len)
{ {
if (serial_recv(&pgm->fd, buf, len) != 0) { if (serial_recv(&pgm->fd, buf, len) != 0) {
fprintf(stderr, avrdude_message("\n%s: jtagmkI_recv(): failed to send command to serial port\n",
"\n%s: jtagmkI_recv(): failed to send command to serial port\n",
progname); progname);
return -1; return -1;
} }
@ -257,7 +254,7 @@ static int jtagmkI_resync(PROGRAMMER * pgm, int maxtries, int signon)
serial_recv_timeout = 200; serial_recv_timeout = 200;
if (verbose >= 3) if (verbose >= 3)
fprintf(stderr, "%s: jtagmkI_resync()\n", progname); avrdude_message("%s: jtagmkI_resync()\n", progname);
jtagmkI_drain(pgm, 0); jtagmkI_drain(pgm, 0);
@ -266,19 +263,18 @@ static int jtagmkI_resync(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;
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, "%s: jtagmkI_resync(): Sending sync command: ", avrdude_message("%s: jtagmkI_resync(): Sending sync command: ",
progname); progname);
if (serial_send(&pgm->fd, buf, 1) != 0) { if (serial_send(&pgm->fd, buf, 1) != 0) {
fprintf(stderr, avrdude_message("\n%s: jtagmkI_resync(): failed to send command to serial port\n",
"\n%s: jtagmkI_resync(): failed to send command to serial port\n",
progname); progname);
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) {
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, "got RESP_OK\n"); avrdude_message("got RESP_OK\n");
break; break;
} }
@ -298,27 +294,25 @@ static int jtagmkI_resync(PROGRAMMER * pgm, int maxtries, int signon)
buf[2] = ' '; buf[2] = ' ';
buf[3] = ' '; buf[3] = ' ';
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, "%s: jtagmkI_resync(): Sending sign-on command: ", avrdude_message("%s: jtagmkI_resync(): Sending sign-on command: ",
progname); progname);
if (serial_send(&pgm->fd, buf, 4) != 0) { if (serial_send(&pgm->fd, buf, 4) != 0) {
fprintf(stderr, avrdude_message("\n%s: jtagmkI_resync(): failed to send command to serial port\n",
"\n%s: jtagmkI_resync(): failed to send command to serial port\n",
progname); progname);
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) {
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, "got RESP_OK\n"); avrdude_message("got RESP_OK\n");
break; break;
} }
} }
} }
if (tries >= maxtries) { if (tries >= maxtries) {
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, avrdude_message("%s: jtagmkI_resync(): "
"%s: jtagmkI_resync(): "
"timeout/error communicating with programmer\n", "timeout/error communicating with programmer\n",
progname); progname);
serial_recv_timeout = otimeout; serial_recv_timeout = otimeout;
@ -341,7 +335,7 @@ static int jtagmkI_getsync(PROGRAMMER * pgm)
jtagmkI_drain(pgm, 0); jtagmkI_drain(pgm, 0);
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, "%s: jtagmkI_getsync(): Sending sign-on command: ", avrdude_message("%s: jtagmkI_getsync(): Sending sign-on command: ",
progname); progname);
buf[0] = CMD_GET_SIGNON; buf[0] = CMD_GET_SIGNON;
@ -350,7 +344,7 @@ static int jtagmkI_getsync(PROGRAMMER * pgm)
return -1; return -1;
if (verbose >= 2) { if (verbose >= 2) {
resp[8] = '\0'; resp[8] = '\0';
fprintf(stderr, "got %s\n", resp + 1); avrdude_message("got %s\n", resp + 1);
} }
return 0; return 0;
@ -365,7 +359,7 @@ static int jtagmkI_chip_erase(PROGRAMMER * pgm, AVRPART * p)
buf[0] = CMD_CHIP_ERASE; buf[0] = CMD_CHIP_ERASE;
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, "%s: jtagmkI_chip_erase(): Sending chip erase command: ", avrdude_message("%s: jtagmkI_chip_erase(): Sending chip erase command: ",
progname); 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)
@ -373,14 +367,13 @@ static int jtagmkI_chip_erase(PROGRAMMER * pgm, AVRPART * p)
if (resp[0] != RESP_OK) { if (resp[0] != RESP_OK) {
if (verbose >= 2) if (verbose >= 2)
putc('\n', stderr); putc('\n', stderr);
fprintf(stderr, avrdude_message("%s: jtagmkI_chip_erase(): "
"%s: jtagmkI_chip_erase(): "
"timeout/error communicating with programmer (resp %c)\n", "timeout/error communicating with programmer (resp %c)\n",
progname, resp[0]); progname, resp[0]);
return -1; return -1;
} else { } else {
if (verbose == 2) if (verbose == 2)
fprintf(stderr, "OK\n"); avrdude_message("OK\n");
} }
pgm->initialize(pgm, p); pgm->initialize(pgm, p);
@ -414,7 +407,7 @@ static void jtagmkI_set_devdescr(PROGRAMMER * pgm, AVRPART * p)
} }
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, "%s: jtagmkI_set_devdescr(): " avrdude_message("%s: jtagmkI_set_devdescr(): "
"Sending set device descriptor command: ", "Sending set device descriptor command: ",
progname); progname);
jtagmkI_send(pgm, (unsigned char *)&sendbuf, sizeof(sendbuf)); jtagmkI_send(pgm, (unsigned char *)&sendbuf, sizeof(sendbuf));
@ -424,13 +417,12 @@ static void jtagmkI_set_devdescr(PROGRAMMER * pgm, AVRPART * p)
if (resp[0] != RESP_OK) { if (resp[0] != RESP_OK) {
if (verbose >= 2) if (verbose >= 2)
putc('\n', stderr); putc('\n', stderr);
fprintf(stderr, avrdude_message("%s: jtagmkI_set_devdescr(): "
"%s: jtagmkI_set_devdescr(): "
"timeout/error communicating with programmer (resp %c)\n", "timeout/error communicating with programmer (resp %c)\n",
progname, resp[0]); progname, resp[0]);
} else { } else {
if (verbose == 2) if (verbose == 2)
fprintf(stderr, "OK\n"); avrdude_message("OK\n");
} }
} }
@ -443,7 +435,7 @@ static int jtagmkI_reset(PROGRAMMER * pgm)
buf[0] = CMD_RESET; buf[0] = CMD_RESET;
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, "%s: jtagmkI_reset(): Sending reset command: ", avrdude_message("%s: jtagmkI_reset(): Sending reset command: ",
progname); progname);
jtagmkI_send(pgm, buf, 1); jtagmkI_send(pgm, buf, 1);
@ -452,14 +444,13 @@ static int jtagmkI_reset(PROGRAMMER * pgm)
if (resp[0] != RESP_OK) { if (resp[0] != RESP_OK) {
if (verbose >= 2) if (verbose >= 2)
putc('\n', stderr); putc('\n', stderr);
fprintf(stderr, avrdude_message("%s: jtagmkI_reset(): "
"%s: jtagmkI_reset(): "
"timeout/error communicating with programmer (resp %c)\n", "timeout/error communicating with programmer (resp %c)\n",
progname, resp[0]); progname, resp[0]);
return -1; return -1;
} else { } else {
if (verbose == 2) if (verbose == 2)
fprintf(stderr, "OK\n"); avrdude_message("OK\n");
} }
return 0; return 0;
@ -480,7 +471,7 @@ static int jtagmkI_program_enable(PROGRAMMER * pgm)
buf[0] = CMD_ENTER_PROGMODE; buf[0] = CMD_ENTER_PROGMODE;
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, "%s: jtagmkI_program_enable(): " avrdude_message("%s: jtagmkI_program_enable(): "
"Sending enter progmode command: ", "Sending enter progmode command: ",
progname); progname);
jtagmkI_send(pgm, buf, 1); jtagmkI_send(pgm, buf, 1);
@ -490,14 +481,13 @@ static int jtagmkI_program_enable(PROGRAMMER * pgm)
if (resp[0] != RESP_OK) { if (resp[0] != RESP_OK) {
if (verbose >= 2) if (verbose >= 2)
putc('\n', stderr); putc('\n', stderr);
fprintf(stderr, avrdude_message("%s: jtagmkI_program_enable(): "
"%s: jtagmkI_program_enable(): "
"timeout/error communicating with programmer (resp %c)\n", "timeout/error communicating with programmer (resp %c)\n",
progname, resp[0]); progname, resp[0]);
return -1; return -1;
} else { } else {
if (verbose == 2) if (verbose == 2)
fprintf(stderr, "OK\n"); avrdude_message("OK\n");
} }
PDATA(pgm)->prog_enabled = 1; PDATA(pgm)->prog_enabled = 1;
@ -515,7 +505,7 @@ static int jtagmkI_program_disable(PROGRAMMER * pgm)
if (pgm->fd.ifd != -1) { if (pgm->fd.ifd != -1) {
buf[0] = CMD_LEAVE_PROGMODE; buf[0] = CMD_LEAVE_PROGMODE;
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, "%s: jtagmkI_program_disable(): " avrdude_message("%s: jtagmkI_program_disable(): "
"Sending leave progmode command: ", "Sending leave progmode command: ",
progname); progname);
jtagmkI_send(pgm, buf, 1); jtagmkI_send(pgm, buf, 1);
@ -525,14 +515,13 @@ static int jtagmkI_program_disable(PROGRAMMER * pgm)
if (resp[0] != RESP_OK) { if (resp[0] != RESP_OK) {
if (verbose >= 2) if (verbose >= 2)
putc('\n', stderr); putc('\n', stderr);
fprintf(stderr, avrdude_message("%s: jtagmkI_program_disable(): "
"%s: jtagmkI_program_disable(): "
"timeout/error communicating with programmer (resp %c)\n", "timeout/error communicating with programmer (resp %c)\n",
progname, resp[0]); progname, resp[0]);
return -1; return -1;
} else { } else {
if (verbose == 2) if (verbose == 2)
fprintf(stderr, "OK\n"); avrdude_message("OK\n");
} }
} }
PDATA(pgm)->prog_enabled = 0; PDATA(pgm)->prog_enabled = 0;
@ -561,7 +550,7 @@ static int jtagmkI_initialize(PROGRAMMER * pgm, AVRPART * p)
unsigned char b; unsigned char b;
if (!(p->flags & AVRPART_HAS_JTAG)) { if (!(p->flags & AVRPART_HAS_JTAG)) {
fprintf(stderr, "%s: jtagmkI_initialize(): part %s has no JTAG interface\n", avrdude_message("%s: jtagmkI_initialize(): part %s has no JTAG interface\n",
progname, p->desc); progname, p->desc);
return -1; return -1;
} }
@ -570,11 +559,11 @@ static int jtagmkI_initialize(PROGRAMMER * pgm, AVRPART * p)
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) {
fprintf(stderr, "%s: jtagmkI_initialize(): unsupported baudrate %d\n", avrdude_message("%s: jtagmkI_initialize(): unsupported baudrate %d\n",
progname, pgm->baudrate); progname, pgm->baudrate);
} else { } else {
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, "%s: jtagmkI_initialize(): " avrdude_message("%s: jtagmkI_initialize(): "
"trying to set baudrate to %d\n", "trying to set baudrate to %d\n",
progname, pgm->baudrate); progname, pgm->baudrate);
if (jtagmkI_setparm(pgm, PARM_BITRATE, b) == 0) { if (jtagmkI_setparm(pgm, PARM_BITRATE, b) == 0) {
@ -586,7 +575,7 @@ static int jtagmkI_initialize(PROGRAMMER * pgm, AVRPART * p)
if (pgm->bitclock != 0.0) { if (pgm->bitclock != 0.0) {
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, "%s: jtagmkI_initialize(): " avrdude_message("%s: jtagmkI_initialize(): "
"trying to set JTAG clock period to %.1f us\n", "trying to set JTAG clock period to %.1f us\n",
progname, pgm->bitclock); progname, pgm->bitclock);
if (jtagmkI_set_sck_period(pgm, pgm->bitclock) != 0) if (jtagmkI_set_sck_period(pgm, pgm->bitclock) != 0)
@ -600,13 +589,12 @@ static int jtagmkI_initialize(PROGRAMMER * pgm, AVRPART * p)
if (resp[0] != RESP_OK) { if (resp[0] != RESP_OK) {
if (verbose >= 2) if (verbose >= 2)
putc('\n', stderr); putc('\n', stderr);
fprintf(stderr, avrdude_message("%s: jtagmkI_initialize(): "
"%s: jtagmkI_initialize(): "
"timeout/error communicating with programmer (resp %c)\n", "timeout/error communicating with programmer (resp %c)\n",
progname, resp[0]); progname, resp[0]);
} else { } else {
if (verbose == 2) if (verbose == 2)
fprintf(stderr, "OK\n"); avrdude_message("OK\n");
} }
/* /*
@ -621,12 +609,12 @@ static int jtagmkI_initialize(PROGRAMMER * pgm, 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) {
fprintf(stderr, "%s: jtagmkI_initialize(): Out of memory\n", avrdude_message("%s: jtagmkI_initialize(): Out of memory\n",
progname); 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) {
fprintf(stderr, "%s: jtagmkI_initialize(): Out of memory\n", avrdude_message("%s: jtagmkI_initialize(): Out of memory\n",
progname); progname);
free(PDATA(pgm)->flash_pagecache); free(PDATA(pgm)->flash_pagecache);
return -1; return -1;
@ -640,8 +628,7 @@ static int jtagmkI_initialize(PROGRAMMER * pgm, 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)
fprintf(stderr, avrdude_message("%s: jtagmkI_initialize(): warning: OCDEN fuse not programmed, "
"%s: jtagmkI_initialize(): warning: OCDEN fuse not programmed, "
"single-byte EEPROM updates not possible\n", "single-byte EEPROM updates not possible\n",
progname); progname);
@ -671,7 +658,7 @@ static int jtagmkI_open(PROGRAMMER * pgm, char * port)
size_t i; size_t i;
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, "%s: jtagmkI_open()\n", progname); avrdude_message("%s: jtagmkI_open()\n", progname);
strcpy(pgm->port, port); strcpy(pgm->port, port);
PDATA(pgm)->initial_baudrate = -1L; PDATA(pgm)->initial_baudrate = -1L;
@ -680,8 +667,7 @@ static int jtagmkI_open(PROGRAMMER * pgm, char * port)
union pinfo pinfo; union pinfo pinfo;
pinfo.baud = baudtab[i].baud; pinfo.baud = baudtab[i].baud;
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, avrdude_message("%s: jtagmkI_open(): trying to sync at baud rate %ld:\n",
"%s: jtagmkI_open(): trying to sync at baud rate %ld:\n",
progname, pinfo.baud); progname, pinfo.baud);
if (serial_open(port, pinfo, &pgm->fd)==-1) { if (serial_open(port, pinfo, &pgm->fd)==-1) {
return -1; return -1;
@ -695,15 +681,14 @@ static int jtagmkI_open(PROGRAMMER * pgm, 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;
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, "%s: jtagmkI_open(): succeeded\n", progname); avrdude_message("%s: jtagmkI_open(): succeeded\n", progname);
return 0; return 0;
} }
serial_close(&pgm->fd); serial_close(&pgm->fd);
} }
fprintf(stderr, avrdude_message("%s: jtagmkI_open(): failed to synchronize to ICE\n",
"%s: jtagmkI_open(): failed to synchronize to ICE\n",
progname); progname);
pgm->fd.ifd = -1; pgm->fd.ifd = -1;
@ -716,7 +701,7 @@ static void jtagmkI_close(PROGRAMMER * pgm)
unsigned char b; unsigned char b;
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, "%s: jtagmkI_close()\n", progname); avrdude_message("%s: jtagmkI_close()\n", progname);
/* /*
* 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
@ -725,11 +710,11 @@ 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) {
fprintf(stderr, "%s: jtagmkI_close(): unsupported baudrate %d\n", avrdude_message("%s: jtagmkI_close(): unsupported baudrate %d\n",
progname, PDATA(pgm)->initial_baudrate); progname, PDATA(pgm)->initial_baudrate);
} else { } else {
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, "%s: jtagmkI_close(): " avrdude_message("%s: jtagmkI_close(): "
"trying to set baudrate to %d\n", "trying to set baudrate to %d\n",
progname, 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) {
@ -759,7 +744,7 @@ static int jtagmkI_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
#define MAXTRIES 3 #define MAXTRIES 3
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, "%s: jtagmkI_paged_write(.., %s, %d, %d)\n", avrdude_message("%s: jtagmkI_paged_write(.., %s, %d, %d)\n",
progname, 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)
@ -768,13 +753,13 @@ static int jtagmkI_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
if (page_size == 0) page_size = 256; if (page_size == 0) page_size = 256;
if (page_size > 256) { if (page_size > 256) {
fprintf(stderr, "%s: jtagmkI_paged_write(): page size %d too large\n", avrdude_message("%s: jtagmkI_paged_write(): page size %d too large\n",
progname, page_size); progname, page_size);
return -1; return -1;
} }
if ((datacmd = malloc(page_size + 1)) == NULL) { if ((datacmd = malloc(page_size + 1)) == NULL) {
fprintf(stderr, "%s: jtagmkI_paged_write(): Out of memory\n", avrdude_message("%s: jtagmkI_paged_write(): Out of memory\n",
progname); progname);
return -1; return -1;
} }
@ -798,8 +783,7 @@ static int jtagmkI_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
again: again:
if (tries != 0 && jtagmkI_resync(pgm, 2000, 0) < 0) { if (tries != 0 && jtagmkI_resync(pgm, 2000, 0) < 0) {
fprintf(stderr, avrdude_message("%s: jtagmkI_paged_write(): sync loss, retries exhausted\n",
"%s: jtagmkI_paged_write(): sync loss, retries exhausted\n",
progname); progname);
return -1; return -1;
} }
@ -809,7 +793,7 @@ static int jtagmkI_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
else else
block_size = page_size; block_size = page_size;
if (verbose >= 3) if (verbose >= 3)
fprintf(stderr, "%s: jtagmkI_paged_write(): " avrdude_message("%s: jtagmkI_paged_write(): "
"block_size at addr %d is %d\n", "block_size at addr %d is %d\n",
progname, addr, block_size); progname, addr, block_size);
@ -824,7 +808,7 @@ static int jtagmkI_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
} }
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, "%s: jtagmkI_paged_write(): " avrdude_message("%s: jtagmkI_paged_write(): "
"Sending write memory command: ", "Sending write memory command: ",
progname); progname);
@ -835,8 +819,7 @@ static int jtagmkI_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
if (resp[0] != RESP_OK) { if (resp[0] != RESP_OK) {
if (verbose >= 2) if (verbose >= 2)
putc('\n', stderr); putc('\n', stderr);
fprintf(stderr, avrdude_message("%s: jtagmkI_paged_write(): "
"%s: jtagmkI_paged_write(): "
"timeout/error communicating with programmer (resp %c)\n", "timeout/error communicating with programmer (resp %c)\n",
progname, resp[0]); progname, resp[0]);
if (tries++ < MAXTRIES) if (tries++ < MAXTRIES)
@ -845,7 +828,7 @@ static int jtagmkI_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
return -1; return -1;
} else { } else {
if (verbose == 2) if (verbose == 2)
fprintf(stderr, "OK\n"); avrdude_message("OK\n");
} }
/* /*
@ -865,8 +848,7 @@ static int jtagmkI_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
if (resp[1] != RESP_OK) { if (resp[1] != RESP_OK) {
if (verbose >= 2) if (verbose >= 2)
putc('\n', stderr); putc('\n', stderr);
fprintf(stderr, avrdude_message("%s: jtagmkI_paged_write(): "
"%s: jtagmkI_paged_write(): "
"timeout/error communicating with programmer (resp %c)\n", "timeout/error communicating with programmer (resp %c)\n",
progname, resp[0]); progname, resp[0]);
if (tries++ < MAXTRIES) if (tries++ < MAXTRIES)
@ -875,7 +857,7 @@ static int jtagmkI_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
return -1; return -1;
} else { } else {
if (verbose == 2) if (verbose == 2)
fprintf(stderr, "OK\n"); avrdude_message("OK\n");
} }
} }
@ -897,7 +879,7 @@ static int jtagmkI_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
#define MAXTRIES 3 #define MAXTRIES 3
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, "%s: jtagmkI_paged_load(.., %s, %d, %d)\n", avrdude_message("%s: jtagmkI_paged_load(.., %s, %d, %d)\n",
progname, 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)
@ -914,7 +896,7 @@ static int jtagmkI_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
} }
if (page_size > (is_flash? 512: 256)) { if (page_size > (is_flash? 512: 256)) {
fprintf(stderr, "%s: jtagmkI_paged_load(): page size %d too large\n", avrdude_message("%s: jtagmkI_paged_load(): page size %d too large\n",
progname, page_size); progname, page_size);
return -1; return -1;
} }
@ -924,8 +906,7 @@ static int jtagmkI_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
tries = 0; tries = 0;
again: again:
if (tries != 0 && jtagmkI_resync(pgm, 2000, 0) < 0) { if (tries != 0 && jtagmkI_resync(pgm, 2000, 0) < 0) {
fprintf(stderr, avrdude_message("%s: jtagmkI_paged_load(): sync loss, retries exhausted\n",
"%s: jtagmkI_paged_load(): sync loss, retries exhausted\n",
progname); progname);
return -1; return -1;
} }
@ -935,7 +916,7 @@ static int jtagmkI_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
else else
block_size = page_size; block_size = page_size;
if (verbose >= 3) if (verbose >= 3)
fprintf(stderr, "%s: jtagmkI_paged_load(): " avrdude_message("%s: jtagmkI_paged_load(): "
"block_size at addr %d is %d\n", "block_size at addr %d is %d\n",
progname, addr, block_size); progname, addr, block_size);
@ -950,7 +931,7 @@ static int jtagmkI_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
} }
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, "%s: jtagmkI_paged_load(): Sending read memory command: ", avrdude_message("%s: jtagmkI_paged_load(): Sending read memory command: ",
progname); progname);
jtagmkI_send(pgm, cmd, 6); jtagmkI_send(pgm, cmd, 6);
@ -960,8 +941,7 @@ static int jtagmkI_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
if (resp[read_size + 3 - 1] != RESP_OK) { if (resp[read_size + 3 - 1] != RESP_OK) {
if (verbose >= 2) if (verbose >= 2)
putc('\n', stderr); putc('\n', stderr);
fprintf(stderr, avrdude_message("%s: jtagmkI_paged_load(): "
"%s: jtagmkI_paged_load(): "
"timeout/error communicating with programmer (resp %c)\n", "timeout/error communicating with programmer (resp %c)\n",
progname, resp[read_size + 3 - 1]); progname, resp[read_size + 3 - 1]);
if (tries++ < MAXTRIES) if (tries++ < MAXTRIES)
@ -971,7 +951,7 @@ static int jtagmkI_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
return -1; return -1;
} else { } else {
if (verbose == 2) if (verbose == 2)
fprintf(stderr, "OK\n"); avrdude_message("OK\n");
} }
memcpy(m->buf + addr, resp + 1, block_size); memcpy(m->buf + addr, resp + 1, block_size);
@ -993,7 +973,7 @@ static int jtagmkI_read_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
int is_flash = 0; int is_flash = 0;
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, "%s: jtagmkI_read_byte(.., %s, 0x%lx, ...)\n", avrdude_message("%s: jtagmkI_read_byte(.., %s, 0x%lx, ...)\n",
progname, mem->desc, addr); progname, mem->desc, addr);
if (jtagmkI_program_enable(pgm) < 0) if (jtagmkI_program_enable(pgm) < 0)
@ -1077,14 +1057,13 @@ static int jtagmkI_read_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
if (resp[respsize - 1] != RESP_OK) { if (resp[respsize - 1] != RESP_OK) {
if (verbose >= 2) if (verbose >= 2)
putc('\n', stderr); putc('\n', stderr);
fprintf(stderr, avrdude_message("%s: jtagmkI_read_byte(): "
"%s: jtagmkI_read_byte(): "
"timeout/error communicating with programmer (resp %c)\n", "timeout/error communicating with programmer (resp %c)\n",
progname, resp[respsize - 1]); progname, resp[respsize - 1]);
return -1; return -1;
} else { } else {
if (verbose == 2) if (verbose == 2)
fprintf(stderr, "OK\n"); avrdude_message("OK\n");
} }
if (pagesize) { if (pagesize) {
@ -1108,7 +1087,7 @@ static int jtagmkI_write_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
int len, need_progmode = 1; int len, need_progmode = 1;
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, "%s: jtagmkI_write_byte(.., %s, 0x%lx, ...)\n", avrdude_message("%s: jtagmkI_write_byte(.., %s, 0x%lx, ...)\n",
progname, mem->desc, addr); progname, mem->desc, addr);
writedata = data; writedata = data;
@ -1163,14 +1142,13 @@ static int jtagmkI_write_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
if (resp[0] != RESP_OK) { if (resp[0] != RESP_OK) {
if (verbose >= 2) if (verbose >= 2)
putc('\n', stderr); putc('\n', stderr);
fprintf(stderr, avrdude_message("%s: jtagmkI_write_byte(): "
"%s: jtagmkI_write_byte(): "
"timeout/error communicating with programmer (resp %c)\n", "timeout/error communicating with programmer (resp %c)\n",
progname, resp[0]); progname, resp[0]);
return -1; return -1;
} else { } else {
if (verbose == 2) if (verbose == 2)
fprintf(stderr, "OK\n"); avrdude_message("OK\n");
} }
/* Now, send the data buffer. */ /* Now, send the data buffer. */
@ -1194,14 +1172,13 @@ static int jtagmkI_write_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
if (resp[0] != RESP_OK) { if (resp[0] != RESP_OK) {
if (verbose >= 2) if (verbose >= 2)
putc('\n', stderr); putc('\n', stderr);
fprintf(stderr, avrdude_message("%s: jtagmkI_write_byte(): "
"%s: jtagmkI_write_byte(): "
"timeout/error communicating with programmer (resp %c)\n", "timeout/error communicating with programmer (resp %c)\n",
progname, resp[0]); progname, resp[0]);
return -1; return -1;
} else { } else {
if (verbose == 2) if (verbose == 2)
fprintf(stderr, "OK\n"); avrdude_message("OK\n");
} }
return 0; return 0;
@ -1246,12 +1223,12 @@ static int jtagmkI_getparm(PROGRAMMER * pgm, unsigned char parm,
unsigned char buf[2], resp[3]; unsigned char buf[2], resp[3];
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, "%s: jtagmkI_getparm()\n", progname); avrdude_message("%s: jtagmkI_getparm()\n", progname);
buf[0] = CMD_GET_PARAM; buf[0] = CMD_GET_PARAM;
buf[1] = parm; buf[1] = parm;
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, "%s: jtagmkI_getparm(): " avrdude_message("%s: jtagmkI_getparm(): "
"Sending get parameter command (parm 0x%02x): ", "Sending get parameter command (parm 0x%02x): ",
progname, parm); progname, parm);
jtagmkI_send(pgm, buf, 2); jtagmkI_send(pgm, buf, 2);
@ -1261,22 +1238,20 @@ static int jtagmkI_getparm(PROGRAMMER * pgm, unsigned char parm,
if (resp[0] != RESP_OK) { if (resp[0] != RESP_OK) {
if (verbose >= 2) if (verbose >= 2)
putc('\n', stderr); putc('\n', stderr);
fprintf(stderr, avrdude_message("%s: jtagmkI_getparm(): "
"%s: jtagmkI_getparm(): "
"timeout/error communicating with programmer (resp %c)\n", "timeout/error communicating with programmer (resp %c)\n",
progname, resp[0]); progname, resp[0]);
return -1; return -1;
} else if (resp[2] != RESP_OK) { } else if (resp[2] != RESP_OK) {
if (verbose >= 2) if (verbose >= 2)
putc('\n', stderr); putc('\n', stderr);
fprintf(stderr, avrdude_message("%s: jtagmkI_getparm(): "
"%s: jtagmkI_getparm(): "
"unknown parameter 0x%02x\n", "unknown parameter 0x%02x\n",
progname, parm); progname, parm);
return -1; return -1;
} else { } else {
if (verbose == 2) if (verbose == 2)
fprintf(stderr, "OK, value 0x%02x\n", resp[1]); avrdude_message("OK, value 0x%02x\n", resp[1]);
} }
*value = resp[1]; *value = resp[1];
@ -1293,13 +1268,13 @@ static int jtagmkI_setparm(PROGRAMMER * pgm, unsigned char parm,
unsigned char buf[3], resp[2]; unsigned char buf[3], resp[2];
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, "%s: jtagmkI_setparm()\n", progname); avrdude_message("%s: jtagmkI_setparm()\n", progname);
buf[0] = CMD_SET_PARAM; buf[0] = CMD_SET_PARAM;
buf[1] = parm; buf[1] = parm;
buf[2] = value; buf[2] = value;
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, "%s: jtagmkI_setparm(): " avrdude_message("%s: jtagmkI_setparm(): "
"Sending set parameter command (parm 0x%02x): ", "Sending set parameter command (parm 0x%02x): ",
progname, parm); progname, parm);
jtagmkI_send(pgm, buf, 3); jtagmkI_send(pgm, buf, 3);
@ -1308,14 +1283,13 @@ static int jtagmkI_setparm(PROGRAMMER * pgm, unsigned char parm,
if (resp[0] != RESP_OK) { if (resp[0] != RESP_OK) {
if (verbose >= 2) if (verbose >= 2)
putc('\n', stderr); putc('\n', stderr);
fprintf(stderr, avrdude_message("%s: jtagmkI_setparm(): "
"%s: jtagmkI_setparm(): "
"timeout/error communicating with programmer (resp %c)\n", "timeout/error communicating with programmer (resp %c)\n",
progname, resp[0]); progname, resp[0]);
return -1; return -1;
} else { } else {
if (verbose == 2) if (verbose == 2)
fprintf(stderr, "OK\n"); avrdude_message("OK\n");
} }
return 0; return 0;
@ -1331,8 +1305,8 @@ static void jtagmkI_display(PROGRAMMER * pgm, const char * p)
jtagmkI_getparm(pgm, PARM_SW_VERSION, &fw) < 0) jtagmkI_getparm(pgm, PARM_SW_VERSION, &fw) < 0)
return; return;
fprintf(stderr, "%sICE hardware version: 0x%02x\n", p, hw); avrdude_message("%sICE hardware version: 0x%02x\n", p, hw);
fprintf(stderr, "%sICE firmware version: 0x%02x\n", p, fw); avrdude_message("%sICE firmware version: 0x%02x\n", p, fw);
jtagmkI_print_parms1(pgm, p); jtagmkI_print_parms1(pgm, p);
@ -1376,9 +1350,9 @@ static void jtagmkI_print_parms1(PROGRAMMER * pgm, const char * p)
clk = 1e6; clk = 1e6;
} }
fprintf(stderr, "%sVtarget : %.1f V\n", p, avrdude_message("%sVtarget : %.1f V\n", p,
6.25 * (unsigned)vtarget / 255.0); 6.25 * (unsigned)vtarget / 255.0);
fprintf(stderr, "%sJTAG clock : %s (%.1f us)\n", p, clkstr, avrdude_message("%sJTAG clock : %s (%.1f us)\n", p, clkstr,
1.0e6 / clk); 1.0e6 / clk);
return; return;

File diff suppressed because it is too large Load Diff

10
lexer.l
View File

@ -95,9 +95,9 @@ SIGN [+-]
} }
if (c == EOF) { if (c == EOF) {
fprintf(stderr, "error at %s:%d: EOF in comment\n", avrdude_message("error at %s:%d: EOF in comment\n",
infile, lineno); infile, lineno);
fprintf(stderr, " comment started on line %d\n", avrdude_message(" comment started on line %d\n",
comment_start); comment_start);
exit(1); exit(1);
break; break;
@ -116,7 +116,7 @@ SIGN [+-]
<strng>\\(.|\n) *(string_buf_ptr++) = yytext[1]; <strng>\\(.|\n) *(string_buf_ptr++) = yytext[1];
<strng>[^\\\n\"]+ { char *yptr = yytext; while (*yptr) <strng>[^\\\n\"]+ { char *yptr = yytext; while (*yptr)
*(string_buf_ptr++) = *(yptr++); } *(string_buf_ptr++) = *(yptr++); }
<strng>\n { fprintf(stderr, "error at line %d: unterminated character constant\n", <strng>\n { avrdude_message("error at line %d: unterminated character constant\n",
lineno); lineno);
exit(1); } exit(1); }
@ -255,9 +255,9 @@ yes { yylval=new_token(K_YES); return K_YES; }
"\n" { lineno++; } "\n" { lineno++; }
[ \r\t]+ { /* ignore whitespace */ } [ \r\t]+ { /* ignore whitespace */ }
c: { fprintf(stderr, "error at %s:%d: possible old-style config file entry\n", c: { avrdude_message("error at %s:%d: possible old-style config file entry\n",
infile, lineno); infile, lineno);
fprintf(stderr, " Update your config file (see %s%s for a sample)\n", avrdude_message(" Update your config file (see %s%s for a sample)\n",
CONFIG_DIR, "/avrdude.conf.sample"); CONFIG_DIR, "/avrdude.conf.sample");
return YYERRCODE; } return YYERRCODE; }

View File

@ -33,7 +33,7 @@
#define ppi_claim(fd) \ #define ppi_claim(fd) \
if (ioctl(fd, PPCLAIM)) { \ if (ioctl(fd, PPCLAIM)) { \
fprintf(stderr, "%s: can't claim device \"%s\": %s\n\n", \ avrdude_message("%s: can't claim device \"%s\": %s\n\n", \
progname, port, strerror(errno)); \ progname, port, strerror(errno)); \
close(fd); \ close(fd); \
exit(1); \ exit(1); \
@ -41,7 +41,7 @@
#define ppi_release(fd) \ #define ppi_release(fd) \
if (ioctl(fd, PPRELEASE)) { \ if (ioctl(fd, PPRELEASE)) { \
fprintf(stderr, "%s: can't release device: %s\n\n", \ avrdude_message("%s: can't release device: %s\n\n", \
progname, strerror(errno)); \ progname, strerror(errno)); \
exit(1); \ exit(1); \
} }

View File

@ -219,7 +219,7 @@ static int linuxgpio_highpulsepin(PROGRAMMER * pgm, int pinfunc)
static void linuxgpio_display(PROGRAMMER *pgm, const char *p) static void linuxgpio_display(PROGRAMMER *pgm, const char *p)
{ {
fprintf(stderr, "%sPin assignment : /sys/class/gpio/gpio{n}\n",p); avrdude_message("%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);
} }
@ -269,7 +269,7 @@ static int linuxgpio_open(PROGRAMMER *pgm, 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) {
fprintf(stderr, "Can't export GPIO %d, already exported/busy?: %s", avrdude_message("Can't export GPIO %d, already exported/busy?: %s",
pin, strerror(errno)); pin, strerror(errno));
return r; return r;
} }
@ -346,8 +346,7 @@ const char linuxgpio_desc[] = "GPIO bitbanging using the Linux sysfs interface";
void linuxgpio_initpgm(PROGRAMMER * pgm) void linuxgpio_initpgm(PROGRAMMER * pgm)
{ {
fprintf(stderr, avrdude_message("%s: Linux sysfs GPIO support not available in this configuration\n",
"%s: Linux sysfs GPIO support not available in this configuration\n",
progname); progname);
} }

256
main.c
View File

@ -33,6 +33,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <limits.h> #include <limits.h>
@ -65,12 +66,21 @@ 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 yyerror(char * errmsg) int avrdude_message(const char *format, ...)
{ {
fprintf(stderr, "%s: %s at %s:%d\n", progname, errmsg, infile, lineno); int rc;
exit(1); va_list ap;
va_start(ap, format);
rc = vfprintf(stderr, format, ap);
va_end(ap);
return rc;
} }
int yyerror(char * errmsg)
{
avrdude_message("%s: %s at %s:%d\n", progname, errmsg, infile, lineno);
exit(1);
}
struct list_walk_cookie struct list_walk_cookie
{ {
@ -94,12 +104,14 @@ int quell_progress; /* un-verebose output */
int ovsigck; /* 1=override sig check, 0=don't */ int ovsigck; /* 1=override sig check, 0=don't */
/* /*
* usage message * usage message
*/ */
static void usage(void) static void usage(void)
{ {
fprintf(stderr, avrdude_message(
"Usage: %s [options]\n" "Usage: %s [options]\n"
"Options:\n" "Options:\n"
" -p <partno> Required. Specify AVR device.\n" " -p <partno> Required. Specify AVR device.\n"
@ -153,18 +165,18 @@ static void update_progress_tty (int percent, double etime, char *hdr)
} }
if (hdr) { if (hdr) {
fprintf (stderr, "\n"); avrdude_message("\n");
last = 0; last = 0;
header = hdr; header = hdr;
} }
if (last == 0) { if (last == 0) {
fprintf(stderr, "\r%s | %s | %d%% %0.2fs", avrdude_message("\r%s | %s | %d%% %0.2fs",
header, hashes, percent, etime); header, hashes, percent, etime);
} }
if (percent == 100) { if (percent == 100) {
if (!last) fprintf (stderr, "\n\n"); if (!last) avrdude_message("\n\n");
last = 1; last = 1;
} }
@ -180,19 +192,19 @@ static void update_progress_no_tty (int percent, double etime, char *hdr)
setvbuf(stderr, (char*)NULL, _IONBF, 0); setvbuf(stderr, (char*)NULL, _IONBF, 0);
if (hdr) { if (hdr) {
fprintf (stderr, "\n%s | ", hdr); avrdude_message("\n%s | ", hdr);
last = 0; last = 0;
done = 0; done = 0;
} }
else { else {
while ((cnt > last) && (done == 0)) { while ((cnt > last) && (done == 0)) {
fprintf (stderr, "#"); avrdude_message("#");
cnt -= 2; cnt -= 2;
} }
} }
if ((percent == 100) && (done == 0)) { if ((percent == 100) && (done == 0)) {
fprintf (stderr, " | 100%% %0.2fs\n\n", etime); avrdude_message(" | 100%% %0.2fs\n\n", etime);
last = 0; last = 0;
done = 1; done = 1;
} }
@ -381,19 +393,19 @@ int main(int argc, char * argv [])
updates = lcreat(NULL, 0); updates = lcreat(NULL, 0);
if (updates == NULL) { if (updates == NULL) {
fprintf(stderr, "%s: cannot initialize updater list\n", progname); avrdude_message("%s: cannot initialize updater list\n", progname);
exit(1); exit(1);
} }
extended_params = lcreat(NULL, 0); extended_params = lcreat(NULL, 0);
if (extended_params == NULL) { if (extended_params == NULL) {
fprintf(stderr, "%s: cannot initialize extended parameter list\n", progname); avrdude_message("%s: cannot initialize extended parameter list\n", progname);
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) {
fprintf(stderr, "%s: cannot initialize additional config files list\n", progname); avrdude_message("%s: cannot initialize additional config files list\n", progname);
exit(1); exit(1);
} }
@ -466,7 +478,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)) {
fprintf(stderr, "%s: invalid baud rate specified '%s'\n", avrdude_message("%s: invalid baud rate specified '%s'\n",
progname, optarg); progname, optarg);
exit(1); exit(1);
} }
@ -475,7 +487,7 @@ int main(int argc, char * argv [])
case 'B': /* specify JTAG ICE bit clock period */ case 'B': /* specify JTAG ICE bit clock period */
bitclock = strtod(optarg, &e); bitclock = strtod(optarg, &e);
if ((e == optarg) || (*e != 0) || bitclock == 0.0) { if ((e == optarg) || (*e != 0) || bitclock == 0.0) {
fprintf(stderr, "%s: invalid bit clock period specified '%s'\n", avrdude_message("%s: invalid bit clock period specified '%s'\n",
progname, optarg); progname, optarg);
exit(1); exit(1);
} }
@ -484,7 +496,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) {
fprintf(stderr, "%s: invalid isp clock delay specified '%s'\n", avrdude_message("%s: invalid isp clock delay specified '%s'\n",
progname, optarg); progname, optarg);
exit(1); exit(1);
} }
@ -560,7 +572,7 @@ int main(int argc, char * argv [])
case 'U': case 'U':
upd = parse_op(optarg); upd = parse_op(optarg);
if (upd == NULL) { if (upd == NULL) {
fprintf(stderr, "%s: error parsing update operation '%s'\n", avrdude_message("%s: error parsing update operation '%s'\n",
progname, optarg); progname, optarg);
exit(1); exit(1);
} }
@ -586,12 +598,12 @@ int main(int argc, char * argv [])
break; break;
case 'y': case 'y':
fprintf(stderr, "%s: erase cycle counter no longer supported\n", avrdude_message("%s: erase cycle counter no longer supported\n",
progname); progname);
break; break;
case 'Y': case 'Y':
fprintf(stderr, "%s: erase cycle counter no longer supported\n", avrdude_message("%s: erase cycle counter no longer supported\n",
progname); progname);
break; break;
@ -601,7 +613,7 @@ int main(int argc, char * argv [])
break; break;
default: default:
fprintf(stderr, "%s: invalid option -%c\n\n", progname, ch); avrdude_message("%s: invalid option -%c\n\n", progname, ch);
usage(); usage();
exit(1); exit(1);
break; break;
@ -637,37 +649,34 @@ 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
*/ */
fprintf(stderr, avrdude_message("\n%s: Version %s, compiled on %s at %s\n"
"\n%s: Version %s, compiled on %s at %s\n"
"%sCopyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/\n" "%sCopyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/\n"
"%sCopyright (c) 2007-2014 Joerg Wunsch\n\n", "%sCopyright (c) 2007-2014 Joerg Wunsch\n\n",
progname, version, __DATE__, __TIME__, progbuf, progbuf); progname, version, __DATE__, __TIME__, progbuf, progbuf);
} }
if (verbose) { if (verbose) {
fprintf(stderr, "%sSystem wide configuration file is \"%s\"\n", avrdude_message("%sSystem wide configuration file is \"%s\"\n",
progbuf, sys_config); progbuf, sys_config);
} }
rc = read_config(sys_config); rc = read_config(sys_config);
if (rc) { if (rc) {
fprintf(stderr, avrdude_message("%s: error reading system wide configuration file \"%s\"\n",
"%s: error reading system wide configuration file \"%s\"\n",
progname, sys_config); progname, sys_config);
exit(1); exit(1);
} }
if (usr_config[0] != 0) { if (usr_config[0] != 0) {
if (verbose) { if (verbose) {
fprintf(stderr, "%sUser configuration file is \"%s\"\n", avrdude_message("%sUser configuration file is \"%s\"\n",
progbuf, 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)) {
if (verbose) { if (verbose) {
fprintf(stderr, avrdude_message("%sUser configuration file does not exist or is not a "
"%sUser configuration file does not exist or is not a "
"regular file, skipping\n", "regular file, skipping\n",
progbuf); progbuf);
} }
@ -675,7 +684,7 @@ int main(int argc, char * argv [])
else { else {
rc = read_config(usr_config); rc = read_config(usr_config);
if (rc) { if (rc) {
fprintf(stderr, "%s: error reading user configuration file \"%s\"\n", avrdude_message("%s: error reading user configuration file \"%s\"\n",
progname, usr_config); progname, usr_config);
exit(1); exit(1);
} }
@ -689,14 +698,13 @@ 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);
if (verbose) { if (verbose) {
fprintf(stderr, "%sAdditional configuration file is \"%s\"\n", avrdude_message("%sAdditional configuration file is \"%s\"\n",
progbuf, p); progbuf, p);
} }
rc = read_config(p); rc = read_config(p);
if (rc) { if (rc) {
fprintf(stderr, avrdude_message("%s: error reading additional configuration file \"%s\"\n",
"%s: error reading additional configuration file \"%s\"\n",
progname, p); progname, p);
exit(1); exit(1);
} }
@ -709,65 +717,61 @@ int main(int argc, char * argv [])
} }
if (verbose) { if (verbose) {
fprintf(stderr, "\n"); avrdude_message("\n");
} }
if (partdesc) { if (partdesc) {
if (strcmp(partdesc, "?") == 0) { if (strcmp(partdesc, "?") == 0) {
fprintf(stderr, "\n"); avrdude_message("\n");
fprintf(stderr,"Valid parts are:\n"); avrdude_message("Valid parts are:\n");
list_parts(stderr, " ", part_list); list_parts(stderr, " ", part_list);
fprintf(stderr, "\n"); avrdude_message("\n");
exit(1); exit(1);
} }
} }
if (programmer) { if (programmer) {
if (strcmp(programmer, "?") == 0) { if (strcmp(programmer, "?") == 0) {
fprintf(stderr, "\n"); avrdude_message("\n");
fprintf(stderr,"Valid programmers are:\n"); avrdude_message("Valid programmers are:\n");
list_programmers(stderr, " ", programmers); list_programmers(stderr, " ", programmers);
fprintf(stderr,"\n"); avrdude_message("\n");
exit(1); exit(1);
} }
if (strcmp(programmer, "?type") == 0) { if (strcmp(programmer, "?type") == 0) {
fprintf(stderr, "\n"); avrdude_message("\n");
fprintf(stderr,"Valid programmer types are:\n"); avrdude_message("Valid programmer types are:\n");
list_programmer_types(stderr, " "); list_programmer_types(stderr, " ");
fprintf(stderr,"\n"); avrdude_message("\n");
exit(1); exit(1);
} }
} }
if (programmer[0] == 0) { if (programmer[0] == 0) {
fprintf(stderr, avrdude_message("\n%s: no programmer has been specified on the command line "
"\n%s: no programmer has been specified on the command line "
"or the config file\n", "or the config file\n",
progname); progname);
fprintf(stderr, avrdude_message("%sSpecify a programmer using the -c option and try again\n\n",
"%sSpecify a programmer using the -c option and try again\n\n",
progbuf); progbuf);
exit(1); exit(1);
} }
pgm = locate_programmer(programmers, programmer); pgm = locate_programmer(programmers, programmer);
if (pgm == NULL) { if (pgm == NULL) {
fprintf(stderr,"\n"); avrdude_message("\n");
fprintf(stderr, avrdude_message("%s: Can't find programmer id \"%s\"\n",
"%s: Can't find programmer id \"%s\"\n",
progname, programmer); progname, programmer);
fprintf(stderr,"\nValid programmers are:\n"); avrdude_message("\nValid programmers are:\n");
list_programmers(stderr, " ", programmers); list_programmers(stderr, " ", programmers);
fprintf(stderr,"\n"); avrdude_message("\n");
exit(1); exit(1);
} }
if (pgm->initpgm) { if (pgm->initpgm) {
pgm->initpgm(pgm); pgm->initpgm(pgm);
} else { } else {
fprintf(stderr, avrdude_message("\n%s: Can't initialize the programmer.\n\n",
"\n%s: Can't initialize the programmer.\n\n",
progname); progname);
exit(1); exit(1);
} }
@ -781,14 +785,12 @@ int main(int argc, char * argv [])
if (lsize(extended_params) > 0) { if (lsize(extended_params) > 0) {
if (pgm->parseextparams == NULL) { if (pgm->parseextparams == NULL) {
fprintf(stderr, avrdude_message("%s: WARNING: Programmer doesn't support extended parameters,"
"%s: WARNING: Programmer doesn't support extended parameters,"
" -x option(s) ignored\n", " -x option(s) ignored\n",
progname); progname);
} else { } else {
if (pgm->parseextparams(pgm, extended_params) < 0) { if (pgm->parseextparams(pgm, extended_params) < 0) {
fprintf(stderr, avrdude_message("%s: Error parsing extended parameter list\n",
"%s: Error parsing extended parameter list\n",
progname); progname);
exit(1); exit(1);
} }
@ -813,32 +815,29 @@ int main(int argc, char * argv [])
} }
if (partdesc == NULL) { if (partdesc == NULL) {
fprintf(stderr, avrdude_message("%s: No AVR part has been specified, use \"-p Part\"\n\n",
"%s: No AVR part has been specified, use \"-p Part\"\n\n",
progname); progname);
fprintf(stderr,"Valid parts are:\n"); avrdude_message("Valid parts are:\n");
list_parts(stderr, " ", part_list); list_parts(stderr, " ", part_list);
fprintf(stderr, "\n"); avrdude_message("\n");
exit(1); exit(1);
} }
p = locate_part(part_list, partdesc); p = locate_part(part_list, partdesc);
if (p == NULL) { if (p == NULL) {
fprintf(stderr, avrdude_message("%s: AVR Part \"%s\" not found.\n\n",
"%s: AVR Part \"%s\" not found.\n\n",
progname, partdesc); progname, partdesc);
fprintf(stderr,"Valid parts are:\n"); avrdude_message("Valid parts are:\n");
list_parts(stderr, " ", part_list); list_parts(stderr, " ", part_list);
fprintf(stderr, "\n"); avrdude_message("\n");
exit(1); exit(1);
} }
if (exitspecs != NULL) { if (exitspecs != NULL) {
if (pgm->parseexitspecs == NULL) { if (pgm->parseexitspecs == NULL) {
fprintf(stderr, avrdude_message("%s: WARNING: -E option not supported by this programmer type\n",
"%s: WARNING: -E option not supported by this programmer type\n",
progname); progname);
exitspecs = NULL; exitspecs = NULL;
} }
@ -873,7 +872,7 @@ int main(int argc, char * argv [])
if (avr_initmem(p) != 0) if (avr_initmem(p) != 0)
{ {
fprintf(stderr, "\n%s: failed to initialize memories\n", avrdude_message("\n%s: failed to initialize memories\n",
progname); progname);
exit(1); exit(1);
} }
@ -889,14 +888,13 @@ int main(int argc, char * argv [])
if (upd->memtype == NULL) { if (upd->memtype == NULL) {
const char *mtype = (p->flags & AVRPART_HAS_PDI)? "application": "flash"; const char *mtype = (p->flags & AVRPART_HAS_PDI)? "application": "flash";
if (verbose >= 2) { if (verbose >= 2) {
fprintf(stderr, avrdude_message("%s: defaulting memtype in -U %c:%s option to \"%s\"\n",
"%s: defaulting memtype in -U %c:%s option to \"%s\"\n",
progname, 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);
} }
if ((upd->memtype = strdup(mtype)) == NULL) { if ((upd->memtype = strdup(mtype)) == NULL) {
fprintf(stderr, "%s: out of memory\n", progname); avrdude_message("%s: out of memory\n", progname);
exit(1); exit(1);
} }
} }
@ -906,41 +904,41 @@ int main(int argc, char * argv [])
* open the programmer * open the programmer
*/ */
if (port[0] == 0) { if (port[0] == 0) {
fprintf(stderr, "\n%s: no port has been specified on the command line " avrdude_message("\n%s: no port has been specified on the command line "
"or the config file\n", "or the config file\n",
progname); progname);
fprintf(stderr, "%sSpecify a port using the -P option and try again\n\n", avrdude_message("%sSpecify a port using the -P option and try again\n\n",
progbuf); progbuf);
exit(1); exit(1);
} }
if (verbose) { if (verbose) {
fprintf(stderr, "%sUsing Port : %s\n", progbuf, port); avrdude_message("%sUsing Port : %s\n", progbuf, port);
fprintf(stderr, "%sUsing Programmer : %s\n", progbuf, programmer); avrdude_message("%sUsing Programmer : %s\n", progbuf, programmer);
if ((strcmp(pgm->type, "avr910") == 0)) { if ((strcmp(pgm->type, "avr910") == 0)) {
fprintf(stderr, "%savr910_devcode (avrdude.conf) : ", progbuf); avrdude_message("%savr910_devcode (avrdude.conf) : ", progbuf);
if(p->avr910_devcode)fprintf(stderr, "0x%x\n", p->avr910_devcode); if(p->avr910_devcode)avrdude_message("0x%x\n", p->avr910_devcode);
else fprintf(stderr, "none\n"); else avrdude_message("none\n");
} }
} }
if (baudrate != 0) { if (baudrate != 0) {
if (verbose) { if (verbose) {
fprintf(stderr, "%sOverriding Baud Rate : %d\n", progbuf, baudrate); avrdude_message("%sOverriding Baud Rate : %d\n", progbuf, baudrate);
} }
pgm->baudrate = baudrate; pgm->baudrate = baudrate;
} }
if (bitclock != 0.0) { if (bitclock != 0.0) {
if (verbose) { if (verbose) {
fprintf(stderr, "%sSetting bit clk period : %.1f\n", progbuf, bitclock); avrdude_message("%sSetting bit clk period : %.1f\n", progbuf, bitclock);
} }
pgm->bitclock = bitclock * 1e-6; pgm->bitclock = bitclock * 1e-6;
} }
if (ispdelay != 0) { if (ispdelay != 0) {
if (verbose) { if (verbose) {
fprintf(stderr, "%sSetting isp clock delay : %3i\n", progbuf, ispdelay); avrdude_message("%sSetting isp clock delay : %3i\n", progbuf, ispdelay);
} }
pgm->ispdelay = ispdelay; pgm->ispdelay = ispdelay;
} }
@ -959,17 +957,15 @@ 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) {
fprintf(stderr, avrdude_message("%s: programmer does not support RC oscillator calibration\n",
"%s: programmer does not support RC oscillator calibration\n",
progname); progname);
exitrc = 1; exitrc = 1;
} else { } else {
fprintf(stderr, "%s: performing RC oscillator calibration\n", progname); avrdude_message("%s: performing RC oscillator calibration\n", progname);
exitrc = pgm->perform_osccal(pgm); exitrc = pgm->perform_osccal(pgm);
} }
if (exitrc == 0 && quell_progress < 2) { if (exitrc == 0 && quell_progress < 2) {
fprintf(stderr, avrdude_message("%s: calibration value is now stored in EEPROM at address 0\n",
"%s: calibration value is now stored in EEPROM at address 0\n",
progname); progname);
} }
goto main_exit; goto main_exit;
@ -977,12 +973,12 @@ int main(int argc, char * argv [])
if (verbose) { if (verbose) {
avr_display(stderr, p, progbuf, verbose); avr_display(stderr, p, progbuf, verbose);
fprintf(stderr, "\n"); avrdude_message("\n");
programmer_display(pgm, progbuf); programmer_display(pgm, progbuf);
} }
if (quell_progress < 2) { if (quell_progress < 2) {
fprintf(stderr, "\n"); avrdude_message("\n");
} }
exitrc = 0; exitrc = 0;
@ -1005,9 +1001,9 @@ 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) {
fprintf(stderr, "%s: initialization failed, rc=%d\n", progname, rc); avrdude_message("%s: initialization failed, rc=%d\n", progname, rc);
if (!ovsigck) { if (!ovsigck) {
fprintf(stderr, "%sDouble check connections and try again, " avrdude_message("%sDouble check connections and try again, "
"or use -F to override\n" "or use -F to override\n"
"%sthis check.\n\n", "%sthis check.\n\n",
progbuf, progbuf); progbuf, progbuf);
@ -1020,8 +1016,7 @@ int main(int argc, char * argv [])
pgm->rdy_led(pgm, ON); pgm->rdy_led(pgm, ON);
if (quell_progress < 2) { if (quell_progress < 2) {
fprintf(stderr, avrdude_message("%s: AVR device initialized and ready to accept instructions\n",
"%s: AVR device initialized and ready to accept instructions\n",
progname); progname);
} }
@ -1040,7 +1035,7 @@ int main(int argc, char * argv [])
if (init_ok) { if (init_ok) {
rc = avr_signature(pgm, p); rc = avr_signature(pgm, p);
if (rc != 0) { if (rc != 0) {
fprintf(stderr, "%s: error reading signature data, rc=%d\n", avrdude_message("%s: error reading signature data, rc=%d\n",
progname, rc); progname, rc);
exitrc = 1; exitrc = 1;
goto main_exit; goto main_exit;
@ -1049,8 +1044,7 @@ int main(int argc, char * argv [])
sig = avr_locate_mem(p, "signature"); sig = avr_locate_mem(p, "signature");
if (sig == NULL) { if (sig == NULL) {
fprintf(stderr, avrdude_message("%s: WARNING: signature data not defined for device \"%s\"\n",
"%s: WARNING: signature data not defined for device \"%s\"\n",
progname, p->desc); progname, p->desc);
} }
@ -1058,12 +1052,12 @@ int main(int argc, char * argv [])
int ff, zz; int ff, zz;
if (quell_progress < 2) { if (quell_progress < 2) {
fprintf(stderr, "%s: Device signature = 0x", progname); avrdude_message("%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) { if (quell_progress < 2) {
fprintf(stderr, "%02x", sig->buf[i]); avrdude_message("%02x", sig->buf[i]);
} }
if (sig->buf[i] != 0xff) if (sig->buf[i] != 0xff)
ff = 0; ff = 0;
@ -1074,17 +1068,16 @@ int main(int argc, char * argv [])
if (++attempt < 3) { if (++attempt < 3) {
waittime *= 5; waittime *= 5;
if (quell_progress < 2) { if (quell_progress < 2) {
fprintf(stderr, " (retrying)\n"); avrdude_message(" (retrying)\n");
} }
goto sig_again; goto sig_again;
} }
if (quell_progress < 2) { if (quell_progress < 2) {
fprintf(stderr, "\n"); avrdude_message("\n");
} }
fprintf(stderr, avrdude_message("%s: Yikes! Invalid device signature.\n", progname);
"%s: Yikes! Invalid device signature.\n", progname);
if (!ovsigck) { if (!ovsigck) {
fprintf(stderr, "%sDouble check connections and try again, " avrdude_message("%sDouble check connections and try again, "
"or use -F to override\n" "or use -F to override\n"
"%sthis check.\n\n", "%sthis check.\n\n",
progbuf, progbuf); progbuf, progbuf);
@ -1093,7 +1086,7 @@ int main(int argc, char * argv [])
} }
} else { } else {
if (quell_progress < 2) { if (quell_progress < 2) {
fprintf(stderr, "\n"); avrdude_message("\n");
} }
} }
@ -1101,12 +1094,11 @@ int main(int argc, char * argv [])
sig->buf[0] != p->signature[0] || sig->buf[0] != p->signature[0] ||
sig->buf[1] != p->signature[1] || sig->buf[1] != p->signature[1] ||
sig->buf[2] != p->signature[2]) { sig->buf[2] != p->signature[2]) {
fprintf(stderr, avrdude_message("%s: Expected signature for %s is %02X %02X %02X\n",
"%s: Expected signature for %s is %02X %02X %02X\n",
progname, p->desc, progname, p->desc,
p->signature[0], p->signature[1], p->signature[2]); p->signature[0], p->signature[1], p->signature[2]);
if (!ovsigck) { if (!ovsigck) {
fprintf(stderr, "%sDouble check chip, " avrdude_message("%sDouble check chip, "
"or use -F to override this check.\n", "or use -F to override this check.\n",
progbuf); progbuf);
exitrc = 1; exitrc = 1;
@ -1130,7 +1122,7 @@ int main(int argc, char * argv [])
{ {
if (verbose > 0) if (verbose > 0)
{ {
fprintf(stderr, "%s: safemode: Fuse reading not support by programmer.\n" avrdude_message("%s: safemode: Fuse reading not support by programmer.\n"
" Safemode disabled.\n", progname); " Safemode disabled.\n", progname);
} }
safemode = 0; safemode = 0;
@ -1138,7 +1130,7 @@ int main(int argc, char * argv [])
else else
{ {
fprintf(stderr, "%s: safemode: To protect your AVR the programming " avrdude_message("%s: safemode: To protect your AVR the programming "
"will be aborted\n", "will be aborted\n",
progname); progname);
exitrc = 1; exitrc = 1;
@ -1154,8 +1146,7 @@ int main(int argc, char * argv [])
if ((p->flags & AVRPART_HAS_PDI) && pgm->page_erase != NULL && if ((p->flags & AVRPART_HAS_PDI) && pgm->page_erase != NULL &&
lsize(updates) > 0) { lsize(updates) > 0) {
if (quell_progress < 2) { if (quell_progress < 2) {
fprintf(stderr, avrdude_message("%s: NOTE: Programmer supports page erase for Xmega devices.\n"
"%s: NOTE: Programmer supports page erase for Xmega devices.\n"
"%sEach page will be erased before programming it, but no chip erase is performed.\n" "%sEach page will be erased before programming it, but no chip erase is performed.\n"
"%sTo disable page erases, specify the -D option; for a chip-erase, use the -e option.\n", "%sTo disable page erases, specify the -D option; for a chip-erase, use the -e option.\n",
progname, progbuf, progbuf); progname, progbuf, progbuf);
@ -1173,8 +1164,7 @@ int main(int argc, char * argv [])
if ((strcasecmp(m->desc, memname) == 0) && (upd->op == DEVICE_WRITE)) { if ((strcasecmp(m->desc, memname) == 0) && (upd->op == DEVICE_WRITE)) {
erase = 1; erase = 1;
if (quell_progress < 2) { if (quell_progress < 2) {
fprintf(stderr, avrdude_message("%s: NOTE: \"%s\" memory has been specified, an erase cycle "
"%s: NOTE: \"%s\" memory has been specified, an erase cycle "
"will be performed\n" "will be performed\n"
"%sTo disable this feature, specify the -D option.\n", "%sTo disable this feature, specify the -D option.\n",
progname, memname, progbuf); progname, memname, progbuf);
@ -1191,12 +1181,11 @@ 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) {
fprintf(stderr, avrdude_message("%s: conflicting -e and -n options specified, NOT erasing chip\n",
"%s: conflicting -e and -n options specified, NOT erasing chip\n",
progname); progname);
} else { } else {
if (quell_progress < 2) { if (quell_progress < 2) {
fprintf(stderr, "%s: erasing chip\n", progname); avrdude_message("%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;
@ -1241,7 +1230,7 @@ int main(int argc, char * argv [])
char yes[1] = {'y'}; char yes[1] = {'y'};
if (quell_progress < 2) { if (quell_progress < 2) {
fprintf(stderr, "\n"); avrdude_message("\n");
} }
//Restore the default fuse values //Restore the default fuse values
@ -1253,8 +1242,7 @@ int main(int argc, char * argv [])
/* Uh-oh.. try once more to read back fuses */ /* Uh-oh.. try once more to read back fuses */
if (safemode_readfuses(&safemodeafter_lfuse, &safemodeafter_hfuse, if (safemode_readfuses(&safemodeafter_lfuse, &safemodeafter_hfuse,
&safemodeafter_efuse, &safemodeafter_fuse, pgm, p, verbose) != 0) { &safemodeafter_efuse, &safemodeafter_fuse, pgm, p, verbose) != 0) {
fprintf(stderr, avrdude_message("%s: safemode: Sorry, reading back fuses was unreliable. "
"%s: safemode: Sorry, reading back fuses was unreliable. "
"I have given up and exited programming mode\n", "I have given up and exited programming mode\n",
progname); progname);
exitrc = 1; exitrc = 1;
@ -1265,7 +1253,7 @@ int main(int argc, char * argv [])
/* Now check what fuses are against what they should be */ /* Now check what fuses are against what they should be */
if (safemodeafter_fuse != safemode_fuse) { if (safemodeafter_fuse != safemode_fuse) {
fuses_updated = 1; fuses_updated = 1;
fprintf(stderr, "%s: safemode: fuse changed! Was %x, and is now %x\n", avrdude_message("%s: safemode: fuse changed! Was %x, and is now %x\n",
progname, safemode_fuse, safemodeafter_fuse); progname, safemode_fuse, safemodeafter_fuse);
@ -1281,10 +1269,10 @@ int main(int argc, char * argv [])
/* Enough chit-chat, time to program some fuses and check them */ /* Enough chit-chat, time to program some fuses and check them */
if (safemode_writefuse (safemode_fuse, "fuse", pgm, p, if (safemode_writefuse (safemode_fuse, "fuse", pgm, p,
10, verbose) == 0) { 10, verbose) == 0) {
fprintf(stderr, "%s: safemode: and is now rescued\n", progname); avrdude_message("%s: safemode: and is now rescued\n", progname);
} }
else { else {
fprintf(stderr, "%s: and COULD NOT be changed\n", progname); avrdude_message("%s: and COULD NOT be changed\n", progname);
failures++; failures++;
} }
} }
@ -1293,7 +1281,7 @@ int main(int argc, char * argv [])
/* Now check what fuses are against what they should be */ /* Now check what fuses are against what they should be */
if (safemodeafter_lfuse != safemode_lfuse) { if (safemodeafter_lfuse != safemode_lfuse) {
fuses_updated = 1; fuses_updated = 1;
fprintf(stderr, "%s: safemode: lfuse changed! Was %x, and is now %x\n", avrdude_message("%s: safemode: lfuse changed! Was %x, and is now %x\n",
progname, safemode_lfuse, safemodeafter_lfuse); progname, safemode_lfuse, safemodeafter_lfuse);
@ -1309,10 +1297,10 @@ int main(int argc, char * argv [])
/* Enough chit-chat, time to program some fuses and check them */ /* Enough chit-chat, time to program some fuses and check them */
if (safemode_writefuse (safemode_lfuse, "lfuse", pgm, p, if (safemode_writefuse (safemode_lfuse, "lfuse", pgm, p,
10, verbose) == 0) { 10, verbose) == 0) {
fprintf(stderr, "%s: safemode: and is now rescued\n", progname); avrdude_message("%s: safemode: and is now rescued\n", progname);
} }
else { else {
fprintf(stderr, "%s: and COULD NOT be changed\n", progname); avrdude_message("%s: and COULD NOT be changed\n", progname);
failures++; failures++;
} }
} }
@ -1321,7 +1309,7 @@ int main(int argc, char * argv [])
/* Now check what fuses are against what they should be */ /* Now check what fuses are against what they should be */
if (safemodeafter_hfuse != safemode_hfuse) { if (safemodeafter_hfuse != safemode_hfuse) {
fuses_updated = 1; fuses_updated = 1;
fprintf(stderr, "%s: safemode: hfuse changed! Was %x, and is now %x\n", avrdude_message("%s: safemode: hfuse changed! Was %x, and is now %x\n",
progname, safemode_hfuse, safemodeafter_hfuse); progname, safemode_hfuse, safemodeafter_hfuse);
/* Ask user - should we change them */ /* Ask user - should we change them */
@ -1334,10 +1322,10 @@ int main(int argc, char * argv [])
/* Enough chit-chat, time to program some fuses and check them */ /* Enough chit-chat, time to program some fuses and check them */
if (safemode_writefuse(safemode_hfuse, "hfuse", pgm, p, if (safemode_writefuse(safemode_hfuse, "hfuse", pgm, p,
10, verbose) == 0) { 10, verbose) == 0) {
fprintf(stderr, "%s: safemode: and is now rescued\n", progname); avrdude_message("%s: safemode: and is now rescued\n", progname);
} }
else { else {
fprintf(stderr, "%s: and COULD NOT be changed\n", progname); avrdude_message("%s: and COULD NOT be changed\n", progname);
failures++; failures++;
} }
} }
@ -1346,7 +1334,7 @@ int main(int argc, char * argv [])
/* Now check what fuses are against what they should be */ /* Now check what fuses are against what they should be */
if (safemodeafter_efuse != safemode_efuse) { if (safemodeafter_efuse != safemode_efuse) {
fuses_updated = 1; fuses_updated = 1;
fprintf(stderr, "%s: safemode: efuse changed! Was %x, and is now %x\n", avrdude_message("%s: safemode: efuse changed! Was %x, and is now %x\n",
progname, safemode_efuse, safemodeafter_efuse); progname, safemode_efuse, safemodeafter_efuse);
/* Ask user - should we change them */ /* Ask user - should we change them */
@ -1359,23 +1347,23 @@ int main(int argc, char * argv [])
/* Enough chit-chat, time to program some fuses and check them */ /* Enough chit-chat, time to program some fuses and check them */
if (safemode_writefuse (safemode_efuse, "efuse", pgm, p, if (safemode_writefuse (safemode_efuse, "efuse", pgm, p,
10, verbose) == 0) { 10, verbose) == 0) {
fprintf(stderr, "%s: safemode: and is now rescued\n", progname); avrdude_message("%s: safemode: and is now rescued\n", progname);
} }
else { else {
fprintf(stderr, "%s: and COULD NOT be changed\n", progname); avrdude_message("%s: and COULD NOT be changed\n", progname);
failures++; failures++;
} }
} }
} }
if (quell_progress < 2) { if (quell_progress < 2) {
fprintf(stderr, "%s: safemode: ", progname); avrdude_message("%s: safemode: ", progname);
if (failures == 0) { if (failures == 0) {
fprintf(stderr, "Fuses OK (E:%02X, H:%02X, L:%02X)\n", avrdude_message("Fuses OK (E:%02X, H:%02X, L:%02X)\n",
safemode_efuse, safemode_hfuse, safemode_lfuse); safemode_efuse, safemode_hfuse, safemode_lfuse);
} }
else { else {
fprintf(stderr, "Fuses not recovered, sorry\n"); avrdude_message("Fuses not recovered, sorry\n");
} }
} }
@ -1403,7 +1391,7 @@ main_exit:
} }
if (quell_progress < 2) { if (quell_progress < 2) {
fprintf(stderr, "\n%s done. Thank you.\n\n", progname); avrdude_message("\n%s done. Thank you.\n\n", progname);
} }
return exitrc; return exitrc;

9
par.c
View File

@ -242,7 +242,7 @@ static int par_open(PROGRAMMER * pgm, char * port)
ppi_open(port, &pgm->fd); ppi_open(port, &pgm->fd);
if (pgm->fd.ifd < 0) { if (pgm->fd.ifd < 0) {
fprintf(stderr, "%s: failed to open parallel port \"%s\"\n\n", avrdude_message("%s: failed to open parallel port \"%s\"\n\n",
progname, port); progname, port);
return -1; return -1;
} }
@ -252,14 +252,14 @@ static int par_open(PROGRAMMER * pgm, char * port)
*/ */
rc = ppi_getall(&pgm->fd, PPIDATA); rc = ppi_getall(&pgm->fd, PPIDATA);
if (rc < 0) { if (rc < 0) {
fprintf(stderr, "%s: error reading status of ppi data port\n", progname); avrdude_message("%s: error reading status of ppi data port\n", progname);
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) {
fprintf(stderr, "%s: error reading status of ppi ctrl port\n", progname); avrdude_message("%s: error reading status of ppi ctrl port\n", progname);
return -1; return -1;
} }
pgm->ppictrl = rc; pgm->ppictrl = rc;
@ -403,8 +403,7 @@ void par_initpgm(PROGRAMMER * pgm)
void par_initpgm(PROGRAMMER * pgm) void par_initpgm(PROGRAMMER * pgm)
{ {
fprintf(stderr, avrdude_message("%s: parallel port access not available in this configuration\n",
"%s: parallel port access not available in this configuration\n",
progname); progname);
} }

34
pgm.c
View File

@ -39,7 +39,7 @@ static void pgm_default_6 (struct programmer_t *, const char *);
static int pgm_default_open (struct programmer_t *pgm, char * name) static int pgm_default_open (struct programmer_t *pgm, char * name)
{ {
fprintf (stderr, "\n%s: Fatal error: Programmer does not support open()", avrdude_message("\n%s: Fatal error: Programmer does not support open()",
progname); progname);
return -1; return -1;
} }
@ -68,7 +68,7 @@ PROGRAMMER * pgm_new(void)
pgm = (PROGRAMMER *)malloc(sizeof(*pgm)); pgm = (PROGRAMMER *)malloc(sizeof(*pgm));
if (pgm == NULL) { if (pgm == NULL) {
fprintf(stderr, "%s: out of memory allocating programmer structure\n", avrdude_message("%s: out of memory allocating programmer structure\n",
progname); progname);
exit(1); exit(1);
} }
@ -159,7 +159,7 @@ PROGRAMMER * pgm_dup(const PROGRAMMER * const src)
pgm = (PROGRAMMER *)malloc(sizeof(*pgm)); pgm = (PROGRAMMER *)malloc(sizeof(*pgm));
if (pgm == NULL) { if (pgm == NULL) {
fprintf(stderr, "%s: out of memory allocating programmer structure\n", avrdude_message("%s: out of memory allocating programmer structure\n",
progname); progname);
exit(1); exit(1);
} }
@ -172,7 +172,7 @@ PROGRAMMER * pgm_dup(const PROGRAMMER * const src)
for (ln = lfirst(src->usbpid); ln; ln = lnext(ln)) { for (ln = lfirst(src->usbpid); ln; ln = lnext(ln)) {
int *ip = malloc(sizeof(int)); int *ip = malloc(sizeof(int));
if (ip == NULL) { if (ip == NULL) {
fprintf(stderr, "%s: out of memory allocating programmer structure\n", avrdude_message("%s: out of memory allocating programmer structure\n",
progname); progname);
exit(1); exit(1);
} }
@ -186,7 +186,7 @@ PROGRAMMER * pgm_dup(const PROGRAMMER * const src)
static void pgm_default(void) static void pgm_default(void)
{ {
fprintf(stderr, "%s: programmer operation not supported\n", progname); avrdude_message("%s: programmer operation not supported\n", progname);
} }
@ -223,8 +223,8 @@ static void pgm_default_6 (struct programmer_t * pgm, const char * p)
void programmer_display(PROGRAMMER * pgm, const char * p) void programmer_display(PROGRAMMER * pgm, const char * p)
{ {
fprintf(stderr, "%sProgrammer Type : %s\n", p, pgm->type); avrdude_message("%sProgrammer Type : %s\n", p, pgm->type);
fprintf(stderr, "%sDescription : %s\n", p, pgm->desc); avrdude_message("%sDescription : %s\n", p, pgm->desc);
pgm->display(pgm, p); pgm->display(pgm, p);
} }
@ -233,25 +233,25 @@ void programmer_display(PROGRAMMER * pgm, const char * p)
void pgm_display_generic_mask(PROGRAMMER * pgm, const char * p, unsigned int show) void pgm_display_generic_mask(PROGRAMMER * pgm, const char * p, unsigned int show)
{ {
if(show & (1<<PPI_AVR_VCC)) if(show & (1<<PPI_AVR_VCC))
fprintf(stderr, "%s VCC = %s\n", p, pins_to_str(&pgm->pin[PPI_AVR_VCC])); avrdude_message("%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))
fprintf(stderr, "%s BUFF = %s\n", p, pins_to_str(&pgm->pin[PPI_AVR_BUFF])); avrdude_message("%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))
fprintf(stderr, "%s RESET = %s\n", p, pins_to_str(&pgm->pin[PIN_AVR_RESET])); avrdude_message("%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))
fprintf(stderr, "%s SCK = %s\n", p, pins_to_str(&pgm->pin[PIN_AVR_SCK])); avrdude_message("%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))
fprintf(stderr, "%s MOSI = %s\n", p, pins_to_str(&pgm->pin[PIN_AVR_MOSI])); avrdude_message("%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))
fprintf(stderr, "%s MISO = %s\n", p, pins_to_str(&pgm->pin[PIN_AVR_MISO])); avrdude_message("%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))
fprintf(stderr, "%s ERR LED = %s\n", p, pins_to_str(&pgm->pin[PIN_LED_ERR])); avrdude_message("%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))
fprintf(stderr, "%s RDY LED = %s\n", p, pins_to_str(&pgm->pin[PIN_LED_RDY])); avrdude_message("%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))
fprintf(stderr, "%s PGM LED = %s\n", p, pins_to_str(&pgm->pin[PIN_LED_PGM])); avrdude_message("%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))
fprintf(stderr, "%s VFY LED = %s\n", p, pins_to_str(&pgm->pin[PIN_LED_VFY])); avrdude_message("%s VFY LED = %s\n", p, pins_to_str(&pgm->pin[PIN_LED_VFY]));
} }
void pgm_display_generic(PROGRAMMER * pgm, const char * p) void pgm_display_generic(PROGRAMMER * pgm, const char * p)

View File

@ -76,13 +76,13 @@
#endif #endif
#if 0 #if 0
#define DEBUG(...) do { fprintf(stderr, __VA_ARGS__); } while(0) #define DEBUG(...) do { avrdude_message(__VA_ARGS__); } while(0)
#else #else
#define DEBUG(...) ((void)0) #define DEBUG(...) ((void)0)
#endif #endif
#if 0 #if 0
#define DEBUGRECV(...) do { fprintf(stderr, __VA_ARGS__); } while(0) #define DEBUGRECV(...) do { avrdude_message(__VA_ARGS__); } while(0)
#else #else
#define DEBUGRECV(...) ((void)0) #define DEBUGRECV(...) ((void)0)
#endif #endif
@ -169,8 +169,7 @@ static void pickit2_setup(PROGRAMMER * pgm)
{ {
if ((pgm->cookie = malloc(sizeof(struct pdata))) == 0) if ((pgm->cookie = malloc(sizeof(struct pdata))) == 0)
{ {
fprintf(stderr, avrdude_message("%s: pickit2_setup(): Out of memory allocating private data\n",
"%s: pickit2_setup(): Out of memory allocating private data\n",
progname); progname);
exit(1); exit(1);
} }
@ -193,8 +192,7 @@ static int pickit2_open(PROGRAMMER * pgm, char * port)
if (PDATA(pgm)->usb_handle == INVALID_HANDLE_VALUE) if (PDATA(pgm)->usb_handle == INVALID_HANDLE_VALUE)
{ {
/* no PICkit2 found */ /* no PICkit2 found */
fprintf(stderr, avrdude_message("%s: error: could not find PICkit2 with vid=0x%x pid=0x%x\n",
"%s: error: could not find PICkit2 with vid=0x%x pid=0x%x\n",
progname, PICKIT2_VID, PICKIT2_PID); progname, PICKIT2_VID, PICKIT2_PID);
return -1; return -1;
} }
@ -215,8 +213,7 @@ static int pickit2_open(PROGRAMMER * pgm, 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 */
fprintf(stderr, avrdude_message("%s: error: could not find PICkit2 with vid=0x%x pid=0x%x\n",
"%s: error: could not find PICkit2 with vid=0x%x pid=0x%x\n",
progname, PICKIT2_VID, PICKIT2_PID); progname, PICKIT2_VID, PICKIT2_PID);
return -1; return -1;
} }
@ -267,7 +264,7 @@ static int pickit2_initialize(PROGRAMMER * pgm, AVRPART * p)
{ {
if (verbose) if (verbose)
{ {
fprintf(stderr, "%s: %s firmware version %d.%d.%d\n", progname, pgm->desc, (int)report[1], (int)report[2], (int)report[3]); avrdude_message("%s: %s firmware version %d.%d.%d\n", progname, pgm->desc, (int)report[1], (int)report[2], (int)report[3]);
} }
// set the pins, apply reset, // set the pins, apply reset,
@ -303,19 +300,19 @@ static int pickit2_initialize(PROGRAMMER * pgm, AVRPART * p)
if (pickit2_write_report(pgm, report) < 0) if (pickit2_write_report(pgm, report) < 0)
{ {
fprintf(stderr, "pickit2_read_report failed (ec %d). %s\n", errorCode, usb_strerror()); avrdude_message("pickit2_read_report failed (ec %d). %s\n", errorCode, usb_strerror());
return -1; return -1;
} }
} }
else else
{ {
fprintf(stderr, "pickit2_read_report failed (ec %d). %s\n", errorCode, usb_strerror()); avrdude_message("pickit2_read_report failed (ec %d). %s\n", errorCode, usb_strerror());
return -1; return -1;
} }
} }
else else
{ {
fprintf(stderr, "pickit2_write_report failed (ec %d). %s\n", errorCode, usb_strerror()); avrdude_message("pickit2_write_report failed (ec %d). %s\n", errorCode, usb_strerror());
return -1; return -1;
} }
@ -428,7 +425,7 @@ static int pickit2_program_enable(struct programmer_t * pgm, AVRPART * p)
if (p->op[AVR_OP_PGM_ENABLE] == NULL) if (p->op[AVR_OP_PGM_ENABLE] == NULL)
{ {
fprintf(stderr, "program enable instruction not defined for part \"%s\"\n", avrdude_message("program enable instruction not defined for part \"%s\"\n",
p->desc); p->desc);
return -1; return -1;
} }
@ -440,13 +437,13 @@ static int pickit2_program_enable(struct programmer_t * pgm, AVRPART * p)
if (verbose) if (verbose)
{ {
int i; int i;
fprintf(stderr, "program_enable(): sending command. Resp = "); avrdude_message("program_enable(): sending command. Resp = ");
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
{ {
fprintf(stderr, "%x ", (int)res[i]); avrdude_message("%x ", (int)res[i]);
} }
fprintf(stderr, "\n"); avrdude_message("\n");
} }
// check for sync character // check for sync character
@ -463,7 +460,7 @@ static int pickit2_chip_erase(struct programmer_t * pgm, AVRPART * p)
if (p->op[AVR_OP_CHIP_ERASE] == NULL) if (p->op[AVR_OP_CHIP_ERASE] == NULL)
{ {
fprintf(stderr, "chip erase instruction not defined for part \"%s\"\n", avrdude_message("chip erase instruction not defined for part \"%s\"\n",
p->desc); p->desc);
return -1; return -1;
} }
@ -540,7 +537,7 @@ static int pickit2_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
} }
else else
{ {
fprintf(stderr, "no read command specified\n"); avrdude_message("no read command specified\n");
return -1; return -1;
} }
@ -552,7 +549,7 @@ static int pickit2_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
if (bytes_read < 0) if (bytes_read < 0)
{ {
fprintf(stderr, "Failed @ pgm->spi()\n"); avrdude_message("Failed @ pgm->spi()\n");
pgm->err_led(pgm, ON); pgm->err_led(pgm, ON);
return -1; return -1;
} }
@ -586,8 +583,7 @@ static int pickit2_commit_page(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
wp = mem->op[AVR_OP_WRITEPAGE]; wp = mem->op[AVR_OP_WRITEPAGE];
if (wp == NULL) if (wp == NULL)
{ {
fprintf(stderr, avrdude_message("pickit2_commit_page(): memory \"%s\" not configured for page writes\n",
"pickit2_commit_page(): memory \"%s\" not configured for page writes\n",
mem->desc); mem->desc);
return -1; return -1;
} }
@ -635,7 +631,7 @@ static int pickit2_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
// 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)
{ {
fprintf(stderr, "Part does not support %d paged write of %s\n", page_size, mem->desc); avrdude_message("Part does not support %d paged write of %s\n", page_size, mem->desc);
return -1; return -1;
} }
@ -692,7 +688,7 @@ static int pickit2_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
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
fprintf(stderr, "Error AVR_OP_WRITE_LO defined only (where's the HIGH command?)\n"); avrdude_message("Error AVR_OP_WRITE_LO defined only (where's the HIGH command?)\n");
return -1; return -1;
} }
else else
@ -717,7 +713,7 @@ static int pickit2_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
if (bytes_read < 0) if (bytes_read < 0)
{ {
fprintf(stderr, "Failed @ pgm->spi()\n"); avrdude_message("Failed @ pgm->spi()\n");
pgm->err_led(pgm, ON); pgm->err_led(pgm, ON);
return -1; return -1;
} }
@ -1159,7 +1155,7 @@ 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;
fprintf(stderr, "%s: Warning: cannot open USB device: %s\n", progname, usb_strerror()); avrdude_message("%s: Warning: cannot open USB device: %s\n", progname, usb_strerror());
continue; continue;
} }
@ -1168,18 +1164,18 @@ static int usb_open_device(struct usb_dev_handle **device, int vendor, int produ
{ {
if (verbose) if (verbose)
{ {
fprintf(stderr, "Device %p seemed to open OK.\n", handle); avrdude_message("Device %p seemed to open OK.\n", handle);
} }
if ((errorCode = usb_set_configuration(handle, 1)) < 0) if ((errorCode = usb_set_configuration(handle, 1)) < 0)
{ {
fprintf(stderr, "Could not set configuration. Error code %d, %s.\n" avrdude_message("Could not 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)
{ {
fprintf(stderr, "Could not claim interface. Error code %d, %s\n" avrdude_message("Could not 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());
} }
@ -1222,8 +1218,7 @@ static int pickit2_parseextparams(struct programmer_t * pgm, 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)
{ {
fprintf(stderr, avrdude_message("%s: pickit2_parseextparms(): invalid clockrate '%s'\n",
"%s: pickit2_parseextparms(): invalid clockrate '%s'\n",
progname, extended_param); progname, extended_param);
rv = -1; rv = -1;
continue; continue;
@ -1234,8 +1229,7 @@ static int pickit2_parseextparams(struct programmer_t * pgm, LISTID extparms)
if (verbose >= 2) if (verbose >= 2)
{ {
fprintf(stderr, avrdude_message("%s: pickit2_parseextparms(): clockrate set to 0x%02x\n",
"%s: pickit2_parseextparms(): clockrate set to 0x%02x\n",
progname, clock_rate); progname, clock_rate);
} }
PDATA(pgm)->clock_period = clock_period; PDATA(pgm)->clock_period = clock_period;
@ -1248,8 +1242,7 @@ static int pickit2_parseextparams(struct programmer_t * pgm, 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)
{ {
fprintf(stderr, avrdude_message("%s: pickit2_parseextparms(): invalid timeout '%s'\n",
"%s: pickit2_parseextparms(): invalid timeout '%s'\n",
progname, extended_param); progname, extended_param);
rv = -1; rv = -1;
continue; continue;
@ -1257,8 +1250,7 @@ static int pickit2_parseextparams(struct programmer_t * pgm, LISTID extparms)
if (verbose >= 2) if (verbose >= 2)
{ {
fprintf(stderr, avrdude_message("%s: pickit2_parseextparms(): usb timeout set to 0x%02x\n",
"%s: pickit2_parseextparms(): usb timeout set to 0x%02x\n",
progname, timeout); progname, timeout);
} }
PDATA(pgm)->transaction_timeout = timeout; PDATA(pgm)->transaction_timeout = timeout;
@ -1266,8 +1258,7 @@ static int pickit2_parseextparams(struct programmer_t * pgm, LISTID extparms)
continue; continue;
} }
fprintf(stderr, avrdude_message("%s: pickit2_parseextparms(): invalid extended parameter '%s'\n",
"%s: pickit2_parseextparms(): invalid extended parameter '%s'\n",
progname, extended_param); progname, extended_param);
rv = -1; rv = -1;
} }
@ -1333,7 +1324,7 @@ void pickit2_initpgm (PROGRAMMER * pgm)
} }
#else #else
static int pickit2_nousb_open (struct programmer_t *pgm, char * name) { static int pickit2_nousb_open (struct programmer_t *pgm, char * name) {
fprintf(stderr, avrdude_message(
#ifdef WIN32NATIVE #ifdef WIN32NATIVE
"%s: error: no usb or hid support. Please compile again with libusb or HID support from Win32 DDK installed.\n", "%s: error: no usb or hid support. Please compile again with libusb or HID support from Win32 DDK installed.\n",
#else #else

View File

@ -63,7 +63,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) {
fprintf(stderr, "Multiple pins found\n"); //TODO avrdude_message("Multiple pins found\n"); //TODO
return -1; return -1;
} }
found = true; found = true;
@ -88,7 +88,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) {
fprintf(stderr, "Pins of higher index than max field size for old pinno found\n"); avrdude_message("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) {
@ -100,11 +100,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 {
fprintf(stderr, "pins have different polarity set\n"); avrdude_message("pins have different polarity set\n");
return -1; return -1;
} }
} else if(pindef->mask[i] != 0) { } else if(pindef->mask[i] != 0) {
fprintf(stderr, "Pins have higher number than fit in old format\n"); avrdude_message("Pins have higher number than fit in old format\n");
return -1; return -1;
} }
} }
@ -270,12 +270,10 @@ int pins_check(const struct programmer_t * const pgm, const struct pin_checklist
} }
if(invalid) { if(invalid) {
if(output) { if(output) {
fprintf(stderr, avrdude_message("%s: %s: Following pins are not valid pins for this function: %s\n",
"%s: %s: Following pins are not valid pins for this function: %s\n",
progname, avr_pin_name(pinname), pinmask_to_str(invalid_used)); progname, avr_pin_name(pinname), pinmask_to_str(invalid_used));
if(verbose >= 2) { if(verbose >= 2) {
fprintf(stderr, avrdude_message("%s: %s: Valid pins for this function are: %s\n",
"%s: %s: Valid pins for this function are: %s\n",
progname, avr_pin_name(pinname), pinmask_to_str(valid_pins->mask)); progname, avr_pin_name(pinname), pinmask_to_str(valid_pins->mask));
} }
} }
@ -283,12 +281,10 @@ int pins_check(const struct programmer_t * const pgm, const struct pin_checklist
} }
if(inverse) { if(inverse) {
if(output) { if(output) {
fprintf(stderr, avrdude_message("%s: %s: Following pins are not usable as inverse pins for this function: %s\n",
"%s: %s: Following pins are not usable as inverse pins for this function: %s\n",
progname, avr_pin_name(pinname), pinmask_to_str(inverse_used)); progname, avr_pin_name(pinname), pinmask_to_str(inverse_used));
if(verbose >= 2) { if(verbose >= 2) {
fprintf(stderr, avrdude_message("%s: %s: Valid inverse pins for this function are: %s\n",
"%s: %s: Valid inverse pins for this function are: %s\n",
progname, avr_pin_name(pinname), pinmask_to_str(valid_pins->inverse)); progname, avr_pin_name(pinname), pinmask_to_str(valid_pins->inverse));
} }
} }
@ -296,16 +292,14 @@ int pins_check(const struct programmer_t * const pgm, const struct pin_checklist
} }
if(used) { if(used) {
if(output) { if(output) {
fprintf(stderr, avrdude_message("%s: %s: Following pins are set for other functions too: %s\n",
"%s: %s: Following pins are set for other functions too: %s\n",
progname, avr_pin_name(pinname), pinmask_to_str(already_used)); progname, 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) {
fprintf(stderr, avrdude_message("%s: %s: Mandatory pin is not defined.\n",
"%s: %s: Mandatory pin is not defined.\n",
progname, avr_pin_name(pinname)); progname, avr_pin_name(pinname));
} }
is_ok = false; is_ok = false;
@ -313,8 +307,7 @@ int pins_check(const struct programmer_t * const pgm, const struct pin_checklist
if(!is_ok) { if(!is_ok) {
rv = -1; rv = -1;
} else if(output && verbose >= 3) { } else if(output && verbose >= 3) {
fprintf(stderr, avrdude_message("%s: %s: Pin is ok.\n",
"%s: %s: Pin is ok.\n",
progname, avr_pin_name(pinname)); progname, avr_pin_name(pinname));
} }
} }

4
ppi.c
View File

@ -69,7 +69,7 @@ static int ppi_shadow_access(union filedescriptor *fdp, int reg,
shadow_num = 2; shadow_num = 2;
break; break;
default: default:
fprintf(stderr, "%s: avr_set(): invalid register=%d\n", avrdude_message("%s: avr_set(): invalid register=%d\n",
progname, reg); progname, reg);
return -1; return -1;
break; break;
@ -206,7 +206,7 @@ void ppi_open(char * port, union filedescriptor *fdp)
fd = open(port, O_RDWR); fd = open(port, O_RDWR);
if (fd < 0) { if (fd < 0) {
fprintf(stderr, "%s: can't open device \"%s\": %s\n", avrdude_message("%s: can't open device \"%s\": %s\n",
progname, port, strerror(errno)); progname, port, strerror(errno));
fdp->ifd = -1; fdp->ifd = -1;
return; return;

View File

@ -91,7 +91,7 @@ void ppi_open(char *port, union filedescriptor *fdp)
if(fd < 0) if(fd < 0)
{ {
fprintf(stderr, "%s: can't open device \"giveio\"\n\n", progname); avrdude_message("%s: can't open device \"giveio\"\n\n", progname);
fdp->ifd = -1; fdp->ifd = -1;
return; return;
} }
@ -119,15 +119,14 @@ void ppi_open(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')
{ {
fprintf(stderr, avrdude_message("%s: port name \"%s\" is neither lpt1/2/3 nor valid number\n",
"%s: port name \"%s\" is neither lpt1/2/3 nor valid number\n",
progname, port); progname, port);
fd = -1; fd = -1;
} }
} }
if(fd < 0) if(fd < 0)
{ {
fprintf(stderr, "%s: can't open device \"%s\"\n\n", progname, port); avrdude_message("%s: can't open device \"%s\"\n\n", progname, port);
fdp->ifd = -1; fdp->ifd = -1;
return; return;
} }
@ -361,7 +360,7 @@ int gettimeofday(struct timeval *tv, struct timezone *unused){
unsigned long dt; \ unsigned long dt; \
dt = (unsigned long)((stop.QuadPart - start.QuadPart) * 1000 * 1000 \ dt = (unsigned long)((stop.QuadPart - start.QuadPart) * 1000 * 1000 \
/ freq.QuadPart); \ / freq.QuadPart); \
fprintf(stderr, \ avrdude_message(\
"hpt:%i usleep usec:%lu sleep msec:%lu timed usec:%lu\n", \ "hpt:%i usleep usec:%lu sleep msec:%lu timed usec:%lu\n", \
has_highperf, us, ((us + 999) / 1000), dt); \ has_highperf, us, ((us + 999) / 1000), dt); \
} while (0) } while (0)

View File

@ -58,8 +58,7 @@ int safemode_writefuse (unsigned char fuse, char * fusename, PROGRAMMER * pgm,
/* Report information to user if needed */ /* Report information to user if needed */
if (verbose > 0) { if (verbose > 0) {
fprintf(stderr, avrdude_message("%s: safemode: Wrote %s to %x, read as %x. %d attempts left\n",
"%s: safemode: Wrote %s to %x, read as %x. %d attempts left\n",
progname, fusename, fuse, fuseread, tries-1); progname, fusename, fuse, fuseread, tries-1);
} }
@ -110,7 +109,7 @@ int safemode_readfuses (unsigned char * lfuse, unsigned char * hfuse,
} }
if (verbose > 2) if (verbose > 2)
{ {
fprintf(stderr, "%s: safemode read 1, fuse value: %x\n",progname, safemode_fuse); avrdude_message("%s: safemode read 1, fuse value: %x\n",progname, safemode_fuse);
} }
if(pgm->read_byte(pgm, p, m, 0, &value) != 0) if(pgm->read_byte(pgm, p, m, 0, &value) != 0)
{ {
@ -118,7 +117,7 @@ int safemode_readfuses (unsigned char * lfuse, unsigned char * hfuse,
} }
if (verbose > 2) if (verbose > 2)
{ {
fprintf(stderr, "%s: safemode read 2, fuse value: %x\n",progname, value); avrdude_message("%s: safemode read 2, fuse value: %x\n",progname, value);
} }
if (value == safemode_fuse) { if (value == safemode_fuse) {
if (pgm->read_byte(pgm, p, m, 0, &value) != 0) if (pgm->read_byte(pgm, p, m, 0, &value) != 0)
@ -127,7 +126,7 @@ int safemode_readfuses (unsigned char * lfuse, unsigned char * hfuse,
} }
if (verbose > 2) if (verbose > 2)
{ {
fprintf(stderr, "%s: safemode read 3, fuse value: %x\n",progname, value); avrdude_message("%s: safemode read 3, fuse value: %x\n",progname, value);
} }
if (value == safemode_fuse) if (value == safemode_fuse)
{ {
@ -143,13 +142,12 @@ int safemode_readfuses (unsigned char * lfuse, unsigned char * hfuse,
} }
if (fusegood == 0) { if (fusegood == 0) {
fprintf(stderr, avrdude_message("%s: safemode: Verify error - unable to read fuse properly. "
"%s: safemode: Verify error - unable to read fuse properly. "
"Programmer may not be reliable.\n", progname); "Programmer may not be reliable.\n", progname);
return -1; return -1;
} }
else if ((fusegood == 1) && (verbose > 0)) { else if ((fusegood == 1) && (verbose > 0)) {
fprintf(stderr, "%s: safemode: fuse reads as %X\n", progname, safemode_fuse); avrdude_message("%s: safemode: fuse reads as %X\n", progname, safemode_fuse);
} }
@ -165,7 +163,7 @@ int safemode_readfuses (unsigned char * lfuse, unsigned char * hfuse,
} }
if (verbose > 2) if (verbose > 2)
{ {
fprintf(stderr, "%s: safemode read 1, lfuse value: %x\n",progname, safemode_lfuse); avrdude_message("%s: safemode read 1, lfuse value: %x\n",progname, safemode_lfuse);
} }
if (pgm->read_byte(pgm, p, m, 0, &value) != 0) if (pgm->read_byte(pgm, p, m, 0, &value) != 0)
{ {
@ -173,7 +171,7 @@ int safemode_readfuses (unsigned char * lfuse, unsigned char * hfuse,
} }
if (verbose > 2) if (verbose > 2)
{ {
fprintf(stderr, "%s: safemode read 2, lfuse value: %x\n",progname, value); avrdude_message("%s: safemode read 2, lfuse value: %x\n",progname, value);
} }
if (value == safemode_lfuse) { if (value == safemode_lfuse) {
if (pgm->read_byte(pgm, p, m, 0, &value) != 0) if (pgm->read_byte(pgm, p, m, 0, &value) != 0)
@ -182,7 +180,7 @@ int safemode_readfuses (unsigned char * lfuse, unsigned char * hfuse,
} }
if (verbose > 2) if (verbose > 2)
{ {
fprintf(stderr, "%s: safemode read 3, lfuse value: %x\n",progname, value); avrdude_message("%s: safemode read 3, lfuse value: %x\n",progname, value);
} }
if (value == safemode_lfuse){ if (value == safemode_lfuse){
fusegood = 1; /* Fuse read OK three times */ fusegood = 1; /* Fuse read OK three times */
@ -198,13 +196,12 @@ int safemode_readfuses (unsigned char * lfuse, unsigned char * hfuse,
if (fusegood == 0) { if (fusegood == 0) {
fprintf(stderr, avrdude_message("%s: safemode: Verify error - unable to read lfuse properly. "
"%s: safemode: Verify error - unable to read lfuse properly. "
"Programmer may not be reliable.\n", progname); "Programmer may not be reliable.\n", progname);
return -1; return -1;
} }
else if ((fusegood == 1) && (verbose > 0)) { else if ((fusegood == 1) && (verbose > 0)) {
fprintf(stderr, "%s: safemode: lfuse reads as %X\n", progname, safemode_lfuse); avrdude_message("%s: safemode: lfuse reads as %X\n", progname, safemode_lfuse);
} }
/* Read hfuse three times */ /* Read hfuse three times */
@ -219,7 +216,7 @@ int safemode_readfuses (unsigned char * lfuse, unsigned char * hfuse,
} }
if (verbose > 2) if (verbose > 2)
{ {
fprintf(stderr, "%s: safemode read 1, hfuse value: %x\n",progname, safemode_hfuse); avrdude_message("%s: safemode read 1, hfuse value: %x\n",progname, safemode_hfuse);
} }
if (pgm->read_byte(pgm, p, m, 0, &value) != 0) if (pgm->read_byte(pgm, p, m, 0, &value) != 0)
{ {
@ -227,7 +224,7 @@ int safemode_readfuses (unsigned char * lfuse, unsigned char * hfuse,
} }
if (verbose > 2) if (verbose > 2)
{ {
fprintf(stderr, "%s: safemode read 2, hfuse value: %x\n",progname, value); avrdude_message("%s: safemode read 2, hfuse value: %x\n",progname, value);
} }
if (value == safemode_hfuse) { if (value == safemode_hfuse) {
if (pgm->read_byte(pgm, p, m, 0, &value) != 0) if (pgm->read_byte(pgm, p, m, 0, &value) != 0)
@ -236,7 +233,7 @@ int safemode_readfuses (unsigned char * lfuse, unsigned char * hfuse,
} }
if (verbose > 2) if (verbose > 2)
{ {
fprintf(stderr, "%s: safemode read 3, hfuse value: %x\n",progname, value); avrdude_message("%s: safemode read 3, hfuse value: %x\n",progname, value);
} }
if (value == safemode_hfuse){ if (value == safemode_hfuse){
fusegood = 1; /* Fuse read OK three times */ fusegood = 1; /* Fuse read OK three times */
@ -251,13 +248,12 @@ int safemode_readfuses (unsigned char * lfuse, unsigned char * hfuse,
} }
if (fusegood == 0) { if (fusegood == 0) {
fprintf(stderr, avrdude_message("%s: safemode: Verify error - unable to read hfuse properly. "
"%s: safemode: Verify error - unable to read hfuse properly. "
"Programmer may not be reliable.\n", progname); "Programmer may not be reliable.\n", progname);
return -2; return -2;
} }
else if ((fusegood == 1) && (verbose > 0)){ else if ((fusegood == 1) && (verbose > 0)){
fprintf(stderr, "%s: safemode: hfuse reads as %X\n", progname, safemode_hfuse); avrdude_message("%s: safemode: hfuse reads as %X\n", progname, safemode_hfuse);
} }
/* Read efuse three times */ /* Read efuse three times */
@ -272,7 +268,7 @@ int safemode_readfuses (unsigned char * lfuse, unsigned char * hfuse,
} }
if (verbose > 2) if (verbose > 2)
{ {
fprintf(stderr, "%s: safemode read 1, efuse value: %x\n",progname, safemode_efuse); avrdude_message("%s: safemode read 1, efuse value: %x\n",progname, safemode_efuse);
} }
if (pgm->read_byte(pgm, p, m, 0, &value) != 0) if (pgm->read_byte(pgm, p, m, 0, &value) != 0)
{ {
@ -280,7 +276,7 @@ int safemode_readfuses (unsigned char * lfuse, unsigned char * hfuse,
} }
if (verbose > 2) if (verbose > 2)
{ {
fprintf(stderr, "%s: safemode read 2, efuse value: %x\n",progname, value); avrdude_message("%s: safemode read 2, efuse value: %x\n",progname, value);
} }
if (value == safemode_efuse) { if (value == safemode_efuse) {
if (pgm->read_byte(pgm, p, m, 0, &value) != 0) if (pgm->read_byte(pgm, p, m, 0, &value) != 0)
@ -289,7 +285,7 @@ int safemode_readfuses (unsigned char * lfuse, unsigned char * hfuse,
} }
if (verbose > 2) if (verbose > 2)
{ {
fprintf(stderr, "%s: safemode read 3, efuse value: %x\n",progname, value); avrdude_message("%s: safemode read 3, efuse value: %x\n",progname, value);
} }
if (value == safemode_efuse){ if (value == safemode_efuse){
fusegood = 1; /* Fuse read OK three times */ fusegood = 1; /* Fuse read OK three times */
@ -304,13 +300,12 @@ int safemode_readfuses (unsigned char * lfuse, unsigned char * hfuse,
} }
if (fusegood == 0) { if (fusegood == 0) {
fprintf(stderr, avrdude_message("%s: safemode: Verify error - unable to read efuse properly. "
"%s: safemode: Verify error - unable to read efuse properly. "
"Programmer may not be reliable.\n", progname); "Programmer may not be reliable.\n", progname);
return -3; return -3;
} }
else if ((fusegood == 1) && (verbose > 0)) { else if ((fusegood == 1) && (verbose > 0)) {
fprintf(stderr, "%s: safemode: efuse reads as %X\n", progname, safemode_efuse); avrdude_message("%s: safemode: efuse reads as %X\n", progname, safemode_efuse);
} }
*lfuse = safemode_lfuse; *lfuse = safemode_lfuse;

View File

@ -313,7 +313,7 @@ static int usbOpenDevice(union filedescriptor *fdp, int vendor, char *vendorName
handle = usb_open(dev); /* we need to open the device in order to query strings */ handle = usb_open(dev); /* we need to open the device in order to query strings */
if(!handle){ if(!handle){
errorCode = USB_ERROR_ACCESS; errorCode = USB_ERROR_ACCESS;
fprintf(stderr, "Warning: cannot open USB device: %s\n", avrdude_message("Warning: cannot open USB device: %s\n",
usb_strerror()); usb_strerror());
continue; continue;
} }
@ -325,23 +325,21 @@ static int usbOpenDevice(union filedescriptor *fdp, int vendor, char *vendorName
0x0409, string, sizeof(string)); 0x0409, string, sizeof(string));
if(len < 0){ if(len < 0){
errorCode = USB_ERROR_IO; errorCode = USB_ERROR_IO;
fprintf(stderr, avrdude_message("Warning: cannot query manufacturer for device: %s\n",
"Warning: cannot query manufacturer for device: %s\n",
usb_strerror()); usb_strerror());
}else{ }else{
errorCode = USB_ERROR_NOTFOUND; errorCode = USB_ERROR_NOTFOUND;
/* fprintf(stderr, "seen device from vendor ->%s<-\n", string); */ /* avrdude_message("seen device from vendor ->%s<-\n", string); */
if(strcmp(string, vendorName) == 0){ if(strcmp(string, vendorName) == 0){
len = usbGetStringAscii(handle, dev->descriptor.iProduct, len = usbGetStringAscii(handle, dev->descriptor.iProduct,
0x0409, string, sizeof(string)); 0x0409, string, sizeof(string));
if(len < 0){ if(len < 0){
errorCode = USB_ERROR_IO; errorCode = USB_ERROR_IO;
fprintf(stderr, avrdude_message("Warning: cannot query product for device: %s\n",
"Warning: cannot query product for device: %s\n",
usb_strerror()); usb_strerror());
}else{ }else{
errorCode = USB_ERROR_NOTFOUND; errorCode = USB_ERROR_NOTFOUND;
/* fprintf(stderr, "seen product ->%s<-\n", string); */ /* avrdude_message("seen product ->%s<-\n", string); */
if(strcmp(string, productName) == 0) if(strcmp(string, productName) == 0)
break; break;
} }
@ -357,7 +355,7 @@ static int usbOpenDevice(union filedescriptor *fdp, int vendor, char *vendorName
if(handle != NULL){ if(handle != NULL){
int rval, retries = 3; int rval, retries = 3;
if(usb_set_configuration(handle, 1)){ if(usb_set_configuration(handle, 1)){
fprintf(stderr, "Warning: could not set configuration: %s\n", avrdude_message("Warning: could not set configuration: %s\n",
usb_strerror()); usb_strerror());
} }
/* now try to claim the interface and detach the kernel HID driver on /* now try to claim the interface and detach the kernel HID driver on
@ -366,13 +364,13 @@ static int usbOpenDevice(union filedescriptor *fdp, int vendor, char *vendorName
while((rval = usb_claim_interface(handle, 0)) != 0 && retries-- > 0){ while((rval = usb_claim_interface(handle, 0)) != 0 && retries-- > 0){
#ifdef LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP #ifdef LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP
if(usb_detach_kernel_driver_np(handle, 0) < 0){ if(usb_detach_kernel_driver_np(handle, 0) < 0){
fprintf(stderr, "Warning: could not detach kernel HID driver: %s\n", avrdude_message("Warning: could not detach kernel HID driver: %s\n",
usb_strerror()); usb_strerror());
} }
#endif #endif
} }
if(rval != 0) if(rval != 0)
fprintf(stderr, "Warning: could not claim interface\n"); avrdude_message("Warning: could not claim interface\n");
/* Continue anyway, even if we could not claim the interface. Control transfers /* Continue anyway, even if we could not claim the interface. Control transfers
* should still work. * should still work.
*/ */
@ -405,7 +403,7 @@ static int usbSetReport(union filedescriptor *fdp, int reportType, char *buffer,
reportType << 8 | buffer[0], 0, buffer, len, 5000); reportType << 8 | buffer[0], 0, buffer, len, 5000);
if(bytesSent != len){ if(bytesSent != len){
if(bytesSent < 0) if(bytesSent < 0)
fprintf(stderr, "Error sending message: %s\n", usb_strerror()); avrdude_message("Error sending message: %s\n", usb_strerror());
return USB_ERROR_IO; return USB_ERROR_IO;
} }
return 0; return 0;
@ -426,7 +424,7 @@ static int usbGetReport(union filedescriptor *fdp, int reportType, int reportNum
USB_RECIP_INTERFACE | USB_ENDPOINT_IN, USBRQ_HID_GET_REPORT, USB_RECIP_INTERFACE | USB_ENDPOINT_IN, USBRQ_HID_GET_REPORT,
reportType << 8 | reportNumber, 0, buffer, maxLen, 5000); reportType << 8 | reportNumber, 0, buffer, maxLen, 5000);
if(bytesReceived < 0){ if(bytesReceived < 0){
fprintf(stderr, "Error sending message: %s\n", usb_strerror()); avrdude_message("Error sending message: %s\n", usb_strerror());
return USB_ERROR_IO; return USB_ERROR_IO;
} }
*len = bytesReceived; *len = bytesReceived;
@ -450,11 +448,11 @@ static void dumpBlock(char *prefix, 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 */
fprintf(stderr, "%s: %d bytes: ", prefix, len); avrdude_message("%s: %d bytes: ", prefix, len);
for(i = 0; i < len; i++){ for(i = 0; i < len; i++){
fprintf(stderr, "%02x ", buf[i]); avrdude_message("%02x ", buf[i]);
} }
fprintf(stderr, " \""); avrdude_message(" \"");
for(i = 0; i < len; i++){ for(i = 0; i < len; i++){
if(buf[i] >= 0x20 && buf[i] < 0x7f){ if(buf[i] >= 0x20 && buf[i] < 0x7f){
fputc(buf[i], stderr); fputc(buf[i], stderr);
@ -462,20 +460,20 @@ static void dumpBlock(char *prefix, unsigned char *buf, int len)
fputc('.', stderr); fputc('.', stderr);
} }
} }
fprintf(stderr, "\"\n"); avrdude_message("\"\n");
}else{ }else{
fprintf(stderr, "%s: %d bytes:\n", prefix, len); avrdude_message("%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){
fprintf(stderr, "%02x ", buf[i]); avrdude_message("%02x ", buf[i]);
}else{ }else{
fprintf(stderr, " "); avrdude_message(" ");
} }
if(i == 7) if(i == 7)
fputc(' ', stderr); fputc(' ', stderr);
} }
fprintf(stderr, " \""); avrdude_message(" \"");
for(i = 0; i < 16; i++){ for(i = 0; i < 16; i++){
if(i < len){ if(i < len){
if(buf[i] >= 0x20 && buf[i] < 0x7f){ if(buf[i] >= 0x20 && buf[i] < 0x7f){
@ -485,7 +483,7 @@ static void dumpBlock(char *prefix, unsigned char *buf, int len)
} }
} }
} }
fprintf(stderr, "\"\n"); avrdude_message("\"\n");
buf += 16; buf += 16;
len -= 16; len -= 16;
} }
@ -518,7 +516,7 @@ static int avrdoper_open(char *port, union pinfo pinfo, union filedescriptor *fd
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){
fprintf(stderr, "%s: avrdoper_open(): %s\n", progname, usbErrorText(rval)); avrdude_message("%s: avrdoper_open(): %s\n", progname, usbErrorText(rval));
return -1; return -1;
} }
return 0; return 0;
@ -557,11 +555,11 @@ static int avrdoper_send(union filedescriptor *fdp, unsigned char *buf, size_t b
buffer[1] = thisLen; buffer[1] = thisLen;
memcpy(buffer + 2, buf, thisLen); memcpy(buffer + 2, buf, thisLen);
if(verbose > 3) if(verbose > 3)
fprintf(stderr, "Sending %d bytes data chunk\n", thisLen); avrdude_message("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){
fprintf(stderr, "%s: avrdoper_send(): %s\n", progname, usbErrorText(rval)); avrdude_message("%s: avrdoper_send(): %s\n", progname, usbErrorText(rval));
return -1; return -1;
} }
buflen -= thisLen; buflen -= thisLen;
@ -587,18 +585,17 @@ static int avrdoperFillBuffer(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){
fprintf(stderr, "%s: avrdoperFillBuffer(): %s\n", progname, usbErrorText(usbErr)); avrdude_message("%s: avrdoperFillBuffer(): %s\n", progname, usbErrorText(usbErr));
return -1; return -1;
} }
if(verbose > 3) if(verbose > 3)
fprintf(stderr, "Received %d bytes data chunk of total %d\n", len - 2, buffer[1]); avrdude_message("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)){
fprintf(stderr, avrdude_message("%s: avrdoperFillBuffer(): internal error: buffer overflow\n",
"%s: avrdoperFillBuffer(): internal error: buffer overflow\n",
progname); progname);
return -1; return -1;
} }
@ -646,7 +643,7 @@ static int avrdoper_drain(union filedescriptor *fdp, int display)
static int avrdoper_set_dtr_rts(union filedescriptor *fdp, int is_on) static int avrdoper_set_dtr_rts(union filedescriptor *fdp, int is_on)
{ {
fprintf(stderr, "%s: AVR-Doper doesn't support DTR/RTS setting\n", progname); avrdude_message("%s: AVR-Doper doesn't support DTR/RTS setting\n", progname);
return -1; return -1;
} }

View File

@ -91,7 +91,7 @@ static speed_t serial_baud_lookup(long baud)
* a warning (if we are verbose) and return the raw rate * a warning (if we are verbose) and return the raw rate
*/ */
if (verbose > 0) if (verbose > 0)
fprintf(stderr, "%s: serial_baud_lookup(): Using non-standard baud rate: %ld", avrdude_message("%s: serial_baud_lookup(): Using non-standard baud rate: %ld",
progname, baud); progname, baud);
return baud; return baud;
@ -111,7 +111,7 @@ static int ser_setspeed(union filedescriptor *fd, long baud)
*/ */
rc = tcgetattr(fd->ifd, &termios); rc = tcgetattr(fd->ifd, &termios);
if (rc < 0) { if (rc < 0) {
fprintf(stderr, "%s: ser_setspeed(): tcgetattr() failed", avrdude_message("%s: ser_setspeed(): tcgetattr() failed",
progname); progname);
return -errno; return -errno;
} }
@ -135,7 +135,7 @@ static int ser_setspeed(union filedescriptor *fd, long baud)
rc = tcsetattr(fd->ifd, TCSANOW, &termios); rc = tcsetattr(fd->ifd, TCSANOW, &termios);
if (rc < 0) { if (rc < 0) {
fprintf(stderr, "%s: ser_setspeed(): tcsetattr() failed\n", avrdude_message("%s: ser_setspeed(): tcsetattr() failed\n",
progname); progname);
return -errno; return -errno;
} }
@ -167,13 +167,13 @@ net_open(const char *port, union filedescriptor *fdp)
struct hostent *hp; struct hostent *hp;
if ((hstr = strdup(port)) == NULL) { if ((hstr = strdup(port)) == NULL) {
fprintf(stderr, "%s: net_open(): Out of memory!\n", avrdude_message("%s: net_open(): Out of memory!\n",
progname); progname);
return -1; return -1;
} }
if (((pstr = strchr(hstr, ':')) == NULL) || (pstr == hstr)) { if (((pstr = strchr(hstr, ':')) == NULL) || (pstr == hstr)) {
fprintf(stderr, "%s: net_open(): Mangled host:port string \"%s\"\n", avrdude_message("%s: net_open(): Mangled host:port string \"%s\"\n",
progname, hstr); progname, hstr);
free(hstr); free(hstr);
return -1; return -1;
@ -187,14 +187,14 @@ 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)) {
fprintf(stderr, "%s: net_open(): Bad port number \"%s\"\n", avrdude_message("%s: net_open(): Bad port number \"%s\"\n",
progname, pstr); progname, pstr);
free(hstr); free(hstr);
return -1; return -1;
} }
if ((hp = gethostbyname(hstr)) == NULL) { if ((hp = gethostbyname(hstr)) == NULL) {
fprintf(stderr, "%s: net_open(): unknown host \"%s\"\n", avrdude_message("%s: net_open(): unknown host \"%s\"\n",
progname, hstr); progname, hstr);
free(hstr); free(hstr);
return -1; return -1;
@ -203,7 +203,7 @@ net_open(const char *port, union filedescriptor *fdp)
free(hstr); free(hstr);
if ((fd = socket(PF_INET, SOCK_STREAM, 0)) < 0) { if ((fd = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
fprintf(stderr, "%s: net_open(): Cannot open socket: %s\n", avrdude_message("%s: net_open(): Cannot open socket: %s\n",
progname, strerror(errno)); progname, strerror(errno));
return -1; return -1;
} }
@ -214,7 +214,7 @@ net_open(const char *port, union filedescriptor *fdp)
memcpy(&(sockaddr.sin_addr.s_addr), hp->h_addr, sizeof(struct in_addr)); memcpy(&(sockaddr.sin_addr.s_addr), hp->h_addr, sizeof(struct in_addr));
if (connect(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr))) { if (connect(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr))) {
fprintf(stderr, "%s: net_open(): Connect failed: %s\n", avrdude_message("%s: net_open(): Connect failed: %s\n",
progname, strerror(errno)); progname, strerror(errno));
return -1; return -1;
} }
@ -271,7 +271,7 @@ static int ser_open(char * port, union pinfo pinfo, union filedescriptor *fdp)
*/ */
fd = open(port, O_RDWR | O_NOCTTY | O_NONBLOCK); fd = open(port, O_RDWR | O_NOCTTY | O_NONBLOCK);
if (fd < 0) { if (fd < 0) {
fprintf(stderr, "%s: ser_open(): can't open device \"%s\": %s\n", avrdude_message("%s: ser_open(): can't open device \"%s\": %s\n",
progname, port, strerror(errno)); progname, port, strerror(errno));
return -1; return -1;
} }
@ -283,8 +283,7 @@ static int ser_open(char * port, union pinfo pinfo, union filedescriptor *fdp)
*/ */
rc = ser_setspeed(fdp, pinfo.baud); rc = ser_setspeed(fdp, pinfo.baud);
if (rc) { if (rc) {
fprintf(stderr, avrdude_message("%s: ser_open(): can't set attributes for device \"%s\": %s\n",
"%s: ser_open(): can't set attributes for device \"%s\": %s\n",
progname, port, strerror(-rc)); progname, port, strerror(-rc));
close(fd); close(fd);
return -1; return -1;
@ -301,8 +300,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) {
fprintf(stderr, avrdude_message("%s: ser_close(): can't reset attributes for device: %s\n",
"%s: ser_close(): can't reset attributes for device: %s\n",
progname, strerror(errno)); progname, strerror(errno));
} }
saved_original_termios = 0; saved_original_termios = 0;
@ -323,29 +321,29 @@ static int ser_send(union filedescriptor *fd, unsigned char * buf, size_t buflen
if (verbose > 3) if (verbose > 3)
{ {
fprintf(stderr, "%s: Send: ", progname); avrdude_message("%s: Send: ", progname);
while (buflen) { while (buflen) {
unsigned char c = *buf; unsigned char c = *buf;
if (isprint(c)) { if (isprint(c)) {
fprintf(stderr, "%c ", c); avrdude_message("%c ", c);
} }
else { else {
fprintf(stderr, ". "); avrdude_message(". ");
} }
fprintf(stderr, "[%02x] ", c); avrdude_message("[%02x] ", c);
buf++; buf++;
buflen--; buflen--;
} }
fprintf(stderr, "\n"); avrdude_message("\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) {
fprintf(stderr, "%s: ser_send(): write error: %s\n", avrdude_message("%s: ser_send(): write error: %s\n",
progname, strerror(errno)); progname, strerror(errno));
return -1; return -1;
} }
@ -378,20 +376,18 @@ static int ser_recv(union filedescriptor *fd, unsigned char * buf, size_t buflen
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)
fprintf(stderr, avrdude_message("%s: ser_recv(): programmer is not responding\n",
"%s: ser_recv(): programmer is not responding\n",
progname); progname);
return -1; return -1;
} }
else if (nfds == -1) { else if (nfds == -1) {
if (errno == EINTR || errno == EAGAIN) { if (errno == EINTR || errno == EAGAIN) {
fprintf(stderr, avrdude_message("%s: ser_recv(): programmer is not responding,reselecting\n",
"%s: ser_recv(): programmer is not responding,reselecting\n",
progname); progname);
goto reselect; goto reselect;
} }
else { else {
fprintf(stderr, "%s: ser_recv(): select(): %s\n", avrdude_message("%s: ser_recv(): select(): %s\n",
progname, strerror(errno)); progname, strerror(errno));
return -1; return -1;
} }
@ -399,7 +395,7 @@ static int ser_recv(union filedescriptor *fd, unsigned char * buf, size_t buflen
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) {
fprintf(stderr, "%s: ser_recv(): read error: %s\n", avrdude_message("%s: ser_recv(): read error: %s\n",
progname, strerror(errno)); progname, strerror(errno));
return -1; return -1;
} }
@ -411,22 +407,22 @@ static int ser_recv(union filedescriptor *fd, unsigned char * buf, size_t buflen
if (verbose > 3) if (verbose > 3)
{ {
fprintf(stderr, "%s: Recv: ", progname); avrdude_message("%s: Recv: ", progname);
while (len) { while (len) {
unsigned char c = *p; unsigned char c = *p;
if (isprint(c)) { if (isprint(c)) {
fprintf(stderr, "%c ", c); avrdude_message("%c ", c);
} }
else { else {
fprintf(stderr, ". "); avrdude_message(". ");
} }
fprintf(stderr, "[%02x] ", c); avrdude_message("[%02x] ", c);
p++; p++;
len--; len--;
} }
fprintf(stderr, "\n"); avrdude_message("\n");
} }
return 0; return 0;
@ -445,7 +441,7 @@ static int ser_drain(union filedescriptor *fd, int display)
timeout.tv_usec = 250000; timeout.tv_usec = 250000;
if (display) { if (display) {
fprintf(stderr, "drain>"); avrdude_message("drain>");
} }
while (1) { while (1) {
@ -456,7 +452,7 @@ static int ser_drain(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) {
fprintf(stderr, "<drain\n"); avrdude_message("<drain\n");
} }
break; break;
@ -466,7 +462,7 @@ static int ser_drain(union filedescriptor *fd, int display)
goto reselect; goto reselect;
} }
else { else {
fprintf(stderr, "%s: ser_drain(): select(): %s\n", avrdude_message("%s: ser_drain(): select(): %s\n",
progname, strerror(errno)); progname, strerror(errno));
return -1; return -1;
} }
@ -474,12 +470,12 @@ static int ser_drain(union filedescriptor *fd, int display)
rc = read(fd->ifd, &buf, 1); rc = read(fd->ifd, &buf, 1);
if (rc < 0) { if (rc < 0) {
fprintf(stderr, "%s: ser_drain(): read error: %s\n", avrdude_message("%s: ser_drain(): read error: %s\n",
progname, strerror(errno)); progname, strerror(errno));
return -1; return -1;
} }
if (display) { if (display) {
fprintf(stderr, "%02x ", buf); avrdude_message("%02x ", buf);
} }
} }

View File

@ -71,7 +71,7 @@ static DWORD serial_baud_lookup(long baud)
* a warning (if we are verbose) and return the raw rate * a warning (if we are verbose) and return the raw rate
*/ */
if (verbose > 0) if (verbose > 0)
fprintf(stderr, "%s: serial_baud_lookup(): Using non-standard baud rate: %ld", avrdude_message("%s: serial_baud_lookup(): Using non-standard baud rate: %ld",
progname, baud); progname, baud);
return baud; return baud;
@ -124,8 +124,7 @@ static int ser_open(char * port, union pinfo pinfo, union filedescriptor *fdp)
* This is curently not implemented for Win32. * This is curently not implemented for Win32.
*/ */
if (strncmp(port, "net:", strlen("net:")) == 0) { if (strncmp(port, "net:", strlen("net:")) == 0) {
fprintf(stderr, avrdude_message("%s: ser_open(): network connects are currently not"
"%s: ser_open(): network connects are currently not"
"implemented for Win32 environments\n", "implemented for Win32 environments\n",
progname); progname);
return -1; return -1;
@ -137,8 +136,7 @@ static int ser_open(char * port, union pinfo pinfo, union filedescriptor *fdp)
newname = malloc(strlen("\\\\.\\") + strlen(port) + 1); newname = malloc(strlen("\\\\.\\") + strlen(port) + 1);
if (newname == 0) { if (newname == 0) {
fprintf(stderr, avrdude_message("%s: ser_open(): out of memory\n",
"%s: ser_open(): out of memory\n",
progname); progname);
exit(1); exit(1);
} }
@ -162,7 +160,7 @@ static int ser_open(char * port, union pinfo pinfo, union filedescriptor *fdp)
(LPTSTR) &lpMsgBuf, (LPTSTR) &lpMsgBuf,
0, 0,
NULL); NULL);
fprintf(stderr, "%s: ser_open(): can't open device \"%s\": %s\n", avrdude_message("%s: ser_open(): can't open device \"%s\": %s\n",
progname, port, (char*)lpMsgBuf); progname, port, (char*)lpMsgBuf);
LocalFree( lpMsgBuf ); LocalFree( lpMsgBuf );
return -1; return -1;
@ -171,7 +169,7 @@ static int ser_open(char * port, union pinfo pinfo, union filedescriptor *fdp)
if (!SetupComm(hComPort, W32SERBUFSIZE, W32SERBUFSIZE)) if (!SetupComm(hComPort, W32SERBUFSIZE, W32SERBUFSIZE))
{ {
CloseHandle(hComPort); CloseHandle(hComPort);
fprintf(stderr, "%s: ser_open(): can't set buffers for \"%s\"\n", avrdude_message("%s: ser_open(): can't set buffers for \"%s\"\n",
progname, port); progname, port);
return -1; return -1;
} }
@ -180,7 +178,7 @@ static int ser_open(char * port, union pinfo pinfo, union filedescriptor *fdp)
if (ser_setspeed(fdp, pinfo.baud) != 0) if (ser_setspeed(fdp, pinfo.baud) != 0)
{ {
CloseHandle(hComPort); CloseHandle(hComPort);
fprintf(stderr, "%s: ser_open(): can't set com-state for \"%s\"\n", avrdude_message("%s: ser_open(): can't set com-state for \"%s\"\n",
progname, port); progname, port);
return -1; return -1;
} }
@ -188,7 +186,7 @@ static int ser_open(char * port, union pinfo pinfo, union filedescriptor *fdp)
if (!serial_w32SetTimeOut(hComPort,0)) if (!serial_w32SetTimeOut(hComPort,0))
{ {
CloseHandle(hComPort); CloseHandle(hComPort);
fprintf(stderr, "%s: ser_open(): can't set initial timeout for \"%s\"\n", avrdude_message("%s: ser_open(): can't set initial timeout for \"%s\"\n",
progname, port); progname, port);
return -1; return -1;
} }
@ -234,7 +232,7 @@ static int ser_send(union filedescriptor *fd, unsigned char * buf, size_t buflen
HANDLE hComPort=(HANDLE)fd->pfd; HANDLE hComPort=(HANDLE)fd->pfd;
if (hComPort == INVALID_HANDLE_VALUE) { if (hComPort == INVALID_HANDLE_VALUE) {
fprintf(stderr, "%s: ser_send(): port not open\n", avrdude_message("%s: ser_send(): port not open\n",
progname); progname);
return -1; return -1;
} }
@ -244,33 +242,33 @@ static int ser_send(union filedescriptor *fd, unsigned char * buf, size_t buflen
if (verbose > 3) if (verbose > 3)
{ {
fprintf(stderr, "%s: Send: ", progname); avrdude_message("%s: Send: ", progname);
while (len) { while (len) {
c = *b; c = *b;
if (isprint(c)) { if (isprint(c)) {
fprintf(stderr, "%c ", c); avrdude_message("%c ", c);
} }
else { else {
fprintf(stderr, ". "); avrdude_message(". ");
} }
fprintf(stderr, "[%02x] ", c); avrdude_message("[%02x] ", c);
b++; b++;
len--; len--;
} }
fprintf(stderr, "\n"); avrdude_message("\n");
} }
serial_w32SetTimeOut(hComPort,500); serial_w32SetTimeOut(hComPort,500);
if (!WriteFile (hComPort, buf, buflen, &written, NULL)) { if (!WriteFile (hComPort, buf, buflen, &written, NULL)) {
fprintf(stderr, "%s: ser_send(): write error: %s\n", avrdude_message("%s: ser_send(): write error: %s\n",
progname, "sorry no info avail"); // TODO progname, "sorry no info avail"); // TODO
return -1; return -1;
} }
if (written != buflen) { if (written != buflen) {
fprintf(stderr, "%s: ser_send(): size/send mismatch\n", avrdude_message("%s: ser_send(): size/send mismatch\n",
progname); progname);
return -1; return -1;
} }
@ -288,7 +286,7 @@ static int ser_recv(union filedescriptor *fd, unsigned char * buf, size_t buflen
HANDLE hComPort=(HANDLE)fd->pfd; HANDLE hComPort=(HANDLE)fd->pfd;
if (hComPort == INVALID_HANDLE_VALUE) { if (hComPort == INVALID_HANDLE_VALUE) {
fprintf(stderr, "%s: ser_read(): port not open\n", avrdude_message("%s: ser_read(): port not open\n",
progname); progname);
return -1; return -1;
} }
@ -307,7 +305,7 @@ static int ser_recv(union filedescriptor *fd, unsigned char * buf, size_t buflen
(LPTSTR) &lpMsgBuf, (LPTSTR) &lpMsgBuf,
0, 0,
NULL ); NULL );
fprintf(stderr, "%s: ser_recv(): read error: %s\n", avrdude_message("%s: ser_recv(): read error: %s\n",
progname, (char*)lpMsgBuf); progname, (char*)lpMsgBuf);
LocalFree( lpMsgBuf ); LocalFree( lpMsgBuf );
return -1; return -1;
@ -316,8 +314,7 @@ static int ser_recv(union filedescriptor *fd, unsigned char * buf, size_t buflen
/* time out detected */ /* time out detected */
if (read == 0) { if (read == 0) {
if (verbose > 1) if (verbose > 1)
fprintf(stderr, avrdude_message("%s: ser_recv(): programmer is not responding\n",
"%s: ser_recv(): programmer is not responding\n",
progname); progname);
return -1; return -1;
} }
@ -326,22 +323,22 @@ static int ser_recv(union filedescriptor *fd, unsigned char * buf, size_t buflen
if (verbose > 3) if (verbose > 3)
{ {
fprintf(stderr, "%s: Recv: ", progname); avrdude_message("%s: Recv: ", progname);
while (read) { while (read) {
c = *p; c = *p;
if (isprint(c)) { if (isprint(c)) {
fprintf(stderr, "%c ", c); avrdude_message("%c ", c);
} }
else { else {
fprintf(stderr, ". "); avrdude_message(". ");
} }
fprintf(stderr, "[%02x] ", c); avrdude_message("[%02x] ", c);
p++; p++;
read--; read--;
} }
fprintf(stderr, "\n"); avrdude_message("\n");
} }
return 0; return 0;
} }
@ -357,7 +354,7 @@ static int ser_drain(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) {
fprintf(stderr, "%s: ser_drain(): port not open\n", avrdude_message("%s: ser_drain(): port not open\n",
progname); progname);
return -1; return -1;
} }
@ -365,7 +362,7 @@ static int ser_drain(union filedescriptor *fd, int display)
serial_w32SetTimeOut(hComPort,250); serial_w32SetTimeOut(hComPort,250);
if (display) { if (display) {
fprintf(stderr, "drain>"); avrdude_message("drain>");
} }
while (1) { while (1) {
@ -382,17 +379,17 @@ static int ser_drain(union filedescriptor *fd, int display)
(LPTSTR) &lpMsgBuf, (LPTSTR) &lpMsgBuf,
0, 0,
NULL ); NULL );
fprintf(stderr, "%s: ser_drain(): read error: %s\n", avrdude_message("%s: ser_drain(): read error: %s\n",
progname, (char*)lpMsgBuf); progname, (char*)lpMsgBuf);
LocalFree( lpMsgBuf ); LocalFree( lpMsgBuf );
return -1; return -1;
} }
if (read) { // data avail if (read) { // data avail
if (display) fprintf(stderr, "%02x ", buf[0]); if (display) avrdude_message("%02x ", buf[0]);
} }
else { // no more data else { // no more data
if (display) fprintf(stderr, "<drain\n"); if (display) avrdude_message("<drain\n");
break; break;
} }
} // while } // while

View File

@ -239,7 +239,7 @@ static int serbb_open(PROGRAMMER *pgm, char *port)
r = tcgetattr(pgm->fd.ifd, &mode); r = tcgetattr(pgm->fd.ifd, &mode);
if (r < 0) { if (r < 0) {
fprintf(stderr, "%s: ", port); avrdude_message("%s: ", port);
perror("tcgetattr"); perror("tcgetattr");
return(-1); return(-1);
} }
@ -253,7 +253,7 @@ static int serbb_open(PROGRAMMER *pgm, char *port)
r = tcsetattr(pgm->fd.ifd, TCSANOW, &mode); r = tcsetattr(pgm->fd.ifd, TCSANOW, &mode);
if (r < 0) { if (r < 0) {
fprintf(stderr, "%s: ", port); avrdude_message("%s: ", port);
perror("tcsetattr"); perror("tcsetattr");
return(-1); return(-1);
} }
@ -262,14 +262,14 @@ static int serbb_open(PROGRAMMER *pgm, char *port)
flags = fcntl(pgm->fd.ifd, F_GETFL, 0); flags = fcntl(pgm->fd.ifd, F_GETFL, 0);
if (flags == -1) if (flags == -1)
{ {
fprintf(stderr, "%s: Can not get flags: %s\n", avrdude_message("%s: Can not get flags: %s\n",
progname, 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)
{ {
fprintf(stderr, "%s: Can not clear nonblock flag: %s\n", avrdude_message("%s: Can not clear nonblock flag: %s\n",
progname, strerror(errno)); progname, strerror(errno));
return(-1); return(-1);
} }

View File

@ -98,14 +98,12 @@ static int serbb_setpin(PROGRAMMER * pgm, int pinfunc, int value)
default: default:
if (verbose) if (verbose)
fprintf(stderr, avrdude_message("%s: serbb_setpin(): unknown pin %d\n",
"%s: serbb_setpin(): unknown pin %d\n",
progname, pin + 1); progname, pin + 1);
return -1; return -1;
} }
if (verbose > 4) if (verbose > 4)
fprintf(stderr, avrdude_message("%s: serbb_setpin(): EscapeCommFunction(%s)\n",
"%s: serbb_setpin(): EscapeCommFunction(%s)\n",
progname, name); progname, name);
if (!EscapeCommFunction(hComPort, dwFunc)) if (!EscapeCommFunction(hComPort, dwFunc))
{ {
@ -119,8 +117,7 @@ static int serbb_setpin(PROGRAMMER * pgm, int pinfunc, int value)
(LPTSTR) &lpMsgBuf, (LPTSTR) &lpMsgBuf,
0, 0,
NULL); NULL);
fprintf(stderr, avrdude_message("%s: serbb_setpin(): SetCommState() failed: %s\n",
"%s: serbb_setpin(): SetCommState() failed: %s\n",
progname, (char *)lpMsgBuf); progname, (char *)lpMsgBuf);
CloseHandle(hComPort); CloseHandle(hComPort);
LocalFree(lpMsgBuf); LocalFree(lpMsgBuf);
@ -166,16 +163,14 @@ static int serbb_getpin(PROGRAMMER * pgm, int pinfunc)
(LPTSTR) &lpMsgBuf, (LPTSTR) &lpMsgBuf,
0, 0,
NULL); NULL);
fprintf(stderr, avrdude_message("%s: serbb_setpin(): GetCommModemStatus() failed: %s\n",
"%s: serbb_setpin(): GetCommModemStatus() failed: %s\n",
progname, (char *)lpMsgBuf); progname, (char *)lpMsgBuf);
CloseHandle(hComPort); CloseHandle(hComPort);
LocalFree(lpMsgBuf); LocalFree(lpMsgBuf);
return -1; return -1;
} }
if (verbose > 4) if (verbose > 4)
fprintf(stderr, avrdude_message("%s: serbb_getpin(): GetCommState() => 0x%lx\n",
"%s: serbb_getpin(): GetCommState() => 0x%lx\n",
progname, modemstate); progname, modemstate);
switch (pin) switch (pin)
{ {
@ -212,14 +207,12 @@ static int serbb_getpin(PROGRAMMER * pgm, int pinfunc)
break; break;
default: default:
if (verbose) if (verbose)
fprintf(stderr, avrdude_message("%s: serbb_getpin(): unknown pin %d\n",
"%s: serbb_getpin(): unknown pin %d\n",
progname, pin + 1); progname, pin + 1);
return -1; return -1;
} }
if (verbose > 4) if (verbose > 4)
fprintf(stderr, avrdude_message("%s: serbb_getpin(): return cached state for %s\n",
"%s: serbb_getpin(): return cached state for %s\n",
progname, name); progname, name);
if (invert) if (invert)
rv = !rv; rv = !rv;
@ -288,7 +281,7 @@ static int serbb_open(PROGRAMMER *pgm, char *port)
(LPTSTR) &lpMsgBuf, (LPTSTR) &lpMsgBuf,
0, 0,
NULL); NULL);
fprintf(stderr, "%s: ser_open(): can't open device \"%s\": %s\n", avrdude_message("%s: ser_open(): can't open device \"%s\": %s\n",
progname, port, (char*)lpMsgBuf); progname, port, (char*)lpMsgBuf);
LocalFree(lpMsgBuf); LocalFree(lpMsgBuf);
return -1; return -1;
@ -297,7 +290,7 @@ static int serbb_open(PROGRAMMER *pgm, char *port)
if (!SetupComm(hComPort, W32SERBUFSIZE, W32SERBUFSIZE)) if (!SetupComm(hComPort, W32SERBUFSIZE, W32SERBUFSIZE))
{ {
CloseHandle(hComPort); CloseHandle(hComPort);
fprintf(stderr, "%s: ser_open(): can't set buffers for \"%s\"\n", avrdude_message("%s: ser_open(): can't set buffers for \"%s\"\n",
progname, port); progname, port);
return -1; return -1;
} }
@ -316,13 +309,12 @@ static int serbb_open(PROGRAMMER *pgm, char *port)
if (!SetCommState(hComPort, &dcb)) if (!SetCommState(hComPort, &dcb))
{ {
CloseHandle(hComPort); CloseHandle(hComPort);
fprintf(stderr, "%s: ser_open(): can't set com-state for \"%s\"\n", avrdude_message("%s: ser_open(): can't set com-state for \"%s\"\n",
progname, port); progname, port);
return -1; return -1;
} }
if (verbose > 2) if (verbose > 2)
fprintf(stderr, avrdude_message("%s: ser_open(): opened comm port \"%s\", handle 0x%x\n",
"%s: ser_open(): opened comm port \"%s\", handle 0x%x\n",
progname, port, (int)hComPort); progname, port, (int)hComPort);
pgm->fd.pfd = (void *)hComPort; pgm->fd.pfd = (void *)hComPort;
@ -341,8 +333,7 @@ static void serbb_close(PROGRAMMER *pgm)
CloseHandle (hComPort); CloseHandle (hComPort);
} }
if (verbose > 2) if (verbose > 2)
fprintf(stderr, avrdude_message("%s: ser_close(): closed comm port handle 0x%x\n",
"%s: ser_close(): closed comm port handle 0x%x\n",
progname, (int)hComPort); progname, (int)hComPort);
hComPort = INVALID_HANDLE_VALUE; hComPort = INVALID_HANDLE_VALUE;

175
stk500.c
View File

@ -72,8 +72,7 @@ static int stk500_recv(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) {
fprintf(stderr, avrdude_message("%s: stk500_recv(): programmer is not responding\n",
"%s: stk500_recv(): programmer is not responding\n",
progname); progname);
return -1; return -1;
} }
@ -112,8 +111,7 @@ int stk500_getsync(PROGRAMMER * pgm)
if (resp[0] == Resp_STK_INSYNC){ if (resp[0] == Resp_STK_INSYNC){
break; break;
} }
fprintf(stderr, avrdude_message("%s: stk500_getsync() attempt %d of %d: not in sync: resp=0x%02x\n",
"%s: stk500_getsync() attempt %d of %d: not in sync: resp=0x%02x\n",
progname, 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) {
@ -124,8 +122,7 @@ int stk500_getsync(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) {
fprintf(stderr, avrdude_message("%s: stk500_getsync(): can't communicate with device: "
"%s: stk500_getsync(): can't communicate with device: "
"resp=0x%02x\n", "resp=0x%02x\n",
progname, resp[0]); progname, resp[0]);
return -1; return -1;
@ -156,7 +153,7 @@ static int stk500_cmd(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) {
fprintf(stderr, "%s: stk500_cmd(): programmer is out of sync\n", progname); avrdude_message("%s: stk500_cmd(): programmer is out of sync\n", progname);
return -1; return -1;
} }
@ -169,7 +166,7 @@ static int stk500_cmd(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) {
fprintf(stderr, "%s: stk500_cmd(): protocol error\n", progname); avrdude_message("%s: stk500_cmd(): protocol error\n", progname);
return -1; return -1;
} }
@ -187,15 +184,14 @@ static int stk500_chip_erase(PROGRAMMER * pgm, AVRPART * p)
unsigned char res[4]; unsigned char res[4];
if (pgm->cmd == NULL) { if (pgm->cmd == NULL) {
fprintf(stderr, avrdude_message("%s: Error: %s programmer uses stk500_chip_erase() but does not\n"
"%s: Error: %s programmer uses stk500_chip_erase() but does not\n"
"provide a cmd() method.\n", "provide a cmd() method.\n",
progname, pgm->type); progname, pgm->type);
return -1; return -1;
} }
if (p->op[AVR_OP_CHIP_ERASE] == NULL) { if (p->op[AVR_OP_CHIP_ERASE] == NULL) {
fprintf(stderr, "chip erase instruction not defined for part \"%s\"\n", avrdude_message("chip erase instruction not defined for part \"%s\"\n",
p->desc); p->desc);
return -1; return -1;
} }
@ -234,7 +230,7 @@ static int stk500_program_enable(PROGRAMMER * pgm, AVRPART * p)
return -1; return -1;
if (buf[0] == Resp_STK_NOSYNC) { if (buf[0] == Resp_STK_NOSYNC) {
if (tries > 33) { if (tries > 33) {
fprintf(stderr, "%s: stk500_program_enable(): can't get into sync\n", avrdude_message("%s: stk500_program_enable(): can't get into sync\n",
progname); progname);
return -1; return -1;
} }
@ -243,8 +239,7 @@ static int stk500_program_enable(PROGRAMMER * pgm, AVRPART * p)
goto retry; goto retry;
} }
else if (buf[0] != Resp_STK_INSYNC) { else if (buf[0] != Resp_STK_INSYNC) {
fprintf(stderr, avrdude_message("%s: stk500_program_enable(): protocol error, "
"%s: stk500_program_enable(): protocol error, "
"expect=0x%02x, resp=0x%02x\n", "expect=0x%02x, resp=0x%02x\n",
progname, Resp_STK_INSYNC, buf[0]); progname, Resp_STK_INSYNC, buf[0]);
return -1; return -1;
@ -256,21 +251,20 @@ static int stk500_program_enable(PROGRAMMER * pgm, AVRPART * p)
return 0; return 0;
} }
else if (buf[0] == Resp_STK_NODEVICE) { else if (buf[0] == Resp_STK_NODEVICE) {
fprintf(stderr, "%s: stk500_program_enable(): no device\n", avrdude_message("%s: stk500_program_enable(): no device\n",
progname); progname);
return -1; return -1;
} }
if(buf[0] == Resp_STK_FAILED) if(buf[0] == Resp_STK_FAILED)
{ {
fprintf(stderr, avrdude_message("%s: stk500_program_enable(): failed to enter programming mode\n",
"%s: stk500_program_enable(): failed to enter programming mode\n",
progname); progname);
return -1; return -1;
} }
fprintf(stderr, "%s: stk500_program_enable(): unknown response=0x%02x\n", avrdude_message("%s: stk500_program_enable(): unknown response=0x%02x\n",
progname, buf[0]); progname, buf[0]);
return -1; return -1;
@ -301,7 +295,7 @@ static int stk500_set_extended_parms(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) {
fprintf(stderr, "%s: stk500_set_extended_parms(): can't get into sync\n", avrdude_message("%s: stk500_set_extended_parms(): can't get into sync\n",
progname); progname);
return -1; return -1;
} }
@ -310,8 +304,7 @@ static int stk500_set_extended_parms(PROGRAMMER * pgm, int n,
goto retry; goto retry;
} }
else if (buf[0] != Resp_STK_INSYNC) { else if (buf[0] != Resp_STK_INSYNC) {
fprintf(stderr, avrdude_message("%s: stk500_set_extended_parms(): protocol error, "
"%s: stk500_set_extended_parms(): protocol error, "
"expect=0x%02x, resp=0x%02x\n", "expect=0x%02x, resp=0x%02x\n",
progname, Resp_STK_INSYNC, buf[0]); progname, Resp_STK_INSYNC, buf[0]);
return -1; return -1;
@ -323,22 +316,21 @@ static int stk500_set_extended_parms(PROGRAMMER * pgm, int n,
return 0; return 0;
} }
else if (buf[0] == Resp_STK_NODEVICE) { else if (buf[0] == Resp_STK_NODEVICE) {
fprintf(stderr, "%s: stk500_set_extended_parms(): no device\n", avrdude_message("%s: stk500_set_extended_parms(): no device\n",
progname); progname);
return -1; return -1;
} }
if(buf[0] == Resp_STK_FAILED) if(buf[0] == Resp_STK_FAILED)
{ {
fprintf(stderr, avrdude_message("%s: stk500_set_extended_parms(): failed to set extended "
"%s: stk500_set_extended_parms(): failed to set extended "
"device programming parameters\n", "device programming parameters\n",
progname); progname);
return -1; return -1;
} }
fprintf(stderr, "%s: stk500_set_extended_parms(): unknown response=0x%02x\n", avrdude_message("%s: stk500_set_extended_parms(): unknown response=0x%02x\n",
progname, buf[0]); progname, buf[0]);
return -1; return -1;
@ -373,7 +365,7 @@ static int mib510_isp(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) {
fprintf(stderr, "%s: mib510_isp(): can't get into sync\n", avrdude_message("%s: mib510_isp(): can't get into sync\n",
progname); progname);
return -1; return -1;
} }
@ -382,8 +374,7 @@ static int mib510_isp(PROGRAMMER * pgm, unsigned char cmd)
goto retry; goto retry;
} }
else if (buf[0] != Resp_STK_INSYNC) { else if (buf[0] != Resp_STK_INSYNC) {
fprintf(stderr, avrdude_message("%s: mib510_isp(): protocol error, "
"%s: mib510_isp(): protocol error, "
"expect=0x%02x, resp=0x%02x\n", "expect=0x%02x, resp=0x%02x\n",
progname, Resp_STK_INSYNC, buf[0]); progname, Resp_STK_INSYNC, buf[0]);
return -1; return -1;
@ -395,21 +386,20 @@ static int mib510_isp(PROGRAMMER * pgm, unsigned char cmd)
return 0; return 0;
} }
else if (buf[0] == Resp_STK_NODEVICE) { else if (buf[0] == Resp_STK_NODEVICE) {
fprintf(stderr, "%s: mib510_isp(): no device\n", avrdude_message("%s: mib510_isp(): no device\n",
progname); progname);
return -1; return -1;
} }
if (buf[0] == Resp_STK_FAILED) if (buf[0] == Resp_STK_FAILED)
{ {
fprintf(stderr, avrdude_message("%s: mib510_isp(): command %d failed\n",
"%s: mib510_isp(): command %d failed\n",
progname, cmd); progname, cmd);
return -1; return -1;
} }
fprintf(stderr, "%s: mib510_isp(): unknown response=0x%02x\n", avrdude_message("%s: mib510_isp(): unknown response=0x%02x\n",
progname, buf[0]); progname, buf[0]);
return -1; return -1;
@ -470,7 +460,7 @@ static int stk500_initialize(PROGRAMMER * pgm, AVRPART * p)
} }
#if 0 #if 0
fprintf(stderr, "%s: stk500_initialize(): n_extparms = %d\n", avrdude_message("%s: stk500_initialize(): n_extparms = %d\n",
progname, n_extparms); progname, n_extparms);
#endif #endif
@ -544,8 +534,7 @@ static int stk500_initialize(PROGRAMMER * pgm, 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) {
fprintf(stderr, avrdude_message("%s: stk500_initialize(): programmer not in sync, resp=0x%02x\n",
"%s: stk500_initialize(): programmer not in sync, resp=0x%02x\n",
progname, buf[0]); progname, buf[0]);
if (tries > 33) if (tries > 33)
return -1; return -1;
@ -554,8 +543,7 @@ static int stk500_initialize(PROGRAMMER * pgm, AVRPART * p)
goto retry; goto retry;
} }
else if (buf[0] != Resp_STK_INSYNC) { else if (buf[0] != Resp_STK_INSYNC) {
fprintf(stderr, avrdude_message("%s: stk500_initialize(): (a) protocol error, "
"%s: stk500_initialize(): (a) protocol error, "
"expect=0x%02x, resp=0x%02x\n", "expect=0x%02x, resp=0x%02x\n",
progname, Resp_STK_INSYNC, buf[0]); progname, Resp_STK_INSYNC, buf[0]);
return -1; return -1;
@ -564,8 +552,7 @@ static int stk500_initialize(PROGRAMMER * pgm, 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_OK) { if (buf[0] != Resp_STK_OK) {
fprintf(stderr, avrdude_message("%s: stk500_initialize(): (b) protocol error, "
"%s: stk500_initialize(): (b) protocol error, "
"expect=0x%02x, resp=0x%02x\n", "expect=0x%02x, resp=0x%02x\n",
progname, Resp_STK_OK, buf[0]); progname, Resp_STK_OK, buf[0]);
return -1; return -1;
@ -574,8 +561,7 @@ static int stk500_initialize(PROGRAMMER * pgm, AVRPART * p)
if (n_extparms) { if (n_extparms) {
if ((p->pagel == 0) || (p->bs2 == 0)) { if ((p->pagel == 0) || (p->bs2 == 0)) {
if (verbose > 1) if (verbose > 1)
fprintf(stderr, avrdude_message("%s: PAGEL and BS2 signals not defined in the configuration "
"%s: 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",
progname, p->desc); progname, p->desc);
buf[2] = 0xD7; /* they look somehow possible, */ buf[2] = 0xD7; /* they look somehow possible, */
@ -605,7 +591,7 @@ static int stk500_initialize(PROGRAMMER * pgm, 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) {
fprintf(stderr, "%s: stk500_initialize(): failed\n", progname); avrdude_message("%s: stk500_initialize(): failed\n", progname);
return -1; return -1;
} }
} }
@ -631,7 +617,7 @@ static void stk500_disable(PROGRAMMER * pgm)
return; return;
if (buf[0] == Resp_STK_NOSYNC) { if (buf[0] == Resp_STK_NOSYNC) {
if (tries > 33) { if (tries > 33) {
fprintf(stderr, "%s: stk500_disable(): can't get into sync\n", avrdude_message("%s: stk500_disable(): can't get into sync\n",
progname); progname);
return; return;
} }
@ -640,8 +626,7 @@ static void stk500_disable(PROGRAMMER * pgm)
goto retry; goto retry;
} }
else if (buf[0] != Resp_STK_INSYNC) { else if (buf[0] != Resp_STK_INSYNC) {
fprintf(stderr, avrdude_message("%s: stk500_disable(): protocol error, expect=0x%02x, "
"%s: stk500_disable(): protocol error, expect=0x%02x, "
"resp=0x%02x\n", "resp=0x%02x\n",
progname, Resp_STK_INSYNC, buf[0]); progname, Resp_STK_INSYNC, buf[0]);
return; return;
@ -653,12 +638,12 @@ static void stk500_disable(PROGRAMMER * pgm)
return; return;
} }
else if (buf[0] == Resp_STK_NODEVICE) { else if (buf[0] == Resp_STK_NODEVICE) {
fprintf(stderr, "%s: stk500_disable(): no device\n", avrdude_message("%s: stk500_disable(): no device\n",
progname); progname);
return; return;
} }
fprintf(stderr, "%s: stk500_disable(): unknown response=0x%02x\n", avrdude_message("%s: stk500_disable(): unknown response=0x%02x\n",
progname, buf[0]); progname, buf[0]);
return; return;
@ -743,7 +728,7 @@ static int stk500_loadaddr(PROGRAMMER * pgm, AVRMEM * mem, unsigned int addr)
return -1; return -1;
if (buf[0] == Resp_STK_NOSYNC) { if (buf[0] == Resp_STK_NOSYNC) {
if (tries > 33) { if (tries > 33) {
fprintf(stderr, "%s: stk500_loadaddr(): can't get into sync\n", avrdude_message("%s: stk500_loadaddr(): can't get into sync\n",
progname); progname);
return -1; return -1;
} }
@ -752,8 +737,7 @@ static int stk500_loadaddr(PROGRAMMER * pgm, AVRMEM * mem, unsigned int addr)
goto retry; goto retry;
} }
else if (buf[0] != Resp_STK_INSYNC) { else if (buf[0] != Resp_STK_INSYNC) {
fprintf(stderr, avrdude_message("%s: stk500_loadaddr(): (a) protocol error, "
"%s: stk500_loadaddr(): (a) protocol error, "
"expect=0x%02x, resp=0x%02x\n", "expect=0x%02x, resp=0x%02x\n",
progname, Resp_STK_INSYNC, buf[0]); progname, Resp_STK_INSYNC, buf[0]);
return -1; return -1;
@ -765,8 +749,7 @@ static int stk500_loadaddr(PROGRAMMER * pgm, AVRMEM * mem, unsigned int addr)
return 0; return 0;
} }
fprintf(stderr, avrdude_message("%s: loadaddr(): (b) protocol error, "
"%s: loadaddr(): (b) protocol error, "
"expect=0x%02x, resp=0x%02x\n", "expect=0x%02x, resp=0x%02x\n",
progname, Resp_STK_INSYNC, buf[0]); progname, Resp_STK_INSYNC, buf[0]);
@ -803,8 +786,7 @@ static int stk500_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
n = addr + n_bytes; n = addr + n_bytes;
#if 0 #if 0
fprintf(stderr, avrdude_message("n_bytes = %d\n"
"n_bytes = %d\n"
"n = %u\n" "n = %u\n"
"a_div = %d\n" "a_div = %d\n"
"page_size = %d\n", "page_size = %d\n",
@ -842,7 +824,7 @@ static int stk500_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
return -1; return -1;
if (buf[0] == Resp_STK_NOSYNC) { if (buf[0] == Resp_STK_NOSYNC) {
if (tries > 33) { if (tries > 33) {
fprintf(stderr, "\n%s: stk500_paged_write(): can't get into sync\n", avrdude_message("\n%s: stk500_paged_write(): can't get into sync\n",
progname); progname);
return -3; return -3;
} }
@ -851,8 +833,7 @@ static int stk500_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
goto retry; goto retry;
} }
else if (buf[0] != Resp_STK_INSYNC) { else if (buf[0] != Resp_STK_INSYNC) {
fprintf(stderr, avrdude_message("\n%s: stk500_paged_write(): (a) protocol error, "
"\n%s: stk500_paged_write(): (a) protocol error, "
"expect=0x%02x, resp=0x%02x\n", "expect=0x%02x, resp=0x%02x\n",
progname, Resp_STK_INSYNC, buf[0]); progname, Resp_STK_INSYNC, buf[0]);
return -4; return -4;
@ -861,8 +842,7 @@ static int stk500_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
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) {
fprintf(stderr, avrdude_message("\n%s: stk500_paged_write(): (a) protocol error, "
"\n%s: stk500_paged_write(): (a) protocol error, "
"expect=0x%02x, resp=0x%02x\n", "expect=0x%02x, resp=0x%02x\n",
progname, Resp_STK_INSYNC, buf[0]); progname, Resp_STK_INSYNC, buf[0]);
return -5; return -5;
@ -925,7 +905,7 @@ static int stk500_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
return -1; return -1;
if (buf[0] == Resp_STK_NOSYNC) { if (buf[0] == Resp_STK_NOSYNC) {
if (tries > 33) { if (tries > 33) {
fprintf(stderr, "\n%s: stk500_paged_load(): can't get into sync\n", avrdude_message("\n%s: stk500_paged_load(): can't get into sync\n",
progname); progname);
return -3; return -3;
} }
@ -934,8 +914,7 @@ static int stk500_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
goto retry; goto retry;
} }
else if (buf[0] != Resp_STK_INSYNC) { else if (buf[0] != Resp_STK_INSYNC) {
fprintf(stderr, avrdude_message("\n%s: stk500_paged_load(): (a) protocol error, "
"\n%s: stk500_paged_load(): (a) protocol error, "
"expect=0x%02x, resp=0x%02x\n", "expect=0x%02x, resp=0x%02x\n",
progname, Resp_STK_INSYNC, buf[0]); progname, Resp_STK_INSYNC, buf[0]);
return -4; return -4;
@ -949,8 +928,7 @@ static int stk500_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
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) {
fprintf(stderr, avrdude_message("\n%s: stk500_paged_load(): (a) protocol error, "
"\n%s: stk500_paged_load(): (a) protocol error, "
"expect=0x%02x, resp=0x%02x\n", "expect=0x%02x, resp=0x%02x\n",
progname, Resp_STK_INSYNC, buf[0]); progname, Resp_STK_INSYNC, buf[0]);
return -5; return -5;
@ -958,8 +936,7 @@ static int stk500_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
} }
else { else {
if (buf[0] != Resp_STK_OK) { if (buf[0] != Resp_STK_OK) {
fprintf(stderr, avrdude_message("\n%s: stk500_paged_load(): (a) protocol error, "
"\n%s: stk500_paged_load(): (a) protocol error, "
"expect=0x%02x, resp=0x%02x\n", "expect=0x%02x, resp=0x%02x\n",
progname, Resp_STK_OK, buf[0]); progname, Resp_STK_OK, buf[0]);
return -5; return -5;
@ -978,15 +955,13 @@ static int stk500_set_vtarget(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) {
fprintf(stderr, avrdude_message("%s: stk500_set_vtarget(): cannot obtain V[aref]\n",
"%s: stk500_set_vtarget(): cannot obtain V[aref]\n",
progname); progname);
return -1; return -1;
} }
if (uaref > utarg) { if (uaref > utarg) {
fprintf(stderr, avrdude_message("%s: stk500_set_vtarget(): reducing V[aref] from %.1f to %.1f\n",
"%s: stk500_set_vtarget(): reducing V[aref] from %.1f to %.1f\n",
progname, uaref / 10.0, v); progname, uaref / 10.0, v);
if (stk500_setparm(pgm, Parm_STK_VADJUST, utarg) if (stk500_setparm(pgm, Parm_STK_VADJUST, utarg)
!= 0) != 0)
@ -1004,15 +979,13 @@ static int stk500_set_varef(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) {
fprintf(stderr, avrdude_message("%s: stk500_set_varef(): cannot obtain V[target]\n",
"%s: stk500_set_varef(): cannot obtain V[target]\n",
progname); progname);
return -1; return -1;
} }
if (uaref > utarg) { if (uaref > utarg) {
fprintf(stderr, avrdude_message("%s: stk500_set_varef(): V[aref] must not be greater than "
"%s: stk500_set_varef(): V[aref] must not be greater than "
"V[target] = %.1f\n", "V[target] = %.1f\n",
progname, utarg / 10.0); progname, utarg / 10.0);
return -1; return -1;
@ -1041,8 +1014,7 @@ static int stk500_set_fosc(PROGRAMMER * pgm, double v)
unit = "kHz"; unit = "kHz";
} else } else
unit = "Hz"; unit = "Hz";
fprintf(stderr, avrdude_message("%s: stk500_set_fosc(): f = %.3f %s too high, using %.3f MHz\n",
"%s: stk500_set_fosc(): f = %.3f %s too high, using %.3f MHz\n",
progname, v, unit, STK500_XTAL / 2e6); progname, v, unit, STK500_XTAL / 2e6);
fosc = STK500_XTAL / 2; fosc = STK500_XTAL / 2;
} else } else
@ -1057,7 +1029,7 @@ static int stk500_set_fosc(PROGRAMMER * pgm, double v)
} }
} }
if (idx == sizeof(ps) / sizeof(ps[0])) { if (idx == sizeof(ps) / sizeof(ps[0])) {
fprintf(stderr, "%s: stk500_set_fosc(): f = %u Hz too low, %u Hz min\n", avrdude_message("%s: stk500_set_fosc(): f = %u Hz too low, %u Hz min\n",
progname, fosc, STK500_XTAL / (256 * 1024 * 2)); progname, fosc, STK500_XTAL / (256 * 1024 * 2));
return -1; return -1;
} }
@ -1089,13 +1061,11 @@ static int stk500_set_sck_period(PROGRAMMER * pgm, double v)
if (v < min) { if (v < min) {
dur = 1; dur = 1;
fprintf(stderr, avrdude_message("%s: stk500_set_sck_period(): p = %.1f us too small, using %.1f us\n",
"%s: stk500_set_sck_period(): p = %.1f us too small, using %.1f us\n",
progname, v / 1e-6, dur * min / 1e-6); progname, v / 1e-6, dur * min / 1e-6);
} else if (v > max) { } else if (v > max) {
dur = 255; dur = 255;
fprintf(stderr, avrdude_message("%s: stk500_set_sck_period(): p = %.1f us too large, using %.1f us\n",
"%s: stk500_set_sck_period(): p = %.1f us too large, using %.1f us\n",
progname, v / 1e-6, dur * min / 1e-6); progname, v / 1e-6, dur * min / 1e-6);
} }
@ -1121,7 +1091,7 @@ static int stk500_getparm(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) {
fprintf(stderr, "\n%s: stk500_getparm(): can't get into sync\n", avrdude_message("\n%s: stk500_getparm(): can't get into sync\n",
progname); progname);
return -1; return -1;
} }
@ -1130,8 +1100,7 @@ static int stk500_getparm(PROGRAMMER * pgm, unsigned parm, unsigned * value)
goto retry; goto retry;
} }
else if (buf[0] != Resp_STK_INSYNC) { else if (buf[0] != Resp_STK_INSYNC) {
fprintf(stderr, avrdude_message("\n%s: stk500_getparm(): (a) protocol error, "
"\n%s: stk500_getparm(): (a) protocol error, "
"expect=0x%02x, resp=0x%02x\n", "expect=0x%02x, resp=0x%02x\n",
progname, Resp_STK_INSYNC, buf[0]); progname, Resp_STK_INSYNC, buf[0]);
return -2; return -2;
@ -1144,14 +1113,12 @@ static int stk500_getparm(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) {
fprintf(stderr, avrdude_message("\n%s: stk500_getparm(): parameter 0x%02x failed\n",
"\n%s: stk500_getparm(): parameter 0x%02x failed\n",
progname, v); progname, v);
return -3; return -3;
} }
else if (buf[0] != Resp_STK_OK) { else if (buf[0] != Resp_STK_OK) {
fprintf(stderr, avrdude_message("\n%s: stk500_getparm(): (a) protocol error, "
"\n%s: stk500_getparm(): (a) protocol error, "
"expect=0x%02x, resp=0x%02x\n", "expect=0x%02x, resp=0x%02x\n",
progname, Resp_STK_INSYNC, buf[0]); progname, Resp_STK_INSYNC, buf[0]);
return -3; return -3;
@ -1181,7 +1148,7 @@ static int stk500_setparm(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) {
fprintf(stderr, "\n%s: stk500_setparm(): can't get into sync\n", avrdude_message("\n%s: stk500_setparm(): can't get into sync\n",
progname); progname);
return -1; return -1;
} }
@ -1190,8 +1157,7 @@ static int stk500_setparm(PROGRAMMER * pgm, unsigned parm, unsigned value)
goto retry; goto retry;
} }
else if (buf[0] != Resp_STK_INSYNC) { else if (buf[0] != Resp_STK_INSYNC) {
fprintf(stderr, avrdude_message("\n%s: stk500_setparm(): (a) protocol error, "
"\n%s: stk500_setparm(): (a) protocol error, "
"expect=0x%02x, resp=0x%02x\n", "expect=0x%02x, resp=0x%02x\n",
progname, Resp_STK_INSYNC, buf[0]); progname, Resp_STK_INSYNC, buf[0]);
return -2; return -2;
@ -1206,14 +1172,12 @@ static int stk500_setparm(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) {
fprintf(stderr, avrdude_message("\n%s: stk500_setparm(): parameter 0x%02x failed\n",
"\n%s: stk500_setparm(): parameter 0x%02x failed\n",
progname, parm); progname, parm);
return -3; return -3;
} }
else { else {
fprintf(stderr, avrdude_message("\n%s: stk500_setparm(): (a) protocol error, "
"\n%s: stk500_setparm(): (a) protocol error, "
"expect=0x%02x, resp=0x%02x\n", "expect=0x%02x, resp=0x%02x\n",
progname, Resp_STK_INSYNC, buf[0]); progname, Resp_STK_INSYNC, buf[0]);
return -3; return -3;
@ -1230,8 +1194,8 @@ static void stk500_display(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);
fprintf(stderr, "%sHardware Version: %d\n", p, hdw); avrdude_message("%sHardware Version: %d\n", p, hdw);
fprintf(stderr, "%sFirmware Version: %d.%d\n", p, maj, min); avrdude_message("%sFirmware Version: %d.%d\n", p, maj, min);
if (topcard < 3) { if (topcard < 3) {
const char *n = "Unknown"; const char *n = "Unknown";
@ -1244,7 +1208,7 @@ static void stk500_display(PROGRAMMER * pgm, const char * p)
n = "STK501"; n = "STK501";
break; break;
} }
fprintf(stderr, "%sTopcard : %s\n", p, n); avrdude_message("%sTopcard : %s\n", p, n);
} }
stk500_print_parms1(pgm, p); stk500_print_parms1(pgm, p);
@ -1262,11 +1226,11 @@ static void stk500_print_parms1(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);
fprintf(stderr, "%sVtarget : %.1f V\n", p, vtarget / 10.0); avrdude_message("%sVtarget : %.1f V\n", p, vtarget / 10.0);
fprintf(stderr, "%sVaref : %.1f V\n", p, vadjust / 10.0); avrdude_message("%sVaref : %.1f V\n", p, vadjust / 10.0);
fprintf(stderr, "%sOscillator : ", p); avrdude_message("%sOscillator : ", p);
if (osc_pscale == 0) if (osc_pscale == 0)
fprintf(stderr, "Off\n"); avrdude_message("Off\n");
else { else {
int prescale = 1; int prescale = 1;
double f = STK500_XTAL / 2; double f = STK500_XTAL / 2;
@ -1290,9 +1254,9 @@ static void stk500_print_parms1(PROGRAMMER * pgm, const char * p)
unit = "kHz"; unit = "kHz";
} else } else
unit = "Hz"; unit = "Hz";
fprintf(stderr, "%.3f %s\n", f, unit); avrdude_message("%.3f %s\n", f, unit);
} }
fprintf(stderr, "%sSCK period : %.1f us\n", p, avrdude_message("%sSCK period : %.1f us\n", p,
sck_duration * 8.0e6 / STK500_XTAL + 0.05); sck_duration * 8.0e6 / STK500_XTAL + 0.05);
return; return;
@ -1307,8 +1271,7 @@ static void stk500_print_parms(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) {
fprintf(stderr, avrdude_message("%s: stk500_setup(): Out of memory allocating private data\n",
"%s: stk500_setup(): Out of memory allocating private data\n",
progname); progname);
return; return;
} }

View File

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

File diff suppressed because it is too large Load Diff

119
term.c
View File

@ -248,7 +248,7 @@ static int cmd_dump(PROGRAMMER * pgm, struct avrpart * p,
int rc; int rc;
if (!((argc == 2) || (argc == 4))) { if (!((argc == 2) || (argc == 4))) {
fprintf(stderr, "Usage: dump <memtype> [<addr> <len>]\n"); avrdude_message("Usage: dump <memtype> [<addr> <len>]\n");
return -1; return -1;
} }
@ -263,7 +263,7 @@ static int cmd_dump(PROGRAMMER * pgm, struct avrpart * p,
mem = avr_locate_mem(p, memtype); mem = avr_locate_mem(p, memtype);
if (mem == NULL) { if (mem == NULL) {
fprintf(stderr, "\"%s\" memory type not defined for part \"%s\"\n", avrdude_message("\"%s\" memory type not defined for part \"%s\"\n",
memtype, p->desc); memtype, p->desc);
return -1; return -1;
} }
@ -271,14 +271,14 @@ static int cmd_dump(PROGRAMMER * pgm, struct avrpart * p,
if (argc == 4) { if (argc == 4) {
addr = strtoul(argv[2], &e, 0); addr = strtoul(argv[2], &e, 0);
if (*e || (e == argv[2])) { if (*e || (e == argv[2])) {
fprintf(stderr, "%s (dump): can't parse address \"%s\"\n", avrdude_message("%s (dump): can't parse address \"%s\"\n",
progname, argv[2]); progname, argv[2]);
return -1; return -1;
} }
len = strtol(argv[3], &e, 0); len = strtol(argv[3], &e, 0);
if (*e || (e == argv[3])) { if (*e || (e == argv[3])) {
fprintf(stderr, "%s (dump): can't parse length \"%s\"\n", avrdude_message("%s (dump): can't parse length \"%s\"\n",
progname, argv[3]); progname, argv[3]);
return -1; return -1;
} }
@ -292,8 +292,7 @@ static int cmd_dump(PROGRAMMER * pgm, struct avrpart * p,
addr = 0; addr = 0;
} }
else { else {
fprintf(stderr, avrdude_message("%s (dump): address 0x%05lx is out of range for %s memory\n",
"%s (dump): address 0x%05lx is out of range for %s memory\n",
progname, addr, mem->desc); progname, addr, mem->desc);
return -1; return -1;
} }
@ -305,17 +304,17 @@ static int cmd_dump(PROGRAMMER * pgm, struct avrpart * p,
buf = malloc(len); buf = malloc(len);
if (buf == NULL) { if (buf == NULL) {
fprintf(stderr, "%s (dump): out of memory\n", progname); avrdude_message("%s (dump): out of memory\n", progname);
return -1; return -1;
} }
for (i=0; i<len; i++) { for (i=0; i<len; i++) {
rc = pgm->read_byte(pgm, p, mem, addr+i, &buf[i]); rc = pgm->read_byte(pgm, p, mem, addr+i, &buf[i]);
if (rc != 0) { if (rc != 0) {
fprintf(stderr, "error reading %s address 0x%05lx of part %s\n", avrdude_message("error reading %s address 0x%05lx of part %s\n",
mem->desc, addr+i, p->desc); mem->desc, addr+i, p->desc);
if (rc == -1) if (rc == -1)
fprintf(stderr, "read operation not supported on memory type \"%s\"\n", avrdude_message("read operation not supported on memory type \"%s\"\n",
mem->desc); mem->desc);
return -1; return -1;
} }
@ -347,7 +346,7 @@ static int cmd_write(PROGRAMMER * pgm, struct avrpart * p,
AVRMEM * mem; AVRMEM * mem;
if (argc < 4) { if (argc < 4) {
fprintf(stderr, "Usage: write <memtype> <addr> <byte1> " avrdude_message("Usage: write <memtype> <addr> <byte1> "
"<byte2> ... byteN>\n"); "<byte2> ... byteN>\n");
return -1; return -1;
} }
@ -356,7 +355,7 @@ static int cmd_write(PROGRAMMER * pgm, struct avrpart * p,
mem = avr_locate_mem(p, memtype); mem = avr_locate_mem(p, memtype);
if (mem == NULL) { if (mem == NULL) {
fprintf(stderr, "\"%s\" memory type not defined for part \"%s\"\n", avrdude_message("\"%s\" memory type not defined for part \"%s\"\n",
memtype, p->desc); memtype, p->desc);
return -1; return -1;
} }
@ -365,14 +364,13 @@ static int cmd_write(PROGRAMMER * pgm, struct avrpart * p,
addr = strtoul(argv[2], &e, 0); addr = strtoul(argv[2], &e, 0);
if (*e || (e == argv[2])) { if (*e || (e == argv[2])) {
fprintf(stderr, "%s (write): can't parse address \"%s\"\n", avrdude_message("%s (write): can't parse address \"%s\"\n",
progname, argv[2]); progname, argv[2]);
return -1; return -1;
} }
if (addr > maxsize) { if (addr > maxsize) {
fprintf(stderr, avrdude_message("%s (write): address 0x%05lx is out of range for %s memory\n",
"%s (write): address 0x%05lx is out of range for %s memory\n",
progname, addr, memtype); progname, addr, memtype);
return -1; return -1;
} }
@ -381,8 +379,7 @@ static int cmd_write(PROGRAMMER * pgm, struct avrpart * p,
len = argc - 3; len = argc - 3;
if ((addr + len) > maxsize) { if ((addr + len) > maxsize) {
fprintf(stderr, avrdude_message("%s (write): selected address and # bytes exceed "
"%s (write): selected address and # bytes exceed "
"range for %s memory\n", "range for %s memory\n",
progname, memtype); progname, memtype);
return -1; return -1;
@ -390,14 +387,14 @@ static int cmd_write(PROGRAMMER * pgm, struct avrpart * p,
buf = malloc(len); buf = malloc(len);
if (buf == NULL) { if (buf == NULL) {
fprintf(stderr, "%s (write): out of memory\n", progname); avrdude_message("%s (write): out of memory\n", progname);
return -1; return -1;
} }
for (i=3; i<argc; i++) { for (i=3; i<argc; i++) {
buf[i-3] = strtoul(argv[i], &e, 0); buf[i-3] = strtoul(argv[i], &e, 0);
if (*e || (e == argv[i])) { if (*e || (e == argv[i])) {
fprintf(stderr, "%s (write): can't parse byte \"%s\"\n", avrdude_message("%s (write): can't parse byte \"%s\"\n",
progname, argv[i]); progname, argv[i]);
free(buf); free(buf);
return -1; return -1;
@ -409,19 +406,17 @@ static int cmd_write(PROGRAMMER * pgm, struct avrpart * p,
rc = avr_write_byte(pgm, p, mem, addr+i, buf[i]); rc = avr_write_byte(pgm, p, mem, addr+i, buf[i]);
if (rc) { if (rc) {
fprintf(stderr, "%s (write): error writing 0x%02x at 0x%05lx, rc=%d\n", avrdude_message("%s (write): error writing 0x%02x at 0x%05lx, rc=%d\n",
progname, buf[i], addr+i, rc); progname, buf[i], addr+i, rc);
if (rc == -1) if (rc == -1)
fprintf(stderr, avrdude_message("write operation not supported on memory type \"%s\"\n",
"write operation not supported on memory type \"%s\"\n",
mem->desc); mem->desc);
werror = 1; werror = 1;
} }
rc = pgm->read_byte(pgm, p, mem, addr+i, &b); rc = pgm->read_byte(pgm, p, mem, addr+i, &b);
if (b != buf[i]) { if (b != buf[i]) {
fprintf(stderr, avrdude_message("%s (write): error writing 0x%02x at 0x%05lx cell=0x%02x\n",
"%s (write): error writing 0x%02x at 0x%05lx cell=0x%02x\n",
progname, buf[i], addr+i, b); progname, buf[i], addr+i, b);
werror = 1; werror = 1;
} }
@ -448,22 +443,20 @@ static int cmd_send(PROGRAMMER * pgm, struct avrpart * p,
int len; int len;
if (pgm->cmd == NULL) { if (pgm->cmd == NULL) {
fprintf(stderr, avrdude_message("The %s programmer does not support direct ISP commands.\n",
"The %s programmer does not support direct ISP commands.\n",
pgm->type); pgm->type);
return -1; return -1;
} }
if (spi_mode && (pgm->spi == NULL)) { if (spi_mode && (pgm->spi == NULL)) {
fprintf(stderr, avrdude_message("The %s programmer does not support direct SPI transfers.\n",
"The %s programmer does not support direct SPI transfers.\n",
pgm->type); pgm->type);
return -1; return -1;
} }
if ((argc > 5) || ((argc < 5) && (!spi_mode))) { if ((argc > 5) || ((argc < 5) && (!spi_mode))) {
fprintf(stderr, spi_mode? avrdude_message(spi_mode?
"Usage: send <byte1> [<byte2> [<byte3> [<byte4>]]]\n": "Usage: send <byte1> [<byte2> [<byte3> [<byte4>]]]\n":
"Usage: send <byte1> <byte2> <byte3> <byte4>\n"); "Usage: send <byte1> <byte2> <byte3> <byte4>\n");
return -1; return -1;
@ -476,7 +469,7 @@ static int cmd_send(PROGRAMMER * pgm, struct avrpart * p,
for (i=1; i<argc; i++) { for (i=1; i<argc; i++) {
cmd[i-1] = strtoul(argv[i], &e, 0); cmd[i-1] = strtoul(argv[i], &e, 0);
if (*e || (e == argv[i])) { if (*e || (e == argv[i])) {
fprintf(stderr, "%s (send): can't parse byte \"%s\"\n", avrdude_message("%s (send): can't parse byte \"%s\"\n",
progname, argv[i]); progname, argv[i]);
return -1; return -1;
} }
@ -492,10 +485,10 @@ static int cmd_send(PROGRAMMER * pgm, struct avrpart * p,
/* /*
* display results * display results
*/ */
fprintf(stderr, "results:"); avrdude_message("results:");
for (i=0; i<len; i++) for (i=0; i<len; i++)
fprintf(stderr, " %02x", res[i]); avrdude_message(" %02x", res[i]);
fprintf(stderr, "\n"); avrdude_message("\n");
fprintf(stdout, "\n"); fprintf(stdout, "\n");
@ -506,7 +499,7 @@ static int cmd_send(PROGRAMMER * pgm, struct avrpart * p,
static int cmd_erase(PROGRAMMER * pgm, struct avrpart * p, static int cmd_erase(PROGRAMMER * pgm, struct avrpart * p,
int argc, char * argv[]) int argc, char * argv[])
{ {
fprintf(stderr, "%s: erasing chip\n", progname); avrdude_message("%s: erasing chip\n", progname);
pgm->chip_erase(pgm, p); pgm->chip_erase(pgm, p);
return 0; return 0;
} }
@ -532,14 +525,13 @@ static int cmd_sig(PROGRAMMER * pgm, struct avrpart * p,
rc = avr_signature(pgm, p); rc = avr_signature(pgm, p);
if (rc != 0) { if (rc != 0) {
fprintf(stderr, "error reading signature data, rc=%d\n", avrdude_message("error reading signature data, rc=%d\n",
rc); rc);
} }
m = avr_locate_mem(p, "signature"); m = avr_locate_mem(p, "signature");
if (m == NULL) { if (m == NULL) {
fprintf(stderr, avrdude_message("signature data not defined for device \"%s\"\n",
"signature data not defined for device \"%s\"\n",
p->desc); p->desc);
} }
else { else {
@ -564,8 +556,7 @@ static int cmd_parms(PROGRAMMER * pgm, struct avrpart * p,
int argc, char * argv[]) int argc, char * argv[])
{ {
if (pgm->print_parms == NULL) { if (pgm->print_parms == NULL) {
fprintf(stderr, avrdude_message("%s (parms): the %s programmer does not support "
"%s (parms): the %s programmer does not support "
"adjustable parameters\n", "adjustable parameters\n",
progname, pgm->type); progname, pgm->type);
return -1; return -1;
@ -584,22 +575,22 @@ static int cmd_vtarg(PROGRAMMER * pgm, struct avrpart * p,
char *endp; char *endp;
if (argc != 2) { if (argc != 2) {
fprintf(stderr, "Usage: vtarg <value>\n"); avrdude_message("Usage: vtarg <value>\n");
return -1; return -1;
} }
v = strtod(argv[1], &endp); v = strtod(argv[1], &endp);
if (endp == argv[1]) { if (endp == argv[1]) {
fprintf(stderr, "%s (vtarg): can't parse voltage \"%s\"\n", avrdude_message("%s (vtarg): can't parse voltage \"%s\"\n",
progname, argv[1]); progname, argv[1]);
return -1; return -1;
} }
if (pgm->set_vtarget == NULL) { if (pgm->set_vtarget == NULL) {
fprintf(stderr, "%s (vtarg): the %s programmer cannot set V[target]\n", avrdude_message("%s (vtarg): the %s programmer cannot set V[target]\n",
progname, pgm->type); progname, pgm->type);
return -2; return -2;
} }
if ((rc = pgm->set_vtarget(pgm, v)) != 0) { if ((rc = pgm->set_vtarget(pgm, v)) != 0) {
fprintf(stderr, "%s (vtarg): failed to set V[target] (rc = %d)\n", avrdude_message("%s (vtarg): failed to set V[target] (rc = %d)\n",
progname, rc); progname, rc);
return -3; return -3;
} }
@ -615,7 +606,7 @@ static int cmd_fosc(PROGRAMMER * pgm, struct avrpart * p,
char *endp; char *endp;
if (argc != 2) { if (argc != 2) {
fprintf(stderr, "Usage: fosc <value>[M|k] | off\n"); avrdude_message("Usage: fosc <value>[M|k] | off\n");
return -1; return -1;
} }
v = strtod(argv[1], &endp); v = strtod(argv[1], &endp);
@ -623,7 +614,7 @@ static int cmd_fosc(PROGRAMMER * pgm, struct avrpart * p,
if (strcmp(argv[1], "off") == 0) if (strcmp(argv[1], "off") == 0)
v = 0.0; v = 0.0;
else { else {
fprintf(stderr, "%s (fosc): can't parse frequency \"%s\"\n", avrdude_message("%s (fosc): can't parse frequency \"%s\"\n",
progname, argv[1]); progname, argv[1]);
return -1; return -1;
} }
@ -633,13 +624,12 @@ static int cmd_fosc(PROGRAMMER * pgm, struct avrpart * p,
else if (*endp == 'k' || *endp == 'K') else if (*endp == 'k' || *endp == 'K')
v *= 1e3; v *= 1e3;
if (pgm->set_fosc == NULL) { if (pgm->set_fosc == NULL) {
fprintf(stderr, avrdude_message("%s (fosc): the %s programmer cannot set oscillator frequency\n",
"%s (fosc): the %s programmer cannot set oscillator frequency\n",
progname, pgm->type); progname, pgm->type);
return -2; return -2;
} }
if ((rc = pgm->set_fosc(pgm, v)) != 0) { if ((rc = pgm->set_fosc(pgm, v)) != 0) {
fprintf(stderr, "%s (fosc): failed to set oscillator_frequency (rc = %d)\n", avrdude_message("%s (fosc): failed to set oscillator_frequency (rc = %d)\n",
progname, rc); progname, rc);
return -3; return -3;
} }
@ -655,24 +645,23 @@ static int cmd_sck(PROGRAMMER * pgm, struct avrpart * p,
char *endp; char *endp;
if (argc != 2) { if (argc != 2) {
fprintf(stderr, "Usage: sck <value>\n"); avrdude_message("Usage: sck <value>\n");
return -1; return -1;
} }
v = strtod(argv[1], &endp); v = strtod(argv[1], &endp);
if (endp == argv[1]) { if (endp == argv[1]) {
fprintf(stderr, "%s (sck): can't parse period \"%s\"\n", avrdude_message("%s (sck): can't parse period \"%s\"\n",
progname, argv[1]); progname, argv[1]);
return -1; return -1;
} }
v *= 1e-6; /* Convert from microseconds to seconds. */ v *= 1e-6; /* Convert from microseconds to seconds. */
if (pgm->set_sck_period == NULL) { if (pgm->set_sck_period == NULL) {
fprintf(stderr, avrdude_message("%s (sck): the %s programmer cannot set SCK period\n",
"%s (sck): the %s programmer cannot set SCK period\n",
progname, pgm->type); progname, pgm->type);
return -2; return -2;
} }
if ((rc = pgm->set_sck_period(pgm, v)) != 0) { if ((rc = pgm->set_sck_period(pgm, v)) != 0) {
fprintf(stderr, "%s (sck): failed to set SCK period (rc = %d)\n", avrdude_message("%s (sck): failed to set SCK period (rc = %d)\n",
progname, rc); progname, rc);
return -3; return -3;
} }
@ -689,38 +678,38 @@ static int cmd_varef(PROGRAMMER * pgm, struct avrpart * p,
char *endp; char *endp;
if (argc != 2 && argc != 3) { if (argc != 2 && argc != 3) {
fprintf(stderr, "Usage: varef [channel] <value>\n"); avrdude_message("Usage: varef [channel] <value>\n");
return -1; return -1;
} }
if (argc == 2) { if (argc == 2) {
chan = 0; chan = 0;
v = strtod(argv[1], &endp); v = strtod(argv[1], &endp);
if (endp == argv[1]) { if (endp == argv[1]) {
fprintf(stderr, "%s (varef): can't parse voltage \"%s\"\n", avrdude_message("%s (varef): can't parse voltage \"%s\"\n",
progname, argv[1]); progname, argv[1]);
return -1; return -1;
} }
} else { } else {
chan = strtoul(argv[1], &endp, 10); chan = strtoul(argv[1], &endp, 10);
if (endp == argv[1]) { if (endp == argv[1]) {
fprintf(stderr, "%s (varef): can't parse channel \"%s\"\n", avrdude_message("%s (varef): can't parse channel \"%s\"\n",
progname, argv[1]); progname, argv[1]);
return -1; return -1;
} }
v = strtod(argv[2], &endp); v = strtod(argv[2], &endp);
if (endp == argv[2]) { if (endp == argv[2]) {
fprintf(stderr, "%s (varef): can't parse voltage \"%s\"\n", avrdude_message("%s (varef): can't parse voltage \"%s\"\n",
progname, argv[2]); progname, argv[2]);
return -1; return -1;
} }
} }
if (pgm->set_varef == NULL) { if (pgm->set_varef == NULL) {
fprintf(stderr, "%s (varef): the %s programmer cannot set V[aref]\n", avrdude_message("%s (varef): the %s programmer cannot set V[aref]\n",
progname, pgm->type); progname, pgm->type);
return -2; return -2;
} }
if ((rc = pgm->set_varef(pgm, chan, v)) != 0) { if ((rc = pgm->set_varef(pgm, chan, v)) != 0) {
fprintf(stderr, "%s (varef): failed to set V[aref] (rc = %d)\n", avrdude_message("%s (varef): failed to set V[aref] (rc = %d)\n",
progname, rc); progname, rc);
return -3; return -3;
} }
@ -770,26 +759,26 @@ static int cmd_verbose(PROGRAMMER * pgm, struct avrpart * p,
char *endp; char *endp;
if (argc != 1 && argc != 2) { if (argc != 1 && argc != 2) {
fprintf(stderr, "Usage: verbose [<value>]\n"); avrdude_message("Usage: verbose [<value>]\n");
return -1; return -1;
} }
if (argc == 1) { if (argc == 1) {
fprintf(stderr, "Verbosity level: %d\n", verbose); avrdude_message("Verbosity level: %d\n", verbose);
return 0; return 0;
} }
nverb = strtol(argv[1], &endp, 0); nverb = strtol(argv[1], &endp, 0);
if (endp == argv[2]) { if (endp == argv[2]) {
fprintf(stderr, "%s: can't parse verbosity level \"%s\"\n", avrdude_message("%s: can't parse verbosity level \"%s\"\n",
progname, argv[2]); progname, argv[2]);
return -1; return -1;
} }
if (nverb < 0) { if (nverb < 0) {
fprintf(stderr, "%s: verbosity level must be positive: %d\n", avrdude_message("%s: verbosity level must be positive: %d\n",
progname, nverb); progname, nverb);
return -1; return -1;
} }
verbose = nverb; verbose = nverb;
fprintf(stderr, "New verbosity level: %d\n", verbose); avrdude_message("New verbosity level: %d\n", verbose);
return 0; return 0;
} }
@ -886,7 +875,7 @@ static int do_cmd(PROGRAMMER * pgm, struct avrpart * p,
} }
else if (strncasecmp(argv[0], cmd[i].name, len)==0) { else if (strncasecmp(argv[0], cmd[i].name, len)==0) {
if (hold != -1) { if (hold != -1) {
fprintf(stderr, "%s: command \"%s\" is ambiguous\n", avrdude_message("%s: command \"%s\" is ambiguous\n",
progname, argv[0]); progname, argv[0]);
return -1; return -1;
} }
@ -897,7 +886,7 @@ static int do_cmd(PROGRAMMER * pgm, struct avrpart * p,
if (hold != -1) if (hold != -1)
return cmd[hold].func(pgm, p, argc, argv); return cmd[hold].func(pgm, p, argc, argv);
fprintf(stderr, "%s: invalid command \"%s\"\n", avrdude_message("%s: invalid command \"%s\"\n",
progname, argv[0]); progname, argv[0]);
return -1; return -1;

View File

@ -42,7 +42,7 @@ UPDATE * parse_op(char * s)
upd = (UPDATE *)malloc(sizeof(UPDATE)); upd = (UPDATE *)malloc(sizeof(UPDATE));
if (upd == NULL) { if (upd == NULL) {
fprintf(stderr, "%s: out of memory\n", progname); avrdude_message("%s: out of memory\n", progname);
exit(1); exit(1);
} }
@ -57,7 +57,7 @@ UPDATE * parse_op(char * s)
upd->op = DEVICE_WRITE; upd->op = DEVICE_WRITE;
upd->filename = (char *)malloc(strlen(buf) + 1); upd->filename = (char *)malloc(strlen(buf) + 1);
if (upd->filename == NULL) { if (upd->filename == NULL) {
fprintf(stderr, "%s: out of memory\n", progname); avrdude_message("%s: out of memory\n", progname);
exit(1); exit(1);
} }
strcpy(upd->filename, buf); strcpy(upd->filename, buf);
@ -67,7 +67,7 @@ UPDATE * parse_op(char * s)
upd->memtype = (char *)malloc(strlen(buf)+1); upd->memtype = (char *)malloc(strlen(buf)+1);
if (upd->memtype == NULL) { if (upd->memtype == NULL) {
fprintf(stderr, "%s: out of memory\n", progname); avrdude_message("%s: out of memory\n", progname);
exit(1); exit(1);
} }
strcpy(upd->memtype, buf); strcpy(upd->memtype, buf);
@ -83,10 +83,9 @@ UPDATE * parse_op(char * s)
upd->op = DEVICE_VERIFY; upd->op = DEVICE_VERIFY;
} }
else { else {
fprintf(stderr, "%s: invalid I/O mode '%c' in update specification\n", avrdude_message("%s: invalid I/O mode '%c' in update specification\n",
progname, *p); progname, *p);
fprintf(stderr, avrdude_message(" allowed values are:\n"
" 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");
@ -98,7 +97,7 @@ UPDATE * parse_op(char * s)
p++; p++;
if (*p != ':') { if (*p != ':') {
fprintf(stderr, "%s: invalid update specification\n", progname); avrdude_message("%s: invalid update specification\n", progname);
free(upd->memtype); free(upd->memtype);
free(upd); free(upd);
return NULL; return NULL;
@ -140,7 +139,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:
fprintf(stderr, "%s: invalid file format '%s' in update specifier\n", avrdude_message("%s: invalid file format '%s' in update specifier\n",
progname, p); progname, p);
free(upd->memtype); free(upd->memtype);
free(upd); free(upd);
@ -149,7 +148,7 @@ UPDATE * parse_op(char * s)
} }
if (upd->filename == NULL) { if (upd->filename == NULL) {
fprintf(stderr, "%s: out of memory\n", progname); avrdude_message("%s: out of memory\n", progname);
free(upd->memtype); free(upd->memtype);
free(upd); free(upd);
return NULL; return NULL;
@ -166,7 +165,7 @@ UPDATE * dup_update(UPDATE * upd)
u = (UPDATE *)malloc(sizeof(UPDATE)); u = (UPDATE *)malloc(sizeof(UPDATE));
if (u == NULL) { if (u == NULL) {
fprintf(stderr, "%s: out of memory\n", progname); avrdude_message("%s: out of memory\n", progname);
exit(1); exit(1);
} }
@ -187,7 +186,7 @@ UPDATE * new_update(int op, char * memtype, int filefmt, char * filename)
u = (UPDATE *)malloc(sizeof(UPDATE)); u = (UPDATE *)malloc(sizeof(UPDATE));
if (u == NULL) { if (u == NULL) {
fprintf(stderr, "%s: out of memory\n", progname); avrdude_message("%s: out of memory\n", progname);
exit(1); exit(1);
} }
@ -224,7 +223,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) {
fprintf(stderr, "\"%s\" memory type not defined for part \"%s\"\n", avrdude_message("\"%s\" memory type not defined for part \"%s\"\n",
upd->memtype, p->desc); upd->memtype, p->desc);
return -1; return -1;
} }
@ -234,13 +233,13 @@ int do_op(PROGRAMMER * pgm, struct avrpart * p, UPDATE * upd, enum updateflags f
* read out the specified device memory and write it to a file * read out the specified device memory and write it to a file
*/ */
if (quell_progress < 2) { if (quell_progress < 2) {
fprintf(stderr, "%s: reading %s memory:\n", avrdude_message("%s: reading %s memory:\n",
progname, mem->desc); progname, 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);
if (rc < 0) { if (rc < 0) {
fprintf(stderr, "%s: failed to read all of %s memory, rc=%d\n", avrdude_message("%s: failed to read all of %s memory, rc=%d\n",
progname, mem->desc, rc); progname, mem->desc, rc);
return -1; return -1;
} }
@ -248,14 +247,13 @@ int do_op(PROGRAMMER * pgm, struct avrpart * p, UPDATE * upd, enum updateflags f
size = rc; size = rc;
if (quell_progress < 2) { if (quell_progress < 2) {
fprintf(stderr, avrdude_message("%s: writing output file \"%s\"\n",
"%s: writing output file \"%s\"\n",
progname, progname,
strcmp(upd->filename, "-")==0 ? "<stdout>" : upd->filename); strcmp(upd->filename, "-")==0 ? "<stdout>" : upd->filename);
} }
rc = fileio(FIO_WRITE, upd->filename, upd->format, p, upd->memtype, size); rc = fileio(FIO_WRITE, upd->filename, upd->format, p, upd->memtype, size);
if (rc < 0) { if (rc < 0) {
fprintf(stderr, "%s: write to file '%s' failed\n", avrdude_message("%s: write to file '%s' failed\n",
progname, upd->filename); progname, upd->filename);
return -1; return -1;
} }
@ -266,14 +264,13 @@ int do_op(PROGRAMMER * pgm, struct avrpart * p, UPDATE * upd, enum updateflags f
* read the data from the specified file * read the data from the specified file
*/ */
if (quell_progress < 2) { if (quell_progress < 2) {
fprintf(stderr, avrdude_message("%s: reading input file \"%s\"\n",
"%s: reading input file \"%s\"\n",
progname, progname,
strcmp(upd->filename, "-")==0 ? "<stdin>" : upd->filename); strcmp(upd->filename, "-")==0 ? "<stdin>" : upd->filename);
} }
rc = fileio(FIO_READ, upd->filename, upd->format, p, upd->memtype, -1); rc = fileio(FIO_READ, upd->filename, upd->format, p, upd->memtype, -1);
if (rc < 0) { if (rc < 0) {
fprintf(stderr, "%s: read from file '%s' failed\n", avrdude_message("%s: read from file '%s' failed\n",
progname, upd->filename); progname, upd->filename);
return -1; return -1;
} }
@ -283,7 +280,7 @@ int do_op(PROGRAMMER * pgm, struct avrpart * p, UPDATE * upd, enum updateflags f
* write the buffer contents to the selected memory type * write the buffer contents to the selected memory type
*/ */
if (quell_progress < 2) { if (quell_progress < 2) {
fprintf(stderr, "%s: writing %s (%d bytes):\n", avrdude_message("%s: writing %s (%d bytes):\n",
progname, mem->desc, size); progname, mem->desc, size);
} }
@ -301,7 +298,7 @@ int do_op(PROGRAMMER * pgm, struct avrpart * p, UPDATE * upd, enum updateflags f
} }
if (rc < 0) { if (rc < 0) {
fprintf(stderr, "%s: failed to write %s memory, rc=%d\n", avrdude_message("%s: failed to write %s memory, rc=%d\n",
progname, mem->desc, rc); progname, mem->desc, rc);
return -1; return -1;
} }
@ -309,7 +306,7 @@ int do_op(PROGRAMMER * pgm, struct avrpart * p, UPDATE * upd, enum updateflags f
vsize = rc; vsize = rc;
if (quell_progress < 2) { if (quell_progress < 2) {
fprintf(stderr, "%s: %d bytes of %s written\n", progname, avrdude_message("%s: %d bytes of %s written\n", progname,
vsize, mem->desc); vsize, mem->desc);
} }
@ -322,32 +319,32 @@ int do_op(PROGRAMMER * pgm, struct avrpart * p, UPDATE * upd, enum updateflags f
pgm->vfy_led(pgm, ON); pgm->vfy_led(pgm, ON);
if (quell_progress < 2) { if (quell_progress < 2) {
fprintf(stderr, "%s: verifying %s memory against %s:\n", avrdude_message("%s: verifying %s memory against %s:\n",
progname, mem->desc, upd->filename); progname, mem->desc, upd->filename);
fprintf(stderr, "%s: load data %s data from input file %s:\n", avrdude_message("%s: load data %s data from input file %s:\n",
progname, mem->desc, upd->filename); progname, mem->desc, upd->filename);
} }
rc = fileio(FIO_READ, upd->filename, upd->format, p, upd->memtype, -1); rc = fileio(FIO_READ, upd->filename, upd->format, p, upd->memtype, -1);
if (rc < 0) { if (rc < 0) {
fprintf(stderr, "%s: read from file '%s' failed\n", avrdude_message("%s: read from file '%s' failed\n",
progname, upd->filename); progname, upd->filename);
return -1; return -1;
} }
v = avr_dup_part(p); v = avr_dup_part(p);
size = rc; size = rc;
if (quell_progress < 2) { if (quell_progress < 2) {
fprintf(stderr, "%s: input file %s contains %d bytes\n", avrdude_message("%s: input file %s contains %d bytes\n",
progname, upd->filename, size); progname, upd->filename, size);
fprintf(stderr, "%s: reading on-chip %s data:\n", avrdude_message("%s: reading on-chip %s data:\n",
progname, mem->desc); progname, 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);
if (rc < 0) { if (rc < 0) {
fprintf(stderr, "%s: failed to read all of %s memory, rc=%d\n", avrdude_message("%s: failed to read all of %s memory, rc=%d\n",
progname, mem->desc, rc); progname, mem->desc, rc);
pgm->err_led(pgm, ON); pgm->err_led(pgm, ON);
return -1; return -1;
@ -357,25 +354,25 @@ int do_op(PROGRAMMER * pgm, struct avrpart * p, UPDATE * upd, enum updateflags f
if (quell_progress < 2) { if (quell_progress < 2) {
fprintf(stderr, "%s: verifying ...\n", progname); avrdude_message("%s: verifying ...\n", progname);
} }
rc = avr_verify(p, v, upd->memtype, size); rc = avr_verify(p, v, upd->memtype, size);
if (rc < 0) { if (rc < 0) {
fprintf(stderr, "%s: verification error; content mismatch\n", avrdude_message("%s: verification error; content mismatch\n",
progname); progname);
pgm->err_led(pgm, ON); pgm->err_led(pgm, ON);
return -1; return -1;
} }
if (quell_progress < 2) { if (quell_progress < 2) {
fprintf(stderr, "%s: %d bytes of %s verified\n", avrdude_message("%s: %d bytes of %s verified\n",
progname, rc, mem->desc); progname, rc, mem->desc);
} }
pgm->vfy_led(pgm, OFF); pgm->vfy_led(pgm, OFF);
} }
else { else {
fprintf(stderr, "%s: invalid update operation (%d) requested\n", avrdude_message("%s: invalid update operation (%d) requested\n",
progname, upd->op); progname, upd->op);
return -1; return -1;
} }

View File

@ -97,8 +97,7 @@ static int usbdev_open(char * port, union pinfo pinfo, union filedescriptor *fd)
if (strlen(serno) > 12) if (strlen(serno) > 12)
{ {
fprintf(stderr, avrdude_message("%s: usbdev_open(): invalid serial number \"%s\"\n",
"%s: usbdev_open(): invalid serial number \"%s\"\n",
progname, serno); progname, serno);
return -1; return -1;
} }
@ -127,8 +126,7 @@ static int usbdev_open(char * port, union pinfo pinfo, union filedescriptor *fd)
dev->descriptor.iSerialNumber, dev->descriptor.iSerialNumber,
string, sizeof(string)) < 0) string, sizeof(string)) < 0)
{ {
fprintf(stderr, avrdude_message("%s: usb_open(): cannot read serial number \"%s\"\n",
"%s: usb_open(): cannot read serial number \"%s\"\n",
progname, usb_strerror()); progname, usb_strerror());
/* /*
* On some systems, libusb appears to have * On some systems, libusb appears to have
@ -147,8 +145,7 @@ static int usbdev_open(char * port, union pinfo pinfo, union filedescriptor *fd)
dev->descriptor.iProduct, dev->descriptor.iProduct,
product, sizeof(product)) < 0) product, sizeof(product)) < 0)
{ {
fprintf(stderr, avrdude_message("%s: usb_open(): cannot read product name \"%s\"\n",
"%s: usb_open(): cannot read product name \"%s\"\n",
progname, usb_strerror()); progname, usb_strerror());
strcpy(product, "[unnamed product]"); strcpy(product, "[unnamed product]");
} }
@ -169,8 +166,7 @@ static int usbdev_open(char * port, union pinfo pinfo, union filedescriptor *fd)
} }
if (verbose) if (verbose)
fprintf(stderr, avrdude_message("%s: usbdev_open(): Found %s, serno: %s\n",
"%s: usbdev_open(): Found %s, serno: %s\n",
progname, product, string); progname, product, string);
if (serno != NULL) if (serno != NULL)
{ {
@ -183,8 +179,7 @@ static int usbdev_open(char * port, union pinfo pinfo, union filedescriptor *fd)
if (strcasecmp(string + x, serno) != 0) if (strcasecmp(string + x, serno) != 0)
{ {
if (verbose > 2) if (verbose > 2)
fprintf(stderr, avrdude_message("%s: usbdev_open(): serial number doesn't match\n",
"%s: usbdev_open(): serial number doesn't match\n",
progname); progname);
usb_close(udev); usb_close(udev);
continue; continue;
@ -193,16 +188,14 @@ static int usbdev_open(char * port, union pinfo pinfo, union filedescriptor *fd)
if (dev->config == NULL) if (dev->config == NULL)
{ {
fprintf(stderr, avrdude_message("%s: usbdev_open(): USB device has no configuration\n",
"%s: usbdev_open(): USB device has no configuration\n",
progname); progname);
goto trynext; goto trynext;
} }
if (usb_set_configuration(udev, dev->config[0].bConfigurationValue)) if (usb_set_configuration(udev, dev->config[0].bConfigurationValue))
{ {
fprintf(stderr, avrdude_message("%s: usbdev_open(): WARNING: failed to set configuration %d: %s\n",
"%s: usbdev_open(): WARNING: failed to set configuration %d: %s\n",
progname, dev->config[0].bConfigurationValue, progname, dev->config[0].bConfigurationValue,
usb_strerror()); usb_strerror());
/* let's hope it has already been configured */ /* let's hope it has already been configured */
@ -223,8 +216,7 @@ static int usbdev_open(char * port, union pinfo pinfo, union filedescriptor *fd)
#endif #endif
if (usb_claim_interface(udev, usb_interface)) if (usb_claim_interface(udev, usb_interface))
{ {
fprintf(stderr, avrdude_message("%s: usbdev_open(): error claiming interface %d: %s\n",
"%s: usbdev_open(): error claiming interface %d: %s\n",
progname, usb_interface, usb_strerror()); progname, usb_interface, usb_strerror());
} }
else else
@ -242,8 +234,7 @@ static int usbdev_open(char * port, union pinfo pinfo, union filedescriptor *fd)
} }
if (iface == dev->config[0].bNumInterfaces) if (iface == dev->config[0].bNumInterfaces)
{ {
fprintf(stderr, avrdude_message("%s: usbdev_open(): no usable interface found\n",
"%s: usbdev_open(): no usable interface found\n",
progname); progname);
goto trynext; goto trynext;
} }
@ -261,8 +252,7 @@ static int usbdev_open(char * port, union pinfo pinfo, union filedescriptor *fd)
{ {
if (verbose > 1) if (verbose > 1)
{ {
fprintf(stderr, avrdude_message("%s: usbdev_open(): using read endpoint 0x%02x\n",
"%s: usbdev_open(): using read endpoint 0x%02x\n",
progname, possible_ep); progname, possible_ep);
} }
fd->usb.rep = possible_ep; fd->usb.rep = possible_ep;
@ -271,8 +261,7 @@ static int usbdev_open(char * port, union pinfo pinfo, union filedescriptor *fd)
} }
if (fd->usb.rep == 0) if (fd->usb.rep == 0)
{ {
fprintf(stderr, avrdude_message("%s: usbdev_open(): cannot find a read endpoint, using 0x%02x\n",
"%s: usbdev_open(): cannot find a read endpoint, using 0x%02x\n",
progname, USBDEV_BULK_EP_READ_MKII); progname, USBDEV_BULK_EP_READ_MKII);
fd->usb.rep = USBDEV_BULK_EP_READ_MKII; fd->usb.rep = USBDEV_BULK_EP_READ_MKII;
} }
@ -284,8 +273,7 @@ static int usbdev_open(char * port, union pinfo pinfo, union filedescriptor *fd)
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)
{ {
if (verbose != 0) if (verbose != 0)
fprintf(stderr, avrdude_message("%s: max packet size expected %d, but found %d due to EP 0x%02x's wMaxPacketSize\n",
"%s: max packet size expected %d, but found %d due to EP 0x%02x's wMaxPacketSize\n",
progname, 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,
@ -296,22 +284,21 @@ static int usbdev_open(char * port, union pinfo pinfo, union filedescriptor *fd)
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)
fprintf(stderr, "%s: usbdev_open(): SET_IDLE failed\n", progname); avrdude_message("%s: usbdev_open(): SET_IDLE failed\n", progname);
} }
return 0; return 0;
trynext: trynext:
usb_close(udev); usb_close(udev);
} }
else else
fprintf(stderr, avrdude_message("%s: usbdev_open(): cannot open device: %s\n",
"%s: usbdev_open(): cannot open device: %s\n",
progname, usb_strerror()); progname, usb_strerror());
} }
} }
} }
if ((pinfo.usbinfo.flags & PINFO_FL_SILENT) == 0 || verbose > 0) if ((pinfo.usbinfo.flags & PINFO_FL_SILENT) == 0 || verbose > 0)
fprintf(stderr, "%s: usbdev_open(): did not find any%s USB device \"%s\" (0x%04x:0x%04x)\n", avrdude_message("%s: usbdev_open(): did not find any%s USB device \"%s\" (0x%04x:0x%04x)\n",
progname, serno? " (matching)": "", port, progname, serno? " (matching)": "", port,
(unsigned)pinfo.usbinfo.vid, (unsigned)pinfo.usbinfo.pid); (unsigned)pinfo.usbinfo.vid, (unsigned)pinfo.usbinfo.pid);
return -1; return -1;
@ -365,7 +352,7 @@ static int usbdev_send(union filedescriptor *fd, unsigned char *bp, size_t mlen)
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)
{ {
fprintf(stderr, "%s: usbdev_send(): wrote %d out of %d bytes, err = %s\n", avrdude_message("%s: usbdev_send(): wrote %d out of %d bytes, err = %s\n",
progname, rv, tx_size, usb_strerror()); progname, rv, tx_size, usb_strerror());
return -1; return -1;
} }
@ -375,22 +362,22 @@ static int usbdev_send(union filedescriptor *fd, unsigned char *bp, size_t mlen)
if (verbose > 3) if (verbose > 3)
{ {
fprintf(stderr, "%s: Sent: ", progname); avrdude_message("%s: Sent: ", progname);
while (i) { while (i) {
unsigned char c = *p; unsigned char c = *p;
if (isprint(c)) { if (isprint(c)) {
fprintf(stderr, "%c ", c); avrdude_message("%c ", c);
} }
else { else {
fprintf(stderr, ". "); avrdude_message(". ");
} }
fprintf(stderr, "[%02x] ", c); avrdude_message("[%02x] ", c);
p++; p++;
i--; i--;
} }
fprintf(stderr, "\n"); avrdude_message("\n");
} }
return 0; return 0;
} }
@ -415,7 +402,7 @@ usb_fill_buf(usb_dev_handle *udev, int maxsize, int ep, int use_interrupt_xfer)
if (rv < 0) if (rv < 0)
{ {
if (verbose > 1) if (verbose > 1)
fprintf(stderr, "%s: usb_fill_buf(): usb_%s_read() error %s\n", avrdude_message("%s: usb_fill_buf(): usb_%s_read() error %s\n",
progname, (use_interrupt_xfer? "interrupt": "bulk"), progname, (use_interrupt_xfer? "interrupt": "bulk"),
usb_strerror()); usb_strerror());
return -1; return -1;
@ -452,22 +439,22 @@ static int usbdev_recv(union filedescriptor *fd, unsigned char *buf, size_t nbyt
if (verbose > 4) if (verbose > 4)
{ {
fprintf(stderr, "%s: Recv: ", progname); avrdude_message("%s: Recv: ", progname);
while (i) { while (i) {
unsigned char c = *p; unsigned char c = *p;
if (isprint(c)) { if (isprint(c)) {
fprintf(stderr, "%c ", c); avrdude_message("%c ", c);
} }
else { else {
fprintf(stderr, ". "); avrdude_message(". ");
} }
fprintf(stderr, "[%02x] ", c); avrdude_message("[%02x] ", c);
p++; p++;
i--; i--;
} }
fprintf(stderr, "\n"); avrdude_message("\n");
} }
return 0; return 0;
@ -506,7 +493,7 @@ static int usbdev_recv_frame(union filedescriptor *fd, unsigned char *buf, size_
} }
else if (rv > 0) else if (rv > 0)
{ {
fprintf(stderr, "Short event len = %d, ignored.\n", rv); avrdude_message("Short event len = %d, ignored.\n", rv);
/* fallthrough */ /* fallthrough */
} }
} }
@ -523,7 +510,7 @@ static int usbdev_recv_frame(union filedescriptor *fd, unsigned char *buf, size_
if (rv < 0) if (rv < 0)
{ {
if (verbose > 1) if (verbose > 1)
fprintf(stderr, "%s: usbdev_recv_frame(): usb_%s_read(): %s\n", avrdude_message("%s: usbdev_recv_frame(): usb_%s_read(): %s\n",
progname, (fd->usb.use_interrupt_xfer? "interrupt": "bulk"), progname, (fd->usb.use_interrupt_xfer? "interrupt": "bulk"),
usb_strerror()); usb_strerror());
return -1; return -1;
@ -547,22 +534,22 @@ static int usbdev_recv_frame(union filedescriptor *fd, unsigned char *buf, size_
if (verbose > 3) if (verbose > 3)
{ {
i = n & USB_RECV_LENGTH_MASK; i = n & USB_RECV_LENGTH_MASK;
fprintf(stderr, "%s: Recv: ", progname); avrdude_message("%s: Recv: ", progname);
while (i) { while (i) {
unsigned char c = *p; unsigned char c = *p;
if (isprint(c)) { if (isprint(c)) {
fprintf(stderr, "%c ", c); avrdude_message("%c ", c);
} }
else { else {
fprintf(stderr, ". "); avrdude_message(". ");
} }
fprintf(stderr, "[%02x] ", c); avrdude_message("[%02x] ", c);
p++; p++;
i--; i--;
} }
fprintf(stderr, "\n"); avrdude_message("\n");
} }
return n; return n;
} }
@ -581,7 +568,7 @@ static int usbdev_drain(union filedescriptor *fd, int display)
else else
rv = usb_bulk_read(udev, fd->usb.rep, usbbuf, fd->usb.max_xfer, 100); rv = usb_bulk_read(udev, fd->usb.rep, usbbuf, fd->usb.max_xfer, 100);
if (rv > 0 && verbose >= 4) if (rv > 0 && verbose >= 4)
fprintf(stderr, "%s: usbdev_drain(): flushed %d characters\n", avrdude_message("%s: usbdev_drain(): flushed %d characters\n",
progname, rv); progname, rv);
} while (rv > 0); } while (rv > 0);

148
usbasp.c
View File

@ -180,8 +180,7 @@ static int usbasp_tpi_write_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, unsi
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) {
fprintf(stderr, avrdude_message("%s: usbasp_setup(): Out of memory allocating private data\n",
"%s: usbasp_setup(): Out of memory allocating private data\n",
progname); progname);
exit(1); exit(1);
} }
@ -230,16 +229,15 @@ static int usbasp_transmit(PROGRAMMER * pgm,
int nbytes; int nbytes;
if (verbose > 3) { if (verbose > 3) {
fprintf(stderr, avrdude_message("%s: usbasp_transmit(\"%s\", 0x%02x, 0x%02x, 0x%02x, 0x%02x)\n",
"%s: usbasp_transmit(\"%s\", 0x%02x, 0x%02x, 0x%02x, 0x%02x)\n",
progname, 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;
fprintf(stderr, "%s => ", progbuf); avrdude_message("%s => ", progbuf);
for (i = 0; i < buffersize; i++) for (i = 0; i < buffersize; i++)
fprintf(stderr, "[%02x] ", buffer[i]); avrdude_message("[%02x] ", buffer[i]);
fprintf(stderr, "\n"); avrdude_message("\n");
} }
} }
@ -253,7 +251,7 @@ static int usbasp_transmit(PROGRAMMER * pgm,
buffersize & 0xffff, buffersize & 0xffff,
5000); 5000);
if(nbytes < 0){ if(nbytes < 0){
fprintf(stderr, "%s: error: usbasp_transmit: %s\n", progname, strerror(libusb_to_errno(nbytes))); avrdude_message("%s: error: usbasp_transmit: %s\n", progname, strerror(libusb_to_errno(nbytes)));
return -1; return -1;
} }
#else #else
@ -265,17 +263,17 @@ static int usbasp_transmit(PROGRAMMER * pgm,
(char *)buffer, buffersize, (char *)buffer, buffersize,
5000); 5000);
if(nbytes < 0){ if(nbytes < 0){
fprintf(stderr, "%s: error: usbasp_transmit: %s\n", progname, usb_strerror()); avrdude_message("%s: error: usbasp_transmit: %s\n", progname, usb_strerror());
return -1; return -1;
} }
#endif #endif
if (verbose > 3 && receive && nbytes > 0) { if (verbose > 3 && receive && nbytes > 0) {
int i; int i;
fprintf(stderr, "%s<= ", progbuf); avrdude_message("%s<= ", progbuf);
for (i = 0; i < nbytes; i++) for (i = 0; i < nbytes; i++)
fprintf(stderr, "[%02x] ", buffer[i]); avrdude_message("[%02x] ", buffer[i]);
fprintf(stderr, "\n"); avrdude_message("\n");
} }
return nbytes; return nbytes;
@ -316,8 +314,7 @@ 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;
fprintf(stderr, avrdude_message("%s: Warning: cannot open USB device: %s\n",
"%s: Warning: cannot open USB device: %s\n",
progname, strerror(libusb_to_errno(r))); progname, strerror(libusb_to_errno(r)));
continue; continue;
} }
@ -328,14 +325,12 @@ 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;
fprintf(stderr, avrdude_message("%s: Warning: cannot query manufacturer for device: %s\n",
"%s: Warning: cannot query manufacturer for device: %s\n",
progname, strerror(libusb_to_errno(r))); progname, strerror(libusb_to_errno(r)));
} }
} else { } else {
if (verbose > 1) if (verbose > 1)
fprintf(stderr, avrdude_message("%s: seen device from vendor ->%s<-\n",
"%s: seen device from vendor ->%s<-\n",
progname, 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;
@ -345,14 +340,12 @@ 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;
fprintf(stderr, avrdude_message("%s: Warning: cannot query product for device: %s\n",
"%s: Warning: cannot query product for device: %s\n",
progname, strerror(libusb_to_errno(r))); progname, strerror(libusb_to_errno(r)));
} }
} else { } else {
if (verbose > 1) if (verbose > 1)
fprintf(stderr, avrdude_message("%s: seen product ->%s<-\n",
"%s: seen product ->%s<-\n",
progname, 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;
@ -396,8 +389,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;
fprintf(stderr, avrdude_message("%s: Warning: cannot open USB device: %s\n",
"%s: Warning: cannot open USB device: %s\n",
progname, usb_strerror()); progname, usb_strerror());
continue; continue;
} }
@ -409,14 +401,12 @@ 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;
fprintf(stderr, avrdude_message("%s: Warning: cannot query manufacturer for device: %s\n",
"%s: Warning: cannot query manufacturer for device: %s\n",
progname, usb_strerror()); progname, usb_strerror());
} }
} else { } else {
if (verbose > 1) if (verbose > 1)
fprintf(stderr, avrdude_message("%s: seen device from vendor ->%s<-\n",
"%s: seen device from vendor ->%s<-\n",
progname, 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;
@ -427,14 +417,12 @@ 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;
fprintf(stderr, avrdude_message("%s: Warning: cannot query product for device: %s\n",
"%s: Warning: cannot query product for device: %s\n",
progname, usb_strerror()); progname, usb_strerror());
} }
} else { } else {
if (verbose > 1) if (verbose > 1)
fprintf(stderr, avrdude_message("%s: seen product ->%s<-\n",
"%s: seen product ->%s<-\n",
progname, 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;
@ -461,7 +449,7 @@ static int didUsbInit = 0;
static int usbasp_open(PROGRAMMER * pgm, char * port) static int usbasp_open(PROGRAMMER * pgm, char * port)
{ {
if (verbose > 2) if (verbose > 2)
fprintf(stderr, "%s: usbasp_open(\"%s\")\n", avrdude_message("%s: usbasp_open(\"%s\")\n",
progname, port); progname, port);
/* usb_init will be done in usbOpenDevice */ /* usb_init will be done in usbOpenDevice */
@ -470,8 +458,7 @@ static int usbasp_open(PROGRAMMER * pgm, char * port)
if (usbpid) { if (usbpid) {
pid = *(int *)(ldata(usbpid)); pid = *(int *)(ldata(usbpid));
if (lnext(usbpid)) if (lnext(usbpid))
fprintf(stderr, avrdude_message("%s: Warning: using PID 0x%04x, ignoring remaining PIDs in list\n",
"%s: Warning: using PID 0x%04x, ignoring remaining PIDs in list\n",
progname, pid); progname, pid);
} else { } else {
pid = USBASP_SHARED_PID; pid = USBASP_SHARED_PID;
@ -482,14 +469,12 @@ static int usbasp_open(PROGRAMMER * pgm, 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) {
fprintf(stderr, avrdude_message("%s: warning: Using \"-C usbasp -P nibobee\" is deprecated,"
"%s: warning: Using \"-C usbasp -P nibobee\" is deprecated,"
"use \"-C nibobee\" instead.\n", "use \"-C nibobee\" instead.\n",
progname); 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) {
fprintf(stderr, avrdude_message("%s: error: could not find USB device "
"%s: error: could not find USB device "
"\"NIBObee\" with vid=0x%x pid=0x%x\n", "\"NIBObee\" with vid=0x%x pid=0x%x\n",
progname, USBASP_NIBOBEE_VID, USBASP_NIBOBEE_PID); progname, USBASP_NIBOBEE_VID, USBASP_NIBOBEE_PID);
return -1; return -1;
@ -500,8 +485,7 @@ static int usbasp_open(PROGRAMMER * pgm, 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 */
fprintf(stderr, avrdude_message("%s: Warning: Found USB device \"USBasp\" with "
"%s: Warning: Found USB device \"USBasp\" with "
"old VID/PID! Please update firmware of USBasp!\n", "old VID/PID! Please update firmware of USBasp!\n",
progname); progname);
return 0; return 0;
@ -510,16 +494,15 @@ static int usbasp_open(PROGRAMMER * pgm, char * port)
/* no alternative found => fall through to generic error message */ /* no alternative found => fall through to generic error message */
} }
fprintf(stderr, avrdude_message("%s: error: could not find USB device with vid=0x%x pid=0x%x",
"%s: error: could not find USB device with vid=0x%x pid=0x%x",
progname, vid, pid); progname, vid, pid);
if (pgm->usbvendor[0] != 0) { if (pgm->usbvendor[0] != 0) {
fprintf(stderr, " vendor='%s'", pgm->usbvendor); avrdude_message(" vendor='%s'", pgm->usbvendor);
} }
if (pgm->usbproduct[0] != 0) { if (pgm->usbproduct[0] != 0) {
fprintf(stderr, " product='%s'", pgm->usbproduct); avrdude_message(" product='%s'", pgm->usbproduct);
} }
fprintf(stderr,"\n"); avrdude_message("\n");
return -1; return -1;
} }
@ -529,7 +512,7 @@ static int usbasp_open(PROGRAMMER * pgm, char * port)
static void usbasp_close(PROGRAMMER * pgm) static void usbasp_close(PROGRAMMER * pgm)
{ {
if (verbose > 2) if (verbose > 2)
fprintf(stderr, "%s: usbasp_close()\n", progname); avrdude_message("%s: usbasp_close()\n", progname);
if (PDATA(pgm)->usbhandle!=NULL) { if (PDATA(pgm)->usbhandle!=NULL) {
unsigned char temp[4]; unsigned char temp[4];
@ -584,7 +567,7 @@ static int usbasp_initialize(PROGRAMMER * pgm, AVRPART * p)
IMPORT_PDATA(pgm); IMPORT_PDATA(pgm);
if (verbose > 2) if (verbose > 2)
fprintf(stderr, "%s: usbasp_initialize()\n", progname); avrdude_message("%s: usbasp_initialize()\n", progname);
/* get capabilities */ /* get capabilities */
memset(temp, 0, sizeof(temp)); memset(temp, 0, sizeof(temp));
@ -649,7 +632,7 @@ static int usbasp_spi_cmd(PROGRAMMER * pgm, const unsigned char *cmd,
unsigned char *res) unsigned char *res)
{ {
if (verbose > 2) if (verbose > 2)
fprintf(stderr, "%s: usbasp_cpi_cmd(0x%02x, 0x%02x, 0x%02x, 0x%02x)%s", avrdude_message("%s: usbasp_cpi_cmd(0x%02x, 0x%02x, 0x%02x, 0x%02x)%s",
progname, cmd[0], cmd[1], cmd[2], cmd[3], progname, cmd[0], cmd[1], cmd[2], cmd[3],
verbose > 3? "...\n": ""); verbose > 3? "...\n": "");
@ -660,14 +643,14 @@ static int usbasp_spi_cmd(PROGRAMMER * pgm, const unsigned char *cmd,
if (verbose == 3) if (verbose == 3)
putc('\n', stderr); putc('\n', stderr);
fprintf(stderr, "%s: error: wrong responds size\n", avrdude_message("%s: error: wrong responds size\n",
progname); progname);
return -1; return -1;
} }
if (verbose > 2) { if (verbose > 2) {
if (verbose > 3) if (verbose > 3)
fprintf(stderr, "%s: usbasp_cpi_cmd()", progname); avrdude_message("%s: usbasp_cpi_cmd()", progname);
fprintf(stderr, " => 0x%02x, 0x%02x, 0x%02x, 0x%02x\n", avrdude_message(" => 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]);
} }
@ -684,14 +667,14 @@ static int usbasp_spi_program_enable(PROGRAMMER * pgm, AVRPART * p)
cmd[0] = 0; cmd[0] = 0;
if (verbose > 2) if (verbose > 2)
fprintf(stderr, "%s: usbasp_program_enable()\n", avrdude_message("%s: usbasp_program_enable()\n",
progname); 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)) {
fprintf(stderr, "%s: error: programm enable: target doesn't answer. %x \n", avrdude_message("%s: error: programm enable: target doesn't answer. %x \n",
progname, res[0]); progname, res[0]);
return -1; return -1;
} }
@ -705,11 +688,11 @@ static int usbasp_spi_chip_erase(PROGRAMMER * pgm, AVRPART * p)
unsigned char res[4]; unsigned char res[4];
if (verbose > 2) if (verbose > 2)
fprintf(stderr, "%s: usbasp_chip_erase()\n", avrdude_message("%s: usbasp_chip_erase()\n",
progname); progname);
if (p->op[AVR_OP_CHIP_ERASE] == NULL) { if (p->op[AVR_OP_CHIP_ERASE] == NULL) {
fprintf(stderr, "chip erase instruction not defined for part \"%s\"\n", avrdude_message("chip erase instruction not defined for part \"%s\"\n",
p->desc); p->desc);
return -1; return -1;
} }
@ -736,8 +719,7 @@ static int usbasp_spi_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
int function; int function;
if (verbose > 2) if (verbose > 2)
fprintf(stderr, avrdude_message("%s: usbasp_program_paged_load(\"%s\", 0x%x, %d)\n",
"%s: usbasp_program_paged_load(\"%s\", 0x%x, %d)\n",
progname, m->desc, address, n_bytes); progname, m->desc, address, n_bytes);
if (strcmp(m->desc, "flash") == 0) { if (strcmp(m->desc, "flash") == 0) {
@ -781,7 +763,7 @@ static int usbasp_spi_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
n = usbasp_transmit(pgm, 1, function, cmd, buffer, blocksize); n = usbasp_transmit(pgm, 1, function, cmd, buffer, blocksize);
if (n != blocksize) { if (n != blocksize) {
fprintf(stderr, "%s: error: wrong reading bytes %x\n", avrdude_message("%s: error: wrong reading bytes %x\n",
progname, n); progname, n);
return -3; return -3;
} }
@ -806,8 +788,7 @@ static int usbasp_spi_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
int function; int function;
if (verbose > 2) if (verbose > 2)
fprintf(stderr, avrdude_message("%s: usbasp_program_paged_write(\"%s\", 0x%x, %d)\n",
"%s: usbasp_program_paged_write(\"%s\", 0x%x, %d)\n",
progname, m->desc, address, n_bytes); progname, m->desc, address, n_bytes);
if (strcmp(m->desc, "flash") == 0) { if (strcmp(m->desc, "flash") == 0) {
@ -856,7 +837,7 @@ static int usbasp_spi_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
n = usbasp_transmit(pgm, 0, function, cmd, buffer, blocksize); n = usbasp_transmit(pgm, 0, function, cmd, buffer, blocksize);
if (n != blocksize) { if (n != blocksize) {
fprintf(stderr, "%s: error: wrong count at writing %x\n", avrdude_message("%s: error: wrong count at writing %x\n",
progname, n); progname, n);
return -3; return -3;
} }
@ -896,8 +877,7 @@ static int usbasp_spi_set_sck_period(PROGRAMMER *pgm, double sckperiod)
unsigned char cmd[4]; unsigned char cmd[4];
if (verbose > 2) if (verbose > 2)
fprintf(stderr, avrdude_message("%s: usbasp_spi_set_sck_period(%g)\n",
"%s: usbasp_spi_set_sck_period(%g)\n",
progname, sckperiod); progname, sckperiod);
memset(cmd, 0, sizeof(cmd)); memset(cmd, 0, sizeof(cmd));
@ -910,7 +890,7 @@ static int usbasp_spi_set_sck_period(PROGRAMMER *pgm, double sckperiod)
/* auto sck set */ /* auto sck set */
if (verbose >= 1) if (verbose >= 1)
fprintf(stderr, "%s: auto set sck period (because given equals null)\n", progname); avrdude_message("%s: auto set sck period (because given equals null)\n", progname);
} else { } else {
@ -918,7 +898,7 @@ static int usbasp_spi_set_sck_period(PROGRAMMER *pgm, double sckperiod)
int usefreq = 0; int usefreq = 0;
if (verbose >= 2) if (verbose >= 2)
fprintf(stderr, "%s: try to set SCK period to %g s (= %i Hz)\n", progname, sckperiod, sckfreq); avrdude_message("%s: try to set SCK period to %g s (= %i Hz)\n", progname, sckperiod, sckfreq);
if (sckfreq >= usbaspSCKoptions[0].frequency) { if (sckfreq >= usbaspSCKoptions[0].frequency) {
clockoption = usbaspSCKoptions[0].id; clockoption = usbaspSCKoptions[0].id;
@ -939,7 +919,7 @@ static int usbasp_spi_set_sck_period(PROGRAMMER *pgm, double sckperiod)
/* save used sck frequency */ /* save used sck frequency */
PDATA(pgm)->sckfreq_hz = usefreq; PDATA(pgm)->sckfreq_hz = usefreq;
fprintf(stderr, "%s: set SCK frequency to %i Hz\n", progname, usefreq); avrdude_message("%s: set SCK frequency to %i Hz\n", progname, usefreq);
} }
cmd[0] = clockoption; cmd[0] = clockoption;
@ -948,7 +928,7 @@ static int usbasp_spi_set_sck_period(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)) {
fprintf(stderr, "%s: warning: cannot set sck period. please check for usbasp firmware update.\n", avrdude_message("%s: warning: cannot set sck period. please check for usbasp firmware update.\n",
progname); progname);
return -1; return -1;
} }
@ -975,7 +955,7 @@ static int usbasp_tpi_recv_byte(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)
{ {
fprintf(stderr, "%s: error: wrong responds size\n", progname); avrdude_message("%s: error: wrong responds size\n", progname);
return -1; return -1;
} }
@ -988,7 +968,7 @@ static int usbasp_tpi_nvm_waitbusy(PROGRAMMER * pgm)
int retry; int retry;
if (verbose > 2) if (verbose > 2)
fprintf(stderr, "%s: usbasp_tpi_nvm_waitbusy() ...", progname); avrdude_message("%s: usbasp_tpi_nvm_waitbusy() ...", progname);
for(retry=50; retry>0; retry--) for(retry=50; retry>0; retry--)
{ {
@ -997,20 +977,20 @@ static int usbasp_tpi_nvm_waitbusy(PROGRAMMER * pgm)
continue; continue;
if (verbose > 2) if (verbose > 2)
fprintf(stderr, " ready\n"); avrdude_message(" ready\n");
return 0; return 0;
} }
if (verbose > 2) if (verbose > 2)
fprintf(stderr, " failure\n"); avrdude_message(" failure\n");
return -1; return -1;
} }
static int usbasp_tpi_cmd(PROGRAMMER * pgm, const unsigned char *cmd, unsigned char *res) static int usbasp_tpi_cmd(PROGRAMMER * pgm, const unsigned char *cmd, unsigned char *res)
{ {
fprintf(stderr, "%s: error: spi_cmd used in TPI mode: not allowed\n", progname); avrdude_message("%s: error: spi_cmd used in TPI mode: not allowed\n", progname);
return -1; return -1;
} }
@ -1019,7 +999,7 @@ static int usbasp_tpi_program_enable(PROGRAMMER * pgm, AVRPART * p)
int retry; int retry;
if (verbose > 2) if (verbose > 2)
fprintf(stderr, "%s: usbasp_tpi_program_enable()\n", progname); avrdude_message("%s: usbasp_tpi_program_enable()\n", progname);
/* change guard time */ /* change guard time */
usbasp_tpi_send_byte(pgm, TPI_OP_SSTCS(TPIPCR)); usbasp_tpi_send_byte(pgm, TPI_OP_SSTCS(TPIPCR));
@ -1049,7 +1029,7 @@ static int usbasp_tpi_program_enable(PROGRAMMER * pgm, AVRPART * p)
} }
if(retry >= 10) if(retry >= 10)
{ {
fprintf(stderr, "%s: error: programm enable: target doesn't answer.\n", progname); avrdude_message("%s: error: programm enable: target doesn't answer.\n", progname);
return -1; return -1;
} }
@ -1059,7 +1039,7 @@ static int usbasp_tpi_program_enable(PROGRAMMER * pgm, AVRPART * p)
static int usbasp_tpi_chip_erase(PROGRAMMER * pgm, AVRPART * p) static int usbasp_tpi_chip_erase(PROGRAMMER * pgm, AVRPART * p)
{ {
if (verbose > 2) if (verbose > 2)
fprintf(stderr, "%s: usbasp_tpi_chip_erase()\n", progname); avrdude_message("%s: usbasp_tpi_chip_erase()\n", progname);
/* Set PR to flash */ /* Set PR to flash */
usbasp_tpi_send_byte(pgm, TPI_OP_SSTPR(0)); usbasp_tpi_send_byte(pgm, TPI_OP_SSTPR(0));
@ -1091,7 +1071,7 @@ static int usbasp_tpi_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
if (verbose > 2) if (verbose > 2)
fprintf(stderr, "%s: usbasp_tpi_paged_load(\"%s\", 0x%0x, %d)\n", avrdude_message("%s: usbasp_tpi_paged_load(\"%s\", 0x%0x, %d)\n",
progname, m->desc, addr, n_bytes); progname, m->desc, addr, n_bytes);
dptr = addr + m->buf; dptr = addr + m->buf;
@ -1112,7 +1092,7 @@ static int usbasp_tpi_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
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)
{ {
fprintf(stderr, "%s: error: wrong reading bytes %x\n", progname, n); avrdude_message("%s: error: wrong reading bytes %x\n", progname, n);
return -3; return -3;
} }
@ -1135,7 +1115,7 @@ static int usbasp_tpi_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
if (verbose > 2) if (verbose > 2)
fprintf(stderr, "%s: usbasp_tpi_paged_write(\"%s\", 0x%0x, %d)\n", avrdude_message("%s: usbasp_tpi_paged_write(\"%s\", 0x%0x, %d)\n",
progname, m->desc, addr, n_bytes); progname, m->desc, addr, n_bytes);
sptr = addr + m->buf; sptr = addr + m->buf;
@ -1162,7 +1142,7 @@ static int usbasp_tpi_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
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)
{ {
fprintf(stderr, "%s: error: wrong count at writing %x\n", progname, n); avrdude_message("%s: error: wrong count at writing %x\n", progname, n);
return -3; return -3;
} }
@ -1186,7 +1166,7 @@ static int usbasp_tpi_read_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, unsig
if (verbose > 2) if (verbose > 2)
fprintf(stderr, "%s: usbasp_tpi_read_byte(\"%s\", 0x%0lx)\n", avrdude_message("%s: usbasp_tpi_read_byte(\"%s\", 0x%0lx)\n",
progname, m->desc, addr); progname, m->desc, addr);
pr = m->offset + addr; pr = m->offset + addr;
@ -1199,7 +1179,7 @@ static int usbasp_tpi_read_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, unsig
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)
{ {
fprintf(stderr, "%s: error: wrong reading bytes %x\n", progname, n); avrdude_message("%s: error: wrong reading bytes %x\n", progname, n);
return -3; return -3;
} }
return 0; return 0;
@ -1207,7 +1187,7 @@ static int usbasp_tpi_read_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, unsig
static int usbasp_tpi_write_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, unsigned long addr, unsigned char data) static int usbasp_tpi_write_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, unsigned long addr, unsigned char data)
{ {
fprintf(stderr, "%s: error: usbasp_write_byte in TPI mode: all writes have to be done at page level\n", progname); avrdude_message("%s: error: usbasp_write_byte in TPI mode: all writes have to be done at page level\n", progname);
return -1; return -1;
} }
@ -1249,7 +1229,7 @@ void usbasp_initpgm(PROGRAMMER * pgm)
static int usbasp_nousb_open (struct programmer_t *pgm, char * name) static int usbasp_nousb_open (struct programmer_t *pgm, char * name)
{ {
fprintf(stderr, "%s: error: no usb support. please compile again with libusb installed.\n", avrdude_message("%s: error: no usb support. please compile again with libusb installed.\n",
progname); progname);
return -1; return -1;

View File

@ -76,8 +76,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) {
fprintf(stderr, avrdude_message("%s: usbtiny_setup(): Out of memory allocating private data\n",
"%s: usbtiny_setup(): Out of memory allocating private data\n",
progname); progname);
exit(1); exit(1);
} }
@ -101,7 +100,7 @@ static int usb_control (PROGRAMMER * pgm,
NULL, 0, // no data buffer in control messge NULL, 0, // no data buffer in control messge
USB_TIMEOUT ); // default timeout USB_TIMEOUT ); // default timeout
if(nbytes < 0){ if(nbytes < 0){
fprintf(stderr, "\n%s: error: usbtiny_transmit: %s\n", progname, usb_strerror()); avrdude_message("\n%s: error: usbtiny_transmit: %s\n", progname, usb_strerror());
return -1; return -1;
} }
@ -133,7 +132,7 @@ static int usb_in (PROGRAMMER * pgm,
} }
PDATA(pgm)->retries++; PDATA(pgm)->retries++;
} }
fprintf(stderr, "\n%s: error: usbtiny_receive: %s (expected %d, got %d)\n", avrdude_message("\n%s: error: usbtiny_receive: %s (expected %d, got %d)\n",
progname, usb_strerror(), buflen, nbytes); progname, usb_strerror(), buflen, nbytes);
return -1; return -1;
} }
@ -142,7 +141,7 @@ static int usb_in (PROGRAMMER * pgm,
static void check_retries (PROGRAMMER * pgm, const char* operation) static void check_retries (PROGRAMMER * pgm, const char* operation)
{ {
if (PDATA(pgm)->retries > 0 && quell_progress < 2) { if (PDATA(pgm)->retries > 0 && quell_progress < 2) {
fprintf(stderr, "%s: %d retries during %s\n", progname, avrdude_message("%s: %d retries during %s\n", progname,
PDATA(pgm)->retries, operation); PDATA(pgm)->retries, operation);
} }
PDATA(pgm)->retries = 0; PDATA(pgm)->retries = 0;
@ -167,7 +166,7 @@ static int usb_out (PROGRAMMER * pgm,
(char *)buffer, buflen, (char *)buffer, buflen,
timeout); timeout);
if (nbytes != buflen) { if (nbytes != buflen) {
fprintf(stderr, "\n%s: error: usbtiny_send: %s (expected %d, got %d)\n", avrdude_message("\n%s: error: usbtiny_send: %s (expected %d, got %d)\n",
progname, usb_strerror(), buflen, nbytes); progname, usb_strerror(), buflen, nbytes);
return -1; return -1;
} }
@ -186,7 +185,7 @@ static int usbtiny_avr_op (PROGRAMMER * pgm, AVRPART * p,
unsigned char cmd[4]; unsigned char cmd[4];
if (p->op[op] == NULL) { if (p->op[op] == NULL) {
fprintf( stderr, "Operation %d not defined for this chip!\n", op ); avrdude_message("Operation %d not defined for this chip!\n", op );
return -1; return -1;
} }
memset(cmd, 0, sizeof(cmd)); memset(cmd, 0, sizeof(cmd));
@ -236,8 +235,7 @@ static int usbtiny_open(PROGRAMMER* pgm, char* name)
if (usbpid) { if (usbpid) {
pid = *(int *)(ldata(usbpid)); pid = *(int *)(ldata(usbpid));
if (lnext(usbpid)) if (lnext(usbpid))
fprintf(stderr, avrdude_message("%s: Warning: using PID 0x%04x, ignoring remaining PIDs in list\n",
"%s: Warning: using PID 0x%04x, ignoring remaining PIDs in list\n",
progname, pid); progname, pid);
} else { } else {
pid = USBTINY_PRODUCT_DEFAULT; pid = USBTINY_PRODUCT_DEFAULT;
@ -250,8 +248,7 @@ static int usbtiny_open(PROGRAMMER* pgm, char* name)
if (dev->descriptor.idVendor == vid if (dev->descriptor.idVendor == vid
&& dev->descriptor.idProduct == pid ) { // found match? && dev->descriptor.idProduct == pid ) { // found match?
if(verbose) if(verbose)
fprintf(stderr, avrdude_message("%s: usbdev_open(): Found USBtinyISP, bus:device: %s:%s\n",
"%s: usbdev_open(): Found USBtinyISP, bus:device: %s:%s\n",
progname, 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 &&
@ -263,7 +260,7 @@ static int usbtiny_open(PROGRAMMER* pgm, char* name)
// wrong permissions or something? // wrong permissions or something?
if (!PDATA(pgm)->usb_handle) { if (!PDATA(pgm)->usb_handle) {
fprintf(stderr, "%s: Warning: cannot open USB device: %s\n", avrdude_message("%s: Warning: cannot open USB device: %s\n",
progname, usb_strerror()); progname, usb_strerror());
continue; continue;
} }
@ -272,12 +269,12 @@ static int usbtiny_open(PROGRAMMER* pgm, char* name)
} }
if(NULL != name && NULL == dev_name) { if(NULL != name && NULL == dev_name) {
fprintf(stderr, "%s: Error: Invalid -P value: '%s'\n", progname, name); avrdude_message("%s: Error: Invalid -P value: '%s'\n", progname, name);
fprintf(stderr, "%sUse -P usb:bus:device\n", progbuf); avrdude_message("%sUse -P usb:bus:device\n", progbuf);
return -1; return -1;
} }
if (!PDATA(pgm)->usb_handle) { if (!PDATA(pgm)->usb_handle) {
fprintf( stderr, "%s: Error: Could not find USBtiny device (0x%x/0x%x)\n", avrdude_message("%s: Error: Could not find USBtiny device (0x%x/0x%x)\n",
progname, vid, pid ); progname, vid, pid );
return -1; return -1;
} }
@ -323,7 +320,7 @@ static int usbtiny_set_sck_period (PROGRAMMER *pgm, double v)
PDATA(pgm)->sck_period = SCK_MAX; PDATA(pgm)->sck_period = SCK_MAX;
if (verbose) { if (verbose) {
fprintf(stderr, "%s: Setting SCK period to %d usec\n", progname, avrdude_message("%s: Setting SCK period to %d usec\n", progname,
PDATA(pgm)->sck_period ); PDATA(pgm)->sck_period );
} }
@ -350,7 +347,7 @@ static int usbtiny_initialize (PROGRAMMER *pgm, AVRPART *p )
// -B option not specified: use default // -B option not specified: use default
PDATA(pgm)->sck_period = SCK_DEFAULT; PDATA(pgm)->sck_period = SCK_DEFAULT;
if (verbose) { if (verbose) {
fprintf(stderr, "%s: Using SCK period of %d usec\n", avrdude_message("%s: Using SCK period of %d usec\n",
progname, PDATA(pgm)->sck_period ); progname, PDATA(pgm)->sck_period );
} }
if (usb_control(pgm, USBTINY_POWERUP, if (usb_control(pgm, USBTINY_POWERUP,
@ -406,7 +403,7 @@ static int usbtiny_cmd(PROGRAMMER * pgm, const unsigned char *cmd, unsigned char
check_retries(pgm, "SPI command"); check_retries(pgm, "SPI command");
if (verbose > 1) { if (verbose > 1) {
// print out the data we sent and received // print out the data we sent and received
fprintf(stderr, "CMD: [%02x %02x %02x %02x] [%02x %02x %02x %02x]\n", avrdude_message("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] );
} }
@ -420,7 +417,7 @@ static int usbtiny_chip_erase(PROGRAMMER * pgm, 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) {
fprintf(stderr, "Chip erase instruction not defined for part \"%s\"\n", avrdude_message("Chip erase instruction not defined for part \"%s\"\n",
p->desc); p->desc);
return -1; return -1;
} }
@ -581,7 +578,7 @@ void usbtiny_initpgm ( PROGRAMMER* pgm )
static int usbtiny_nousb_open(struct programmer_t *pgm, char * name) static int usbtiny_nousb_open(struct programmer_t *pgm, char * name)
{ {
fprintf(stderr, "%s: error: no usb support. Please compile again with libusb installed.\n", avrdude_message("%s: error: no usb support. Please compile again with libusb installed.\n",
progname); 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) {
fprintf(stderr, avrdude_message("%s: wiring_setup(): Out of memory allocating private data\n",
"%s: wiring_setup(): Out of memory allocating private data\n",
progname); progname);
exit(1); exit(1);
} }
@ -124,15 +123,13 @@ static int wiring_parseextparms(PROGRAMMER * pgm, 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) {
fprintf(stderr, avrdude_message("%s: wiring_parseextparms(): invalid snooze time '%s'\n",
"%s: wiring_parseextparms(): invalid snooze time '%s'\n",
progname, extended_param); progname, extended_param);
rv = -1; rv = -1;
continue; continue;
} }
if (verbose >= 2) { if (verbose >= 2) {
fprintf(stderr, avrdude_message("%s: wiring_parseextparms(): snooze time set to %d ms\n",
"%s: wiring_parseextparms(): snooze time set to %d ms\n",
progname, newsnooze); progname, newsnooze);
} }
WIRINGPDATA(mycookie)->snoozetime = newsnooze; WIRINGPDATA(mycookie)->snoozetime = newsnooze;
@ -140,8 +137,7 @@ static int wiring_parseextparms(PROGRAMMER * pgm, LISTID extparms)
continue; continue;
} }
fprintf(stderr, avrdude_message("%s: wiring_parseextparms(): invalid extended parameter '%s'\n",
"%s: wiring_parseextparms(): invalid extended parameter '%s'\n",
progname, extended_param); progname, extended_param);
rv = -1; rv = -1;
} }
@ -165,15 +161,13 @@ static int wiring_open(PROGRAMMER * pgm, char * port)
timetosnooze = WIRINGPDATA(mycookie)->snoozetime; timetosnooze = WIRINGPDATA(mycookie)->snoozetime;
if (verbose >= 2) { if (verbose >= 2) {
fprintf(stderr, avrdude_message("%s: wiring_open(): snoozing for %d ms\n",
"%s: wiring_open(): snoozing for %d ms\n",
progname, timetosnooze); progname, timetosnooze);
} }
while (timetosnooze--) while (timetosnooze--)
usleep(1000); usleep(1000);
if (verbose >= 2) { if (verbose >= 2) {
fprintf(stderr, avrdude_message("%s: wiring_open(): done snoozing\n",
"%s: wiring_open(): done snoozing\n",
progname); progname);
} }
@ -184,8 +178,7 @@ static int wiring_open(PROGRAMMER * pgm, char * port)
/* since they are active LOW signals. */ /* since they are active LOW signals. */
if (verbose >= 2) { if (verbose >= 2) {
fprintf(stderr, avrdude_message("%s: wiring_open(): releasing DTR/RTS\n",
"%s: wiring_open(): releasing DTR/RTS\n",
progname); progname);
} }
@ -196,8 +189,7 @@ static int wiring_open(PROGRAMMER * pgm, char * port)
/* are asserted (i.e. logic LOW) again. */ /* are asserted (i.e. logic LOW) again. */
if (verbose >= 2) { if (verbose >= 2) {
fprintf(stderr, avrdude_message("%s: wiring_open(): asserting DTR/RTS\n",
"%s: wiring_open(): asserting DTR/RTS\n",
progname); progname);
} }