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