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