From 872fb9d53ee7ed588142ecd5b7e63ef35c446cba Mon Sep 17 00:00:00 2001 From: Stefan Rueger Date: Wed, 25 Oct 2023 13:24:37 +0100 Subject: [PATCH] Replace and remove avr_memstr_is_...() functions --- src/avr.c | 22 +++------------------- src/libavrdude.h | 7 +------ src/main.c | 3 ++- 3 files changed, 6 insertions(+), 26 deletions(-) diff --git a/src/avr.c b/src/avr.c index 61710a08..f3715f60 100644 --- a/src/avr.c +++ b/src/avr.c @@ -1524,32 +1524,16 @@ int avr_get_mem_type(const char *str) { exit(1); } -int avr_memstr_is_flash_type(const char *memstr) { - return memstr && ( - str_eq(memstr, "flash") || - str_eq(memstr, "application") || - str_eq(memstr, "apptable") || - str_eq(memstr, "boot")); -} - int avr_mem_is_flash_type(const AVRMEM *mem) { - return avr_memstr_is_flash_type(mem->desc); -} - -int avr_memstr_is_eeprom_type(const char *memstr) { - return memstr && str_eq(memstr, "eeprom"); + return mem_is_in_flash(mem); } int avr_mem_is_eeprom_type(const AVRMEM *mem) { - return avr_memstr_is_eeprom_type(mem->desc); -} - -int avr_memstr_is_usersig_type(const char *memstr) { // Bootrow is subsumed under usersig type - return memstr && (str_eq(memstr, "bootrow") || str_eq(memstr, "usersig") || str_eq(memstr, "userrow")); + return mem_is_eeprom(mem); } int avr_mem_is_usersig_type(const AVRMEM *mem) { - return avr_memstr_is_usersig_type(mem->desc); + return mem_is_user_type(mem); } int avr_mem_is_known(const char *str) { diff --git a/src/libavrdude.h b/src/libavrdude.h index 3036f494..3b16c304 100644 --- a/src/libavrdude.h +++ b/src/libavrdude.h @@ -400,6 +400,7 @@ typedef struct { #define mem_is_user_type(mem) (!!((mem)->type & MEM_USER_TYPE)) #define mem_is_in_sigrow(mem) (!!((mem)->type & MEM_IN_SIGROW)) // If sigrow exists, that is #define mem_is_readonly(mem) (!!((mem)->type & MEM_READONLY)) +#define mem_is_paged_type(mem) (!!((mem)->type & (MEM_IN_FLASH | MEM_EEPROM | MEM_USER_TYPE))) #define mem_fuse_offset(mem) ((mem)->type & MEM_FUSEOFF_MASK) // Valid if mem_is_a_fuse(mem) @@ -1060,16 +1061,10 @@ char *avr_prog_modes(int pm); int avr_get_mem_type(const char *str); -int avr_memstr_is_flash_type(const char *mem); - int avr_mem_is_flash_type(const AVRMEM *mem); -int avr_memstr_is_eeprom_type(const char *mem); - int avr_mem_is_eeprom_type(const AVRMEM *mem); -int avr_memstr_is_usersig_type(const char *mem); - int avr_mem_is_usersig_type(const AVRMEM *mem); int avr_mem_is_known(const char *str); diff --git a/src/main.c b/src/main.c index e02db6f2..9af4840e 100644 --- a/src/main.c +++ b/src/main.c @@ -1586,6 +1586,7 @@ skipopen: int wrmem = 0, terminal = 0; for (ln=lfirst(updates); ln; ln=lnext(ln)) { + const AVRMEM *m; upd = ldata(ln); if(upd->cmdline && wrmem) { // Invalidate cache if device was written to wrmem = 0; @@ -1600,7 +1601,7 @@ skipopen: if (rc && rc != LIBAVRDUDE_SOFTFAIL) { exitrc = 1; break; - } else if(rc == 0 && upd->op == DEVICE_WRITE && avr_memstr_is_flash_type(upd->memstr)) + } else if(rc == 0 && upd->op == DEVICE_WRITE && (m = avr_locate_mem(p, upd->memstr)) && mem_is_in_flash(m)) ce_delayed = 0; // Redeemed chip erase promise } pgm->flush_cache(pgm, p);