Skip to content

Commit

Permalink
Merge pull request #17 from facchinm/arduino-extrapatch
Browse files Browse the repository at this point in the history
Arduino extrapatch
  • Loading branch information
facchinm authored Jan 8, 2021
2 parents 3b8dc7a + bc89469 commit 1ebcc35
Show file tree
Hide file tree
Showing 16 changed files with 1,263 additions and 114 deletions.
1 change: 0 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ libavrdude_a_SOURCES = \
linuxspi.h \
linux_ppdev.h \
lists.c \
my_ddk_hidsdi.h \
par.c \
par.h \
pgm.c \
Expand Down
50 changes: 45 additions & 5 deletions avr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,39 @@ int avr_signature(PROGRAMMER * pgm, AVRPART * p)
return 0;
}

uint8_t get_fuse_bitmask(AVRMEM * m) {
uint8_t bitmask_r = 0;
uint8_t bitmask_w = 0;
int i, j;

if (m->size > 1) {
// not a fuse, compare bytes directly
return 0xFF;
}

for (i=0; i<AVR_OP_MAX; i++) {
if (m->op[i] && i == AVR_OP_READ) {
for (j=7; j>=0; j--) {
bitmask_r |= (m->op[i]->bit[j].type != AVR_CMDBIT_IGNORE) << j;
}
}
if (m->op[i] && i == AVR_OP_WRITE) {
for (j=7; j>=0; j--) {
bitmask_w |= (m->op[i]->bit[j].type != AVR_CMDBIT_VALUE &&
m->op[i]->bit[j].type != AVR_CMDBIT_IGNORE) << j;
}
}
}
return bitmask_r & bitmask_w;
}

int compare_memory_masked(AVRMEM * m, unsigned char buf1, unsigned char buf2) {
uint8_t bitmask = 0xFF;
if(m) {
bitmask = get_fuse_bitmask(m);
}
return ((buf1 & bitmask) != (buf2 & bitmask));
}

/*
* Verify the memory buffer of p with that of v. The byte range of v,
Expand Down Expand Up @@ -1109,11 +1142,18 @@ int avr_verify(AVRPART * p, AVRPART * v, char * memtype, int size)
for (i=0; i<size; i++) {
if ((b->tags[i] & TAG_ALLOCATED) != 0 &&
buf1[i] != buf2[i]) {
avrdude_message(MSG_INFO, "%s: verification error, first mismatch at byte 0x%04x\n"
"%s0x%02x != 0x%02x\n",
progname, i,
progbuf, buf1[i], buf2[i]);
return -1;
if(compare_memory_masked(a , buf1[i], buf2[i])) {
avrdude_message(MSG_INFO, "%s: verification error, first mismatch at byte 0x%04x\n"
"%s0x%02x != 0x%02x\n",
progname, i,
progbuf, buf1[i], buf2[i]);
return -1;
} else {
avrdude_message(MSG_INFO, "%s: WARNING: invalid value for unused bits in fuse \"%s\", should be set to 1 according to datasheet\n"
"This behaviour is deprecated and will result in an error in future version\n"
"You probably want to use 0x%02x instead of 0x%02x (double check with your datasheet first).\n",
progname, memtype, buf1[i], buf2[i]);
}
}
}

Expand Down
Loading

0 comments on commit 1ebcc35

Please sign in to comment.