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