binman: Select compression bintools in cbfs_util class
Select the lz4 and lzma_alone bintools in cbfs_util class to centralize the supported compression algorithm evaluation inside the class and over multiple classes. Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com> Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
cbe2e75d00
commit
edafeb8da6
@ -20,7 +20,7 @@ import io
|
|||||||
import struct
|
import struct
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from binman import comp_util
|
from binman import bintool
|
||||||
from binman import elf
|
from binman import elf
|
||||||
from patman import command
|
from patman import command
|
||||||
from patman import tools
|
from patman import tools
|
||||||
@ -236,14 +236,18 @@ class CbfsFile(object):
|
|||||||
self.data_len = len(data)
|
self.data_len = len(data)
|
||||||
self.erase_byte = None
|
self.erase_byte = None
|
||||||
self.size = None
|
self.size = None
|
||||||
|
if self.compress == COMPRESS_LZ4:
|
||||||
|
self.comp_bintool = bintool.Bintool.create('lz4')
|
||||||
|
elif self.compress == COMPRESS_LZMA:
|
||||||
|
self.comp_bintool = bintool.Bintool.create('lzma_alone')
|
||||||
|
else:
|
||||||
|
self.comp_bintool = None
|
||||||
|
|
||||||
def decompress(self):
|
def decompress(self):
|
||||||
"""Handle decompressing data if necessary"""
|
"""Handle decompressing data if necessary"""
|
||||||
indata = self.data
|
indata = self.data
|
||||||
if self.compress == COMPRESS_LZ4:
|
if self.comp_bintool:
|
||||||
data = comp_util.decompress(indata, 'lz4')
|
data = self.comp_bintool.decompress(indata)
|
||||||
elif self.compress == COMPRESS_LZMA:
|
|
||||||
data = comp_util.decompress(indata, 'lzma')
|
|
||||||
else:
|
else:
|
||||||
data = indata
|
data = indata
|
||||||
self.memlen = len(data)
|
self.memlen = len(data)
|
||||||
@ -361,10 +365,8 @@ class CbfsFile(object):
|
|||||||
data = elf_data.data
|
data = elf_data.data
|
||||||
elif self.ftype == TYPE_RAW:
|
elif self.ftype == TYPE_RAW:
|
||||||
orig_data = data
|
orig_data = data
|
||||||
if self.compress == COMPRESS_LZ4:
|
if self.comp_bintool:
|
||||||
data = comp_util.compress(orig_data, 'lz4')
|
data = self.comp_bintool.compress(orig_data)
|
||||||
elif self.compress == COMPRESS_LZMA:
|
|
||||||
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,
|
||||||
|
@ -19,7 +19,6 @@ import unittest
|
|||||||
from binman import bintool
|
from binman import bintool
|
||||||
from binman import cbfs_util
|
from binman import cbfs_util
|
||||||
from binman.cbfs_util import CbfsWriter
|
from binman.cbfs_util import CbfsWriter
|
||||||
from binman import comp_util
|
|
||||||
from binman import elf
|
from binman import elf
|
||||||
from patman import test_util
|
from patman import test_util
|
||||||
from patman import tools
|
from patman import tools
|
||||||
@ -50,7 +49,8 @@ class TestCbfs(unittest.TestCase):
|
|||||||
cls.cbfstool = bintool.Bintool.create('cbfstool')
|
cls.cbfstool = bintool.Bintool.create('cbfstool')
|
||||||
cls.have_cbfstool = cls.cbfstool.is_present()
|
cls.have_cbfstool = cls.cbfstool.is_present()
|
||||||
|
|
||||||
cls.have_lz4 = comp_util.HAVE_LZ4
|
lz4 = bintool.Bintool.create('lz4')
|
||||||
|
cls.have_lz4 = lz4.is_present()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
||||||
|
Loading…
Reference in New Issue
Block a user