blob: 65731b4fa04c1eefedf72d2217588880a18aecc0 [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 Shen7c67ab12023-03-14 14:41:34 +080060if(DEFINED PROJECT_CONFIG_HEADER_FILE)
61 get_property(HELP_STRING CACHE PROJECT_CONFIG_HEADER_FILE PROPERTY HELPSTRING)
62
63 # It is not supported to set PROJECT_CONFIG_HEADER_FILE while using Kconfig, either from
64 # command line or CMake files. It should be set to the file generated the Kconfig system.
65 # As this file set it itself, if the user re-run the CMake config command, the
66 # PROJECT_CONFIG_HEADER_FILE will be already defined set.
67 # So the existence of the ${DOTCONFIG_FILE} is used to indicate if it is a re-configuration.
68 if("${HELP_STRING}" MATCHES "variable specified on the command line" OR NOT EXISTS ${DOTCONFIG_FILE})
69 message(FATAL_ERROR "It is NOT supported to manually set PROJECT_CONFIG_HEADER_FILE while using Kconfig.")
70 endif()
71endif()
72
Jianliang Shen7e48bef2022-10-31 16:15:36 +080073find_package(Python3)
74
Jianliang Shen7e48bef2022-10-31 16:15:36 +080075execute_process(
76 COMMAND
77 ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/kconfig/tfm_kconfig.py
Kevin Peng97ac6982022-11-24 17:10:00 +080078 -k ${ROOT_KCONFIG} -o ${KCONFIG_OUTPUT_DIR}
79 --envs ${KCONFIG_ENV_VARS}
80 --config-files ${CONFIG_FILE_LIST}
81 ${MENUCONFIG_ARG}
Jianliang Shen7e48bef2022-10-31 16:15:36 +080082 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
83 RESULT_VARIABLE ret
84)
85
86if(NOT ret EQUAL 0)
87 message(FATAL_ERROR "Kconfig tool failed!")
88endif()
89
Kevin Peng97ac6982022-11-24 17:10:00 +080090# Component configs generated by tfm_kconfig.py
91set(PROJECT_CONFIG_HEADER_FILE ${KCONFIG_OUTPUT_DIR}/project_config.h CACHE FILEPATH "User defined header file for TF-M config")
92
Jianliang Shen7e48bef2022-10-31 16:15:36 +080093# Load project cmake configs generated by tfm_kconfig.py
Kevin Peng97ac6982022-11-24 17:10:00 +080094include(${KCONFIG_OUTPUT_DIR}/project_config.cmake)
Kevin Pengb9c99f02022-12-07 11:23:17 +080095
96####################################################################################################
97
98# The Kconfig system does not cover all the config options for the time being.
99# So part of them still use the CMake config system.
100
101# Load regression configs overrided by platform
102if(EXISTS ${TARGET_PLATFORM_PATH}/reg_config_override.cmake)
103 include(${TARGET_PLATFORM_PATH}/reg_config_override.cmake)
104endif()
105
106# Load build type config, setting options not already set
107if(EXISTS ${CMAKE_SOURCE_DIR}/config/build_type/${CMAKE_BUILD_TYPE_LOWERCASE}.cmake)
108 include(${CMAKE_SOURCE_DIR}/config/build_type/${CMAKE_BUILD_TYPE_LOWERCASE}.cmake)
109endif()
110
111# Load TF-M model specific default config
112# Load IPC backend config if isolation level is explicitly specified to 2/3 or IPC backend is
113# selected via build command line. Otherwise, load SFN backend config by default.
114# If a pair of invalid settings are passed via command line, it will be captured later via config
115# check.
116# Also select IPC model by default for multi-core platform unless it has already selected SFN model
117if((DEFINED TFM_ISOLATION_LEVEL AND TFM_ISOLATION_LEVEL GREATER 1) OR
118 CONFIG_TFM_SPM_BACKEND STREQUAL "IPC" OR
119 TFM_MULTI_CORE_TOPOLOGY)
120 include(config/tfm_ipc_config_default.cmake)
121else()
122 #The default backend is SFN
123 include(config/tfm_sfn_config_default.cmake)
124endif()
125
126# Load bl1 config
127if(BL1 AND PLATFORM_DEFAULT_BL1)
128 include(${CMAKE_SOURCE_DIR}/bl1/config/bl1_config_default.cmake)
129endif()
130
131# Load MCUboot specific default.cmake
132if(NOT DEFINED BL2 OR BL2)
133 include(${CMAKE_SOURCE_DIR}/bl2/ext/mcuboot/mcuboot_default_config.cmake)
134endif()
135
136# Include FWU partition configs.
137include(config/tfm_fwu_config.cmake)
138
139# Include coprocessor configs
140include(config/cp_config_default.cmake)
141
142# Load defaults, setting options not already set
143include(config/config_base.cmake)
144
145# Set secure log configs
146# It also depends on regression test config.
147include(config/tfm_secure_log.cmake)