diff mbox series

[U-Boot,v2,18/31] binman: Use the cbfs memlen field only for uncompressed length

Message ID 20190708202553.225715-19-sjg@chromium.org
State Accepted
Commit 52107ee4df878d26923a498b62beedbbaa5c1f7e
Delegated to: Simon Glass
Headers show
Series binman: Allow reading of images to list contents | expand

Commit Message

Simon Glass July 8, 2019, 8:25 p.m. UTC
The purpose of this badly named field is a bit ambiguous. Adjust the code
to use it only to store the uncompressed length of a file, leaving it set
to None if there is no compression used. This makes it easy to see if the
value in this field is relevant / useful.

Also set data_len for compressed fields, since it should be the length of
the compressed data, not the uncompressed data.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v2: None

 tools/binman/cbfs_util.py | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

Comments

Simon Glass July 18, 2019, 1:58 a.m. UTC | #1
The purpose of this badly named field is a bit ambiguous. Adjust the code
to use it only to store the uncompressed length of a file, leaving it set
to None if there is no compression used. This makes it easy to see if the
value in this field is relevant / useful.

Also set data_len for compressed fields, since it should be the length of
the compressed data, not the uncompressed data.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v2: None

 tools/binman/cbfs_util.py | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

Applied to u-boot-dm, thanks!
diff mbox series

Patch

diff --git a/tools/binman/cbfs_util.py b/tools/binman/cbfs_util.py
index 530629a5c96..4691be4aee2 100644
--- a/tools/binman/cbfs_util.py
+++ b/tools/binman/cbfs_util.py
@@ -197,7 +197,8 @@  class CbfsFile(object):
         data_len: Length of (possibly compressed) data in bytes
         ftype: File type (TYPE_...)
         compression: Compression type (COMPRESS_...)
-        memlen: Length of data in memory (typically the uncompressed length)
+        memlen: Length of data in memory, i.e. the uncompressed length, None if
+            no compression algortihm is selected
         load: Load address in memory if known, else None
         entry: Entry address in memory if known, else None. This is where
             execution starts after the file is loaded
@@ -213,11 +214,11 @@  class CbfsFile(object):
         self.data = data
         self.ftype = ftype
         self.compress = compress
-        self.memlen = len(data)
+        self.memlen = None
         self.load = None
         self.entry = None
         self.base_address = None
-        self.data_len = 0
+        self.data_len = len(data)
         self.erase_byte = None
         self.size = None
 
@@ -349,9 +350,11 @@  class CbfsFile(object):
                 data = tools.Compress(orig_data, 'lz4')
             elif self.compress == COMPRESS_LZMA:
                 data = tools.Compress(orig_data, 'lzma')
+            self.memlen = len(orig_data)
+            self.data_len = len(data)
             attr = struct.pack(ATTR_COMPRESSION_FORMAT,
                                FILE_ATTR_TAG_COMPRESSION, ATTR_COMPRESSION_LEN,
-                               self.compress, len(orig_data))
+                               self.compress, self.memlen)
         elif self.ftype == TYPE_EMPTY:
             data = tools.GetBytes(self.erase_byte, self.size)
         else: