|
1 | 1 | --- avr.c |
2 | 2 | +++ avr.c |
3 | | -@@ -1058,6 +1058,36 @@ int avr_signature(PROGRAMMER * pgm, AVRPART * p) |
| 3 | +@@ -1058,6 +1058,39 @@ |
4 | 4 | return 0; |
5 | 5 | } |
6 | 6 |
|
|
31 | 31 | +} |
32 | 32 | + |
33 | 33 | +int compare_memory_masked(AVRMEM * m, unsigned char buf1, unsigned char buf2) { |
34 | | -+ uint8_t bitmask = get_fuse_bitmask(m); |
| 34 | ++ uint8_t bitmask = 0xFF; |
| 35 | ++ if(m) { |
| 36 | ++ bitmask = get_fuse_bitmask(m); |
| 37 | ++ } |
35 | 38 | + return ((buf1 & bitmask) != (buf2 & bitmask)); |
36 | 39 | +} |
37 | 40 |
|
38 | 41 | /* |
39 | 42 | * Verify the memory buffer of p with that of v. The byte range of v, |
40 | | -@@ -1103,7 +1133,7 @@ int avr_verify(AVRPART * p, AVRPART * v, char * memtype, int size) |
41 | | - |
| 43 | +@@ -1104,11 +1137,18 @@ |
42 | 44 | for (i=0; i<size; i++) { |
43 | 45 | if ((b->tags[i] & TAG_ALLOCATED) != 0 && |
44 | | -- buf1[i] != buf2[i]) { |
45 | | -+ compare_memory_masked(a , buf1[i], buf2[i])) { |
46 | | - avrdude_message(MSG_INFO, "%s: verification error, first mismatch at byte 0x%04x\n" |
47 | | - "%s0x%02x != 0x%02x\n", |
48 | | - progname, i, |
| 46 | + buf1[i] != buf2[i]) { |
| 47 | +- avrdude_message(MSG_INFO, "%s: verification error, first mismatch at byte 0x%04x\n" |
| 48 | +- "%s0x%02x != 0x%02x\n", |
| 49 | +- progname, i, |
| 50 | +- progbuf, buf1[i], buf2[i]); |
| 51 | +- return -1; |
| 52 | ++ if(compare_memory_masked(a , buf1[i], buf2[i])) { |
| 53 | ++ avrdude_message(MSG_INFO, "%s: verification error, first mismatch at byte 0x%04x\n" |
| 54 | ++ "%s0x%02x != 0x%02x\n", |
| 55 | ++ progname, i, |
| 56 | ++ progbuf, buf1[i], buf2[i]); |
| 57 | ++ return -1; |
| 58 | ++ } else { |
| 59 | ++ avrdude_message(MSG_INFO, "%s: WARNING: invalid value for unused bits in fuse \"%s\", should be set to 1 according to datasheet\n" |
| 60 | ++ "This behaviour is deprecated and will result in an error in future version\n" |
| 61 | ++ "You probably want to use 0x%02x instead of 0x%02x (double check with your datasheet first).\n", |
| 62 | ++ progname, memtype, buf1[i], buf2[i]); |
| 63 | ++ } |
| 64 | + } |
| 65 | + } |
| 66 | + |
49 | 67 | --- libavrdude.h |
50 | 68 | +++ libavrdude.h |
51 | | -@@ -337,6 +337,9 @@ typedef void (*walk_avrparts_cb)(const char *name, const char *desc, |
| 69 | +@@ -337,6 +337,10 @@ |
52 | 70 | void *cookie); |
53 | 71 | void walk_avrparts(LISTID avrparts, walk_avrparts_cb cb, void *cookie); |
54 | 72 | void sort_avrparts(LISTID avrparts); |
55 | 73 | + |
56 | 74 | +uint8_t get_fuse_bitmask(AVRMEM * m); |
| 75 | ++int compare_memory_masked(AVRMEM * m, unsigned char buf1, unsigned char buf2); |
57 | 76 | + |
58 | 77 | #ifdef __cplusplus |
59 | 78 | } |
60 | 79 | #endif |
61 | 80 | --- main.c |
62 | 81 | +++ main.c |
63 | | -@@ -1239,6 +1239,7 @@ int main(int argc, char * argv []) |
64 | | - unsigned char safemodeafter_lfuse = 0xff; |
65 | | - unsigned char safemodeafter_hfuse = 0xff; |
66 | | - unsigned char safemodeafter_efuse = 0xff; |
67 | | -+ unsigned char safemodeafter_efuse_mask = 0xff; |
68 | | - unsigned char safemodeafter_fuse = 0xff; |
69 | | - unsigned char failures = 0; |
70 | | - char yes[1] = {'y'}; |
71 | | -@@ -1345,8 +1346,15 @@ int main(int argc, char * argv []) |
| 82 | +@@ -1264,8 +1264,11 @@ |
72 | 83 | } |
73 | 84 | } |
74 | | - |
75 | | -+ /* Get efuse bitmask if it exists */ |
| 85 | + |
76 | 86 | + AVRMEM * m; |
77 | | -+ m = avr_locate_mem(p, "efuse"); |
78 | | -+ if (m != NULL) { |
79 | | -+ safemodeafter_efuse_mask = get_fuse_bitmask(m); |
80 | | -+ } |
81 | | -+ |
| 87 | ++ |
| 88 | + /* Now check what fuses are against what they should be */ |
| 89 | +- if (safemodeafter_fuse != safemode_fuse) { |
| 90 | ++ m = avr_locate_mem(p, "fuse"); |
| 91 | ++ if (compare_memory_masked(m, safemodeafter_fuse, safemode_fuse)) { |
| 92 | + fuses_updated = 1; |
| 93 | + avrdude_message(MSG_INFO, "%s: safemode: fuse changed! Was %x, and is now %x\n", |
| 94 | + progname, safemode_fuse, safemodeafter_fuse); |
| 95 | +@@ -1293,7 +1296,8 @@ |
| 96 | + } |
| 97 | + |
| 98 | + /* Now check what fuses are against what they should be */ |
| 99 | +- if (safemodeafter_lfuse != safemode_lfuse) { |
| 100 | ++ m = avr_locate_mem(p, "lfuse"); |
| 101 | ++ if (compare_memory_masked(m, safemodeafter_lfuse, safemode_lfuse)) { |
| 102 | + fuses_updated = 1; |
| 103 | + avrdude_message(MSG_INFO, "%s: safemode: lfuse changed! Was %x, and is now %x\n", |
| 104 | + progname, safemode_lfuse, safemodeafter_lfuse); |
| 105 | +@@ -1321,7 +1325,8 @@ |
| 106 | + } |
| 107 | + |
| 108 | + /* Now check what fuses are against what they should be */ |
| 109 | +- if (safemodeafter_hfuse != safemode_hfuse) { |
| 110 | ++ m = avr_locate_mem(p, "hfuse"); |
| 111 | ++ if (compare_memory_masked(m, safemodeafter_hfuse, safemode_hfuse)) { |
| 112 | + fuses_updated = 1; |
| 113 | + avrdude_message(MSG_INFO, "%s: safemode: hfuse changed! Was %x, and is now %x\n", |
| 114 | + progname, safemode_hfuse, safemodeafter_hfuse); |
| 115 | +@@ -1346,7 +1351,8 @@ |
| 116 | + } |
| 117 | + |
82 | 118 | /* Now check what fuses are against what they should be */ |
83 | 119 | - if (safemodeafter_efuse != safemode_efuse) { |
84 | | -+ if ((safemodeafter_efuse & safemodeafter_efuse_mask) != (safemode_efuse & safemodeafter_efuse_mask)) { |
| 120 | ++ m = avr_locate_mem(p, "efuse"); |
| 121 | ++ if (compare_memory_masked(m, safemodeafter_efuse, safemode_efuse)) { |
85 | 122 | fuses_updated = 1; |
86 | 123 | avrdude_message(MSG_INFO, "%s: safemode: efuse changed! Was %x, and is now %x\n", |
87 | 124 | progname, safemode_efuse, safemodeafter_efuse); |
|
0 commit comments