The latest development version of this page may be more current than this released 4.0.0 version.

Custom Kconfig Preprocessor Functions

Kconfiglib supports custom Kconfig preprocessor functions written in Python. These functions are defined in scripts/kconfig/kconfigfunctions.py.

Note

The official Kconfig preprocessor documentation can be found here.

See the Python docstrings in scripts/kconfig/kconfigfunctions.py for detailed documentation. Most of the custom preprocessor functions are used to get devicetree information into Kconfig. For example, the default value of a Kconfig symbol can be fetched from a devicetree reg property.

Integer functions

The functions listed below can be used to do arithmetic operations on integer variables, such as addition, subtraction and more.

$(add,<value>[,value]...)
$(dec,<value>[,value]...)
$(div,<value>[,value]...)
$(inc,<value>[,value]...)
$(max,<value>[,value]...)
$(min,<value>[,value]...)
$(mod,<value>[,value]...)
$(mul,<value>[,value]...)
$(sub,<value>[,value]...)

String functions

The functions listed below can be used to modify string variables.

$(normalize_upper,<string>)
$(substring,<string>,<start>[,<stop>])

Other functions

Functions to perform specific operations, currently only a check if a shield name is specified.

$(shields_list_contains,<shield name>)

Example Usage

Assume that the devicetree for some board looks like this:

{
     soc {
             #address-cells = <1>;
             #size-cells = <1>;

             spi0: spi@10014000 {
                     compatible = "sifive,spi0";
                     reg = <0x10014000 0x1000 0x20010000 0x3c0900>;
                     reg-names = "control", "mem";
                     ...
             };
};

The second entry in reg in spi@1001400 (<0x20010000 0x3c0900>) corresponds to mem, and has the address 0x20010000. This address can be inserted into Kconfig as follows:

config FLASH_BASE_ADDRESS
     default $(dt_node_reg_addr_hex,/soc/spi@1001400,1)

After preprocessor expansion, this turns into the definition below:

config FLASH_BASE_ADDRESS
     default 0x20010000