[U-Boot] [PATCH 16/31] binman: Centralise device-tree updates within binman

Simon Glass sjg at chromium.org
Fri Sep 14 10:57:21 UTC 2018


At present we have a few calls to device-tree functions in binman and plan
to add more as we add new entry types which need to report their results.

It makes sense to put this code in a central place so that we can make
sure all device trees are updated. At present we only have U-Boot proper,
but plan to add SPL and TPL too.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 tools/binman/bsection.py |  9 +++++----
 tools/binman/entry.py    |  8 ++++----
 tools/binman/state.py    | 35 +++++++++++++++++++++++++++++++++++
 3 files changed, 44 insertions(+), 8 deletions(-)

diff --git a/tools/binman/bsection.py b/tools/binman/bsection.py
index a0bd1b6d34e..4f5c33f048b 100644
--- a/tools/binman/bsection.py
+++ b/tools/binman/bsection.py
@@ -12,6 +12,7 @@ import sys
 
 import fdt_util
 import re
+import state
 import tools
 
 class Section(object):
@@ -98,14 +99,14 @@ class Section(object):
         """Add new properties to the device tree as needed for this entry"""
         for prop in ['offset', 'size', 'image-pos']:
             if not prop in self._node.props:
-                self._node.AddZeroProp(prop)
+                state.AddZeroProp(self._node, prop)
         for entry in self._entries.values():
             entry.AddMissingProperties()
 
     def SetCalculatedProperties(self):
-        self._node.SetInt('offset', self._offset)
-        self._node.SetInt('size', self._size)
-        self._node.SetInt('image-pos', self._image_pos)
+        state.SetInt(self._node, 'offset', self._offset)
+        state.SetInt(self._node, 'size', self._size)
+        state.SetInt(self._node, 'image-pos', self._image_pos)
         for entry in self._entries.values():
             entry.SetCalculatedProperties()
 
diff --git a/tools/binman/entry.py b/tools/binman/entry.py
index 1d6299aefa5..4b87156ff80 100644
--- a/tools/binman/entry.py
+++ b/tools/binman/entry.py
@@ -168,13 +168,13 @@ class Entry(object):
         """Add new properties to the device tree as needed for this entry"""
         for prop in ['offset', 'size', 'image-pos']:
             if not prop in self._node.props:
-                self._node.AddZeroProp(prop)
+                state.AddZeroProp(self._node, prop)
 
     def SetCalculatedProperties(self):
         """Set the value of device-tree properties calculated by binman"""
-        self._node.SetInt('offset', self.offset)
-        self._node.SetInt('size', self.size)
-        self._node.SetInt('image-pos', self.image_pos)
+        state.SetInt(self._node, 'offset', self.offset)
+        state.SetInt(self._node, 'size', self.size)
+        state.SetInt(self._node, 'image-pos', self.image_pos)
 
     def ProcessFdt(self, fdt):
         return True
diff --git a/tools/binman/state.py b/tools/binman/state.py
index 9583b3fa5f6..5f25b907b9e 100644
--- a/tools/binman/state.py
+++ b/tools/binman/state.py
@@ -118,3 +118,38 @@ def GetFdts():
     """
     yield main_dtb
 
+def GetUpdateNodes(node):
+    """Yield all the nodes that need to be updated in all device trees
+
+    The property referenced by this node is added to any device trees which
+    have the given node. Due to removable of unwanted notes, SPL and TPL may
+    not have this node.
+
+    Args:
+        node: Node object in the main device tree to look up
+
+    Yields:
+        Node objects in each device tree that is in use (U-Boot proper, which
+            is node, SPL and TPL)
+    """
+    yield node
+
+def AddZeroProp(node, prop):
+    """Add a new property to affected device trees with an integer value of 0.
+
+    Args:
+        prop_name: Name of property
+    """
+    for n in GetUpdateNodes(node):
+        n.AddZeroProp(prop)
+
+def SetInt(node, prop, value):
+    """Update an integer property in affected device trees with an integer value
+
+    This is not allowed to change the size of the FDT.
+
+    Args:
+        prop_name: Name of property
+    """
+    for n in GetUpdateNodes(node):
+        n.SetInt(prop, value)
-- 
2.19.0.397.gdd90340f6a-goog



More information about the U-Boot mailing list