| 1 | #!/usr/bin/env python3 |
| 2 | # |
| 3 | # Functional test that boots a Linux kernel on an Orange Pi machine |
| 4 | # and checks the console |
| 5 | # |
| 6 | # SPDX-License-Identifier: GPL-2.0-or-later |
| 7 | |
| 8 | import os |
| 9 | import shutil |
| 10 | |
| 11 | from qemu_test import LinuxKernelTest, exec_command_and_wait_for_pattern |
| 12 | from qemu_test import Asset, interrupt_interactive_console_until_pattern |
| 13 | from qemu_test import wait_for_console_pattern, skipBigDataTest |
| 14 | from qemu_test.utils import image_pow2ceil_expand |
| 15 | |
| 16 | |
| 17 | class OrangePiMachine(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_ARMBIAN = Asset( |
| 36 | ('https://k-space.ee.armbian.com/archive/orangepipc/archive/' |
| 37 | 'Armbian_23.8.1_Orangepipc_jammy_current_6.1.47.img.xz'), |
| 38 | 'b386dff6552513b5f164ea00f94814a6b0f1da9fb90b83725e949cf797e11afb') |
| 39 | |
| 40 | ASSET_UBOOT = Asset( |
| 41 | ('http://snapshot.debian.org/archive/debian/20200108T145233Z/pool/' |
| 42 | 'main/u/u-boot/u-boot-sunxi_2020.01%2Bdfsg-1_armhf.deb'), |
| 43 | '9223d94dc283ab54df41ce9d6f69025a5b47fece29fb67a714e23aa0cdf3bdfa') |
| 44 | |
| 45 | ASSET_NETBSD = Asset( |
| 46 | ('https://archive.netbsd.org/pub/NetBSD-archive/NetBSD-9.0/' |
| 47 | 'evbarm-earmv7hf/binary/gzimg/armv7.img.gz'), |
| 48 | '20d3e07dc057e15c12452620e90ecab2047f0f7940d9cba8182ebc795927177f') |
| 49 | |
| 50 | def test_arm_orangepi(self): |
| 51 | self.set_machine('orangepi-pc') |
| 52 | kernel_path = self.archive_extract( |
| 53 | self.ASSET_DEB, member='boot/vmlinuz-6.6.16-current-sunxi') |
| 54 | dtb_path = ('usr/lib/linux-image-6.6.16-current-sunxi/' + |
| 55 | 'sun8i-h3-orangepi-pc.dtb') |
| 56 | dtb_path = self.archive_extract(self.ASSET_DEB, member=dtb_path) |
| 57 | |
| 58 | self.vm.set_console() |
| 59 | kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + |
| 60 | 'console=ttyS0,115200n8 ' |
| 61 | 'earlycon=uart,mmio32,0x1c28000') |
| 62 | self.vm.add_args('-kernel', kernel_path, |
| 63 | '-dtb', dtb_path, |
| 64 | '-append', kernel_command_line) |
| 65 | self.vm.launch() |
| 66 | console_pattern = 'Kernel command line: %s' % kernel_command_line |
| 67 | self.wait_for_console_pattern(console_pattern) |
| 68 | os.remove(kernel_path) |
| 69 | os.remove(dtb_path) |
| 70 | |
| 71 | def test_arm_orangepi_initrd(self): |
| 72 | self.set_machine('orangepi-pc') |
| 73 | kernel_path = self.archive_extract( |
| 74 | self.ASSET_DEB, member='boot/vmlinuz-6.6.16-current-sunxi') |
| 75 | dtb_path = ('usr/lib/linux-image-6.6.16-current-sunxi/' + |
| 76 | 'sun8i-h3-orangepi-pc.dtb') |
| 77 | dtb_path = self.archive_extract(self.ASSET_DEB, member=dtb_path) |
| 78 | initrd_path = self.uncompress(self.ASSET_INITRD) |
| 79 | |
| 80 | self.vm.set_console() |
| 81 | kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + |
| 82 | 'console=ttyS0,115200 ' |
| 83 | 'panic=-1 noreboot') |
| 84 | self.vm.add_args('-kernel', kernel_path, |
| 85 | '-dtb', dtb_path, |
| 86 | '-initrd', initrd_path, |
| 87 | '-append', kernel_command_line, |
| 88 | '-no-reboot') |
| 89 | self.vm.launch() |
| 90 | self.wait_for_console_pattern('Boot successful.') |
| 91 | |
| 92 | exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo', |
| 93 | 'Allwinner sun8i Family') |
| 94 | exec_command_and_wait_for_pattern(self, 'cat /proc/iomem', |
| 95 | 'system-control@1c00000') |
| 96 | exec_command_and_wait_for_pattern(self, 'reboot', |
| 97 | 'reboot: Restarting system') |
| 98 | # Wait for VM to shut down gracefully |
| 99 | self.vm.wait() |
| 100 | os.remove(kernel_path) |
| 101 | os.remove(dtb_path) |
| 102 | os.remove(initrd_path) |
| 103 | |
| 104 | def test_arm_orangepi_sd(self): |
| 105 | self.set_machine('orangepi-pc') |
| 106 | self.require_netdev('user') |
| 107 | kernel_path = self.archive_extract( |
| 108 | self.ASSET_DEB, member='boot/vmlinuz-6.6.16-current-sunxi') |
| 109 | dtb_path = ('usr/lib/linux-image-6.6.16-current-sunxi/' + |
| 110 | 'sun8i-h3-orangepi-pc.dtb') |
| 111 | dtb_path = self.archive_extract(self.ASSET_DEB, member=dtb_path) |
| 112 | rootfs_path = self.uncompress(self.ASSET_ROOTFS) |
| 113 | image_pow2ceil_expand(rootfs_path) |
| 114 | |
| 115 | self.vm.set_console() |
| 116 | kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + |
| 117 | 'console=ttyS0,115200 ' |
| 118 | 'root=/dev/mmcblk0 rootwait rw ' |
| 119 | 'panic=-1 noreboot') |
| 120 | self.vm.add_args('-kernel', kernel_path, |
| 121 | '-dtb', dtb_path, |
| 122 | '-drive', 'file=' + rootfs_path + ',if=sd,format=raw', |
| 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 | 'mmcblk0') |
| 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_orangepi_armbian(self): |
| 149 | self.set_machine('orangepi-pc') |
| 150 | self.require_netdev('user') |
| 151 | |
| 152 | # This test download a 275 MiB compressed image and expand it |
| 153 | # to 1036 MiB, but the underlying filesystem is 1552 MiB... |
| 154 | # As we expand it to 2 GiB we are safe. |
| 155 | image_path = self.uncompress(self.ASSET_ARMBIAN) |
| 156 | image_pow2ceil_expand(image_path) |
| 157 | |
| 158 | self.vm.set_console() |
| 159 | self.vm.add_args('-drive', 'file=' + image_path + ',if=sd,format=raw', |
| 160 | '-nic', 'user', |
| 161 | '-no-reboot') |
| 162 | self.vm.launch() |
| 163 | |
| 164 | kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + |
| 165 | 'console=ttyS0,115200 ' |
| 166 | 'loglevel=7 ' |
| 167 | 'nosmp ' |
| 168 | 'systemd.default_timeout_start_sec=9000 ' |
| 169 | 'systemd.mask=armbian-zram-config.service ' |
| 170 | 'systemd.mask=armbian-ramlog.service') |
| 171 | |
| 172 | self.wait_for_console_pattern('U-Boot SPL') |
| 173 | self.wait_for_console_pattern('Autoboot in ') |
| 174 | exec_command_and_wait_for_pattern(self, ' ', '=>') |
| 175 | exec_command_and_wait_for_pattern(self, "setenv extraargs '" + |
| 176 | kernel_command_line + "'", '=>') |
| 177 | exec_command_and_wait_for_pattern(self, 'boot', 'Starting kernel ...') |
| 178 | |
| 179 | self.wait_for_console_pattern('systemd[1]: Hostname set ' + |
| 180 | 'to <orangepipc>') |
| 181 | self.wait_for_console_pattern('Starting Load Kernel Modules...') |
| 182 | |
| 183 | @skipBigDataTest() |
| 184 | def test_arm_orangepi_uboot_netbsd9(self): |
| 185 | self.set_machine('orangepi-pc') |
| 186 | self.require_netdev('user') |
| 187 | |
| 188 | # This test download a 304MB compressed image and expand it to 2GB |
| 189 | # We use the common OrangePi PC 'plus' build of U-Boot for our secondary |
| 190 | # program loader (SPL). We will then set the path to the more specific |
| 191 | # OrangePi "PC" device tree blob with 'setenv fdtfile' in U-Boot prompt, |
| 192 | # before to boot NetBSD. |
| 193 | uboot_path = 'usr/lib/u-boot/orangepi_plus/u-boot-sunxi-with-spl.bin' |
| 194 | uboot_path = self.archive_extract(self.ASSET_UBOOT, member=uboot_path) |
| 195 | image_path = self.uncompress(self.ASSET_NETBSD) |
| 196 | image_pow2ceil_expand(image_path) |
| 197 | image_drive_args = 'if=sd,format=raw,snapshot=on,file=' + image_path |
| 198 | |
| 199 | # dd if=u-boot-sunxi-with-spl.bin of=armv7.img bs=1K seek=8 conv=notrunc |
| 200 | with open(uboot_path, 'rb') as f_in: |
| 201 | with open(image_path, 'r+b') as f_out: |
| 202 | f_out.seek(8 * 1024) |
| 203 | shutil.copyfileobj(f_in, f_out) |
| 204 | |
| 205 | self.vm.set_console() |
| 206 | self.vm.add_args('-nic', 'user', |
| 207 | '-drive', image_drive_args, |
| 208 | '-global', 'allwinner-rtc.base-year=2000', |
| 209 | '-no-reboot') |
| 210 | self.vm.launch() |
| 211 | wait_for_console_pattern(self, 'U-Boot 2020.01+dfsg-1') |
| 212 | interrupt_interactive_console_until_pattern(self, |
| 213 | 'Hit any key to stop autoboot:', |
| 214 | 'switch to partitions #0, OK') |
| 215 | |
| 216 | exec_command_and_wait_for_pattern(self, '', '=>') |
| 217 | cmd = 'setenv bootargs root=ld0a' |
| 218 | exec_command_and_wait_for_pattern(self, cmd, '=>') |
| 219 | cmd = 'setenv kernel netbsd-GENERIC.ub' |
| 220 | exec_command_and_wait_for_pattern(self, cmd, '=>') |
| 221 | cmd = 'setenv fdtfile dtb/sun8i-h3-orangepi-pc.dtb' |
| 222 | exec_command_and_wait_for_pattern(self, cmd, '=>') |
| 223 | cmd = ("setenv bootcmd 'fatload mmc 0:1 ${kernel_addr_r} ${kernel}; " |
| 224 | "fatload mmc 0:1 ${fdt_addr_r} ${fdtfile}; " |
| 225 | "fdt addr ${fdt_addr_r}; " |
| 226 | "bootm ${kernel_addr_r} - ${fdt_addr_r}'") |
| 227 | exec_command_and_wait_for_pattern(self, cmd, '=>') |
| 228 | |
| 229 | exec_command_and_wait_for_pattern(self, 'boot', |
| 230 | 'Booting kernel from Legacy Image') |
| 231 | wait_for_console_pattern(self, 'Starting kernel ...') |
| 232 | wait_for_console_pattern(self, 'NetBSD 9.0 (GENERIC)') |
| 233 | # Wait for user-space |
| 234 | wait_for_console_pattern(self, 'Starting root file system check') |
| 235 | |
| 236 | if __name__ == '__main__': |
| 237 | LinuxKernelTest.main() |