@@ -49,7 +49,7 @@ int binimage_add_segment(uint32_t address, uint32_t size, unsigned char *data)
49
49
LOGERR ("no data for binimage segment #%i" , b_image .num_segments );
50
50
return 0 ;
51
51
}
52
-
52
+
53
53
if (b_image .segments == 0 )
54
54
{
55
55
b_image .segments = malloc (size );
@@ -79,7 +79,7 @@ int binimage_add_segment(uint32_t address, uint32_t size, unsigned char *data)
79
79
b_image .num_segments ,
80
80
b_image .segments [b_image .num_segments ].address ,
81
81
b_image .segments [b_image .num_segments ].size );
82
-
82
+
83
83
b_image .num_segments ++ ;
84
84
return 1 ;
85
85
}
@@ -90,9 +90,9 @@ int binimage_prepare(const char *fname, uint32_t entry)
90
90
{
91
91
return 0 ;
92
92
}
93
-
94
- b_image .entry = entry ;
95
-
93
+
94
+ b_image .entry = entry ;
95
+
96
96
if (fname [0 ])
97
97
{
98
98
b_image .image_file = fopen (fname , "wb" );
@@ -106,13 +106,13 @@ int binimage_prepare(const char *fname, uint32_t entry)
106
106
{
107
107
return 0 ;
108
108
}
109
-
109
+
110
110
b_image .segments = 0 ;
111
111
b_image .num_segments = 0 ;
112
112
total_size = 0 ;
113
-
113
+
114
114
LOGINFO ("created structure for binimage \"%s\" with entry address 0x%08X" , fname , b_image .entry );
115
-
115
+
116
116
return 1 ;
117
117
}
118
118
@@ -126,22 +126,22 @@ int binimage_write(uint32_t padsize, bool close)
126
126
{
127
127
unsigned int cnt , cnt2 ;
128
128
unsigned char chksum ;
129
-
129
+
130
130
chksum = 0xEF ;
131
-
131
+
132
132
if (b_image .image_file == 0 )
133
133
{
134
134
return 0 ;
135
135
}
136
-
136
+
137
137
if (fwrite ((unsigned char * )& b_image , 1 , 8 , b_image .image_file ) != 8 )
138
138
{
139
139
LOGERR ("cant write main header to binimage file, aborting" );
140
140
fclose (b_image .image_file );
141
141
b_image .image_file = 0 ;
142
142
return 0 ;
143
143
}
144
-
144
+
145
145
total_size = 8 ;
146
146
147
147
if (header_layout == HL_ESP32BOOT )
@@ -157,9 +157,9 @@ int binimage_write(uint32_t padsize, bool close)
157
157
b_image .image_file = 0 ;
158
158
return 0 ;
159
159
}
160
- total_size += sizeof (extra_header );
160
+ total_size += sizeof (extra_header );
161
161
}
162
-
162
+
163
163
for (cnt = 0 ; cnt < b_image .num_segments ; cnt ++ )
164
164
{
165
165
if (fwrite ((unsigned char * )& b_image .segments [cnt ], 1 , 8 , b_image .image_file ) != 8 )
@@ -169,26 +169,26 @@ int binimage_write(uint32_t padsize, bool close)
169
169
b_image .image_file = 0 ;
170
170
return 0 ;
171
171
}
172
-
172
+
173
173
total_size += 8 ;
174
-
174
+
175
175
if (fwrite (b_image .segments [cnt ].data , 1 , b_image .segments [cnt ].size , b_image .image_file ) != b_image .segments [cnt ].size )
176
176
{
177
177
LOGERR ("cant write data block for segment #%i to binimage file, aborting" , cnt );
178
178
fclose (b_image .image_file );
179
179
b_image .image_file = 0 ;
180
180
return 0 ;
181
181
}
182
-
182
+
183
183
total_size += b_image .segments [cnt ].size ;
184
184
for (cnt2 = 0 ; cnt2 < b_image .segments [cnt ].size ; cnt2 ++ )
185
185
{
186
186
chksum ^= b_image .segments [cnt ].data [cnt2 ];
187
187
}
188
188
}
189
-
189
+
190
190
padsize -- ;
191
-
191
+
192
192
while (++ total_size & padsize )
193
193
{
194
194
if (fputc (0x00 , b_image .image_file ) == EOF )
@@ -200,7 +200,7 @@ int binimage_write(uint32_t padsize, bool close)
200
200
}
201
201
cnt ++ ;
202
202
}
203
-
203
+
204
204
if (fputc (chksum , b_image .image_file ) == EOF )
205
205
{
206
206
LOGERR ("cant write checksum byte 0x%02X at 0x%08X to binimage file, aborting" , chksum , total_size );
@@ -210,13 +210,13 @@ int binimage_write(uint32_t padsize, bool close)
210
210
}
211
211
212
212
LOGINFO ("saved binimage file, total size is %i bytes, checksum byte is 0x%02X" , total_size , chksum );
213
-
214
- if (close )
213
+
214
+ if (close )
215
215
{
216
216
fclose (b_image .image_file );
217
217
b_image .image_file = 0 ;
218
218
}
219
-
219
+
220
220
if (b_image .segments )
221
221
{
222
222
for (cnt = 0 ; cnt < b_image .num_segments ; cnt ++ )
@@ -250,13 +250,13 @@ int binimage_write_padto(uint32_t padsize, uint32_t address)
250
250
return 0 ;
251
251
252
252
LOGDEBUG ("binimage_write_padto: total:%x addr:%x" , total_size , address );
253
- if (address < total_size )
253
+ if (address < total_size )
254
254
{
255
255
LOGERR ("binimage_write_padto: address is less than size written" );
256
256
return 0 ;
257
257
}
258
258
259
- while (total_size < address )
259
+ while (total_size < address )
260
260
{
261
261
if (fputc (0xaa , b_image .image_file ) == EOF )
262
262
return 0 ;
@@ -286,7 +286,7 @@ int binimage_set_flash_mode(const char* modestr)
286
286
return 0 ;
287
287
}
288
288
289
- LOGINFO ("setting flash mode from %s to %s" ,
289
+ LOGINFO ("setting flash mode from %s to %s" ,
290
290
binimage_flash_mode_to_str (b_image .flash_mode ),
291
291
binimage_flash_mode_to_str (mode ));
292
292
@@ -303,10 +303,10 @@ int binimage_set_flash_size(const char* sizestr)
303
303
return 0 ;
304
304
}
305
305
306
- LOGINFO ("setting flash size from %s to %s" ,
306
+ LOGINFO ("setting flash size from %s to %s" ,
307
307
binimage_flash_size_to_str (b_image .flash_size_freq & 0xf0 ),
308
308
binimage_flash_size_to_str (size ));
309
-
309
+
310
310
b_image .flash_size_freq = size | (b_image .flash_size_freq & 0x0f );
311
311
return 1 ;
312
312
}
@@ -320,23 +320,23 @@ int binimage_set_flash_freq(const char* freqstr)
320
320
return 0 ;
321
321
}
322
322
323
- LOGINFO ("setting flash frequency from %s to %s" ,
323
+ LOGINFO ("setting flash frequency from %s to %s" ,
324
324
binimage_flash_freq_to_str (b_image .flash_size_freq & 0x0f ),
325
325
binimage_flash_freq_to_str (freq ));
326
-
326
+
327
327
b_image .flash_size_freq = (b_image .flash_size_freq & 0xf0 ) | freq ;
328
328
return 1 ;
329
329
}
330
330
331
331
static const char * flash_mode_str [] = {"qio" , "qout" , "dio" , "dout" };
332
- static const char * flash_size_str [] = {"512K" , "256K" , "1M" , "2M" , "4M" , "8M" , "16M " , "32M " };
332
+ static const char * flash_size_str [] = {"512K" , "256K" , "1M" , "2M" , "4M" ,"XM" , "XM" , "XM" , "8M " , "16M " };
333
333
334
334
unsigned char binimage_parse_flash_mode (const char * str )
335
335
{
336
336
const int n = sizeof (flash_mode_str )/sizeof (const char * );
337
- for (int i = 0 ; i < n ; ++ i )
337
+ for (int i = 0 ; i < n ; ++ i )
338
338
{
339
- if (strcasecmp (str , flash_mode_str [i ]) == 0 )
339
+ if (strcasecmp (str , flash_mode_str [i ]) == 0 )
340
340
{
341
341
return (unsigned char ) i ;
342
342
}
@@ -347,9 +347,9 @@ unsigned char binimage_parse_flash_mode(const char* str)
347
347
unsigned char binimage_parse_flash_size (const char * str )
348
348
{
349
349
const int n = sizeof (flash_size_str )/sizeof (const char * );
350
- for (int i = 0 ; i < n ; ++ i )
350
+ for (int i = 0 ; i < n ; ++ i )
351
351
{
352
- if (strcasecmp (str , flash_size_str [i ]) == 0 )
352
+ if (strcasecmp (str , flash_size_str [i ]) == 0 )
353
353
{
354
354
return (unsigned char ) i << 4 ;
355
355
}
@@ -360,7 +360,7 @@ unsigned char binimage_parse_flash_size(const char* str)
360
360
unsigned char binimage_parse_flash_freq (const char * str )
361
361
{
362
362
int val = atoi (str );
363
- switch (val )
363
+ switch (val )
364
364
{
365
365
case 40 : return FLASH_FREQ_40 ;
366
366
case 26 : return FLASH_FREQ_26 ;
@@ -380,7 +380,7 @@ const char* binimage_flash_mode_to_str(unsigned char mode)
380
380
381
381
const char * binimage_flash_size_to_str (unsigned char size )
382
382
{
383
- if ((size >> 4 ) > FLASH_SIZE_32M )
383
+ if ((size >> 4 ) > FLASH_SIZE_16M )
384
384
return "" ;
385
385
return flash_size_str [size >> 4 ];
386
386
}
@@ -414,4 +414,3 @@ int binimage_set_header_layout(const char* layout)
414
414
LOGERR ("invalid image header layout: %s" , layout );
415
415
return 0 ;
416
416
}
417
-
0 commit comments