@@ -652,16 +652,30 @@ def generate_project_ld_script(sdk_config, ignore_targets=None):
652
652
'--objdump "{objdump}"'
653
653
).format (** args )
654
654
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
+
655
676
return env .Command (
656
677
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 ,
665
679
env .VerboseAction (cmd , "Generating project linker script $TARGET" ),
666
680
)
667
681
@@ -752,8 +766,8 @@ def compile_source_files(
752
766
obj_path = os .path .join (obj_path , os .path .basename (src_path ))
753
767
754
768
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"
757
771
758
772
objects .append (
759
773
build_envs [compile_group_idx ].StaticObject (
@@ -999,12 +1013,38 @@ def find_default_component(target_configs):
999
1013
env .Exit (1 )
1000
1014
1001
1015
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
+
1002
1043
def create_version_file ():
1003
1044
version_file = os .path .join (FRAMEWORK_DIR , "version.txt" )
1004
1045
if not os .path .isfile (version_file ):
1005
1046
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 ())
1008
1048
1009
1049
1010
1050
def generate_empty_partition_image (binary_path , image_size ):
@@ -1085,6 +1125,46 @@ def get_app_partition_offset(pt_table, pt_offset):
1085
1125
return app_params .get ("offset" , "0x10000" )
1086
1126
1087
1127
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
+
1088
1168
def generate_mbedtls_bundle (sdk_config ):
1089
1169
bundle_path = os .path .join ("$BUILD_DIR" , "x509_crt_bundle" )
1090
1170
if os .path .isfile (env .subst (bundle_path )):
@@ -1236,7 +1316,7 @@ def get_idf_venv_dir():
1236
1316
# unnecessary reinstallation of Python dependencies in cases when Arduino
1237
1317
# as an IDF component requires a different version of the IDF package and
1238
1318
# 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 ( )
1240
1320
return os .path .join (
1241
1321
env .subst ("$PROJECT_CORE_DIR" ), "penv" , ".espidf-" + idf_version
1242
1322
)
@@ -1330,19 +1410,30 @@ def get_python_exe():
1330
1410
#
1331
1411
1332
1412
if 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 ,
1337
1425
os .path .join (
1338
- FRAMEWORK_DIR ,
1339
- "components " ,
1426
+ BUILD_DIR ,
1427
+ "esp-idf " ,
1340
1428
"esp_system" ,
1341
1429
"ld" ,
1342
- idf_variant ,
1343
1430
"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 ,
1346
1437
env .VerboseAction (
1347
1438
'$CC -I"$BUILD_DIR/config" -I"%s" -C -P -x c -E $SOURCE -o $TARGET'
1348
1439
% os .path .join (FRAMEWORK_DIR , "components" , "esp_system" , "ld" ),
@@ -1504,7 +1595,9 @@ def get_python_exe():
1504
1595
1505
1596
# Extra flags which need to be explicitly specified in LINKFLAGS section because SCons
1506
1597
# 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
+ )
1508
1601
link_args ["LINKFLAGS" ] = sorted (list (set (link_args ["LINKFLAGS" ]) - set (extra_flags )))
1509
1602
1510
1603
# remove the main linker script flags '-T memory.ld'
0 commit comments