Merge tag 'u-boot-rockchip-20200501' of https://gitlab.denx.de/u-boot/custodians...
[platform/kernel/u-boot.git] / tools / binman / etype / blob.py
index 642a0e4..ede7a7a 100644 (file)
@@ -5,10 +5,10 @@
 # Entry-type module for blobs, which are binary objects read from files
 #
 
-from entry import Entry
-import fdt_util
-import state
-import tools
+from binman.entry import Entry
+from dtoc import fdt_util
+from patman import tools
+from patman import tout
 
 class Entry_blob(Entry):
     """Entry containing an arbitrary binary blob
@@ -33,8 +33,7 @@ class Entry_blob(Entry):
     def __init__(self, section, etype, node):
         Entry.__init__(self, section, etype, node)
         self._filename = fdt_util.GetString(self._node, 'filename', self.etype)
-        self._compress = fdt_util.GetString(self._node, 'compress', 'none')
-        self._uncompressed_size = None
+        self.compress = fdt_util.GetString(self._node, 'compress', 'none')
 
     def ObtainContents(self):
         self._filename = self.GetDefaultFilename()
@@ -42,37 +41,28 @@ 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):
-        # We assume the data is small enough to fit into memory. If this
-        # is used for large filesystem image that might not be true.
-        # In that case, Image.BuildImage() could be adjusted to use a
-        # new Entry method which can read in chunks. Then we could copy
-        # the data in chunks and avoid reading it all at once. For now
-        # this seems like an unnecessary complication.
-        data = tools.ReadFile(self._pathname)
-        if self._compress == 'lz4':
-            self._uncompressed_size = len(data)
-            '''
-            import lz4  # Import this only if needed (python-lz4 dependency)
+        """Read blob contents into memory
+
+        This function compresses the data before storing if needed.
 
-            try:
-                data = lz4.frame.compress(data)
-            except AttributeError:
-                data = lz4.compress(data)
-            '''
-            data = tools.Run('lz4', '-c', self._pathname, )
+        We assume the data is small enough to fit into memory. If this
+        is used for large filesystem image that might not be true.
+        In that case, Image.BuildImage() could be adjusted to use a
+        new Entry method which can read in chunks. Then we could copy
+        the data in chunks and avoid reading it all at once. For now
+        this seems like an unnecessary complication.
+        """
+        indata = tools.ReadFile(self._pathname)
+        data = self.CompressData(indata)
         self.SetContents(data)
         return True
 
     def GetDefaultFilename(self):
         return self._filename
-
-    def AddMissingProperties(self):
-        Entry.AddMissingProperties(self)
-        if self._compress != 'none':
-            state.AddZeroProp(self._node, 'uncomp-size')
-
-    def SetCalculatedProperties(self):
-        Entry.SetCalculatedProperties(self)
-        if self._uncompressed_size is not None:
-            state.SetInt(self._node, 'uncomp-size', self._uncompressed_size)