mirror of
https://github.com/u-boot/u-boot.git
synced 2025-05-08 19:11:53 +00:00
binman: Support replacing data in a cbfs
At present binman cannot replace data within a CBFS since it does not allow rewriting of the files in that CBFS. Implement this by using the new WriteData() method to handle the case. Add a header to compressed data so that the amount of compressed data can be determined without reference to the size of the containing entry. This allows the entry to be larger that the contents, without causing errors in decompression. This is necessary to cope with a compressed device tree being updated in such a way that it shrinks after the entry size is already set (an obscure case). It is not used with CBFS since it has its own metadata for this. Increase the number of passes allowed to resolve the position of entries, to handle this case. Add a test for this new logic. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
7210c89eac
commit
eb0f4a4cb4
7 changed files with 87 additions and 9 deletions
|
@ -9,6 +9,7 @@ import command
|
|||
import glob
|
||||
import os
|
||||
import shutil
|
||||
import struct
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
|
@ -377,7 +378,7 @@ def ToBytes(string):
|
|||
return string.encode('utf-8')
|
||||
return string
|
||||
|
||||
def Compress(indata, algo):
|
||||
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
|
||||
|
@ -408,9 +409,12 @@ def Compress(indata, algo):
|
|||
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):
|
||||
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
|
||||
|
@ -428,6 +432,9 @@ def Decompress(indata, algo):
|
|||
"""
|
||||
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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue