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