error if not)
force-bad-datatype: Force a call to GetEntryArgsOrProps() with a bad
data type (generating an error)
+ require-bintool-for-contents: Raise an error if the specified
+ bintool isn't usable in ObtainContents()
+ require-bintool-for-pack: Raise an error if the specified
+ bintool isn't usable in Pack()
"""
def __init__(self, section, etype, node):
super().__init__(section, etype, node)
self.return_contents = True
self.contents = b'aa'
+ # Set to the required bintool when collecting bintools.
+ self.bintool_for_contents = None
+ self.require_bintool_for_contents = fdt_util.GetString(self._node,
+ 'require-bintool-for-contents')
+ if self.require_bintool_for_contents == '':
+ self.require_bintool_for_contents = '_testing'
+
+ self.bintool_for_pack = None
+ self.require_bintool_for_pack = fdt_util.GetString(self._node,
+ 'require-bintool-for-pack')
+ if self.require_bintool_for_pack == '':
+ self.require_bintool_for_pack = '_testing'
+
+ def Pack(self, offset):
+ """Figure out how to pack the entry into the section"""
+ if self.require_bintool_for_pack:
+ if self.bintool_for_pack is None:
+ self.Raise("Required bintool unusable in Pack()")
+ return super().Pack(offset)
+
def ObtainContents(self, fake_size=0):
if self.return_unknown_contents or not self.return_contents:
return False
self.contents_size = len(self.data)
if self.return_contents_once:
self.return_contents = False
+ if self.require_bintool_for_contents:
+ if self.bintool_for_contents is None:
+ self.Raise("Required bintool unusable in ObtainContents()")
return True
def GetOffsets(self):
if not self.never_complete_process_fdt:
self.process_fdt_ready = True
return ready
+
+ def AddBintools(self, btools):
+ """Add the bintools used by this entry type"""
+ if self.require_bintool_for_contents is not None:
+ self.bintool_for_contents = self.AddBintool(btools,
+ self.require_bintool_for_contents)
+ if self.require_bintool_for_pack is not None:
+ self.bintool_for_pack = self.AddBintool(btools,
+ self.require_bintool_for_pack)
self._CheckSafeUniqueNames(orig_image, image)
+ def testReplaceCmdWithBintool(self):
+ """Test replacing an entry that needs a bintool to pack"""
+ data = self._DoReadFileRealDtb('232_replace_with_bintool.dts')
+ expected = U_BOOT_DATA + b'aa'
+ self.assertEqual(expected, data[:len(expected)])
+
+ try:
+ tmpdir, updated_fname = self._SetupImageInTmpdir()
+ fname = os.path.join(tmpdir, 'update-testing.bin')
+ tools.write_file(fname, b'zz')
+ self._DoBinman('replace', '-i', updated_fname,
+ '_testing', '-f', fname)
+
+ data = tools.read_file(updated_fname)
+ expected = U_BOOT_DATA + b'zz'
+ self.assertEqual(expected, data[:len(expected)])
+ finally:
+ shutil.rmtree(tmpdir)
+
+ def testReplaceCmdOtherWithBintool(self):
+ """Test replacing an entry when another needs a bintool to pack"""
+ data = self._DoReadFileRealDtb('232_replace_with_bintool.dts')
+ expected = U_BOOT_DATA + b'aa'
+ self.assertEqual(expected, data[:len(expected)])
+
+ try:
+ tmpdir, updated_fname = self._SetupImageInTmpdir()
+ fname = os.path.join(tmpdir, 'update-u-boot.bin')
+ tools.write_file(fname, b'x' * len(U_BOOT_DATA))
+ self._DoBinman('replace', '-i', updated_fname,
+ 'u-boot', '-f', fname)
+
+ data = tools.read_file(updated_fname)
+ expected = b'x' * len(U_BOOT_DATA) + b'aa'
+ self.assertEqual(expected, data[:len(expected)])
+ finally:
+ shutil.rmtree(tmpdir)
+
+
if __name__ == "__main__":
unittest.main()