X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=test%2Fimage%2Ftest-fit.py;h=db0649fca8d0138103a4bfc7b26246138728ba92;hb=20fe3f1791fa836de8c0e9991dde40362350b1a0;hp=c4e821116203df4a46d1fe6a615941833d953f92;hpb=eecf9e2e78c3af4304740804b3649f3d4b8a922a;p=oweals%2Fu-boot.git diff --git a/test/image/test-fit.py b/test/image/test-fit.py index c4e8211162..db0649fca8 100755 --- a/test/image/test-fit.py +++ b/test/image/test-fit.py @@ -4,20 +4,7 @@ # # Sanity check of the FIT handling in U-Boot # -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation; either version 2 of -# the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, -# MA 02111-1307 USA +# SPDX-License-Identifier: GPL-2.0+ # # To run this: # @@ -33,6 +20,9 @@ import struct import sys import tempfile +# Enable printing of all U-Boot output +DEBUG = True + # The 'command' library in patman is convenient for running commands base_path = os.path.dirname(sys.argv[0]) patman = os.path.join(base_path, '../../tools/patman') @@ -58,6 +48,15 @@ base_its = ''' load = <0x40000>; entry = <0x8>; }; + kernel@2 { + data = /incbin/("%(loadables1)s"); + type = "kernel"; + arch = "sandbox"; + os = "linux"; + compression = "none"; + %(loadables1_load)s + entry = <0x0>; + }; fdt@1 { description = "snow"; data = /incbin/("u-boot.dtb"); @@ -79,6 +78,15 @@ base_its = ''' %(ramdisk_load)s compression = "none"; }; + ramdisk@2 { + description = "snow"; + data = /incbin/("%(loadables2)s"); + type = "ramdisk"; + arch = "sandbox"; + os = "linux"; + %(loadables2_load)s + compression = "none"; + }; }; configurations { default = "conf@1"; @@ -86,6 +94,7 @@ base_its = ''' kernel = "kernel@1"; fdt = "fdt@1"; %(ramdisk_config)s + %(loadables_config)s }; }; }; @@ -99,6 +108,10 @@ base_fdt = ''' model = "Sandbox Verified Boot Test"; compatible = "sandbox"; + reset@0 { + compatible = "sandbox,reset"; + }; + }; ''' @@ -106,16 +119,22 @@ base_fdt = ''' # then do the 'bootm' command, then save out memory from the places where # we expect 'bootm' to write things. Then quit. base_script = ''' -sb load host 0 %(fit_addr)x %(fit)s +sb load hostfs 0 %(fit_addr)x %(fit)s fdt addr %(fit_addr)x bootm start %(fit_addr)x bootm loados -sb save host 0 %(kernel_out)s %(kernel_addr)x %(kernel_size)x -sb save host 0 %(fdt_out)s %(fdt_addr)x %(fdt_size)x -sb save host 0 %(ramdisk_out)s %(ramdisk_addr)x %(ramdisk_size)x +sb save hostfs 0 %(kernel_addr)x %(kernel_out)s %(kernel_size)x +sb save hostfs 0 %(fdt_addr)x %(fdt_out)s %(fdt_size)x +sb save hostfs 0 %(ramdisk_addr)x %(ramdisk_out)s %(ramdisk_size)x +sb save hostfs 0 %(loadables1_addr)x %(loadables1_out)s %(loadables1_size)x +sb save hostfs 0 %(loadables2_addr)x %(loadables2_out)s %(loadables2_size)x reset ''' +def debug_stdout(stdout): + if DEBUG: + print stdout + def make_fname(leaf): """Make a temporary filename @@ -194,30 +213,32 @@ def make_fit(mkimage, params): print >>fd, base_fdt return fit -def make_kernel(): +def make_kernel(filename, text): """Make a sample kernel with test data + Args: + filename: the name of the file you want to create Returns: - Filename of kernel created + Full path and filename of the kernel it created """ - fname = make_fname('test-kernel.bin') + fname = make_fname(filename) data = '' for i in range(100): - data += 'this kernel %d is unlikely to boot\n' % i + data += 'this %s %d is unlikely to boot\n' % (text, i) with open(fname, 'w') as fd: print >>fd, data return fname -def make_ramdisk(): +def make_ramdisk(filename, text): """Make a sample ramdisk with test data Returns: Filename of ramdisk created """ - fname = make_fname('test-ramdisk.bin') + fname = make_fname(filename) data = '' for i in range(100): - data += 'ramdisk %d was seldom used in the middle ages\n' % i + data += '%s %d was seldom used in the middle ages\n' % (text, i) with open(fname, 'w') as fd: print >>fd, data return fname @@ -272,12 +293,13 @@ def set_test(name): test_name = name print name -def fail(msg): +def fail(msg, stdout): """Raise an error with a helpful failure message Args: msg: Message to display """ + print stdout raise ValueError("Test '%s' failed: %s" % (test_name, msg)) def run_fit_test(mkimage, u_boot): @@ -303,11 +325,15 @@ def run_fit_test(mkimage, u_boot): # Set up invariant files control_dtb = make_dtb() - kernel = make_kernel() - ramdisk = make_ramdisk() + kernel = make_kernel('test-kernel.bin', 'kernel') + ramdisk = make_ramdisk('test-ramdisk.bin', 'ramdisk') + loadables1 = make_kernel('test-loadables1.bin', 'lenrek') + loadables2 = make_ramdisk('test-loadables2.bin', 'ksidmar') kernel_out = make_fname('kernel-out.bin') fdt_out = make_fname('fdt-out.dtb') ramdisk_out = make_fname('ramdisk-out.bin') + loadables1_out = make_fname('loadables1-out.bin') + loadables2_out = make_fname('loadables2-out.bin') # Set up basic parameters with default values params = { @@ -329,6 +355,20 @@ def run_fit_test(mkimage, u_boot): 'ramdisk_size' : filesize(ramdisk), 'ramdisk_load' : '', 'ramdisk_config' : '', + + 'loadables1' : loadables1, + 'loadables1_out' : loadables1_out, + 'loadables1_addr' : 0x100000, + 'loadables1_size' : filesize(loadables1), + 'loadables1_load' : '', + + 'loadables2' : loadables2, + 'loadables2_out' : loadables2_out, + 'loadables2_addr' : 0x140000, + 'loadables2_size' : filesize(loadables2), + 'loadables2_load' : '', + + 'loadables_config' : '', } # Make a basic FIT and a script to load it @@ -340,12 +380,13 @@ def run_fit_test(mkimage, u_boot): # We could perhaps reduce duplication with some loss of readability set_test('Kernel load') stdout = command.Output(u_boot, '-d', control_dtb, '-c', cmd) + debug_stdout(stdout) if read_file(kernel) != read_file(kernel_out): - fail('Kernel not loaded') + fail('Kernel not loaded', stdout) if read_file(control_dtb) == read_file(fdt_out): - fail('FDT loaded but should be ignored') + fail('FDT loaded but should be ignored', stdout) if read_file(ramdisk) == read_file(ramdisk_out): - fail('Ramdisk loaded but should not be') + fail('Ramdisk loaded but should not be', stdout) # Find out the offset in the FIT where U-Boot has found the FDT line = find_matching(stdout, 'Booting using the fdt blob at ') @@ -357,19 +398,20 @@ def run_fit_test(mkimage, u_boot): real_fit_offset = data.find(fdt_magic, 4) if fit_offset != real_fit_offset: fail('U-Boot loaded FDT from offset %#x, FDT is actually at %#x' % - (fit_offset, real_fit_offset)) + (fit_offset, real_fit_offset), stdout) # Now a kernel and an FDT set_test('Kernel + FDT load') params['fdt_load'] = 'load = <%#x>;' % params['fdt_addr'] fit = make_fit(mkimage, params) stdout = command.Output(u_boot, '-d', control_dtb, '-c', cmd) + debug_stdout(stdout) if read_file(kernel) != read_file(kernel_out): - fail('Kernel not loaded') + fail('Kernel not loaded', stdout) if read_file(control_dtb) != read_file(fdt_out): - fail('FDT not loaded') + fail('FDT not loaded', stdout) if read_file(ramdisk) == read_file(ramdisk_out): - fail('Ramdisk loaded but should not be') + fail('Ramdisk loaded but should not be', stdout) # Try a ramdisk set_test('Kernel + FDT + Ramdisk load') @@ -377,8 +419,22 @@ def run_fit_test(mkimage, u_boot): params['ramdisk_load'] = 'load = <%#x>;' % params['ramdisk_addr'] fit = make_fit(mkimage, params) stdout = command.Output(u_boot, '-d', control_dtb, '-c', cmd) + debug_stdout(stdout) if read_file(ramdisk) != read_file(ramdisk_out): - fail('Ramdisk not loaded') + fail('Ramdisk not loaded', stdout) + + # Configuration with some Loadables + set_test('Kernel + FDT + Ramdisk load + Loadables') + params['loadables_config'] = 'loadables = "kernel@2", "ramdisk@2";' + params['loadables1_load'] = 'load = <%#x>;' % params['loadables1_addr'] + params['loadables2_load'] = 'load = <%#x>;' % params['loadables2_addr'] + fit = make_fit(mkimage, params) + stdout = command.Output(u_boot, '-d', control_dtb, '-c', cmd) + debug_stdout(stdout) + if read_file(loadables1) != read_file(loadables1_out): + fail('Loadables1 (kernel) not loaded', stdout) + if read_file(loadables2) != read_file(loadables2_out): + fail('Loadables2 (ramdisk) not loaded', stdout) def run_tests(): """Parse options, run the FIT tests and print the result"""