blob: 691c1e1f2097dce2d499131f92ad0a4db804c1a5 [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()
68embedded_set_target_linker_file(TARGET tfm_ns PATH "${NS_SCATTER_FILE_NAME}")
69
Gyorgy Szing30fa9872017-12-05 01:08:47 +000070#Set include directories.
71embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${TFM_ROOT_DIR}/common/sct ABSOLUTE APPEND)
Antonio de Angelis8ad3d3812018-04-13 16:48:00 +010072embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${TEST_INTERFACE_DIR}/include ABSOLUTE APPEND)
Gyorgy Szing30fa9872017-12-05 01:08:47 +000073embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${INTERFACE_DIR}/include ABSOLUTE APPEND)
74embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${TFM_ROOT_DIR} ABSOLUTE APPEND)
75embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${TFM_ROOT_DIR}/secure_fw/spm ABSOLUTE APPEND)
76embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${TFM_ROOT_DIR}/secure_fw/core ABSOLUTE APPEND)
77embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Include ABSOLUTE APPEND)
78embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${CMSIS_5_DIR}/CMSIS/RTOS2/Include ABSOLUTE APPEND)
79embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Config ABSOLUTE APPEND)
80
81#Create an executable
82add_executable(${PROJECT_NAME} ${ALL_SRC_C} ${ALL_SRC_C_NS} ${ALL_SRC_ASM_NS} ${NS_APP_SRC})
83#Add the RTX library
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +010084if(NOT DEFINED RTX_LIB_PATH)
85 message(FATAL_ERROR "ERROR: Incomplete Configuration: RTX_LIB_PATH is not defined.")
86endif()
87target_link_libraries(${PROJECT_NAME} "${RTX_LIB_PATH}")
Gyorgy Szing30fa9872017-12-05 01:08:47 +000088#Set macro definitions
Tamas Ban581034a2017-12-19 19:54:37 +000089target_compile_definitions(${PROJECT_NAME} PRIVATE __thumb2__ __DOMAIN_NS=1 __ARM_FEATURE_CMSE=3 LOG_MSG_HANDLER_MODE_PRINTF_ENABLED)
90
91#Generate binary file from axf
92compiler_generate_binary_output(${PROJECT_NAME})
93
Mate Toth-Pal65c935e2018-01-17 18:42:13 +010094#Generate MCUBoot compatible payload
95if (BL2)
96 #Find Python3.x interpreter
97 find_package(PythonInterp 3)
98
Tamas Ban581034a2017-12-19 19:54:37 +000099 if (NOT PYTHONINTERP_FOUND)
Avinash Mehta788036c2018-03-15 12:38:43 +0000100 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 +0000101 endif()
102
103 set(MCUBOOT_DIR ${TFM_ROOT_DIR}/bl2/ext/mcuboot)
104
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +0100105if(NOT DEFINED FLASH_LAYOUT)
106 message(FATAL_ERROR "ERROR: Incomplete Configuration: FLASH_LAYOUT is not defined.")
107endif()
108
Tamas Ban581034a2017-12-19 19:54:37 +0000109 add_custom_command(TARGET ${PROJECT_NAME}
110 POST_BUILD
111
112 #Create concatenated binary image from tfm_ns.bin and tfm_s.bin
113 COMMAND ${PYTHON_EXECUTABLE} ${MCUBOOT_DIR}/scripts/assemble.py
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +0100114 ARGS -l ${FLASH_LAYOUT}
115 -s $<TARGET_FILE_DIR:tfm_s>/tfm_s.bin
Tamas Ban581034a2017-12-19 19:54:37 +0000116 -n $<TARGET_FILE_DIR:tfm_ns>/tfm_ns.bin
Mate Toth-Pald577f0f2018-02-01 15:36:25 +0100117 -o ${CMAKE_BINARY_DIR}/tfm_full.bin
Tamas Ban581034a2017-12-19 19:54:37 +0000118
119 #Sign concatenated binary image with default public key in mcuboot folder
120 COMMAND ${PYTHON_EXECUTABLE} ${MCUBOOT_DIR}/scripts/imgtool.py
121 ARGS sign
122 -k ${MCUBOOT_DIR}/root-rsa-2048.pem
123 --align 1
124 -v 1.0
Mate Toth-Pal74684d92018-01-17 19:15:47 +0100125 -H 0x400
Avinash Mehta788036c2018-03-15 12:38:43 +0000126 --pad ${SIGN_BIN_SIZE}
Mate Toth-Pald577f0f2018-02-01 15:36:25 +0100127 ${CMAKE_BINARY_DIR}/tfm_full.bin
128 ${CMAKE_BINARY_DIR}/tfm_sign.bin
Tamas Ban581034a2017-12-19 19:54:37 +0000129 )
130endif()
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000131
132if (NOT DEFINED CORE_TEST)
133 message(FATAL_ERROR "Incomplete build configuration: CORE_TEST is undefined. ")
134elseif(CORE_TEST)
135 target_compile_definitions(${PROJECT_NAME} PRIVATE CORE_TEST)
136endif()
137
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100138if (NOT DEFINED TFM_PARTITION_TEST_CORE)
139 message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_CORE is undefined. ")
140elseif (TFM_PARTITION_TEST_CORE)
Mate Toth-Pal76867262018-03-09 13:15:36 +0100141 embedded_set_target_link_defines(TARGET ${PROJECT_NAME} DEFINES "TFM_PARTITION_TEST_CORE")
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000142endif()
143
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100144if (NOT DEFINED TFM_PARTITION_TEST_SST)
145 message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_SST is undefined. ")
146elseif (TFM_PARTITION_TEST_SST)
Mate Toth-Pal76867262018-03-09 13:15:36 +0100147 embedded_set_target_link_defines(TARGET ${PROJECT_NAME} DEFINES "TFM_PARTITION_TEST_SST")
Jamie Fox5592db02017-12-18 16:48:29 +0000148endif()
149
Tamas Ban581034a2017-12-19 19:54:37 +0000150#Set BL2 specific settings.
151if (NOT DEFINED BL2)
152 message(FATAL_ERROR "Incomplete build configuration: BL2 is undefined. ")
153elseif (BL2)
Mate Toth-Pal76867262018-03-09 13:15:36 +0100154 embedded_set_target_link_defines(TARGET ${PROJECT_NAME} DEFINES "BL2")
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000155endif()
156
157
158if(NOT TARGET tfm_s)
159 #We need access to the secure veneers. If the location is not already
160 #specified, then set it.
161 if (NOT DEFINED S_VENEER_FILE)
162 set(S_VENEER_FILE "${CMAKE_CURRENT_BINARY_DIR}/s_veneers.o")
163 endif()
164 add_subdirectory(../secure_fw ${CMAKE_CURRENT_BINARY_DIR}/secure_fw)
165endif()
166
167#We depend on the non secure tests. See if the library target is available.
168if(TARGET tfm_non_secure_tests)
169 #If yes, then use the library.
170 target_link_libraries(${PROJECT_NAME} tfm_non_secure_tests)
171 #Ensure library is built first.
172 #add_dependencies(${PROJECT_NAME} tfm_non_secure_tests)
173else()
174 #If not, add the test source to the build.
175 #As of today since secufre_fw is built as a sub-project this code will never
176 #execute.
177 option(ENABLE_INVERT_SERVICE_TESTS "" TRUE)
178 option(ENABLE_SECURE_STORAGE_SERVICE_TESTS "" TRUE)
179 include(../test/CMakeLists.inc)
180 target_sources(${PROJECT_NAME} PUBLIC ${ALL_SRC_C} ${ALL_SRC_C_NS})
181endif()
182
183#Ensure secure_fw is built before our executable.
184add_dependencies(${PROJECT_NAME} tfm_s)
185
186#Add the veneers to the executable.
187set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY LINK_LIBRARIES ${S_VENEER_FILE})
188
189#Finally let cmake system apply changes after the whole project is defined.
190embedded_project_end(${PROJECT_NAME})