The objective of using Kconfig in RIOT is to configure software modules at compile-time. This means having a standard way of:
Modules in RIOT expose their configurable parameters via Kconfig files (for more information on Kconfig syntax check the specification). In these files documentation, restrictions, default values and dependencies can be expressed.
Kconfig files are structured through the file system mirroring the current module distribution. In time, all modules will have Kconfig files to make themselves configurable through this system.
The user can assign values to the exposed parameters, either by manually writing '.config' files or using an interface such as Menuconfig. Parameters with no assigned values will take the default ones. For a detailed distinction between Kconfig and '.config' files see Appendix B.
Using '.config' and Kconfig files the build system takes care of doing the necessary checks on the values according to the parameter definition. After that, the
autoconf.h header file is generated, it contains all the configurations in the form of (
CONFIG_ prefixed) macros.
In order to use the graphical interface menuconfig to configure the application, run
make menuconfig in the application's folder. All available configurations (based on the used modules) for the particular platform will be presented. By default, the configuration of a module via Kconfig is not enabled. In order to activate the configuration via Kconfig the corresponding option should be selected. That will enable the configuration of all inner options, if available.
Once the desired configuration is achieved save the configuration to the default proposed path and exit. The saved configuration will be applied when the code is compiled (
If the current configuration will be used in the future it can be saved in the application's folder as
user.config, using the 'Save' option in menuconfig. This way it will be persistent after cleaning the application directory (
The second way to configure the application is by directly writing '.config' files. Two files will be sources of configuration during the generation of the final header file:
user.config, which should be placed inside the application's folder.
app.config sets default configuration values for the particular application, the user can override them by setting them in
Let's say that the
SOCK_UTIL_SCHEME_MAXLEN symbol in
sock_util module needs to be configured. The
user.config file could look like:
In this case, there is no need for using menuconfig. It's enough just to call
make all in the application folder, as this configuration will be read and applied. Note that if any dependency issue occurs, warnings will be generated (e.g. not enabling the configuration of a module via Kconfig).
To expose application-specific configuration options a
Kconfig file can be placed in the application's folder. For an example of this you can check the tests/kconfig application.
When a certain module is being configured via Kconfig the configuration macro will not longer be overridable by means of CFLAGS (e.g. set on the compilation command or on a Makefile). Consider this if you are getting a 'redefined warning'.
When using Kconfig as the configurator for RIOT, configuration symbols may be used in Makefiles through the build system. For this to work properly make sure that when cleaning an application you call
make clean && make all, instead of
make clean all.
The integration of Kconfig into the build system is mainly done in
Currently, the resolution of module dependencies is performed by the build system where all the used modules and packages end up listed in the
USEMODULE make variables. In the next phases of integration we plan to resolve dependencies using Kconfig.
The list of modules needed for the particular build is dumped into the
$ (GENERATED_DIR)/Kconfig.dep file, where each module is translated into a Kconfig symbol as documented in Appendix A.
In this step configuration values are taken from multiple sources and merged into a single
merged.config configuration file. This file is temporary and is removed on clean. If the user needs to save a particular configuration set, a backup has to be saved (this can be done using the menuconfig interface) so it can be loaded later in this step.
To accomplish merging of multiple input files, the
mergeconfig script is used. Note that the order matters: existing configuration values are merged in the order expressed in the input section, where the last value assigned to a parameter has the highest priority. If no configuration files are available all default values will be applied.
merged.config is the only configuration input for the
autoconf.h in the generation step.
$ (APPDIR)/app.config: Application specific default configurations.
$ (APPDIR)/user.config: Configurations saved by user.
Menuconfig is a graphical interface for software configuration. It is used for the configuration of the Linux kernel. This section explains the process that occurs when RIOT is being configured using the menuconfig interface.
Kconfig file is used in this step to show the configurable parameters of the system. Kconfig will filter innaplicable parameters (i.e. parameters exposed by modules that are not being used) based on the file
$ (GENERATED_DIR)/Kconfig.dep generated in step 1.
During the transition phase, the user needs to enable Kconfig explicitly per module, by setting the corresponding option. If using
menuconfig a checkbox with a submenu has to be selected, if using
.config files a
CONFIG_KCONFIG_MODULE_ prefixed option has to be set to
y. For more information see Making configuration via Kconfig optional.
Note that if Kconfig is not used to configure a module, the corresponding header files default values will be used.
merged.config is one of the inputs for menuconfig. This means that any configuration that the application defines in the
app.config or a backup configuration from the user in
user.config are taken into account on the first run (see Appendix C).
In this step the user chooses configuration values (or selects the minimal configuration) and saves it to the
merged.config file. Here the user can choose to save a backup configuration file for later at a different location (e.g. a
user.config file in the application folder).
$ (GENERATED_DIR)/merged.config.oldbackup file.
With the addition of Kconfig a dependency has been added to the build process: the
$ (GENERATED_DIR)/autoconf.h header file. This header file is the main output from the Kconfig configuration system. It holds all the macros that should be used to configure modules in RIOT:
In order to generate the
autoconf.h file the
genconfig script is used. Inputs for this script are the main
Kconfig file and
merged.config configuration file, which holds the selected values for the exposed parameters.
Kconfigfile exposing configuration of modules.
$ (GENERATED_DIR)/autoconf.hconfiguration header file.
These files are defined in
|Defines configuration options of modules.|
|Holds a list of the modules that are being compiled.|
|Holds default application configuration values.|
|Holds configuration values applied by the user.|
|Holds configuration from multiple sources. Used to generate header.|
|Header file containing the macros that applied the selected configuration.|
As '.config' files have Makefile syntax they can be included when building, which allows to access the applied configuration from the build system and, in the future, to check for enabled modules.
During migration this is also useful, as it gives the ability to check if a parameter is being configured via Kconfig or a default value via
CFLAGS could be injected. For example:
Symbols will have the same name as the configuration macros (thus will always have the
CONFIG_ prefix). As the configuration file is loaded in
Makefile.include care should be taken when performing checks in the application's Makefile. The symbols will not be defined until after including
During transition to the usage of Kconfig as the main configurator for RIOT, the default behavior will be the traditional one: expose configuration options in header files and use CFLAGS as inputs. To allow optional configuration via Kconfig, a convention will be used when writing Kconfig files.
Modules should be contained in their own
menuconfig entries, this way the user can choose to enable the configuration via Kconfig for an specific module. These entries should define a dependency on the module they configure (see Appendix A to see how to check if a module is being used).
The module configuration then can be enabled either via the menuconfig interface:
or by means of a '.config' file:
In order to show only the relevant configuration parameters to the user with respect to a given application and board selection, Kconfig needs knowledge about all modules and packages to be used for a compilation. Currently dependency handling among modules is performed by the build system (via
Makefile.dep files). The interface defined to declared the used modules and packages is the
$ (GENERATED_DIR)/Kconfig.dep file.
Kconfig.dep is a Kconfig file that will define symbols of the form:
There will be a symbol for every used module (i.e. every module in
USEMODULE make variable) and package. The names in the symbols will be uppercase and separated by
_. Based on these symbols configurability is decided. Modules and packages symbols will have
PKG_ prefixes respectively.
The following is an example of how to use these symbols in Kconfig files to enable/disable a configuration menu:
Then, every configuration option for the previous module would be modeled like:
Kconfig files describe a configuration database, which is a collection of configuration options organized in a tree structure. Configuration options may have dependencies (among other attributes), which are used to determine their visibility.
Kconfig files are written in Kconfig language defined in the Linux kernel. Configuration options have attributes such as types, prompts and default values.
On the other hand configuration files contain assignment of values to configuration options and use Makefile syntax. They can also be used to save a set of configuration values as backup.
In other words: Kconfig files describe configuration options and '.config' files assign their values.
In the current configuration flow the user can choose to configure RIOT using the menuconfig graphical interface or writing '.config' files by hand.
As explained in the 'Configuration sources merging step' of the configuration process, configuration from multiple sources are loaded to create a single
merged.config file, and the order of merging matters: last file has priority.
While editing values directly via '.config' files
merged.config will be re-built. Once the user decides to edit
merged.config directly using menuconfig, the file will not be re-built anymore, and any changes by manually editing the source files will have no effect. To go back to manual edition a
make clean has to be issued in the application directory.