Skip to content

Commit 77b00e4

Browse files
authored
Backport from upstream supporting all IDF 5.X
1 parent 8765f6f commit 77b00e4

File tree

1 file changed

+89
-27
lines changed

1 file changed

+89
-27
lines changed

builder/frameworks/espidf.py

Lines changed: 89 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,9 @@
5858
mcu = board.get("build.mcu", "esp32")
5959
idf_variant = mcu.lower()
6060

61-
# Required until Arduino switches to v5
62-
IDF5 = (
63-
platform.get_package_version("framework-espidf")
64-
.split(".")[1]
65-
.startswith("5")
66-
)
61+
IDF_version = platform.get_package_version("framework-espidf")
62+
IDF5 = IDF_version.split(".")[1].startswith("5") # bool; Major IDF5 ?
63+
IDF_minor = int(("".join(IDF_version.split(".")[1]))[1:3]) # Minor version as int
6764
IDF_ENV_VERSION = "1.0.0"
6865
FRAMEWORK_DIR = platform.get_package_dir("framework-espidf")
6966
TOOLCHAIN_DIR = platform.get_package_dir(
@@ -248,7 +245,7 @@ def populate_idf_env_vars(idf_env):
248245
os.path.dirname(get_python_exe()),
249246
]
250247

251-
if mcu not in ("esp32c2", "esp32c3", "esp32c6","esp32h2"):
248+
if mcu not in ("esp32c2", "esp32c3", "esp32c6", "esp32h2", "esp32p4"):
252249
additional_packages.append(
253250
os.path.join(platform.get_package_dir("toolchain-esp32ulp"), "bin"),
254251
)
@@ -503,7 +500,7 @@ def extract_linker_script_fragments_backup(framework_components_dir, sdk_config)
503500
sys.stderr.write("Error: Failed to extract paths to linker script fragments\n")
504501
env.Exit(1)
505502

506-
if mcu in ("esp32c2", "esp32c3", "esp32c6", "esp32h2"):
503+
if mcu in ("esp32c2", "esp32c3", "esp32c6", "esp32h2", "esp32p4"):
507504
result.append(os.path.join(framework_components_dir, "riscv", "linker.lf"))
508505

509506
# Add extra linker fragments
@@ -644,16 +641,30 @@ def generate_project_ld_script(sdk_config, ignore_targets=None):
644641
'--objdump "{objdump}"'
645642
).format(**args)
646643

644+
initial_ld_script = os.path.join(
645+
FRAMEWORK_DIR,
646+
"components",
647+
"esp_system",
648+
"ld",
649+
idf_variant,
650+
"sections.ld.in",
651+
)
652+
653+
if IDF5 and IDF_minor > 2:
654+
initial_ld_script = preprocess_linker_file(
655+
initial_ld_script,
656+
os.path.join(
657+
BUILD_DIR,
658+
"esp-idf",
659+
"esp_system",
660+
"ld",
661+
"sections.ld.in",
662+
)
663+
)
664+
647665
return env.Command(
648666
os.path.join("$BUILD_DIR", "sections.ld"),
649-
os.path.join(
650-
FRAMEWORK_DIR,
651-
"components",
652-
"esp_system",
653-
"ld",
654-
idf_variant,
655-
"sections.ld.in",
656-
),
667+
initial_ld_script,
657668
env.VerboseAction(cmd, "Generating project linker script $TARGET"),
658669
)
659670

@@ -1103,6 +1114,46 @@ def get_app_partition_offset(pt_table, pt_offset):
11031114
return app_params.get("offset", "0x10000")
11041115

11051116

1117+
def preprocess_linker_file(src_ld_script, target_ld_script):
1118+
return env.Command(
1119+
target_ld_script,
1120+
src_ld_script,
1121+
env.VerboseAction(
1122+
" ".join(
1123+
[
1124+
os.path.join(
1125+
platform.get_package_dir("tool-cmake"),
1126+
"bin",
1127+
"cmake",
1128+
),
1129+
"-DCC=%s"
1130+
% os.path.join(
1131+
TOOLCHAIN_DIR,
1132+
"bin",
1133+
"$CC",
1134+
),
1135+
"-DSOURCE=$SOURCE",
1136+
"-DTARGET=$TARGET",
1137+
"-DCONFIG_DIR=%s" % os.path.join(BUILD_DIR, "config"),
1138+
"-DLD_DIR=%s"
1139+
% os.path.join(
1140+
FRAMEWORK_DIR, "components", "esp_system", "ld"
1141+
),
1142+
"-P",
1143+
os.path.join(
1144+
"$BUILD_DIR",
1145+
"esp-idf",
1146+
"esp_system",
1147+
"ld",
1148+
"linker_script_generator.cmake",
1149+
),
1150+
]
1151+
),
1152+
"Generating LD script $TARGET",
1153+
),
1154+
)
1155+
1156+
11061157
def generate_mbedtls_bundle(sdk_config):
11071158
bundle_path = os.path.join("$BUILD_DIR", "x509_crt_bundle")
11081159
if os.path.isfile(env.subst(bundle_path)):
@@ -1349,19 +1400,30 @@ def get_python_exe():
13491400
#
13501401

13511402
if not board.get("build.ldscript", ""):
1352-
linker_script = env.Command(
1353-
os.path.join("$BUILD_DIR", "memory.ld"),
1354-
board.get(
1355-
"build.esp-idf.ldscript",
1403+
initial_ld_script = board.get("build.esp-idf.ldscript", os.path.join(
1404+
FRAMEWORK_DIR,
1405+
"components",
1406+
"esp_system",
1407+
"ld",
1408+
idf_variant,
1409+
"memory.ld.in",
1410+
))
1411+
1412+
if IDF5 and IDF_minor > 2:
1413+
initial_ld_script = preprocess_linker_file(
1414+
initial_ld_script,
13561415
os.path.join(
1357-
FRAMEWORK_DIR,
1358-
"components",
1416+
BUILD_DIR,
1417+
"esp-idf",
13591418
"esp_system",
13601419
"ld",
1361-
idf_variant,
13621420
"memory.ld.in",
1363-
),
1364-
),
1421+
)
1422+
)
1423+
1424+
linker_script = env.Command(
1425+
os.path.join("$BUILD_DIR", "memory.ld"),
1426+
initial_ld_script,
13651427
env.VerboseAction(
13661428
'$CC -I"$BUILD_DIR/config" -I"%s" -C -P -x c -E $SOURCE -o $TARGET'
13671429
% os.path.join(FRAMEWORK_DIR, "components", "esp_system", "ld"),
@@ -1601,7 +1663,7 @@ def _skip_prj_source_files(node):
16011663
(
16021664
board.get(
16031665
"upload.bootloader_offset",
1604-
"0x0" if mcu in ("esp32c2", "esp32c3", "esp32c6", "esp32s3", "esp32h2") else "0x1000",
1666+
"0x0" if mcu in ("esp32c2", "esp32c3", "esp32c6", "esp32s3", "esp32h2") else ("0x2000" if mcu in ("esp32p4") else "0x1000"),
16051667
),
16061668
os.path.join("$BUILD_DIR", "bootloader.bin"),
16071669
),
@@ -1712,7 +1774,7 @@ def _skip_prj_source_files(node):
17121774
#
17131775

17141776
ulp_dir = os.path.join(PROJECT_DIR, "ulp")
1715-
if os.path.isdir(ulp_dir) and os.listdir(ulp_dir) and mcu not in ("esp32c2", "esp32c3", "esp32h2"):
1777+
if os.path.isdir(ulp_dir) and os.listdir(ulp_dir) and mcu not in ("esp32c2", "esp32c3", "esp32c6", "esp32h2", "esp32p4"):
17161778
env.SConscript("ulp.py", exports="env sdk_config project_config idf_variant")
17171779

17181780
#

0 commit comments

Comments
 (0)