From 3aaa722f72a32f153867efb0a8147da75c7951d2 Mon Sep 17 00:00:00 2001 From: Stefan Rueger Date: Tue, 2 Jul 2024 19:48:48 +0100 Subject: [PATCH] Inspect memory lists to decide whether initial chip erase is needed --- src/libavrdude.h | 2 ++ src/main.c | 19 +++++-------------- src/update.c | 17 +++++++++++++++-- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/libavrdude.h b/src/libavrdude.h index d67420f9..627d54b1 100644 --- a/src/libavrdude.h +++ b/src/libavrdude.h @@ -1318,6 +1318,8 @@ int update_is_readable(const char *fn); int update_dryrun(const AVRPART *p, UPDATE *upd); +AVRMEM **memory_list(const char *mstr, const AVRPART *p, int *np, int *rwvsoftp, int *dry); +int memlist_contains_flash(const char *mstr, const AVRPART *p); #ifdef __cplusplus } diff --git a/src/main.c b/src/main.c index 6cc74233..9f7dc311 100644 --- a/src/main.c +++ b/src/main.c @@ -242,7 +242,7 @@ static void usage(void) " -r Reconnect to -P port after \"touching\" it; wait\n" " 400 ms for each -r; needed for some USB boards\n" " -F Override invalid signature or initial checks\n" - " -e Perform a chip erase\n" + " -e Perform a chip erase at the beginning\n" " -O Perform RC oscillator calibration (see AVR053)\n" " -t Run an interactive terminal when it is its turn\n" " -T Run terminal line when it is its turn\n" @@ -1686,22 +1686,13 @@ skipopen: imsg_info("Each page will be erased before programming it, but no chip erase is performed.\n"); imsg_info("To disable page erases, specify the -D option; for a chip-erase, use the -e option.\n"); } else { - AVRMEM * m; - const char *memname = p->prog_modes & PM_PDI? "application": "flash"; - uflags &= ~UF_AUTO_ERASE; - for (ln=lfirst(updates); ln; ln=lnext(ln)) { + for(ln=lfirst(updates); !erase && ln; ln=lnext(ln)) { upd = ldata(ln); - if(!upd->memstr) - continue; - m = avr_locate_mem(p, upd->memstr); - if (m == NULL) - continue; - if(str_eq(m->desc, memname) && upd->op == DEVICE_WRITE) { + if(upd->memstr && upd->op == DEVICE_WRITE && memlist_contains_flash(upd->memstr, p)) { erase = 1; - pmsg_info("Note: %s memory has been specified, an erase cycle will be performed.\n", memname); - imsg_info("To disable this feature, specify the -D option.\n"); - break; + pmsg_info("Note: carrying out an erase cycle as flash memory needs programming (-U %s:w:...)\n", upd->memstr); + imsg_info("specify the -D option to disable this feature\n"); } } } diff --git a/src/update.c b/src/update.c index 7829d9fa..80a1326f 100644 --- a/src/update.c +++ b/src/update.c @@ -38,7 +38,7 @@ // Is s a multi-memory string (comma-separates list, all, ALL, etc or list subtraction)? static int is_multimem(const char *s) { - return str_eq(s, "ALL") || str_eq(s, "all") || str_eq(s, "etc") || strpbrk(s, ",\\"); + return str_eq(s, "ALL") || str_eq(s, "all") || str_eq(s, "etc") || strpbrk(s, "-,\\"); } /* @@ -304,7 +304,7 @@ static int memadd(AVRMEM **mlist, int nm, int not, AVRMEM *m) { * to *np and *rwvsoftfail indicating unknown memories for this part. If dry is * set then -1 will be written to *dry when a generally unknown memory is used. */ -static AVRMEM **memory_list(const char *mstr, const AVRPART *p, int *np, int *rwvsoftp, int *dry) { +AVRMEM **memory_list(const char *mstr, const AVRPART *p, int *np, int *rwvsoftp, int *dry) { int not, nm = (lsize(p->mem) + 1) * ((int) str_numc(mstr, ',') + 1); // Upper limit AVRMEM *m, **umemlist = mmt_malloc(nm*sizeof*umemlist); char *dstr = mmt_strdup(mstr), *s = dstr, *e; @@ -363,6 +363,19 @@ done: return umemlist; } + +// Returns whether or not the memory list contains a flash memory +int memlist_contains_flash(const char *mstr, const AVRPART *p) { + int ret = 0, nm = 0; + AVRMEM **mlist = memory_list(mstr, p, &nm, NULL, NULL); + for(int i=0; i