[PATCH v2 04/11] binman: Move 'external' support into base class

Simon Glass sjg at chromium.org
Mon Aug 31 01:20:09 CEST 2020


At present we have an Entry_blob_ext which implement a blob which holds an
external binary. We need to support other entry types that hold external
binaries, e.g. Entry_blob_named_by_arg. Move the support into the base
Entry class to allow this.

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

Changes in v2:
- Add new patch to move 'external' support into base class

 tools/binman/README.entries    |  2 +-
 tools/binman/entry.py          | 14 ++++++++++++++
 tools/binman/etype/blob.py     |  8 +++++++-
 tools/binman/etype/blob_ext.py | 11 -----------
 tools/binman/etype/section.py  | 14 ++------------
 5 files changed, 24 insertions(+), 25 deletions(-)

diff --git a/tools/binman/README.entries b/tools/binman/README.entries
index 97bfae16116..1086a6a9790 100644
--- a/tools/binman/README.entries
+++ b/tools/binman/README.entries
@@ -692,7 +692,7 @@ Properties / Entry arguments: (see binman README for more information)
         when writing out the map
 
 Properties:
-    _allow_missing: True if this section permits external blobs to be
+    allow_missing: True if this section permits external blobs to be
         missing their contents. The second will produce an image but of
         course it will not work.
 
diff --git a/tools/binman/entry.py b/tools/binman/entry.py
index 3434a3f8048..7e4b0ab29ae 100644
--- a/tools/binman/entry.py
+++ b/tools/binman/entry.py
@@ -59,6 +59,10 @@ class Entry(object):
         compress: Compression algoithm used (e.g. 'lz4'), 'none' if none
         orig_offset: Original offset value read from node
         orig_size: Original size value read from node
+        missing: True if this entry is missing its contents
+        allow_missing: Allow children of this entry to be missing (used by
+            subclasses such as Entry_section)
+        external: True if this entry contains an external binary blob
     """
     def __init__(self, section, etype, node, name_prefix=''):
         # Put this here to allow entry-docs and help to work without libfdt
@@ -85,6 +89,8 @@ class Entry(object):
         self._expand_size = False
         self.compress = 'none'
         self.missing = False
+        self.external = False
+        self.allow_missing = False
 
     @staticmethod
     def Lookup(node_path, etype):
@@ -815,3 +821,11 @@ features to produce new behaviours.
         """
         if self.missing:
             missing_list.append(self)
+
+    def GetAllowMissing(self):
+        """Get whether a section allows missing external blobs
+
+        Returns:
+            True if allowed, False if not allowed
+        """
+        return self.allow_missing
diff --git a/tools/binman/etype/blob.py b/tools/binman/etype/blob.py
index e507203709f..c5f97c85a38 100644
--- a/tools/binman/etype/blob.py
+++ b/tools/binman/etype/blob.py
@@ -37,7 +37,13 @@ class Entry_blob(Entry):
 
     def ObtainContents(self):
         self._filename = self.GetDefaultFilename()
-        self._pathname = tools.GetInputFilename(self._filename)
+        self._pathname = tools.GetInputFilename(self._filename,
+                                                self.section.GetAllowMissing())
+        # Allow the file to be missing
+        if self.external and not self._pathname:
+            self.SetContents(b'')
+            self.missing = True
+            return True
         self.ReadBlobContents()
         return True
 
diff --git a/tools/binman/etype/blob_ext.py b/tools/binman/etype/blob_ext.py
index 8d641001a9e..e372445f300 100644
--- a/tools/binman/etype/blob_ext.py
+++ b/tools/binman/etype/blob_ext.py
@@ -26,14 +26,3 @@ class Entry_blob_ext(Entry_blob):
     def __init__(self, section, etype, node):
         Entry_blob.__init__(self, section, etype, node)
         self.external = True
-
-    def ObtainContents(self):
-        self._filename = self.GetDefaultFilename()
-        self._pathname = tools.GetInputFilename(self._filename,
-                                                self.section.GetAllowMissing())
-        # Allow the file to be missing
-        if not self._pathname:
-            self.SetContents(b'')
-            self.missing = True
-            return True
-        return super().ObtainContents()
diff --git a/tools/binman/etype/section.py b/tools/binman/etype/section.py
index 73c5553c812..328e2cfad01 100644
--- a/tools/binman/etype/section.py
+++ b/tools/binman/etype/section.py
@@ -35,7 +35,7 @@ class Entry_section(Entry):
             when writing out the map
 
     Properties:
-        _allow_missing: True if this section permits external blobs to be
+        allow_missing: True if this section permits external blobs to be
             missing their contents. The second will produce an image but of
             course it will not work.
 
@@ -54,8 +54,6 @@ class Entry_section(Entry):
         self._sort = False
         self._skip_at_start = None
         self._end_4gb = False
-        self._allow_missing = False
-        self.missing = False
 
     def ReadNode(self):
         """Read properties from the image node"""
@@ -549,18 +547,10 @@ class Entry_section(Entry):
         Args:
             allow_missing: True if allowed, False if not allowed
         """
-        self._allow_missing = allow_missing
+        self.allow_missing = allow_missing
         for entry in self._entries.values():
             entry.SetAllowMissing(allow_missing)
 
-    def GetAllowMissing(self):
-        """Get whether a section allows missing external blobs
-
-        Returns:
-            True if allowed, False if not allowed
-        """
-        return self._allow_missing
-
     def CheckMissing(self, missing_list):
         """Check if any entries in this section have missing external blobs
 
-- 
2.28.0.402.g5ffc5be6b7-goog



More information about the U-Boot mailing list