scripts: kconfigfunctions: Add dt_has_compat()
Add a function for checking if any node with a given compatible exists,
no matter if its status is "okay" or not.
Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
diff --git a/doc/guides/build/kconfig/preprocessor-functions.rst b/doc/guides/build/kconfig/preprocessor-functions.rst
index 685ff01..5ca13cb 100644
--- a/doc/guides/build/kconfig/preprocessor-functions.rst
+++ b/doc/guides/build/kconfig/preprocessor-functions.rst
@@ -28,6 +28,7 @@
.. code-block:: none
+ $(dt_has_compat,<compatible string>)
$(dt_compat_enabled,<compatible string>)
$(dt_compat_on_bus,<compatible string>,<bus>)
$(dt_chosen_label,<property in /chosen>)
diff --git a/scripts/kconfig/kconfigfunctions.py b/scripts/kconfig/kconfigfunctions.py
index bb254c8..6b2e237 100644
--- a/scripts/kconfig/kconfigfunctions.py
+++ b/scripts/kconfig/kconfigfunctions.py
@@ -457,6 +457,18 @@
return "n"
+
+def dt_has_compat(kconf, _, compat):
+ """
+ This function takes a 'compat' and returns "y" if any compatible node
+ can be found in the EDT, otherwise it returns "n".
+ """
+ if doc_mode or edt is None:
+ return "n"
+
+ return "y" if compat in edt.compat2nodes else "n"
+
+
def dt_compat_enabled(kconf, _, compat):
"""
This function takes a 'compat' and returns "y" if we find a status "okay"
@@ -539,6 +551,7 @@
#
# See the kconfiglib documentation for more details.
functions = {
+ "dt_has_compat": (dt_has_compat, 1, 1),
"dt_compat_enabled": (dt_compat_enabled, 1, 1),
"dt_compat_on_bus": (dt_compat_on_bus, 2, 2),
"dt_chosen_label": (dt_chosen_label, 1, 1),