Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 4f44304 | 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 | 4f44304 | 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 | |
Simon Glass | d5164a7 | 2019-07-08 13:18:49 -0600 | [diff] [blame] | 9 | from __future__ import print_function |
| 10 | |
Simon Glass | e0e5df9 | 2018-09-14 04:57:31 -0600 | [diff] [blame] | 11 | import hashlib |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 12 | from optparse import OptionParser |
| 13 | import os |
| 14 | import shutil |
| 15 | import struct |
| 16 | import sys |
| 17 | import tempfile |
| 18 | import unittest |
| 19 | |
| 20 | import binman |
Simon Glass | ac62fba | 2019-07-08 13:18:53 -0600 | [diff] [blame] | 21 | import cbfs_util |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 22 | import cmdline |
| 23 | import command |
| 24 | import control |
Simon Glass | 1979063 | 2017-11-13 18:55:01 -0700 | [diff] [blame] | 25 | import elf |
Simon Glass | 99ed4a2 | 2017-05-27 07:38:30 -0600 | [diff] [blame] | 26 | import fdt |
Simon Glass | e1925fa | 2019-07-08 14:25:44 -0600 | [diff] [blame] | 27 | from etype import fdtmap |
Simon Glass | 2d26003 | 2019-07-08 14:25:45 -0600 | [diff] [blame^] | 28 | from etype import image_header |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 29 | import fdt_util |
Simon Glass | 11e36cc | 2018-07-17 13:25:38 -0600 | [diff] [blame] | 30 | import fmap_util |
Simon Glass | fd8d1f7 | 2018-07-17 13:25:36 -0600 | [diff] [blame] | 31 | import test_util |
Simon Glass | c5ac138 | 2019-07-08 13:18:54 -0600 | [diff] [blame] | 32 | import gzip |
Simon Glass | c55a50f | 2018-09-14 04:57:19 -0600 | [diff] [blame] | 33 | import state |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 34 | import tools |
| 35 | import tout |
| 36 | |
| 37 | # Contents of test files, corresponding to different entry types |
Simon Glass | c6c10e7 | 2019-05-17 22:00:46 -0600 | [diff] [blame] | 38 | U_BOOT_DATA = b'1234' |
| 39 | U_BOOT_IMG_DATA = b'img' |
| 40 | U_BOOT_SPL_DATA = b'56780123456789abcde' |
| 41 | U_BOOT_TPL_DATA = b'tpl' |
| 42 | BLOB_DATA = b'89' |
| 43 | ME_DATA = b'0abcd' |
| 44 | VGA_DATA = b'vga' |
| 45 | U_BOOT_DTB_DATA = b'udtb' |
| 46 | U_BOOT_SPL_DTB_DATA = b'spldtb' |
| 47 | U_BOOT_TPL_DTB_DATA = b'tpldtb' |
| 48 | X86_START16_DATA = b'start16' |
| 49 | X86_START16_SPL_DATA = b'start16spl' |
| 50 | X86_START16_TPL_DATA = b'start16tpl' |
| 51 | PPC_MPC85XX_BR_DATA = b'ppcmpc85xxbr' |
| 52 | U_BOOT_NODTB_DATA = b'nodtb with microcode pointer somewhere in here' |
| 53 | U_BOOT_SPL_NODTB_DATA = b'splnodtb with microcode pointer somewhere in here' |
| 54 | U_BOOT_TPL_NODTB_DATA = b'tplnodtb with microcode pointer somewhere in here' |
| 55 | FSP_DATA = b'fsp' |
| 56 | CMC_DATA = b'cmc' |
| 57 | VBT_DATA = b'vbt' |
| 58 | MRC_DATA = b'mrc' |
Simon Glass | bb74837 | 2018-07-17 13:25:33 -0600 | [diff] [blame] | 59 | TEXT_DATA = 'text' |
| 60 | TEXT_DATA2 = 'text2' |
| 61 | TEXT_DATA3 = 'text3' |
Simon Glass | c6c10e7 | 2019-05-17 22:00:46 -0600 | [diff] [blame] | 62 | CROS_EC_RW_DATA = b'ecrw' |
| 63 | GBB_DATA = b'gbbd' |
| 64 | BMPBLK_DATA = b'bmp' |
| 65 | VBLOCK_DATA = b'vblk' |
| 66 | FILES_DATA = (b"sorry I'm late\nOh, don't bother apologising, I'm " + |
| 67 | b"sorry you're alive\n") |
Simon Glass | ff5c7e3 | 2019-07-08 13:18:42 -0600 | [diff] [blame] | 68 | COMPRESS_DATA = b'compress xxxxxxxxxxxxxxxxxxxxxx data' |
Simon Glass | c6c10e7 | 2019-05-17 22:00:46 -0600 | [diff] [blame] | 69 | REFCODE_DATA = b'refcode' |
Simon Glass | ec127af | 2018-07-17 13:25:39 -0600 | [diff] [blame] | 70 | |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 71 | |
| 72 | class TestFunctional(unittest.TestCase): |
| 73 | """Functional tests for binman |
| 74 | |
| 75 | Most of these use a sample .dts file to build an image and then check |
| 76 | that it looks correct. The sample files are in the test/ subdirectory |
| 77 | and are numbered. |
| 78 | |
| 79 | For each entry type a very small test file is created using fixed |
| 80 | string contents. This makes it easy to test that things look right, and |
| 81 | debug problems. |
| 82 | |
| 83 | In some cases a 'real' file must be used - these are also supplied in |
| 84 | the test/ diurectory. |
| 85 | """ |
| 86 | @classmethod |
| 87 | def setUpClass(self): |
Simon Glass | 4d5994f | 2017-11-12 21:52:20 -0700 | [diff] [blame] | 88 | global entry |
| 89 | import entry |
| 90 | |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 91 | # Handle the case where argv[0] is 'python' |
| 92 | self._binman_dir = os.path.dirname(os.path.realpath(sys.argv[0])) |
| 93 | self._binman_pathname = os.path.join(self._binman_dir, 'binman') |
| 94 | |
| 95 | # Create a temporary directory for input files |
| 96 | self._indir = tempfile.mkdtemp(prefix='binmant.') |
| 97 | |
| 98 | # Create some test files |
| 99 | TestFunctional._MakeInputFile('u-boot.bin', U_BOOT_DATA) |
| 100 | TestFunctional._MakeInputFile('u-boot.img', U_BOOT_IMG_DATA) |
| 101 | TestFunctional._MakeInputFile('spl/u-boot-spl.bin', U_BOOT_SPL_DATA) |
Simon Glass | b8ef5b6 | 2018-07-17 13:25:48 -0600 | [diff] [blame] | 102 | TestFunctional._MakeInputFile('tpl/u-boot-tpl.bin', U_BOOT_TPL_DATA) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 103 | TestFunctional._MakeInputFile('blobfile', BLOB_DATA) |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 104 | TestFunctional._MakeInputFile('me.bin', ME_DATA) |
| 105 | TestFunctional._MakeInputFile('vga.bin', VGA_DATA) |
Simon Glass | b8ef5b6 | 2018-07-17 13:25:48 -0600 | [diff] [blame] | 106 | self._ResetDtbs() |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 107 | TestFunctional._MakeInputFile('u-boot-x86-16bit.bin', X86_START16_DATA) |
Jagdish Gediya | 9d368f3 | 2018-09-03 21:35:08 +0530 | [diff] [blame] | 108 | TestFunctional._MakeInputFile('u-boot-br.bin', PPC_MPC85XX_BR_DATA) |
Simon Glass | 8772213 | 2017-11-12 21:52:26 -0700 | [diff] [blame] | 109 | TestFunctional._MakeInputFile('spl/u-boot-x86-16bit-spl.bin', |
| 110 | X86_START16_SPL_DATA) |
Simon Glass | 35b384c | 2018-09-14 04:57:10 -0600 | [diff] [blame] | 111 | TestFunctional._MakeInputFile('tpl/u-boot-x86-16bit-tpl.bin', |
| 112 | X86_START16_TPL_DATA) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 113 | TestFunctional._MakeInputFile('u-boot-nodtb.bin', U_BOOT_NODTB_DATA) |
Simon Glass | 6b187df | 2017-11-12 21:52:27 -0700 | [diff] [blame] | 114 | TestFunctional._MakeInputFile('spl/u-boot-spl-nodtb.bin', |
| 115 | U_BOOT_SPL_NODTB_DATA) |
Simon Glass | f025363 | 2018-09-14 04:57:32 -0600 | [diff] [blame] | 116 | TestFunctional._MakeInputFile('tpl/u-boot-tpl-nodtb.bin', |
| 117 | U_BOOT_TPL_NODTB_DATA) |
Simon Glass | da22909 | 2016-11-25 20:15:56 -0700 | [diff] [blame] | 118 | TestFunctional._MakeInputFile('fsp.bin', FSP_DATA) |
| 119 | TestFunctional._MakeInputFile('cmc.bin', CMC_DATA) |
Bin Meng | 59ea8c2 | 2017-08-15 22:41:54 -0700 | [diff] [blame] | 120 | TestFunctional._MakeInputFile('vbt.bin', VBT_DATA) |
Simon Glass | ca4f4ff | 2017-11-12 21:52:28 -0700 | [diff] [blame] | 121 | TestFunctional._MakeInputFile('mrc.bin', MRC_DATA) |
Simon Glass | ec127af | 2018-07-17 13:25:39 -0600 | [diff] [blame] | 122 | TestFunctional._MakeInputFile('ecrw.bin', CROS_EC_RW_DATA) |
Simon Glass | 0ef87aa | 2018-07-17 13:25:44 -0600 | [diff] [blame] | 123 | TestFunctional._MakeInputDir('devkeys') |
| 124 | TestFunctional._MakeInputFile('bmpblk.bin', BMPBLK_DATA) |
Simon Glass | 3ae192c | 2018-10-01 12:22:31 -0600 | [diff] [blame] | 125 | TestFunctional._MakeInputFile('refcode.bin', REFCODE_DATA) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 126 | |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 127 | # ELF file with a '_dt_ucode_base_size' symbol |
Simon Glass | 1d0ebf7 | 2019-05-14 15:53:42 -0600 | [diff] [blame] | 128 | with open(self.TestFile('u_boot_ucode_ptr'), 'rb') as fd: |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 129 | TestFunctional._MakeInputFile('u-boot', fd.read()) |
| 130 | |
| 131 | # Intel flash descriptor file |
Simon Glass | 1d0ebf7 | 2019-05-14 15:53:42 -0600 | [diff] [blame] | 132 | with open(self.TestFile('descriptor.bin'), 'rb') as fd: |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 133 | TestFunctional._MakeInputFile('descriptor.bin', fd.read()) |
| 134 | |
Simon Glass | 0a98b28 | 2018-09-14 04:57:28 -0600 | [diff] [blame] | 135 | shutil.copytree(self.TestFile('files'), |
| 136 | os.path.join(self._indir, 'files')) |
| 137 | |
Simon Glass | 83d73c2 | 2018-09-14 04:57:26 -0600 | [diff] [blame] | 138 | TestFunctional._MakeInputFile('compress', COMPRESS_DATA) |
| 139 | |
Simon Glass | ac62fba | 2019-07-08 13:18:53 -0600 | [diff] [blame] | 140 | # Travis-CI may have an old lz4 |
| 141 | self.have_lz4 = True |
| 142 | try: |
| 143 | tools.Run('lz4', '--no-frame-crc', '-c', |
| 144 | os.path.join(self._indir, 'u-boot.bin')) |
| 145 | except: |
| 146 | self.have_lz4 = False |
| 147 | |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 148 | @classmethod |
| 149 | def tearDownClass(self): |
| 150 | """Remove the temporary input directory and its contents""" |
Simon Glass | d5164a7 | 2019-07-08 13:18:49 -0600 | [diff] [blame] | 151 | if self.preserve_indir: |
| 152 | print('Preserving input dir: %s' % self._indir) |
| 153 | else: |
| 154 | if self._indir: |
| 155 | shutil.rmtree(self._indir) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 156 | self._indir = None |
| 157 | |
Simon Glass | d5164a7 | 2019-07-08 13:18:49 -0600 | [diff] [blame] | 158 | @classmethod |
Simon Glass | 8acce60 | 2019-07-08 13:18:50 -0600 | [diff] [blame] | 159 | def setup_test_args(cls, preserve_indir=False, preserve_outdirs=False, |
Simon Glass | 53cd5d9 | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 160 | toolpath=None, verbosity=None): |
Simon Glass | d5164a7 | 2019-07-08 13:18:49 -0600 | [diff] [blame] | 161 | """Accept arguments controlling test execution |
| 162 | |
| 163 | Args: |
| 164 | preserve_indir: Preserve the shared input directory used by all |
| 165 | tests in this class. |
| 166 | preserve_outdir: Preserve the output directories used by tests. Each |
| 167 | test has its own, so this is normally only useful when running a |
| 168 | single test. |
Simon Glass | 8acce60 | 2019-07-08 13:18:50 -0600 | [diff] [blame] | 169 | toolpath: ist of paths to use for tools |
Simon Glass | d5164a7 | 2019-07-08 13:18:49 -0600 | [diff] [blame] | 170 | """ |
| 171 | cls.preserve_indir = preserve_indir |
| 172 | cls.preserve_outdirs = preserve_outdirs |
Simon Glass | 8acce60 | 2019-07-08 13:18:50 -0600 | [diff] [blame] | 173 | cls.toolpath = toolpath |
Simon Glass | 53cd5d9 | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 174 | cls.verbosity = verbosity |
Simon Glass | d5164a7 | 2019-07-08 13:18:49 -0600 | [diff] [blame] | 175 | |
Simon Glass | ac62fba | 2019-07-08 13:18:53 -0600 | [diff] [blame] | 176 | def _CheckLz4(self): |
| 177 | if not self.have_lz4: |
| 178 | self.skipTest('lz4 --no-frame-crc not available') |
| 179 | |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 180 | def setUp(self): |
| 181 | # Enable this to turn on debugging output |
| 182 | # tout.Init(tout.DEBUG) |
| 183 | command.test_result = None |
| 184 | |
| 185 | def tearDown(self): |
| 186 | """Remove the temporary output directory""" |
Simon Glass | d5164a7 | 2019-07-08 13:18:49 -0600 | [diff] [blame] | 187 | if self.preserve_outdirs: |
| 188 | print('Preserving output dir: %s' % tools.outdir) |
| 189 | else: |
| 190 | tools._FinaliseForTest() |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 191 | |
Simon Glass | b8ef5b6 | 2018-07-17 13:25:48 -0600 | [diff] [blame] | 192 | @classmethod |
| 193 | def _ResetDtbs(self): |
| 194 | TestFunctional._MakeInputFile('u-boot.dtb', U_BOOT_DTB_DATA) |
| 195 | TestFunctional._MakeInputFile('spl/u-boot-spl.dtb', U_BOOT_SPL_DTB_DATA) |
| 196 | TestFunctional._MakeInputFile('tpl/u-boot-tpl.dtb', U_BOOT_TPL_DTB_DATA) |
| 197 | |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 198 | def _RunBinman(self, *args, **kwargs): |
| 199 | """Run binman using the command line |
| 200 | |
| 201 | Args: |
| 202 | Arguments to pass, as a list of strings |
| 203 | kwargs: Arguments to pass to Command.RunPipe() |
| 204 | """ |
| 205 | result = command.RunPipe([[self._binman_pathname] + list(args)], |
| 206 | capture=True, capture_stderr=True, raise_on_error=False) |
| 207 | if result.return_code and kwargs.get('raise_on_error', True): |
| 208 | raise Exception("Error running '%s': %s" % (' '.join(args), |
| 209 | result.stdout + result.stderr)) |
| 210 | return result |
| 211 | |
Simon Glass | 53cd5d9 | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 212 | def _DoBinman(self, *argv): |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 213 | """Run binman using directly (in the same process) |
| 214 | |
| 215 | Args: |
| 216 | Arguments to pass, as a list of strings |
| 217 | Returns: |
| 218 | Return value (0 for success) |
| 219 | """ |
Simon Glass | 53cd5d9 | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 220 | argv = list(argv) |
| 221 | args = cmdline.ParseArgs(argv) |
| 222 | args.pager = 'binman-invalid-pager' |
| 223 | args.build_dir = self._indir |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 224 | |
| 225 | # For testing, you can force an increase in verbosity here |
Simon Glass | 53cd5d9 | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 226 | # args.verbosity = tout.DEBUG |
| 227 | return control.Binman(args) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 228 | |
Simon Glass | 53af22a | 2018-07-17 13:25:32 -0600 | [diff] [blame] | 229 | def _DoTestFile(self, fname, debug=False, map=False, update_dtb=False, |
Simon Glass | eb833d8 | 2019-04-25 21:58:34 -0600 | [diff] [blame] | 230 | entry_args=None, images=None, use_real_dtb=False, |
| 231 | verbosity=None): |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 232 | """Run binman with a given test file |
| 233 | |
| 234 | Args: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 235 | fname: Device-tree source filename to use (e.g. 005_simple.dts) |
Simon Glass | 7ae5f31 | 2018-06-01 09:38:19 -0600 | [diff] [blame] | 236 | debug: True to enable debugging output |
Simon Glass | 3b0c382 | 2018-06-01 09:38:20 -0600 | [diff] [blame] | 237 | map: True to output map files for the images |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 238 | update_dtb: Update the offset and size of each entry in the device |
Simon Glass | 16b8d6b | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 239 | tree before packing it into the image |
Simon Glass | 0bfa7b0 | 2018-09-14 04:57:12 -0600 | [diff] [blame] | 240 | entry_args: Dict of entry args to supply to binman |
| 241 | key: arg name |
| 242 | value: value of that arg |
| 243 | images: List of image names to build |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 244 | """ |
Simon Glass | 53cd5d9 | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 245 | args = [] |
Simon Glass | 7fe9173 | 2017-11-13 18:55:00 -0700 | [diff] [blame] | 246 | if debug: |
| 247 | args.append('-D') |
Simon Glass | 53cd5d9 | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 248 | if verbosity is not None: |
| 249 | args.append('-v%d' % verbosity) |
| 250 | elif self.verbosity: |
| 251 | args.append('-v%d' % self.verbosity) |
| 252 | if self.toolpath: |
| 253 | for path in self.toolpath: |
| 254 | args += ['--toolpath', path] |
| 255 | args += ['build', '-p', '-I', self._indir, '-d', self.TestFile(fname)] |
Simon Glass | 3b0c382 | 2018-06-01 09:38:20 -0600 | [diff] [blame] | 256 | if map: |
| 257 | args.append('-m') |
Simon Glass | 16b8d6b | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 258 | if update_dtb: |
Simon Glass | 2569e10 | 2019-07-08 13:18:47 -0600 | [diff] [blame] | 259 | args.append('-u') |
Simon Glass | 93d1741 | 2018-09-14 04:57:23 -0600 | [diff] [blame] | 260 | if not use_real_dtb: |
| 261 | args.append('--fake-dtb') |
Simon Glass | 53af22a | 2018-07-17 13:25:32 -0600 | [diff] [blame] | 262 | if entry_args: |
Simon Glass | 5097915 | 2019-05-14 15:53:41 -0600 | [diff] [blame] | 263 | for arg, value in entry_args.items(): |
Simon Glass | 53af22a | 2018-07-17 13:25:32 -0600 | [diff] [blame] | 264 | args.append('-a%s=%s' % (arg, value)) |
Simon Glass | 0bfa7b0 | 2018-09-14 04:57:12 -0600 | [diff] [blame] | 265 | if images: |
| 266 | for image in images: |
| 267 | args += ['-i', image] |
Simon Glass | 7fe9173 | 2017-11-13 18:55:00 -0700 | [diff] [blame] | 268 | return self._DoBinman(*args) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 269 | |
| 270 | def _SetupDtb(self, fname, outfile='u-boot.dtb'): |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 271 | """Set up a new test device-tree file |
| 272 | |
| 273 | The given file is compiled and set up as the device tree to be used |
| 274 | for ths test. |
| 275 | |
| 276 | Args: |
| 277 | fname: Filename of .dts file to read |
Simon Glass | 7ae5f31 | 2018-06-01 09:38:19 -0600 | [diff] [blame] | 278 | outfile: Output filename for compiled device-tree binary |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 279 | |
| 280 | Returns: |
Simon Glass | 7ae5f31 | 2018-06-01 09:38:19 -0600 | [diff] [blame] | 281 | Contents of device-tree binary |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 282 | """ |
Simon Glass | e0e6275 | 2018-10-01 21:12:41 -0600 | [diff] [blame] | 283 | tools.PrepareOutputDir(None) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 284 | dtb = fdt_util.EnsureCompiled(self.TestFile(fname)) |
Simon Glass | 1d0ebf7 | 2019-05-14 15:53:42 -0600 | [diff] [blame] | 285 | with open(dtb, 'rb') as fd: |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 286 | data = fd.read() |
| 287 | TestFunctional._MakeInputFile(outfile, data) |
Simon Glass | e0e6275 | 2018-10-01 21:12:41 -0600 | [diff] [blame] | 288 | tools.FinaliseOutputDir() |
| 289 | return data |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 290 | |
Simon Glass | 6ed45ba | 2018-09-14 04:57:24 -0600 | [diff] [blame] | 291 | def _GetDtbContentsForSplTpl(self, dtb_data, name): |
| 292 | """Create a version of the main DTB for SPL or SPL |
| 293 | |
| 294 | For testing we don't actually have different versions of the DTB. With |
| 295 | U-Boot we normally run fdtgrep to remove unwanted nodes, but for tests |
| 296 | we don't normally have any unwanted nodes. |
| 297 | |
| 298 | We still want the DTBs for SPL and TPL to be different though, since |
| 299 | otherwise it is confusing to know which one we are looking at. So add |
| 300 | an 'spl' or 'tpl' property to the top-level node. |
| 301 | """ |
| 302 | dtb = fdt.Fdt.FromData(dtb_data) |
| 303 | dtb.Scan() |
| 304 | dtb.GetNode('/binman').AddZeroProp(name) |
| 305 | dtb.Sync(auto_resize=True) |
| 306 | dtb.Pack() |
| 307 | return dtb.GetContents() |
| 308 | |
Simon Glass | 16b8d6b | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 309 | def _DoReadFileDtb(self, fname, use_real_dtb=False, map=False, |
Simon Glass | 6ed45ba | 2018-09-14 04:57:24 -0600 | [diff] [blame] | 310 | update_dtb=False, entry_args=None, reset_dtbs=True): |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 311 | """Run binman and return the resulting image |
| 312 | |
| 313 | This runs binman with a given test file and then reads the resulting |
| 314 | output file. It is a shortcut function since most tests need to do |
| 315 | these steps. |
| 316 | |
| 317 | Raises an assertion failure if binman returns a non-zero exit code. |
| 318 | |
| 319 | Args: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 320 | fname: Device-tree source filename to use (e.g. 005_simple.dts) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 321 | use_real_dtb: True to use the test file as the contents of |
| 322 | the u-boot-dtb entry. Normally this is not needed and the |
| 323 | test contents (the U_BOOT_DTB_DATA string) can be used. |
| 324 | But in some test we need the real contents. |
Simon Glass | 3b0c382 | 2018-06-01 09:38:20 -0600 | [diff] [blame] | 325 | map: True to output map files for the images |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 326 | update_dtb: Update the offset and size of each entry in the device |
Simon Glass | 16b8d6b | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 327 | tree before packing it into the image |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 328 | |
| 329 | Returns: |
| 330 | Tuple: |
| 331 | Resulting image contents |
| 332 | Device tree contents |
Simon Glass | 3b0c382 | 2018-06-01 09:38:20 -0600 | [diff] [blame] | 333 | Map data showing contents of image (or None if none) |
Simon Glass | ea6922e | 2018-07-17 13:25:27 -0600 | [diff] [blame] | 334 | Output device tree binary filename ('u-boot.dtb' path) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 335 | """ |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 336 | dtb_data = None |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 337 | # Use the compiled test file as the u-boot-dtb input |
| 338 | if use_real_dtb: |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 339 | dtb_data = self._SetupDtb(fname) |
Simon Glass | 6ed45ba | 2018-09-14 04:57:24 -0600 | [diff] [blame] | 340 | |
| 341 | # For testing purposes, make a copy of the DT for SPL and TPL. Add |
| 342 | # a node indicating which it is, so aid verification. |
| 343 | for name in ['spl', 'tpl']: |
| 344 | dtb_fname = '%s/u-boot-%s.dtb' % (name, name) |
| 345 | outfile = os.path.join(self._indir, dtb_fname) |
| 346 | TestFunctional._MakeInputFile(dtb_fname, |
| 347 | self._GetDtbContentsForSplTpl(dtb_data, name)) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 348 | |
| 349 | try: |
Simon Glass | 53af22a | 2018-07-17 13:25:32 -0600 | [diff] [blame] | 350 | retcode = self._DoTestFile(fname, map=map, update_dtb=update_dtb, |
Simon Glass | 6ed45ba | 2018-09-14 04:57:24 -0600 | [diff] [blame] | 351 | entry_args=entry_args, use_real_dtb=use_real_dtb) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 352 | self.assertEqual(0, retcode) |
Simon Glass | 6ed45ba | 2018-09-14 04:57:24 -0600 | [diff] [blame] | 353 | out_dtb_fname = tools.GetOutputFilename('u-boot.dtb.out') |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 354 | |
| 355 | # Find the (only) image, read it and return its contents |
| 356 | image = control.images['image'] |
Simon Glass | 16b8d6b | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 357 | image_fname = tools.GetOutputFilename('image.bin') |
| 358 | self.assertTrue(os.path.exists(image_fname)) |
Simon Glass | 3b0c382 | 2018-06-01 09:38:20 -0600 | [diff] [blame] | 359 | if map: |
| 360 | map_fname = tools.GetOutputFilename('image.map') |
| 361 | with open(map_fname) as fd: |
| 362 | map_data = fd.read() |
| 363 | else: |
| 364 | map_data = None |
Simon Glass | 1d0ebf7 | 2019-05-14 15:53:42 -0600 | [diff] [blame] | 365 | with open(image_fname, 'rb') as fd: |
Simon Glass | 16b8d6b | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 366 | return fd.read(), dtb_data, map_data, out_dtb_fname |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 367 | finally: |
| 368 | # Put the test file back |
Simon Glass | 6ed45ba | 2018-09-14 04:57:24 -0600 | [diff] [blame] | 369 | if reset_dtbs and use_real_dtb: |
Simon Glass | b8ef5b6 | 2018-07-17 13:25:48 -0600 | [diff] [blame] | 370 | self._ResetDtbs() |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 371 | |
Simon Glass | 3c08131 | 2019-07-08 14:25:26 -0600 | [diff] [blame] | 372 | def _DoReadFileRealDtb(self, fname): |
| 373 | """Run binman with a real .dtb file and return the resulting data |
| 374 | |
| 375 | Args: |
| 376 | fname: DT source filename to use (e.g. 082_fdt_update_all.dts) |
| 377 | |
| 378 | Returns: |
| 379 | Resulting image contents |
| 380 | """ |
| 381 | return self._DoReadFileDtb(fname, use_real_dtb=True, update_dtb=True)[0] |
| 382 | |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 383 | def _DoReadFile(self, fname, use_real_dtb=False): |
Simon Glass | 7ae5f31 | 2018-06-01 09:38:19 -0600 | [diff] [blame] | 384 | """Helper function which discards the device-tree binary |
| 385 | |
| 386 | Args: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 387 | fname: Device-tree source filename to use (e.g. 005_simple.dts) |
Simon Glass | 7ae5f31 | 2018-06-01 09:38:19 -0600 | [diff] [blame] | 388 | use_real_dtb: True to use the test file as the contents of |
| 389 | the u-boot-dtb entry. Normally this is not needed and the |
| 390 | test contents (the U_BOOT_DTB_DATA string) can be used. |
| 391 | But in some test we need the real contents. |
Simon Glass | ea6922e | 2018-07-17 13:25:27 -0600 | [diff] [blame] | 392 | |
| 393 | Returns: |
| 394 | Resulting image contents |
Simon Glass | 7ae5f31 | 2018-06-01 09:38:19 -0600 | [diff] [blame] | 395 | """ |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 396 | return self._DoReadFileDtb(fname, use_real_dtb)[0] |
| 397 | |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 398 | @classmethod |
| 399 | def _MakeInputFile(self, fname, contents): |
| 400 | """Create a new test input file, creating directories as needed |
| 401 | |
| 402 | Args: |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 403 | fname: Filename to create |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 404 | contents: File contents to write in to the file |
| 405 | Returns: |
| 406 | Full pathname of file created |
| 407 | """ |
| 408 | pathname = os.path.join(self._indir, fname) |
| 409 | dirname = os.path.dirname(pathname) |
| 410 | if dirname and not os.path.exists(dirname): |
| 411 | os.makedirs(dirname) |
| 412 | with open(pathname, 'wb') as fd: |
| 413 | fd.write(contents) |
| 414 | return pathname |
| 415 | |
| 416 | @classmethod |
Simon Glass | 0ef87aa | 2018-07-17 13:25:44 -0600 | [diff] [blame] | 417 | def _MakeInputDir(self, dirname): |
| 418 | """Create a new test input directory, creating directories as needed |
| 419 | |
| 420 | Args: |
| 421 | dirname: Directory name to create |
| 422 | |
| 423 | Returns: |
| 424 | Full pathname of directory created |
| 425 | """ |
| 426 | pathname = os.path.join(self._indir, dirname) |
| 427 | if not os.path.exists(pathname): |
| 428 | os.makedirs(pathname) |
| 429 | return pathname |
| 430 | |
| 431 | @classmethod |
Simon Glass | 11ae93e | 2018-10-01 21:12:47 -0600 | [diff] [blame] | 432 | def _SetupSplElf(self, src_fname='bss_data'): |
| 433 | """Set up an ELF file with a '_dt_ucode_base_size' symbol |
| 434 | |
| 435 | Args: |
| 436 | Filename of ELF file to use as SPL |
| 437 | """ |
Simon Glass | 1d0ebf7 | 2019-05-14 15:53:42 -0600 | [diff] [blame] | 438 | with open(self.TestFile(src_fname), 'rb') as fd: |
Simon Glass | 11ae93e | 2018-10-01 21:12:47 -0600 | [diff] [blame] | 439 | TestFunctional._MakeInputFile('spl/u-boot-spl', fd.read()) |
| 440 | |
| 441 | @classmethod |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 442 | def TestFile(self, fname): |
| 443 | return os.path.join(self._binman_dir, 'test', fname) |
| 444 | |
| 445 | def AssertInList(self, grep_list, target): |
| 446 | """Assert that at least one of a list of things is in a target |
| 447 | |
| 448 | Args: |
| 449 | grep_list: List of strings to check |
| 450 | target: Target string |
| 451 | """ |
| 452 | for grep in grep_list: |
| 453 | if grep in target: |
| 454 | return |
Simon Glass | 1fc62de | 2019-05-17 22:00:50 -0600 | [diff] [blame] | 455 | self.fail("Error: '%s' not found in '%s'" % (grep_list, target)) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 456 | |
| 457 | def CheckNoGaps(self, entries): |
| 458 | """Check that all entries fit together without gaps |
| 459 | |
| 460 | Args: |
| 461 | entries: List of entries to check |
| 462 | """ |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 463 | offset = 0 |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 464 | for entry in entries.values(): |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 465 | self.assertEqual(offset, entry.offset) |
| 466 | offset += entry.size |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 467 | |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 468 | def GetFdtLen(self, dtb): |
Simon Glass | 7ae5f31 | 2018-06-01 09:38:19 -0600 | [diff] [blame] | 469 | """Get the totalsize field from a device-tree binary |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 470 | |
| 471 | Args: |
Simon Glass | 7ae5f31 | 2018-06-01 09:38:19 -0600 | [diff] [blame] | 472 | dtb: Device-tree binary contents |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 473 | |
| 474 | Returns: |
Simon Glass | 7ae5f31 | 2018-06-01 09:38:19 -0600 | [diff] [blame] | 475 | Total size of device-tree binary, from the header |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 476 | """ |
| 477 | return struct.unpack('>L', dtb[4:8])[0] |
| 478 | |
Simon Glass | 086cec9 | 2019-07-08 14:25:27 -0600 | [diff] [blame] | 479 | def _GetPropTree(self, dtb, prop_names, prefix='/binman/'): |
Simon Glass | 16b8d6b | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 480 | def AddNode(node, path): |
| 481 | if node.name != '/': |
| 482 | path += '/' + node.name |
Simon Glass | 086cec9 | 2019-07-08 14:25:27 -0600 | [diff] [blame] | 483 | for prop in node.props.values(): |
| 484 | if prop.name in prop_names: |
| 485 | prop_path = path + ':' + prop.name |
| 486 | tree[prop_path[len(prefix):]] = fdt_util.fdt32_to_cpu( |
| 487 | prop.value) |
Simon Glass | 16b8d6b | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 488 | for subnode in node.subnodes: |
Simon Glass | 16b8d6b | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 489 | AddNode(subnode, path) |
| 490 | |
| 491 | tree = {} |
Simon Glass | 16b8d6b | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 492 | AddNode(dtb.GetRoot(), '') |
| 493 | return tree |
| 494 | |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 495 | def testRun(self): |
| 496 | """Test a basic run with valid args""" |
| 497 | result = self._RunBinman('-h') |
| 498 | |
| 499 | def testFullHelp(self): |
| 500 | """Test that the full help is displayed with -H""" |
| 501 | result = self._RunBinman('-H') |
| 502 | help_file = os.path.join(self._binman_dir, 'README') |
Tom Rini | 3759df0 | 2018-01-16 15:29:50 -0500 | [diff] [blame] | 503 | # Remove possible extraneous strings |
| 504 | extra = '::::::::::::::\n' + help_file + '\n::::::::::::::\n' |
| 505 | gothelp = result.stdout.replace(extra, '') |
| 506 | self.assertEqual(len(gothelp), os.path.getsize(help_file)) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 507 | self.assertEqual(0, len(result.stderr)) |
| 508 | self.assertEqual(0, result.return_code) |
| 509 | |
| 510 | def testFullHelpInternal(self): |
| 511 | """Test that the full help is displayed with -H""" |
| 512 | try: |
| 513 | command.test_result = command.CommandResult() |
| 514 | result = self._DoBinman('-H') |
| 515 | help_file = os.path.join(self._binman_dir, 'README') |
| 516 | finally: |
| 517 | command.test_result = None |
| 518 | |
| 519 | def testHelp(self): |
| 520 | """Test that the basic help is displayed with -h""" |
| 521 | result = self._RunBinman('-h') |
| 522 | self.assertTrue(len(result.stdout) > 200) |
| 523 | self.assertEqual(0, len(result.stderr)) |
| 524 | self.assertEqual(0, result.return_code) |
| 525 | |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 526 | def testBoard(self): |
| 527 | """Test that we can run it with a specific board""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 528 | self._SetupDtb('005_simple.dts', 'sandbox/u-boot.dtb') |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 529 | TestFunctional._MakeInputFile('sandbox/u-boot.bin', U_BOOT_DATA) |
Simon Glass | 53cd5d9 | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 530 | result = self._DoBinman('build', '-b', 'sandbox') |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 531 | self.assertEqual(0, result) |
| 532 | |
| 533 | def testNeedBoard(self): |
| 534 | """Test that we get an error when no board ius supplied""" |
| 535 | with self.assertRaises(ValueError) as e: |
Simon Glass | 53cd5d9 | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 536 | result = self._DoBinman('build') |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 537 | self.assertIn("Must provide a board to process (use -b <board>)", |
| 538 | str(e.exception)) |
| 539 | |
| 540 | def testMissingDt(self): |
Simon Glass | 7ae5f31 | 2018-06-01 09:38:19 -0600 | [diff] [blame] | 541 | """Test that an invalid device-tree file generates an error""" |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 542 | with self.assertRaises(Exception) as e: |
Simon Glass | 53cd5d9 | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 543 | self._RunBinman('build', '-d', 'missing_file') |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 544 | # We get one error from libfdt, and a different one from fdtget. |
| 545 | self.AssertInList(["Couldn't open blob from 'missing_file'", |
| 546 | 'No such file or directory'], str(e.exception)) |
| 547 | |
| 548 | def testBrokenDt(self): |
Simon Glass | 7ae5f31 | 2018-06-01 09:38:19 -0600 | [diff] [blame] | 549 | """Test that an invalid device-tree source file generates an error |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 550 | |
| 551 | Since this is a source file it should be compiled and the error |
| 552 | will come from the device-tree compiler (dtc). |
| 553 | """ |
| 554 | with self.assertRaises(Exception) as e: |
Simon Glass | 53cd5d9 | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 555 | self._RunBinman('build', '-d', self.TestFile('001_invalid.dts')) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 556 | self.assertIn("FATAL ERROR: Unable to parse input tree", |
| 557 | str(e.exception)) |
| 558 | |
| 559 | def testMissingNode(self): |
| 560 | """Test that a device tree without a 'binman' node generates an error""" |
| 561 | with self.assertRaises(Exception) as e: |
Simon Glass | 53cd5d9 | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 562 | self._DoBinman('build', '-d', self.TestFile('002_missing_node.dts')) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 563 | self.assertIn("does not have a 'binman' node", str(e.exception)) |
| 564 | |
| 565 | def testEmpty(self): |
| 566 | """Test that an empty binman node works OK (i.e. does nothing)""" |
Simon Glass | 53cd5d9 | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 567 | result = self._RunBinman('build', '-d', self.TestFile('003_empty.dts')) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 568 | self.assertEqual(0, len(result.stderr)) |
| 569 | self.assertEqual(0, result.return_code) |
| 570 | |
| 571 | def testInvalidEntry(self): |
| 572 | """Test that an invalid entry is flagged""" |
| 573 | with self.assertRaises(Exception) as e: |
Simon Glass | 53cd5d9 | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 574 | result = self._RunBinman('build', '-d', |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 575 | self.TestFile('004_invalid_entry.dts')) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 576 | self.assertIn("Unknown entry type 'not-a-valid-type' in node " |
| 577 | "'/binman/not-a-valid-type'", str(e.exception)) |
| 578 | |
| 579 | def testSimple(self): |
| 580 | """Test a simple binman with a single file""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 581 | data = self._DoReadFile('005_simple.dts') |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 582 | self.assertEqual(U_BOOT_DATA, data) |
| 583 | |
Simon Glass | 7fe9173 | 2017-11-13 18:55:00 -0700 | [diff] [blame] | 584 | def testSimpleDebug(self): |
| 585 | """Test a simple binman run with debugging enabled""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 586 | data = self._DoTestFile('005_simple.dts', debug=True) |
Simon Glass | 7fe9173 | 2017-11-13 18:55:00 -0700 | [diff] [blame] | 587 | |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 588 | def testDual(self): |
| 589 | """Test that we can handle creating two images |
| 590 | |
| 591 | This also tests image padding. |
| 592 | """ |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 593 | retcode = self._DoTestFile('006_dual_image.dts') |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 594 | self.assertEqual(0, retcode) |
| 595 | |
| 596 | image = control.images['image1'] |
| 597 | self.assertEqual(len(U_BOOT_DATA), image._size) |
| 598 | fname = tools.GetOutputFilename('image1.bin') |
| 599 | self.assertTrue(os.path.exists(fname)) |
Simon Glass | 1d0ebf7 | 2019-05-14 15:53:42 -0600 | [diff] [blame] | 600 | with open(fname, 'rb') as fd: |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 601 | data = fd.read() |
| 602 | self.assertEqual(U_BOOT_DATA, data) |
| 603 | |
| 604 | image = control.images['image2'] |
| 605 | self.assertEqual(3 + len(U_BOOT_DATA) + 5, image._size) |
| 606 | fname = tools.GetOutputFilename('image2.bin') |
| 607 | self.assertTrue(os.path.exists(fname)) |
Simon Glass | 1d0ebf7 | 2019-05-14 15:53:42 -0600 | [diff] [blame] | 608 | with open(fname, 'rb') as fd: |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 609 | data = fd.read() |
| 610 | self.assertEqual(U_BOOT_DATA, data[3:7]) |
Simon Glass | e6d85ff | 2019-05-14 15:53:47 -0600 | [diff] [blame] | 611 | self.assertEqual(tools.GetBytes(0, 3), data[:3]) |
| 612 | self.assertEqual(tools.GetBytes(0, 5), data[7:]) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 613 | |
| 614 | def testBadAlign(self): |
| 615 | """Test that an invalid alignment value is detected""" |
| 616 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 617 | self._DoTestFile('007_bad_align.dts') |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 618 | self.assertIn("Node '/binman/u-boot': Alignment 23 must be a power " |
| 619 | "of two", str(e.exception)) |
| 620 | |
| 621 | def testPackSimple(self): |
| 622 | """Test that packing works as expected""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 623 | retcode = self._DoTestFile('008_pack.dts') |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 624 | self.assertEqual(0, retcode) |
| 625 | self.assertIn('image', control.images) |
| 626 | image = control.images['image'] |
Simon Glass | 8f1da50 | 2018-06-01 09:38:12 -0600 | [diff] [blame] | 627 | entries = image.GetEntries() |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 628 | self.assertEqual(5, len(entries)) |
| 629 | |
| 630 | # First u-boot |
| 631 | self.assertIn('u-boot', entries) |
| 632 | entry = entries['u-boot'] |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 633 | self.assertEqual(0, entry.offset) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 634 | self.assertEqual(len(U_BOOT_DATA), entry.size) |
| 635 | |
| 636 | # Second u-boot, aligned to 16-byte boundary |
| 637 | self.assertIn('u-boot-align', entries) |
| 638 | entry = entries['u-boot-align'] |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 639 | self.assertEqual(16, entry.offset) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 640 | self.assertEqual(len(U_BOOT_DATA), entry.size) |
| 641 | |
| 642 | # Third u-boot, size 23 bytes |
| 643 | self.assertIn('u-boot-size', entries) |
| 644 | entry = entries['u-boot-size'] |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 645 | self.assertEqual(20, entry.offset) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 646 | self.assertEqual(len(U_BOOT_DATA), entry.contents_size) |
| 647 | self.assertEqual(23, entry.size) |
| 648 | |
| 649 | # Fourth u-boot, placed immediate after the above |
| 650 | self.assertIn('u-boot-next', entries) |
| 651 | entry = entries['u-boot-next'] |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 652 | self.assertEqual(43, entry.offset) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 653 | self.assertEqual(len(U_BOOT_DATA), entry.size) |
| 654 | |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 655 | # Fifth u-boot, placed at a fixed offset |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 656 | self.assertIn('u-boot-fixed', entries) |
| 657 | entry = entries['u-boot-fixed'] |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 658 | self.assertEqual(61, entry.offset) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 659 | self.assertEqual(len(U_BOOT_DATA), entry.size) |
| 660 | |
| 661 | self.assertEqual(65, image._size) |
| 662 | |
| 663 | def testPackExtra(self): |
| 664 | """Test that extra packing feature works as expected""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 665 | retcode = self._DoTestFile('009_pack_extra.dts') |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 666 | |
| 667 | self.assertEqual(0, retcode) |
| 668 | self.assertIn('image', control.images) |
| 669 | image = control.images['image'] |
Simon Glass | 8f1da50 | 2018-06-01 09:38:12 -0600 | [diff] [blame] | 670 | entries = image.GetEntries() |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 671 | self.assertEqual(5, len(entries)) |
| 672 | |
| 673 | # First u-boot with padding before and after |
| 674 | self.assertIn('u-boot', entries) |
| 675 | entry = entries['u-boot'] |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 676 | self.assertEqual(0, entry.offset) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 677 | self.assertEqual(3, entry.pad_before) |
| 678 | self.assertEqual(3 + 5 + len(U_BOOT_DATA), entry.size) |
| 679 | |
| 680 | # Second u-boot has an aligned size, but it has no effect |
| 681 | self.assertIn('u-boot-align-size-nop', entries) |
| 682 | entry = entries['u-boot-align-size-nop'] |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 683 | self.assertEqual(12, entry.offset) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 684 | self.assertEqual(4, entry.size) |
| 685 | |
| 686 | # Third u-boot has an aligned size too |
| 687 | self.assertIn('u-boot-align-size', entries) |
| 688 | entry = entries['u-boot-align-size'] |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 689 | self.assertEqual(16, entry.offset) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 690 | self.assertEqual(32, entry.size) |
| 691 | |
| 692 | # Fourth u-boot has an aligned end |
| 693 | self.assertIn('u-boot-align-end', entries) |
| 694 | entry = entries['u-boot-align-end'] |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 695 | self.assertEqual(48, entry.offset) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 696 | self.assertEqual(16, entry.size) |
| 697 | |
| 698 | # Fifth u-boot immediately afterwards |
| 699 | self.assertIn('u-boot-align-both', entries) |
| 700 | entry = entries['u-boot-align-both'] |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 701 | self.assertEqual(64, entry.offset) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 702 | self.assertEqual(64, entry.size) |
| 703 | |
| 704 | self.CheckNoGaps(entries) |
| 705 | self.assertEqual(128, image._size) |
| 706 | |
| 707 | def testPackAlignPowerOf2(self): |
| 708 | """Test that invalid entry alignment is detected""" |
| 709 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 710 | self._DoTestFile('010_pack_align_power2.dts') |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 711 | self.assertIn("Node '/binman/u-boot': Alignment 5 must be a power " |
| 712 | "of two", str(e.exception)) |
| 713 | |
| 714 | def testPackAlignSizePowerOf2(self): |
| 715 | """Test that invalid entry size alignment is detected""" |
| 716 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 717 | self._DoTestFile('011_pack_align_size_power2.dts') |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 718 | self.assertIn("Node '/binman/u-boot': Alignment size 55 must be a " |
| 719 | "power of two", str(e.exception)) |
| 720 | |
| 721 | def testPackInvalidAlign(self): |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 722 | """Test detection of an offset that does not match its alignment""" |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 723 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 724 | self._DoTestFile('012_pack_inv_align.dts') |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 725 | self.assertIn("Node '/binman/u-boot': Offset 0x5 (5) does not match " |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 726 | "align 0x4 (4)", str(e.exception)) |
| 727 | |
| 728 | def testPackInvalidSizeAlign(self): |
| 729 | """Test that invalid entry size alignment is detected""" |
| 730 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 731 | self._DoTestFile('013_pack_inv_size_align.dts') |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 732 | self.assertIn("Node '/binman/u-boot': Size 0x5 (5) does not match " |
| 733 | "align-size 0x4 (4)", str(e.exception)) |
| 734 | |
| 735 | def testPackOverlap(self): |
| 736 | """Test that overlapping regions are detected""" |
| 737 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 738 | self._DoTestFile('014_pack_overlap.dts') |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 739 | self.assertIn("Node '/binman/u-boot-align': Offset 0x3 (3) overlaps " |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 740 | "with previous entry '/binman/u-boot' ending at 0x4 (4)", |
| 741 | str(e.exception)) |
| 742 | |
| 743 | def testPackEntryOverflow(self): |
| 744 | """Test that entries that overflow their size are detected""" |
| 745 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 746 | self._DoTestFile('015_pack_overflow.dts') |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 747 | self.assertIn("Node '/binman/u-boot': Entry contents size is 0x4 (4) " |
| 748 | "but entry size is 0x3 (3)", str(e.exception)) |
| 749 | |
| 750 | def testPackImageOverflow(self): |
| 751 | """Test that entries which overflow the image size are detected""" |
| 752 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 753 | self._DoTestFile('016_pack_image_overflow.dts') |
Simon Glass | 8f1da50 | 2018-06-01 09:38:12 -0600 | [diff] [blame] | 754 | self.assertIn("Section '/binman': contents size 0x4 (4) exceeds section " |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 755 | "size 0x3 (3)", str(e.exception)) |
| 756 | |
| 757 | def testPackImageSize(self): |
| 758 | """Test that the image size can be set""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 759 | retcode = self._DoTestFile('017_pack_image_size.dts') |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 760 | self.assertEqual(0, retcode) |
| 761 | self.assertIn('image', control.images) |
| 762 | image = control.images['image'] |
| 763 | self.assertEqual(7, image._size) |
| 764 | |
| 765 | def testPackImageSizeAlign(self): |
| 766 | """Test that image size alignemnt works as expected""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 767 | retcode = self._DoTestFile('018_pack_image_align.dts') |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 768 | self.assertEqual(0, retcode) |
| 769 | self.assertIn('image', control.images) |
| 770 | image = control.images['image'] |
| 771 | self.assertEqual(16, image._size) |
| 772 | |
| 773 | def testPackInvalidImageAlign(self): |
| 774 | """Test that invalid image alignment is detected""" |
| 775 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 776 | self._DoTestFile('019_pack_inv_image_align.dts') |
Simon Glass | 8f1da50 | 2018-06-01 09:38:12 -0600 | [diff] [blame] | 777 | self.assertIn("Section '/binman': Size 0x7 (7) does not match " |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 778 | "align-size 0x8 (8)", str(e.exception)) |
| 779 | |
| 780 | def testPackAlignPowerOf2(self): |
| 781 | """Test that invalid image alignment is detected""" |
| 782 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 783 | self._DoTestFile('020_pack_inv_image_align_power2.dts') |
Simon Glass | 8f1da50 | 2018-06-01 09:38:12 -0600 | [diff] [blame] | 784 | self.assertIn("Section '/binman': Alignment size 131 must be a power of " |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 785 | "two", str(e.exception)) |
| 786 | |
| 787 | def testImagePadByte(self): |
| 788 | """Test that the image pad byte can be specified""" |
Simon Glass | 11ae93e | 2018-10-01 21:12:47 -0600 | [diff] [blame] | 789 | self._SetupSplElf() |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 790 | data = self._DoReadFile('021_image_pad.dts') |
Simon Glass | e6d85ff | 2019-05-14 15:53:47 -0600 | [diff] [blame] | 791 | self.assertEqual(U_BOOT_SPL_DATA + tools.GetBytes(0xff, 1) + |
| 792 | U_BOOT_DATA, data) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 793 | |
| 794 | def testImageName(self): |
| 795 | """Test that image files can be named""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 796 | retcode = self._DoTestFile('022_image_name.dts') |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 797 | self.assertEqual(0, retcode) |
| 798 | image = control.images['image1'] |
| 799 | fname = tools.GetOutputFilename('test-name') |
| 800 | self.assertTrue(os.path.exists(fname)) |
| 801 | |
| 802 | image = control.images['image2'] |
| 803 | fname = tools.GetOutputFilename('test-name.xx') |
| 804 | self.assertTrue(os.path.exists(fname)) |
| 805 | |
| 806 | def testBlobFilename(self): |
| 807 | """Test that generic blobs can be provided by filename""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 808 | data = self._DoReadFile('023_blob.dts') |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 809 | self.assertEqual(BLOB_DATA, data) |
| 810 | |
| 811 | def testPackSorted(self): |
| 812 | """Test that entries can be sorted""" |
Simon Glass | 11ae93e | 2018-10-01 21:12:47 -0600 | [diff] [blame] | 813 | self._SetupSplElf() |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 814 | data = self._DoReadFile('024_sorted.dts') |
Simon Glass | e6d85ff | 2019-05-14 15:53:47 -0600 | [diff] [blame] | 815 | self.assertEqual(tools.GetBytes(0, 1) + U_BOOT_SPL_DATA + |
| 816 | tools.GetBytes(0, 2) + U_BOOT_DATA, data) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 817 | |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 818 | def testPackZeroOffset(self): |
| 819 | """Test that an entry at offset 0 is not given a new offset""" |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 820 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 821 | self._DoTestFile('025_pack_zero_size.dts') |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 822 | self.assertIn("Node '/binman/u-boot-spl': Offset 0x0 (0) overlaps " |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 823 | "with previous entry '/binman/u-boot' ending at 0x4 (4)", |
| 824 | str(e.exception)) |
| 825 | |
| 826 | def testPackUbootDtb(self): |
| 827 | """Test that a device tree can be added to U-Boot""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 828 | data = self._DoReadFile('026_pack_u_boot_dtb.dts') |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 829 | self.assertEqual(U_BOOT_NODTB_DATA + U_BOOT_DTB_DATA, data) |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 830 | |
| 831 | def testPackX86RomNoSize(self): |
| 832 | """Test that the end-at-4gb property requires a size property""" |
| 833 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 834 | self._DoTestFile('027_pack_4gb_no_size.dts') |
Simon Glass | 8f1da50 | 2018-06-01 09:38:12 -0600 | [diff] [blame] | 835 | self.assertIn("Section '/binman': Section size must be provided when " |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 836 | "using end-at-4gb", str(e.exception)) |
| 837 | |
Jagdish Gediya | 94b57db | 2018-09-03 21:35:07 +0530 | [diff] [blame] | 838 | def test4gbAndSkipAtStartTogether(self): |
| 839 | """Test that the end-at-4gb and skip-at-size property can't be used |
| 840 | together""" |
| 841 | with self.assertRaises(ValueError) as e: |
| 842 | self._DoTestFile('80_4gb_and_skip_at_start_together.dts') |
| 843 | self.assertIn("Section '/binman': Provide either 'end-at-4gb' or " |
| 844 | "'skip-at-start'", str(e.exception)) |
| 845 | |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 846 | def testPackX86RomOutside(self): |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 847 | """Test that the end-at-4gb property checks for offset boundaries""" |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 848 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 849 | self._DoTestFile('028_pack_4gb_outside.dts') |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 850 | self.assertIn("Node '/binman/u-boot': Offset 0x0 (0) is outside " |
Simon Glass | 8f1da50 | 2018-06-01 09:38:12 -0600 | [diff] [blame] | 851 | "the section starting at 0xffffffe0 (4294967264)", |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 852 | str(e.exception)) |
| 853 | |
| 854 | def testPackX86Rom(self): |
| 855 | """Test that a basic x86 ROM can be created""" |
Simon Glass | 11ae93e | 2018-10-01 21:12:47 -0600 | [diff] [blame] | 856 | self._SetupSplElf() |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 857 | data = self._DoReadFile('029_x86-rom.dts') |
Simon Glass | e6d85ff | 2019-05-14 15:53:47 -0600 | [diff] [blame] | 858 | self.assertEqual(U_BOOT_DATA + tools.GetBytes(0, 7) + U_BOOT_SPL_DATA + |
| 859 | tools.GetBytes(0, 2), data) |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 860 | |
| 861 | def testPackX86RomMeNoDesc(self): |
| 862 | """Test that an invalid Intel descriptor entry is detected""" |
Simon Glass | c6c10e7 | 2019-05-17 22:00:46 -0600 | [diff] [blame] | 863 | TestFunctional._MakeInputFile('descriptor.bin', b'') |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 864 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 865 | self._DoTestFile('031_x86-rom-me.dts') |
Simon Glass | 458be45 | 2019-07-08 13:18:32 -0600 | [diff] [blame] | 866 | self.assertIn("Node '/binman/intel-descriptor': Cannot find Intel Flash Descriptor (FD) signature", |
| 867 | str(e.exception)) |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 868 | |
| 869 | def testPackX86RomBadDesc(self): |
| 870 | """Test that the Intel requires a descriptor entry""" |
| 871 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 872 | self._DoTestFile('030_x86-rom-me-no-desc.dts') |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 873 | self.assertIn("Node '/binman/intel-me': No offset set with " |
| 874 | "offset-unset: should another entry provide this correct " |
| 875 | "offset?", str(e.exception)) |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 876 | |
| 877 | def testPackX86RomMe(self): |
| 878 | """Test that an x86 ROM with an ME region can be created""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 879 | data = self._DoReadFile('031_x86-rom-me.dts') |
Simon Glass | c5ac138 | 2019-07-08 13:18:54 -0600 | [diff] [blame] | 880 | expected_desc = tools.ReadFile(self.TestFile('descriptor.bin')) |
| 881 | if data[:0x1000] != expected_desc: |
| 882 | self.fail('Expected descriptor binary at start of image') |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 883 | self.assertEqual(ME_DATA, data[0x1000:0x1000 + len(ME_DATA)]) |
| 884 | |
| 885 | def testPackVga(self): |
| 886 | """Test that an image with a VGA binary can be created""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 887 | data = self._DoReadFile('032_intel-vga.dts') |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 888 | self.assertEqual(VGA_DATA, data[:len(VGA_DATA)]) |
| 889 | |
| 890 | def testPackStart16(self): |
| 891 | """Test that an image with an x86 start16 region can be created""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 892 | data = self._DoReadFile('033_x86-start16.dts') |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 893 | self.assertEqual(X86_START16_DATA, data[:len(X86_START16_DATA)]) |
| 894 | |
Jagdish Gediya | 9d368f3 | 2018-09-03 21:35:08 +0530 | [diff] [blame] | 895 | def testPackPowerpcMpc85xxBootpgResetvec(self): |
| 896 | """Test that an image with powerpc-mpc85xx-bootpg-resetvec can be |
| 897 | created""" |
| 898 | data = self._DoReadFile('81_powerpc_mpc85xx_bootpg_resetvec.dts') |
| 899 | self.assertEqual(PPC_MPC85XX_BR_DATA, data[:len(PPC_MPC85XX_BR_DATA)]) |
| 900 | |
Simon Glass | 736bb0a | 2018-07-06 10:27:17 -0600 | [diff] [blame] | 901 | def _RunMicrocodeTest(self, dts_fname, nodtb_data, ucode_second=False): |
Simon Glass | adc5701 | 2018-07-06 10:27:16 -0600 | [diff] [blame] | 902 | """Handle running a test for insertion of microcode |
| 903 | |
| 904 | Args: |
| 905 | dts_fname: Name of test .dts file |
| 906 | nodtb_data: Data that we expect in the first section |
Simon Glass | 736bb0a | 2018-07-06 10:27:17 -0600 | [diff] [blame] | 907 | ucode_second: True if the microsecond entry is second instead of |
| 908 | third |
Simon Glass | adc5701 | 2018-07-06 10:27:16 -0600 | [diff] [blame] | 909 | |
| 910 | Returns: |
| 911 | Tuple: |
| 912 | Contents of first region (U-Boot or SPL) |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 913 | Offset and size components of microcode pointer, as inserted |
Simon Glass | adc5701 | 2018-07-06 10:27:16 -0600 | [diff] [blame] | 914 | in the above (two 4-byte words) |
| 915 | """ |
Simon Glass | 6b187df | 2017-11-12 21:52:27 -0700 | [diff] [blame] | 916 | data = self._DoReadFile(dts_fname, True) |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 917 | |
| 918 | # Now check the device tree has no microcode |
Simon Glass | 736bb0a | 2018-07-06 10:27:17 -0600 | [diff] [blame] | 919 | if ucode_second: |
| 920 | ucode_content = data[len(nodtb_data):] |
| 921 | ucode_pos = len(nodtb_data) |
| 922 | dtb_with_ucode = ucode_content[16:] |
| 923 | fdt_len = self.GetFdtLen(dtb_with_ucode) |
| 924 | else: |
| 925 | dtb_with_ucode = data[len(nodtb_data):] |
| 926 | fdt_len = self.GetFdtLen(dtb_with_ucode) |
| 927 | ucode_content = dtb_with_ucode[fdt_len:] |
| 928 | ucode_pos = len(nodtb_data) + fdt_len |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 929 | fname = tools.GetOutputFilename('test.dtb') |
| 930 | with open(fname, 'wb') as fd: |
Simon Glass | adc5701 | 2018-07-06 10:27:16 -0600 | [diff] [blame] | 931 | fd.write(dtb_with_ucode) |
Simon Glass | ec3f378 | 2017-05-27 07:38:29 -0600 | [diff] [blame] | 932 | dtb = fdt.FdtScan(fname) |
| 933 | ucode = dtb.GetNode('/microcode') |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 934 | self.assertTrue(ucode) |
| 935 | for node in ucode.subnodes: |
| 936 | self.assertFalse(node.props.get('data')) |
| 937 | |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 938 | # Check that the microcode appears immediately after the Fdt |
| 939 | # This matches the concatenation of the data properties in |
Simon Glass | 8772213 | 2017-11-12 21:52:26 -0700 | [diff] [blame] | 940 | # the /microcode/update@xxx nodes in 34_x86_ucode.dts. |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 941 | ucode_data = struct.pack('>4L', 0x12345678, 0x12345679, 0xabcd0000, |
| 942 | 0x78235609) |
Simon Glass | adc5701 | 2018-07-06 10:27:16 -0600 | [diff] [blame] | 943 | self.assertEqual(ucode_data, ucode_content[:len(ucode_data)]) |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 944 | |
| 945 | # Check that the microcode pointer was inserted. It should match the |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 946 | # expected offset and size |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 947 | pos_and_size = struct.pack('<2L', 0xfffffe00 + ucode_pos, |
| 948 | len(ucode_data)) |
Simon Glass | 736bb0a | 2018-07-06 10:27:17 -0600 | [diff] [blame] | 949 | u_boot = data[:len(nodtb_data)] |
| 950 | return u_boot, pos_and_size |
Simon Glass | 6b187df | 2017-11-12 21:52:27 -0700 | [diff] [blame] | 951 | |
| 952 | def testPackUbootMicrocode(self): |
| 953 | """Test that x86 microcode can be handled correctly |
| 954 | |
| 955 | We expect to see the following in the image, in order: |
| 956 | u-boot-nodtb.bin with a microcode pointer inserted at the correct |
| 957 | place |
| 958 | u-boot.dtb with the microcode removed |
| 959 | the microcode |
| 960 | """ |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 961 | first, pos_and_size = self._RunMicrocodeTest('034_x86_ucode.dts', |
Simon Glass | 6b187df | 2017-11-12 21:52:27 -0700 | [diff] [blame] | 962 | U_BOOT_NODTB_DATA) |
Simon Glass | c6c10e7 | 2019-05-17 22:00:46 -0600 | [diff] [blame] | 963 | self.assertEqual(b'nodtb with microcode' + pos_and_size + |
| 964 | b' somewhere in here', first) |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 965 | |
Simon Glass | 160a766 | 2017-05-27 07:38:26 -0600 | [diff] [blame] | 966 | def _RunPackUbootSingleMicrocode(self): |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 967 | """Test that x86 microcode can be handled correctly |
| 968 | |
| 969 | We expect to see the following in the image, in order: |
| 970 | u-boot-nodtb.bin with a microcode pointer inserted at the correct |
| 971 | place |
| 972 | u-boot.dtb with the microcode |
| 973 | an empty microcode region |
| 974 | """ |
| 975 | # We need the libfdt library to run this test since only that allows |
| 976 | # finding the offset of a property. This is required by |
| 977 | # Entry_u_boot_dtb_with_ucode.ObtainContents(). |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 978 | data = self._DoReadFile('035_x86_single_ucode.dts', True) |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 979 | |
| 980 | second = data[len(U_BOOT_NODTB_DATA):] |
| 981 | |
| 982 | fdt_len = self.GetFdtLen(second) |
| 983 | third = second[fdt_len:] |
| 984 | second = second[:fdt_len] |
| 985 | |
Simon Glass | 160a766 | 2017-05-27 07:38:26 -0600 | [diff] [blame] | 986 | ucode_data = struct.pack('>2L', 0x12345678, 0x12345679) |
| 987 | self.assertIn(ucode_data, second) |
| 988 | ucode_pos = second.find(ucode_data) + len(U_BOOT_NODTB_DATA) |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 989 | |
Simon Glass | 160a766 | 2017-05-27 07:38:26 -0600 | [diff] [blame] | 990 | # Check that the microcode pointer was inserted. It should match the |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 991 | # expected offset and size |
Simon Glass | 160a766 | 2017-05-27 07:38:26 -0600 | [diff] [blame] | 992 | pos_and_size = struct.pack('<2L', 0xfffffe00 + ucode_pos, |
| 993 | len(ucode_data)) |
| 994 | first = data[:len(U_BOOT_NODTB_DATA)] |
Simon Glass | c6c10e7 | 2019-05-17 22:00:46 -0600 | [diff] [blame] | 995 | self.assertEqual(b'nodtb with microcode' + pos_and_size + |
| 996 | b' somewhere in here', first) |
Simon Glass | c49deb8 | 2016-11-25 20:15:54 -0700 | [diff] [blame] | 997 | |
Simon Glass | 75db086 | 2016-11-25 20:15:55 -0700 | [diff] [blame] | 998 | def testPackUbootSingleMicrocode(self): |
| 999 | """Test that x86 microcode can be handled correctly with fdt_normal. |
| 1000 | """ |
Simon Glass | 160a766 | 2017-05-27 07:38:26 -0600 | [diff] [blame] | 1001 | self._RunPackUbootSingleMicrocode() |
Simon Glass | 75db086 | 2016-11-25 20:15:55 -0700 | [diff] [blame] | 1002 | |
Simon Glass | c49deb8 | 2016-11-25 20:15:54 -0700 | [diff] [blame] | 1003 | def testUBootImg(self): |
| 1004 | """Test that u-boot.img can be put in a file""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1005 | data = self._DoReadFile('036_u_boot_img.dts') |
Simon Glass | c49deb8 | 2016-11-25 20:15:54 -0700 | [diff] [blame] | 1006 | self.assertEqual(U_BOOT_IMG_DATA, data) |
Simon Glass | 75db086 | 2016-11-25 20:15:55 -0700 | [diff] [blame] | 1007 | |
| 1008 | def testNoMicrocode(self): |
| 1009 | """Test that a missing microcode region is detected""" |
| 1010 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1011 | self._DoReadFile('037_x86_no_ucode.dts', True) |
Simon Glass | 75db086 | 2016-11-25 20:15:55 -0700 | [diff] [blame] | 1012 | self.assertIn("Node '/binman/u-boot-dtb-with-ucode': No /microcode " |
| 1013 | "node found in ", str(e.exception)) |
| 1014 | |
| 1015 | def testMicrocodeWithoutNode(self): |
| 1016 | """Test that a missing u-boot-dtb-with-ucode node is detected""" |
| 1017 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1018 | self._DoReadFile('038_x86_ucode_missing_node.dts', True) |
Simon Glass | 75db086 | 2016-11-25 20:15:55 -0700 | [diff] [blame] | 1019 | self.assertIn("Node '/binman/u-boot-with-ucode-ptr': Cannot find " |
| 1020 | "microcode region u-boot-dtb-with-ucode", str(e.exception)) |
| 1021 | |
| 1022 | def testMicrocodeWithoutNode2(self): |
| 1023 | """Test that a missing u-boot-ucode node is detected""" |
| 1024 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1025 | self._DoReadFile('039_x86_ucode_missing_node2.dts', True) |
Simon Glass | 75db086 | 2016-11-25 20:15:55 -0700 | [diff] [blame] | 1026 | self.assertIn("Node '/binman/u-boot-with-ucode-ptr': Cannot find " |
| 1027 | "microcode region u-boot-ucode", str(e.exception)) |
| 1028 | |
| 1029 | def testMicrocodeWithoutPtrInElf(self): |
| 1030 | """Test that a U-Boot binary without the microcode symbol is detected""" |
| 1031 | # ELF file without a '_dt_ucode_base_size' symbol |
Simon Glass | 75db086 | 2016-11-25 20:15:55 -0700 | [diff] [blame] | 1032 | try: |
Simon Glass | 1d0ebf7 | 2019-05-14 15:53:42 -0600 | [diff] [blame] | 1033 | with open(self.TestFile('u_boot_no_ucode_ptr'), 'rb') as fd: |
Simon Glass | 75db086 | 2016-11-25 20:15:55 -0700 | [diff] [blame] | 1034 | TestFunctional._MakeInputFile('u-boot', fd.read()) |
| 1035 | |
| 1036 | with self.assertRaises(ValueError) as e: |
Simon Glass | 160a766 | 2017-05-27 07:38:26 -0600 | [diff] [blame] | 1037 | self._RunPackUbootSingleMicrocode() |
Simon Glass | 75db086 | 2016-11-25 20:15:55 -0700 | [diff] [blame] | 1038 | self.assertIn("Node '/binman/u-boot-with-ucode-ptr': Cannot locate " |
| 1039 | "_dt_ucode_base_size symbol in u-boot", str(e.exception)) |
| 1040 | |
| 1041 | finally: |
| 1042 | # Put the original file back |
Simon Glass | 1d0ebf7 | 2019-05-14 15:53:42 -0600 | [diff] [blame] | 1043 | with open(self.TestFile('u_boot_ucode_ptr'), 'rb') as fd: |
Simon Glass | 75db086 | 2016-11-25 20:15:55 -0700 | [diff] [blame] | 1044 | TestFunctional._MakeInputFile('u-boot', fd.read()) |
| 1045 | |
| 1046 | def testMicrocodeNotInImage(self): |
| 1047 | """Test that microcode must be placed within the image""" |
| 1048 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1049 | self._DoReadFile('040_x86_ucode_not_in_image.dts', True) |
Simon Glass | 75db086 | 2016-11-25 20:15:55 -0700 | [diff] [blame] | 1050 | self.assertIn("Node '/binman/u-boot-with-ucode-ptr': Microcode " |
| 1051 | "pointer _dt_ucode_base_size at fffffe14 is outside the " |
Simon Glass | 25ac0e6 | 2018-06-01 09:38:14 -0600 | [diff] [blame] | 1052 | "section ranging from 00000000 to 0000002e", str(e.exception)) |
Simon Glass | 75db086 | 2016-11-25 20:15:55 -0700 | [diff] [blame] | 1053 | |
| 1054 | def testWithoutMicrocode(self): |
| 1055 | """Test that we can cope with an image without microcode (e.g. qemu)""" |
Simon Glass | 1d0ebf7 | 2019-05-14 15:53:42 -0600 | [diff] [blame] | 1056 | with open(self.TestFile('u_boot_no_ucode_ptr'), 'rb') as fd: |
Simon Glass | 75db086 | 2016-11-25 20:15:55 -0700 | [diff] [blame] | 1057 | TestFunctional._MakeInputFile('u-boot', fd.read()) |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1058 | data, dtb, _, _ = self._DoReadFileDtb('044_x86_optional_ucode.dts', True) |
Simon Glass | 75db086 | 2016-11-25 20:15:55 -0700 | [diff] [blame] | 1059 | |
| 1060 | # Now check the device tree has no microcode |
| 1061 | self.assertEqual(U_BOOT_NODTB_DATA, data[:len(U_BOOT_NODTB_DATA)]) |
| 1062 | second = data[len(U_BOOT_NODTB_DATA):] |
| 1063 | |
| 1064 | fdt_len = self.GetFdtLen(second) |
| 1065 | self.assertEqual(dtb, second[:fdt_len]) |
| 1066 | |
| 1067 | used_len = len(U_BOOT_NODTB_DATA) + fdt_len |
| 1068 | third = data[used_len:] |
Simon Glass | e6d85ff | 2019-05-14 15:53:47 -0600 | [diff] [blame] | 1069 | self.assertEqual(tools.GetBytes(0, 0x200 - used_len), third) |
Simon Glass | 75db086 | 2016-11-25 20:15:55 -0700 | [diff] [blame] | 1070 | |
| 1071 | def testUnknownPosSize(self): |
| 1072 | """Test that microcode must be placed within the image""" |
| 1073 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1074 | self._DoReadFile('041_unknown_pos_size.dts', True) |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 1075 | self.assertIn("Section '/binman': Unable to set offset/size for unknown " |
Simon Glass | 75db086 | 2016-11-25 20:15:55 -0700 | [diff] [blame] | 1076 | "entry 'invalid-entry'", str(e.exception)) |
Simon Glass | da22909 | 2016-11-25 20:15:56 -0700 | [diff] [blame] | 1077 | |
| 1078 | def testPackFsp(self): |
| 1079 | """Test that an image with a FSP binary can be created""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1080 | data = self._DoReadFile('042_intel-fsp.dts') |
Simon Glass | da22909 | 2016-11-25 20:15:56 -0700 | [diff] [blame] | 1081 | self.assertEqual(FSP_DATA, data[:len(FSP_DATA)]) |
| 1082 | |
| 1083 | def testPackCmc(self): |
Bin Meng | 59ea8c2 | 2017-08-15 22:41:54 -0700 | [diff] [blame] | 1084 | """Test that an image with a CMC binary can be created""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1085 | data = self._DoReadFile('043_intel-cmc.dts') |
Simon Glass | da22909 | 2016-11-25 20:15:56 -0700 | [diff] [blame] | 1086 | self.assertEqual(CMC_DATA, data[:len(CMC_DATA)]) |
Bin Meng | 59ea8c2 | 2017-08-15 22:41:54 -0700 | [diff] [blame] | 1087 | |
| 1088 | def testPackVbt(self): |
| 1089 | """Test that an image with a VBT binary can be created""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1090 | data = self._DoReadFile('046_intel-vbt.dts') |
Bin Meng | 59ea8c2 | 2017-08-15 22:41:54 -0700 | [diff] [blame] | 1091 | self.assertEqual(VBT_DATA, data[:len(VBT_DATA)]) |
Simon Glass | 9fc60b4 | 2017-11-12 21:52:22 -0700 | [diff] [blame] | 1092 | |
Simon Glass | 5650984 | 2017-11-12 21:52:25 -0700 | [diff] [blame] | 1093 | def testSplBssPad(self): |
| 1094 | """Test that we can pad SPL's BSS with zeros""" |
Simon Glass | 6b187df | 2017-11-12 21:52:27 -0700 | [diff] [blame] | 1095 | # ELF file with a '__bss_size' symbol |
Simon Glass | 11ae93e | 2018-10-01 21:12:47 -0600 | [diff] [blame] | 1096 | self._SetupSplElf() |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1097 | data = self._DoReadFile('047_spl_bss_pad.dts') |
Simon Glass | e6d85ff | 2019-05-14 15:53:47 -0600 | [diff] [blame] | 1098 | self.assertEqual(U_BOOT_SPL_DATA + tools.GetBytes(0, 10) + U_BOOT_DATA, |
| 1099 | data) |
Simon Glass | 5650984 | 2017-11-12 21:52:25 -0700 | [diff] [blame] | 1100 | |
Simon Glass | 86af511 | 2018-10-01 21:12:42 -0600 | [diff] [blame] | 1101 | def testSplBssPadMissing(self): |
| 1102 | """Test that a missing symbol is detected""" |
Simon Glass | 11ae93e | 2018-10-01 21:12:47 -0600 | [diff] [blame] | 1103 | self._SetupSplElf('u_boot_ucode_ptr') |
Simon Glass | b50e561 | 2017-11-13 18:54:54 -0700 | [diff] [blame] | 1104 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1105 | self._DoReadFile('047_spl_bss_pad.dts') |
Simon Glass | b50e561 | 2017-11-13 18:54:54 -0700 | [diff] [blame] | 1106 | self.assertIn('Expected __bss_size symbol in spl/u-boot-spl', |
| 1107 | str(e.exception)) |
| 1108 | |
Simon Glass | 8772213 | 2017-11-12 21:52:26 -0700 | [diff] [blame] | 1109 | def testPackStart16Spl(self): |
Simon Glass | 35b384c | 2018-09-14 04:57:10 -0600 | [diff] [blame] | 1110 | """Test that an image with an x86 start16 SPL region can be created""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1111 | data = self._DoReadFile('048_x86-start16-spl.dts') |
Simon Glass | 8772213 | 2017-11-12 21:52:26 -0700 | [diff] [blame] | 1112 | self.assertEqual(X86_START16_SPL_DATA, data[:len(X86_START16_SPL_DATA)]) |
| 1113 | |
Simon Glass | 736bb0a | 2018-07-06 10:27:17 -0600 | [diff] [blame] | 1114 | def _PackUbootSplMicrocode(self, dts, ucode_second=False): |
| 1115 | """Helper function for microcode tests |
Simon Glass | 6b187df | 2017-11-12 21:52:27 -0700 | [diff] [blame] | 1116 | |
| 1117 | We expect to see the following in the image, in order: |
| 1118 | u-boot-spl-nodtb.bin with a microcode pointer inserted at the |
| 1119 | correct place |
| 1120 | u-boot.dtb with the microcode removed |
| 1121 | the microcode |
Simon Glass | 736bb0a | 2018-07-06 10:27:17 -0600 | [diff] [blame] | 1122 | |
| 1123 | Args: |
| 1124 | dts: Device tree file to use for test |
| 1125 | ucode_second: True if the microsecond entry is second instead of |
| 1126 | third |
Simon Glass | 6b187df | 2017-11-12 21:52:27 -0700 | [diff] [blame] | 1127 | """ |
Simon Glass | 11ae93e | 2018-10-01 21:12:47 -0600 | [diff] [blame] | 1128 | self._SetupSplElf('u_boot_ucode_ptr') |
Simon Glass | 736bb0a | 2018-07-06 10:27:17 -0600 | [diff] [blame] | 1129 | first, pos_and_size = self._RunMicrocodeTest(dts, U_BOOT_SPL_NODTB_DATA, |
| 1130 | ucode_second=ucode_second) |
Simon Glass | c6c10e7 | 2019-05-17 22:00:46 -0600 | [diff] [blame] | 1131 | self.assertEqual(b'splnodtb with microc' + pos_and_size + |
| 1132 | b'ter somewhere in here', first) |
Simon Glass | 6b187df | 2017-11-12 21:52:27 -0700 | [diff] [blame] | 1133 | |
Simon Glass | 736bb0a | 2018-07-06 10:27:17 -0600 | [diff] [blame] | 1134 | def testPackUbootSplMicrocode(self): |
| 1135 | """Test that x86 microcode can be handled correctly in SPL""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1136 | self._PackUbootSplMicrocode('049_x86_ucode_spl.dts') |
Simon Glass | 736bb0a | 2018-07-06 10:27:17 -0600 | [diff] [blame] | 1137 | |
| 1138 | def testPackUbootSplMicrocodeReorder(self): |
| 1139 | """Test that order doesn't matter for microcode entries |
| 1140 | |
| 1141 | This is the same as testPackUbootSplMicrocode but when we process the |
| 1142 | u-boot-ucode entry we have not yet seen the u-boot-dtb-with-ucode |
| 1143 | entry, so we reply on binman to try later. |
| 1144 | """ |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1145 | self._PackUbootSplMicrocode('058_x86_ucode_spl_needs_retry.dts', |
Simon Glass | 736bb0a | 2018-07-06 10:27:17 -0600 | [diff] [blame] | 1146 | ucode_second=True) |
| 1147 | |
Simon Glass | ca4f4ff | 2017-11-12 21:52:28 -0700 | [diff] [blame] | 1148 | def testPackMrc(self): |
| 1149 | """Test that an image with an MRC binary can be created""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1150 | data = self._DoReadFile('050_intel_mrc.dts') |
Simon Glass | ca4f4ff | 2017-11-12 21:52:28 -0700 | [diff] [blame] | 1151 | self.assertEqual(MRC_DATA, data[:len(MRC_DATA)]) |
| 1152 | |
Simon Glass | 47419ea | 2017-11-13 18:54:55 -0700 | [diff] [blame] | 1153 | def testSplDtb(self): |
| 1154 | """Test that an image with spl/u-boot-spl.dtb can be created""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1155 | data = self._DoReadFile('051_u_boot_spl_dtb.dts') |
Simon Glass | 47419ea | 2017-11-13 18:54:55 -0700 | [diff] [blame] | 1156 | self.assertEqual(U_BOOT_SPL_DTB_DATA, data[:len(U_BOOT_SPL_DTB_DATA)]) |
| 1157 | |
Simon Glass | 4e6fdbe | 2017-11-13 18:54:56 -0700 | [diff] [blame] | 1158 | def testSplNoDtb(self): |
| 1159 | """Test that an image with spl/u-boot-spl-nodtb.bin can be created""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1160 | data = self._DoReadFile('052_u_boot_spl_nodtb.dts') |
Simon Glass | 4e6fdbe | 2017-11-13 18:54:56 -0700 | [diff] [blame] | 1161 | self.assertEqual(U_BOOT_SPL_NODTB_DATA, data[:len(U_BOOT_SPL_NODTB_DATA)]) |
| 1162 | |
Simon Glass | 1979063 | 2017-11-13 18:55:01 -0700 | [diff] [blame] | 1163 | def testSymbols(self): |
| 1164 | """Test binman can assign symbols embedded in U-Boot""" |
| 1165 | elf_fname = self.TestFile('u_boot_binman_syms') |
| 1166 | syms = elf.GetSymbols(elf_fname, ['binman', 'image']) |
| 1167 | addr = elf.GetSymbolAddress(elf_fname, '__image_copy_start') |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 1168 | self.assertEqual(syms['_binman_u_boot_spl_prop_offset'].address, addr) |
Simon Glass | 1979063 | 2017-11-13 18:55:01 -0700 | [diff] [blame] | 1169 | |
Simon Glass | 11ae93e | 2018-10-01 21:12:47 -0600 | [diff] [blame] | 1170 | self._SetupSplElf('u_boot_binman_syms') |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1171 | data = self._DoReadFile('053_symbols.dts') |
Simon Glass | 1979063 | 2017-11-13 18:55:01 -0700 | [diff] [blame] | 1172 | sym_values = struct.pack('<LQL', 0x24 + 0, 0x24 + 24, 0x24 + 20) |
Simon Glass | e6d85ff | 2019-05-14 15:53:47 -0600 | [diff] [blame] | 1173 | expected = (sym_values + U_BOOT_SPL_DATA[16:] + |
| 1174 | tools.GetBytes(0xff, 1) + U_BOOT_DATA + sym_values + |
| 1175 | U_BOOT_SPL_DATA[16:]) |
Simon Glass | 1979063 | 2017-11-13 18:55:01 -0700 | [diff] [blame] | 1176 | self.assertEqual(expected, data) |
| 1177 | |
Simon Glass | dd57c13 | 2018-06-01 09:38:11 -0600 | [diff] [blame] | 1178 | def testPackUnitAddress(self): |
| 1179 | """Test that we support multiple binaries with the same name""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1180 | data = self._DoReadFile('054_unit_address.dts') |
Simon Glass | dd57c13 | 2018-06-01 09:38:11 -0600 | [diff] [blame] | 1181 | self.assertEqual(U_BOOT_DATA + U_BOOT_DATA, data) |
| 1182 | |
Simon Glass | 1854695 | 2018-06-01 09:38:16 -0600 | [diff] [blame] | 1183 | def testSections(self): |
| 1184 | """Basic test of sections""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1185 | data = self._DoReadFile('055_sections.dts') |
Simon Glass | c6c10e7 | 2019-05-17 22:00:46 -0600 | [diff] [blame] | 1186 | expected = (U_BOOT_DATA + tools.GetBytes(ord('!'), 12) + |
| 1187 | U_BOOT_DATA + tools.GetBytes(ord('a'), 12) + |
| 1188 | U_BOOT_DATA + tools.GetBytes(ord('&'), 4)) |
Simon Glass | 1854695 | 2018-06-01 09:38:16 -0600 | [diff] [blame] | 1189 | self.assertEqual(expected, data) |
Simon Glass | 9fc60b4 | 2017-11-12 21:52:22 -0700 | [diff] [blame] | 1190 | |
Simon Glass | 3b0c382 | 2018-06-01 09:38:20 -0600 | [diff] [blame] | 1191 | def testMap(self): |
| 1192 | """Tests outputting a map of the images""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1193 | _, _, map_data, _ = self._DoReadFileDtb('055_sections.dts', map=True) |
Simon Glass | 1be70d2 | 2018-07-17 13:25:49 -0600 | [diff] [blame] | 1194 | self.assertEqual('''ImagePos Offset Size Name |
| 1195 | 00000000 00000000 00000028 main-section |
| 1196 | 00000000 00000000 00000010 section@0 |
| 1197 | 00000000 00000000 00000004 u-boot |
| 1198 | 00000010 00000010 00000010 section@1 |
| 1199 | 00000010 00000000 00000004 u-boot |
| 1200 | 00000020 00000020 00000004 section@2 |
| 1201 | 00000020 00000000 00000004 u-boot |
Simon Glass | 3b0c382 | 2018-06-01 09:38:20 -0600 | [diff] [blame] | 1202 | ''', map_data) |
| 1203 | |
Simon Glass | c8d48ef | 2018-06-01 09:38:21 -0600 | [diff] [blame] | 1204 | def testNamePrefix(self): |
| 1205 | """Tests that name prefixes are used""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1206 | _, _, map_data, _ = self._DoReadFileDtb('056_name_prefix.dts', map=True) |
Simon Glass | 1be70d2 | 2018-07-17 13:25:49 -0600 | [diff] [blame] | 1207 | self.assertEqual('''ImagePos Offset Size Name |
| 1208 | 00000000 00000000 00000028 main-section |
| 1209 | 00000000 00000000 00000010 section@0 |
| 1210 | 00000000 00000000 00000004 ro-u-boot |
| 1211 | 00000010 00000010 00000010 section@1 |
| 1212 | 00000010 00000000 00000004 rw-u-boot |
Simon Glass | c8d48ef | 2018-06-01 09:38:21 -0600 | [diff] [blame] | 1213 | ''', map_data) |
| 1214 | |
Simon Glass | 736bb0a | 2018-07-06 10:27:17 -0600 | [diff] [blame] | 1215 | def testUnknownContents(self): |
| 1216 | """Test that obtaining the contents works as expected""" |
| 1217 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1218 | self._DoReadFile('057_unknown_contents.dts', True) |
Simon Glass | 736bb0a | 2018-07-06 10:27:17 -0600 | [diff] [blame] | 1219 | self.assertIn("Section '/binman': Internal error: Could not complete " |
| 1220 | "processing of contents: remaining [<_testing.Entry__testing ", |
| 1221 | str(e.exception)) |
| 1222 | |
Simon Glass | 5c89023 | 2018-07-06 10:27:19 -0600 | [diff] [blame] | 1223 | def testBadChangeSize(self): |
| 1224 | """Test that trying to change the size of an entry fails""" |
Simon Glass | c52c9e7 | 2019-07-08 14:25:37 -0600 | [diff] [blame] | 1225 | try: |
| 1226 | state.SetAllowEntryExpansion(False) |
| 1227 | with self.assertRaises(ValueError) as e: |
| 1228 | self._DoReadFile('059_change_size.dts', True) |
| 1229 | self.assertIn("Node '/binman/_testing': Cannot update entry size from 1 to 2", |
| 1230 | str(e.exception)) |
| 1231 | finally: |
| 1232 | state.SetAllowEntryExpansion(True) |
Simon Glass | 5c89023 | 2018-07-06 10:27:19 -0600 | [diff] [blame] | 1233 | |
Simon Glass | 16b8d6b | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 1234 | def testUpdateFdt(self): |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 1235 | """Test that we can update the device tree with offset/size info""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1236 | _, _, _, out_dtb_fname = self._DoReadFileDtb('060_fdt_update.dts', |
Simon Glass | 16b8d6b | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 1237 | update_dtb=True) |
Simon Glass | cee02e6 | 2018-07-17 13:25:52 -0600 | [diff] [blame] | 1238 | dtb = fdt.Fdt(out_dtb_fname) |
| 1239 | dtb.Scan() |
| 1240 | props = self._GetPropTree(dtb, ['offset', 'size', 'image-pos']) |
Simon Glass | 16b8d6b | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 1241 | self.assertEqual({ |
Simon Glass | dbf6be9 | 2018-08-01 15:22:42 -0600 | [diff] [blame] | 1242 | 'image-pos': 0, |
Simon Glass | 8122f39 | 2018-07-17 13:25:28 -0600 | [diff] [blame] | 1243 | 'offset': 0, |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 1244 | '_testing:offset': 32, |
Simon Glass | 16b8d6b | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 1245 | '_testing:size': 1, |
Simon Glass | dbf6be9 | 2018-08-01 15:22:42 -0600 | [diff] [blame] | 1246 | '_testing:image-pos': 32, |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 1247 | 'section@0/u-boot:offset': 0, |
Simon Glass | 16b8d6b | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 1248 | 'section@0/u-boot:size': len(U_BOOT_DATA), |
Simon Glass | dbf6be9 | 2018-08-01 15:22:42 -0600 | [diff] [blame] | 1249 | 'section@0/u-boot:image-pos': 0, |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 1250 | 'section@0:offset': 0, |
Simon Glass | 16b8d6b | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 1251 | 'section@0:size': 16, |
Simon Glass | dbf6be9 | 2018-08-01 15:22:42 -0600 | [diff] [blame] | 1252 | 'section@0:image-pos': 0, |
Simon Glass | 16b8d6b | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 1253 | |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 1254 | 'section@1/u-boot:offset': 0, |
Simon Glass | 16b8d6b | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 1255 | 'section@1/u-boot:size': len(U_BOOT_DATA), |
Simon Glass | dbf6be9 | 2018-08-01 15:22:42 -0600 | [diff] [blame] | 1256 | 'section@1/u-boot:image-pos': 16, |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 1257 | 'section@1:offset': 16, |
Simon Glass | 16b8d6b | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 1258 | 'section@1:size': 16, |
Simon Glass | dbf6be9 | 2018-08-01 15:22:42 -0600 | [diff] [blame] | 1259 | 'section@1:image-pos': 16, |
Simon Glass | 16b8d6b | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 1260 | 'size': 40 |
| 1261 | }, props) |
| 1262 | |
| 1263 | def testUpdateFdtBad(self): |
| 1264 | """Test that we detect when ProcessFdt never completes""" |
| 1265 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1266 | self._DoReadFileDtb('061_fdt_update_bad.dts', update_dtb=True) |
Simon Glass | 16b8d6b | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 1267 | self.assertIn('Could not complete processing of Fdt: remaining ' |
| 1268 | '[<_testing.Entry__testing', str(e.exception)) |
Simon Glass | 5c89023 | 2018-07-06 10:27:19 -0600 | [diff] [blame] | 1269 | |
Simon Glass | 53af22a | 2018-07-17 13:25:32 -0600 | [diff] [blame] | 1270 | def testEntryArgs(self): |
| 1271 | """Test passing arguments to entries from the command line""" |
| 1272 | entry_args = { |
| 1273 | 'test-str-arg': 'test1', |
| 1274 | 'test-int-arg': '456', |
| 1275 | } |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1276 | self._DoReadFileDtb('062_entry_args.dts', entry_args=entry_args) |
Simon Glass | 53af22a | 2018-07-17 13:25:32 -0600 | [diff] [blame] | 1277 | self.assertIn('image', control.images) |
| 1278 | entry = control.images['image'].GetEntries()['_testing'] |
| 1279 | self.assertEqual('test0', entry.test_str_fdt) |
| 1280 | self.assertEqual('test1', entry.test_str_arg) |
| 1281 | self.assertEqual(123, entry.test_int_fdt) |
| 1282 | self.assertEqual(456, entry.test_int_arg) |
| 1283 | |
| 1284 | def testEntryArgsMissing(self): |
| 1285 | """Test missing arguments and properties""" |
| 1286 | entry_args = { |
| 1287 | 'test-int-arg': '456', |
| 1288 | } |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1289 | self._DoReadFileDtb('063_entry_args_missing.dts', entry_args=entry_args) |
Simon Glass | 53af22a | 2018-07-17 13:25:32 -0600 | [diff] [blame] | 1290 | entry = control.images['image'].GetEntries()['_testing'] |
| 1291 | self.assertEqual('test0', entry.test_str_fdt) |
| 1292 | self.assertEqual(None, entry.test_str_arg) |
| 1293 | self.assertEqual(None, entry.test_int_fdt) |
| 1294 | self.assertEqual(456, entry.test_int_arg) |
| 1295 | |
| 1296 | def testEntryArgsRequired(self): |
| 1297 | """Test missing arguments and properties""" |
| 1298 | entry_args = { |
| 1299 | 'test-int-arg': '456', |
| 1300 | } |
| 1301 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1302 | self._DoReadFileDtb('064_entry_args_required.dts') |
Simon Glass | 53af22a | 2018-07-17 13:25:32 -0600 | [diff] [blame] | 1303 | self.assertIn("Node '/binman/_testing': Missing required " |
| 1304 | 'properties/entry args: test-str-arg, test-int-fdt, test-int-arg', |
| 1305 | str(e.exception)) |
| 1306 | |
| 1307 | def testEntryArgsInvalidFormat(self): |
| 1308 | """Test that an invalid entry-argument format is detected""" |
Simon Glass | 53cd5d9 | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 1309 | args = ['build', '-d', self.TestFile('064_entry_args_required.dts'), |
| 1310 | '-ano-value'] |
Simon Glass | 53af22a | 2018-07-17 13:25:32 -0600 | [diff] [blame] | 1311 | with self.assertRaises(ValueError) as e: |
| 1312 | self._DoBinman(*args) |
| 1313 | self.assertIn("Invalid entry arguemnt 'no-value'", str(e.exception)) |
| 1314 | |
| 1315 | def testEntryArgsInvalidInteger(self): |
| 1316 | """Test that an invalid entry-argument integer is detected""" |
| 1317 | entry_args = { |
| 1318 | 'test-int-arg': 'abc', |
| 1319 | } |
| 1320 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1321 | self._DoReadFileDtb('062_entry_args.dts', entry_args=entry_args) |
Simon Glass | 53af22a | 2018-07-17 13:25:32 -0600 | [diff] [blame] | 1322 | self.assertIn("Node '/binman/_testing': Cannot convert entry arg " |
| 1323 | "'test-int-arg' (value 'abc') to integer", |
| 1324 | str(e.exception)) |
| 1325 | |
| 1326 | def testEntryArgsInvalidDatatype(self): |
| 1327 | """Test that an invalid entry-argument datatype is detected |
| 1328 | |
| 1329 | This test could be written in entry_test.py except that it needs |
| 1330 | access to control.entry_args, which seems more than that module should |
| 1331 | be able to see. |
| 1332 | """ |
| 1333 | entry_args = { |
| 1334 | 'test-bad-datatype-arg': '12', |
| 1335 | } |
| 1336 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1337 | self._DoReadFileDtb('065_entry_args_unknown_datatype.dts', |
Simon Glass | 53af22a | 2018-07-17 13:25:32 -0600 | [diff] [blame] | 1338 | entry_args=entry_args) |
| 1339 | self.assertIn('GetArg() internal error: Unknown data type ', |
| 1340 | str(e.exception)) |
| 1341 | |
Simon Glass | bb74837 | 2018-07-17 13:25:33 -0600 | [diff] [blame] | 1342 | def testText(self): |
| 1343 | """Test for a text entry type""" |
| 1344 | entry_args = { |
| 1345 | 'test-id': TEXT_DATA, |
| 1346 | 'test-id2': TEXT_DATA2, |
| 1347 | 'test-id3': TEXT_DATA3, |
| 1348 | } |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1349 | data, _, _, _ = self._DoReadFileDtb('066_text.dts', |
Simon Glass | bb74837 | 2018-07-17 13:25:33 -0600 | [diff] [blame] | 1350 | entry_args=entry_args) |
Simon Glass | c6c10e7 | 2019-05-17 22:00:46 -0600 | [diff] [blame] | 1351 | expected = (tools.ToBytes(TEXT_DATA) + |
| 1352 | tools.GetBytes(0, 8 - len(TEXT_DATA)) + |
| 1353 | tools.ToBytes(TEXT_DATA2) + tools.ToBytes(TEXT_DATA3) + |
Simon Glass | aa88b50 | 2019-07-08 13:18:40 -0600 | [diff] [blame] | 1354 | b'some text' + b'more text') |
Simon Glass | bb74837 | 2018-07-17 13:25:33 -0600 | [diff] [blame] | 1355 | self.assertEqual(expected, data) |
| 1356 | |
Simon Glass | fd8d1f7 | 2018-07-17 13:25:36 -0600 | [diff] [blame] | 1357 | def testEntryDocs(self): |
| 1358 | """Test for creation of entry documentation""" |
| 1359 | with test_util.capture_sys_output() as (stdout, stderr): |
| 1360 | control.WriteEntryDocs(binman.GetEntryModules()) |
| 1361 | self.assertTrue(len(stdout.getvalue()) > 0) |
| 1362 | |
| 1363 | def testEntryDocsMissing(self): |
| 1364 | """Test handling of missing entry documentation""" |
| 1365 | with self.assertRaises(ValueError) as e: |
| 1366 | with test_util.capture_sys_output() as (stdout, stderr): |
| 1367 | control.WriteEntryDocs(binman.GetEntryModules(), 'u_boot') |
| 1368 | self.assertIn('Documentation is missing for modules: u_boot', |
| 1369 | str(e.exception)) |
| 1370 | |
Simon Glass | 11e36cc | 2018-07-17 13:25:38 -0600 | [diff] [blame] | 1371 | def testFmap(self): |
| 1372 | """Basic test of generation of a flashrom fmap""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1373 | data = self._DoReadFile('067_fmap.dts') |
Simon Glass | 11e36cc | 2018-07-17 13:25:38 -0600 | [diff] [blame] | 1374 | fhdr, fentries = fmap_util.DecodeFmap(data[32:]) |
Simon Glass | c6c10e7 | 2019-05-17 22:00:46 -0600 | [diff] [blame] | 1375 | expected = (U_BOOT_DATA + tools.GetBytes(ord('!'), 12) + |
| 1376 | U_BOOT_DATA + tools.GetBytes(ord('a'), 12)) |
Simon Glass | 11e36cc | 2018-07-17 13:25:38 -0600 | [diff] [blame] | 1377 | self.assertEqual(expected, data[:32]) |
Simon Glass | c6c10e7 | 2019-05-17 22:00:46 -0600 | [diff] [blame] | 1378 | self.assertEqual(b'__FMAP__', fhdr.signature) |
Simon Glass | 11e36cc | 2018-07-17 13:25:38 -0600 | [diff] [blame] | 1379 | self.assertEqual(1, fhdr.ver_major) |
| 1380 | self.assertEqual(0, fhdr.ver_minor) |
| 1381 | self.assertEqual(0, fhdr.base) |
| 1382 | self.assertEqual(16 + 16 + |
| 1383 | fmap_util.FMAP_HEADER_LEN + |
| 1384 | fmap_util.FMAP_AREA_LEN * 3, fhdr.image_size) |
Simon Glass | c6c10e7 | 2019-05-17 22:00:46 -0600 | [diff] [blame] | 1385 | self.assertEqual(b'FMAP', fhdr.name) |
Simon Glass | 11e36cc | 2018-07-17 13:25:38 -0600 | [diff] [blame] | 1386 | self.assertEqual(3, fhdr.nareas) |
| 1387 | for fentry in fentries: |
| 1388 | self.assertEqual(0, fentry.flags) |
| 1389 | |
| 1390 | self.assertEqual(0, fentries[0].offset) |
| 1391 | self.assertEqual(4, fentries[0].size) |
Simon Glass | c6c10e7 | 2019-05-17 22:00:46 -0600 | [diff] [blame] | 1392 | self.assertEqual(b'RO_U_BOOT', fentries[0].name) |
Simon Glass | 11e36cc | 2018-07-17 13:25:38 -0600 | [diff] [blame] | 1393 | |
| 1394 | self.assertEqual(16, fentries[1].offset) |
| 1395 | self.assertEqual(4, fentries[1].size) |
Simon Glass | c6c10e7 | 2019-05-17 22:00:46 -0600 | [diff] [blame] | 1396 | self.assertEqual(b'RW_U_BOOT', fentries[1].name) |
Simon Glass | 11e36cc | 2018-07-17 13:25:38 -0600 | [diff] [blame] | 1397 | |
| 1398 | self.assertEqual(32, fentries[2].offset) |
| 1399 | self.assertEqual(fmap_util.FMAP_HEADER_LEN + |
| 1400 | fmap_util.FMAP_AREA_LEN * 3, fentries[2].size) |
Simon Glass | c6c10e7 | 2019-05-17 22:00:46 -0600 | [diff] [blame] | 1401 | self.assertEqual(b'FMAP', fentries[2].name) |
Simon Glass | 11e36cc | 2018-07-17 13:25:38 -0600 | [diff] [blame] | 1402 | |
Simon Glass | ec127af | 2018-07-17 13:25:39 -0600 | [diff] [blame] | 1403 | def testBlobNamedByArg(self): |
| 1404 | """Test we can add a blob with the filename coming from an entry arg""" |
| 1405 | entry_args = { |
| 1406 | 'cros-ec-rw-path': 'ecrw.bin', |
| 1407 | } |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1408 | data, _, _, _ = self._DoReadFileDtb('068_blob_named_by_arg.dts', |
Simon Glass | ec127af | 2018-07-17 13:25:39 -0600 | [diff] [blame] | 1409 | entry_args=entry_args) |
| 1410 | |
Simon Glass | 3af8e49 | 2018-07-17 13:25:40 -0600 | [diff] [blame] | 1411 | def testFill(self): |
| 1412 | """Test for an fill entry type""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1413 | data = self._DoReadFile('069_fill.dts') |
Simon Glass | e6d85ff | 2019-05-14 15:53:47 -0600 | [diff] [blame] | 1414 | expected = tools.GetBytes(0xff, 8) + tools.GetBytes(0, 8) |
Simon Glass | 3af8e49 | 2018-07-17 13:25:40 -0600 | [diff] [blame] | 1415 | self.assertEqual(expected, data) |
| 1416 | |
| 1417 | def testFillNoSize(self): |
| 1418 | """Test for an fill entry type with no size""" |
| 1419 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1420 | self._DoReadFile('070_fill_no_size.dts') |
Simon Glass | 3af8e49 | 2018-07-17 13:25:40 -0600 | [diff] [blame] | 1421 | self.assertIn("'fill' entry must have a size property", |
| 1422 | str(e.exception)) |
| 1423 | |
Simon Glass | 0ef87aa | 2018-07-17 13:25:44 -0600 | [diff] [blame] | 1424 | def _HandleGbbCommand(self, pipe_list): |
| 1425 | """Fake calls to the futility utility""" |
| 1426 | if pipe_list[0][0] == 'futility': |
| 1427 | fname = pipe_list[0][-1] |
| 1428 | # Append our GBB data to the file, which will happen every time the |
| 1429 | # futility command is called. |
Simon Glass | 1d0ebf7 | 2019-05-14 15:53:42 -0600 | [diff] [blame] | 1430 | with open(fname, 'ab') as fd: |
Simon Glass | 0ef87aa | 2018-07-17 13:25:44 -0600 | [diff] [blame] | 1431 | fd.write(GBB_DATA) |
| 1432 | return command.CommandResult() |
| 1433 | |
| 1434 | def testGbb(self): |
| 1435 | """Test for the Chromium OS Google Binary Block""" |
| 1436 | command.test_result = self._HandleGbbCommand |
| 1437 | entry_args = { |
| 1438 | 'keydir': 'devkeys', |
| 1439 | 'bmpblk': 'bmpblk.bin', |
| 1440 | } |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1441 | data, _, _, _ = self._DoReadFileDtb('071_gbb.dts', entry_args=entry_args) |
Simon Glass | 0ef87aa | 2018-07-17 13:25:44 -0600 | [diff] [blame] | 1442 | |
| 1443 | # Since futility |
Simon Glass | e6d85ff | 2019-05-14 15:53:47 -0600 | [diff] [blame] | 1444 | expected = (GBB_DATA + GBB_DATA + tools.GetBytes(0, 8) + |
| 1445 | tools.GetBytes(0, 0x2180 - 16)) |
Simon Glass | 0ef87aa | 2018-07-17 13:25:44 -0600 | [diff] [blame] | 1446 | self.assertEqual(expected, data) |
| 1447 | |
| 1448 | def testGbbTooSmall(self): |
| 1449 | """Test for the Chromium OS Google Binary Block being large enough""" |
| 1450 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1451 | self._DoReadFileDtb('072_gbb_too_small.dts') |
Simon Glass | 0ef87aa | 2018-07-17 13:25:44 -0600 | [diff] [blame] | 1452 | self.assertIn("Node '/binman/gbb': GBB is too small", |
| 1453 | str(e.exception)) |
| 1454 | |
| 1455 | def testGbbNoSize(self): |
| 1456 | """Test for the Chromium OS Google Binary Block having a size""" |
| 1457 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1458 | self._DoReadFileDtb('073_gbb_no_size.dts') |
Simon Glass | 0ef87aa | 2018-07-17 13:25:44 -0600 | [diff] [blame] | 1459 | self.assertIn("Node '/binman/gbb': GBB must have a fixed size", |
| 1460 | str(e.exception)) |
| 1461 | |
Simon Glass | 24d0d3c | 2018-07-17 13:25:47 -0600 | [diff] [blame] | 1462 | def _HandleVblockCommand(self, pipe_list): |
| 1463 | """Fake calls to the futility utility""" |
| 1464 | if pipe_list[0][0] == 'futility': |
| 1465 | fname = pipe_list[0][3] |
Simon Glass | a326b49 | 2018-09-14 04:57:11 -0600 | [diff] [blame] | 1466 | with open(fname, 'wb') as fd: |
Simon Glass | 24d0d3c | 2018-07-17 13:25:47 -0600 | [diff] [blame] | 1467 | fd.write(VBLOCK_DATA) |
| 1468 | return command.CommandResult() |
| 1469 | |
| 1470 | def testVblock(self): |
| 1471 | """Test for the Chromium OS Verified Boot Block""" |
| 1472 | command.test_result = self._HandleVblockCommand |
| 1473 | entry_args = { |
| 1474 | 'keydir': 'devkeys', |
| 1475 | } |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1476 | data, _, _, _ = self._DoReadFileDtb('074_vblock.dts', |
Simon Glass | 24d0d3c | 2018-07-17 13:25:47 -0600 | [diff] [blame] | 1477 | entry_args=entry_args) |
| 1478 | expected = U_BOOT_DATA + VBLOCK_DATA + U_BOOT_DTB_DATA |
| 1479 | self.assertEqual(expected, data) |
| 1480 | |
| 1481 | def testVblockNoContent(self): |
| 1482 | """Test we detect a vblock which has no content to sign""" |
| 1483 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1484 | self._DoReadFile('075_vblock_no_content.dts') |
Simon Glass | 24d0d3c | 2018-07-17 13:25:47 -0600 | [diff] [blame] | 1485 | self.assertIn("Node '/binman/vblock': Vblock must have a 'content' " |
| 1486 | 'property', str(e.exception)) |
| 1487 | |
| 1488 | def testVblockBadPhandle(self): |
| 1489 | """Test that we detect a vblock with an invalid phandle in contents""" |
| 1490 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1491 | self._DoReadFile('076_vblock_bad_phandle.dts') |
Simon Glass | 24d0d3c | 2018-07-17 13:25:47 -0600 | [diff] [blame] | 1492 | self.assertIn("Node '/binman/vblock': Cannot find node for phandle " |
| 1493 | '1000', str(e.exception)) |
| 1494 | |
| 1495 | def testVblockBadEntry(self): |
| 1496 | """Test that we detect an entry that points to a non-entry""" |
| 1497 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1498 | self._DoReadFile('077_vblock_bad_entry.dts') |
Simon Glass | 24d0d3c | 2018-07-17 13:25:47 -0600 | [diff] [blame] | 1499 | self.assertIn("Node '/binman/vblock': Cannot find entry for node " |
| 1500 | "'other'", str(e.exception)) |
| 1501 | |
Simon Glass | b8ef5b6 | 2018-07-17 13:25:48 -0600 | [diff] [blame] | 1502 | def testTpl(self): |
| 1503 | """Test that an image with TPL and ots device tree can be created""" |
| 1504 | # ELF file with a '__bss_size' symbol |
Simon Glass | 1d0ebf7 | 2019-05-14 15:53:42 -0600 | [diff] [blame] | 1505 | with open(self.TestFile('bss_data'), 'rb') as fd: |
Simon Glass | b8ef5b6 | 2018-07-17 13:25:48 -0600 | [diff] [blame] | 1506 | TestFunctional._MakeInputFile('tpl/u-boot-tpl', fd.read()) |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1507 | data = self._DoReadFile('078_u_boot_tpl.dts') |
Simon Glass | b8ef5b6 | 2018-07-17 13:25:48 -0600 | [diff] [blame] | 1508 | self.assertEqual(U_BOOT_TPL_DATA + U_BOOT_TPL_DTB_DATA, data) |
| 1509 | |
Simon Glass | 15a587c | 2018-07-17 13:25:51 -0600 | [diff] [blame] | 1510 | def testUsesPos(self): |
| 1511 | """Test that the 'pos' property cannot be used anymore""" |
| 1512 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1513 | data = self._DoReadFile('079_uses_pos.dts') |
Simon Glass | 15a587c | 2018-07-17 13:25:51 -0600 | [diff] [blame] | 1514 | self.assertIn("Node '/binman/u-boot': Please use 'offset' instead of " |
| 1515 | "'pos'", str(e.exception)) |
| 1516 | |
Simon Glass | d178eab | 2018-09-14 04:57:08 -0600 | [diff] [blame] | 1517 | def testFillZero(self): |
| 1518 | """Test for an fill entry type with a size of 0""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1519 | data = self._DoReadFile('080_fill_empty.dts') |
Simon Glass | e6d85ff | 2019-05-14 15:53:47 -0600 | [diff] [blame] | 1520 | self.assertEqual(tools.GetBytes(0, 16), data) |
Simon Glass | d178eab | 2018-09-14 04:57:08 -0600 | [diff] [blame] | 1521 | |
Simon Glass | 0b48936 | 2018-09-14 04:57:09 -0600 | [diff] [blame] | 1522 | def testTextMissing(self): |
| 1523 | """Test for a text entry type where there is no text""" |
| 1524 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1525 | self._DoReadFileDtb('066_text.dts',) |
Simon Glass | 0b48936 | 2018-09-14 04:57:09 -0600 | [diff] [blame] | 1526 | self.assertIn("Node '/binman/text': No value provided for text label " |
| 1527 | "'test-id'", str(e.exception)) |
| 1528 | |
Simon Glass | 35b384c | 2018-09-14 04:57:10 -0600 | [diff] [blame] | 1529 | def testPackStart16Tpl(self): |
| 1530 | """Test that an image with an x86 start16 TPL region can be created""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1531 | data = self._DoReadFile('081_x86-start16-tpl.dts') |
Simon Glass | 35b384c | 2018-09-14 04:57:10 -0600 | [diff] [blame] | 1532 | self.assertEqual(X86_START16_TPL_DATA, data[:len(X86_START16_TPL_DATA)]) |
| 1533 | |
Simon Glass | 0bfa7b0 | 2018-09-14 04:57:12 -0600 | [diff] [blame] | 1534 | def testSelectImage(self): |
| 1535 | """Test that we can select which images to build""" |
Simon Glass | eb833d8 | 2019-04-25 21:58:34 -0600 | [diff] [blame] | 1536 | expected = 'Skipping images: image1' |
Simon Glass | 0bfa7b0 | 2018-09-14 04:57:12 -0600 | [diff] [blame] | 1537 | |
Simon Glass | eb833d8 | 2019-04-25 21:58:34 -0600 | [diff] [blame] | 1538 | # We should only get the expected message in verbose mode |
Simon Glass | ee0c9a7 | 2019-07-08 13:18:48 -0600 | [diff] [blame] | 1539 | for verbosity in (0, 2): |
Simon Glass | eb833d8 | 2019-04-25 21:58:34 -0600 | [diff] [blame] | 1540 | with test_util.capture_sys_output() as (stdout, stderr): |
| 1541 | retcode = self._DoTestFile('006_dual_image.dts', |
| 1542 | verbosity=verbosity, |
| 1543 | images=['image2']) |
| 1544 | self.assertEqual(0, retcode) |
| 1545 | if verbosity: |
| 1546 | self.assertIn(expected, stdout.getvalue()) |
| 1547 | else: |
| 1548 | self.assertNotIn(expected, stdout.getvalue()) |
| 1549 | |
| 1550 | self.assertFalse(os.path.exists(tools.GetOutputFilename('image1.bin'))) |
| 1551 | self.assertTrue(os.path.exists(tools.GetOutputFilename('image2.bin'))) |
Simon Glass | 0bfa7b0 | 2018-09-14 04:57:12 -0600 | [diff] [blame] | 1552 | |
Simon Glass | 6ed45ba | 2018-09-14 04:57:24 -0600 | [diff] [blame] | 1553 | def testUpdateFdtAll(self): |
| 1554 | """Test that all device trees are updated with offset/size info""" |
Simon Glass | 3c08131 | 2019-07-08 14:25:26 -0600 | [diff] [blame] | 1555 | data = self._DoReadFileRealDtb('082_fdt_update_all.dts') |
Simon Glass | 6ed45ba | 2018-09-14 04:57:24 -0600 | [diff] [blame] | 1556 | |
| 1557 | base_expected = { |
| 1558 | 'section:image-pos': 0, |
| 1559 | 'u-boot-tpl-dtb:size': 513, |
| 1560 | 'u-boot-spl-dtb:size': 513, |
| 1561 | 'u-boot-spl-dtb:offset': 493, |
| 1562 | 'image-pos': 0, |
| 1563 | 'section/u-boot-dtb:image-pos': 0, |
| 1564 | 'u-boot-spl-dtb:image-pos': 493, |
| 1565 | 'section/u-boot-dtb:size': 493, |
| 1566 | 'u-boot-tpl-dtb:image-pos': 1006, |
| 1567 | 'section/u-boot-dtb:offset': 0, |
| 1568 | 'section:size': 493, |
| 1569 | 'offset': 0, |
| 1570 | 'section:offset': 0, |
| 1571 | 'u-boot-tpl-dtb:offset': 1006, |
| 1572 | 'size': 1519 |
| 1573 | } |
| 1574 | |
| 1575 | # We expect three device-tree files in the output, one after the other. |
| 1576 | # Read them in sequence. We look for an 'spl' property in the SPL tree, |
| 1577 | # and 'tpl' in the TPL tree, to make sure they are distinct from the |
| 1578 | # main U-Boot tree. All three should have the same postions and offset. |
| 1579 | start = 0 |
| 1580 | for item in ['', 'spl', 'tpl']: |
| 1581 | dtb = fdt.Fdt.FromData(data[start:]) |
| 1582 | dtb.Scan() |
| 1583 | props = self._GetPropTree(dtb, ['offset', 'size', 'image-pos', |
| 1584 | 'spl', 'tpl']) |
| 1585 | expected = dict(base_expected) |
| 1586 | if item: |
| 1587 | expected[item] = 0 |
| 1588 | self.assertEqual(expected, props) |
| 1589 | start += dtb._fdt_obj.totalsize() |
| 1590 | |
| 1591 | def testUpdateFdtOutput(self): |
| 1592 | """Test that output DTB files are updated""" |
| 1593 | try: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1594 | data, dtb_data, _, _ = self._DoReadFileDtb('082_fdt_update_all.dts', |
Simon Glass | 6ed45ba | 2018-09-14 04:57:24 -0600 | [diff] [blame] | 1595 | use_real_dtb=True, update_dtb=True, reset_dtbs=False) |
| 1596 | |
| 1597 | # Unfortunately, compiling a source file always results in a file |
| 1598 | # called source.dtb (see fdt_util.EnsureCompiled()). The test |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1599 | # source file (e.g. test/075_fdt_update_all.dts) thus does not enter |
Simon Glass | 6ed45ba | 2018-09-14 04:57:24 -0600 | [diff] [blame] | 1600 | # binman as a file called u-boot.dtb. To fix this, copy the file |
| 1601 | # over to the expected place. |
| 1602 | #tools.WriteFile(os.path.join(self._indir, 'u-boot.dtb'), |
| 1603 | #tools.ReadFile(tools.GetOutputFilename('source.dtb'))) |
| 1604 | start = 0 |
| 1605 | for fname in ['u-boot.dtb.out', 'spl/u-boot-spl.dtb.out', |
| 1606 | 'tpl/u-boot-tpl.dtb.out']: |
| 1607 | dtb = fdt.Fdt.FromData(data[start:]) |
| 1608 | size = dtb._fdt_obj.totalsize() |
| 1609 | pathname = tools.GetOutputFilename(os.path.split(fname)[1]) |
| 1610 | outdata = tools.ReadFile(pathname) |
| 1611 | name = os.path.split(fname)[0] |
| 1612 | |
| 1613 | if name: |
| 1614 | orig_indata = self._GetDtbContentsForSplTpl(dtb_data, name) |
| 1615 | else: |
| 1616 | orig_indata = dtb_data |
| 1617 | self.assertNotEqual(outdata, orig_indata, |
| 1618 | "Expected output file '%s' be updated" % pathname) |
| 1619 | self.assertEqual(outdata, data[start:start + size], |
| 1620 | "Expected output file '%s' to match output image" % |
| 1621 | pathname) |
| 1622 | start += size |
| 1623 | finally: |
| 1624 | self._ResetDtbs() |
| 1625 | |
Simon Glass | 83d73c2 | 2018-09-14 04:57:26 -0600 | [diff] [blame] | 1626 | def _decompress(self, data): |
Simon Glass | ff5c7e3 | 2019-07-08 13:18:42 -0600 | [diff] [blame] | 1627 | return tools.Decompress(data, 'lz4') |
Simon Glass | 83d73c2 | 2018-09-14 04:57:26 -0600 | [diff] [blame] | 1628 | |
| 1629 | def testCompress(self): |
| 1630 | """Test compression of blobs""" |
Simon Glass | ac62fba | 2019-07-08 13:18:53 -0600 | [diff] [blame] | 1631 | self._CheckLz4() |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1632 | data, _, _, out_dtb_fname = self._DoReadFileDtb('083_compress.dts', |
Simon Glass | 83d73c2 | 2018-09-14 04:57:26 -0600 | [diff] [blame] | 1633 | use_real_dtb=True, update_dtb=True) |
| 1634 | dtb = fdt.Fdt(out_dtb_fname) |
| 1635 | dtb.Scan() |
| 1636 | props = self._GetPropTree(dtb, ['size', 'uncomp-size']) |
| 1637 | orig = self._decompress(data) |
| 1638 | self.assertEquals(COMPRESS_DATA, orig) |
| 1639 | expected = { |
| 1640 | 'blob:uncomp-size': len(COMPRESS_DATA), |
| 1641 | 'blob:size': len(data), |
| 1642 | 'size': len(data), |
| 1643 | } |
| 1644 | self.assertEqual(expected, props) |
| 1645 | |
Simon Glass | 0a98b28 | 2018-09-14 04:57:28 -0600 | [diff] [blame] | 1646 | def testFiles(self): |
| 1647 | """Test bringing in multiple files""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1648 | data = self._DoReadFile('084_files.dts') |
Simon Glass | 0a98b28 | 2018-09-14 04:57:28 -0600 | [diff] [blame] | 1649 | self.assertEqual(FILES_DATA, data) |
| 1650 | |
| 1651 | def testFilesCompress(self): |
| 1652 | """Test bringing in multiple files and compressing them""" |
Simon Glass | ac62fba | 2019-07-08 13:18:53 -0600 | [diff] [blame] | 1653 | self._CheckLz4() |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1654 | data = self._DoReadFile('085_files_compress.dts') |
Simon Glass | 0a98b28 | 2018-09-14 04:57:28 -0600 | [diff] [blame] | 1655 | |
| 1656 | image = control.images['image'] |
| 1657 | entries = image.GetEntries() |
| 1658 | files = entries['files'] |
| 1659 | entries = files._section._entries |
| 1660 | |
Simon Glass | c6c10e7 | 2019-05-17 22:00:46 -0600 | [diff] [blame] | 1661 | orig = b'' |
Simon Glass | 0a98b28 | 2018-09-14 04:57:28 -0600 | [diff] [blame] | 1662 | for i in range(1, 3): |
| 1663 | key = '%d.dat' % i |
| 1664 | start = entries[key].image_pos |
| 1665 | len = entries[key].size |
| 1666 | chunk = data[start:start + len] |
| 1667 | orig += self._decompress(chunk) |
| 1668 | |
| 1669 | self.assertEqual(FILES_DATA, orig) |
| 1670 | |
| 1671 | def testFilesMissing(self): |
| 1672 | """Test missing files""" |
| 1673 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1674 | data = self._DoReadFile('086_files_none.dts') |
Simon Glass | 0a98b28 | 2018-09-14 04:57:28 -0600 | [diff] [blame] | 1675 | self.assertIn("Node '/binman/files': Pattern \'files/*.none\' matched " |
| 1676 | 'no files', str(e.exception)) |
| 1677 | |
| 1678 | def testFilesNoPattern(self): |
| 1679 | """Test missing files""" |
| 1680 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1681 | data = self._DoReadFile('087_files_no_pattern.dts') |
Simon Glass | 0a98b28 | 2018-09-14 04:57:28 -0600 | [diff] [blame] | 1682 | self.assertIn("Node '/binman/files': Missing 'pattern' property", |
| 1683 | str(e.exception)) |
| 1684 | |
Simon Glass | ba64a0b | 2018-09-14 04:57:29 -0600 | [diff] [blame] | 1685 | def testExpandSize(self): |
| 1686 | """Test an expanding entry""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1687 | data, _, map_data, _ = self._DoReadFileDtb('088_expand_size.dts', |
Simon Glass | ba64a0b | 2018-09-14 04:57:29 -0600 | [diff] [blame] | 1688 | map=True) |
Simon Glass | c6c10e7 | 2019-05-17 22:00:46 -0600 | [diff] [blame] | 1689 | expect = (tools.GetBytes(ord('a'), 8) + U_BOOT_DATA + |
| 1690 | MRC_DATA + tools.GetBytes(ord('b'), 1) + U_BOOT_DATA + |
| 1691 | tools.GetBytes(ord('c'), 8) + U_BOOT_DATA + |
| 1692 | tools.GetBytes(ord('d'), 8)) |
Simon Glass | ba64a0b | 2018-09-14 04:57:29 -0600 | [diff] [blame] | 1693 | self.assertEqual(expect, data) |
| 1694 | self.assertEqual('''ImagePos Offset Size Name |
| 1695 | 00000000 00000000 00000028 main-section |
| 1696 | 00000000 00000000 00000008 fill |
| 1697 | 00000008 00000008 00000004 u-boot |
| 1698 | 0000000c 0000000c 00000004 section |
| 1699 | 0000000c 00000000 00000003 intel-mrc |
| 1700 | 00000010 00000010 00000004 u-boot2 |
| 1701 | 00000014 00000014 0000000c section2 |
| 1702 | 00000014 00000000 00000008 fill |
| 1703 | 0000001c 00000008 00000004 u-boot |
| 1704 | 00000020 00000020 00000008 fill2 |
| 1705 | ''', map_data) |
| 1706 | |
| 1707 | def testExpandSizeBad(self): |
| 1708 | """Test an expanding entry which fails to provide contents""" |
Simon Glass | 163ed6c | 2018-09-14 04:57:36 -0600 | [diff] [blame] | 1709 | with test_util.capture_sys_output() as (stdout, stderr): |
| 1710 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1711 | self._DoReadFileDtb('089_expand_size_bad.dts', map=True) |
Simon Glass | ba64a0b | 2018-09-14 04:57:29 -0600 | [diff] [blame] | 1712 | self.assertIn("Node '/binman/_testing': Cannot obtain contents when " |
| 1713 | 'expanding entry', str(e.exception)) |
| 1714 | |
Simon Glass | e0e5df9 | 2018-09-14 04:57:31 -0600 | [diff] [blame] | 1715 | def testHash(self): |
| 1716 | """Test hashing of the contents of an entry""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1717 | _, _, _, out_dtb_fname = self._DoReadFileDtb('090_hash.dts', |
Simon Glass | e0e5df9 | 2018-09-14 04:57:31 -0600 | [diff] [blame] | 1718 | use_real_dtb=True, update_dtb=True) |
| 1719 | dtb = fdt.Fdt(out_dtb_fname) |
| 1720 | dtb.Scan() |
| 1721 | hash_node = dtb.GetNode('/binman/u-boot/hash').props['value'] |
| 1722 | m = hashlib.sha256() |
| 1723 | m.update(U_BOOT_DATA) |
Simon Glass | c6c10e7 | 2019-05-17 22:00:46 -0600 | [diff] [blame] | 1724 | self.assertEqual(m.digest(), b''.join(hash_node.value)) |
Simon Glass | e0e5df9 | 2018-09-14 04:57:31 -0600 | [diff] [blame] | 1725 | |
| 1726 | def testHashNoAlgo(self): |
| 1727 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1728 | self._DoReadFileDtb('091_hash_no_algo.dts', update_dtb=True) |
Simon Glass | e0e5df9 | 2018-09-14 04:57:31 -0600 | [diff] [blame] | 1729 | self.assertIn("Node \'/binman/u-boot\': Missing \'algo\' property for " |
| 1730 | 'hash node', str(e.exception)) |
| 1731 | |
| 1732 | def testHashBadAlgo(self): |
| 1733 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1734 | self._DoReadFileDtb('092_hash_bad_algo.dts', update_dtb=True) |
Simon Glass | e0e5df9 | 2018-09-14 04:57:31 -0600 | [diff] [blame] | 1735 | self.assertIn("Node '/binman/u-boot': Unknown hash algorithm", |
| 1736 | str(e.exception)) |
| 1737 | |
| 1738 | def testHashSection(self): |
| 1739 | """Test hashing of the contents of an entry""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1740 | _, _, _, out_dtb_fname = self._DoReadFileDtb('099_hash_section.dts', |
Simon Glass | e0e5df9 | 2018-09-14 04:57:31 -0600 | [diff] [blame] | 1741 | use_real_dtb=True, update_dtb=True) |
| 1742 | dtb = fdt.Fdt(out_dtb_fname) |
| 1743 | dtb.Scan() |
| 1744 | hash_node = dtb.GetNode('/binman/section/hash').props['value'] |
| 1745 | m = hashlib.sha256() |
| 1746 | m.update(U_BOOT_DATA) |
Simon Glass | c6c10e7 | 2019-05-17 22:00:46 -0600 | [diff] [blame] | 1747 | m.update(tools.GetBytes(ord('a'), 16)) |
| 1748 | self.assertEqual(m.digest(), b''.join(hash_node.value)) |
Simon Glass | e0e5df9 | 2018-09-14 04:57:31 -0600 | [diff] [blame] | 1749 | |
Simon Glass | f025363 | 2018-09-14 04:57:32 -0600 | [diff] [blame] | 1750 | def testPackUBootTplMicrocode(self): |
| 1751 | """Test that x86 microcode can be handled correctly in TPL |
| 1752 | |
| 1753 | We expect to see the following in the image, in order: |
| 1754 | u-boot-tpl-nodtb.bin with a microcode pointer inserted at the correct |
| 1755 | place |
| 1756 | u-boot-tpl.dtb with the microcode removed |
| 1757 | the microcode |
| 1758 | """ |
Simon Glass | 1d0ebf7 | 2019-05-14 15:53:42 -0600 | [diff] [blame] | 1759 | with open(self.TestFile('u_boot_ucode_ptr'), 'rb') as fd: |
Simon Glass | f025363 | 2018-09-14 04:57:32 -0600 | [diff] [blame] | 1760 | TestFunctional._MakeInputFile('tpl/u-boot-tpl', fd.read()) |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1761 | first, pos_and_size = self._RunMicrocodeTest('093_x86_tpl_ucode.dts', |
Simon Glass | f025363 | 2018-09-14 04:57:32 -0600 | [diff] [blame] | 1762 | U_BOOT_TPL_NODTB_DATA) |
Simon Glass | c6c10e7 | 2019-05-17 22:00:46 -0600 | [diff] [blame] | 1763 | self.assertEqual(b'tplnodtb with microc' + pos_and_size + |
| 1764 | b'ter somewhere in here', first) |
Simon Glass | f025363 | 2018-09-14 04:57:32 -0600 | [diff] [blame] | 1765 | |
Simon Glass | f8f8df6 | 2018-09-14 04:57:34 -0600 | [diff] [blame] | 1766 | def testFmapX86(self): |
| 1767 | """Basic test of generation of a flashrom fmap""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1768 | data = self._DoReadFile('094_fmap_x86.dts') |
Simon Glass | f8f8df6 | 2018-09-14 04:57:34 -0600 | [diff] [blame] | 1769 | fhdr, fentries = fmap_util.DecodeFmap(data[32:]) |
Simon Glass | c6c10e7 | 2019-05-17 22:00:46 -0600 | [diff] [blame] | 1770 | expected = U_BOOT_DATA + MRC_DATA + tools.GetBytes(ord('a'), 32 - 7) |
Simon Glass | f8f8df6 | 2018-09-14 04:57:34 -0600 | [diff] [blame] | 1771 | self.assertEqual(expected, data[:32]) |
| 1772 | fhdr, fentries = fmap_util.DecodeFmap(data[32:]) |
| 1773 | |
| 1774 | self.assertEqual(0x100, fhdr.image_size) |
| 1775 | |
| 1776 | self.assertEqual(0, fentries[0].offset) |
| 1777 | self.assertEqual(4, fentries[0].size) |
Simon Glass | c6c10e7 | 2019-05-17 22:00:46 -0600 | [diff] [blame] | 1778 | self.assertEqual(b'U_BOOT', fentries[0].name) |
Simon Glass | f8f8df6 | 2018-09-14 04:57:34 -0600 | [diff] [blame] | 1779 | |
| 1780 | self.assertEqual(4, fentries[1].offset) |
| 1781 | self.assertEqual(3, fentries[1].size) |
Simon Glass | c6c10e7 | 2019-05-17 22:00:46 -0600 | [diff] [blame] | 1782 | self.assertEqual(b'INTEL_MRC', fentries[1].name) |
Simon Glass | f8f8df6 | 2018-09-14 04:57:34 -0600 | [diff] [blame] | 1783 | |
| 1784 | self.assertEqual(32, fentries[2].offset) |
| 1785 | self.assertEqual(fmap_util.FMAP_HEADER_LEN + |
| 1786 | fmap_util.FMAP_AREA_LEN * 3, fentries[2].size) |
Simon Glass | c6c10e7 | 2019-05-17 22:00:46 -0600 | [diff] [blame] | 1787 | self.assertEqual(b'FMAP', fentries[2].name) |
Simon Glass | f8f8df6 | 2018-09-14 04:57:34 -0600 | [diff] [blame] | 1788 | |
| 1789 | def testFmapX86Section(self): |
| 1790 | """Basic test of generation of a flashrom fmap""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1791 | data = self._DoReadFile('095_fmap_x86_section.dts') |
Simon Glass | c6c10e7 | 2019-05-17 22:00:46 -0600 | [diff] [blame] | 1792 | expected = U_BOOT_DATA + MRC_DATA + tools.GetBytes(ord('b'), 32 - 7) |
Simon Glass | f8f8df6 | 2018-09-14 04:57:34 -0600 | [diff] [blame] | 1793 | self.assertEqual(expected, data[:32]) |
| 1794 | fhdr, fentries = fmap_util.DecodeFmap(data[36:]) |
| 1795 | |
| 1796 | self.assertEqual(0x100, fhdr.image_size) |
| 1797 | |
| 1798 | self.assertEqual(0, fentries[0].offset) |
| 1799 | self.assertEqual(4, fentries[0].size) |
Simon Glass | c6c10e7 | 2019-05-17 22:00:46 -0600 | [diff] [blame] | 1800 | self.assertEqual(b'U_BOOT', fentries[0].name) |
Simon Glass | f8f8df6 | 2018-09-14 04:57:34 -0600 | [diff] [blame] | 1801 | |
| 1802 | self.assertEqual(4, fentries[1].offset) |
| 1803 | self.assertEqual(3, fentries[1].size) |
Simon Glass | c6c10e7 | 2019-05-17 22:00:46 -0600 | [diff] [blame] | 1804 | self.assertEqual(b'INTEL_MRC', fentries[1].name) |
Simon Glass | f8f8df6 | 2018-09-14 04:57:34 -0600 | [diff] [blame] | 1805 | |
| 1806 | self.assertEqual(36, fentries[2].offset) |
| 1807 | self.assertEqual(fmap_util.FMAP_HEADER_LEN + |
| 1808 | fmap_util.FMAP_AREA_LEN * 3, fentries[2].size) |
Simon Glass | c6c10e7 | 2019-05-17 22:00:46 -0600 | [diff] [blame] | 1809 | self.assertEqual(b'FMAP', fentries[2].name) |
Simon Glass | f8f8df6 | 2018-09-14 04:57:34 -0600 | [diff] [blame] | 1810 | |
Simon Glass | fe1ae3e | 2018-09-14 04:57:35 -0600 | [diff] [blame] | 1811 | def testElf(self): |
| 1812 | """Basic test of ELF entries""" |
Simon Glass | 11ae93e | 2018-10-01 21:12:47 -0600 | [diff] [blame] | 1813 | self._SetupSplElf() |
Simon Glass | 1d0ebf7 | 2019-05-14 15:53:42 -0600 | [diff] [blame] | 1814 | with open(self.TestFile('bss_data'), 'rb') as fd: |
Simon Glass | 4c65025 | 2019-07-08 13:18:46 -0600 | [diff] [blame] | 1815 | TestFunctional._MakeInputFile('tpl/u-boot-tpl', fd.read()) |
| 1816 | with open(self.TestFile('bss_data'), 'rb') as fd: |
Simon Glass | fe1ae3e | 2018-09-14 04:57:35 -0600 | [diff] [blame] | 1817 | TestFunctional._MakeInputFile('-boot', fd.read()) |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1818 | data = self._DoReadFile('096_elf.dts') |
Simon Glass | fe1ae3e | 2018-09-14 04:57:35 -0600 | [diff] [blame] | 1819 | |
Simon Glass | 093d168 | 2019-07-08 13:18:25 -0600 | [diff] [blame] | 1820 | def testElfStrip(self): |
Simon Glass | fe1ae3e | 2018-09-14 04:57:35 -0600 | [diff] [blame] | 1821 | """Basic test of ELF entries""" |
Simon Glass | 11ae93e | 2018-10-01 21:12:47 -0600 | [diff] [blame] | 1822 | self._SetupSplElf() |
Simon Glass | 1d0ebf7 | 2019-05-14 15:53:42 -0600 | [diff] [blame] | 1823 | with open(self.TestFile('bss_data'), 'rb') as fd: |
Simon Glass | fe1ae3e | 2018-09-14 04:57:35 -0600 | [diff] [blame] | 1824 | TestFunctional._MakeInputFile('-boot', fd.read()) |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1825 | data = self._DoReadFile('097_elf_strip.dts') |
Simon Glass | fe1ae3e | 2018-09-14 04:57:35 -0600 | [diff] [blame] | 1826 | |
Simon Glass | 163ed6c | 2018-09-14 04:57:36 -0600 | [diff] [blame] | 1827 | def testPackOverlapMap(self): |
| 1828 | """Test that overlapping regions are detected""" |
| 1829 | with test_util.capture_sys_output() as (stdout, stderr): |
| 1830 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1831 | self._DoTestFile('014_pack_overlap.dts', map=True) |
Simon Glass | 163ed6c | 2018-09-14 04:57:36 -0600 | [diff] [blame] | 1832 | map_fname = tools.GetOutputFilename('image.map') |
| 1833 | self.assertEqual("Wrote map file '%s' to show errors\n" % map_fname, |
| 1834 | stdout.getvalue()) |
| 1835 | |
| 1836 | # We should not get an inmage, but there should be a map file |
| 1837 | self.assertFalse(os.path.exists(tools.GetOutputFilename('image.bin'))) |
| 1838 | self.assertTrue(os.path.exists(map_fname)) |
Simon Glass | eb546ac | 2019-05-17 22:00:51 -0600 | [diff] [blame] | 1839 | map_data = tools.ReadFile(map_fname, binary=False) |
Simon Glass | 163ed6c | 2018-09-14 04:57:36 -0600 | [diff] [blame] | 1840 | self.assertEqual('''ImagePos Offset Size Name |
| 1841 | <none> 00000000 00000007 main-section |
| 1842 | <none> 00000000 00000004 u-boot |
| 1843 | <none> 00000003 00000004 u-boot-align |
| 1844 | ''', map_data) |
| 1845 | |
Simon Glass | 093d168 | 2019-07-08 13:18:25 -0600 | [diff] [blame] | 1846 | def testPackRefCode(self): |
Simon Glass | 3ae192c | 2018-10-01 12:22:31 -0600 | [diff] [blame] | 1847 | """Test that an image with an Intel Reference code binary works""" |
| 1848 | data = self._DoReadFile('100_intel_refcode.dts') |
| 1849 | self.assertEqual(REFCODE_DATA, data[:len(REFCODE_DATA)]) |
| 1850 | |
Simon Glass | 9481c80 | 2019-04-25 21:58:39 -0600 | [diff] [blame] | 1851 | def testSectionOffset(self): |
| 1852 | """Tests use of a section with an offset""" |
| 1853 | data, _, map_data, _ = self._DoReadFileDtb('101_sections_offset.dts', |
| 1854 | map=True) |
| 1855 | self.assertEqual('''ImagePos Offset Size Name |
| 1856 | 00000000 00000000 00000038 main-section |
| 1857 | 00000004 00000004 00000010 section@0 |
| 1858 | 00000004 00000000 00000004 u-boot |
| 1859 | 00000018 00000018 00000010 section@1 |
| 1860 | 00000018 00000000 00000004 u-boot |
| 1861 | 0000002c 0000002c 00000004 section@2 |
| 1862 | 0000002c 00000000 00000004 u-boot |
| 1863 | ''', map_data) |
| 1864 | self.assertEqual(data, |
Simon Glass | e6d85ff | 2019-05-14 15:53:47 -0600 | [diff] [blame] | 1865 | tools.GetBytes(0x26, 4) + U_BOOT_DATA + |
| 1866 | tools.GetBytes(0x21, 12) + |
| 1867 | tools.GetBytes(0x26, 4) + U_BOOT_DATA + |
| 1868 | tools.GetBytes(0x61, 12) + |
| 1869 | tools.GetBytes(0x26, 4) + U_BOOT_DATA + |
| 1870 | tools.GetBytes(0x26, 8)) |
Simon Glass | 9481c80 | 2019-04-25 21:58:39 -0600 | [diff] [blame] | 1871 | |
Simon Glass | ac62fba | 2019-07-08 13:18:53 -0600 | [diff] [blame] | 1872 | def testCbfsRaw(self): |
| 1873 | """Test base handling of a Coreboot Filesystem (CBFS) |
| 1874 | |
| 1875 | The exact contents of the CBFS is verified by similar tests in |
| 1876 | cbfs_util_test.py. The tests here merely check that the files added to |
| 1877 | the CBFS can be found in the final image. |
| 1878 | """ |
| 1879 | data = self._DoReadFile('102_cbfs_raw.dts') |
| 1880 | size = 0xb0 |
| 1881 | |
| 1882 | cbfs = cbfs_util.CbfsReader(data) |
| 1883 | self.assertEqual(size, cbfs.rom_size) |
| 1884 | |
| 1885 | self.assertIn('u-boot-dtb', cbfs.files) |
| 1886 | cfile = cbfs.files['u-boot-dtb'] |
| 1887 | self.assertEqual(U_BOOT_DTB_DATA, cfile.data) |
| 1888 | |
| 1889 | def testCbfsArch(self): |
| 1890 | """Test on non-x86 architecture""" |
| 1891 | data = self._DoReadFile('103_cbfs_raw_ppc.dts') |
| 1892 | size = 0x100 |
| 1893 | |
| 1894 | cbfs = cbfs_util.CbfsReader(data) |
| 1895 | self.assertEqual(size, cbfs.rom_size) |
| 1896 | |
| 1897 | self.assertIn('u-boot-dtb', cbfs.files) |
| 1898 | cfile = cbfs.files['u-boot-dtb'] |
| 1899 | self.assertEqual(U_BOOT_DTB_DATA, cfile.data) |
| 1900 | |
| 1901 | def testCbfsStage(self): |
| 1902 | """Tests handling of a Coreboot Filesystem (CBFS)""" |
| 1903 | if not elf.ELF_TOOLS: |
| 1904 | self.skipTest('Python elftools not available') |
| 1905 | elf_fname = os.path.join(self._indir, 'cbfs-stage.elf') |
| 1906 | elf.MakeElf(elf_fname, U_BOOT_DATA, U_BOOT_DTB_DATA) |
| 1907 | size = 0xb0 |
| 1908 | |
| 1909 | data = self._DoReadFile('104_cbfs_stage.dts') |
| 1910 | cbfs = cbfs_util.CbfsReader(data) |
| 1911 | self.assertEqual(size, cbfs.rom_size) |
| 1912 | |
| 1913 | self.assertIn('u-boot', cbfs.files) |
| 1914 | cfile = cbfs.files['u-boot'] |
| 1915 | self.assertEqual(U_BOOT_DATA + U_BOOT_DTB_DATA, cfile.data) |
| 1916 | |
| 1917 | def testCbfsRawCompress(self): |
| 1918 | """Test handling of compressing raw files""" |
| 1919 | self._CheckLz4() |
| 1920 | data = self._DoReadFile('105_cbfs_raw_compress.dts') |
| 1921 | size = 0x140 |
| 1922 | |
| 1923 | cbfs = cbfs_util.CbfsReader(data) |
| 1924 | self.assertIn('u-boot', cbfs.files) |
| 1925 | cfile = cbfs.files['u-boot'] |
| 1926 | self.assertEqual(COMPRESS_DATA, cfile.data) |
| 1927 | |
| 1928 | def testCbfsBadArch(self): |
| 1929 | """Test handling of a bad architecture""" |
| 1930 | with self.assertRaises(ValueError) as e: |
| 1931 | self._DoReadFile('106_cbfs_bad_arch.dts') |
| 1932 | self.assertIn("Invalid architecture 'bad-arch'", str(e.exception)) |
| 1933 | |
| 1934 | def testCbfsNoSize(self): |
| 1935 | """Test handling of a missing size property""" |
| 1936 | with self.assertRaises(ValueError) as e: |
| 1937 | self._DoReadFile('107_cbfs_no_size.dts') |
| 1938 | self.assertIn('entry must have a size property', str(e.exception)) |
| 1939 | |
| 1940 | def testCbfsNoCOntents(self): |
| 1941 | """Test handling of a CBFS entry which does not provide contentsy""" |
| 1942 | with self.assertRaises(ValueError) as e: |
| 1943 | self._DoReadFile('108_cbfs_no_contents.dts') |
| 1944 | self.assertIn('Could not complete processing of contents', |
| 1945 | str(e.exception)) |
| 1946 | |
| 1947 | def testCbfsBadCompress(self): |
| 1948 | """Test handling of a bad architecture""" |
| 1949 | with self.assertRaises(ValueError) as e: |
| 1950 | self._DoReadFile('109_cbfs_bad_compress.dts') |
| 1951 | self.assertIn("Invalid compression in 'u-boot': 'invalid-algo'", |
| 1952 | str(e.exception)) |
| 1953 | |
| 1954 | def testCbfsNamedEntries(self): |
| 1955 | """Test handling of named entries""" |
| 1956 | data = self._DoReadFile('110_cbfs_name.dts') |
| 1957 | |
| 1958 | cbfs = cbfs_util.CbfsReader(data) |
| 1959 | self.assertIn('FRED', cbfs.files) |
| 1960 | cfile1 = cbfs.files['FRED'] |
| 1961 | self.assertEqual(U_BOOT_DATA, cfile1.data) |
| 1962 | |
| 1963 | self.assertIn('hello', cbfs.files) |
| 1964 | cfile2 = cbfs.files['hello'] |
| 1965 | self.assertEqual(U_BOOT_DTB_DATA, cfile2.data) |
| 1966 | |
Simon Glass | c5ac138 | 2019-07-08 13:18:54 -0600 | [diff] [blame] | 1967 | def _SetupIfwi(self, fname): |
| 1968 | """Set up to run an IFWI test |
| 1969 | |
| 1970 | Args: |
| 1971 | fname: Filename of input file to provide (fitimage.bin or ifwi.bin) |
| 1972 | """ |
| 1973 | self._SetupSplElf() |
| 1974 | |
| 1975 | # Intel Integrated Firmware Image (IFWI) file |
| 1976 | with gzip.open(self.TestFile('%s.gz' % fname), 'rb') as fd: |
| 1977 | data = fd.read() |
| 1978 | TestFunctional._MakeInputFile(fname,data) |
| 1979 | |
| 1980 | def _CheckIfwi(self, data): |
| 1981 | """Check that an image with an IFWI contains the correct output |
| 1982 | |
| 1983 | Args: |
| 1984 | data: Conents of output file |
| 1985 | """ |
| 1986 | expected_desc = tools.ReadFile(self.TestFile('descriptor.bin')) |
| 1987 | if data[:0x1000] != expected_desc: |
| 1988 | self.fail('Expected descriptor binary at start of image') |
| 1989 | |
| 1990 | # We expect to find the TPL wil in subpart IBBP entry IBBL |
| 1991 | image_fname = tools.GetOutputFilename('image.bin') |
| 1992 | tpl_fname = tools.GetOutputFilename('tpl.out') |
| 1993 | tools.RunIfwiTool(image_fname, tools.CMD_EXTRACT, fname=tpl_fname, |
| 1994 | subpart='IBBP', entry_name='IBBL') |
| 1995 | |
| 1996 | tpl_data = tools.ReadFile(tpl_fname) |
| 1997 | self.assertEqual(tpl_data[:len(U_BOOT_TPL_DATA)], U_BOOT_TPL_DATA) |
| 1998 | |
| 1999 | def testPackX86RomIfwi(self): |
| 2000 | """Test that an x86 ROM with Integrated Firmware Image can be created""" |
| 2001 | self._SetupIfwi('fitimage.bin') |
| 2002 | data = self._DoReadFile('111_x86-rom-ifwi.dts') |
| 2003 | self._CheckIfwi(data) |
| 2004 | |
| 2005 | def testPackX86RomIfwiNoDesc(self): |
| 2006 | """Test that an x86 ROM with IFWI can be created from an ifwi.bin file""" |
| 2007 | self._SetupIfwi('ifwi.bin') |
| 2008 | data = self._DoReadFile('112_x86-rom-ifwi-nodesc.dts') |
| 2009 | self._CheckIfwi(data) |
| 2010 | |
| 2011 | def testPackX86RomIfwiNoData(self): |
| 2012 | """Test that an x86 ROM with IFWI handles missing data""" |
| 2013 | self._SetupIfwi('ifwi.bin') |
| 2014 | with self.assertRaises(ValueError) as e: |
| 2015 | data = self._DoReadFile('113_x86-rom-ifwi-nodata.dts') |
| 2016 | self.assertIn('Could not complete processing of contents', |
| 2017 | str(e.exception)) |
Simon Glass | 53af22a | 2018-07-17 13:25:32 -0600 | [diff] [blame] | 2018 | |
Simon Glass | e073d4e | 2019-07-08 13:18:56 -0600 | [diff] [blame] | 2019 | def testCbfsOffset(self): |
| 2020 | """Test a CBFS with files at particular offsets |
| 2021 | |
| 2022 | Like all CFBS tests, this is just checking the logic that calls |
| 2023 | cbfs_util. See cbfs_util_test for fully tests (e.g. test_cbfs_offset()). |
| 2024 | """ |
| 2025 | data = self._DoReadFile('114_cbfs_offset.dts') |
| 2026 | size = 0x200 |
| 2027 | |
| 2028 | cbfs = cbfs_util.CbfsReader(data) |
| 2029 | self.assertEqual(size, cbfs.rom_size) |
| 2030 | |
| 2031 | self.assertIn('u-boot', cbfs.files) |
| 2032 | cfile = cbfs.files['u-boot'] |
| 2033 | self.assertEqual(U_BOOT_DATA, cfile.data) |
| 2034 | self.assertEqual(0x40, cfile.cbfs_offset) |
| 2035 | |
| 2036 | self.assertIn('u-boot-dtb', cbfs.files) |
| 2037 | cfile2 = cbfs.files['u-boot-dtb'] |
| 2038 | self.assertEqual(U_BOOT_DTB_DATA, cfile2.data) |
| 2039 | self.assertEqual(0x140, cfile2.cbfs_offset) |
| 2040 | |
Simon Glass | 086cec9 | 2019-07-08 14:25:27 -0600 | [diff] [blame] | 2041 | def testFdtmap(self): |
| 2042 | """Test an FDT map can be inserted in the image""" |
| 2043 | data = self.data = self._DoReadFileRealDtb('115_fdtmap.dts') |
| 2044 | fdtmap_data = data[len(U_BOOT_DATA):] |
| 2045 | magic = fdtmap_data[:8] |
| 2046 | self.assertEqual('_FDTMAP_', magic) |
| 2047 | self.assertEqual(tools.GetBytes(0, 8), fdtmap_data[8:16]) |
| 2048 | |
| 2049 | fdt_data = fdtmap_data[16:] |
| 2050 | dtb = fdt.Fdt.FromData(fdt_data) |
| 2051 | dtb.Scan() |
| 2052 | props = self._GetPropTree(dtb, ['offset', 'size', 'image-pos'], |
| 2053 | prefix='/') |
| 2054 | self.assertEqual({ |
| 2055 | 'image-pos': 0, |
| 2056 | 'offset': 0, |
| 2057 | 'u-boot:offset': 0, |
| 2058 | 'u-boot:size': len(U_BOOT_DATA), |
| 2059 | 'u-boot:image-pos': 0, |
| 2060 | 'fdtmap:image-pos': 4, |
| 2061 | 'fdtmap:offset': 4, |
| 2062 | 'fdtmap:size': len(fdtmap_data), |
| 2063 | 'size': len(data), |
| 2064 | }, props) |
| 2065 | |
| 2066 | def testFdtmapNoMatch(self): |
| 2067 | """Check handling of an FDT map when the section cannot be found""" |
| 2068 | self.data = self._DoReadFileRealDtb('115_fdtmap.dts') |
| 2069 | |
| 2070 | # Mangle the section name, which should cause a mismatch between the |
| 2071 | # correct FDT path and the one expected by the section |
| 2072 | image = control.images['image'] |
Simon Glass | cf22894 | 2019-07-08 14:25:28 -0600 | [diff] [blame] | 2073 | image._node.path += '-suffix' |
Simon Glass | 086cec9 | 2019-07-08 14:25:27 -0600 | [diff] [blame] | 2074 | entries = image.GetEntries() |
| 2075 | fdtmap = entries['fdtmap'] |
| 2076 | with self.assertRaises(ValueError) as e: |
| 2077 | fdtmap._GetFdtmap() |
| 2078 | self.assertIn("Cannot locate node for path '/binman-suffix'", |
| 2079 | str(e.exception)) |
| 2080 | |
Simon Glass | cf22894 | 2019-07-08 14:25:28 -0600 | [diff] [blame] | 2081 | def testFdtmapHeader(self): |
| 2082 | """Test an FDT map and image header can be inserted in the image""" |
| 2083 | data = self.data = self._DoReadFileRealDtb('116_fdtmap_hdr.dts') |
| 2084 | fdtmap_pos = len(U_BOOT_DATA) |
| 2085 | fdtmap_data = data[fdtmap_pos:] |
| 2086 | fdt_data = fdtmap_data[16:] |
| 2087 | dtb = fdt.Fdt.FromData(fdt_data) |
| 2088 | fdt_size = dtb.GetFdtObj().totalsize() |
| 2089 | hdr_data = data[-8:] |
| 2090 | self.assertEqual('BinM', hdr_data[:4]) |
| 2091 | offset = struct.unpack('<I', hdr_data[4:])[0] & 0xffffffff |
| 2092 | self.assertEqual(fdtmap_pos - 0x400, offset - (1 << 32)) |
| 2093 | |
| 2094 | def testFdtmapHeaderStart(self): |
| 2095 | """Test an image header can be inserted at the image start""" |
| 2096 | data = self.data = self._DoReadFileRealDtb('117_fdtmap_hdr_start.dts') |
| 2097 | fdtmap_pos = 0x100 + len(U_BOOT_DATA) |
| 2098 | hdr_data = data[:8] |
| 2099 | self.assertEqual('BinM', hdr_data[:4]) |
| 2100 | offset = struct.unpack('<I', hdr_data[4:])[0] |
| 2101 | self.assertEqual(fdtmap_pos, offset) |
| 2102 | |
| 2103 | def testFdtmapHeaderPos(self): |
| 2104 | """Test an image header can be inserted at a chosen position""" |
| 2105 | data = self.data = self._DoReadFileRealDtb('118_fdtmap_hdr_pos.dts') |
| 2106 | fdtmap_pos = 0x100 + len(U_BOOT_DATA) |
| 2107 | hdr_data = data[0x80:0x88] |
| 2108 | self.assertEqual('BinM', hdr_data[:4]) |
| 2109 | offset = struct.unpack('<I', hdr_data[4:])[0] |
| 2110 | self.assertEqual(fdtmap_pos, offset) |
| 2111 | |
| 2112 | def testHeaderMissingFdtmap(self): |
| 2113 | """Test an image header requires an fdtmap""" |
| 2114 | with self.assertRaises(ValueError) as e: |
| 2115 | self.data = self._DoReadFileRealDtb('119_fdtmap_hdr_missing.dts') |
| 2116 | self.assertIn("'image_header' section must have an 'fdtmap' sibling", |
| 2117 | str(e.exception)) |
| 2118 | |
| 2119 | def testHeaderNoLocation(self): |
| 2120 | """Test an image header with a no specified location is detected""" |
| 2121 | with self.assertRaises(ValueError) as e: |
| 2122 | self.data = self._DoReadFileRealDtb('120_hdr_no_location.dts') |
| 2123 | self.assertIn("Invalid location 'None', expected 'start' or 'end'", |
| 2124 | str(e.exception)) |
| 2125 | |
Simon Glass | c52c9e7 | 2019-07-08 14:25:37 -0600 | [diff] [blame] | 2126 | def testEntryExpand(self): |
| 2127 | """Test expanding an entry after it is packed""" |
| 2128 | data = self._DoReadFile('121_entry_expand.dts') |
| 2129 | self.assertEqual(b'aa', data[:2]) |
| 2130 | self.assertEqual(U_BOOT_DATA, data[2:2 + len(U_BOOT_DATA)]) |
| 2131 | self.assertEqual(b'aa', data[-2:]) |
| 2132 | |
| 2133 | def testEntryExpandBad(self): |
| 2134 | """Test expanding an entry after it is packed, twice""" |
| 2135 | with self.assertRaises(ValueError) as e: |
| 2136 | self._DoReadFile('122_entry_expand_twice.dts') |
| 2137 | self.assertIn("Image '/binman': Entries expanded after packing", |
| 2138 | str(e.exception)) |
| 2139 | |
| 2140 | def testEntryExpandSection(self): |
| 2141 | """Test expanding an entry within a section after it is packed""" |
| 2142 | data = self._DoReadFile('123_entry_expand_section.dts') |
| 2143 | self.assertEqual(b'aa', data[:2]) |
| 2144 | self.assertEqual(U_BOOT_DATA, data[2:2 + len(U_BOOT_DATA)]) |
| 2145 | self.assertEqual(b'aa', data[-2:]) |
| 2146 | |
Simon Glass | 6c223fd | 2019-07-08 14:25:38 -0600 | [diff] [blame] | 2147 | def testCompressDtb(self): |
| 2148 | """Test that compress of device-tree files is supported""" |
| 2149 | self._CheckLz4() |
| 2150 | data = self.data = self._DoReadFileRealDtb('124_compress_dtb.dts') |
| 2151 | self.assertEqual(U_BOOT_DATA, data[:len(U_BOOT_DATA)]) |
| 2152 | comp_data = data[len(U_BOOT_DATA):] |
| 2153 | orig = self._decompress(comp_data) |
| 2154 | dtb = fdt.Fdt.FromData(orig) |
| 2155 | dtb.Scan() |
| 2156 | props = self._GetPropTree(dtb, ['size', 'uncomp-size']) |
| 2157 | expected = { |
| 2158 | 'u-boot:size': len(U_BOOT_DATA), |
| 2159 | 'u-boot-dtb:uncomp-size': len(orig), |
| 2160 | 'u-boot-dtb:size': len(comp_data), |
| 2161 | 'size': len(data), |
| 2162 | } |
| 2163 | self.assertEqual(expected, props) |
| 2164 | |
Simon Glass | 69f7cb3 | 2019-07-08 14:25:41 -0600 | [diff] [blame] | 2165 | def testCbfsUpdateFdt(self): |
| 2166 | """Test that we can update the device tree with CBFS offset/size info""" |
| 2167 | self._CheckLz4() |
| 2168 | data, _, _, out_dtb_fname = self._DoReadFileDtb('125_cbfs_update.dts', |
| 2169 | update_dtb=True) |
| 2170 | dtb = fdt.Fdt(out_dtb_fname) |
| 2171 | dtb.Scan() |
| 2172 | props = self._GetPropTree(dtb, ['offset', 'size', 'image-pos', |
| 2173 | 'uncomp-size']) |
| 2174 | del props['cbfs/u-boot:size'] |
| 2175 | self.assertEqual({ |
| 2176 | 'offset': 0, |
| 2177 | 'size': len(data), |
| 2178 | 'image-pos': 0, |
| 2179 | 'cbfs:offset': 0, |
| 2180 | 'cbfs:size': len(data), |
| 2181 | 'cbfs:image-pos': 0, |
| 2182 | 'cbfs/u-boot:offset': 0x38, |
| 2183 | 'cbfs/u-boot:uncomp-size': len(U_BOOT_DATA), |
| 2184 | 'cbfs/u-boot:image-pos': 0x38, |
| 2185 | 'cbfs/u-boot-dtb:offset': 0xb8, |
| 2186 | 'cbfs/u-boot-dtb:size': len(U_BOOT_DATA), |
| 2187 | 'cbfs/u-boot-dtb:image-pos': 0xb8, |
| 2188 | }, props) |
| 2189 | |
Simon Glass | 8a1ad06 | 2019-07-08 14:25:42 -0600 | [diff] [blame] | 2190 | def testCbfsBadType(self): |
| 2191 | """Test an image header with a no specified location is detected""" |
| 2192 | with self.assertRaises(ValueError) as e: |
| 2193 | self._DoReadFile('126_cbfs_bad_type.dts') |
| 2194 | self.assertIn("Unknown cbfs-type 'badtype'", str(e.exception)) |
| 2195 | |
Simon Glass | 41b8ba0 | 2019-07-08 14:25:43 -0600 | [diff] [blame] | 2196 | def testList(self): |
| 2197 | """Test listing the files in an image""" |
| 2198 | self._CheckLz4() |
| 2199 | data = self._DoReadFile('127_list.dts') |
| 2200 | image = control.images['image'] |
| 2201 | entries = image.BuildEntryList() |
| 2202 | self.assertEqual(7, len(entries)) |
| 2203 | |
| 2204 | ent = entries[0] |
| 2205 | self.assertEqual(0, ent.indent) |
| 2206 | self.assertEqual('main-section', ent.name) |
| 2207 | self.assertEqual('section', ent.etype) |
| 2208 | self.assertEqual(len(data), ent.size) |
| 2209 | self.assertEqual(0, ent.image_pos) |
| 2210 | self.assertEqual(None, ent.uncomp_size) |
| 2211 | self.assertEqual(None, ent.offset) |
| 2212 | |
| 2213 | ent = entries[1] |
| 2214 | self.assertEqual(1, ent.indent) |
| 2215 | self.assertEqual('u-boot', ent.name) |
| 2216 | self.assertEqual('u-boot', ent.etype) |
| 2217 | self.assertEqual(len(U_BOOT_DATA), ent.size) |
| 2218 | self.assertEqual(0, ent.image_pos) |
| 2219 | self.assertEqual(None, ent.uncomp_size) |
| 2220 | self.assertEqual(0, ent.offset) |
| 2221 | |
| 2222 | ent = entries[2] |
| 2223 | self.assertEqual(1, ent.indent) |
| 2224 | self.assertEqual('section', ent.name) |
| 2225 | self.assertEqual('section', ent.etype) |
| 2226 | section_size = ent.size |
| 2227 | self.assertEqual(0x100, ent.image_pos) |
| 2228 | self.assertEqual(None, ent.uncomp_size) |
| 2229 | self.assertEqual(len(U_BOOT_DATA), ent.offset) |
| 2230 | |
| 2231 | ent = entries[3] |
| 2232 | self.assertEqual(2, ent.indent) |
| 2233 | self.assertEqual('cbfs', ent.name) |
| 2234 | self.assertEqual('cbfs', ent.etype) |
| 2235 | self.assertEqual(0x400, ent.size) |
| 2236 | self.assertEqual(0x100, ent.image_pos) |
| 2237 | self.assertEqual(None, ent.uncomp_size) |
| 2238 | self.assertEqual(0, ent.offset) |
| 2239 | |
| 2240 | ent = entries[4] |
| 2241 | self.assertEqual(3, ent.indent) |
| 2242 | self.assertEqual('u-boot', ent.name) |
| 2243 | self.assertEqual('u-boot', ent.etype) |
| 2244 | self.assertEqual(len(U_BOOT_DATA), ent.size) |
| 2245 | self.assertEqual(0x138, ent.image_pos) |
| 2246 | self.assertEqual(None, ent.uncomp_size) |
| 2247 | self.assertEqual(0x38, ent.offset) |
| 2248 | |
| 2249 | ent = entries[5] |
| 2250 | self.assertEqual(3, ent.indent) |
| 2251 | self.assertEqual('u-boot-dtb', ent.name) |
| 2252 | self.assertEqual('text', ent.etype) |
| 2253 | self.assertGreater(len(COMPRESS_DATA), ent.size) |
| 2254 | self.assertEqual(0x178, ent.image_pos) |
| 2255 | self.assertEqual(len(COMPRESS_DATA), ent.uncomp_size) |
| 2256 | self.assertEqual(0x78, ent.offset) |
| 2257 | |
| 2258 | ent = entries[6] |
| 2259 | self.assertEqual(2, ent.indent) |
| 2260 | self.assertEqual('u-boot-dtb', ent.name) |
| 2261 | self.assertEqual('u-boot-dtb', ent.etype) |
| 2262 | self.assertEqual(0x500, ent.image_pos) |
| 2263 | self.assertEqual(len(U_BOOT_DTB_DATA), ent.uncomp_size) |
| 2264 | dtb_size = ent.size |
| 2265 | # Compressing this data expands it since headers are added |
| 2266 | self.assertGreater(dtb_size, len(U_BOOT_DTB_DATA)) |
| 2267 | self.assertEqual(0x400, ent.offset) |
| 2268 | |
| 2269 | self.assertEqual(len(data), 0x100 + section_size) |
| 2270 | self.assertEqual(section_size, 0x400 + dtb_size) |
| 2271 | |
Simon Glass | e1925fa | 2019-07-08 14:25:44 -0600 | [diff] [blame] | 2272 | def testFindFdtmap(self): |
| 2273 | """Test locating an FDT map in an image""" |
| 2274 | self._CheckLz4() |
| 2275 | data = self.data = self._DoReadFileRealDtb('128_decode_image.dts') |
| 2276 | image = control.images['image'] |
| 2277 | entries = image.GetEntries() |
| 2278 | entry = entries['fdtmap'] |
| 2279 | self.assertEqual(entry.image_pos, fdtmap.LocateFdtmap(data)) |
| 2280 | |
| 2281 | def testFindFdtmapMissing(self): |
| 2282 | """Test failing to locate an FDP map""" |
| 2283 | data = self._DoReadFile('005_simple.dts') |
| 2284 | self.assertEqual(None, fdtmap.LocateFdtmap(data)) |
| 2285 | |
Simon Glass | 2d26003 | 2019-07-08 14:25:45 -0600 | [diff] [blame^] | 2286 | def testFindImageHeader(self): |
| 2287 | """Test locating a image header""" |
| 2288 | self._CheckLz4() |
| 2289 | data = self._DoReadFileDtb('128_decode_image.dts', use_real_dtb=True, |
| 2290 | update_dtb=True)[0] |
| 2291 | image = control.images['image'] |
| 2292 | entries = image.GetEntries() |
| 2293 | entry = entries['fdtmap'] |
| 2294 | # The header should point to the FDT map |
| 2295 | self.assertEqual(entry.image_pos, image_header.LocateHeaderOffset(data)) |
| 2296 | |
| 2297 | def testFindImageHeaderStart(self): |
| 2298 | """Test locating a image header located at the start of an image""" |
| 2299 | data = self._DoReadFileDtb('117_fdtmap_hdr_start.dts', |
| 2300 | use_real_dtb=True, update_dtb=True)[0] |
| 2301 | image = control.images['image'] |
| 2302 | entries = image.GetEntries() |
| 2303 | entry = entries['fdtmap'] |
| 2304 | # The header should point to the FDT map |
| 2305 | self.assertEqual(entry.image_pos, image_header.LocateHeaderOffset(data)) |
| 2306 | |
| 2307 | def testFindImageHeaderMissing(self): |
| 2308 | """Test failing to locate an image header""" |
| 2309 | data = self._DoReadFile('005_simple.dts') |
| 2310 | self.assertEqual(None, image_header.LocateHeaderOffset(data)) |
| 2311 | |
Simon Glass | e073d4e | 2019-07-08 13:18:56 -0600 | [diff] [blame] | 2312 | |
Simon Glass | 9fc60b4 | 2017-11-12 21:52:22 -0700 | [diff] [blame] | 2313 | if __name__ == "__main__": |
| 2314 | unittest.main() |