ftest.py 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089
  1. # SPDX-License-Identifier: GPL-2.0+
  2. # Copyright (c) 2016 Google, Inc
  3. # Written by Simon Glass <sjg@chromium.org>
  4. #
  5. # To run a single test, change to this directory, and:
  6. #
  7. # python -m unittest func_test.TestFunctional.testHelp
  8. from optparse import OptionParser
  9. import os
  10. import shutil
  11. import struct
  12. import sys
  13. import tempfile
  14. import unittest
  15. import binman
  16. import cmdline
  17. import command
  18. import control
  19. import elf
  20. import fdt
  21. import fdt_util
  22. import tools
  23. import tout
  24. # Contents of test files, corresponding to different entry types
  25. U_BOOT_DATA = '1234'
  26. U_BOOT_IMG_DATA = 'img'
  27. U_BOOT_SPL_DATA = '56780123456789abcde'
  28. BLOB_DATA = '89'
  29. ME_DATA = '0abcd'
  30. VGA_DATA = 'vga'
  31. U_BOOT_DTB_DATA = 'udtb'
  32. U_BOOT_SPL_DTB_DATA = 'spldtb'
  33. X86_START16_DATA = 'start16'
  34. X86_START16_SPL_DATA = 'start16spl'
  35. U_BOOT_NODTB_DATA = 'nodtb with microcode pointer somewhere in here'
  36. U_BOOT_SPL_NODTB_DATA = 'splnodtb with microcode pointer somewhere in here'
  37. FSP_DATA = 'fsp'
  38. CMC_DATA = 'cmc'
  39. VBT_DATA = 'vbt'
  40. MRC_DATA = 'mrc'
  41. class TestFunctional(unittest.TestCase):
  42. """Functional tests for binman
  43. Most of these use a sample .dts file to build an image and then check
  44. that it looks correct. The sample files are in the test/ subdirectory
  45. and are numbered.
  46. For each entry type a very small test file is created using fixed
  47. string contents. This makes it easy to test that things look right, and
  48. debug problems.
  49. In some cases a 'real' file must be used - these are also supplied in
  50. the test/ diurectory.
  51. """
  52. @classmethod
  53. def setUpClass(self):
  54. global entry
  55. import entry
  56. # Handle the case where argv[0] is 'python'
  57. self._binman_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
  58. self._binman_pathname = os.path.join(self._binman_dir, 'binman')
  59. # Create a temporary directory for input files
  60. self._indir = tempfile.mkdtemp(prefix='binmant.')
  61. # Create some test files
  62. TestFunctional._MakeInputFile('u-boot.bin', U_BOOT_DATA)
  63. TestFunctional._MakeInputFile('u-boot.img', U_BOOT_IMG_DATA)
  64. TestFunctional._MakeInputFile('spl/u-boot-spl.bin', U_BOOT_SPL_DATA)
  65. TestFunctional._MakeInputFile('blobfile', BLOB_DATA)
  66. TestFunctional._MakeInputFile('me.bin', ME_DATA)
  67. TestFunctional._MakeInputFile('vga.bin', VGA_DATA)
  68. TestFunctional._MakeInputFile('u-boot.dtb', U_BOOT_DTB_DATA)
  69. TestFunctional._MakeInputFile('spl/u-boot-spl.dtb', U_BOOT_SPL_DTB_DATA)
  70. TestFunctional._MakeInputFile('u-boot-x86-16bit.bin', X86_START16_DATA)
  71. TestFunctional._MakeInputFile('spl/u-boot-x86-16bit-spl.bin',
  72. X86_START16_SPL_DATA)
  73. TestFunctional._MakeInputFile('u-boot-nodtb.bin', U_BOOT_NODTB_DATA)
  74. TestFunctional._MakeInputFile('spl/u-boot-spl-nodtb.bin',
  75. U_BOOT_SPL_NODTB_DATA)
  76. TestFunctional._MakeInputFile('fsp.bin', FSP_DATA)
  77. TestFunctional._MakeInputFile('cmc.bin', CMC_DATA)
  78. TestFunctional._MakeInputFile('vbt.bin', VBT_DATA)
  79. TestFunctional._MakeInputFile('mrc.bin', MRC_DATA)
  80. self._output_setup = False
  81. # ELF file with a '_dt_ucode_base_size' symbol
  82. with open(self.TestFile('u_boot_ucode_ptr')) as fd:
  83. TestFunctional._MakeInputFile('u-boot', fd.read())
  84. # Intel flash descriptor file
  85. with open(self.TestFile('descriptor.bin')) as fd:
  86. TestFunctional._MakeInputFile('descriptor.bin', fd.read())
  87. @classmethod
  88. def tearDownClass(self):
  89. """Remove the temporary input directory and its contents"""
  90. if self._indir:
  91. shutil.rmtree(self._indir)
  92. self._indir = None
  93. def setUp(self):
  94. # Enable this to turn on debugging output
  95. # tout.Init(tout.DEBUG)
  96. command.test_result = None
  97. def tearDown(self):
  98. """Remove the temporary output directory"""
  99. tools._FinaliseForTest()
  100. def _RunBinman(self, *args, **kwargs):
  101. """Run binman using the command line
  102. Args:
  103. Arguments to pass, as a list of strings
  104. kwargs: Arguments to pass to Command.RunPipe()
  105. """
  106. result = command.RunPipe([[self._binman_pathname] + list(args)],
  107. capture=True, capture_stderr=True, raise_on_error=False)
  108. if result.return_code and kwargs.get('raise_on_error', True):
  109. raise Exception("Error running '%s': %s" % (' '.join(args),
  110. result.stdout + result.stderr))
  111. return result
  112. def _DoBinman(self, *args):
  113. """Run binman using directly (in the same process)
  114. Args:
  115. Arguments to pass, as a list of strings
  116. Returns:
  117. Return value (0 for success)
  118. """
  119. args = list(args)
  120. if '-D' in sys.argv:
  121. args = args + ['-D']
  122. (options, args) = cmdline.ParseArgs(args)
  123. options.pager = 'binman-invalid-pager'
  124. options.build_dir = self._indir
  125. # For testing, you can force an increase in verbosity here
  126. # options.verbosity = tout.DEBUG
  127. return control.Binman(options, args)
  128. def _DoTestFile(self, fname, debug=False, map=False, update_dtb=False):
  129. """Run binman with a given test file
  130. Args:
  131. fname: Device-tree source filename to use (e.g. 05_simple.dts)
  132. debug: True to enable debugging output
  133. map: True to output map files for the images
  134. update_dtb: Update the offset and size of each entry in the device
  135. tree before packing it into the image
  136. """
  137. args = ['-p', '-I', self._indir, '-d', self.TestFile(fname)]
  138. if debug:
  139. args.append('-D')
  140. if map:
  141. args.append('-m')
  142. if update_dtb:
  143. args.append('-up')
  144. return self._DoBinman(*args)
  145. def _SetupDtb(self, fname, outfile='u-boot.dtb'):
  146. """Set up a new test device-tree file
  147. The given file is compiled and set up as the device tree to be used
  148. for ths test.
  149. Args:
  150. fname: Filename of .dts file to read
  151. outfile: Output filename for compiled device-tree binary
  152. Returns:
  153. Contents of device-tree binary
  154. """
  155. if not self._output_setup:
  156. tools.PrepareOutputDir(self._indir, True)
  157. self._output_setup = True
  158. dtb = fdt_util.EnsureCompiled(self.TestFile(fname))
  159. with open(dtb) as fd:
  160. data = fd.read()
  161. TestFunctional._MakeInputFile(outfile, data)
  162. return data
  163. def _DoReadFileDtb(self, fname, use_real_dtb=False, map=False,
  164. update_dtb=False):
  165. """Run binman and return the resulting image
  166. This runs binman with a given test file and then reads the resulting
  167. output file. It is a shortcut function since most tests need to do
  168. these steps.
  169. Raises an assertion failure if binman returns a non-zero exit code.
  170. Args:
  171. fname: Device-tree source filename to use (e.g. 05_simple.dts)
  172. use_real_dtb: True to use the test file as the contents of
  173. the u-boot-dtb entry. Normally this is not needed and the
  174. test contents (the U_BOOT_DTB_DATA string) can be used.
  175. But in some test we need the real contents.
  176. map: True to output map files for the images
  177. update_dtb: Update the offset and size of each entry in the device
  178. tree before packing it into the image
  179. Returns:
  180. Tuple:
  181. Resulting image contents
  182. Device tree contents
  183. Map data showing contents of image (or None if none)
  184. Output device tree binary filename ('u-boot.dtb' path)
  185. """
  186. dtb_data = None
  187. # Use the compiled test file as the u-boot-dtb input
  188. if use_real_dtb:
  189. dtb_data = self._SetupDtb(fname)
  190. try:
  191. retcode = self._DoTestFile(fname, map=map, update_dtb=update_dtb)
  192. self.assertEqual(0, retcode)
  193. out_dtb_fname = control.GetFdtPath('u-boot.dtb')
  194. # Find the (only) image, read it and return its contents
  195. image = control.images['image']
  196. image_fname = tools.GetOutputFilename('image.bin')
  197. self.assertTrue(os.path.exists(image_fname))
  198. if map:
  199. map_fname = tools.GetOutputFilename('image.map')
  200. with open(map_fname) as fd:
  201. map_data = fd.read()
  202. else:
  203. map_data = None
  204. with open(image_fname) as fd:
  205. return fd.read(), dtb_data, map_data, out_dtb_fname
  206. finally:
  207. # Put the test file back
  208. if use_real_dtb:
  209. TestFunctional._MakeInputFile('u-boot.dtb', U_BOOT_DTB_DATA)
  210. def _DoReadFile(self, fname, use_real_dtb=False):
  211. """Helper function which discards the device-tree binary
  212. Args:
  213. fname: Device-tree source filename to use (e.g. 05_simple.dts)
  214. use_real_dtb: True to use the test file as the contents of
  215. the u-boot-dtb entry. Normally this is not needed and the
  216. test contents (the U_BOOT_DTB_DATA string) can be used.
  217. But in some test we need the real contents.
  218. Returns:
  219. Resulting image contents
  220. """
  221. return self._DoReadFileDtb(fname, use_real_dtb)[0]
  222. @classmethod
  223. def _MakeInputFile(self, fname, contents):
  224. """Create a new test input file, creating directories as needed
  225. Args:
  226. fname: Filename to create
  227. contents: File contents to write in to the file
  228. Returns:
  229. Full pathname of file created
  230. """
  231. pathname = os.path.join(self._indir, fname)
  232. dirname = os.path.dirname(pathname)
  233. if dirname and not os.path.exists(dirname):
  234. os.makedirs(dirname)
  235. with open(pathname, 'wb') as fd:
  236. fd.write(contents)
  237. return pathname
  238. @classmethod
  239. def TestFile(self, fname):
  240. return os.path.join(self._binman_dir, 'test', fname)
  241. def AssertInList(self, grep_list, target):
  242. """Assert that at least one of a list of things is in a target
  243. Args:
  244. grep_list: List of strings to check
  245. target: Target string
  246. """
  247. for grep in grep_list:
  248. if grep in target:
  249. return
  250. self.fail("Error: '%' not found in '%s'" % (grep_list, target))
  251. def CheckNoGaps(self, entries):
  252. """Check that all entries fit together without gaps
  253. Args:
  254. entries: List of entries to check
  255. """
  256. offset = 0
  257. for entry in entries.values():
  258. self.assertEqual(offset, entry.offset)
  259. offset += entry.size
  260. def GetFdtLen(self, dtb):
  261. """Get the totalsize field from a device-tree binary
  262. Args:
  263. dtb: Device-tree binary contents
  264. Returns:
  265. Total size of device-tree binary, from the header
  266. """
  267. return struct.unpack('>L', dtb[4:8])[0]
  268. def _GetPropTree(self, dtb_data, node_names):
  269. def AddNode(node, path):
  270. if node.name != '/':
  271. path += '/' + node.name
  272. for subnode in node.subnodes:
  273. for prop in subnode.props.values():
  274. if prop.name in node_names:
  275. prop_path = path + '/' + subnode.name + ':' + prop.name
  276. tree[prop_path[len('/binman/'):]] = fdt_util.fdt32_to_cpu(
  277. prop.value)
  278. AddNode(subnode, path)
  279. tree = {}
  280. dtb = fdt.Fdt(dtb_data)
  281. dtb.Scan()
  282. AddNode(dtb.GetRoot(), '')
  283. return tree
  284. def testRun(self):
  285. """Test a basic run with valid args"""
  286. result = self._RunBinman('-h')
  287. def testFullHelp(self):
  288. """Test that the full help is displayed with -H"""
  289. result = self._RunBinman('-H')
  290. help_file = os.path.join(self._binman_dir, 'README')
  291. # Remove possible extraneous strings
  292. extra = '::::::::::::::\n' + help_file + '\n::::::::::::::\n'
  293. gothelp = result.stdout.replace(extra, '')
  294. self.assertEqual(len(gothelp), os.path.getsize(help_file))
  295. self.assertEqual(0, len(result.stderr))
  296. self.assertEqual(0, result.return_code)
  297. def testFullHelpInternal(self):
  298. """Test that the full help is displayed with -H"""
  299. try:
  300. command.test_result = command.CommandResult()
  301. result = self._DoBinman('-H')
  302. help_file = os.path.join(self._binman_dir, 'README')
  303. finally:
  304. command.test_result = None
  305. def testHelp(self):
  306. """Test that the basic help is displayed with -h"""
  307. result = self._RunBinman('-h')
  308. self.assertTrue(len(result.stdout) > 200)
  309. self.assertEqual(0, len(result.stderr))
  310. self.assertEqual(0, result.return_code)
  311. def testBoard(self):
  312. """Test that we can run it with a specific board"""
  313. self._SetupDtb('05_simple.dts', 'sandbox/u-boot.dtb')
  314. TestFunctional._MakeInputFile('sandbox/u-boot.bin', U_BOOT_DATA)
  315. result = self._DoBinman('-b', 'sandbox')
  316. self.assertEqual(0, result)
  317. def testNeedBoard(self):
  318. """Test that we get an error when no board ius supplied"""
  319. with self.assertRaises(ValueError) as e:
  320. result = self._DoBinman()
  321. self.assertIn("Must provide a board to process (use -b <board>)",
  322. str(e.exception))
  323. def testMissingDt(self):
  324. """Test that an invalid device-tree file generates an error"""
  325. with self.assertRaises(Exception) as e:
  326. self._RunBinman('-d', 'missing_file')
  327. # We get one error from libfdt, and a different one from fdtget.
  328. self.AssertInList(["Couldn't open blob from 'missing_file'",
  329. 'No such file or directory'], str(e.exception))
  330. def testBrokenDt(self):
  331. """Test that an invalid device-tree source file generates an error
  332. Since this is a source file it should be compiled and the error
  333. will come from the device-tree compiler (dtc).
  334. """
  335. with self.assertRaises(Exception) as e:
  336. self._RunBinman('-d', self.TestFile('01_invalid.dts'))
  337. self.assertIn("FATAL ERROR: Unable to parse input tree",
  338. str(e.exception))
  339. def testMissingNode(self):
  340. """Test that a device tree without a 'binman' node generates an error"""
  341. with self.assertRaises(Exception) as e:
  342. self._DoBinman('-d', self.TestFile('02_missing_node.dts'))
  343. self.assertIn("does not have a 'binman' node", str(e.exception))
  344. def testEmpty(self):
  345. """Test that an empty binman node works OK (i.e. does nothing)"""
  346. result = self._RunBinman('-d', self.TestFile('03_empty.dts'))
  347. self.assertEqual(0, len(result.stderr))
  348. self.assertEqual(0, result.return_code)
  349. def testInvalidEntry(self):
  350. """Test that an invalid entry is flagged"""
  351. with self.assertRaises(Exception) as e:
  352. result = self._RunBinman('-d',
  353. self.TestFile('04_invalid_entry.dts'))
  354. self.assertIn("Unknown entry type 'not-a-valid-type' in node "
  355. "'/binman/not-a-valid-type'", str(e.exception))
  356. def testSimple(self):
  357. """Test a simple binman with a single file"""
  358. data = self._DoReadFile('05_simple.dts')
  359. self.assertEqual(U_BOOT_DATA, data)
  360. def testSimpleDebug(self):
  361. """Test a simple binman run with debugging enabled"""
  362. data = self._DoTestFile('05_simple.dts', debug=True)
  363. def testDual(self):
  364. """Test that we can handle creating two images
  365. This also tests image padding.
  366. """
  367. retcode = self._DoTestFile('06_dual_image.dts')
  368. self.assertEqual(0, retcode)
  369. image = control.images['image1']
  370. self.assertEqual(len(U_BOOT_DATA), image._size)
  371. fname = tools.GetOutputFilename('image1.bin')
  372. self.assertTrue(os.path.exists(fname))
  373. with open(fname) as fd:
  374. data = fd.read()
  375. self.assertEqual(U_BOOT_DATA, data)
  376. image = control.images['image2']
  377. self.assertEqual(3 + len(U_BOOT_DATA) + 5, image._size)
  378. fname = tools.GetOutputFilename('image2.bin')
  379. self.assertTrue(os.path.exists(fname))
  380. with open(fname) as fd:
  381. data = fd.read()
  382. self.assertEqual(U_BOOT_DATA, data[3:7])
  383. self.assertEqual(chr(0) * 3, data[:3])
  384. self.assertEqual(chr(0) * 5, data[7:])
  385. def testBadAlign(self):
  386. """Test that an invalid alignment value is detected"""
  387. with self.assertRaises(ValueError) as e:
  388. self._DoTestFile('07_bad_align.dts')
  389. self.assertIn("Node '/binman/u-boot': Alignment 23 must be a power "
  390. "of two", str(e.exception))
  391. def testPackSimple(self):
  392. """Test that packing works as expected"""
  393. retcode = self._DoTestFile('08_pack.dts')
  394. self.assertEqual(0, retcode)
  395. self.assertIn('image', control.images)
  396. image = control.images['image']
  397. entries = image.GetEntries()
  398. self.assertEqual(5, len(entries))
  399. # First u-boot
  400. self.assertIn('u-boot', entries)
  401. entry = entries['u-boot']
  402. self.assertEqual(0, entry.offset)
  403. self.assertEqual(len(U_BOOT_DATA), entry.size)
  404. # Second u-boot, aligned to 16-byte boundary
  405. self.assertIn('u-boot-align', entries)
  406. entry = entries['u-boot-align']
  407. self.assertEqual(16, entry.offset)
  408. self.assertEqual(len(U_BOOT_DATA), entry.size)
  409. # Third u-boot, size 23 bytes
  410. self.assertIn('u-boot-size', entries)
  411. entry = entries['u-boot-size']
  412. self.assertEqual(20, entry.offset)
  413. self.assertEqual(len(U_BOOT_DATA), entry.contents_size)
  414. self.assertEqual(23, entry.size)
  415. # Fourth u-boot, placed immediate after the above
  416. self.assertIn('u-boot-next', entries)
  417. entry = entries['u-boot-next']
  418. self.assertEqual(43, entry.offset)
  419. self.assertEqual(len(U_BOOT_DATA), entry.size)
  420. # Fifth u-boot, placed at a fixed offset
  421. self.assertIn('u-boot-fixed', entries)
  422. entry = entries['u-boot-fixed']
  423. self.assertEqual(61, entry.offset)
  424. self.assertEqual(len(U_BOOT_DATA), entry.size)
  425. self.assertEqual(65, image._size)
  426. def testPackExtra(self):
  427. """Test that extra packing feature works as expected"""
  428. retcode = self._DoTestFile('09_pack_extra.dts')
  429. self.assertEqual(0, retcode)
  430. self.assertIn('image', control.images)
  431. image = control.images['image']
  432. entries = image.GetEntries()
  433. self.assertEqual(5, len(entries))
  434. # First u-boot with padding before and after
  435. self.assertIn('u-boot', entries)
  436. entry = entries['u-boot']
  437. self.assertEqual(0, entry.offset)
  438. self.assertEqual(3, entry.pad_before)
  439. self.assertEqual(3 + 5 + len(U_BOOT_DATA), entry.size)
  440. # Second u-boot has an aligned size, but it has no effect
  441. self.assertIn('u-boot-align-size-nop', entries)
  442. entry = entries['u-boot-align-size-nop']
  443. self.assertEqual(12, entry.offset)
  444. self.assertEqual(4, entry.size)
  445. # Third u-boot has an aligned size too
  446. self.assertIn('u-boot-align-size', entries)
  447. entry = entries['u-boot-align-size']
  448. self.assertEqual(16, entry.offset)
  449. self.assertEqual(32, entry.size)
  450. # Fourth u-boot has an aligned end
  451. self.assertIn('u-boot-align-end', entries)
  452. entry = entries['u-boot-align-end']
  453. self.assertEqual(48, entry.offset)
  454. self.assertEqual(16, entry.size)
  455. # Fifth u-boot immediately afterwards
  456. self.assertIn('u-boot-align-both', entries)
  457. entry = entries['u-boot-align-both']
  458. self.assertEqual(64, entry.offset)
  459. self.assertEqual(64, entry.size)
  460. self.CheckNoGaps(entries)
  461. self.assertEqual(128, image._size)
  462. def testPackAlignPowerOf2(self):
  463. """Test that invalid entry alignment is detected"""
  464. with self.assertRaises(ValueError) as e:
  465. self._DoTestFile('10_pack_align_power2.dts')
  466. self.assertIn("Node '/binman/u-boot': Alignment 5 must be a power "
  467. "of two", str(e.exception))
  468. def testPackAlignSizePowerOf2(self):
  469. """Test that invalid entry size alignment is detected"""
  470. with self.assertRaises(ValueError) as e:
  471. self._DoTestFile('11_pack_align_size_power2.dts')
  472. self.assertIn("Node '/binman/u-boot': Alignment size 55 must be a "
  473. "power of two", str(e.exception))
  474. def testPackInvalidAlign(self):
  475. """Test detection of an offset that does not match its alignment"""
  476. with self.assertRaises(ValueError) as e:
  477. self._DoTestFile('12_pack_inv_align.dts')
  478. self.assertIn("Node '/binman/u-boot': Offset 0x5 (5) does not match "
  479. "align 0x4 (4)", str(e.exception))
  480. def testPackInvalidSizeAlign(self):
  481. """Test that invalid entry size alignment is detected"""
  482. with self.assertRaises(ValueError) as e:
  483. self._DoTestFile('13_pack_inv_size_align.dts')
  484. self.assertIn("Node '/binman/u-boot': Size 0x5 (5) does not match "
  485. "align-size 0x4 (4)", str(e.exception))
  486. def testPackOverlap(self):
  487. """Test that overlapping regions are detected"""
  488. with self.assertRaises(ValueError) as e:
  489. self._DoTestFile('14_pack_overlap.dts')
  490. self.assertIn("Node '/binman/u-boot-align': Offset 0x3 (3) overlaps "
  491. "with previous entry '/binman/u-boot' ending at 0x4 (4)",
  492. str(e.exception))
  493. def testPackEntryOverflow(self):
  494. """Test that entries that overflow their size are detected"""
  495. with self.assertRaises(ValueError) as e:
  496. self._DoTestFile('15_pack_overflow.dts')
  497. self.assertIn("Node '/binman/u-boot': Entry contents size is 0x4 (4) "
  498. "but entry size is 0x3 (3)", str(e.exception))
  499. def testPackImageOverflow(self):
  500. """Test that entries which overflow the image size are detected"""
  501. with self.assertRaises(ValueError) as e:
  502. self._DoTestFile('16_pack_image_overflow.dts')
  503. self.assertIn("Section '/binman': contents size 0x4 (4) exceeds section "
  504. "size 0x3 (3)", str(e.exception))
  505. def testPackImageSize(self):
  506. """Test that the image size can be set"""
  507. retcode = self._DoTestFile('17_pack_image_size.dts')
  508. self.assertEqual(0, retcode)
  509. self.assertIn('image', control.images)
  510. image = control.images['image']
  511. self.assertEqual(7, image._size)
  512. def testPackImageSizeAlign(self):
  513. """Test that image size alignemnt works as expected"""
  514. retcode = self._DoTestFile('18_pack_image_align.dts')
  515. self.assertEqual(0, retcode)
  516. self.assertIn('image', control.images)
  517. image = control.images['image']
  518. self.assertEqual(16, image._size)
  519. def testPackInvalidImageAlign(self):
  520. """Test that invalid image alignment is detected"""
  521. with self.assertRaises(ValueError) as e:
  522. self._DoTestFile('19_pack_inv_image_align.dts')
  523. self.assertIn("Section '/binman': Size 0x7 (7) does not match "
  524. "align-size 0x8 (8)", str(e.exception))
  525. def testPackAlignPowerOf2(self):
  526. """Test that invalid image alignment is detected"""
  527. with self.assertRaises(ValueError) as e:
  528. self._DoTestFile('20_pack_inv_image_align_power2.dts')
  529. self.assertIn("Section '/binman': Alignment size 131 must be a power of "
  530. "two", str(e.exception))
  531. def testImagePadByte(self):
  532. """Test that the image pad byte can be specified"""
  533. with open(self.TestFile('bss_data')) as fd:
  534. TestFunctional._MakeInputFile('spl/u-boot-spl', fd.read())
  535. data = self._DoReadFile('21_image_pad.dts')
  536. self.assertEqual(U_BOOT_SPL_DATA + (chr(0xff) * 1) + U_BOOT_DATA, data)
  537. def testImageName(self):
  538. """Test that image files can be named"""
  539. retcode = self._DoTestFile('22_image_name.dts')
  540. self.assertEqual(0, retcode)
  541. image = control.images['image1']
  542. fname = tools.GetOutputFilename('test-name')
  543. self.assertTrue(os.path.exists(fname))
  544. image = control.images['image2']
  545. fname = tools.GetOutputFilename('test-name.xx')
  546. self.assertTrue(os.path.exists(fname))
  547. def testBlobFilename(self):
  548. """Test that generic blobs can be provided by filename"""
  549. data = self._DoReadFile('23_blob.dts')
  550. self.assertEqual(BLOB_DATA, data)
  551. def testPackSorted(self):
  552. """Test that entries can be sorted"""
  553. data = self._DoReadFile('24_sorted.dts')
  554. self.assertEqual(chr(0) * 1 + U_BOOT_SPL_DATA + chr(0) * 2 +
  555. U_BOOT_DATA, data)
  556. def testPackZeroOffset(self):
  557. """Test that an entry at offset 0 is not given a new offset"""
  558. with self.assertRaises(ValueError) as e:
  559. self._DoTestFile('25_pack_zero_size.dts')
  560. self.assertIn("Node '/binman/u-boot-spl': Offset 0x0 (0) overlaps "
  561. "with previous entry '/binman/u-boot' ending at 0x4 (4)",
  562. str(e.exception))
  563. def testPackUbootDtb(self):
  564. """Test that a device tree can be added to U-Boot"""
  565. data = self._DoReadFile('26_pack_u_boot_dtb.dts')
  566. self.assertEqual(U_BOOT_NODTB_DATA + U_BOOT_DTB_DATA, data)
  567. def testPackX86RomNoSize(self):
  568. """Test that the end-at-4gb property requires a size property"""
  569. with self.assertRaises(ValueError) as e:
  570. self._DoTestFile('27_pack_4gb_no_size.dts')
  571. self.assertIn("Section '/binman': Section size must be provided when "
  572. "using end-at-4gb", str(e.exception))
  573. def testPackX86RomOutside(self):
  574. """Test that the end-at-4gb property checks for offset boundaries"""
  575. with self.assertRaises(ValueError) as e:
  576. self._DoTestFile('28_pack_4gb_outside.dts')
  577. self.assertIn("Node '/binman/u-boot': Offset 0x0 (0) is outside "
  578. "the section starting at 0xffffffe0 (4294967264)",
  579. str(e.exception))
  580. def testPackX86Rom(self):
  581. """Test that a basic x86 ROM can be created"""
  582. data = self._DoReadFile('29_x86-rom.dts')
  583. self.assertEqual(U_BOOT_DATA + chr(0) * 7 + U_BOOT_SPL_DATA +
  584. chr(0) * 2, data)
  585. def testPackX86RomMeNoDesc(self):
  586. """Test that an invalid Intel descriptor entry is detected"""
  587. TestFunctional._MakeInputFile('descriptor.bin', '')
  588. with self.assertRaises(ValueError) as e:
  589. self._DoTestFile('31_x86-rom-me.dts')
  590. self.assertIn("Node '/binman/intel-descriptor': Cannot find FD "
  591. "signature", str(e.exception))
  592. def testPackX86RomBadDesc(self):
  593. """Test that the Intel requires a descriptor entry"""
  594. with self.assertRaises(ValueError) as e:
  595. self._DoTestFile('30_x86-rom-me-no-desc.dts')
  596. self.assertIn("Node '/binman/intel-me': No offset set with "
  597. "offset-unset: should another entry provide this correct "
  598. "offset?", str(e.exception))
  599. def testPackX86RomMe(self):
  600. """Test that an x86 ROM with an ME region can be created"""
  601. data = self._DoReadFile('31_x86-rom-me.dts')
  602. self.assertEqual(ME_DATA, data[0x1000:0x1000 + len(ME_DATA)])
  603. def testPackVga(self):
  604. """Test that an image with a VGA binary can be created"""
  605. data = self._DoReadFile('32_intel-vga.dts')
  606. self.assertEqual(VGA_DATA, data[:len(VGA_DATA)])
  607. def testPackStart16(self):
  608. """Test that an image with an x86 start16 region can be created"""
  609. data = self._DoReadFile('33_x86-start16.dts')
  610. self.assertEqual(X86_START16_DATA, data[:len(X86_START16_DATA)])
  611. def _RunMicrocodeTest(self, dts_fname, nodtb_data, ucode_second=False):
  612. """Handle running a test for insertion of microcode
  613. Args:
  614. dts_fname: Name of test .dts file
  615. nodtb_data: Data that we expect in the first section
  616. ucode_second: True if the microsecond entry is second instead of
  617. third
  618. Returns:
  619. Tuple:
  620. Contents of first region (U-Boot or SPL)
  621. Offset and size components of microcode pointer, as inserted
  622. in the above (two 4-byte words)
  623. """
  624. data = self._DoReadFile(dts_fname, True)
  625. # Now check the device tree has no microcode
  626. if ucode_second:
  627. ucode_content = data[len(nodtb_data):]
  628. ucode_pos = len(nodtb_data)
  629. dtb_with_ucode = ucode_content[16:]
  630. fdt_len = self.GetFdtLen(dtb_with_ucode)
  631. else:
  632. dtb_with_ucode = data[len(nodtb_data):]
  633. fdt_len = self.GetFdtLen(dtb_with_ucode)
  634. ucode_content = dtb_with_ucode[fdt_len:]
  635. ucode_pos = len(nodtb_data) + fdt_len
  636. fname = tools.GetOutputFilename('test.dtb')
  637. with open(fname, 'wb') as fd:
  638. fd.write(dtb_with_ucode)
  639. dtb = fdt.FdtScan(fname)
  640. ucode = dtb.GetNode('/microcode')
  641. self.assertTrue(ucode)
  642. for node in ucode.subnodes:
  643. self.assertFalse(node.props.get('data'))
  644. # Check that the microcode appears immediately after the Fdt
  645. # This matches the concatenation of the data properties in
  646. # the /microcode/update@xxx nodes in 34_x86_ucode.dts.
  647. ucode_data = struct.pack('>4L', 0x12345678, 0x12345679, 0xabcd0000,
  648. 0x78235609)
  649. self.assertEqual(ucode_data, ucode_content[:len(ucode_data)])
  650. # Check that the microcode pointer was inserted. It should match the
  651. # expected offset and size
  652. pos_and_size = struct.pack('<2L', 0xfffffe00 + ucode_pos,
  653. len(ucode_data))
  654. u_boot = data[:len(nodtb_data)]
  655. return u_boot, pos_and_size
  656. def testPackUbootMicrocode(self):
  657. """Test that x86 microcode can be handled correctly
  658. We expect to see the following in the image, in order:
  659. u-boot-nodtb.bin with a microcode pointer inserted at the correct
  660. place
  661. u-boot.dtb with the microcode removed
  662. the microcode
  663. """
  664. first, pos_and_size = self._RunMicrocodeTest('34_x86_ucode.dts',
  665. U_BOOT_NODTB_DATA)
  666. self.assertEqual('nodtb with microcode' + pos_and_size +
  667. ' somewhere in here', first)
  668. def _RunPackUbootSingleMicrocode(self):
  669. """Test that x86 microcode can be handled correctly
  670. We expect to see the following in the image, in order:
  671. u-boot-nodtb.bin with a microcode pointer inserted at the correct
  672. place
  673. u-boot.dtb with the microcode
  674. an empty microcode region
  675. """
  676. # We need the libfdt library to run this test since only that allows
  677. # finding the offset of a property. This is required by
  678. # Entry_u_boot_dtb_with_ucode.ObtainContents().
  679. data = self._DoReadFile('35_x86_single_ucode.dts', True)
  680. second = data[len(U_BOOT_NODTB_DATA):]
  681. fdt_len = self.GetFdtLen(second)
  682. third = second[fdt_len:]
  683. second = second[:fdt_len]
  684. ucode_data = struct.pack('>2L', 0x12345678, 0x12345679)
  685. self.assertIn(ucode_data, second)
  686. ucode_pos = second.find(ucode_data) + len(U_BOOT_NODTB_DATA)
  687. # Check that the microcode pointer was inserted. It should match the
  688. # expected offset and size
  689. pos_and_size = struct.pack('<2L', 0xfffffe00 + ucode_pos,
  690. len(ucode_data))
  691. first = data[:len(U_BOOT_NODTB_DATA)]
  692. self.assertEqual('nodtb with microcode' + pos_and_size +
  693. ' somewhere in here', first)
  694. def testPackUbootSingleMicrocode(self):
  695. """Test that x86 microcode can be handled correctly with fdt_normal.
  696. """
  697. self._RunPackUbootSingleMicrocode()
  698. def testUBootImg(self):
  699. """Test that u-boot.img can be put in a file"""
  700. data = self._DoReadFile('36_u_boot_img.dts')
  701. self.assertEqual(U_BOOT_IMG_DATA, data)
  702. def testNoMicrocode(self):
  703. """Test that a missing microcode region is detected"""
  704. with self.assertRaises(ValueError) as e:
  705. self._DoReadFile('37_x86_no_ucode.dts', True)
  706. self.assertIn("Node '/binman/u-boot-dtb-with-ucode': No /microcode "
  707. "node found in ", str(e.exception))
  708. def testMicrocodeWithoutNode(self):
  709. """Test that a missing u-boot-dtb-with-ucode node is detected"""
  710. with self.assertRaises(ValueError) as e:
  711. self._DoReadFile('38_x86_ucode_missing_node.dts', True)
  712. self.assertIn("Node '/binman/u-boot-with-ucode-ptr': Cannot find "
  713. "microcode region u-boot-dtb-with-ucode", str(e.exception))
  714. def testMicrocodeWithoutNode2(self):
  715. """Test that a missing u-boot-ucode node is detected"""
  716. with self.assertRaises(ValueError) as e:
  717. self._DoReadFile('39_x86_ucode_missing_node2.dts', True)
  718. self.assertIn("Node '/binman/u-boot-with-ucode-ptr': Cannot find "
  719. "microcode region u-boot-ucode", str(e.exception))
  720. def testMicrocodeWithoutPtrInElf(self):
  721. """Test that a U-Boot binary without the microcode symbol is detected"""
  722. # ELF file without a '_dt_ucode_base_size' symbol
  723. try:
  724. with open(self.TestFile('u_boot_no_ucode_ptr')) as fd:
  725. TestFunctional._MakeInputFile('u-boot', fd.read())
  726. with self.assertRaises(ValueError) as e:
  727. self._RunPackUbootSingleMicrocode()
  728. self.assertIn("Node '/binman/u-boot-with-ucode-ptr': Cannot locate "
  729. "_dt_ucode_base_size symbol in u-boot", str(e.exception))
  730. finally:
  731. # Put the original file back
  732. with open(self.TestFile('u_boot_ucode_ptr')) as fd:
  733. TestFunctional._MakeInputFile('u-boot', fd.read())
  734. def testMicrocodeNotInImage(self):
  735. """Test that microcode must be placed within the image"""
  736. with self.assertRaises(ValueError) as e:
  737. self._DoReadFile('40_x86_ucode_not_in_image.dts', True)
  738. self.assertIn("Node '/binman/u-boot-with-ucode-ptr': Microcode "
  739. "pointer _dt_ucode_base_size at fffffe14 is outside the "
  740. "section ranging from 00000000 to 0000002e", str(e.exception))
  741. def testWithoutMicrocode(self):
  742. """Test that we can cope with an image without microcode (e.g. qemu)"""
  743. with open(self.TestFile('u_boot_no_ucode_ptr')) as fd:
  744. TestFunctional._MakeInputFile('u-boot', fd.read())
  745. data, dtb, _, _ = self._DoReadFileDtb('44_x86_optional_ucode.dts', True)
  746. # Now check the device tree has no microcode
  747. self.assertEqual(U_BOOT_NODTB_DATA, data[:len(U_BOOT_NODTB_DATA)])
  748. second = data[len(U_BOOT_NODTB_DATA):]
  749. fdt_len = self.GetFdtLen(second)
  750. self.assertEqual(dtb, second[:fdt_len])
  751. used_len = len(U_BOOT_NODTB_DATA) + fdt_len
  752. third = data[used_len:]
  753. self.assertEqual(chr(0) * (0x200 - used_len), third)
  754. def testUnknownPosSize(self):
  755. """Test that microcode must be placed within the image"""
  756. with self.assertRaises(ValueError) as e:
  757. self._DoReadFile('41_unknown_pos_size.dts', True)
  758. self.assertIn("Section '/binman': Unable to set offset/size for unknown "
  759. "entry 'invalid-entry'", str(e.exception))
  760. def testPackFsp(self):
  761. """Test that an image with a FSP binary can be created"""
  762. data = self._DoReadFile('42_intel-fsp.dts')
  763. self.assertEqual(FSP_DATA, data[:len(FSP_DATA)])
  764. def testPackCmc(self):
  765. """Test that an image with a CMC binary can be created"""
  766. data = self._DoReadFile('43_intel-cmc.dts')
  767. self.assertEqual(CMC_DATA, data[:len(CMC_DATA)])
  768. def testPackVbt(self):
  769. """Test that an image with a VBT binary can be created"""
  770. data = self._DoReadFile('46_intel-vbt.dts')
  771. self.assertEqual(VBT_DATA, data[:len(VBT_DATA)])
  772. def testSplBssPad(self):
  773. """Test that we can pad SPL's BSS with zeros"""
  774. # ELF file with a '__bss_size' symbol
  775. with open(self.TestFile('bss_data')) as fd:
  776. TestFunctional._MakeInputFile('spl/u-boot-spl', fd.read())
  777. data = self._DoReadFile('47_spl_bss_pad.dts')
  778. self.assertEqual(U_BOOT_SPL_DATA + (chr(0) * 10) + U_BOOT_DATA, data)
  779. with open(self.TestFile('u_boot_ucode_ptr')) as fd:
  780. TestFunctional._MakeInputFile('spl/u-boot-spl', fd.read())
  781. with self.assertRaises(ValueError) as e:
  782. data = self._DoReadFile('47_spl_bss_pad.dts')
  783. self.assertIn('Expected __bss_size symbol in spl/u-boot-spl',
  784. str(e.exception))
  785. def testPackStart16Spl(self):
  786. """Test that an image with an x86 start16 region can be created"""
  787. data = self._DoReadFile('48_x86-start16-spl.dts')
  788. self.assertEqual(X86_START16_SPL_DATA, data[:len(X86_START16_SPL_DATA)])
  789. def _PackUbootSplMicrocode(self, dts, ucode_second=False):
  790. """Helper function for microcode tests
  791. We expect to see the following in the image, in order:
  792. u-boot-spl-nodtb.bin with a microcode pointer inserted at the
  793. correct place
  794. u-boot.dtb with the microcode removed
  795. the microcode
  796. Args:
  797. dts: Device tree file to use for test
  798. ucode_second: True if the microsecond entry is second instead of
  799. third
  800. """
  801. # ELF file with a '_dt_ucode_base_size' symbol
  802. with open(self.TestFile('u_boot_ucode_ptr')) as fd:
  803. TestFunctional._MakeInputFile('spl/u-boot-spl', fd.read())
  804. first, pos_and_size = self._RunMicrocodeTest(dts, U_BOOT_SPL_NODTB_DATA,
  805. ucode_second=ucode_second)
  806. self.assertEqual('splnodtb with microc' + pos_and_size +
  807. 'ter somewhere in here', first)
  808. def testPackUbootSplMicrocode(self):
  809. """Test that x86 microcode can be handled correctly in SPL"""
  810. self._PackUbootSplMicrocode('49_x86_ucode_spl.dts')
  811. def testPackUbootSplMicrocodeReorder(self):
  812. """Test that order doesn't matter for microcode entries
  813. This is the same as testPackUbootSplMicrocode but when we process the
  814. u-boot-ucode entry we have not yet seen the u-boot-dtb-with-ucode
  815. entry, so we reply on binman to try later.
  816. """
  817. self._PackUbootSplMicrocode('58_x86_ucode_spl_needs_retry.dts',
  818. ucode_second=True)
  819. def testPackMrc(self):
  820. """Test that an image with an MRC binary can be created"""
  821. data = self._DoReadFile('50_intel_mrc.dts')
  822. self.assertEqual(MRC_DATA, data[:len(MRC_DATA)])
  823. def testSplDtb(self):
  824. """Test that an image with spl/u-boot-spl.dtb can be created"""
  825. data = self._DoReadFile('51_u_boot_spl_dtb.dts')
  826. self.assertEqual(U_BOOT_SPL_DTB_DATA, data[:len(U_BOOT_SPL_DTB_DATA)])
  827. def testSplNoDtb(self):
  828. """Test that an image with spl/u-boot-spl-nodtb.bin can be created"""
  829. data = self._DoReadFile('52_u_boot_spl_nodtb.dts')
  830. self.assertEqual(U_BOOT_SPL_NODTB_DATA, data[:len(U_BOOT_SPL_NODTB_DATA)])
  831. def testSymbols(self):
  832. """Test binman can assign symbols embedded in U-Boot"""
  833. elf_fname = self.TestFile('u_boot_binman_syms')
  834. syms = elf.GetSymbols(elf_fname, ['binman', 'image'])
  835. addr = elf.GetSymbolAddress(elf_fname, '__image_copy_start')
  836. self.assertEqual(syms['_binman_u_boot_spl_prop_offset'].address, addr)
  837. with open(self.TestFile('u_boot_binman_syms')) as fd:
  838. TestFunctional._MakeInputFile('spl/u-boot-spl', fd.read())
  839. data = self._DoReadFile('53_symbols.dts')
  840. sym_values = struct.pack('<LQL', 0x24 + 0, 0x24 + 24, 0x24 + 20)
  841. expected = (sym_values + U_BOOT_SPL_DATA[16:] + chr(0xff) +
  842. U_BOOT_DATA +
  843. sym_values + U_BOOT_SPL_DATA[16:])
  844. self.assertEqual(expected, data)
  845. def testPackUnitAddress(self):
  846. """Test that we support multiple binaries with the same name"""
  847. data = self._DoReadFile('54_unit_address.dts')
  848. self.assertEqual(U_BOOT_DATA + U_BOOT_DATA, data)
  849. def testSections(self):
  850. """Basic test of sections"""
  851. data = self._DoReadFile('55_sections.dts')
  852. expected = (U_BOOT_DATA + '!' * 12 + U_BOOT_DATA + 'a' * 12 +
  853. U_BOOT_DATA + '&' * 4)
  854. self.assertEqual(expected, data)
  855. def testMap(self):
  856. """Tests outputting a map of the images"""
  857. _, _, map_data, _ = self._DoReadFileDtb('55_sections.dts', map=True)
  858. self.assertEqual(''' Offset Size Name
  859. 00000000 00000028 main-section
  860. 00000000 00000010 section@0
  861. 00000000 00000004 u-boot
  862. 00000010 00000010 section@1
  863. 00000000 00000004 u-boot
  864. 00000020 00000004 section@2
  865. 00000000 00000004 u-boot
  866. ''', map_data)
  867. def testNamePrefix(self):
  868. """Tests that name prefixes are used"""
  869. _, _, map_data, _ = self._DoReadFileDtb('56_name_prefix.dts', map=True)
  870. self.assertEqual(''' Offset Size Name
  871. 00000000 00000028 main-section
  872. 00000000 00000010 section@0
  873. 00000000 00000004 ro-u-boot
  874. 00000010 00000010 section@1
  875. 00000000 00000004 rw-u-boot
  876. ''', map_data)
  877. def testUnknownContents(self):
  878. """Test that obtaining the contents works as expected"""
  879. with self.assertRaises(ValueError) as e:
  880. self._DoReadFile('57_unknown_contents.dts', True)
  881. self.assertIn("Section '/binman': Internal error: Could not complete "
  882. "processing of contents: remaining [<_testing.Entry__testing ",
  883. str(e.exception))
  884. def testBadChangeSize(self):
  885. """Test that trying to change the size of an entry fails"""
  886. with self.assertRaises(ValueError) as e:
  887. self._DoReadFile('59_change_size.dts', True)
  888. self.assertIn("Node '/binman/_testing': Cannot update entry size from "
  889. '2 to 1', str(e.exception))
  890. def testUpdateFdt(self):
  891. """Test that we can update the device tree with offset/size info"""
  892. _, _, _, out_dtb_fname = self._DoReadFileDtb('60_fdt_update.dts',
  893. update_dtb=True)
  894. props = self._GetPropTree(out_dtb_fname, ['offset', 'size',
  895. 'image-pos'])
  896. with open('/tmp/x.dtb', 'wb') as outf:
  897. with open(out_dtb_fname) as inf:
  898. outf.write(inf.read())
  899. self.assertEqual({
  900. 'image-pos': 0,
  901. 'offset': 0,
  902. '_testing:offset': 32,
  903. '_testing:size': 1,
  904. '_testing:image-pos': 32,
  905. 'section@0/u-boot:offset': 0,
  906. 'section@0/u-boot:size': len(U_BOOT_DATA),
  907. 'section@0/u-boot:image-pos': 0,
  908. 'section@0:offset': 0,
  909. 'section@0:size': 16,
  910. 'section@0:image-pos': 0,
  911. 'section@1/u-boot:offset': 0,
  912. 'section@1/u-boot:size': len(U_BOOT_DATA),
  913. 'section@1/u-boot:image-pos': 16,
  914. 'section@1:offset': 16,
  915. 'section@1:size': 16,
  916. 'section@1:image-pos': 16,
  917. 'size': 40
  918. }, props)
  919. def testUpdateFdtBad(self):
  920. """Test that we detect when ProcessFdt never completes"""
  921. with self.assertRaises(ValueError) as e:
  922. self._DoReadFileDtb('61_fdt_update_bad.dts', update_dtb=True)
  923. self.assertIn('Could not complete processing of Fdt: remaining '
  924. '[<_testing.Entry__testing', str(e.exception))
  925. if __name__ == "__main__":
  926. unittest.main()