diff options
author | David Hu <david.hu@arm.com> | 2019-05-21 13:54:50 +0800 |
---|---|---|
committer | David Hu <david.hu@arm.com> | 2019-07-22 13:55:03 +0800 |
commit | 061198aeedffc588ae72fec0347e93c864ec4aa9 (patch) | |
tree | 94ebf18f6c293e1b0263bde6a3e665cf2a2a2a29 | |
parent | cb473975558c1a04e53212616ddacb6c12a359d4 (diff) | |
download | trusted-firmware-m-061198aeedffc588ae72fec0347e93c864ec4aa9.tar.gz |
Twincpu: Support building multi-core TF-M in a single building execution
Enable building multi-core TF-M in a single building execution.
- Add MultiCore.cmake to support bulding in multi-core scenario.
Provide functions to platform specific cmake script to select
secure or non-secure configuration, including cpu type and
platform specific definitions.
- Add a building flag TFM_BUILD_IN_SPE to indicate whether current
building is for SPE or not.
- According to TFM_BUILD_IN_SPE flag value, select corresponding
configuration.
Change-Id: Ic1aca49190af9a9a5ec8ef1b855239a839fabe65
Signed-off-by: David Hu <david.hu@arm.com>
-rw-r--r-- | CommonConfig.cmake | 15 | ||||
-rw-r--r-- | app/CMakeLists.txt | 2 | ||||
-rw-r--r-- | bl2/ext/mcuboot/CMakeLists.txt | 10 | ||||
-rw-r--r-- | cmake/Common/MultiCore.cmake | 88 | ||||
-rw-r--r-- | secure_fw/CMakeLists.txt | 8 |
5 files changed, 121 insertions, 2 deletions
diff --git a/CommonConfig.cmake b/CommonConfig.cmake index c033bb60bd..38cd989c87 100644 --- a/CommonConfig.cmake +++ b/CommonConfig.cmake @@ -55,6 +55,19 @@ if (NOT DEFINED IMAGE_VERSION) set(IMAGE_VERSION 0.0.0+0) endif() +# Select the corresponding CPU type and configuration according to current +# building status in multi-core scenario. +# The updated configuration will be used in following compiler setting. +if (DEFINED TFM_MULTI_CORE_TOPOLOGY AND TFM_MULTI_CORE_TOPOLOGY) + include("Common/MultiCore") + + if (NOT DEFINED TFM_BUILD_IN_SPE) + message(FATAL_ERROR "Flag of building in SPE is not specified. Please set TFM_BUILD_IN_SPE.") + else() + select_arm_cpu_type(${TFM_BUILD_IN_SPE}) + endif() +endif() + if (DEFINED TFM_MULTI_CORE_TOPOLOGY AND TFM_MULTI_CORE_TOPOLOGY) # CMSE is unnecessary in multi-core scenarios. # TODO: Need further discussion about if CMSE is required when an Armv8-M @@ -64,7 +77,7 @@ if (DEFINED TFM_MULTI_CORE_TOPOLOGY AND TFM_MULTI_CORE_TOPOLOGY) else () set (CMSE_FLAGS "-mcmse") set (ARM_FEATURE_CMSE 3) -endif () +endif() if(${COMPILER} STREQUAL "ARMCLANG") #Use any ARMCLANG version found on PATH. Note: Only versions supported by the diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 832397c576..6c7834206e 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -7,6 +7,8 @@ cmake_minimum_required(VERSION 3.7) +set(TFM_BUILD_IN_SPE OFF) + #Tell cmake where our modules can be found list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../cmake) diff --git a/bl2/ext/mcuboot/CMakeLists.txt b/bl2/ext/mcuboot/CMakeLists.txt index ddc80a64c4..e0785d1cbe 100644 --- a/bl2/ext/mcuboot/CMakeLists.txt +++ b/bl2/ext/mcuboot/CMakeLists.txt @@ -7,6 +7,8 @@ cmake_minimum_required(VERSION 3.7) +set(TFM_BUILD_IN_SPE ON) + #Tell cmake where our modules can be found list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../../cmake) @@ -53,6 +55,12 @@ else() include(${PLATFORM_CMAKE_FILE}) endif() +#Add platform specific definitions in SPE +if (DEFINED TFM_PLATFORM_SECURE_DEFS) + embedded_set_target_compile_defines(TARGET ${PROJECT_NAME} LANGUAGE C DEFINES ${TFM_PLATFORM_SECURE_DEFS} APPEND) + embedded_set_target_compile_defines(TARGET ${PROJECT_NAME} LANGUAGE ASM DEFINES ${TFM_PLATFORM_SECURE_DEFS} APPEND) +endif() + #Append all our source files to global lists. list(APPEND ALL_SRC_C "${MCUBOOT_DIR}/bl2_main.c" @@ -100,7 +108,7 @@ if(NOT DEFINED PLATFORM_LINK_INCLUDES) endif() embedded_set_target_link_includes(TARGET ${PROJECT_NAME} INCLUDES "${PLATFORM_LINK_INCLUDES}") -add_executable(${PROJECT_NAME} ${ALL_SRC_ASM} ${ALL_SRC_ASM_BL2} ${ALL_SRC_C} ${ALL_SRC_CXX}) +add_executable(${PROJECT_NAME} ${ALL_SRC_ASM} ${ALL_SRC_C_BL2} ${ALL_SRC_ASM_BL2} ${ALL_SRC_C} ${ALL_SRC_CXX}) #Set common compiler and linker flags config_setting_shared_compiler_flags(${PROJECT_NAME}) diff --git a/cmake/Common/MultiCore.cmake b/cmake/Common/MultiCore.cmake new file mode 100644 index 0000000000..46effbd92b --- /dev/null +++ b/cmake/Common/MultiCore.cmake @@ -0,0 +1,88 @@ +#------------------------------------------------------------------------------- +# Copyright (c) 2019, Arm Limited. All rights reserved. +# +# SPDX-License-Identifier: BSD-3-Clause +# +#------------------------------------------------------------------------------- + +# This file provides functions to support multi-core building. +cmake_minimum_required(VERSION 3.7) + +# Platform specific cmake script calls this function to select and enable +# building configuration in mulit-core scenario +function(enable_multi_core_topology_config) + set(TFM_MULTI_CORE_TOPOLOGY ON PARENT_SCOPE) +endfunction(enable_multi_core_topology_config) + +# Platform specific cmake script calls this function to set secure core cpu type +# Argument CPU_TYPE_CMAKE represents the CMake file of the corresponding secure +# CPU type. +# CPU_TYPE_CMAKE value CMake file CPU type to be selected +# CpuM0p CpuM0p.cmake Cortex-M0+ +# CpuM4 CpuM4.cmake Cortex-M4 +# CpuM23 CpuM23.cmake Cortex-M23 +# CpuM33 CpuM33.cmake Cortex-M33 +# Other CPU types are not yet supported. +function(set_secure_cpu_type CPU_TYPE_CMAKE) + include("Common/${CPU_TYPE_CMAKE}") + + if (NOT DEFINED ARM_CPU_TYPE) + message(FATAL_ERROR "Error: Fail to set secure cpu type.") + else () + set(SECURE_ARM_CPU_TYPE ${ARM_CPU_TYPE} PARENT_SCOPE) + endif () +endfunction(set_secure_cpu_type) + +# Platform specific cmake script calls this function to set non-secure core cpu +# type +# Argument CPU_TYPE_CMAKE represents the CMake file of the corresponding +# non-secure CPU type. +# CPU_TYPE_CMAKE value CMake file CPU type to be selected +# CpuM0p CpuM0p.cmake Cortex-M0+ +# CpuM4 CpuM4.cmake Cortex-M4 +# CpuM23 CpuM23.cmake Cortex-M23 +# CpuM33 CpuM33.cmake Cortex-M33 +# Other CPU types are not yet supported. +function(set_ns_cpu_type CPU_TYPE_CMAKE) + include("Common/${CPU_TYPE_CMAKE}") + + if (NOT DEFINED ARM_CPU_TYPE) + message(FATAL_ERROR "Error: Fail to set non-secure cpu type.") + else () + set(NS_ARM_CPU_TYPE ${ARM_CPU_TYPE} PARENT_SCOPE) + endif () +endfunction(set_ns_cpu_type) + +# Platform specific cmake script calls this function to add platform specific +# secure definitions. +# Multiple definitions and options can be organized in argument PLATFORM_DEFS, +# separated by spaces: +# add_platform_secure_definitions(DEF1 DEF2=VAL DEF3) +# The `-D` option flag before preprocessor macros should be skipped. +function(add_platform_secure_definitions PLATFORM_DEFS) + # Check if the same definition is already set + string(FIND TFM_PLATFORM_SECURE_DEFS PLATFORM_DEFS find_output) + + if (find_output EQUAL -1) + # Not set yet. Add it into secure definition list. + set(TFM_PLATFORM_SECURE_DEFS ${TFM_PLATFORM_SECURE_DEFS} + ${PLATFORM_DEFS} + PARENT_SCOPE) + endif () +endfunction(add_platform_secure_definitions) + +function(select_arm_cpu_type BUILD_IN_SPE_FLAG) + if (BUILD_IN_SPE_FLAG) + if (NOT DEFINED SECURE_ARM_CPU_TYPE) + message(FATAL_ERROR "Error: cannot find definition of SECURE_ARM_CPU_TYPE") + else () + set(ARM_CPU_TYPE ${SECURE_ARM_CPU_TYPE} PARENT_SCOPE) + endif () + else () + if (NOT DEFINED NS_ARM_CPU_TYPE) + message(FATAL_ERROR "Error: cannot find definition of NS_ARM_CPU_TYPE") + else () + set(ARM_CPU_TYPE ${NS_ARM_CPU_TYPE} PARENT_SCOPE) + endif () + endif () +endfunction(select_arm_cpu_type) diff --git a/secure_fw/CMakeLists.txt b/secure_fw/CMakeLists.txt index 94f1f6e00d..592b71cb69 100644 --- a/secure_fw/CMakeLists.txt +++ b/secure_fw/CMakeLists.txt @@ -7,6 +7,8 @@ cmake_minimum_required(VERSION 3.7) +set(TFM_BUILD_IN_SPE ON) + #Tell cmake where our modules can be found list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../cmake) @@ -87,6 +89,12 @@ embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${TFM_ROOT_DIR} set(PROJECT_OBJ_LIB ${PROJECT_NAME}_obj_lib) add_library(${PROJECT_OBJ_LIB} OBJECT ${ALL_SRC_C} ${ALL_SRC_C_S} ${ALL_SRC_ASM} ${ALL_SRC_ASM_S}) +#Add platform specific definitions in SPE +if (DEFINED TFM_PLATFORM_SECURE_DEFS) + embedded_set_target_compile_defines(TARGET ${PROJECT_OBJ_LIB} LANGUAGE C DEFINES ${TFM_PLATFORM_SECURE_DEFS} APPEND) + embedded_set_target_compile_defines(TARGET ${PROJECT_OBJ_LIB} LANGUAGE ASM DEFINES ${TFM_PLATFORM_SECURE_DEFS} APPEND) +endif() + #Set common compiler flags config_setting_shared_compiler_flags(${PROJECT_OBJ_LIB}) |