]> git.proxmox.com Git - mirror_qemu.git/blame - tests/avocado/machine_aspeed.py
tpm: Add support for TPM device over I2C bus
[mirror_qemu.git] / tests / avocado / machine_aspeed.py
CommitLineData
438eff63
JL
1# Functional test that boots the ASPEED SoCs with firmware
2#
3# Copyright (C) 2022 ASPEED Technology Inc
4#
5# This work is licensed under the terms of the GNU GPL, version 2 or
6# later. See the COPYING file in the top-level directory.
7
f7bc7da0 8import time
92f8e8e2 9import os
f7bc7da0 10
438eff63
JL
11from avocado_qemu import QemuSystemTest
12from avocado_qemu import wait_for_console_pattern
f7bc7da0 13from avocado_qemu import exec_command
438eff63 14from avocado_qemu import exec_command_and_wait_for_pattern
a4b14b46 15from avocado_qemu import interrupt_interactive_console_until_pattern
438eff63 16from avocado.utils import archive
92f8e8e2 17from avocado import skipIf
438eff63
JL
18
19
20class AST1030Machine(QemuSystemTest):
21 """Boots the zephyr os and checks that the console is operational"""
22
23 timeout = 10
24
44055caa 25 def test_ast1030_zephyros_1_04(self):
438eff63
JL
26 """
27 :avocado: tags=arch:arm
28 :avocado: tags=machine:ast1030-evb
44055caa 29 :avocado: tags=os:zephyr
438eff63
JL
30 """
31 tar_url = ('https://github.com/AspeedTech-BMC'
32 '/zephyr/releases/download/v00.01.04/ast1030-evb-demo.zip')
33 tar_hash = '4c6a8ce3a8ba76ef1a65dae419ae3409343c4b20'
34 tar_path = self.fetch_asset(tar_url, asset_hash=tar_hash)
35 archive.extract(tar_path, self.workdir)
36 kernel_file = self.workdir + "/ast1030-evb-demo/zephyr.elf"
37 self.vm.set_console()
38 self.vm.add_args('-kernel', kernel_file,
39 '-nographic')
40 self.vm.launch()
41 wait_for_console_pattern(self, "Booting Zephyr OS")
42 exec_command_and_wait_for_pattern(self, "help",
43 "Available commands")
341e21fa 44
44055caa
PMD
45 def test_ast1030_zephyros_1_07(self):
46 """
47 :avocado: tags=arch:arm
48 :avocado: tags=machine:ast1030-evb
49 :avocado: tags=os:zephyr
50 """
51 tar_url = ('https://github.com/AspeedTech-BMC'
52 '/zephyr/releases/download/v00.01.07/ast1030-evb-demo.zip')
53 tar_hash = '40ac87eabdcd3b3454ce5aad11fedc72a33ecda2'
54 tar_path = self.fetch_asset(tar_url, asset_hash=tar_hash)
55 archive.extract(tar_path, self.workdir)
56 kernel_file = self.workdir + "/ast1030-evb-demo/zephyr.bin"
57 self.vm.set_console()
58 self.vm.add_args('-kernel', kernel_file,
59 '-nographic')
60 self.vm.launch()
61 wait_for_console_pattern(self, "Booting Zephyr OS")
62 for shell_cmd in [
63 'kernel stacks',
64 'otp info conf',
65 'otp info scu',
66 'hwinfo devid',
67 'crypto aes256_cbc_vault',
68 'random get',
69 'jtag JTAG1 sw_xfer high TMS',
70 'adc ADC0 resolution 12',
71 'adc ADC0 read 42',
72 'adc ADC1 read 69',
73 'i2c scan I2C_0',
74 'i3c attach I3C_0',
75 'hash test',
76 'kernel uptime',
77 'kernel reboot warm',
78 'kernel uptime',
79 'kernel reboot cold',
80 'kernel uptime',
81 ]: exec_command_and_wait_for_pattern(self, shell_cmd, "uart:~$")
82
341e21fa
CLG
83class AST2x00Machine(QemuSystemTest):
84
b1ceae2f
AB
85 timeout = 90
86
341e21fa
CLG
87 def wait_for_console_pattern(self, success_message, vm=None):
88 wait_for_console_pattern(self, success_message,
89 failure_message='Kernel panic - not syncing',
90 vm=vm)
91
92 def do_test_arm_aspeed(self, image):
93 self.vm.set_console()
94 self.vm.add_args('-drive', 'file=' + image + ',if=mtd,format=raw',
95 '-net', 'nic')
96 self.vm.launch()
97
98 self.wait_for_console_pattern("U-Boot 2016.07")
99 self.wait_for_console_pattern("## Loading kernel from FIT Image at 20080000")
100 self.wait_for_console_pattern("Starting kernel ...")
101 self.wait_for_console_pattern("Booting Linux on physical CPU 0x0")
102 wait_for_console_pattern(self,
103 "aspeed-smc 1e620000.spi: read control register: 203b0641")
104 self.wait_for_console_pattern("ftgmac100 1e660000.ethernet eth0: irq ")
105 self.wait_for_console_pattern("systemd[1]: Set hostname to")
106
107 def test_arm_ast2400_palmetto_openbmc_v2_9_0(self):
108 """
109 :avocado: tags=arch:arm
110 :avocado: tags=machine:palmetto-bmc
111 """
112
113 image_url = ('https://github.com/openbmc/openbmc/releases/download/2.9.0/'
114 'obmc-phosphor-image-palmetto.static.mtd')
115 image_hash = ('3e13bbbc28e424865dc42f35ad672b10f2e82cdb11846bb28fa625b48beafd0d')
116 image_path = self.fetch_asset(image_url, asset_hash=image_hash,
117 algorithm='sha256')
118
119 self.do_test_arm_aspeed(image_path)
120
121 def test_arm_ast2500_romulus_openbmc_v2_9_0(self):
122 """
123 :avocado: tags=arch:arm
124 :avocado: tags=machine:romulus-bmc
125 """
126
127 image_url = ('https://github.com/openbmc/openbmc/releases/download/2.9.0/'
128 'obmc-phosphor-image-romulus.static.mtd')
129 image_hash = ('820341076803f1955bc31e647a512c79f9add4f5233d0697678bab4604c7bb25')
130 image_path = self.fetch_asset(image_url, asset_hash=image_hash,
131 algorithm='sha256')
132
133 self.do_test_arm_aspeed(image_path)
f7bc7da0 134
7b5093b8 135 def do_test_arm_aspeed_buildroot_start(self, image, cpu_id):
0793fe01
PM
136 self.require_netdev('user')
137
f7bc7da0
CLG
138 self.vm.set_console()
139 self.vm.add_args('-drive', 'file=' + image + ',if=mtd,format=raw',
140 '-net', 'nic', '-net', 'user')
141 self.vm.launch()
142
143 self.wait_for_console_pattern('U-Boot 2019.04')
144 self.wait_for_console_pattern('## Loading kernel from FIT Image')
145 self.wait_for_console_pattern('Starting kernel ...')
146 self.wait_for_console_pattern('Booting Linux on physical CPU ' + cpu_id)
147 self.wait_for_console_pattern('lease of 10.0.2.15')
65711f9a 148 # the line before login:
f7bc7da0 149 self.wait_for_console_pattern('Aspeed EVB')
65711f9a 150 time.sleep(0.1)
f7bc7da0
CLG
151 exec_command(self, 'root')
152 time.sleep(0.1)
153
7b5093b8 154 def do_test_arm_aspeed_buildroot_poweroff(self):
f7bc7da0
CLG
155 exec_command_and_wait_for_pattern(self, 'poweroff',
156 'reboot: System halted');
157
7b5093b8 158 def test_arm_ast2500_evb_buildroot(self):
f7bc7da0
CLG
159 """
160 :avocado: tags=arch:arm
161 :avocado: tags=machine:ast2500-evb
162 """
163
164 image_url = ('https://github.com/legoater/qemu-aspeed-boot/raw/master/'
ed1f5ff8
CLG
165 'images/ast2500-evb/buildroot-2022.11-2-g15d3648df9/flash.img')
166 image_hash = ('f96d11db521fe7a2787745e9e391225deeeec3318ee0fc07c8b799b8833dd474')
f7bc7da0
CLG
167 image_path = self.fetch_asset(image_url, asset_hash=image_hash,
168 algorithm='sha256')
169
7a7308ea
CLG
170 self.vm.add_args('-device',
171 'tmp105,bus=aspeed.i2c.bus.3,address=0x4d,id=tmp-test');
7b5093b8 172 self.do_test_arm_aspeed_buildroot_start(image_path, '0x0')
7a7308ea
CLG
173
174 exec_command_and_wait_for_pattern(self,
175 'echo lm75 0x4d > /sys/class/i2c-dev/i2c-3/device/new_device',
176 'i2c i2c-3: new_device: Instantiated device lm75 at 0x4d');
177 exec_command_and_wait_for_pattern(self,
178 'cat /sys/class/hwmon/hwmon1/temp1_input', '0')
179 self.vm.command('qom-set', path='/machine/peripheral/tmp-test',
180 property='temperature', value=18000);
181 exec_command_and_wait_for_pattern(self,
182 'cat /sys/class/hwmon/hwmon1/temp1_input', '18000')
183
7b5093b8 184 self.do_test_arm_aspeed_buildroot_poweroff()
f7bc7da0 185
7b5093b8 186 def test_arm_ast2600_evb_buildroot(self):
f7bc7da0
CLG
187 """
188 :avocado: tags=arch:arm
189 :avocado: tags=machine:ast2600-evb
190 """
191
192 image_url = ('https://github.com/legoater/qemu-aspeed-boot/raw/master/'
ed1f5ff8
CLG
193 'images/ast2600-evb/buildroot-2022.11-2-g15d3648df9/flash.img')
194 image_hash = ('e598d86e5ea79671ca8b59212a326c911bc8bea728dec1a1f5390d717a28bb8b')
f7bc7da0
CLG
195 image_path = self.fetch_asset(image_url, asset_hash=image_hash,
196 algorithm='sha256')
197
61cf757d
CLG
198 self.vm.add_args('-device',
199 'tmp105,bus=aspeed.i2c.bus.3,address=0x4d,id=tmp-test');
3302184f
CLG
200 self.vm.add_args('-device',
201 'ds1338,bus=aspeed.i2c.bus.3,address=0x32');
82e94da5
CLG
202 self.vm.add_args('-device',
203 'i2c-echo,bus=aspeed.i2c.bus.3,address=0x42');
7b5093b8 204 self.do_test_arm_aspeed_buildroot_start(image_path, '0xf00')
61cf757d
CLG
205
206 exec_command_and_wait_for_pattern(self,
207 'echo lm75 0x4d > /sys/class/i2c-dev/i2c-3/device/new_device',
208 'i2c i2c-3: new_device: Instantiated device lm75 at 0x4d');
209 exec_command_and_wait_for_pattern(self,
210 'cat /sys/class/hwmon/hwmon0/temp1_input', '0')
211 self.vm.command('qom-set', path='/machine/peripheral/tmp-test',
212 property='temperature', value=18000);
213 exec_command_and_wait_for_pattern(self,
214 'cat /sys/class/hwmon/hwmon0/temp1_input', '18000')
215
3302184f
CLG
216 exec_command_and_wait_for_pattern(self,
217 'echo ds1307 0x32 > /sys/class/i2c-dev/i2c-3/device/new_device',
218 'i2c i2c-3: new_device: Instantiated device ds1307 at 0x32');
219 year = time.strftime("%Y")
220 exec_command_and_wait_for_pattern(self, 'hwclock -f /dev/rtc1', year);
221
82e94da5
CLG
222 exec_command_and_wait_for_pattern(self,
223 'echo slave-24c02 0x1064 > /sys/bus/i2c/devices/i2c-3/new_device',
224 'i2c i2c-3: new_device: Instantiated device slave-24c02 at 0x64');
225 exec_command(self, 'i2cset -y 3 0x42 0x64 0x00 0xaa i');
226 time.sleep(0.1)
227 exec_command_and_wait_for_pattern(self,
228 'hexdump /sys/bus/i2c/devices/3-1064/slave-eeprom',
229 '0000000 ffaa ffff ffff ffff ffff ffff ffff ffff');
7b5093b8 230 self.do_test_arm_aspeed_buildroot_poweroff()
bceb4d99
CLG
231
232
92f8e8e2
AB
233class AST2x00MachineSDK(QemuSystemTest):
234
30d7aac4
CLG
235 EXTRA_BOOTARGS = (
236 'quiet '
237 'systemd.mask=org.openbmc.HostIpmi.service '
238 'systemd.mask=xyz.openbmc_project.Chassis.Control.Power@0.service '
239 'systemd.mask=modprobe@fuse.service '
240 'systemd.mask=rngd.service '
241 'systemd.mask=obmc-console@ttyS2.service '
242 )
a4b14b46 243
92f8e8e2
AB
244 # FIXME: Although these tests boot a whole distro they are still
245 # slower than comparable machine models. There may be some
246 # optimisations which bring down the runtime. In the meantime they
247 # have generous timeouts and are disable for CI which aims for all
248 # tests to run in less than 60 seconds.
249 timeout = 240
250
251 def wait_for_console_pattern(self, success_message, vm=None):
252 wait_for_console_pattern(self, success_message,
253 failure_message='Kernel panic - not syncing',
254 vm=vm)
255
a4b14b46 256 def do_test_arm_aspeed_sdk_start(self, image):
0793fe01 257 self.require_netdev('user')
bceb4d99
CLG
258 self.vm.set_console()
259 self.vm.add_args('-drive', 'file=' + image + ',if=mtd,format=raw',
260 '-net', 'nic', '-net', 'user')
261 self.vm.launch()
262
263 self.wait_for_console_pattern('U-Boot 2019.04')
a4b14b46
CLG
264 interrupt_interactive_console_until_pattern(
265 self, 'Hit any key to stop autoboot:', 'ast#')
266 exec_command_and_wait_for_pattern(
30d7aac4 267 self, 'setenv bootargs ${bootargs} ' + self.EXTRA_BOOTARGS, 'ast#')
a4b14b46
CLG
268 exec_command_and_wait_for_pattern(
269 self, 'boot', '## Loading kernel from FIT Image')
bceb4d99 270 self.wait_for_console_pattern('Starting kernel ...')
bceb4d99 271
92f8e8e2 272 @skipIf(os.getenv('GITLAB_CI'), 'Running on GitLab')
bceb4d99
CLG
273 def test_arm_ast2500_evb_sdk(self):
274 """
275 :avocado: tags=arch:arm
276 :avocado: tags=machine:ast2500-evb
277 """
278
279 image_url = ('https://github.com/AspeedTech-BMC/openbmc/releases/'
280 'download/v08.01/ast2500-default-obmc.tar.gz')
281 image_hash = ('5375f82b4c43a79427909342a1e18b4e48bd663e38466862145d27bb358796fd')
282 image_path = self.fetch_asset(image_url, asset_hash=image_hash,
283 algorithm='sha256')
284 archive.extract(image_path, self.workdir)
285
286 self.do_test_arm_aspeed_sdk_start(
a4b14b46 287 self.workdir + '/ast2500-default/image-bmc')
bceb4d99
CLG
288 self.wait_for_console_pattern('ast2500-default login:')
289
92f8e8e2 290 @skipIf(os.getenv('GITLAB_CI'), 'Running on GitLab')
bceb4d99
CLG
291 def test_arm_ast2600_evb_sdk(self):
292 """
293 :avocado: tags=arch:arm
294 :avocado: tags=machine:ast2600-evb
295 """
296
297 image_url = ('https://github.com/AspeedTech-BMC/openbmc/releases/'
298 'download/v08.01/ast2600-default-obmc.tar.gz')
299 image_hash = ('f12ef15e8c1f03a214df3b91c814515c5e2b2f56119021398c1dbdd626817d15')
300 image_path = self.fetch_asset(image_url, asset_hash=image_hash,
301 algorithm='sha256')
302 archive.extract(image_path, self.workdir)
303
304 self.vm.add_args('-device',
305 'tmp105,bus=aspeed.i2c.bus.5,address=0x4d,id=tmp-test');
306 self.vm.add_args('-device',
307 'ds1338,bus=aspeed.i2c.bus.5,address=0x32');
308 self.do_test_arm_aspeed_sdk_start(
a4b14b46 309 self.workdir + '/ast2600-default/image-bmc')
bceb4d99
CLG
310 self.wait_for_console_pattern('ast2600-default login:')
311 exec_command_and_wait_for_pattern(self, 'root', 'Password:')
312 exec_command_and_wait_for_pattern(self, '0penBmc', 'root@ast2600-default:~#')
313
314 exec_command_and_wait_for_pattern(self,
315 'echo lm75 0x4d > /sys/class/i2c-dev/i2c-5/device/new_device',
316 'i2c i2c-5: new_device: Instantiated device lm75 at 0x4d');
317 exec_command_and_wait_for_pattern(self,
318 'cat /sys/class/hwmon/hwmon19/temp1_input', '0')
319 self.vm.command('qom-set', path='/machine/peripheral/tmp-test',
320 property='temperature', value=18000);
321 exec_command_and_wait_for_pattern(self,
322 'cat /sys/class/hwmon/hwmon19/temp1_input', '18000')
323
324 exec_command_and_wait_for_pattern(self,
325 'echo ds1307 0x32 > /sys/class/i2c-dev/i2c-5/device/new_device',
326 'i2c i2c-5: new_device: Instantiated device ds1307 at 0x32');
327 year = time.strftime("%Y")
328 exec_command_and_wait_for_pattern(self, 'hwclock -f /dev/rtc1', year);