Raef Coles | 958aeef | 2020-10-08 12:12:58 +0100 | [diff] [blame] | 1 | #------------------------------------------------------------------------------- |
David Hu | cc14498 | 2023-01-16 12:24:27 +0800 | [diff] [blame] | 2 | # Copyright (c) 2020-2023, Arm Limited. All rights reserved. |
Raef Coles | 958aeef | 2020-10-08 12:12:58 +0100 | [diff] [blame] | 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | # |
| 6 | #------------------------------------------------------------------------------- |
| 7 | |
| 8 | # The Configuration sequence is captured in the documentation, in |
| 9 | # docs/getting_started/tfm_build_instructions.rst under Cmake Configuration. If |
| 10 | # the sequence is updated here the docs must also be updated. |
| 11 | |
Dávid Házi | e50f0a9 | 2022-07-06 14:46:01 +0200 | [diff] [blame] | 12 | # The default build type is MinSizeRel. If debug symbols are needed then |
| 13 | # -DCMAKE_BUILD_TYPE=debug should be used (likewise with other build types) |
| 14 | if (NOT CMAKE_BUILD_TYPE) |
| 15 | set(CMAKE_BUILD_TYPE "MinSizeRel" CACHE STRING "Build type: [Debug, Release, RelWithDebInfo, MinSizeRel]" FORCE) |
| 16 | endif() |
| 17 | |
Summer Qin | 566e03b | 2022-10-08 17:27:42 +0800 | [diff] [blame] | 18 | if (TFM_LIB_MODEL) |
| 19 | message(FATAL_ERROR "Library Model is deprecated, please DO NOT use TFM_LIB_MODEL anymore." |
| 20 | "SFN model is a replacement for Library Model. You can use -DCONFIG_TFM_SPM_BACKEND=SFN to select SFN model.") |
| 21 | endif() |
| 22 | |
Tamas Ban | 6921920 | 2020-10-27 08:13:18 +0000 | [diff] [blame] | 23 | # Load extra config |
| 24 | if (TFM_EXTRA_CONFIG_PATH) |
| 25 | include(${TFM_EXTRA_CONFIG_PATH}) |
| 26 | endif() |
Raef Coles | 958aeef | 2020-10-08 12:12:58 +0100 | [diff] [blame] | 27 | |
David Hu | cc14498 | 2023-01-16 12:24:27 +0800 | [diff] [blame] | 28 | # Some compiler flags depend on the CPU / platform config. This include should |
| 29 | # be run before the toolchain file so the compiler can be configured properly. |
Kevin Peng | a2b6802 | 2023-01-13 13:54:05 +0800 | [diff] [blame] | 30 | if (NOT EXISTS ${TARGET_PLATFORM_PATH}/preload.cmake) |
David Hu | cc14498 | 2023-01-16 12:24:27 +0800 | [diff] [blame] | 31 | Message(FATAL_ERROR "preload.cmake is not found in ${TFM_PLATFORM}") |
| 32 | else() |
Kevin Peng | a2b6802 | 2023-01-13 13:54:05 +0800 | [diff] [blame] | 33 | include(${TARGET_PLATFORM_PATH}/preload.cmake) |
David Hu | cc14498 | 2023-01-16 12:24:27 +0800 | [diff] [blame] | 34 | endif() |
| 35 | |
Xinyu Zhang | e7581b1 | 2022-11-23 14:19:02 +0800 | [diff] [blame] | 36 | # Set TF-M project config header file |
| 37 | add_library(tfm_config INTERFACE) |
| 38 | |
Tamas Ban | 6921920 | 2020-10-27 08:13:18 +0000 | [diff] [blame] | 39 | # Load PSA config, setting options not already set |
| 40 | if (TEST_PSA_API) |
| 41 | include(config/tests/config_test_psa_api.cmake) |
| 42 | endif() |
| 43 | |
| 44 | # Load build type config, setting options not already set |
Raef Coles | 958aeef | 2020-10-08 12:12:58 +0100 | [diff] [blame] | 45 | string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWERCASE) |
| 46 | if (EXISTS ${CMAKE_SOURCE_DIR}/config/build_type/${CMAKE_BUILD_TYPE_LOWERCASE}.cmake) |
| 47 | include(${CMAKE_SOURCE_DIR}/config/build_type/${CMAKE_BUILD_TYPE_LOWERCASE}.cmake) |
| 48 | endif() |
| 49 | |
Tamas Ban | 6921920 | 2020-10-27 08:13:18 +0000 | [diff] [blame] | 50 | # Load platform config, setting options not already set |
Kevin Peng | a2b6802 | 2023-01-13 13:54:05 +0800 | [diff] [blame] | 51 | if (EXISTS ${TARGET_PLATFORM_PATH}/config.cmake) |
| 52 | include(${TARGET_PLATFORM_PATH}/config.cmake) |
Raef Coles | 958aeef | 2020-10-08 12:12:58 +0100 | [diff] [blame] | 53 | endif() |
| 54 | |
Jianliang Shen | 7e48bef | 2022-10-31 16:15:36 +0800 | [diff] [blame] | 55 | # Load configs generated from Kconfig |
| 56 | include(${CMAKE_SOURCE_DIR}/config/kconfig.cmake) |
| 57 | |
| 58 | # Parse tf-m-tests config prior to platform specific config.cmake |
| 59 | # Some platforms select different configuration according when regression tests |
| 60 | # are enabled. |
| 61 | include(lib/ext/tf-m-tests/reg_parse.cmake) |
| 62 | |
Tamas Ban | 6921920 | 2020-10-27 08:13:18 +0000 | [diff] [blame] | 63 | # Load profile config, setting options not already set |
Raef Coles | 958aeef | 2020-10-08 12:12:58 +0100 | [diff] [blame] | 64 | if (TFM_PROFILE) |
Tamas Ban | 6921920 | 2020-10-27 08:13:18 +0000 | [diff] [blame] | 65 | include(config/profile/${TFM_PROFILE}.cmake) |
Raef Coles | 958aeef | 2020-10-08 12:12:58 +0100 | [diff] [blame] | 66 | endif() |
| 67 | |
David Hu | dcc5a4a | 2022-11-14 17:59:11 +0800 | [diff] [blame] | 68 | # Load Secure Partition settings according to regression configuration as all SPs are disabled |
| 69 | # by default |
| 70 | if(TFM_S_REG_TEST OR TFM_NS_REG_TEST) |
| 71 | include(${CMAKE_CURRENT_LIST_DIR}/tests/regression_config.cmake) |
| 72 | endif() |
| 73 | |
Kevin Peng | c32279d | 2022-02-10 11:11:55 +0800 | [diff] [blame] | 74 | include(${CMAKE_SOURCE_DIR}/config/tfm_build_log_config.cmake) |
| 75 | |
David Hu | 372b45c | 2022-11-16 10:06:28 +0800 | [diff] [blame] | 76 | # Load TF-M model specific default config |
David Hu | 85a92e0 | 2022-11-23 10:44:58 +0800 | [diff] [blame] | 77 | # Load IPC backend config if isolation level is explicitly specified to 2/3 or IPC backend is |
David Hu | 372b45c | 2022-11-16 10:06:28 +0800 | [diff] [blame] | 78 | # selected via build command line. Otherwise, load SFN backend config by default. |
| 79 | # If a pair of invalid settings are passed via command line, it will be captured later via config |
| 80 | # check. |
| 81 | # Also select IPC model by default for multi-core platform unless it has already selected SFN model |
| 82 | if ((DEFINED TFM_ISOLATION_LEVEL AND TFM_ISOLATION_LEVEL GREATER 1) OR |
| 83 | CONFIG_TFM_SPM_BACKEND STREQUAL "IPC" OR |
| 84 | TFM_MULTI_CORE_TOPOLOGY) |
| 85 | include(config/tfm_ipc_config_default.cmake) |
| 86 | else() |
| 87 | #The default backend is SFN |
| 88 | include(config/tfm_sfn_config_default.cmake) |
| 89 | endif() |
| 90 | |
Raef Coles | 15a37f8 | 2021-12-07 15:59:14 +0000 | [diff] [blame] | 91 | # Load bl1 config |
Raef Coles | d32f6bf | 2022-04-19 15:13:00 +0100 | [diff] [blame] | 92 | if (BL1 AND PLATFORM_DEFAULT_BL1) |
Raef Coles | 15a37f8 | 2021-12-07 15:59:14 +0000 | [diff] [blame] | 93 | include(${CMAKE_SOURCE_DIR}/bl1/config/bl1_config_default.cmake) |
| 94 | endif() |
| 95 | |
shejia01 | 8444011 | 2021-07-07 10:49:09 +0800 | [diff] [blame] | 96 | # Load MCUboot specific default.cmake |
Raef Coles | f0ba05b | 2021-11-25 09:57:17 +0000 | [diff] [blame] | 97 | if (NOT DEFINED BL2 OR BL2) |
shejia01 | 8444011 | 2021-07-07 10:49:09 +0800 | [diff] [blame] | 98 | include(${CMAKE_SOURCE_DIR}/bl2/ext/mcuboot/mcuboot_default_config.cmake) |
| 99 | endif() |
| 100 | |
Sherry Zhang | 7146895 | 2022-10-19 14:09:05 +0800 | [diff] [blame] | 101 | # Include FWU partition configs. |
| 102 | include(config/tfm_fwu_config.cmake) |
| 103 | |
Feder Liang | d4dbaa9 | 2021-09-07 15:34:46 +0800 | [diff] [blame] | 104 | # Include coprocessor configs |
| 105 | include(config/cp_config_default.cmake) |
| 106 | |
Ludovic Barre | 5319ac0 | 2021-11-02 09:51:29 +0100 | [diff] [blame] | 107 | # Load defaults, setting options not already set |
Anton Komlev | 1dfd209 | 2022-10-25 17:50:09 +0100 | [diff] [blame] | 108 | include(config/config_base.cmake) |
Ludovic Barre | 5319ac0 | 2021-11-02 09:51:29 +0100 | [diff] [blame] | 109 | |
David Hu | 3d2121f | 2021-08-23 18:00:26 +0800 | [diff] [blame] | 110 | # Fetch tf-m-tests repo during config, if NS or regression test is required. |
| 111 | # Therefore tf-m-tests configs can be set with TF-M configs since their configs |
| 112 | # are coupled. |
David Hu | 195cb5a | 2022-05-10 22:03:26 +0800 | [diff] [blame] | 113 | include(lib/ext/tf-m-tests/fetch_repo.cmake) |
David Hu | 52ff16f | 2021-08-20 11:39:37 +0800 | [diff] [blame] | 114 | |
| 115 | # Set secure log configs |
| 116 | # It also depends on regression test config. |
| 117 | include(config/tfm_secure_log.cmake) |
Xinyu Zhang | a2fab0e | 2022-10-24 15:37:46 +0800 | [diff] [blame] | 118 | |
Xinyu Zhang | a2fab0e | 2022-10-24 15:37:46 +0800 | [diff] [blame] | 119 | # Set user defined TF-M config header file |
| 120 | if(PROJECT_CONFIG_HEADER_FILE) |
| 121 | if(NOT EXISTS ${PROJECT_CONFIG_HEADER_FILE}) |
| 122 | message(FATAL_ERROR "${PROJECT_CONFIG_HEADER_FILE} does not exist! Please use absolute path.") |
| 123 | endif() |
| 124 | target_compile_definitions(tfm_config |
| 125 | INTERFACE |
| 126 | PROJECT_CONFIG_HEADER_FILE="${PROJECT_CONFIG_HEADER_FILE}" |
| 127 | ) |
| 128 | endif() |
| 129 | |
| 130 | # Set platform defined TF-M config header file |
Kevin Peng | a2b6802 | 2023-01-13 13:54:05 +0800 | [diff] [blame] | 131 | set(TARGET_CONFIG_HEADER_FILE ${TARGET_PLATFORM_PATH}/config_tfm_target.h) |
Xinyu Zhang | a2fab0e | 2022-10-24 15:37:46 +0800 | [diff] [blame] | 132 | if(EXISTS ${TARGET_CONFIG_HEADER_FILE}) |
| 133 | target_compile_definitions(tfm_config |
| 134 | INTERFACE |
| 135 | TARGET_CONFIG_HEADER_FILE="${TARGET_CONFIG_HEADER_FILE}" |
| 136 | ) |
| 137 | endif() |