aboutsummaryrefslogtreecommitdiff
path: root/tools/binman/entry.py
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2018-07-06 10:27:19 -0600
committerSimon Glass <sjg@chromium.org>2018-07-09 09:11:00 -0600
commit5c890238c480a96d4d0b06c92199e21867170c31 (patch)
treee538c0257a7f4d8c8377ecb00044281536085dec /tools/binman/entry.py
parent2cd01285b53f376e439e4cbdbce808ca8231ef84 (diff)
downloadu-boot-5c890238c480a96d4d0b06c92199e21867170c31.zip
u-boot-5c890238c480a96d4d0b06c92199e21867170c31.tar.gz
u-boot-5c890238c480a96d4d0b06c92199e21867170c31.tar.bz2
binman: Tidy up setting of entry contents
At present the contents of an entry are set in subclasses simply by assigning to the data and content_size properties. Add some methods to do this, so that we have more control. In particular, add a method to set the contents without changing its size, so we can validate that case. Add a test case for trying to change the size when this is not allowed. 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, 28 insertions, 0 deletions
diff --git a/tools/binman/entry.py b/tools/binman/entry.py
index e4d688c..303c992 100644
--- a/tools/binman/entry.py
+++ b/tools/binman/entry.py
@@ -55,6 +55,7 @@ class Entry(object):
self.name = node and (name_prefix + node.name) or 'none'
self.pos = None
self.size = None
+ self.data = ''
self.contents_size = 0
self.align = None
self.align_size = None
@@ -138,6 +139,33 @@ class Entry(object):
if prefix:
self.name = prefix + self.name
+ def SetContents(self, data):
+ """Set the contents of an entry
+
+ This sets both the data and content_size properties
+
+ Args:
+ data: Data to set to the contents (string)
+ """
+ self.data = data
+ self.contents_size = len(self.data)
+
+ def ProcessContentsUpdate(self, data):
+ """Update the contens of an entry, after the size is fixed
+
+ This checks that the new data is the same size as the old.
+
+ Args:
+ data: Data to set to the contents (string)
+
+ Raises:
+ ValueError if the new data size is not the same as the old
+ """
+ if len(data) != self.contents_size:
+ self.Raise('Cannot update entry size from %d to %d' %
+ (len(data), self.contents_size))
+ self.SetContents(data)
+
def ObtainContents(self):
"""Figure out the contents of an entry.