mirror of
https://github.com/mariusgreuel/avrdude.git
synced 2025-12-17 11:04:16 +00:00
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:
104
flip1.c
104
flip1.c
@@ -239,18 +239,16 @@ int flip1_initialize(PROGRAMMER* pgm, AVRPART *part)
|
||||
if (usbpid) {
|
||||
pid = *(int *)(ldata(usbpid));
|
||||
if (lnext(usbpid))
|
||||
fprintf(stderr,
|
||||
"%s: Warning: using PID 0x%04x, ignoring remaining PIDs in list\n",
|
||||
progname, pid);
|
||||
avrdude_message("%s: Warning: using PID 0x%04x, ignoring remaining PIDs in list\n",
|
||||
progname, pid);
|
||||
} else {
|
||||
pid = part->usbpid;
|
||||
}
|
||||
if (!ovsigck && (part->flags & AVRPART_HAS_PDI)) {
|
||||
fprintf(stderr,
|
||||
"%s: \"flip1\" (FLIP protocol version 1) is for AT90USB* and ATmega*U* devices.\n"
|
||||
"%s For Xmega devices, use \"flip2\".\n"
|
||||
"%s (Use -F to bypass this check.)\n",
|
||||
progname, progbuf, progbuf);
|
||||
avrdude_message("%s: \"flip1\" (FLIP protocol version 1) is for AT90USB* and ATmega*U* devices.\n"
|
||||
"%s For Xmega devices, use \"flip2\".\n"
|
||||
"%s (Use -F to bypass this check.)\n",
|
||||
progname, progbuf, progbuf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -262,31 +260,31 @@ int flip1_initialize(PROGRAMMER* pgm, AVRPART *part)
|
||||
/* Check if descriptor values are what we expect. */
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
/*
|
||||
@@ -297,20 +295,20 @@ int flip1_initialize(PROGRAMMER* pgm, AVRPART *part)
|
||||
*/
|
||||
if (0) {
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
if (verbose)
|
||||
@@ -367,7 +365,7 @@ int flip1_chip_erase(PROGRAMMER* pgm, AVRPART *part)
|
||||
unsigned int default_timeout = FLIP1(pgm)->dfu->timeout;
|
||||
|
||||
if (verbose > 1)
|
||||
fprintf(stderr, "%s: flip_chip_erase()\n", progname);
|
||||
avrdude_message("%s: flip_chip_erase()\n", progname);
|
||||
|
||||
struct flip1_cmd cmd = {
|
||||
FLIP1_CMD_WRITE_COMMAND, { 0, 0xff }
|
||||
@@ -382,7 +380,7 @@ int flip1_chip_erase(PROGRAMMER* pgm, AVRPART *part)
|
||||
return -1;
|
||||
|
||||
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));
|
||||
if (status.bState == STATE_dfuERROR)
|
||||
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)
|
||||
return -1;
|
||||
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);
|
||||
return -1;
|
||||
}
|
||||
@@ -415,10 +413,10 @@ int flip1_read_byte(PROGRAMMER* pgm, AVRPART *part, AVRMEM *mem,
|
||||
mem_unit = flip1_mem_unit(mem->desc);
|
||||
|
||||
if (mem_unit == FLIP1_MEM_UNIT_UNKNOWN) {
|
||||
fprintf(stderr, "%s: Error: "
|
||||
avrdude_message("%s: Error: "
|
||||
"\"%s\" memory not accessible using FLIP",
|
||||
progname, mem->desc);
|
||||
fprintf(stderr, "\n");
|
||||
avrdude_message("\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -440,10 +438,10 @@ int flip1_write_byte(PROGRAMMER* pgm, AVRPART *part, AVRMEM *mem,
|
||||
mem_unit = flip1_mem_unit(mem->desc);
|
||||
|
||||
if (mem_unit == FLIP1_MEM_UNIT_UNKNOWN) {
|
||||
fprintf(stderr, "%s: Error: "
|
||||
avrdude_message("%s: Error: "
|
||||
"\"%s\" memory not accessible using FLIP",
|
||||
progname, mem->desc);
|
||||
fprintf(stderr, "\n");
|
||||
avrdude_message("\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -461,10 +459,10 @@ int flip1_paged_load(PROGRAMMER* pgm, AVRPART *part, AVRMEM *mem,
|
||||
mem_unit = flip1_mem_unit(mem->desc);
|
||||
|
||||
if (mem_unit == FLIP1_MEM_UNIT_UNKNOWN) {
|
||||
fprintf(stderr, "%s: Error: "
|
||||
avrdude_message("%s: Error: "
|
||||
"\"%s\" memory not accessible using FLIP",
|
||||
progname, mem->desc);
|
||||
fprintf(stderr, "\n");
|
||||
avrdude_message("\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -487,16 +485,16 @@ int flip1_paged_write(PROGRAMMER* pgm, AVRPART *part, AVRMEM *mem,
|
||||
mem_unit = flip1_mem_unit(mem->desc);
|
||||
|
||||
if (mem_unit == FLIP1_MEM_UNIT_UNKNOWN) {
|
||||
fprintf(stderr, "%s: Error: "
|
||||
avrdude_message("%s: Error: "
|
||||
"\"%s\" memory not accessible using FLIP",
|
||||
progname, mem->desc);
|
||||
fprintf(stderr, "\n");
|
||||
avrdude_message("\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (n_bytes > INT_MAX) {
|
||||
/* 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);
|
||||
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)
|
||||
{
|
||||
if (verbose > 1)
|
||||
fprintf(stderr, "%s: flip1_read_sig_bytes(): ", progname);
|
||||
avrdude_message("%s: flip1_read_sig_bytes(): ", progname);
|
||||
|
||||
if (FLIP1(pgm)->dfu == NULL)
|
||||
return -1;
|
||||
|
||||
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));
|
||||
return -1;
|
||||
}
|
||||
@@ -535,7 +533,7 @@ int flip1_read_sig_bytes(PROGRAMMER* pgm, AVRPART *part, AVRMEM *mem)
|
||||
};
|
||||
|
||||
if (verbose > 1)
|
||||
fprintf(stderr, "from device\n");
|
||||
avrdude_message("from device\n");
|
||||
|
||||
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)
|
||||
{
|
||||
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));
|
||||
if (status.bState == STATE_dfuERROR)
|
||||
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)
|
||||
{
|
||||
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));
|
||||
if (status.bState == STATE_dfuERROR)
|
||||
dfu_clrstatus(FLIP1(pgm)->dfu);
|
||||
@@ -578,7 +576,7 @@ int flip1_read_sig_bytes(PROGRAMMER* pgm, AVRPART *part, AVRMEM *mem)
|
||||
else
|
||||
{
|
||||
if (verbose > 1)
|
||||
fprintf(stderr, "cached\n");
|
||||
avrdude_message("cached\n");
|
||||
}
|
||||
|
||||
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));
|
||||
|
||||
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);
|
||||
exit(1);
|
||||
}
|
||||
@@ -609,7 +607,7 @@ void flip1_teardown(PROGRAMMER * pgm)
|
||||
void flip1_show_info(struct flip1 *flip1)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -628,9 +626,8 @@ int flip1_read_memory(PROGRAMMER * pgm,
|
||||
|
||||
|
||||
if (verbose > 1)
|
||||
fprintf(stderr,
|
||||
"%s: flip_read_memory(%s, 0x%04x, %d)\n",
|
||||
progname, flip1_mem_unit_str(mem_unit), addr, size);
|
||||
avrdude_message("%s: flip_read_memory(%s, 0x%04x, %d)\n",
|
||||
progname, flip1_mem_unit_str(mem_unit), addr, size);
|
||||
|
||||
/*
|
||||
* As this function is called once per page, no need to handle 64
|
||||
@@ -660,7 +657,7 @@ int flip1_read_memory(PROGRAMMER * pgm,
|
||||
|
||||
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,
|
||||
flip1_status_str(&status));
|
||||
if (status.bState == STATE_dfuERROR)
|
||||
@@ -674,8 +671,7 @@ int flip1_read_memory(PROGRAMMER * pgm,
|
||||
if (cmd_result < 0 && aux_result == 0 &&
|
||||
status.bStatus == DFU_STATUS_ERR_WRITE) {
|
||||
if (FLIP1(pgm)->security_mode_flag == 0)
|
||||
fprintf(stderr,
|
||||
"\n%s:\n"
|
||||
avrdude_message("\n%s:\n"
|
||||
"%s***********************************************************************\n"
|
||||
"%sMaybe the device is in ``security mode´´, and needs a chip erase first?\n"
|
||||
"%s***********************************************************************\n"
|
||||
@@ -689,7 +685,7 @@ int flip1_read_memory(PROGRAMMER * pgm,
|
||||
|
||||
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,
|
||||
flip1_status_str(&status));
|
||||
if (status.bState == STATE_dfuERROR)
|
||||
@@ -724,16 +720,14 @@ int flip1_write_memory(struct dfu_dev *dfu,
|
||||
unsigned char *buf;
|
||||
|
||||
if (verbose > 1)
|
||||
fprintf(stderr,
|
||||
"%s: flip_write_memory(%s, 0x%04x, %d)\n",
|
||||
progname, flip1_mem_unit_str(mem_unit), addr, size);
|
||||
avrdude_message("%s: flip_write_memory(%s, 0x%04x, %d)\n",
|
||||
progname, flip1_mem_unit_str(mem_unit), addr, size);
|
||||
|
||||
if (size < 32) {
|
||||
/* presumably single-byte updates; must be padded to USB endpoint size */
|
||||
if ((addr + size - 1) / 32 != addr / 32) {
|
||||
fprintf(stderr,
|
||||
"%s: flip_write_memory(): begin (0x%x) and end (0x%x) not within same 32-byte block\n",
|
||||
progname, addr, addr + size - 1);
|
||||
avrdude_message("%s: flip_write_memory(): begin (0x%x) and end (0x%x) not within same 32-byte block\n",
|
||||
progname, addr, addr + size - 1);
|
||||
return -1;
|
||||
}
|
||||
write_size = 32;
|
||||
@@ -744,7 +738,7 @@ int flip1_write_memory(struct dfu_dev *dfu,
|
||||
if ((buf = malloc(sizeof(struct flip1_cmd_header) +
|
||||
write_size +
|
||||
sizeof(struct flip1_prog_footer))) == 0) {
|
||||
fprintf(stderr, "%s: Out of memory\n", progname);
|
||||
avrdude_message("%s: Out of memory\n", progname);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -793,7 +787,7 @@ int flip1_write_memory(struct dfu_dev *dfu,
|
||||
|
||||
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,
|
||||
flip1_status_str(&status));
|
||||
if (status.bState == STATE_dfuERROR)
|
||||
@@ -824,7 +818,7 @@ int flip1_set_mem_page(struct dfu_dev *dfu,
|
||||
|
||||
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));
|
||||
if (status.bState == STATE_dfuERROR)
|
||||
dfu_clrstatus(dfu);
|
||||
|
||||
Reference in New Issue
Block a user