Skip to content

Commit 2c2c11f

Browse files
authored
IDF 5.3 support
1 parent 8765f6f commit 2c2c11f

File tree

1 file changed

+89
-22
lines changed

1 file changed

+89
-22
lines changed

builder/frameworks/espidf.py

Lines changed: 89 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@
6767
IDF_ENV_VERSION = "1.0.0"
6868
FRAMEWORK_DIR = platform.get_package_dir("framework-espidf")
6969
TOOLCHAIN_DIR = platform.get_package_dir(
70-
"toolchain-%s" % ("riscv32-esp" if mcu in ("esp32c2", "esp32c3", "esp32c6", "esp32h2") else ("xtensa-%s" % mcu))
70+
"toolchain-riscv32-esp"
71+
if mcu in ("esp32c2", "esp32c3", "esp32c6", "esp32h2", "esp32p4")
72+
else "toolchain-xtensa-esp-elf"
7173
)
7274

7375

@@ -248,7 +250,7 @@ def populate_idf_env_vars(idf_env):
248250
os.path.dirname(get_python_exe()),
249251
]
250252

251-
if mcu not in ("esp32c2", "esp32c3", "esp32c6","esp32h2"):
253+
if mcu not in ("esp32c2", "esp32c3", "esp32c6", "esp32h2", "esp32p4"):
252254
additional_packages.append(
253255
os.path.join(platform.get_package_dir("toolchain-esp32ulp"), "bin"),
254256
)
@@ -503,7 +505,7 @@ def extract_linker_script_fragments_backup(framework_components_dir, sdk_config)
503505
sys.stderr.write("Error: Failed to extract paths to linker script fragments\n")
504506
env.Exit(1)
505507

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

509511
# Add extra linker fragments
@@ -644,16 +646,30 @@ def generate_project_ld_script(sdk_config, ignore_targets=None):
644646
'--objdump "{objdump}"'
645647
).format(**args)
646648

649+
initial_ld_script = os.path.join(
650+
FRAMEWORK_DIR,
651+
"components",
652+
"esp_system",
653+
"ld",
654+
idf_variant,
655+
"sections.ld.in",
656+
)
657+
658+
if IDF5:
659+
initial_ld_script = preprocess_linker_file(
660+
initial_ld_script,
661+
os.path.join(
662+
BUILD_DIR,
663+
"esp-idf",
664+
"esp_system",
665+
"ld",
666+
"sections.ld.in",
667+
)
668+
)
669+
647670
return env.Command(
648671
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-
),
672+
initial_ld_script,
657673
env.VerboseAction(cmd, "Generating project linker script $TARGET"),
658674
)
659675

@@ -1103,6 +1119,46 @@ def get_app_partition_offset(pt_table, pt_offset):
11031119
return app_params.get("offset", "0x10000")
11041120

11051121

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

13511407
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",
1408+
initial_ld_script = board.get("build.esp-idf.ldscript", os.path.join(
1409+
FRAMEWORK_DIR,
1410+
"components",
1411+
"esp_system",
1412+
"ld",
1413+
idf_variant,
1414+
"memory.ld.in",
1415+
))
1416+
1417+
if IDF5:
1418+
initial_ld_script = preprocess_linker_file(
1419+
initial_ld_script,
13561420
os.path.join(
1357-
FRAMEWORK_DIR,
1358-
"components",
1421+
BUILD_DIR,
1422+
"esp-idf",
13591423
"esp_system",
13601424
"ld",
1361-
idf_variant,
13621425
"memory.ld.in",
1363-
),
1364-
),
1426+
)
1427+
)
1428+
1429+
linker_script = env.Command(
1430+
os.path.join("$BUILD_DIR", "memory.ld"),
1431+
initial_ld_script,
13651432
env.VerboseAction(
13661433
'$CC -I"$BUILD_DIR/config" -I"%s" -C -P -x c -E $SOURCE -o $TARGET'
13671434
% os.path.join(FRAMEWORK_DIR, "components", "esp_system", "ld"),
@@ -1601,7 +1668,7 @@ def _skip_prj_source_files(node):
16011668
(
16021669
board.get(
16031670
"upload.bootloader_offset",
1604-
"0x0" if mcu in ("esp32c2", "esp32c3", "esp32c6", "esp32s3", "esp32h2") else "0x1000",
1671+
"0x0" if mcu in ("esp32c2", "esp32c3", "esp32c6", "esp32s3", "esp32h2") else ("0x2000" if mcu in ("esp32p4") else "0x1000"),
16051672
),
16061673
os.path.join("$BUILD_DIR", "bootloader.bin"),
16071674
),
@@ -1712,7 +1779,7 @@ def _skip_prj_source_files(node):
17121779
#
17131780

17141781
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"):
1782+
if os.path.isdir(ulp_dir) and os.listdir(ulp_dir) and mcu not in ("esp32c2", "esp32c3", "esp32c6", "esp32h2", "esp32p4"):
17161783
env.SConscript("ulp.py", exports="env sdk_config project_config idf_variant")
17171784

17181785
#

0 commit comments

Comments
 (0)