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
10c3d58a7aSJoel Stanleyimport tempfile
11c3d58a7aSJoel Stanleyimport subprocess
12f7bc7da0SCédric Le Goater
13dd562bbfSThomas Huthfrom avocado_qemu import LinuxSSHMixIn
14438eff63SJamin Linfrom avocado_qemu import QemuSystemTest
15438eff63SJamin Linfrom avocado_qemu import wait_for_console_pattern
16f7bc7da0SCédric Le Goaterfrom avocado_qemu import exec_command
17438eff63SJamin Linfrom avocado_qemu import exec_command_and_wait_for_pattern
18a4b14b46SCédric Le Goaterfrom avocado_qemu import interrupt_interactive_console_until_pattern
19c3d58a7aSJoel Stanleyfrom avocado_qemu import has_cmd
20438eff63SJamin Linfrom avocado.utils import archive
219b45cc99SAlex Bennéefrom avocado import skipUnless
22c3d58a7aSJoel Stanleyfrom avocado import skipUnless
23438eff63SJamin Lin
24438eff63SJamin Lin
25438eff63SJamin Linclass AST1030Machine(QemuSystemTest):
26438eff63SJamin Lin    """Boots the zephyr os and checks that the console is operational"""
27438eff63SJamin Lin
28438eff63SJamin Lin    timeout = 10
29438eff63SJamin Lin
3044055caaSPhilippe Mathieu-Daudé    def test_ast1030_zephyros_1_04(self):
31438eff63SJamin Lin        """
32438eff63SJamin Lin        :avocado: tags=arch:arm
33438eff63SJamin Lin        :avocado: tags=machine:ast1030-evb
3444055caaSPhilippe Mathieu-Daudé        :avocado: tags=os:zephyr
35438eff63SJamin Lin        """
36438eff63SJamin Lin        tar_url = ('https://github.com/AspeedTech-BMC'
37438eff63SJamin Lin                   '/zephyr/releases/download/v00.01.04/ast1030-evb-demo.zip')
38438eff63SJamin Lin        tar_hash = '4c6a8ce3a8ba76ef1a65dae419ae3409343c4b20'
39438eff63SJamin Lin        tar_path = self.fetch_asset(tar_url, asset_hash=tar_hash)
40438eff63SJamin Lin        archive.extract(tar_path, self.workdir)
41438eff63SJamin Lin        kernel_file = self.workdir + "/ast1030-evb-demo/zephyr.elf"
42438eff63SJamin Lin        self.vm.set_console()
43438eff63SJamin Lin        self.vm.add_args('-kernel', kernel_file,
44438eff63SJamin Lin                         '-nographic')
45438eff63SJamin Lin        self.vm.launch()
46438eff63SJamin Lin        wait_for_console_pattern(self, "Booting Zephyr OS")
47438eff63SJamin Lin        exec_command_and_wait_for_pattern(self, "help",
48438eff63SJamin Lin                                          "Available commands")
49341e21faSCédric Le Goater
5044055caaSPhilippe Mathieu-Daudé    def test_ast1030_zephyros_1_07(self):
5144055caaSPhilippe Mathieu-Daudé        """
5244055caaSPhilippe Mathieu-Daudé        :avocado: tags=arch:arm
5344055caaSPhilippe Mathieu-Daudé        :avocado: tags=machine:ast1030-evb
5444055caaSPhilippe Mathieu-Daudé        :avocado: tags=os:zephyr
5544055caaSPhilippe Mathieu-Daudé        """
5644055caaSPhilippe Mathieu-Daudé        tar_url = ('https://github.com/AspeedTech-BMC'
5744055caaSPhilippe Mathieu-Daudé                   '/zephyr/releases/download/v00.01.07/ast1030-evb-demo.zip')
5844055caaSPhilippe Mathieu-Daudé        tar_hash = '40ac87eabdcd3b3454ce5aad11fedc72a33ecda2'
5944055caaSPhilippe Mathieu-Daudé        tar_path = self.fetch_asset(tar_url, asset_hash=tar_hash)
6044055caaSPhilippe Mathieu-Daudé        archive.extract(tar_path, self.workdir)
6144055caaSPhilippe Mathieu-Daudé        kernel_file = self.workdir + "/ast1030-evb-demo/zephyr.bin"
6244055caaSPhilippe Mathieu-Daudé        self.vm.set_console()
6344055caaSPhilippe Mathieu-Daudé        self.vm.add_args('-kernel', kernel_file,
6444055caaSPhilippe Mathieu-Daudé                         '-nographic')
6544055caaSPhilippe Mathieu-Daudé        self.vm.launch()
6644055caaSPhilippe Mathieu-Daudé        wait_for_console_pattern(self, "Booting Zephyr OS")
6744055caaSPhilippe Mathieu-Daudé        for shell_cmd in [
6844055caaSPhilippe Mathieu-Daudé                'kernel stacks',
6944055caaSPhilippe Mathieu-Daudé                'otp info conf',
7044055caaSPhilippe Mathieu-Daudé                'otp info scu',
7144055caaSPhilippe Mathieu-Daudé                'hwinfo devid',
7244055caaSPhilippe Mathieu-Daudé                'crypto aes256_cbc_vault',
7344055caaSPhilippe Mathieu-Daudé                'random get',
7444055caaSPhilippe Mathieu-Daudé                'jtag JTAG1 sw_xfer high TMS',
7544055caaSPhilippe Mathieu-Daudé                'adc ADC0 resolution 12',
7644055caaSPhilippe Mathieu-Daudé                'adc ADC0 read 42',
7744055caaSPhilippe Mathieu-Daudé                'adc ADC1 read 69',
7844055caaSPhilippe Mathieu-Daudé                'i2c scan I2C_0',
7944055caaSPhilippe Mathieu-Daudé                'i3c attach I3C_0',
8044055caaSPhilippe Mathieu-Daudé                'hash test',
8144055caaSPhilippe Mathieu-Daudé                'kernel uptime',
8244055caaSPhilippe Mathieu-Daudé                'kernel reboot warm',
8344055caaSPhilippe Mathieu-Daudé                'kernel uptime',
8444055caaSPhilippe Mathieu-Daudé                'kernel reboot cold',
8544055caaSPhilippe Mathieu-Daudé                'kernel uptime',
8644055caaSPhilippe Mathieu-Daudé        ]: exec_command_and_wait_for_pattern(self, shell_cmd, "uart:~$")
8744055caaSPhilippe Mathieu-Daudé
88341e21faSCédric Le Goaterclass AST2x00Machine(QemuSystemTest):
89341e21faSCédric Le Goater
90b1ceae2fSAlex Bennée    timeout = 90
91b1ceae2fSAlex Bennée
92341e21faSCédric Le Goater    def wait_for_console_pattern(self, success_message, vm=None):
93341e21faSCédric Le Goater        wait_for_console_pattern(self, success_message,
94341e21faSCédric Le Goater                                 failure_message='Kernel panic - not syncing',
95341e21faSCédric Le Goater                                 vm=vm)
96341e21faSCédric Le Goater
97341e21faSCédric Le Goater    def do_test_arm_aspeed(self, image):
98341e21faSCédric Le Goater        self.vm.set_console()
99341e21faSCédric Le Goater        self.vm.add_args('-drive', 'file=' + image + ',if=mtd,format=raw',
100341e21faSCédric Le Goater                         '-net', 'nic')
101341e21faSCédric Le Goater        self.vm.launch()
102341e21faSCédric Le Goater
103341e21faSCédric Le Goater        self.wait_for_console_pattern("U-Boot 2016.07")
104341e21faSCédric Le Goater        self.wait_for_console_pattern("## Loading kernel from FIT Image at 20080000")
105341e21faSCédric Le Goater        self.wait_for_console_pattern("Starting kernel ...")
106341e21faSCédric Le Goater        self.wait_for_console_pattern("Booting Linux on physical CPU 0x0")
107341e21faSCédric Le Goater        wait_for_console_pattern(self,
108341e21faSCédric Le Goater                "aspeed-smc 1e620000.spi: read control register: 203b0641")
109341e21faSCédric Le Goater        self.wait_for_console_pattern("ftgmac100 1e660000.ethernet eth0: irq ")
110341e21faSCédric Le Goater        self.wait_for_console_pattern("systemd[1]: Set hostname to")
111341e21faSCédric Le Goater
112341e21faSCédric Le Goater    def test_arm_ast2400_palmetto_openbmc_v2_9_0(self):
113341e21faSCédric Le Goater        """
114341e21faSCédric Le Goater        :avocado: tags=arch:arm
115341e21faSCédric Le Goater        :avocado: tags=machine:palmetto-bmc
116341e21faSCédric Le Goater        """
117341e21faSCédric Le Goater
118341e21faSCédric Le Goater        image_url = ('https://github.com/openbmc/openbmc/releases/download/2.9.0/'
119341e21faSCédric Le Goater                     'obmc-phosphor-image-palmetto.static.mtd')
120341e21faSCédric Le Goater        image_hash = ('3e13bbbc28e424865dc42f35ad672b10f2e82cdb11846bb28fa625b48beafd0d')
121341e21faSCédric Le Goater        image_path = self.fetch_asset(image_url, asset_hash=image_hash,
122341e21faSCédric Le Goater                                      algorithm='sha256')
123341e21faSCédric Le Goater
124341e21faSCédric Le Goater        self.do_test_arm_aspeed(image_path)
125341e21faSCédric Le Goater
126341e21faSCédric Le Goater    def test_arm_ast2500_romulus_openbmc_v2_9_0(self):
127341e21faSCédric Le Goater        """
128341e21faSCédric Le Goater        :avocado: tags=arch:arm
129341e21faSCédric Le Goater        :avocado: tags=machine:romulus-bmc
130341e21faSCédric Le Goater        """
131341e21faSCédric Le Goater
132341e21faSCédric Le Goater        image_url = ('https://github.com/openbmc/openbmc/releases/download/2.9.0/'
133341e21faSCédric Le Goater                     'obmc-phosphor-image-romulus.static.mtd')
134341e21faSCédric Le Goater        image_hash = ('820341076803f1955bc31e647a512c79f9add4f5233d0697678bab4604c7bb25')
135341e21faSCédric Le Goater        image_path = self.fetch_asset(image_url, asset_hash=image_hash,
136341e21faSCédric Le Goater                                      algorithm='sha256')
137341e21faSCédric Le Goater
138341e21faSCédric Le Goater        self.do_test_arm_aspeed(image_path)
139f7bc7da0SCédric Le Goater
140c3d58a7aSJoel Stanley    def do_test_arm_aspeed_buildroot_start(self, image, cpu_id, pattern='Aspeed EVB'):
1410793fe01SPeter Maydell        self.require_netdev('user')
1420793fe01SPeter Maydell
143f7bc7da0SCédric Le Goater        self.vm.set_console()
144f7bc7da0SCédric Le Goater        self.vm.add_args('-drive', 'file=' + image + ',if=mtd,format=raw',
145f7bc7da0SCédric Le Goater                         '-net', 'nic', '-net', 'user')
146f7bc7da0SCédric Le Goater        self.vm.launch()
147f7bc7da0SCédric Le Goater
148f7bc7da0SCédric Le Goater        self.wait_for_console_pattern('U-Boot 2019.04')
149f7bc7da0SCédric Le Goater        self.wait_for_console_pattern('## Loading kernel from FIT Image')
150f7bc7da0SCédric Le Goater        self.wait_for_console_pattern('Starting kernel ...')
151f7bc7da0SCédric Le Goater        self.wait_for_console_pattern('Booting Linux on physical CPU ' + cpu_id)
152f7bc7da0SCédric Le Goater        self.wait_for_console_pattern('lease of 10.0.2.15')
15365711f9aSAlex Bennée        # the line before login:
154c3d58a7aSJoel Stanley        self.wait_for_console_pattern(pattern)
15565711f9aSAlex Bennée        time.sleep(0.1)
156f7bc7da0SCédric Le Goater        exec_command(self, 'root')
157f7bc7da0SCédric Le Goater        time.sleep(0.1)
158*9e7ef089SCédric Le Goater        exec_command(self, "passw0rd")
159f7bc7da0SCédric Le Goater
1607b5093b8SCédric Le Goater    def do_test_arm_aspeed_buildroot_poweroff(self):
161f7bc7da0SCédric Le Goater        exec_command_and_wait_for_pattern(self, 'poweroff',
162f7bc7da0SCédric Le Goater                                          'reboot: System halted');
163f7bc7da0SCédric Le Goater
1647b5093b8SCédric Le Goater    def test_arm_ast2500_evb_buildroot(self):
165f7bc7da0SCédric Le Goater        """
166f7bc7da0SCédric Le Goater        :avocado: tags=arch:arm
167f7bc7da0SCédric Le Goater        :avocado: tags=machine:ast2500-evb
168f7bc7da0SCédric Le Goater        """
169f7bc7da0SCédric Le Goater
170f7bc7da0SCédric Le Goater        image_url = ('https://github.com/legoater/qemu-aspeed-boot/raw/master/'
171*9e7ef089SCédric Le Goater                     'images/ast2500-evb/buildroot-2023.11/flash.img')
172*9e7ef089SCédric Le Goater        image_hash = ('c23db6160cf77d0258397eb2051162c8473a56c441417c52a91ba217186e715f')
173f7bc7da0SCédric Le Goater        image_path = self.fetch_asset(image_url, asset_hash=image_hash,
174f7bc7da0SCédric Le Goater                                      algorithm='sha256')
175f7bc7da0SCédric Le Goater
1767a7308eaSCédric Le Goater        self.vm.add_args('-device',
1777a7308eaSCédric Le Goater                         'tmp105,bus=aspeed.i2c.bus.3,address=0x4d,id=tmp-test');
178*9e7ef089SCédric Le Goater        self.do_test_arm_aspeed_buildroot_start(image_path, '0x0', 'Aspeed AST2500 EVB')
1797a7308eaSCédric Le Goater
1807a7308eaSCédric Le Goater        exec_command_and_wait_for_pattern(self,
1817a7308eaSCédric Le Goater             'echo lm75 0x4d > /sys/class/i2c-dev/i2c-3/device/new_device',
1827a7308eaSCédric Le Goater             'i2c i2c-3: new_device: Instantiated device lm75 at 0x4d');
1837a7308eaSCédric Le Goater        exec_command_and_wait_for_pattern(self,
1847a7308eaSCédric Le Goater                             'cat /sys/class/hwmon/hwmon1/temp1_input', '0')
185684750abSVladimir Sementsov-Ogievskiy        self.vm.cmd('qom-set', path='/machine/peripheral/tmp-test',
1867a7308eaSCédric Le Goater                    property='temperature', value=18000);
1877a7308eaSCédric Le Goater        exec_command_and_wait_for_pattern(self,
1887a7308eaSCédric Le Goater                             'cat /sys/class/hwmon/hwmon1/temp1_input', '18000')
1897a7308eaSCédric Le Goater
1907b5093b8SCédric Le Goater        self.do_test_arm_aspeed_buildroot_poweroff()
191f7bc7da0SCédric Le Goater
1927b5093b8SCédric Le Goater    def test_arm_ast2600_evb_buildroot(self):
193f7bc7da0SCédric Le Goater        """
194f7bc7da0SCédric Le Goater        :avocado: tags=arch:arm
195f7bc7da0SCédric Le Goater        :avocado: tags=machine:ast2600-evb
196f7bc7da0SCédric Le Goater        """
197f7bc7da0SCédric Le Goater
198f7bc7da0SCédric Le Goater        image_url = ('https://github.com/legoater/qemu-aspeed-boot/raw/master/'
199*9e7ef089SCédric Le Goater                     'images/ast2600-evb/buildroot-2023.11/flash.img')
200*9e7ef089SCédric Le Goater        image_hash = ('b62808daef48b438d0728ee07662290490ecfa65987bb91294cafb1bb7ad1a68')
201f7bc7da0SCédric Le Goater        image_path = self.fetch_asset(image_url, asset_hash=image_hash,
202f7bc7da0SCédric Le Goater                                      algorithm='sha256')
203f7bc7da0SCédric Le Goater
20461cf757dSCédric Le Goater        self.vm.add_args('-device',
20561cf757dSCédric Le Goater                         'tmp105,bus=aspeed.i2c.bus.3,address=0x4d,id=tmp-test');
2063302184fSCédric Le Goater        self.vm.add_args('-device',
2073302184fSCédric Le Goater                         'ds1338,bus=aspeed.i2c.bus.3,address=0x32');
20882e94da5SCédric Le Goater        self.vm.add_args('-device',
20982e94da5SCédric Le Goater                         'i2c-echo,bus=aspeed.i2c.bus.3,address=0x42');
210*9e7ef089SCédric Le Goater        self.do_test_arm_aspeed_buildroot_start(image_path, '0xf00', 'Aspeed AST2600 EVB')
21161cf757dSCédric Le Goater
21261cf757dSCédric Le Goater        exec_command_and_wait_for_pattern(self,
21361cf757dSCédric Le Goater             'echo lm75 0x4d > /sys/class/i2c-dev/i2c-3/device/new_device',
21461cf757dSCédric Le Goater             'i2c i2c-3: new_device: Instantiated device lm75 at 0x4d');
21561cf757dSCédric Le Goater        exec_command_and_wait_for_pattern(self,
216*9e7ef089SCédric Le Goater                             'cat /sys/class/hwmon/hwmon1/temp1_input', '0')
217684750abSVladimir Sementsov-Ogievskiy        self.vm.cmd('qom-set', path='/machine/peripheral/tmp-test',
21861cf757dSCédric Le Goater                    property='temperature', value=18000);
21961cf757dSCédric Le Goater        exec_command_and_wait_for_pattern(self,
220*9e7ef089SCédric Le Goater                             'cat /sys/class/hwmon/hwmon1/temp1_input', '18000')
22161cf757dSCédric Le Goater
2223302184fSCédric Le Goater        exec_command_and_wait_for_pattern(self,
2233302184fSCédric Le Goater             'echo ds1307 0x32 > /sys/class/i2c-dev/i2c-3/device/new_device',
2243302184fSCédric Le Goater             'i2c i2c-3: new_device: Instantiated device ds1307 at 0x32');
2253302184fSCédric Le Goater        year = time.strftime("%Y")
2263302184fSCédric Le Goater        exec_command_and_wait_for_pattern(self, 'hwclock -f /dev/rtc1', year);
2273302184fSCédric Le Goater
22882e94da5SCédric Le Goater        exec_command_and_wait_for_pattern(self,
22982e94da5SCédric Le Goater             'echo slave-24c02 0x1064 > /sys/bus/i2c/devices/i2c-3/new_device',
23082e94da5SCédric Le Goater             'i2c i2c-3: new_device: Instantiated device slave-24c02 at 0x64');
23182e94da5SCédric Le Goater        exec_command(self, 'i2cset -y 3 0x42 0x64 0x00 0xaa i');
23282e94da5SCédric Le Goater        time.sleep(0.1)
23382e94da5SCédric Le Goater        exec_command_and_wait_for_pattern(self,
23482e94da5SCédric Le Goater             'hexdump /sys/bus/i2c/devices/3-1064/slave-eeprom',
23582e94da5SCédric Le Goater             '0000000 ffaa ffff ffff ffff ffff ffff ffff ffff');
2367b5093b8SCédric Le Goater        self.do_test_arm_aspeed_buildroot_poweroff()
237bceb4d99SCédric Le Goater
238c3d58a7aSJoel Stanley    @skipUnless(*has_cmd('swtpm'))
239c3d58a7aSJoel Stanley    def test_arm_ast2600_evb_buildroot_tpm(self):
240c3d58a7aSJoel Stanley        """
241c3d58a7aSJoel Stanley        :avocado: tags=arch:arm
242c3d58a7aSJoel Stanley        :avocado: tags=machine:ast2600-evb
243c3d58a7aSJoel Stanley        """
244c3d58a7aSJoel Stanley
245c3d58a7aSJoel Stanley        image_url = ('https://github.com/legoater/qemu-aspeed-boot/raw/master/'
246c3d58a7aSJoel Stanley                     'images/ast2600-evb/buildroot-2023.02-tpm/flash.img')
247c3d58a7aSJoel Stanley        image_hash = ('a46009ae8a5403a0826d607215e731a8c68d27c14c41e55331706b8f9c7bd997')
248c3d58a7aSJoel Stanley        image_path = self.fetch_asset(image_url, asset_hash=image_hash,
249c3d58a7aSJoel Stanley                                      algorithm='sha256')
250c3d58a7aSJoel Stanley
25146d4747aSJohn Snow        # force creation of VM object, which also defines self._sd
25246d4747aSJohn Snow        vm = self.vm
25346d4747aSJohn Snow
25446d4747aSJohn Snow        socket = os.path.join(self._sd.name, 'swtpm-socket')
255c3d58a7aSJoel Stanley
256c3d58a7aSJoel Stanley        subprocess.run(['swtpm', 'socket', '-d', '--tpm2',
257c3d58a7aSJoel Stanley                        '--tpmstate', f'dir={self.vm.temp_dir}',
258c3d58a7aSJoel Stanley                        '--ctrl', f'type=unixio,path={socket}'])
259c3d58a7aSJoel Stanley
260c3d58a7aSJoel Stanley        self.vm.add_args('-chardev', f'socket,id=chrtpm,path={socket}')
261c3d58a7aSJoel Stanley        self.vm.add_args('-tpmdev', 'emulator,id=tpm0,chardev=chrtpm')
262c3d58a7aSJoel Stanley        self.vm.add_args('-device',
263c3d58a7aSJoel Stanley                         'tpm-tis-i2c,tpmdev=tpm0,bus=aspeed.i2c.bus.12,address=0x2e')
264c3d58a7aSJoel Stanley        self.do_test_arm_aspeed_buildroot_start(image_path, '0xf00', 'Aspeed AST2600 EVB')
265c3d58a7aSJoel Stanley
266c3d58a7aSJoel Stanley        exec_command_and_wait_for_pattern(self,
267c3d58a7aSJoel Stanley            'echo tpm_tis_i2c 0x2e > /sys/bus/i2c/devices/i2c-12/new_device',
268c3d58a7aSJoel Stanley            'tpm_tis_i2c 12-002e: 2.0 TPM (device-id 0x1, rev-id 1)');
269c3d58a7aSJoel Stanley        exec_command_and_wait_for_pattern(self,
270c3d58a7aSJoel Stanley            'cat /sys/class/tpm/tpm0/pcr-sha256/0',
271c3d58a7aSJoel Stanley            'B804724EA13F52A9072BA87FE8FDCC497DFC9DF9AA15B9088694639C431688E0');
272c3d58a7aSJoel Stanley
273c3d58a7aSJoel Stanley        self.do_test_arm_aspeed_buildroot_poweroff()
274bceb4d99SCédric Le Goater
275dd562bbfSThomas Huthclass AST2x00MachineSDK(QemuSystemTest, LinuxSSHMixIn):
27692f8e8e2SAlex Bennée
27730d7aac4SCédric Le Goater    EXTRA_BOOTARGS = (
27830d7aac4SCédric Le Goater        'quiet '
27930d7aac4SCédric Le Goater        'systemd.mask=org.openbmc.HostIpmi.service '
28030d7aac4SCédric Le Goater        'systemd.mask=xyz.openbmc_project.Chassis.Control.Power@0.service '
28130d7aac4SCédric Le Goater        'systemd.mask=modprobe@fuse.service '
28230d7aac4SCédric Le Goater        'systemd.mask=rngd.service '
28330d7aac4SCédric Le Goater        'systemd.mask=obmc-console@ttyS2.service '
28430d7aac4SCédric Le Goater    )
285a4b14b46SCédric Le Goater
28692f8e8e2SAlex Bennée    # FIXME: Although these tests boot a whole distro they are still
28792f8e8e2SAlex Bennée    # slower than comparable machine models. There may be some
28892f8e8e2SAlex Bennée    # optimisations which bring down the runtime. In the meantime they
28992f8e8e2SAlex Bennée    # have generous timeouts and are disable for CI which aims for all
29092f8e8e2SAlex Bennée    # tests to run in less than 60 seconds.
29192f8e8e2SAlex Bennée    timeout = 240
29292f8e8e2SAlex Bennée
29392f8e8e2SAlex Bennée    def wait_for_console_pattern(self, success_message, vm=None):
29492f8e8e2SAlex Bennée        wait_for_console_pattern(self, success_message,
29592f8e8e2SAlex Bennée                                 failure_message='Kernel panic - not syncing',
29692f8e8e2SAlex Bennée                                 vm=vm)
29792f8e8e2SAlex Bennée
298a4b14b46SCédric Le Goater    def do_test_arm_aspeed_sdk_start(self, image):
2990793fe01SPeter Maydell        self.require_netdev('user')
300bceb4d99SCédric Le Goater        self.vm.set_console()
301bceb4d99SCédric Le Goater        self.vm.add_args('-drive', 'file=' + image + ',if=mtd,format=raw',
302dd562bbfSThomas Huth                         '-net', 'nic', '-net', 'user,hostfwd=:127.0.0.1:0-:22')
303bceb4d99SCédric Le Goater        self.vm.launch()
304bceb4d99SCédric Le Goater
305bceb4d99SCédric Le Goater        self.wait_for_console_pattern('U-Boot 2019.04')
306a4b14b46SCédric Le Goater        interrupt_interactive_console_until_pattern(
307a4b14b46SCédric Le Goater            self, 'Hit any key to stop autoboot:', 'ast#')
308a4b14b46SCédric Le Goater        exec_command_and_wait_for_pattern(
309a4b14b46SCédric Le Goater            self, 'setenv bootargs ${bootargs} ' + self.EXTRA_BOOTARGS, 'ast#')
310a4b14b46SCédric Le Goater        exec_command_and_wait_for_pattern(
311a4b14b46SCédric Le Goater            self, 'boot', '## Loading kernel from FIT Image')
312bceb4d99SCédric Le Goater        self.wait_for_console_pattern('Starting kernel ...')
313bceb4d99SCédric Le Goater
3149b45cc99SAlex Bennée    @skipUnless(os.getenv('QEMU_TEST_FLAKY_TESTS'), 'Test is unstable on GitLab')
3159b45cc99SAlex Bennée
316bceb4d99SCédric Le Goater    def test_arm_ast2500_evb_sdk(self):
317bceb4d99SCédric Le Goater        """
318bceb4d99SCédric Le Goater        :avocado: tags=arch:arm
319bceb4d99SCédric Le Goater        :avocado: tags=machine:ast2500-evb
3205d25fcb7SAlex Bennée        :avocado: tags=flaky
321bceb4d99SCédric Le Goater        """
322bceb4d99SCédric Le Goater
323bceb4d99SCédric Le Goater        image_url = ('https://github.com/AspeedTech-BMC/openbmc/releases/'
3249bf9865cSCédric Le Goater                     'download/v08.06/ast2500-default-obmc.tar.gz')
3259bf9865cSCédric Le Goater        image_hash = ('e1755f3cadff69190438c688d52dd0f0d399b70a1e14b1d3d5540fc4851d38ca')
326bceb4d99SCédric Le Goater        image_path = self.fetch_asset(image_url, asset_hash=image_hash,
327bceb4d99SCédric Le Goater                                      algorithm='sha256')
328bceb4d99SCédric Le Goater        archive.extract(image_path, self.workdir)
329bceb4d99SCédric Le Goater
330bceb4d99SCédric Le Goater        self.do_test_arm_aspeed_sdk_start(
331a4b14b46SCédric Le Goater            self.workdir + '/ast2500-default/image-bmc')
332dd562bbfSThomas Huth        self.wait_for_console_pattern('nodistro.0 ast2500-default ttyS4')
333bceb4d99SCédric Le Goater
3349b45cc99SAlex Bennée    @skipUnless(os.getenv('QEMU_TEST_FLAKY_TESTS'), 'Test is unstable on GitLab')
3359b45cc99SAlex Bennée
336bceb4d99SCédric Le Goater    def test_arm_ast2600_evb_sdk(self):
337bceb4d99SCédric Le Goater        """
338bceb4d99SCédric Le Goater        :avocado: tags=arch:arm
339bceb4d99SCédric Le Goater        :avocado: tags=machine:ast2600-evb
3405d25fcb7SAlex Bennée        :avocado: tags=flaky
341bceb4d99SCédric Le Goater        """
342bceb4d99SCédric Le Goater
343bceb4d99SCédric Le Goater        image_url = ('https://github.com/AspeedTech-BMC/openbmc/releases/'
3449bf9865cSCédric Le Goater                     'download/v08.06/ast2600-a2-obmc.tar.gz')
3459bf9865cSCédric Le Goater        image_hash = ('9083506135f622d5e7351fcf7d4e1c7125cee5ba16141220c0ba88931f3681a4')
346bceb4d99SCédric Le Goater        image_path = self.fetch_asset(image_url, asset_hash=image_hash,
347bceb4d99SCédric Le Goater                                      algorithm='sha256')
348bceb4d99SCédric Le Goater        archive.extract(image_path, self.workdir)
349bceb4d99SCédric Le Goater
350bceb4d99SCédric Le Goater        self.vm.add_args('-device',
351bceb4d99SCédric Le Goater                         'tmp105,bus=aspeed.i2c.bus.5,address=0x4d,id=tmp-test');
352bceb4d99SCédric Le Goater        self.vm.add_args('-device',
353bceb4d99SCédric Le Goater                         'ds1338,bus=aspeed.i2c.bus.5,address=0x32');
354bceb4d99SCédric Le Goater        self.do_test_arm_aspeed_sdk_start(
3559bf9865cSCédric Le Goater            self.workdir + '/ast2600-a2/image-bmc')
3569bf9865cSCédric Le Goater        self.wait_for_console_pattern('nodistro.0 ast2600-a2 ttyS4')
357bceb4d99SCédric Le Goater
358dd562bbfSThomas Huth        self.ssh_connect('root', '0penBmc', False)
359dd562bbfSThomas Huth        self.ssh_command('dmesg -c > /dev/null')
360dd562bbfSThomas Huth
361dd562bbfSThomas Huth        self.ssh_command_output_contains(
362dd562bbfSThomas Huth             'echo lm75 0x4d > /sys/class/i2c-dev/i2c-5/device/new_device ; '
363dd562bbfSThomas Huth             'dmesg -c',
364bceb4d99SCédric Le Goater             'i2c i2c-5: new_device: Instantiated device lm75 at 0x4d');
365dd562bbfSThomas Huth        self.ssh_command_output_contains(
366bceb4d99SCédric Le Goater                             'cat /sys/class/hwmon/hwmon19/temp1_input', '0')
367684750abSVladimir Sementsov-Ogievskiy        self.vm.cmd('qom-set', path='/machine/peripheral/tmp-test',
368bceb4d99SCédric Le Goater                    property='temperature', value=18000);
369dd562bbfSThomas Huth        self.ssh_command_output_contains(
370bceb4d99SCédric Le Goater                             'cat /sys/class/hwmon/hwmon19/temp1_input', '18000')
371bceb4d99SCédric Le Goater
372dd562bbfSThomas Huth        self.ssh_command_output_contains(
373dd562bbfSThomas Huth             'echo ds1307 0x32 > /sys/class/i2c-dev/i2c-5/device/new_device ; '
374dd562bbfSThomas Huth             'dmesg -c',
375bceb4d99SCédric Le Goater             'i2c i2c-5: new_device: Instantiated device ds1307 at 0x32');
376bceb4d99SCédric Le Goater        year = time.strftime("%Y")
377dd562bbfSThomas Huth        self.ssh_command_output_contains('/sbin/hwclock -f /dev/rtc1', year);
378