[fdt] Fix some problems

pull/24/head
remittor 1 year ago
parent c6281e5269
commit b782ca1426

@ -78,11 +78,14 @@ class FDT:
""" String representation """
return self.info()
def info(self):
def info(self, props = False):
""" Return object info in human readable format """
msg = "FDT Content:\n"
for path, nodes, props in self.walk():
msg += "{} [{}N, {}P]\n".format(path, len(nodes), len(props))
txt = "{} ({},{})".format(path, len(nodes), len(props))
if props:
txt += ' : ' + ", ".join(x.name for x in props)
msg += txt + "\n"
return msg
def get_node(self, path: str, create: bool = False) -> Node:
@ -242,7 +245,7 @@ class FDT:
node = self.get_node(path)
while True:
all_nodes += node.nodes
current_path = "{}/{}".format(node.path, node.name)
current_path = node.path
current_path = current_path.replace('///', '/')
current_path = current_path.replace('//', '/')
if path and relative:
@ -302,7 +305,7 @@ class FDT:
if node.path == '/':
phandle_value = self.add_label(node.name)
else:
phandle_value = self.add_label(node.path+'/'+node.name)
phandle_value = self.add_label(node.path)
node.set_property('linux,phandle', phandle_value)
node.set_property('phandle', phandle_value)

@ -39,7 +39,7 @@ def new_property(name: str, raw_value: bytes) -> object:
obj.append(st)
return obj
elif len(raw_value) and len(raw_value) % 4 == 0:
elif len(raw_value) > 0 and len(raw_value) <= 256*1024 and len(raw_value) % 4 == 0:
obj = PropWords(name)
# Extract words from raw value
obj.data = [BIGENDIAN_WORD.unpack(raw_value[i:i + 4])[0] for i in range(0, len(raw_value), 4)]
@ -48,8 +48,7 @@ def new_property(name: str, raw_value: bytes) -> object:
elif len(raw_value):
return PropBytes(name, data=raw_value)
else:
return Property(name)
return Property(name)
########################################################################################################################
@ -510,6 +509,10 @@ class PropIncBin(PropBytes):
class Node(BaseItem):
"""Node representation"""
@property
def path(self):
return super().path + '/' + self.name
@property
def props(self):
return self._props

Loading…
Cancel
Save