Skip to content

Commit a66257d

Browse files
committed
Move custom ElfToBin to a framework script
1 parent 32f0b31 commit a66257d

File tree

2 files changed

+56
-70
lines changed

2 files changed

+56
-70
lines changed

builder/frameworks/simba.py

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

2424
from os.path import join, sep
2525

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

2828
from platformio.builder.tools import platformio as platformio_tool
2929

@@ -50,13 +50,41 @@ def VariantDirWrap(env, variant_dir, src_dir, duplicate=False):
5050
env.AddMethod(LookupSources)
5151
env.AddMethod(VariantDirWrap)
5252

53+
env.Replace(
54+
PLATFORMFW_DIR=env.PioPlatform().get_package_dir("framework-simba"),
55+
OBJCOPY="esptool"
56+
)
57+
5358
env.Append(
5459
CPPDEFINES=[
5560
("F_CPU", "$BOARD_F_CPU")
56-
]
57-
)
58-
env.Replace(
59-
PLATFORMFW_DIR=env.PioPlatform().get_package_dir("framework-simba")
61+
],
62+
63+
BUILDERS=dict(
64+
ElfToBin=Builder(
65+
action=env.VerboseAction(" ".join([
66+
'esptool',
67+
"-eo", '"%s"' % join(
68+
"$PLATFORMFW_DIR", "3pp", "esp8266Arduino", "2.3.0",
69+
"bootloaders", "eboot", "eboot.elf"
70+
),
71+
"-bo", "$TARGET",
72+
"-bm", "$BOARD_FLASH_MODE",
73+
"-bf", "${__get_board_f_flash(__env__)}",
74+
"-bz", "${__get_flash_size(__env__)}",
75+
"-bs", ".text",
76+
"-bp", "4096",
77+
"-ec",
78+
"-eo", "$SOURCES",
79+
"-bs", ".irom0.text",
80+
"-bs", ".text",
81+
"-bs", ".data",
82+
"-bs", ".rodata",
83+
"-bc", "-ec"
84+
]), "Building $TARGET"),
85+
suffix=".bin"
86+
)
87+
)
6088
)
6189

6290
env.SConscript(

builder/main.py

Lines changed: 23 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ def _update_max_upload_size(env):
136136
CC="xtensa-lx106-elf-gcc",
137137
CXX="xtensa-lx106-elf-g++",
138138
GDB="xtensa-lx106-elf-gdb",
139-
OBJCOPY="esptool",
140139
RANLIB="xtensa-lx106-elf-ranlib",
141140
SIZETOOL="xtensa-lx106-elf-size",
142141

@@ -148,7 +147,7 @@ def _update_max_upload_size(env):
148147

149148
MKSPIFFSTOOL="mkspiffs",
150149

151-
SIZEPROGREGEXP=r"^(?:\.irom0\.text|\.text|\.data|\.rodata|)\s+([0-9]+).*",
150+
SIZEPROGREGEXP=r"^(?:\.irom0\.text|\.text|\.text1|\.data|\.rodata|)\s+([0-9]+).*",
152151
SIZEDATAREGEXP=r"^(?:\.data|\.rodata|\.bss)\s+([0-9]+).*",
153152
SIZECHECKCMD="$SIZETOOL -A -d $SOURCES",
154153
SIZEPRINTCMD='$SIZETOOL -B -d $SOURCES',
@@ -192,79 +191,38 @@ def _update_max_upload_size(env):
192191
emitter=__fetch_spiffs_size,
193192
source_factory=env.Dir,
194193
suffix=".bin"
194+
),
195+
196+
# Default for ESP8266 RTOS SDK and Native SDK common configuration
197+
# Frameworks may override "ElfToBin" builder
198+
ElfToBin=Builder(
199+
action=env.VerboseAction(" ".join([
200+
'esptool',
201+
"-eo", "$SOURCES",
202+
"-bo", "${TARGETS[0]}",
203+
"-bm", "$BOARD_FLASH_MODE",
204+
"-bf", "${__get_board_f_flash(__env__)}",
205+
"-bz", "${__get_flash_size(__env__)}",
206+
"-bs", ".text",
207+
"-bs", ".data",
208+
"-bs", ".rodata",
209+
"-bc", "-ec",
210+
"-eo", "$SOURCES",
211+
"-es", ".irom0.text", "${TARGETS[1]}",
212+
"-ec", "-v"
213+
]), "Building $TARGET"),
214+
suffix=".bin"
195215
)
196216
)
197217
)
198218

199219

200-
#
201-
# Framework and SDK specific configuration
202-
#
203-
204-
if env.subst("$PIOFRAMEWORK") in ("arduino", "simba"):
205-
if "simba" in env.subst("$PIOFRAMEWORK"):
206-
ebootelf_path = join(
207-
platform.get_package_dir("framework-simba") or "", "3pp",
208-
"esp8266Arduino", "2.3.0", "bootloaders", "eboot", "eboot.elf")
209-
else:
210-
ebootelf_path = join(
211-
platform.get_package_dir("framework-arduinoespressif8266") or "",
212-
"bootloaders", "eboot", "eboot.elf")
213-
214-
env.Append(
215-
BUILDERS=dict(
216-
ElfToBin=Builder(
217-
action=env.VerboseAction(" ".join([
218-
'"$OBJCOPY"',
219-
"-eo", '"%s"' % ebootelf_path,
220-
"-bo", "$TARGET",
221-
"-bm", "$BOARD_FLASH_MODE",
222-
"-bf", "${__get_board_f_flash(__env__)}",
223-
"-bz", "${__get_flash_size(__env__)}",
224-
"-bs", ".text",
225-
"-bp", "4096",
226-
"-ec",
227-
"-eo", "$SOURCES",
228-
"-bs", ".irom0.text",
229-
"-bs", ".text",
230-
"-bs", ".data",
231-
"-bs", ".rodata",
232-
"-bc", "-ec"
233-
]), "Building $TARGET"),
234-
suffix=".bin"
235-
)
236-
)
237-
)
238-
else:
239-
# ESP8266 RTOS SDK and Native SDK common configuration
240-
env.Append(
241-
BUILDERS=dict(
242-
ElfToBin=Builder(
243-
action=env.VerboseAction(" ".join([
244-
'"$OBJCOPY"',
245-
"-eo", "$SOURCES",
246-
"-bo", "${TARGETS[0]}",
247-
"-bm", "$BOARD_FLASH_MODE",
248-
"-bf", "${__get_board_f_flash(__env__)}",
249-
"-bz", "${__get_flash_size(__env__)}",
250-
"-bs", ".text",
251-
"-bs", ".data",
252-
"-bs", ".rodata",
253-
"-bc", "-ec",
254-
"-eo", "$SOURCES",
255-
"-es", ".irom0.text", "${TARGETS[1]}",
256-
"-ec", "-v"
257-
]), "Building $TARGET"),
258-
suffix=".bin"
259-
)
260-
)
261-
)
262-
263220
#
264221
# Target: Build executable and linkable firmware or SPIFFS image
265222
#
266223

267224
target_elf = env.BuildProgram()
225+
268226
if "nobuild" in COMMAND_LINE_TARGETS:
269227
if set(["uploadfs", "uploadfsota"]) & set(COMMAND_LINE_TARGETS):
270228
fetch_spiffs_size(env)

0 commit comments

Comments
 (0)