xref: /qemu/tests/functional/test_arm_aspeed_rainier.py (revision 5f2b9738b281894d3fdc0affbdcada2f8c0cc19e)
1#!/usr/bin/env python3
2#
3# Functional test that boots the ASPEED SoCs with firmware
4#
5# Copyright (C) 2022 ASPEED Technology Inc
6#
7# SPDX-License-Identifier: GPL-2.0-or-later
8
9import os
10import time
11import subprocess
12import tempfile
13
14from qemu_test import LinuxKernelTest, Asset
15from qemu_test import exec_command_and_wait_for_pattern
16from qemu_test import interrupt_interactive_console_until_pattern
17from qemu_test import has_cmd
18from qemu_test.utils import archive_extract
19from zipfile import ZipFile
20from unittest import skipUnless
21
22class AST2x00Machine(LinuxKernelTest):
23
24    def do_test_arm_aspeed_buildroot_start(self, image, cpu_id, pattern='Aspeed EVB'):
25        self.require_netdev('user')
26        self.vm.set_console()
27        self.vm.add_args('-drive', 'file=' + image + ',if=mtd,format=raw,read-only=true',
28                         '-net', 'nic', '-net', 'user')
29        self.vm.launch()
30
31        self.wait_for_console_pattern('U-Boot 2019.04')
32        self.wait_for_console_pattern('## Loading kernel from FIT Image')
33        self.wait_for_console_pattern('Starting kernel ...')
34        self.wait_for_console_pattern('Booting Linux on physical CPU ' + cpu_id)
35        self.wait_for_console_pattern('lease of 10.0.2.15')
36        # the line before login:
37        self.wait_for_console_pattern(pattern)
38        exec_command_and_wait_for_pattern(self, 'root', 'Password:')
39        exec_command_and_wait_for_pattern(self, 'passw0rd', '#')
40
41    def do_test_arm_aspeed_buildroot_poweroff(self):
42        exec_command_and_wait_for_pattern(self, 'poweroff',
43                                          'reboot: System halted');
44
45    ASSET_BR2_202311_AST2500_FLASH = Asset(
46        ('https://github.com/legoater/qemu-aspeed-boot/raw/master/'
47         'images/ast2500-evb/buildroot-2023.11/flash.img'),
48        'c23db6160cf77d0258397eb2051162c8473a56c441417c52a91ba217186e715f')
49
50    def test_arm_ast2500_evb_buildroot(self):
51        self.set_machine('ast2500-evb')
52
53        image_path = self.ASSET_BR2_202311_AST2500_FLASH.fetch()
54
55        self.vm.add_args('-device',
56                         'tmp105,bus=aspeed.i2c.bus.3,address=0x4d,id=tmp-test');
57        self.do_test_arm_aspeed_buildroot_start(image_path, '0x0',
58                                                'ast2500-evb login:')
59
60        exec_command_and_wait_for_pattern(self,
61             'echo lm75 0x4d > /sys/class/i2c-dev/i2c-3/device/new_device',
62             'i2c i2c-3: new_device: Instantiated device lm75 at 0x4d');
63        exec_command_and_wait_for_pattern(self,
64                             'cat /sys/class/hwmon/hwmon1/temp1_input', '0')
65        self.vm.cmd('qom-set', path='/machine/peripheral/tmp-test',
66                    property='temperature', value=18000);
67        exec_command_and_wait_for_pattern(self,
68                             'cat /sys/class/hwmon/hwmon1/temp1_input', '18000')
69
70        self.do_test_arm_aspeed_buildroot_poweroff()
71
72    ASSET_BR2_202311_AST2600_FLASH = Asset(
73        ('https://github.com/legoater/qemu-aspeed-boot/raw/master/'
74         'images/ast2600-evb/buildroot-2023.11/flash.img'),
75        'b62808daef48b438d0728ee07662290490ecfa65987bb91294cafb1bb7ad1a68')
76
77    def test_arm_ast2600_evb_buildroot(self):
78        self.set_machine('ast2600-evb')
79
80        image_path = self.ASSET_BR2_202311_AST2600_FLASH.fetch()
81
82        self.vm.add_args('-device',
83                         'tmp105,bus=aspeed.i2c.bus.3,address=0x4d,id=tmp-test');
84        self.vm.add_args('-device',
85                         'ds1338,bus=aspeed.i2c.bus.3,address=0x32');
86        self.vm.add_args('-device',
87                         'i2c-echo,bus=aspeed.i2c.bus.3,address=0x42');
88        self.do_test_arm_aspeed_buildroot_start(image_path, '0xf00',
89                                                'ast2600-evb login:')
90
91        exec_command_and_wait_for_pattern(self,
92             'echo lm75 0x4d > /sys/class/i2c-dev/i2c-3/device/new_device',
93             'i2c i2c-3: new_device: Instantiated device lm75 at 0x4d');
94        exec_command_and_wait_for_pattern(self,
95                             'cat /sys/class/hwmon/hwmon1/temp1_input', '0')
96        self.vm.cmd('qom-set', path='/machine/peripheral/tmp-test',
97                    property='temperature', value=18000);
98        exec_command_and_wait_for_pattern(self,
99                             'cat /sys/class/hwmon/hwmon1/temp1_input', '18000')
100
101        exec_command_and_wait_for_pattern(self,
102             'echo ds1307 0x32 > /sys/class/i2c-dev/i2c-3/device/new_device',
103             'i2c i2c-3: new_device: Instantiated device ds1307 at 0x32');
104        year = time.strftime("%Y")
105        exec_command_and_wait_for_pattern(self, 'hwclock -f /dev/rtc1', year);
106
107        exec_command_and_wait_for_pattern(self,
108             'echo slave-24c02 0x1064 > /sys/bus/i2c/devices/i2c-3/new_device',
109             'i2c i2c-3: new_device: Instantiated device slave-24c02 at 0x64');
110        exec_command_and_wait_for_pattern(self,
111             'i2cset -y 3 0x42 0x64 0x00 0xaa i', '#');
112        exec_command_and_wait_for_pattern(self,
113             'hexdump /sys/bus/i2c/devices/3-1064/slave-eeprom',
114             '0000000 ffaa ffff ffff ffff ffff ffff ffff ffff');
115        self.do_test_arm_aspeed_buildroot_poweroff()
116
117    ASSET_BR2_202302_AST2600_TPM_FLASH = Asset(
118        ('https://github.com/legoater/qemu-aspeed-boot/raw/master/'
119         'images/ast2600-evb/buildroot-2023.02-tpm/flash.img'),
120        'a46009ae8a5403a0826d607215e731a8c68d27c14c41e55331706b8f9c7bd997')
121
122    @skipUnless(*has_cmd('swtpm'))
123    def test_arm_ast2600_evb_buildroot_tpm(self):
124        self.set_machine('ast2600-evb')
125
126        image_path = self.ASSET_BR2_202302_AST2600_TPM_FLASH.fetch()
127
128        tpmstate_dir = tempfile.TemporaryDirectory(prefix="qemu_")
129        socket = os.path.join(tpmstate_dir.name, 'swtpm-socket')
130
131        # We must put the TPM state dir in /tmp/, not the build dir,
132        # because some distros use AppArmor to lock down swtpm and
133        # restrict the set of locations it can access files in.
134        subprocess.run(['swtpm', 'socket', '-d', '--tpm2',
135                        '--tpmstate', f'dir={tpmstate_dir.name}',
136                        '--ctrl', f'type=unixio,path={socket}'])
137
138        self.vm.add_args('-chardev', f'socket,id=chrtpm,path={socket}')
139        self.vm.add_args('-tpmdev', 'emulator,id=tpm0,chardev=chrtpm')
140        self.vm.add_args('-device',
141                         'tpm-tis-i2c,tpmdev=tpm0,bus=aspeed.i2c.bus.12,address=0x2e')
142        self.do_test_arm_aspeed_buildroot_start(image_path, '0xf00', 'Aspeed AST2600 EVB')
143
144        exec_command_and_wait_for_pattern(self,
145            'echo tpm_tis_i2c 0x2e > /sys/bus/i2c/devices/i2c-12/new_device',
146            'tpm_tis_i2c 12-002e: 2.0 TPM (device-id 0x1, rev-id 1)');
147        exec_command_and_wait_for_pattern(self,
148            'cat /sys/class/tpm/tpm0/pcr-sha256/0',
149            'B804724EA13F52A9072BA87FE8FDCC497DFC9DF9AA15B9088694639C431688E0');
150
151        self.do_test_arm_aspeed_buildroot_poweroff()
152
153    def do_test_arm_aspeed_sdk_start(self, image):
154        self.require_netdev('user')
155        self.vm.set_console()
156        self.vm.add_args('-drive', 'file=' + image + ',if=mtd,format=raw',
157                         '-net', 'nic', '-net', 'user', '-snapshot')
158        self.vm.launch()
159
160        self.wait_for_console_pattern('U-Boot 2019.04')
161        self.wait_for_console_pattern('## Loading kernel from FIT Image')
162        self.wait_for_console_pattern('Starting kernel ...')
163
164    ASSET_SDK_V806_AST2500 = Asset(
165        'https://github.com/AspeedTech-BMC/openbmc/releases/download/v08.06/ast2500-default-obmc.tar.gz',
166        'e1755f3cadff69190438c688d52dd0f0d399b70a1e14b1d3d5540fc4851d38ca')
167
168    def test_arm_ast2500_evb_sdk(self):
169        self.set_machine('ast2500-evb')
170
171        image_path = self.ASSET_SDK_V806_AST2500.fetch()
172
173        archive_extract(image_path, self.workdir)
174
175        self.do_test_arm_aspeed_sdk_start(
176            self.workdir + '/ast2500-default/image-bmc')
177
178        self.wait_for_console_pattern('ast2500-default login:')
179
180    ASSET_SDK_V806_AST2600_A2 = Asset(
181        'https://github.com/AspeedTech-BMC/openbmc/releases/download/v08.06/ast2600-a2-obmc.tar.gz',
182        '9083506135f622d5e7351fcf7d4e1c7125cee5ba16141220c0ba88931f3681a4')
183
184    def test_arm_ast2600_evb_sdk(self):
185        self.set_machine('ast2600-evb')
186
187        image_path = self.ASSET_SDK_V806_AST2600_A2.fetch()
188
189        archive_extract(image_path, self.workdir)
190
191        self.vm.add_args('-device',
192            'tmp105,bus=aspeed.i2c.bus.5,address=0x4d,id=tmp-test');
193        self.vm.add_args('-device',
194            'ds1338,bus=aspeed.i2c.bus.5,address=0x32');
195        self.do_test_arm_aspeed_sdk_start(
196            self.workdir + '/ast2600-a2/image-bmc')
197
198        self.wait_for_console_pattern('ast2600-a2 login:')
199
200        exec_command_and_wait_for_pattern(self, 'root', 'Password:')
201        exec_command_and_wait_for_pattern(self, '0penBmc', 'root@ast2600-a2:~#')
202
203        exec_command_and_wait_for_pattern(self,
204            'echo lm75 0x4d > /sys/class/i2c-dev/i2c-5/device/new_device',
205            'i2c i2c-5: new_device: Instantiated device lm75 at 0x4d');
206        exec_command_and_wait_for_pattern(self,
207             'cat /sys/class/hwmon/hwmon19/temp1_input', '0')
208        self.vm.cmd('qom-set', path='/machine/peripheral/tmp-test',
209                    property='temperature', value=18000);
210        exec_command_and_wait_for_pattern(self,
211             'cat /sys/class/hwmon/hwmon19/temp1_input', '18000')
212
213        exec_command_and_wait_for_pattern(self,
214             'echo ds1307 0x32 > /sys/class/i2c-dev/i2c-5/device/new_device',
215             'i2c i2c-5: new_device: Instantiated device ds1307 at 0x32');
216        year = time.strftime("%Y")
217        exec_command_and_wait_for_pattern(self,
218             '/sbin/hwclock -f /dev/rtc1', year);
219
220
221class AST2x00MachineMMC(LinuxKernelTest):
222
223    ASSET_RAINIER_EMMC = Asset(
224        ('https://fileserver.linaro.org/s/B6pJTwWEkzSDi36/download/'
225         'mmc-p10bmc-20240617.qcow2'),
226        'd523fb478d2b84d5adc5658d08502bc64b1486955683814f89c6137518acd90b')
227
228    def test_arm_aspeed_emmc_boot(self):
229        self.set_machine('rainier-bmc')
230        self.require_netdev('user')
231
232        image_path = self.ASSET_RAINIER_EMMC.fetch()
233
234        self.vm.set_console()
235        self.vm.add_args('-drive',
236                         'file=' + image_path + ',if=sd,id=sd2,index=2',
237                         '-net', 'nic', '-net', 'user', '-snapshot')
238        self.vm.launch()
239
240        self.wait_for_console_pattern('U-Boot SPL 2019.04')
241        self.wait_for_console_pattern('Trying to boot from MMC1')
242        self.wait_for_console_pattern('U-Boot 2019.04')
243        self.wait_for_console_pattern('eMMC 2nd Boot')
244        self.wait_for_console_pattern('## Loading kernel from FIT Image')
245        self.wait_for_console_pattern('Starting kernel ...')
246        self.wait_for_console_pattern('Booting Linux on physical CPU 0xf00')
247        self.wait_for_console_pattern('mmcblk0: p1 p2 p3 p4 p5 p6 p7')
248        self.wait_for_console_pattern('IBM eBMC (OpenBMC for IBM Enterprise')
249
250if __name__ == '__main__':
251    LinuxKernelTest.main()
252