aboutsummaryrefslogtreecommitdiff
path: root/tools/dtoc/fdt.py
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2018-09-14 04:57:15 -0600
committerSimon Glass <sjg@chromium.org>2018-09-28 11:09:01 -0600
commite21c27af47183619c7ec7097abb1dec34410e775 (patch)
tree3ce664c775d41266a3cad56335c3c52c4c9e5587 /tools/dtoc/fdt.py
parentaf53f5aafcbbe1ba97264a0262067657f3dc8c34 (diff)
downloadu-boot-e21c27af47183619c7ec7097abb1dec34410e775.zip
u-boot-e21c27af47183619c7ec7097abb1dec34410e775.tar.gz
u-boot-e21c27af47183619c7ec7097abb1dec34410e775.tar.bz2
dtoc: Support adding new nodes
Add a way to add new nodes and sync them back to the blob. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools/dtoc/fdt.py')
-rw-r--r--tools/dtoc/fdt.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py
index ccf3b23..26f4a4e 100644
--- a/tools/dtoc/fdt.py
+++ b/tools/dtoc/fdt.py
@@ -337,6 +337,12 @@ class Node:
"""
self.props[prop_name].SetInt(val)
+ def AddSubnode(self, name):
+ path = self.path + '/' + name
+ subnode = Node(self._fdt, self, None, name, path)
+ self.subnodes.append(subnode)
+ return subnode
+
def Sync(self, auto_resize=False):
"""Sync node changes back to the device tree
@@ -350,6 +356,20 @@ class Node:
Raises:
FdtException if auto_resize is False and there is not enough space
"""
+ if self._offset is None:
+ # The subnode doesn't exist yet, so add it
+ fdt_obj = self._fdt._fdt_obj
+ if auto_resize:
+ while True:
+ offset = fdt_obj.add_subnode(self.parent._offset, self.name,
+ (libfdt.NOSPACE,))
+ if offset != -libfdt.NOSPACE:
+ break
+ fdt_obj.resize(fdt_obj.totalsize() + 1024)
+ else:
+ offset = fdt_obj.add_subnode(self.parent._offset, self.name)
+ self._offset = offset
+
# Sync subnodes in reverse so that we don't disturb node offsets for
# nodes that are earlier in the DT. This avoids an O(n^2) rescan of
# node offsets.