Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 1 | #------------------------------------------------------------------------------- |
Marc Moreno Berengue | a1f296f | 2018-01-25 15:21:22 +0000 | [diff] [blame] | 2 | # Copyright (c) 2017-2018, Arm Limited. All rights reserved. |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | # |
| 6 | #------------------------------------------------------------------------------- |
| 7 | |
| 8 | cmake_minimum_required(VERSION 3.7) |
| 9 | |
| 10 | #Tell cmake where our modules can be found |
| 11 | list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../cmake) |
| 12 | |
| 13 | #Include common stuff to control cmake. |
| 14 | include("Common/BuildSys") |
| 15 | |
| 16 | #Start an embedded project. |
| 17 | embedded_project_start(CONFIG "${CMAKE_CURRENT_LIST_DIR}/../ConfigDefault.cmake") |
| 18 | project(tfm_s LANGUAGES ASM C) |
| 19 | embedded_project_fixup() |
| 20 | |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 21 | set(SECURE_FW_DIR "${CMAKE_CURRENT_LIST_DIR}") |
| 22 | set(TFM_ROOT_DIR "${SECURE_FW_DIR}/..") |
| 23 | set(TEST_DIR "${TFM_ROOT_DIR}/test") |
| 24 | set(INTERFACE_DIR "${TFM_ROOT_DIR}/interface") |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 25 | |
Tamas Ban | 3109b30 | 2018-08-15 14:51:58 +0100 | [diff] [blame] | 26 | if (NOT DEFINED TFM_LVL) |
| 27 | message(FATAL_ERROR "Incomplete build configuration: TFM_LVL is undefined. ") |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 28 | endif() |
| 29 | |
| 30 | include(${SECURE_FW_DIR}/spm/CMakeLists.inc) |
| 31 | include(${SECURE_FW_DIR}/core/CMakeLists.inc) |
| 32 | include(${SECURE_FW_DIR}/ns_callable/CMakeLists.inc) |
| 33 | |
Marc Moreno Berengue | a1f296f | 2018-01-25 15:21:22 +0000 | [diff] [blame] | 34 | set(BUILD_CMSIS_CORE On) |
| 35 | set(BUILD_RETARGET On) |
| 36 | set(BUILD_NATIVE_DRIVERS On) |
| 37 | set(BUILD_STARTUP On) |
| 38 | set(BUILD_TARGET_CFG On) |
Marc Moreno Berengue | 4cc81fc | 2018-08-10 14:32:01 +0100 | [diff] [blame] | 39 | # FIXME: The following TARGET flags are platform dependent. |
| 40 | # It is required to add a mechanism to expose the |
| 41 | # target capabilities and, based on them, set the |
| 42 | # flags properly. |
Marc Moreno Berengue | a1f296f | 2018-01-25 15:21:22 +0000 | [diff] [blame] | 43 | set(BUILD_TARGET_HARDWARE_KEYS On) |
Marc Moreno Berengue | 4cc81fc | 2018-08-10 14:32:01 +0100 | [diff] [blame] | 44 | set(BUILD_TARGET_NV_COUNTERS On) |
Marc Moreno Berengue | a1f296f | 2018-01-25 15:21:22 +0000 | [diff] [blame] | 45 | set(BUILD_CMSIS_DRIVERS On) |
| 46 | set(BUILD_TIME Off) |
| 47 | set(BUILD_UART_STDOUT On) |
Marc Moreno Berengue | 792fc68 | 2018-02-20 11:53:30 +0000 | [diff] [blame] | 48 | set(BUILD_FLASH On) |
Marc Moreno Berengue | a1f296f | 2018-01-25 15:21:22 +0000 | [diff] [blame] | 49 | if(NOT DEFINED PLATFORM_CMAKE_FILE) |
| 50 | message (FATAL_ERROR "Platform specific CMake is not defined. Please set PLATFORM_CMAKE_FILE.") |
| 51 | elseif(NOT EXISTS ${PLATFORM_CMAKE_FILE}) |
| 52 | message (FATAL_ERROR "Platform specific CMake \"${PLATFORM_CMAKE_FILE}\" file does not exist. Please fix value of PLATFORM_CMAKE_FILE.") |
| 53 | else() |
| 54 | include(${PLATFORM_CMAKE_FILE}) |
| 55 | endif() |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 56 | |
Mate Toth-Pal | 48fc6a0 | 2018-01-24 09:50:14 +0100 | [diff] [blame] | 57 | if(NOT DEFINED S_SCATTER_FILE_NAME) |
| 58 | message(FATAL_ERROR "ERROR: Incomplete Configuration: S_SCATTER_FILE_NAME not defined, Include this file from a Config*.cmake") |
| 59 | endif() |
Gabor Kertesz | d7d7d74 | 2018-07-04 11:50:05 +0200 | [diff] [blame] | 60 | embedded_set_target_linker_file(TARGET ${PROJECT_NAME} PATH "${S_SCATTER_FILE_NAME}") |
| 61 | |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 62 | embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${TFM_ROOT_DIR} ABSOLUTE APPEND) |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 63 | #Create an object library to avoid compiling all source files twice, when two executables |
| 64 | #with different memory map need to be linked(BL2 non-swapping) |
| 65 | set(PROJECT_OBJ_LIB ${PROJECT_NAME}_obj_lib) |
| 66 | add_library(${PROJECT_OBJ_LIB} OBJECT ${ALL_SRC_C} ${ALL_SRC_C_S} ${ALL_SRC_ASM_S}) |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 67 | |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 68 | #Set common compiler flags |
| 69 | config_setting_shared_compiler_flags(${PROJECT_OBJ_LIB}) |
| 70 | |
Marc Moreno Berengue | 4cc81fc | 2018-08-10 14:32:01 +0100 | [diff] [blame] | 71 | if(NOT DEFINED TARGET_NV_COUNTERS_ENABLE) |
| 72 | set(TARGET_NV_COUNTERS_ENABLE OFF) |
| 73 | endif() |
| 74 | |
| 75 | if(TARGET_NV_COUNTERS_ENABLE) |
| 76 | embedded_set_target_compile_defines(TARGET ${PROJECT_OBJ_LIB} LANGUAGE C DEFINES TFM_NVCOUNTERS_ENABLE APPEND) |
| 77 | endif() |
| 78 | |
| 79 | if(CORE_TEST) |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 80 | embedded_set_target_compile_defines(TARGET ${PROJECT_OBJ_LIB} LANGUAGE C DEFINES TFM_CORE_DEBUG TFM_PARTITION_TEST_CORE APPEND) |
| 81 | endif() |
| 82 | |
| 83 | #Set include directories |
| 84 | embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${TFM_ROOT_DIR} ABSOLUTE APPEND) |
| 85 | |
| 86 | # For the non-swapping BL2 configuration two executables need to be built. |
| 87 | # One can be executed from flash partition slot_0 and other from slot_1. |
| 88 | # Only the linking phase is different. This function captures common settings |
| 89 | # and eliminates copy-paste. |
| 90 | function(set_up_secure_fw_build) |
| 91 | set( _OPTIONS_ARGS) #Option (on/off) arguments (e.g. IGNORE_CASE) |
| 92 | set( _ONE_VALUE_ARGS S_TARGET VENEER_NAME POSTFIX) #Single option arguments (e.g. PATH "./foo/bar") |
| 93 | set( _MULTI_VALUE_ARGS LINK_DEFINES) #List arguments (e.g. LANGUAGES C ASM CXX) |
| 94 | cmake_parse_arguments(_MY_PARAMS "${_OPTIONS_ARGS}" "${_ONE_VALUE_ARGS}" "${_MULTI_VALUE_ARGS}" ${ARGN}) |
| 95 | |
| 96 | if (NOT DEFINED _MY_PARAMS_S_TARGET) |
| 97 | message(FATAL_ERROR "set_up_secure_fw_build(): mandatory parameter 'S_TARGET' missing.") |
| 98 | endif() |
| 99 | |
| 100 | if (NOT DEFINED _MY_PARAMS_VENEER_NAME) |
| 101 | message(FATAL_ERROR "set_up_secure_fw_build(): mandatory parameter 'VENEER_NAME' missing.") |
| 102 | endif() |
| 103 | |
| 104 | set(EXE_NAME ${_MY_PARAMS_S_TARGET}${_MY_PARAMS_POSTFIX}) |
| 105 | set(VENEER_NAME ${_MY_PARAMS_VENEER_NAME}${_MY_PARAMS_POSTFIX}.o) |
| 106 | |
| 107 | #Create linker target: add object library to executable |
| 108 | add_executable(${EXE_NAME} $<TARGET_OBJECTS:${PROJECT_OBJ_LIB}>) |
| 109 | |
| 110 | #Set common linker flags |
| 111 | config_setting_shared_linker_flags(${EXE_NAME}) |
| 112 | |
| 113 | #Indicates to secure target(s) already created |
| 114 | set(TARGET_TFM_S_EXISTED True PARENT_SCOPE) |
| 115 | |
| 116 | #Set individual linker flags per linker target/executable |
| 117 | foreach(flag ${_MY_PARAMS_LINK_DEFINES}) |
| 118 | embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "${flag}") |
| 119 | endforeach(flag) |
| 120 | |
| 121 | embedded_set_target_linker_file(TARGET ${EXE_NAME} PATH "${S_SCATTER_FILE_NAME}") |
| 122 | |
| 123 | add_dependencies(${EXE_NAME} tfm_storage) |
| 124 | add_dependencies(${EXE_NAME} tfm_audit) |
| 125 | add_dependencies(${EXE_NAME} tfm_secure_tests) |
| 126 | |
| 127 | #Set macro definitions for the project. |
| 128 | embedded_set_target_compile_defines(TARGET ${PROJECT_OBJ_LIB} LANGUAGE C DEFINES __thumb2__ __ARM_FEATURE_CMSE=3 TFM_LVL=${TFM_LVL} DAUTH_CHIP_DEFAULT APPEND) |
| 129 | |
| 130 | if (REGRESSION OR CORE_TEST) |
| 131 | #The test service veneers may not be referenced in the secure binary so the |
| 132 | #veneer objects are explicitly loaded from the secure tests library. |
| 133 | if(${COMPILER} STREQUAL "ARMCLANG") |
| 134 | target_link_libraries(${EXE_NAME} tfm_storage tfm_audit $<TARGET_LINKER_FILE:tfm_secure_tests>\(*veneers.o\) tfm_secure_tests) |
| 135 | elseif(${COMPILER} STREQUAL "GNUARM") |
Mate Toth-Pal | f64f1eb | 2018-04-26 17:22:37 +0200 | [diff] [blame] | 136 | target_link_libraries(${EXE_NAME} tfm_secure_tests tfm_storage tfm_audit) |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 137 | else() |
| 138 | message(FATAL_ERROR "unknown compiler" ) |
| 139 | endif() |
| 140 | else() |
| 141 | target_link_libraries(${EXE_NAME} tfm_storage tfm_audit) |
| 142 | endif() |
| 143 | |
| 144 | embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TFM_LVL=${TFM_LVL}") |
| 145 | |
| 146 | if (NOT DEFINED TFM_PARTITION_TEST_CORE) |
| 147 | message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_CORE is undefined. ") |
| 148 | elseif (TFM_PARTITION_TEST_CORE) |
| 149 | embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TFM_PARTITION_TEST_CORE") |
| 150 | endif() |
| 151 | |
| 152 | if (NOT DEFINED TFM_PARTITION_TEST_SST) |
| 153 | message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_SST is undefined. ") |
| 154 | elseif (TFM_PARTITION_TEST_SST) |
| 155 | embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TFM_PARTITION_TEST_SST") |
| 156 | endif() |
| 157 | |
| 158 | if (NOT DEFINED TFM_PARTITION_TEST_SECURE_SERVICES) |
| 159 | message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_SECURE_SERVICES is undefined. ") |
| 160 | elseif (TFM_PARTITION_TEST_SECURE_SERVICES) |
| 161 | embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TFM_PARTITION_TEST_SECURE_SERVICES") |
| 162 | endif() |
| 163 | |
| 164 | if (NOT DEFINED BL2) |
| 165 | message(FATAL_ERROR "Incomplete build configuration: BL2 is undefined. ") |
| 166 | elseif (BL2) |
| 167 | embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "BL2") |
| 168 | endif() |
| 169 | |
| 170 | if(CORE_TEST) |
| 171 | set(SECURE_AXF_DIR_PREFIX "${CMAKE_BINARY_DIR}/unit_test/") |
| 172 | set_target_properties(${EXE_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${SECURE_AXF_DIR_PREFIX}) |
| 173 | embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TFM_PARTITION_TEST_CORE") |
| 174 | endif() |
| 175 | |
| 176 | if(NOT DEFINED PLATFORM_LINK_INCLUDES) |
| 177 | message(FATAL_ERROR "ERROR: Incomplete Configuration: PLATFORM_LINK_INCLUDES is not defined.") |
| 178 | endif() |
| 179 | embedded_set_target_link_includes(TARGET ${EXE_NAME} INCLUDES "${PLATFORM_LINK_INCLUDES}") |
| 180 | |
| 181 | #Generate binary file from executable |
| 182 | compiler_generate_binary_output(${EXE_NAME}) |
| 183 | |
| 184 | #Configure where we put the CMSE veneers generated by the compiler. |
| 185 | if (DEFINED S_VENEER_FILE_LOCATION) |
| 186 | set(S_VENEER_FILE "${S_VENEER_FILE_LOCATION}/${VENEER_NAME}") |
| 187 | else() |
| 188 | set(S_VENEER_FILE "${CMAKE_CURRENT_BINARY_DIR}/${VENEER_NAME}") |
| 189 | endif() |
| 190 | compiler_set_cmse_output(${EXE_NAME} "${S_VENEER_FILE}") |
| 191 | |
| 192 | #Configure what file shall be installed. |
| 193 | #Set install location. Keep original value to avoid overriding command line settings. |
| 194 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) |
| 195 | set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Default install location for secure_fw." FORCE) |
| 196 | endif() |
| 197 | |
Tamas Ban | 57bfa43 | 2018-04-13 16:05:49 +0100 | [diff] [blame] | 198 | #Export files needed to interface external applications at: <build_dir>/install/export/tfm/ |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 199 | install(DIRECTORY ${TFM_ROOT_DIR}/interface/include/ |
Tamas Ban | 57bfa43 | 2018-04-13 16:05:49 +0100 | [diff] [blame] | 200 | DESTINATION export/tfm/inc) |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 201 | |
| 202 | install(DIRECTORY ${TFM_ROOT_DIR}/interface/src/ |
Tamas Ban | 57bfa43 | 2018-04-13 16:05:49 +0100 | [diff] [blame] | 203 | DESTINATION export/tfm/src) |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 204 | |
Tamas Ban | 57bfa43 | 2018-04-13 16:05:49 +0100 | [diff] [blame] | 205 | install(FILES ${S_VENEER_FILE} DESTINATION export/tfm/veneers) |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 206 | |
Tamas Ban | 57bfa43 | 2018-04-13 16:05:49 +0100 | [diff] [blame] | 207 | #Collect executables to common location: <build_dir>/install/outputs/ |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 208 | if (DEFINED SECURE_AXF_DIR_PREFIX) |
| 209 | set(MY_BINARY_DIR ${SECURE_AXF_DIR_PREFIX}) |
| 210 | else() |
| 211 | set(MY_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) |
| 212 | endif() |
| 213 | |
| 214 | install(FILES ${MY_BINARY_DIR}/${EXE_NAME}.axf |
| 215 | ${MY_BINARY_DIR}/${EXE_NAME}.bin |
| 216 | DESTINATION outputs/${TARGET_PLATFORM}/) |
| 217 | |
| 218 | install(FILES ${MY_BINARY_DIR}/${EXE_NAME}.axf |
| 219 | ${MY_BINARY_DIR}/${EXE_NAME}.bin |
| 220 | DESTINATION outputs/fvp/) |
| 221 | endfunction() |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 222 | |
| 223 | #Adds the test directory |
| 224 | add_subdirectory(${TFM_ROOT_DIR}/test ${CMAKE_BINARY_DIR}/test) |
| 225 | |
| 226 | #Add the secure storage library target |
| 227 | add_subdirectory(${SECURE_FW_DIR}/services/secure_storage) |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 228 | |
Antonio de Angelis | cc657b3 | 2018-02-05 15:56:47 +0000 | [diff] [blame] | 229 | #Add the audit logging library target |
| 230 | add_subdirectory(${SECURE_FW_DIR}/services/audit_logging) |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 231 | |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 232 | if (LINK_TO_BOTH_MEMORY_REGION) |
| 233 | #Link to primary memory region |
| 234 | set_up_secure_fw_build(S_TARGET ${PROJECT_NAME} |
| 235 | VENEER_NAME s_veneers |
| 236 | POSTFIX "_0") |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 237 | |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 238 | #Link to secondary memory region(add extra linker flag) |
| 239 | set_up_secure_fw_build(S_TARGET ${PROJECT_NAME} |
| 240 | LINK_DEFINES "LINK_TO_SECONDARY_PARTITION" |
| 241 | VENEER_NAME s_veneers |
| 242 | POSTFIX "_1") |
Jamie Fox | 5592db0 | 2017-12-18 16:48:29 +0000 | [diff] [blame] | 243 | else() |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 244 | #Link to primary memory region only |
| 245 | set_up_secure_fw_build(S_TARGET ${PROJECT_NAME} |
| 246 | VENEER_NAME s_veneers) |
Jamie Fox | 5592db0 | 2017-12-18 16:48:29 +0000 | [diff] [blame] | 247 | endif() |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 248 | |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 249 | #Finally let CMake system apply changes after the whole project is defined. |
| 250 | if (TARGET ${PROJECT_NAME}) |
| 251 | embedded_project_end(${PROJECT_NAME}) |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 252 | endif() |
| 253 | |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 254 | if (TARGET ${PROJECT_NAME}_0) |
| 255 | embedded_project_end(${PROJECT_NAME}_0) |
Jamie Fox | 5592db0 | 2017-12-18 16:48:29 +0000 | [diff] [blame] | 256 | endif() |
| 257 | |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 258 | if (TARGET ${PROJECT_NAME}_1) |
| 259 | embedded_project_end(${PROJECT_NAME}_1) |
Ben Davis | 6d7256b | 2018-04-18 14:16:53 +0100 | [diff] [blame] | 260 | endif() |
| 261 | |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 262 | embedded_project_end(${PROJECT_OBJ_LIB}) |