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