xref: /qemu/tests/functional/test_aarch64_raspi4.py (revision beaf88c895a5eda649777757c80ab4171de777ff)
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
10from qemu_test.utils import gzip_uncompress
11
12
13class Aarch64Raspi4Machine(LinuxKernelTest):
14
15    """
16    The kernel can be rebuilt using the kernel source referenced
17    and following the instructions on the on:
18    https://www.raspberrypi.org/documentation/linux/kernel/building.md
19    """
20    ASSET_KERNEL_20190215 = Asset(
21        ('http://archive.raspberrypi.org/debian/'
22         'pool/main/r/raspberrypi-firmware/'
23         'raspberrypi-kernel_1.20230106-1_arm64.deb'),
24        '56d5713c8f6eee8a0d3f0e73600ec11391144fef318b08943e9abd94c0a9baf7')
25
26    ASSET_INITRD = Asset(
27        ('https://github.com/groeck/linux-build-test/raw/'
28         '86b2be1384d41c8c388e63078a847f1e1c4cb1de/rootfs/'
29         'arm64/rootfs.cpio.gz'),
30        '7c0b16d1853772f6f4c3ca63e789b3b9ff4936efac9c8a01fb0c98c05c7a7648')
31
32    def test_arm_raspi4(self):
33        deb_path = self.ASSET_KERNEL_20190215.fetch()
34        kernel_path = self.extract_from_deb(deb_path, '/boot/kernel8.img')
35        dtb_path = self.extract_from_deb(deb_path, '/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        deb_path = self.ASSET_KERNEL_20190215.fetch()
62        kernel_path = self.extract_from_deb(deb_path, '/boot/kernel8.img')
63        dtb_path = self.extract_from_deb(deb_path, '/boot/bcm2711-rpi-4-b.dtb')
64        initrd_path_gz = self.ASSET_INITRD.fetch()
65        initrd_path = self.scratch_file('rootfs.cpio')
66        gzip_uncompress(initrd_path_gz, initrd_path)
67
68        self.set_machine('raspi4b')
69        self.vm.set_console()
70        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
71                               'earlycon=pl011,mmio32,0xfe201000 ' +
72                               'console=ttyAMA0,115200 ' +
73                               'panic=-1 noreboot ' +
74                               'dwc_otg.fiq_fsm_enable=0')
75        self.vm.add_args('-kernel', kernel_path,
76                         '-dtb', dtb_path,
77                         '-initrd', initrd_path,
78                         '-append', kernel_command_line,
79                         '-no-reboot')
80        # When PCI is supported we can add a USB controller:
81        #                '-device', 'qemu-xhci,bus=pcie.1,id=xhci',
82        #                '-device', 'usb-kbd,bus=xhci.0',
83        self.vm.launch()
84        self.wait_for_console_pattern('Boot successful.')
85
86        exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
87                                                'BCM2835')
88        exec_command_and_wait_for_pattern(self, 'cat /proc/iomem',
89                                                'cprman@7e101000')
90        exec_command_and_wait_for_pattern(self, 'halt', 'reboot: System halted')
91        # TODO: Raspberry Pi4 doesn't shut down properly with recent kernels
92        # Wait for VM to shut down gracefully
93        #self.vm.wait()
94
95
96if __name__ == '__main__':
97    LinuxKernelTest.main()
98