summaryrefslogtreecommitdiff
path: root/tools/binman/ftest.py
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/ftest.py
parent04187a845c86215da0e3ad680cdcf2fc7515b99a (diff)
downloadu-boot-83d73c2f7c471c1a7e5a9a2bf0de287491408b2d.tar.gz
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/ftest.py')
-rw-r--r--tools/binman/ftest.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index 6bfef7b63a..1c3c46fc23 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -54,6 +54,7 @@ CROS_EC_RW_DATA = 'ecrw'
GBB_DATA = 'gbbd'
BMPBLK_DATA = 'bmp'
VBLOCK_DATA = 'vblk'
+COMPRESS_DATA = 'data to compress'
class TestFunctional(unittest.TestCase):
@@ -116,6 +117,8 @@ class TestFunctional(unittest.TestCase):
with open(self.TestFile('descriptor.bin')) as fd:
TestFunctional._MakeInputFile('descriptor.bin', fd.read())
+ TestFunctional._MakeInputFile('compress', COMPRESS_DATA)
+
@classmethod
def tearDownClass(self):
"""Remove the temporary input directory and its contents"""
@@ -1505,6 +1508,34 @@ class TestFunctional(unittest.TestCase):
finally:
self._ResetDtbs()
+ def _decompress(self, data):
+ out = os.path.join(self._indir, 'lz4.tmp')
+ with open(out, 'wb') as fd:
+ fd.write(data)
+ return tools.Run('lz4', '-dc', out)
+ '''
+ try:
+ orig = lz4.frame.decompress(data)
+ except AttributeError:
+ orig = lz4.decompress(data)
+ '''
+
+ def testCompress(self):
+ """Test compression of blobs"""
+ data, _, _, out_dtb_fname = self._DoReadFileDtb('83_compress.dts',
+ use_real_dtb=True, update_dtb=True)
+ dtb = fdt.Fdt(out_dtb_fname)
+ dtb.Scan()
+ props = self._GetPropTree(dtb, ['size', 'uncomp-size'])
+ orig = self._decompress(data)
+ self.assertEquals(COMPRESS_DATA, orig)
+ expected = {
+ 'blob:uncomp-size': len(COMPRESS_DATA),
+ 'blob:size': len(data),
+ 'size': len(data),
+ }
+ self.assertEqual(expected, props)
+
if __name__ == "__main__":
unittest.main()