[U-Boot] [PATCH 24/53] binman: Add a function to obtain the image for an Entry

Simon Glass sjg at chromium.org
Sat Jul 20 18:23:46 UTC 2019


At present we have an 'image' property in the entry for this purpose, but
this is not necessary and seems error-prone in the presence of
inheritance. Add a function instead. The Entry_section class overrides
this with a special version, since top-level sections are in fact images,
since Image inherits Entry_section.

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

 tools/binman/entry.py         |  8 ++++++++
 tools/binman/etype/fmap.py    |  2 +-
 tools/binman/etype/section.py | 17 ++++++++++++++---
 tools/binman/image.py         |  1 -
 4 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/tools/binman/entry.py b/tools/binman/entry.py
index c4ddb43b318..ddf52d8e103 100644
--- a/tools/binman/entry.py
+++ b/tools/binman/entry.py
@@ -700,3 +700,11 @@ features to produce new behaviours.
         data = self.ReadData(decomp)
         self.ProcessContentsUpdate(data)
         self.Detail('Loaded data size %x' % len(data))
+
+    def GetImage(self):
+        """Get the image containing this entry
+
+        Returns:
+            Image object containing this entry
+        """
+        return self.section.GetImage()
diff --git a/tools/binman/etype/fmap.py b/tools/binman/etype/fmap.py
index f8d8d866f13..56677cbac1c 100644
--- a/tools/binman/etype/fmap.py
+++ b/tools/binman/etype/fmap.py
@@ -49,7 +49,7 @@ class Entry_fmap(Entry):
                 areas.append(fmap_util.FmapArea(pos or 0, entry.size or 0,
                                             tools.FromUnicode(entry.name), 0))
 
-        entries = self.section.image.GetEntries()
+        entries = self.GetImage().GetEntries()
         areas = []
         for entry in entries.values():
             _AddEntries(areas, entry)
diff --git a/tools/binman/etype/section.py b/tools/binman/etype/section.py
index c875a79f1ff..0fb81419cea 100644
--- a/tools/binman/etype/section.py
+++ b/tools/binman/etype/section.py
@@ -45,8 +45,6 @@ class Entry_section(Entry):
     def __init__(self, section, etype, node, test=False):
         if not test:
             Entry.__init__(self, section, etype, node)
-        if section:
-            self.image = section.image
         self._entries = OrderedDict()
         self._pad_byte = 0
         self._sort = False
@@ -374,7 +372,7 @@ class Entry_section(Entry):
             Image size as an integer number of bytes, which may be None if the
                 image size is dynamic and its sections have not yet been packed
         """
-        return self.image.size
+        return self.GetImage().size
 
     def FindEntryType(self, etype):
         """Find an entry type in the section
@@ -468,3 +466,16 @@ class Entry_section(Entry):
         for entry in self._entries.values():
             entry.LoadData(decomp)
         self.Detail('Loaded data')
+
+    def GetImage(self):
+        """Get the image containing this section
+
+        Note that a top-level section is actually an Image, so this function may
+        return self.
+
+        Returns:
+            Image object containing this section
+        """
+        if not self.section:
+            return self
+        return self.section.GetImage()
diff --git a/tools/binman/image.py b/tools/binman/image.py
index 970d33f7110..c9908187343 100644
--- a/tools/binman/image.py
+++ b/tools/binman/image.py
@@ -42,7 +42,6 @@ class Image(section.Entry_section):
             we create a section manually.
     """
     def __init__(self, name, node, test=False):
-        self.image = self
         section.Entry_section.__init__(self, None, 'section', node, test)
         self.name = 'main-section'
         self.image_name = name
-- 
2.22.0.657.g960e92d24f-goog



More information about the U-Boot mailing list