xref: /qemu/tests/functional/test_aarch64_imx8mp_evk.py (revision 57b6f8d07f1478375f85a4593a207e936c63ff59)
1#!/usr/bin/env python3
2#
3# Functional test that boots a Linux kernel and checks the console
4#
5# SPDX-License-Identifier: GPL-2.0-or-later
6
7from qemu_test import LinuxKernelTest, Asset
8
9
10class Imx8mpEvkMachine(LinuxKernelTest):
11
12    ASSET_IMAGE = Asset(
13        ('https://cloud.debian.org/images/cloud/bookworm/20231210-1590/'
14         'debian-12-generic-arm64-20231210-1590.tar.xz'),
15        '7ebf1577b32d5af6204df74b54ca2e4675de9b5a9fa14f3ff70b88eeb7b3b359')
16
17    KERNEL_OFFSET = 0x51000000
18    KERNEL_SIZE = 32622528
19    INITRD_OFFSET = 0x76000000
20    INITRD_SIZE = 30987766
21    DTB_OFFSET = 0x64F51000
22    DTB_SIZE = 45 * 1024
23
24    def extract(self, in_path, out_path, offset, size):
25        try:
26            with open(in_path, "rb") as source:
27                source.seek(offset)
28                data = source.read(size)
29            with open(out_path, "wb") as target:
30                target.write(data)
31        except (IOError, ValueError) as e:
32            self.log.error(f"Failed to extract {out_path}: {e}")
33            raise
34
35    def setUp(self):
36        super().setUp()
37
38        self.image_path = self.scratch_file("disk.raw")
39        self.kernel_path = self.scratch_file("linux")
40        self.initrd_path = self.scratch_file("initrd.zstd")
41        self.dtb_path = self.scratch_file("imx8mp-evk.dtb")
42
43        self.archive_extract(self.ASSET_IMAGE)
44        self.extract(self.image_path, self.kernel_path,
45                     self.KERNEL_OFFSET, self.KERNEL_SIZE)
46        self.extract(self.image_path, self.initrd_path,
47                     self.INITRD_OFFSET, self.INITRD_SIZE)
48        self.extract(self.image_path, self.dtb_path,
49                     self.DTB_OFFSET, self.DTB_SIZE)
50
51    def test_aarch64_imx8mp_evk_usdhc(self):
52        self.set_machine('imx8mp-evk')
53        self.vm.set_console(console_index=1)
54        self.vm.add_args('-m', '2G',
55                         '-smp', '4',
56                         '-kernel', self.kernel_path,
57                         '-initrd', self.initrd_path,
58                         '-dtb', self.dtb_path,
59                         '-append', 'root=/dev/mmcblk2p1',
60                         '-drive', f'file={self.image_path},if=sd,bus=2,'
61                                    'format=raw,id=mmcblk2,snapshot=on')
62
63        self.vm.launch()
64        self.wait_for_console_pattern('Welcome to ')
65
66if __name__ == '__main__':
67    LinuxKernelTest.main()
68