summaryrefslogtreecommitdiff
path: root/tools/binman/entry.py
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2019-07-20 21:23:58 +0300
committerSimon Glass <sjg@chromium.org>2019-07-29 18:38:06 +0300
commit61ec04f9eda413664e5c11a6099c89a44b73b5b9 (patch)
tree5234f74a0da4d87cd229b08ce61dd12d2c18822a /tools/binman/entry.py
parent79d3c58d1268786ce40c6c0920ed2a447247fdc4 (diff)
downloadu-boot-61ec04f9eda413664e5c11a6099c89a44b73b5b9.tar.xz
binman: Support shrinking a entry after packing
Sometimes an entry may shrink after it has already been packed. In that case we must repack the items. Of course it is always possible to just leave the entry at its original size and waste space at the end. This is what binman does by default, since there is the possibility of the entry changing size every time binman calculates its contents, thus causing a loop. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools/binman/entry.py')
-rw-r--r--tools/binman/entry.py28
1 files changed, 19 insertions, 9 deletions
diff --git a/tools/binman/entry.py b/tools/binman/entry.py
index 8dacc61f5a..90192c11b7 100644
--- a/tools/binman/entry.py
+++ b/tools/binman/entry.py
@@ -285,16 +285,26 @@ class Entry(object):
"""
size_ok = True
new_size = len(data)
- if state.AllowEntryExpansion():
+ if state.AllowEntryExpansion() and new_size > self.contents_size:
+ # self.data will indicate the new size needed
+ size_ok = False
+ elif state.AllowEntryContraction() and new_size < self.contents_size:
+ size_ok = False
+
+ # If not allowed to change, try to deal with it or give up
+ if size_ok:
if new_size > self.contents_size:
- tout.Debug("Entry '%s' size change from %s to %s" % (
- self._node.path, ToHex(self.contents_size),
- ToHex(new_size)))
- # self.data will indicate the new size needed
- size_ok = False
- elif new_size != self.contents_size:
- self.Raise('Cannot update entry size from %d to %d' %
- (self.contents_size, new_size))
+ self.Raise('Cannot update entry size from %d to %d' %
+ (self.contents_size, new_size))
+
+ # Don't let the data shrink. Pad it if necessary
+ if size_ok and new_size < self.contents_size:
+ data += tools.GetBytes(0, self.contents_size - new_size)
+
+ if not size_ok:
+ tout.Debug("Entry '%s' size change from %s to %s" % (
+ self._node.path, ToHex(self.contents_size),
+ ToHex(new_size)))
self.SetContents(data)
return size_ok