xref: /qemu/tests/functional/test_arm_aspeed_ast2600.py (revision 513823e7521a09ed7ad1e32e6454bac3b2cbf52d)
1#!/usr/bin/env python3
2#
3# Functional test that boots the ASPEED machines
4#
5# SPDX-License-Identifier: GPL-2.0-or-later
6
7import os
8import time
9import tempfile
10import subprocess
11
12from qemu_test import Asset
13from aspeed import AspeedTest
14from qemu_test import exec_command_and_wait_for_pattern, skipIfMissingCommands
15
16
17class AST2600Machine(AspeedTest):
18
19    ASSET_BR2_202411_AST2600_FLASH = Asset(
20        ('https://github.com/legoater/qemu-aspeed-boot/raw/master/'
21         'images/ast2600-evb/buildroot-2024.11/flash.img'),
22        '4bb2f3dfdea31199b51d66b42f686dc5374c144a7346fdc650194a5578b73609')
23
24    def test_arm_ast2600_evb_buildroot(self):
25        self.set_machine('ast2600-evb')
26
27        image_path = self.ASSET_BR2_202411_AST2600_FLASH.fetch()
28
29        self.vm.add_args('-device',
30                         'tmp105,bus=aspeed.i2c.bus.3,address=0x4d,id=tmp-test');
31        self.vm.add_args('-device',
32                         'ds1338,bus=aspeed.i2c.bus.3,address=0x32');
33        self.vm.add_args('-device',
34                         'i2c-echo,bus=aspeed.i2c.bus.3,address=0x42');
35        self.do_test_arm_aspeed_buildroot_start(image_path, '0xf00',
36                                                'ast2600-evb login:')
37
38        exec_command_and_wait_for_pattern(self,
39             'echo lm75 0x4d > /sys/class/i2c-dev/i2c-3/device/new_device',
40             'i2c i2c-3: new_device: Instantiated device lm75 at 0x4d');
41        exec_command_and_wait_for_pattern(self,
42                             'cat /sys/class/hwmon/hwmon1/temp1_input', '0')
43        self.vm.cmd('qom-set', path='/machine/peripheral/tmp-test',
44                    property='temperature', value=18000);
45        exec_command_and_wait_for_pattern(self,
46                             'cat /sys/class/hwmon/hwmon1/temp1_input', '18000')
47
48        exec_command_and_wait_for_pattern(self,
49             'echo ds1307 0x32 > /sys/class/i2c-dev/i2c-3/device/new_device',
50             'i2c i2c-3: new_device: Instantiated device ds1307 at 0x32');
51        year = time.strftime("%Y")
52        exec_command_and_wait_for_pattern(self, 'hwclock -f /dev/rtc1', year);
53
54        exec_command_and_wait_for_pattern(self,
55             'echo slave-24c02 0x1064 > /sys/bus/i2c/devices/i2c-3/new_device',
56             'i2c i2c-3: new_device: Instantiated device slave-24c02 at 0x64');
57        exec_command_and_wait_for_pattern(self,
58             'i2cset -y 3 0x42 0x64 0x00 0xaa i', '#');
59        exec_command_and_wait_for_pattern(self,
60             'hexdump /sys/bus/i2c/devices/3-1064/slave-eeprom',
61             '0000000 ffaa ffff ffff ffff ffff ffff ffff ffff');
62        self.do_test_arm_aspeed_buildroot_poweroff()
63
64    ASSET_BR2_202302_AST2600_TPM_FLASH = Asset(
65        ('https://github.com/legoater/qemu-aspeed-boot/raw/master/'
66         'images/ast2600-evb/buildroot-2023.02-tpm/flash.img'),
67        'a46009ae8a5403a0826d607215e731a8c68d27c14c41e55331706b8f9c7bd997')
68
69    @skipIfMissingCommands('swtpm')
70    def test_arm_ast2600_evb_buildroot_tpm(self):
71        self.set_machine('ast2600-evb')
72
73        image_path = self.ASSET_BR2_202302_AST2600_TPM_FLASH.fetch()
74
75        tpmstate_dir = tempfile.TemporaryDirectory(prefix="qemu_")
76        socket = os.path.join(tpmstate_dir.name, 'swtpm-socket')
77
78        # We must put the TPM state dir in /tmp/, not the build dir,
79        # because some distros use AppArmor to lock down swtpm and
80        # restrict the set of locations it can access files in.
81        subprocess.run(['swtpm', 'socket', '-d', '--tpm2',
82                        '--tpmstate', f'dir={tpmstate_dir.name}',
83                        '--ctrl', f'type=unixio,path={socket}'])
84
85        self.vm.add_args('-chardev', f'socket,id=chrtpm,path={socket}')
86        self.vm.add_args('-tpmdev', 'emulator,id=tpm0,chardev=chrtpm')
87        self.vm.add_args('-device',
88                         'tpm-tis-i2c,tpmdev=tpm0,bus=aspeed.i2c.bus.12,address=0x2e')
89        self.do_test_arm_aspeed_buildroot_start(image_path, '0xf00', 'Aspeed AST2600 EVB')
90
91        exec_command_and_wait_for_pattern(self,
92            'echo tpm_tis_i2c 0x2e > /sys/bus/i2c/devices/i2c-12/new_device',
93            'tpm_tis_i2c 12-002e: 2.0 TPM (device-id 0x1, rev-id 1)');
94        exec_command_and_wait_for_pattern(self,
95            'cat /sys/class/tpm/tpm0/pcr-sha256/0',
96            'B804724EA13F52A9072BA87FE8FDCC497DFC9DF9AA15B9088694639C431688E0');
97
98        self.do_test_arm_aspeed_buildroot_poweroff()
99
100    ASSET_SDK_V806_AST2600_A2 = Asset(
101        'https://github.com/AspeedTech-BMC/openbmc/releases/download/v08.06/ast2600-a2-obmc.tar.gz',
102        '9083506135f622d5e7351fcf7d4e1c7125cee5ba16141220c0ba88931f3681a4')
103
104    def test_arm_ast2600_evb_sdk(self):
105        self.set_machine('ast2600-evb')
106
107        self.archive_extract(self.ASSET_SDK_V806_AST2600_A2)
108
109        self.vm.add_args('-device',
110            'tmp105,bus=aspeed.i2c.bus.5,address=0x4d,id=tmp-test');
111        self.vm.add_args('-device',
112            'ds1338,bus=aspeed.i2c.bus.5,address=0x32');
113        self.do_test_arm_aspeed_sdk_start(
114            self.scratch_file("ast2600-a2", "image-bmc"))
115
116        self.wait_for_console_pattern('ast2600-a2 login:')
117
118        exec_command_and_wait_for_pattern(self, 'root', 'Password:')
119        exec_command_and_wait_for_pattern(self, '0penBmc', 'root@ast2600-a2:~#')
120
121        exec_command_and_wait_for_pattern(self,
122            'echo lm75 0x4d > /sys/class/i2c-dev/i2c-5/device/new_device',
123            'i2c i2c-5: new_device: Instantiated device lm75 at 0x4d');
124        exec_command_and_wait_for_pattern(self,
125             'cat /sys/class/hwmon/hwmon19/temp1_input', '0')
126        self.vm.cmd('qom-set', path='/machine/peripheral/tmp-test',
127                    property='temperature', value=18000);
128        exec_command_and_wait_for_pattern(self,
129             'cat /sys/class/hwmon/hwmon19/temp1_input', '18000')
130
131        exec_command_and_wait_for_pattern(self,
132             'echo ds1307 0x32 > /sys/class/i2c-dev/i2c-5/device/new_device',
133             'i2c i2c-5: new_device: Instantiated device ds1307 at 0x32');
134        year = time.strftime("%Y")
135        exec_command_and_wait_for_pattern(self,
136             '/sbin/hwclock -f /dev/rtc1', year);
137
138if __name__ == '__main__':
139    AspeedTest.main()
140