scripts: kconfig: add dt_node_parent kconfig function

Add dt_node_parent kconfig function, to get parent path for a given
devicetree path when parsing kconfig files

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
This commit is contained in:
Daniel DeGrasse 2022-08-26 12:10:14 -05:00 committed by Carles Cufí
parent 4796ffee7a
commit db9bcd90ce
2 changed files with 21 additions and 0 deletions

View file

@ -58,6 +58,7 @@ while the ``*_hex`` version returns a hexadecimal value starting with ``0x``.
$(dt_node_str_prop_equals,<node path>,<prop>,<value>)
$(dt_nodelabel_has_compat,<node label>,<compatible string>)
$(dt_nodelabel_path,<node label>)
$(dt_node_parent,<node path>)
$(shields_list_contains,<shield name>)

View file

@ -639,6 +639,25 @@ def dt_nodelabel_path(kconf, _, label):
return node.path if node else ""
def dt_node_parent(kconf, _, path):
"""
This function takes a 'path' and looks for an EDT node at that path. If it
finds an EDT node, it will look for the parent of that node. If the parent
exists, it will return the path to that parent. Otherwise, an empty string
will be returned.
"""
if doc_mode or edt is None:
return ""
try:
node = edt.get_node(path)
except edtlib.EDTError:
return ""
if node is None:
return ""
return node.parent.path if node.parent else ""
def shields_list_contains(kconf, _, shield):
"""
@ -694,5 +713,6 @@ functions = {
"dt_node_str_prop_equals": (dt_node_str_prop_equals, 3, 3),
"dt_nodelabel_has_compat": (dt_nodelabel_has_compat, 2, 2),
"dt_nodelabel_path": (dt_nodelabel_path, 1, 1),
"dt_node_parent": (dt_node_parent, 1, 1),
"shields_list_contains": (shields_list_contains, 1, 1),
}