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