1#!/usr/bin/env python3 2# 3# Functional test that boots a Linux kernel on a Raspberry Pi machine 4# and checks the console 5# 6# SPDX-License-Identifier: GPL-2.0-or-later 7 8from qemu_test import LinuxKernelTest, Asset 9from qemu_test import exec_command_and_wait_for_pattern 10 11 12class Aarch64Raspi4Machine(LinuxKernelTest): 13 14 """ 15 The kernel can be rebuilt using the kernel source referenced 16 and following the instructions on the on: 17 https://www.raspberrypi.org/documentation/linux/kernel/building.md 18 """ 19 ASSET_KERNEL_20190215 = Asset( 20 ('http://archive.raspberrypi.org/debian/' 21 'pool/main/r/raspberrypi-firmware/' 22 'raspberrypi-kernel_1.20230106-1_arm64.deb'), 23 '56d5713c8f6eee8a0d3f0e73600ec11391144fef318b08943e9abd94c0a9baf7') 24 25 ASSET_INITRD = Asset( 26 ('https://github.com/groeck/linux-build-test/raw/' 27 '86b2be1384d41c8c388e63078a847f1e1c4cb1de/rootfs/' 28 'arm64/rootfs.cpio.gz'), 29 '7c0b16d1853772f6f4c3ca63e789b3b9ff4936efac9c8a01fb0c98c05c7a7648') 30 31 def test_arm_raspi4(self): 32 kernel_path = self.archive_extract(self.ASSET_KERNEL_20190215, 33 member='boot/kernel8.img') 34 dtb_path = self.archive_extract(self.ASSET_KERNEL_20190215, 35 member='boot/bcm2711-rpi-4-b.dtb') 36 37 self.set_machine('raspi4b') 38 self.vm.set_console() 39 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 40 'earlycon=pl011,mmio32,0xfe201000 ' + 41 'console=ttyAMA0,115200 ' + 42 'root=/dev/mmcblk1p2 rootwait ' + 43 'dwc_otg.fiq_fsm_enable=0') 44 self.vm.add_args('-kernel', kernel_path, 45 '-dtb', dtb_path, 46 '-append', kernel_command_line) 47 # When PCI is supported we can add a USB controller: 48 # '-device', 'qemu-xhci,bus=pcie.1,id=xhci', 49 # '-device', 'usb-kbd,bus=xhci.0', 50 self.vm.launch() 51 console_pattern = 'Kernel command line: %s' % kernel_command_line 52 self.wait_for_console_pattern(console_pattern) 53 # When USB is enabled we can look for this 54 # console_pattern = 'Product: QEMU USB Keyboard' 55 # self.wait_for_console_pattern(console_pattern) 56 console_pattern = 'Waiting for root device' 57 self.wait_for_console_pattern(console_pattern) 58 59 60 def test_arm_raspi4_initrd(self): 61 kernel_path = self.archive_extract(self.ASSET_KERNEL_20190215, 62 member='boot/kernel8.img') 63 dtb_path = self.archive_extract(self.ASSET_KERNEL_20190215, 64 member='boot/bcm2711-rpi-4-b.dtb') 65 initrd_path = self.uncompress(self.ASSET_INITRD) 66 67 self.set_machine('raspi4b') 68 self.vm.set_console() 69 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 70 'earlycon=pl011,mmio32,0xfe201000 ' + 71 'console=ttyAMA0,115200 ' + 72 'panic=-1 noreboot ' + 73 'dwc_otg.fiq_fsm_enable=0') 74 self.vm.add_args('-kernel', kernel_path, 75 '-dtb', dtb_path, 76 '-initrd', initrd_path, 77 '-append', kernel_command_line, 78 '-no-reboot') 79 # When PCI is supported we can add a USB controller: 80 # '-device', 'qemu-xhci,bus=pcie.1,id=xhci', 81 # '-device', 'usb-kbd,bus=xhci.0', 82 self.vm.launch() 83 self.wait_for_console_pattern('Boot successful.') 84 85 exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo', 86 'BCM2835') 87 exec_command_and_wait_for_pattern(self, 'cat /proc/iomem', 88 'cprman@7e101000') 89 exec_command_and_wait_for_pattern(self, 'halt', 'reboot: System halted') 90 # TODO: Raspberry Pi4 doesn't shut down properly with recent kernels 91 # Wait for VM to shut down gracefully 92 #self.vm.wait() 93 94 95if __name__ == '__main__': 96 LinuxKernelTest.main() 97