1.. _kconfig-functions:
2
3Custom Kconfig Preprocessor Functions
4#####################################
5
6Kconfiglib supports custom Kconfig preprocessor functions written in Python.
7These functions are defined in
8:zephyr_file:`scripts/kconfig/kconfigfunctions.py`.
9
10.. note::
11
12   The official Kconfig preprocessor documentation can be found `here
13   <https://www.kernel.org/doc/html/latest/kbuild/kconfig-macro-language.html>`__.
14
15Most of the custom preprocessor functions are used to get devicetree
16information into Kconfig. For example, the default value of a Kconfig symbol
17can be fetched from a devicetree ``reg`` property.
18
19Devicetree-related Functions
20****************************
21
22The functions listed below are used to get devicetree information into Kconfig.
23See the Python docstrings in :zephyr_file:`scripts/kconfig/kconfigfunctions.py`
24for detailed documentation.
25
26The ``*_int`` version of each function returns the value as a decimal integer,
27while the ``*_hex`` version returns a hexadecimal value starting with ``0x``.
28
29.. code-block:: none
30
31   $(dt_alias_enabled,<node alias>)
32   $(dt_chosen_bool_prop, <property in /chosen>, <prop>)
33   $(dt_chosen_enabled,<property in /chosen>)
34   $(dt_chosen_has_compat,<property in /chosen>)
35   $(dt_chosen_label,<property in /chosen>)
36   $(dt_chosen_path,<property in /chosen>)
37   $(dt_chosen_reg_addr_hex,<property in /chosen>[,<index>,<unit>])
38   $(dt_chosen_reg_addr_int,<property in /chosen>[,<index>,<unit>])
39   $(dt_chosen_reg_size_hex,<property in /chosen>[,<index>,<unit>])
40   $(dt_chosen_reg_size_int,<property in /chosen>[,<index>,<unit>])
41   $(dt_compat_enabled,<compatible string>)
42   $(dt_compat_on_bus,<compatible string>,<bus>)
43   $(dt_gpio_hogs_enabled)
44   $(dt_has_compat,<compatible string>)
45   $(dt_node_bool_prop,<node path>,<prop>)
46   $(dt_node_has_compat,<node path>,<compatible string>)
47   $(dt_node_has_prop,<node path>,<prop>)
48   $(dt_node_int_prop_hex,<node path>,<prop>[,<unit>])
49   $(dt_node_int_prop_int,<node path>,<prop>[,<unit>])
50   $(dt_node_parent,<node path>)
51   $(dt_node_reg_addr_hex,<node path>[,<index>,<unit>])
52   $(dt_node_reg_addr_int,<node path>[,<index>,<unit>])
53   $(dt_node_reg_size_hex,<node path>[,<index>,<unit>])
54   $(dt_node_reg_size_int,<node path>[,<index>,<unit>])
55   $(dt_node_str_prop_equals,<node path>,<prop>,<value>)
56   $(dt_nodelabel_array_prop_has_val, <node label>, <prop>, <value>)
57   $(dt_nodelabel_bool_prop,<node label>,<prop>)
58   $(dt_nodelabel_enabled,<node label>)
59   $(dt_nodelabel_enabled_with_compat,<node label>,<compatible string>)
60   $(dt_nodelabel_has_compat,<node label>,<compatible string>)
61   $(dt_nodelabel_has_prop,<node label>,<prop>)
62   $(dt_nodelabel_path,<node label>)
63   $(dt_nodelabel_reg_addr_hex,<node label>[,<index>,<unit>])
64   $(dt_nodelabel_reg_addr_int,<node label>[,<index>,<unit>])
65   $(dt_nodelabel_reg_size_hex,<node label>[,<index>,<unit>])
66   $(dt_nodelabel_reg_size_int,<node label>[,<index>,<unit>])
67   $(dt_path_enabled,<node path>)
68   $(shields_list_contains,<shield name>)
69
70
71Example Usage
72=============
73
74Assume that the devicetree for some board looks like this:
75
76.. code-block:: devicetree
77
78   {
79   	soc {
80   		#address-cells = <1>;
81   		#size-cells = <1>;
82
83   		spi0: spi@10014000 {
84   			compatible = "sifive,spi0";
85   			reg = <0x10014000 0x1000 0x20010000 0x3c0900>;
86   			reg-names = "control", "mem";
87   			...
88   		};
89   };
90
91The second entry in ``reg`` in ``spi@1001400`` (``<0x20010000 0x3c0900>``)
92corresponds to ``mem``, and has the address ``0x20010000``. This address can be
93inserted into Kconfig as follows:
94
95.. code-block:: kconfig
96
97   config FLASH_BASE_ADDRESS
98   	default $(dt_node_reg_addr_hex,/soc/spi@1001400,1)
99
100After preprocessor expansion, this turns into the definition below:
101
102.. code-block:: kconfig
103
104   config FLASH_BASE_ADDRESS
105   	default 0x20010000
106