1#!/usr/bin/env python3 2# 3# Functional test that boots a Linux kernel on a Sifive U machine 4# and checks the console 5# 6# Copyright (c) Linaro Ltd. 7# 8# Author: 9# Philippe Mathieu-Daudé 10# 11# SPDX-License-Identifier: GPL-2.0-or-later 12 13import os 14 15from qemu_test import Asset, LinuxKernelTest 16from qemu_test import skipIfMissingCommands 17 18 19class SifiveU(LinuxKernelTest): 20 21 ASSET_KERNEL = Asset( 22 'https://storage.tuxboot.com/buildroot/20241119/riscv64/Image', 23 '2bd8132a3bf21570290042324fff48c987f42f2a00c08de979f43f0662ebadba') 24 ASSET_ROOTFS = Asset( 25 ('https://github.com/groeck/linux-build-test/raw/' 26 '9819da19e6eef291686fdd7b029ea00e764dc62f/rootfs/riscv64/' 27 'rootfs.ext2.gz'), 28 'b6ed95610310b7956f9bf20c4c9c0c05fea647900df441da9dfe767d24e8b28b') 29 30 def do_test_riscv64_sifive_u_mmc_spi(self, connect_card): 31 self.set_machine('sifive_u') 32 kernel_path = self.ASSET_KERNEL.fetch() 33 rootfs_path = self.uncompress(self.ASSET_ROOTFS) 34 35 self.vm.set_console() 36 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 37 'earlycon=sbi console=ttySIF0 ' 38 'root=/dev/mmcblk0 ') 39 self.vm.add_args('-kernel', kernel_path, 40 '-append', kernel_command_line, 41 '-no-reboot') 42 if connect_card: 43 kernel_command_line += 'panic=-1 noreboot rootwait ' 44 self.vm.add_args('-drive', f'file={rootfs_path},if=sd,format=raw') 45 pattern = 'Boot successful.' 46 else: 47 kernel_command_line += 'panic=0 noreboot ' 48 pattern = 'Cannot open root device "mmcblk0" or unknown-block(0,0)' 49 50 self.vm.launch() 51 self.wait_for_console_pattern(pattern) 52 53 os.remove(rootfs_path) 54 55 def test_riscv64_sifive_u_nommc_spi(self): 56 self.do_test_riscv64_sifive_u_mmc_spi(False) 57 58 def test_riscv64_sifive_u_mmc_spi(self): 59 self.do_test_riscv64_sifive_u_mmc_spi(True) 60 61 62if __name__ == '__main__': 63 LinuxKernelTest.main() 64