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