1*165ab274SPhilippe Mathieu-Daudé#!/usr/bin/env python3 2*165ab274SPhilippe Mathieu-Daudé# 3*165ab274SPhilippe Mathieu-Daudé# Functional test that boots a Linux kernel on a Raspberry Pi machine 4*165ab274SPhilippe Mathieu-Daudé# and checks the console 5*165ab274SPhilippe Mathieu-Daudé# 6*165ab274SPhilippe Mathieu-Daudé# Copyright (c) 2019 Philippe Mathieu-Daudé <f4bug@amsat.org> 7*165ab274SPhilippe Mathieu-Daudé# 8*165ab274SPhilippe Mathieu-Daudé# SPDX-License-Identifier: GPL-2.0-or-later 9*165ab274SPhilippe Mathieu-Daudé 10*165ab274SPhilippe Mathieu-Daudéimport os 11*165ab274SPhilippe Mathieu-Daudé 12*165ab274SPhilippe Mathieu-Daudéfrom qemu_test import LinuxKernelTest, Asset 13*165ab274SPhilippe Mathieu-Daudéfrom qemu_test import exec_command_and_wait_for_pattern 14*165ab274SPhilippe Mathieu-Daudéfrom qemu_test.utils import gzip_uncompress 15*165ab274SPhilippe Mathieu-Daudé 16*165ab274SPhilippe Mathieu-Daudé 17*165ab274SPhilippe Mathieu-Daudéclass ArmRaspi2Machine(LinuxKernelTest): 18*165ab274SPhilippe Mathieu-Daudé 19*165ab274SPhilippe Mathieu-Daudé ASSET_KERNEL_20190215 = Asset( 20*165ab274SPhilippe Mathieu-Daudé ('http://archive.raspberrypi.org/debian/' 21*165ab274SPhilippe Mathieu-Daudé 'pool/main/r/raspberrypi-firmware/' 22*165ab274SPhilippe Mathieu-Daudé 'raspberrypi-kernel_1.20190215-1_armhf.deb'), 23*165ab274SPhilippe Mathieu-Daudé '9f1759f7228113da24f5ee2aa6312946ec09a83e076aba9406c46ff776dfb291') 24*165ab274SPhilippe Mathieu-Daudé 25*165ab274SPhilippe Mathieu-Daudé ASSET_INITRD = Asset( 26*165ab274SPhilippe Mathieu-Daudé ('https://github.com/groeck/linux-build-test/raw/' 27*165ab274SPhilippe Mathieu-Daudé '2eb0a73b5d5a28df3170c546ddaaa9757e1e0848/rootfs/' 28*165ab274SPhilippe Mathieu-Daudé 'arm/rootfs-armv7a.cpio.gz'), 29*165ab274SPhilippe Mathieu-Daudé '2c8dbdb16ea7af2dfbcbea96044dde639fb07d09fd3c4fb31f2027ef71e55ddd') 30*165ab274SPhilippe Mathieu-Daudé 31*165ab274SPhilippe Mathieu-Daudé def do_test_arm_raspi2(self, uart_id): 32*165ab274SPhilippe Mathieu-Daudé """ 33*165ab274SPhilippe Mathieu-Daudé The kernel can be rebuilt using the kernel source referenced 34*165ab274SPhilippe Mathieu-Daudé and following the instructions on the on: 35*165ab274SPhilippe Mathieu-Daudé https://www.raspberrypi.org/documentation/linux/kernel/building.md 36*165ab274SPhilippe Mathieu-Daudé """ 37*165ab274SPhilippe Mathieu-Daudé serial_kernel_cmdline = { 38*165ab274SPhilippe Mathieu-Daudé 0: 'earlycon=pl011,0x3f201000 console=ttyAMA0', 39*165ab274SPhilippe Mathieu-Daudé } 40*165ab274SPhilippe Mathieu-Daudé deb_path = self.ASSET_KERNEL_20190215.fetch() 41*165ab274SPhilippe Mathieu-Daudé kernel_path = self.extract_from_deb(deb_path, '/boot/kernel7.img') 42*165ab274SPhilippe Mathieu-Daudé dtb_path = self.extract_from_deb(deb_path, '/boot/bcm2709-rpi-2-b.dtb') 43*165ab274SPhilippe Mathieu-Daudé 44*165ab274SPhilippe Mathieu-Daudé self.set_machine('raspi2b') 45*165ab274SPhilippe Mathieu-Daudé self.vm.set_console() 46*165ab274SPhilippe Mathieu-Daudé kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 47*165ab274SPhilippe Mathieu-Daudé serial_kernel_cmdline[uart_id] + 48*165ab274SPhilippe Mathieu-Daudé ' root=/dev/mmcblk0p2 rootwait ' + 49*165ab274SPhilippe Mathieu-Daudé 'dwc_otg.fiq_fsm_enable=0') 50*165ab274SPhilippe Mathieu-Daudé self.vm.add_args('-kernel', kernel_path, 51*165ab274SPhilippe Mathieu-Daudé '-dtb', dtb_path, 52*165ab274SPhilippe Mathieu-Daudé '-append', kernel_command_line, 53*165ab274SPhilippe Mathieu-Daudé '-device', 'usb-kbd') 54*165ab274SPhilippe Mathieu-Daudé self.vm.launch() 55*165ab274SPhilippe Mathieu-Daudé 56*165ab274SPhilippe Mathieu-Daudé console_pattern = 'Kernel command line: %s' % kernel_command_line 57*165ab274SPhilippe Mathieu-Daudé self.wait_for_console_pattern(console_pattern) 58*165ab274SPhilippe Mathieu-Daudé self.wait_for_console_pattern('Product: QEMU USB Keyboard') 59*165ab274SPhilippe Mathieu-Daudé 60*165ab274SPhilippe Mathieu-Daudé def test_arm_raspi2_uart0(self): 61*165ab274SPhilippe Mathieu-Daudé self.do_test_arm_raspi2(0) 62*165ab274SPhilippe Mathieu-Daudé 63*165ab274SPhilippe Mathieu-Daudé def test_arm_raspi2_initrd(self): 64*165ab274SPhilippe Mathieu-Daudé deb_path = self.ASSET_KERNEL_20190215.fetch() 65*165ab274SPhilippe Mathieu-Daudé kernel_path = self.extract_from_deb(deb_path, '/boot/kernel7.img') 66*165ab274SPhilippe Mathieu-Daudé dtb_path = self.extract_from_deb(deb_path, '/boot/bcm2709-rpi-2-b.dtb') 67*165ab274SPhilippe Mathieu-Daudé initrd_path_gz = self.ASSET_INITRD.fetch() 68*165ab274SPhilippe Mathieu-Daudé initrd_path = os.path.join(self.workdir, 'rootfs.cpio') 69*165ab274SPhilippe Mathieu-Daudé gzip_uncompress(initrd_path_gz, initrd_path) 70*165ab274SPhilippe Mathieu-Daudé 71*165ab274SPhilippe Mathieu-Daudé self.set_machine('raspi2b') 72*165ab274SPhilippe Mathieu-Daudé self.vm.set_console() 73*165ab274SPhilippe Mathieu-Daudé kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 74*165ab274SPhilippe Mathieu-Daudé 'earlycon=pl011,0x3f201000 console=ttyAMA0 ' 75*165ab274SPhilippe Mathieu-Daudé 'panic=-1 noreboot ' + 76*165ab274SPhilippe Mathieu-Daudé 'dwc_otg.fiq_fsm_enable=0') 77*165ab274SPhilippe Mathieu-Daudé self.vm.add_args('-kernel', kernel_path, 78*165ab274SPhilippe Mathieu-Daudé '-dtb', dtb_path, 79*165ab274SPhilippe Mathieu-Daudé '-initrd', initrd_path, 80*165ab274SPhilippe Mathieu-Daudé '-append', kernel_command_line, 81*165ab274SPhilippe Mathieu-Daudé '-no-reboot') 82*165ab274SPhilippe Mathieu-Daudé self.vm.launch() 83*165ab274SPhilippe Mathieu-Daudé self.wait_for_console_pattern('Boot successful.') 84*165ab274SPhilippe Mathieu-Daudé 85*165ab274SPhilippe Mathieu-Daudé exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo', 86*165ab274SPhilippe Mathieu-Daudé 'BCM2835') 87*165ab274SPhilippe Mathieu-Daudé exec_command_and_wait_for_pattern(self, 'cat /proc/iomem', 88*165ab274SPhilippe Mathieu-Daudé '/soc/cprman@7e101000') 89*165ab274SPhilippe Mathieu-Daudé exec_command_and_wait_for_pattern(self, 'halt', 'reboot: System halted') 90*165ab274SPhilippe Mathieu-Daudé # Wait for VM to shut down gracefully 91*165ab274SPhilippe Mathieu-Daudé self.vm.wait() 92*165ab274SPhilippe Mathieu-Daudé 93*165ab274SPhilippe Mathieu-Daudé 94*165ab274SPhilippe Mathieu-Daudéif __name__ == '__main__': 95*165ab274SPhilippe Mathieu-Daudé LinuxKernelTest.main() 96