Make getfusel() cache independent of host endianness

This commit is contained in:
Stefan Rueger
2026-06-14 13:35:38 +01:00
parent 65468c08de
commit 99932524e8

View File

@@ -1373,11 +1373,6 @@ static int cmd_pgerase(const PROGRAMMER *pgm, const AVRPART *p, int argc, const
static const int MAX_PAD = 10; // Align value labels if their length difference is less than this
typedef union { // Lock memory can be 1 or 4 bytes
uint8_t b[4];
uint32_t i;
} Intbytes;
typedef struct { // Fuses and lock bits
uint16_t fuses[16]; // pdicfg fuse has two bytes
uint32_t lock;
@@ -1435,26 +1430,23 @@ static int getfusel(const PROGRAMMER *pgm, const AVRPART *p, Part_FL *fl, const
goto back;
}
Intbytes m = {.i = 0 };
unsigned char fuselmem[4] = { 0 };
for(int i = 0; i < mem->size; i++)
if(led_read_byte(pgm, p, mem, i, m.b + i) < 0) {
if(led_read_byte(pgm, p, mem, i, fuselmem + i) < 0) {
err = cache_string(str_ccprintf("cannot read %s's %s memory", p->desc, mem->desc));
goto back;
}
uint32_t fuselval = buf2uint32(fuselmem);
if(islock) {
fl->lock = m.i;
fl->lock = fuselval;
fl->lread = 1;
} else {
fl->fread[cci->t->memoffset] = 1;
int result = 0;
for(int i = mem->size - 1; i >= 0; i--)
result <<= 8, result |= m.b[i];
fl->fuses[cci->t->memoffset] = result;
fl->fuses[cci->t->memoffset] = fuselval;
}
fl->islock = islock;
fl->current = m.i;
fl->current = fuselval;
back:
if(err && errpp)
@@ -1968,9 +1960,7 @@ static int cmd_config(const PROGRAMMER *pgm, const AVRPART *p, int argc, const c
goto finished;
}
Intbytes towrite;
towrite.i = (fusel.current & ~ct[ci].mask) | (toassign << ct[ci].lsh);
uint32_t towrite = (fusel.current & ~ct[ci].mask) | (toassign << ct[ci].lsh);
const AVRMEM *mem = avr_locate_mem(p, cc[ci].memstr);
if(!mem) {
@@ -1986,10 +1976,10 @@ static int cmd_config(const PROGRAMMER *pgm, const AVRPART *p, int argc, const c
}
int confirm = 0;
if(towrite.i != fusel.current) {
if(towrite != fusel.current) {
confirm = o.confirm;
for(int i = 0; i < mem->size; i++)
if(led_write_byte(pgm, p, mem, i, towrite.b[i]) < 0) {
if(led_write_byte(pgm, p, mem, i, (towrite >> i*8) & 0xff) < 0) {
pmsg_error("(config) cannot write to %s's %s memory\n", p->desc, mem->desc);
ret = -1;
goto finished;