--- /dev/null
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (C) 2022 Weidmüller Interface GmbH & Co. KG
+# Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
+#
+"""Bintool implementation for zstd
+
+zstd allows compression and decompression of files.
+
+Documentation is available via::
+
+ man zstd
+"""
+
+from binman import bintool
+
+# pylint: disable=C0103
+class Bintoolzstd(bintool.BintoolPacker):
+ """Compression/decompression using the zstd algorithm
+
+ This bintool supports running `zstd` to compress and decompress data, as
+ used by binman.
+
+ It is also possible to fetch the tool, which uses `apt` to install it.
+
+ Documentation is available via::
+
+ man zstd
+ """
+ def __init__(self, name):
+ super().__init__(name)
"""
algo = self.compress
if algo != 'none':
- algos = ['bzip2', 'gzip', 'lz4', 'lzma', 'lzo', 'xz']
+ algos = ['bzip2', 'gzip', 'lz4', 'lzma', 'lzo', 'xz', 'zstd']
if algo not in algos:
raise ValueError("Unknown algorithm '%s'" % algo)
names = {'lzma': 'lzma_alone', 'lzo': 'lzop'}
def ProcessContents(self):
"""Re-read the DTB contents so that we get any calculated properties"""
_, indata = state.GetFdtContents(self.GetFdtEtype())
+
+ if self.compress == 'zstd' and self.prepend != 'length':
+ self.Raise('The zstd compression requires a length header')
+
data = self.CompressData(indata)
return self.ProcessContentsUpdate(data)
REPACK_DTB_PROPS = ['orig-offset', 'orig-size']
# Supported compression bintools
-COMP_BINTOOLS = ['bzip2', 'gzip', 'lz4', 'lzma_alone', 'lzop', 'xz']
+COMP_BINTOOLS = ['bzip2', 'gzip', 'lz4', 'lzma_alone', 'lzop', 'xz', 'zstd']
class TestFunctional(unittest.TestCase):
"""Functional tests for binman
def testCompUtilPadding(self):
"""Test padding of compression algorithms"""
- for bintool in self.comp_bintools.values():
+ # Skip zstd because it doesn't support padding
+ for bintool in [v for k,v in self.comp_bintools.items() if k != 'zstd']:
self._CheckBintool(bintool)
data = bintool.compress(COMPRESS_DATA)
self.assertNotEqual(COMPRESS_DATA, data)
orig = bintool.decompress(data)
self.assertEquals(COMPRESS_DATA, orig)
+ def testCompressDtbZstd(self):
+ """Test that zstd compress of device-tree files failed"""
+ with self.assertRaises(ValueError) as e:
+ self._DoTestFile('238_compress_dtb_zstd.dts')
+ self.assertIn("Node '/binman/u-boot-dtb': The zstd compression "
+ "requires a length header", str(e.exception))
+
if __name__ == "__main__":
unittest.main()