blob: 46dfd262e9f1d7f198c09ee27860b511fcb9054e [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
62#Set include directories.
63embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${TFM_ROOT_DIR}/common/sct ABSOLUTE APPEND)
64embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${INTERFACE_DIR}/include ABSOLUTE APPEND)
65embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${TFM_ROOT_DIR} ABSOLUTE APPEND)
66embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${TFM_ROOT_DIR}/secure_fw/spm ABSOLUTE APPEND)
67embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${TFM_ROOT_DIR}/secure_fw/core ABSOLUTE APPEND)
68embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Include ABSOLUTE APPEND)
69embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${CMSIS_5_DIR}/CMSIS/RTOS2/Include ABSOLUTE APPEND)
70embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Config ABSOLUTE APPEND)
71
72#Create an executable
73add_executable(${PROJECT_NAME} ${ALL_SRC_C} ${ALL_SRC_C_NS} ${ALL_SRC_ASM_NS} ${NS_APP_SRC})
74#Add the RTX library
75target_link_libraries(${PROJECT_NAME} "${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Library/ARM/RTX_V8MMN.lib")
76#Set macro definitions
Tamas Ban581034a2017-12-19 19:54:37 +000077target_compile_definitions(${PROJECT_NAME} PRIVATE __thumb2__ __DOMAIN_NS=1 __ARM_FEATURE_CMSE=3 LOG_MSG_HANDLER_MODE_PRINTF_ENABLED)
78
79#Generate binary file from axf
80compiler_generate_binary_output(${PROJECT_NAME})
81
Mate Toth-Pal65c935e2018-01-17 18:42:13 +010082#Generate MCUBoot compatible payload
83if (BL2)
84 #Find Python3.x interpreter
85 find_package(PythonInterp 3)
86
Tamas Ban581034a2017-12-19 19:54:37 +000087 if (NOT PYTHONINTERP_FOUND)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +010088 message(FATAL_ERROR "Failed to find Python3.x interpreter. Pyhton3 must be installed an available on the PATH.")
Tamas Ban581034a2017-12-19 19:54:37 +000089 endif()
90
91 set(MCUBOOT_DIR ${TFM_ROOT_DIR}/bl2/ext/mcuboot)
92
93 add_custom_command(TARGET ${PROJECT_NAME}
94 POST_BUILD
95
96 #Create concatenated binary image from tfm_ns.bin and tfm_s.bin
97 COMMAND ${PYTHON_EXECUTABLE} ${MCUBOOT_DIR}/scripts/assemble.py
98 ARGS -s $<TARGET_FILE_DIR:tfm_s>/tfm_s.bin
99 -n $<TARGET_FILE_DIR:tfm_ns>/tfm_ns.bin
100 -o ${CMAKE_BINARY_DIR}/app/tfm_full.bin
101
102 #Sign concatenated binary image with default public key in mcuboot folder
103 COMMAND ${PYTHON_EXECUTABLE} ${MCUBOOT_DIR}/scripts/imgtool.py
104 ARGS sign
105 -k ${MCUBOOT_DIR}/root-rsa-2048.pem
106 --align 1
107 -v 1.0
Mate Toth-Pal74684d92018-01-17 19:15:47 +0100108 -H 0x400
Tamas Ban581034a2017-12-19 19:54:37 +0000109 --pad 0x100000
110 ${CMAKE_BINARY_DIR}/app/tfm_full.bin
111 ${CMAKE_BINARY_DIR}/app/tfm_sign.bin
112 )
113endif()
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000114
115if (NOT DEFINED CORE_TEST)
116 message(FATAL_ERROR "Incomplete build configuration: CORE_TEST is undefined. ")
117elseif(CORE_TEST)
118 target_compile_definitions(${PROJECT_NAME} PRIVATE CORE_TEST)
119endif()
120
121if (NOT DEFINED CORE_TEST_SERVICES)
122 message(FATAL_ERROR "Incomplete build configuration: CORE_TEST_SERVICES is undefined. ")
123elseif (CORE_TEST_SERVICES)
124 set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY LINK_FLAGS " --predefine=\"-DCORE_TEST_SERVICES\"")
125endif()
126
Tamas Ban581034a2017-12-19 19:54:37 +0000127#Set BL2 specific settings.
128if (NOT DEFINED BL2)
129 message(FATAL_ERROR "Incomplete build configuration: BL2 is undefined. ")
130elseif (BL2)
131 set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY LINK_FLAGS " --predefine=\"-DBL2\"")
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000132endif()
133
134
135if(NOT TARGET tfm_s)
136 #We need access to the secure veneers. If the location is not already
137 #specified, then set it.
138 if (NOT DEFINED S_VENEER_FILE)
139 set(S_VENEER_FILE "${CMAKE_CURRENT_BINARY_DIR}/s_veneers.o")
140 endif()
141 add_subdirectory(../secure_fw ${CMAKE_CURRENT_BINARY_DIR}/secure_fw)
142endif()
143
144#We depend on the non secure tests. See if the library target is available.
145if(TARGET tfm_non_secure_tests)
146 #If yes, then use the library.
147 target_link_libraries(${PROJECT_NAME} tfm_non_secure_tests)
148 #Ensure library is built first.
149 #add_dependencies(${PROJECT_NAME} tfm_non_secure_tests)
150else()
151 #If not, add the test source to the build.
152 #As of today since secufre_fw is built as a sub-project this code will never
153 #execute.
154 option(ENABLE_INVERT_SERVICE_TESTS "" TRUE)
155 option(ENABLE_SECURE_STORAGE_SERVICE_TESTS "" TRUE)
156 include(../test/CMakeLists.inc)
157 target_sources(${PROJECT_NAME} PUBLIC ${ALL_SRC_C} ${ALL_SRC_C_NS})
158endif()
159
160#Ensure secure_fw is built before our executable.
161add_dependencies(${PROJECT_NAME} tfm_s)
162
163#Add the veneers to the executable.
164set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY LINK_LIBRARIES ${S_VENEER_FILE})
165
166#Finally let cmake system apply changes after the whole project is defined.
167embedded_project_end(${PROJECT_NAME})