blob: a6de4cb93b8afe06061ba000e6126db313124a3f [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001# SPDX-License-Identifier: GPL-2.0+
Simon Glass57454f42016-11-25 20:15:52 -07002# Copyright (c) 2016 Google, Inc
3# Written by Simon Glass <sjg@chromium.org>
4#
Simon Glass57454f42016-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 Glass4ca8e042017-11-13 18:55:01 -070021import elf
Simon Glassa9440932017-05-27 07:38:30 -060022import fdt
Simon Glass57454f42016-11-25 20:15:52 -070023import fdt_util
Simon Glass704784b2018-07-17 13:25:38 -060024import fmap_util
Simon Glass969616c2018-07-17 13:25:36 -060025import test_util
Simon Glass57454f42016-11-25 20:15:52 -070026import tools
27import tout
28
29# Contents of test files, corresponding to different entry types
Simon Glass3d274232017-11-12 21:52:27 -070030U_BOOT_DATA = '1234'
31U_BOOT_IMG_DATA = 'img'
Simon Glassd6051522017-11-13 18:54:59 -070032U_BOOT_SPL_DATA = '56780123456789abcde'
Simon Glass3d274232017-11-12 21:52:27 -070033BLOB_DATA = '89'
34ME_DATA = '0abcd'
35VGA_DATA = 'vga'
36U_BOOT_DTB_DATA = 'udtb'
Simon Glass9aa6a6f2017-11-13 18:54:55 -070037U_BOOT_SPL_DTB_DATA = 'spldtb'
Simon Glass3d274232017-11-12 21:52:27 -070038X86_START16_DATA = 'start16'
39X86_START16_SPL_DATA = 'start16spl'
40U_BOOT_NODTB_DATA = 'nodtb with microcode pointer somewhere in here'
41U_BOOT_SPL_NODTB_DATA = 'splnodtb with microcode pointer somewhere in here'
42FSP_DATA = 'fsp'
43CMC_DATA = 'cmc'
44VBT_DATA = 'vbt'
Simon Glassa409c932017-11-12 21:52:28 -070045MRC_DATA = 'mrc'
Simon Glass2ca52032018-07-17 13:25:33 -060046TEXT_DATA = 'text'
47TEXT_DATA2 = 'text2'
48TEXT_DATA3 = 'text3'
Simon Glassdb168d42018-07-17 13:25:39 -060049CROS_EC_RW_DATA = 'ecrw'
Simon Glassc1ae83c2018-07-17 13:25:44 -060050GBB_DATA = 'gbbd'
51BMPBLK_DATA = 'bmp'
Simon Glass5c350162018-07-17 13:25:47 -060052VBLOCK_DATA = 'vblk'
Simon Glassdb168d42018-07-17 13:25:39 -060053
Simon Glass57454f42016-11-25 20:15:52 -070054
55class TestFunctional(unittest.TestCase):
56 """Functional tests for binman
57
58 Most of these use a sample .dts file to build an image and then check
59 that it looks correct. The sample files are in the test/ subdirectory
60 and are numbered.
61
62 For each entry type a very small test file is created using fixed
63 string contents. This makes it easy to test that things look right, and
64 debug problems.
65
66 In some cases a 'real' file must be used - these are also supplied in
67 the test/ diurectory.
68 """
69 @classmethod
70 def setUpClass(self):
Simon Glassb3393262017-11-12 21:52:20 -070071 global entry
72 import entry
73
Simon Glass57454f42016-11-25 20:15:52 -070074 # Handle the case where argv[0] is 'python'
75 self._binman_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
76 self._binman_pathname = os.path.join(self._binman_dir, 'binman')
77
78 # Create a temporary directory for input files
79 self._indir = tempfile.mkdtemp(prefix='binmant.')
80
81 # Create some test files
82 TestFunctional._MakeInputFile('u-boot.bin', U_BOOT_DATA)
83 TestFunctional._MakeInputFile('u-boot.img', U_BOOT_IMG_DATA)
84 TestFunctional._MakeInputFile('spl/u-boot-spl.bin', U_BOOT_SPL_DATA)
85 TestFunctional._MakeInputFile('blobfile', BLOB_DATA)
Simon Glass72232452016-11-25 20:15:53 -070086 TestFunctional._MakeInputFile('me.bin', ME_DATA)
87 TestFunctional._MakeInputFile('vga.bin', VGA_DATA)
Simon Glass57454f42016-11-25 20:15:52 -070088 TestFunctional._MakeInputFile('u-boot.dtb', U_BOOT_DTB_DATA)
Simon Glass9aa6a6f2017-11-13 18:54:55 -070089 TestFunctional._MakeInputFile('spl/u-boot-spl.dtb', U_BOOT_SPL_DTB_DATA)
Simon Glass72232452016-11-25 20:15:53 -070090 TestFunctional._MakeInputFile('u-boot-x86-16bit.bin', X86_START16_DATA)
Simon Glasse83679d2017-11-12 21:52:26 -070091 TestFunctional._MakeInputFile('spl/u-boot-x86-16bit-spl.bin',
92 X86_START16_SPL_DATA)
Simon Glass57454f42016-11-25 20:15:52 -070093 TestFunctional._MakeInputFile('u-boot-nodtb.bin', U_BOOT_NODTB_DATA)
Simon Glass3d274232017-11-12 21:52:27 -070094 TestFunctional._MakeInputFile('spl/u-boot-spl-nodtb.bin',
95 U_BOOT_SPL_NODTB_DATA)
Simon Glassb4176d42016-11-25 20:15:56 -070096 TestFunctional._MakeInputFile('fsp.bin', FSP_DATA)
97 TestFunctional._MakeInputFile('cmc.bin', CMC_DATA)
Bin Mengd7bcdf52017-08-15 22:41:54 -070098 TestFunctional._MakeInputFile('vbt.bin', VBT_DATA)
Simon Glassa409c932017-11-12 21:52:28 -070099 TestFunctional._MakeInputFile('mrc.bin', MRC_DATA)
Simon Glassdb168d42018-07-17 13:25:39 -0600100 TestFunctional._MakeInputFile('ecrw.bin', CROS_EC_RW_DATA)
Simon Glassc1ae83c2018-07-17 13:25:44 -0600101 TestFunctional._MakeInputDir('devkeys')
102 TestFunctional._MakeInputFile('bmpblk.bin', BMPBLK_DATA)
Simon Glass57454f42016-11-25 20:15:52 -0700103 self._output_setup = False
104
Simon Glass72232452016-11-25 20:15:53 -0700105 # ELF file with a '_dt_ucode_base_size' symbol
106 with open(self.TestFile('u_boot_ucode_ptr')) as fd:
107 TestFunctional._MakeInputFile('u-boot', fd.read())
108
109 # Intel flash descriptor file
110 with open(self.TestFile('descriptor.bin')) as fd:
111 TestFunctional._MakeInputFile('descriptor.bin', fd.read())
112
Simon Glass57454f42016-11-25 20:15:52 -0700113 @classmethod
114 def tearDownClass(self):
115 """Remove the temporary input directory and its contents"""
116 if self._indir:
117 shutil.rmtree(self._indir)
118 self._indir = None
119
120 def setUp(self):
121 # Enable this to turn on debugging output
122 # tout.Init(tout.DEBUG)
123 command.test_result = None
124
125 def tearDown(self):
126 """Remove the temporary output directory"""
127 tools._FinaliseForTest()
128
129 def _RunBinman(self, *args, **kwargs):
130 """Run binman using the command line
131
132 Args:
133 Arguments to pass, as a list of strings
134 kwargs: Arguments to pass to Command.RunPipe()
135 """
136 result = command.RunPipe([[self._binman_pathname] + list(args)],
137 capture=True, capture_stderr=True, raise_on_error=False)
138 if result.return_code and kwargs.get('raise_on_error', True):
139 raise Exception("Error running '%s': %s" % (' '.join(args),
140 result.stdout + result.stderr))
141 return result
142
143 def _DoBinman(self, *args):
144 """Run binman using directly (in the same process)
145
146 Args:
147 Arguments to pass, as a list of strings
148 Returns:
149 Return value (0 for success)
150 """
Simon Glass075a45c2017-11-13 18:55:00 -0700151 args = list(args)
152 if '-D' in sys.argv:
153 args = args + ['-D']
154 (options, args) = cmdline.ParseArgs(args)
Simon Glass57454f42016-11-25 20:15:52 -0700155 options.pager = 'binman-invalid-pager'
156 options.build_dir = self._indir
157
158 # For testing, you can force an increase in verbosity here
159 # options.verbosity = tout.DEBUG
160 return control.Binman(options, args)
161
Simon Glass91710b32018-07-17 13:25:32 -0600162 def _DoTestFile(self, fname, debug=False, map=False, update_dtb=False,
163 entry_args=None):
Simon Glass57454f42016-11-25 20:15:52 -0700164 """Run binman with a given test file
165
166 Args:
Simon Glass1e324002018-06-01 09:38:19 -0600167 fname: Device-tree source filename to use (e.g. 05_simple.dts)
168 debug: True to enable debugging output
Simon Glass30732662018-06-01 09:38:20 -0600169 map: True to output map files for the images
Simon Glasse8561af2018-08-01 15:22:37 -0600170 update_dtb: Update the offset and size of each entry in the device
Simon Glassa87014e2018-07-06 10:27:42 -0600171 tree before packing it into the image
Simon Glass57454f42016-11-25 20:15:52 -0700172 """
Simon Glass075a45c2017-11-13 18:55:00 -0700173 args = ['-p', '-I', self._indir, '-d', self.TestFile(fname)]
174 if debug:
175 args.append('-D')
Simon Glass30732662018-06-01 09:38:20 -0600176 if map:
177 args.append('-m')
Simon Glassa87014e2018-07-06 10:27:42 -0600178 if update_dtb:
179 args.append('-up')
Simon Glass91710b32018-07-17 13:25:32 -0600180 if entry_args:
181 for arg, value in entry_args.iteritems():
182 args.append('-a%s=%s' % (arg, value))
Simon Glass075a45c2017-11-13 18:55:00 -0700183 return self._DoBinman(*args)
Simon Glass57454f42016-11-25 20:15:52 -0700184
185 def _SetupDtb(self, fname, outfile='u-boot.dtb'):
Simon Glass72232452016-11-25 20:15:53 -0700186 """Set up a new test device-tree file
187
188 The given file is compiled and set up as the device tree to be used
189 for ths test.
190
191 Args:
192 fname: Filename of .dts file to read
Simon Glass1e324002018-06-01 09:38:19 -0600193 outfile: Output filename for compiled device-tree binary
Simon Glass72232452016-11-25 20:15:53 -0700194
195 Returns:
Simon Glass1e324002018-06-01 09:38:19 -0600196 Contents of device-tree binary
Simon Glass72232452016-11-25 20:15:53 -0700197 """
Simon Glass57454f42016-11-25 20:15:52 -0700198 if not self._output_setup:
199 tools.PrepareOutputDir(self._indir, True)
200 self._output_setup = True
201 dtb = fdt_util.EnsureCompiled(self.TestFile(fname))
202 with open(dtb) as fd:
203 data = fd.read()
204 TestFunctional._MakeInputFile(outfile, data)
Simon Glass72232452016-11-25 20:15:53 -0700205 return data
Simon Glass57454f42016-11-25 20:15:52 -0700206
Simon Glassa87014e2018-07-06 10:27:42 -0600207 def _DoReadFileDtb(self, fname, use_real_dtb=False, map=False,
Simon Glass91710b32018-07-17 13:25:32 -0600208 update_dtb=False, entry_args=None):
Simon Glass57454f42016-11-25 20:15:52 -0700209 """Run binman and return the resulting image
210
211 This runs binman with a given test file and then reads the resulting
212 output file. It is a shortcut function since most tests need to do
213 these steps.
214
215 Raises an assertion failure if binman returns a non-zero exit code.
216
217 Args:
Simon Glass1e324002018-06-01 09:38:19 -0600218 fname: Device-tree source filename to use (e.g. 05_simple.dts)
Simon Glass57454f42016-11-25 20:15:52 -0700219 use_real_dtb: True to use the test file as the contents of
220 the u-boot-dtb entry. Normally this is not needed and the
221 test contents (the U_BOOT_DTB_DATA string) can be used.
222 But in some test we need the real contents.
Simon Glass30732662018-06-01 09:38:20 -0600223 map: True to output map files for the images
Simon Glasse8561af2018-08-01 15:22:37 -0600224 update_dtb: Update the offset and size of each entry in the device
Simon Glassa87014e2018-07-06 10:27:42 -0600225 tree before packing it into the image
Simon Glass72232452016-11-25 20:15:53 -0700226
227 Returns:
228 Tuple:
229 Resulting image contents
230 Device tree contents
Simon Glass30732662018-06-01 09:38:20 -0600231 Map data showing contents of image (or None if none)
Simon Glassdef77b52018-07-17 13:25:27 -0600232 Output device tree binary filename ('u-boot.dtb' path)
Simon Glass57454f42016-11-25 20:15:52 -0700233 """
Simon Glass72232452016-11-25 20:15:53 -0700234 dtb_data = None
Simon Glass57454f42016-11-25 20:15:52 -0700235 # Use the compiled test file as the u-boot-dtb input
236 if use_real_dtb:
Simon Glass72232452016-11-25 20:15:53 -0700237 dtb_data = self._SetupDtb(fname)
Simon Glass57454f42016-11-25 20:15:52 -0700238
239 try:
Simon Glass91710b32018-07-17 13:25:32 -0600240 retcode = self._DoTestFile(fname, map=map, update_dtb=update_dtb,
241 entry_args=entry_args)
Simon Glass57454f42016-11-25 20:15:52 -0700242 self.assertEqual(0, retcode)
Simon Glassa87014e2018-07-06 10:27:42 -0600243 out_dtb_fname = control.GetFdtPath('u-boot.dtb')
Simon Glass57454f42016-11-25 20:15:52 -0700244
245 # Find the (only) image, read it and return its contents
246 image = control.images['image']
Simon Glassa87014e2018-07-06 10:27:42 -0600247 image_fname = tools.GetOutputFilename('image.bin')
248 self.assertTrue(os.path.exists(image_fname))
Simon Glass30732662018-06-01 09:38:20 -0600249 if map:
250 map_fname = tools.GetOutputFilename('image.map')
251 with open(map_fname) as fd:
252 map_data = fd.read()
253 else:
254 map_data = None
Simon Glassa87014e2018-07-06 10:27:42 -0600255 with open(image_fname) as fd:
256 return fd.read(), dtb_data, map_data, out_dtb_fname
Simon Glass57454f42016-11-25 20:15:52 -0700257 finally:
258 # Put the test file back
259 if use_real_dtb:
260 TestFunctional._MakeInputFile('u-boot.dtb', U_BOOT_DTB_DATA)
261
Simon Glass72232452016-11-25 20:15:53 -0700262 def _DoReadFile(self, fname, use_real_dtb=False):
Simon Glass1e324002018-06-01 09:38:19 -0600263 """Helper function which discards the device-tree binary
264
265 Args:
266 fname: Device-tree source filename to use (e.g. 05_simple.dts)
267 use_real_dtb: True to use the test file as the contents of
268 the u-boot-dtb entry. Normally this is not needed and the
269 test contents (the U_BOOT_DTB_DATA string) can be used.
270 But in some test we need the real contents.
Simon Glassdef77b52018-07-17 13:25:27 -0600271
272 Returns:
273 Resulting image contents
Simon Glass1e324002018-06-01 09:38:19 -0600274 """
Simon Glass72232452016-11-25 20:15:53 -0700275 return self._DoReadFileDtb(fname, use_real_dtb)[0]
276
Simon Glass57454f42016-11-25 20:15:52 -0700277 @classmethod
278 def _MakeInputFile(self, fname, contents):
279 """Create a new test input file, creating directories as needed
280
281 Args:
Simon Glasse8561af2018-08-01 15:22:37 -0600282 fname: Filename to create
Simon Glass57454f42016-11-25 20:15:52 -0700283 contents: File contents to write in to the file
284 Returns:
285 Full pathname of file created
286 """
287 pathname = os.path.join(self._indir, fname)
288 dirname = os.path.dirname(pathname)
289 if dirname and not os.path.exists(dirname):
290 os.makedirs(dirname)
291 with open(pathname, 'wb') as fd:
292 fd.write(contents)
293 return pathname
294
295 @classmethod
Simon Glassc1ae83c2018-07-17 13:25:44 -0600296 def _MakeInputDir(self, dirname):
297 """Create a new test input directory, creating directories as needed
298
299 Args:
300 dirname: Directory name to create
301
302 Returns:
303 Full pathname of directory created
304 """
305 pathname = os.path.join(self._indir, dirname)
306 if not os.path.exists(pathname):
307 os.makedirs(pathname)
308 return pathname
309
310 @classmethod
Simon Glass57454f42016-11-25 20:15:52 -0700311 def TestFile(self, fname):
312 return os.path.join(self._binman_dir, 'test', fname)
313
314 def AssertInList(self, grep_list, target):
315 """Assert that at least one of a list of things is in a target
316
317 Args:
318 grep_list: List of strings to check
319 target: Target string
320 """
321 for grep in grep_list:
322 if grep in target:
323 return
324 self.fail("Error: '%' not found in '%s'" % (grep_list, target))
325
326 def CheckNoGaps(self, entries):
327 """Check that all entries fit together without gaps
328
329 Args:
330 entries: List of entries to check
331 """
Simon Glasse8561af2018-08-01 15:22:37 -0600332 offset = 0
Simon Glass57454f42016-11-25 20:15:52 -0700333 for entry in entries.values():
Simon Glasse8561af2018-08-01 15:22:37 -0600334 self.assertEqual(offset, entry.offset)
335 offset += entry.size
Simon Glass57454f42016-11-25 20:15:52 -0700336
Simon Glass72232452016-11-25 20:15:53 -0700337 def GetFdtLen(self, dtb):
Simon Glass1e324002018-06-01 09:38:19 -0600338 """Get the totalsize field from a device-tree binary
Simon Glass72232452016-11-25 20:15:53 -0700339
340 Args:
Simon Glass1e324002018-06-01 09:38:19 -0600341 dtb: Device-tree binary contents
Simon Glass72232452016-11-25 20:15:53 -0700342
343 Returns:
Simon Glass1e324002018-06-01 09:38:19 -0600344 Total size of device-tree binary, from the header
Simon Glass72232452016-11-25 20:15:53 -0700345 """
346 return struct.unpack('>L', dtb[4:8])[0]
347
Simon Glassa87014e2018-07-06 10:27:42 -0600348 def _GetPropTree(self, dtb_data, node_names):
349 def AddNode(node, path):
350 if node.name != '/':
351 path += '/' + node.name
Simon Glassa87014e2018-07-06 10:27:42 -0600352 for subnode in node.subnodes:
353 for prop in subnode.props.values():
354 if prop.name in node_names:
355 prop_path = path + '/' + subnode.name + ':' + prop.name
356 tree[prop_path[len('/binman/'):]] = fdt_util.fdt32_to_cpu(
357 prop.value)
Simon Glassa87014e2018-07-06 10:27:42 -0600358 AddNode(subnode, path)
359
360 tree = {}
361 dtb = fdt.Fdt(dtb_data)
362 dtb.Scan()
363 AddNode(dtb.GetRoot(), '')
364 return tree
365
Simon Glass57454f42016-11-25 20:15:52 -0700366 def testRun(self):
367 """Test a basic run with valid args"""
368 result = self._RunBinman('-h')
369
370 def testFullHelp(self):
371 """Test that the full help is displayed with -H"""
372 result = self._RunBinman('-H')
373 help_file = os.path.join(self._binman_dir, 'README')
Tom Rinic3c0b6d2018-01-16 15:29:50 -0500374 # Remove possible extraneous strings
375 extra = '::::::::::::::\n' + help_file + '\n::::::::::::::\n'
376 gothelp = result.stdout.replace(extra, '')
377 self.assertEqual(len(gothelp), os.path.getsize(help_file))
Simon Glass57454f42016-11-25 20:15:52 -0700378 self.assertEqual(0, len(result.stderr))
379 self.assertEqual(0, result.return_code)
380
381 def testFullHelpInternal(self):
382 """Test that the full help is displayed with -H"""
383 try:
384 command.test_result = command.CommandResult()
385 result = self._DoBinman('-H')
386 help_file = os.path.join(self._binman_dir, 'README')
387 finally:
388 command.test_result = None
389
390 def testHelp(self):
391 """Test that the basic help is displayed with -h"""
392 result = self._RunBinman('-h')
393 self.assertTrue(len(result.stdout) > 200)
394 self.assertEqual(0, len(result.stderr))
395 self.assertEqual(0, result.return_code)
396
Simon Glass57454f42016-11-25 20:15:52 -0700397 def testBoard(self):
398 """Test that we can run it with a specific board"""
399 self._SetupDtb('05_simple.dts', 'sandbox/u-boot.dtb')
400 TestFunctional._MakeInputFile('sandbox/u-boot.bin', U_BOOT_DATA)
401 result = self._DoBinman('-b', 'sandbox')
402 self.assertEqual(0, result)
403
404 def testNeedBoard(self):
405 """Test that we get an error when no board ius supplied"""
406 with self.assertRaises(ValueError) as e:
407 result = self._DoBinman()
408 self.assertIn("Must provide a board to process (use -b <board>)",
409 str(e.exception))
410
411 def testMissingDt(self):
Simon Glass1e324002018-06-01 09:38:19 -0600412 """Test that an invalid device-tree file generates an error"""
Simon Glass57454f42016-11-25 20:15:52 -0700413 with self.assertRaises(Exception) as e:
414 self._RunBinman('-d', 'missing_file')
415 # We get one error from libfdt, and a different one from fdtget.
416 self.AssertInList(["Couldn't open blob from 'missing_file'",
417 'No such file or directory'], str(e.exception))
418
419 def testBrokenDt(self):
Simon Glass1e324002018-06-01 09:38:19 -0600420 """Test that an invalid device-tree source file generates an error
Simon Glass57454f42016-11-25 20:15:52 -0700421
422 Since this is a source file it should be compiled and the error
423 will come from the device-tree compiler (dtc).
424 """
425 with self.assertRaises(Exception) as e:
426 self._RunBinman('-d', self.TestFile('01_invalid.dts'))
427 self.assertIn("FATAL ERROR: Unable to parse input tree",
428 str(e.exception))
429
430 def testMissingNode(self):
431 """Test that a device tree without a 'binman' node generates an error"""
432 with self.assertRaises(Exception) as e:
433 self._DoBinman('-d', self.TestFile('02_missing_node.dts'))
434 self.assertIn("does not have a 'binman' node", str(e.exception))
435
436 def testEmpty(self):
437 """Test that an empty binman node works OK (i.e. does nothing)"""
438 result = self._RunBinman('-d', self.TestFile('03_empty.dts'))
439 self.assertEqual(0, len(result.stderr))
440 self.assertEqual(0, result.return_code)
441
442 def testInvalidEntry(self):
443 """Test that an invalid entry is flagged"""
444 with self.assertRaises(Exception) as e:
445 result = self._RunBinman('-d',
446 self.TestFile('04_invalid_entry.dts'))
Simon Glass57454f42016-11-25 20:15:52 -0700447 self.assertIn("Unknown entry type 'not-a-valid-type' in node "
448 "'/binman/not-a-valid-type'", str(e.exception))
449
450 def testSimple(self):
451 """Test a simple binman with a single file"""
452 data = self._DoReadFile('05_simple.dts')
453 self.assertEqual(U_BOOT_DATA, data)
454
Simon Glass075a45c2017-11-13 18:55:00 -0700455 def testSimpleDebug(self):
456 """Test a simple binman run with debugging enabled"""
457 data = self._DoTestFile('05_simple.dts', debug=True)
458
Simon Glass57454f42016-11-25 20:15:52 -0700459 def testDual(self):
460 """Test that we can handle creating two images
461
462 This also tests image padding.
463 """
464 retcode = self._DoTestFile('06_dual_image.dts')
465 self.assertEqual(0, retcode)
466
467 image = control.images['image1']
468 self.assertEqual(len(U_BOOT_DATA), image._size)
469 fname = tools.GetOutputFilename('image1.bin')
470 self.assertTrue(os.path.exists(fname))
471 with open(fname) as fd:
472 data = fd.read()
473 self.assertEqual(U_BOOT_DATA, data)
474
475 image = control.images['image2']
476 self.assertEqual(3 + len(U_BOOT_DATA) + 5, image._size)
477 fname = tools.GetOutputFilename('image2.bin')
478 self.assertTrue(os.path.exists(fname))
479 with open(fname) as fd:
480 data = fd.read()
481 self.assertEqual(U_BOOT_DATA, data[3:7])
482 self.assertEqual(chr(0) * 3, data[:3])
483 self.assertEqual(chr(0) * 5, data[7:])
484
485 def testBadAlign(self):
486 """Test that an invalid alignment value is detected"""
487 with self.assertRaises(ValueError) as e:
488 self._DoTestFile('07_bad_align.dts')
489 self.assertIn("Node '/binman/u-boot': Alignment 23 must be a power "
490 "of two", str(e.exception))
491
492 def testPackSimple(self):
493 """Test that packing works as expected"""
494 retcode = self._DoTestFile('08_pack.dts')
495 self.assertEqual(0, retcode)
496 self.assertIn('image', control.images)
497 image = control.images['image']
Simon Glasseca32212018-06-01 09:38:12 -0600498 entries = image.GetEntries()
Simon Glass57454f42016-11-25 20:15:52 -0700499 self.assertEqual(5, len(entries))
500
501 # First u-boot
502 self.assertIn('u-boot', entries)
503 entry = entries['u-boot']
Simon Glasse8561af2018-08-01 15:22:37 -0600504 self.assertEqual(0, entry.offset)
Simon Glass57454f42016-11-25 20:15:52 -0700505 self.assertEqual(len(U_BOOT_DATA), entry.size)
506
507 # Second u-boot, aligned to 16-byte boundary
508 self.assertIn('u-boot-align', entries)
509 entry = entries['u-boot-align']
Simon Glasse8561af2018-08-01 15:22:37 -0600510 self.assertEqual(16, entry.offset)
Simon Glass57454f42016-11-25 20:15:52 -0700511 self.assertEqual(len(U_BOOT_DATA), entry.size)
512
513 # Third u-boot, size 23 bytes
514 self.assertIn('u-boot-size', entries)
515 entry = entries['u-boot-size']
Simon Glasse8561af2018-08-01 15:22:37 -0600516 self.assertEqual(20, entry.offset)
Simon Glass57454f42016-11-25 20:15:52 -0700517 self.assertEqual(len(U_BOOT_DATA), entry.contents_size)
518 self.assertEqual(23, entry.size)
519
520 # Fourth u-boot, placed immediate after the above
521 self.assertIn('u-boot-next', entries)
522 entry = entries['u-boot-next']
Simon Glasse8561af2018-08-01 15:22:37 -0600523 self.assertEqual(43, entry.offset)
Simon Glass57454f42016-11-25 20:15:52 -0700524 self.assertEqual(len(U_BOOT_DATA), entry.size)
525
Simon Glasse8561af2018-08-01 15:22:37 -0600526 # Fifth u-boot, placed at a fixed offset
Simon Glass57454f42016-11-25 20:15:52 -0700527 self.assertIn('u-boot-fixed', entries)
528 entry = entries['u-boot-fixed']
Simon Glasse8561af2018-08-01 15:22:37 -0600529 self.assertEqual(61, entry.offset)
Simon Glass57454f42016-11-25 20:15:52 -0700530 self.assertEqual(len(U_BOOT_DATA), entry.size)
531
532 self.assertEqual(65, image._size)
533
534 def testPackExtra(self):
535 """Test that extra packing feature works as expected"""
536 retcode = self._DoTestFile('09_pack_extra.dts')
537
538 self.assertEqual(0, retcode)
539 self.assertIn('image', control.images)
540 image = control.images['image']
Simon Glasseca32212018-06-01 09:38:12 -0600541 entries = image.GetEntries()
Simon Glass57454f42016-11-25 20:15:52 -0700542 self.assertEqual(5, len(entries))
543
544 # First u-boot with padding before and after
545 self.assertIn('u-boot', entries)
546 entry = entries['u-boot']
Simon Glasse8561af2018-08-01 15:22:37 -0600547 self.assertEqual(0, entry.offset)
Simon Glass57454f42016-11-25 20:15:52 -0700548 self.assertEqual(3, entry.pad_before)
549 self.assertEqual(3 + 5 + len(U_BOOT_DATA), entry.size)
550
551 # Second u-boot has an aligned size, but it has no effect
552 self.assertIn('u-boot-align-size-nop', entries)
553 entry = entries['u-boot-align-size-nop']
Simon Glasse8561af2018-08-01 15:22:37 -0600554 self.assertEqual(12, entry.offset)
Simon Glass57454f42016-11-25 20:15:52 -0700555 self.assertEqual(4, entry.size)
556
557 # Third u-boot has an aligned size too
558 self.assertIn('u-boot-align-size', entries)
559 entry = entries['u-boot-align-size']
Simon Glasse8561af2018-08-01 15:22:37 -0600560 self.assertEqual(16, entry.offset)
Simon Glass57454f42016-11-25 20:15:52 -0700561 self.assertEqual(32, entry.size)
562
563 # Fourth u-boot has an aligned end
564 self.assertIn('u-boot-align-end', entries)
565 entry = entries['u-boot-align-end']
Simon Glasse8561af2018-08-01 15:22:37 -0600566 self.assertEqual(48, entry.offset)
Simon Glass57454f42016-11-25 20:15:52 -0700567 self.assertEqual(16, entry.size)
568
569 # Fifth u-boot immediately afterwards
570 self.assertIn('u-boot-align-both', entries)
571 entry = entries['u-boot-align-both']
Simon Glasse8561af2018-08-01 15:22:37 -0600572 self.assertEqual(64, entry.offset)
Simon Glass57454f42016-11-25 20:15:52 -0700573 self.assertEqual(64, entry.size)
574
575 self.CheckNoGaps(entries)
576 self.assertEqual(128, image._size)
577
578 def testPackAlignPowerOf2(self):
579 """Test that invalid entry alignment is detected"""
580 with self.assertRaises(ValueError) as e:
581 self._DoTestFile('10_pack_align_power2.dts')
582 self.assertIn("Node '/binman/u-boot': Alignment 5 must be a power "
583 "of two", str(e.exception))
584
585 def testPackAlignSizePowerOf2(self):
586 """Test that invalid entry size alignment is detected"""
587 with self.assertRaises(ValueError) as e:
588 self._DoTestFile('11_pack_align_size_power2.dts')
589 self.assertIn("Node '/binman/u-boot': Alignment size 55 must be a "
590 "power of two", str(e.exception))
591
592 def testPackInvalidAlign(self):
Simon Glasse8561af2018-08-01 15:22:37 -0600593 """Test detection of an offset that does not match its alignment"""
Simon Glass57454f42016-11-25 20:15:52 -0700594 with self.assertRaises(ValueError) as e:
595 self._DoTestFile('12_pack_inv_align.dts')
Simon Glasse8561af2018-08-01 15:22:37 -0600596 self.assertIn("Node '/binman/u-boot': Offset 0x5 (5) does not match "
Simon Glass57454f42016-11-25 20:15:52 -0700597 "align 0x4 (4)", str(e.exception))
598
599 def testPackInvalidSizeAlign(self):
600 """Test that invalid entry size alignment is detected"""
601 with self.assertRaises(ValueError) as e:
602 self._DoTestFile('13_pack_inv_size_align.dts')
603 self.assertIn("Node '/binman/u-boot': Size 0x5 (5) does not match "
604 "align-size 0x4 (4)", str(e.exception))
605
606 def testPackOverlap(self):
607 """Test that overlapping regions are detected"""
608 with self.assertRaises(ValueError) as e:
609 self._DoTestFile('14_pack_overlap.dts')
Simon Glasse8561af2018-08-01 15:22:37 -0600610 self.assertIn("Node '/binman/u-boot-align': Offset 0x3 (3) overlaps "
Simon Glass57454f42016-11-25 20:15:52 -0700611 "with previous entry '/binman/u-boot' ending at 0x4 (4)",
612 str(e.exception))
613
614 def testPackEntryOverflow(self):
615 """Test that entries that overflow their size are detected"""
616 with self.assertRaises(ValueError) as e:
617 self._DoTestFile('15_pack_overflow.dts')
618 self.assertIn("Node '/binman/u-boot': Entry contents size is 0x4 (4) "
619 "but entry size is 0x3 (3)", str(e.exception))
620
621 def testPackImageOverflow(self):
622 """Test that entries which overflow the image size are detected"""
623 with self.assertRaises(ValueError) as e:
624 self._DoTestFile('16_pack_image_overflow.dts')
Simon Glasseca32212018-06-01 09:38:12 -0600625 self.assertIn("Section '/binman': contents size 0x4 (4) exceeds section "
Simon Glass57454f42016-11-25 20:15:52 -0700626 "size 0x3 (3)", str(e.exception))
627
628 def testPackImageSize(self):
629 """Test that the image size can be set"""
630 retcode = self._DoTestFile('17_pack_image_size.dts')
631 self.assertEqual(0, retcode)
632 self.assertIn('image', control.images)
633 image = control.images['image']
634 self.assertEqual(7, image._size)
635
636 def testPackImageSizeAlign(self):
637 """Test that image size alignemnt works as expected"""
638 retcode = self._DoTestFile('18_pack_image_align.dts')
639 self.assertEqual(0, retcode)
640 self.assertIn('image', control.images)
641 image = control.images['image']
642 self.assertEqual(16, image._size)
643
644 def testPackInvalidImageAlign(self):
645 """Test that invalid image alignment is detected"""
646 with self.assertRaises(ValueError) as e:
647 self._DoTestFile('19_pack_inv_image_align.dts')
Simon Glasseca32212018-06-01 09:38:12 -0600648 self.assertIn("Section '/binman': Size 0x7 (7) does not match "
Simon Glass57454f42016-11-25 20:15:52 -0700649 "align-size 0x8 (8)", str(e.exception))
650
651 def testPackAlignPowerOf2(self):
652 """Test that invalid image alignment is detected"""
653 with self.assertRaises(ValueError) as e:
654 self._DoTestFile('20_pack_inv_image_align_power2.dts')
Simon Glasseca32212018-06-01 09:38:12 -0600655 self.assertIn("Section '/binman': Alignment size 131 must be a power of "
Simon Glass57454f42016-11-25 20:15:52 -0700656 "two", str(e.exception))
657
658 def testImagePadByte(self):
659 """Test that the image pad byte can be specified"""
Simon Glass4ca8e042017-11-13 18:55:01 -0700660 with open(self.TestFile('bss_data')) as fd:
661 TestFunctional._MakeInputFile('spl/u-boot-spl', fd.read())
Simon Glass57454f42016-11-25 20:15:52 -0700662 data = self._DoReadFile('21_image_pad.dts')
Simon Glassd6051522017-11-13 18:54:59 -0700663 self.assertEqual(U_BOOT_SPL_DATA + (chr(0xff) * 1) + U_BOOT_DATA, data)
Simon Glass57454f42016-11-25 20:15:52 -0700664
665 def testImageName(self):
666 """Test that image files can be named"""
667 retcode = self._DoTestFile('22_image_name.dts')
668 self.assertEqual(0, retcode)
669 image = control.images['image1']
670 fname = tools.GetOutputFilename('test-name')
671 self.assertTrue(os.path.exists(fname))
672
673 image = control.images['image2']
674 fname = tools.GetOutputFilename('test-name.xx')
675 self.assertTrue(os.path.exists(fname))
676
677 def testBlobFilename(self):
678 """Test that generic blobs can be provided by filename"""
679 data = self._DoReadFile('23_blob.dts')
680 self.assertEqual(BLOB_DATA, data)
681
682 def testPackSorted(self):
683 """Test that entries can be sorted"""
684 data = self._DoReadFile('24_sorted.dts')
Simon Glassd6051522017-11-13 18:54:59 -0700685 self.assertEqual(chr(0) * 1 + U_BOOT_SPL_DATA + chr(0) * 2 +
Simon Glass57454f42016-11-25 20:15:52 -0700686 U_BOOT_DATA, data)
687
Simon Glasse8561af2018-08-01 15:22:37 -0600688 def testPackZeroOffset(self):
689 """Test that an entry at offset 0 is not given a new offset"""
Simon Glass57454f42016-11-25 20:15:52 -0700690 with self.assertRaises(ValueError) as e:
691 self._DoTestFile('25_pack_zero_size.dts')
Simon Glasse8561af2018-08-01 15:22:37 -0600692 self.assertIn("Node '/binman/u-boot-spl': Offset 0x0 (0) overlaps "
Simon Glass57454f42016-11-25 20:15:52 -0700693 "with previous entry '/binman/u-boot' ending at 0x4 (4)",
694 str(e.exception))
695
696 def testPackUbootDtb(self):
697 """Test that a device tree can be added to U-Boot"""
698 data = self._DoReadFile('26_pack_u_boot_dtb.dts')
699 self.assertEqual(U_BOOT_NODTB_DATA + U_BOOT_DTB_DATA, data)
Simon Glass72232452016-11-25 20:15:53 -0700700
701 def testPackX86RomNoSize(self):
702 """Test that the end-at-4gb property requires a size property"""
703 with self.assertRaises(ValueError) as e:
704 self._DoTestFile('27_pack_4gb_no_size.dts')
Simon Glasseca32212018-06-01 09:38:12 -0600705 self.assertIn("Section '/binman': Section size must be provided when "
Simon Glass72232452016-11-25 20:15:53 -0700706 "using end-at-4gb", str(e.exception))
707
708 def testPackX86RomOutside(self):
Simon Glasse8561af2018-08-01 15:22:37 -0600709 """Test that the end-at-4gb property checks for offset boundaries"""
Simon Glass72232452016-11-25 20:15:53 -0700710 with self.assertRaises(ValueError) as e:
711 self._DoTestFile('28_pack_4gb_outside.dts')
Simon Glasse8561af2018-08-01 15:22:37 -0600712 self.assertIn("Node '/binman/u-boot': Offset 0x0 (0) is outside "
Simon Glasseca32212018-06-01 09:38:12 -0600713 "the section starting at 0xffffffe0 (4294967264)",
Simon Glass72232452016-11-25 20:15:53 -0700714 str(e.exception))
715
716 def testPackX86Rom(self):
717 """Test that a basic x86 ROM can be created"""
718 data = self._DoReadFile('29_x86-rom.dts')
Simon Glassd6051522017-11-13 18:54:59 -0700719 self.assertEqual(U_BOOT_DATA + chr(0) * 7 + U_BOOT_SPL_DATA +
720 chr(0) * 2, data)
Simon Glass72232452016-11-25 20:15:53 -0700721
722 def testPackX86RomMeNoDesc(self):
723 """Test that an invalid Intel descriptor entry is detected"""
724 TestFunctional._MakeInputFile('descriptor.bin', '')
725 with self.assertRaises(ValueError) as e:
726 self._DoTestFile('31_x86-rom-me.dts')
727 self.assertIn("Node '/binman/intel-descriptor': Cannot find FD "
728 "signature", str(e.exception))
729
730 def testPackX86RomBadDesc(self):
731 """Test that the Intel requires a descriptor entry"""
732 with self.assertRaises(ValueError) as e:
733 self._DoTestFile('30_x86-rom-me-no-desc.dts')
Simon Glasse8561af2018-08-01 15:22:37 -0600734 self.assertIn("Node '/binman/intel-me': No offset set with "
735 "offset-unset: should another entry provide this correct "
736 "offset?", str(e.exception))
Simon Glass72232452016-11-25 20:15:53 -0700737
738 def testPackX86RomMe(self):
739 """Test that an x86 ROM with an ME region can be created"""
740 data = self._DoReadFile('31_x86-rom-me.dts')
741 self.assertEqual(ME_DATA, data[0x1000:0x1000 + len(ME_DATA)])
742
743 def testPackVga(self):
744 """Test that an image with a VGA binary can be created"""
745 data = self._DoReadFile('32_intel-vga.dts')
746 self.assertEqual(VGA_DATA, data[:len(VGA_DATA)])
747
748 def testPackStart16(self):
749 """Test that an image with an x86 start16 region can be created"""
750 data = self._DoReadFile('33_x86-start16.dts')
751 self.assertEqual(X86_START16_DATA, data[:len(X86_START16_DATA)])
752
Simon Glass6ba679c2018-07-06 10:27:17 -0600753 def _RunMicrocodeTest(self, dts_fname, nodtb_data, ucode_second=False):
Simon Glass820af1d2018-07-06 10:27:16 -0600754 """Handle running a test for insertion of microcode
755
756 Args:
757 dts_fname: Name of test .dts file
758 nodtb_data: Data that we expect in the first section
Simon Glass6ba679c2018-07-06 10:27:17 -0600759 ucode_second: True if the microsecond entry is second instead of
760 third
Simon Glass820af1d2018-07-06 10:27:16 -0600761
762 Returns:
763 Tuple:
764 Contents of first region (U-Boot or SPL)
Simon Glasse8561af2018-08-01 15:22:37 -0600765 Offset and size components of microcode pointer, as inserted
Simon Glass820af1d2018-07-06 10:27:16 -0600766 in the above (two 4-byte words)
767 """
Simon Glass3d274232017-11-12 21:52:27 -0700768 data = self._DoReadFile(dts_fname, True)
Simon Glass72232452016-11-25 20:15:53 -0700769
770 # Now check the device tree has no microcode
Simon Glass6ba679c2018-07-06 10:27:17 -0600771 if ucode_second:
772 ucode_content = data[len(nodtb_data):]
773 ucode_pos = len(nodtb_data)
774 dtb_with_ucode = ucode_content[16:]
775 fdt_len = self.GetFdtLen(dtb_with_ucode)
776 else:
777 dtb_with_ucode = data[len(nodtb_data):]
778 fdt_len = self.GetFdtLen(dtb_with_ucode)
779 ucode_content = dtb_with_ucode[fdt_len:]
780 ucode_pos = len(nodtb_data) + fdt_len
Simon Glass72232452016-11-25 20:15:53 -0700781 fname = tools.GetOutputFilename('test.dtb')
782 with open(fname, 'wb') as fd:
Simon Glass820af1d2018-07-06 10:27:16 -0600783 fd.write(dtb_with_ucode)
Simon Glass22c92ca2017-05-27 07:38:29 -0600784 dtb = fdt.FdtScan(fname)
785 ucode = dtb.GetNode('/microcode')
Simon Glass72232452016-11-25 20:15:53 -0700786 self.assertTrue(ucode)
787 for node in ucode.subnodes:
788 self.assertFalse(node.props.get('data'))
789
Simon Glass72232452016-11-25 20:15:53 -0700790 # Check that the microcode appears immediately after the Fdt
791 # This matches the concatenation of the data properties in
Simon Glasse83679d2017-11-12 21:52:26 -0700792 # the /microcode/update@xxx nodes in 34_x86_ucode.dts.
Simon Glass72232452016-11-25 20:15:53 -0700793 ucode_data = struct.pack('>4L', 0x12345678, 0x12345679, 0xabcd0000,
794 0x78235609)
Simon Glass820af1d2018-07-06 10:27:16 -0600795 self.assertEqual(ucode_data, ucode_content[:len(ucode_data)])
Simon Glass72232452016-11-25 20:15:53 -0700796
797 # Check that the microcode pointer was inserted. It should match the
Simon Glasse8561af2018-08-01 15:22:37 -0600798 # expected offset and size
Simon Glass72232452016-11-25 20:15:53 -0700799 pos_and_size = struct.pack('<2L', 0xfffffe00 + ucode_pos,
800 len(ucode_data))
Simon Glass6ba679c2018-07-06 10:27:17 -0600801 u_boot = data[:len(nodtb_data)]
802 return u_boot, pos_and_size
Simon Glass3d274232017-11-12 21:52:27 -0700803
804 def testPackUbootMicrocode(self):
805 """Test that x86 microcode can be handled correctly
806
807 We expect to see the following in the image, in order:
808 u-boot-nodtb.bin with a microcode pointer inserted at the correct
809 place
810 u-boot.dtb with the microcode removed
811 the microcode
812 """
813 first, pos_and_size = self._RunMicrocodeTest('34_x86_ucode.dts',
814 U_BOOT_NODTB_DATA)
Simon Glass72232452016-11-25 20:15:53 -0700815 self.assertEqual('nodtb with microcode' + pos_and_size +
816 ' somewhere in here', first)
817
Simon Glassbac25c82017-05-27 07:38:26 -0600818 def _RunPackUbootSingleMicrocode(self):
Simon Glass72232452016-11-25 20:15:53 -0700819 """Test that x86 microcode can be handled correctly
820
821 We expect to see the following in the image, in order:
822 u-boot-nodtb.bin with a microcode pointer inserted at the correct
823 place
824 u-boot.dtb with the microcode
825 an empty microcode region
826 """
827 # We need the libfdt library to run this test since only that allows
828 # finding the offset of a property. This is required by
829 # Entry_u_boot_dtb_with_ucode.ObtainContents().
Simon Glass72232452016-11-25 20:15:53 -0700830 data = self._DoReadFile('35_x86_single_ucode.dts', True)
831
832 second = data[len(U_BOOT_NODTB_DATA):]
833
834 fdt_len = self.GetFdtLen(second)
835 third = second[fdt_len:]
836 second = second[:fdt_len]
837
Simon Glassbac25c82017-05-27 07:38:26 -0600838 ucode_data = struct.pack('>2L', 0x12345678, 0x12345679)
839 self.assertIn(ucode_data, second)
840 ucode_pos = second.find(ucode_data) + len(U_BOOT_NODTB_DATA)
Simon Glass72232452016-11-25 20:15:53 -0700841
Simon Glassbac25c82017-05-27 07:38:26 -0600842 # Check that the microcode pointer was inserted. It should match the
Simon Glasse8561af2018-08-01 15:22:37 -0600843 # expected offset and size
Simon Glassbac25c82017-05-27 07:38:26 -0600844 pos_and_size = struct.pack('<2L', 0xfffffe00 + ucode_pos,
845 len(ucode_data))
846 first = data[:len(U_BOOT_NODTB_DATA)]
847 self.assertEqual('nodtb with microcode' + pos_and_size +
848 ' somewhere in here', first)
Simon Glass996021e2016-11-25 20:15:54 -0700849
Simon Glassd2dfb5f2016-11-25 20:15:55 -0700850 def testPackUbootSingleMicrocode(self):
851 """Test that x86 microcode can be handled correctly with fdt_normal.
852 """
Simon Glassbac25c82017-05-27 07:38:26 -0600853 self._RunPackUbootSingleMicrocode()
Simon Glassd2dfb5f2016-11-25 20:15:55 -0700854
Simon Glass996021e2016-11-25 20:15:54 -0700855 def testUBootImg(self):
856 """Test that u-boot.img can be put in a file"""
857 data = self._DoReadFile('36_u_boot_img.dts')
858 self.assertEqual(U_BOOT_IMG_DATA, data)
Simon Glassd2dfb5f2016-11-25 20:15:55 -0700859
860 def testNoMicrocode(self):
861 """Test that a missing microcode region is detected"""
862 with self.assertRaises(ValueError) as e:
863 self._DoReadFile('37_x86_no_ucode.dts', True)
864 self.assertIn("Node '/binman/u-boot-dtb-with-ucode': No /microcode "
865 "node found in ", str(e.exception))
866
867 def testMicrocodeWithoutNode(self):
868 """Test that a missing u-boot-dtb-with-ucode node is detected"""
869 with self.assertRaises(ValueError) as e:
870 self._DoReadFile('38_x86_ucode_missing_node.dts', True)
871 self.assertIn("Node '/binman/u-boot-with-ucode-ptr': Cannot find "
872 "microcode region u-boot-dtb-with-ucode", str(e.exception))
873
874 def testMicrocodeWithoutNode2(self):
875 """Test that a missing u-boot-ucode node is detected"""
876 with self.assertRaises(ValueError) as e:
877 self._DoReadFile('39_x86_ucode_missing_node2.dts', True)
878 self.assertIn("Node '/binman/u-boot-with-ucode-ptr': Cannot find "
879 "microcode region u-boot-ucode", str(e.exception))
880
881 def testMicrocodeWithoutPtrInElf(self):
882 """Test that a U-Boot binary without the microcode symbol is detected"""
883 # ELF file without a '_dt_ucode_base_size' symbol
Simon Glassd2dfb5f2016-11-25 20:15:55 -0700884 try:
885 with open(self.TestFile('u_boot_no_ucode_ptr')) as fd:
886 TestFunctional._MakeInputFile('u-boot', fd.read())
887
888 with self.assertRaises(ValueError) as e:
Simon Glassbac25c82017-05-27 07:38:26 -0600889 self._RunPackUbootSingleMicrocode()
Simon Glassd2dfb5f2016-11-25 20:15:55 -0700890 self.assertIn("Node '/binman/u-boot-with-ucode-ptr': Cannot locate "
891 "_dt_ucode_base_size symbol in u-boot", str(e.exception))
892
893 finally:
894 # Put the original file back
895 with open(self.TestFile('u_boot_ucode_ptr')) as fd:
896 TestFunctional._MakeInputFile('u-boot', fd.read())
897
898 def testMicrocodeNotInImage(self):
899 """Test that microcode must be placed within the image"""
900 with self.assertRaises(ValueError) as e:
901 self._DoReadFile('40_x86_ucode_not_in_image.dts', True)
902 self.assertIn("Node '/binman/u-boot-with-ucode-ptr': Microcode "
903 "pointer _dt_ucode_base_size at fffffe14 is outside the "
Simon Glassad5a7712018-06-01 09:38:14 -0600904 "section ranging from 00000000 to 0000002e", str(e.exception))
Simon Glassd2dfb5f2016-11-25 20:15:55 -0700905
906 def testWithoutMicrocode(self):
907 """Test that we can cope with an image without microcode (e.g. qemu)"""
908 with open(self.TestFile('u_boot_no_ucode_ptr')) as fd:
909 TestFunctional._MakeInputFile('u-boot', fd.read())
Simon Glassa87014e2018-07-06 10:27:42 -0600910 data, dtb, _, _ = self._DoReadFileDtb('44_x86_optional_ucode.dts', True)
Simon Glassd2dfb5f2016-11-25 20:15:55 -0700911
912 # Now check the device tree has no microcode
913 self.assertEqual(U_BOOT_NODTB_DATA, data[:len(U_BOOT_NODTB_DATA)])
914 second = data[len(U_BOOT_NODTB_DATA):]
915
916 fdt_len = self.GetFdtLen(second)
917 self.assertEqual(dtb, second[:fdt_len])
918
919 used_len = len(U_BOOT_NODTB_DATA) + fdt_len
920 third = data[used_len:]
921 self.assertEqual(chr(0) * (0x200 - used_len), third)
922
923 def testUnknownPosSize(self):
924 """Test that microcode must be placed within the image"""
925 with self.assertRaises(ValueError) as e:
926 self._DoReadFile('41_unknown_pos_size.dts', True)
Simon Glasse8561af2018-08-01 15:22:37 -0600927 self.assertIn("Section '/binman': Unable to set offset/size for unknown "
Simon Glassd2dfb5f2016-11-25 20:15:55 -0700928 "entry 'invalid-entry'", str(e.exception))
Simon Glassb4176d42016-11-25 20:15:56 -0700929
930 def testPackFsp(self):
931 """Test that an image with a FSP binary can be created"""
932 data = self._DoReadFile('42_intel-fsp.dts')
933 self.assertEqual(FSP_DATA, data[:len(FSP_DATA)])
934
935 def testPackCmc(self):
Bin Mengd7bcdf52017-08-15 22:41:54 -0700936 """Test that an image with a CMC binary can be created"""
Simon Glassb4176d42016-11-25 20:15:56 -0700937 data = self._DoReadFile('43_intel-cmc.dts')
938 self.assertEqual(CMC_DATA, data[:len(CMC_DATA)])
Bin Mengd7bcdf52017-08-15 22:41:54 -0700939
940 def testPackVbt(self):
941 """Test that an image with a VBT binary can be created"""
942 data = self._DoReadFile('46_intel-vbt.dts')
943 self.assertEqual(VBT_DATA, data[:len(VBT_DATA)])
Simon Glassac599912017-11-12 21:52:22 -0700944
Simon Glass7f94e832017-11-12 21:52:25 -0700945 def testSplBssPad(self):
946 """Test that we can pad SPL's BSS with zeros"""
Simon Glass3d274232017-11-12 21:52:27 -0700947 # ELF file with a '__bss_size' symbol
948 with open(self.TestFile('bss_data')) as fd:
949 TestFunctional._MakeInputFile('spl/u-boot-spl', fd.read())
Simon Glass7f94e832017-11-12 21:52:25 -0700950 data = self._DoReadFile('47_spl_bss_pad.dts')
951 self.assertEqual(U_BOOT_SPL_DATA + (chr(0) * 10) + U_BOOT_DATA, data)
952
Simon Glass24ad3652017-11-13 18:54:54 -0700953 with open(self.TestFile('u_boot_ucode_ptr')) as fd:
954 TestFunctional._MakeInputFile('spl/u-boot-spl', fd.read())
955 with self.assertRaises(ValueError) as e:
956 data = self._DoReadFile('47_spl_bss_pad.dts')
957 self.assertIn('Expected __bss_size symbol in spl/u-boot-spl',
958 str(e.exception))
959
Simon Glasse83679d2017-11-12 21:52:26 -0700960 def testPackStart16Spl(self):
961 """Test that an image with an x86 start16 region can be created"""
962 data = self._DoReadFile('48_x86-start16-spl.dts')
963 self.assertEqual(X86_START16_SPL_DATA, data[:len(X86_START16_SPL_DATA)])
964
Simon Glass6ba679c2018-07-06 10:27:17 -0600965 def _PackUbootSplMicrocode(self, dts, ucode_second=False):
966 """Helper function for microcode tests
Simon Glass3d274232017-11-12 21:52:27 -0700967
968 We expect to see the following in the image, in order:
969 u-boot-spl-nodtb.bin with a microcode pointer inserted at the
970 correct place
971 u-boot.dtb with the microcode removed
972 the microcode
Simon Glass6ba679c2018-07-06 10:27:17 -0600973
974 Args:
975 dts: Device tree file to use for test
976 ucode_second: True if the microsecond entry is second instead of
977 third
Simon Glass3d274232017-11-12 21:52:27 -0700978 """
979 # ELF file with a '_dt_ucode_base_size' symbol
980 with open(self.TestFile('u_boot_ucode_ptr')) as fd:
981 TestFunctional._MakeInputFile('spl/u-boot-spl', fd.read())
Simon Glass6ba679c2018-07-06 10:27:17 -0600982 first, pos_and_size = self._RunMicrocodeTest(dts, U_BOOT_SPL_NODTB_DATA,
983 ucode_second=ucode_second)
Simon Glass3d274232017-11-12 21:52:27 -0700984 self.assertEqual('splnodtb with microc' + pos_and_size +
985 'ter somewhere in here', first)
986
Simon Glass6ba679c2018-07-06 10:27:17 -0600987 def testPackUbootSplMicrocode(self):
988 """Test that x86 microcode can be handled correctly in SPL"""
989 self._PackUbootSplMicrocode('49_x86_ucode_spl.dts')
990
991 def testPackUbootSplMicrocodeReorder(self):
992 """Test that order doesn't matter for microcode entries
993
994 This is the same as testPackUbootSplMicrocode but when we process the
995 u-boot-ucode entry we have not yet seen the u-boot-dtb-with-ucode
996 entry, so we reply on binman to try later.
997 """
998 self._PackUbootSplMicrocode('58_x86_ucode_spl_needs_retry.dts',
999 ucode_second=True)
1000
Simon Glassa409c932017-11-12 21:52:28 -07001001 def testPackMrc(self):
1002 """Test that an image with an MRC binary can be created"""
1003 data = self._DoReadFile('50_intel_mrc.dts')
1004 self.assertEqual(MRC_DATA, data[:len(MRC_DATA)])
1005
Simon Glass9aa6a6f2017-11-13 18:54:55 -07001006 def testSplDtb(self):
1007 """Test that an image with spl/u-boot-spl.dtb can be created"""
1008 data = self._DoReadFile('51_u_boot_spl_dtb.dts')
1009 self.assertEqual(U_BOOT_SPL_DTB_DATA, data[:len(U_BOOT_SPL_DTB_DATA)])
1010
Simon Glass0a6da312017-11-13 18:54:56 -07001011 def testSplNoDtb(self):
1012 """Test that an image with spl/u-boot-spl-nodtb.bin can be created"""
1013 data = self._DoReadFile('52_u_boot_spl_nodtb.dts')
1014 self.assertEqual(U_BOOT_SPL_NODTB_DATA, data[:len(U_BOOT_SPL_NODTB_DATA)])
1015
Simon Glass4ca8e042017-11-13 18:55:01 -07001016 def testSymbols(self):
1017 """Test binman can assign symbols embedded in U-Boot"""
1018 elf_fname = self.TestFile('u_boot_binman_syms')
1019 syms = elf.GetSymbols(elf_fname, ['binman', 'image'])
1020 addr = elf.GetSymbolAddress(elf_fname, '__image_copy_start')
Simon Glasse8561af2018-08-01 15:22:37 -06001021 self.assertEqual(syms['_binman_u_boot_spl_prop_offset'].address, addr)
Simon Glass4ca8e042017-11-13 18:55:01 -07001022
1023 with open(self.TestFile('u_boot_binman_syms')) as fd:
1024 TestFunctional._MakeInputFile('spl/u-boot-spl', fd.read())
1025 data = self._DoReadFile('53_symbols.dts')
1026 sym_values = struct.pack('<LQL', 0x24 + 0, 0x24 + 24, 0x24 + 20)
1027 expected = (sym_values + U_BOOT_SPL_DATA[16:] + chr(0xff) +
1028 U_BOOT_DATA +
1029 sym_values + U_BOOT_SPL_DATA[16:])
1030 self.assertEqual(expected, data)
1031
Simon Glasse76a3e62018-06-01 09:38:11 -06001032 def testPackUnitAddress(self):
1033 """Test that we support multiple binaries with the same name"""
1034 data = self._DoReadFile('54_unit_address.dts')
1035 self.assertEqual(U_BOOT_DATA + U_BOOT_DATA, data)
1036
Simon Glassa91e1152018-06-01 09:38:16 -06001037 def testSections(self):
1038 """Basic test of sections"""
1039 data = self._DoReadFile('55_sections.dts')
Simon Glass3a9a2b82018-07-17 13:25:28 -06001040 expected = (U_BOOT_DATA + '!' * 12 + U_BOOT_DATA + 'a' * 12 +
1041 U_BOOT_DATA + '&' * 4)
Simon Glassa91e1152018-06-01 09:38:16 -06001042 self.assertEqual(expected, data)
Simon Glassac599912017-11-12 21:52:22 -07001043
Simon Glass30732662018-06-01 09:38:20 -06001044 def testMap(self):
1045 """Tests outputting a map of the images"""
Simon Glassa87014e2018-07-06 10:27:42 -06001046 _, _, map_data, _ = self._DoReadFileDtb('55_sections.dts', map=True)
Simon Glasse8561af2018-08-01 15:22:37 -06001047 self.assertEqual(''' Offset Size Name
Simon Glass3a9a2b82018-07-17 13:25:28 -0600104800000000 00000028 main-section
1049 00000000 00000010 section@0
1050 00000000 00000004 u-boot
1051 00000010 00000010 section@1
1052 00000000 00000004 u-boot
1053 00000020 00000004 section@2
1054 00000000 00000004 u-boot
Simon Glass30732662018-06-01 09:38:20 -06001055''', map_data)
1056
Simon Glass3b78d532018-06-01 09:38:21 -06001057 def testNamePrefix(self):
1058 """Tests that name prefixes are used"""
Simon Glassa87014e2018-07-06 10:27:42 -06001059 _, _, map_data, _ = self._DoReadFileDtb('56_name_prefix.dts', map=True)
Simon Glasse8561af2018-08-01 15:22:37 -06001060 self.assertEqual(''' Offset Size Name
Simon Glass3a9a2b82018-07-17 13:25:28 -0600106100000000 00000028 main-section
1062 00000000 00000010 section@0
1063 00000000 00000004 ro-u-boot
1064 00000010 00000010 section@1
1065 00000000 00000004 rw-u-boot
Simon Glass3b78d532018-06-01 09:38:21 -06001066''', map_data)
1067
Simon Glass6ba679c2018-07-06 10:27:17 -06001068 def testUnknownContents(self):
1069 """Test that obtaining the contents works as expected"""
1070 with self.assertRaises(ValueError) as e:
1071 self._DoReadFile('57_unknown_contents.dts', True)
1072 self.assertIn("Section '/binman': Internal error: Could not complete "
1073 "processing of contents: remaining [<_testing.Entry__testing ",
1074 str(e.exception))
1075
Simon Glass2e1169f2018-07-06 10:27:19 -06001076 def testBadChangeSize(self):
1077 """Test that trying to change the size of an entry fails"""
1078 with self.assertRaises(ValueError) as e:
1079 self._DoReadFile('59_change_size.dts', True)
1080 self.assertIn("Node '/binman/_testing': Cannot update entry size from "
1081 '2 to 1', str(e.exception))
1082
Simon Glassa87014e2018-07-06 10:27:42 -06001083 def testUpdateFdt(self):
Simon Glasse8561af2018-08-01 15:22:37 -06001084 """Test that we can update the device tree with offset/size info"""
Simon Glassa87014e2018-07-06 10:27:42 -06001085 _, _, _, out_dtb_fname = self._DoReadFileDtb('60_fdt_update.dts',
1086 update_dtb=True)
Simon Glass9dcc8612018-08-01 15:22:42 -06001087 props = self._GetPropTree(out_dtb_fname, ['offset', 'size',
1088 'image-pos'])
Simon Glassa87014e2018-07-06 10:27:42 -06001089 with open('/tmp/x.dtb', 'wb') as outf:
1090 with open(out_dtb_fname) as inf:
1091 outf.write(inf.read())
1092 self.assertEqual({
Simon Glass9dcc8612018-08-01 15:22:42 -06001093 'image-pos': 0,
Simon Glass3a9a2b82018-07-17 13:25:28 -06001094 'offset': 0,
Simon Glasse8561af2018-08-01 15:22:37 -06001095 '_testing:offset': 32,
Simon Glassa87014e2018-07-06 10:27:42 -06001096 '_testing:size': 1,
Simon Glass9dcc8612018-08-01 15:22:42 -06001097 '_testing:image-pos': 32,
Simon Glasse8561af2018-08-01 15:22:37 -06001098 'section@0/u-boot:offset': 0,
Simon Glassa87014e2018-07-06 10:27:42 -06001099 'section@0/u-boot:size': len(U_BOOT_DATA),
Simon Glass9dcc8612018-08-01 15:22:42 -06001100 'section@0/u-boot:image-pos': 0,
Simon Glasse8561af2018-08-01 15:22:37 -06001101 'section@0:offset': 0,
Simon Glassa87014e2018-07-06 10:27:42 -06001102 'section@0:size': 16,
Simon Glass9dcc8612018-08-01 15:22:42 -06001103 'section@0:image-pos': 0,
Simon Glassa87014e2018-07-06 10:27:42 -06001104
Simon Glasse8561af2018-08-01 15:22:37 -06001105 'section@1/u-boot:offset': 0,
Simon Glassa87014e2018-07-06 10:27:42 -06001106 'section@1/u-boot:size': len(U_BOOT_DATA),
Simon Glass9dcc8612018-08-01 15:22:42 -06001107 'section@1/u-boot:image-pos': 16,
Simon Glasse8561af2018-08-01 15:22:37 -06001108 'section@1:offset': 16,
Simon Glassa87014e2018-07-06 10:27:42 -06001109 'section@1:size': 16,
Simon Glass9dcc8612018-08-01 15:22:42 -06001110 'section@1:image-pos': 16,
Simon Glassa87014e2018-07-06 10:27:42 -06001111 'size': 40
1112 }, props)
1113
1114 def testUpdateFdtBad(self):
1115 """Test that we detect when ProcessFdt never completes"""
1116 with self.assertRaises(ValueError) as e:
1117 self._DoReadFileDtb('61_fdt_update_bad.dts', update_dtb=True)
1118 self.assertIn('Could not complete processing of Fdt: remaining '
1119 '[<_testing.Entry__testing', str(e.exception))
Simon Glass2e1169f2018-07-06 10:27:19 -06001120
Simon Glass91710b32018-07-17 13:25:32 -06001121 def testEntryArgs(self):
1122 """Test passing arguments to entries from the command line"""
1123 entry_args = {
1124 'test-str-arg': 'test1',
1125 'test-int-arg': '456',
1126 }
1127 self._DoReadFileDtb('62_entry_args.dts', entry_args=entry_args)
1128 self.assertIn('image', control.images)
1129 entry = control.images['image'].GetEntries()['_testing']
1130 self.assertEqual('test0', entry.test_str_fdt)
1131 self.assertEqual('test1', entry.test_str_arg)
1132 self.assertEqual(123, entry.test_int_fdt)
1133 self.assertEqual(456, entry.test_int_arg)
1134
1135 def testEntryArgsMissing(self):
1136 """Test missing arguments and properties"""
1137 entry_args = {
1138 'test-int-arg': '456',
1139 }
1140 self._DoReadFileDtb('63_entry_args_missing.dts', entry_args=entry_args)
1141 entry = control.images['image'].GetEntries()['_testing']
1142 self.assertEqual('test0', entry.test_str_fdt)
1143 self.assertEqual(None, entry.test_str_arg)
1144 self.assertEqual(None, entry.test_int_fdt)
1145 self.assertEqual(456, entry.test_int_arg)
1146
1147 def testEntryArgsRequired(self):
1148 """Test missing arguments and properties"""
1149 entry_args = {
1150 'test-int-arg': '456',
1151 }
1152 with self.assertRaises(ValueError) as e:
1153 self._DoReadFileDtb('64_entry_args_required.dts')
1154 self.assertIn("Node '/binman/_testing': Missing required "
1155 'properties/entry args: test-str-arg, test-int-fdt, test-int-arg',
1156 str(e.exception))
1157
1158 def testEntryArgsInvalidFormat(self):
1159 """Test that an invalid entry-argument format is detected"""
1160 args = ['-d', self.TestFile('64_entry_args_required.dts'), '-ano-value']
1161 with self.assertRaises(ValueError) as e:
1162 self._DoBinman(*args)
1163 self.assertIn("Invalid entry arguemnt 'no-value'", str(e.exception))
1164
1165 def testEntryArgsInvalidInteger(self):
1166 """Test that an invalid entry-argument integer is detected"""
1167 entry_args = {
1168 'test-int-arg': 'abc',
1169 }
1170 with self.assertRaises(ValueError) as e:
1171 self._DoReadFileDtb('62_entry_args.dts', entry_args=entry_args)
1172 self.assertIn("Node '/binman/_testing': Cannot convert entry arg "
1173 "'test-int-arg' (value 'abc') to integer",
1174 str(e.exception))
1175
1176 def testEntryArgsInvalidDatatype(self):
1177 """Test that an invalid entry-argument datatype is detected
1178
1179 This test could be written in entry_test.py except that it needs
1180 access to control.entry_args, which seems more than that module should
1181 be able to see.
1182 """
1183 entry_args = {
1184 'test-bad-datatype-arg': '12',
1185 }
1186 with self.assertRaises(ValueError) as e:
1187 self._DoReadFileDtb('65_entry_args_unknown_datatype.dts',
1188 entry_args=entry_args)
1189 self.assertIn('GetArg() internal error: Unknown data type ',
1190 str(e.exception))
1191
Simon Glass2ca52032018-07-17 13:25:33 -06001192 def testText(self):
1193 """Test for a text entry type"""
1194 entry_args = {
1195 'test-id': TEXT_DATA,
1196 'test-id2': TEXT_DATA2,
1197 'test-id3': TEXT_DATA3,
1198 }
1199 data, _, _, _ = self._DoReadFileDtb('66_text.dts',
1200 entry_args=entry_args)
1201 expected = (TEXT_DATA + chr(0) * (8 - len(TEXT_DATA)) + TEXT_DATA2 +
1202 TEXT_DATA3 + 'some text')
1203 self.assertEqual(expected, data)
1204
Simon Glass969616c2018-07-17 13:25:36 -06001205 def testEntryDocs(self):
1206 """Test for creation of entry documentation"""
1207 with test_util.capture_sys_output() as (stdout, stderr):
1208 control.WriteEntryDocs(binman.GetEntryModules())
1209 self.assertTrue(len(stdout.getvalue()) > 0)
1210
1211 def testEntryDocsMissing(self):
1212 """Test handling of missing entry documentation"""
1213 with self.assertRaises(ValueError) as e:
1214 with test_util.capture_sys_output() as (stdout, stderr):
1215 control.WriteEntryDocs(binman.GetEntryModules(), 'u_boot')
1216 self.assertIn('Documentation is missing for modules: u_boot',
1217 str(e.exception))
1218
Simon Glass704784b2018-07-17 13:25:38 -06001219 def testFmap(self):
1220 """Basic test of generation of a flashrom fmap"""
1221 data = self._DoReadFile('67_fmap.dts')
1222 fhdr, fentries = fmap_util.DecodeFmap(data[32:])
1223 expected = U_BOOT_DATA + '!' * 12 + U_BOOT_DATA + 'a' * 12
1224 self.assertEqual(expected, data[:32])
1225 self.assertEqual('__FMAP__', fhdr.signature)
1226 self.assertEqual(1, fhdr.ver_major)
1227 self.assertEqual(0, fhdr.ver_minor)
1228 self.assertEqual(0, fhdr.base)
1229 self.assertEqual(16 + 16 +
1230 fmap_util.FMAP_HEADER_LEN +
1231 fmap_util.FMAP_AREA_LEN * 3, fhdr.image_size)
1232 self.assertEqual('FMAP', fhdr.name)
1233 self.assertEqual(3, fhdr.nareas)
1234 for fentry in fentries:
1235 self.assertEqual(0, fentry.flags)
1236
1237 self.assertEqual(0, fentries[0].offset)
1238 self.assertEqual(4, fentries[0].size)
1239 self.assertEqual('RO_U_BOOT', fentries[0].name)
1240
1241 self.assertEqual(16, fentries[1].offset)
1242 self.assertEqual(4, fentries[1].size)
1243 self.assertEqual('RW_U_BOOT', fentries[1].name)
1244
1245 self.assertEqual(32, fentries[2].offset)
1246 self.assertEqual(fmap_util.FMAP_HEADER_LEN +
1247 fmap_util.FMAP_AREA_LEN * 3, fentries[2].size)
1248 self.assertEqual('FMAP', fentries[2].name)
1249
Simon Glassdb168d42018-07-17 13:25:39 -06001250 def testBlobNamedByArg(self):
1251 """Test we can add a blob with the filename coming from an entry arg"""
1252 entry_args = {
1253 'cros-ec-rw-path': 'ecrw.bin',
1254 }
1255 data, _, _, _ = self._DoReadFileDtb('68_blob_named_by_arg.dts',
1256 entry_args=entry_args)
1257
Simon Glass53f53992018-07-17 13:25:40 -06001258 def testFill(self):
1259 """Test for an fill entry type"""
1260 data = self._DoReadFile('69_fill.dts')
1261 expected = 8 * chr(0xff) + 8 * chr(0)
1262 self.assertEqual(expected, data)
1263
1264 def testFillNoSize(self):
1265 """Test for an fill entry type with no size"""
1266 with self.assertRaises(ValueError) as e:
1267 self._DoReadFile('70_fill_no_size.dts')
1268 self.assertIn("'fill' entry must have a size property",
1269 str(e.exception))
1270
Simon Glassc1ae83c2018-07-17 13:25:44 -06001271 def _HandleGbbCommand(self, pipe_list):
1272 """Fake calls to the futility utility"""
1273 if pipe_list[0][0] == 'futility':
1274 fname = pipe_list[0][-1]
1275 # Append our GBB data to the file, which will happen every time the
1276 # futility command is called.
1277 with open(fname, 'a') as fd:
1278 fd.write(GBB_DATA)
1279 return command.CommandResult()
1280
1281 def testGbb(self):
1282 """Test for the Chromium OS Google Binary Block"""
1283 command.test_result = self._HandleGbbCommand
1284 entry_args = {
1285 'keydir': 'devkeys',
1286 'bmpblk': 'bmpblk.bin',
1287 }
1288 data, _, _, _ = self._DoReadFileDtb('71_gbb.dts', entry_args=entry_args)
1289
1290 # Since futility
1291 expected = GBB_DATA + GBB_DATA + 8 * chr(0) + (0x2180 - 16) * chr(0)
1292 self.assertEqual(expected, data)
1293
1294 def testGbbTooSmall(self):
1295 """Test for the Chromium OS Google Binary Block being large enough"""
1296 with self.assertRaises(ValueError) as e:
1297 self._DoReadFileDtb('72_gbb_too_small.dts')
1298 self.assertIn("Node '/binman/gbb': GBB is too small",
1299 str(e.exception))
1300
1301 def testGbbNoSize(self):
1302 """Test for the Chromium OS Google Binary Block having a size"""
1303 with self.assertRaises(ValueError) as e:
1304 self._DoReadFileDtb('73_gbb_no_size.dts')
1305 self.assertIn("Node '/binman/gbb': GBB must have a fixed size",
1306 str(e.exception))
1307
Simon Glass5c350162018-07-17 13:25:47 -06001308 def _HandleVblockCommand(self, pipe_list):
1309 """Fake calls to the futility utility"""
1310 if pipe_list[0][0] == 'futility':
1311 fname = pipe_list[0][3]
1312 with open(fname, 'w') as fd:
1313 fd.write(VBLOCK_DATA)
1314 return command.CommandResult()
1315
1316 def testVblock(self):
1317 """Test for the Chromium OS Verified Boot Block"""
1318 command.test_result = self._HandleVblockCommand
1319 entry_args = {
1320 'keydir': 'devkeys',
1321 }
1322 data, _, _, _ = self._DoReadFileDtb('74_vblock.dts',
1323 entry_args=entry_args)
1324 expected = U_BOOT_DATA + VBLOCK_DATA + U_BOOT_DTB_DATA
1325 self.assertEqual(expected, data)
1326
1327 def testVblockNoContent(self):
1328 """Test we detect a vblock which has no content to sign"""
1329 with self.assertRaises(ValueError) as e:
1330 self._DoReadFile('75_vblock_no_content.dts')
1331 self.assertIn("Node '/binman/vblock': Vblock must have a 'content' "
1332 'property', str(e.exception))
1333
1334 def testVblockBadPhandle(self):
1335 """Test that we detect a vblock with an invalid phandle in contents"""
1336 with self.assertRaises(ValueError) as e:
1337 self._DoReadFile('76_vblock_bad_phandle.dts')
1338 self.assertIn("Node '/binman/vblock': Cannot find node for phandle "
1339 '1000', str(e.exception))
1340
1341 def testVblockBadEntry(self):
1342 """Test that we detect an entry that points to a non-entry"""
1343 with self.assertRaises(ValueError) as e:
1344 self._DoReadFile('77_vblock_bad_entry.dts')
1345 self.assertIn("Node '/binman/vblock': Cannot find entry for node "
1346 "'other'", str(e.exception))
1347
Simon Glass91710b32018-07-17 13:25:32 -06001348
Simon Glassac599912017-11-12 21:52:22 -07001349if __name__ == "__main__":
1350 unittest.main()