From 80e240b5df36b13f291a3b2cf2829f760f0cf00a Mon Sep 17 00:00:00 2001 From: Stefan Rueger Date: Wed, 21 Jun 2023 18:48:05 +0100 Subject: [PATCH] Replace ldata(lfirst(pgm->id)) with pgmid where possible --- src/avr910.c | 3 +-- src/avrdude.h | 3 ++- src/buspirate.c | 3 +-- src/dryrun.c | 5 ++--- src/jtag3.c | 11 +++++------ src/jtagmkII.c | 13 +++++-------- src/linuxspi.c | 3 +-- src/main.c | 7 +++---- src/micronucleus.c | 3 +-- src/pickit2.c | 3 +-- src/serialupdi.c | 3 +-- src/stk500.c | 17 ++++++++--------- src/stk500v2.c | 8 +++----- src/teensy.c | 3 +-- src/term.c | 4 ++-- src/urclock.c | 4 ++-- src/usbasp.c | 5 ++--- src/wiring.c | 3 +-- src/xbee.c | 3 +-- 19 files changed, 43 insertions(+), 61 deletions(-) diff --git a/src/avr910.c b/src/avr910.c index 792e2667..a7c78e95 100644 --- a/src/avr910.c +++ b/src/avr910.c @@ -333,8 +333,7 @@ static int avr910_parseextparms(const PROGRAMMER *pgm, const LISTID extparms) { continue; } if (str_eq(extended_param, "help")) { - char *prg = (char *)ldata(lfirst(pgm->id)); - msg_error("%s -c %s extended options:\n", progname, prg); + msg_error("%s -c %s extended options:\n", progname, pgmid); msg_error(" -xdevcode= Override device code\n"); msg_error(" -xno_blockmode Disable default checking for block transfer capability\n"); msg_error(" -xhelp Show this help menu and exit\n"); diff --git a/src/avrdude.h b/src/avrdude.h index 8219252a..3ab85e5a 100644 --- a/src/avrdude.h +++ b/src/avrdude.h @@ -37,7 +37,8 @@ extern char progbuf[]; // Spaces same length as progname extern int ovsigck; // Override signature check (-F) extern int verbose; // Verbosity level (-v, -vv, ...) extern int quell_progress; // Quell progress report -q, reduce effective verbosity level (-qq, -qqq) -extern const char *partdesc; // Part id +extern const char *partdesc; // Part -p string +extern const char *pgmid; // Programmer -c string int avrdude_message(int msglvl, const char *format, ...); int avrdude_message2(FILE *fp, int lno, const char *file, const char *func, int msgmode, int msglvl, const char *format, ...); diff --git a/src/buspirate.c b/src/buspirate.c index 4792ae43..3708722b 100644 --- a/src/buspirate.c +++ b/src/buspirate.c @@ -378,8 +378,7 @@ buspirate_parseextparms(const PROGRAMMER *pgm, const LISTID extparms) { } if (str_eq(extended_param, "help")) { - char *prg = (char *)ldata(lfirst(pgm->id)); - msg_error("%s -c %s extended options:\n", progname, prg); + msg_error("%s -c %s extended options:\n", progname, pgmid); msg_error(" -xreset=cs,aux,aux2 Override default reset pin\n"); msg_error(" -xspifreq=<0..7> Set binary SPI mode speed\n"); msg_error(" -xrawfreq=<0..3> Set \"raw-wire\" SPI mode speed\n"); diff --git a/src/dryrun.c b/src/dryrun.c index ee50eadd..313501f2 100644 --- a/src/dryrun.c +++ b/src/dryrun.c @@ -164,11 +164,10 @@ static int dryrun_initialize(const PROGRAMMER *pgm, const AVRPART *p) { int pm = pgm->prog_modes & p->prog_modes; if(!pm) - Return("programmer %s and part %s have no common programming mode", - (char *) ldata(lfirst(pgm->id)), p->desc); + Return("programmer %s and part %s have no common programming mode", pgmid, p->desc); if(pm & (pm-1)) Return("%s and %s share multiple programming modes (%s)", - (char *) ldata(lfirst(pgm->id)), p->desc, avr_prog_modes(pm)); + pgmid, p->desc, avr_prog_modes(pm)); */ return pgm->program_enable(pgm, p); diff --git a/src/jtag3.c b/src/jtag3.c index a8533a53..3d5dc9ad 100644 --- a/src/jtag3.c +++ b/src/jtag3.c @@ -879,7 +879,7 @@ int jtag3_getsync(const PROGRAMMER *pgm, int mode) { /* XplainedMini boards do not need this, and early revisions had a * firmware bug where they complained about it. */ if ((pgm->flag & PGM_FL_IS_EDBG) && - !str_starts(ldata(lfirst(pgm->id)), "xplainedmini")) { + !str_starts(pgmid, "xplainedmini")) { if (jtag3_edbg_prepare(pgm) < 0) { return -1; } @@ -1583,13 +1583,12 @@ static int jtag3_parseextparms(const PROGRAMMER *pgm, const LISTID extparms) { } else if (str_eq(extended_param, "help")) { - char *prg = (char *)ldata(lfirst(pgm->id)); - msg_error("%s -c %s extended options:\n", progname, prg); + msg_error("%s -c %s extended options:\n", progname, pgmid); if (str_eq(pgm->type, "JTAGICE3")) msg_error(" -xjtagchain=UB,UA,BB,BA Setup the JTAG scan chain order\n"); - if (str_eq(prg, "powerdebugger_updi") || str_eq(prg, "pickit4_updi")) + if (str_eq(pgmid, "powerdebugger_updi") || str_eq(pgmid, "pickit4_updi")) msg_error(" -xhvupdi Enable high-voltage UPDI initialization\n"); - if (str_starts(prg, "xplainedmini") && !str_eq(prg, "xplainedmini_tpi")) { + if (str_starts(pgmid, "xplainedmini") && !str_eq(pgmid, "xplainedmini_tpi")) { msg_error(" -xsuffer Read SUFFER register value\n"); msg_error(" -xsuffer= Set SUFFER register value\n"); msg_error(" -xvtarg_switch Read on-board target voltage switch state\n"); @@ -1820,7 +1819,7 @@ void jtag3_close(PROGRAMMER * pgm) { /* XplainedMini boards do not need this, and early revisions had a * firmware bug where they complained about it. */ if ((pgm->flag & PGM_FL_IS_EDBG) && - !str_starts(ldata(lfirst(pgm->id)), "xplainedmini")) { + !str_starts(pgmid, "xplainedmini")) { jtag3_edbg_signoff(pgm); } diff --git a/src/jtagmkII.c b/src/jtagmkII.c index 1433d404..458697db 100644 --- a/src/jtagmkII.c +++ b/src/jtagmkII.c @@ -1216,10 +1216,9 @@ static int jtagmkII_initialize(const PROGRAMMER *pgm, const AVRPART *p) { const char *ifname; /* Abort and print error if programmer does not support the target microcontroller */ - if ((strncmp(pgm->type, "JTAGMKII_UPDI", strlen("JTAGMKII_UPDI")) == 0 && !(p->prog_modes & PM_UPDI)) || - (strncmp(ldata(lfirst(pgm->id)), "jtagmkII", strlen("jtagmkII")) == 0 && (p->prog_modes & PM_UPDI))) { - msg_error("programmer %s does not support target %s\n\n", - (char *) ldata(lfirst(pgm->id)), p->desc); + if((str_starts(pgm->type, "JTAGMKII_UPDI") && !(p->prog_modes & PM_UPDI)) || + (str_starts(pgmid, "jtagmkII") && (p->prog_modes & PM_UPDI))) { + msg_error("programmer %s does not support target %s\n\n", pgmid, p->desc); return -1; } @@ -1289,9 +1288,8 @@ static int jtagmkII_initialize(const PROGRAMMER *pgm, const AVRPART *p) { AVRMEM *bootmem = avr_locate_mem(p, "boot"); AVRMEM *flashmem = avr_locate_mem(p, "flash"); if (bootmem == NULL || flashmem == NULL) { - if (strncmp(ldata(lfirst(pgm->id)), "jtagmkII", strlen("jtagmkII")) == 0) { + if(str_starts(pgmid, "jtagmkII")) pmsg_error("cannot locate flash or boot memories in description\n"); - } } else { if (PDATA(pgm)->fwver < 0x700) { /* V7+ firmware does not need this anymore */ @@ -1401,8 +1399,7 @@ static int jtagmkII_parseextparms(const PROGRAMMER *pgm, const LISTID extparms) } else if (str_eq(extended_param, "help")) { - char *prg = (char *)ldata(lfirst(pgm->id)); - msg_error("%s -c %s extended options:\n", progname, prg); + msg_error("%s -c %s extended options:\n", progname, pgmid); if (str_eq(pgm->type, "JTAGMKII") || str_eq(pgm->type, "DRAGON_JTAG")) msg_error(" -xjtagchain=UB,UA,BB,BA Setup the JTAG scan chain order\n"); msg_error( " -xhelp Show this help menu and exit\n"); diff --git a/src/linuxspi.c b/src/linuxspi.c index 00e6650d..15a8abb0 100644 --- a/src/linuxspi.c +++ b/src/linuxspi.c @@ -414,8 +414,7 @@ static int linuxspi_parseextparams(const PROGRAMMER *pgm, const LISTID extparms) continue; } if (str_eq(extended_param, "help")) { - char *prg = (char *)ldata(lfirst(pgm->id)); - msg_error("%s -c %s extended options:\n", progname, prg); + msg_error("%s -c %s extended options:\n", progname, pgmid); msg_error(" -xdisable_no_cs Do not use the SPI_NO_CS bit for the SPI driver\n"); msg_error(" -xhelp Show this help menu and exit\n"); exit(0); diff --git a/src/main.c b/src/main.c index 2f16eef2..4d95c735 100644 --- a/src/main.c +++ b/src/main.c @@ -213,8 +213,8 @@ static PROGRAMMER * pgm; int verbose; // Verbose output int quell_progress; // Quell progress report and un-verbose output int ovsigck; // 1 = override sig check, 0 = don't -const char *partdesc; // Part id -const char *pgmid; // Programmer id +const char *partdesc; // Part -p string +const char *pgmid; // Programmer -c string /* * usage message @@ -1103,8 +1103,7 @@ int main(int argc, char * argv []) for (LNODEID ln = lfirst(extended_params); ln; ln = lnext(ln)) { const char *extended_param = ldata(ln); if (str_eq(extended_param, "help")) { - char *prg = (char *)ldata(lfirst(pgm->id)); - msg_error("%s -c %s extended options:\n", progname, prg); + msg_error("%s -c %s extended options:\n", progname, pgmid); msg_error(" -xhelp Show this help menu and exit\n"); exit(0); } diff --git a/src/micronucleus.c b/src/micronucleus.c index e322f9dc..11e8fec6 100644 --- a/src/micronucleus.c +++ b/src/micronucleus.c @@ -922,8 +922,7 @@ static int micronucleus_parseextparams(const PROGRAMMER *pgm, const LISTID xpara } else if (str_eq(param, "help")) { - char *prg = (char *)ldata(lfirst(pgm->id)); - msg_error("%s -c %s extended options:\n", progname, prg); + msg_error("%s -c %s extended options:\n", progname, pgmid); msg_error(" -xwait Wait for the device to be plugged in if not connected\n"); msg_error(" -xwait= Wait [s] for the device to be plugged in if not connected\n"); msg_error(" -xhelp Show this help menu and exit\n"); diff --git a/src/pickit2.c b/src/pickit2.c index e3b70819..caa87256 100644 --- a/src/pickit2.c +++ b/src/pickit2.c @@ -1212,8 +1212,7 @@ static int pickit2_parseextparams(const PROGRAMMER *pgm, const LISTID extparms) continue; } if (str_eq(extended_param, "help")) { - char *prg = (char *)ldata(lfirst(pgm->id)); - msg_error("%s -c %s extended options:\n", progname, prg); + msg_error("%s -c %s extended options:\n", progname, pgmid); msg_error(" -xclockrate= Set the SPI clocking rate in [Hz]\n"); msg_error(" -xtimeout= Set the timeout for USB read/write to [ms]\n"); msg_error(" -xhelp Show this help menu and exit\n"); diff --git a/src/serialupdi.c b/src/serialupdi.c index 428f83e7..e27b1406 100644 --- a/src/serialupdi.c +++ b/src/serialupdi.c @@ -944,8 +944,7 @@ static int serialupdi_parseextparms(const PROGRAMMER *pgm, const LISTID extparms continue; } if (str_eq(extended_param, "help")) { - char *prg = (char *)ldata(lfirst(pgm->id)); - msg_error("%s -c %s extended options:\n", progname, prg); + msg_error("%s -c %s extended options:\n", progname, pgmid); msg_error(" -xrtsdtr=low,high Force RTS/DTR lines low or high state during programming\n"); msg_error(" -xhelp Show this help menu and exit\n"); exit(0); diff --git a/src/stk500.c b/src/stk500.c index ccbb5004..ddc7fc84 100644 --- a/src/stk500.c +++ b/src/stk500.c @@ -403,7 +403,7 @@ static int stk500_initialize(const PROGRAMMER *pgm, const AVRPART *p) { stk500_getparm(pgm, Parm_STK_SW_MINOR, &min); // MIB510 does not need extparams - if (str_eq(ldata(lfirst(pgm->id)), "mib510")) + if (str_eq(pgmid, "mib510")) n_extparms = 0; else if ((maj > 1) || ((maj == 1) && (min > 10))) n_extparms = 4; @@ -749,8 +749,7 @@ static int stk500_parseextparms(const PROGRAMMER *pgm, const LISTID extparms) } else if (str_eq(extended_param, "help")) { - char *prg = (char *)ldata(lfirst(pgm->id)); - msg_error("%s -c %s extended options:\n", progname, prg); + msg_error("%s -c %s extended options:\n", progname, pgmid); msg_error(" -xattempts= Specify no. connection retry attempts\n"); if (pgm->extra_features & HAS_VTARG_ADJ) { msg_error(" -xvtarg Read target supply voltage\n"); @@ -844,7 +843,7 @@ static int stk500_open(PROGRAMMER *pgm, const char *port) { stk500_drain(pgm, 0); // MIB510 init - if (str_eq(ldata(lfirst(pgm->id)), "mib510") && mib510_isp(pgm, 1) != 0) + if (str_eq(pgmid, "mib510") && mib510_isp(pgm, 1) != 0) return -1; if (stk500_getsync(pgm) < 0) @@ -857,7 +856,7 @@ static int stk500_open(PROGRAMMER *pgm, const char *port) { static void stk500_close(PROGRAMMER * pgm) { // MIB510 close - if (str_eq(ldata(lfirst(pgm->id)), "mib510")) + if (str_eq(pgmid, "mib510")) (void)mib510_isp(pgm, 0); serial_close(&pgm->fd); @@ -967,7 +966,7 @@ static int set_memtype_a_div(const PROGRAMMER *pgm, const AVRPART *p, const AVRM if(avr_mem_is_eeprom_type(m)) { *memtypep = 'E'; // Word addr for bootloaders or Arduino as ISP if part is a "classic" part, byte addr otherwise - *a_divp = ((pgm->prog_modes & PM_SPM) || str_caseeq(ldata(lfirst(pgm->id)), "arduino_as_isp")) \ + *a_divp = ((pgm->prog_modes & PM_SPM) || str_caseeq(pgmid, "arduino_as_isp")) \ && !(p->prog_modes & (PM_UPDI | PM_PDI))? 2: 1; return 0; } @@ -1003,7 +1002,7 @@ static int stk500_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const AVR for (; addr < n; addr += block_size) { // MIB510 uses fixed blocks size of 256 bytes - if (str_eq(ldata(lfirst(pgm->id)), "mib510")) { + if (str_eq(pgmid, "mib510")) { block_size = 256; } else { if (n - addr < page_size) @@ -1075,7 +1074,7 @@ static int stk500_paged_load(const PROGRAMMER *pgm, const AVRPART *p, const AVRM n = addr + n_bytes; for (; addr < n; addr += block_size) { // MIB510 uses fixed blocks size of 256 bytes - if (str_eq(ldata(lfirst(pgm->id)), "mib510")) { + if(str_eq(pgmid, "mib510")) { block_size = 256; } else { if (n - addr < page_size) @@ -1119,7 +1118,7 @@ static int stk500_paged_load(const PROGRAMMER *pgm, const AVRPART *p, const AVRM if (stk500_recv(pgm, buf, 1) < 0) return -1; - if(str_eq(ldata(lfirst(pgm->id)), "mib510")) { + if(str_eq(pgmid, "mib510")) { if (buf[0] != Resp_STK_INSYNC) { msg_error("\n"); pmsg_error("protocol expects sync byte 0x%02x but got 0x%02x\n", Resp_STK_INSYNC, buf[0]); diff --git a/src/stk500v2.c b/src/stk500v2.c index a95af29c..37f4379e 100644 --- a/src/stk500v2.c +++ b/src/stk500v2.c @@ -1932,8 +1932,7 @@ static int stk500v2_parseextparms(const PROGRAMMER *pgm, const LISTID extparms) } else if (str_eq(extended_param, "help")) { - char *prg = (char *)ldata(lfirst(pgm->id)); - msg_error("%s -c %s extended options:\n", progname, prg); + msg_error("%s -c %s extended options:\n", progname, pgmid); if (pgm->extra_features & HAS_VTARG_ADJ) { msg_error(" -xvtarg Read target supply voltage\n"); msg_error(" -xvtarg= Set target supply voltage\n"); @@ -2046,9 +2045,8 @@ static int stk500v2_jtag3_parseextparms(const PROGRAMMER *pgm, const LISTID extp } else if (str_eq(extended_param, "help")) { - char *prg = (char *)ldata(lfirst(pgm->id)); - msg_error("%s -c %s extended options:\n", progname, prg); - if (str_starts(prg, "xplainedmini")) { + msg_error("%s -c %s extended options:\n", progname, pgmid); + if(str_starts(pgmid, "xplainedmini")) { msg_error(" -xsuffer Read SUFFER register value\n"); msg_error(" -xsuffer= Set SUFFER register value\n"); msg_error(" -xvtarg_switch Read on-board target voltage switch state\n"); diff --git a/src/teensy.c b/src/teensy.c index 67cc0e09..2c4d35f4 100644 --- a/src/teensy.c +++ b/src/teensy.c @@ -569,8 +569,7 @@ static int teensy_parseextparams(const PROGRAMMER *pgm, const LISTID xparams) { } else if (str_eq(param, "help")) { - char *prg = (char *)ldata(lfirst(pgm->id)); - msg_error("%s -c %s extended options:\n", progname, prg); + msg_error("%s -c %s extended options:\n", progname, pgmid); msg_error(" -xwait Wait for the device to be plugged in if not connected\n"); msg_error(" -xwait= Wait [s] for the device to be plugged in if not connected\n"); msg_error(" -xhelp Show this help menu and exit\n"); diff --git a/src/term.c b/src/term.c index 46a3721f..da2e0e04 100644 --- a/src/term.c +++ b/src/term.c @@ -895,7 +895,7 @@ static int cmd_erase(const PROGRAMMER *pgm, const AVRPART *p, int argc, char *ar } if(rc) { - pmsg_error("(erase) programmer %s failed erasing the chip\n", (char *) ldata(lfirst(pgm->id))); + pmsg_error("(erase) programmer %s failed erasing the chip\n", pgmid); return -1; } @@ -919,7 +919,7 @@ static int cmd_pgerase(const PROGRAMMER *pgm, const AVRPART *p, int argc, char * return -1; } if(!avr_has_paged_access(pgm, mem)) { - pmsg_error("(pgerase) %s memory cannot be paged addressed by %s\n", memtype, (char *) ldata(lfirst(pgm->id))); + pmsg_error("(pgerase) %s memory cannot be paged addressed by %s\n", memtype, pgmid); return -1; } diff --git a/src/urclock.c b/src/urclock.c index f686bf85..56042f85 100644 --- a/src/urclock.c +++ b/src/urclock.c @@ -1757,7 +1757,7 @@ static int ur_readEF(const PROGRAMMER *pgm, const AVRPART *p, uint8_t *buf, uint int classic = !(p->prog_modes & (PM_UPDI | PM_PDI | PM_aWire)); pmsg_debug("ur_readEF(%s, %s, %s, %p, 0x%06x, %d, %c)\n", - (char *) ldata(lfirst(pgm->id)), p->desc, mchr=='F'? "flash": "eeprom", buf, badd, len, mchr); + pgmid, p->desc, mchr=='F'? "flash": "eeprom", buf, badd, len, mchr); if(mchr == 'F' && ur.urprotocol && !(ur.urfeatures & UB_READ_FLASH)) Return("bootloader does not have flash read capability"); @@ -2498,7 +2498,7 @@ static int urclock_parseextparms(const PROGRAMMER *pgm, LISTID extparms) { } if(help || rc < 0) { - msg_error("%s -c %s extended options:\n", progname, (char *) ldata(lfirst(pgm->id))); + msg_error("%s -c %s extended options:\n", progname, pgmid); for(size_t i=0; i": "", urmax(0, 16-(int) strlen(options[i].name)-(options[i].assign? 6: 0)), "", options[i].help); diff --git a/src/usbasp.c b/src/usbasp.c index 19dfbe3c..fe8d36fa 100644 --- a/src/usbasp.c +++ b/src/usbasp.c @@ -290,8 +290,7 @@ static int usbasp_parseextparms(const PROGRAMMER *pgm, const LISTID extparms) { continue; } if (str_eq(extended_param, "help")) { - char *prg = (char *)ldata(lfirst(pgm->id)); - msg_error("%s -c %s extended options:\n", progname, prg); + msg_error("%s -c %s extended options:\n", progname, pgmid); msg_error(" -xsection_config Erase configuration section only with -e (TPI only)\n"); msg_error(" -xhelp Show this help menu and exit\n"); exit(0); @@ -560,7 +559,7 @@ static int usbasp_open(PROGRAMMER *pgm, const char *port) { vid = pgm->usbvid? pgm->usbvid: USBASP_SHARED_VID; if (usbOpenDevice(&PDATA(pgm)->usbhandle, vid, pgm->usbvendor, pid, pgm->usbproduct) != 0) { /* try alternatives */ - if(strcasecmp(ldata(lfirst(pgm->id)), "usbasp") == 0) { + if(str_eq(pgmid, "usbasp")) { /* for id usbasp autodetect some variants */ if(strcasecmp(port, "nibobee") == 0) { pmsg_error("using -C usbasp -P nibobee is deprecated, use -C nibobee instead\n"); diff --git a/src/wiring.c b/src/wiring.c index 2a6c1bed..ae99b304 100644 --- a/src/wiring.c +++ b/src/wiring.c @@ -131,8 +131,7 @@ static int wiring_parseextparms(const PROGRAMMER *pgm, const LISTID extparms) { continue; } if (str_eq(extended_param, "help")) { - char *prg = (char *)ldata(lfirst(pgm->id)); - msg_error("%s -c %s extended options:\n", progname, prg); + msg_error("%s -c %s extended options:\n", progname, pgmid); msg_error(" -xsnooze= Wait [ms] before protocol sync after port open\n"); msg_error(" -xhelp Show this help menu and exit\n"); exit(0); diff --git a/src/xbee.c b/src/xbee.c index ee454162..0aaf0469 100644 --- a/src/xbee.c +++ b/src/xbee.c @@ -1652,8 +1652,7 @@ static int xbee_parseextparms(const PROGRAMMER *pgm, const LISTID extparms) { continue; } if (str_eq(extended_param, "help")) { - char *prg = (char *)ldata(lfirst(pgm->id)); - msg_error("%s -c %s extended options:\n", progname, prg); + msg_error("%s -c %s extended options:\n", progname, pgmid); msg_error(" -xxbeeresetpin=<1..7> Set XBee pin DIO<1..7> as reset pin\n"); msg_error(" -xhelp Show this help menu and exit\n"); exit(0);