Add libavrdude functions avr_mem_is_flash_type() and avr_mem_is_eeprom_type()
This commit is contained in:
parent
e332ecf0b4
commit
dfef8bb0a8
17
src/avr.c
17
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++)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 "
|
||||
|
|
Loading…
Reference in New Issue