Skip to content

Commit 0d2518f

Browse files
committed
Fix "esptool write_flash error" when using ESP8266 SDK // Resolve #149
1 parent adb4965 commit 0d2518f

File tree

3 files changed

+55
-50
lines changed

3 files changed

+55
-50
lines changed

builder/frameworks/esp8266-nonos-sdk.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
from os.path import isdir, join
2424

25-
from SCons.Script import DefaultEnvironment
25+
from SCons.Script import Builder, DefaultEnvironment
2626

2727
env = DefaultEnvironment()
2828
platform = env.PioPlatform()
@@ -96,10 +96,31 @@
9696
],
9797

9898
LIBS=[
99-
"airkiss", "at", "c", "crypto", "driver", "espnow", "gcc", "json", "lwip",
100-
"main", "mbedtls", "mesh", "net80211", "phy", "pp", "pwm", "smartconfig",
101-
"ssl", "upgrade", "wpa", "wpa2", "wps"
102-
]
99+
"airkiss", "at", "c", "crypto", "driver", "espnow", "gcc", "json",
100+
"lwip", "main", "mbedtls", "mesh", "net80211", "phy", "pp", "pwm",
101+
"smartconfig", "ssl", "upgrade", "wpa", "wpa2", "wps"
102+
],
103+
104+
BUILDERS=dict(
105+
ElfToBin=Builder(
106+
action=env.VerboseAction(" ".join([
107+
'esptool',
108+
"-eo", "$SOURCE",
109+
"-bo", "${TARGET}",
110+
"-bm", "$BOARD_FLASH_MODE",
111+
"-bf", "${__get_board_f_flash(__env__)}",
112+
"-bz", "${__get_flash_size(__env__)}",
113+
"-bs", ".text",
114+
"-bs", ".data",
115+
"-bs", ".rodata",
116+
"-bc", "-ec",
117+
"-eo", "$SOURCE",
118+
"-es", ".irom0.text", "${TARGET}.irom0text.bin",
119+
"-ec", "-v"
120+
]), "Building $TARGET"),
121+
suffix=".bin"
122+
)
123+
)
103124
)
104125

105126
# copy CCFLAGS to ASFLAGS (-x assembler-with-cpp mode)
@@ -125,8 +146,7 @@
125146

126147
env.Append(
127148
FLASH_EXTRA_IMAGES=[
128-
("0x00000", join("$BUILD_DIR", "eagle.flash.bin")),
129-
("0x10000", join("$BUILD_DIR", "eagle.irom0text.bin")),
149+
("0x10000", join("$BUILD_DIR", "${PROGNAME}.bin.irom0text.bin")),
130150
(hex(init_data_flash_address),
131151
join(FRAMEWORK_DIR, "bin", "esp_init_data_default.bin")),
132152
(hex(init_data_flash_address + 0x2000),

builder/frameworks/esp8266-rtos-sdk.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
from os.path import isdir, join
2525

26-
from SCons.Script import DefaultEnvironment
26+
from SCons.Script import Builder, DefaultEnvironment
2727

2828
env = DefaultEnvironment()
2929
platform = env.PioPlatform()
@@ -99,7 +99,28 @@
9999
"cirom", "crypto", "driver", "espconn", "espnow", "freertos", "gcc",
100100
"json", "hal", "lwip", "main", "mesh", "mirom", "net80211", "nopoll",
101101
"phy", "pp", "pwm", "smartconfig", "spiffs", "ssl", "wpa", "wps"
102-
]
102+
],
103+
104+
BUILDERS=dict(
105+
ElfToBin=Builder(
106+
action=env.VerboseAction(" ".join([
107+
'esptool',
108+
"-eo", "$SOURCE",
109+
"-bo", "${TARGET}",
110+
"-bm", "$BOARD_FLASH_MODE",
111+
"-bf", "${__get_board_f_flash(__env__)}",
112+
"-bz", "${__get_flash_size(__env__)}",
113+
"-bs", ".text",
114+
"-bs", ".data",
115+
"-bs", ".rodata",
116+
"-bc", "-ec",
117+
"-eo", "$SOURCE",
118+
"-es", ".irom0.text", "${TARGET}.irom0text.bin",
119+
"-ec", "-v"
120+
]), "Building $TARGET"),
121+
suffix=".bin"
122+
)
123+
)
103124
)
104125

105126
# copy CCFLAGS to ASFLAGS (-x assembler-with-cpp mode)
@@ -126,8 +147,7 @@
126147

127148
env.Append(
128149
FLASH_EXTRA_IMAGES=[
129-
("0x00000", join("$BUILD_DIR", "eagle.flash.bin")),
130-
("0x20000", join("$BUILD_DIR", "eagle.irom0text.bin")),
150+
("0x20000", join("$BUILD_DIR", "${PROGNAME}.bin.irom0text.bin")),
131151
(hex(init_data_flash_address),
132152
join(FRAMEWORK_DIR, "bin", "esp_init_data_default.bin")),
133153
(hex(init_data_flash_address + 0x2000),

builder/main.py

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,6 @@ def _update_max_upload_size(env):
163163
PROGSUFFIX=".elf"
164164
)
165165

166-
if int(ARGUMENTS.get("PIOVERBOSE", 0)):
167-
env.Prepend(UPLOADERFLAGS=["-vv"])
168-
169166
# Allow user to override via pre:script
170167
if env.get("PROGNAME", "program") == "program":
171168
env.Replace(PROGNAME="firmware")
@@ -193,27 +190,6 @@ def _update_max_upload_size(env):
193190
emitter=__fetch_spiffs_size,
194191
source_factory=env.Dir,
195192
suffix=".bin"
196-
),
197-
198-
# Default for ESP8266 RTOS SDK and Native SDK common configuration
199-
# Frameworks may override "ElfToBin" builder
200-
ElfToBin=Builder(
201-
action=env.VerboseAction(" ".join([
202-
'esptool',
203-
"-eo", "$SOURCES",
204-
"-bo", "${TARGETS[0]}",
205-
"-bm", "$BOARD_FLASH_MODE",
206-
"-bf", "${__get_board_f_flash(__env__)}",
207-
"-bz", "${__get_flash_size(__env__)}",
208-
"-bs", ".text",
209-
"-bs", ".data",
210-
"-bs", ".rodata",
211-
"-bc", "-ec",
212-
"-eo", "$SOURCES",
213-
"-es", ".irom0.text", "${TARGETS[1]}",
214-
"-ec", "-v"
215-
]), "Building $TARGET"),
216-
suffix=".bin"
217193
)
218194
)
219195
)
@@ -229,28 +205,17 @@ def _update_max_upload_size(env):
229205
if set(["uploadfs", "uploadfsota"]) & set(COMMAND_LINE_TARGETS):
230206
fetch_spiffs_size(env)
231207
target_firm = join("$BUILD_DIR", "spiffs.bin")
232-
elif env.subst("$PIOFRAMEWORK") in ("arduino", "simba"):
233-
target_firm = join("$BUILD_DIR", "${PROGNAME}.bin")
234208
else:
235-
target_firm = [
236-
join("$BUILD_DIR", "eagle.flash.bin"),
237-
join("$BUILD_DIR", "eagle.irom0text.bin")
238-
]
209+
target_firm = join("$BUILD_DIR", "${PROGNAME}.bin")
239210
else:
240211
if set(["buildfs", "uploadfs", "uploadfsota"]) & set(COMMAND_LINE_TARGETS):
241212
target_firm = env.DataToBin(
242213
join("$BUILD_DIR", "spiffs"), "$PROJECTDATA_DIR")
243214
AlwaysBuild(target_firm)
244215
AlwaysBuild(env.Alias("buildfs", target_firm))
245216
else:
246-
if env.subst("$PIOFRAMEWORK") in ("arduino", "simba"):
247-
target_firm = env.ElfToBin(
248-
join("$BUILD_DIR", "${PROGNAME}"), target_elf)
249-
else:
250-
target_firm = env.ElfToBin([
251-
join("$BUILD_DIR", "eagle.flash.bin"),
252-
join("$BUILD_DIR", "eagle.irom0text.bin")
253-
], target_elf)
217+
target_firm = env.ElfToBin(
218+
join("$BUILD_DIR", "${PROGNAME}"), target_elf)
254219

255220
AlwaysBuild(env.Alias("nobuild", target_firm))
256221
target_buildprog = env.Alias("buildprog", target_firm, target_firm)
@@ -322,7 +287,7 @@ def _update_max_upload_size(env):
322287
"--baud", "$UPLOAD_SPEED",
323288
"write_flash"
324289
],
325-
UPLOADCMD='"$PYTHONEXE" "$UPLOADER" $UPLOADERFLAGS 0 $SOURCE'
290+
UPLOADCMD='"$PYTHONEXE" "$UPLOADER" $UPLOADERFLAGS 0x0 $SOURCE'
326291
)
327292
for image in env.get("FLASH_EXTRA_IMAGES", []):
328293
env.Append(UPLOADERFLAGS=[image[0], env.subst(image[1])])

0 commit comments

Comments
 (0)