xref: /openbmc/qemu/tests/functional/test_arm_aspeed_ast2600.py (revision 862c0dec625aeb8e8832736f0bc28ad0a6874fde)
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.vm.add_args('-device',
114            'pcie-root-port,id=root_port0,slot=1,addr=8,bus=pcie.0')
115        self.vm.add_args('-device', 'e1000e,netdev=net0,bus=root_port0')
116        self.vm.add_args('-netdev', 'user,id=net0')
117        self.do_test_arm_aspeed_sdk_start(
118            self.scratch_file("ast2600-default", "image-bmc"))
119
120        self.wait_for_console_pattern('ast2600-default login:')
121
122        exec_command_and_wait_for_pattern(self, 'root', 'Password:')
123        exec_command_and_wait_for_pattern(self, '0penBmc',
124                                          'root@ast2600-default:~#')
125
126        exec_command_and_wait_for_pattern(self,
127            'echo lm75 0x4d > /sys/class/i2c-dev/i2c-5/device/new_device',
128            'i2c i2c-5: new_device: Instantiated device lm75 at 0x4d')
129        exec_command_and_wait_for_pattern(self,
130             'cat /sys/class/hwmon/hwmon19/temp1_input', '0')
131        self.vm.cmd('qom-set', path='/machine/peripheral/tmp-test',
132                    property='temperature', value=18000)
133        exec_command_and_wait_for_pattern(self,
134             'cat /sys/class/hwmon/hwmon19/temp1_input', '18000')
135
136        exec_command_and_wait_for_pattern(self,
137             'echo ds1307 0x32 > /sys/class/i2c-dev/i2c-5/device/new_device',
138             'i2c i2c-5: new_device: Instantiated device ds1307 at 0x32')
139        year = time.strftime("%Y")
140        exec_command_and_wait_for_pattern(self,
141             '/sbin/hwclock -f /dev/rtc1', year)
142
143        exec_command_and_wait_for_pattern(self,
144            'lspci -s 0001:80:00.0',
145            '0001:80:00.0 Host bridge: ASPEED Technology, Inc. AST1150 PCI-to-PCI Bridge')
146        exec_command_and_wait_for_pattern(self,
147            'lspci -s 0001:80:08.0',
148            '0001:80:08.0 PCI bridge: Red Hat, Inc. QEMU PCIe Root port')
149        exec_command_and_wait_for_pattern(self,
150            'lspci -s 0001:81:00.0',
151            '0001:81:00.0 Ethernet controller: Intel Corporation 82574L Gigabit Network Connection')
152
153    ASSET_SDK_V906_AST2600_515 = Asset(
154        'https://github.com/AspeedTech-BMC/openbmc/releases/download/v09.06/ast2600-default-515-obmc.tar.gz',
155        '5501a032f79e217aeb351302da338e5d3faec45315b46e4aae9661583669ceaa')
156
157    def test_arm_ast2600_evb_sdk_515(self):
158        self.set_machine('ast2600-evb')
159
160        self.archive_extract(self.ASSET_SDK_V906_AST2600_515)
161
162        self.do_test_arm_aspeed_sdk_start(
163            self.scratch_file("ast2600-default-515", "image-bmc"))
164
165        self.wait_for_console_pattern('ast2600-default-515 login:')
166
167
168if __name__ == '__main__':
169    AspeedTest.main()
170