From 9a5d090e664aa5af687af930d487ad94ee671613 Mon Sep 17 00:00:00 2001 From: remittor Date: Sun, 22 Oct 2023 00:37:24 +0300 Subject: [PATCH] [fdt] Fix some problems --- xmir_base/fdt/__init__.py | 11 +++++++---- xmir_base/fdt/items.py | 9 ++++++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/xmir_base/fdt/__init__.py b/xmir_base/fdt/__init__.py index 689b97f..2dfa8ac 100644 --- a/xmir_base/fdt/__init__.py +++ b/xmir_base/fdt/__init__.py @@ -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) diff --git a/xmir_base/fdt/items.py b/xmir_base/fdt/items.py index 277b152..cc7ce8b 100644 --- a/xmir_base/fdt/items.py +++ b/xmir_base/fdt/items.py @@ -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