blob: 6efff4e4c44fb0544b95b8b5597941ca5965d557 [file] [log] [blame]
Jianliang Shen7e48bef2022-10-31 16:15:36 +08001#-------------------------------------------------------------------------------
Kevin Penga2b68022023-01-13 13:54:05 +08002# Copyright (c) 2022-2023, Arm Limited. All rights reserved.
Jianliang Shen7e48bef2022-10-31 16:15:36 +08003#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6#-------------------------------------------------------------------------------
7
Kevin Peng97ac6982022-11-24 17:10:00 +08008# 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
16set(KCONFIG_OUTPUT_DIR ${CMAKE_BINARY_DIR}/kconfig)
17
18set(DOTCONFIG_FILE ${KCONFIG_OUTPUT_DIR}/.config)
19set(ROOT_KCONFIG ${CMAKE_SOURCE_DIR}/Kconfig)
20set(PLATFORM_KCONFIG ${TARGET_PLATFORM_PATH}/Kconfig)
Jianliang Shen7e48bef2022-10-31 16:15:36 +080021
Kevin Pengb9c99f02022-12-07 11:23:17 +080022if(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 Shen7e48bef2022-10-31 16:15:36 +080025endif()
26
Kevin Pengb9c99f02022-12-07 11:23:17 +080027if(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()
35endif()
Jianliang Shen7e48bef2022-10-31 16:15:36 +080036
Kevin Peng97ac6982022-11-24 17:10:00 +080037# User customized config file
38if(DEFINED KCONFIG_CONFIG_FILE AND NOT EXISTS ${KCONFIG_CONFIG_FILE})
39 message(FATAL_ERROR "No such file: ${KCONFIG_CONFIG_FILE}")
40endif()
41
42# Note the order of CONFIG_FILE_LIST, as the first loaded configs would be
43# overridden by later ones.
44list(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 Shenc4e719b2023-03-02 14:37:54 +080048set(KCONFIG_ENV_VARS "TFM_SOURCE_DIR=${CMAKE_SOURCE_DIR} \
Kevin Peng97ac6982022-11-24 17:10:00 +080049 TFM_VERSION=${TFM_VERSION} \
50 PLATFORM_PATH=${TARGET_PLATFORM_PATH} \
51 CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
52
53if(MENUCONFIG)
54 # Note: Currently, only GUI menuconfig can be supported with CMake integration
55 set(MENUCONFIG_ARG "-u=gui")
56else()
57 set(MENUCONFIG_ARG "")
58endif()
59
Jianliang Shen7e48bef2022-10-31 16:15:36 +080060find_package(Python3)
61
Jianliang Shen7e48bef2022-10-31 16:15:36 +080062execute_process(
63 COMMAND
64 ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/kconfig/tfm_kconfig.py
Kevin Peng97ac6982022-11-24 17:10:00 +080065 -k ${ROOT_KCONFIG} -o ${KCONFIG_OUTPUT_DIR}
66 --envs ${KCONFIG_ENV_VARS}
67 --config-files ${CONFIG_FILE_LIST}
68 ${MENUCONFIG_ARG}
Jianliang Shen7e48bef2022-10-31 16:15:36 +080069 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
70 RESULT_VARIABLE ret
71)
72
73if(NOT ret EQUAL 0)
74 message(FATAL_ERROR "Kconfig tool failed!")
75endif()
76
Kevin Peng97ac6982022-11-24 17:10:00 +080077if(DEFINED PROJECT_CONFIG_HEADER_FILE)
78 message(FATAL_ERROR "It is NOT supported to manually set PROJECT_CONFIG_HEADER_FILE while using Kconfig.")
Jianliang Shen7e48bef2022-10-31 16:15:36 +080079endif()
80
Kevin Peng97ac6982022-11-24 17:10:00 +080081# Component configs generated by tfm_kconfig.py
82set(PROJECT_CONFIG_HEADER_FILE ${KCONFIG_OUTPUT_DIR}/project_config.h CACHE FILEPATH "User defined header file for TF-M config")
83
Jianliang Shen7e48bef2022-10-31 16:15:36 +080084# Load project cmake configs generated by tfm_kconfig.py
Kevin Peng97ac6982022-11-24 17:10:00 +080085include(${KCONFIG_OUTPUT_DIR}/project_config.cmake)
Kevin Pengb9c99f02022-12-07 11:23:17 +080086
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
93if(EXISTS ${TARGET_PLATFORM_PATH}/reg_config_override.cmake)
94 include(${TARGET_PLATFORM_PATH}/reg_config_override.cmake)
95endif()
96
97# Load build type config, setting options not already set
98if(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)
100endif()
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
108if((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)
112else()
113 #The default backend is SFN
114 include(config/tfm_sfn_config_default.cmake)
115endif()
116
117# Load bl1 config
118if(BL1 AND PLATFORM_DEFAULT_BL1)
119 include(${CMAKE_SOURCE_DIR}/bl1/config/bl1_config_default.cmake)
120endif()
121
122# Load MCUboot specific default.cmake
123if(NOT DEFINED BL2 OR BL2)
124 include(${CMAKE_SOURCE_DIR}/bl2/ext/mcuboot/mcuboot_default_config.cmake)
125endif()
126
127# Include FWU partition configs.
128include(config/tfm_fwu_config.cmake)
129
130# Include coprocessor configs
131include(config/cp_config_default.cmake)
132
133# Load defaults, setting options not already set
134include(config/config_base.cmake)
135
136# Set secure log configs
137# It also depends on regression test config.
138include(config/tfm_secure_log.cmake)