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 | |
| 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") |
| 25 | |
| 26 | if(CORE_TEST) |
| 27 | set (TFM_LVL 3) |
| 28 | else() |
| 29 | set (TFM_LVL 1) |
| 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() |
| 57 | embedded_set_target_linker_file(TARGET tfm_s 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) |
| 60 | |
| 61 | #Specify what we build |
| 62 | add_executable(${PROJECT_NAME} ${ALL_SRC_C} ${ALL_SRC_C_S} ${ALL_SRC_ASM_S}) |
| 63 | |
| 64 | #Adds the test directory |
| 65 | add_subdirectory(${TFM_ROOT_DIR}/test ${CMAKE_BINARY_DIR}/test) |
| 66 | |
| 67 | #Add the secure storage library target |
| 68 | add_subdirectory(${SECURE_FW_DIR}/services/secure_storage) |
Antonio de Angelis | cc657b3 | 2018-02-05 15:56:47 +0000 | [diff] [blame] | 69 | #Add the audit logging library target |
| 70 | add_subdirectory(${SECURE_FW_DIR}/services/audit_logging) |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 71 | |
| 72 | add_dependencies(${PROJECT_NAME} tfm_storage) |
Antonio de Angelis | cc657b3 | 2018-02-05 15:56:47 +0000 | [diff] [blame] | 73 | add_dependencies(${PROJECT_NAME} tfm_audit) |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 74 | add_dependencies(${PROJECT_NAME} tfm_secure_tests) |
| 75 | |
| 76 | #Set macro definitions for the project. |
| 77 | embedded_set_target_compile_defines(TARGET ${PROJECT_NAME} LANGUAGE C DEFINES __thumb2__ __ARM_FEATURE_CMSE=3 TFM_LVL=${TFM_LVL} DAUTH_CHIP_DEFAULT APPEND) |
Jamie Fox | 5592db0 | 2017-12-18 16:48:29 +0000 | [diff] [blame] | 78 | |
| 79 | if (REGRESSION OR CORE_TEST) |
| 80 | #The test service veneers may not be referenced in the secure binary so the |
| 81 | #veneer objects are explicitly loaded from the secure tests library. |
Mate Toth-Pal | 7686726 | 2018-03-09 13:15:36 +0100 | [diff] [blame] | 82 | if(${COMPILER} STREQUAL "ARMCLANG") |
Antonio de Angelis | cc657b3 | 2018-02-05 15:56:47 +0000 | [diff] [blame] | 83 | target_link_libraries(${PROJECT_NAME} tfm_storage tfm_audit $<TARGET_LINKER_FILE:tfm_secure_tests>\(*veneers.o\) tfm_secure_tests) |
Mate Toth-Pal | 7686726 | 2018-03-09 13:15:36 +0100 | [diff] [blame] | 84 | elseif(${COMPILER} STREQUAL "GNUARM") |
Antonio de Angelis | cc657b3 | 2018-02-05 15:56:47 +0000 | [diff] [blame] | 85 | target_link_libraries(${PROJECT_NAME} -Wl,--whole-archive tfm_secure_tests -Wl,--no-whole-archive tfm_storage tfm_audit) |
Mate Toth-Pal | 7686726 | 2018-03-09 13:15:36 +0100 | [diff] [blame] | 86 | else() |
| 87 | message(FATAL_ERROR "unknown compiler" ) |
| 88 | endif() |
Jamie Fox | 5592db0 | 2017-12-18 16:48:29 +0000 | [diff] [blame] | 89 | else() |
Antonio de Angelis | cc657b3 | 2018-02-05 15:56:47 +0000 | [diff] [blame] | 90 | target_link_libraries(${PROJECT_NAME} tfm_storage tfm_audit) |
Jamie Fox | 5592db0 | 2017-12-18 16:48:29 +0000 | [diff] [blame] | 91 | endif() |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 92 | |
Mate Toth-Pal | 7686726 | 2018-03-09 13:15:36 +0100 | [diff] [blame] | 93 | embedded_set_target_link_defines(TARGET ${PROJECT_NAME} DEFINES "TFM_LVL=${TFM_LVL}") |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 94 | |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 95 | if (NOT DEFINED TFM_PARTITION_TEST_CORE) |
| 96 | message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_CORE is undefined. ") |
| 97 | elseif (TFM_PARTITION_TEST_CORE) |
Mate Toth-Pal | 7686726 | 2018-03-09 13:15:36 +0100 | [diff] [blame] | 98 | embedded_set_target_link_defines(TARGET ${PROJECT_NAME} DEFINES "TFM_PARTITION_TEST_CORE") |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 99 | endif() |
| 100 | |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 101 | if (NOT DEFINED TFM_PARTITION_TEST_SST) |
| 102 | message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_SST is undefined. ") |
| 103 | elseif (TFM_PARTITION_TEST_SST) |
Mate Toth-Pal | 7686726 | 2018-03-09 13:15:36 +0100 | [diff] [blame] | 104 | embedded_set_target_link_defines(TARGET ${PROJECT_NAME} DEFINES "TFM_PARTITION_TEST_SST") |
Jamie Fox | 5592db0 | 2017-12-18 16:48:29 +0000 | [diff] [blame] | 105 | endif() |
| 106 | |
Tamas Ban | 581034a | 2017-12-19 19:54:37 +0000 | [diff] [blame] | 107 | if (NOT DEFINED BL2) |
| 108 | message(FATAL_ERROR "Incomplete build configuration: BL2 is undefined. ") |
| 109 | elseif (BL2) |
Mate Toth-Pal | 7686726 | 2018-03-09 13:15:36 +0100 | [diff] [blame] | 110 | embedded_set_target_link_defines(TARGET ${PROJECT_NAME} DEFINES "BL2") |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 111 | endif() |
| 112 | |
| 113 | if(CORE_TEST) |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 114 | embedded_set_target_compile_defines(TARGET ${PROJECT_NAME} LANGUAGE C DEFINES TFM_CORE_DEBUG TFM_PARTITION_TEST_CORE APPEND) |
Tamas Ban | 581034a | 2017-12-19 19:54:37 +0000 | [diff] [blame] | 115 | set(SECURE_AXF_DIR_PREFIX "${CMAKE_BINARY_DIR}/unit_test/") |
| 116 | set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${SECURE_AXF_DIR_PREFIX}) |
Mate Toth-Pal | 7686726 | 2018-03-09 13:15:36 +0100 | [diff] [blame] | 117 | embedded_set_target_link_defines(TARGET ${PROJECT_NAME} DEFINES "TFM_PARTITION_TEST_CORE") |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 118 | endif() |
| 119 | |
Tamas Ban | 581034a | 2017-12-19 19:54:37 +0000 | [diff] [blame] | 120 | #Generate binary file from axf |
| 121 | compiler_generate_binary_output(${PROJECT_NAME}) |
| 122 | |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 123 | #Configure where we put the CMSE veneers generated by the compiler. |
| 124 | if (NOT DEFINED S_VENEER_FILE) |
| 125 | set(S_VENEER_FILE "${CMAKE_CURRENT_BINARY_DIR}/s_veneers.o") |
| 126 | endif() |
| 127 | compiler_set_cmse_output(${PROJECT_NAME} "${S_VENEER_FILE}") |
| 128 | |
| 129 | #Configure what file shall be installed. |
| 130 | #Set install location. Keep original value to avoid overriding command line |
| 131 | #settings. |
| 132 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) |
Tamas Ban | 581034a | 2017-12-19 19:54:37 +0000 | [diff] [blame] | 133 | SET(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Default install location for secure_fw." FORCE) |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 134 | endif() |
| 135 | |
| 136 | install(DIRECTORY ${TFM_ROOT_DIR}/interface/include/ |
| 137 | DESTINATION tfm/inc) |
| 138 | |
| 139 | install(DIRECTORY ${TFM_ROOT_DIR}/interface/src/ |
| 140 | DESTINATION tfm/src) |
| 141 | |
| 142 | install(FILES ${S_VENEER_FILE} |
| 143 | DESTINATION tfm/veneers) |
| 144 | |
| 145 | #Finally let cmake system apply changes after the whole project is defined. |
| 146 | embedded_project_end(${PROJECT_NAME}) |