dtoc: Add a function to obtain a list of phandles

Add a function which can decode a property containing a list of phandles.
This is useful for finding nodes linked to a property. Also provide a way
to look up a single phandle and get the Fdt object from a Node.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass
2018-07-17 13:25:46 -06:00
parent 4f5dea4543
commit 94a7c603b4
3 changed files with 57 additions and 0 deletions

View File

@@ -181,6 +181,14 @@ class Node:
self.subnodes = []
self.props = {}
def GetFdt(self):
"""Get the Fdt object for this node
Returns:
Fdt object
"""
return self._fdt
def FindNode(self, name):
"""Find a node given its name
@@ -314,6 +322,17 @@ class Fdt:
with open(self._fname) as fd:
self._fdt_obj = libfdt.Fdt(fd.read())
def LookupPhandle(self, phandle):
"""Look up a phandle
Args:
phandle: Phandle to look up (int)
Returns:
Node object the phandle points to
"""
return self.phandle_to_node.get(phandle)
def Scan(self, root='/'):
"""Scan a device tree, building up a tree of Node objects