From 42c8169c37923345758664ca3fdc4e229bc112d0 Mon Sep 17 00:00:00 2001 From: Stefan Rueger Date: Tue, 2 Aug 2022 23:53:00 +0100 Subject: [PATCH] Add ordered list of known memories to avr.c with access functions --- src/avr.c | 39 +++++++++++++++++++++++++++++++++++++++ src/config_gram.y | 1 + src/developer_opts.c | 43 +++++++------------------------------------ src/libavrdude.h | 5 +++++ 4 files changed, 52 insertions(+), 36 deletions(-) diff --git a/src/avr.c b/src/avr.c index 7f91e9a1..eb077b32 100644 --- a/src/avr.c +++ b/src/avr.c @@ -1220,7 +1220,46 @@ int avr_put_cycle_count(PROGRAMMER * pgm, AVRPART * p, int cycles) } return 0; +} + + +// Typical order in which memories show in avrdude.conf, runtime adds unknown ones (if any) +const char *avr_mem_order[100] = { + "eeprom", "flash", "application", "apptable", + "boot", "lfuse", "hfuse", "efuse", + "fuse", "fuse0", "wdtcfg", "fuse1", + "bodcfg", "fuse2", "osccfg", "fuse3", + "fuse4", "tcd0cfg", "fuse5", "syscfg0", + "fuse6", "syscfg1", "fuse7", "append", + "codesize", "fuse8", "fuse9", "bootend", + "bootsize", "fuses", "lock", "lockbits", + "tempsense", "signature", "prodsig", "sernum", + "calibration", "osccal16", "osccal20", "osc16err", + "osc20err", "usersig", "userrow", "data", +}; + +void avr_add_mem_order(const char *str) { + for(size_t i=0; i < sizeof avr_mem_order/sizeof *avr_mem_order; i++) { + if(avr_mem_order[i] && !strcmp(avr_mem_order[i], str)) + return; + if(!avr_mem_order[i]) { + avr_mem_order[i] = strdup(str); + return; + } } + avrdude_message(MSG_INFO, + "%s: avr_mem_order[] under-dimensioned in avr.c; increase and recompile\n", + progname); + exit(1); +} + +int avr_known_mem(const char *str) { + for(size_t i=0; i < sizeof avr_mem_order/sizeof *avr_mem_order; i++) + if(avr_mem_order[i] && !strcmp(avr_mem_order[i], str)) + return 1; + return 0; +} + int avr_chip_erase(PROGRAMMER * pgm, AVRPART * p) { diff --git a/src/config_gram.y b/src/config_gram.y index 68718dd1..ce11b924 100644 --- a/src/config_gram.y +++ b/src/config_gram.y @@ -1320,6 +1320,7 @@ part_parm : mem->desc[AVR_MEMDESCLEN-1] = 0; ladd(current_part->mem, mem); } + avr_add_mem_order($2->value.string); current_mem = mem; free_token($2); } diff --git a/src/developer_opts.c b/src/developer_opts.c index f4a55478..b82c1805 100644 --- a/src/developer_opts.c +++ b/src/developer_opts.c @@ -280,35 +280,6 @@ static void dev_stack_out(bool tsv, AVRPART *p, const char *name, unsigned char } -// order in which memories are processed, runtime adds unknown ones (but there shouldn't be any) -static const char *mem_order[100] = { - "eeprom", "flash", "application", "apptable", - "boot", "lfuse", "hfuse", "efuse", - "fuse", "fuse0", "wdtcfg", "fuse1", - "bodcfg", "fuse2", "osccfg", "fuse3", - "fuse4", "tcd0cfg", "fuse5", "syscfg0", - "fuse6", "syscfg1", "fuse7", "append", - "codesize", "fuse8", "fuse9", "bootend", - "bootsize", "fuses", "lock", "lockbits", - "tempsense", "signature", "prodsig", "sernum", - "calibration", "osccal16", "osccal20", "osc16err", - "osc20err", "usersig", "userrow", "data", -}; - -static void add_mem_order(const char *str) { - for(size_t i=0; i < sizeof mem_order/sizeof *mem_order; i++) { - if(mem_order[i] && !strcmp(mem_order[i], str)) - return; - if(!mem_order[i]) { - mem_order[i] = strdup(str); - return; - } - } - dev_info("%s: mem_order[] under-dimensioned in developer_opts.c; increase and recompile\n", progname); - exit(1); -} - - static int intcmp(int a, int b) { return a-b; } @@ -410,8 +381,8 @@ static int avrpart_deep_copy(AVRPARTdeep *d, AVRPART *p) { // fill in all memories we got in defined order di = 0; - for(size_t mi=0; mi < sizeof mem_order/sizeof *mem_order && mem_order[mi]; mi++) { - m = p->mem? avr_locate_mem(p, mem_order[mi]): NULL; + for(size_t mi=0; mi < sizeof avr_mem_order/sizeof *avr_mem_order && avr_mem_order[mi]; mi++) { + m = p->mem? avr_locate_mem(p, avr_mem_order[mi]): NULL; if(m) { if(di >= sizeof d->mems/sizeof *d->mems) { avrdude_message(MSG_INFO, "%s: ran out of mems[] space, increase size in AVRMEMdeep of developer_opts.c and recompile\n", progname); @@ -566,11 +537,11 @@ static void dev_part_strct(AVRPART *p, bool tsv, AVRPART *base) { if(!base || opcodecmp(p->op[i], base->op[i], i)) dev_part_strct_entry(tsv, ".ptop", p->desc, "part", opcodename(i), opcode2str(p->op[i], i, !tsv)); - for(size_t mi=0; mi < sizeof mem_order/sizeof *mem_order && mem_order[mi]; mi++) { + for(size_t mi=0; mi < sizeof avr_mem_order/sizeof *avr_mem_order && avr_mem_order[mi]; mi++) { AVRMEM *m, *bm; - m = p->mem? avr_locate_mem(p, mem_order[mi]): NULL; - bm = base && base->mem? avr_locate_mem(base, mem_order[mi]): NULL; + m = p->mem? avr_locate_mem(p, avr_mem_order[mi]): NULL; + bm = base && base->mem? avr_locate_mem(base, avr_mem_order[mi]): NULL; if(!m && bm && !tsv) dev_info("\n memory \"%s\" = NULL;\n", bm->desc); @@ -694,12 +665,12 @@ void dev_output_part_defs(char *partdesc) { AVRPART *p = ldata(ln1); if(p->mem) for(LNODEID lnm=lfirst(p->mem); lnm; lnm=lnext(lnm)) - add_mem_order(((AVRMEM *) ldata(lnm))->desc); + avr_add_mem_order(((AVRMEM *) ldata(lnm))->desc); // same for aliased memories (though probably not needed) if(p->mem_alias) for(LNODEID lnm=lfirst(p->mem_alias); lnm; lnm=lnext(lnm)) - add_mem_order(((AVRMEM_ALIAS *) ldata(lnm))->desc); + avr_add_mem_order(((AVRMEM_ALIAS *) ldata(lnm))->desc); } nprinted = dev_nprinted; diff --git a/src/libavrdude.h b/src/libavrdude.h index 95e08d18..cc332ec7 100644 --- a/src/libavrdude.h +++ b/src/libavrdude.h @@ -783,6 +783,7 @@ void sort_programmers(LISTID programmers); typedef void (*FP_UpdateProgress)(int percent, double etime, char *hdr); extern struct avrpart parts[]; +extern const char *avr_mem_order[100]; extern FP_UpdateProgress update_progress; @@ -818,6 +819,10 @@ int avr_get_cycle_count(PROGRAMMER * pgm, AVRPART * p, int * cycles); int avr_put_cycle_count(PROGRAMMER * pgm, AVRPART * p, int cycles); +void avr_add_mem_order(const char *str); + +int avr_known_mem(const char *str); + #define disable_trailing_ff_removal() avr_mem_hiaddr(NULL) int avr_mem_hiaddr(AVRMEM * mem);