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