mirror of
https://github.com/u-boot/u-boot.git
synced 2025-04-30 08:07:59 +00:00
binman: Remove obsolete compressed data header handling
Remove the obsolete compressed data header handling from the utilities to compress and decompress data. The header is uncommon, not supported by U-Boot and incompatible with external compressed artifacts. Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com> Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
9f74395ee5
commit
4f463e3dee
4 changed files with 15 additions and 24 deletions
|
@ -241,9 +241,9 @@ class CbfsFile(object):
|
||||||
"""Handle decompressing data if necessary"""
|
"""Handle decompressing data if necessary"""
|
||||||
indata = self.data
|
indata = self.data
|
||||||
if self.compress == COMPRESS_LZ4:
|
if self.compress == COMPRESS_LZ4:
|
||||||
data = comp_util.decompress(indata, 'lz4', with_header=False)
|
data = comp_util.decompress(indata, 'lz4')
|
||||||
elif self.compress == COMPRESS_LZMA:
|
elif self.compress == COMPRESS_LZMA:
|
||||||
data = comp_util.decompress(indata, 'lzma', with_header=False)
|
data = comp_util.decompress(indata, 'lzma')
|
||||||
else:
|
else:
|
||||||
data = indata
|
data = indata
|
||||||
self.memlen = len(data)
|
self.memlen = len(data)
|
||||||
|
@ -362,9 +362,9 @@ class CbfsFile(object):
|
||||||
elif self.ftype == TYPE_RAW:
|
elif self.ftype == TYPE_RAW:
|
||||||
orig_data = data
|
orig_data = data
|
||||||
if self.compress == COMPRESS_LZ4:
|
if self.compress == COMPRESS_LZ4:
|
||||||
data = comp_util.compress(orig_data, 'lz4', with_header=False)
|
data = comp_util.compress(orig_data, 'lz4')
|
||||||
elif self.compress == COMPRESS_LZMA:
|
elif self.compress == COMPRESS_LZMA:
|
||||||
data = comp_util.compress(orig_data, 'lzma', with_header=False)
|
data = comp_util.compress(orig_data, 'lzma')
|
||||||
self.memlen = len(orig_data)
|
self.memlen = len(orig_data)
|
||||||
self.data_len = len(data)
|
self.data_len = len(data)
|
||||||
attr = struct.pack(ATTR_COMPRESSION_FORMAT,
|
attr = struct.pack(ATTR_COMPRESSION_FORMAT,
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
#
|
#
|
||||||
"""Utilities to compress and decompress data"""
|
"""Utilities to compress and decompress data"""
|
||||||
|
|
||||||
import struct
|
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
from binman import bintool
|
from binman import bintool
|
||||||
|
@ -16,7 +15,7 @@ LZMA_ALONE = bintool.Bintool.create('lzma_alone')
|
||||||
HAVE_LZMA_ALONE = LZMA_ALONE.is_present()
|
HAVE_LZMA_ALONE = LZMA_ALONE.is_present()
|
||||||
|
|
||||||
|
|
||||||
def compress(indata, algo, with_header=True):
|
def compress(indata, algo):
|
||||||
"""Compress some data using a given algorithm
|
"""Compress some data using a given algorithm
|
||||||
|
|
||||||
Note that for lzma this uses an old version of the algorithm, not that
|
Note that for lzma this uses an old version of the algorithm, not that
|
||||||
|
@ -41,12 +40,9 @@ def compress(indata, algo, with_header=True):
|
||||||
data = LZMA_ALONE.compress(indata)
|
data = LZMA_ALONE.compress(indata)
|
||||||
else:
|
else:
|
||||||
raise ValueError("Unknown algorithm '%s'" % algo)
|
raise ValueError("Unknown algorithm '%s'" % algo)
|
||||||
if with_header:
|
|
||||||
hdr = struct.pack('<I', len(data))
|
|
||||||
data = hdr + data
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def decompress(indata, algo, with_header=True):
|
def decompress(indata, algo):
|
||||||
"""Decompress some data using a given algorithm
|
"""Decompress some data using a given algorithm
|
||||||
|
|
||||||
Note that for lzma this uses an old version of the algorithm, not that
|
Note that for lzma this uses an old version of the algorithm, not that
|
||||||
|
@ -64,9 +60,6 @@ def decompress(indata, algo, with_header=True):
|
||||||
"""
|
"""
|
||||||
if algo == 'none':
|
if algo == 'none':
|
||||||
return indata
|
return indata
|
||||||
if with_header:
|
|
||||||
data_len = struct.unpack('<I', indata[:4])[0]
|
|
||||||
indata = indata[4:4 + data_len]
|
|
||||||
if algo == 'lz4':
|
if algo == 'lz4':
|
||||||
data = LZ4.decompress(indata)
|
data = LZ4.decompress(indata)
|
||||||
elif algo == 'lzma':
|
elif algo == 'lzma':
|
||||||
|
|
|
@ -1112,12 +1112,12 @@ features to produce new behaviours.
|
||||||
indata: Data to compress
|
indata: Data to compress
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Compressed data (first word is the compressed size)
|
Compressed data
|
||||||
"""
|
"""
|
||||||
self.uncomp_data = indata
|
self.uncomp_data = indata
|
||||||
if self.compress != 'none':
|
if self.compress != 'none':
|
||||||
self.uncomp_size = len(indata)
|
self.uncomp_size = len(indata)
|
||||||
data = comp_util.compress(indata, self.compress, with_header=False)
|
data = comp_util.compress(indata, self.compress)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def DecompressData(self, indata):
|
def DecompressData(self, indata):
|
||||||
|
@ -1129,7 +1129,7 @@ features to produce new behaviours.
|
||||||
Returns:
|
Returns:
|
||||||
Decompressed data
|
Decompressed data
|
||||||
"""
|
"""
|
||||||
data = comp_util.decompress(indata, self.compress, with_header=False)
|
data = comp_util.decompress(indata, self.compress)
|
||||||
if self.compress != 'none':
|
if self.compress != 'none':
|
||||||
self.uncomp_size = len(data)
|
self.uncomp_size = len(data)
|
||||||
self.uncomp_data = data
|
self.uncomp_data = data
|
||||||
|
|
|
@ -1967,7 +1967,7 @@ class TestFunctional(unittest.TestCase):
|
||||||
self._ResetDtbs()
|
self._ResetDtbs()
|
||||||
|
|
||||||
def _decompress(self, data):
|
def _decompress(self, data):
|
||||||
return comp_util.decompress(data, 'lz4', with_header=False)
|
return comp_util.decompress(data, 'lz4')
|
||||||
|
|
||||||
def testCompress(self):
|
def testCompress(self):
|
||||||
"""Test compression of blobs"""
|
"""Test compression of blobs"""
|
||||||
|
@ -2856,7 +2856,7 @@ class TestFunctional(unittest.TestCase):
|
||||||
def testExtractCbfsRaw(self):
|
def testExtractCbfsRaw(self):
|
||||||
"""Test extracting CBFS compressed data without decompressing it"""
|
"""Test extracting CBFS compressed data without decompressing it"""
|
||||||
data = self._RunExtractCmd('section/cbfs/u-boot-dtb', decomp=False)
|
data = self._RunExtractCmd('section/cbfs/u-boot-dtb', decomp=False)
|
||||||
dtb = comp_util.decompress(data, 'lzma', with_header=False)
|
dtb = comp_util.decompress(data, 'lzma')
|
||||||
self.assertEqual(EXTRACT_DTB_SIZE, len(dtb))
|
self.assertEqual(EXTRACT_DTB_SIZE, len(dtb))
|
||||||
|
|
||||||
def testExtractBadEntry(self):
|
def testExtractBadEntry(self):
|
||||||
|
@ -4427,16 +4427,14 @@ class TestFunctional(unittest.TestCase):
|
||||||
rest = base[len(U_BOOT_DATA):]
|
rest = base[len(U_BOOT_DATA):]
|
||||||
|
|
||||||
# Check compressed data
|
# Check compressed data
|
||||||
expect1 = comp_util.compress(COMPRESS_DATA + U_BOOT_DATA, 'lz4',
|
expect1 = comp_util.compress(COMPRESS_DATA + U_BOOT_DATA, 'lz4')
|
||||||
with_header=False)
|
|
||||||
data1 = rest[:len(expect1)]
|
data1 = rest[:len(expect1)]
|
||||||
section1 = self._decompress(data1)
|
section1 = self._decompress(data1)
|
||||||
self.assertEquals(expect1, data1)
|
self.assertEquals(expect1, data1)
|
||||||
self.assertEquals(COMPRESS_DATA + U_BOOT_DATA, section1)
|
self.assertEquals(COMPRESS_DATA + U_BOOT_DATA, section1)
|
||||||
rest1 = rest[len(expect1):]
|
rest1 = rest[len(expect1):]
|
||||||
|
|
||||||
expect2 = comp_util.compress(COMPRESS_DATA + COMPRESS_DATA, 'lz4',
|
expect2 = comp_util.compress(COMPRESS_DATA + COMPRESS_DATA, 'lz4')
|
||||||
with_header=False)
|
|
||||||
data2 = rest1[:len(expect2)]
|
data2 = rest1[:len(expect2)]
|
||||||
section2 = self._decompress(data2)
|
section2 = self._decompress(data2)
|
||||||
self.assertEquals(expect2, data2)
|
self.assertEquals(expect2, data2)
|
||||||
|
@ -5221,11 +5219,11 @@ fdt fdtmap Extract the devicetree blob from the fdtmap
|
||||||
|
|
||||||
def testInvalidCompress(self):
|
def testInvalidCompress(self):
|
||||||
with self.assertRaises(ValueError) as e:
|
with self.assertRaises(ValueError) as e:
|
||||||
comp_util.compress(b'', 'invalid', with_header=False)
|
comp_util.compress(b'', 'invalid')
|
||||||
self.assertIn("Unknown algorithm 'invalid'", str(e.exception))
|
self.assertIn("Unknown algorithm 'invalid'", str(e.exception))
|
||||||
|
|
||||||
with self.assertRaises(ValueError) as e:
|
with self.assertRaises(ValueError) as e:
|
||||||
comp_util.decompress(b'1234', 'invalid', with_header=False)
|
comp_util.decompress(b'1234', 'invalid')
|
||||||
self.assertIn("Unknown algorithm 'invalid'", str(e.exception))
|
self.assertIn("Unknown algorithm 'invalid'", str(e.exception))
|
||||||
|
|
||||||
def testBintoolDocs(self):
|
def testBintoolDocs(self):
|
||||||
|
|
Loading…
Add table
Reference in a new issue