From dfef8bb0a8afce211836e0153fecec707ba427b0 Mon Sep 17 00:00:00 2001 From: Stefan Rueger Date: Mon, 15 Aug 2022 14:57:04 +0100 Subject: [PATCH] Add libavrdude functions avr_mem_is_flash_type() and avr_mem_is_eeprom_type() --- src/avr.c | 17 +++++++++++++---- src/flip1.c | 6 +++--- src/flip2.c | 6 +++--- src/jtag3.c | 7 ++----- src/jtagmkII.c | 7 ++----- src/libavrdude.h | 5 +++++ src/main.c | 2 +- 7 files changed, 29 insertions(+), 21 deletions(-) diff --git a/src/avr.c b/src/avr.c index 62760ce7..49994c47 100644 --- a/src/avr.c +++ b/src/avr.c @@ -295,10 +295,7 @@ int avr_mem_hiaddr(AVRMEM * mem) return mem->size; /* if the memory is not a flash-type memory do not remove trailing 0xff */ - if(strcasecmp(mem->desc, "flash") && - strcasecmp(mem->desc, "application") && - strcasecmp(mem->desc, "apptable") && - strcasecmp(mem->desc, "boot")) + if(!avr_mem_is_flash_type(mem)) return mem->size; /* return the highest non-0xff address regardless of how much @@ -1253,6 +1250,18 @@ void avr_add_mem_order(const char *str) { exit(1); } +int avr_mem_is_flash_type(AVRMEM *mem) { + return + strcmp(mem->desc, "flash") == 0 || + strcmp(mem->desc, "application") == 0 || + strcmp(mem->desc, "apptable") == 0 || + strcmp(mem->desc, "boot") == 0; +} + +int avr_mem_is_eeprom_type(AVRMEM *mem) { + return strcmp(mem->desc, "eeprom") == 0; +} + int avr_mem_is_known(const char *str) { if(str && *str) for(size_t i=0; i < sizeof avr_mem_order/sizeof *avr_mem_order; i++) diff --git a/src/flip1.c b/src/flip1.c index 0c8a3ab2..4db54aad 100644 --- a/src/flip1.c +++ b/src/flip1.c @@ -395,7 +395,7 @@ int flip1_read_byte(PROGRAMMER* pgm, AVRPART *part, AVRMEM *mem, if (FLIP1(pgm)->dfu == NULL) return -1; - if (strcasecmp(mem->desc, "signature") == 0) { + if (strcmp(mem->desc, "signature") == 0) { if (flip1_read_sig_bytes(pgm, part, mem) < 0) return -1; if (addr > mem->size) { @@ -856,9 +856,9 @@ const char * flip1_mem_unit_str(enum flip1_mem_unit mem_unit) } enum flip1_mem_unit flip1_mem_unit(const char *name) { - if (strcasecmp(name, "flash") == 0) + if (strcmp(name, "flash") == 0) return FLIP1_MEM_UNIT_FLASH; - if (strcasecmp(name, "eeprom") == 0) + if (strcmp(name, "eeprom") == 0) return FLIP1_MEM_UNIT_EEPROM; return FLIP1_MEM_UNIT_UNKNOWN; } diff --git a/src/flip2.c b/src/flip2.c index 750be244..a1bebc1c 100644 --- a/src/flip2.c +++ b/src/flip2.c @@ -905,11 +905,11 @@ const char * flip2_mem_unit_str(enum flip2_mem_unit mem_unit) } enum flip2_mem_unit flip2_mem_unit(const char *name) { - if (strcasecmp(name, "application") == 0) + if (strcmp(name, "application") == 0) return FLIP2_MEM_UNIT_FLASH; - if (strcasecmp(name, "eeprom") == 0) + if (strcmp(name, "eeprom") == 0) return FLIP2_MEM_UNIT_EEPROM; - if (strcasecmp(name, "signature") == 0) + if (strcmp(name, "signature") == 0) return FLIP2_MEM_UNIT_SIGNATURE; return FLIP2_MEM_UNIT_UNKNOWN; } diff --git a/src/jtag3.c b/src/jtag3.c index 5612d0ed..a13c5c39 100644 --- a/src/jtag3.c +++ b/src/jtag3.c @@ -1976,16 +1976,13 @@ static int jtag3_read_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem, cmd[2] = 0; cmd[3] = ( p->flags & AVRPART_HAS_PDI || p->flags & AVRPART_HAS_UPDI ) ? MTYPE_FLASH : MTYPE_FLASH_PAGE; - if (strcmp(mem->desc, "flash") == 0 || - strcmp(mem->desc, "application") == 0 || - strcmp(mem->desc, "apptable") == 0 || - strcmp(mem->desc, "boot") == 0) { + if (avr_mem_is_flash_type(mem)) { addr += mem->offset & (512 * 1024 - 1); /* max 512 KiB flash */ pagesize = PDATA(pgm)->flash_pagesize; paddr = addr & ~(pagesize - 1); paddr_ptr = &PDATA(pgm)->flash_pageaddr; cache_ptr = PDATA(pgm)->flash_pagecache; - } else if (strcmp(mem->desc, "eeprom") == 0) { + } else if (avr_mem_is_eeprom_type(mem)) { if ( (pgm->flag & PGM_FL_IS_DW) || ( p->flags & AVRPART_HAS_PDI ) || ( p->flags & AVRPART_HAS_UPDI ) ) { cmd[3] = MTYPE_EEPROM; } else { diff --git a/src/jtagmkII.c b/src/jtagmkII.c index ef45ee22..98ee87b1 100644 --- a/src/jtagmkII.c +++ b/src/jtagmkII.c @@ -2253,15 +2253,12 @@ static int jtagmkII_read_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem, addr += mem->offset; cmd[1] = ( p->flags & (AVRPART_HAS_PDI | AVRPART_HAS_UPDI) ) ? MTYPE_FLASH : MTYPE_FLASH_PAGE; - if (strcmp(mem->desc, "flash") == 0 || - strcmp(mem->desc, "application") == 0 || - strcmp(mem->desc, "apptable") == 0 || - strcmp(mem->desc, "boot") == 0) { + if (avr_mem_is_flash_type(mem)) { pagesize = PDATA(pgm)->flash_pagesize; paddr = addr & ~(pagesize - 1); paddr_ptr = &PDATA(pgm)->flash_pageaddr; cache_ptr = PDATA(pgm)->flash_pagecache; - } else if (strcmp(mem->desc, "eeprom") == 0) { + } else if (avr_mem_is_eeprom_type(mem)) { if ( (pgm->flag & PGM_FL_IS_DW) || ( p->flags & (AVRPART_HAS_PDI | AVRPART_HAS_UPDI) ) ) { /* debugWire cannot use page access for EEPROM */ cmd[1] = MTYPE_EEPROM; diff --git a/src/libavrdude.h b/src/libavrdude.h index 4e22c5ed..eef7a67c 100644 --- a/src/libavrdude.h +++ b/src/libavrdude.h @@ -842,7 +842,12 @@ int avr_put_cycle_count(PROGRAMMER * pgm, AVRPART * p, int cycles); void avr_add_mem_order(const char *str); +int avr_mem_is_flash_type(AVRMEM *mem); + +int avr_mem_is_eeprom_type(AVRMEM *mem); + 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) diff --git a/src/main.c b/src/main.c index da1c90b6..54f6e633 100644 --- a/src/main.c +++ b/src/main.c @@ -1213,7 +1213,7 @@ int main(int argc, char * argv []) m = avr_locate_mem(p, upd->memtype); if (m == NULL) continue; - if ((strcasecmp(m->desc, memname) == 0) && (upd->op == DEVICE_WRITE)) { + if ((strcmp(m->desc, memname) == 0) && (upd->op == DEVICE_WRITE)) { erase = 1; if (quell_progress < 2) { avrdude_message(MSG_INFO, "%s: NOTE: \"%s\" memory has been specified, an erase cycle "