Skip to content

Commit bc284f7

Browse files
committed
Update IDF build script according to v4.4.1
1 parent 1728319 commit bc284f7

File tree

2 files changed

+66
-71
lines changed

2 files changed

+66
-71
lines changed

builder/frameworks/espidf.py

Lines changed: 64 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,9 @@
5050
idf_variant = mcu.lower()
5151

5252
FRAMEWORK_DIR = platform.get_package_dir("framework-espidf")
53-
54-
# Legacy toolchains for mixed IDF/Arduino projects
55-
if "arduino" in env.subst("$PIOFRAMEWORK"):
56-
TOOLCHAIN_DIR = platform.get_package_dir("toolchain-xtensa32")
57-
else:
58-
TOOLCHAIN_DIR = platform.get_package_dir(
59-
"toolchain-%s"
60-
% (
61-
"riscv32-esp"
62-
if mcu == "esp32c3"
63-
else ("xtensa-esp32s2" if mcu == "esp32s2" else "xtensa-esp32")
64-
)
65-
)
53+
TOOLCHAIN_DIR = platform.get_package_dir(
54+
"toolchain-%s" % ("riscv32-esp" if mcu == "esp32c3" else ("xtensa-%s" % mcu))
55+
)
6656

6757

6858
assert os.path.isdir(FRAMEWORK_DIR)
@@ -233,7 +223,7 @@ def populate_idf_env_vars(idf_env):
233223
os.path.dirname(env.subst("$PYTHONEXE")),
234224
]
235225

236-
if mcu != "esp32c3":
226+
if mcu not in ("esp32c3", "esp32s3"):
237227
additional_packages.append(
238228
os.path.join(platform.get_package_dir("toolchain-%sulp" % mcu), "bin"),
239229
)
@@ -857,9 +847,11 @@ def generate_default_component():
857847
file(GLOB component_sources *.c* *.S)
858848
idf_component_register(SRCS ${component_sources})
859849
"""
860-
dummy_component_path = os.path.join(BUILD_DIR, "__pio_env")
861-
if not os.path.isdir(dummy_component_path):
862-
os.makedirs(dummy_component_path)
850+
dummy_component_path = os.path.join(FRAMEWORK_DIR, "components", "__pio_env")
851+
if os.path.isdir(dummy_component_path):
852+
return
853+
854+
os.makedirs(dummy_component_path)
863855

864856
for ext in (".cpp", ".c", ".S"):
865857
dummy_file = os.path.join(dummy_component_path, "__dummy" + ext)
@@ -871,8 +863,6 @@ def generate_default_component():
871863
with open(component_cmake, "w") as fp:
872864
fp.write(prj_cmake_tpl)
873865

874-
return dummy_component_path
875-
876866

877867
def find_default_component(target_configs):
878868
for config in target_configs:
@@ -1098,66 +1088,45 @@ def _get_installed_pip_packages():
10981088

10991089
install_python_deps()
11001090

1101-
11021091
# ESP-IDF package doesn't contain .git folder, instead package version is specified
11031092
# in a special file "version.h" in the root folder of the package
11041093

11051094
create_version_file()
11061095

1096+
# Generate a default component with dummy C/C++/ASM source files in the framework
1097+
# folder. This component is used to force the IDF build system generate build
1098+
# information for generic C/C++/ASM sources regardless of whether such files are used in project
1099+
1100+
generate_default_component()
1101+
11071102
#
11081103
# Generate final linker script
11091104
#
11101105

11111106
if not board.get("build.ldscript", ""):
1112-
linker_common = os.path.join(FRAMEWORK_DIR, "components", "esp_system", "ld")
11131107
linker_script = env.Command(
11141108
os.path.join("$BUILD_DIR", "memory.ld"),
11151109
board.get(
11161110
"build.esp-idf.ldscript",
11171111
os.path.join(
1118-
FRAMEWORK_DIR, "components", "esp_system", "ld", idf_variant, "memory.ld.in"
1112+
FRAMEWORK_DIR,
1113+
"components",
1114+
"esp_system",
1115+
"ld",
1116+
idf_variant,
1117+
"memory.ld.in",
11191118
),
11201119
),
11211120
env.VerboseAction(
1122-
f'$CC -I"$BUILD_DIR/config" -I"{linker_common}" -C -P -x c -E $SOURCE -o $TARGET',
1121+
'$CC -I"$BUILD_DIR/config" -I"%s" -C -P -x c -E $SOURCE -o $TARGET'
1122+
% os.path.join(FRAMEWORK_DIR, "components", "esp_system", "ld"),
11231123
"Generating LD script $TARGET",
11241124
),
11251125
)
11261126

11271127
env.Depends("$BUILD_DIR/$PROGNAME$PROGSUFFIX", linker_script)
11281128
env.Replace(LDSCRIPT_PATH="memory.ld")
11291129

1130-
#
1131-
# Generate partition table
1132-
#
1133-
1134-
fwpartitions_dir = os.path.join(FRAMEWORK_DIR, "components", "partition_table")
1135-
partitions_csv = board.get("build.partitions", "partitions_singleapp.csv")
1136-
1137-
env.Replace(
1138-
PARTITIONS_TABLE_CSV=os.path.abspath(
1139-
os.path.join(fwpartitions_dir, partitions_csv)
1140-
if os.path.isfile(os.path.join(fwpartitions_dir, partitions_csv))
1141-
else partitions_csv
1142-
)
1143-
)
1144-
1145-
partition_table = env.Command(
1146-
os.path.join("$BUILD_DIR", "partitions.bin"),
1147-
"$PARTITIONS_TABLE_CSV",
1148-
env.VerboseAction(
1149-
'"$PYTHONEXE" "%s" -q --flash-size "%s" $SOURCE $TARGET'
1150-
% (
1151-
os.path.join(
1152-
FRAMEWORK_DIR, "components", "partition_table", "gen_esp32part.py"
1153-
),
1154-
board.get("upload.flash_size", "4MB"),
1155-
),
1156-
"Generating partitions $TARGET",
1157-
),
1158-
)
1159-
1160-
env.Depends("$BUILD_DIR/$PROGNAME$PROGSUFFIX", partition_table)
11611130

11621131
#
11631132
# Current build script limitations
@@ -1195,7 +1164,7 @@ def _get_installed_pip_packages():
11951164
# By default 'main' folder is used to store source files. In case when a user has
11961165
# default 'src' folder we need to add this as an extra component. If there is no 'main'
11971166
# folder CMake won't generate dependencies properly
1198-
extra_components = [generate_default_component()]
1167+
extra_components = []
11991168
if PROJECT_SRC_DIR != os.path.join(PROJECT_DIR, "main"):
12001169
extra_components.append(PROJECT_SRC_DIR)
12011170
if "arduino" in env.subst("$PIOFRAMEWORK"):
@@ -1309,7 +1278,7 @@ def _get_installed_pip_packages():
13091278
extra_flags = filter_args(link_args["LINKFLAGS"], ["-T", "-u"])
13101279
link_args["LINKFLAGS"] = sorted(list(set(link_args["LINKFLAGS"]) - set(extra_flags)))
13111280

1312-
# remove the main linker script flags '-T esp32_out.ld'
1281+
# remove the main linker script flags '-T memory.ld'
13131282
try:
13141283
ld_index = extra_flags.index("memory.ld")
13151284
extra_flags.pop(ld_index)
@@ -1358,7 +1327,44 @@ def _skip_prj_source_files(node):
13581327
)
13591328
)
13601329

1330+
#
1331+
# Generate partition table
1332+
#
1333+
1334+
fwpartitions_dir = os.path.join(FRAMEWORK_DIR, "components", "partition_table")
1335+
partitions_csv = board.get("build.partitions", "partitions_singleapp.csv")
13611336
partition_table_offset = sdk_config.get("PARTITION_TABLE_OFFSET", 0x8000)
1337+
1338+
env.Replace(
1339+
PARTITIONS_TABLE_CSV=os.path.abspath(
1340+
os.path.join(fwpartitions_dir, partitions_csv)
1341+
if os.path.isfile(os.path.join(fwpartitions_dir, partitions_csv))
1342+
else partitions_csv
1343+
)
1344+
)
1345+
1346+
partition_table = env.Command(
1347+
os.path.join("$BUILD_DIR", "partitions.bin"),
1348+
"$PARTITIONS_TABLE_CSV",
1349+
env.VerboseAction(
1350+
'"$PYTHONEXE" "%s" -q --offset "%s" --flash-size "%s" $SOURCE $TARGET'
1351+
% (
1352+
os.path.join(
1353+
FRAMEWORK_DIR, "components", "partition_table", "gen_esp32part.py"
1354+
),
1355+
partition_table_offset,
1356+
board.get("upload.flash_size", "4MB"),
1357+
),
1358+
"Generating partitions $TARGET",
1359+
),
1360+
)
1361+
1362+
env.Depends("$BUILD_DIR/$PROGNAME$PROGSUFFIX", partition_table)
1363+
1364+
#
1365+
# Main environment configuration
1366+
#
1367+
13621368
project_flags.update(link_args)
13631369
env.MergeFlags(project_flags)
13641370
env.Prepend(
@@ -1369,7 +1375,8 @@ def _skip_prj_source_files(node):
13691375
FLASH_EXTRA_IMAGES=[
13701376
(
13711377
board.get(
1372-
"upload.bootloader_offset", "0x0" if mcu == "esp32c3" else "0x1000"
1378+
"upload.bootloader_offset",
1379+
"0x0" if mcu in ("esp32c3", "esp32s3") else "0x1000",
13731380
),
13741381
os.path.join("$BUILD_DIR", "bootloader.bin"),
13751382
),

platform.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,7 @@ def configure_default_packages(self, variables, targets):
108108
# RISC-V based toolchain for ESP32C3, ESP32S2, ESP32S3 ULP
109109
self.packages["toolchain-riscv32-esp"]["optional"] = False
110110

111-
is_legacy_project = (
112-
build_core == "mbcwb"
113-
or set(("arduino", "espidf")) == set(frameworks)
114-
)
115-
116-
if is_legacy_project:
111+
if build_core == "mbcwb":
117112
# Remove the main toolchains from PATH
118113
for toolchain in (
119114
"toolchain-xtensa-esp32",
@@ -127,16 +122,9 @@ def configure_default_packages(self, variables, targets):
127122
self.packages["toolchain-xtensa32"] = {
128123
"type": "toolchain",
129124
"owner": "platformio",
130-
"version": "~2.80400.0"
131-
if "arduino" in frameworks and build_core != "mbcwb"
132-
else "~2.50200.0",
125+
"version": "~2.50200.0"
133126
}
134127

135-
# Legacy setting for mixed IDF+Arduino projects
136-
if set(("arduino", "espidf")) == set(frameworks):
137-
# Arduino component is not compatible with ESP-IDF >=4.1
138-
self.packages["framework-espidf"]["version"] = "~3.40001.0"
139-
140128
if build_core == "mbcwb":
141129
self.packages["framework-arduinoespressif32"]["optional"] = True
142130
self.packages["framework-arduino-mbcwb"]["optional"] = False

0 commit comments

Comments
 (0)