Fix shell exit value when chip erase is delayed to next flash write

This commit is contained in:
Stefan Rueger 2022-11-23 19:53:55 +00:00
parent 883d9494c8
commit c3413ff0f4
No known key found for this signature in database
GPG Key ID: B0B4F1FD86B1EC55
3 changed files with 25 additions and 9 deletions

View File

@ -1257,16 +1257,24 @@ void avr_add_mem_order(const char *str) {
exit(1); exit(1);
} }
int avr_memtype_is_flash_type(const char *memtype) {
return memtype && (
strcmp(memtype, "flash") == 0 ||
strcmp(memtype, "application") == 0 ||
strcmp(memtype, "apptable") == 0 ||
strcmp(memtype, "boot") == 0);
}
int avr_mem_is_flash_type(const AVRMEM *mem) { int avr_mem_is_flash_type(const AVRMEM *mem) {
return return avr_memtype_is_flash_type(mem->desc);
strcmp(mem->desc, "flash") == 0 || }
strcmp(mem->desc, "application") == 0 ||
strcmp(mem->desc, "apptable") == 0 || int avr_memtype_is_eeprom_type(const char *memtype) {
strcmp(mem->desc, "boot") == 0; return memtype && strcmp(memtype, "eeprom") == 0;
} }
int avr_mem_is_eeprom_type(const AVRMEM *mem) { int avr_mem_is_eeprom_type(const AVRMEM *mem) {
return strcmp(mem->desc, "eeprom") == 0; return avr_memtype_is_eeprom_type(mem->desc);
} }
int avr_mem_is_known(const char *str) { int avr_mem_is_known(const char *str) {

View File

@ -897,8 +897,12 @@ int avr_put_cycle_count(const PROGRAMMER *pgm, const AVRPART *p, int cycles);
void avr_add_mem_order(const char *str); void avr_add_mem_order(const char *str);
int avr_memtype_is_flash_type(const char *mem);
int avr_mem_is_flash_type(const AVRMEM *mem); int avr_mem_is_flash_type(const AVRMEM *mem);
int avr_memtype_is_eeprom_type(const char *mem);
int avr_mem_is_eeprom_type(const AVRMEM *mem); int avr_mem_is_eeprom_type(const AVRMEM *mem);
int avr_mem_is_known(const char *str); int avr_mem_is_known(const char *str);

View File

@ -495,6 +495,7 @@ int main(int argc, char * argv [])
int ispdelay; /* Specify the delay for ISP clock */ int ispdelay; /* Specify the delay for ISP clock */
int init_ok; /* Device initialization worked well */ int init_ok; /* Device initialization worked well */
int is_open; /* Device open succeeded */ int is_open; /* Device open succeeded */
int ce_delayed; /* Chip erase delayed */
char * logfile; /* Use logfile rather than stderr for diagnostics */ char * logfile; /* Use logfile rather than stderr for diagnostics */
enum updateflags uflags = UF_AUTO_ERASE | UF_VERIFY; /* Flags for do_op() */ enum updateflags uflags = UF_AUTO_ERASE | UF_VERIFY; /* Flags for do_op() */
@ -574,6 +575,7 @@ int main(int argc, char * argv [])
bitclock = 0.0; bitclock = 0.0;
ispdelay = 0; ispdelay = 0;
is_open = 0; is_open = 0;
ce_delayed = 0;
logfile = NULL; logfile = NULL;
len = strlen(progname) + 2; len = strlen(progname) + 2;
@ -1400,7 +1402,8 @@ int main(int argc, char * argv [])
exitrc = avr_chip_erase(pgm, p); exitrc = avr_chip_erase(pgm, p);
if(exitrc == LIBAVRDUDE_SOFTFAIL) { if(exitrc == LIBAVRDUDE_SOFTFAIL) {
imsg_info("delaying chip erase until first -U upload to flash\n"); imsg_info("delaying chip erase until first -U upload to flash\n");
exitrc = 1; ce_delayed = 1;
exitrc = 0;
} else if(exitrc) } else if(exitrc)
goto main_exit; goto main_exit;
} }
@ -1428,7 +1431,8 @@ int main(int argc, char * argv [])
if (rc && rc != LIBAVRDUDE_SOFTFAIL) { if (rc && rc != LIBAVRDUDE_SOFTFAIL) {
exitrc = 1; exitrc = 1;
break; break;
} } else if(rc == 0 && upd->op == DEVICE_WRITE && avr_memtype_is_flash_type(upd->memtype))
ce_delayed = 0; // Redeemed chip erase promise
} }
main_exit: main_exit:
@ -1449,5 +1453,5 @@ main_exit:
msg_info("\n%s done. Thank you.\n\n", progname); msg_info("\n%s done. Thank you.\n\n", progname);
return exitrc; return ce_delayed? 1: exitrc;
} }