Fix usbtiny read/verify for parts with more than 64 kB flash
Usbtiny has a protocol or firmware problem that prevents it from reading
flash above 64 kB in page mode (used by -U flash:r:... and -U flash✌️...).
This commit fixes that problem by falling back on byte access for flash paged
reads above 64k. It also issues the correct load extended address command for
parts with more than 128 kB flash thus extending support to ATmega2560 et al.
This commit is contained in:
parent
c81f52ff10
commit
d05ddd188d
|
@ -657,15 +657,39 @@ static int usbtiny_paged_load (PROGRAMMER * pgm, AVRPART * p, AVRMEM* m,
|
||||||
unsigned int addr, unsigned int n_bytes)
|
unsigned int addr, unsigned int n_bytes)
|
||||||
{
|
{
|
||||||
unsigned int maxaddr = addr + n_bytes;
|
unsigned int maxaddr = addr + n_bytes;
|
||||||
int chunk;
|
int chunk, function;
|
||||||
int function;
|
OPCODE *lext, *readop;
|
||||||
|
unsigned char cmd[8];
|
||||||
|
|
||||||
// First determine what we're doing
|
// First determine what we're doing
|
||||||
if (strcmp( m->desc, "flash" ) == 0) {
|
function = strcmp(m->desc, "eeprom")==0?
|
||||||
function = USBTINY_FLASH_READ;
|
USBTINY_EEPROM_READ: USBTINY_FLASH_READ;
|
||||||
} else {
|
|
||||||
function = USBTINY_EEPROM_READ;
|
// paged_load() only called for pages, so OK to set ext addr once at start
|
||||||
|
if((lext = m->op[AVR_OP_LOAD_EXT_ADDR])) {
|
||||||
|
memset(cmd, 0, sizeof(cmd));
|
||||||
|
avr_set_bits(lext, cmd);
|
||||||
|
avr_set_addr(lext, cmd, addr/2);
|
||||||
|
if(pgm->cmd(pgm, cmd, cmd+4) < 0)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Byte acces as work around to correctly read flash above 64 kiB
|
||||||
|
if(function == USBTINY_FLASH_READ && addr >= 0x10000) {
|
||||||
|
for(unsigned int i=0; i<n_bytes; i++, addr++) {
|
||||||
|
if(!(readop = m->op[addr&1? AVR_OP_READ_HI: AVR_OP_READ_LO]))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
memset(cmd, 0, sizeof(cmd));
|
||||||
|
avr_set_bits(readop, cmd);
|
||||||
|
avr_set_addr(readop, cmd, addr/2);
|
||||||
|
if(pgm->cmd(pgm, cmd, cmd+4) < 0)
|
||||||
|
return -1;
|
||||||
|
m->buf[addr] = 0;
|
||||||
|
avr_get_output(readop, cmd+4, m->buf + addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
return n_bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; addr < maxaddr; addr += chunk) {
|
for (; addr < maxaddr; addr += chunk) {
|
||||||
|
|
Loading…
Reference in New Issue