Skip to content

Commit b6a8755

Browse files
author
Me No Dev
committed
Add support for 8 and 16MB flash
Connected to esp8266/Arduino#2351
1 parent afcd26f commit b6a8755

File tree

3 files changed

+45
-46
lines changed

3 files changed

+45
-46
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
esptool
22
esptool.exe
3-
build/
3+
build/
4+
*.o

binimage/esptool_binimage.c

+37-38
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ int binimage_add_segment(uint32_t address, uint32_t size, unsigned char *data)
4949
LOGERR("no data for binimage segment #%i", b_image.num_segments);
5050
return 0;
5151
}
52-
52+
5353
if(b_image.segments == 0)
5454
{
5555
b_image.segments = malloc(size);
@@ -79,7 +79,7 @@ int binimage_add_segment(uint32_t address, uint32_t size, unsigned char *data)
7979
b_image.num_segments,
8080
b_image.segments[b_image.num_segments].address,
8181
b_image.segments[b_image.num_segments].size);
82-
82+
8383
b_image.num_segments++;
8484
return 1;
8585
}
@@ -90,9 +90,9 @@ int binimage_prepare(const char *fname, uint32_t entry)
9090
{
9191
return 0;
9292
}
93-
94-
b_image.entry = entry;
95-
93+
94+
b_image.entry = entry;
95+
9696
if(fname[0])
9797
{
9898
b_image.image_file = fopen(fname, "wb");
@@ -106,13 +106,13 @@ int binimage_prepare(const char *fname, uint32_t entry)
106106
{
107107
return 0;
108108
}
109-
109+
110110
b_image.segments = 0;
111111
b_image.num_segments = 0;
112112
total_size = 0;
113-
113+
114114
LOGINFO("created structure for binimage \"%s\" with entry address 0x%08X", fname, b_image.entry);
115-
115+
116116
return 1;
117117
}
118118

@@ -126,22 +126,22 @@ int binimage_write(uint32_t padsize, bool close)
126126
{
127127
unsigned int cnt, cnt2;
128128
unsigned char chksum;
129-
129+
130130
chksum = 0xEF;
131-
131+
132132
if(b_image.image_file == 0)
133133
{
134134
return 0;
135135
}
136-
136+
137137
if(fwrite((unsigned char*)&b_image, 1, 8, b_image.image_file) != 8)
138138
{
139139
LOGERR("cant write main header to binimage file, aborting");
140140
fclose(b_image.image_file);
141141
b_image.image_file = 0;
142142
return 0;
143143
}
144-
144+
145145
total_size = 8;
146146

147147
if (header_layout == HL_ESP32BOOT)
@@ -157,9 +157,9 @@ int binimage_write(uint32_t padsize, bool close)
157157
b_image.image_file = 0;
158158
return 0;
159159
}
160-
total_size += sizeof(extra_header);
160+
total_size += sizeof(extra_header);
161161
}
162-
162+
163163
for(cnt = 0; cnt < b_image.num_segments; cnt++)
164164
{
165165
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)
169169
b_image.image_file = 0;
170170
return 0;
171171
}
172-
172+
173173
total_size += 8;
174-
174+
175175
if(fwrite(b_image.segments[cnt].data, 1, b_image.segments[cnt].size, b_image.image_file) != b_image.segments[cnt].size)
176176
{
177177
LOGERR("cant write data block for segment #%i to binimage file, aborting", cnt);
178178
fclose(b_image.image_file);
179179
b_image.image_file = 0;
180180
return 0;
181181
}
182-
182+
183183
total_size += b_image.segments[cnt].size;
184184
for(cnt2 = 0; cnt2 < b_image.segments[cnt].size; cnt2++)
185185
{
186186
chksum ^= b_image.segments[cnt].data[cnt2];
187187
}
188188
}
189-
189+
190190
padsize--;
191-
191+
192192
while(++total_size & padsize)
193193
{
194194
if(fputc(0x00, b_image.image_file) == EOF)
@@ -200,7 +200,7 @@ int binimage_write(uint32_t padsize, bool close)
200200
}
201201
cnt++;
202202
}
203-
203+
204204
if(fputc(chksum, b_image.image_file) == EOF)
205205
{
206206
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)
210210
}
211211

212212
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)
215215
{
216216
fclose(b_image.image_file);
217217
b_image.image_file = 0;
218218
}
219-
219+
220220
if(b_image.segments)
221221
{
222222
for(cnt = 0; cnt < b_image.num_segments; cnt++)
@@ -250,13 +250,13 @@ int binimage_write_padto(uint32_t padsize, uint32_t address)
250250
return 0;
251251

252252
LOGDEBUG("binimage_write_padto: total:%x addr:%x", total_size, address);
253-
if (address < total_size)
253+
if (address < total_size)
254254
{
255255
LOGERR("binimage_write_padto: address is less than size written");
256256
return 0;
257257
}
258258

259-
while (total_size < address)
259+
while (total_size < address)
260260
{
261261
if (fputc(0xaa, b_image.image_file) == EOF)
262262
return 0;
@@ -286,7 +286,7 @@ int binimage_set_flash_mode(const char* modestr)
286286
return 0;
287287
}
288288

289-
LOGINFO("setting flash mode from %s to %s",
289+
LOGINFO("setting flash mode from %s to %s",
290290
binimage_flash_mode_to_str(b_image.flash_mode),
291291
binimage_flash_mode_to_str(mode));
292292

@@ -303,10 +303,10 @@ int binimage_set_flash_size(const char* sizestr)
303303
return 0;
304304
}
305305

306-
LOGINFO("setting flash size from %s to %s",
306+
LOGINFO("setting flash size from %s to %s",
307307
binimage_flash_size_to_str(b_image.flash_size_freq & 0xf0),
308308
binimage_flash_size_to_str(size));
309-
309+
310310
b_image.flash_size_freq = size | (b_image.flash_size_freq & 0x0f);
311311
return 1;
312312
}
@@ -320,23 +320,23 @@ int binimage_set_flash_freq(const char* freqstr)
320320
return 0;
321321
}
322322

323-
LOGINFO("setting flash frequency from %s to %s",
323+
LOGINFO("setting flash frequency from %s to %s",
324324
binimage_flash_freq_to_str(b_image.flash_size_freq & 0x0f),
325325
binimage_flash_freq_to_str(freq));
326-
326+
327327
b_image.flash_size_freq = (b_image.flash_size_freq & 0xf0) | freq;
328328
return 1;
329329
}
330330

331331
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"};
333333

334334
unsigned char binimage_parse_flash_mode(const char* str)
335335
{
336336
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)
338338
{
339-
if (strcasecmp(str, flash_mode_str[i]) == 0)
339+
if (strcasecmp(str, flash_mode_str[i]) == 0)
340340
{
341341
return (unsigned char) i;
342342
}
@@ -347,9 +347,9 @@ unsigned char binimage_parse_flash_mode(const char* str)
347347
unsigned char binimage_parse_flash_size(const char* str)
348348
{
349349
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)
351351
{
352-
if (strcasecmp(str, flash_size_str[i]) == 0)
352+
if (strcasecmp(str, flash_size_str[i]) == 0)
353353
{
354354
return (unsigned char) i << 4;
355355
}
@@ -360,7 +360,7 @@ unsigned char binimage_parse_flash_size(const char* str)
360360
unsigned char binimage_parse_flash_freq(const char* str)
361361
{
362362
int val = atoi(str);
363-
switch (val)
363+
switch (val)
364364
{
365365
case 40: return FLASH_FREQ_40;
366366
case 26: return FLASH_FREQ_26;
@@ -380,7 +380,7 @@ const char* binimage_flash_mode_to_str(unsigned char mode)
380380

381381
const char* binimage_flash_size_to_str(unsigned char size)
382382
{
383-
if ((size >> 4) > FLASH_SIZE_32M)
383+
if ((size >> 4) > FLASH_SIZE_16M)
384384
return "";
385385
return flash_size_str[size >> 4];
386386
}
@@ -414,4 +414,3 @@ int binimage_set_header_layout(const char* layout)
414414
LOGERR("invalid image header layout: %s", layout);
415415
return 0;
416416
}
417-

binimage/esptool_binimage.h

+6-7
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@
2828
#include <stdio.h>
2929
#include <inttypes.h>
3030
#include <stdbool.h>
31-
31+
3232
/*
3333
** structs used to build and maintain internal representation
3434
** of the binary firmware image
3535
*/
3636

3737
/*
38-
** structure holding a given chunk of binary data
38+
** structure holding a given chunk of binary data
3939
*/
4040

4141
typedef struct {
@@ -45,7 +45,7 @@ typedef struct {
4545
} binary_segment;
4646

4747
/*
48-
** structure specifying the binary firmware image
48+
** structure specifying the binary firmware image
4949
** also stores the list of chunks used
5050
*/
5151

@@ -56,7 +56,7 @@ typedef struct {
5656
/* SPI Flash Interface (0 = QIO, 1 = QOUT, 2 = DIO, 0x3 = DOUT) */
5757
unsigned char flash_mode;
5858

59-
/* High four bits: 0 = 512K, 1 = 256K, 2 = 1M, 3 = 2M, 4 = 4M,
59+
/* High four bits: 0 = 512K, 1 = 256K, 2 = 1M, 3 = 2M, 4 = 4M,
6060
Low four bits: 0 = 40MHz, 1= 26MHz, 2 = 20MHz, 0xf = 80MHz */
6161
unsigned char flash_size_freq;
6262

@@ -75,9 +75,8 @@ typedef struct {
7575
#define FLASH_SIZE_1M 2 << 4
7676
#define FLASH_SIZE_2M 3 << 4
7777
#define FLASH_SIZE_4M 4 << 4
78-
#define FLASH_SIZE_8M 5 << 4
79-
#define FLASH_SIZE_16M 6 << 4
80-
#define FLASH_SIZE_32M 7 << 4
78+
#define FLASH_SIZE_8M 8 << 4
79+
#define FLASH_SIZE_16M 9 << 4
8180

8281
// flash frequency in MHz
8382
#define FLASH_FREQ_40 0x0

0 commit comments

Comments
 (0)