From b3ef03f08048a8531a624c1b17dae3cad1504725 Mon Sep 17 00:00:00 2001 From: valeros Date: Mon, 29 Jul 2024 12:46:36 +0300 Subject: [PATCH 1/3] Update IDF script --- builder/frameworks/espidf.py | 99 +++++++++++++++++++++++++++++------- builder/frameworks/ulp.py | 12 +++-- 2 files changed, 91 insertions(+), 20 deletions(-) diff --git a/builder/frameworks/espidf.py b/builder/frameworks/espidf.py index 3b9850039..c488352c6 100644 --- a/builder/frameworks/espidf.py +++ b/builder/frameworks/espidf.py @@ -652,16 +652,30 @@ def generate_project_ld_script(sdk_config, ignore_targets=None): '--objdump "{objdump}"' ).format(**args) + initial_ld_script = os.path.join( + FRAMEWORK_DIR, + "components", + "esp_system", + "ld", + idf_variant, + "sections.ld.in", + ) + + if IDF5: + initial_ld_script = preprocess_linker_file( + initial_ld_script, + os.path.join( + BUILD_DIR, + "esp-idf", + "esp_system", + "ld", + "sections.ld.in", + ) + ) + return env.Command( os.path.join("$BUILD_DIR", "sections.ld"), - os.path.join( - FRAMEWORK_DIR, - "components", - "esp_system", - "ld", - idf_variant, - "sections.ld.in", - ), + initial_ld_script, env.VerboseAction(cmd, "Generating project linker script $TARGET"), ) @@ -1111,6 +1125,46 @@ def get_app_partition_offset(pt_table, pt_offset): return app_params.get("offset", "0x10000") +def preprocess_linker_file(src_ld_script, target_ld_script): + return env.Command( + target_ld_script, + src_ld_script, + env.VerboseAction( + " ".join( + [ + os.path.join( + platform.get_package_dir("tool-cmake"), + "bin", + "cmake", + ), + "-DCC=%s" + % os.path.join( + TOOLCHAIN_DIR, + "bin", + "$CC", + ), + "-DSOURCE=$SOURCE", + "-DTARGET=$TARGET", + "-DCONFIG_DIR=%s" % os.path.join(BUILD_DIR, "config"), + "-DLD_DIR=%s" + % os.path.join( + FRAMEWORK_DIR, "components", "esp_system", "ld" + ), + "-P", + os.path.join( + "$BUILD_DIR", + "esp-idf", + "esp_system", + "ld", + "linker_script_generator.cmake", + ), + ] + ), + "Generating LD script $TARGET", + ), + ) + + def generate_mbedtls_bundle(sdk_config): bundle_path = os.path.join("$BUILD_DIR", "x509_crt_bundle") if os.path.isfile(env.subst(bundle_path)): @@ -1356,19 +1410,30 @@ def get_python_exe(): # if not board.get("build.ldscript", ""): - linker_script = env.Command( - os.path.join("$BUILD_DIR", "memory.ld"), - board.get( - "build.esp-idf.ldscript", + initial_ld_script = board.get("build.esp-idf.ldscript", os.path.join( + FRAMEWORK_DIR, + "components", + "esp_system", + "ld", + idf_variant, + "memory.ld.in", + )) + + if IDF5: + initial_ld_script = preprocess_linker_file( + initial_ld_script, os.path.join( - FRAMEWORK_DIR, - "components", + BUILD_DIR, + "esp-idf", "esp_system", "ld", - idf_variant, "memory.ld.in", - ), - ), + ) + ) + + linker_script = env.Command( + os.path.join("$BUILD_DIR", "memory.ld"), + initial_ld_script, env.VerboseAction( '$CC -I"$BUILD_DIR/config" -I"%s" -C -P -x c -E $SOURCE -o $TARGET' % os.path.join(FRAMEWORK_DIR, "components", "esp_system", "ld"), diff --git a/builder/frameworks/ulp.py b/builder/frameworks/ulp.py index 1a66c2bc9..ad61d8002 100644 --- a/builder/frameworks/ulp.py +++ b/builder/frameworks/ulp.py @@ -13,6 +13,7 @@ # limitations under the License. import os +import sys from platformio import fs from platformio.util import get_systype @@ -60,7 +61,7 @@ def prepare_ulp_env_vars(env): def collect_ulp_sources(): return [ - fs.to_unix_path(os.path.join(ulp_env.subst("$PROJECT_DIR"), "ulp", f)) + os.path.join(ulp_env.subst("$PROJECT_DIR"), "ulp", f) for f in os.listdir(os.path.join(ulp_env.subst("$PROJECT_DIR"), "ulp")) if f.endswith((".c", ".S", ".s")) ] @@ -98,7 +99,7 @@ def _generate_ulp_configuration_action(env, target, source): "-riscv" if riscv_ulp_enabled else "", ), ), - "-DULP_S_SOURCES=%s" % ";".join([s.get_abspath() for s in source]), + "-DULP_S_SOURCES=%s" % ";".join([fs.to_unix_path(s.get_abspath()) for s in source]), "-DULP_APP_NAME=ulp_main", "-DCOMPONENT_DIR=" + os.path.join(ulp_env.subst("$PROJECT_DIR"), "ulp"), "-DCOMPONENT_INCLUDES=%s" % ";".join(get_component_includes(target_config)), @@ -113,7 +114,12 @@ def _generate_ulp_configuration_action(env, target, source): os.path.join(FRAMEWORK_DIR, "components", "ulp", "cmake"), ) - exec_command(cmd) + print(555, cmd) + + result = exec_command(cmd) + if result["returncode"] != 0: + sys.stderr.write(result["err"] + "\n") + env.Exit(1) ulp_sources = collect_ulp_sources() ulp_sources.sort() From e519b925e10c7e32eadf89287232cfffdaf82774 Mon Sep 17 00:00:00 2001 From: valeros Date: Mon, 29 Jul 2024 12:47:21 +0300 Subject: [PATCH 2/3] Update packages --- platform.json | 8 ++++---- platform.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/platform.json b/platform.json index 78cc059cf..e4ff766fb 100644 --- a/platform.json +++ b/platform.json @@ -52,19 +52,19 @@ "optional": true, "owner": "espressif", "version": "8.4.0+2021r2-patch5", - "optionalVersions": ["13.2.0+20230928"] + "optionalVersions": ["13.2.0+20240530"] }, "toolchain-xtensa-esp-elf": { "type": "toolchain", "optional": true, "owner": "platformio", - "version": "13.2.0+20230928" + "version": "13.2.0+20240530" }, "toolchain-esp32ulp": { "type": "toolchain", "optional": true, "owner": "platformio", - "version": "~1.23500.0" + "version": "~1.23800.0" }, "tool-xtensa-esp-elf-gdb": { "type": "debugger", @@ -88,7 +88,7 @@ "type": "framework", "optional": true, "owner": "platformio", - "version": "~3.50202.0", + "version": "~3.50300.0", "optionalVersions": ["~3.40407.0"] }, "tool-esptoolpy": { diff --git a/platform.py b/platform.py index e0537875e..895948e06 100644 --- a/platform.py +++ b/platform.py @@ -137,7 +137,7 @@ def configure_default_packages(self, variables, targets): self.packages["toolchain-riscv32-esp"]["owner"] = "platformio" self.packages["toolchain-riscv32-esp"][ "version" - ] = "13.2.0+20230928" + ] = "13.2.0+20240530" if "arduino" in frameworks: # Disable standalone GDB packages for Arduino and Arduino/IDF projects From cb702f414def21c8da32709a93b51d6a34d05415 Mon Sep 17 00:00:00 2001 From: valeros Date: Mon, 29 Jul 2024 18:04:48 +0300 Subject: [PATCH 3/3] Fix incorrect handling of positional linker flags Resolves #1430 --- builder/frameworks/espidf.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/builder/frameworks/espidf.py b/builder/frameworks/espidf.py index c488352c6..9c5158785 100644 --- a/builder/frameworks/espidf.py +++ b/builder/frameworks/espidf.py @@ -1595,7 +1595,9 @@ def get_python_exe(): # Extra flags which need to be explicitly specified in LINKFLAGS section because SCons # cannot merge them correctly -extra_flags = filter_args(link_args["LINKFLAGS"], ["-T", "-u"]) +extra_flags = filter_args( + link_args["LINKFLAGS"], ["-T", "-u", "-Wl,--start-group", "-Wl,--end-group"] +) link_args["LINKFLAGS"] = sorted(list(set(link_args["LINKFLAGS"]) - set(extra_flags))) # remove the main linker script flags '-T memory.ld'