@@ -652,16 +652,30 @@ def generate_project_ld_script(sdk_config, ignore_targets=None):
652652 '--objdump "{objdump}"'
653653 ).format (** args )
654654
655+ initial_ld_script = os .path .join (
656+ FRAMEWORK_DIR ,
657+ "components" ,
658+ "esp_system" ,
659+ "ld" ,
660+ idf_variant ,
661+ "sections.ld.in" ,
662+ )
663+
664+ if IDF5 :
665+ initial_ld_script = preprocess_linker_file (
666+ initial_ld_script ,
667+ os .path .join (
668+ BUILD_DIR ,
669+ "esp-idf" ,
670+ "esp_system" ,
671+ "ld" ,
672+ "sections.ld.in" ,
673+ )
674+ )
675+
655676 return env .Command (
656677 os .path .join ("$BUILD_DIR" , "sections.ld" ),
657- os .path .join (
658- FRAMEWORK_DIR ,
659- "components" ,
660- "esp_system" ,
661- "ld" ,
662- idf_variant ,
663- "sections.ld.in" ,
664- ),
678+ initial_ld_script ,
665679 env .VerboseAction (cmd , "Generating project linker script $TARGET" ),
666680 )
667681
@@ -752,8 +766,8 @@ def compile_source_files(
752766 obj_path = os .path .join (obj_path , os .path .basename (src_path ))
753767
754768 preserve_source_file_extension = board .get (
755- "build.esp-idf.preserve_source_file_extension" , True
756- )
769+ "build.esp-idf.preserve_source_file_extension" , "yes"
770+ ) == "yes"
757771
758772 objects .append (
759773 build_envs [compile_group_idx ].StaticObject (
@@ -999,12 +1013,38 @@ def find_default_component(target_configs):
9991013 env .Exit (1 )
10001014
10011015
1016+ def get_framework_version ():
1017+ def _extract_from_cmake_version_file ():
1018+ version_cmake_file = os .path .join (
1019+ FRAMEWORK_DIR , "tools" , "cmake" , "version.cmake"
1020+ )
1021+ if not os .path .isfile (version_cmake_file ):
1022+ return
1023+
1024+ with open (version_cmake_file , encoding = "utf8" ) as fp :
1025+ pattern = r"set\(IDF_VERSION_(MAJOR|MINOR|PATCH) (\d+)\)"
1026+ matches = re .findall (pattern , fp .read ())
1027+ if len (matches ) != 3 :
1028+ return
1029+ # If found all three parts of the version
1030+ return "." .join ([match [1 ] for match in matches ])
1031+
1032+ pkg = platform .get_package ("framework-espidf" )
1033+ version = get_original_version (str (pkg .metadata .version .truncate ()))
1034+ if not version :
1035+ # Fallback value extracted directly from the cmake version file
1036+ version = _extract_from_cmake_version_file ()
1037+ if not version :
1038+ version = "0.0.0"
1039+
1040+ return version
1041+
1042+
10021043def create_version_file ():
10031044 version_file = os .path .join (FRAMEWORK_DIR , "version.txt" )
10041045 if not os .path .isfile (version_file ):
10051046 with open (version_file , "w" ) as fp :
1006- package_version = platform .get_package_version ("framework-espidf" )
1007- fp .write (get_original_version (package_version ) or package_version )
1047+ fp .write (get_framework_version ())
10081048
10091049
10101050def generate_empty_partition_image (binary_path , image_size ):
@@ -1085,6 +1125,46 @@ def get_app_partition_offset(pt_table, pt_offset):
10851125 return app_params .get ("offset" , "0x10000" )
10861126
10871127
1128+ def preprocess_linker_file (src_ld_script , target_ld_script ):
1129+ return env .Command (
1130+ target_ld_script ,
1131+ src_ld_script ,
1132+ env .VerboseAction (
1133+ " " .join (
1134+ [
1135+ os .path .join (
1136+ platform .get_package_dir ("tool-cmake" ),
1137+ "bin" ,
1138+ "cmake" ,
1139+ ),
1140+ "-DCC=%s"
1141+ % os .path .join (
1142+ TOOLCHAIN_DIR ,
1143+ "bin" ,
1144+ "$CC" ,
1145+ ),
1146+ "-DSOURCE=$SOURCE" ,
1147+ "-DTARGET=$TARGET" ,
1148+ "-DCONFIG_DIR=%s" % os .path .join (BUILD_DIR , "config" ),
1149+ "-DLD_DIR=%s"
1150+ % os .path .join (
1151+ FRAMEWORK_DIR , "components" , "esp_system" , "ld"
1152+ ),
1153+ "-P" ,
1154+ os .path .join (
1155+ "$BUILD_DIR" ,
1156+ "esp-idf" ,
1157+ "esp_system" ,
1158+ "ld" ,
1159+ "linker_script_generator.cmake" ,
1160+ ),
1161+ ]
1162+ ),
1163+ "Generating LD script $TARGET" ,
1164+ ),
1165+ )
1166+
1167+
10881168def generate_mbedtls_bundle (sdk_config ):
10891169 bundle_path = os .path .join ("$BUILD_DIR" , "x509_crt_bundle" )
10901170 if os .path .isfile (env .subst (bundle_path )):
@@ -1236,7 +1316,7 @@ def get_idf_venv_dir():
12361316 # unnecessary reinstallation of Python dependencies in cases when Arduino
12371317 # as an IDF component requires a different version of the IDF package and
12381318 # hence a different set of Python deps or their versions
1239- idf_version = get_original_version ( platform . get_package_version ( "framework-espidf" ) )
1319+ idf_version = get_framework_version ( )
12401320 return os .path .join (
12411321 env .subst ("$PROJECT_CORE_DIR" ), "penv" , ".espidf-" + idf_version
12421322 )
@@ -1330,19 +1410,30 @@ def get_python_exe():
13301410#
13311411
13321412if not board .get ("build.ldscript" , "" ):
1333- linker_script = env .Command (
1334- os .path .join ("$BUILD_DIR" , "memory.ld" ),
1335- board .get (
1336- "build.esp-idf.ldscript" ,
1413+ initial_ld_script = board .get ("build.esp-idf.ldscript" , os .path .join (
1414+ FRAMEWORK_DIR ,
1415+ "components" ,
1416+ "esp_system" ,
1417+ "ld" ,
1418+ idf_variant ,
1419+ "memory.ld.in" ,
1420+ ))
1421+
1422+ if IDF5 :
1423+ initial_ld_script = preprocess_linker_file (
1424+ initial_ld_script ,
13371425 os .path .join (
1338- FRAMEWORK_DIR ,
1339- "components " ,
1426+ BUILD_DIR ,
1427+ "esp-idf " ,
13401428 "esp_system" ,
13411429 "ld" ,
1342- idf_variant ,
13431430 "memory.ld.in" ,
1344- ),
1345- ),
1431+ )
1432+ )
1433+
1434+ linker_script = env .Command (
1435+ os .path .join ("$BUILD_DIR" , "memory.ld" ),
1436+ initial_ld_script ,
13461437 env .VerboseAction (
13471438 '$CC -I"$BUILD_DIR/config" -I"%s" -C -P -x c -E $SOURCE -o $TARGET'
13481439 % os .path .join (FRAMEWORK_DIR , "components" , "esp_system" , "ld" ),
@@ -1504,7 +1595,9 @@ def get_python_exe():
15041595
15051596# Extra flags which need to be explicitly specified in LINKFLAGS section because SCons
15061597# cannot merge them correctly
1507- extra_flags = filter_args (link_args ["LINKFLAGS" ], ["-T" , "-u" ])
1598+ extra_flags = filter_args (
1599+ link_args ["LINKFLAGS" ], ["-T" , "-u" , "-Wl,--start-group" , "-Wl,--end-group" ]
1600+ )
15081601link_args ["LINKFLAGS" ] = sorted (list (set (link_args ["LINKFLAGS" ]) - set (extra_flags )))
15091602
15101603# remove the main linker script flags '-T memory.ld'
0 commit comments