Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0+ |
Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame^] | 2 | # Copyright (c) 2013, Google Inc. |
Simon Glass | 301e803 | 2013-05-16 13:53:28 +0000 | [diff] [blame] | 3 | # |
Simon Glass | 77b4267 | 2017-08-05 10:28:40 -0600 | [diff] [blame] | 4 | # Sanity check of the FIT handling in U-Boot |
Simon Glass | 301e803 | 2013-05-16 13:53:28 +0000 | [diff] [blame] | 5 | |
Simon Glass | 301e803 | 2013-05-16 13:53:28 +0000 | [diff] [blame] | 6 | import os |
Simon Glass | 77b4267 | 2017-08-05 10:28:40 -0600 | [diff] [blame] | 7 | import pytest |
Simon Glass | 301e803 | 2013-05-16 13:53:28 +0000 | [diff] [blame] | 8 | import struct |
Simon Glass | 77b4267 | 2017-08-05 10:28:40 -0600 | [diff] [blame] | 9 | import u_boot_utils as util |
Simon Glass | 301e803 | 2013-05-16 13:53:28 +0000 | [diff] [blame] | 10 | |
| 11 | # Define a base ITS which we can adjust using % and a dictionary |
| 12 | base_its = ''' |
| 13 | /dts-v1/; |
| 14 | |
| 15 | / { |
| 16 | description = "Chrome OS kernel image with one or more FDT blobs"; |
| 17 | #address-cells = <1>; |
| 18 | |
| 19 | images { |
| 20 | kernel@1 { |
| 21 | data = /incbin/("%(kernel)s"); |
| 22 | type = "kernel"; |
| 23 | arch = "sandbox"; |
| 24 | os = "linux"; |
| 25 | compression = "none"; |
| 26 | load = <0x40000>; |
| 27 | entry = <0x8>; |
| 28 | }; |
Karl Apsite | 657fd2d | 2015-05-21 09:52:50 -0400 | [diff] [blame] | 29 | kernel@2 { |
| 30 | data = /incbin/("%(loadables1)s"); |
| 31 | type = "kernel"; |
| 32 | arch = "sandbox"; |
| 33 | os = "linux"; |
| 34 | compression = "none"; |
| 35 | %(loadables1_load)s |
| 36 | entry = <0x0>; |
| 37 | }; |
Simon Glass | 301e803 | 2013-05-16 13:53:28 +0000 | [diff] [blame] | 38 | fdt@1 { |
| 39 | description = "snow"; |
| 40 | data = /incbin/("u-boot.dtb"); |
| 41 | type = "flat_dt"; |
| 42 | arch = "sandbox"; |
| 43 | %(fdt_load)s |
| 44 | compression = "none"; |
| 45 | signature@1 { |
| 46 | algo = "sha1,rsa2048"; |
| 47 | key-name-hint = "dev"; |
| 48 | }; |
| 49 | }; |
| 50 | ramdisk@1 { |
| 51 | description = "snow"; |
| 52 | data = /incbin/("%(ramdisk)s"); |
| 53 | type = "ramdisk"; |
| 54 | arch = "sandbox"; |
| 55 | os = "linux"; |
| 56 | %(ramdisk_load)s |
| 57 | compression = "none"; |
| 58 | }; |
Karl Apsite | 657fd2d | 2015-05-21 09:52:50 -0400 | [diff] [blame] | 59 | ramdisk@2 { |
| 60 | description = "snow"; |
| 61 | data = /incbin/("%(loadables2)s"); |
| 62 | type = "ramdisk"; |
| 63 | arch = "sandbox"; |
| 64 | os = "linux"; |
| 65 | %(loadables2_load)s |
| 66 | compression = "none"; |
| 67 | }; |
Simon Glass | 301e803 | 2013-05-16 13:53:28 +0000 | [diff] [blame] | 68 | }; |
| 69 | configurations { |
| 70 | default = "conf@1"; |
| 71 | conf@1 { |
| 72 | kernel = "kernel@1"; |
| 73 | fdt = "fdt@1"; |
| 74 | %(ramdisk_config)s |
Karl Apsite | 657fd2d | 2015-05-21 09:52:50 -0400 | [diff] [blame] | 75 | %(loadables_config)s |
Simon Glass | 301e803 | 2013-05-16 13:53:28 +0000 | [diff] [blame] | 76 | }; |
| 77 | }; |
| 78 | }; |
| 79 | ''' |
| 80 | |
| 81 | # Define a base FDT - currently we don't use anything in this |
| 82 | base_fdt = ''' |
| 83 | /dts-v1/; |
| 84 | |
| 85 | / { |
| 86 | model = "Sandbox Verified Boot Test"; |
| 87 | compatible = "sandbox"; |
| 88 | |
Simon Glass | 0edd82e | 2016-02-24 09:14:44 -0700 | [diff] [blame] | 89 | reset@0 { |
| 90 | compatible = "sandbox,reset"; |
| 91 | }; |
| 92 | |
Simon Glass | 301e803 | 2013-05-16 13:53:28 +0000 | [diff] [blame] | 93 | }; |
| 94 | ''' |
| 95 | |
Robert P. J. Day | b28c5fc | 2017-03-13 06:50:55 -0400 | [diff] [blame] | 96 | # This is the U-Boot script that is run for each test. First load the FIT, |
| 97 | # then run the 'bootm' command, then save out memory from the places where |
Simon Glass | 301e803 | 2013-05-16 13:53:28 +0000 | [diff] [blame] | 98 | # we expect 'bootm' to write things. Then quit. |
| 99 | base_script = ''' |
Simon Glass | dfe6f4d | 2014-08-22 14:26:44 -0600 | [diff] [blame] | 100 | sb load hostfs 0 %(fit_addr)x %(fit)s |
Simon Glass | 301e803 | 2013-05-16 13:53:28 +0000 | [diff] [blame] | 101 | fdt addr %(fit_addr)x |
| 102 | bootm start %(fit_addr)x |
| 103 | bootm loados |
Simon Glass | b5493d1 | 2014-12-02 13:17:31 -0700 | [diff] [blame] | 104 | sb save hostfs 0 %(kernel_addr)x %(kernel_out)s %(kernel_size)x |
| 105 | sb save hostfs 0 %(fdt_addr)x %(fdt_out)s %(fdt_size)x |
| 106 | sb save hostfs 0 %(ramdisk_addr)x %(ramdisk_out)s %(ramdisk_size)x |
Karl Apsite | 657fd2d | 2015-05-21 09:52:50 -0400 | [diff] [blame] | 107 | sb save hostfs 0 %(loadables1_addr)x %(loadables1_out)s %(loadables1_size)x |
| 108 | sb save hostfs 0 %(loadables2_addr)x %(loadables2_out)s %(loadables2_size)x |
Simon Glass | 301e803 | 2013-05-16 13:53:28 +0000 | [diff] [blame] | 109 | ''' |
| 110 | |
Simon Glass | 77b4267 | 2017-08-05 10:28:40 -0600 | [diff] [blame] | 111 | @pytest.mark.boardspec('sandbox') |
| 112 | @pytest.mark.buildconfigspec('fit_signature') |
Stephen Warren | 2d26bf6 | 2017-09-18 11:11:49 -0600 | [diff] [blame] | 113 | @pytest.mark.requiredtool('dtc') |
Simon Glass | 77b4267 | 2017-08-05 10:28:40 -0600 | [diff] [blame] | 114 | def test_fit(u_boot_console): |
Simon Glass | bde6712 | 2017-08-05 10:28:39 -0600 | [diff] [blame] | 115 | def make_fname(leaf): |
| 116 | """Make a temporary filename |
| 117 | |
| 118 | Args: |
| 119 | leaf: Leaf name of file to create (within temporary directory) |
| 120 | Return: |
| 121 | Temporary filename |
| 122 | """ |
Simon Glass | bde6712 | 2017-08-05 10:28:39 -0600 | [diff] [blame] | 123 | |
Simon Glass | 77b4267 | 2017-08-05 10:28:40 -0600 | [diff] [blame] | 124 | return os.path.join(cons.config.build_dir, leaf) |
Simon Glass | bde6712 | 2017-08-05 10:28:39 -0600 | [diff] [blame] | 125 | |
| 126 | def filesize(fname): |
| 127 | """Get the size of a file |
| 128 | |
| 129 | Args: |
| 130 | fname: Filename to check |
| 131 | Return: |
| 132 | Size of file in bytes |
| 133 | """ |
| 134 | return os.stat(fname).st_size |
| 135 | |
| 136 | def read_file(fname): |
| 137 | """Read the contents of a file |
| 138 | |
| 139 | Args: |
| 140 | fname: Filename to read |
| 141 | Returns: |
| 142 | Contents of file as a string |
| 143 | """ |
| 144 | with open(fname, 'r') as fd: |
| 145 | return fd.read() |
| 146 | |
| 147 | def make_dtb(): |
| 148 | """Make a sample .dts file and compile it to a .dtb |
| 149 | |
| 150 | Returns: |
| 151 | Filename of .dtb file created |
| 152 | """ |
| 153 | src = make_fname('u-boot.dts') |
| 154 | dtb = make_fname('u-boot.dtb') |
| 155 | with open(src, 'w') as fd: |
Simon Glass | 77b4267 | 2017-08-05 10:28:40 -0600 | [diff] [blame] | 156 | print >> fd, base_fdt |
| 157 | util.run_and_log(cons, ['dtc', src, '-O', 'dtb', '-o', dtb]) |
Simon Glass | bde6712 | 2017-08-05 10:28:39 -0600 | [diff] [blame] | 158 | return dtb |
| 159 | |
| 160 | def make_its(params): |
| 161 | """Make a sample .its file with parameters embedded |
| 162 | |
| 163 | Args: |
| 164 | params: Dictionary containing parameters to embed in the %() strings |
| 165 | Returns: |
| 166 | Filename of .its file created |
| 167 | """ |
| 168 | its = make_fname('test.its') |
| 169 | with open(its, 'w') as fd: |
Simon Glass | 77b4267 | 2017-08-05 10:28:40 -0600 | [diff] [blame] | 170 | print >> fd, base_its % params |
Simon Glass | bde6712 | 2017-08-05 10:28:39 -0600 | [diff] [blame] | 171 | return its |
| 172 | |
| 173 | def make_fit(mkimage, params): |
| 174 | """Make a sample .fit file ready for loading |
| 175 | |
| 176 | This creates a .its script with the selected parameters and uses mkimage to |
| 177 | turn this into a .fit image. |
| 178 | |
| 179 | Args: |
| 180 | mkimage: Filename of 'mkimage' utility |
| 181 | params: Dictionary containing parameters to embed in the %() strings |
| 182 | Return: |
| 183 | Filename of .fit file created |
| 184 | """ |
| 185 | fit = make_fname('test.fit') |
| 186 | its = make_its(params) |
Simon Glass | 77b4267 | 2017-08-05 10:28:40 -0600 | [diff] [blame] | 187 | util.run_and_log(cons, [mkimage, '-f', its, fit]) |
Simon Glass | bde6712 | 2017-08-05 10:28:39 -0600 | [diff] [blame] | 188 | with open(make_fname('u-boot.dts'), 'w') as fd: |
Simon Glass | 77b4267 | 2017-08-05 10:28:40 -0600 | [diff] [blame] | 189 | print >> fd, base_fdt |
Simon Glass | bde6712 | 2017-08-05 10:28:39 -0600 | [diff] [blame] | 190 | return fit |
| 191 | |
| 192 | def make_kernel(filename, text): |
| 193 | """Make a sample kernel with test data |
| 194 | |
| 195 | Args: |
| 196 | filename: the name of the file you want to create |
| 197 | Returns: |
| 198 | Full path and filename of the kernel it created |
| 199 | """ |
| 200 | fname = make_fname(filename) |
| 201 | data = '' |
| 202 | for i in range(100): |
| 203 | data += 'this %s %d is unlikely to boot\n' % (text, i) |
| 204 | with open(fname, 'w') as fd: |
Simon Glass | 77b4267 | 2017-08-05 10:28:40 -0600 | [diff] [blame] | 205 | print >> fd, data |
Simon Glass | bde6712 | 2017-08-05 10:28:39 -0600 | [diff] [blame] | 206 | return fname |
| 207 | |
| 208 | def make_ramdisk(filename, text): |
| 209 | """Make a sample ramdisk with test data |
| 210 | |
| 211 | Returns: |
| 212 | Filename of ramdisk created |
| 213 | """ |
| 214 | fname = make_fname(filename) |
| 215 | data = '' |
| 216 | for i in range(100): |
| 217 | data += '%s %d was seldom used in the middle ages\n' % (text, i) |
| 218 | with open(fname, 'w') as fd: |
Simon Glass | 77b4267 | 2017-08-05 10:28:40 -0600 | [diff] [blame] | 219 | print >> fd, data |
Simon Glass | bde6712 | 2017-08-05 10:28:39 -0600 | [diff] [blame] | 220 | return fname |
| 221 | |
| 222 | def find_matching(text, match): |
| 223 | """Find a match in a line of text, and return the unmatched line portion |
| 224 | |
| 225 | This is used to extract a part of a line from some text. The match string |
| 226 | is used to locate the line - we use the first line that contains that |
| 227 | match text. |
| 228 | |
| 229 | Once we find a match, we discard the match string itself from the line, |
| 230 | and return what remains. |
| 231 | |
| 232 | TODO: If this function becomes more generally useful, we could change it |
| 233 | to use regex and return groups. |
| 234 | |
| 235 | Args: |
Simon Glass | 77b4267 | 2017-08-05 10:28:40 -0600 | [diff] [blame] | 236 | text: Text to check (list of strings, one for each command issued) |
Simon Glass | bde6712 | 2017-08-05 10:28:39 -0600 | [diff] [blame] | 237 | match: String to search for |
| 238 | Return: |
| 239 | String containing unmatched portion of line |
| 240 | Exceptions: |
| 241 | ValueError: If match is not found |
| 242 | |
Simon Glass | 77b4267 | 2017-08-05 10:28:40 -0600 | [diff] [blame] | 243 | >>> find_matching(['first line:10', 'second_line:20'], 'first line:') |
Simon Glass | bde6712 | 2017-08-05 10:28:39 -0600 | [diff] [blame] | 244 | '10' |
Simon Glass | 77b4267 | 2017-08-05 10:28:40 -0600 | [diff] [blame] | 245 | >>> find_matching(['first line:10', 'second_line:20'], 'second line') |
Simon Glass | bde6712 | 2017-08-05 10:28:39 -0600 | [diff] [blame] | 246 | Traceback (most recent call last): |
| 247 | ... |
| 248 | ValueError: Test aborted |
Simon Glass | 77b4267 | 2017-08-05 10:28:40 -0600 | [diff] [blame] | 249 | >>> find_matching('first line:10\', 'second_line:20'], 'second_line:') |
Simon Glass | bde6712 | 2017-08-05 10:28:39 -0600 | [diff] [blame] | 250 | '20' |
Simon Glass | 77b4267 | 2017-08-05 10:28:40 -0600 | [diff] [blame] | 251 | >>> find_matching('first line:10\', 'second_line:20\nthird_line:30'], |
| 252 | 'third_line:') |
| 253 | '30' |
Simon Glass | bde6712 | 2017-08-05 10:28:39 -0600 | [diff] [blame] | 254 | """ |
Simon Glass | 77b4267 | 2017-08-05 10:28:40 -0600 | [diff] [blame] | 255 | __tracebackhide__ = True |
| 256 | for line in '\n'.join(text).splitlines(): |
Simon Glass | bde6712 | 2017-08-05 10:28:39 -0600 | [diff] [blame] | 257 | pos = line.find(match) |
| 258 | if pos != -1: |
| 259 | return line[:pos] + line[pos + len(match):] |
| 260 | |
Simon Glass | 77b4267 | 2017-08-05 10:28:40 -0600 | [diff] [blame] | 261 | pytest.fail("Expected '%s' but not found in output") |
Simon Glass | bde6712 | 2017-08-05 10:28:39 -0600 | [diff] [blame] | 262 | |
Simon Glass | 77b4267 | 2017-08-05 10:28:40 -0600 | [diff] [blame] | 263 | def check_equal(expected_fname, actual_fname, failure_msg): |
| 264 | """Check that a file matches its expected contents |
Simon Glass | bde6712 | 2017-08-05 10:28:39 -0600 | [diff] [blame] | 265 | |
| 266 | Args: |
Simon Glass | 77b4267 | 2017-08-05 10:28:40 -0600 | [diff] [blame] | 267 | expected_fname: Filename containing expected contents |
| 268 | actual_fname: Filename containing actual contents |
| 269 | failure_msg: Message to print on failure |
Simon Glass | bde6712 | 2017-08-05 10:28:39 -0600 | [diff] [blame] | 270 | """ |
Simon Glass | 77b4267 | 2017-08-05 10:28:40 -0600 | [diff] [blame] | 271 | expected_data = read_file(expected_fname) |
| 272 | actual_data = read_file(actual_fname) |
| 273 | assert expected_data == actual_data, failure_msg |
Simon Glass | bde6712 | 2017-08-05 10:28:39 -0600 | [diff] [blame] | 274 | |
Simon Glass | 77b4267 | 2017-08-05 10:28:40 -0600 | [diff] [blame] | 275 | def check_not_equal(expected_fname, actual_fname, failure_msg): |
| 276 | """Check that a file does not match its expected contents |
Simon Glass | bde6712 | 2017-08-05 10:28:39 -0600 | [diff] [blame] | 277 | |
| 278 | Args: |
Simon Glass | 77b4267 | 2017-08-05 10:28:40 -0600 | [diff] [blame] | 279 | expected_fname: Filename containing expected contents |
| 280 | actual_fname: Filename containing actual contents |
| 281 | failure_msg: Message to print on failure |
Simon Glass | bde6712 | 2017-08-05 10:28:39 -0600 | [diff] [blame] | 282 | """ |
Simon Glass | 77b4267 | 2017-08-05 10:28:40 -0600 | [diff] [blame] | 283 | expected_data = read_file(expected_fname) |
| 284 | actual_data = read_file(actual_fname) |
| 285 | assert expected_data != actual_data, failure_msg |
Simon Glass | cc44772 | 2014-12-02 13:17:32 -0700 | [diff] [blame] | 286 | |
Simon Glass | 77b4267 | 2017-08-05 10:28:40 -0600 | [diff] [blame] | 287 | def run_fit_test(mkimage): |
Simon Glass | bde6712 | 2017-08-05 10:28:39 -0600 | [diff] [blame] | 288 | """Basic sanity check of FIT loading in U-Boot |
Simon Glass | 301e803 | 2013-05-16 13:53:28 +0000 | [diff] [blame] | 289 | |
Simon Glass | bde6712 | 2017-08-05 10:28:39 -0600 | [diff] [blame] | 290 | TODO: Almost everything: |
| 291 | - hash algorithms - invalid hash/contents should be detected |
| 292 | - signature algorithms - invalid sig/contents should be detected |
| 293 | - compression |
| 294 | - checking that errors are detected like: |
| 295 | - image overwriting |
| 296 | - missing images |
| 297 | - invalid configurations |
| 298 | - incorrect os/arch/type fields |
| 299 | - empty data |
| 300 | - images too large/small |
| 301 | - invalid FDT (e.g. putting a random binary in instead) |
| 302 | - default configuration selection |
| 303 | - bootm command line parameters should have desired effect |
| 304 | - run code coverage to make sure we are testing all the code |
| 305 | """ |
Simon Glass | bde6712 | 2017-08-05 10:28:39 -0600 | [diff] [blame] | 306 | # Set up invariant files |
| 307 | control_dtb = make_dtb() |
| 308 | kernel = make_kernel('test-kernel.bin', 'kernel') |
| 309 | ramdisk = make_ramdisk('test-ramdisk.bin', 'ramdisk') |
| 310 | loadables1 = make_kernel('test-loadables1.bin', 'lenrek') |
| 311 | loadables2 = make_ramdisk('test-loadables2.bin', 'ksidmar') |
| 312 | kernel_out = make_fname('kernel-out.bin') |
| 313 | fdt_out = make_fname('fdt-out.dtb') |
| 314 | ramdisk_out = make_fname('ramdisk-out.bin') |
| 315 | loadables1_out = make_fname('loadables1-out.bin') |
| 316 | loadables2_out = make_fname('loadables2-out.bin') |
Simon Glass | 301e803 | 2013-05-16 13:53:28 +0000 | [diff] [blame] | 317 | |
Simon Glass | bde6712 | 2017-08-05 10:28:39 -0600 | [diff] [blame] | 318 | # Set up basic parameters with default values |
| 319 | params = { |
| 320 | 'fit_addr' : 0x1000, |
Simon Glass | 301e803 | 2013-05-16 13:53:28 +0000 | [diff] [blame] | 321 | |
Simon Glass | bde6712 | 2017-08-05 10:28:39 -0600 | [diff] [blame] | 322 | 'kernel' : kernel, |
| 323 | 'kernel_out' : kernel_out, |
| 324 | 'kernel_addr' : 0x40000, |
| 325 | 'kernel_size' : filesize(kernel), |
Simon Glass | 301e803 | 2013-05-16 13:53:28 +0000 | [diff] [blame] | 326 | |
Simon Glass | bde6712 | 2017-08-05 10:28:39 -0600 | [diff] [blame] | 327 | 'fdt_out' : fdt_out, |
| 328 | 'fdt_addr' : 0x80000, |
| 329 | 'fdt_size' : filesize(control_dtb), |
| 330 | 'fdt_load' : '', |
Simon Glass | 301e803 | 2013-05-16 13:53:28 +0000 | [diff] [blame] | 331 | |
Simon Glass | bde6712 | 2017-08-05 10:28:39 -0600 | [diff] [blame] | 332 | 'ramdisk' : ramdisk, |
| 333 | 'ramdisk_out' : ramdisk_out, |
| 334 | 'ramdisk_addr' : 0xc0000, |
| 335 | 'ramdisk_size' : filesize(ramdisk), |
| 336 | 'ramdisk_load' : '', |
| 337 | 'ramdisk_config' : '', |
Simon Glass | 301e803 | 2013-05-16 13:53:28 +0000 | [diff] [blame] | 338 | |
Simon Glass | bde6712 | 2017-08-05 10:28:39 -0600 | [diff] [blame] | 339 | 'loadables1' : loadables1, |
| 340 | 'loadables1_out' : loadables1_out, |
| 341 | 'loadables1_addr' : 0x100000, |
| 342 | 'loadables1_size' : filesize(loadables1), |
| 343 | 'loadables1_load' : '', |
Simon Glass | 301e803 | 2013-05-16 13:53:28 +0000 | [diff] [blame] | 344 | |
Simon Glass | bde6712 | 2017-08-05 10:28:39 -0600 | [diff] [blame] | 345 | 'loadables2' : loadables2, |
| 346 | 'loadables2_out' : loadables2_out, |
| 347 | 'loadables2_addr' : 0x140000, |
| 348 | 'loadables2_size' : filesize(loadables2), |
| 349 | 'loadables2_load' : '', |
Simon Glass | 301e803 | 2013-05-16 13:53:28 +0000 | [diff] [blame] | 350 | |
Simon Glass | bde6712 | 2017-08-05 10:28:39 -0600 | [diff] [blame] | 351 | 'loadables_config' : '', |
| 352 | } |
Simon Glass | 301e803 | 2013-05-16 13:53:28 +0000 | [diff] [blame] | 353 | |
Simon Glass | bde6712 | 2017-08-05 10:28:39 -0600 | [diff] [blame] | 354 | # Make a basic FIT and a script to load it |
| 355 | fit = make_fit(mkimage, params) |
| 356 | params['fit'] = fit |
| 357 | cmd = base_script % params |
Simon Glass | 301e803 | 2013-05-16 13:53:28 +0000 | [diff] [blame] | 358 | |
Simon Glass | bde6712 | 2017-08-05 10:28:39 -0600 | [diff] [blame] | 359 | # First check that we can load a kernel |
| 360 | # We could perhaps reduce duplication with some loss of readability |
Simon Glass | 77b4267 | 2017-08-05 10:28:40 -0600 | [diff] [blame] | 361 | cons.config.dtb = control_dtb |
| 362 | cons.restart_uboot() |
| 363 | with cons.log.section('Kernel load'): |
| 364 | output = cons.run_command_list(cmd.splitlines()) |
| 365 | check_equal(kernel, kernel_out, 'Kernel not loaded') |
| 366 | check_not_equal(control_dtb, fdt_out, |
| 367 | 'FDT loaded but should be ignored') |
| 368 | check_not_equal(ramdisk, ramdisk_out, |
| 369 | 'Ramdisk loaded but should not be') |
Simon Glass | 301e803 | 2013-05-16 13:53:28 +0000 | [diff] [blame] | 370 | |
Simon Glass | bde6712 | 2017-08-05 10:28:39 -0600 | [diff] [blame] | 371 | # Find out the offset in the FIT where U-Boot has found the FDT |
Simon Glass | 77b4267 | 2017-08-05 10:28:40 -0600 | [diff] [blame] | 372 | line = find_matching(output, 'Booting using the fdt blob at ') |
Simon Glass | bde6712 | 2017-08-05 10:28:39 -0600 | [diff] [blame] | 373 | fit_offset = int(line, 16) - params['fit_addr'] |
| 374 | fdt_magic = struct.pack('>L', 0xd00dfeed) |
| 375 | data = read_file(fit) |
Simon Glass | 301e803 | 2013-05-16 13:53:28 +0000 | [diff] [blame] | 376 | |
Simon Glass | bde6712 | 2017-08-05 10:28:39 -0600 | [diff] [blame] | 377 | # Now find where it actually is in the FIT (skip the first word) |
| 378 | real_fit_offset = data.find(fdt_magic, 4) |
Simon Glass | 77b4267 | 2017-08-05 10:28:40 -0600 | [diff] [blame] | 379 | assert fit_offset == real_fit_offset, ( |
| 380 | 'U-Boot loaded FDT from offset %#x, FDT is actually at %#x' % |
| 381 | (fit_offset, real_fit_offset)) |
Simon Glass | 301e803 | 2013-05-16 13:53:28 +0000 | [diff] [blame] | 382 | |
Simon Glass | bde6712 | 2017-08-05 10:28:39 -0600 | [diff] [blame] | 383 | # Now a kernel and an FDT |
Simon Glass | 77b4267 | 2017-08-05 10:28:40 -0600 | [diff] [blame] | 384 | with cons.log.section('Kernel + FDT load'): |
Simon Glass | bde6712 | 2017-08-05 10:28:39 -0600 | [diff] [blame] | 385 | params['fdt_load'] = 'load = <%#x>;' % params['fdt_addr'] |
| 386 | fit = make_fit(mkimage, params) |
Simon Glass | 77b4267 | 2017-08-05 10:28:40 -0600 | [diff] [blame] | 387 | cons.restart_uboot() |
| 388 | output = cons.run_command_list(cmd.splitlines()) |
| 389 | check_equal(kernel, kernel_out, 'Kernel not loaded') |
| 390 | check_equal(control_dtb, fdt_out, 'FDT not loaded') |
| 391 | check_not_equal(ramdisk, ramdisk_out, |
| 392 | 'Ramdisk loaded but should not be') |
Simon Glass | 301e803 | 2013-05-16 13:53:28 +0000 | [diff] [blame] | 393 | |
Simon Glass | bde6712 | 2017-08-05 10:28:39 -0600 | [diff] [blame] | 394 | # Try a ramdisk |
Simon Glass | 77b4267 | 2017-08-05 10:28:40 -0600 | [diff] [blame] | 395 | with cons.log.section('Kernel + FDT + Ramdisk load'): |
Simon Glass | bde6712 | 2017-08-05 10:28:39 -0600 | [diff] [blame] | 396 | params['ramdisk_config'] = 'ramdisk = "ramdisk@1";' |
| 397 | params['ramdisk_load'] = 'load = <%#x>;' % params['ramdisk_addr'] |
| 398 | fit = make_fit(mkimage, params) |
Simon Glass | 77b4267 | 2017-08-05 10:28:40 -0600 | [diff] [blame] | 399 | cons.restart_uboot() |
| 400 | output = cons.run_command_list(cmd.splitlines()) |
| 401 | check_equal(ramdisk, ramdisk_out, 'Ramdisk not loaded') |
Simon Glass | 301e803 | 2013-05-16 13:53:28 +0000 | [diff] [blame] | 402 | |
Simon Glass | bde6712 | 2017-08-05 10:28:39 -0600 | [diff] [blame] | 403 | # Configuration with some Loadables |
Simon Glass | 77b4267 | 2017-08-05 10:28:40 -0600 | [diff] [blame] | 404 | with cons.log.section('Kernel + FDT + Ramdisk load + Loadables'): |
Simon Glass | bde6712 | 2017-08-05 10:28:39 -0600 | [diff] [blame] | 405 | params['loadables_config'] = 'loadables = "kernel@2", "ramdisk@2";' |
Simon Glass | 77b4267 | 2017-08-05 10:28:40 -0600 | [diff] [blame] | 406 | params['loadables1_load'] = ('load = <%#x>;' % |
| 407 | params['loadables1_addr']) |
| 408 | params['loadables2_load'] = ('load = <%#x>;' % |
| 409 | params['loadables2_addr']) |
Simon Glass | bde6712 | 2017-08-05 10:28:39 -0600 | [diff] [blame] | 410 | fit = make_fit(mkimage, params) |
Simon Glass | 77b4267 | 2017-08-05 10:28:40 -0600 | [diff] [blame] | 411 | cons.restart_uboot() |
| 412 | output = cons.run_command_list(cmd.splitlines()) |
| 413 | check_equal(loadables1, loadables1_out, |
| 414 | 'Loadables1 (kernel) not loaded') |
| 415 | check_equal(loadables2, loadables2_out, |
| 416 | 'Loadables2 (ramdisk) not loaded') |
Karl Apsite | 657fd2d | 2015-05-21 09:52:50 -0400 | [diff] [blame] | 417 | |
Simon Glass | 77b4267 | 2017-08-05 10:28:40 -0600 | [diff] [blame] | 418 | cons = u_boot_console |
| 419 | try: |
| 420 | # We need to use our own device tree file. Remember to restore it |
| 421 | # afterwards. |
| 422 | old_dtb = cons.config.dtb |
| 423 | mkimage = cons.config.build_dir + '/tools/mkimage' |
| 424 | run_fit_test(mkimage) |
| 425 | finally: |
| 426 | # Go back to the original U-Boot with the correct dtb. |
| 427 | cons.config.dtb = old_dtb |
| 428 | cons.restart_uboot() |