@@ -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
@@ -1111,6 +1125,46 @@ def get_app_partition_offset(pt_table, pt_offset):
1111
1125
return app_params .get ("offset" , "0x10000" )
1112
1126
1113
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
+
1114
1168
def generate_mbedtls_bundle (sdk_config ):
1115
1169
bundle_path = os .path .join ("$BUILD_DIR" , "x509_crt_bundle" )
1116
1170
if os .path .isfile (env .subst (bundle_path )):
@@ -1356,19 +1410,30 @@ def get_python_exe():
1356
1410
#
1357
1411
1358
1412
if not board .get ("build.ldscript" , "" ):
1359
- linker_script = env .Command (
1360
- os .path .join ("$BUILD_DIR" , "memory.ld" ),
1361
- board .get (
1362
- "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 ,
1363
1425
os .path .join (
1364
- FRAMEWORK_DIR ,
1365
- "components " ,
1426
+ BUILD_DIR ,
1427
+ "esp-idf " ,
1366
1428
"esp_system" ,
1367
1429
"ld" ,
1368
- idf_variant ,
1369
1430
"memory.ld.in" ,
1370
- ),
1371
- ),
1431
+ )
1432
+ )
1433
+
1434
+ linker_script = env .Command (
1435
+ os .path .join ("$BUILD_DIR" , "memory.ld" ),
1436
+ initial_ld_script ,
1372
1437
env .VerboseAction (
1373
1438
'$CC -I"$BUILD_DIR/config" -I"%s" -C -P -x c -E $SOURCE -o $TARGET'
1374
1439
% os .path .join (FRAMEWORK_DIR , "components" , "esp_system" , "ld" ),
0 commit comments