-
Notifications
You must be signed in to change notification settings - Fork 0
/
binutils.TI_SimpleLink.cmake
383 lines (290 loc) · 15.4 KB
/
binutils.TI_SimpleLink.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
#
# Copyright (c) .NET Foundation and Contributors
# See LICENSE file in the project root for full license information.
#
include(FetchContent)
FetchContent_GetProperties(simplelinkcc13xx_26xxsdk)
FetchContent_GetProperties(ti_sysconfig)
FetchContent_GetProperties(ti_xdctools)
function(nf_set_optimization_options target)
target_compile_options(${target} PRIVATE
$<$<CONFIG:Debug>:-Og -femit-class-debug-always -g3 -ggdb>
$<$<CONFIG:Release>:-O3 -flto -fuse-linker-plugin -fno-fat-lto-objects>
$<$<CONFIG:MinSizeRel>:-Os -flto -fuse-linker-plugin -fno-fat-lto-objects>
$<$<CONFIG:RelWithDebInfo>:-Os -femit-class-debug-always -g3 -ggdb>
)
endfunction()
function(nf_set_linker_file target linker_file_name)
# set linker file name
set_target_properties(${target} PROPERTIES LINK_FLAGS "-Wl,-T${linker_file_name}")
endfunction()
# setting compile definitions for a target based on general build options
# TARGET parameter to set the target that's setting them for
# optional BUILD_TARGET when target it's a library pass here the name ot the target that's building for (either nanoBooter or nanoCLR)
# optional EXTRA_COMPILE_DEFINITIONS with compiler definitions to be added to the library
macro(nf_set_compile_definitions)
# parse arguments
cmake_parse_arguments(NFSCD "" "TARGET" "EXTRA_COMPILE_DEFINITIONS;BUILD_TARGET" ${ARGN})
if(NOT NFSCD_TARGET OR "${NFSCD_TARGET}" STREQUAL "")
message(FATAL_ERROR "Need to set TARGET argument when calling nf_set_compile_definitions()")
endif()
# definitions required for SimpleLink SDK
target_compile_definitions(${NFSCD_TARGET} PUBLIC -Dgcc)
nf_common_compiler_definitions(TARGET ${NFSCD_TARGET} BUILD_TARGET ${NFSCD_BUILD_TARGET})
# include extra compiler definitions
target_compile_definitions(${NFSCD_TARGET} PUBLIC ${NFSCD_EXTRA_COMPILE_DEFINITIONS})
endmacro()
# check valid frequency and if configuration file exists
function(nf_check_radio_frequency)
if(NOT DEFINED RADIO_FREQUENCY)
message(FATAL_ERROR "Radio frequncy NOT defined. Please set build option 'RADIO_FREQUENCY'. Valid values are 868 and 915.")
endif()
find_file(
SYS-CONFIG-FILE
*_${RADIO_FREQUENCY}.syscfg
PATHS
${TARGET_BASE_LOCATION}
)
# check if file was found
if(SYS-CONFIG-FILE-NOTFOUND)
message(FATAL_ERROR "Couldn't find a sysconfig file for radio frequency ${RADIO_FREQUENCY}. Valid values are 868 and 915.")
endif()
endfunction()
# Add packages that are common to TI SimpleLink platform builds
# To be called from target CMakeList.txt
# To be called from target CMakeList.txt
# optional TARGET argument with target name
macro(nf_add_platform_packages)
# parse arguments
cmake_parse_arguments(NFAPP "" "TARGET" "" ${ARGN})
find_package(TI_SimpleLink REQUIRED QUIET)
# packages specific for nanoBooter
if("${NFAPP_TARGET}" STREQUAL "${NANOBOOTER_PROJECT_NAME}")
# no packages for booter
endif()
# packages specific for nanoCLR
if("${NFAPP_TARGET}" STREQUAL "${NANOCLR_PROJECT_NAME}")
# no packages for nanoCLR
endif()
endmacro()
# Add TI SimpleLink platform dependencies to a specific CMake target
# To be called from target CMakeList.txt
macro(nf_add_platform_dependencies target)
nf_add_common_dependencies(${target})
# dependencies specific to nanoCLR
if("${target}" STREQUAL "${NANOCLR_PROJECT_NAME}")
nf_add_lib_coreclr(
EXTRA_COMPILE_DEFINITIONS
${NFSTBC_CLR_EXTRA_COMPILE_DEFINITIONS}
EXTRA_INCLUDES
${TI_SimpleLink_INCLUDE_DIRS}
${TI_XDCTools_INCLUDE_DIR}
${TARGET_TI_SimpleLink_COMMON_INCLUDE_DIRS}
${TARGET_TI_SimpleLink_NANOCLR_INCLUDE_DIRS})
add_dependencies(${target}.elf nano::NF_CoreCLR)
nf_add_lib_wireprotocol(
EXTRA_INCLUDES
${TI_SimpleLink_INCLUDE_DIRS}
${TI_XDCTools_INCLUDE_DIR}
${TARGET_TI_SimpleLink_COMMON_INCLUDE_DIRS}
${TARGET_TI_SimpleLink_NANOCLR_INCLUDE_DIRS})
add_dependencies(${target}.elf nano::WireProtocol)
if(NF_FEATURE_DEBUGGER)
nf_add_lib_debugger(
EXTRA_COMPILE_DEFINITIONS
${NFSTBC_CLR_EXTRA_COMPILE_DEFINITIONS}
EXTRA_INCLUDES
${TI_SimpleLink_INCLUDE_DIRS}
${TI_XDCTools_INCLUDE_DIR}
${TARGET_TI_SimpleLink_COMMON_INCLUDE_DIRS}
${TARGET_TI_SimpleLink_NANOCLR_INCLUDE_DIRS})
add_dependencies(${target}.elf nano::NF_Debugger)
endif()
nf_add_lib_native_assemblies(
EXTRA_INCLUDES
${CMAKE_CURRENT_BINARY_DIR}/syscfg
${TI_SimpleLink_INCLUDE_DIRS}
${TI_XDCTools_INCLUDE_DIR}
${TARGET_TI_SimpleLink_COMMON_INCLUDE_DIRS}
${TARGET_TI_SimpleLink_NANOCLR_INCLUDE_DIRS})
# add dependency from SysConfig and TI RTOS configs (this is required to make sure that the intermediate artifacts are generated in the proper order)
add_dependencies(COPY_TIRTOS_CONFIG SYSCONFIG_TASKS)
add_dependencies(TIRTOS_CONFIG COPY_TIRTOS_CONFIG)
add_dependencies(NF_NativeAssemblies TIRTOS_CONFIG)
add_dependencies(${target}.elf nano::NF_NativeAssemblies)
# nF feature: networking
if(USE_NETWORKING_OPTION)
nf_add_lib_network(
BUILD_TARGET
${target}
EXTRA_INCLUDES
${TI_SimpleLink_INCLUDE_DIRS}
${TI_XDCTools_INCLUDE_DIR}
${TARGET_TI_SimpleLink_COMMON_INCLUDE_DIRS}
${TARGET_TI_SimpleLink_NANOCLR_INCLUDE_DIRS})
add_dependencies(${target}.elf nano::NF_Network)
endif()
endif()
endmacro()
# Add TI SimpleLink platform include directories to a specific CMake target
# To be called from target CMakeList.txt
macro(nf_add_platform_include_directories target)
target_include_directories(${target}.elf PUBLIC
${TI_SimpleLink_INCLUDE_DIRS}
${TI_XDCTools_INCLUDE_DIR}
${CMAKE_CURRENT_BINARY_DIR}/syscfg
${TARGET_TI_SimpleLink_COMMON_INCLUDE_DIRS}
${TARGET_TI_SimpleLink_NANOCLR_INCLUDE_DIRS}
)
endmacro()
# Add TI SimpleLink platform target sources to a specific CMake target
# To be called from target CMakeList.txt
macro(nf_add_platform_sources target)
# add header files with common OS definitions and board definitions specific for each image
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/nanoCLR/target_board.h.in
${CMAKE_BINARY_DIR}/targets/${RTOS}/${TARGET_BOARD}/nanoCLR/target_board.h @ONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/target_common.h.in
${CMAKE_BINARY_DIR}/targets/${RTOS}/${TARGET_BOARD}/target_common.h @ONLY)
# sources specific to nanoCLR
if(${target} STREQUAL ${NANOCLR_PROJECT_NAME})
target_sources(${target}.elf PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/target_Power.c
${TARGET_TI_SimpleLink_COMMON_SOURCES}
${TARGET_TI_SimpleLink_NANOCLR_SOURCES}
${TARGET_TI_SimpleLink_SOURCES}
${CMAKE_CURRENT_BINARY_DIR}/syscfg/ti_devices_config.c
${CMAKE_CURRENT_BINARY_DIR}/syscfg/ti_drivers_config.c
${CMAKE_CURRENT_BINARY_DIR}/syscfg/ti_easylink_config.c
${CMAKE_CURRENT_BINARY_DIR}/syscfg/ti_radio_config.c
)
endif()
endmacro()
# Add TI SimpleLink sys config steps
# To be called from target CMakeList.txt
macro(nf_add_platform_sysconfig_steps ti_device ti_device_family)
# setup target to take care of generating SimpleLink SysConfig files
add_custom_target(SYSCONFIG_TASKS ALL)
set(TI_DEVICE_FAMILIES_WITH_RADIO_FREQUENCY "CC13X2")
list(FIND TI_DEVICE_FAMILIES_WITH_RADIO_FREQUENCY ${TARGET_SERIES} TI_DEVICE_FAMILY_NAME_INDEX)
string(TOLOWER ${ti_device_family} TI_DEVICE_FAMILY_LOWER_CASE)
if(TI_DEVICE_FAMILY_NAME_INDEX EQUAL -1)
# this target series doesn't have/support/care radio frequency option
# compose sys config file name
set(SYS_CONFIG_FILENAME ${TARGET_BOARD}.syscfg)
else()
# check for valid frequency setting
nf_check_radio_frequency()
# compose sys config file name
set(SYS_CONFIG_FILENAME ${TARGET_BOARD}_${RADIO_FREQUENCY}.syscfg)
endif()
# copy Sys Config file to build directory
add_custom_command(
TARGET
SYSCONFIG_TASKS PRE_BUILD
BYPRODUCTS
${CMAKE_CURRENT_BINARY_DIR}/${SYS_CONFIG_FILENAME}
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/${SYS_CONFIG_FILENAME}
${CMAKE_CURRENT_BINARY_DIR}/${SYS_CONFIG_FILENAME}
COMMENT "Copy TI-RTOS configuration file to build directory"
)
# execute Sys Config with configuration file
if(CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
add_custom_command(
TARGET
SYSCONFIG_TASKS PRE_BUILD
BYPRODUCTS
${CMAKE_CURRENT_BINARY_DIR}/syscfg/ti_devices_config.c
${CMAKE_CURRENT_BINARY_DIR}/syscfg/ti_drivers_config.c
${CMAKE_CURRENT_BINARY_DIR}/syscfg/ti_easylink_config.c
${CMAKE_CURRENT_BINARY_DIR}/syscfg/ti_radio_config.c
COMMAND ${ti_sysconfig_SOURCE_DIR}/sysconfig_cli.bat -s "${simplelinkcc13xx_26xxsdk_SOURCE_DIR}/.metadata/product.json" --script ${SYS_CONFIG_FILENAME} -o "syscfg" --compiler gcc
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generate configuration files"
)
else()
add_custom_command(
TARGET
SYSCONFIG_TASKS PRE_BUILD
BYPRODUCTS
${CMAKE_CURRENT_BINARY_DIR}/syscfg/ti_devices_config.c
${CMAKE_CURRENT_BINARY_DIR}/syscfg/ti_drivers_config.c
${CMAKE_CURRENT_BINARY_DIR}/syscfg/ti_easylink_config.c
${CMAKE_CURRENT_BINARY_DIR}/syscfg/ti_radio_config.c
COMMAND ${ti_sysconfig_SOURCE_DIR}/sysconfig_cli.sh -s "${simplelinkcc13xx_26xxsdk_SOURCE_DIR}/.metadata/product.json" --script ${SYS_CONFIG_FILENAME} -o "syscfg" --compiler gcc
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generate configuration files"
)
endif()
######################################
# need to copy the configuration file to the build directory
# because the obj files resulting from TI-RTOS build are placed in the same directory as the configuration file
if(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES RelWithDebInfo)
set(TI_RTOS_CONFIG_FILE ti-rtos-debug.cfg)
else()
set(TI_RTOS_CONFIG_FILE ti-rtos-release.cfg)
endif()
# need to use a specific target because target dependency PRE_BUILT doesn't work on NINJA build files
add_custom_target(
COPY_TIRTOS_CONFIG
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/${TI_RTOS_CONFIG_FILE}
${CMAKE_CURRENT_BINARY_DIR}/${TI_RTOS_CONFIG_FILE}
COMMENT "Copy TI-RTOS configuration file to build directory"
)
if(CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
add_custom_target(
TIRTOS_CONFIG
COMMAND ${ti_xdctools_SOURCE_DIR}/xs.exe --xdcpath="${simplelinkcc13xx_26xxsdk_SOURCE_DIR}/source\;${simplelinkcc13xx_26xxsdk_SOURCE_DIR}/kernel/tirtos/packages" xdc.tools.configuro -o configPkg -t gnu.targets.arm.M4F -p ti.platforms.simplelink:${ti_device} -r release -c "${TOOLCHAIN_PREFIX}" --compileOptions " -DDeviceFamily_${ti_device_family} " "${CMAKE_CURRENT_BINARY_DIR}/${TI_RTOS_CONFIG_FILE}"
COMMENT "Generate TI-RTOS configuration"
)
else()
add_custom_target(
TIRTOS_CONFIG
COMMAND ${ti_xdctools_SOURCE_DIR}/xs --xdcpath="${simplelinkcc13xx_26xxsdk_SOURCE_DIR}/source\;${simplelinkcc13xx_26xxsdk_SOURCE_DIR}/kernel/tirtos/packages" xdc.tools.configuro -o configPkg -t gnu.targets.arm.M4F -p ti.platforms.simplelink:${ti_device} -r release -c "${TOOLCHAIN_PREFIX}" --compileOptions " -DDeviceFamily_${ti_device_family} " "${CMAKE_CURRENT_BINARY_DIR}/${TI_RTOS_CONFIG_FILE}"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generate TI-RTOS configuration"
)
endif()
endmacro()
# macro to setup the build for a target
# mandatory HAS_NANOBOOTER specifing if the target implements nanoBooter
# BOOTER_LINKER_FILE with the path to the linker file for nanoBooter (if the target has it)
# mandatory CLR_LINKER_FILE with the path to the linker file for nanoCLR
# optional BOOTER_EXTRA_SOURCE_FILES with paths to extra files to be added to the nanoBooter build target
# optional CLR_EXTRA_SOURCE_FILES with paths to extra files to be added to the nanoCLR build target
# optional BOOTER_EXTRA_COMPILE_DEFINITIONS extra nanoBooter compile definitions to pass to nf_set_compile_definitions()
# optional CLR_EXTRA_COMPILE_DEFINITIONS extra nanoCLR compile definitions to pass to nf_set_compile_definitions()
# optional BOOTER_EXTRA_LINKMAP_PROPERTIES extra nanoBooter link map properties to pass to nf_set_link_map()
# optional CLR_EXTRA_LINKMAP_PROPERTIES extra nanoCLR link map properties to pass to nf_set_link_map()
# optional BOOTER_EXTRA_LINK_FLAGS extra nanoBooter link flags to pass to nf_set_link_options()
# optional CLR_EXTRA_LINK_FLAGS extra nanoCLR link flags to pass to nf_set_link_options()
macro(nf_setup_target_build)
# add extra libraries for SimpleLink
set(CLR_EXTRA_LIBRARIES
${simplelinkcc13xx_26xxsdk_SOURCE_DIR}/source/ti/display/lib/gcc/m4f/display_${TI_DEVICE_FAMILY_LOWER_CASE}.a
${simplelinkcc13xx_26xxsdk_SOURCE_DIR}/source/ti/grlib/lib/gcc/m4f/grlib.a
${simplelinkcc13xx_26xxsdk_SOURCE_DIR}/source/ti/drivers/rf/lib/gcc/m4f/rf_multiMode_${TI_DEVICE_FAMILY_LOWER_CASE}.a
${simplelinkcc13xx_26xxsdk_SOURCE_DIR}/source/ti/drivers/lib/gcc/m4f/drivers_${TI_DEVICE_FAMILY_LOWER_CASE}.a
${simplelinkcc13xx_26xxsdk_SOURCE_DIR}/source/ti/devices/cc13x2_cc26x2/driverlib/bin/gcc/driverlib.lib
${simplelinkcc13xx_26xxsdk_SOURCE_DIR}/kernel/tirtos/packages/ti/dpl/lib/gcc/m4f/dpl_${TI_DEVICE_FAMILY_LOWER_CASE}.a
${simplelinkcc13xx_26xxsdk_SOURCE_DIR}/kernel/tirtos/packages/gnu/targets/arm/libs/install-native/arm-none-eabi/lib/thumb/v7e-m/hard/libm.a
${simplelinkcc13xx_26xxsdk_SOURCE_DIR}/kernel/tirtos/packages/gnu/targets/arm/libs/install-native/arm-none-eabi/lib/thumb/v7e-m/hard/libnosys.a
)
# add these to the ARGN list
list(APPEND ARGN CLR_EXTRA_LIBRARIES ${CLR_EXTRA_LIBRARIES})
# OK to pass ARGN, to have it perform it's parsings and validation
nf_setup_target_build_common(${ARGN})
endmacro()
# macro to clear binary files related with nanoBooter from output
# to make sure that the build file it's up to date
macro(nf_clear_output_files_nanobooter)
nf_clear_common_output_files_nanobooter()
# other files specific to this platform should go here
endmacro()
# macro to clear binary files related with nanoCLR from output
# to make sure that the build file it's up to date
macro(nf_clear_output_files_nanoclr)
nf_clear_common_output_files_nanoclr()
# other files specific to this platform should go here
endmacro()