1#!/usr/bin/env python3 2# 3# Functional test that boots a Linux kernel on a Banana Pi machine 4# and checks the console 5# 6# SPDX-License-Identifier: GPL-2.0-or-later 7 8import os 9 10from qemu_test import LinuxKernelTest, exec_command_and_wait_for_pattern 11from qemu_test import Asset, interrupt_interactive_console_until_pattern 12from qemu_test import skipBigDataTest 13from qemu_test.utils import image_pow2ceil_expand 14 15 16class BananaPiMachine(LinuxKernelTest): 17 18 ASSET_DEB = Asset( 19 ('https://apt.armbian.com/pool/main/l/linux-6.6.16/' 20 'linux-image-current-sunxi_24.2.1_armhf__6.6.16-Seb3e-D6b4a-P2359-Ce96bHfe66-HK01ba-V014b-B067e-R448a.deb'), 21 '3d968c15b121ede871dce49d13ee7644d6f74b6b121b84c9a40f51b0c80d6d22') 22 23 ASSET_INITRD = Asset( 24 ('https://github.com/groeck/linux-build-test/raw/' 25 '2eb0a73b5d5a28df3170c546ddaaa9757e1e0848/rootfs/' 26 'arm/rootfs-armv7a.cpio.gz'), 27 '2c8dbdb16ea7af2dfbcbea96044dde639fb07d09fd3c4fb31f2027ef71e55ddd') 28 29 ASSET_ROOTFS = Asset( 30 ('http://storage.kernelci.org/images/rootfs/buildroot/' 31 'buildroot-baseline/20230703.0/armel/rootfs.ext2.xz'), 32 '42b44a12965ac0afe9a88378527fb698a7dc76af50495efc2361ee1595b4e5c6') 33 34 ASSET_SD_IMAGE = Asset( 35 ('https://downloads.openwrt.org/releases/22.03.3/targets/sunxi/cortexa7/' 36 'openwrt-22.03.3-sunxi-cortexa7-sinovoip_bananapi-m2-ultra-ext4-sdcard.img.gz'), 37 '5b41b4e11423e562c6011640f9a7cd3bdd0a3d42b83430f7caa70a432e6cd82c') 38 39 def test_arm_bpim2u(self): 40 self.set_machine('bpim2u') 41 kernel_path = self.archive_extract( 42 self.ASSET_DEB, member='boot/vmlinuz-6.6.16-current-sunxi') 43 dtb_path = ('usr/lib/linux-image-6.6.16-current-sunxi/' 44 'sun8i-r40-bananapi-m2-ultra.dtb') 45 dtb_path = self.archive_extract(self.ASSET_DEB, member=dtb_path) 46 47 self.vm.set_console() 48 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 49 'console=ttyS0,115200n8 ' 50 'earlycon=uart,mmio32,0x1c28000') 51 self.vm.add_args('-kernel', kernel_path, 52 '-dtb', dtb_path, 53 '-append', kernel_command_line) 54 self.vm.launch() 55 console_pattern = 'Kernel command line: %s' % kernel_command_line 56 self.wait_for_console_pattern(console_pattern) 57 os.remove(kernel_path) 58 os.remove(dtb_path) 59 60 def test_arm_bpim2u_initrd(self): 61 self.set_machine('bpim2u') 62 kernel_path = self.archive_extract( 63 self.ASSET_DEB, member='boot/vmlinuz-6.6.16-current-sunxi') 64 dtb_path = ('usr/lib/linux-image-6.6.16-current-sunxi/' 65 'sun8i-r40-bananapi-m2-ultra.dtb') 66 dtb_path = self.archive_extract(self.ASSET_DEB, member=dtb_path) 67 initrd_path = self.uncompress(self.ASSET_INITRD) 68 69 self.vm.set_console() 70 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 71 'console=ttyS0,115200 ' 72 'panic=-1 noreboot') 73 self.vm.add_args('-kernel', kernel_path, 74 '-dtb', dtb_path, 75 '-initrd', initrd_path, 76 '-append', kernel_command_line, 77 '-no-reboot') 78 self.vm.launch() 79 self.wait_for_console_pattern('Boot successful.') 80 81 exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo', 82 'Allwinner sun8i Family') 83 exec_command_and_wait_for_pattern(self, 'cat /proc/iomem', 84 'system-control@1c00000') 85 exec_command_and_wait_for_pattern(self, 'reboot', 86 'reboot: Restarting system') 87 # Wait for VM to shut down gracefully 88 self.vm.wait() 89 os.remove(kernel_path) 90 os.remove(dtb_path) 91 os.remove(initrd_path) 92 93 def test_arm_bpim2u_gmac(self): 94 self.set_machine('bpim2u') 95 self.require_netdev('user') 96 97 deb_path = self.ASSET_DEB.fetch() 98 kernel_path = self.archive_extract( 99 self.ASSET_DEB, member='boot/vmlinuz-6.6.16-current-sunxi') 100 dtb_path = ('usr/lib/linux-image-6.6.16-current-sunxi/' 101 'sun8i-r40-bananapi-m2-ultra.dtb') 102 dtb_path = self.archive_extract(self.ASSET_DEB, member=dtb_path) 103 rootfs_path = self.uncompress(self.ASSET_ROOTFS) 104 image_pow2ceil_expand(rootfs_path) 105 106 self.vm.set_console() 107 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 108 'console=ttyS0,115200 ' 109 'root=b300 rootwait rw ' 110 'panic=-1 noreboot') 111 self.vm.add_args('-kernel', kernel_path, 112 '-dtb', dtb_path, 113 '-drive', 'file=' + rootfs_path + ',if=sd,format=raw', 114 '-net', 'nic,model=gmac,netdev=host_gmac', 115 '-netdev', 'user,id=host_gmac', 116 '-append', kernel_command_line, 117 '-no-reboot') 118 self.vm.launch() 119 shell_ready = "/bin/sh: can't access tty; job control turned off" 120 self.wait_for_console_pattern(shell_ready) 121 122 exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo', 123 'Allwinner sun8i Family') 124 exec_command_and_wait_for_pattern(self, 'cat /proc/partitions', 125 'mmcblk') 126 exec_command_and_wait_for_pattern(self, 'ifconfig eth0 up', 127 'eth0: Link is Up') 128 exec_command_and_wait_for_pattern(self, 'udhcpc eth0', 129 'udhcpc: lease of 10.0.2.15 obtained') 130 exec_command_and_wait_for_pattern(self, 'ping -c 3 10.0.2.2', 131 '3 packets transmitted, 3 packets received, 0% packet loss') 132 exec_command_and_wait_for_pattern(self, 'reboot', 133 'reboot: Restarting system') 134 # Wait for VM to shut down gracefully 135 self.vm.wait() 136 os.remove(kernel_path) 137 os.remove(dtb_path) 138 os.remove(rootfs_path) 139 140 @skipBigDataTest() 141 def test_arm_bpim2u_openwrt_22_03_3(self): 142 self.set_machine('bpim2u') 143 self.require_netdev('user') 144 145 # This test download a 8.9 MiB compressed image and expand it 146 # to 127 MiB. 147 image_path = self.uncompress(self.ASSET_SD_IMAGE) 148 image_pow2ceil_expand(image_path) 149 150 self.vm.set_console() 151 self.vm.add_args('-drive', 'file=' + image_path + ',if=sd,format=raw', 152 '-nic', 'user', 153 '-no-reboot') 154 self.vm.launch() 155 156 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 157 'usbcore.nousb ' 158 'noreboot') 159 160 self.wait_for_console_pattern('U-Boot SPL') 161 162 interrupt_interactive_console_until_pattern( 163 self, 'Hit any key to stop autoboot:', '=>') 164 exec_command_and_wait_for_pattern(self, "setenv extraargs '" + 165 kernel_command_line + "'", '=>') 166 exec_command_and_wait_for_pattern(self, 'boot', 'Starting kernel ...') 167 168 self.wait_for_console_pattern( 169 'Please press Enter to activate this console.') 170 171 exec_command_and_wait_for_pattern(self, ' ', 'root@') 172 173 exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo', 174 'Allwinner sun8i Family') 175 exec_command_and_wait_for_pattern(self, 'cat /proc/iomem', 176 'system-control@1c00000') 177 os.remove(image_path) 178 179if __name__ == '__main__': 180 LinuxKernelTest.main() 181