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 10 11from avocado_qemu import QemuSystemTest 12from avocado_qemu import wait_for_console_pattern 13from avocado_qemu import exec_command 14from avocado_qemu import exec_command_and_wait_for_pattern 15from avocado_qemu import interrupt_interactive_console_until_pattern 16from avocado.utils import archive 17from avocado import skipIf 18 19 20class AST1030Machine(QemuSystemTest): 21 """Boots the zephyr os and checks that the console is operational""" 22 23 timeout = 10 24 25 def test_ast1030_zephyros_1_04(self): 26 """ 27 :avocado: tags=arch:arm 28 :avocado: tags=machine:ast1030-evb 29 :avocado: tags=os:zephyr 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") 44 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 83class AST2x00Machine(QemuSystemTest): 84 85 timeout = 90 86 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) 134 135 def do_test_arm_aspeed_buildroot_start(self, image, cpu_id): 136 self.require_netdev('user') 137 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') 148 # the line before login: 149 self.wait_for_console_pattern('Aspeed EVB') 150 time.sleep(0.1) 151 exec_command(self, 'root') 152 time.sleep(0.1) 153 154 def do_test_arm_aspeed_buildroot_poweroff(self): 155 exec_command_and_wait_for_pattern(self, 'poweroff', 156 'reboot: System halted'); 157 158 def test_arm_ast2500_evb_buildroot(self): 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/' 165 'images/ast2500-evb/buildroot-2022.11-2-g15d3648df9/flash.img') 166 image_hash = ('f96d11db521fe7a2787745e9e391225deeeec3318ee0fc07c8b799b8833dd474') 167 image_path = self.fetch_asset(image_url, asset_hash=image_hash, 168 algorithm='sha256') 169 170 self.vm.add_args('-device', 171 'tmp105,bus=aspeed.i2c.bus.3,address=0x4d,id=tmp-test'); 172 self.do_test_arm_aspeed_buildroot_start(image_path, '0x0') 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 184 self.do_test_arm_aspeed_buildroot_poweroff() 185 186 def test_arm_ast2600_evb_buildroot(self): 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/' 193 'images/ast2600-evb/buildroot-2022.11-2-g15d3648df9/flash.img') 194 image_hash = ('e598d86e5ea79671ca8b59212a326c911bc8bea728dec1a1f5390d717a28bb8b') 195 image_path = self.fetch_asset(image_url, asset_hash=image_hash, 196 algorithm='sha256') 197 198 self.vm.add_args('-device', 199 'tmp105,bus=aspeed.i2c.bus.3,address=0x4d,id=tmp-test'); 200 self.vm.add_args('-device', 201 'ds1338,bus=aspeed.i2c.bus.3,address=0x32'); 202 self.do_test_arm_aspeed_buildroot_start(image_path, '0xf00') 203 204 exec_command_and_wait_for_pattern(self, 205 'echo lm75 0x4d > /sys/class/i2c-dev/i2c-3/device/new_device', 206 'i2c i2c-3: new_device: Instantiated device lm75 at 0x4d'); 207 exec_command_and_wait_for_pattern(self, 208 'cat /sys/class/hwmon/hwmon0/temp1_input', '0') 209 self.vm.command('qom-set', path='/machine/peripheral/tmp-test', 210 property='temperature', value=18000); 211 exec_command_and_wait_for_pattern(self, 212 'cat /sys/class/hwmon/hwmon0/temp1_input', '18000') 213 214 exec_command_and_wait_for_pattern(self, 215 'echo ds1307 0x32 > /sys/class/i2c-dev/i2c-3/device/new_device', 216 'i2c i2c-3: new_device: Instantiated device ds1307 at 0x32'); 217 year = time.strftime("%Y") 218 exec_command_and_wait_for_pattern(self, 'hwclock -f /dev/rtc1', year); 219 220 self.do_test_arm_aspeed_buildroot_poweroff() 221 222 223class AST2x00MachineSDK(QemuSystemTest): 224 225 EXTRA_BOOTARGS = ( 226 'quiet ' 227 'systemd.mask=org.openbmc.HostIpmi.service ' 228 'systemd.mask=xyz.openbmc_project.Chassis.Control.Power@0.service ' 229 'systemd.mask=modprobe@fuse.service ' 230 'systemd.mask=rngd.service ' 231 'systemd.mask=obmc-console@ttyS2.service ' 232 ) 233 234 # FIXME: Although these tests boot a whole distro they are still 235 # slower than comparable machine models. There may be some 236 # optimisations which bring down the runtime. In the meantime they 237 # have generous timeouts and are disable for CI which aims for all 238 # tests to run in less than 60 seconds. 239 timeout = 240 240 241 def wait_for_console_pattern(self, success_message, vm=None): 242 wait_for_console_pattern(self, success_message, 243 failure_message='Kernel panic - not syncing', 244 vm=vm) 245 246 def do_test_arm_aspeed_sdk_start(self, image): 247 self.require_netdev('user') 248 self.vm.set_console() 249 self.vm.add_args('-drive', 'file=' + image + ',if=mtd,format=raw', 250 '-net', 'nic', '-net', 'user') 251 self.vm.launch() 252 253 self.wait_for_console_pattern('U-Boot 2019.04') 254 interrupt_interactive_console_until_pattern( 255 self, 'Hit any key to stop autoboot:', 'ast#') 256 exec_command_and_wait_for_pattern( 257 self, 'setenv bootargs ${bootargs} ' + self.EXTRA_BOOTARGS, 'ast#') 258 exec_command_and_wait_for_pattern( 259 self, 'boot', '## Loading kernel from FIT Image') 260 self.wait_for_console_pattern('Starting kernel ...') 261 262 @skipIf(os.getenv('GITLAB_CI'), 'Running on GitLab') 263 def test_arm_ast2500_evb_sdk(self): 264 """ 265 :avocado: tags=arch:arm 266 :avocado: tags=machine:ast2500-evb 267 """ 268 269 image_url = ('https://github.com/AspeedTech-BMC/openbmc/releases/' 270 'download/v08.01/ast2500-default-obmc.tar.gz') 271 image_hash = ('5375f82b4c43a79427909342a1e18b4e48bd663e38466862145d27bb358796fd') 272 image_path = self.fetch_asset(image_url, asset_hash=image_hash, 273 algorithm='sha256') 274 archive.extract(image_path, self.workdir) 275 276 self.do_test_arm_aspeed_sdk_start( 277 self.workdir + '/ast2500-default/image-bmc') 278 self.wait_for_console_pattern('ast2500-default login:') 279 280 @skipIf(os.getenv('GITLAB_CI'), 'Running on GitLab') 281 def test_arm_ast2600_evb_sdk(self): 282 """ 283 :avocado: tags=arch:arm 284 :avocado: tags=machine:ast2600-evb 285 """ 286 287 image_url = ('https://github.com/AspeedTech-BMC/openbmc/releases/' 288 'download/v08.01/ast2600-default-obmc.tar.gz') 289 image_hash = ('f12ef15e8c1f03a214df3b91c814515c5e2b2f56119021398c1dbdd626817d15') 290 image_path = self.fetch_asset(image_url, asset_hash=image_hash, 291 algorithm='sha256') 292 archive.extract(image_path, self.workdir) 293 294 self.vm.add_args('-device', 295 'tmp105,bus=aspeed.i2c.bus.5,address=0x4d,id=tmp-test'); 296 self.vm.add_args('-device', 297 'ds1338,bus=aspeed.i2c.bus.5,address=0x32'); 298 self.do_test_arm_aspeed_sdk_start( 299 self.workdir + '/ast2600-default/image-bmc') 300 self.wait_for_console_pattern('ast2600-default login:') 301 exec_command_and_wait_for_pattern(self, 'root', 'Password:') 302 exec_command_and_wait_for_pattern(self, '0penBmc', 'root@ast2600-default:~#') 303 304 exec_command_and_wait_for_pattern(self, 305 'echo lm75 0x4d > /sys/class/i2c-dev/i2c-5/device/new_device', 306 'i2c i2c-5: new_device: Instantiated device lm75 at 0x4d'); 307 exec_command_and_wait_for_pattern(self, 308 'cat /sys/class/hwmon/hwmon19/temp1_input', '0') 309 self.vm.command('qom-set', path='/machine/peripheral/tmp-test', 310 property='temperature', value=18000); 311 exec_command_and_wait_for_pattern(self, 312 'cat /sys/class/hwmon/hwmon19/temp1_input', '18000') 313 314 exec_command_and_wait_for_pattern(self, 315 'echo ds1307 0x32 > /sys/class/i2c-dev/i2c-5/device/new_device', 316 'i2c i2c-5: new_device: Instantiated device ds1307 at 0x32'); 317 year = time.strftime("%Y") 318 exec_command_and_wait_for_pattern(self, 'hwclock -f /dev/rtc1', year); 319