Fix for TPI fuse write

In get_fuse_bitmask(), ensure the AVR_OP_READ and AVR_OP_WRITE
m->op[] fields are actually filled in, before referencing them.
If they are missing, just return a full byte mask (0xFF).

In avr_write(), for TPI memory, if the write consist of one byte onle
(which is the case for fuse byte writing), resort to avr_write_byte()
instead as it already implements everything needed. This leaves the
avr_write() implementation to handle full paged writes with an even
number of bytes only.
This commit is contained in:
Joerg Wunsch 2022-01-11 22:00:22 +01:00
parent 1049777283
commit 65d5cfadc1
1 changed files with 10 additions and 0 deletions

View File

@ -867,6 +867,11 @@ int avr_write(PROGRAMMER * pgm, AVRPART * p, char * memtype, int size,
if ((p->flags & AVRPART_HAS_TPI) && m->page_size > 1 &&
pgm->cmd_tpi != NULL) {
if (wsize == 1) {
/* fuse (configuration) memory: only single byte to write */
return avr_write_byte(pgm, p, m, 0, m->buf[0]) == 0? 1: -1;
}
while (avr_tpi_poll_nvmbsy(pgm));
/* setup for WORD_WRITE */
@ -1074,6 +1079,11 @@ static uint8_t get_fuse_bitmask(AVRMEM * m) {
return 0xFF;
}
if (m->op[AVR_OP_WRITE] == NULL ||
m->op[AVR_OP_READ] == NULL)
// no memory operations provided by configuration, compare directly
return 0xFF;
// For fuses, only compare bytes that are actually written *and* read.
for (i = 0; i < 32; i++) {
if (m->op[AVR_OP_WRITE]->bit[i].type == AVR_CMDBIT_INPUT)