diff mbox series

[v2,08/28] binman: Move CompressData() into Entry base class

Message ID 20201026174016.v2.8.Ic9d88753747c0ece1716ee5b006c38282fc6f040@changeid
State Accepted
Commit 87c962943aec7aef8849c60f018a5e7756e5b7ba
Delegated to: Simon Glass
Headers show
Series binman: Support compression of sections | expand

Commit Message

Simon Glass Oct. 26, 2020, 11:40 p.m. UTC
At present this is only used by blobs. To allow it to be used by other
entry types (such as sections), move it into the base class.

Also read the compression type in the base class.

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

(no changes since v1)

 tools/binman/entry.py      | 17 +++++++++++++++++
 tools/binman/etype/blob.py |  7 -------
 2 files changed, 17 insertions(+), 7 deletions(-)

Comments

Simon Glass Oct. 30, 2020, 3:34 a.m. UTC | #1
At present this is only used by blobs. To allow it to be used by other
entry types (such as sections), move it into the base class.

Also read the compression type in the base class.

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

(no changes since v1)

 tools/binman/entry.py      | 17 +++++++++++++++++
 tools/binman/etype/blob.py |  7 -------
 2 files changed, 17 insertions(+), 7 deletions(-)

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

Patch

diff --git a/tools/binman/entry.py b/tools/binman/entry.py
index f7adc3b1abb..173c9131cbb 100644
--- a/tools/binman/entry.py
+++ b/tools/binman/entry.py
@@ -180,6 +180,9 @@  class Entry(object):
         self.expand_size = fdt_util.GetBool(self._node, 'expand-size')
         self.missing_msg = fdt_util.GetString(self._node, 'missing-msg')
 
+        # This is only supported by blobs and sections at present
+        self.compress = fdt_util.GetString(self._node, 'compress', 'none')
+
     def GetDefaultFilename(self):
         return None
 
@@ -836,3 +839,17 @@  features to produce new behaviours.
             list of possible tags, most desirable first
         """
         return list(filter(None, [self.missing_msg, self.name, self.etype]))
+
+    def CompressData(self, indata):
+        """Compress data according to the entry's compression method
+
+        Args:
+            indata: Data to compress
+
+        Returns:
+            Compressed data (first word is the compressed size)
+        """
+        if self.compress != 'none':
+            self.uncomp_size = len(indata)
+        data = tools.Compress(indata, self.compress)
+        return data
diff --git a/tools/binman/etype/blob.py b/tools/binman/etype/blob.py
index ecfb1e476e8..301ac55e3b2 100644
--- a/tools/binman/etype/blob.py
+++ b/tools/binman/etype/blob.py
@@ -33,7 +33,6 @@  class Entry_blob(Entry):
     def __init__(self, section, etype, node):
         super().__init__(section, etype, node)
         self._filename = fdt_util.GetString(self._node, 'filename', self.etype)
-        self.compress = fdt_util.GetString(self._node, 'compress', 'none')
 
     def ObtainContents(self):
         self._filename = self.GetDefaultFilename()
@@ -48,12 +47,6 @@  class Entry_blob(Entry):
         self.ReadBlobContents()
         return True
 
-    def CompressData(self, indata):
-        if self.compress != 'none':
-            self.uncomp_size = len(indata)
-        data = tools.Compress(indata, self.compress)
-        return data
-
     def ReadBlobContents(self):
         """Read blob contents into memory