Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 2 | # Copyright (c) 2016 Google, Inc |
| 3 | # Written by Simon Glass <sjg@chromium.org> |
| 4 | # |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 5 | # To run a single test, change to this directory, and: |
| 6 | # |
| 7 | # python -m unittest func_test.TestFunctional.testHelp |
| 8 | |
| 9 | from optparse import OptionParser |
| 10 | import os |
| 11 | import shutil |
| 12 | import struct |
| 13 | import sys |
| 14 | import tempfile |
| 15 | import unittest |
| 16 | |
| 17 | import binman |
| 18 | import cmdline |
| 19 | import command |
| 20 | import control |
Simon Glass | 4ca8e04 | 2017-11-13 18:55:01 -0700 | [diff] [blame] | 21 | import elf |
Simon Glass | a944093 | 2017-05-27 07:38:30 -0600 | [diff] [blame] | 22 | import fdt |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 23 | import fdt_util |
Simon Glass | 704784b | 2018-07-17 13:25:38 -0600 | [diff] [blame] | 24 | import fmap_util |
Simon Glass | 969616c | 2018-07-17 13:25:36 -0600 | [diff] [blame] | 25 | import test_util |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 26 | import tools |
| 27 | import tout |
| 28 | |
| 29 | # Contents of test files, corresponding to different entry types |
Simon Glass | 3d27423 | 2017-11-12 21:52:27 -0700 | [diff] [blame] | 30 | U_BOOT_DATA = '1234' |
| 31 | U_BOOT_IMG_DATA = 'img' |
Simon Glass | d605152 | 2017-11-13 18:54:59 -0700 | [diff] [blame] | 32 | U_BOOT_SPL_DATA = '56780123456789abcde' |
Simon Glass | 3d27423 | 2017-11-12 21:52:27 -0700 | [diff] [blame] | 33 | BLOB_DATA = '89' |
| 34 | ME_DATA = '0abcd' |
| 35 | VGA_DATA = 'vga' |
| 36 | U_BOOT_DTB_DATA = 'udtb' |
Simon Glass | 9aa6a6f | 2017-11-13 18:54:55 -0700 | [diff] [blame] | 37 | U_BOOT_SPL_DTB_DATA = 'spldtb' |
Simon Glass | 3d27423 | 2017-11-12 21:52:27 -0700 | [diff] [blame] | 38 | X86_START16_DATA = 'start16' |
| 39 | X86_START16_SPL_DATA = 'start16spl' |
| 40 | U_BOOT_NODTB_DATA = 'nodtb with microcode pointer somewhere in here' |
| 41 | U_BOOT_SPL_NODTB_DATA = 'splnodtb with microcode pointer somewhere in here' |
| 42 | FSP_DATA = 'fsp' |
| 43 | CMC_DATA = 'cmc' |
| 44 | VBT_DATA = 'vbt' |
Simon Glass | a409c93 | 2017-11-12 21:52:28 -0700 | [diff] [blame] | 45 | MRC_DATA = 'mrc' |
Simon Glass | 2ca5203 | 2018-07-17 13:25:33 -0600 | [diff] [blame] | 46 | TEXT_DATA = 'text' |
| 47 | TEXT_DATA2 = 'text2' |
| 48 | TEXT_DATA3 = 'text3' |
Simon Glass | db168d4 | 2018-07-17 13:25:39 -0600 | [diff] [blame] | 49 | CROS_EC_RW_DATA = 'ecrw' |
Simon Glass | c1ae83c | 2018-07-17 13:25:44 -0600 | [diff] [blame] | 50 | GBB_DATA = 'gbbd' |
| 51 | BMPBLK_DATA = 'bmp' |
Simon Glass | 5c35016 | 2018-07-17 13:25:47 -0600 | [diff] [blame^] | 52 | VBLOCK_DATA = 'vblk' |
Simon Glass | db168d4 | 2018-07-17 13:25:39 -0600 | [diff] [blame] | 53 | |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 54 | |
| 55 | class 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 Glass | b339326 | 2017-11-12 21:52:20 -0700 | [diff] [blame] | 71 | global entry |
| 72 | import entry |
| 73 | |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 74 | # 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 Glass | 7223245 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 86 | TestFunctional._MakeInputFile('me.bin', ME_DATA) |
| 87 | TestFunctional._MakeInputFile('vga.bin', VGA_DATA) |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 88 | TestFunctional._MakeInputFile('u-boot.dtb', U_BOOT_DTB_DATA) |
Simon Glass | 9aa6a6f | 2017-11-13 18:54:55 -0700 | [diff] [blame] | 89 | TestFunctional._MakeInputFile('spl/u-boot-spl.dtb', U_BOOT_SPL_DTB_DATA) |
Simon Glass | 7223245 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 90 | TestFunctional._MakeInputFile('u-boot-x86-16bit.bin', X86_START16_DATA) |
Simon Glass | e83679d | 2017-11-12 21:52:26 -0700 | [diff] [blame] | 91 | TestFunctional._MakeInputFile('spl/u-boot-x86-16bit-spl.bin', |
| 92 | X86_START16_SPL_DATA) |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 93 | TestFunctional._MakeInputFile('u-boot-nodtb.bin', U_BOOT_NODTB_DATA) |
Simon Glass | 3d27423 | 2017-11-12 21:52:27 -0700 | [diff] [blame] | 94 | TestFunctional._MakeInputFile('spl/u-boot-spl-nodtb.bin', |
| 95 | U_BOOT_SPL_NODTB_DATA) |
Simon Glass | b4176d4 | 2016-11-25 20:15:56 -0700 | [diff] [blame] | 96 | TestFunctional._MakeInputFile('fsp.bin', FSP_DATA) |
| 97 | TestFunctional._MakeInputFile('cmc.bin', CMC_DATA) |
Bin Meng | d7bcdf5 | 2017-08-15 22:41:54 -0700 | [diff] [blame] | 98 | TestFunctional._MakeInputFile('vbt.bin', VBT_DATA) |
Simon Glass | a409c93 | 2017-11-12 21:52:28 -0700 | [diff] [blame] | 99 | TestFunctional._MakeInputFile('mrc.bin', MRC_DATA) |
Simon Glass | db168d4 | 2018-07-17 13:25:39 -0600 | [diff] [blame] | 100 | TestFunctional._MakeInputFile('ecrw.bin', CROS_EC_RW_DATA) |
Simon Glass | c1ae83c | 2018-07-17 13:25:44 -0600 | [diff] [blame] | 101 | TestFunctional._MakeInputDir('devkeys') |
| 102 | TestFunctional._MakeInputFile('bmpblk.bin', BMPBLK_DATA) |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 103 | self._output_setup = False |
| 104 | |
Simon Glass | 7223245 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 105 | # 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 Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 113 | @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 Glass | 075a45c | 2017-11-13 18:55:00 -0700 | [diff] [blame] | 151 | args = list(args) |
| 152 | if '-D' in sys.argv: |
| 153 | args = args + ['-D'] |
| 154 | (options, args) = cmdline.ParseArgs(args) |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 155 | 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 Glass | 91710b3 | 2018-07-17 13:25:32 -0600 | [diff] [blame] | 162 | def _DoTestFile(self, fname, debug=False, map=False, update_dtb=False, |
| 163 | entry_args=None): |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 164 | """Run binman with a given test file |
| 165 | |
| 166 | Args: |
Simon Glass | 1e32400 | 2018-06-01 09:38:19 -0600 | [diff] [blame] | 167 | fname: Device-tree source filename to use (e.g. 05_simple.dts) |
| 168 | debug: True to enable debugging output |
Simon Glass | 3073266 | 2018-06-01 09:38:20 -0600 | [diff] [blame] | 169 | map: True to output map files for the images |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 170 | update_dtb: Update the offset and size of each entry in the device |
Simon Glass | a87014e | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 171 | tree before packing it into the image |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 172 | """ |
Simon Glass | 075a45c | 2017-11-13 18:55:00 -0700 | [diff] [blame] | 173 | args = ['-p', '-I', self._indir, '-d', self.TestFile(fname)] |
| 174 | if debug: |
| 175 | args.append('-D') |
Simon Glass | 3073266 | 2018-06-01 09:38:20 -0600 | [diff] [blame] | 176 | if map: |
| 177 | args.append('-m') |
Simon Glass | a87014e | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 178 | if update_dtb: |
| 179 | args.append('-up') |
Simon Glass | 91710b3 | 2018-07-17 13:25:32 -0600 | [diff] [blame] | 180 | if entry_args: |
| 181 | for arg, value in entry_args.iteritems(): |
| 182 | args.append('-a%s=%s' % (arg, value)) |
Simon Glass | 075a45c | 2017-11-13 18:55:00 -0700 | [diff] [blame] | 183 | return self._DoBinman(*args) |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 184 | |
| 185 | def _SetupDtb(self, fname, outfile='u-boot.dtb'): |
Simon Glass | 7223245 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 186 | """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 Glass | 1e32400 | 2018-06-01 09:38:19 -0600 | [diff] [blame] | 193 | outfile: Output filename for compiled device-tree binary |
Simon Glass | 7223245 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 194 | |
| 195 | Returns: |
Simon Glass | 1e32400 | 2018-06-01 09:38:19 -0600 | [diff] [blame] | 196 | Contents of device-tree binary |
Simon Glass | 7223245 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 197 | """ |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 198 | 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 Glass | 7223245 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 205 | return data |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 206 | |
Simon Glass | a87014e | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 207 | def _DoReadFileDtb(self, fname, use_real_dtb=False, map=False, |
Simon Glass | 91710b3 | 2018-07-17 13:25:32 -0600 | [diff] [blame] | 208 | update_dtb=False, entry_args=None): |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 209 | """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 Glass | 1e32400 | 2018-06-01 09:38:19 -0600 | [diff] [blame] | 218 | fname: Device-tree source filename to use (e.g. 05_simple.dts) |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 219 | 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 Glass | 3073266 | 2018-06-01 09:38:20 -0600 | [diff] [blame] | 223 | map: True to output map files for the images |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 224 | update_dtb: Update the offset and size of each entry in the device |
Simon Glass | a87014e | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 225 | tree before packing it into the image |
Simon Glass | 7223245 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 226 | |
| 227 | Returns: |
| 228 | Tuple: |
| 229 | Resulting image contents |
| 230 | Device tree contents |
Simon Glass | 3073266 | 2018-06-01 09:38:20 -0600 | [diff] [blame] | 231 | Map data showing contents of image (or None if none) |
Simon Glass | def77b5 | 2018-07-17 13:25:27 -0600 | [diff] [blame] | 232 | Output device tree binary filename ('u-boot.dtb' path) |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 233 | """ |
Simon Glass | 7223245 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 234 | dtb_data = None |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 235 | # Use the compiled test file as the u-boot-dtb input |
| 236 | if use_real_dtb: |
Simon Glass | 7223245 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 237 | dtb_data = self._SetupDtb(fname) |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 238 | |
| 239 | try: |
Simon Glass | 91710b3 | 2018-07-17 13:25:32 -0600 | [diff] [blame] | 240 | retcode = self._DoTestFile(fname, map=map, update_dtb=update_dtb, |
| 241 | entry_args=entry_args) |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 242 | self.assertEqual(0, retcode) |
Simon Glass | a87014e | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 243 | out_dtb_fname = control.GetFdtPath('u-boot.dtb') |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 244 | |
| 245 | # Find the (only) image, read it and return its contents |
| 246 | image = control.images['image'] |
Simon Glass | a87014e | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 247 | image_fname = tools.GetOutputFilename('image.bin') |
| 248 | self.assertTrue(os.path.exists(image_fname)) |
Simon Glass | 3073266 | 2018-06-01 09:38:20 -0600 | [diff] [blame] | 249 | 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 Glass | a87014e | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 255 | with open(image_fname) as fd: |
| 256 | return fd.read(), dtb_data, map_data, out_dtb_fname |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 257 | finally: |
| 258 | # Put the test file back |
| 259 | if use_real_dtb: |
| 260 | TestFunctional._MakeInputFile('u-boot.dtb', U_BOOT_DTB_DATA) |
| 261 | |
Simon Glass | 7223245 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 262 | def _DoReadFile(self, fname, use_real_dtb=False): |
Simon Glass | 1e32400 | 2018-06-01 09:38:19 -0600 | [diff] [blame] | 263 | """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 Glass | def77b5 | 2018-07-17 13:25:27 -0600 | [diff] [blame] | 271 | |
| 272 | Returns: |
| 273 | Resulting image contents |
Simon Glass | 1e32400 | 2018-06-01 09:38:19 -0600 | [diff] [blame] | 274 | """ |
Simon Glass | 7223245 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 275 | return self._DoReadFileDtb(fname, use_real_dtb)[0] |
| 276 | |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 277 | @classmethod |
| 278 | def _MakeInputFile(self, fname, contents): |
| 279 | """Create a new test input file, creating directories as needed |
| 280 | |
| 281 | Args: |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 282 | fname: Filename to create |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 283 | 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 Glass | c1ae83c | 2018-07-17 13:25:44 -0600 | [diff] [blame] | 296 | 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 Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 311 | 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 Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 332 | offset = 0 |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 333 | for entry in entries.values(): |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 334 | self.assertEqual(offset, entry.offset) |
| 335 | offset += entry.size |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 336 | |
Simon Glass | 7223245 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 337 | def GetFdtLen(self, dtb): |
Simon Glass | 1e32400 | 2018-06-01 09:38:19 -0600 | [diff] [blame] | 338 | """Get the totalsize field from a device-tree binary |
Simon Glass | 7223245 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 339 | |
| 340 | Args: |
Simon Glass | 1e32400 | 2018-06-01 09:38:19 -0600 | [diff] [blame] | 341 | dtb: Device-tree binary contents |
Simon Glass | 7223245 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 342 | |
| 343 | Returns: |
Simon Glass | 1e32400 | 2018-06-01 09:38:19 -0600 | [diff] [blame] | 344 | Total size of device-tree binary, from the header |
Simon Glass | 7223245 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 345 | """ |
| 346 | return struct.unpack('>L', dtb[4:8])[0] |
| 347 | |
Simon Glass | a87014e | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 348 | def _GetPropTree(self, dtb_data, node_names): |
| 349 | def AddNode(node, path): |
| 350 | if node.name != '/': |
| 351 | path += '/' + node.name |
Simon Glass | a87014e | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 352 | 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 Glass | a87014e | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 358 | AddNode(subnode, path) |
| 359 | |
| 360 | tree = {} |
| 361 | dtb = fdt.Fdt(dtb_data) |
| 362 | dtb.Scan() |
| 363 | AddNode(dtb.GetRoot(), '') |
| 364 | return tree |
| 365 | |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 366 | 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 Rini | c3c0b6d | 2018-01-16 15:29:50 -0500 | [diff] [blame] | 374 | # 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 Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 378 | 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 Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 397 | 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 Glass | 1e32400 | 2018-06-01 09:38:19 -0600 | [diff] [blame] | 412 | """Test that an invalid device-tree file generates an error""" |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 413 | 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 Glass | 1e32400 | 2018-06-01 09:38:19 -0600 | [diff] [blame] | 420 | """Test that an invalid device-tree source file generates an error |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 421 | |
| 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 Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 447 | 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 Glass | 075a45c | 2017-11-13 18:55:00 -0700 | [diff] [blame] | 455 | def testSimpleDebug(self): |
| 456 | """Test a simple binman run with debugging enabled""" |
| 457 | data = self._DoTestFile('05_simple.dts', debug=True) |
| 458 | |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 459 | 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 Glass | eca3221 | 2018-06-01 09:38:12 -0600 | [diff] [blame] | 498 | entries = image.GetEntries() |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 499 | self.assertEqual(5, len(entries)) |
| 500 | |
| 501 | # First u-boot |
| 502 | self.assertIn('u-boot', entries) |
| 503 | entry = entries['u-boot'] |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 504 | self.assertEqual(0, entry.offset) |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 505 | 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 Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 510 | self.assertEqual(16, entry.offset) |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 511 | 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 Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 516 | self.assertEqual(20, entry.offset) |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 517 | 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 Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 523 | self.assertEqual(43, entry.offset) |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 524 | self.assertEqual(len(U_BOOT_DATA), entry.size) |
| 525 | |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 526 | # Fifth u-boot, placed at a fixed offset |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 527 | self.assertIn('u-boot-fixed', entries) |
| 528 | entry = entries['u-boot-fixed'] |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 529 | self.assertEqual(61, entry.offset) |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 530 | 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 Glass | eca3221 | 2018-06-01 09:38:12 -0600 | [diff] [blame] | 541 | entries = image.GetEntries() |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 542 | 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 Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 547 | self.assertEqual(0, entry.offset) |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 548 | 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 Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 554 | self.assertEqual(12, entry.offset) |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 555 | 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 Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 560 | self.assertEqual(16, entry.offset) |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 561 | 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 Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 566 | self.assertEqual(48, entry.offset) |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 567 | 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 Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 572 | self.assertEqual(64, entry.offset) |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 573 | 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 Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 593 | """Test detection of an offset that does not match its alignment""" |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 594 | with self.assertRaises(ValueError) as e: |
| 595 | self._DoTestFile('12_pack_inv_align.dts') |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 596 | self.assertIn("Node '/binman/u-boot': Offset 0x5 (5) does not match " |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 597 | "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 Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 610 | self.assertIn("Node '/binman/u-boot-align': Offset 0x3 (3) overlaps " |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 611 | "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 Glass | eca3221 | 2018-06-01 09:38:12 -0600 | [diff] [blame] | 625 | self.assertIn("Section '/binman': contents size 0x4 (4) exceeds section " |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 626 | "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 Glass | eca3221 | 2018-06-01 09:38:12 -0600 | [diff] [blame] | 648 | self.assertIn("Section '/binman': Size 0x7 (7) does not match " |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 649 | "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 Glass | eca3221 | 2018-06-01 09:38:12 -0600 | [diff] [blame] | 655 | self.assertIn("Section '/binman': Alignment size 131 must be a power of " |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 656 | "two", str(e.exception)) |
| 657 | |
| 658 | def testImagePadByte(self): |
| 659 | """Test that the image pad byte can be specified""" |
Simon Glass | 4ca8e04 | 2017-11-13 18:55:01 -0700 | [diff] [blame] | 660 | with open(self.TestFile('bss_data')) as fd: |
| 661 | TestFunctional._MakeInputFile('spl/u-boot-spl', fd.read()) |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 662 | data = self._DoReadFile('21_image_pad.dts') |
Simon Glass | d605152 | 2017-11-13 18:54:59 -0700 | [diff] [blame] | 663 | self.assertEqual(U_BOOT_SPL_DATA + (chr(0xff) * 1) + U_BOOT_DATA, data) |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 664 | |
| 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 Glass | d605152 | 2017-11-13 18:54:59 -0700 | [diff] [blame] | 685 | self.assertEqual(chr(0) * 1 + U_BOOT_SPL_DATA + chr(0) * 2 + |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 686 | U_BOOT_DATA, data) |
| 687 | |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 688 | def testPackZeroOffset(self): |
| 689 | """Test that an entry at offset 0 is not given a new offset""" |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 690 | with self.assertRaises(ValueError) as e: |
| 691 | self._DoTestFile('25_pack_zero_size.dts') |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 692 | self.assertIn("Node '/binman/u-boot-spl': Offset 0x0 (0) overlaps " |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 693 | "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 Glass | 7223245 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 700 | |
| 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 Glass | eca3221 | 2018-06-01 09:38:12 -0600 | [diff] [blame] | 705 | self.assertIn("Section '/binman': Section size must be provided when " |
Simon Glass | 7223245 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 706 | "using end-at-4gb", str(e.exception)) |
| 707 | |
| 708 | def testPackX86RomOutside(self): |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 709 | """Test that the end-at-4gb property checks for offset boundaries""" |
Simon Glass | 7223245 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 710 | with self.assertRaises(ValueError) as e: |
| 711 | self._DoTestFile('28_pack_4gb_outside.dts') |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 712 | self.assertIn("Node '/binman/u-boot': Offset 0x0 (0) is outside " |
Simon Glass | eca3221 | 2018-06-01 09:38:12 -0600 | [diff] [blame] | 713 | "the section starting at 0xffffffe0 (4294967264)", |
Simon Glass | 7223245 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 714 | 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 Glass | d605152 | 2017-11-13 18:54:59 -0700 | [diff] [blame] | 719 | self.assertEqual(U_BOOT_DATA + chr(0) * 7 + U_BOOT_SPL_DATA + |
| 720 | chr(0) * 2, data) |
Simon Glass | 7223245 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 721 | |
| 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 Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 734 | 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 Glass | 7223245 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 737 | |
| 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 Glass | 6ba679c | 2018-07-06 10:27:17 -0600 | [diff] [blame] | 753 | def _RunMicrocodeTest(self, dts_fname, nodtb_data, ucode_second=False): |
Simon Glass | 820af1d | 2018-07-06 10:27:16 -0600 | [diff] [blame] | 754 | """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 Glass | 6ba679c | 2018-07-06 10:27:17 -0600 | [diff] [blame] | 759 | ucode_second: True if the microsecond entry is second instead of |
| 760 | third |
Simon Glass | 820af1d | 2018-07-06 10:27:16 -0600 | [diff] [blame] | 761 | |
| 762 | Returns: |
| 763 | Tuple: |
| 764 | Contents of first region (U-Boot or SPL) |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 765 | Offset and size components of microcode pointer, as inserted |
Simon Glass | 820af1d | 2018-07-06 10:27:16 -0600 | [diff] [blame] | 766 | in the above (two 4-byte words) |
| 767 | """ |
Simon Glass | 3d27423 | 2017-11-12 21:52:27 -0700 | [diff] [blame] | 768 | data = self._DoReadFile(dts_fname, True) |
Simon Glass | 7223245 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 769 | |
| 770 | # Now check the device tree has no microcode |
Simon Glass | 6ba679c | 2018-07-06 10:27:17 -0600 | [diff] [blame] | 771 | 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 Glass | 7223245 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 781 | fname = tools.GetOutputFilename('test.dtb') |
| 782 | with open(fname, 'wb') as fd: |
Simon Glass | 820af1d | 2018-07-06 10:27:16 -0600 | [diff] [blame] | 783 | fd.write(dtb_with_ucode) |
Simon Glass | 22c92ca | 2017-05-27 07:38:29 -0600 | [diff] [blame] | 784 | dtb = fdt.FdtScan(fname) |
| 785 | ucode = dtb.GetNode('/microcode') |
Simon Glass | 7223245 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 786 | self.assertTrue(ucode) |
| 787 | for node in ucode.subnodes: |
| 788 | self.assertFalse(node.props.get('data')) |
| 789 | |
Simon Glass | 7223245 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 790 | # Check that the microcode appears immediately after the Fdt |
| 791 | # This matches the concatenation of the data properties in |
Simon Glass | e83679d | 2017-11-12 21:52:26 -0700 | [diff] [blame] | 792 | # the /microcode/update@xxx nodes in 34_x86_ucode.dts. |
Simon Glass | 7223245 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 793 | ucode_data = struct.pack('>4L', 0x12345678, 0x12345679, 0xabcd0000, |
| 794 | 0x78235609) |
Simon Glass | 820af1d | 2018-07-06 10:27:16 -0600 | [diff] [blame] | 795 | self.assertEqual(ucode_data, ucode_content[:len(ucode_data)]) |
Simon Glass | 7223245 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 796 | |
| 797 | # Check that the microcode pointer was inserted. It should match the |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 798 | # expected offset and size |
Simon Glass | 7223245 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 799 | pos_and_size = struct.pack('<2L', 0xfffffe00 + ucode_pos, |
| 800 | len(ucode_data)) |
Simon Glass | 6ba679c | 2018-07-06 10:27:17 -0600 | [diff] [blame] | 801 | u_boot = data[:len(nodtb_data)] |
| 802 | return u_boot, pos_and_size |
Simon Glass | 3d27423 | 2017-11-12 21:52:27 -0700 | [diff] [blame] | 803 | |
| 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 Glass | 7223245 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 815 | self.assertEqual('nodtb with microcode' + pos_and_size + |
| 816 | ' somewhere in here', first) |
| 817 | |
Simon Glass | bac25c8 | 2017-05-27 07:38:26 -0600 | [diff] [blame] | 818 | def _RunPackUbootSingleMicrocode(self): |
Simon Glass | 7223245 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 819 | """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 Glass | 7223245 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 830 | 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 Glass | bac25c8 | 2017-05-27 07:38:26 -0600 | [diff] [blame] | 838 | 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 Glass | 7223245 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 841 | |
Simon Glass | bac25c8 | 2017-05-27 07:38:26 -0600 | [diff] [blame] | 842 | # Check that the microcode pointer was inserted. It should match the |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 843 | # expected offset and size |
Simon Glass | bac25c8 | 2017-05-27 07:38:26 -0600 | [diff] [blame] | 844 | 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 Glass | 996021e | 2016-11-25 20:15:54 -0700 | [diff] [blame] | 849 | |
Simon Glass | d2dfb5f | 2016-11-25 20:15:55 -0700 | [diff] [blame] | 850 | def testPackUbootSingleMicrocode(self): |
| 851 | """Test that x86 microcode can be handled correctly with fdt_normal. |
| 852 | """ |
Simon Glass | bac25c8 | 2017-05-27 07:38:26 -0600 | [diff] [blame] | 853 | self._RunPackUbootSingleMicrocode() |
Simon Glass | d2dfb5f | 2016-11-25 20:15:55 -0700 | [diff] [blame] | 854 | |
Simon Glass | 996021e | 2016-11-25 20:15:54 -0700 | [diff] [blame] | 855 | 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 Glass | d2dfb5f | 2016-11-25 20:15:55 -0700 | [diff] [blame] | 859 | |
| 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 Glass | d2dfb5f | 2016-11-25 20:15:55 -0700 | [diff] [blame] | 884 | 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 Glass | bac25c8 | 2017-05-27 07:38:26 -0600 | [diff] [blame] | 889 | self._RunPackUbootSingleMicrocode() |
Simon Glass | d2dfb5f | 2016-11-25 20:15:55 -0700 | [diff] [blame] | 890 | 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 Glass | ad5a771 | 2018-06-01 09:38:14 -0600 | [diff] [blame] | 904 | "section ranging from 00000000 to 0000002e", str(e.exception)) |
Simon Glass | d2dfb5f | 2016-11-25 20:15:55 -0700 | [diff] [blame] | 905 | |
| 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 Glass | a87014e | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 910 | data, dtb, _, _ = self._DoReadFileDtb('44_x86_optional_ucode.dts', True) |
Simon Glass | d2dfb5f | 2016-11-25 20:15:55 -0700 | [diff] [blame] | 911 | |
| 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 Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 927 | self.assertIn("Section '/binman': Unable to set offset/size for unknown " |
Simon Glass | d2dfb5f | 2016-11-25 20:15:55 -0700 | [diff] [blame] | 928 | "entry 'invalid-entry'", str(e.exception)) |
Simon Glass | b4176d4 | 2016-11-25 20:15:56 -0700 | [diff] [blame] | 929 | |
| 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 Meng | d7bcdf5 | 2017-08-15 22:41:54 -0700 | [diff] [blame] | 936 | """Test that an image with a CMC binary can be created""" |
Simon Glass | b4176d4 | 2016-11-25 20:15:56 -0700 | [diff] [blame] | 937 | data = self._DoReadFile('43_intel-cmc.dts') |
| 938 | self.assertEqual(CMC_DATA, data[:len(CMC_DATA)]) |
Bin Meng | d7bcdf5 | 2017-08-15 22:41:54 -0700 | [diff] [blame] | 939 | |
| 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 Glass | ac59991 | 2017-11-12 21:52:22 -0700 | [diff] [blame] | 944 | |
Simon Glass | 7f94e83 | 2017-11-12 21:52:25 -0700 | [diff] [blame] | 945 | def testSplBssPad(self): |
| 946 | """Test that we can pad SPL's BSS with zeros""" |
Simon Glass | 3d27423 | 2017-11-12 21:52:27 -0700 | [diff] [blame] | 947 | # 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 Glass | 7f94e83 | 2017-11-12 21:52:25 -0700 | [diff] [blame] | 950 | data = self._DoReadFile('47_spl_bss_pad.dts') |
| 951 | self.assertEqual(U_BOOT_SPL_DATA + (chr(0) * 10) + U_BOOT_DATA, data) |
| 952 | |
Simon Glass | 24ad365 | 2017-11-13 18:54:54 -0700 | [diff] [blame] | 953 | 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 Glass | e83679d | 2017-11-12 21:52:26 -0700 | [diff] [blame] | 960 | 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 Glass | 6ba679c | 2018-07-06 10:27:17 -0600 | [diff] [blame] | 965 | def _PackUbootSplMicrocode(self, dts, ucode_second=False): |
| 966 | """Helper function for microcode tests |
Simon Glass | 3d27423 | 2017-11-12 21:52:27 -0700 | [diff] [blame] | 967 | |
| 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 Glass | 6ba679c | 2018-07-06 10:27:17 -0600 | [diff] [blame] | 973 | |
| 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 Glass | 3d27423 | 2017-11-12 21:52:27 -0700 | [diff] [blame] | 978 | """ |
| 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 Glass | 6ba679c | 2018-07-06 10:27:17 -0600 | [diff] [blame] | 982 | first, pos_and_size = self._RunMicrocodeTest(dts, U_BOOT_SPL_NODTB_DATA, |
| 983 | ucode_second=ucode_second) |
Simon Glass | 3d27423 | 2017-11-12 21:52:27 -0700 | [diff] [blame] | 984 | self.assertEqual('splnodtb with microc' + pos_and_size + |
| 985 | 'ter somewhere in here', first) |
| 986 | |
Simon Glass | 6ba679c | 2018-07-06 10:27:17 -0600 | [diff] [blame] | 987 | 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 Glass | a409c93 | 2017-11-12 21:52:28 -0700 | [diff] [blame] | 1001 | 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 Glass | 9aa6a6f | 2017-11-13 18:54:55 -0700 | [diff] [blame] | 1006 | 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 Glass | 0a6da31 | 2017-11-13 18:54:56 -0700 | [diff] [blame] | 1011 | 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 Glass | 4ca8e04 | 2017-11-13 18:55:01 -0700 | [diff] [blame] | 1016 | 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 Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 1021 | self.assertEqual(syms['_binman_u_boot_spl_prop_offset'].address, addr) |
Simon Glass | 4ca8e04 | 2017-11-13 18:55:01 -0700 | [diff] [blame] | 1022 | |
| 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 Glass | e76a3e6 | 2018-06-01 09:38:11 -0600 | [diff] [blame] | 1032 | 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 Glass | a91e115 | 2018-06-01 09:38:16 -0600 | [diff] [blame] | 1037 | def testSections(self): |
| 1038 | """Basic test of sections""" |
| 1039 | data = self._DoReadFile('55_sections.dts') |
Simon Glass | 3a9a2b8 | 2018-07-17 13:25:28 -0600 | [diff] [blame] | 1040 | expected = (U_BOOT_DATA + '!' * 12 + U_BOOT_DATA + 'a' * 12 + |
| 1041 | U_BOOT_DATA + '&' * 4) |
Simon Glass | a91e115 | 2018-06-01 09:38:16 -0600 | [diff] [blame] | 1042 | self.assertEqual(expected, data) |
Simon Glass | ac59991 | 2017-11-12 21:52:22 -0700 | [diff] [blame] | 1043 | |
Simon Glass | 3073266 | 2018-06-01 09:38:20 -0600 | [diff] [blame] | 1044 | def testMap(self): |
| 1045 | """Tests outputting a map of the images""" |
Simon Glass | a87014e | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 1046 | _, _, map_data, _ = self._DoReadFileDtb('55_sections.dts', map=True) |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 1047 | self.assertEqual(''' Offset Size Name |
Simon Glass | 3a9a2b8 | 2018-07-17 13:25:28 -0600 | [diff] [blame] | 1048 | 00000000 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 Glass | 3073266 | 2018-06-01 09:38:20 -0600 | [diff] [blame] | 1055 | ''', map_data) |
| 1056 | |
Simon Glass | 3b78d53 | 2018-06-01 09:38:21 -0600 | [diff] [blame] | 1057 | def testNamePrefix(self): |
| 1058 | """Tests that name prefixes are used""" |
Simon Glass | a87014e | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 1059 | _, _, map_data, _ = self._DoReadFileDtb('56_name_prefix.dts', map=True) |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 1060 | self.assertEqual(''' Offset Size Name |
Simon Glass | 3a9a2b8 | 2018-07-17 13:25:28 -0600 | [diff] [blame] | 1061 | 00000000 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 Glass | 3b78d53 | 2018-06-01 09:38:21 -0600 | [diff] [blame] | 1066 | ''', map_data) |
| 1067 | |
Simon Glass | 6ba679c | 2018-07-06 10:27:17 -0600 | [diff] [blame] | 1068 | 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 Glass | 2e1169f | 2018-07-06 10:27:19 -0600 | [diff] [blame] | 1076 | 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 Glass | a87014e | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 1083 | def testUpdateFdt(self): |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 1084 | """Test that we can update the device tree with offset/size info""" |
Simon Glass | a87014e | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 1085 | _, _, _, out_dtb_fname = self._DoReadFileDtb('60_fdt_update.dts', |
| 1086 | update_dtb=True) |
Simon Glass | 9dcc861 | 2018-08-01 15:22:42 -0600 | [diff] [blame] | 1087 | props = self._GetPropTree(out_dtb_fname, ['offset', 'size', |
| 1088 | 'image-pos']) |
Simon Glass | a87014e | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 1089 | 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 Glass | 9dcc861 | 2018-08-01 15:22:42 -0600 | [diff] [blame] | 1093 | 'image-pos': 0, |
Simon Glass | 3a9a2b8 | 2018-07-17 13:25:28 -0600 | [diff] [blame] | 1094 | 'offset': 0, |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 1095 | '_testing:offset': 32, |
Simon Glass | a87014e | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 1096 | '_testing:size': 1, |
Simon Glass | 9dcc861 | 2018-08-01 15:22:42 -0600 | [diff] [blame] | 1097 | '_testing:image-pos': 32, |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 1098 | 'section@0/u-boot:offset': 0, |
Simon Glass | a87014e | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 1099 | 'section@0/u-boot:size': len(U_BOOT_DATA), |
Simon Glass | 9dcc861 | 2018-08-01 15:22:42 -0600 | [diff] [blame] | 1100 | 'section@0/u-boot:image-pos': 0, |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 1101 | 'section@0:offset': 0, |
Simon Glass | a87014e | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 1102 | 'section@0:size': 16, |
Simon Glass | 9dcc861 | 2018-08-01 15:22:42 -0600 | [diff] [blame] | 1103 | 'section@0:image-pos': 0, |
Simon Glass | a87014e | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 1104 | |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 1105 | 'section@1/u-boot:offset': 0, |
Simon Glass | a87014e | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 1106 | 'section@1/u-boot:size': len(U_BOOT_DATA), |
Simon Glass | 9dcc861 | 2018-08-01 15:22:42 -0600 | [diff] [blame] | 1107 | 'section@1/u-boot:image-pos': 16, |
Simon Glass | e8561af | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 1108 | 'section@1:offset': 16, |
Simon Glass | a87014e | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 1109 | 'section@1:size': 16, |
Simon Glass | 9dcc861 | 2018-08-01 15:22:42 -0600 | [diff] [blame] | 1110 | 'section@1:image-pos': 16, |
Simon Glass | a87014e | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 1111 | '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 Glass | 2e1169f | 2018-07-06 10:27:19 -0600 | [diff] [blame] | 1120 | |
Simon Glass | 91710b3 | 2018-07-17 13:25:32 -0600 | [diff] [blame] | 1121 | 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 Glass | 2ca5203 | 2018-07-17 13:25:33 -0600 | [diff] [blame] | 1192 | 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 Glass | 969616c | 2018-07-17 13:25:36 -0600 | [diff] [blame] | 1205 | 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 Glass | 704784b | 2018-07-17 13:25:38 -0600 | [diff] [blame] | 1219 | 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 Glass | db168d4 | 2018-07-17 13:25:39 -0600 | [diff] [blame] | 1250 | 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 Glass | 53f5399 | 2018-07-17 13:25:40 -0600 | [diff] [blame] | 1258 | 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 Glass | c1ae83c | 2018-07-17 13:25:44 -0600 | [diff] [blame] | 1271 | 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 Glass | 5c35016 | 2018-07-17 13:25:47 -0600 | [diff] [blame^] | 1308 | 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 Glass | 91710b3 | 2018-07-17 13:25:32 -0600 | [diff] [blame] | 1348 | |
Simon Glass | ac59991 | 2017-11-12 21:52:22 -0700 | [diff] [blame] | 1349 | if __name__ == "__main__": |
| 1350 | unittest.main() |