Jianliang Shen | 7e48bef | 2022-10-31 16:15:36 +0800 | [diff] [blame] | 1 | #------------------------------------------------------------------------------- |
Kevin Peng | a2b6802 | 2023-01-13 13:54:05 +0800 | [diff] [blame] | 2 | # Copyright (c) 2022-2023, Arm Limited. All rights reserved. |
Jianliang Shen | 7e48bef | 2022-10-31 16:15:36 +0800 | [diff] [blame] | 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | # |
| 6 | #------------------------------------------------------------------------------- |
| 7 | |
Kevin Peng | 97ac698 | 2022-11-24 17:10:00 +0800 | [diff] [blame] | 8 | # Load multiple config files and merge into one, generates CMake config file and config header file. |
| 9 | # The first loaded configs would be overridden by later ones. That's how the "merge" works. |
| 10 | # Check CONFIG_FILE_LIST for the loading order. |
| 11 | # Configurations not set by any of the config files would be set to the default values in Kconfig |
| 12 | # files with dependencies respected. |
| 13 | # If a ".config" already exists in the output folder, then the CONFIG_FILE_LIST is ignored. |
| 14 | # For more details, check the kconfig_system.rst. |
| 15 | |
| 16 | set(KCONFIG_OUTPUT_DIR ${CMAKE_BINARY_DIR}/kconfig) |
| 17 | |
| 18 | set(DOTCONFIG_FILE ${KCONFIG_OUTPUT_DIR}/.config) |
| 19 | set(ROOT_KCONFIG ${CMAKE_SOURCE_DIR}/Kconfig) |
| 20 | set(PLATFORM_KCONFIG ${TARGET_PLATFORM_PATH}/Kconfig) |
Jianliang Shen | 7e48bef | 2022-10-31 16:15:36 +0800 | [diff] [blame] | 21 | |
Kevin Peng | b9c99f0 | 2022-12-07 11:23:17 +0800 | [diff] [blame] | 22 | if(TFM_PROFILE) |
| 23 | # Selecting TF-M profiles is not supported yet. |
| 24 | message(FATAL_ERROR "Selecting TF-M profiles is not supported yet in Kconfig system!") |
Jianliang Shen | 7e48bef | 2022-10-31 16:15:36 +0800 | [diff] [blame] | 25 | endif() |
| 26 | |
Kevin Peng | b9c99f0 | 2022-12-07 11:23:17 +0800 | [diff] [blame] | 27 | if(NOT EXISTS ${PLATFORM_KCONFIG}) |
| 28 | message(WARNING "The platform does not have Kconfig file! \ |
| 29 | The Kconfig system cannot get its configuration settings. |
| 30 | So it is not guaranteed that the Kconfig system works properly.") |
| 31 | |
| 32 | if(EXISTS ${TARGET_PLATFORM_PATH}/config.cmake) |
| 33 | include(${TARGET_PLATFORM_PATH}/config.cmake) |
| 34 | endif() |
| 35 | endif() |
Jianliang Shen | 7e48bef | 2022-10-31 16:15:36 +0800 | [diff] [blame] | 36 | |
Kevin Peng | 97ac698 | 2022-11-24 17:10:00 +0800 | [diff] [blame] | 37 | # User customized config file |
| 38 | if(DEFINED KCONFIG_CONFIG_FILE AND NOT EXISTS ${KCONFIG_CONFIG_FILE}) |
| 39 | message(FATAL_ERROR "No such file: ${KCONFIG_CONFIG_FILE}") |
| 40 | endif() |
| 41 | |
| 42 | # Note the order of CONFIG_FILE_LIST, as the first loaded configs would be |
| 43 | # overridden by later ones. |
| 44 | list(APPEND CONFIG_FILE_LIST |
| 45 | ${KCONFIG_CONFIG_FILE}) |
| 46 | |
| 47 | # Set up ENV variables for the tfm_kconfig.py which are then consumed by Kconfig files. |
Jianliang Shen | c4e719b | 2023-03-02 14:37:54 +0800 | [diff] [blame] | 48 | set(KCONFIG_ENV_VARS "TFM_SOURCE_DIR=${CMAKE_SOURCE_DIR} \ |
Kevin Peng | 97ac698 | 2022-11-24 17:10:00 +0800 | [diff] [blame] | 49 | TFM_VERSION=${TFM_VERSION} \ |
| 50 | PLATFORM_PATH=${TARGET_PLATFORM_PATH} \ |
| 51 | CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}") |
| 52 | |
| 53 | if(MENUCONFIG) |
| 54 | # Note: Currently, only GUI menuconfig can be supported with CMake integration |
| 55 | set(MENUCONFIG_ARG "-u=gui") |
| 56 | else() |
| 57 | set(MENUCONFIG_ARG "") |
| 58 | endif() |
| 59 | |
Jianliang Shen | 7e48bef | 2022-10-31 16:15:36 +0800 | [diff] [blame] | 60 | find_package(Python3) |
| 61 | |
Jianliang Shen | 7e48bef | 2022-10-31 16:15:36 +0800 | [diff] [blame] | 62 | execute_process( |
| 63 | COMMAND |
| 64 | ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/kconfig/tfm_kconfig.py |
Kevin Peng | 97ac698 | 2022-11-24 17:10:00 +0800 | [diff] [blame] | 65 | -k ${ROOT_KCONFIG} -o ${KCONFIG_OUTPUT_DIR} |
| 66 | --envs ${KCONFIG_ENV_VARS} |
| 67 | --config-files ${CONFIG_FILE_LIST} |
| 68 | ${MENUCONFIG_ARG} |
Jianliang Shen | 7e48bef | 2022-10-31 16:15:36 +0800 | [diff] [blame] | 69 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} |
| 70 | RESULT_VARIABLE ret |
| 71 | ) |
| 72 | |
| 73 | if(NOT ret EQUAL 0) |
| 74 | message(FATAL_ERROR "Kconfig tool failed!") |
| 75 | endif() |
| 76 | |
Kevin Peng | 97ac698 | 2022-11-24 17:10:00 +0800 | [diff] [blame] | 77 | if(DEFINED PROJECT_CONFIG_HEADER_FILE) |
| 78 | message(FATAL_ERROR "It is NOT supported to manually set PROJECT_CONFIG_HEADER_FILE while using Kconfig.") |
Jianliang Shen | 7e48bef | 2022-10-31 16:15:36 +0800 | [diff] [blame] | 79 | endif() |
| 80 | |
Kevin Peng | 97ac698 | 2022-11-24 17:10:00 +0800 | [diff] [blame] | 81 | # Component configs generated by tfm_kconfig.py |
| 82 | set(PROJECT_CONFIG_HEADER_FILE ${KCONFIG_OUTPUT_DIR}/project_config.h CACHE FILEPATH "User defined header file for TF-M config") |
| 83 | |
Jianliang Shen | 7e48bef | 2022-10-31 16:15:36 +0800 | [diff] [blame] | 84 | # Load project cmake configs generated by tfm_kconfig.py |
Kevin Peng | 97ac698 | 2022-11-24 17:10:00 +0800 | [diff] [blame] | 85 | include(${KCONFIG_OUTPUT_DIR}/project_config.cmake) |
Kevin Peng | b9c99f0 | 2022-12-07 11:23:17 +0800 | [diff] [blame] | 86 | |
| 87 | #################################################################################################### |
| 88 | |
| 89 | # The Kconfig system does not cover all the config options for the time being. |
| 90 | # So part of them still use the CMake config system. |
| 91 | |
| 92 | # Load regression configs overrided by platform |
| 93 | if(EXISTS ${TARGET_PLATFORM_PATH}/reg_config_override.cmake) |
| 94 | include(${TARGET_PLATFORM_PATH}/reg_config_override.cmake) |
| 95 | endif() |
| 96 | |
| 97 | # Load build type config, setting options not already set |
| 98 | if(EXISTS ${CMAKE_SOURCE_DIR}/config/build_type/${CMAKE_BUILD_TYPE_LOWERCASE}.cmake) |
| 99 | include(${CMAKE_SOURCE_DIR}/config/build_type/${CMAKE_BUILD_TYPE_LOWERCASE}.cmake) |
| 100 | endif() |
| 101 | |
| 102 | # Load TF-M model specific default config |
| 103 | # Load IPC backend config if isolation level is explicitly specified to 2/3 or IPC backend is |
| 104 | # selected via build command line. Otherwise, load SFN backend config by default. |
| 105 | # If a pair of invalid settings are passed via command line, it will be captured later via config |
| 106 | # check. |
| 107 | # Also select IPC model by default for multi-core platform unless it has already selected SFN model |
| 108 | if((DEFINED TFM_ISOLATION_LEVEL AND TFM_ISOLATION_LEVEL GREATER 1) OR |
| 109 | CONFIG_TFM_SPM_BACKEND STREQUAL "IPC" OR |
| 110 | TFM_MULTI_CORE_TOPOLOGY) |
| 111 | include(config/tfm_ipc_config_default.cmake) |
| 112 | else() |
| 113 | #The default backend is SFN |
| 114 | include(config/tfm_sfn_config_default.cmake) |
| 115 | endif() |
| 116 | |
| 117 | # Load bl1 config |
| 118 | if(BL1 AND PLATFORM_DEFAULT_BL1) |
| 119 | include(${CMAKE_SOURCE_DIR}/bl1/config/bl1_config_default.cmake) |
| 120 | endif() |
| 121 | |
| 122 | # Load MCUboot specific default.cmake |
| 123 | if(NOT DEFINED BL2 OR BL2) |
| 124 | include(${CMAKE_SOURCE_DIR}/bl2/ext/mcuboot/mcuboot_default_config.cmake) |
| 125 | endif() |
| 126 | |
| 127 | # Include FWU partition configs. |
| 128 | include(config/tfm_fwu_config.cmake) |
| 129 | |
| 130 | # Include coprocessor configs |
| 131 | include(config/cp_config_default.cmake) |
| 132 | |
| 133 | # Load defaults, setting options not already set |
| 134 | include(config/config_base.cmake) |
| 135 | |
| 136 | # Set secure log configs |
| 137 | # It also depends on regression test config. |
| 138 | include(config/tfm_secure_log.cmake) |