@@ -21,7 +21,7 @@ uint16_t readSignature (void)
21
21
SPI.setClockDivider (CLOCKSPEED_FUSES);
22
22
23
23
uint16_t target_type = 0 ;
24
- fp (" \n Reading signature:" );
24
+ Serial. print (" \n Reading signature:" );
25
25
26
26
target_type = spi_transaction (0x30 , 0x00 , 0x01 , 0x00 );
27
27
target_type <<= 8 ;
@@ -30,7 +30,7 @@ uint16_t readSignature (void)
30
30
Serial.println (target_type, HEX);
31
31
if (target_type == 0 || target_type == 0xFFFF ) {
32
32
if (target_type == 0 ) {
33
- fp (" (no target attached?)\n " );
33
+ Serial. println (" (no target attached?)" );
34
34
}
35
35
}
36
36
return target_type;
@@ -46,111 +46,108 @@ uint16_t readSignature (void)
46
46
image_t *findImage (uint16_t signature)
47
47
{
48
48
image_t *ip;
49
- fp (" Searching for image...\n " );
49
+ Serial. println (" Searching for image..." );
50
50
51
51
for (byte i=0 ; i < NUMIMAGES; i++) {
52
52
ip = images[i];
53
53
54
54
if (ip && (pgm_read_word (&ip->image_chipsig ) == signature)) {
55
- fp (" Found \" " );
55
+ Serial. print (" Found \" " );
56
56
flashprint (&ip->image_name [0 ]);
57
- fp (" \" for " );
57
+ Serial. print (" \" for " );
58
58
flashprint (&ip->image_chipname [0 ]);
59
- fp ( " \n " );
59
+ Serial. println ( );
60
60
61
61
return ip;
62
62
}
63
63
}
64
- fp (" Not Found\n " );
64
+ Serial. println (" Not Found" );
65
65
return 0 ;
66
66
}
67
67
68
68
/*
69
69
* programmingFuses
70
- * reprogram the fuses to the state we want during chip programming.
71
- * This is not necessarily the same as the
72
- * 'final' fuses due to changes in clock speed, lock byte, etc
70
+ * Program the fuse/lock bits
73
71
*/
74
- boolean programmingFuses ( image_t *target )
72
+ boolean programFuses ( const byte *fuses )
75
73
{
76
74
SPI.setClockDivider (CLOCKSPEED_FUSES);
77
75
78
76
byte f;
79
- fp (" \n Setting fuses for programming " );
77
+ Serial. print (" \n Setting fuses" );
80
78
81
- f = pgm_read_byte (target-> image_progfuses [FUSE_PROT]);
79
+ f = pgm_read_byte (&fuses [FUSE_PROT]);
82
80
if (f) {
83
- fp (" \n Lock: " );
81
+ Serial. print (" \n Set Lock Fuse to : " );
84
82
Serial.print (f, HEX);
85
- fp ( " " );
83
+ Serial. print ( " -> " );
86
84
Serial.print (spi_transaction (0xAC , 0xE0 , 0x00 , f), HEX);
87
85
}
88
- f = pgm_read_byte (target-> image_progfuses [FUSE_LOW]);
86
+ f = pgm_read_byte (&fuses [FUSE_LOW]);
89
87
if (f) {
90
- fp (" Low: " );
88
+ Serial. print (" Set Low Fuse to : " );
91
89
Serial.print (f, HEX);
92
- fp ( " " );
90
+ Serial. print ( " -> " );
93
91
Serial.print (spi_transaction (0xAC , 0xA0 , 0x00 , f), HEX);
94
92
}
95
- f = pgm_read_byte (target-> image_progfuses [FUSE_HIGH]);
93
+ f = pgm_read_byte (&fuses [FUSE_HIGH]);
96
94
if (f) {
97
- fp (" High: " );
95
+ Serial. print (" Set High Fuse to : " );
98
96
Serial.print (f, HEX);
99
- fp ( " " );
97
+ Serial. print ( " -> " );
100
98
Serial.print (spi_transaction (0xAC , 0xA8 , 0x00 , f), HEX);
101
99
}
102
- f = pgm_read_byte (target-> image_progfuses [FUSE_EXT]);
100
+ f = pgm_read_byte (&fuses [FUSE_EXT]);
103
101
if (f) {
104
- fp (" Ext: " );
102
+ Serial. print (" Set Ext Fuse to : " );
105
103
Serial.print (f, HEX);
106
- fp ( " " );
104
+ Serial. print ( " -> " );
107
105
Serial.print (spi_transaction (0xAC , 0xA4 , 0x00 , f), HEX);
108
106
}
109
107
Serial.println ();
110
108
return true ; /* */
111
109
}
112
110
113
-
114
111
/*
115
- * normalFuses
116
- * reprogram the fuses to the state we want after the chip has
117
- * been programmed - this is not necessarily the same as the
118
- * 'programming' fuses due to changes in clock speed, lock byte, etc
112
+ * verifyFuses
113
+ * Verifies a fuse set
119
114
*/
120
- boolean normalFuses ( image_t *target )
115
+ boolean verifyFuses ( const byte *fuses, const byte *fusemask )
121
116
{
122
117
SPI.setClockDivider (CLOCKSPEED_FUSES);
123
-
124
118
byte f;
125
- fp (" \n Restoring normal fuses" );
126
-
127
- f = pgm_read_byte (target->image_normfuses [FUSE_PROT]);
119
+ Serial.println (" Verifying fuses..." );
120
+ f = pgm_read_byte (&fuses[FUSE_PROT]);
128
121
if (f) {
129
- fp (" \n Lock: " );
130
- Serial.print (f, HEX);
131
- fp (" " );
132
- Serial.print (spi_transaction (0xAC , 0xE0 , 0x00 , f), HEX);
122
+ uint8_t readfuse = spi_transaction (0x58 , 0x00 , 0x00 , 0x00 ); // lock fuse
123
+ readfuse &= pgm_read_byte (&fusemask[FUSE_PROT]);
124
+ Serial.print (" \t Lock Fuse: " ); Serial.print (f, HEX); Serial.print (" is " ); Serial.print (readfuse, HEX);
125
+ if (readfuse != f)
126
+ return false ;
133
127
}
134
- f = pgm_read_byte (target-> image_normfuses [FUSE_LOW]);
128
+ f = pgm_read_byte (&fuses [FUSE_LOW]);
135
129
if (f) {
136
- fp (" Low: " );
137
- Serial.print (f, HEX);
138
- fp (" " );
139
- Serial.print (spi_transaction (0xAC , 0xA0 , 0x00 , f), HEX);
130
+ uint8_t readfuse = spi_transaction (0x50 , 0x00 , 0x00 , 0x00 ); // low fuse
131
+ Serial.print (" \t Low Fuse: 0x" ); Serial.print (f, HEX); Serial.print (" is 0x" ); Serial.print (readfuse, HEX);
132
+ readfuse &= pgm_read_byte (&fusemask[FUSE_LOW]);
133
+ if (readfuse != f)
134
+ return false ;
140
135
}
141
- f = pgm_read_byte (target-> image_normfuses [FUSE_HIGH]);
136
+ f = pgm_read_byte (&fuses [FUSE_HIGH]);
142
137
if (f) {
143
- fp (" High: " );
144
- Serial.print (f, HEX);
145
- fp (" " );
146
- Serial.print (spi_transaction (0xAC , 0xA8 , 0x00 , f), HEX);
138
+ uint8_t readfuse = spi_transaction (0x58 , 0x08 , 0x00 , 0x00 ); // high fuse
139
+ readfuse &= pgm_read_byte (&fusemask[FUSE_HIGH]);
140
+ Serial.print (" \t High Fuse: 0x" ); Serial.print (f, HEX); Serial.print (" is 0x" ); Serial.print (readfuse, HEX);
141
+ if (readfuse != f)
142
+ return false ;
147
143
}
148
- f = pgm_read_byte (target-> image_normfuses [FUSE_EXT]);
144
+ f = pgm_read_byte (&fuses [FUSE_EXT]);
149
145
if (f) {
150
- fp (" Ext: " );
151
- Serial.print (f, HEX);
152
- fp (" " );
153
- Serial.print (spi_transaction (0xAC , 0xA4 , 0x00 , f), HEX);
146
+ uint8_t readfuse = spi_transaction (0x50 , 0x08 , 0x00 , 0x00 ); // ext fuse
147
+ readfuse &= pgm_read_byte (&fusemask[FUSE_EXT]);
148
+ Serial.print (" \t Ext Fuse: 0x" ); Serial.print (f, HEX); Serial.print (" is 0x" ); Serial.print (readfuse, HEX);
149
+ if (readfuse != f)
150
+ return false ;
154
151
}
155
152
Serial.println ();
156
153
return true ; /* */
@@ -260,7 +257,7 @@ byte * readImagePage (byte *hextext, uint16_t pageaddr, uint8_t pagesize, byte *
260
257
break ;
261
258
}
262
259
#if VERBOSE
263
- fp (" \n Total bytes read: " );
260
+ Serial. print (" \n Total bytes read: " );
264
261
Serial.println (page_idx, DEC);
265
262
#endif
266
263
return hextext;
0 commit comments