| 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 | |
| 9 | import os |
| 10 | |
| 11 | from qemu_test import QemuSystemTest, Asset |
| 12 | from qemu_test import wait_for_console_pattern, exec_command |
| 13 | from qemu_test import exec_command_and_wait_for_pattern |
| 14 | |
| 15 | |
| 16 | class AST2x00MachineSDK(QemuSystemTest): |
| 17 | |
| 18 | def do_test_aarch64_aspeed_sdk_start(self, image, bus_id): |
| 19 | bus_str = str(bus_id) |
| 20 | self.require_netdev('user') |
| 21 | self.vm.set_console() |
| 22 | self.vm.add_args( |
| 23 | '-device', |
| 24 | f'tmp105,' |
| 25 | f'bus=aspeed.i2c.bus.{bus_str},' |
| 26 | f'address=0x4d,' |
| 27 | f'id=tmp-test-{bus_str}' |
| 28 | ) |
| 29 | self.vm.add_args('-drive', 'file=' + image + ',if=mtd,format=raw', |
| 30 | '-net', 'nic', '-net', 'user', '-snapshot') |
| 31 | |
| 32 | self.vm.launch() |
| 33 | |
| 34 | def verify_vbootrom_firmware_flow(self): |
| 35 | wait_for_console_pattern(self, 'Found valid caliptra flash image') |
| 36 | wait_for_console_pattern(self, 'Check flash image checksum') |
| 37 | wait_for_console_pattern(self, 'pass') |
| 38 | wait_for_console_pattern(self, 'Read abb header') |
| 39 | wait_for_console_pattern(self, 'pass') |
| 40 | wait_for_console_pattern(self, 'Read soc manifest') |
| 41 | wait_for_console_pattern(self, 'pass') |
| 42 | wait_for_console_pattern(self, 'Load atf image') |
| 43 | wait_for_console_pattern(self, 'pass') |
| 44 | wait_for_console_pattern(self, 'Load optee image') |
| 45 | wait_for_console_pattern(self, 'pass') |
| 46 | wait_for_console_pattern(self, 'Load uboot image') |
| 47 | wait_for_console_pattern(self, 'pass') |
| 48 | wait_for_console_pattern(self, 'Load ssp image') |
| 49 | wait_for_console_pattern(self, 'pass') |
| 50 | wait_for_console_pattern(self, 'Load tsp image') |
| 51 | wait_for_console_pattern(self, 'pass') |
| 52 | wait_for_console_pattern(self, 'Jumping to BL31 (Trusted Firmware-A)') |
| 53 | |
| 54 | def disable_kernel_crypto_selftest(self): |
| 55 | exec_command_and_wait_for_pattern(self, |
| 56 | 'setenv bootargs "${bootargs} cryptomgr.notests=1"', '=>') |
| 57 | |
| 58 | def enable_ast2700_pcie2(self): |
| 59 | exec_command_and_wait_for_pattern(self, |
| 60 | 'cp 100420000 403000000 900000', '=>') |
| 61 | exec_command_and_wait_for_pattern(self, |
| 62 | 'bootm start 403000000', '=>') |
| 63 | exec_command_and_wait_for_pattern(self, 'bootm loados', '=>') |
| 64 | exec_command_and_wait_for_pattern(self, 'bootm ramdisk', '=>') |
| 65 | exec_command_and_wait_for_pattern(self, 'bootm prep', '=>') |
| 66 | exec_command_and_wait_for_pattern(self, |
| 67 | 'fdt set /soc@14000000/pcie@140d0000 status "okay"', '=>') |
| 68 | exec_command(self, 'bootm go') |
| 69 | |
| 70 | def verify_openbmc_boot_start(self, enable_pcie=True): |
| 71 | wait_for_console_pattern(self, 'U-Boot 2023.10') |
| 72 | wait_for_console_pattern(self, 'Hit any key to stop autoboot') |
| 73 | exec_command_and_wait_for_pattern(self, '\012', '=>') |
| 74 | self.disable_kernel_crypto_selftest() |
| 75 | if enable_pcie: |
| 76 | self.enable_ast2700_pcie2() |
| 77 | else: |
| 78 | exec_command(self, 'boot') |
| 79 | wait_for_console_pattern(self, 'Linux version ') |
| 80 | |
| 81 | def verify_openbmc_boot_and_login(self, name, enable_pcie=True): |
| 82 | self.verify_openbmc_boot_start(enable_pcie) |
| 83 | |
| 84 | wait_for_console_pattern(self, 'login:') |
| 85 | exec_command_and_wait_for_pattern(self, 'root', 'Password:') |
| 86 | exec_command_and_wait_for_pattern(self, '0penBmc', f'root@{name}:~#') |
| 87 | |
| 88 | ASSET_SDK_V1103_AST2700A2 = Asset( |
| 89 | 'https://github.com/AspeedTech-BMC/openbmc/releases/download/v11.03/ast2700-default-image.tar.gz', |
| 90 | 'b91450d53da234591060cfb926fa30f7534ce20eaab766cb0f80ec332f8f0adb') |
| 91 | |
| 92 | ASSET_SDK_V1103_AST2700A2_DCSCM = Asset( |
| 93 | 'https://github.com/AspeedTech-BMC/openbmc/releases/download/v11.03/ast2700-dcscm-image.tar.gz', |
| 94 | '7afd8323fc95097c14872b90d68c5cae5d078530c704591b192b74bd892c1dbf') |
| 95 | |
| 96 | def do_ast2700_i2c_test(self, bus_id): |
| 97 | bus_str = str(bus_id) |
| 98 | exec_command_and_wait_for_pattern(self, |
| 99 | 'echo lm75 0x4d > ' |
| 100 | f'/sys/class/i2c-dev/i2c-{bus_str}/device/new_device ', |
| 101 | f'i2c i2c-{bus_str}: new_device: Instantiated device lm75 at 0x4d') |
| 102 | exec_command_and_wait_for_pattern(self, |
| 103 | f'cat /sys/bus/i2c/devices/{bus_str}-004d/hwmon/hwmon*/temp1_input', |
| 104 | '0') |
| 105 | self.vm.cmd('qom-set', path=f'/machine/peripheral/tmp-test-{bus_str}', |
| 106 | property='temperature', value=18000) |
| 107 | exec_command_and_wait_for_pattern(self, |
| 108 | f'cat /sys/bus/i2c/devices/{bus_str}-004d/hwmon/hwmon*/temp1_input', |
| 109 | '18000') |
| 110 | |
| 111 | def do_ast2700_pcie_test(self): |
| 112 | exec_command_and_wait_for_pattern(self, |
| 113 | 'lspci -s 0002:00:00.0', |
| 114 | '0002:00:00.0 PCI bridge: ' |
| 115 | 'ASPEED Technology, Inc. AST1150 PCI-to-PCI Bridge') |
| 116 | exec_command_and_wait_for_pattern(self, |
| 117 | 'lspci -s 0002:01:00.0', |
| 118 | '0002:01:00.0 Ethernet controller: ' |
| 119 | 'Intel Corporation 82574L Gigabit Network Connection') |
| 120 | exec_command_and_wait_for_pattern(self, |
| 121 | 'ip addr show dev eth2', |
| 122 | 'inet 10.0.2.15/24') |
| 123 | |
| 124 | def do_ast2700_usb_ehci_test(self): |
| 125 | exec_command_and_wait_for_pattern(self, |
| 126 | 'lsusb', |
| 127 | 'QEMU QEMU USB Keyboard') |
| 128 | |
| 129 | def start_ast2700_test(self, name, bus_id): |
| 130 | num_cpu = 4 |
| 131 | load_images_list = [ |
| 132 | { |
| 133 | 'addr': '0x400000000', |
| 134 | 'file': self.scratch_file(name, 'u-boot.bin') |
| 135 | }, |
| 136 | { |
| 137 | 'addr': '0x430000000', |
| 138 | 'file': self.scratch_file(name, 'trusted-firmware-a', |
| 139 | 'bl31.bin') |
| 140 | }, |
| 141 | { |
| 142 | 'addr': '0x430080000', |
| 143 | 'file': self.scratch_file(name, 'optee', 'tee-raw.bin') |
| 144 | } |
| 145 | ] |
| 146 | |
| 147 | for load_image in load_images_list: |
| 148 | addr = load_image['addr'] |
| 149 | file = load_image['file'] |
| 150 | self.vm.add_args('-device', |
| 151 | f'loader,force-raw=on,addr={addr},file={file}') |
| 152 | |
| 153 | for i in range(num_cpu): |
| 154 | self.vm.add_args('-device', |
| 155 | f'loader,addr=0x430000000,cpu-num={i}') |
| 156 | |
| 157 | self.vm.add_args('-smp', str(num_cpu)) |
| 158 | self.do_test_aarch64_aspeed_sdk_start( |
| 159 | self.scratch_file(name, 'image-bmc'), bus_id) |
| 160 | |
| 161 | def start_ast2700_test_vbootrom(self, name, bus_id): |
| 162 | self.vm.add_args('-bios', 'ast27x0_bootrom.bin') |
| 163 | self.do_test_aarch64_aspeed_sdk_start( |
| 164 | self.scratch_file(name, 'image-bmc'), bus_id) |
| 165 | |
| 166 | def test_aarch64_ast2700a2_evb_sdk_v11_03(self): |
| 167 | self.set_machine('ast2700a2-evb') |
| 168 | self.require_netdev('user') |
| 169 | |
| 170 | self.archive_extract(self.ASSET_SDK_V1103_AST2700A2) |
| 171 | self.vm.add_args('-device', 'e1000e,netdev=net1,bus=pcie.2') |
| 172 | self.vm.add_args('-netdev', 'user,id=net1') |
| 173 | self.vm.add_args('-device', 'usb-kbd,bus=usb-bus.3') |
| 174 | self.start_ast2700_test('ast2700-default-image', 1) |
| 175 | self.verify_openbmc_boot_and_login('ast2700-default') |
| 176 | self.do_ast2700_i2c_test(1) |
| 177 | self.do_ast2700_pcie_test() |
| 178 | self.do_ast2700_usb_ehci_test() |
| 179 | |
| 180 | def test_aarch64_ast2700a2_evb_sdk_vbootrom_v11_03(self): |
| 181 | self.set_machine('ast2700a2-evb') |
| 182 | self.require_netdev('user') |
| 183 | |
| 184 | self.archive_extract(self.ASSET_SDK_V1103_AST2700A2) |
| 185 | self.vm.add_args('-device', 'e1000e,netdev=net1,bus=pcie.2') |
| 186 | self.vm.add_args('-netdev', 'user,id=net1') |
| 187 | self.start_ast2700_test_vbootrom('ast2700-default-image', 1) |
| 188 | self.verify_vbootrom_firmware_flow() |
| 189 | self.verify_openbmc_boot_start() |
| 190 | |
| 191 | def test_aarch64_ast2700a2_evb_ioexp_v11_03(self): |
| 192 | self.set_machine('ast2700a2-evb') |
| 193 | self.require_netdev('user') |
| 194 | |
| 195 | self.archive_extract(self.ASSET_SDK_V1103_AST2700A2_DCSCM) |
| 196 | self.vm.set_machine('ast2700a2-evb,fmc-model=w25q512jv') |
| 197 | self.vm.add_args('-device', |
| 198 | 'tmp105,bus=ioexp0.0,address=0x4d,id=tmp-test-16') |
| 199 | self.start_ast2700_test('ast2700-dcscm-image', 8) |
| 200 | self.verify_openbmc_boot_and_login('ast2700-dcscm', False) |
| 201 | self.do_ast2700_i2c_test(8) |
| 202 | self.do_ast2700_i2c_test(16) |
| 203 | |
| 204 | if __name__ == '__main__': |
| 205 | QemuSystemTest.main() |