Skip to content

Commit

Permalink
Merge pull request avrdudes#1816 from stefanrueger/differentiate-prog…
Browse files Browse the repository at this point in the history
…-mode

Allow selection of program modes for developer options
  • Loading branch information
stefanrueger authored Jun 1, 2024
2 parents 48b5874 + d3c1777 commit 4fcb10d
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 28 deletions.
91 changes: 67 additions & 24 deletions src/developer_opts.c
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,29 @@ void dev_output_pgm_part(int dev_opt_c, const char *programmer, int dev_opt_p, c
}


// -p */[dASsrcow*ti]
// Which programming modes should be considered, given the flags?
static int prog_modes_in_flags(int prog_modes, const char *flags) {
int pm = 0, quirky = 0;

for(const char *p = flags; *p; p++)
switch(*p) {
case 'B': pm |= PM_SPM; break;
case 'U': pm |= PM_UPDI; break;
case 'P': pm |= PM_PDI; break;
case 'T': pm |= PM_TPI; break;
case 'I': pm |= PM_ISP; break;
case 'J': pm |= PM_JTAG | PM_JTAGmkI | PM_XMEGAJTAG; break;
case 'W': pm |= PM_debugWIRE; break;
case 'H': pm |= PM_HVPP | PM_HVSP; break;
case 'Q': pm |= PM_ALL & ~(PM_SPM | PM_UPDI | PM_PDI | PM_TPI | PM_ISP | PM_JTAG | PM_JTAGmkI |
PM_XMEGAJTAG | PM_debugWIRE | PM_HVPP | PM_HVSP);
quirky = 1;
}

return (prog_modes == 0 && quirky) || !pm || (prog_modes & pm);
}

// -p <wildcard>/[cdoASsrw*tiBUPTIJWHQ]
void dev_output_part_defs(char *partdesc) {
bool cmdok, waits, opspi, descs, astrc, strct, cmpst, injct, raw, all, tsv;
char *flags;
Expand All @@ -840,7 +862,7 @@ void dev_output_part_defs(char *partdesc) {
if(!flags && str_eq(partdesc, "*")) // Treat -p * as if it was -p */s
flags = "s";

if(!*flags || !strchr("cdoASsrw*ti", *flags)) {
if(!*flags || !strchr("cdoASsrw*tiBUPTIJWHQ", *flags)) {
dev_info("%s: flags for developer option -p <wildcard>/<flags> not recognised\n", progname);
dev_info(
"Wildcard examples (these need protecting in the shell through quoting):\n"
Expand All @@ -849,20 +871,22 @@ void dev_output_part_defs(char *partdesc) {
" *32[0-9] matches ATmega329, ATmega325 and ATmega328\n"
" *32? matches ATmega329, ATmega32A, ATmega325 and ATmega328\n"
"Flags (one or more of the characters below):\n"
" d description of core part features\n"
" A show entries of avrdude.conf parts with all values\n"
" S show entries of avrdude.conf parts with necessary values\n"
" s show short entries of avrdude.conf parts using parent\n"
" r show entries of avrdude.conf parts as raw dump\n"
" c check and report errors in address bits of SPI commands\n"
" o opcodes for SPI programming parts and memories\n"
" w wd_... constants for ISP parts\n"
" * all of the above except s and S\n"
" t use tab separated values as much as possible\n"
" i inject assignments from source code table\n"
" d description of core part features\n"
" A show entries of avrdude.conf parts with all values\n"
" S show entries of avrdude.conf parts with necessary values\n"
" s show short entries of avrdude.conf parts using parent\n"
" r show entries of avrdude.conf parts as raw dump\n"
" c check and report errors in address bits of SPI commands\n"
" o opcodes for SPI programming parts and memories\n"
" w wd_... constants for ISP parts\n"
" * as first character: all of the above except s and S\n"
" BUPTIJWHQ only Bootloader/UPDI/PDI/TPI/ISP/JTAG/debugWire/HV/quirky MUCs\n"
" t use tab separated values as much as possible\n"
" i inject assignments from source code table\n"
"Examples:\n"
" $ avrdude -p ATmega328P/s\n"
" $ avrdude -p m328*/st | grep chip_erase_delay\n"
" $ avrdude -p ATmega*/Ud | wc -l\n"
" avrdude -p*/r | sort\n"
"Notes:\n"
" -p * is the same as -p */s\n"
Expand All @@ -888,7 +912,6 @@ void dev_output_part_defs(char *partdesc) {
tsv = !!strchr(flags, 't');
injct = !!strchr(flags, 'i');


// Go through all memories and add them to the memory order list
for(LNODEID ln1 = lfirst(part_list); ln1; ln1 = lnext(ln1)) {
AVRPART *p = ldata(ln1);
Expand Down Expand Up @@ -918,6 +941,8 @@ void dev_output_part_defs(char *partdesc) {

if(!part_eq(p, partdesc, str_casematch))
continue;
if(!prog_modes_in_flags(p->prog_modes, flags))
continue;

if(astrc || strct || cmpst)
dev_part_strct(p, tsv,
Expand Down Expand Up @@ -1338,9 +1363,9 @@ static void dev_pgm_strct(const PROGRAMMER *pgm, bool tsv, const PROGRAMMER *bas
}


// -c */[ASsrti]
// -c <wildcard>/[dASsrtiBUPTIJWHQ]
void dev_output_pgm_defs(char *pgmidcp) {
bool astrc, strct, cmpst, raw, tsv, injct;
bool descs, astrc, strct, cmpst, raw, tsv, injct;
char *flags;
int nprinted;
PROGRAMMER *nullpgm = pgm_new();
Expand All @@ -1351,7 +1376,7 @@ void dev_output_pgm_defs(char *pgmidcp) {
if(!flags && str_eq(pgmidcp, "*")) // Treat -c * as if it was -c */s
flags = "s";

if(!*flags || !strchr("ASsrti", *flags)) {
if(!*flags || !strchr("dASsrtiBUPTIJWHQ", *flags)) {
dev_info("%s: flags for developer option -c <wildcard>/<flags> not recognised\n", progname);
dev_info(
"Wildcard examples (these need protecting in the shell through quoting):\n"
Expand All @@ -1360,12 +1385,14 @@ void dev_output_pgm_defs(char *pgmidcp) {
" jtag*pdi matches jtag2pdi, jtag3pdi, jtag3updi and jtag2updi\n"
" jtag?pdi matches jtag2pdi and jtag3pdi\n"
"Flags (one or more of the characters below):\n"
" A show entries of avrdude.conf programmers with all values\n"
" S show entries of avrdude.conf programmers with necessary values\n"
" s show short entries of avrdude.conf programmers using parent\n"
" r show entries of avrdude.conf programmers as raw dump\n"
" t use tab separated values as much as possible\n"
" i inject assignments from source code table\n"
" d description of core programmer features\n"
" A show entries of avrdude.conf programmers with all values\n"
" S show entries of avrdude.conf programmers with necessary values\n"
" s show short entries of avrdude.conf programmers using parent\n"
" r show entries of avrdude.conf programmers as raw dump\n"
" t use tab separated values as much as possible\n"
" i inject assignments from source code table\n"
" BUPTIJWHQ only Bootloader/UPDI/PDI/TPI/ISP/JTAG/debugWire/HV/quirky MUCs\n"
"Examples:\n"
" $ avrdude -c usbasp/s\n"
" $ avrdude -c */st | grep baudrate\n"
Expand All @@ -1384,6 +1411,7 @@ void dev_output_pgm_defs(char *pgmidcp) {
astrc = !!strchr(flags, 'A');
strct = !!strchr(flags, 'S');
cmpst = !!strchr(flags, 's');
descs = !!strchr(flags, 'd');
raw = !!strchr(flags, 'r');
tsv = !!strchr(flags, 't');
injct = !!strchr(flags, 'i');
Expand All @@ -1402,8 +1430,10 @@ void dev_output_pgm_defs(char *pgmidcp) {
}
if(!matched)
continue;
if(!prog_modes_in_flags(pgm->prog_modes, flags))
continue;

if(dev_nprinted > nprinted) {
if(!descs && dev_nprinted > nprinted) {
dev_info("\n");
nprinted = dev_nprinted;
}
Expand All @@ -1415,6 +1445,19 @@ void dev_output_pgm_defs(char *pgmidcp) {
pgm->parent_id && *pgm->parent_id? locate_programmer(programmers, pgm->parent_id): nullpgm,
injct);

if(descs)
for(LNODEID idn=lfirst(pgm->id); idn; idn=lnext(idn)) {
char *id = ldata(idn);
int len = 19-strlen(id);
dev_info("%s '%s' =>%*s ['%s', '%s'], # %s %d\n",
tsv? ".desc": " ",
id, len > 0? len: 0, "",
dev_prog_modes(pgm->prog_modes),
pgm->desc,
pgm->config_file, pgm->lineno
);
}

if(raw)
dev_pgm_raw(pgm);
}
Expand Down
8 changes: 4 additions & 4 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,11 +437,11 @@ static void replace_backslashes(char *s)
}
}

// Return 2 if str is * or starts with */, 1 if str contains / but is not a valid part, 0 otherwise
// Return whether a part/programmer string is a developer option and if so which type
static int dev_opt(const char *str) {
return
!str? 0:
str_eq(str, "*") || str_starts(str, "*/")? 2:
str_eq(str, "*") || str_starts(str, "*/s")? 2: // Print PART DEFINITIONS comment as well
strchr(str, '/') && !locate_part(part_list, str);
}

Expand Down Expand Up @@ -1127,8 +1127,8 @@ int main(int argc, char * argv [])
pgmid = cache_string(default_programmer);

// Developer options to print parts and/or programmer entries of avrdude.conf
int dev_opt_c = dev_opt(pgmid); // -c <wildcard>/[sSArt]
int dev_opt_p = dev_opt(partdesc); // -p <wildcard>/[dsSArcow*t]
int dev_opt_c = dev_opt(pgmid); // -c <wildcard>/[dASsrtiBUPTIJWHQ]
int dev_opt_p = dev_opt(partdesc); // -p <wildcard>/[cdoASsrw*tiBUPTIJWHQ]

if(dev_opt_c || dev_opt_p) { // See -c/h and or -p/h
dev_output_pgm_part(dev_opt_c, pgmid, dev_opt_p, partdesc);
Expand Down

0 comments on commit 4fcb10d

Please sign in to comment.