xref: /qemu/tests/functional/test_arm_aspeed_ast2600.py (revision 6d0d9add0d98effc7045466249921a09845225ac)
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_V906_AST2600 = Asset(
101        'https://github.com/AspeedTech-BMC/openbmc/releases/download/v09.06/ast2600-default-obmc.tar.gz',
102        '768d76e247896ad78c154b9cff4f766da2ce65f217d620b286a4a03a8a4f68f5')
103
104    def test_arm_ast2600_evb_sdk(self):
105        self.set_machine('ast2600-evb')
106
107        self.archive_extract(self.ASSET_SDK_V906_AST2600)
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-default", "image-bmc"))
115
116        self.wait_for_console_pattern('ast2600-default login:')
117
118        exec_command_and_wait_for_pattern(self, 'root', 'Password:')
119        exec_command_and_wait_for_pattern(self, '0penBmc',
120                                          'root@ast2600-default:~#')
121
122        exec_command_and_wait_for_pattern(self,
123            'echo lm75 0x4d > /sys/class/i2c-dev/i2c-5/device/new_device',
124            'i2c i2c-5: new_device: Instantiated device lm75 at 0x4d')
125        exec_command_and_wait_for_pattern(self,
126             'cat /sys/class/hwmon/hwmon19/temp1_input', '0')
127        self.vm.cmd('qom-set', path='/machine/peripheral/tmp-test',
128                    property='temperature', value=18000)
129        exec_command_and_wait_for_pattern(self,
130             'cat /sys/class/hwmon/hwmon19/temp1_input', '18000')
131
132        exec_command_and_wait_for_pattern(self,
133             'echo ds1307 0x32 > /sys/class/i2c-dev/i2c-5/device/new_device',
134             'i2c i2c-5: new_device: Instantiated device ds1307 at 0x32')
135        year = time.strftime("%Y")
136        exec_command_and_wait_for_pattern(self,
137             '/sbin/hwclock -f /dev/rtc1', year)
138
139if __name__ == '__main__':
140    AspeedTest.main()
141