blob: e849ebe1ccc7708e5060affde7dab7495aa15513 [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)
24
25#Set variables
26get_filename_component(CMSIS_5_DIR ${TFM_ROOT_DIR}/../CMSIS_5 ABSOLUTE)
27
28if(NOT EXISTS ${CMSIS_5_DIR})
29 message(FATAL_ERROR "Missing CMSIS_5. Please clone the CMSIS_5 repo to directory \"${CMSIS_5_DIR}\".")
30endif()
31
32set(NS_APP_SRC "${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Config/RTX_Config.c"
33 "${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Source/rtx_lib.c"
34 "${APP_DIR}/main_ns.c"
35 "${APP_DIR}/ext/tz_context.c"
36 "${APP_DIR}/tfm_integ_test.c"
37 "${APP_DIR}/os_wrapper_rtx.c"
38 "${INTERFACE_DIR}/src/tfm_sst_api.c"
39 "${INTERFACE_DIR}/src/tfm_sst_svc_handler.c"
40 "${INTERFACE_DIR}/src/tfm_id_mngr_dummy.c"
41 "${INTERFACE_DIR}/src/tfm_ns_lock_rtx.c"
42 )
43
Marc Moreno Berenguea1f296f2018-01-25 15:21:22 +000044set(BUILD_CMSIS_CORE On)
45set(BUILD_RETARGET On)
46set(BUILD_NATIVE_DRIVERS On)
47set(BUILD_TIME Off)
48set(BUILD_STARTUP On)
49set(BUILD_TARGET_CFG Off)
50set(BUILD_TARGET_HARDWARE_KEYS Off)
51set(BUILD_CMSIS_DRIVERS On)
52set(BUILD_UART_STDOUT Off)
53set(BUILD_FLASH Off)
54if(NOT DEFINED PLATFORM_CMAKE_FILE)
55 message (FATAL_ERROR "Platform specific CMake is not defined. Please set PLATFORM_CMAKE_FILE.")
56elseif(NOT EXISTS ${PLATFORM_CMAKE_FILE})
57 message (FATAL_ERROR "Platform specific CMake \"${PLATFORM_CMAKE_FILE}\" file does not exist. Please fix value of PLATFORM_CMAKE_FILE.")
58else()
59 include(${PLATFORM_CMAKE_FILE})
60endif()
Gyorgy Szing30fa9872017-12-05 01:08:47 +000061
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +010062if(NOT DEFINED NS_SCATTER_FILE_NAME)
63 message(FATAL_ERROR "ERROR: Incomplete Configuration: NS_SCATTER_FILE_NAME not defined, Include this file from a Config*.cmake")
64endif()
65embedded_set_target_linker_file(TARGET tfm_ns PATH "${NS_SCATTER_FILE_NAME}")
66
Gyorgy Szing30fa9872017-12-05 01:08:47 +000067#Set include directories.
68embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${TFM_ROOT_DIR}/common/sct ABSOLUTE APPEND)
69embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${INTERFACE_DIR}/include ABSOLUTE APPEND)
70embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${TFM_ROOT_DIR} ABSOLUTE APPEND)
71embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${TFM_ROOT_DIR}/secure_fw/spm ABSOLUTE APPEND)
72embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${TFM_ROOT_DIR}/secure_fw/core ABSOLUTE APPEND)
73embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Include ABSOLUTE APPEND)
74embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${CMSIS_5_DIR}/CMSIS/RTOS2/Include ABSOLUTE APPEND)
75embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Config ABSOLUTE APPEND)
76
77#Create an executable
78add_executable(${PROJECT_NAME} ${ALL_SRC_C} ${ALL_SRC_C_NS} ${ALL_SRC_ASM_NS} ${NS_APP_SRC})
79#Add the RTX library
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +010080if(NOT DEFINED RTX_LIB_PATH)
81 message(FATAL_ERROR "ERROR: Incomplete Configuration: RTX_LIB_PATH is not defined.")
82endif()
83target_link_libraries(${PROJECT_NAME} "${RTX_LIB_PATH}")
Gyorgy Szing30fa9872017-12-05 01:08:47 +000084#Set macro definitions
Tamas Ban581034a2017-12-19 19:54:37 +000085target_compile_definitions(${PROJECT_NAME} PRIVATE __thumb2__ __DOMAIN_NS=1 __ARM_FEATURE_CMSE=3 LOG_MSG_HANDLER_MODE_PRINTF_ENABLED)
86
87#Generate binary file from axf
88compiler_generate_binary_output(${PROJECT_NAME})
89
Mate Toth-Pal65c935e2018-01-17 18:42:13 +010090#Generate MCUBoot compatible payload
91if (BL2)
92 #Find Python3.x interpreter
93 find_package(PythonInterp 3)
94
Tamas Ban581034a2017-12-19 19:54:37 +000095 if (NOT PYTHONINTERP_FOUND)
Avinash Mehta788036c2018-03-15 12:38:43 +000096 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 +000097 endif()
98
99 set(MCUBOOT_DIR ${TFM_ROOT_DIR}/bl2/ext/mcuboot)
100
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +0100101if(NOT DEFINED FLASH_LAYOUT)
102 message(FATAL_ERROR "ERROR: Incomplete Configuration: FLASH_LAYOUT is not defined.")
103endif()
104
Tamas Ban581034a2017-12-19 19:54:37 +0000105 add_custom_command(TARGET ${PROJECT_NAME}
106 POST_BUILD
107
108 #Create concatenated binary image from tfm_ns.bin and tfm_s.bin
109 COMMAND ${PYTHON_EXECUTABLE} ${MCUBOOT_DIR}/scripts/assemble.py
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +0100110 ARGS -l ${FLASH_LAYOUT}
111 -s $<TARGET_FILE_DIR:tfm_s>/tfm_s.bin
Tamas Ban581034a2017-12-19 19:54:37 +0000112 -n $<TARGET_FILE_DIR:tfm_ns>/tfm_ns.bin
Mate Toth-Pald577f0f2018-02-01 15:36:25 +0100113 -o ${CMAKE_BINARY_DIR}/tfm_full.bin
Tamas Ban581034a2017-12-19 19:54:37 +0000114
115 #Sign concatenated binary image with default public key in mcuboot folder
116 COMMAND ${PYTHON_EXECUTABLE} ${MCUBOOT_DIR}/scripts/imgtool.py
117 ARGS sign
118 -k ${MCUBOOT_DIR}/root-rsa-2048.pem
119 --align 1
120 -v 1.0
Mate Toth-Pal74684d92018-01-17 19:15:47 +0100121 -H 0x400
Avinash Mehta788036c2018-03-15 12:38:43 +0000122 --pad ${SIGN_BIN_SIZE}
Mate Toth-Pald577f0f2018-02-01 15:36:25 +0100123 ${CMAKE_BINARY_DIR}/tfm_full.bin
124 ${CMAKE_BINARY_DIR}/tfm_sign.bin
Tamas Ban581034a2017-12-19 19:54:37 +0000125 )
126endif()
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000127
128if (NOT DEFINED CORE_TEST)
129 message(FATAL_ERROR "Incomplete build configuration: CORE_TEST is undefined. ")
130elseif(CORE_TEST)
131 target_compile_definitions(${PROJECT_NAME} PRIVATE CORE_TEST)
132endif()
133
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100134if (NOT DEFINED TFM_PARTITION_TEST_CORE)
135 message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_CORE is undefined. ")
136elseif (TFM_PARTITION_TEST_CORE)
137 set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY LINK_FLAGS " --predefine=\"-DTFM_PARTITION_TEST_CORE\"")
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000138endif()
139
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100140if (NOT DEFINED TFM_PARTITION_TEST_SST)
141 message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_SST is undefined. ")
142elseif (TFM_PARTITION_TEST_SST)
143 set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY LINK_FLAGS " --predefine=\"-DTFM_PARTITION_TEST_SST\"")
Jamie Fox5592db02017-12-18 16:48:29 +0000144endif()
145
Tamas Ban581034a2017-12-19 19:54:37 +0000146#Set BL2 specific settings.
147if (NOT DEFINED BL2)
148 message(FATAL_ERROR "Incomplete build configuration: BL2 is undefined. ")
149elseif (BL2)
150 set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY LINK_FLAGS " --predefine=\"-DBL2\"")
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000151endif()
152
153
154if(NOT TARGET tfm_s)
155 #We need access to the secure veneers. If the location is not already
156 #specified, then set it.
157 if (NOT DEFINED S_VENEER_FILE)
158 set(S_VENEER_FILE "${CMAKE_CURRENT_BINARY_DIR}/s_veneers.o")
159 endif()
160 add_subdirectory(../secure_fw ${CMAKE_CURRENT_BINARY_DIR}/secure_fw)
161endif()
162
163#We depend on the non secure tests. See if the library target is available.
164if(TARGET tfm_non_secure_tests)
165 #If yes, then use the library.
166 target_link_libraries(${PROJECT_NAME} tfm_non_secure_tests)
167 #Ensure library is built first.
168 #add_dependencies(${PROJECT_NAME} tfm_non_secure_tests)
169else()
170 #If not, add the test source to the build.
171 #As of today since secufre_fw is built as a sub-project this code will never
172 #execute.
173 option(ENABLE_INVERT_SERVICE_TESTS "" TRUE)
174 option(ENABLE_SECURE_STORAGE_SERVICE_TESTS "" TRUE)
175 include(../test/CMakeLists.inc)
176 target_sources(${PROJECT_NAME} PUBLIC ${ALL_SRC_C} ${ALL_SRC_C_NS})
177endif()
178
179#Ensure secure_fw is built before our executable.
180add_dependencies(${PROJECT_NAME} tfm_s)
181
182#Add the veneers to the executable.
183set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY LINK_LIBRARIES ${S_VENEER_FILE})
184
185#Finally let cmake system apply changes after the whole project is defined.
186embedded_project_end(${PROJECT_NAME})