diff mbox series

[U-Boot,43/53] binman: Update Entry.WriteData() to handle special sections

Message ID 20190720182416.183626-44-sjg@chromium.org
State Accepted
Commit 7210c89eac7fb68947f5f31372d9f1e93f42df0c
Delegated to: Simon Glass
Headers show
Series binman: Support replacing entries in an existing image | expand

Commit Message

Simon Glass July 20, 2019, 6:24 p.m. UTC
At present this method assumes that the parent section does not need
to recalculate its position or adjust any metadata it may contain. But
when the entry changes size this may not be true. Also if the parent
section is more than just a container (e.g. it is a CBFS) then the
section may need to regenerate its output.

Add a new WriteChildData() method to sections and call this from the
WriteData() method, to handle this situation.

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

 tools/binman/entry.py         | 21 ++++++++++++++++++++-
 tools/binman/etype/cbfs.py    |  8 ++++++--
 tools/binman/etype/section.py |  3 +++
 3 files changed, 29 insertions(+), 3 deletions(-)

Comments

Simon Glass July 29, 2019, 9:22 p.m. UTC | #1
At present this method assumes that the parent section does not need
to recalculate its position or adjust any metadata it may contain. But
when the entry changes size this may not be true. Also if the parent
section is more than just a container (e.g. it is a CBFS) then the
section may need to regenerate its output.

Add a new WriteChildData() method to sections and call this from the
WriteData() method, to handle this situation.

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

 tools/binman/entry.py         | 21 ++++++++++++++++++++-
 tools/binman/etype/cbfs.py    |  8 ++++++--
 tools/binman/etype/section.py |  3 +++
 3 files changed, 29 insertions(+), 3 deletions(-)

Applied to u-boot-dm, thanks!
diff mbox series

Patch

diff --git a/tools/binman/entry.py b/tools/binman/entry.py
index 8416214fc93..6a2c6e0d92e 100644
--- a/tools/binman/entry.py
+++ b/tools/binman/entry.py
@@ -751,7 +751,26 @@  features to produce new behaviours.
         self.contents_size = self.size
         ok = self.ProcessContentsUpdate(data)
         self.Detail('WriteData: size=%x, ok=%s' % (len(data), ok))
-        return ok
+        section_ok = self.section.WriteChildData(self)
+        return ok and section_ok
+
+    def WriteChildData(self, child):
+        """Handle writing the data in a child entry
+
+        This should be called on the child's parent section after the child's
+        data has been updated. It
+
+        This base-class implementation does nothing, since the base Entry object
+        does not have any children.
+
+        Args:
+            child: Child Entry that was written
+
+        Returns:
+            True if the section could be updated successfully, False if the
+                data is such that the section could not updat
+        """
+        return True
 
     def GetSiblingOrder(self):
         """Get the relative order of an entry amoung its siblings
diff --git a/tools/binman/etype/cbfs.py b/tools/binman/etype/cbfs.py
index 2bcdf2fd433..0109fdbb918 100644
--- a/tools/binman/etype/cbfs.py
+++ b/tools/binman/etype/cbfs.py
@@ -169,7 +169,7 @@  class Entry_cbfs(Entry):
         self._cbfs_entries = OrderedDict()
         self._ReadSubnodes()
 
-    def ObtainContents(self):
+    def ObtainContents(self, skip=None):
         arch = cbfs_util.find_arch(self._cbfs_arg)
         if arch is None:
             self.Raise("Invalid architecture '%s'" % self._cbfs_arg)
@@ -179,7 +179,7 @@  class Entry_cbfs(Entry):
         for entry in self._cbfs_entries.values():
             # First get the input data and put it in a file. If not available,
             # try later.
-            if not entry.ObtainContents():
+            if entry != skip and not entry.ObtainContents():
                 return False
             data = entry.GetData()
             cfile = None
@@ -274,3 +274,7 @@  class Entry_cbfs(Entry):
         reader = self.reader
         cfile = reader.files.get(child.name)
         return cfile.data if decomp else cfile.orig_data
+
+    def WriteChildData(self, child):
+        self.ObtainContents(skip=child)
+        return True
diff --git a/tools/binman/etype/section.py b/tools/binman/etype/section.py
index 855e291bc43..5d34fc546af 100644
--- a/tools/binman/etype/section.py
+++ b/tools/binman/etype/section.py
@@ -520,3 +520,6 @@  class Entry_section(Entry):
                             (child.GetPath(), len(indata), child.compress,
                             len(data)))
         return data
+
+    def WriteChildData(self, child):
+        return True