Skip to content

Commit

Permalink
Update IDF script
Browse files Browse the repository at this point in the history
  • Loading branch information
valeros committed Jul 29, 2024
1 parent 3ef6a7a commit b3ef03f
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 20 deletions.
99 changes: 82 additions & 17 deletions builder/frameworks/espidf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
)

Expand Down Expand Up @@ -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)):
Expand Down Expand Up @@ -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"),
Expand Down
12 changes: 9 additions & 3 deletions builder/frameworks/ulp.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import os
import sys

from platformio import fs
from platformio.util import get_systype
Expand Down Expand Up @@ -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"))
]
Expand Down Expand Up @@ -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)),
Expand All @@ -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()
Expand Down

0 comments on commit b3ef03f

Please sign in to comment.