blob: c6572762e969e7d4a30fc9a62879eaf999265f0a [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"
41 "${INTERFACE_DIR}/src/tfm_id_mngr_dummy.c"
42 "${INTERFACE_DIR}/src/tfm_ns_lock_rtx.c"
43 )
44
Marc Moreno Berenguea1f296f2018-01-25 15:21:22 +000045set(BUILD_CMSIS_CORE On)
46set(BUILD_RETARGET On)
47set(BUILD_NATIVE_DRIVERS On)
48set(BUILD_TIME Off)
49set(BUILD_STARTUP On)
50set(BUILD_TARGET_CFG Off)
51set(BUILD_TARGET_HARDWARE_KEYS Off)
52set(BUILD_CMSIS_DRIVERS On)
53set(BUILD_UART_STDOUT Off)
54set(BUILD_FLASH Off)
55if(NOT DEFINED PLATFORM_CMAKE_FILE)
56 message (FATAL_ERROR "Platform specific CMake is not defined. Please set PLATFORM_CMAKE_FILE.")
57elseif(NOT EXISTS ${PLATFORM_CMAKE_FILE})
58 message (FATAL_ERROR "Platform specific CMake \"${PLATFORM_CMAKE_FILE}\" file does not exist. Please fix value of PLATFORM_CMAKE_FILE.")
59else()
60 include(${PLATFORM_CMAKE_FILE})
61endif()
Gyorgy Szing30fa9872017-12-05 01:08:47 +000062
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +010063if(NOT DEFINED NS_SCATTER_FILE_NAME)
64 message(FATAL_ERROR "ERROR: Incomplete Configuration: NS_SCATTER_FILE_NAME not defined, Include this file from a Config*.cmake")
65endif()
66embedded_set_target_linker_file(TARGET tfm_ns PATH "${NS_SCATTER_FILE_NAME}")
67
Gyorgy Szing30fa9872017-12-05 01:08:47 +000068#Set include directories.
69embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${TFM_ROOT_DIR}/common/sct ABSOLUTE APPEND)
Antonio de Angelis8ad3d3812018-04-13 16:48:00 +010070embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${TEST_INTERFACE_DIR}/include ABSOLUTE APPEND)
Gyorgy Szing30fa9872017-12-05 01:08:47 +000071embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${INTERFACE_DIR}/include ABSOLUTE APPEND)
72embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${TFM_ROOT_DIR} ABSOLUTE APPEND)
73embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${TFM_ROOT_DIR}/secure_fw/spm ABSOLUTE APPEND)
74embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${TFM_ROOT_DIR}/secure_fw/core ABSOLUTE APPEND)
75embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Include ABSOLUTE APPEND)
76embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${CMSIS_5_DIR}/CMSIS/RTOS2/Include ABSOLUTE APPEND)
77embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Config ABSOLUTE APPEND)
78
79#Create an executable
80add_executable(${PROJECT_NAME} ${ALL_SRC_C} ${ALL_SRC_C_NS} ${ALL_SRC_ASM_NS} ${NS_APP_SRC})
81#Add the RTX library
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +010082if(NOT DEFINED RTX_LIB_PATH)
83 message(FATAL_ERROR "ERROR: Incomplete Configuration: RTX_LIB_PATH is not defined.")
84endif()
85target_link_libraries(${PROJECT_NAME} "${RTX_LIB_PATH}")
Gyorgy Szing30fa9872017-12-05 01:08:47 +000086#Set macro definitions
Tamas Ban581034a2017-12-19 19:54:37 +000087target_compile_definitions(${PROJECT_NAME} PRIVATE __thumb2__ __DOMAIN_NS=1 __ARM_FEATURE_CMSE=3 LOG_MSG_HANDLER_MODE_PRINTF_ENABLED)
88
89#Generate binary file from axf
90compiler_generate_binary_output(${PROJECT_NAME})
91
Mate Toth-Pal65c935e2018-01-17 18:42:13 +010092#Generate MCUBoot compatible payload
93if (BL2)
94 #Find Python3.x interpreter
95 find_package(PythonInterp 3)
96
Tamas Ban581034a2017-12-19 19:54:37 +000097 if (NOT PYTHONINTERP_FOUND)
Avinash Mehta788036c2018-03-15 12:38:43 +000098 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 +000099 endif()
100
101 set(MCUBOOT_DIR ${TFM_ROOT_DIR}/bl2/ext/mcuboot)
102
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +0100103if(NOT DEFINED FLASH_LAYOUT)
104 message(FATAL_ERROR "ERROR: Incomplete Configuration: FLASH_LAYOUT is not defined.")
105endif()
106
Tamas Ban581034a2017-12-19 19:54:37 +0000107 add_custom_command(TARGET ${PROJECT_NAME}
108 POST_BUILD
109
110 #Create concatenated binary image from tfm_ns.bin and tfm_s.bin
111 COMMAND ${PYTHON_EXECUTABLE} ${MCUBOOT_DIR}/scripts/assemble.py
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +0100112 ARGS -l ${FLASH_LAYOUT}
113 -s $<TARGET_FILE_DIR:tfm_s>/tfm_s.bin
Tamas Ban581034a2017-12-19 19:54:37 +0000114 -n $<TARGET_FILE_DIR:tfm_ns>/tfm_ns.bin
Mate Toth-Pald577f0f2018-02-01 15:36:25 +0100115 -o ${CMAKE_BINARY_DIR}/tfm_full.bin
Tamas Ban581034a2017-12-19 19:54:37 +0000116
117 #Sign concatenated binary image with default public key in mcuboot folder
118 COMMAND ${PYTHON_EXECUTABLE} ${MCUBOOT_DIR}/scripts/imgtool.py
119 ARGS sign
120 -k ${MCUBOOT_DIR}/root-rsa-2048.pem
121 --align 1
122 -v 1.0
Mate Toth-Pal74684d92018-01-17 19:15:47 +0100123 -H 0x400
Avinash Mehta788036c2018-03-15 12:38:43 +0000124 --pad ${SIGN_BIN_SIZE}
Mate Toth-Pald577f0f2018-02-01 15:36:25 +0100125 ${CMAKE_BINARY_DIR}/tfm_full.bin
126 ${CMAKE_BINARY_DIR}/tfm_sign.bin
Tamas Ban581034a2017-12-19 19:54:37 +0000127 )
128endif()
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000129
130if (NOT DEFINED CORE_TEST)
131 message(FATAL_ERROR "Incomplete build configuration: CORE_TEST is undefined. ")
132elseif(CORE_TEST)
133 target_compile_definitions(${PROJECT_NAME} PRIVATE CORE_TEST)
134endif()
135
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100136if (NOT DEFINED TFM_PARTITION_TEST_CORE)
137 message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_CORE is undefined. ")
138elseif (TFM_PARTITION_TEST_CORE)
Mate Toth-Pal76867262018-03-09 13:15:36 +0100139 embedded_set_target_link_defines(TARGET ${PROJECT_NAME} DEFINES "TFM_PARTITION_TEST_CORE")
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000140endif()
141
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100142if (NOT DEFINED TFM_PARTITION_TEST_SST)
143 message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_SST is undefined. ")
144elseif (TFM_PARTITION_TEST_SST)
Mate Toth-Pal76867262018-03-09 13:15:36 +0100145 embedded_set_target_link_defines(TARGET ${PROJECT_NAME} DEFINES "TFM_PARTITION_TEST_SST")
Jamie Fox5592db02017-12-18 16:48:29 +0000146endif()
147
Tamas Ban581034a2017-12-19 19:54:37 +0000148#Set BL2 specific settings.
149if (NOT DEFINED BL2)
150 message(FATAL_ERROR "Incomplete build configuration: BL2 is undefined. ")
151elseif (BL2)
Mate Toth-Pal76867262018-03-09 13:15:36 +0100152 embedded_set_target_link_defines(TARGET ${PROJECT_NAME} DEFINES "BL2")
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000153endif()
154
155
156if(NOT TARGET tfm_s)
157 #We need access to the secure veneers. If the location is not already
158 #specified, then set it.
159 if (NOT DEFINED S_VENEER_FILE)
160 set(S_VENEER_FILE "${CMAKE_CURRENT_BINARY_DIR}/s_veneers.o")
161 endif()
162 add_subdirectory(../secure_fw ${CMAKE_CURRENT_BINARY_DIR}/secure_fw)
163endif()
164
165#We depend on the non secure tests. See if the library target is available.
166if(TARGET tfm_non_secure_tests)
167 #If yes, then use the library.
168 target_link_libraries(${PROJECT_NAME} tfm_non_secure_tests)
169 #Ensure library is built first.
170 #add_dependencies(${PROJECT_NAME} tfm_non_secure_tests)
171else()
172 #If not, add the test source to the build.
173 #As of today since secufre_fw is built as a sub-project this code will never
174 #execute.
175 option(ENABLE_INVERT_SERVICE_TESTS "" TRUE)
176 option(ENABLE_SECURE_STORAGE_SERVICE_TESTS "" TRUE)
177 include(../test/CMakeLists.inc)
178 target_sources(${PROJECT_NAME} PUBLIC ${ALL_SRC_C} ${ALL_SRC_C_NS})
179endif()
180
181#Ensure secure_fw is built before our executable.
182add_dependencies(${PROJECT_NAME} tfm_s)
183
184#Add the veneers to the executable.
185set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY LINK_LIBRARIES ${S_VENEER_FILE})
186
187#Finally let cmake system apply changes after the whole project is defined.
188embedded_project_end(${PROJECT_NAME})