mirror of
https://github.com/brain-hackers/u-boot-brain
synced 2024-10-02 09:30:43 +09:00
dtoc: Update Fdt.FromData() to allow a name
It is confusing when something goes wrong with a device tree which was created from data rather than a file, since there is no identifying filename. Add an option to provide this. Use the filename as the name, where available Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
d9dad10e3c
commit
880e9ee650
@ -498,29 +498,35 @@ class Fdt:
|
|||||||
Properties:
|
Properties:
|
||||||
fname: Filename of fdt
|
fname: Filename of fdt
|
||||||
_root: Root of device tree (a Node object)
|
_root: Root of device tree (a Node object)
|
||||||
|
name: Helpful name for this Fdt for the user (useful when creating the
|
||||||
|
DT from data rather than a file)
|
||||||
"""
|
"""
|
||||||
def __init__(self, fname):
|
def __init__(self, fname):
|
||||||
self._fname = fname
|
self._fname = fname
|
||||||
self._cached_offsets = False
|
self._cached_offsets = False
|
||||||
self.phandle_to_node = {}
|
self.phandle_to_node = {}
|
||||||
|
self.name = ''
|
||||||
if self._fname:
|
if self._fname:
|
||||||
|
self.name = self._fname
|
||||||
self._fname = fdt_util.EnsureCompiled(self._fname)
|
self._fname = fdt_util.EnsureCompiled(self._fname)
|
||||||
|
|
||||||
with open(self._fname, 'rb') as fd:
|
with open(self._fname, 'rb') as fd:
|
||||||
self._fdt_obj = libfdt.Fdt(fd.read())
|
self._fdt_obj = libfdt.Fdt(fd.read())
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def FromData(data):
|
def FromData(data, name=''):
|
||||||
"""Create a new Fdt object from the given data
|
"""Create a new Fdt object from the given data
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
data: Device-tree data blob
|
data: Device-tree data blob
|
||||||
|
name: Helpful name for this Fdt for the user
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Fdt object containing the data
|
Fdt object containing the data
|
||||||
"""
|
"""
|
||||||
fdt = Fdt(None)
|
fdt = Fdt(None)
|
||||||
fdt._fdt_obj = libfdt.Fdt(bytes(data))
|
fdt._fdt_obj = libfdt.Fdt(bytes(data))
|
||||||
|
fdt.name = name
|
||||||
return fdt
|
return fdt
|
||||||
|
|
||||||
def LookupPhandle(self, phandle):
|
def LookupPhandle(self, phandle):
|
||||||
|
Loading…
Reference in New Issue
Block a user