-
Notifications
You must be signed in to change notification settings - Fork 270
/
CMakeLists.txt
367 lines (276 loc) · 7.91 KB
/
CMakeLists.txt
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
###| CMAKE Kiibohd Controller Bootloader |###
#
# Jacob Alexander 2011-2018
# Due to this file's usefulness:
#
# Released into the Public Domain
#
# This bootloader is based upon the MCHCK dfu-usb bootloader.
# DO NOT USE with Teensy based microcontrollers.
#
###
###
# Chip Selection
#
#| You _MUST_ set this to match the microcontroller you are trying to compile for
#| You _MUST_ clean the build directory if you change this value
#|
set ( CHIP
"mk20dx128vlf5" # McHCK mk20dx128vlf5
# "mk20dx256vlh7" # Kiibohd-dfu mk20dx256vlh7
# "sam4s8c" # Sam
CACHE STRING "Chip"
)
if ( "${CHIP}" MATCHES "^mk2.*$" )
set( FAMILY "kinetis" )
elseif ( "${CHIP}" MATCHES "^sam.*$" )
set( FAMILY "sam" )
else ( )
message( FATAL_ERROR "Unknown chip ${CHIP}" )
endif ( )
###
# Compiler Selection
#
#| *** EXPERIMENTAL ***
#| Stick with gcc unless you know what you're doing
#| Currently only arm is supported with clang
set ( COMPILER
"gcc" # arm-none-eabi-gcc / avr-gcc - Default
# "clang" # arm-none-eabi
CACHE STRING "Compiler Type"
)
###
# Product String
#
set ( BOOT_PRODUCT_STR
"Kiibohd DFU Bootloader"
CACHE STRING "Product String"
)
###
# Flashing Station ID
#
set ( FLASHING_STATION_ID
"xXXx"
CACHE STRING "Placeholder string for flashing station"
)
###
# Bootloader Configuration
#
set ( BOOTLOADER 1 )
###
# Debug
#
# Use a JLink programmer (no bootloader required)
set( JLINK
1
CACHE STRING "Enable JLINK Programming/Debugging"
)
#| swd or jtag
set( JLINK_INTERFACE
"swd"
CACHE STRING "JLink Interface"
)
#| Speed in kHz or auto
set( JLINK_SPEED
"auto"
CACHE STRING "JLink Speed"
)
###
# Compiler Intialization
#
set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/../Lib/CMake )
include ( initialize )
##
# Source Defines
#
if ( FAMILY STREQUAL "kinetis" )
set ( SRCS
main.c
debug.c
dfu.c
dfu.desc.c
flash.c
usb.c
${FAMILY}.c
Devices/${CHIP}.c
)
elseif ( FAMILY STREQUAL "sam" )
set ( SRCS
../Lib/ASF/common/services/clock/sam4s/sysclk.c
../Lib/ASF/common/services/isp/flip/sam/isp.c
../Lib/ASF/common/services/usb/class/dfu_flip/device/udi_dfu_atmel.c
../Lib/ASF/common/services/usb/class/dfu_flip/device/udi_dfu_atmel_desc.c
../Lib/ASF/common/services/usb/udc/udc.c
../Lib/ASF/common/utils/interrupt/interrupt_sam_nvic.c
../Lib/ASF/sam/drivers/adc/adc.c
../Lib/ASF/sam/drivers/efc/efc.c
../Lib/ASF/sam/drivers/matrix/matrix.c
../Lib/ASF/sam/drivers/pmc/pmc.c
../Lib/ASF/sam/drivers/udp/udp_device.c
../Lib/ASF/sam/drivers/wdt/wdt.c
../Lib/ASF/sam/services/flash_efc/flash_efc.c
../Lib/ASF/sam/utils/cmsis/sam4s/source/templates/system_sam4s.c
swd/DAP.c
swd/SW_DP.c
swd/swd_host.c
swd/target_reset_nrf52.c
main.c
debug.c
dfu.c
dfu.desc.c
flash.c
usb.c
Devices/${CHIP}.c
)
add_definitions(
-D__SAM4S8C__
-DBOARD=SAM4S_XPLAINED_PRO
-DDFU_EXTRA_BLE_SWD_SUPPORT=${DFU_EXTRA_BLE_SWD_SUPPORT}
)
else ( )
message( FATAL_ERROR "Unsupported family ${FAMILY}" )
endif ( )
# Add device file, if it exists
string ( REPLACE " " "_" BOOT_PRODUCT_STR_CLEAN ${BOOT_PRODUCT_STR} )
if ( EXISTS ${CMAKE_SOURCE_DIR}/Devices/${BOOT_PRODUCT_STR_CLEAN}.c )
set ( SRCS ${SRCS}
Devices/${BOOT_PRODUCT_STR_CLEAN}.c
)
endif ()
message ( STATUS "Bootloader Source Files:" )
message ( "${SRCS}" )
#| Add Lib sources to main list
foreach ( SRC_FILE ${COMPILER_SRCS} )
set ( SRCS ${SRCS} ${CMAKE_SOURCE_DIR}/../${SRC_FILE} )
endforeach ()
###
# Directory Includes
#
include_directories (
${CMAKE_SOURCE_DIR}/../Lib
${CMAKE_SOURCE_DIR}/..
${CMAKE_SOURCE_DIR}
"../Lib/ASF"
"../Lib/ASF/config"
"../Lib/ASF/common/boards"
"../Lib/ASF/common/services/isp/flip"
"../Lib/ASF/common/services/isp/flip/module_config"
"../Lib/ASF/common/services/sleepmgr"
"../Lib/ASF/common/services/usb/class/dfu_flip"
"../Lib/ASF/common/services/usb/class/dfu_flip/device"
"../Lib/ASF/sam/boards"
"../Lib/ASF/sam/utils"
"../Lib/ASF/sam/utils/cmsis/sam4s/include"
"../Lib/ASF/sam/utils/header_files"
"../Lib/ASF/sam/utils/preprocessor"
"../Lib/CMSIS/Include"
"../Lib/CMSIS/Lib/GCC"
)
###
# Project Description
#
#| Project
project ( kiibohd_bootloader C )
#| Target Name (output name)
set ( TARGET kiibohd_bootloader )
#| General Settings
cmake_minimum_required ( VERSION 3.0 )
#| Compiler Version (only available after project() command)
message( STATUS "Full Compiler:" )
message( "${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_VERSION}" )
###
# Minimum Compiler Version Checks
#
# Due to optimization requirements, we have to impose a minimum GCC version on the bootloader
set ( BOOTLOADER_MIN_GCC_VERSION "4.9" )
if ( "${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" )
if ( CMAKE_C_COMPILER_VERSION VERSION_LESS "${BOOTLOADER_MIN_GCC_VERSION}" )
message( FATAL_ERROR "arm-none-eabi-gcc ${BOOTLOADER_MIN_GCC_VERSION} or higher is required for bootloader" )
endif ()
endif ()
###
# CMake Build Env
#
include ( buildinfo )
###
# Generate Header Files
#
configure_file ( _buildvars.h buildvars.h )
include_directories ( ${CMAKE_BINARY_DIR} )
###
# ctag Generation
#
find_package ( Ctags ) # Optional
if ( CTAGS_EXECUTABLE )
# Generate the ctags
execute_process( COMMAND ${CTAGS_EXECUTABLE} ${SRCS}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
endif ()
###
# Disable -Wl,-search_paths_first for OSX (not supported by arm-none-eabi-gcc)
#
if ( APPLE )
string ( REPLACE "-Wl,-search_paths_first" "" CMAKE_C_LINK_FLAGS ${CMAKE_C_LINK_FLAGS} )
string ( REPLACE "-Wl,-search_paths_first" "" CMAKE_CXX_LINK_FLAGS ${CMAKE_CXX_LINK_FLAGS} )
message ( AUTHOR_WARNING "Bootloader binary may not fit on device (must be less than 4096 bytes). Macports arm-none-eabi-gcc 4.7.3 doesn't seem to work properly with -flto. However, even disabling it doesn't shrink the binary enough... 4.9.1 is known to work on Arch Linux." )
endif ()
###
# Build Targets
#
#| Create the .ELF file
set ( TARGET_ELF ${TARGET}.elf )
add_executable ( ${TARGET_ELF} ${SRCS} )
#| .ELF Properties
set_target_properties ( ${TARGET_ELF} PROPERTIES
LINK_FLAGS ${LINKER_FLAGS}
SUFFIX "" # XXX Force Windows to keep the .exe off
)
#| Convert the .ELF into a .bin to load onto the McHCK
set ( TARGET_BIN ${TARGET}.bin )
set ( TARGET_HEX ${TARGET}.hex )
set(
TARGET_ADDRESS "0x0"
CACHE STRING "Bootloader starting address"
)
add_custom_command ( TARGET ${TARGET_ELF} POST_BUILD
COMMAND ${CMAKE_OBJCOPY} ${BIN_FLAGS} ${TARGET_ELF} ${TARGET_BIN}
COMMAND ${CMAKE_OBJCOPY} -O ihex ${TARGET_ELF} ${TARGET_HEX}
COMMENT "Creating binary file to load: ${TARGET_BIN}"
)
#| Generate the Extended .LSS
set ( TARGET_LSS ${TARGET}.lss )
add_custom_command ( TARGET ${TARGET_ELF} POST_BUILD
COMMAND ${CMAKE_OBJDUMP} ${LSS_FLAGS} ${TARGET_ELF} > ${TARGET_LSS}
COMMENT "Creating Extended Listing: ${TARGET_LSS}"
)
#| Generate the Symbol Table .SYM
set ( TARGET_SYM ${TARGET}.sym )
add_custom_command ( TARGET ${TARGET_ELF} POST_BUILD
COMMAND ${CMAKE_NM} -n ${TARGET_ELF} > ${TARGET_SYM}
COMMENT "Creating Symbol Table: ${TARGET_SYM}"
)
#| Compiler Selection Record
add_custom_command ( TARGET ${TARGET_ELF} POST_BUILD
COMMAND ${CMAKE_SOURCE_DIR}/../Lib/CMake/writer compiler ${COMPILER_FAMILY}
)
###
# Size Information
#
#| After Changes Size Information
add_custom_target ( SizeAfter ALL
COMMAND ${CMAKE_SOURCE_DIR}/../Lib/CMake/sizeCalculator ${CMAKE_SIZE} ram ${TARGET_ELF} ${SIZE_RAM} " SRAM"
COMMAND ${CMAKE_SOURCE_DIR}/../Lib/CMake/sizeCalculator ${CMAKE_SIZE} flash ${TARGET_ELF} ${SIZE_FLASH} "Flash"
DEPENDS ${TARGET_ELF}
COMMENT "Chip usage for ${CHIP}"
)
###
# Setup Loader Script and Program
#
if ( JLINK )
configure_file( ${CMAKE_SOURCE_DIR}/../LoadFile/load.jlink load NEWLINE_STYLE UNIX )
configure_file( ${CMAKE_SOURCE_DIR}/../LoadFile/dump.jlink dump NEWLINE_STYLE UNIX @ONLY )
configure_file( ${CMAKE_SOURCE_DIR}/../LoadFile/debug.jlink debug NEWLINE_STYLE UNIX )
configure_file( ${CMAKE_SOURCE_DIR}/../LoadFile/rtt.jlink rtt NEWLINE_STYLE UNIX )
configure_file( ${CMAKE_SOURCE_DIR}/../LoadFile/reset.jlink reset NEWLINE_STYLE UNIX )
endif()