blob: 61bbb53f8c3ca2b591d96d28368c15f8ef2c0b89 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001# SPDX-License-Identifier: GPL-2.0+
Simon Glass4f443042016-11-25 20:15:52 -07002# Copyright (c) 2016 Google, Inc
3# Written by Simon Glass <sjg@chromium.org>
4#
Simon Glass4f443042016-11-25 20:15:52 -07005# To run a single test, change to this directory, and:
6#
7# python -m unittest func_test.TestFunctional.testHelp
8
9from optparse import OptionParser
10import os
11import shutil
12import struct
13import sys
14import tempfile
15import unittest
16
17import binman
18import cmdline
19import command
20import control
Simon Glass19790632017-11-13 18:55:01 -070021import elf
Simon Glass99ed4a22017-05-27 07:38:30 -060022import fdt
Simon Glass4f443042016-11-25 20:15:52 -070023import fdt_util
24import tools
25import tout
26
27# Contents of test files, corresponding to different entry types
Simon Glass6b187df2017-11-12 21:52:27 -070028U_BOOT_DATA = '1234'
29U_BOOT_IMG_DATA = 'img'
Simon Glassf6898902017-11-13 18:54:59 -070030U_BOOT_SPL_DATA = '56780123456789abcde'
Simon Glass6b187df2017-11-12 21:52:27 -070031BLOB_DATA = '89'
32ME_DATA = '0abcd'
33VGA_DATA = 'vga'
34U_BOOT_DTB_DATA = 'udtb'
Simon Glass47419ea2017-11-13 18:54:55 -070035U_BOOT_SPL_DTB_DATA = 'spldtb'
Simon Glass6b187df2017-11-12 21:52:27 -070036X86_START16_DATA = 'start16'
37X86_START16_SPL_DATA = 'start16spl'
38U_BOOT_NODTB_DATA = 'nodtb with microcode pointer somewhere in here'
39U_BOOT_SPL_NODTB_DATA = 'splnodtb with microcode pointer somewhere in here'
40FSP_DATA = 'fsp'
41CMC_DATA = 'cmc'
42VBT_DATA = 'vbt'
Simon Glassca4f4ff2017-11-12 21:52:28 -070043MRC_DATA = 'mrc'
Simon Glass4f443042016-11-25 20:15:52 -070044
45class TestFunctional(unittest.TestCase):
46 """Functional tests for binman
47
48 Most of these use a sample .dts file to build an image and then check
49 that it looks correct. The sample files are in the test/ subdirectory
50 and are numbered.
51
52 For each entry type a very small test file is created using fixed
53 string contents. This makes it easy to test that things look right, and
54 debug problems.
55
56 In some cases a 'real' file must be used - these are also supplied in
57 the test/ diurectory.
58 """
59 @classmethod
60 def setUpClass(self):
Simon Glass4d5994f2017-11-12 21:52:20 -070061 global entry
62 import entry
63
Simon Glass4f443042016-11-25 20:15:52 -070064 # Handle the case where argv[0] is 'python'
65 self._binman_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
66 self._binman_pathname = os.path.join(self._binman_dir, 'binman')
67
68 # Create a temporary directory for input files
69 self._indir = tempfile.mkdtemp(prefix='binmant.')
70
71 # Create some test files
72 TestFunctional._MakeInputFile('u-boot.bin', U_BOOT_DATA)
73 TestFunctional._MakeInputFile('u-boot.img', U_BOOT_IMG_DATA)
74 TestFunctional._MakeInputFile('spl/u-boot-spl.bin', U_BOOT_SPL_DATA)
75 TestFunctional._MakeInputFile('blobfile', BLOB_DATA)
Simon Glasse0ff8552016-11-25 20:15:53 -070076 TestFunctional._MakeInputFile('me.bin', ME_DATA)
77 TestFunctional._MakeInputFile('vga.bin', VGA_DATA)
Simon Glass4f443042016-11-25 20:15:52 -070078 TestFunctional._MakeInputFile('u-boot.dtb', U_BOOT_DTB_DATA)
Simon Glass47419ea2017-11-13 18:54:55 -070079 TestFunctional._MakeInputFile('spl/u-boot-spl.dtb', U_BOOT_SPL_DTB_DATA)
Simon Glasse0ff8552016-11-25 20:15:53 -070080 TestFunctional._MakeInputFile('u-boot-x86-16bit.bin', X86_START16_DATA)
Simon Glass87722132017-11-12 21:52:26 -070081 TestFunctional._MakeInputFile('spl/u-boot-x86-16bit-spl.bin',
82 X86_START16_SPL_DATA)
Simon Glass4f443042016-11-25 20:15:52 -070083 TestFunctional._MakeInputFile('u-boot-nodtb.bin', U_BOOT_NODTB_DATA)
Simon Glass6b187df2017-11-12 21:52:27 -070084 TestFunctional._MakeInputFile('spl/u-boot-spl-nodtb.bin',
85 U_BOOT_SPL_NODTB_DATA)
Simon Glassda229092016-11-25 20:15:56 -070086 TestFunctional._MakeInputFile('fsp.bin', FSP_DATA)
87 TestFunctional._MakeInputFile('cmc.bin', CMC_DATA)
Bin Meng59ea8c22017-08-15 22:41:54 -070088 TestFunctional._MakeInputFile('vbt.bin', VBT_DATA)
Simon Glassca4f4ff2017-11-12 21:52:28 -070089 TestFunctional._MakeInputFile('mrc.bin', MRC_DATA)
Simon Glass4f443042016-11-25 20:15:52 -070090 self._output_setup = False
91
Simon Glasse0ff8552016-11-25 20:15:53 -070092 # ELF file with a '_dt_ucode_base_size' symbol
93 with open(self.TestFile('u_boot_ucode_ptr')) as fd:
94 TestFunctional._MakeInputFile('u-boot', fd.read())
95
96 # Intel flash descriptor file
97 with open(self.TestFile('descriptor.bin')) as fd:
98 TestFunctional._MakeInputFile('descriptor.bin', fd.read())
99
Simon Glass4f443042016-11-25 20:15:52 -0700100 @classmethod
101 def tearDownClass(self):
102 """Remove the temporary input directory and its contents"""
103 if self._indir:
104 shutil.rmtree(self._indir)
105 self._indir = None
106
107 def setUp(self):
108 # Enable this to turn on debugging output
109 # tout.Init(tout.DEBUG)
110 command.test_result = None
111
112 def tearDown(self):
113 """Remove the temporary output directory"""
114 tools._FinaliseForTest()
115
116 def _RunBinman(self, *args, **kwargs):
117 """Run binman using the command line
118
119 Args:
120 Arguments to pass, as a list of strings
121 kwargs: Arguments to pass to Command.RunPipe()
122 """
123 result = command.RunPipe([[self._binman_pathname] + list(args)],
124 capture=True, capture_stderr=True, raise_on_error=False)
125 if result.return_code and kwargs.get('raise_on_error', True):
126 raise Exception("Error running '%s': %s" % (' '.join(args),
127 result.stdout + result.stderr))
128 return result
129
130 def _DoBinman(self, *args):
131 """Run binman using directly (in the same process)
132
133 Args:
134 Arguments to pass, as a list of strings
135 Returns:
136 Return value (0 for success)
137 """
Simon Glass7fe91732017-11-13 18:55:00 -0700138 args = list(args)
139 if '-D' in sys.argv:
140 args = args + ['-D']
141 (options, args) = cmdline.ParseArgs(args)
Simon Glass4f443042016-11-25 20:15:52 -0700142 options.pager = 'binman-invalid-pager'
143 options.build_dir = self._indir
144
145 # For testing, you can force an increase in verbosity here
146 # options.verbosity = tout.DEBUG
147 return control.Binman(options, args)
148
Simon Glass3b0c3822018-06-01 09:38:20 -0600149 def _DoTestFile(self, fname, debug=False, map=False):
Simon Glass4f443042016-11-25 20:15:52 -0700150 """Run binman with a given test file
151
152 Args:
Simon Glass7ae5f312018-06-01 09:38:19 -0600153 fname: Device-tree source filename to use (e.g. 05_simple.dts)
154 debug: True to enable debugging output
Simon Glass3b0c3822018-06-01 09:38:20 -0600155 map: True to output map files for the images
Simon Glass4f443042016-11-25 20:15:52 -0700156 """
Simon Glass7fe91732017-11-13 18:55:00 -0700157 args = ['-p', '-I', self._indir, '-d', self.TestFile(fname)]
158 if debug:
159 args.append('-D')
Simon Glass3b0c3822018-06-01 09:38:20 -0600160 if map:
161 args.append('-m')
Simon Glass7fe91732017-11-13 18:55:00 -0700162 return self._DoBinman(*args)
Simon Glass4f443042016-11-25 20:15:52 -0700163
164 def _SetupDtb(self, fname, outfile='u-boot.dtb'):
Simon Glasse0ff8552016-11-25 20:15:53 -0700165 """Set up a new test device-tree file
166
167 The given file is compiled and set up as the device tree to be used
168 for ths test.
169
170 Args:
171 fname: Filename of .dts file to read
Simon Glass7ae5f312018-06-01 09:38:19 -0600172 outfile: Output filename for compiled device-tree binary
Simon Glasse0ff8552016-11-25 20:15:53 -0700173
174 Returns:
Simon Glass7ae5f312018-06-01 09:38:19 -0600175 Contents of device-tree binary
Simon Glasse0ff8552016-11-25 20:15:53 -0700176 """
Simon Glass4f443042016-11-25 20:15:52 -0700177 if not self._output_setup:
178 tools.PrepareOutputDir(self._indir, True)
179 self._output_setup = True
180 dtb = fdt_util.EnsureCompiled(self.TestFile(fname))
181 with open(dtb) as fd:
182 data = fd.read()
183 TestFunctional._MakeInputFile(outfile, data)
Simon Glasse0ff8552016-11-25 20:15:53 -0700184 return data
Simon Glass4f443042016-11-25 20:15:52 -0700185
Simon Glass3b0c3822018-06-01 09:38:20 -0600186 def _DoReadFileDtb(self, fname, use_real_dtb=False, map=False):
Simon Glass4f443042016-11-25 20:15:52 -0700187 """Run binman and return the resulting image
188
189 This runs binman with a given test file and then reads the resulting
190 output file. It is a shortcut function since most tests need to do
191 these steps.
192
193 Raises an assertion failure if binman returns a non-zero exit code.
194
195 Args:
Simon Glass7ae5f312018-06-01 09:38:19 -0600196 fname: Device-tree source filename to use (e.g. 05_simple.dts)
Simon Glass4f443042016-11-25 20:15:52 -0700197 use_real_dtb: True to use the test file as the contents of
198 the u-boot-dtb entry. Normally this is not needed and the
199 test contents (the U_BOOT_DTB_DATA string) can be used.
200 But in some test we need the real contents.
Simon Glass3b0c3822018-06-01 09:38:20 -0600201 map: True to output map files for the images
Simon Glasse0ff8552016-11-25 20:15:53 -0700202
203 Returns:
204 Tuple:
205 Resulting image contents
206 Device tree contents
Simon Glass3b0c3822018-06-01 09:38:20 -0600207 Map data showing contents of image (or None if none)
Simon Glass4f443042016-11-25 20:15:52 -0700208 """
Simon Glasse0ff8552016-11-25 20:15:53 -0700209 dtb_data = None
Simon Glass4f443042016-11-25 20:15:52 -0700210 # Use the compiled test file as the u-boot-dtb input
211 if use_real_dtb:
Simon Glasse0ff8552016-11-25 20:15:53 -0700212 dtb_data = self._SetupDtb(fname)
Simon Glass4f443042016-11-25 20:15:52 -0700213
214 try:
Simon Glass3b0c3822018-06-01 09:38:20 -0600215 retcode = self._DoTestFile(fname, map=map)
Simon Glass4f443042016-11-25 20:15:52 -0700216 self.assertEqual(0, retcode)
217
218 # Find the (only) image, read it and return its contents
219 image = control.images['image']
220 fname = tools.GetOutputFilename('image.bin')
221 self.assertTrue(os.path.exists(fname))
Simon Glass3b0c3822018-06-01 09:38:20 -0600222 if map:
223 map_fname = tools.GetOutputFilename('image.map')
224 with open(map_fname) as fd:
225 map_data = fd.read()
226 else:
227 map_data = None
Simon Glass4f443042016-11-25 20:15:52 -0700228 with open(fname) as fd:
Simon Glass3b0c3822018-06-01 09:38:20 -0600229 return fd.read(), dtb_data, map_data
Simon Glass4f443042016-11-25 20:15:52 -0700230 finally:
231 # Put the test file back
232 if use_real_dtb:
233 TestFunctional._MakeInputFile('u-boot.dtb', U_BOOT_DTB_DATA)
234
Simon Glasse0ff8552016-11-25 20:15:53 -0700235 def _DoReadFile(self, fname, use_real_dtb=False):
Simon Glass7ae5f312018-06-01 09:38:19 -0600236 """Helper function which discards the device-tree binary
237
238 Args:
239 fname: Device-tree source filename to use (e.g. 05_simple.dts)
240 use_real_dtb: True to use the test file as the contents of
241 the u-boot-dtb entry. Normally this is not needed and the
242 test contents (the U_BOOT_DTB_DATA string) can be used.
243 But in some test we need the real contents.
244 """
Simon Glasse0ff8552016-11-25 20:15:53 -0700245 return self._DoReadFileDtb(fname, use_real_dtb)[0]
246
Simon Glass4f443042016-11-25 20:15:52 -0700247 @classmethod
248 def _MakeInputFile(self, fname, contents):
249 """Create a new test input file, creating directories as needed
250
251 Args:
252 fname: Filenaem to create
253 contents: File contents to write in to the file
254 Returns:
255 Full pathname of file created
256 """
257 pathname = os.path.join(self._indir, fname)
258 dirname = os.path.dirname(pathname)
259 if dirname and not os.path.exists(dirname):
260 os.makedirs(dirname)
261 with open(pathname, 'wb') as fd:
262 fd.write(contents)
263 return pathname
264
265 @classmethod
266 def TestFile(self, fname):
267 return os.path.join(self._binman_dir, 'test', fname)
268
269 def AssertInList(self, grep_list, target):
270 """Assert that at least one of a list of things is in a target
271
272 Args:
273 grep_list: List of strings to check
274 target: Target string
275 """
276 for grep in grep_list:
277 if grep in target:
278 return
279 self.fail("Error: '%' not found in '%s'" % (grep_list, target))
280
281 def CheckNoGaps(self, entries):
282 """Check that all entries fit together without gaps
283
284 Args:
285 entries: List of entries to check
286 """
287 pos = 0
288 for entry in entries.values():
289 self.assertEqual(pos, entry.pos)
290 pos += entry.size
291
Simon Glasse0ff8552016-11-25 20:15:53 -0700292 def GetFdtLen(self, dtb):
Simon Glass7ae5f312018-06-01 09:38:19 -0600293 """Get the totalsize field from a device-tree binary
Simon Glasse0ff8552016-11-25 20:15:53 -0700294
295 Args:
Simon Glass7ae5f312018-06-01 09:38:19 -0600296 dtb: Device-tree binary contents
Simon Glasse0ff8552016-11-25 20:15:53 -0700297
298 Returns:
Simon Glass7ae5f312018-06-01 09:38:19 -0600299 Total size of device-tree binary, from the header
Simon Glasse0ff8552016-11-25 20:15:53 -0700300 """
301 return struct.unpack('>L', dtb[4:8])[0]
302
Simon Glass4f443042016-11-25 20:15:52 -0700303 def testRun(self):
304 """Test a basic run with valid args"""
305 result = self._RunBinman('-h')
306
307 def testFullHelp(self):
308 """Test that the full help is displayed with -H"""
309 result = self._RunBinman('-H')
310 help_file = os.path.join(self._binman_dir, 'README')
Tom Rini3759df02018-01-16 15:29:50 -0500311 # Remove possible extraneous strings
312 extra = '::::::::::::::\n' + help_file + '\n::::::::::::::\n'
313 gothelp = result.stdout.replace(extra, '')
314 self.assertEqual(len(gothelp), os.path.getsize(help_file))
Simon Glass4f443042016-11-25 20:15:52 -0700315 self.assertEqual(0, len(result.stderr))
316 self.assertEqual(0, result.return_code)
317
318 def testFullHelpInternal(self):
319 """Test that the full help is displayed with -H"""
320 try:
321 command.test_result = command.CommandResult()
322 result = self._DoBinman('-H')
323 help_file = os.path.join(self._binman_dir, 'README')
324 finally:
325 command.test_result = None
326
327 def testHelp(self):
328 """Test that the basic help is displayed with -h"""
329 result = self._RunBinman('-h')
330 self.assertTrue(len(result.stdout) > 200)
331 self.assertEqual(0, len(result.stderr))
332 self.assertEqual(0, result.return_code)
333
Simon Glass4f443042016-11-25 20:15:52 -0700334 def testBoard(self):
335 """Test that we can run it with a specific board"""
336 self._SetupDtb('05_simple.dts', 'sandbox/u-boot.dtb')
337 TestFunctional._MakeInputFile('sandbox/u-boot.bin', U_BOOT_DATA)
338 result = self._DoBinman('-b', 'sandbox')
339 self.assertEqual(0, result)
340
341 def testNeedBoard(self):
342 """Test that we get an error when no board ius supplied"""
343 with self.assertRaises(ValueError) as e:
344 result = self._DoBinman()
345 self.assertIn("Must provide a board to process (use -b <board>)",
346 str(e.exception))
347
348 def testMissingDt(self):
Simon Glass7ae5f312018-06-01 09:38:19 -0600349 """Test that an invalid device-tree file generates an error"""
Simon Glass4f443042016-11-25 20:15:52 -0700350 with self.assertRaises(Exception) as e:
351 self._RunBinman('-d', 'missing_file')
352 # We get one error from libfdt, and a different one from fdtget.
353 self.AssertInList(["Couldn't open blob from 'missing_file'",
354 'No such file or directory'], str(e.exception))
355
356 def testBrokenDt(self):
Simon Glass7ae5f312018-06-01 09:38:19 -0600357 """Test that an invalid device-tree source file generates an error
Simon Glass4f443042016-11-25 20:15:52 -0700358
359 Since this is a source file it should be compiled and the error
360 will come from the device-tree compiler (dtc).
361 """
362 with self.assertRaises(Exception) as e:
363 self._RunBinman('-d', self.TestFile('01_invalid.dts'))
364 self.assertIn("FATAL ERROR: Unable to parse input tree",
365 str(e.exception))
366
367 def testMissingNode(self):
368 """Test that a device tree without a 'binman' node generates an error"""
369 with self.assertRaises(Exception) as e:
370 self._DoBinman('-d', self.TestFile('02_missing_node.dts'))
371 self.assertIn("does not have a 'binman' node", str(e.exception))
372
373 def testEmpty(self):
374 """Test that an empty binman node works OK (i.e. does nothing)"""
375 result = self._RunBinman('-d', self.TestFile('03_empty.dts'))
376 self.assertEqual(0, len(result.stderr))
377 self.assertEqual(0, result.return_code)
378
379 def testInvalidEntry(self):
380 """Test that an invalid entry is flagged"""
381 with self.assertRaises(Exception) as e:
382 result = self._RunBinman('-d',
383 self.TestFile('04_invalid_entry.dts'))
384 #print e.exception
385 self.assertIn("Unknown entry type 'not-a-valid-type' in node "
386 "'/binman/not-a-valid-type'", str(e.exception))
387
388 def testSimple(self):
389 """Test a simple binman with a single file"""
390 data = self._DoReadFile('05_simple.dts')
391 self.assertEqual(U_BOOT_DATA, data)
392
Simon Glass7fe91732017-11-13 18:55:00 -0700393 def testSimpleDebug(self):
394 """Test a simple binman run with debugging enabled"""
395 data = self._DoTestFile('05_simple.dts', debug=True)
396
Simon Glass4f443042016-11-25 20:15:52 -0700397 def testDual(self):
398 """Test that we can handle creating two images
399
400 This also tests image padding.
401 """
402 retcode = self._DoTestFile('06_dual_image.dts')
403 self.assertEqual(0, retcode)
404
405 image = control.images['image1']
406 self.assertEqual(len(U_BOOT_DATA), image._size)
407 fname = tools.GetOutputFilename('image1.bin')
408 self.assertTrue(os.path.exists(fname))
409 with open(fname) as fd:
410 data = fd.read()
411 self.assertEqual(U_BOOT_DATA, data)
412
413 image = control.images['image2']
414 self.assertEqual(3 + len(U_BOOT_DATA) + 5, image._size)
415 fname = tools.GetOutputFilename('image2.bin')
416 self.assertTrue(os.path.exists(fname))
417 with open(fname) as fd:
418 data = fd.read()
419 self.assertEqual(U_BOOT_DATA, data[3:7])
420 self.assertEqual(chr(0) * 3, data[:3])
421 self.assertEqual(chr(0) * 5, data[7:])
422
423 def testBadAlign(self):
424 """Test that an invalid alignment value is detected"""
425 with self.assertRaises(ValueError) as e:
426 self._DoTestFile('07_bad_align.dts')
427 self.assertIn("Node '/binman/u-boot': Alignment 23 must be a power "
428 "of two", str(e.exception))
429
430 def testPackSimple(self):
431 """Test that packing works as expected"""
432 retcode = self._DoTestFile('08_pack.dts')
433 self.assertEqual(0, retcode)
434 self.assertIn('image', control.images)
435 image = control.images['image']
Simon Glass8f1da502018-06-01 09:38:12 -0600436 entries = image.GetEntries()
Simon Glass4f443042016-11-25 20:15:52 -0700437 self.assertEqual(5, len(entries))
438
439 # First u-boot
440 self.assertIn('u-boot', entries)
441 entry = entries['u-boot']
442 self.assertEqual(0, entry.pos)
443 self.assertEqual(len(U_BOOT_DATA), entry.size)
444
445 # Second u-boot, aligned to 16-byte boundary
446 self.assertIn('u-boot-align', entries)
447 entry = entries['u-boot-align']
448 self.assertEqual(16, entry.pos)
449 self.assertEqual(len(U_BOOT_DATA), entry.size)
450
451 # Third u-boot, size 23 bytes
452 self.assertIn('u-boot-size', entries)
453 entry = entries['u-boot-size']
454 self.assertEqual(20, entry.pos)
455 self.assertEqual(len(U_BOOT_DATA), entry.contents_size)
456 self.assertEqual(23, entry.size)
457
458 # Fourth u-boot, placed immediate after the above
459 self.assertIn('u-boot-next', entries)
460 entry = entries['u-boot-next']
461 self.assertEqual(43, entry.pos)
462 self.assertEqual(len(U_BOOT_DATA), entry.size)
463
464 # Fifth u-boot, placed at a fixed position
465 self.assertIn('u-boot-fixed', entries)
466 entry = entries['u-boot-fixed']
467 self.assertEqual(61, entry.pos)
468 self.assertEqual(len(U_BOOT_DATA), entry.size)
469
470 self.assertEqual(65, image._size)
471
472 def testPackExtra(self):
473 """Test that extra packing feature works as expected"""
474 retcode = self._DoTestFile('09_pack_extra.dts')
475
476 self.assertEqual(0, retcode)
477 self.assertIn('image', control.images)
478 image = control.images['image']
Simon Glass8f1da502018-06-01 09:38:12 -0600479 entries = image.GetEntries()
Simon Glass4f443042016-11-25 20:15:52 -0700480 self.assertEqual(5, len(entries))
481
482 # First u-boot with padding before and after
483 self.assertIn('u-boot', entries)
484 entry = entries['u-boot']
485 self.assertEqual(0, entry.pos)
486 self.assertEqual(3, entry.pad_before)
487 self.assertEqual(3 + 5 + len(U_BOOT_DATA), entry.size)
488
489 # Second u-boot has an aligned size, but it has no effect
490 self.assertIn('u-boot-align-size-nop', entries)
491 entry = entries['u-boot-align-size-nop']
492 self.assertEqual(12, entry.pos)
493 self.assertEqual(4, entry.size)
494
495 # Third u-boot has an aligned size too
496 self.assertIn('u-boot-align-size', entries)
497 entry = entries['u-boot-align-size']
498 self.assertEqual(16, entry.pos)
499 self.assertEqual(32, entry.size)
500
501 # Fourth u-boot has an aligned end
502 self.assertIn('u-boot-align-end', entries)
503 entry = entries['u-boot-align-end']
504 self.assertEqual(48, entry.pos)
505 self.assertEqual(16, entry.size)
506
507 # Fifth u-boot immediately afterwards
508 self.assertIn('u-boot-align-both', entries)
509 entry = entries['u-boot-align-both']
510 self.assertEqual(64, entry.pos)
511 self.assertEqual(64, entry.size)
512
513 self.CheckNoGaps(entries)
514 self.assertEqual(128, image._size)
515
516 def testPackAlignPowerOf2(self):
517 """Test that invalid entry alignment is detected"""
518 with self.assertRaises(ValueError) as e:
519 self._DoTestFile('10_pack_align_power2.dts')
520 self.assertIn("Node '/binman/u-boot': Alignment 5 must be a power "
521 "of two", str(e.exception))
522
523 def testPackAlignSizePowerOf2(self):
524 """Test that invalid entry size alignment is detected"""
525 with self.assertRaises(ValueError) as e:
526 self._DoTestFile('11_pack_align_size_power2.dts')
527 self.assertIn("Node '/binman/u-boot': Alignment size 55 must be a "
528 "power of two", str(e.exception))
529
530 def testPackInvalidAlign(self):
531 """Test detection of an position that does not match its alignment"""
532 with self.assertRaises(ValueError) as e:
533 self._DoTestFile('12_pack_inv_align.dts')
534 self.assertIn("Node '/binman/u-boot': Position 0x5 (5) does not match "
535 "align 0x4 (4)", str(e.exception))
536
537 def testPackInvalidSizeAlign(self):
538 """Test that invalid entry size alignment is detected"""
539 with self.assertRaises(ValueError) as e:
540 self._DoTestFile('13_pack_inv_size_align.dts')
541 self.assertIn("Node '/binman/u-boot': Size 0x5 (5) does not match "
542 "align-size 0x4 (4)", str(e.exception))
543
544 def testPackOverlap(self):
545 """Test that overlapping regions are detected"""
546 with self.assertRaises(ValueError) as e:
547 self._DoTestFile('14_pack_overlap.dts')
548 self.assertIn("Node '/binman/u-boot-align': Position 0x3 (3) overlaps "
549 "with previous entry '/binman/u-boot' ending at 0x4 (4)",
550 str(e.exception))
551
552 def testPackEntryOverflow(self):
553 """Test that entries that overflow their size are detected"""
554 with self.assertRaises(ValueError) as e:
555 self._DoTestFile('15_pack_overflow.dts')
556 self.assertIn("Node '/binman/u-boot': Entry contents size is 0x4 (4) "
557 "but entry size is 0x3 (3)", str(e.exception))
558
559 def testPackImageOverflow(self):
560 """Test that entries which overflow the image size are detected"""
561 with self.assertRaises(ValueError) as e:
562 self._DoTestFile('16_pack_image_overflow.dts')
Simon Glass8f1da502018-06-01 09:38:12 -0600563 self.assertIn("Section '/binman': contents size 0x4 (4) exceeds section "
Simon Glass4f443042016-11-25 20:15:52 -0700564 "size 0x3 (3)", str(e.exception))
565
566 def testPackImageSize(self):
567 """Test that the image size can be set"""
568 retcode = self._DoTestFile('17_pack_image_size.dts')
569 self.assertEqual(0, retcode)
570 self.assertIn('image', control.images)
571 image = control.images['image']
572 self.assertEqual(7, image._size)
573
574 def testPackImageSizeAlign(self):
575 """Test that image size alignemnt works as expected"""
576 retcode = self._DoTestFile('18_pack_image_align.dts')
577 self.assertEqual(0, retcode)
578 self.assertIn('image', control.images)
579 image = control.images['image']
580 self.assertEqual(16, image._size)
581
582 def testPackInvalidImageAlign(self):
583 """Test that invalid image alignment is detected"""
584 with self.assertRaises(ValueError) as e:
585 self._DoTestFile('19_pack_inv_image_align.dts')
Simon Glass8f1da502018-06-01 09:38:12 -0600586 self.assertIn("Section '/binman': Size 0x7 (7) does not match "
Simon Glass4f443042016-11-25 20:15:52 -0700587 "align-size 0x8 (8)", str(e.exception))
588
589 def testPackAlignPowerOf2(self):
590 """Test that invalid image alignment is detected"""
591 with self.assertRaises(ValueError) as e:
592 self._DoTestFile('20_pack_inv_image_align_power2.dts')
Simon Glass8f1da502018-06-01 09:38:12 -0600593 self.assertIn("Section '/binman': Alignment size 131 must be a power of "
Simon Glass4f443042016-11-25 20:15:52 -0700594 "two", str(e.exception))
595
596 def testImagePadByte(self):
597 """Test that the image pad byte can be specified"""
Simon Glass19790632017-11-13 18:55:01 -0700598 with open(self.TestFile('bss_data')) as fd:
599 TestFunctional._MakeInputFile('spl/u-boot-spl', fd.read())
Simon Glass4f443042016-11-25 20:15:52 -0700600 data = self._DoReadFile('21_image_pad.dts')
Simon Glassf6898902017-11-13 18:54:59 -0700601 self.assertEqual(U_BOOT_SPL_DATA + (chr(0xff) * 1) + U_BOOT_DATA, data)
Simon Glass4f443042016-11-25 20:15:52 -0700602
603 def testImageName(self):
604 """Test that image files can be named"""
605 retcode = self._DoTestFile('22_image_name.dts')
606 self.assertEqual(0, retcode)
607 image = control.images['image1']
608 fname = tools.GetOutputFilename('test-name')
609 self.assertTrue(os.path.exists(fname))
610
611 image = control.images['image2']
612 fname = tools.GetOutputFilename('test-name.xx')
613 self.assertTrue(os.path.exists(fname))
614
615 def testBlobFilename(self):
616 """Test that generic blobs can be provided by filename"""
617 data = self._DoReadFile('23_blob.dts')
618 self.assertEqual(BLOB_DATA, data)
619
620 def testPackSorted(self):
621 """Test that entries can be sorted"""
622 data = self._DoReadFile('24_sorted.dts')
Simon Glassf6898902017-11-13 18:54:59 -0700623 self.assertEqual(chr(0) * 1 + U_BOOT_SPL_DATA + chr(0) * 2 +
Simon Glass4f443042016-11-25 20:15:52 -0700624 U_BOOT_DATA, data)
625
626 def testPackZeroPosition(self):
627 """Test that an entry at position 0 is not given a new position"""
628 with self.assertRaises(ValueError) as e:
629 self._DoTestFile('25_pack_zero_size.dts')
630 self.assertIn("Node '/binman/u-boot-spl': Position 0x0 (0) overlaps "
631 "with previous entry '/binman/u-boot' ending at 0x4 (4)",
632 str(e.exception))
633
634 def testPackUbootDtb(self):
635 """Test that a device tree can be added to U-Boot"""
636 data = self._DoReadFile('26_pack_u_boot_dtb.dts')
637 self.assertEqual(U_BOOT_NODTB_DATA + U_BOOT_DTB_DATA, data)
Simon Glasse0ff8552016-11-25 20:15:53 -0700638
639 def testPackX86RomNoSize(self):
640 """Test that the end-at-4gb property requires a size property"""
641 with self.assertRaises(ValueError) as e:
642 self._DoTestFile('27_pack_4gb_no_size.dts')
Simon Glass8f1da502018-06-01 09:38:12 -0600643 self.assertIn("Section '/binman': Section size must be provided when "
Simon Glasse0ff8552016-11-25 20:15:53 -0700644 "using end-at-4gb", str(e.exception))
645
646 def testPackX86RomOutside(self):
647 """Test that the end-at-4gb property checks for position boundaries"""
648 with self.assertRaises(ValueError) as e:
649 self._DoTestFile('28_pack_4gb_outside.dts')
650 self.assertIn("Node '/binman/u-boot': Position 0x0 (0) is outside "
Simon Glass8f1da502018-06-01 09:38:12 -0600651 "the section starting at 0xffffffe0 (4294967264)",
Simon Glasse0ff8552016-11-25 20:15:53 -0700652 str(e.exception))
653
654 def testPackX86Rom(self):
655 """Test that a basic x86 ROM can be created"""
656 data = self._DoReadFile('29_x86-rom.dts')
Simon Glassf6898902017-11-13 18:54:59 -0700657 self.assertEqual(U_BOOT_DATA + chr(0) * 7 + U_BOOT_SPL_DATA +
658 chr(0) * 2, data)
Simon Glasse0ff8552016-11-25 20:15:53 -0700659
660 def testPackX86RomMeNoDesc(self):
661 """Test that an invalid Intel descriptor entry is detected"""
662 TestFunctional._MakeInputFile('descriptor.bin', '')
663 with self.assertRaises(ValueError) as e:
664 self._DoTestFile('31_x86-rom-me.dts')
665 self.assertIn("Node '/binman/intel-descriptor': Cannot find FD "
666 "signature", str(e.exception))
667
668 def testPackX86RomBadDesc(self):
669 """Test that the Intel requires a descriptor entry"""
670 with self.assertRaises(ValueError) as e:
671 self._DoTestFile('30_x86-rom-me-no-desc.dts')
672 self.assertIn("Node '/binman/intel-me': No position set with "
673 "pos-unset: should another entry provide this correct "
674 "position?", str(e.exception))
675
676 def testPackX86RomMe(self):
677 """Test that an x86 ROM with an ME region can be created"""
678 data = self._DoReadFile('31_x86-rom-me.dts')
679 self.assertEqual(ME_DATA, data[0x1000:0x1000 + len(ME_DATA)])
680
681 def testPackVga(self):
682 """Test that an image with a VGA binary can be created"""
683 data = self._DoReadFile('32_intel-vga.dts')
684 self.assertEqual(VGA_DATA, data[:len(VGA_DATA)])
685
686 def testPackStart16(self):
687 """Test that an image with an x86 start16 region can be created"""
688 data = self._DoReadFile('33_x86-start16.dts')
689 self.assertEqual(X86_START16_DATA, data[:len(X86_START16_DATA)])
690
Simon Glass6b187df2017-11-12 21:52:27 -0700691 def _RunMicrocodeTest(self, dts_fname, nodtb_data):
692 data = self._DoReadFile(dts_fname, True)
Simon Glasse0ff8552016-11-25 20:15:53 -0700693
694 # Now check the device tree has no microcode
Simon Glass6b187df2017-11-12 21:52:27 -0700695 second = data[len(nodtb_data):]
Simon Glasse0ff8552016-11-25 20:15:53 -0700696 fname = tools.GetOutputFilename('test.dtb')
697 with open(fname, 'wb') as fd:
698 fd.write(second)
Simon Glassec3f3782017-05-27 07:38:29 -0600699 dtb = fdt.FdtScan(fname)
700 ucode = dtb.GetNode('/microcode')
Simon Glasse0ff8552016-11-25 20:15:53 -0700701 self.assertTrue(ucode)
702 for node in ucode.subnodes:
703 self.assertFalse(node.props.get('data'))
704
705 fdt_len = self.GetFdtLen(second)
706 third = second[fdt_len:]
707
708 # Check that the microcode appears immediately after the Fdt
709 # This matches the concatenation of the data properties in
Simon Glass87722132017-11-12 21:52:26 -0700710 # the /microcode/update@xxx nodes in 34_x86_ucode.dts.
Simon Glasse0ff8552016-11-25 20:15:53 -0700711 ucode_data = struct.pack('>4L', 0x12345678, 0x12345679, 0xabcd0000,
712 0x78235609)
713 self.assertEqual(ucode_data, third[:len(ucode_data)])
Simon Glass6b187df2017-11-12 21:52:27 -0700714 ucode_pos = len(nodtb_data) + fdt_len
Simon Glasse0ff8552016-11-25 20:15:53 -0700715
716 # Check that the microcode pointer was inserted. It should match the
717 # expected position and size
718 pos_and_size = struct.pack('<2L', 0xfffffe00 + ucode_pos,
719 len(ucode_data))
Simon Glass6b187df2017-11-12 21:52:27 -0700720 first = data[:len(nodtb_data)]
721 return first, pos_and_size
722
723 def testPackUbootMicrocode(self):
724 """Test that x86 microcode can be handled correctly
725
726 We expect to see the following in the image, in order:
727 u-boot-nodtb.bin with a microcode pointer inserted at the correct
728 place
729 u-boot.dtb with the microcode removed
730 the microcode
731 """
732 first, pos_and_size = self._RunMicrocodeTest('34_x86_ucode.dts',
733 U_BOOT_NODTB_DATA)
Simon Glasse0ff8552016-11-25 20:15:53 -0700734 self.assertEqual('nodtb with microcode' + pos_and_size +
735 ' somewhere in here', first)
736
Simon Glass160a7662017-05-27 07:38:26 -0600737 def _RunPackUbootSingleMicrocode(self):
Simon Glasse0ff8552016-11-25 20:15:53 -0700738 """Test that x86 microcode can be handled correctly
739
740 We expect to see the following in the image, in order:
741 u-boot-nodtb.bin with a microcode pointer inserted at the correct
742 place
743 u-boot.dtb with the microcode
744 an empty microcode region
745 """
746 # We need the libfdt library to run this test since only that allows
747 # finding the offset of a property. This is required by
748 # Entry_u_boot_dtb_with_ucode.ObtainContents().
Simon Glasse0ff8552016-11-25 20:15:53 -0700749 data = self._DoReadFile('35_x86_single_ucode.dts', True)
750
751 second = data[len(U_BOOT_NODTB_DATA):]
752
753 fdt_len = self.GetFdtLen(second)
754 third = second[fdt_len:]
755 second = second[:fdt_len]
756
Simon Glass160a7662017-05-27 07:38:26 -0600757 ucode_data = struct.pack('>2L', 0x12345678, 0x12345679)
758 self.assertIn(ucode_data, second)
759 ucode_pos = second.find(ucode_data) + len(U_BOOT_NODTB_DATA)
Simon Glasse0ff8552016-11-25 20:15:53 -0700760
Simon Glass160a7662017-05-27 07:38:26 -0600761 # Check that the microcode pointer was inserted. It should match the
762 # expected position and size
763 pos_and_size = struct.pack('<2L', 0xfffffe00 + ucode_pos,
764 len(ucode_data))
765 first = data[:len(U_BOOT_NODTB_DATA)]
766 self.assertEqual('nodtb with microcode' + pos_and_size +
767 ' somewhere in here', first)
Simon Glassc49deb82016-11-25 20:15:54 -0700768
Simon Glass75db0862016-11-25 20:15:55 -0700769 def testPackUbootSingleMicrocode(self):
770 """Test that x86 microcode can be handled correctly with fdt_normal.
771 """
Simon Glass160a7662017-05-27 07:38:26 -0600772 self._RunPackUbootSingleMicrocode()
Simon Glass75db0862016-11-25 20:15:55 -0700773
Simon Glassc49deb82016-11-25 20:15:54 -0700774 def testUBootImg(self):
775 """Test that u-boot.img can be put in a file"""
776 data = self._DoReadFile('36_u_boot_img.dts')
777 self.assertEqual(U_BOOT_IMG_DATA, data)
Simon Glass75db0862016-11-25 20:15:55 -0700778
779 def testNoMicrocode(self):
780 """Test that a missing microcode region is detected"""
781 with self.assertRaises(ValueError) as e:
782 self._DoReadFile('37_x86_no_ucode.dts', True)
783 self.assertIn("Node '/binman/u-boot-dtb-with-ucode': No /microcode "
784 "node found in ", str(e.exception))
785
786 def testMicrocodeWithoutNode(self):
787 """Test that a missing u-boot-dtb-with-ucode node is detected"""
788 with self.assertRaises(ValueError) as e:
789 self._DoReadFile('38_x86_ucode_missing_node.dts', True)
790 self.assertIn("Node '/binman/u-boot-with-ucode-ptr': Cannot find "
791 "microcode region u-boot-dtb-with-ucode", str(e.exception))
792
793 def testMicrocodeWithoutNode2(self):
794 """Test that a missing u-boot-ucode node is detected"""
795 with self.assertRaises(ValueError) as e:
796 self._DoReadFile('39_x86_ucode_missing_node2.dts', True)
797 self.assertIn("Node '/binman/u-boot-with-ucode-ptr': Cannot find "
798 "microcode region u-boot-ucode", str(e.exception))
799
800 def testMicrocodeWithoutPtrInElf(self):
801 """Test that a U-Boot binary without the microcode symbol is detected"""
802 # ELF file without a '_dt_ucode_base_size' symbol
Simon Glass75db0862016-11-25 20:15:55 -0700803 try:
804 with open(self.TestFile('u_boot_no_ucode_ptr')) as fd:
805 TestFunctional._MakeInputFile('u-boot', fd.read())
806
807 with self.assertRaises(ValueError) as e:
Simon Glass160a7662017-05-27 07:38:26 -0600808 self._RunPackUbootSingleMicrocode()
Simon Glass75db0862016-11-25 20:15:55 -0700809 self.assertIn("Node '/binman/u-boot-with-ucode-ptr': Cannot locate "
810 "_dt_ucode_base_size symbol in u-boot", str(e.exception))
811
812 finally:
813 # Put the original file back
814 with open(self.TestFile('u_boot_ucode_ptr')) as fd:
815 TestFunctional._MakeInputFile('u-boot', fd.read())
816
817 def testMicrocodeNotInImage(self):
818 """Test that microcode must be placed within the image"""
819 with self.assertRaises(ValueError) as e:
820 self._DoReadFile('40_x86_ucode_not_in_image.dts', True)
821 self.assertIn("Node '/binman/u-boot-with-ucode-ptr': Microcode "
822 "pointer _dt_ucode_base_size at fffffe14 is outside the "
Simon Glass25ac0e62018-06-01 09:38:14 -0600823 "section ranging from 00000000 to 0000002e", str(e.exception))
Simon Glass75db0862016-11-25 20:15:55 -0700824
825 def testWithoutMicrocode(self):
826 """Test that we can cope with an image without microcode (e.g. qemu)"""
827 with open(self.TestFile('u_boot_no_ucode_ptr')) as fd:
828 TestFunctional._MakeInputFile('u-boot', fd.read())
Simon Glass3b0c3822018-06-01 09:38:20 -0600829 data, dtb, _ = self._DoReadFileDtb('44_x86_optional_ucode.dts', True)
Simon Glass75db0862016-11-25 20:15:55 -0700830
831 # Now check the device tree has no microcode
832 self.assertEqual(U_BOOT_NODTB_DATA, data[:len(U_BOOT_NODTB_DATA)])
833 second = data[len(U_BOOT_NODTB_DATA):]
834
835 fdt_len = self.GetFdtLen(second)
836 self.assertEqual(dtb, second[:fdt_len])
837
838 used_len = len(U_BOOT_NODTB_DATA) + fdt_len
839 third = data[used_len:]
840 self.assertEqual(chr(0) * (0x200 - used_len), third)
841
842 def testUnknownPosSize(self):
843 """Test that microcode must be placed within the image"""
844 with self.assertRaises(ValueError) as e:
845 self._DoReadFile('41_unknown_pos_size.dts', True)
Simon Glass8f1da502018-06-01 09:38:12 -0600846 self.assertIn("Section '/binman': Unable to set pos/size for unknown "
Simon Glass75db0862016-11-25 20:15:55 -0700847 "entry 'invalid-entry'", str(e.exception))
Simon Glassda229092016-11-25 20:15:56 -0700848
849 def testPackFsp(self):
850 """Test that an image with a FSP binary can be created"""
851 data = self._DoReadFile('42_intel-fsp.dts')
852 self.assertEqual(FSP_DATA, data[:len(FSP_DATA)])
853
854 def testPackCmc(self):
Bin Meng59ea8c22017-08-15 22:41:54 -0700855 """Test that an image with a CMC binary can be created"""
Simon Glassda229092016-11-25 20:15:56 -0700856 data = self._DoReadFile('43_intel-cmc.dts')
857 self.assertEqual(CMC_DATA, data[:len(CMC_DATA)])
Bin Meng59ea8c22017-08-15 22:41:54 -0700858
859 def testPackVbt(self):
860 """Test that an image with a VBT binary can be created"""
861 data = self._DoReadFile('46_intel-vbt.dts')
862 self.assertEqual(VBT_DATA, data[:len(VBT_DATA)])
Simon Glass9fc60b42017-11-12 21:52:22 -0700863
Simon Glass56509842017-11-12 21:52:25 -0700864 def testSplBssPad(self):
865 """Test that we can pad SPL's BSS with zeros"""
Simon Glass6b187df2017-11-12 21:52:27 -0700866 # ELF file with a '__bss_size' symbol
867 with open(self.TestFile('bss_data')) as fd:
868 TestFunctional._MakeInputFile('spl/u-boot-spl', fd.read())
Simon Glass56509842017-11-12 21:52:25 -0700869 data = self._DoReadFile('47_spl_bss_pad.dts')
870 self.assertEqual(U_BOOT_SPL_DATA + (chr(0) * 10) + U_BOOT_DATA, data)
871
Simon Glassb50e5612017-11-13 18:54:54 -0700872 with open(self.TestFile('u_boot_ucode_ptr')) as fd:
873 TestFunctional._MakeInputFile('spl/u-boot-spl', fd.read())
874 with self.assertRaises(ValueError) as e:
875 data = self._DoReadFile('47_spl_bss_pad.dts')
876 self.assertIn('Expected __bss_size symbol in spl/u-boot-spl',
877 str(e.exception))
878
Simon Glass87722132017-11-12 21:52:26 -0700879 def testPackStart16Spl(self):
880 """Test that an image with an x86 start16 region can be created"""
881 data = self._DoReadFile('48_x86-start16-spl.dts')
882 self.assertEqual(X86_START16_SPL_DATA, data[:len(X86_START16_SPL_DATA)])
883
Simon Glass6b187df2017-11-12 21:52:27 -0700884 def testPackUbootSplMicrocode(self):
885 """Test that x86 microcode can be handled correctly in SPL
886
887 We expect to see the following in the image, in order:
888 u-boot-spl-nodtb.bin with a microcode pointer inserted at the
889 correct place
890 u-boot.dtb with the microcode removed
891 the microcode
892 """
893 # ELF file with a '_dt_ucode_base_size' symbol
894 with open(self.TestFile('u_boot_ucode_ptr')) as fd:
895 TestFunctional._MakeInputFile('spl/u-boot-spl', fd.read())
896 first, pos_and_size = self._RunMicrocodeTest('49_x86_ucode_spl.dts',
897 U_BOOT_SPL_NODTB_DATA)
898 self.assertEqual('splnodtb with microc' + pos_and_size +
899 'ter somewhere in here', first)
900
Simon Glassca4f4ff2017-11-12 21:52:28 -0700901 def testPackMrc(self):
902 """Test that an image with an MRC binary can be created"""
903 data = self._DoReadFile('50_intel_mrc.dts')
904 self.assertEqual(MRC_DATA, data[:len(MRC_DATA)])
905
Simon Glass47419ea2017-11-13 18:54:55 -0700906 def testSplDtb(self):
907 """Test that an image with spl/u-boot-spl.dtb can be created"""
908 data = self._DoReadFile('51_u_boot_spl_dtb.dts')
909 self.assertEqual(U_BOOT_SPL_DTB_DATA, data[:len(U_BOOT_SPL_DTB_DATA)])
910
Simon Glass4e6fdbe2017-11-13 18:54:56 -0700911 def testSplNoDtb(self):
912 """Test that an image with spl/u-boot-spl-nodtb.bin can be created"""
913 data = self._DoReadFile('52_u_boot_spl_nodtb.dts')
914 self.assertEqual(U_BOOT_SPL_NODTB_DATA, data[:len(U_BOOT_SPL_NODTB_DATA)])
915
Simon Glass19790632017-11-13 18:55:01 -0700916 def testSymbols(self):
917 """Test binman can assign symbols embedded in U-Boot"""
918 elf_fname = self.TestFile('u_boot_binman_syms')
919 syms = elf.GetSymbols(elf_fname, ['binman', 'image'])
920 addr = elf.GetSymbolAddress(elf_fname, '__image_copy_start')
921 self.assertEqual(syms['_binman_u_boot_spl_prop_pos'].address, addr)
922
923 with open(self.TestFile('u_boot_binman_syms')) as fd:
924 TestFunctional._MakeInputFile('spl/u-boot-spl', fd.read())
925 data = self._DoReadFile('53_symbols.dts')
926 sym_values = struct.pack('<LQL', 0x24 + 0, 0x24 + 24, 0x24 + 20)
927 expected = (sym_values + U_BOOT_SPL_DATA[16:] + chr(0xff) +
928 U_BOOT_DATA +
929 sym_values + U_BOOT_SPL_DATA[16:])
930 self.assertEqual(expected, data)
931
Simon Glassdd57c132018-06-01 09:38:11 -0600932 def testPackUnitAddress(self):
933 """Test that we support multiple binaries with the same name"""
934 data = self._DoReadFile('54_unit_address.dts')
935 self.assertEqual(U_BOOT_DATA + U_BOOT_DATA, data)
936
Simon Glass18546952018-06-01 09:38:16 -0600937 def testSections(self):
938 """Basic test of sections"""
939 data = self._DoReadFile('55_sections.dts')
940 expected = U_BOOT_DATA + '!' * 12 + U_BOOT_DATA + 'a' * 12 + '&' * 8
941 self.assertEqual(expected, data)
Simon Glass9fc60b42017-11-12 21:52:22 -0700942
Simon Glass3b0c3822018-06-01 09:38:20 -0600943 def testMap(self):
944 """Tests outputting a map of the images"""
945 _, _, map_data = self._DoReadFileDtb('55_sections.dts', map=True)
946 self.assertEqual('''Position Size Name
94700000000 00000010 section@0
948 00000000 00000004 u-boot
94900000010 00000010 section@1
950 00000000 00000004 u-boot
951''', map_data)
952
Simon Glass9fc60b42017-11-12 21:52:22 -0700953if __name__ == "__main__":
954 unittest.main()