blob: 655d4c2e78baf2b0e3d6d6d1aeec291a5753113b [file] [log] [blame]
Kevin Peng75b0b762022-10-25 18:00:27 +08001.. _Kconfig_system:
2
3##################
4The Kconfig System
5##################
Kevin Peng97ac6982022-11-24 17:10:00 +08006The Kconfig system is an alternative tool to the CMake config system for users to change config
7options of TF-M.
Kevin Peng75b0b762022-10-25 18:00:27 +08008
David Hu64961832023-02-21 23:03:01 +08009.. figure:: kconfig_header_file_system.svg
Kevin Peng75b0b762022-10-25 18:00:27 +080010
11It handles dependencies and validations automatically when you change configurations so that the
12generated configuration options are always valid.
13
Georgios Vasilakis11b48702023-05-04 13:36:28 +020014To use the Kconfig system, enable ``USE_KCONFIG_TOOL`` in command line.
Kevin Peng97ac6982022-11-24 17:10:00 +080015And enable ``MENUCONFIG`` to launch configuration GUI.
16
17The Kconfig system consists of `The Kconfig tool`_ and the `The Kconfig files`_.
Kevin Peng75b0b762022-10-25 18:00:27 +080018
19****************
20The Kconfig tool
21****************
22The Kconfig tool is a python script based on `Kconfiglib <https://github.com/ulfalizer/Kconfiglib>`__
Kevin Peng97ac6982022-11-24 17:10:00 +080023to generate the following config files:
Kevin Peng75b0b762022-10-25 18:00:27 +080024
25- CMake config file
26
27 Contains CMake cache variables of building options.
Kevin Peng75b0b762022-10-25 18:00:27 +080028
29- Header file
30
31 Contains component options in the header file system.
Georgios Vasilakis11b48702023-05-04 13:36:28 +020032 Component options are gathered together in a separate menu ``TF-M component configs`` in
Jianliang Shendfddc982022-11-29 15:08:19 +080033 `The Kconfig files`_.
Kevin Peng75b0b762022-10-25 18:00:27 +080034
Jianliang Shendfddc982022-11-29 15:08:19 +080035- The .config and .config.old files
Kevin Peng75b0b762022-10-25 18:00:27 +080036
37 The ``.config`` file which contains all the above configurations in the Kconfig format.
Jianliang Shendfddc982022-11-29 15:08:19 +080038 It will be created after the first execution of the script. It is only used to allow
39 users to make adjustments basing on the previous settings.
40 The Kconfig tool will load it if it exists and ``.config.old`` will be created to
41 save the previous configurations.
Kevin Peng75b0b762022-10-25 18:00:27 +080042
Kevin Peng97ac6982022-11-24 17:10:00 +080043The tool supports loading multiple pre-set configuration files merging into a single one.
44The first loaded options are overridden by later ones if the config files contain duplicated
45options.
46And dependencies between config options are taken care of.
Georgios Vasilakis11b48702023-05-04 13:36:28 +020047It then launches a configuration GUI for users to change any config options if the ``MENUCONFIG`` is
Kevin Peng97ac6982022-11-24 17:10:00 +080048enabled in build command line.
Kevin Peng75b0b762022-10-25 18:00:27 +080049
Kevin Peng97ac6982022-11-24 17:10:00 +080050Integration with TF-M build system
51----------------------------------
52TF-M build system includes ``kconfig.cmake`` to integrate this tool.
53It prepares the parameters for the script and invokes it to load multiple configuration files basing
54on your build setup, including but not limited to
Kevin Peng75b0b762022-10-25 18:00:27 +080055
Kevin Peng97ac6982022-11-24 17:10:00 +080056 - Build type bound configurations, decided by ``CMAKE_BUILD_TYPE``
57 - Profile configurations, decided by ``TFM_PROFILE``
Kevin Peng75b0b762022-10-25 18:00:27 +080058
Kevin Peng97ac6982022-11-24 17:10:00 +080059**************************
60Customizing config options
61**************************
62By default, the Kconfig system only merges configuration files and generated the final config files.
63To customize the config options, there are several approaches.
Kevin Peng75b0b762022-10-25 18:00:27 +080064
Kevin Peng97ac6982022-11-24 17:10:00 +080065Menuconfig
66----------
67Menuconfig is the recommended approach to adjust the values of the config options because it has
68a graphic interface for you to easily change the options without worrying about dependencies.
Kevin Peng75b0b762022-10-25 18:00:27 +080069
Kevin Peng97ac6982022-11-24 17:10:00 +080070To launch the menuconfig, you need to enable ``MENUCONFIG`` in addition to enabling
71``USE_KCONFIG_TOOL``.
Jianliang Shendfddc982022-11-29 15:08:19 +080072
73.. code-block:: bash
74
Kevin Peng97ac6982022-11-24 17:10:00 +080075 cmake -S . -B cmake_build -DTFM_PLATFORM=arm/mps2/an521 \
76 -DUSE_KCONFIG_TOOL=ON \
77 -DMENUCONFIG=ON
Kevin Peng75b0b762022-10-25 18:00:27 +080078
79.. note::
80
Kevin Peng97ac6982022-11-24 17:10:00 +080081 Although the Kconfiglib provides three
82 `menuconfig interfaces <https://github.com/ulfalizer/Kconfiglib#menuconfig-interfaces>`__,
83 only GUI menuconfig can be launched by CMake for the time being.
84
85Command line options
86--------------------
87The support of passing configurations via command line is kept for the Kconfig system.
88
89.. code-block:: bash
90
91 cmake -S . -B cmake_build -DTFM_PLATFORM=arm/mps2/an521 \
92 -DUSE_KCONFIG_TOOL=ON \
93 -DTFM_ISOLATION_LEVEL=2
94
95Kconfig file
96------------
97You can also put the frequently used config options into a Kconfig file. When you need to apply the
98config options in that file, pass it via command line option ``-DKCONFIG_CONFIG_FILE``
99
100.. code-block:: bash
101
102 cmake -S . -B cmake_build -DTFM_PLATFORM=arm/mps2/an521 \
103 -DTFM_ISOLATION_LEVEL=2 \
104 -DUSE_KCONFIG_TOOL=ON \
105 -DKCONFIG_CONFIG_FILE=my_config.conf
106
107.. note::
108
109 The command line set options override the ones in the config file.
110 And you can always launch menuconfig to do the final adjustments.
Kevin Peng75b0b762022-10-25 18:00:27 +0800111
112*****************
113The Kconfig files
114*****************
Jianliang Shendfddc982022-11-29 15:08:19 +0800115The Kconfig files are the files written by the
Kevin Peng75b0b762022-10-25 18:00:27 +0800116`Kconfig language <https://www.kernel.org/doc/html/latest/kbuild/kconfig-language.html#kconfig-language>`__
117to describe config options.
Jianliang Shendfddc982022-11-29 15:08:19 +0800118They also uses some Kconfiglib extensions such as optional source ``osource`` and relative source ``rsource``
119so they can only work with the Kconfiglib.
Kevin Peng75b0b762022-10-25 18:00:27 +0800120
121--------------
122
Kevin Peng97ac6982022-11-24 17:10:00 +0800123*Copyright (c) 2022-2023, Arm Limited. All rights reserved.*