blob: de846d56470df33677ac33aa2f7cbff9dd300b3c [file] [log] [blame]
Gyorgy Szing30fa9872017-12-05 01:08:47 +00001#-------------------------------------------------------------------------------
Mate Toth-Pal74684d92018-01-17 19:15:47 +01002# Copyright (c) 2017-2018, Arm Limited. All rights reserved.
Gyorgy Szing30fa9872017-12-05 01:08:47 +00003#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6#-------------------------------------------------------------------------------
7
8cmake_minimum_required(VERSION 3.7)
9
10#Tell cmake where our modules can be found
11list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../cmake)
12
13#Include common stuff to control cmake.
14include("Common/BuildSys")
15
16#Start an embedded project.
17embedded_project_start(CONFIG "${CMAKE_CURRENT_LIST_DIR}/../ConfigDefault.cmake")
18project(tfm_ns LANGUAGES ASM C)
19embedded_project_fixup()
20
21set(APP_DIR ${CMAKE_CURRENT_LIST_DIR})
22get_filename_component(TFM_ROOT_DIR ${APP_DIR}/.. ABSOLUTE)
23set(INTERFACE_DIR ${TFM_ROOT_DIR}/interface)
Antonio de Angelis8ad3d3812018-04-13 16:48:00 +010024set(TEST_INTERFACE_DIR ${TFM_ROOT_DIR}/test/interface)
Gyorgy Szing30fa9872017-12-05 01:08:47 +000025
26#Set variables
27get_filename_component(CMSIS_5_DIR ${TFM_ROOT_DIR}/../CMSIS_5 ABSOLUTE)
28
29if(NOT EXISTS ${CMSIS_5_DIR})
30 message(FATAL_ERROR "Missing CMSIS_5. Please clone the CMSIS_5 repo to directory \"${CMSIS_5_DIR}\".")
31endif()
32
33set(NS_APP_SRC "${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Config/RTX_Config.c"
34 "${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Source/rtx_lib.c"
35 "${APP_DIR}/main_ns.c"
36 "${APP_DIR}/ext/tz_context.c"
37 "${APP_DIR}/tfm_integ_test.c"
38 "${APP_DIR}/os_wrapper_rtx.c"
39 "${INTERFACE_DIR}/src/tfm_sst_api.c"
40 "${INTERFACE_DIR}/src/tfm_sst_svc_handler.c"
Antonio de Angeliscc657b32018-02-05 15:56:47 +000041 "${INTERFACE_DIR}/src/tfm_log_api.c"
42 "${INTERFACE_DIR}/src/tfm_log_svc_handler.c"
Gyorgy Szing30fa9872017-12-05 01:08:47 +000043 "${INTERFACE_DIR}/src/tfm_id_mngr_dummy.c"
44 "${INTERFACE_DIR}/src/tfm_ns_lock_rtx.c"
45 )
46
Marc Moreno Berenguea1f296f2018-01-25 15:21:22 +000047set(BUILD_CMSIS_CORE On)
48set(BUILD_RETARGET On)
49set(BUILD_NATIVE_DRIVERS On)
50set(BUILD_TIME Off)
51set(BUILD_STARTUP On)
52set(BUILD_TARGET_CFG Off)
53set(BUILD_TARGET_HARDWARE_KEYS Off)
54set(BUILD_CMSIS_DRIVERS On)
55set(BUILD_UART_STDOUT Off)
56set(BUILD_FLASH Off)
57if(NOT DEFINED PLATFORM_CMAKE_FILE)
58 message (FATAL_ERROR "Platform specific CMake is not defined. Please set PLATFORM_CMAKE_FILE.")
59elseif(NOT EXISTS ${PLATFORM_CMAKE_FILE})
60 message (FATAL_ERROR "Platform specific CMake \"${PLATFORM_CMAKE_FILE}\" file does not exist. Please fix value of PLATFORM_CMAKE_FILE.")
61else()
62 include(${PLATFORM_CMAKE_FILE})
63endif()
Gyorgy Szing30fa9872017-12-05 01:08:47 +000064
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +010065if(NOT DEFINED NS_SCATTER_FILE_NAME)
66 message(FATAL_ERROR "ERROR: Incomplete Configuration: NS_SCATTER_FILE_NAME not defined, Include this file from a Config*.cmake")
67endif()
Gabor Kerteszd7d7d742018-07-04 11:50:05 +020068embedded_set_target_linker_file(TARGET ${PROJECT_NAME} PATH "${NS_SCATTER_FILE_NAME}")
69
70if(NOT DEFINED PLATFORM_LINK_INCLUDES)
71 message(FATAL_ERROR "ERROR: Incomplete Configuration: PLATFORM_LINK_INCLUDES is not defined.")
72endif()
73embedded_set_target_link_includes(TARGET ${PROJECT_NAME} INCLUDES "${PLATFORM_LINK_INCLUDES}")
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +010074
Gyorgy Szing30fa9872017-12-05 01:08:47 +000075#Set include directories.
76embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${TFM_ROOT_DIR}/common/sct ABSOLUTE APPEND)
Antonio de Angelis8ad3d3812018-04-13 16:48:00 +010077embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${TEST_INTERFACE_DIR}/include ABSOLUTE APPEND)
Gyorgy Szing30fa9872017-12-05 01:08:47 +000078embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${INTERFACE_DIR}/include ABSOLUTE APPEND)
79embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${TFM_ROOT_DIR} ABSOLUTE APPEND)
80embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${TFM_ROOT_DIR}/secure_fw/spm ABSOLUTE APPEND)
81embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${TFM_ROOT_DIR}/secure_fw/core ABSOLUTE APPEND)
82embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Include ABSOLUTE APPEND)
83embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${CMSIS_5_DIR}/CMSIS/RTOS2/Include ABSOLUTE APPEND)
84embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Config ABSOLUTE APPEND)
85
86#Create an executable
87add_executable(${PROJECT_NAME} ${ALL_SRC_C} ${ALL_SRC_C_NS} ${ALL_SRC_ASM_NS} ${NS_APP_SRC})
88#Add the RTX library
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +010089if(NOT DEFINED RTX_LIB_PATH)
90 message(FATAL_ERROR "ERROR: Incomplete Configuration: RTX_LIB_PATH is not defined.")
91endif()
92target_link_libraries(${PROJECT_NAME} "${RTX_LIB_PATH}")
Gyorgy Szing30fa9872017-12-05 01:08:47 +000093#Set macro definitions
Tamas Ban581034a2017-12-19 19:54:37 +000094target_compile_definitions(${PROJECT_NAME} PRIVATE __thumb2__ __DOMAIN_NS=1 __ARM_FEATURE_CMSE=3 LOG_MSG_HANDLER_MODE_PRINTF_ENABLED)
95
96#Generate binary file from axf
97compiler_generate_binary_output(${PROJECT_NAME})
98
Mate Toth-Pal65c935e2018-01-17 18:42:13 +010099#Generate MCUBoot compatible payload
100if (BL2)
101 #Find Python3.x interpreter
102 find_package(PythonInterp 3)
103
Tamas Ban581034a2017-12-19 19:54:37 +0000104 if (NOT PYTHONINTERP_FOUND)
Avinash Mehta788036c2018-03-15 12:38:43 +0000105 message(FATAL_ERROR "Failed to find Python3.x interpreter. Python3 must be installed and available on the PATH.")
Tamas Ban581034a2017-12-19 19:54:37 +0000106 endif()
107
108 set(MCUBOOT_DIR ${TFM_ROOT_DIR}/bl2/ext/mcuboot)
109
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +0100110if(NOT DEFINED FLASH_LAYOUT)
111 message(FATAL_ERROR "ERROR: Incomplete Configuration: FLASH_LAYOUT is not defined.")
112endif()
113
Tamas Ban581034a2017-12-19 19:54:37 +0000114 add_custom_command(TARGET ${PROJECT_NAME}
115 POST_BUILD
116
117 #Create concatenated binary image from tfm_ns.bin and tfm_s.bin
118 COMMAND ${PYTHON_EXECUTABLE} ${MCUBOOT_DIR}/scripts/assemble.py
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +0100119 ARGS -l ${FLASH_LAYOUT}
120 -s $<TARGET_FILE_DIR:tfm_s>/tfm_s.bin
Tamas Ban581034a2017-12-19 19:54:37 +0000121 -n $<TARGET_FILE_DIR:tfm_ns>/tfm_ns.bin
Mate Toth-Pald577f0f2018-02-01 15:36:25 +0100122 -o ${CMAKE_BINARY_DIR}/tfm_full.bin
Tamas Ban581034a2017-12-19 19:54:37 +0000123
124 #Sign concatenated binary image with default public key in mcuboot folder
125 COMMAND ${PYTHON_EXECUTABLE} ${MCUBOOT_DIR}/scripts/imgtool.py
126 ARGS sign
127 -k ${MCUBOOT_DIR}/root-rsa-2048.pem
128 --align 1
129 -v 1.0
Mate Toth-Pal74684d92018-01-17 19:15:47 +0100130 -H 0x400
Avinash Mehta788036c2018-03-15 12:38:43 +0000131 --pad ${SIGN_BIN_SIZE}
Mate Toth-Pald577f0f2018-02-01 15:36:25 +0100132 ${CMAKE_BINARY_DIR}/tfm_full.bin
133 ${CMAKE_BINARY_DIR}/tfm_sign.bin
Tamas Ban581034a2017-12-19 19:54:37 +0000134 )
135endif()
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000136
137if (NOT DEFINED CORE_TEST)
138 message(FATAL_ERROR "Incomplete build configuration: CORE_TEST is undefined. ")
139elseif(CORE_TEST)
140 target_compile_definitions(${PROJECT_NAME} PRIVATE CORE_TEST)
141endif()
142
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100143if (NOT DEFINED TFM_PARTITION_TEST_CORE)
144 message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_CORE is undefined. ")
145elseif (TFM_PARTITION_TEST_CORE)
Mate Toth-Pal76867262018-03-09 13:15:36 +0100146 embedded_set_target_link_defines(TARGET ${PROJECT_NAME} DEFINES "TFM_PARTITION_TEST_CORE")
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000147endif()
148
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100149if (NOT DEFINED TFM_PARTITION_TEST_SST)
150 message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_SST is undefined. ")
151elseif (TFM_PARTITION_TEST_SST)
Mate Toth-Pal76867262018-03-09 13:15:36 +0100152 embedded_set_target_link_defines(TARGET ${PROJECT_NAME} DEFINES "TFM_PARTITION_TEST_SST")
Jamie Fox5592db02017-12-18 16:48:29 +0000153endif()
154
Ben Davis6d7256b2018-04-18 14:16:53 +0100155if (NOT DEFINED TFM_PARTITION_TEST_SECURE_SERVICES)
156 message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_SECURE_SERVICES is undefined. ")
157elseif (TFM_PARTITION_TEST_SECURE_SERVICES)
158 embedded_set_target_link_defines(TARGET ${PROJECT_NAME} DEFINES "TFM_PARTITION_TEST_SECURE_SERVICES")
159endif()
160
Tamas Ban581034a2017-12-19 19:54:37 +0000161#Set BL2 specific settings.
162if (NOT DEFINED BL2)
163 message(FATAL_ERROR "Incomplete build configuration: BL2 is undefined. ")
164elseif (BL2)
Mate Toth-Pal76867262018-03-09 13:15:36 +0100165 embedded_set_target_link_defines(TARGET ${PROJECT_NAME} DEFINES "BL2")
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000166endif()
167
168
169if(NOT TARGET tfm_s)
170 #We need access to the secure veneers. If the location is not already
171 #specified, then set it.
172 if (NOT DEFINED S_VENEER_FILE)
173 set(S_VENEER_FILE "${CMAKE_CURRENT_BINARY_DIR}/s_veneers.o")
174 endif()
175 add_subdirectory(../secure_fw ${CMAKE_CURRENT_BINARY_DIR}/secure_fw)
176endif()
177
178#We depend on the non secure tests. See if the library target is available.
179if(TARGET tfm_non_secure_tests)
180 #If yes, then use the library.
181 target_link_libraries(${PROJECT_NAME} tfm_non_secure_tests)
182 #Ensure library is built first.
183 #add_dependencies(${PROJECT_NAME} tfm_non_secure_tests)
184else()
185 #If not, add the test source to the build.
186 #As of today since secufre_fw is built as a sub-project this code will never
187 #execute.
188 option(ENABLE_INVERT_SERVICE_TESTS "" TRUE)
189 option(ENABLE_SECURE_STORAGE_SERVICE_TESTS "" TRUE)
190 include(../test/CMakeLists.inc)
191 target_sources(${PROJECT_NAME} PUBLIC ${ALL_SRC_C} ${ALL_SRC_C_NS})
192endif()
193
194#Ensure secure_fw is built before our executable.
195add_dependencies(${PROJECT_NAME} tfm_s)
196
197#Add the veneers to the executable.
198set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY LINK_LIBRARIES ${S_VENEER_FILE})
199
200#Finally let cmake system apply changes after the whole project is defined.
201embedded_project_end(${PROJECT_NAME})