Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 1 | #------------------------------------------------------------------------------- |
Mate Toth-Pal | 74684d9 | 2018-01-17 19:15:47 +0100 | [diff] [blame^] | 2 | # Copyright (c) 2017-2018, Arm Limited. All rights reserved. |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | # |
| 6 | #------------------------------------------------------------------------------- |
| 7 | |
| 8 | cmake_minimum_required(VERSION 3.7) |
| 9 | |
| 10 | #Tell cmake where our modules can be found |
| 11 | list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../cmake) |
| 12 | |
| 13 | #Include common stuff to control cmake. |
| 14 | include("Common/BuildSys") |
| 15 | |
| 16 | #Start an embedded project. |
| 17 | embedded_project_start(CONFIG "${CMAKE_CURRENT_LIST_DIR}/../ConfigDefault.cmake") |
| 18 | project(tfm_ns LANGUAGES ASM C) |
| 19 | embedded_project_fixup() |
| 20 | |
| 21 | set(APP_DIR ${CMAKE_CURRENT_LIST_DIR}) |
| 22 | get_filename_component(TFM_ROOT_DIR ${APP_DIR}/.. ABSOLUTE) |
| 23 | set(INTERFACE_DIR ${TFM_ROOT_DIR}/interface) |
| 24 | |
| 25 | #Set variables |
| 26 | get_filename_component(CMSIS_5_DIR ${TFM_ROOT_DIR}/../CMSIS_5 ABSOLUTE) |
| 27 | |
| 28 | if(NOT EXISTS ${CMSIS_5_DIR}) |
| 29 | message(FATAL_ERROR "Missing CMSIS_5. Please clone the CMSIS_5 repo to directory \"${CMSIS_5_DIR}\".") |
| 30 | endif() |
| 31 | |
| 32 | set(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 | |
| 44 | set(MPS2_SSE200_BUILD_CMSIS_CORE On) |
| 45 | set(MPS2_SSE200_BUILD_RETARGET On) |
| 46 | set(MPS2_SSE200_BUILD_NATIVE_DRIVERS On) |
| 47 | set(MPS2_SSE200_BUILD_MPS2_TIME Off) |
| 48 | set(MPS2_SSE200_BUILD_STARTUP On) |
| 49 | set(MPS2_SSE200_BUILD_TARGET_CFG Off) |
| 50 | set(MPS2_SSE200_BUILD_TARGET_HARDWARE_KEYS Off) |
| 51 | set(MPS2_SSE200_BUILD_CMSIS_DRIVERS On) |
| 52 | set(MPS2_SSE200_BUILD_UART_STDOUT Off) |
| 53 | set(MPS2_SSE200_BUILD_MPS2_BOARD_LEDS On) |
| 54 | set(MPS2_SSE200_BUILD_MPS2_BOARD_TIME On) |
Tamas Ban | 581034a | 2017-12-19 19:54:37 +0000 | [diff] [blame] | 55 | set(MPS2_SSE200_BUILD_MPS2_BOARD_FLASH Off) |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 56 | include(${TFM_ROOT_DIR}/platform/ext/Mps2SSE200.cmake) |
| 57 | |
| 58 | #Set include directories. |
| 59 | embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${TFM_ROOT_DIR}/common/sct ABSOLUTE APPEND) |
| 60 | embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${INTERFACE_DIR}/include ABSOLUTE APPEND) |
| 61 | embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${TFM_ROOT_DIR} ABSOLUTE APPEND) |
| 62 | embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${TFM_ROOT_DIR}/secure_fw/spm ABSOLUTE APPEND) |
| 63 | embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${TFM_ROOT_DIR}/secure_fw/core ABSOLUTE APPEND) |
| 64 | embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Include ABSOLUTE APPEND) |
| 65 | embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${CMSIS_5_DIR}/CMSIS/RTOS2/Include ABSOLUTE APPEND) |
| 66 | embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Config ABSOLUTE APPEND) |
| 67 | |
| 68 | #Create an executable |
| 69 | add_executable(${PROJECT_NAME} ${ALL_SRC_C} ${ALL_SRC_C_NS} ${ALL_SRC_ASM_NS} ${NS_APP_SRC}) |
| 70 | #Add the RTX library |
| 71 | target_link_libraries(${PROJECT_NAME} "${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Library/ARM/RTX_V8MMN.lib") |
| 72 | #Set macro definitions |
Tamas Ban | 581034a | 2017-12-19 19:54:37 +0000 | [diff] [blame] | 73 | target_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 |
| 76 | compiler_generate_binary_output(${PROJECT_NAME}) |
| 77 | |
Mate Toth-Pal | 65c935e | 2018-01-17 18:42:13 +0100 | [diff] [blame] | 78 | #Generate MCUBoot compatible payload |
| 79 | if (BL2) |
| 80 | #Find Python3.x interpreter |
| 81 | find_package(PythonInterp 3) |
| 82 | |
Tamas Ban | 581034a | 2017-12-19 19:54:37 +0000 | [diff] [blame] | 83 | if (NOT PYTHONINTERP_FOUND) |
Mate Toth-Pal | 65c935e | 2018-01-17 18:42:13 +0100 | [diff] [blame] | 84 | message(FATAL_ERROR "Failed to find Python3.x interpreter. Pyhton3 must be installed an available on the PATH.") |
Tamas Ban | 581034a | 2017-12-19 19:54:37 +0000 | [diff] [blame] | 85 | 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 |
Mate Toth-Pal | 74684d9 | 2018-01-17 19:15:47 +0100 | [diff] [blame^] | 104 | -H 0x400 |
Tamas Ban | 581034a | 2017-12-19 19:54:37 +0000 | [diff] [blame] | 105 | --pad 0x100000 |
| 106 | ${CMAKE_BINARY_DIR}/app/tfm_full.bin |
| 107 | ${CMAKE_BINARY_DIR}/app/tfm_sign.bin |
| 108 | ) |
| 109 | endif() |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 110 | |
| 111 | if (NOT DEFINED CORE_TEST) |
| 112 | message(FATAL_ERROR "Incomplete build configuration: CORE_TEST is undefined. ") |
| 113 | elseif(CORE_TEST) |
| 114 | target_compile_definitions(${PROJECT_NAME} PRIVATE CORE_TEST) |
| 115 | endif() |
| 116 | |
| 117 | if (NOT DEFINED CORE_TEST_SERVICES) |
| 118 | message(FATAL_ERROR "Incomplete build configuration: CORE_TEST_SERVICES is undefined. ") |
| 119 | elseif (CORE_TEST_SERVICES) |
| 120 | set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY LINK_FLAGS " --predefine=\"-DCORE_TEST_SERVICES\"") |
| 121 | endif() |
| 122 | |
Tamas Ban | 581034a | 2017-12-19 19:54:37 +0000 | [diff] [blame] | 123 | #Set BL2 specific settings. |
| 124 | if (NOT DEFINED BL2) |
| 125 | message(FATAL_ERROR "Incomplete build configuration: BL2 is undefined. ") |
| 126 | elseif (BL2) |
| 127 | set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY LINK_FLAGS " --predefine=\"-DBL2\"") |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 128 | endif() |
| 129 | |
| 130 | |
| 131 | if(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) |
| 138 | endif() |
| 139 | |
| 140 | #We depend on the non secure tests. See if the library target is available. |
| 141 | if(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) |
| 146 | else() |
| 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}) |
| 154 | endif() |
| 155 | |
| 156 | #Ensure secure_fw is built before our executable. |
| 157 | add_dependencies(${PROJECT_NAME} tfm_s) |
| 158 | |
| 159 | #Add the veneers to the executable. |
| 160 | set_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. |
| 163 | embedded_project_end(${PROJECT_NAME}) |