@@ -871,13 +871,31 @@ def build_lib(lib_id, target, toolchain_name, clean=False, macros=None,
871
871
# Let Exception propagate
872
872
raise
873
873
874
- # We do have unique legacy conventions about how we build and package the mbed
875
- # library
874
+
875
+ # A number of compiled files need to be copied as objects as the linker
876
+ # will not search for weak symbol overrides in archives. These are:
877
+ # - mbed_retarget.o: to make sure that the C standard lib symbols get
878
+ # overridden
879
+ # - mbed_board.o: `mbed_die` is weak
880
+ # - mbed_overrides.o: this contains platform overrides of various
881
+ # weak SDK functions
882
+ # - mbed_main.o: this contains main redirection
883
+ # - mbed_sdk_boot.o: this contains the main boot code in
884
+ # - PeripheralPins.o: PinMap can be weak
885
+ SEPARATE_NAMES = [
886
+ 'PeripheralPins.o' ,
887
+ 'mbed_retarget.o' ,
888
+ 'mbed_board.o' ,
889
+ 'mbed_overrides.o' ,
890
+ 'mbed_main.o' ,
891
+ 'mbed_sdk_boot.o' ,
892
+ ]
893
+
894
+
876
895
def build_mbed_libs (target , toolchain_name , clean = False , macros = None ,
877
896
notify = None , jobs = 1 , report = None , properties = None ,
878
897
build_profile = None , ignore = None ):
879
- """ Function returns True is library was built and false if building was
880
- skipped
898
+ """ Build legacy libraries for a target and toolchain pair
881
899
882
900
Positional arguments:
883
901
target - the MCU or board that the project will compile for
@@ -892,61 +910,64 @@ def build_mbed_libs(target, toolchain_name, clean=False, macros=None,
892
910
properties - UUUUHHHHH beats me
893
911
build_profile - a dict of flags that will be passed to the compiler
894
912
ignore - list of paths to add to mbedignore
913
+
914
+ Return - True if target + toolchain built correctly, False if not supported
895
915
"""
896
916
897
- if report != None :
917
+ if report is not None :
898
918
start = time ()
899
919
id_name = "MBED"
900
920
description = "mbed SDK"
901
921
vendor_label = target .extra_labels [0 ]
902
922
cur_result = None
903
923
prep_report (report , target .name , toolchain_name , id_name )
904
- cur_result = create_result (target .name , toolchain_name , id_name ,
905
- description )
906
-
907
- if properties != None :
908
- prep_properties (properties , target .name , toolchain_name ,
909
- vendor_label )
924
+ cur_result = create_result (
925
+ target .name , toolchain_name , id_name , description )
926
+ if properties is not None :
927
+ prep_properties (
928
+ properties , target .name , toolchain_name , vendor_label )
910
929
911
- # Check toolchain support
912
930
if toolchain_name not in target .supported_toolchains :
913
931
supported_toolchains_text = ", " .join (target .supported_toolchains )
914
- print ('%s target is not yet supported by toolchain %s' %
915
- (target .name , toolchain_name ))
916
- print ('%s target supports %s toolchain%s' %
917
- (target .name , supported_toolchains_text , 's'
918
- if len (target .supported_toolchains ) > 1 else '' ))
919
-
920
- if report != None :
932
+ notify .info ('The target {} does not support the toolchain {}' .format (
933
+ target .name ,
934
+ toolchain_name
935
+ ))
936
+ notify .info ('{} supports {} toolchain{}' .format (
937
+ target .name ,
938
+ supported_toolchains_text ,
939
+ 's' if len (target .supported_toolchains ) > 1 else ''
940
+ ))
941
+
942
+ if report is not None :
921
943
cur_result ["result" ] = "SKIP"
922
944
add_result_to_report (report , cur_result )
923
945
924
946
return False
925
947
926
948
try :
927
949
# Source and Build Paths
928
- build_target = join (MBED_LIBRARIES , "TARGET_" + target . name )
929
- build_toolchain = join ( MBED_LIBRARIES , mbed2_obj_path (target .name , toolchain_name ))
950
+ build_toolchain = join (
951
+ MBED_LIBRARIES , mbed2_obj_path (target .name , toolchain_name ))
930
952
mkdir (build_toolchain )
931
953
932
- # Toolchain
933
- tmp_path = join (MBED_LIBRARIES , '.temp' , mbed2_obj_path (target .name , toolchain_name ))
954
+ tmp_path = join (
955
+ MBED_LIBRARIES ,
956
+ '.temp' ,
957
+ mbed2_obj_path (target .name , toolchain_name )
958
+ )
934
959
mkdir (tmp_path )
935
960
961
+ # Toolchain and config
936
962
toolchain = prepare_toolchain (
937
963
["" ], tmp_path , target , toolchain_name , macros = macros , notify = notify ,
938
964
build_profile = build_profile , jobs = jobs , clean = clean , ignore = ignore )
939
965
940
- # Take into account the library configuration (MBED_CONFIG_FILE)
941
966
config = toolchain .config
942
967
config .add_config_files ([MBED_CONFIG_FILE ])
943
968
toolchain .set_config_data (toolchain .config .get_config_data ())
944
969
945
- # mbed
946
- notify .info ("Building library %s (%s, %s)" %
947
- ('MBED' , target .name , toolchain_name ))
948
-
949
- # Common Headers
970
+ # distribute header files
950
971
toolchain .copy_files ([MBED_HEADER ], MBED_LIBRARIES )
951
972
library_incdirs = [dirname (MBED_LIBRARIES ), MBED_LIBRARIES ]
952
973
@@ -957,76 +978,70 @@ def build_mbed_libs(target, toolchain_name, clean=False, macros=None,
957
978
toolchain .copy_files (resources .headers , dest )
958
979
library_incdirs .append (dest )
959
980
960
- cmsis_implementation = Resources (notify ).scan_with_toolchain ([MBED_CMSIS_PATH ], toolchain )
961
- toolchain .copy_files (cmsis_implementation .headers , build_target )
962
- toolchain .copy_files (cmsis_implementation .linker_script , build_toolchain )
963
- toolchain .copy_files (cmsis_implementation .bin_files , build_toolchain )
964
-
965
- hal_implementation = Resources (notify ).scan_with_toolchain ([MBED_TARGETS_PATH ], toolchain )
966
- toolchain .copy_files (hal_implementation .headers +
967
- hal_implementation .hex_files +
968
- hal_implementation .libraries +
969
- [MBED_CONFIG_FILE ],
970
- build_target , resources = hal_implementation )
971
- toolchain .copy_files (hal_implementation .linker_script , build_toolchain )
972
- toolchain .copy_files (hal_implementation .bin_files , build_toolchain )
973
- incdirs = Resources (notify ).scan_with_toolchain ([build_target ], toolchain ).inc_dirs
974
- objects = toolchain .compile_sources (cmsis_implementation + hal_implementation ,
975
- library_incdirs + incdirs + [tmp_path ])
976
- toolchain .copy_files (objects , build_toolchain )
977
-
978
- # Common Sources
981
+ # collect resources of the libs to compile
982
+ cmsis_res = Resources (notify ).scan_with_toolchain (
983
+ [MBED_CMSIS_PATH ], toolchain )
984
+ hal_res = Resources (notify ).scan_with_toolchain (
985
+ [MBED_TARGETS_PATH ], toolchain )
979
986
mbed_resources = Resources (notify ).scan_with_toolchain (
980
987
[MBED_DRIVERS , MBED_PLATFORM , MBED_HAL ], toolchain )
981
988
982
- objects = toolchain .compile_sources (mbed_resources ,
983
- library_incdirs + incdirs )
984
-
985
- # A number of compiled files need to be copied as objects as opposed to
986
- # way the linker search for symbols in archives. These are:
987
- # - mbed_retarget.o: to make sure that the C standard lib symbols get
988
- # overridden
989
- # - mbed_board.o: mbed_die is weak
990
- # - mbed_overrides.o: this contains platform overrides of various
991
- # weak SDK functions
992
- # - mbed_main.o: this contains main redirection
993
- # - PeripheralPins.o: PinMap can be weak
994
- separate_names , separate_objects = ['PeripheralPins.o' , 'mbed_retarget.o' , 'mbed_board.o' ,
995
- 'mbed_overrides.o' , 'mbed_main.o' , 'mbed_sdk_boot.o' ], []
989
+ incdirs = cmsis_res .inc_dirs + hal_res .inc_dirs + library_incdirs
990
+
991
+ # Build Things
992
+ notify .info ("Building library %s (%s, %s)" %
993
+ ('MBED' , target .name , toolchain_name ))
994
+ objects = toolchain .compile_sources (mbed_resources , incdirs )
995
+ separate_objects = []
996
996
997
997
for obj in objects :
998
- for name in separate_names :
998
+ for name in SEPARATE_NAMES :
999
999
if obj .endswith (name ):
1000
1000
separate_objects .append (obj )
1001
1001
1002
1002
for obj in separate_objects :
1003
1003
objects .remove (obj )
1004
1004
1005
1005
toolchain .build_library (objects , build_toolchain , "mbed" )
1006
-
1007
- for obj in separate_objects :
1008
- toolchain .copy_files (obj , build_toolchain )
1009
-
1010
- if report != None :
1006
+ notify .info ("Building library %s (%s, %s)" %
1007
+ ('CMSIS' , target .name , toolchain_name ))
1008
+ cmsis_objects = toolchain .compile_sources (cmsis_res , incdirs + [tmp_path ])
1009
+ notify .info ("Building library %s (%s, %s)" %
1010
+ ('HAL' , target .name , toolchain_name ))
1011
+ hal_objects = toolchain .compile_sources (hal_res , incdirs + [tmp_path ])
1012
+
1013
+ # Copy everything into the build directory
1014
+ to_copy = sum ([
1015
+ hal_res .headers ,
1016
+ hal_res .hex_files ,
1017
+ hal_res .bin_files ,
1018
+ hal_res .libraries ,
1019
+ cmsis_res .headers ,
1020
+ cmsis_res .bin_files ,
1021
+ [cmsis_res .linker_script , hal_res .linker_script , MBED_CONFIG_FILE ],
1022
+ cmsis_objects ,
1023
+ hal_objects ,
1024
+ separate_objects ,
1025
+ ], [])
1026
+ toolchain .copy_files (to_copy , build_toolchain )
1027
+
1028
+ if report is not None :
1011
1029
end = time ()
1012
1030
cur_result ["elapsed_time" ] = end - start
1013
1031
cur_result ["result" ] = "OK"
1014
-
1015
1032
add_result_to_report (report , cur_result )
1016
1033
1017
1034
return True
1018
1035
1019
1036
except Exception as exc :
1020
- if report != None :
1037
+ if report is not None :
1021
1038
end = time ()
1022
1039
cur_result ["result" ] = "FAIL"
1023
1040
cur_result ["elapsed_time" ] = end - start
1024
1041
1025
1042
cur_result ["output" ] += str (exc )
1026
1043
1027
1044
add_result_to_report (report , cur_result )
1028
-
1029
- # Let Exception propagate
1030
1045
raise
1031
1046
1032
1047
0 commit comments