xref: /qemu/tests/functional/test_arm_aspeed_ast2600.py (revision beaf88c895a5eda649777757c80ab4171de777ff)
1c7bc9cabSCédric Le Goater#!/usr/bin/env python3
2c7bc9cabSCédric Le Goater#
3c7bc9cabSCédric Le Goater# Functional test that boots the ASPEED machines
4c7bc9cabSCédric Le Goater#
5c7bc9cabSCédric Le Goater# SPDX-License-Identifier: GPL-2.0-or-later
6c7bc9cabSCédric Le Goater
7c7bc9cabSCédric Le Goaterimport os
8c7bc9cabSCédric Le Goaterimport time
9c7bc9cabSCédric Le Goaterimport tempfile
10c7bc9cabSCédric Le Goaterimport subprocess
11c7bc9cabSCédric Le Goater
12c7bc9cabSCédric Le Goaterfrom qemu_test import Asset
13c7bc9cabSCédric Le Goaterfrom aspeed import AspeedTest
143d593860SDaniel P. Berrangéfrom qemu_test import exec_command_and_wait_for_pattern, skipIfMissingCommands
15c7bc9cabSCédric Le Goaterfrom qemu_test.utils import archive_extract
163d593860SDaniel P. Berrangé
17c7bc9cabSCédric Le Goater
18c7bc9cabSCédric Le Goaterclass AST2600Machine(AspeedTest):
19c7bc9cabSCédric Le Goater
20c7bc9cabSCédric Le Goater    ASSET_BR2_202311_AST2600_FLASH = Asset(
21c7bc9cabSCédric Le Goater        ('https://github.com/legoater/qemu-aspeed-boot/raw/master/'
22c7bc9cabSCédric Le Goater         'images/ast2600-evb/buildroot-2023.11/flash.img'),
23c7bc9cabSCédric Le Goater        'b62808daef48b438d0728ee07662290490ecfa65987bb91294cafb1bb7ad1a68')
24c7bc9cabSCédric Le Goater
25c7bc9cabSCédric Le Goater    def test_arm_ast2600_evb_buildroot(self):
26c7bc9cabSCédric Le Goater        self.set_machine('ast2600-evb')
27c7bc9cabSCédric Le Goater
28c7bc9cabSCédric Le Goater        image_path = self.ASSET_BR2_202311_AST2600_FLASH.fetch()
29c7bc9cabSCédric Le Goater
30c7bc9cabSCédric Le Goater        self.vm.add_args('-device',
31c7bc9cabSCédric Le Goater                         'tmp105,bus=aspeed.i2c.bus.3,address=0x4d,id=tmp-test');
32c7bc9cabSCédric Le Goater        self.vm.add_args('-device',
33c7bc9cabSCédric Le Goater                         'ds1338,bus=aspeed.i2c.bus.3,address=0x32');
34c7bc9cabSCédric Le Goater        self.vm.add_args('-device',
35c7bc9cabSCédric Le Goater                         'i2c-echo,bus=aspeed.i2c.bus.3,address=0x42');
36c7bc9cabSCédric Le Goater        self.do_test_arm_aspeed_buildroot_start(image_path, '0xf00',
37c7bc9cabSCédric Le Goater                                                'ast2600-evb login:')
38c7bc9cabSCédric Le Goater
39c7bc9cabSCédric Le Goater        exec_command_and_wait_for_pattern(self,
40c7bc9cabSCédric Le Goater             'echo lm75 0x4d > /sys/class/i2c-dev/i2c-3/device/new_device',
41c7bc9cabSCédric Le Goater             'i2c i2c-3: new_device: Instantiated device lm75 at 0x4d');
42c7bc9cabSCédric Le Goater        exec_command_and_wait_for_pattern(self,
43c7bc9cabSCédric Le Goater                             'cat /sys/class/hwmon/hwmon1/temp1_input', '0')
44c7bc9cabSCédric Le Goater        self.vm.cmd('qom-set', path='/machine/peripheral/tmp-test',
45c7bc9cabSCédric Le Goater                    property='temperature', value=18000);
46c7bc9cabSCédric Le Goater        exec_command_and_wait_for_pattern(self,
47c7bc9cabSCédric Le Goater                             'cat /sys/class/hwmon/hwmon1/temp1_input', '18000')
48c7bc9cabSCédric Le Goater
49c7bc9cabSCédric Le Goater        exec_command_and_wait_for_pattern(self,
50c7bc9cabSCédric Le Goater             'echo ds1307 0x32 > /sys/class/i2c-dev/i2c-3/device/new_device',
51c7bc9cabSCédric Le Goater             'i2c i2c-3: new_device: Instantiated device ds1307 at 0x32');
52c7bc9cabSCédric Le Goater        year = time.strftime("%Y")
53c7bc9cabSCédric Le Goater        exec_command_and_wait_for_pattern(self, 'hwclock -f /dev/rtc1', year);
54c7bc9cabSCédric Le Goater
55c7bc9cabSCédric Le Goater        exec_command_and_wait_for_pattern(self,
56c7bc9cabSCédric Le Goater             'echo slave-24c02 0x1064 > /sys/bus/i2c/devices/i2c-3/new_device',
57c7bc9cabSCédric Le Goater             'i2c i2c-3: new_device: Instantiated device slave-24c02 at 0x64');
58c7bc9cabSCédric Le Goater        exec_command_and_wait_for_pattern(self,
59c7bc9cabSCédric Le Goater             'i2cset -y 3 0x42 0x64 0x00 0xaa i', '#');
60c7bc9cabSCédric Le Goater        exec_command_and_wait_for_pattern(self,
61c7bc9cabSCédric Le Goater             'hexdump /sys/bus/i2c/devices/3-1064/slave-eeprom',
62c7bc9cabSCédric Le Goater             '0000000 ffaa ffff ffff ffff ffff ffff ffff ffff');
63c7bc9cabSCédric Le Goater        self.do_test_arm_aspeed_buildroot_poweroff()
64c7bc9cabSCédric Le Goater
65c7bc9cabSCédric Le Goater    ASSET_BR2_202302_AST2600_TPM_FLASH = Asset(
66c7bc9cabSCédric Le Goater        ('https://github.com/legoater/qemu-aspeed-boot/raw/master/'
67c7bc9cabSCédric Le Goater         'images/ast2600-evb/buildroot-2023.02-tpm/flash.img'),
68c7bc9cabSCédric Le Goater        'a46009ae8a5403a0826d607215e731a8c68d27c14c41e55331706b8f9c7bd997')
69c7bc9cabSCédric Le Goater
703d593860SDaniel P. Berrangé    @skipIfMissingCommands('swtpm')
71c7bc9cabSCédric Le Goater    def test_arm_ast2600_evb_buildroot_tpm(self):
72c7bc9cabSCédric Le Goater        self.set_machine('ast2600-evb')
73c7bc9cabSCédric Le Goater
74c7bc9cabSCédric Le Goater        image_path = self.ASSET_BR2_202302_AST2600_TPM_FLASH.fetch()
75c7bc9cabSCédric Le Goater
76c7bc9cabSCédric Le Goater        tpmstate_dir = tempfile.TemporaryDirectory(prefix="qemu_")
77c7bc9cabSCédric Le Goater        socket = os.path.join(tpmstate_dir.name, 'swtpm-socket')
78c7bc9cabSCédric Le Goater
79c7bc9cabSCédric Le Goater        # We must put the TPM state dir in /tmp/, not the build dir,
80c7bc9cabSCédric Le Goater        # because some distros use AppArmor to lock down swtpm and
81c7bc9cabSCédric Le Goater        # restrict the set of locations it can access files in.
82c7bc9cabSCédric Le Goater        subprocess.run(['swtpm', 'socket', '-d', '--tpm2',
83c7bc9cabSCédric Le Goater                        '--tpmstate', f'dir={tpmstate_dir.name}',
84c7bc9cabSCédric Le Goater                        '--ctrl', f'type=unixio,path={socket}'])
85c7bc9cabSCédric Le Goater
86c7bc9cabSCédric Le Goater        self.vm.add_args('-chardev', f'socket,id=chrtpm,path={socket}')
87c7bc9cabSCédric Le Goater        self.vm.add_args('-tpmdev', 'emulator,id=tpm0,chardev=chrtpm')
88c7bc9cabSCédric Le Goater        self.vm.add_args('-device',
89c7bc9cabSCédric Le Goater                         'tpm-tis-i2c,tpmdev=tpm0,bus=aspeed.i2c.bus.12,address=0x2e')
90c7bc9cabSCédric Le Goater        self.do_test_arm_aspeed_buildroot_start(image_path, '0xf00', 'Aspeed AST2600 EVB')
91c7bc9cabSCédric Le Goater
92c7bc9cabSCédric Le Goater        exec_command_and_wait_for_pattern(self,
93c7bc9cabSCédric Le Goater            'echo tpm_tis_i2c 0x2e > /sys/bus/i2c/devices/i2c-12/new_device',
94c7bc9cabSCédric Le Goater            'tpm_tis_i2c 12-002e: 2.0 TPM (device-id 0x1, rev-id 1)');
95c7bc9cabSCédric Le Goater        exec_command_and_wait_for_pattern(self,
96c7bc9cabSCédric Le Goater            'cat /sys/class/tpm/tpm0/pcr-sha256/0',
97c7bc9cabSCédric Le Goater            'B804724EA13F52A9072BA87FE8FDCC497DFC9DF9AA15B9088694639C431688E0');
98c7bc9cabSCédric Le Goater
99c7bc9cabSCédric Le Goater        self.do_test_arm_aspeed_buildroot_poweroff()
100c7bc9cabSCédric Le Goater
101c7bc9cabSCédric Le Goater    ASSET_SDK_V806_AST2600_A2 = Asset(
102c7bc9cabSCédric Le Goater        'https://github.com/AspeedTech-BMC/openbmc/releases/download/v08.06/ast2600-a2-obmc.tar.gz',
103c7bc9cabSCédric Le Goater        '9083506135f622d5e7351fcf7d4e1c7125cee5ba16141220c0ba88931f3681a4')
104c7bc9cabSCédric Le Goater
105c7bc9cabSCédric Le Goater    def test_arm_ast2600_evb_sdk(self):
106c7bc9cabSCédric Le Goater        self.set_machine('ast2600-evb')
107c7bc9cabSCédric Le Goater
108c7bc9cabSCédric Le Goater        image_path = self.ASSET_SDK_V806_AST2600_A2.fetch()
109c7bc9cabSCédric Le Goater
110c7bc9cabSCédric Le Goater        archive_extract(image_path, self.workdir)
111c7bc9cabSCédric Le Goater
112c7bc9cabSCédric Le Goater        self.vm.add_args('-device',
113c7bc9cabSCédric Le Goater            'tmp105,bus=aspeed.i2c.bus.5,address=0x4d,id=tmp-test');
114c7bc9cabSCédric Le Goater        self.vm.add_args('-device',
115c7bc9cabSCédric Le Goater            'ds1338,bus=aspeed.i2c.bus.5,address=0x32');
116c7bc9cabSCédric Le Goater        self.do_test_arm_aspeed_sdk_start(
117*beaf88c8SDaniel P. Berrangé            self.scratch_file("ast2600-a2", "image-bmc"))
118c7bc9cabSCédric Le Goater
119c7bc9cabSCédric Le Goater        self.wait_for_console_pattern('ast2600-a2 login:')
120c7bc9cabSCédric Le Goater
121c7bc9cabSCédric Le Goater        exec_command_and_wait_for_pattern(self, 'root', 'Password:')
122c7bc9cabSCédric Le Goater        exec_command_and_wait_for_pattern(self, '0penBmc', 'root@ast2600-a2:~#')
123c7bc9cabSCédric Le Goater
124c7bc9cabSCédric Le Goater        exec_command_and_wait_for_pattern(self,
125c7bc9cabSCédric Le Goater            'echo lm75 0x4d > /sys/class/i2c-dev/i2c-5/device/new_device',
126c7bc9cabSCédric Le Goater            'i2c i2c-5: new_device: Instantiated device lm75 at 0x4d');
127c7bc9cabSCédric Le Goater        exec_command_and_wait_for_pattern(self,
128c7bc9cabSCédric Le Goater             'cat /sys/class/hwmon/hwmon19/temp1_input', '0')
129c7bc9cabSCédric Le Goater        self.vm.cmd('qom-set', path='/machine/peripheral/tmp-test',
130c7bc9cabSCédric Le Goater                    property='temperature', value=18000);
131c7bc9cabSCédric Le Goater        exec_command_and_wait_for_pattern(self,
132c7bc9cabSCédric Le Goater             'cat /sys/class/hwmon/hwmon19/temp1_input', '18000')
133c7bc9cabSCédric Le Goater
134c7bc9cabSCédric Le Goater        exec_command_and_wait_for_pattern(self,
135c7bc9cabSCédric Le Goater             'echo ds1307 0x32 > /sys/class/i2c-dev/i2c-5/device/new_device',
136c7bc9cabSCédric Le Goater             'i2c i2c-5: new_device: Instantiated device ds1307 at 0x32');
137c7bc9cabSCédric Le Goater        year = time.strftime("%Y")
138c7bc9cabSCédric Le Goater        exec_command_and_wait_for_pattern(self,
139c7bc9cabSCédric Le Goater             '/sbin/hwclock -f /dev/rtc1', year);
140c7bc9cabSCédric Le Goater
141c7bc9cabSCédric Le Goaterif __name__ == '__main__':
142c7bc9cabSCédric Le Goater    AspeedTest.main()
143