blob: 7a43f94bb0010c0630316b1dc9f88e5163db7072 [file] [log] [blame]
Gyorgy Szing30fa9872017-12-05 01:08:47 +00001#-------------------------------------------------------------------------------
2# Copyright (c) 2017, Arm Limited. All rights reserved.
3#
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
44set(MPS2_SSE200_BUILD_CMSIS_CORE On)
45set(MPS2_SSE200_BUILD_RETARGET On)
46set(MPS2_SSE200_BUILD_NATIVE_DRIVERS On)
47set(MPS2_SSE200_BUILD_MPS2_TIME Off)
48set(MPS2_SSE200_BUILD_STARTUP On)
49set(MPS2_SSE200_BUILD_TARGET_CFG Off)
50set(MPS2_SSE200_BUILD_TARGET_HARDWARE_KEYS Off)
51set(MPS2_SSE200_BUILD_CMSIS_DRIVERS On)
52set(MPS2_SSE200_BUILD_UART_STDOUT Off)
53set(MPS2_SSE200_BUILD_MPS2_BOARD_LEDS On)
54set(MPS2_SSE200_BUILD_MPS2_BOARD_TIME On)
Tamas Ban581034a2017-12-19 19:54:37 +000055set(MPS2_SSE200_BUILD_MPS2_BOARD_FLASH Off)
Gyorgy Szing30fa9872017-12-05 01:08:47 +000056include(${TFM_ROOT_DIR}/platform/ext/Mps2SSE200.cmake)
57
58#Set include directories.
59embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${TFM_ROOT_DIR}/common/sct ABSOLUTE APPEND)
60embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${INTERFACE_DIR}/include ABSOLUTE APPEND)
61embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${TFM_ROOT_DIR} ABSOLUTE APPEND)
62embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${TFM_ROOT_DIR}/secure_fw/spm ABSOLUTE APPEND)
63embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${TFM_ROOT_DIR}/secure_fw/core ABSOLUTE APPEND)
64embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Include ABSOLUTE APPEND)
65embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${CMSIS_5_DIR}/CMSIS/RTOS2/Include ABSOLUTE APPEND)
66embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Config ABSOLUTE APPEND)
67
68#Create an executable
69add_executable(${PROJECT_NAME} ${ALL_SRC_C} ${ALL_SRC_C_NS} ${ALL_SRC_ASM_NS} ${NS_APP_SRC})
70#Add the RTX library
71target_link_libraries(${PROJECT_NAME} "${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Library/ARM/RTX_V8MMN.lib")
72#Set macro definitions
Tamas Ban581034a2017-12-19 19:54:37 +000073target_compile_definitions(${PROJECT_NAME} PRIVATE __thumb2__ __DOMAIN_NS=1 __ARM_FEATURE_CMSE=3 LOG_MSG_HANDLER_MODE_PRINTF_ENABLED)
74
75#Generate binary file from axf
76compiler_generate_binary_output(${PROJECT_NAME})
77
Mate Toth-Pal65c935e2018-01-17 18:42:13 +010078#Generate MCUBoot compatible payload
79if (BL2)
80 #Find Python3.x interpreter
81 find_package(PythonInterp 3)
82
Tamas Ban581034a2017-12-19 19:54:37 +000083 if (NOT PYTHONINTERP_FOUND)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +010084 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 +000085 endif()
86
87 set(MCUBOOT_DIR ${TFM_ROOT_DIR}/bl2/ext/mcuboot)
88
89 add_custom_command(TARGET ${PROJECT_NAME}
90 POST_BUILD
91
92 #Create concatenated binary image from tfm_ns.bin and tfm_s.bin
93 COMMAND ${PYTHON_EXECUTABLE} ${MCUBOOT_DIR}/scripts/assemble.py
94 ARGS -s $<TARGET_FILE_DIR:tfm_s>/tfm_s.bin
95 -n $<TARGET_FILE_DIR:tfm_ns>/tfm_ns.bin
96 -o ${CMAKE_BINARY_DIR}/app/tfm_full.bin
97
98 #Sign concatenated binary image with default public key in mcuboot folder
99 COMMAND ${PYTHON_EXECUTABLE} ${MCUBOOT_DIR}/scripts/imgtool.py
100 ARGS sign
101 -k ${MCUBOOT_DIR}/root-rsa-2048.pem
102 --align 1
103 -v 1.0
104 -H 0x200
105 --pad 0x100000
106 ${CMAKE_BINARY_DIR}/app/tfm_full.bin
107 ${CMAKE_BINARY_DIR}/app/tfm_sign.bin
108 )
109endif()
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000110
111if (NOT DEFINED CORE_TEST)
112 message(FATAL_ERROR "Incomplete build configuration: CORE_TEST is undefined. ")
113elseif(CORE_TEST)
114 target_compile_definitions(${PROJECT_NAME} PRIVATE CORE_TEST)
115endif()
116
117if (NOT DEFINED CORE_TEST_SERVICES)
118 message(FATAL_ERROR "Incomplete build configuration: CORE_TEST_SERVICES is undefined. ")
119elseif (CORE_TEST_SERVICES)
120 set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY LINK_FLAGS " --predefine=\"-DCORE_TEST_SERVICES\"")
121endif()
122
Tamas Ban581034a2017-12-19 19:54:37 +0000123#Set BL2 specific settings.
124if (NOT DEFINED BL2)
125 message(FATAL_ERROR "Incomplete build configuration: BL2 is undefined. ")
126elseif (BL2)
127 set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY LINK_FLAGS " --predefine=\"-DBL2\"")
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000128endif()
129
130
131if(NOT TARGET tfm_s)
132 #We need access to the secure veneers. If the location is not already
133 #specified, then set it.
134 if (NOT DEFINED S_VENEER_FILE)
135 set(S_VENEER_FILE "${CMAKE_CURRENT_BINARY_DIR}/s_veneers.o")
136 endif()
137 add_subdirectory(../secure_fw ${CMAKE_CURRENT_BINARY_DIR}/secure_fw)
138endif()
139
140#We depend on the non secure tests. See if the library target is available.
141if(TARGET tfm_non_secure_tests)
142 #If yes, then use the library.
143 target_link_libraries(${PROJECT_NAME} tfm_non_secure_tests)
144 #Ensure library is built first.
145 #add_dependencies(${PROJECT_NAME} tfm_non_secure_tests)
146else()
147 #If not, add the test source to the build.
148 #As of today since secufre_fw is built as a sub-project this code will never
149 #execute.
150 option(ENABLE_INVERT_SERVICE_TESTS "" TRUE)
151 option(ENABLE_SECURE_STORAGE_SERVICE_TESTS "" TRUE)
152 include(../test/CMakeLists.inc)
153 target_sources(${PROJECT_NAME} PUBLIC ${ALL_SRC_C} ${ALL_SRC_C_NS})
154endif()
155
156#Ensure secure_fw is built before our executable.
157add_dependencies(${PROJECT_NAME} tfm_s)
158
159#Add the veneers to the executable.
160set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY LINK_LIBRARIES ${S_VENEER_FILE})
161
162#Finally let cmake system apply changes after the whole project is defined.
163embedded_project_end(${PROJECT_NAME})