1438eff63SJamin Lin# Functional test that boots the ASPEED SoCs with firmware
2438eff63SJamin Lin#
3438eff63SJamin Lin# Copyright (C) 2022 ASPEED Technology Inc
4438eff63SJamin Lin#
5438eff63SJamin Lin# This work is licensed under the terms of the GNU GPL, version 2 or
6438eff63SJamin Lin# later.  See the COPYING file in the top-level directory.
7438eff63SJamin Lin
8f7bc7da0SCédric Le Goaterimport time
992f8e8e2SAlex Bennéeimport os
10*c3d58a7aSJoel Stanleyimport tempfile
11*c3d58a7aSJoel Stanleyimport subprocess
12f7bc7da0SCédric Le Goater
13438eff63SJamin Linfrom avocado_qemu import QemuSystemTest
14438eff63SJamin Linfrom avocado_qemu import wait_for_console_pattern
15f7bc7da0SCédric Le Goaterfrom avocado_qemu import exec_command
16438eff63SJamin Linfrom avocado_qemu import exec_command_and_wait_for_pattern
17a4b14b46SCédric Le Goaterfrom avocado_qemu import interrupt_interactive_console_until_pattern
18*c3d58a7aSJoel Stanleyfrom avocado_qemu import has_cmd
19438eff63SJamin Linfrom avocado.utils import archive
2092f8e8e2SAlex Bennéefrom avocado import skipIf
21*c3d58a7aSJoel Stanleyfrom avocado import skipUnless
22438eff63SJamin Lin
23438eff63SJamin Lin
24438eff63SJamin Linclass AST1030Machine(QemuSystemTest):
25438eff63SJamin Lin    """Boots the zephyr os and checks that the console is operational"""
26438eff63SJamin Lin
27438eff63SJamin Lin    timeout = 10
28438eff63SJamin Lin
2944055caaSPhilippe Mathieu-Daudé    def test_ast1030_zephyros_1_04(self):
30438eff63SJamin Lin        """
31438eff63SJamin Lin        :avocado: tags=arch:arm
32438eff63SJamin Lin        :avocado: tags=machine:ast1030-evb
3344055caaSPhilippe Mathieu-Daudé        :avocado: tags=os:zephyr
34438eff63SJamin Lin        """
35438eff63SJamin Lin        tar_url = ('https://github.com/AspeedTech-BMC'
36438eff63SJamin Lin                   '/zephyr/releases/download/v00.01.04/ast1030-evb-demo.zip')
37438eff63SJamin Lin        tar_hash = '4c6a8ce3a8ba76ef1a65dae419ae3409343c4b20'
38438eff63SJamin Lin        tar_path = self.fetch_asset(tar_url, asset_hash=tar_hash)
39438eff63SJamin Lin        archive.extract(tar_path, self.workdir)
40438eff63SJamin Lin        kernel_file = self.workdir + "/ast1030-evb-demo/zephyr.elf"
41438eff63SJamin Lin        self.vm.set_console()
42438eff63SJamin Lin        self.vm.add_args('-kernel', kernel_file,
43438eff63SJamin Lin                         '-nographic')
44438eff63SJamin Lin        self.vm.launch()
45438eff63SJamin Lin        wait_for_console_pattern(self, "Booting Zephyr OS")
46438eff63SJamin Lin        exec_command_and_wait_for_pattern(self, "help",
47438eff63SJamin Lin                                          "Available commands")
48341e21faSCédric Le Goater
4944055caaSPhilippe Mathieu-Daudé    def test_ast1030_zephyros_1_07(self):
5044055caaSPhilippe Mathieu-Daudé        """
5144055caaSPhilippe Mathieu-Daudé        :avocado: tags=arch:arm
5244055caaSPhilippe Mathieu-Daudé        :avocado: tags=machine:ast1030-evb
5344055caaSPhilippe Mathieu-Daudé        :avocado: tags=os:zephyr
5444055caaSPhilippe Mathieu-Daudé        """
5544055caaSPhilippe Mathieu-Daudé        tar_url = ('https://github.com/AspeedTech-BMC'
5644055caaSPhilippe Mathieu-Daudé                   '/zephyr/releases/download/v00.01.07/ast1030-evb-demo.zip')
5744055caaSPhilippe Mathieu-Daudé        tar_hash = '40ac87eabdcd3b3454ce5aad11fedc72a33ecda2'
5844055caaSPhilippe Mathieu-Daudé        tar_path = self.fetch_asset(tar_url, asset_hash=tar_hash)
5944055caaSPhilippe Mathieu-Daudé        archive.extract(tar_path, self.workdir)
6044055caaSPhilippe Mathieu-Daudé        kernel_file = self.workdir + "/ast1030-evb-demo/zephyr.bin"
6144055caaSPhilippe Mathieu-Daudé        self.vm.set_console()
6244055caaSPhilippe Mathieu-Daudé        self.vm.add_args('-kernel', kernel_file,
6344055caaSPhilippe Mathieu-Daudé                         '-nographic')
6444055caaSPhilippe Mathieu-Daudé        self.vm.launch()
6544055caaSPhilippe Mathieu-Daudé        wait_for_console_pattern(self, "Booting Zephyr OS")
6644055caaSPhilippe Mathieu-Daudé        for shell_cmd in [
6744055caaSPhilippe Mathieu-Daudé                'kernel stacks',
6844055caaSPhilippe Mathieu-Daudé                'otp info conf',
6944055caaSPhilippe Mathieu-Daudé                'otp info scu',
7044055caaSPhilippe Mathieu-Daudé                'hwinfo devid',
7144055caaSPhilippe Mathieu-Daudé                'crypto aes256_cbc_vault',
7244055caaSPhilippe Mathieu-Daudé                'random get',
7344055caaSPhilippe Mathieu-Daudé                'jtag JTAG1 sw_xfer high TMS',
7444055caaSPhilippe Mathieu-Daudé                'adc ADC0 resolution 12',
7544055caaSPhilippe Mathieu-Daudé                'adc ADC0 read 42',
7644055caaSPhilippe Mathieu-Daudé                'adc ADC1 read 69',
7744055caaSPhilippe Mathieu-Daudé                'i2c scan I2C_0',
7844055caaSPhilippe Mathieu-Daudé                'i3c attach I3C_0',
7944055caaSPhilippe Mathieu-Daudé                'hash test',
8044055caaSPhilippe Mathieu-Daudé                'kernel uptime',
8144055caaSPhilippe Mathieu-Daudé                'kernel reboot warm',
8244055caaSPhilippe Mathieu-Daudé                'kernel uptime',
8344055caaSPhilippe Mathieu-Daudé                'kernel reboot cold',
8444055caaSPhilippe Mathieu-Daudé                'kernel uptime',
8544055caaSPhilippe Mathieu-Daudé        ]: exec_command_and_wait_for_pattern(self, shell_cmd, "uart:~$")
8644055caaSPhilippe Mathieu-Daudé
87341e21faSCédric Le Goaterclass AST2x00Machine(QemuSystemTest):
88341e21faSCédric Le Goater
89b1ceae2fSAlex Bennée    timeout = 90
90b1ceae2fSAlex Bennée
91341e21faSCédric Le Goater    def wait_for_console_pattern(self, success_message, vm=None):
92341e21faSCédric Le Goater        wait_for_console_pattern(self, success_message,
93341e21faSCédric Le Goater                                 failure_message='Kernel panic - not syncing',
94341e21faSCédric Le Goater                                 vm=vm)
95341e21faSCédric Le Goater
96341e21faSCédric Le Goater    def do_test_arm_aspeed(self, image):
97341e21faSCédric Le Goater        self.vm.set_console()
98341e21faSCédric Le Goater        self.vm.add_args('-drive', 'file=' + image + ',if=mtd,format=raw',
99341e21faSCédric Le Goater                         '-net', 'nic')
100341e21faSCédric Le Goater        self.vm.launch()
101341e21faSCédric Le Goater
102341e21faSCédric Le Goater        self.wait_for_console_pattern("U-Boot 2016.07")
103341e21faSCédric Le Goater        self.wait_for_console_pattern("## Loading kernel from FIT Image at 20080000")
104341e21faSCédric Le Goater        self.wait_for_console_pattern("Starting kernel ...")
105341e21faSCédric Le Goater        self.wait_for_console_pattern("Booting Linux on physical CPU 0x0")
106341e21faSCédric Le Goater        wait_for_console_pattern(self,
107341e21faSCédric Le Goater                "aspeed-smc 1e620000.spi: read control register: 203b0641")
108341e21faSCédric Le Goater        self.wait_for_console_pattern("ftgmac100 1e660000.ethernet eth0: irq ")
109341e21faSCédric Le Goater        self.wait_for_console_pattern("systemd[1]: Set hostname to")
110341e21faSCédric Le Goater
111341e21faSCédric Le Goater    def test_arm_ast2400_palmetto_openbmc_v2_9_0(self):
112341e21faSCédric Le Goater        """
113341e21faSCédric Le Goater        :avocado: tags=arch:arm
114341e21faSCédric Le Goater        :avocado: tags=machine:palmetto-bmc
115341e21faSCédric Le Goater        """
116341e21faSCédric Le Goater
117341e21faSCédric Le Goater        image_url = ('https://github.com/openbmc/openbmc/releases/download/2.9.0/'
118341e21faSCédric Le Goater                     'obmc-phosphor-image-palmetto.static.mtd')
119341e21faSCédric Le Goater        image_hash = ('3e13bbbc28e424865dc42f35ad672b10f2e82cdb11846bb28fa625b48beafd0d')
120341e21faSCédric Le Goater        image_path = self.fetch_asset(image_url, asset_hash=image_hash,
121341e21faSCédric Le Goater                                      algorithm='sha256')
122341e21faSCédric Le Goater
123341e21faSCédric Le Goater        self.do_test_arm_aspeed(image_path)
124341e21faSCédric Le Goater
125341e21faSCédric Le Goater    def test_arm_ast2500_romulus_openbmc_v2_9_0(self):
126341e21faSCédric Le Goater        """
127341e21faSCédric Le Goater        :avocado: tags=arch:arm
128341e21faSCédric Le Goater        :avocado: tags=machine:romulus-bmc
129341e21faSCédric Le Goater        """
130341e21faSCédric Le Goater
131341e21faSCédric Le Goater        image_url = ('https://github.com/openbmc/openbmc/releases/download/2.9.0/'
132341e21faSCédric Le Goater                     'obmc-phosphor-image-romulus.static.mtd')
133341e21faSCédric Le Goater        image_hash = ('820341076803f1955bc31e647a512c79f9add4f5233d0697678bab4604c7bb25')
134341e21faSCédric Le Goater        image_path = self.fetch_asset(image_url, asset_hash=image_hash,
135341e21faSCédric Le Goater                                      algorithm='sha256')
136341e21faSCédric Le Goater
137341e21faSCédric Le Goater        self.do_test_arm_aspeed(image_path)
138f7bc7da0SCédric Le Goater
139*c3d58a7aSJoel Stanley    def do_test_arm_aspeed_buildroot_start(self, image, cpu_id, pattern='Aspeed EVB'):
1400793fe01SPeter Maydell        self.require_netdev('user')
1410793fe01SPeter Maydell
142f7bc7da0SCédric Le Goater        self.vm.set_console()
143f7bc7da0SCédric Le Goater        self.vm.add_args('-drive', 'file=' + image + ',if=mtd,format=raw',
144f7bc7da0SCédric Le Goater                         '-net', 'nic', '-net', 'user')
145f7bc7da0SCédric Le Goater        self.vm.launch()
146f7bc7da0SCédric Le Goater
147f7bc7da0SCédric Le Goater        self.wait_for_console_pattern('U-Boot 2019.04')
148f7bc7da0SCédric Le Goater        self.wait_for_console_pattern('## Loading kernel from FIT Image')
149f7bc7da0SCédric Le Goater        self.wait_for_console_pattern('Starting kernel ...')
150f7bc7da0SCédric Le Goater        self.wait_for_console_pattern('Booting Linux on physical CPU ' + cpu_id)
151f7bc7da0SCédric Le Goater        self.wait_for_console_pattern('lease of 10.0.2.15')
15265711f9aSAlex Bennée        # the line before login:
153*c3d58a7aSJoel Stanley        self.wait_for_console_pattern(pattern)
15465711f9aSAlex Bennée        time.sleep(0.1)
155f7bc7da0SCédric Le Goater        exec_command(self, 'root')
156f7bc7da0SCédric Le Goater        time.sleep(0.1)
157f7bc7da0SCédric Le Goater
1587b5093b8SCédric Le Goater    def do_test_arm_aspeed_buildroot_poweroff(self):
159f7bc7da0SCédric Le Goater        exec_command_and_wait_for_pattern(self, 'poweroff',
160f7bc7da0SCédric Le Goater                                          'reboot: System halted');
161f7bc7da0SCédric Le Goater
1627b5093b8SCédric Le Goater    def test_arm_ast2500_evb_buildroot(self):
163f7bc7da0SCédric Le Goater        """
164f7bc7da0SCédric Le Goater        :avocado: tags=arch:arm
165f7bc7da0SCédric Le Goater        :avocado: tags=machine:ast2500-evb
166f7bc7da0SCédric Le Goater        """
167f7bc7da0SCédric Le Goater
168f7bc7da0SCédric Le Goater        image_url = ('https://github.com/legoater/qemu-aspeed-boot/raw/master/'
169ed1f5ff8SCédric Le Goater                     'images/ast2500-evb/buildroot-2022.11-2-g15d3648df9/flash.img')
170ed1f5ff8SCédric Le Goater        image_hash = ('f96d11db521fe7a2787745e9e391225deeeec3318ee0fc07c8b799b8833dd474')
171f7bc7da0SCédric Le Goater        image_path = self.fetch_asset(image_url, asset_hash=image_hash,
172f7bc7da0SCédric Le Goater                                      algorithm='sha256')
173f7bc7da0SCédric Le Goater
1747a7308eaSCédric Le Goater        self.vm.add_args('-device',
1757a7308eaSCédric Le Goater                         'tmp105,bus=aspeed.i2c.bus.3,address=0x4d,id=tmp-test');
1767b5093b8SCédric Le Goater        self.do_test_arm_aspeed_buildroot_start(image_path, '0x0')
1777a7308eaSCédric Le Goater
1787a7308eaSCédric Le Goater        exec_command_and_wait_for_pattern(self,
1797a7308eaSCédric Le Goater             'echo lm75 0x4d > /sys/class/i2c-dev/i2c-3/device/new_device',
1807a7308eaSCédric Le Goater             'i2c i2c-3: new_device: Instantiated device lm75 at 0x4d');
1817a7308eaSCédric Le Goater        exec_command_and_wait_for_pattern(self,
1827a7308eaSCédric Le Goater                             'cat /sys/class/hwmon/hwmon1/temp1_input', '0')
1837a7308eaSCédric Le Goater        self.vm.command('qom-set', path='/machine/peripheral/tmp-test',
1847a7308eaSCédric Le Goater                        property='temperature', value=18000);
1857a7308eaSCédric Le Goater        exec_command_and_wait_for_pattern(self,
1867a7308eaSCédric Le Goater                             'cat /sys/class/hwmon/hwmon1/temp1_input', '18000')
1877a7308eaSCédric Le Goater
1887b5093b8SCédric Le Goater        self.do_test_arm_aspeed_buildroot_poweroff()
189f7bc7da0SCédric Le Goater
1907b5093b8SCédric Le Goater    def test_arm_ast2600_evb_buildroot(self):
191f7bc7da0SCédric Le Goater        """
192f7bc7da0SCédric Le Goater        :avocado: tags=arch:arm
193f7bc7da0SCédric Le Goater        :avocado: tags=machine:ast2600-evb
194f7bc7da0SCédric Le Goater        """
195f7bc7da0SCédric Le Goater
196f7bc7da0SCédric Le Goater        image_url = ('https://github.com/legoater/qemu-aspeed-boot/raw/master/'
197ed1f5ff8SCédric Le Goater                     'images/ast2600-evb/buildroot-2022.11-2-g15d3648df9/flash.img')
198ed1f5ff8SCédric Le Goater        image_hash = ('e598d86e5ea79671ca8b59212a326c911bc8bea728dec1a1f5390d717a28bb8b')
199f7bc7da0SCédric Le Goater        image_path = self.fetch_asset(image_url, asset_hash=image_hash,
200f7bc7da0SCédric Le Goater                                      algorithm='sha256')
201f7bc7da0SCédric Le Goater
20261cf757dSCédric Le Goater        self.vm.add_args('-device',
20361cf757dSCédric Le Goater                         'tmp105,bus=aspeed.i2c.bus.3,address=0x4d,id=tmp-test');
2043302184fSCédric Le Goater        self.vm.add_args('-device',
2053302184fSCédric Le Goater                         'ds1338,bus=aspeed.i2c.bus.3,address=0x32');
20682e94da5SCédric Le Goater        self.vm.add_args('-device',
20782e94da5SCédric Le Goater                         'i2c-echo,bus=aspeed.i2c.bus.3,address=0x42');
2087b5093b8SCédric Le Goater        self.do_test_arm_aspeed_buildroot_start(image_path, '0xf00')
20961cf757dSCédric Le Goater
21061cf757dSCédric Le Goater        exec_command_and_wait_for_pattern(self,
21161cf757dSCédric Le Goater             'echo lm75 0x4d > /sys/class/i2c-dev/i2c-3/device/new_device',
21261cf757dSCédric Le Goater             'i2c i2c-3: new_device: Instantiated device lm75 at 0x4d');
21361cf757dSCédric Le Goater        exec_command_and_wait_for_pattern(self,
21461cf757dSCédric Le Goater                             'cat /sys/class/hwmon/hwmon0/temp1_input', '0')
21561cf757dSCédric Le Goater        self.vm.command('qom-set', path='/machine/peripheral/tmp-test',
21661cf757dSCédric Le Goater                        property='temperature', value=18000);
21761cf757dSCédric Le Goater        exec_command_and_wait_for_pattern(self,
21861cf757dSCédric Le Goater                             'cat /sys/class/hwmon/hwmon0/temp1_input', '18000')
21961cf757dSCédric Le Goater
2203302184fSCédric Le Goater        exec_command_and_wait_for_pattern(self,
2213302184fSCédric Le Goater             'echo ds1307 0x32 > /sys/class/i2c-dev/i2c-3/device/new_device',
2223302184fSCédric Le Goater             'i2c i2c-3: new_device: Instantiated device ds1307 at 0x32');
2233302184fSCédric Le Goater        year = time.strftime("%Y")
2243302184fSCédric Le Goater        exec_command_and_wait_for_pattern(self, 'hwclock -f /dev/rtc1', year);
2253302184fSCédric Le Goater
22682e94da5SCédric Le Goater        exec_command_and_wait_for_pattern(self,
22782e94da5SCédric Le Goater             'echo slave-24c02 0x1064 > /sys/bus/i2c/devices/i2c-3/new_device',
22882e94da5SCédric Le Goater             'i2c i2c-3: new_device: Instantiated device slave-24c02 at 0x64');
22982e94da5SCédric Le Goater        exec_command(self, 'i2cset -y 3 0x42 0x64 0x00 0xaa i');
23082e94da5SCédric Le Goater        time.sleep(0.1)
23182e94da5SCédric Le Goater        exec_command_and_wait_for_pattern(self,
23282e94da5SCédric Le Goater             'hexdump /sys/bus/i2c/devices/3-1064/slave-eeprom',
23382e94da5SCédric Le Goater             '0000000 ffaa ffff ffff ffff ffff ffff ffff ffff');
2347b5093b8SCédric Le Goater        self.do_test_arm_aspeed_buildroot_poweroff()
235bceb4d99SCédric Le Goater
236*c3d58a7aSJoel Stanley    @skipUnless(*has_cmd('swtpm'))
237*c3d58a7aSJoel Stanley    def test_arm_ast2600_evb_buildroot_tpm(self):
238*c3d58a7aSJoel Stanley        """
239*c3d58a7aSJoel Stanley        :avocado: tags=arch:arm
240*c3d58a7aSJoel Stanley        :avocado: tags=machine:ast2600-evb
241*c3d58a7aSJoel Stanley        """
242*c3d58a7aSJoel Stanley
243*c3d58a7aSJoel Stanley        image_url = ('https://github.com/legoater/qemu-aspeed-boot/raw/master/'
244*c3d58a7aSJoel Stanley                     'images/ast2600-evb/buildroot-2023.02-tpm/flash.img')
245*c3d58a7aSJoel Stanley        image_hash = ('a46009ae8a5403a0826d607215e731a8c68d27c14c41e55331706b8f9c7bd997')
246*c3d58a7aSJoel Stanley        image_path = self.fetch_asset(image_url, asset_hash=image_hash,
247*c3d58a7aSJoel Stanley                                      algorithm='sha256')
248*c3d58a7aSJoel Stanley
249*c3d58a7aSJoel Stanley        socket = os.path.join(self.vm.sock_dir, 'swtpm-socket')
250*c3d58a7aSJoel Stanley
251*c3d58a7aSJoel Stanley        subprocess.run(['swtpm', 'socket', '-d', '--tpm2',
252*c3d58a7aSJoel Stanley                        '--tpmstate', f'dir={self.vm.temp_dir}',
253*c3d58a7aSJoel Stanley                        '--ctrl', f'type=unixio,path={socket}'])
254*c3d58a7aSJoel Stanley
255*c3d58a7aSJoel Stanley        self.vm.add_args('-chardev', f'socket,id=chrtpm,path={socket}')
256*c3d58a7aSJoel Stanley        self.vm.add_args('-tpmdev', 'emulator,id=tpm0,chardev=chrtpm')
257*c3d58a7aSJoel Stanley        self.vm.add_args('-device',
258*c3d58a7aSJoel Stanley                         'tpm-tis-i2c,tpmdev=tpm0,bus=aspeed.i2c.bus.12,address=0x2e')
259*c3d58a7aSJoel Stanley        self.do_test_arm_aspeed_buildroot_start(image_path, '0xf00', 'Aspeed AST2600 EVB')
260*c3d58a7aSJoel Stanley        exec_command(self, "passw0rd")
261*c3d58a7aSJoel Stanley
262*c3d58a7aSJoel Stanley        exec_command_and_wait_for_pattern(self,
263*c3d58a7aSJoel Stanley            'echo tpm_tis_i2c 0x2e > /sys/bus/i2c/devices/i2c-12/new_device',
264*c3d58a7aSJoel Stanley            'tpm_tis_i2c 12-002e: 2.0 TPM (device-id 0x1, rev-id 1)');
265*c3d58a7aSJoel Stanley        exec_command_and_wait_for_pattern(self,
266*c3d58a7aSJoel Stanley            'cat /sys/class/tpm/tpm0/pcr-sha256/0',
267*c3d58a7aSJoel Stanley            'B804724EA13F52A9072BA87FE8FDCC497DFC9DF9AA15B9088694639C431688E0');
268*c3d58a7aSJoel Stanley
269*c3d58a7aSJoel Stanley        self.do_test_arm_aspeed_buildroot_poweroff()
270bceb4d99SCédric Le Goater
27192f8e8e2SAlex Bennéeclass AST2x00MachineSDK(QemuSystemTest):
27292f8e8e2SAlex Bennée
27330d7aac4SCédric Le Goater    EXTRA_BOOTARGS = (
27430d7aac4SCédric Le Goater        'quiet '
27530d7aac4SCédric Le Goater        'systemd.mask=org.openbmc.HostIpmi.service '
27630d7aac4SCédric Le Goater        'systemd.mask=xyz.openbmc_project.Chassis.Control.Power@0.service '
27730d7aac4SCédric Le Goater        'systemd.mask=modprobe@fuse.service '
27830d7aac4SCédric Le Goater        'systemd.mask=rngd.service '
27930d7aac4SCédric Le Goater        'systemd.mask=obmc-console@ttyS2.service '
28030d7aac4SCédric Le Goater    )
281a4b14b46SCédric Le Goater
28292f8e8e2SAlex Bennée    # FIXME: Although these tests boot a whole distro they are still
28392f8e8e2SAlex Bennée    # slower than comparable machine models. There may be some
28492f8e8e2SAlex Bennée    # optimisations which bring down the runtime. In the meantime they
28592f8e8e2SAlex Bennée    # have generous timeouts and are disable for CI which aims for all
28692f8e8e2SAlex Bennée    # tests to run in less than 60 seconds.
28792f8e8e2SAlex Bennée    timeout = 240
28892f8e8e2SAlex Bennée
28992f8e8e2SAlex Bennée    def wait_for_console_pattern(self, success_message, vm=None):
29092f8e8e2SAlex Bennée        wait_for_console_pattern(self, success_message,
29192f8e8e2SAlex Bennée                                 failure_message='Kernel panic - not syncing',
29292f8e8e2SAlex Bennée                                 vm=vm)
29392f8e8e2SAlex Bennée
294a4b14b46SCédric Le Goater    def do_test_arm_aspeed_sdk_start(self, image):
2950793fe01SPeter Maydell        self.require_netdev('user')
296bceb4d99SCédric Le Goater        self.vm.set_console()
297bceb4d99SCédric Le Goater        self.vm.add_args('-drive', 'file=' + image + ',if=mtd,format=raw',
298bceb4d99SCédric Le Goater                         '-net', 'nic', '-net', 'user')
299bceb4d99SCédric Le Goater        self.vm.launch()
300bceb4d99SCédric Le Goater
301bceb4d99SCédric Le Goater        self.wait_for_console_pattern('U-Boot 2019.04')
302a4b14b46SCédric Le Goater        interrupt_interactive_console_until_pattern(
303a4b14b46SCédric Le Goater            self, 'Hit any key to stop autoboot:', 'ast#')
304a4b14b46SCédric Le Goater        exec_command_and_wait_for_pattern(
305a4b14b46SCédric Le Goater            self, 'setenv bootargs ${bootargs} ' + self.EXTRA_BOOTARGS, 'ast#')
306a4b14b46SCédric Le Goater        exec_command_and_wait_for_pattern(
307a4b14b46SCédric Le Goater            self, 'boot', '## Loading kernel from FIT Image')
308bceb4d99SCédric Le Goater        self.wait_for_console_pattern('Starting kernel ...')
309bceb4d99SCédric Le Goater
31092f8e8e2SAlex Bennée    @skipIf(os.getenv('GITLAB_CI'), 'Running on GitLab')
311bceb4d99SCédric Le Goater    def test_arm_ast2500_evb_sdk(self):
312bceb4d99SCédric Le Goater        """
313bceb4d99SCédric Le Goater        :avocado: tags=arch:arm
314bceb4d99SCédric Le Goater        :avocado: tags=machine:ast2500-evb
315bceb4d99SCédric Le Goater        """
316bceb4d99SCédric Le Goater
317bceb4d99SCédric Le Goater        image_url = ('https://github.com/AspeedTech-BMC/openbmc/releases/'
318bceb4d99SCédric Le Goater                     'download/v08.01/ast2500-default-obmc.tar.gz')
319bceb4d99SCédric Le Goater        image_hash = ('5375f82b4c43a79427909342a1e18b4e48bd663e38466862145d27bb358796fd')
320bceb4d99SCédric Le Goater        image_path = self.fetch_asset(image_url, asset_hash=image_hash,
321bceb4d99SCédric Le Goater                                      algorithm='sha256')
322bceb4d99SCédric Le Goater        archive.extract(image_path, self.workdir)
323bceb4d99SCédric Le Goater
324bceb4d99SCédric Le Goater        self.do_test_arm_aspeed_sdk_start(
325a4b14b46SCédric Le Goater            self.workdir + '/ast2500-default/image-bmc')
326bceb4d99SCédric Le Goater        self.wait_for_console_pattern('ast2500-default login:')
327bceb4d99SCédric Le Goater
32892f8e8e2SAlex Bennée    @skipIf(os.getenv('GITLAB_CI'), 'Running on GitLab')
329bceb4d99SCédric Le Goater    def test_arm_ast2600_evb_sdk(self):
330bceb4d99SCédric Le Goater        """
331bceb4d99SCédric Le Goater        :avocado: tags=arch:arm
332bceb4d99SCédric Le Goater        :avocado: tags=machine:ast2600-evb
333bceb4d99SCédric Le Goater        """
334bceb4d99SCédric Le Goater
335bceb4d99SCédric Le Goater        image_url = ('https://github.com/AspeedTech-BMC/openbmc/releases/'
336bceb4d99SCédric Le Goater                     'download/v08.01/ast2600-default-obmc.tar.gz')
337bceb4d99SCédric Le Goater        image_hash = ('f12ef15e8c1f03a214df3b91c814515c5e2b2f56119021398c1dbdd626817d15')
338bceb4d99SCédric Le Goater        image_path = self.fetch_asset(image_url, asset_hash=image_hash,
339bceb4d99SCédric Le Goater                                      algorithm='sha256')
340bceb4d99SCédric Le Goater        archive.extract(image_path, self.workdir)
341bceb4d99SCédric Le Goater
342bceb4d99SCédric Le Goater        self.vm.add_args('-device',
343bceb4d99SCédric Le Goater                         'tmp105,bus=aspeed.i2c.bus.5,address=0x4d,id=tmp-test');
344bceb4d99SCédric Le Goater        self.vm.add_args('-device',
345bceb4d99SCédric Le Goater                         'ds1338,bus=aspeed.i2c.bus.5,address=0x32');
346bceb4d99SCédric Le Goater        self.do_test_arm_aspeed_sdk_start(
347a4b14b46SCédric Le Goater            self.workdir + '/ast2600-default/image-bmc')
348bceb4d99SCédric Le Goater        self.wait_for_console_pattern('ast2600-default login:')
349bceb4d99SCédric Le Goater        exec_command_and_wait_for_pattern(self, 'root', 'Password:')
350bceb4d99SCédric Le Goater        exec_command_and_wait_for_pattern(self, '0penBmc', 'root@ast2600-default:~#')
351bceb4d99SCédric Le Goater
352bceb4d99SCédric Le Goater        exec_command_and_wait_for_pattern(self,
353bceb4d99SCédric Le Goater             'echo lm75 0x4d > /sys/class/i2c-dev/i2c-5/device/new_device',
354bceb4d99SCédric Le Goater             'i2c i2c-5: new_device: Instantiated device lm75 at 0x4d');
355bceb4d99SCédric Le Goater        exec_command_and_wait_for_pattern(self,
356bceb4d99SCédric Le Goater                             'cat /sys/class/hwmon/hwmon19/temp1_input', '0')
357bceb4d99SCédric Le Goater        self.vm.command('qom-set', path='/machine/peripheral/tmp-test',
358bceb4d99SCédric Le Goater                        property='temperature', value=18000);
359bceb4d99SCédric Le Goater        exec_command_and_wait_for_pattern(self,
360bceb4d99SCédric Le Goater                             'cat /sys/class/hwmon/hwmon19/temp1_input', '18000')
361bceb4d99SCédric Le Goater
362bceb4d99SCédric Le Goater        exec_command_and_wait_for_pattern(self,
363bceb4d99SCédric Le Goater             'echo ds1307 0x32 > /sys/class/i2c-dev/i2c-5/device/new_device',
364bceb4d99SCédric Le Goater             'i2c i2c-5: new_device: Instantiated device ds1307 at 0x32');
365bceb4d99SCédric Le Goater        year = time.strftime("%Y")
366bceb4d99SCédric Le Goater        exec_command_and_wait_for_pattern(self, 'hwclock -f /dev/rtc1', year);
367