Add libavrdude functions avr_mem_is_flash_type() and avr_mem_is_eeprom_type()

This commit is contained in:
Stefan Rueger 2022-08-15 14:57:04 +01:00
parent e332ecf0b4
commit dfef8bb0a8
No known key found for this signature in database
GPG Key ID: B0B4F1FD86B1EC55
7 changed files with 29 additions and 21 deletions

View File

@ -295,10 +295,7 @@ int avr_mem_hiaddr(AVRMEM * mem)
return mem->size; return mem->size;
/* if the memory is not a flash-type memory do not remove trailing 0xff */ /* if the memory is not a flash-type memory do not remove trailing 0xff */
if(strcasecmp(mem->desc, "flash") && if(!avr_mem_is_flash_type(mem))
strcasecmp(mem->desc, "application") &&
strcasecmp(mem->desc, "apptable") &&
strcasecmp(mem->desc, "boot"))
return mem->size; return mem->size;
/* return the highest non-0xff address regardless of how much /* return the highest non-0xff address regardless of how much
@ -1253,6 +1250,18 @@ void avr_add_mem_order(const char *str) {
exit(1); 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) { int avr_mem_is_known(const char *str) {
if(str && *str) if(str && *str)
for(size_t i=0; i < sizeof avr_mem_order/sizeof *avr_mem_order; i++) for(size_t i=0; i < sizeof avr_mem_order/sizeof *avr_mem_order; i++)

View File

@ -395,7 +395,7 @@ int flip1_read_byte(PROGRAMMER* pgm, AVRPART *part, AVRMEM *mem,
if (FLIP1(pgm)->dfu == NULL) if (FLIP1(pgm)->dfu == NULL)
return -1; return -1;
if (strcasecmp(mem->desc, "signature") == 0) { if (strcmp(mem->desc, "signature") == 0) {
if (flip1_read_sig_bytes(pgm, part, mem) < 0) if (flip1_read_sig_bytes(pgm, part, mem) < 0)
return -1; return -1;
if (addr > mem->size) { 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) { 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; return FLIP1_MEM_UNIT_FLASH;
if (strcasecmp(name, "eeprom") == 0) if (strcmp(name, "eeprom") == 0)
return FLIP1_MEM_UNIT_EEPROM; return FLIP1_MEM_UNIT_EEPROM;
return FLIP1_MEM_UNIT_UNKNOWN; return FLIP1_MEM_UNIT_UNKNOWN;
} }

View File

@ -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) { 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; return FLIP2_MEM_UNIT_FLASH;
if (strcasecmp(name, "eeprom") == 0) if (strcmp(name, "eeprom") == 0)
return FLIP2_MEM_UNIT_EEPROM; return FLIP2_MEM_UNIT_EEPROM;
if (strcasecmp(name, "signature") == 0) if (strcmp(name, "signature") == 0)
return FLIP2_MEM_UNIT_SIGNATURE; return FLIP2_MEM_UNIT_SIGNATURE;
return FLIP2_MEM_UNIT_UNKNOWN; return FLIP2_MEM_UNIT_UNKNOWN;
} }

View File

@ -1976,16 +1976,13 @@ static int jtag3_read_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
cmd[2] = 0; cmd[2] = 0;
cmd[3] = ( p->flags & AVRPART_HAS_PDI || p->flags & AVRPART_HAS_UPDI ) ? MTYPE_FLASH : MTYPE_FLASH_PAGE; cmd[3] = ( p->flags & AVRPART_HAS_PDI || p->flags & AVRPART_HAS_UPDI ) ? MTYPE_FLASH : MTYPE_FLASH_PAGE;
if (strcmp(mem->desc, "flash") == 0 || if (avr_mem_is_flash_type(mem)) {
strcmp(mem->desc, "application") == 0 ||
strcmp(mem->desc, "apptable") == 0 ||
strcmp(mem->desc, "boot") == 0) {
addr += mem->offset & (512 * 1024 - 1); /* max 512 KiB flash */ addr += mem->offset & (512 * 1024 - 1); /* max 512 KiB flash */
pagesize = PDATA(pgm)->flash_pagesize; pagesize = PDATA(pgm)->flash_pagesize;
paddr = addr & ~(pagesize - 1); paddr = addr & ~(pagesize - 1);
paddr_ptr = &PDATA(pgm)->flash_pageaddr; paddr_ptr = &PDATA(pgm)->flash_pageaddr;
cache_ptr = PDATA(pgm)->flash_pagecache; 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 ) ) { if ( (pgm->flag & PGM_FL_IS_DW) || ( p->flags & AVRPART_HAS_PDI ) || ( p->flags & AVRPART_HAS_UPDI ) ) {
cmd[3] = MTYPE_EEPROM; cmd[3] = MTYPE_EEPROM;
} else { } else {

View File

@ -2253,15 +2253,12 @@ static int jtagmkII_read_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
addr += mem->offset; addr += mem->offset;
cmd[1] = ( p->flags & (AVRPART_HAS_PDI | AVRPART_HAS_UPDI) ) ? MTYPE_FLASH : MTYPE_FLASH_PAGE; cmd[1] = ( p->flags & (AVRPART_HAS_PDI | AVRPART_HAS_UPDI) ) ? MTYPE_FLASH : MTYPE_FLASH_PAGE;
if (strcmp(mem->desc, "flash") == 0 || if (avr_mem_is_flash_type(mem)) {
strcmp(mem->desc, "application") == 0 ||
strcmp(mem->desc, "apptable") == 0 ||
strcmp(mem->desc, "boot") == 0) {
pagesize = PDATA(pgm)->flash_pagesize; pagesize = PDATA(pgm)->flash_pagesize;
paddr = addr & ~(pagesize - 1); paddr = addr & ~(pagesize - 1);
paddr_ptr = &PDATA(pgm)->flash_pageaddr; paddr_ptr = &PDATA(pgm)->flash_pageaddr;
cache_ptr = PDATA(pgm)->flash_pagecache; 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) ) ) { if ( (pgm->flag & PGM_FL_IS_DW) || ( p->flags & (AVRPART_HAS_PDI | AVRPART_HAS_UPDI) ) ) {
/* debugWire cannot use page access for EEPROM */ /* debugWire cannot use page access for EEPROM */
cmd[1] = MTYPE_EEPROM; cmd[1] = MTYPE_EEPROM;

View File

@ -842,7 +842,12 @@ int avr_put_cycle_count(PROGRAMMER * pgm, AVRPART * p, int cycles);
void avr_add_mem_order(const char *str); 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_is_known(const char *str);
int avr_mem_might_be_known(const char *str); int avr_mem_might_be_known(const char *str);
#define disable_trailing_ff_removal() avr_mem_hiaddr(NULL) #define disable_trailing_ff_removal() avr_mem_hiaddr(NULL)

View File

@ -1213,7 +1213,7 @@ int main(int argc, char * argv [])
m = avr_locate_mem(p, upd->memtype); m = avr_locate_mem(p, upd->memtype);
if (m == NULL) if (m == NULL)
continue; continue;
if ((strcasecmp(m->desc, memname) == 0) && (upd->op == DEVICE_WRITE)) { if ((strcmp(m->desc, memname) == 0) && (upd->op == DEVICE_WRITE)) {
erase = 1; erase = 1;
if (quell_progress < 2) { if (quell_progress < 2) {
avrdude_message(MSG_INFO, "%s: NOTE: \"%s\" memory has been specified, an erase cycle " avrdude_message(MSG_INFO, "%s: NOTE: \"%s\" memory has been specified, an erase cycle "