1# SPDX-License-Identifier: GPL-2.0+ 2# Copyright 2022 Google LLC 3# 4# Test addition of VBE 5 6import pytest 7 8import fit_util 9 10# Define a base ITS which we can adjust using % and a dictionary 11base_its = ''' 12/dts-v1/; 13 14/ { 15 description = "Example kernel"; 16 17 images { 18 kernel-1 { 19 data = /incbin/("%(kernel)s"); 20 type = "kernel"; 21 arch = "sandbox"; 22 os = "linux"; 23 load = <0x40000>; 24 entry = <0x8>; 25 compression = "%(compression)s"; 26 27 random { 28 compatible = "vbe,random-rand"; 29 vbe,size = <0x40>; 30 vbe,required; 31 }; 32 aslr1 { 33 compatible = "vbe,aslr-move"; 34 vbe,align = <0x100000>; 35 }; 36 aslr2 { 37 compatible = "vbe,aslr-rand"; 38 }; 39 efi-runtime { 40 compatible = "vbe,efi-runtime-rand"; 41 }; 42 wibble { 43 compatible = "vbe,wibble"; 44 }; 45 }; 46 47 fdt-1 { 48 description = "snow"; 49 data = /incbin/("%(fdt)s"); 50 type = "flat_dt"; 51 arch = "sandbox"; 52 load = <%(fdt_addr)#x>; 53 compression = "%(compression)s"; 54 }; 55 }; 56 configurations { 57 default = "conf-1"; 58 conf-1 { 59 kernel = "kernel-1"; 60 fdt = "fdt-1"; 61 }; 62 }; 63}; 64''' 65 66# Define a base FDT - currently we don't use anything in this 67base_fdt = ''' 68/dts-v1/; 69 70/ { 71 chosen { 72 }; 73}; 74''' 75 76# This is the U-Boot script that is run for each test. First load the FIT, 77# then run the 'bootm' command, then run the unit test which checks that the 78# working tree has the required things filled in according to the OS requests 79# above (random, aslr2, etc.) 80base_script = ''' 81host load hostfs 0 %(fit_addr)x %(fit)s 82fdt addr %(fit_addr)x 83bootm start %(fit_addr)x 84bootm loados 85bootm prep 86fdt addr 87fdt print 88ut bootstd -f vbe_test_fixup_norun 89''' 90 91@pytest.mark.boardspec('sandbox_flattree') 92@pytest.mark.requiredtool('dtc') 93def test_vbe(u_boot_console): 94 cons = u_boot_console 95 kernel = fit_util.make_kernel(cons, 'vbe-kernel.bin', 'kernel') 96 fdt = fit_util.make_dtb(cons, base_fdt, 'vbe-fdt') 97 fdt_out = fit_util.make_fname(cons, 'fdt-out.dtb') 98 99 params = { 100 'fit_addr' : 0x1000, 101 102 'kernel' : kernel, 103 104 'fdt' : fdt, 105 'fdt_out' : fdt_out, 106 'fdt_addr' : 0x80000, 107 'fdt_size' : 0x1000, 108 109 'compression' : 'none', 110 } 111 mkimage = cons.config.build_dir + '/tools/mkimage' 112 fit = fit_util.make_fit(cons, mkimage, base_its, params, 'test-vbe.fit', 113 base_fdt) 114 params['fit'] = fit 115 cmd = base_script % params 116 117 with cons.log.section('Kernel load'): 118 output = cons.run_command_list(cmd.splitlines()) 119 120 assert 'Failures: 0' in output[-1] 121