summaryrefslogtreecommitdiff
path: root/tools/binman/etype
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2018-09-14 04:57:26 -0600
committerSimon Glass <sjg@chromium.org>2018-09-29 11:49:32 -0600
commit83d73c2f7c471c1a7e5a9a2bf0de287491408b2d (patch)
tree0f97947d81d656fc25afe2714e2938a6451459cf /tools/binman/etype
parent04187a845c86215da0e3ad680cdcf2fc7515b99a (diff)
binman: Support compressed entries
Add support for compressing blob entries. This can help reduce image sizes for many types of data. It requires that the firmware be able to decompress the data at run-time. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools/binman/etype')
-rw-r--r--tools/binman/etype/blob.py49
1 files changed, 40 insertions, 9 deletions
diff --git a/tools/binman/etype/blob.py b/tools/binman/etype/blob.py
index 3f46eecf30..642a0e482a 100644
--- a/tools/binman/etype/blob.py
+++ b/tools/binman/etype/blob.py
@@ -7,6 +7,7 @@
from entry import Entry
import fdt_util
+import state
import tools
class Entry_blob(Entry):
@@ -17,14 +18,23 @@ class Entry_blob(Entry):
Properties / Entry arguments:
- filename: Filename of file to read into entry
+ - compress: Compression algorithm to use:
+ none: No compression
+ lz4: Use lz4 compression (via 'lz4' command-line utility)
This entry reads data from a file and places it in the entry. The
default filename is often specified specified by the subclass. See for
example the 'u_boot' entry which provides the filename 'u-boot.bin'.
+
+ If compression is enabled, an extra 'uncomp-size' property is written to
+ the node (if enabled with -u) which provides the uncompressed size of the
+ data.
"""
def __init__(self, section, etype, node):
Entry.__init__(self, section, etype, node)
- self._filename = fdt_util.GetString(self._node, "filename", self.etype)
+ self._filename = fdt_util.GetString(self._node, 'filename', self.etype)
+ self._compress = fdt_util.GetString(self._node, 'compress', 'none')
+ self._uncompressed_size = None
def ObtainContents(self):
self._filename = self.GetDefaultFilename()
@@ -33,15 +43,36 @@ class Entry_blob(Entry):
return True
def ReadBlobContents(self):
- with open(self._pathname) as fd:
- # 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.
- self.SetContents(fd.read())
+ # 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)
+
+ try:
+ data = lz4.frame.compress(data)
+ except AttributeError:
+ data = lz4.compress(data)
+ '''
+ data = tools.Run('lz4', '-c', self._pathname, )
+ 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)