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