-
Notifications
You must be signed in to change notification settings - Fork 147
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
281 lines (246 loc) · 10.3 KB
/
CMakeLists.txt
File metadata and controls
281 lines (246 loc) · 10.3 KB
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
# CMakeLists.txt
#
# Copyright (C) 2026 wolfSSL Inc.
#
# This file is part of wolfBoot.
#
# wolfBoot is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# wolfBoot is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
include(../cmake/wolfboot.cmake)
set(PLATFORM_NAME ${WOLFBOOT_TARGET})
if(NOT DEFINED WOLFBOOT_TARGET)
set(WOLFBOOT_TARGET "none")
endif()
if("${SIGN}" STREQUAL "RSA2048")
set(IMAGE_HEADER_SIZE "512")
endif()
if("${SIGN}" STREQUAL "RSA4096")
set(IMAGE_HEADER_SIZE "1024")
endif()
set(APP_SOURCES app_${WOLFBOOT_TARGET}.c led.c system.c timer.c)
if(DEBUG_UART)
list(APPEND APP_SOURCES ../src/string.c)
endif()
if(ARCH STREQUAL "ARM")
list(APPEND APP_SOURCES startup_arm.c)
list(APPEND TEST_APP_COMPILE_DEFINITIONS STM32)
endif()
if(ENCRYPT)
list(APPEND TEST_APP_COMPILE_DEFINITIONS EXT_ENCRYPTED=1)
endif()
if("${WOLFBOOT_TARGET}" STREQUAL "stm32h7")
set(APP_LSCRIPT_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/ARM-stm32h7.ld)
elseif("${WOLFBOOT_TARGET}" STREQUAL "stm32u5")
if(TZEN)
set(APP_LSCRIPT_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/ARM-stm32u5-ns.ld)
else()
set(APP_LSCRIPT_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/ARM-stm32u5.ld)
endif()
elseif("${WOLFBOOT_TARGET}" STREQUAL "stm32h5")
if(TZEN)
set(APP_LSCRIPT_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/ARM-stm32h5-ns.ld)
else()
set(APP_LSCRIPT_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/ARM-stm32h5.ld)
endif()
elseif("${WOLFBOOT_TARGET}" STREQUAL "stm32l5")
if(TZEN)
set(APP_LSCRIPT_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/ARM-stm32l5-ns.ld)
else()
set(APP_LSCRIPT_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/ARM-stm32l5.ld)
endif()
else()
set(APP_LSCRIPT_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/${ARCH}.ld)
endif()
if(SPI_FLASH)
list(APPEND TEST_APP_COMPILE_DEFINITIONS SPI_FLASH)
list(APPEND APP_SOURCES ../hal/spi/spi_drv_${SPI_TARGET}.c ../src/spi_flash.c)
endif()
if(OCTOSPI_FLASH)
set(QSPI_FLASH ON)
list(APPEND TEST_APP_COMPILE_DEFINITIONS OCTOSPI_FLASH)
endif()
if(QSPI_FLASH)
list(APPEND TEST_APP_COMPILE_DEFINITIONS QSPI_FLASH)
list(APPEND APP_SOURCES ../hal/spi/spi_drv_${SPI_TARGET}.c ../src/qspi_flash.c)
endif()
math(EXPR WOLFBOOT_TEST_APP_ADDRESS "${WOLFBOOT_PARTITION_BOOT_ADDRESS} + ${IMAGE_HEADER_SIZE}"
OUTPUT_FORMAT HEXADECIMAL)
math(EXPR WOLFBOOT_TEST_APP_SIZE "${WOLFBOOT_PARTITION_SIZE} - ${IMAGE_HEADER_SIZE}"
OUTPUT_FORMAT HEXADECIMAL)
# determine size of bootloader partition
if(NOT DEFINED BOOTLOADER_PARTITION_SIZE)
math(EXPR BOOTLOADER_PARTITION_SIZE "${WOLFBOOT_PARTITION_BOOT_ADDRESS} - ${ARCH_FLASH_OFFSET}"
OUTPUT_FORMAT HEXADECIMAL)
endif()
get_filename_component(WOLFBOOT_LSCRIPT ${CMAKE_SOURCE_DIR}/${WOLFBOOT_LSCRIPT_TEMPLATE} NAME)
set(WOLFBOOT_LSCRIPT ${CMAKE_CURRENT_BINARY_DIR}/${WOLFBOOT_LSCRIPT})
get_filename_component(APP_LSCRIPT ${APP_LSCRIPT_TEMPLATE} NAME)
set(APP_LSCRIPT ${CMAKE_CURRENT_BINARY_DIR}/${APP_LSCRIPT})
# generate linker script for bootloader
configure_file(${CMAKE_SOURCE_DIR}/${WOLFBOOT_LSCRIPT_TEMPLATE} ${WOLFBOOT_LSCRIPT})
# generate linker script for app
configure_file(${APP_LSCRIPT_TEMPLATE} ${APP_LSCRIPT})
if(WOLFBOOT_TARGET STREQUAL "sim")
# create bootloader for platform
gen_wolfboot_platform_target(${PLATFORM_NAME} "")
else()
add_library(bootloader_linker_script INTERFACE)
target_link_options(bootloader_linker_script INTERFACE -T${WOLFBOOT_LSCRIPT} -Wl,-Map=wolfboot.map)
# create bootloader for platform
gen_wolfboot_platform_target(${PLATFORM_NAME} bootloader_linker_script)
endif()
if(BUILD_TEST_APPS)
message(STATUS "Building wolfBoot test apps")
if(WOLFCRYPT_TZ_PKCS11 AND NOT TZEN)
message(FATAL_ERROR "WOLFCRYPT_TZ_PKCS11 requires TZEN=ON for test-app builds")
endif()
add_executable(image)
target_sources(image PRIVATE ${APP_SOURCES})
# stm32h5-specific sources
if("${WOLFBOOT_TARGET}" STREQUAL "stm32h5")
target_sources(image PRIVATE
../hal/uart/uart_drv_stm32h5.c
)
target_compile_definitions(image PRIVATE
APP_HAS_SYSTICK
RAMFUNCTION=__attribute__\(\(used,section\(".ramcode"\),long_call\)\)
)
target_compile_options(image PRIVATE
-ffunction-sections -fdata-sections -fno-common -mlong-calls
)
if(TZEN)
target_sources(image PRIVATE
wcs/wolfcrypt_secure.c
)
if(WOLFCRYPT_TZ)
set(WOLFSSL_TZ_TEST_SOURCES
../lib/wolfssl/wolfcrypt/src/logging.c
../lib/wolfssl/wolfcrypt/test/test.c
../lib/wolfssl/wolfcrypt/benchmark/benchmark.c
)
target_sources(image PRIVATE ${WOLFSSL_TZ_TEST_SOURCES})
if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
set_source_files_properties(${WOLFSSL_TZ_TEST_SOURCES}
PROPERTIES COMPILE_OPTIONS "-Wno-stack-usage")
endif()
endif()
endif()
endif()
# stm32l5-specific sources
if("${WOLFBOOT_TARGET}" STREQUAL "stm32l5")
target_sources(image PRIVATE
../hal/uart/uart_drv_stm32l5.c
)
target_compile_options(image PRIVATE
-ffunction-sections -fdata-sections -fno-common
)
endif()
target_include_directories(image PRIVATE
../
../include
${CMAKE_CURRENT_BINARY_DIR})
if(TZEN)
target_include_directories(image PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/wcs)
endif()
if(TZEN AND WOLFCRYPT_TZ_PKCS11)
target_include_directories(image PRIVATE ../lib/wolfPKCS11)
endif()
# For TrustZone builds, avoid linking the bootloader lib (it defines NSC stubs).
if(TZEN)
target_sources(image PRIVATE ../src/libwolfboot.c)
if(NOT SIGN STREQUAL "NONE")
set_source_files_properties(${CMAKE_BINARY_DIR}/keystore.c PROPERTIES GENERATED TRUE)
target_sources(image PRIVATE ${CMAKE_BINARY_DIR}/keystore.c)
add_dependencies(image keystore)
endif()
target_link_libraries(image PRIVATE wolfboothal target)
else()
target_link_libraries(image PRIVATE wolfboot wolfboothal public_key target)
endif()
# For TrustZone builds, the test app is a non-secure application and links
# the CMSE import library generated from the secure bootloader veneers.
if(TZEN)
list(APPEND TEST_APP_COMPILE_DEFINITIONS NONSECURE_APP)
add_dependencies(image wolfboot_${PLATFORM_NAME})
target_link_libraries(image PRIVATE ${CMAKE_BINARY_DIR}/wolfboot_tz_nsc.o)
endif()
if(TZEN AND WOLFCRYPT_TZ)
list(APPEND TEST_APP_COMPILE_DEFINITIONS WOLFBOOT_SECURE_CALLS)
endif()
if(TZEN AND WOLFCRYPT_TZ_PKCS11)
list(APPEND TEST_APP_COMPILE_DEFINITIONS
WOLFBOOT_PKCS11_APP
SECURE_PKCS11
WOLFBOOT_TZ_PKCS11
WOLFPKCS11_USER_SETTINGS)
if(PKCS11_TESTAPP)
list(APPEND TEST_APP_COMPILE_DEFINITIONS WOLFBOOT_PKCS11_TESTAPP)
endif()
set(WOLFSSL_PKCS11_SOURCES
test_pkcs11.c
wcs/pkcs11_stub.c
../lib/wolfssl/wolfcrypt/src/ecc.c
../lib/wolfssl/wolfcrypt/src/rsa.c
../lib/wolfssl/wolfcrypt/src/asn.c
../lib/wolfssl/wolfcrypt/src/aes.c
../lib/wolfssl/wolfcrypt/src/hmac.c
../lib/wolfssl/wolfcrypt/src/pwdbased.c
../lib/wolfssl/wolfcrypt/src/hash.c
../lib/wolfssl/wolfcrypt/src/sha256.c
../lib/wolfssl/wolfcrypt/src/sha512.c
../lib/wolfssl/wolfcrypt/src/sha3.c
../lib/wolfssl/wolfcrypt/src/integer.c
../lib/wolfssl/wolfcrypt/src/tfm.c
../lib/wolfssl/wolfcrypt/src/sp_c32.c
../lib/wolfssl/wolfcrypt/src/sp_int.c
../lib/wolfssl/wolfcrypt/src/cryptocb.c
../lib/wolfssl/wolfcrypt/src/wc_pkcs11.c
../lib/wolfssl/wolfcrypt/src/memory.c
../lib/wolfssl/wolfcrypt/src/wolfmath.c
../lib/wolfssl/wolfcrypt/src/dh.c
../lib/wolfssl/wolfcrypt/src/random.c
../lib/wolfssl/wolfcrypt/src/coding.c
../lib/wolfssl/wolfcrypt/src/wc_encrypt.c
../lib/wolfssl/wolfcrypt/src/wc_port.c
)
target_sources(image PRIVATE ${WOLFSSL_PKCS11_SOURCES})
if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
set_source_files_properties(${WOLFSSL_PKCS11_SOURCES}
PROPERTIES COMPILE_OPTIONS "-Wno-stack-usage")
endif()
if(SPMATH AND NOT NO_ASM)
list(APPEND TEST_APP_COMPILE_DEFINITIONS WOLFSSL_HAVE_SP_RSA WOLFSSL_HAVE_SP_ECC WOLFSSL_SP_ARM_CORTEX_M_ASM)
target_sources(image PRIVATE ../lib/wolfssl/wolfcrypt/src/sp_cortexm.c)
endif()
endif()
target_compile_definitions(image PRIVATE TARGET_${WOLFBOOT_TARGET}
${TEST_APP_COMPILE_DEFINITIONS} ${WOLFBOOT_DEFS_PUBLIC})
target_compile_options(image PRIVATE -Wall -Wstack-usage=1024 -ffreestanding -Wno-unused -fomit-frame-pointer
-nostartfiles)
if(WOLFBOOT_TARGET STREQUAL "sim")
target_link_options(image PRIVATE -Wl,-gc-sections -Wl,-Map=image.map)
else()
target_link_options(image PRIVATE -T${APP_LSCRIPT} -Wl,-gc-sections -Wl,-Map=image.map -ffreestanding -nostartfiles)
endif()
if(WOLFBOOT_TARGET IN_LIST ARM_TARGETS)
message(STATUS "Binary output products will be generated")
gen_bin_target_outputs(image)
# add boot address to cache
unset(${PLATFORM_NAME}_BOOT_ADDRESS CACHE)
set(${PLATFORM_NAME}_BOOT_ADDRESS ${WOLFBOOT_PARTITION_BOOT_ADDRESS} CACHE INTERNAL "")
gen_wolfboot_factory_image(${PLATFORM_NAME} image)
else()
gen_wolfboot_signed_image(image)
endif()
endif()