blob: 5856960be2359945591a4bb39df522248bf5428e [file] [log] [blame]
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02001# SPDX-License-Identifier: GPL-2.0+
Tom Rini10e47792018-05-06 17:58:06 -04002# Copyright (c) 2013, Google Inc.
Simon Glassdb749192013-05-16 13:53:28 +00003#
Simon Glassfe394112017-08-05 10:28:40 -06004# Sanity check of the FIT handling in U-Boot
Simon Glassdb749192013-05-16 13:53:28 +00005
Simon Glassdb749192013-05-16 13:53:28 +00006import os
Simon Glassfe394112017-08-05 10:28:40 -06007import pytest
Simon Glassdb749192013-05-16 13:53:28 +00008import struct
Simon Glassfe394112017-08-05 10:28:40 -06009import u_boot_utils as util
Simon Glassdb749192013-05-16 13:53:28 +000010
11# Define a base ITS which we can adjust using % and a dictionary
12base_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 {
Simon Glass44338902021-02-15 17:08:06 -070020 kernel-1 {
Simon Glassdb749192013-05-16 13:53:28 +000021 data = /incbin/("%(kernel)s");
22 type = "kernel";
23 arch = "sandbox";
24 os = "linux";
Julius Werner97b09cd2019-07-24 19:37:55 -070025 compression = "%(compression)s";
Simon Glassdb749192013-05-16 13:53:28 +000026 load = <0x40000>;
27 entry = <0x8>;
28 };
Simon Glass44338902021-02-15 17:08:06 -070029 kernel-2 {
Karl Apsiteaad8dd72015-05-21 09:52:50 -040030 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 Glass44338902021-02-15 17:08:06 -070038 fdt-1 {
Simon Glassdb749192013-05-16 13:53:28 +000039 description = "snow";
Julius Werner97b09cd2019-07-24 19:37:55 -070040 data = /incbin/("%(fdt)s");
Simon Glassdb749192013-05-16 13:53:28 +000041 type = "flat_dt";
42 arch = "sandbox";
43 %(fdt_load)s
Julius Werner97b09cd2019-07-24 19:37:55 -070044 compression = "%(compression)s";
Simon Glass44338902021-02-15 17:08:06 -070045 signature-1 {
Simon Glassdb749192013-05-16 13:53:28 +000046 algo = "sha1,rsa2048";
47 key-name-hint = "dev";
48 };
49 };
Simon Glass44338902021-02-15 17:08:06 -070050 ramdisk-1 {
Simon Glassdb749192013-05-16 13:53:28 +000051 description = "snow";
52 data = /incbin/("%(ramdisk)s");
53 type = "ramdisk";
54 arch = "sandbox";
55 os = "linux";
56 %(ramdisk_load)s
Julius Werner97b09cd2019-07-24 19:37:55 -070057 compression = "%(compression)s";
Simon Glassdb749192013-05-16 13:53:28 +000058 };
Simon Glass44338902021-02-15 17:08:06 -070059 ramdisk-2 {
Karl Apsiteaad8dd72015-05-21 09:52:50 -040060 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 Glassdb749192013-05-16 13:53:28 +000068 };
69 configurations {
Simon Glass44338902021-02-15 17:08:06 -070070 default = "conf-1";
71 conf-1 {
72 kernel = "kernel-1";
73 fdt = "fdt-1";
Simon Glassdb749192013-05-16 13:53:28 +000074 %(ramdisk_config)s
Karl Apsiteaad8dd72015-05-21 09:52:50 -040075 %(loadables_config)s
Simon Glassdb749192013-05-16 13:53:28 +000076 };
77 };
78};
79'''
80
81# Define a base FDT - currently we don't use anything in this
82base_fdt = '''
83/dts-v1/;
84
85/ {
Heinrich Schuchardtdca10562019-12-18 11:05:59 +010086 #address-cells = <1>;
87 #size-cells = <0>;
88
89 model = "Sandbox Verified Boot Test";
90 compatible = "sandbox";
Simon Glassdb749192013-05-16 13:53:28 +000091
Philippe Reynes462d1632022-03-28 22:56:53 +020092 binman {
93 };
94
Simon Glass546bab12016-02-24 09:14:44 -070095 reset@0 {
96 compatible = "sandbox,reset";
Heinrich Schuchardtdca10562019-12-18 11:05:59 +010097 reg = <0>;
Simon Glass546bab12016-02-24 09:14:44 -070098 };
Simon Glassdb749192013-05-16 13:53:28 +000099};
100'''
101
Robert P. J. Day8445f732017-03-13 06:50:55 -0400102# This is the U-Boot script that is run for each test. First load the FIT,
103# then run the 'bootm' command, then save out memory from the places where
Simon Glassdb749192013-05-16 13:53:28 +0000104# we expect 'bootm' to write things. Then quit.
105base_script = '''
Simon Glassf250d472018-11-15 18:44:02 -0700106host load hostfs 0 %(fit_addr)x %(fit)s
Simon Glassdb749192013-05-16 13:53:28 +0000107fdt addr %(fit_addr)x
108bootm start %(fit_addr)x
109bootm loados
Simon Glassf250d472018-11-15 18:44:02 -0700110host save hostfs 0 %(kernel_addr)x %(kernel_out)s %(kernel_size)x
111host save hostfs 0 %(fdt_addr)x %(fdt_out)s %(fdt_size)x
112host save hostfs 0 %(ramdisk_addr)x %(ramdisk_out)s %(ramdisk_size)x
113host save hostfs 0 %(loadables1_addr)x %(loadables1_out)s %(loadables1_size)x
114host save hostfs 0 %(loadables2_addr)x %(loadables2_out)s %(loadables2_size)x
Simon Glassdb749192013-05-16 13:53:28 +0000115'''
116
Simon Glassfe394112017-08-05 10:28:40 -0600117@pytest.mark.boardspec('sandbox')
118@pytest.mark.buildconfigspec('fit_signature')
Stephen Warren2079db32017-09-18 11:11:49 -0600119@pytest.mark.requiredtool('dtc')
Simon Glassfe394112017-08-05 10:28:40 -0600120def test_fit(u_boot_console):
Simon Glass6867ec02017-08-05 10:28:39 -0600121 def make_fname(leaf):
122 """Make a temporary filename
Simon Glassdb749192013-05-16 13:53:28 +0000123
Simon Glass6867ec02017-08-05 10:28:39 -0600124 Args:
125 leaf: Leaf name of file to create (within temporary directory)
126 Return:
127 Temporary filename
128 """
Simon Glassdb749192013-05-16 13:53:28 +0000129
Simon Glassfe394112017-08-05 10:28:40 -0600130 return os.path.join(cons.config.build_dir, leaf)
Simon Glassdb749192013-05-16 13:53:28 +0000131
Simon Glass6867ec02017-08-05 10:28:39 -0600132 def filesize(fname):
133 """Get the size of a file
Simon Glassdb749192013-05-16 13:53:28 +0000134
Simon Glass6867ec02017-08-05 10:28:39 -0600135 Args:
136 fname: Filename to check
137 Return:
138 Size of file in bytes
139 """
140 return os.stat(fname).st_size
Simon Glassdb749192013-05-16 13:53:28 +0000141
Simon Glass6867ec02017-08-05 10:28:39 -0600142 def read_file(fname):
143 """Read the contents of a file
Simon Glassdb749192013-05-16 13:53:28 +0000144
Simon Glass6867ec02017-08-05 10:28:39 -0600145 Args:
146 fname: Filename to read
147 Returns:
148 Contents of file as a string
149 """
Paul Burton4c35e972017-09-14 14:34:48 -0700150 with open(fname, 'rb') as fd:
Simon Glass6867ec02017-08-05 10:28:39 -0600151 return fd.read()
Simon Glassdb749192013-05-16 13:53:28 +0000152
Simon Glass6867ec02017-08-05 10:28:39 -0600153 def make_dtb():
154 """Make a sample .dts file and compile it to a .dtb
Simon Glassdb749192013-05-16 13:53:28 +0000155
Simon Glass6867ec02017-08-05 10:28:39 -0600156 Returns:
157 Filename of .dtb file created
158 """
159 src = make_fname('u-boot.dts')
160 dtb = make_fname('u-boot.dtb')
161 with open(src, 'w') as fd:
Tom Rini6a990412019-10-24 11:59:21 -0400162 fd.write(base_fdt)
Simon Glassfe394112017-08-05 10:28:40 -0600163 util.run_and_log(cons, ['dtc', src, '-O', 'dtb', '-o', dtb])
Simon Glass6867ec02017-08-05 10:28:39 -0600164 return dtb
Simon Glassdb749192013-05-16 13:53:28 +0000165
Simon Glass6867ec02017-08-05 10:28:39 -0600166 def make_its(params):
167 """Make a sample .its file with parameters embedded
Simon Glassdb749192013-05-16 13:53:28 +0000168
Simon Glass6867ec02017-08-05 10:28:39 -0600169 Args:
170 params: Dictionary containing parameters to embed in the %() strings
171 Returns:
172 Filename of .its file created
173 """
174 its = make_fname('test.its')
175 with open(its, 'w') as fd:
Paul Burton00f2d202017-09-14 14:34:43 -0700176 print(base_its % params, file=fd)
Simon Glass6867ec02017-08-05 10:28:39 -0600177 return its
Simon Glassdb749192013-05-16 13:53:28 +0000178
Simon Glass6867ec02017-08-05 10:28:39 -0600179 def make_fit(mkimage, params):
180 """Make a sample .fit file ready for loading
Simon Glassdb749192013-05-16 13:53:28 +0000181
Simon Glass6867ec02017-08-05 10:28:39 -0600182 This creates a .its script with the selected parameters and uses mkimage to
183 turn this into a .fit image.
Simon Glassdb749192013-05-16 13:53:28 +0000184
Simon Glass6867ec02017-08-05 10:28:39 -0600185 Args:
186 mkimage: Filename of 'mkimage' utility
187 params: Dictionary containing parameters to embed in the %() strings
188 Return:
189 Filename of .fit file created
190 """
191 fit = make_fname('test.fit')
192 its = make_its(params)
Simon Glassfe394112017-08-05 10:28:40 -0600193 util.run_and_log(cons, [mkimage, '-f', its, fit])
Simon Glass6867ec02017-08-05 10:28:39 -0600194 with open(make_fname('u-boot.dts'), 'w') as fd:
Tom Rini6a990412019-10-24 11:59:21 -0400195 fd.write(base_fdt)
Simon Glass6867ec02017-08-05 10:28:39 -0600196 return fit
Simon Glassdb749192013-05-16 13:53:28 +0000197
Simon Glass6867ec02017-08-05 10:28:39 -0600198 def make_kernel(filename, text):
199 """Make a sample kernel with test data
Simon Glassdb749192013-05-16 13:53:28 +0000200
Simon Glass6867ec02017-08-05 10:28:39 -0600201 Args:
202 filename: the name of the file you want to create
203 Returns:
204 Full path and filename of the kernel it created
205 """
206 fname = make_fname(filename)
207 data = ''
208 for i in range(100):
209 data += 'this %s %d is unlikely to boot\n' % (text, i)
210 with open(fname, 'w') as fd:
Paul Burton00f2d202017-09-14 14:34:43 -0700211 print(data, file=fd)
Simon Glass6867ec02017-08-05 10:28:39 -0600212 return fname
Simon Glassdb749192013-05-16 13:53:28 +0000213
Simon Glass6867ec02017-08-05 10:28:39 -0600214 def make_ramdisk(filename, text):
215 """Make a sample ramdisk with test data
Simon Glassdb749192013-05-16 13:53:28 +0000216
Simon Glass6867ec02017-08-05 10:28:39 -0600217 Returns:
218 Filename of ramdisk created
219 """
220 fname = make_fname(filename)
221 data = ''
222 for i in range(100):
223 data += '%s %d was seldom used in the middle ages\n' % (text, i)
224 with open(fname, 'w') as fd:
Paul Burton00f2d202017-09-14 14:34:43 -0700225 print(data, file=fd)
Simon Glass6867ec02017-08-05 10:28:39 -0600226 return fname
Simon Glassdb749192013-05-16 13:53:28 +0000227
Julius Werner97b09cd2019-07-24 19:37:55 -0700228 def make_compressed(filename):
229 util.run_and_log(cons, ['gzip', '-f', '-k', filename])
230 return filename + '.gz'
231
Simon Glass6867ec02017-08-05 10:28:39 -0600232 def find_matching(text, match):
233 """Find a match in a line of text, and return the unmatched line portion
Simon Glassdb749192013-05-16 13:53:28 +0000234
Simon Glass6867ec02017-08-05 10:28:39 -0600235 This is used to extract a part of a line from some text. The match string
236 is used to locate the line - we use the first line that contains that
237 match text.
Simon Glassdb749192013-05-16 13:53:28 +0000238
Simon Glass6867ec02017-08-05 10:28:39 -0600239 Once we find a match, we discard the match string itself from the line,
240 and return what remains.
Simon Glassdb749192013-05-16 13:53:28 +0000241
Simon Glass6867ec02017-08-05 10:28:39 -0600242 TODO: If this function becomes more generally useful, we could change it
243 to use regex and return groups.
Simon Glassdb749192013-05-16 13:53:28 +0000244
Simon Glass6867ec02017-08-05 10:28:39 -0600245 Args:
Simon Glassfe394112017-08-05 10:28:40 -0600246 text: Text to check (list of strings, one for each command issued)
Simon Glass6867ec02017-08-05 10:28:39 -0600247 match: String to search for
248 Return:
249 String containing unmatched portion of line
250 Exceptions:
251 ValueError: If match is not found
Simon Glassdb749192013-05-16 13:53:28 +0000252
Simon Glassfe394112017-08-05 10:28:40 -0600253 >>> find_matching(['first line:10', 'second_line:20'], 'first line:')
Simon Glass6867ec02017-08-05 10:28:39 -0600254 '10'
Simon Glassfe394112017-08-05 10:28:40 -0600255 >>> find_matching(['first line:10', 'second_line:20'], 'second line')
Simon Glass6867ec02017-08-05 10:28:39 -0600256 Traceback (most recent call last):
257 ...
258 ValueError: Test aborted
Simon Glassfe394112017-08-05 10:28:40 -0600259 >>> find_matching('first line:10\', 'second_line:20'], 'second_line:')
Simon Glass6867ec02017-08-05 10:28:39 -0600260 '20'
Simon Glassfe394112017-08-05 10:28:40 -0600261 >>> find_matching('first line:10\', 'second_line:20\nthird_line:30'],
262 'third_line:')
263 '30'
Simon Glass6867ec02017-08-05 10:28:39 -0600264 """
Simon Glassfe394112017-08-05 10:28:40 -0600265 __tracebackhide__ = True
266 for line in '\n'.join(text).splitlines():
Simon Glass6867ec02017-08-05 10:28:39 -0600267 pos = line.find(match)
268 if pos != -1:
269 return line[:pos] + line[pos + len(match):]
Simon Glassdb749192013-05-16 13:53:28 +0000270
Simon Glassfe394112017-08-05 10:28:40 -0600271 pytest.fail("Expected '%s' but not found in output")
Simon Glassdb749192013-05-16 13:53:28 +0000272
Simon Glassfe394112017-08-05 10:28:40 -0600273 def check_equal(expected_fname, actual_fname, failure_msg):
274 """Check that a file matches its expected contents
Simon Glassdb749192013-05-16 13:53:28 +0000275
Julius Werner88040022019-08-02 15:52:28 -0700276 This is always used on out-buffers whose size is decided by the test
277 script anyway, which in some cases may be larger than what we're
278 actually looking for. So it's safe to truncate it to the size of the
279 expected data.
280
Simon Glass6867ec02017-08-05 10:28:39 -0600281 Args:
Simon Glassfe394112017-08-05 10:28:40 -0600282 expected_fname: Filename containing expected contents
283 actual_fname: Filename containing actual contents
284 failure_msg: Message to print on failure
Simon Glass6867ec02017-08-05 10:28:39 -0600285 """
Simon Glassfe394112017-08-05 10:28:40 -0600286 expected_data = read_file(expected_fname)
287 actual_data = read_file(actual_fname)
Julius Werner88040022019-08-02 15:52:28 -0700288 if len(expected_data) < len(actual_data):
289 actual_data = actual_data[:len(expected_data)]
Simon Glassfe394112017-08-05 10:28:40 -0600290 assert expected_data == actual_data, failure_msg
Simon Glassdb749192013-05-16 13:53:28 +0000291
Simon Glassfe394112017-08-05 10:28:40 -0600292 def check_not_equal(expected_fname, actual_fname, failure_msg):
293 """Check that a file does not match its expected contents
Simon Glassdb749192013-05-16 13:53:28 +0000294
Simon Glass6867ec02017-08-05 10:28:39 -0600295 Args:
Simon Glassfe394112017-08-05 10:28:40 -0600296 expected_fname: Filename containing expected contents
297 actual_fname: Filename containing actual contents
298 failure_msg: Message to print on failure
Simon Glass6867ec02017-08-05 10:28:39 -0600299 """
Simon Glassfe394112017-08-05 10:28:40 -0600300 expected_data = read_file(expected_fname)
301 actual_data = read_file(actual_fname)
302 assert expected_data != actual_data, failure_msg
Simon Glassdb749192013-05-16 13:53:28 +0000303
Simon Glassfe394112017-08-05 10:28:40 -0600304 def run_fit_test(mkimage):
Simon Glass6867ec02017-08-05 10:28:39 -0600305 """Basic sanity check of FIT loading in U-Boot
Simon Glassdb749192013-05-16 13:53:28 +0000306
Simon Glass6867ec02017-08-05 10:28:39 -0600307 TODO: Almost everything:
308 - hash algorithms - invalid hash/contents should be detected
309 - signature algorithms - invalid sig/contents should be detected
310 - compression
311 - checking that errors are detected like:
312 - image overwriting
313 - missing images
314 - invalid configurations
315 - incorrect os/arch/type fields
316 - empty data
317 - images too large/small
318 - invalid FDT (e.g. putting a random binary in instead)
319 - default configuration selection
320 - bootm command line parameters should have desired effect
321 - run code coverage to make sure we are testing all the code
322 """
Simon Glass6867ec02017-08-05 10:28:39 -0600323 # Set up invariant files
324 control_dtb = make_dtb()
325 kernel = make_kernel('test-kernel.bin', 'kernel')
326 ramdisk = make_ramdisk('test-ramdisk.bin', 'ramdisk')
327 loadables1 = make_kernel('test-loadables1.bin', 'lenrek')
328 loadables2 = make_ramdisk('test-loadables2.bin', 'ksidmar')
329 kernel_out = make_fname('kernel-out.bin')
Julius Werner97b09cd2019-07-24 19:37:55 -0700330 fdt = make_fname('u-boot.dtb')
Simon Glass6867ec02017-08-05 10:28:39 -0600331 fdt_out = make_fname('fdt-out.dtb')
332 ramdisk_out = make_fname('ramdisk-out.bin')
333 loadables1_out = make_fname('loadables1-out.bin')
334 loadables2_out = make_fname('loadables2-out.bin')
Simon Glassdb749192013-05-16 13:53:28 +0000335
Simon Glass6867ec02017-08-05 10:28:39 -0600336 # Set up basic parameters with default values
337 params = {
338 'fit_addr' : 0x1000,
Simon Glassdb749192013-05-16 13:53:28 +0000339
Simon Glass6867ec02017-08-05 10:28:39 -0600340 'kernel' : kernel,
341 'kernel_out' : kernel_out,
342 'kernel_addr' : 0x40000,
343 'kernel_size' : filesize(kernel),
Simon Glassdb749192013-05-16 13:53:28 +0000344
Julius Werner97b09cd2019-07-24 19:37:55 -0700345 'fdt' : fdt,
Simon Glass6867ec02017-08-05 10:28:39 -0600346 'fdt_out' : fdt_out,
347 'fdt_addr' : 0x80000,
348 'fdt_size' : filesize(control_dtb),
349 'fdt_load' : '',
Simon Glassdb749192013-05-16 13:53:28 +0000350
Simon Glass6867ec02017-08-05 10:28:39 -0600351 'ramdisk' : ramdisk,
352 'ramdisk_out' : ramdisk_out,
353 'ramdisk_addr' : 0xc0000,
354 'ramdisk_size' : filesize(ramdisk),
355 'ramdisk_load' : '',
356 'ramdisk_config' : '',
Karl Apsiteaad8dd72015-05-21 09:52:50 -0400357
Simon Glass6867ec02017-08-05 10:28:39 -0600358 'loadables1' : loadables1,
359 'loadables1_out' : loadables1_out,
360 'loadables1_addr' : 0x100000,
361 'loadables1_size' : filesize(loadables1),
362 'loadables1_load' : '',
Karl Apsiteaad8dd72015-05-21 09:52:50 -0400363
Simon Glass6867ec02017-08-05 10:28:39 -0600364 'loadables2' : loadables2,
365 'loadables2_out' : loadables2_out,
366 'loadables2_addr' : 0x140000,
367 'loadables2_size' : filesize(loadables2),
368 'loadables2_load' : '',
Karl Apsiteaad8dd72015-05-21 09:52:50 -0400369
Simon Glass6867ec02017-08-05 10:28:39 -0600370 'loadables_config' : '',
Julius Werner97b09cd2019-07-24 19:37:55 -0700371 'compression' : 'none',
Simon Glass6867ec02017-08-05 10:28:39 -0600372 }
Simon Glassdb749192013-05-16 13:53:28 +0000373
Simon Glass6867ec02017-08-05 10:28:39 -0600374 # Make a basic FIT and a script to load it
375 fit = make_fit(mkimage, params)
376 params['fit'] = fit
377 cmd = base_script % params
Simon Glassdb749192013-05-16 13:53:28 +0000378
Simon Glass6867ec02017-08-05 10:28:39 -0600379 # First check that we can load a kernel
380 # We could perhaps reduce duplication with some loss of readability
Simon Glassfe394112017-08-05 10:28:40 -0600381 cons.config.dtb = control_dtb
382 cons.restart_uboot()
383 with cons.log.section('Kernel load'):
384 output = cons.run_command_list(cmd.splitlines())
385 check_equal(kernel, kernel_out, 'Kernel not loaded')
386 check_not_equal(control_dtb, fdt_out,
387 'FDT loaded but should be ignored')
388 check_not_equal(ramdisk, ramdisk_out,
389 'Ramdisk loaded but should not be')
Simon Glassdb749192013-05-16 13:53:28 +0000390
Simon Glass6867ec02017-08-05 10:28:39 -0600391 # Find out the offset in the FIT where U-Boot has found the FDT
Simon Glassfe394112017-08-05 10:28:40 -0600392 line = find_matching(output, 'Booting using the fdt blob at ')
Simon Glass6867ec02017-08-05 10:28:39 -0600393 fit_offset = int(line, 16) - params['fit_addr']
394 fdt_magic = struct.pack('>L', 0xd00dfeed)
395 data = read_file(fit)
Simon Glassdb749192013-05-16 13:53:28 +0000396
Simon Glass6867ec02017-08-05 10:28:39 -0600397 # Now find where it actually is in the FIT (skip the first word)
398 real_fit_offset = data.find(fdt_magic, 4)
Simon Glassfe394112017-08-05 10:28:40 -0600399 assert fit_offset == real_fit_offset, (
400 'U-Boot loaded FDT from offset %#x, FDT is actually at %#x' %
401 (fit_offset, real_fit_offset))
Simon Glassdb749192013-05-16 13:53:28 +0000402
Simon Glass6867ec02017-08-05 10:28:39 -0600403 # Now a kernel and an FDT
Simon Glassfe394112017-08-05 10:28:40 -0600404 with cons.log.section('Kernel + FDT load'):
Simon Glass6867ec02017-08-05 10:28:39 -0600405 params['fdt_load'] = 'load = <%#x>;' % params['fdt_addr']
406 fit = make_fit(mkimage, params)
Simon Glassfe394112017-08-05 10:28:40 -0600407 cons.restart_uboot()
408 output = cons.run_command_list(cmd.splitlines())
409 check_equal(kernel, kernel_out, 'Kernel not loaded')
410 check_equal(control_dtb, fdt_out, 'FDT not loaded')
411 check_not_equal(ramdisk, ramdisk_out,
412 'Ramdisk loaded but should not be')
Simon Glassdb749192013-05-16 13:53:28 +0000413
Simon Glass6867ec02017-08-05 10:28:39 -0600414 # Try a ramdisk
Simon Glassfe394112017-08-05 10:28:40 -0600415 with cons.log.section('Kernel + FDT + Ramdisk load'):
Simon Glass44338902021-02-15 17:08:06 -0700416 params['ramdisk_config'] = 'ramdisk = "ramdisk-1";'
Simon Glass6867ec02017-08-05 10:28:39 -0600417 params['ramdisk_load'] = 'load = <%#x>;' % params['ramdisk_addr']
418 fit = make_fit(mkimage, params)
Simon Glassfe394112017-08-05 10:28:40 -0600419 cons.restart_uboot()
420 output = cons.run_command_list(cmd.splitlines())
421 check_equal(ramdisk, ramdisk_out, 'Ramdisk not loaded')
Simon Glassdb749192013-05-16 13:53:28 +0000422
Simon Glass6867ec02017-08-05 10:28:39 -0600423 # Configuration with some Loadables
Simon Glassfe394112017-08-05 10:28:40 -0600424 with cons.log.section('Kernel + FDT + Ramdisk load + Loadables'):
Simon Glass44338902021-02-15 17:08:06 -0700425 params['loadables_config'] = 'loadables = "kernel-2", "ramdisk-2";'
Simon Glassfe394112017-08-05 10:28:40 -0600426 params['loadables1_load'] = ('load = <%#x>;' %
427 params['loadables1_addr'])
428 params['loadables2_load'] = ('load = <%#x>;' %
429 params['loadables2_addr'])
Simon Glass6867ec02017-08-05 10:28:39 -0600430 fit = make_fit(mkimage, params)
Simon Glassfe394112017-08-05 10:28:40 -0600431 cons.restart_uboot()
432 output = cons.run_command_list(cmd.splitlines())
433 check_equal(loadables1, loadables1_out,
434 'Loadables1 (kernel) not loaded')
435 check_equal(loadables2, loadables2_out,
436 'Loadables2 (ramdisk) not loaded')
Simon Glassdb749192013-05-16 13:53:28 +0000437
Julius Werner97b09cd2019-07-24 19:37:55 -0700438 # Kernel, FDT and Ramdisk all compressed
439 with cons.log.section('(Kernel + FDT + Ramdisk) compressed'):
440 params['compression'] = 'gzip'
441 params['kernel'] = make_compressed(kernel)
442 params['fdt'] = make_compressed(fdt)
443 params['ramdisk'] = make_compressed(ramdisk)
444 fit = make_fit(mkimage, params)
445 cons.restart_uboot()
446 output = cons.run_command_list(cmd.splitlines())
447 check_equal(kernel, kernel_out, 'Kernel not loaded')
448 check_equal(control_dtb, fdt_out, 'FDT not loaded')
Julius Werner88040022019-08-02 15:52:28 -0700449 check_not_equal(ramdisk, ramdisk_out, 'Ramdisk got decompressed?')
450 check_equal(ramdisk + '.gz', ramdisk_out, 'Ramdist not loaded')
Julius Werner97b09cd2019-07-24 19:37:55 -0700451
452
Simon Glassfe394112017-08-05 10:28:40 -0600453 cons = u_boot_console
454 try:
455 # We need to use our own device tree file. Remember to restore it
456 # afterwards.
457 old_dtb = cons.config.dtb
458 mkimage = cons.config.build_dir + '/tools/mkimage'
459 run_fit_test(mkimage)
460 finally:
461 # Go back to the original U-Boot with the correct dtb.
462 cons.config.dtb = old_dtb
463 cons.restart_uboot()