| 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): |
| 19 | self.require_netdev('user') |
| 20 | self.vm.set_console() |
| 21 | self.vm.add_args('-device', |
| 22 | 'tmp105,bus=aspeed.i2c.bus.1,address=0x4d,id=tmp-test') |
| 23 | self.vm.add_args('-device', 'e1000e,netdev=net1,bus=pcie.2') |
| 24 | self.vm.add_args('-netdev', 'user,id=net1') |
| 25 | self.vm.add_args('-drive', 'file=' + image + ',if=mtd,format=raw', |
| 26 | '-net', 'nic', '-net', 'user', '-snapshot') |
| 27 | |
| 28 | self.vm.launch() |
| 29 | |
| 30 | def disable_kernel_crypto_selftest(self): |
| 31 | exec_command_and_wait_for_pattern(self, |
| 32 | 'setenv bootargs "${bootargs} cryptomgr.notests=1"', '=>') |
| 33 | |
| 34 | def enable_ast2700_pcie2(self): |
| 35 | exec_command_and_wait_for_pattern(self, |
| 36 | 'cp 100420000 403000000 900000', '=>') |
| 37 | exec_command_and_wait_for_pattern(self, |
| 38 | 'bootm start 403000000', '=>') |
| 39 | exec_command_and_wait_for_pattern(self, 'bootm loados', '=>') |
| 40 | exec_command_and_wait_for_pattern(self, 'bootm ramdisk', '=>') |
| 41 | exec_command_and_wait_for_pattern(self, 'bootm prep', '=>') |
| 42 | exec_command_and_wait_for_pattern(self, |
| 43 | 'fdt set /soc@14000000/pcie@140d0000 status "okay"', '=>') |
| 44 | exec_command(self, 'bootm go') |
| 45 | |
| 46 | def verify_openbmc_boot_and_login(self, name): |
| 47 | wait_for_console_pattern(self, 'U-Boot 2023.10') |
| 48 | wait_for_console_pattern(self, 'Hit any key to stop autoboot') |
| 49 | exec_command_and_wait_for_pattern(self, '\012', '=>') |
| 50 | self.disable_kernel_crypto_selftest() |
| 51 | self.enable_ast2700_pcie2() |
| 52 | wait_for_console_pattern(self, 'Starting kernel ...') |
| 53 | |
| 54 | wait_for_console_pattern(self, 'login:') |
| 55 | exec_command_and_wait_for_pattern(self, 'root', 'Password:') |
| 56 | exec_command_and_wait_for_pattern(self, '0penBmc', f'root@{name}:~#') |
| 57 | |
| 58 | def load_ast2700fc_coprocessor(self, name): |
| 59 | load_elf_list = { |
| 60 | 'ssp': self.scratch_file(name, 'zephyr-aspeed-ssp.elf'), |
| 61 | 'tsp': self.scratch_file(name, 'zephyr-aspeed-tsp.elf') |
| 62 | } |
| 63 | |
| 64 | for cpu_num, key in enumerate(load_elf_list, start=4): |
| 65 | file = load_elf_list[key] |
| 66 | self.vm.add_args('-device', |
| 67 | f'loader,file={file},cpu-num={cpu_num}') |
| 68 | |
| 69 | ASSET_SDK_V1103_AST2700 = Asset( |
| 70 | 'https://github.com/AspeedTech-BMC/openbmc/releases/download/v11.03/ast2700-default-image.tar.gz', |
| 71 | 'b91450d53da234591060cfb926fa30f7534ce20eaab766cb0f80ec332f8f0adb') |
| 72 | |
| 73 | def do_ast2700_i2c_test(self): |
| 74 | exec_command_and_wait_for_pattern(self, |
| 75 | 'echo lm75 0x4d > /sys/class/i2c-dev/i2c-1/device/new_device ', |
| 76 | 'i2c i2c-1: new_device: Instantiated device lm75 at 0x4d') |
| 77 | exec_command_and_wait_for_pattern(self, |
| 78 | 'cat /sys/bus/i2c/devices/1-004d/hwmon/hwmon*/temp1_input', '0') |
| 79 | self.vm.cmd('qom-set', path='/machine/peripheral/tmp-test', |
| 80 | property='temperature', value=18000) |
| 81 | exec_command_and_wait_for_pattern(self, |
| 82 | 'cat /sys/bus/i2c/devices/1-004d/hwmon/hwmon*/temp1_input', '18000') |
| 83 | |
| 84 | def do_ast2700_pcie_test(self): |
| 85 | exec_command_and_wait_for_pattern(self, |
| 86 | 'lspci -s 0002:00:00.0', |
| 87 | '0002:00:00.0 PCI bridge: ' |
| 88 | 'ASPEED Technology, Inc. AST1150 PCI-to-PCI Bridge') |
| 89 | exec_command_and_wait_for_pattern(self, |
| 90 | 'lspci -s 0002:01:00.0', |
| 91 | '0002:01:00.0 Ethernet controller: ' |
| 92 | 'Intel Corporation 82574L Gigabit Network Connection') |
| 93 | exec_command_and_wait_for_pattern(self, |
| 94 | 'ip addr show dev eth2', |
| 95 | 'inet 10.0.2.15/24') |
| 96 | |
| 97 | def do_ast2700fc_ssp_test(self): |
| 98 | self.vm.shutdown() |
| 99 | self.vm.set_console(console_index=1) |
| 100 | self.vm.launch() |
| 101 | |
| 102 | exec_command_and_wait_for_pattern(self, '\012', 'ssp_tsp:~$') |
| 103 | exec_command_and_wait_for_pattern(self, 'version', |
| 104 | 'Zephyr version 3.7.2') |
| 105 | exec_command_and_wait_for_pattern(self, 'md 72c02000 1', |
| 106 | '[72c02000] 06020103') |
| 107 | |
| 108 | def do_ast2700fc_tsp_test(self): |
| 109 | self.vm.shutdown() |
| 110 | self.vm.set_console(console_index=2) |
| 111 | self.vm.launch() |
| 112 | |
| 113 | exec_command_and_wait_for_pattern(self, '\012', 'tsp:~$') |
| 114 | exec_command_and_wait_for_pattern(self, 'version', |
| 115 | 'Zephyr version 3.7.2') |
| 116 | exec_command_and_wait_for_pattern(self, 'md 72c02000 1', |
| 117 | '[72c02000] 06020103') |
| 118 | |
| 119 | def start_ast2700fc_test(self, name): |
| 120 | ca35_core = 4 |
| 121 | load_images_list = [ |
| 122 | { |
| 123 | 'addr': '0x400000000', |
| 124 | 'file': self.scratch_file(name, 'u-boot.bin') |
| 125 | }, |
| 126 | { |
| 127 | 'addr': '0x430000000', |
| 128 | 'file': self.scratch_file(name, 'trusted-firmware-a', |
| 129 | 'bl31.bin') |
| 130 | }, |
| 131 | { |
| 132 | 'addr': '0x430080000', |
| 133 | 'file': self.scratch_file(name, 'optee', 'tee-raw.bin') |
| 134 | } |
| 135 | ] |
| 136 | |
| 137 | for load_image in load_images_list: |
| 138 | addr = load_image['addr'] |
| 139 | file = load_image['file'] |
| 140 | self.vm.add_args('-device', |
| 141 | f'loader,force-raw=on,addr={addr},file={file}') |
| 142 | |
| 143 | for i in range(ca35_core): |
| 144 | self.vm.add_args('-device', |
| 145 | f'loader,addr=0x430000000,cpu-num={i}') |
| 146 | |
| 147 | self.load_ast2700fc_coprocessor(name) |
| 148 | self.do_test_aarch64_aspeed_sdk_start( |
| 149 | self.scratch_file(name, 'image-bmc')) |
| 150 | |
| 151 | def start_ast2700fc_test_vbootrom(self, name): |
| 152 | self.vm.add_args('-bios', 'ast27x0_bootrom.bin') |
| 153 | self.load_ast2700fc_coprocessor(name) |
| 154 | self.do_test_aarch64_aspeed_sdk_start( |
| 155 | self.scratch_file(name, 'image-bmc')) |
| 156 | |
| 157 | def test_aarch64_ast2700fc_sdk_v11_03(self): |
| 158 | self.set_machine('ast2700fc') |
| 159 | self.require_netdev('user') |
| 160 | |
| 161 | self.archive_extract(self.ASSET_SDK_V1103_AST2700) |
| 162 | self.start_ast2700fc_test('ast2700-default-image') |
| 163 | self.verify_openbmc_boot_and_login('ast2700-default') |
| 164 | self.do_ast2700_i2c_test() |
| 165 | self.do_ast2700_pcie_test() |
| 166 | self.do_ast2700fc_ssp_test() |
| 167 | self.do_ast2700fc_tsp_test() |
| 168 | |
| 169 | def test_aarch64_ast2700fc_sdk_vbootrom_v11_03(self): |
| 170 | self.set_machine('ast2700fc') |
| 171 | |
| 172 | self.archive_extract(self.ASSET_SDK_V1103_AST2700) |
| 173 | self.start_ast2700fc_test_vbootrom('ast2700-default-image') |
| 174 | self.verify_openbmc_boot_and_login('ast2700-default') |
| 175 | self.do_ast2700fc_ssp_test() |
| 176 | self.do_ast2700fc_tsp_test() |
| 177 | |
| 178 | if __name__ == '__main__': |
| 179 | QemuSystemTest.main() |