[fdt] Fix some problems

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

@ -78,11 +78,14 @@ class FDT:
""" String representation """ """ String representation """
return self.info() return self.info()
def info(self): def info(self, props = False):
""" Return object info in human readable format """ """ Return object info in human readable format """
msg = "FDT Content:\n" msg = "FDT Content:\n"
for path, nodes, props in self.walk(): 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 return msg
def get_node(self, path: str, create: bool = False) -> Node: def get_node(self, path: str, create: bool = False) -> Node:
@ -242,7 +245,7 @@ class FDT:
node = self.get_node(path) node = self.get_node(path)
while True: while True:
all_nodes += node.nodes 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('///', '/')
current_path = current_path.replace('//', '/') current_path = current_path.replace('//', '/')
if path and relative: if path and relative:
@ -302,7 +305,7 @@ class FDT:
if node.path == '/': if node.path == '/':
phandle_value = self.add_label(node.name) phandle_value = self.add_label(node.name)
else: 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('linux,phandle', phandle_value)
node.set_property('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) obj.append(st)
return obj 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) obj = PropWords(name)
# Extract words from raw value # 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)] 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): elif len(raw_value):
return PropBytes(name, data=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): class Node(BaseItem):
"""Node representation""" """Node representation"""
@property
def path(self):
return super().path + '/' + self.name
@property @property
def props(self): def props(self):
return self._props return self._props

Loading…
Cancel
Save