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
9import sys
10import os
11
12from qemu_test import QemuSystemTest, Asset
13from qemu_test import wait_for_console_pattern
14from qemu_test import exec_command_and_wait_for_pattern
15from qemu_test.utils import archive_extract
16
17class AST2x00MachineSDK(QemuSystemTest):
18
19    def do_test_aarch64_aspeed_sdk_start(self, image):
20        self.require_netdev('user')
21        self.vm.set_console()
22        self.vm.add_args('-drive', 'file=' + image + ',if=mtd,format=raw',
23                         '-net', 'nic', '-net', 'user', '-snapshot')
24
25        self.vm.launch()
26
27        wait_for_console_pattern(self, 'U-Boot 2023.10')
28        wait_for_console_pattern(self, '## Loading kernel from FIT Image')
29        wait_for_console_pattern(self, 'Starting kernel ...')
30
31    ASSET_SDK_V902_AST2700 = Asset(
32            'https://github.com/AspeedTech-BMC/openbmc/releases/download/v09.02/ast2700-default-obmc.tar.gz',
33            'ac969c2602f4e6bdb69562ff466b89ae3fe1d86e1f6797bb7969d787f82116a7')
34
35    def test_aarch64_ast2700_evb_sdk_v09_02(self):
36        self.set_machine('ast2700-evb')
37
38        image_path = self.ASSET_SDK_V902_AST2700.fetch()
39        archive_extract(image_path, self.workdir)
40
41        num_cpu = 4
42        image_dir = self.workdir + '/ast2700-default/'
43        uboot_size = os.path.getsize(image_dir + 'u-boot-nodtb.bin')
44        uboot_dtb_load_addr = hex(0x400000000 + uboot_size)
45
46        load_images_list = [
47            {
48                'addr': '0x400000000',
49                'file': image_dir + 'u-boot-nodtb.bin'
50            },
51            {
52                'addr': str(uboot_dtb_load_addr),
53                'file': image_dir + 'u-boot.dtb'
54            },
55            {
56                'addr': '0x430000000',
57                'file': image_dir + 'bl31.bin'
58            },
59            {
60                'addr': '0x430080000',
61                'file': image_dir + 'optee/tee-raw.bin'
62            }
63        ]
64
65        for load_image in load_images_list:
66            addr = load_image['addr']
67            file = load_image['file']
68            self.vm.add_args('-device',
69                             f'loader,force-raw=on,addr={addr},file={file}')
70
71        for i in range(num_cpu):
72            self.vm.add_args('-device',
73                             f'loader,addr=0x430000000,cpu-num={i}')
74
75        self.vm.add_args('-smp', str(num_cpu))
76        self.vm.add_args('-device',
77                         'tmp105,bus=aspeed.i2c.bus.1,address=0x4d,id=tmp-test')
78        self.do_test_aarch64_aspeed_sdk_start(image_dir + 'image-bmc')
79
80        wait_for_console_pattern(self, 'ast2700-default login:')
81
82        exec_command_and_wait_for_pattern(self, 'root', 'Password:')
83        exec_command_and_wait_for_pattern(self,
84            '0penBmc', 'root@ast2700-default:~#')
85
86        exec_command_and_wait_for_pattern(self,
87            'echo lm75 0x4d > /sys/class/i2c-dev/i2c-1/device/new_device ',
88            'i2c i2c-1: new_device: Instantiated device lm75 at 0x4d');
89        exec_command_and_wait_for_pattern(self,
90            'cat /sys/class/hwmon/hwmon20/temp1_input', '0')
91        self.vm.cmd('qom-set', path='/machine/peripheral/tmp-test',
92                    property='temperature', value=18000)
93        exec_command_and_wait_for_pattern(self,
94            'cat /sys/class/hwmon/hwmon20/temp1_input', '18000')
95
96
97if __name__ == '__main__':
98    QemuSystemTest.main()
99