Skip to content

Commit de9e6b0

Browse files
committed
Refactor ldscripts processing
1 parent 4e3dd0d commit de9e6b0

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

platformio-build.py

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
env = DefaultEnvironment()
2828
platform = env.PioPlatform()
29+
board = env.BoardConfig()
2930

3031
FRAMEWORK_DIR = platform.get_package_dir("framework-mbed")
3132
assert isdir(FRAMEWORK_DIR)
@@ -119,7 +120,7 @@ def get_mbed_target(board_type):
119120
join(FRAMEWORK_DIR, "platformio", "variants_remap.json"))
120121
variant = variants_remap[
121122
board_type] if board_type in variants_remap else board_type.upper()
122-
return variant
123+
return board.get("build.mbed_variant", variant)
123124

124125

125126
def get_build_profile(cpp_defines):
@@ -233,26 +234,23 @@ def get_build_profile(cpp_defines):
233234
# Linker requires preprocessing with link flags
234235
#
235236

236-
ldscript = None
237-
if configuration.get("ldscript", [])[0]:
238-
ldscript = join(FRAMEWORK_DIR, configuration.get("ldscript")[0])
239-
elif env.get("LDSCRIPT_PATH", None):
240-
ldscript = env.subst(env.get("LDSCRIPT_PATH"))
241-
else:
242-
print ("Default Linker script is not found!")
243-
244-
if ldscript:
245-
linker_script = env.Command(
246-
join("$BUILD_DIR",
247-
"%s.link_script.ld" % basename(ldscript)),
248-
ldscript,
249-
env.VerboseAction(
250-
'%s -E -P $LINKFLAGS $SOURCE -o $TARGET' %
251-
env.subst("$GDB").replace("-gdb", "-cpp"),
252-
"Generating LD script $TARGET"))
253-
254-
env.Depends("$BUILD_DIR/$PROGNAME$PROGSUFFIX", linker_script)
255-
env.Replace(LDSCRIPT_PATH=linker_script)
237+
if not board.get("build.ldscript", ""):
238+
ldscript = join(FRAMEWORK_DIR, configuration.get("ldscript", [])[0] or "")
239+
if board.get("build.mbed.ldscript", ""):
240+
ldscript = env.subst(board.get("build.mbed.ldscript"))
241+
if isfile(ldscript):
242+
linker_script = env.Command(
243+
join("$BUILD_DIR", "%s.link_script.ld" % basename(ldscript)),
244+
ldscript,
245+
env.VerboseAction(
246+
'%s -E -P $LINKFLAGS $SOURCE -o $TARGET' %
247+
env.subst("$GDB").replace("-gdb", "-cpp"),
248+
"Generating LD script $TARGET"))
249+
250+
env.Depends("$BUILD_DIR/$PROGNAME$PROGSUFFIX", linker_script)
251+
env.Replace(LDSCRIPT_PATH=linker_script)
252+
else:
253+
print ("Warning! Couldn't find linker script file!")
256254

257255
#
258256
# Compile core part

0 commit comments

Comments
 (0)