59
59
)
60
60
)
61
61
62
- # Legacy toolchains for mixed IDF/Arduino projects
63
- if "arduino" in env .subst ("$PIOFRAMEWORK" ):
64
- TOOLCHAIN_DIR = platform .get_package_dir ("toolchain-xtensa32" )
65
-
66
62
assert os .path .isdir (FRAMEWORK_DIR )
67
63
assert os .path .isdir (TOOLCHAIN_DIR )
68
64
69
- # Arduino framework as a component is not compatible with ESP-IDF >=4.1
70
65
if "arduino" in env .subst ("$PIOFRAMEWORK" ):
71
66
ARDUINO_FRAMEWORK_DIR = platform .get_package_dir ("framework-arduinoespressif32" )
72
67
# Possible package names in 'package@version' format is not compatible with CMake
@@ -341,7 +336,7 @@ def _add_archive(archive_path, link_args):
341
336
if fragment .startswith ("-l" ):
342
337
link_args ["LIBS" ].extend (args )
343
338
elif fragment .startswith ("-L" ):
344
- lib_path = fragment .replace ("-L" , "" ).strip ()
339
+ lib_path = fragment .replace ("-L" , "" ).strip (). strip ( '"' )
345
340
_add_to_libpath (lib_path , link_args )
346
341
elif fragment .startswith ("-" ) and not fragment .startswith ("-l" ):
347
342
# CMake mistakenly marks LINKFLAGS as libraries
@@ -455,17 +450,23 @@ def find_framework_service_files(search_path, sdk_config):
455
450
os .path .join (
456
451
FRAMEWORK_DIR ,
457
452
"components" ,
458
- idf_variant ,
459
- "ld" ,
460
- "%s_fragments.lf" % idf_variant ,
461
- ),
453
+ "esp_common" ,
454
+ "common.lf" ),
455
+
462
456
os .path .join (
463
457
FRAMEWORK_DIR ,
464
458
"components" ,
465
- idf_variant ,
466
- "linker.lf" ,
467
- ),
459
+ "esp_common" ,
460
+ "soc.lf" ),
461
+
462
+ os .path .join (
463
+ FRAMEWORK_DIR ,
464
+ "components" ,
465
+ "esp_system" ,
466
+ "app.lf" ),
467
+
468
468
os .path .join (FRAMEWORK_DIR , "components" , "newlib" , "newlib.lf" ),
469
+ os .path .join (FRAMEWORK_DIR , "components" , "newlib" , "system_libs.lf" ),
469
470
]
470
471
)
471
472
@@ -515,14 +516,63 @@ def generate_project_ld_script(sdk_config, ignore_targets=None):
515
516
libraries_list = create_custom_libraries_list (
516
517
os .path .join (BUILD_DIR , "ldgen_libraries" ), ignore_targets
517
518
)
519
+ # Rework the memory template linker script, following components/esp_system/ld.cmake
520
+ args = {
521
+ "preprocess" : os .path .join (
522
+ TOOLCHAIN_DIR ,
523
+ "bin" ,
524
+ env .subst ("$CC" )),
525
+ "ld_output" : os .path .join ("$BUILD_DIR" , "memory.ld" ),
526
+ "ld_dir" : os .path .join (FRAMEWORK_DIR ,
527
+ "components" ,
528
+ "esp_system" ,
529
+ "ld" ),
530
+ "ld_input" : os .path .join (
531
+ FRAMEWORK_DIR ,
532
+ "components" ,
533
+ "esp_system" ,
534
+ "ld" ,
535
+ idf_variant ,
536
+ "memory.ld.in" ,
537
+ ),
538
+ "project_output" : os .path .join ("$BUILD_DIR" , "%s.project.ld" % idf_variant ),
539
+ "config" : os .path .join ("$BUILD_DIR" , "config" ),
540
+ "flags" : '-C -P -x c -E -o '
541
+ }
542
+
543
+ cmd = (
544
+ '"{preprocess}" {flags} "{ld_output}" -I "{config}" -I "{ld_dir}" "{ld_input}"'
545
+ ).format (** args )
546
+
547
+ env .Command (
548
+ os .path .join ("$BUILD_DIR" , "memory.ld" ),
549
+ os .path .join (
550
+ FRAMEWORK_DIR ,
551
+ "components" ,
552
+ "esp_system" ,
553
+ "ld" ,
554
+ idf_variant ,
555
+ "memory.ld.in" ,
556
+ ),
557
+ env .VerboseAction (cmd , "Generating memory linker script $TARGET" ),
558
+ )
518
559
519
560
args = {
520
561
"script" : os .path .join (FRAMEWORK_DIR , "tools" , "ldgen" , "ldgen.py" ),
521
562
"config" : SDKCONFIG_PATH ,
522
- "fragments" : " " .join (['"%s"' % f for f in project_files .get ("lf_files" )]),
563
+ "fragments" : " " .join (['"%s"' % f for f in project_files .get ("lf_files" )]),
564
+ # "fragments": "".join(['%s;' % f for f in project_files.get("lf_files")]).strip(';'),
523
565
"kconfig" : os .path .join (FRAMEWORK_DIR , "Kconfig" ),
524
566
"env_file" : os .path .join ("$BUILD_DIR" , "config.env" ),
525
567
"libraries_list" : libraries_list ,
568
+ "section_input" : os .path .join (
569
+ FRAMEWORK_DIR ,
570
+ "components" ,
571
+ "esp_system" ,
572
+ "ld" ,
573
+ idf_variant ,
574
+ "sections.ld.in" ,
575
+ ),
526
576
"objdump" : os .path .join (
527
577
TOOLCHAIN_DIR ,
528
578
"bin" ,
@@ -539,13 +589,14 @@ def generate_project_ld_script(sdk_config, ignore_targets=None):
539
589
).format (** args )
540
590
541
591
return env .Command (
542
- os .path .join ("$BUILD_DIR" , "%s.project. ld" % idf_variant ),
592
+ os .path .join ("$BUILD_DIR" , "sections. ld" ),
543
593
os .path .join (
544
594
FRAMEWORK_DIR ,
545
595
"components" ,
546
- idf_variant ,
596
+ "esp_system" ,
547
597
"ld" ,
548
- "%s.project.ld.in" % idf_variant ,
598
+ idf_variant ,
599
+ "sections.ld.in" ,
549
600
),
550
601
env .VerboseAction (cmd , "Generating project linker script $TARGET" ),
551
602
)
@@ -703,6 +754,20 @@ def find_lib_deps(components_map, elf_config, link_args, ignore_components=None)
703
754
704
755
return result
705
756
757
+ def fix_ld_paths (extra_flags ):
758
+ peripheral_framework_path = os .path .join (FRAMEWORK_DIR , "components" , "soc" , idf_variant , "ld" )
759
+ rom_framework_path = os .path .join (FRAMEWORK_DIR , "components" , "esp_rom" , idf_variant , "ld" )
760
+ bl_framework_path = os .path .join (FRAMEWORK_DIR , "components" , "bootloader" , "subproject" , "main" , "ld" , idf_variant )
761
+
762
+ # ESP linker scripts changed path in ESP-IDF 4.4+, so add missing paths to linker's search path
763
+ try :
764
+ ld_index = extra_flags .index ("%s.peripherals.ld" % idf_variant )
765
+ extra_flags [ld_index - 1 :ld_index - 1 ] = [ "-L" , peripheral_framework_path , "-L" , rom_framework_path , "-L" , bl_framework_path ]
766
+ except :
767
+ print ("Error while parsing the flags" )
768
+
769
+ return extra_flags
770
+
706
771
707
772
def build_bootloader ():
708
773
bootloader_src_dir = os .path .join (
@@ -747,6 +812,7 @@ def build_bootloader():
747
812
build_components (bootloader_env , components_map , bootloader_src_dir , "bootloader" )
748
813
link_args = extract_link_args (elf_config )
749
814
extra_flags = filter_args (link_args ["LINKFLAGS" ], ["-T" , "-u" ])
815
+ extra_flags = fix_ld_paths (extra_flags )
750
816
link_args ["LINKFLAGS" ] = sorted (
751
817
list (set (link_args ["LINKFLAGS" ]) - set (extra_flags ))
752
818
)
@@ -1061,21 +1127,23 @@ def _get_installed_pip_packages():
1061
1127
1062
1128
if not board .get ("build.ldscript" , "" ):
1063
1129
linker_script = env .Command (
1064
- os .path .join ("$BUILD_DIR" , "%s_out .ld" % idf_variant ),
1130
+ os .path .join ("$BUILD_DIR" , "memory .ld" ),
1065
1131
board .get (
1066
1132
"build.esp-idf.ldscript" ,
1067
1133
os .path .join (
1068
- FRAMEWORK_DIR , "components" , idf_variant , "ld" , "%s .ld" % idf_variant
1134
+ FRAMEWORK_DIR , "components" , "esp_system" , "ld" , idf_variant , "memory .ld.in"
1069
1135
),
1070
1136
),
1071
1137
env .VerboseAction (
1072
- '$CC -I"$BUILD_DIR/config" -C -P -x c -E $SOURCE -o $TARGET' ,
1138
+ '$CC -I"$BUILD_DIR/config" -I"' +
1139
+ os .path .join (FRAMEWORK_DIR , "components" , "esp_system" , "ld" ) +
1140
+ '" -C -P -x c -E $SOURCE -o $TARGET' ,
1073
1141
"Generating LD script $TARGET" ,
1074
1142
),
1075
1143
)
1076
1144
1077
1145
env .Depends ("$BUILD_DIR/$PROGNAME$PROGSUFFIX" , linker_script )
1078
- env .Replace (LDSCRIPT_PATH = "%s_out .ld" % idf_variant )
1146
+ env .Replace (LDSCRIPT_PATH = "memory .ld" )
1079
1147
1080
1148
#
1081
1149
# Generate partition table
@@ -1257,13 +1325,15 @@ def _get_installed_pip_packages():
1257
1325
# Extra flags which need to be explicitly specified in LINKFLAGS section because SCons
1258
1326
# cannot merge them correctly
1259
1327
extra_flags = filter_args (link_args ["LINKFLAGS" ], ["-T" , "-u" ])
1328
+ extra_flags = fix_ld_paths (extra_flags )
1260
1329
link_args ["LINKFLAGS" ] = sorted (list (set (link_args ["LINKFLAGS" ]) - set (extra_flags )))
1261
1330
1262
- # remove the main linker script flags '-T esp32_out .ld'
1331
+ # remove the main linker script flags '-T memory .ld' since it already appears later on
1263
1332
try :
1264
- ld_index = extra_flags .index ("%s_out .ld" % idf_variant )
1333
+ ld_index = extra_flags .index ("memory .ld" )
1265
1334
extra_flags .pop (ld_index )
1266
1335
extra_flags .pop (ld_index - 1 )
1336
+ pass
1267
1337
except :
1268
1338
print ("Warning! Couldn't find the main linker script in the CMake code model." )
1269
1339
0 commit comments