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
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.
'return-invalid-entry')
self.return_unknown_contents = fdt_util.GetBool(self._node,
'return-unknown-contents')
+ self.bad_update_contents = fdt_util.GetBool(self._node,
+ 'bad-update-contents')
def ObtainContents(self):
if self.return_unknown_contents:
if self.return_invalid_entry :
return {'invalid-entry': [1, 2]}
return {}
+
+ def ProcessContents(self):
+ if self.bad_update_contents:
+ # Request to update the conents with something larger, to cause a
+ # failure.
+ self.ProcessContentsUpdate('aa')
# new Entry method which can read in chunks. Then we could copy
# the data in chunks and avoid reading it all at once. For now
# this seems like an unnecessary complication.
- self.data = fd.read()
- self.contents_size = len(self.data)
+ self.SetContents(fd.read())
return True
def GetDefaultFilename(self):
bss_size = elf.GetSymbolAddress(fname, '__bss_size')
if not bss_size:
self.Raise('Expected __bss_size symbol in spl/u-boot-spl')
- self.data = chr(0) * bss_size
- self.contents_size = bss_size
+ self.SetContents(chr(0) * bss_size)
return True
# Write the microcode position and size into the entry
pos_and_size = struct.pack('<2L', pos, size)
self.target_pos -= self.pos
- self.data = (self.data[:self.target_pos] + pos_and_size +
- self.data[self.target_pos + 8:])
+ self.ProcessContentsUpdate(self.data[:self.target_pos] + pos_and_size +
+ self.data[self.target_pos + 8:])
"processing of contents: remaining [<_testing.Entry__testing ",
str(e.exception))
+ def testBadChangeSize(self):
+ """Test that trying to change the size of an entry fails"""
+ with self.assertRaises(ValueError) as e:
+ self._DoReadFile('59_change_size.dts', True)
+ self.assertIn("Node '/binman/_testing': Cannot update entry size from "
+ '2 to 1', str(e.exception))
+
+
if __name__ == "__main__":
unittest.main()
--- /dev/null
+// SPDX-License-Identifier: GPL-2.0+
+
+/dts-v1/;
+
+/ {
+ #address-cells = <1>;
+ #size-cells = <1>;
+
+ binman {
+ _testing {
+ bad-update-contents;
+ };
+ };
+};