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(ubman): 94 kernel = fit_util.make_kernel(ubman, 'vbe-kernel.bin', 'kernel') 95 fdt = fit_util.make_dtb(ubman, base_fdt, 'vbe-fdt') 96 fdt_out = fit_util.make_fname(ubman, 'fdt-out.dtb') 97 98 params = { 99 'fit_addr' : 0x1000, 100 101 'kernel' : kernel, 102 103 'fdt' : fdt, 104 'fdt_out' : fdt_out, 105 'fdt_addr' : 0x80000, 106 'fdt_size' : 0x1000, 107 108 'compression' : 'none', 109 } 110 mkimage = ubman.config.build_dir + '/tools/mkimage' 111 fit = fit_util.make_fit(ubman, mkimage, base_its, params, 'test-vbe.fit', 112 base_fdt) 113 params['fit'] = fit 114 cmd = base_script % params 115 116 with ubman.log.section('Kernel load'): 117 output = ubman.run_command_list(cmd.splitlines()) 118 119 assert 'failures: 0' in output[-1] 120