Skip to content

Commit 3483868

Browse files
committed
Respect linkerscript override if given
1 parent ac37699 commit 3483868

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

builder/frameworks/ch32v003fun.py

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -140,28 +140,30 @@ def get_ld_defines(chip_name: str):
140140
env.Exit(-1)
141141
return (target_mcu, mcu_package, target_mcu_ld)
142142

143-
# retrieve needed macro values
144-
target_mcu, mcu_package, target_mcu_ld = get_ld_defines(chip_name)
143+
# if no custom LD script is given, generate one from the template
144+
if not board.get("build.ldscript", ""):
145+
# retrieve needed macro values
146+
target_mcu, mcu_package, target_mcu_ld = get_ld_defines(chip_name)
145147

146-
# Let the LD script be generated right before the .elf is built
147-
env.AddPreAction(
148-
"$BUILD_DIR/${PROGNAME}.elf",
149-
env.VerboseAction(" ".join([
150-
"$CC",
151-
"-E",
152-
"-P",
153-
"-x",
154-
"c",
155-
"-DTARGET_MCU=%s" % target_mcu,
156-
"-DMCU_PACKAGE=%d" % mcu_package,
157-
"-DTARGET_MCU_LD=%d" % target_mcu_ld,
158-
join(FRAMEWORK_DIR, MAIN_FUN_DIR, CH32FUN_LDSCRIPT),
159-
">",
160-
join("$BUILD_DIR", "ldscript.ld")
161-
]), "Building %s" % join("$BUILD_DIR", "ldscript.ld"))
162-
)
163-
# Already put in the right path for the to-be-generated file
164-
env.Replace(LDSCRIPT_PATH=join("$BUILD_DIR", "ldscript.ld"))
148+
# Let the LD script be generated right before the .elf is built
149+
env.AddPreAction(
150+
"$BUILD_DIR/${PROGNAME}.elf",
151+
env.VerboseAction(" ".join([
152+
"$CC",
153+
"-E",
154+
"-P",
155+
"-x",
156+
"c",
157+
"-DTARGET_MCU=%s" % target_mcu,
158+
"-DMCU_PACKAGE=%d" % mcu_package,
159+
"-DTARGET_MCU_LD=%d" % target_mcu_ld,
160+
join(FRAMEWORK_DIR, MAIN_FUN_DIR, CH32FUN_LDSCRIPT),
161+
">",
162+
join("$BUILD_DIR", "ldscript.ld")
163+
]), "Building %s" % join("$BUILD_DIR", "ldscript.ld"))
164+
)
165+
# Already put in the right path for the to-be-generated file
166+
env.Replace(LDSCRIPT_PATH=join("$BUILD_DIR", "ldscript.ld"))
165167

166168
# build actual ch32v003fun source file
167169
env.BuildSources(

0 commit comments

Comments
 (0)