Add assignment injection code for -c*/si

This commit is contained in:
Stefan Rueger 2022-09-14 18:04:12 +01:00
parent 7087fd9f3e
commit ac8fbadff4
No known key found for this signature in database
GPG Key ID: B0B4F1FD86B1EC55
1 changed files with 29 additions and 11 deletions

View File

@ -54,11 +54,18 @@
#include "developer_opts_private.h" #include "developer_opts_private.h"
// Inject part parameters into a semi-automated rewrite of avrdude.conf // Inject part parameters into a semi-automated rewrite of avrdude.conf
// - Add entries to the tables below; they get written on -p*/i // - Add entries to the tables below; they get written on -p*/si or -c*/si
// - Use the output in a new avrdude.conf // - Use the output in a new avrdude.conf
// - Output again with -p* (no /i) and use that for final avrdude.conf // - Output again with -p* or -c* (no /i) and use that for final avrdude.conf
// - Remove entries from below tables // - Remove entries from below tables
static struct {
const char *pgmid, *var, *value;
} pgminj[] = {
// Add triples here, eg, {"stk500v2", "prog_modes", "PM_TPI|PM_ISP"},
{NULL, NULL, NULL},
};
static struct { static struct {
const char *mcu, *var, *value; const char *mcu, *var, *value;
} ptinj[] = { } ptinj[] = {
@ -812,7 +819,7 @@ void dev_output_pgm_part(int dev_opt_c, char *programmer, int dev_opt_p, char *p
} }
// -p */[dASsrcow*t] // -p */[dASsrcow*ti]
void dev_output_part_defs(char *partdesc) { void dev_output_part_defs(char *partdesc) {
bool cmdok, waits, opspi, descs, astrc, strct, cmpst, injct, raw, all, tsv; bool cmdok, waits, opspi, descs, astrc, strct, cmpst, injct, raw, all, tsv;
char *flags; char *flags;
@ -1171,7 +1178,7 @@ static const char *connstr(conntype_t conntype) {
} }
} }
static void dev_pgm_strct(const PROGRAMMER *pgm, bool tsv, const PROGRAMMER *base) { static void dev_pgm_strct(const PROGRAMMER *pgm, bool tsv, const PROGRAMMER *base, bool injct) {
char *id = ldata(lfirst(pgm->id)); char *id = ldata(lfirst(pgm->id));
LNODEID ln; LNODEID ln;
COMMENT *cp; COMMENT *cp;
@ -1289,6 +1296,14 @@ static void dev_pgm_strct(const PROGRAMMER *pgm, bool tsv, const PROGRAMMER *bas
} }
} }
if(injct)
for(size_t i=0; i<sizeof pgminj/sizeof*pgminj; i++)
if(pgminj[i].pgmid)
for(LNODEID *ln=lfirst(pgm->id); ln; ln=lnext(ln))
if(strcmp(pgminj[i].pgmid, ldata(ln)) == 0)
dev_part_strct_entry(tsv, ".prog", ldata(ln), NULL,
pgminj[i].var, cfg_strdup("pgminj", pgminj[i].value), NULL);
if(!tsv) { if(!tsv) {
dev_cout(pgm->comments, ";", 0, 0); dev_cout(pgm->comments, ";", 0, 0);
dev_info(";\n"); dev_info(";\n");
@ -1296,9 +1311,9 @@ static void dev_pgm_strct(const PROGRAMMER *pgm, bool tsv, const PROGRAMMER *bas
} }
// -c */[ASsrt] // -c */[ASsrti]
void dev_output_pgm_defs(char *pgmid) { void dev_output_pgm_defs(char *pgmid) {
bool astrc, strct, cmpst, raw, tsv; bool astrc, strct, cmpst, raw, tsv, injct;
char *flags; char *flags;
int nprinted; int nprinted;
PROGRAMMER *nullpgm = pgm_new(); PROGRAMMER *nullpgm = pgm_new();
@ -1309,7 +1324,7 @@ void dev_output_pgm_defs(char *pgmid) {
if(!flags && !strcmp(pgmid, "*")) // Treat -c * as if it was -c */s if(!flags && !strcmp(pgmid, "*")) // Treat -c * as if it was -c */s
flags = "s"; flags = "s";
if(!*flags || !strchr("ASsrt", *flags)) { if(!*flags || !strchr("ASsrti", *flags)) {
dev_info("%s: flags for developer option -c <wildcard>/<flags> not recognised\n", progname); dev_info("%s: flags for developer option -c <wildcard>/<flags> not recognised\n", progname);
dev_info( dev_info(
"Wildcard examples (these need protecting in the shell through quoting):\n" "Wildcard examples (these need protecting in the shell through quoting):\n"
@ -1323,6 +1338,7 @@ void dev_output_pgm_defs(char *pgmid) {
" s show short entries of avrdude.conf programmers using parent\n" " s show short entries of avrdude.conf programmers using parent\n"
" r show entries of avrdude.conf programmers as raw dump\n" " r show entries of avrdude.conf programmers as raw dump\n"
" t use tab separated values as much as possible\n" " t use tab separated values as much as possible\n"
" i inject assignments from source code table\n"
"Examples:\n" "Examples:\n"
" $ avrdude -c usbasp/s\n" " $ avrdude -c usbasp/s\n"
" $ avrdude -c */st | grep baudrate\n" " $ avrdude -c */st | grep baudrate\n"
@ -1343,6 +1359,7 @@ void dev_output_pgm_defs(char *pgmid) {
cmpst = !!strchr(flags, 's'); cmpst = !!strchr(flags, 's');
raw = !!strchr(flags, 'r'); raw = !!strchr(flags, 'r');
tsv = !!strchr(flags, 't'); tsv = !!strchr(flags, 't');
injct = !!strchr(flags, 'i');
nprinted = dev_nprinted; nprinted = dev_nprinted;
@ -1368,7 +1385,8 @@ void dev_output_pgm_defs(char *pgmid) {
dev_pgm_strct(pgm, tsv, dev_pgm_strct(pgm, tsv,
astrc? NULL: astrc? NULL:
strct? nullpgm: strct? nullpgm:
pgm->parent_id && *pgm->parent_id? locate_programmer(programmers, pgm->parent_id): nullpgm); pgm->parent_id && *pgm->parent_id? locate_programmer(programmers, pgm->parent_id): nullpgm,
injct);
if(raw) if(raw)
dev_pgm_raw(pgm); dev_pgm_raw(pgm);