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