1165ab274SPhilippe Mathieu-Daudé#!/usr/bin/env python3 2165ab274SPhilippe Mathieu-Daudé# 3165ab274SPhilippe Mathieu-Daudé# Functional test that boots a Linux kernel on a Raspberry Pi machine 4165ab274SPhilippe Mathieu-Daudé# and checks the console 5165ab274SPhilippe Mathieu-Daudé# 6165ab274SPhilippe Mathieu-Daudé# Copyright (c) 2019 Philippe Mathieu-Daudé <f4bug@amsat.org> 7165ab274SPhilippe Mathieu-Daudé# 8165ab274SPhilippe Mathieu-Daudé# SPDX-License-Identifier: GPL-2.0-or-later 9165ab274SPhilippe Mathieu-Daudé 10165ab274SPhilippe Mathieu-Daudéfrom qemu_test import LinuxKernelTest, Asset 11165ab274SPhilippe Mathieu-Daudéfrom qemu_test import exec_command_and_wait_for_pattern 12165ab274SPhilippe Mathieu-Daudéfrom qemu_test.utils import gzip_uncompress 13165ab274SPhilippe Mathieu-Daudé 14165ab274SPhilippe Mathieu-Daudé 15165ab274SPhilippe Mathieu-Daudéclass ArmRaspi2Machine(LinuxKernelTest): 16165ab274SPhilippe Mathieu-Daudé 17165ab274SPhilippe Mathieu-Daudé ASSET_KERNEL_20190215 = Asset( 18165ab274SPhilippe Mathieu-Daudé ('http://archive.raspberrypi.org/debian/' 19165ab274SPhilippe Mathieu-Daudé 'pool/main/r/raspberrypi-firmware/' 20165ab274SPhilippe Mathieu-Daudé 'raspberrypi-kernel_1.20190215-1_armhf.deb'), 21165ab274SPhilippe Mathieu-Daudé '9f1759f7228113da24f5ee2aa6312946ec09a83e076aba9406c46ff776dfb291') 22165ab274SPhilippe Mathieu-Daudé 23165ab274SPhilippe Mathieu-Daudé ASSET_INITRD = Asset( 24165ab274SPhilippe Mathieu-Daudé ('https://github.com/groeck/linux-build-test/raw/' 25165ab274SPhilippe Mathieu-Daudé '2eb0a73b5d5a28df3170c546ddaaa9757e1e0848/rootfs/' 26165ab274SPhilippe Mathieu-Daudé 'arm/rootfs-armv7a.cpio.gz'), 27165ab274SPhilippe Mathieu-Daudé '2c8dbdb16ea7af2dfbcbea96044dde639fb07d09fd3c4fb31f2027ef71e55ddd') 28165ab274SPhilippe Mathieu-Daudé 29165ab274SPhilippe Mathieu-Daudé def do_test_arm_raspi2(self, uart_id): 30165ab274SPhilippe Mathieu-Daudé """ 31165ab274SPhilippe Mathieu-Daudé The kernel can be rebuilt using the kernel source referenced 32165ab274SPhilippe Mathieu-Daudé and following the instructions on the on: 33165ab274SPhilippe Mathieu-Daudé https://www.raspberrypi.org/documentation/linux/kernel/building.md 34165ab274SPhilippe Mathieu-Daudé """ 35165ab274SPhilippe Mathieu-Daudé serial_kernel_cmdline = { 36165ab274SPhilippe Mathieu-Daudé 0: 'earlycon=pl011,0x3f201000 console=ttyAMA0', 37165ab274SPhilippe Mathieu-Daudé } 38*5831ed84SDaniel P. Berrangé kernel_path = self.archive_extract(self.ASSET_KERNEL_20190215, 39*5831ed84SDaniel P. Berrangé member='boot/kernel7.img') 40*5831ed84SDaniel P. Berrangé dtb_path = self.archive_extract(self.ASSET_KERNEL_20190215, 41*5831ed84SDaniel P. Berrangé member='boot/bcm2709-rpi-2-b.dtb') 42165ab274SPhilippe Mathieu-Daudé 43165ab274SPhilippe Mathieu-Daudé self.set_machine('raspi2b') 44165ab274SPhilippe Mathieu-Daudé self.vm.set_console() 45165ab274SPhilippe Mathieu-Daudé kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 46165ab274SPhilippe Mathieu-Daudé serial_kernel_cmdline[uart_id] + 47165ab274SPhilippe Mathieu-Daudé ' root=/dev/mmcblk0p2 rootwait ' + 48165ab274SPhilippe Mathieu-Daudé 'dwc_otg.fiq_fsm_enable=0') 49165ab274SPhilippe Mathieu-Daudé self.vm.add_args('-kernel', kernel_path, 50165ab274SPhilippe Mathieu-Daudé '-dtb', dtb_path, 51165ab274SPhilippe Mathieu-Daudé '-append', kernel_command_line, 52165ab274SPhilippe Mathieu-Daudé '-device', 'usb-kbd') 53165ab274SPhilippe Mathieu-Daudé self.vm.launch() 54165ab274SPhilippe Mathieu-Daudé 55165ab274SPhilippe Mathieu-Daudé console_pattern = 'Kernel command line: %s' % kernel_command_line 56165ab274SPhilippe Mathieu-Daudé self.wait_for_console_pattern(console_pattern) 57165ab274SPhilippe Mathieu-Daudé self.wait_for_console_pattern('Product: QEMU USB Keyboard') 58165ab274SPhilippe Mathieu-Daudé 59165ab274SPhilippe Mathieu-Daudé def test_arm_raspi2_uart0(self): 60165ab274SPhilippe Mathieu-Daudé self.do_test_arm_raspi2(0) 61165ab274SPhilippe Mathieu-Daudé 62165ab274SPhilippe Mathieu-Daudé def test_arm_raspi2_initrd(self): 63*5831ed84SDaniel P. Berrangé kernel_path = self.archive_extract(self.ASSET_KERNEL_20190215, 64*5831ed84SDaniel P. Berrangé member='boot/kernel7.img') 65*5831ed84SDaniel P. Berrangé dtb_path = self.archive_extract(self.ASSET_KERNEL_20190215, 66*5831ed84SDaniel P. Berrangé member='boot/bcm2709-rpi-2-b.dtb') 67165ab274SPhilippe Mathieu-Daudé initrd_path_gz = self.ASSET_INITRD.fetch() 68beaf88c8SDaniel P. Berrangé initrd_path = self.scratch_file('rootfs.cpio') 69165ab274SPhilippe Mathieu-Daudé gzip_uncompress(initrd_path_gz, initrd_path) 70165ab274SPhilippe Mathieu-Daudé 71165ab274SPhilippe Mathieu-Daudé self.set_machine('raspi2b') 72165ab274SPhilippe Mathieu-Daudé self.vm.set_console() 73165ab274SPhilippe Mathieu-Daudé kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 74165ab274SPhilippe Mathieu-Daudé 'earlycon=pl011,0x3f201000 console=ttyAMA0 ' 75165ab274SPhilippe Mathieu-Daudé 'panic=-1 noreboot ' + 76165ab274SPhilippe Mathieu-Daudé 'dwc_otg.fiq_fsm_enable=0') 77165ab274SPhilippe Mathieu-Daudé self.vm.add_args('-kernel', kernel_path, 78165ab274SPhilippe Mathieu-Daudé '-dtb', dtb_path, 79165ab274SPhilippe Mathieu-Daudé '-initrd', initrd_path, 80165ab274SPhilippe Mathieu-Daudé '-append', kernel_command_line, 81165ab274SPhilippe Mathieu-Daudé '-no-reboot') 82165ab274SPhilippe Mathieu-Daudé self.vm.launch() 83165ab274SPhilippe Mathieu-Daudé self.wait_for_console_pattern('Boot successful.') 84165ab274SPhilippe Mathieu-Daudé 85165ab274SPhilippe Mathieu-Daudé exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo', 86165ab274SPhilippe Mathieu-Daudé 'BCM2835') 87165ab274SPhilippe Mathieu-Daudé exec_command_and_wait_for_pattern(self, 'cat /proc/iomem', 88165ab274SPhilippe Mathieu-Daudé '/soc/cprman@7e101000') 89165ab274SPhilippe Mathieu-Daudé exec_command_and_wait_for_pattern(self, 'halt', 'reboot: System halted') 90165ab274SPhilippe Mathieu-Daudé # Wait for VM to shut down gracefully 91165ab274SPhilippe Mathieu-Daudé self.vm.wait() 92165ab274SPhilippe Mathieu-Daudé 93165ab274SPhilippe Mathieu-Daudé 94165ab274SPhilippe Mathieu-Daudéif __name__ == '__main__': 95165ab274SPhilippe Mathieu-Daudé LinuxKernelTest.main() 96