aboutsummaryrefslogtreecommitdiff
path: root/tools/patman
diff options
context:
space:
mode:
authorSimon Glass2022-01-09 20:14:03 -0700
committerSimon Glass2022-01-25 12:36:11 -0700
commitad35ce5466187298bc998e851f355f4bb119428b (patch)
treeef18009bf49172279308fda9c28e0e55d44ceffe /tools/patman
parentf75db1e9960bca5b287d3471819e451f03cd4bd7 (diff)
binman: Move compression into binman
The compression functions are not actually used by patman, so we don't need then in the tools module. Also we want to change them to use bintools, which patman will not support. Move these into a new comp_util module, within binman. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools/patman')
-rw-r--r--tools/patman/tools.py79
1 files changed, 0 insertions, 79 deletions
diff --git a/tools/patman/tools.py b/tools/patman/tools.py
index 072b024646d..5dfecaf917b 100644
--- a/tools/patman/tools.py
+++ b/tools/patman/tools.py
@@ -7,7 +7,6 @@ import glob
import os
import shlex
import shutil
-import struct
import sys
import tempfile
import urllib.request
@@ -518,84 +517,6 @@ def ToString(bval):
"""
return bval.decode('utf-8')
-def Compress(indata, algo, with_header=True):
- """Compress some data using a given algorithm
-
- Note that for lzma this uses an old version of the algorithm, not that
- provided by xz.
-
- This requires 'lz4' and 'lzma_alone' tools. It also requires an output
- directory to be previously set up, by calling PrepareOutputDir().
-
- Care is taken to use unique temporary files so that this function can be
- called from multiple threads.
-
- Args:
- indata: Input data to compress
- algo: Algorithm to use ('none', 'gzip', 'lz4' or 'lzma')
-
- Returns:
- Compressed data
- """
- if algo == 'none':
- return indata
- fname = tempfile.NamedTemporaryFile(prefix='%s.comp.tmp' % algo,
- dir=outdir).name
- WriteFile(fname, indata)
- if algo == 'lz4':
- data = Run('lz4', '--no-frame-crc', '-B4', '-5', '-c', fname,
- binary=True)
- # cbfstool uses a very old version of lzma
- elif algo == 'lzma':
- outfname = tempfile.NamedTemporaryFile(prefix='%s.comp.otmp' % algo,
- dir=outdir).name
- Run('lzma_alone', 'e', fname, outfname, '-lc1', '-lp0', '-pb0', '-d8')
- data = ReadFile(outfname)
- elif algo == 'gzip':
- data = Run('gzip', '-c', fname, binary=True)
- else:
- raise ValueError("Unknown algorithm '%s'" % algo)
- if with_header:
- hdr = struct.pack('<I', len(data))
- data = hdr + data
- return data
-
-def Decompress(indata, algo, with_header=True):
- """Decompress some data using a given algorithm
-
- Note that for lzma this uses an old version of the algorithm, not that
- provided by xz.
-
- This requires 'lz4' and 'lzma_alone' tools. It also requires an output
- directory to be previously set up, by calling PrepareOutputDir().
-
- Args:
- indata: Input data to decompress
- algo: Algorithm to use ('none', 'gzip', 'lz4' or 'lzma')
-
- Returns:
- Compressed data
- """
- if algo == 'none':
- return indata
- if with_header:
- data_len = struct.unpack('<I', indata[:4])[0]
- indata = indata[4:4 + data_len]
- fname = GetOutputFilename('%s.decomp.tmp' % algo)
- with open(fname, 'wb') as fd:
- fd.write(indata)
- if algo == 'lz4':
- data = Run('lz4', '-dc', fname, binary=True)
- elif algo == 'lzma':
- outfname = GetOutputFilename('%s.decomp.otmp' % algo)
- Run('lzma_alone', 'd', fname, outfname)
- data = ReadFile(outfname, binary=True)
- elif algo == 'gzip':
- data = Run('gzip', '-cd', fname, binary=True)
- else:
- raise ValueError("Unknown algorithm '%s'" % algo)
- return data
-
def ToHex(val):
"""Convert an integer value (or None) to a string