Kevin Peng | 75b0b76 | 2022-10-25 18:00:27 +0800 | [diff] [blame] | 1 | .. _Kconfig_system: |
| 2 | |
| 3 | ################## |
| 4 | The Kconfig System |
| 5 | ################## |
Kevin Peng | 97ac698 | 2022-11-24 17:10:00 +0800 | [diff] [blame] | 6 | The Kconfig system is an alternative tool to the CMake config system for users to change config |
| 7 | options of TF-M. |
Kevin Peng | 75b0b76 | 2022-10-25 18:00:27 +0800 | [diff] [blame] | 8 | |
David Hu | 6496183 | 2023-02-21 23:03:01 +0800 | [diff] [blame] | 9 | .. figure:: kconfig_header_file_system.svg |
Kevin Peng | 75b0b76 | 2022-10-25 18:00:27 +0800 | [diff] [blame] | 10 | |
| 11 | It handles dependencies and validations automatically when you change configurations so that the |
| 12 | generated configuration options are always valid. |
| 13 | |
Georgios Vasilakis | 11b4870 | 2023-05-04 13:36:28 +0200 | [diff] [blame] | 14 | To use the Kconfig system, enable ``USE_KCONFIG_TOOL`` in command line. |
Kevin Peng | 97ac698 | 2022-11-24 17:10:00 +0800 | [diff] [blame] | 15 | And enable ``MENUCONFIG`` to launch configuration GUI. |
| 16 | |
| 17 | The Kconfig system consists of `The Kconfig tool`_ and the `The Kconfig files`_. |
Kevin Peng | 75b0b76 | 2022-10-25 18:00:27 +0800 | [diff] [blame] | 18 | |
| 19 | **************** |
| 20 | The Kconfig tool |
| 21 | **************** |
| 22 | The Kconfig tool is a python script based on `Kconfiglib <https://github.com/ulfalizer/Kconfiglib>`__ |
Kevin Peng | 97ac698 | 2022-11-24 17:10:00 +0800 | [diff] [blame] | 23 | to generate the following config files: |
Kevin Peng | 75b0b76 | 2022-10-25 18:00:27 +0800 | [diff] [blame] | 24 | |
| 25 | - CMake config file |
| 26 | |
| 27 | Contains CMake cache variables of building options. |
Kevin Peng | 75b0b76 | 2022-10-25 18:00:27 +0800 | [diff] [blame] | 28 | |
| 29 | - Header file |
| 30 | |
| 31 | Contains component options in the header file system. |
Georgios Vasilakis | 11b4870 | 2023-05-04 13:36:28 +0200 | [diff] [blame] | 32 | Component options are gathered together in a separate menu ``TF-M component configs`` in |
Jianliang Shen | dfddc98 | 2022-11-29 15:08:19 +0800 | [diff] [blame] | 33 | `The Kconfig files`_. |
Kevin Peng | 75b0b76 | 2022-10-25 18:00:27 +0800 | [diff] [blame] | 34 | |
Jianliang Shen | dfddc98 | 2022-11-29 15:08:19 +0800 | [diff] [blame] | 35 | - The .config and .config.old files |
Kevin Peng | 75b0b76 | 2022-10-25 18:00:27 +0800 | [diff] [blame] | 36 | |
| 37 | The ``.config`` file which contains all the above configurations in the Kconfig format. |
Jianliang Shen | dfddc98 | 2022-11-29 15:08:19 +0800 | [diff] [blame] | 38 | 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 Peng | 75b0b76 | 2022-10-25 18:00:27 +0800 | [diff] [blame] | 42 | |
Kevin Peng | 97ac698 | 2022-11-24 17:10:00 +0800 | [diff] [blame] | 43 | The tool supports loading multiple pre-set configuration files merging into a single one. |
| 44 | The first loaded options are overridden by later ones if the config files contain duplicated |
| 45 | options. |
| 46 | And dependencies between config options are taken care of. |
Georgios Vasilakis | 11b4870 | 2023-05-04 13:36:28 +0200 | [diff] [blame] | 47 | It then launches a configuration GUI for users to change any config options if the ``MENUCONFIG`` is |
Kevin Peng | 97ac698 | 2022-11-24 17:10:00 +0800 | [diff] [blame] | 48 | enabled in build command line. |
Kevin Peng | 75b0b76 | 2022-10-25 18:00:27 +0800 | [diff] [blame] | 49 | |
Kevin Peng | 97ac698 | 2022-11-24 17:10:00 +0800 | [diff] [blame] | 50 | Integration with TF-M build system |
| 51 | ---------------------------------- |
| 52 | TF-M build system includes ``kconfig.cmake`` to integrate this tool. |
| 53 | It prepares the parameters for the script and invokes it to load multiple configuration files basing |
| 54 | on your build setup, including but not limited to |
Kevin Peng | 75b0b76 | 2022-10-25 18:00:27 +0800 | [diff] [blame] | 55 | |
Kevin Peng | 97ac698 | 2022-11-24 17:10:00 +0800 | [diff] [blame] | 56 | - Build type bound configurations, decided by ``CMAKE_BUILD_TYPE`` |
| 57 | - Profile configurations, decided by ``TFM_PROFILE`` |
Kevin Peng | 75b0b76 | 2022-10-25 18:00:27 +0800 | [diff] [blame] | 58 | |
Kevin Peng | 97ac698 | 2022-11-24 17:10:00 +0800 | [diff] [blame] | 59 | ************************** |
| 60 | Customizing config options |
| 61 | ************************** |
| 62 | By default, the Kconfig system only merges configuration files and generated the final config files. |
| 63 | To customize the config options, there are several approaches. |
Kevin Peng | 75b0b76 | 2022-10-25 18:00:27 +0800 | [diff] [blame] | 64 | |
Kevin Peng | 97ac698 | 2022-11-24 17:10:00 +0800 | [diff] [blame] | 65 | Menuconfig |
| 66 | ---------- |
| 67 | Menuconfig is the recommended approach to adjust the values of the config options because it has |
| 68 | a graphic interface for you to easily change the options without worrying about dependencies. |
Kevin Peng | 75b0b76 | 2022-10-25 18:00:27 +0800 | [diff] [blame] | 69 | |
Kevin Peng | 97ac698 | 2022-11-24 17:10:00 +0800 | [diff] [blame] | 70 | To launch the menuconfig, you need to enable ``MENUCONFIG`` in addition to enabling |
| 71 | ``USE_KCONFIG_TOOL``. |
Jianliang Shen | dfddc98 | 2022-11-29 15:08:19 +0800 | [diff] [blame] | 72 | |
| 73 | .. code-block:: bash |
| 74 | |
Kevin Peng | 97ac698 | 2022-11-24 17:10:00 +0800 | [diff] [blame] | 75 | cmake -S . -B cmake_build -DTFM_PLATFORM=arm/mps2/an521 \ |
| 76 | -DUSE_KCONFIG_TOOL=ON \ |
| 77 | -DMENUCONFIG=ON |
Kevin Peng | 75b0b76 | 2022-10-25 18:00:27 +0800 | [diff] [blame] | 78 | |
| 79 | .. note:: |
| 80 | |
Kevin Peng | 97ac698 | 2022-11-24 17:10:00 +0800 | [diff] [blame] | 81 | 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 | |
| 85 | Command line options |
| 86 | -------------------- |
| 87 | The 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 | |
| 95 | Kconfig file |
| 96 | ------------ |
| 97 | You can also put the frequently used config options into a Kconfig file. When you need to apply the |
| 98 | config 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 Peng | 75b0b76 | 2022-10-25 18:00:27 +0800 | [diff] [blame] | 111 | |
| 112 | ***************** |
| 113 | The Kconfig files |
| 114 | ***************** |
Jianliang Shen | dfddc98 | 2022-11-29 15:08:19 +0800 | [diff] [blame] | 115 | The Kconfig files are the files written by the |
Kevin Peng | 75b0b76 | 2022-10-25 18:00:27 +0800 | [diff] [blame] | 116 | `Kconfig language <https://www.kernel.org/doc/html/latest/kbuild/kconfig-language.html#kconfig-language>`__ |
| 117 | to describe config options. |
Jianliang Shen | dfddc98 | 2022-11-29 15:08:19 +0800 | [diff] [blame] | 118 | They also uses some Kconfiglib extensions such as optional source ``osource`` and relative source ``rsource`` |
| 119 | so they can only work with the Kconfiglib. |
Kevin Peng | 75b0b76 | 2022-10-25 18:00:27 +0800 | [diff] [blame] | 120 | |
| 121 | -------------- |
| 122 | |
Kevin Peng | 97ac698 | 2022-11-24 17:10:00 +0800 | [diff] [blame] | 123 | *Copyright (c) 2022-2023, Arm Limited. All rights reserved.* |