Skip to content

Commit aa97eb0

Browse files
authored
Move penv setup out of main.py / invert mcu detection logic (#255)
1 parent 7d165d2 commit aa97eb0

File tree

4 files changed

+393
-328
lines changed

4 files changed

+393
-328
lines changed

builder/frameworks/_embed_files.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
Import("env")
2222

2323
board = env.BoardConfig()
24+
mcu = board.get("build.mcu", "esp32")
25+
is_xtensa = mcu in ("esp32", "esp32s2", "esp32s3")
2426

2527
#
2628
# Embedded files helpers
@@ -101,23 +103,22 @@ def transform_to_asm(target, source, env):
101103
files = [join("$BUILD_DIR", s.name + ".S") for s in source]
102104
return files, source
103105

104-
105-
mcu = board.get("build.mcu", "esp32")
106+
106107
env.Append(
107108
BUILDERS=dict(
108109
TxtToBin=Builder(
109110
action=env.VerboseAction(
110111
" ".join(
111112
[
112113
"riscv32-esp-elf-objcopy"
113-
if mcu in ("esp32c2","esp32c3","esp32c5","esp32c6","esp32h2","esp32p4")
114-
else "xtensa-%s-elf-objcopy" % mcu,
114+
if not is_xtensa
115+
else f"xtensa-{mcu}-elf-objcopy",
115116
"--input-target",
116117
"binary",
117118
"--output-target",
118-
"elf32-littleriscv" if mcu in ("esp32c2","esp32c3","esp32c5","esp32c6","esp32h2","esp32p4") else "elf32-xtensa-le",
119+
"elf32-littleriscv" if not is_xtensa else "elf32-xtensa-le",
119120
"--binary-architecture",
120-
"riscv" if mcu in ("esp32c2","esp32c3","esp32c5","esp32c6","esp32h2","esp32p4") else "xtensa",
121+
"riscv" if not is_xtensa else "xtensa",
121122
"--rename-section",
122123
".data=.rodata.embedded",
123124
"$SOURCE",

builder/frameworks/ulp.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,32 +31,35 @@
3131
BUILD_DIR, "esp-idf", project_config["name"].replace("__idf_", ""), "ulp_main"
3232
)
3333

34+
is_xtensa = idf_variant in ("esp32", "esp32s2", "esp32s3")
3435

3536
def prepare_ulp_env_vars(env):
3637
ulp_env.PrependENVPath("IDF_PATH", FRAMEWORK_DIR)
3738

3839
toolchain_path = platform.get_package_dir(
3940
"toolchain-xtensa-esp-elf"
40-
if idf_variant not in ("esp32c5","esp32c6", "esp32p4")
41+
if is_xtensa
4142
else "toolchain-riscv32-esp"
4243
)
4344

4445
toolchain_path_ulp = platform.get_package_dir(
4546
"toolchain-esp32ulp"
4647
if sdk_config.get("ULP_COPROC_TYPE_FSM", False)
47-
else ""
48+
else None
4849
)
4950

51+
python_dir = os.path.dirname(ulp_env.subst("$PYTHONEXE")) or ""
5052
additional_packages = [
5153
toolchain_path,
5254
toolchain_path_ulp,
5355
platform.get_package_dir("tool-ninja"),
5456
os.path.join(platform.get_package_dir("tool-cmake"), "bin"),
55-
os.path.dirname(where_is_program("python")),
57+
python_dir,
5658
]
5759

5860
for package in additional_packages:
59-
ulp_env.PrependENVPath("PATH", package)
61+
if package and os.path.isdir(package):
62+
ulp_env.PrependENVPath("PATH", package)
6063

6164

6265
def collect_ulp_sources():
@@ -85,17 +88,17 @@ def _generate_ulp_configuration_action(env, target, source):
8588
riscv_ulp_enabled = sdk_config.get("ULP_COPROC_TYPE_RISCV", False)
8689
lp_core_ulp_enabled = sdk_config.get("ULP_COPROC_TYPE_LP_CORE", False)
8790

88-
if lp_core_ulp_enabled == False:
91+
if not lp_core_ulp_enabled:
8992
ulp_toolchain = "toolchain-%sulp%s.cmake"% (
9093
"" if riscv_ulp_enabled else idf_variant + "-",
9194
"-riscv" if riscv_ulp_enabled else "",
9295
)
9396
else:
9497
ulp_toolchain = "toolchain-lp-core-riscv.cmake"
9598

96-
comp_includes = ";".join(get_component_includes(target_config))
97-
plain_includes = ";".join(app_includes["plain_includes"])
98-
comp_includes = comp_includes + plain_includes
99+
comp_includes_list = get_component_includes(target_config)
100+
plain_includes_list = app_includes["plain_includes"]
101+
comp_includes = ";".join(comp_includes_list + plain_includes_list)
99102

100103
cmd = (
101104
os.path.join(platform.get_package_dir("tool-cmake"), "bin", "cmake"),
@@ -112,7 +115,7 @@ def _generate_ulp_configuration_action(env, target, source):
112115
"-DULP_S_SOURCES=%s" % ";".join([fs.to_unix_path(s.get_abspath()) for s in source]),
113116
"-DULP_APP_NAME=ulp_main",
114117
"-DCOMPONENT_DIR=" + os.path.join(ulp_env.subst("$PROJECT_DIR"), "ulp"),
115-
"-DCOMPONENT_INCLUDES=" + comp_includes,
118+
"-DCOMPONENT_INCLUDES=%s" % comp_includes,
116119
"-DIDF_TARGET=%s" % idf_variant,
117120
"-DIDF_PATH=" + fs.to_unix_path(FRAMEWORK_DIR),
118121
"-DSDKCONFIG_HEADER=" + os.path.join(BUILD_DIR, "config", "sdkconfig.h"),

0 commit comments

Comments
 (0)