[U-Boot] [PATCH 44/53] binman: Support replacing data in a cbfs

2019-07-20 Thread Simon Glass
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 
---

 tools/binman/cbfs_util.py  | 10 ---
 tools/binman/control.py|  2 +-
 tools/binman/entry_test.py |  5 
 tools/binman/etype/cbfs.py |  3 ++-
 tools/binman/ftest.py  | 26 +-
 tools/binman/test/142_replace_cbfs.dts | 37 ++
 tools/patman/tools.py  | 11 ++--
 7 files changed, 85 insertions(+), 9 deletions(-)
 create mode 100644 tools/binman/test/142_replace_cbfs.dts

diff --git a/tools/binman/cbfs_util.py b/tools/binman/cbfs_util.py
index 6d9a876ee85..99d77878c9a 100644
--- a/tools/binman/cbfs_util.py
+++ b/tools/binman/cbfs_util.py
@@ -208,6 +208,7 @@ class CbfsFile(object):
 cbfs_offset: Offset of file data in bytes from start of CBFS, or None 
to
 place this file anyway
 data: Contents of file, uncompressed
+orig_data: Original data added to the file, possibly compressed
 data_len: Length of (possibly compressed) data in bytes
 ftype: File type (TYPE_...)
 compression: Compression type (COMPRESS_...)
@@ -226,6 +227,7 @@ class CbfsFile(object):
 self.offset = None
 self.cbfs_offset = cbfs_offset
 self.data = data
+self.orig_data = data
 self.ftype = ftype
 self.compress = compress
 self.memlen = None
@@ -240,9 +242,9 @@ class CbfsFile(object):
 """Handle decompressing data if necessary"""
 indata = self.data
 if self.compress == COMPRESS_LZ4:
-data = tools.Decompress(indata, 'lz4')
+data = tools.Decompress(indata, 'lz4', with_header=False)
 elif self.compress == COMPRESS_LZMA:
-data = tools.Decompress(indata, 'lzma')
+data = tools.Decompress(indata, 'lzma', with_header=False)
 else:
 data = indata
 self.memlen = len(data)
@@ -361,9 +363,9 @@ class CbfsFile(object):
 elif self.ftype == TYPE_RAW:
 orig_data = data
 if self.compress == COMPRESS_LZ4:
-data = tools.Compress(orig_data, 'lz4')
+data = tools.Compress(orig_data, 'lz4', with_header=False)
 elif self.compress == COMPRESS_LZMA:
-data = tools.Compress(orig_data, 'lzma')
+data = tools.Compress(orig_data, 'lzma', with_header=False)
 self.memlen = len(orig_data)
 self.data_len = len(data)
 attr = struct.pack(ATTR_COMPRESSION_FORMAT,
diff --git a/tools/binman/control.py b/tools/binman/control.py
index 22e3e306e54..9c8bc6253fc 100644
--- a/tools/binman/control.py
+++ b/tools/binman/control.py
@@ -311,7 +311,7 @@ def ProcessImage(image, update_fdt, write_map, 
get_contents=True,
 # since changing an offset from 0x100 to 0x104 (for example) can
 # alter the compressed size of the device tree. So we need a
 # third pass for this.
-passes = 3
+passes = 5
 for pack_pass in range(passes):
 try:
 image.PackEntries()
diff --git a/tools/binman/entry_test.py b/tools/binman/entry_test.py
index ee729f37519..cc1fb795da5 100644
--- a/tools/binman/entry_test.py
+++ b/tools/binman/entry_test.py
@@ -92,6 +92,11 @@ class TestEntry(unittest.TestCase):
 dtb = entry.Entry.Create(None, self.GetNode(), 'u-boot-dtb')
 self.assertEqual('u-boot-dtb', dtb.GetFdtEtype())
 
+def testWriteChildData(self):
+"""Test the WriteChildData() method of the base class"""
+base = entry.Entry.Create(None, self.GetNode(), 'blob-dtb')
+self.assertTrue(base.WriteChildData(base))
+
 
 if __name__ == "__main__":
 unittest.main()
diff --git a/tools/binman/etype/cbfs.py b/tools/binman/etype/cbfs.py
index 0109fdbb918..28a9c81a8ad 100644
--- a/tools/binman/etype/cbfs.py
+++ b/tools/binman/etype/cbfs.py
@@ -168,6 +168,7 @@ class Entry_cbfs(Entry):
 self._cbfs_arg = fdt_util.GetString(node, 'cbfs-arch', 'x86')
 self._cbfs_entries = OrderedDict()
 self._ReadSubnodes()
+self.reader = None
 
 def ObtainContents(self, skip=None):
 arch = cbfs_util.find_arch(self._cbfs_arg)
@@ -202,7 +203,7 @@ class 

Re: [U-Boot] [PATCH 44/53] binman: Support replacing data in a cbfs

2019-07-29 Thread sjg
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 
---

 tools/binman/cbfs_util.py  | 10 ---
 tools/binman/control.py|  2 +-
 tools/binman/entry_test.py |  5 
 tools/binman/etype/cbfs.py |  3 ++-
 tools/binman/ftest.py  | 26 +-
 tools/binman/test/142_replace_cbfs.dts | 37 ++
 tools/patman/tools.py  | 11 ++--
 7 files changed, 85 insertions(+), 9 deletions(-)
 create mode 100644 tools/binman/test/142_replace_cbfs.dts

Applied to u-boot-dm, thanks!
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot