blob: 89f9c540c7e323cc639d5f5584e52fb7ba9b7d4d [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.
Antonio de Angelis8ad3d3812018-04-13 16:48:00 +010076embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${TEST_INTERFACE_DIR}/include ABSOLUTE APPEND)
Gyorgy Szing30fa9872017-12-05 01:08:47 +000077embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${INTERFACE_DIR}/include ABSOLUTE APPEND)
78embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${TFM_ROOT_DIR} ABSOLUTE APPEND)
79embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${TFM_ROOT_DIR}/secure_fw/spm ABSOLUTE APPEND)
80embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${TFM_ROOT_DIR}/secure_fw/core ABSOLUTE APPEND)
81embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Include ABSOLUTE APPEND)
82embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${CMSIS_5_DIR}/CMSIS/RTOS2/Include ABSOLUTE APPEND)
83embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Config ABSOLUTE APPEND)
84
85#Create an executable
86add_executable(${PROJECT_NAME} ${ALL_SRC_C} ${ALL_SRC_C_NS} ${ALL_SRC_ASM_NS} ${NS_APP_SRC})
87#Add the RTX library
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +010088if(NOT DEFINED RTX_LIB_PATH)
89 message(FATAL_ERROR "ERROR: Incomplete Configuration: RTX_LIB_PATH is not defined.")
90endif()
91target_link_libraries(${PROJECT_NAME} "${RTX_LIB_PATH}")
Gyorgy Szing30fa9872017-12-05 01:08:47 +000092#Set macro definitions
Tamas Ban581034a2017-12-19 19:54:37 +000093target_compile_definitions(${PROJECT_NAME} PRIVATE __thumb2__ __DOMAIN_NS=1 __ARM_FEATURE_CMSE=3 LOG_MSG_HANDLER_MODE_PRINTF_ENABLED)
94
95#Generate binary file from axf
96compiler_generate_binary_output(${PROJECT_NAME})
97
Mate Toth-Pal65c935e2018-01-17 18:42:13 +010098#Generate MCUBoot compatible payload
99if (BL2)
100 #Find Python3.x interpreter
101 find_package(PythonInterp 3)
102
Tamas Ban581034a2017-12-19 19:54:37 +0000103 if (NOT PYTHONINTERP_FOUND)
Avinash Mehta788036c2018-03-15 12:38:43 +0000104 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 +0000105 endif()
106
107 set(MCUBOOT_DIR ${TFM_ROOT_DIR}/bl2/ext/mcuboot)
108
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +0100109if(NOT DEFINED FLASH_LAYOUT)
110 message(FATAL_ERROR "ERROR: Incomplete Configuration: FLASH_LAYOUT is not defined.")
111endif()
112
Tamas Ban581034a2017-12-19 19:54:37 +0000113 add_custom_command(TARGET ${PROJECT_NAME}
114 POST_BUILD
115
116 #Create concatenated binary image from tfm_ns.bin and tfm_s.bin
117 COMMAND ${PYTHON_EXECUTABLE} ${MCUBOOT_DIR}/scripts/assemble.py
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +0100118 ARGS -l ${FLASH_LAYOUT}
119 -s $<TARGET_FILE_DIR:tfm_s>/tfm_s.bin
Tamas Ban581034a2017-12-19 19:54:37 +0000120 -n $<TARGET_FILE_DIR:tfm_ns>/tfm_ns.bin
Mate Toth-Pald577f0f2018-02-01 15:36:25 +0100121 -o ${CMAKE_BINARY_DIR}/tfm_full.bin
Tamas Ban581034a2017-12-19 19:54:37 +0000122
123 #Sign concatenated binary image with default public key in mcuboot folder
124 COMMAND ${PYTHON_EXECUTABLE} ${MCUBOOT_DIR}/scripts/imgtool.py
125 ARGS sign
126 -k ${MCUBOOT_DIR}/root-rsa-2048.pem
127 --align 1
128 -v 1.0
Mate Toth-Pal74684d92018-01-17 19:15:47 +0100129 -H 0x400
Avinash Mehta788036c2018-03-15 12:38:43 +0000130 --pad ${SIGN_BIN_SIZE}
Mate Toth-Pald577f0f2018-02-01 15:36:25 +0100131 ${CMAKE_BINARY_DIR}/tfm_full.bin
132 ${CMAKE_BINARY_DIR}/tfm_sign.bin
Tamas Ban581034a2017-12-19 19:54:37 +0000133 )
134endif()
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000135
136if (NOT DEFINED CORE_TEST)
137 message(FATAL_ERROR "Incomplete build configuration: CORE_TEST is undefined. ")
138elseif(CORE_TEST)
139 target_compile_definitions(${PROJECT_NAME} PRIVATE CORE_TEST)
140endif()
141
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100142if (NOT DEFINED TFM_PARTITION_TEST_CORE)
143 message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_CORE is undefined. ")
144elseif (TFM_PARTITION_TEST_CORE)
Mate Toth-Pal76867262018-03-09 13:15:36 +0100145 embedded_set_target_link_defines(TARGET ${PROJECT_NAME} DEFINES "TFM_PARTITION_TEST_CORE")
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000146endif()
147
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100148if (NOT DEFINED TFM_PARTITION_TEST_SST)
149 message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_SST is undefined. ")
150elseif (TFM_PARTITION_TEST_SST)
Mate Toth-Pal76867262018-03-09 13:15:36 +0100151 embedded_set_target_link_defines(TARGET ${PROJECT_NAME} DEFINES "TFM_PARTITION_TEST_SST")
Jamie Fox5592db02017-12-18 16:48:29 +0000152endif()
153
Ben Davis6d7256b2018-04-18 14:16:53 +0100154if (NOT DEFINED TFM_PARTITION_TEST_SECURE_SERVICES)
155 message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_SECURE_SERVICES is undefined. ")
156elseif (TFM_PARTITION_TEST_SECURE_SERVICES)
157 embedded_set_target_link_defines(TARGET ${PROJECT_NAME} DEFINES "TFM_PARTITION_TEST_SECURE_SERVICES")
158endif()
159
Tamas Ban581034a2017-12-19 19:54:37 +0000160#Set BL2 specific settings.
161if (NOT DEFINED BL2)
162 message(FATAL_ERROR "Incomplete build configuration: BL2 is undefined. ")
163elseif (BL2)
Mate Toth-Pal76867262018-03-09 13:15:36 +0100164 embedded_set_target_link_defines(TARGET ${PROJECT_NAME} DEFINES "BL2")
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000165endif()
166
167
168if(NOT TARGET tfm_s)
169 #We need access to the secure veneers. If the location is not already
170 #specified, then set it.
171 if (NOT DEFINED S_VENEER_FILE)
172 set(S_VENEER_FILE "${CMAKE_CURRENT_BINARY_DIR}/s_veneers.o")
173 endif()
174 add_subdirectory(../secure_fw ${CMAKE_CURRENT_BINARY_DIR}/secure_fw)
175endif()
176
177#We depend on the non secure tests. See if the library target is available.
178if(TARGET tfm_non_secure_tests)
179 #If yes, then use the library.
180 target_link_libraries(${PROJECT_NAME} tfm_non_secure_tests)
181 #Ensure library is built first.
182 #add_dependencies(${PROJECT_NAME} tfm_non_secure_tests)
183else()
184 #If not, add the test source to the build.
185 #As of today since secufre_fw is built as a sub-project this code will never
186 #execute.
187 option(ENABLE_INVERT_SERVICE_TESTS "" TRUE)
188 option(ENABLE_SECURE_STORAGE_SERVICE_TESTS "" TRUE)
189 include(../test/CMakeLists.inc)
190 target_sources(${PROJECT_NAME} PUBLIC ${ALL_SRC_C} ${ALL_SRC_C_NS})
191endif()
192
193#Ensure secure_fw is built before our executable.
194add_dependencies(${PROJECT_NAME} tfm_s)
195
196#Add the veneers to the executable.
197set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY LINK_LIBRARIES ${S_VENEER_FILE})
198
199#Finally let cmake system apply changes after the whole project is defined.
200embedded_project_end(${PROJECT_NAME})