Weaken -U memory type check and move after config file parsing in main.c

The check for typos in -U memory names against a list of known memory names
now happens after the config files have been read, so newly declared memory
names can be considered. This commit also weakens the check against existence
of a known memory: it is now sufficent for a name to pass when it could be
the initial string of any known memory of any part. Any -U memory that cannot
possibly be matched up with a known memory is considered a typo and leads to
an exit before the programmer is opened.

This to protect users from typos that leave a device partially programmed.

When every -U memory name might be matching one of the known memories, the
programming is attempted. If the part to be programmed turns out not to have
a particular -U memory, AVRDUDE warns the user and skips this -U update.

This to support unifying interfaces that call AVRDUDE with potentially more
memories than the actual part has (eg, efuse on ATmega8).
This commit is contained in:
Stefan Rueger 2022-08-04 00:14:19 +01:00
parent 648f3319a9
commit 3412196cd9
4 changed files with 20 additions and 9 deletions

View File

@ -1254,9 +1254,18 @@ void avr_add_mem_order(const char *str) {
}
int avr_mem_is_known(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;
if(str && *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_mem_might_be_known(const char *str) {
if(str && *str)
for(size_t i=0; i < sizeof avr_mem_order/sizeof *avr_mem_order; i++)
if(avr_mem_order[i] && !strncmp(avr_mem_order[i], str, strlen(str)))
return 1;
return 0;
}

View File

@ -822,6 +822,7 @@ int avr_put_cycle_count(PROGRAMMER * pgm, AVRPART * p, int cycles);
void avr_add_mem_order(const char *str);
int avr_mem_is_known(const char *str);
int avr_mem_might_be_known(const char *str);
#define disable_trailing_ff_removal() avr_mem_hiaddr(NULL)
int avr_mem_hiaddr(AVRMEM * mem);

View File

@ -751,6 +751,7 @@ int main(int argc, char * argv [])
bitclock = default_bitclock;
}
avrdude_message(MSG_NOTICE, "\n");
// developer option -p <wildcard>/[*codws] prints various aspects of part descriptions and exits
@ -918,6 +919,12 @@ int main(int argc, char * argv [])
exit(1);
}
}
if (!avr_mem_might_be_known(upd->memtype)) {
avrdude_message(MSG_INFO, "%s: unknown memory type %s\n", progname, upd->memtype);
exit(1);
}
// TODO: check whether filename other than "-" is readable/writable
}
/*

View File

@ -62,12 +62,6 @@ UPDATE * parse_op(char * s)
return upd;
}
if (!avr_mem_is_known(buf)) {
avrdude_message(MSG_INFO, "%s: unknown memory type %s\n", progname, buf);
free(upd);
return NULL;
}
upd->memtype = (char *)malloc(strlen(buf)+1);
if (upd->memtype == NULL) {
avrdude_message(MSG_INFO, "%s: out of memory\n", progname);