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
9f7bc7da0SCédric Le Goater
10438eff63SJamin Linfrom avocado_qemu import QemuSystemTest
11438eff63SJamin Linfrom avocado_qemu import wait_for_console_pattern
12f7bc7da0SCédric Le Goaterfrom avocado_qemu import exec_command
13438eff63SJamin Linfrom avocado_qemu import exec_command_and_wait_for_pattern
14438eff63SJamin Linfrom avocado.utils import archive
15438eff63SJamin Lin
16438eff63SJamin Lin
17438eff63SJamin Linclass AST1030Machine(QemuSystemTest):
18438eff63SJamin Lin    """Boots the zephyr os and checks that the console is operational"""
19438eff63SJamin Lin
20438eff63SJamin Lin    timeout = 10
21438eff63SJamin Lin
22438eff63SJamin Lin    def test_ast1030_zephyros(self):
23438eff63SJamin Lin        """
24438eff63SJamin Lin        :avocado: tags=arch:arm
25438eff63SJamin Lin        :avocado: tags=machine:ast1030-evb
26438eff63SJamin Lin        """
27438eff63SJamin Lin        tar_url = ('https://github.com/AspeedTech-BMC'
28438eff63SJamin Lin                   '/zephyr/releases/download/v00.01.04/ast1030-evb-demo.zip')
29438eff63SJamin Lin        tar_hash = '4c6a8ce3a8ba76ef1a65dae419ae3409343c4b20'
30438eff63SJamin Lin        tar_path = self.fetch_asset(tar_url, asset_hash=tar_hash)
31438eff63SJamin Lin        archive.extract(tar_path, self.workdir)
32438eff63SJamin Lin        kernel_file = self.workdir + "/ast1030-evb-demo/zephyr.elf"
33438eff63SJamin Lin        self.vm.set_console()
34438eff63SJamin Lin        self.vm.add_args('-kernel', kernel_file,
35438eff63SJamin Lin                         '-nographic')
36438eff63SJamin Lin        self.vm.launch()
37438eff63SJamin Lin        wait_for_console_pattern(self, "Booting Zephyr OS")
38438eff63SJamin Lin        exec_command_and_wait_for_pattern(self, "help",
39438eff63SJamin Lin                                          "Available commands")
40341e21faSCédric Le Goater
41341e21faSCédric Le Goaterclass AST2x00Machine(QemuSystemTest):
42341e21faSCédric Le Goater
43341e21faSCédric Le Goater    def wait_for_console_pattern(self, success_message, vm=None):
44341e21faSCédric Le Goater        wait_for_console_pattern(self, success_message,
45341e21faSCédric Le Goater                                 failure_message='Kernel panic - not syncing',
46341e21faSCédric Le Goater                                 vm=vm)
47341e21faSCédric Le Goater
48341e21faSCédric Le Goater    def do_test_arm_aspeed(self, image):
49341e21faSCédric Le Goater        self.vm.set_console()
50341e21faSCédric Le Goater        self.vm.add_args('-drive', 'file=' + image + ',if=mtd,format=raw',
51341e21faSCédric Le Goater                         '-net', 'nic')
52341e21faSCédric Le Goater        self.vm.launch()
53341e21faSCédric Le Goater
54341e21faSCédric Le Goater        self.wait_for_console_pattern("U-Boot 2016.07")
55341e21faSCédric Le Goater        self.wait_for_console_pattern("## Loading kernel from FIT Image at 20080000")
56341e21faSCédric Le Goater        self.wait_for_console_pattern("Starting kernel ...")
57341e21faSCédric Le Goater        self.wait_for_console_pattern("Booting Linux on physical CPU 0x0")
58341e21faSCédric Le Goater        wait_for_console_pattern(self,
59341e21faSCédric Le Goater                "aspeed-smc 1e620000.spi: read control register: 203b0641")
60341e21faSCédric Le Goater        self.wait_for_console_pattern("ftgmac100 1e660000.ethernet eth0: irq ")
61341e21faSCédric Le Goater        self.wait_for_console_pattern("systemd[1]: Set hostname to")
62341e21faSCédric Le Goater
63341e21faSCédric Le Goater    def test_arm_ast2400_palmetto_openbmc_v2_9_0(self):
64341e21faSCédric Le Goater        """
65341e21faSCédric Le Goater        :avocado: tags=arch:arm
66341e21faSCédric Le Goater        :avocado: tags=machine:palmetto-bmc
67341e21faSCédric Le Goater        """
68341e21faSCédric Le Goater
69341e21faSCédric Le Goater        image_url = ('https://github.com/openbmc/openbmc/releases/download/2.9.0/'
70341e21faSCédric Le Goater                     'obmc-phosphor-image-palmetto.static.mtd')
71341e21faSCédric Le Goater        image_hash = ('3e13bbbc28e424865dc42f35ad672b10f2e82cdb11846bb28fa625b48beafd0d')
72341e21faSCédric Le Goater        image_path = self.fetch_asset(image_url, asset_hash=image_hash,
73341e21faSCédric Le Goater                                      algorithm='sha256')
74341e21faSCédric Le Goater
75341e21faSCédric Le Goater        self.do_test_arm_aspeed(image_path)
76341e21faSCédric Le Goater
77341e21faSCédric Le Goater    def test_arm_ast2500_romulus_openbmc_v2_9_0(self):
78341e21faSCédric Le Goater        """
79341e21faSCédric Le Goater        :avocado: tags=arch:arm
80341e21faSCédric Le Goater        :avocado: tags=machine:romulus-bmc
81341e21faSCédric Le Goater        """
82341e21faSCédric Le Goater
83341e21faSCédric Le Goater        image_url = ('https://github.com/openbmc/openbmc/releases/download/2.9.0/'
84341e21faSCédric Le Goater                     'obmc-phosphor-image-romulus.static.mtd')
85341e21faSCédric Le Goater        image_hash = ('820341076803f1955bc31e647a512c79f9add4f5233d0697678bab4604c7bb25')
86341e21faSCédric Le Goater        image_path = self.fetch_asset(image_url, asset_hash=image_hash,
87341e21faSCédric Le Goater                                      algorithm='sha256')
88341e21faSCédric Le Goater
89341e21faSCédric Le Goater        self.do_test_arm_aspeed(image_path)
90f7bc7da0SCédric Le Goater
91f7bc7da0SCédric Le Goater    def do_test_arm_aspeed_buidroot_start(self, image, cpu_id):
92f7bc7da0SCédric Le Goater        self.vm.set_console()
93f7bc7da0SCédric Le Goater        self.vm.add_args('-drive', 'file=' + image + ',if=mtd,format=raw',
94f7bc7da0SCédric Le Goater                         '-net', 'nic', '-net', 'user')
95f7bc7da0SCédric Le Goater        self.vm.launch()
96f7bc7da0SCédric Le Goater
97f7bc7da0SCédric Le Goater        self.wait_for_console_pattern('U-Boot 2019.04')
98f7bc7da0SCédric Le Goater        self.wait_for_console_pattern('## Loading kernel from FIT Image')
99f7bc7da0SCédric Le Goater        self.wait_for_console_pattern('Starting kernel ...')
100f7bc7da0SCédric Le Goater        self.wait_for_console_pattern('Booting Linux on physical CPU ' + cpu_id)
101f7bc7da0SCédric Le Goater        self.wait_for_console_pattern('lease of 10.0.2.15')
102f7bc7da0SCédric Le Goater        self.wait_for_console_pattern('Aspeed EVB')
103f7bc7da0SCédric Le Goater        exec_command(self, 'root')
104f7bc7da0SCédric Le Goater        time.sleep(0.1)
105f7bc7da0SCédric Le Goater
106f7bc7da0SCédric Le Goater    def do_test_arm_aspeed_buidroot_poweroff(self):
107f7bc7da0SCédric Le Goater        exec_command_and_wait_for_pattern(self, 'poweroff',
108f7bc7da0SCédric Le Goater                                          'reboot: System halted');
109f7bc7da0SCédric Le Goater
110f7bc7da0SCédric Le Goater    def test_arm_ast2500_evb_builroot(self):
111f7bc7da0SCédric Le Goater        """
112f7bc7da0SCédric Le Goater        :avocado: tags=arch:arm
113f7bc7da0SCédric Le Goater        :avocado: tags=machine:ast2500-evb
114f7bc7da0SCédric Le Goater        """
115f7bc7da0SCédric Le Goater
116f7bc7da0SCédric Le Goater        image_url = ('https://github.com/legoater/qemu-aspeed-boot/raw/master/'
117f7bc7da0SCédric Le Goater                     'images/ast2500-evb/buildroot-2022.05/flash.img')
118f7bc7da0SCédric Le Goater        image_hash = ('549db6e9d8cdaf4367af21c36385a68bb465779c18b5e37094fc7343decccd3f')
119f7bc7da0SCédric Le Goater        image_path = self.fetch_asset(image_url, asset_hash=image_hash,
120f7bc7da0SCédric Le Goater                                      algorithm='sha256')
121f7bc7da0SCédric Le Goater
1227a7308eaSCédric Le Goater        self.vm.add_args('-device',
1237a7308eaSCédric Le Goater                         'tmp105,bus=aspeed.i2c.bus.3,address=0x4d,id=tmp-test');
124f7bc7da0SCédric Le Goater        self.do_test_arm_aspeed_buidroot_start(image_path, '0x0')
1257a7308eaSCédric Le Goater
1267a7308eaSCédric Le Goater        exec_command_and_wait_for_pattern(self,
1277a7308eaSCédric Le Goater             'echo lm75 0x4d > /sys/class/i2c-dev/i2c-3/device/new_device',
1287a7308eaSCédric Le Goater             'i2c i2c-3: new_device: Instantiated device lm75 at 0x4d');
1297a7308eaSCédric Le Goater        exec_command_and_wait_for_pattern(self,
1307a7308eaSCédric Le Goater                             'cat /sys/class/hwmon/hwmon1/temp1_input', '0')
1317a7308eaSCédric Le Goater        self.vm.command('qom-set', path='/machine/peripheral/tmp-test',
1327a7308eaSCédric Le Goater                        property='temperature', value=18000);
1337a7308eaSCédric Le Goater        exec_command_and_wait_for_pattern(self,
1347a7308eaSCédric Le Goater                             'cat /sys/class/hwmon/hwmon1/temp1_input', '18000')
1357a7308eaSCédric Le Goater
136f7bc7da0SCédric Le Goater        self.do_test_arm_aspeed_buidroot_poweroff()
137f7bc7da0SCédric Le Goater
138f7bc7da0SCédric Le Goater    def test_arm_ast2600_evb_builroot(self):
139f7bc7da0SCédric Le Goater        """
140f7bc7da0SCédric Le Goater        :avocado: tags=arch:arm
141f7bc7da0SCédric Le Goater        :avocado: tags=machine:ast2600-evb
142f7bc7da0SCédric Le Goater        """
143f7bc7da0SCédric Le Goater
144f7bc7da0SCédric Le Goater        image_url = ('https://github.com/legoater/qemu-aspeed-boot/raw/master/'
145f7bc7da0SCédric Le Goater                     'images/ast2600-evb/buildroot-2022.05/flash.img')
146f7bc7da0SCédric Le Goater        image_hash = ('6cc9e7d128fd4fa1fd01c883af67593cae8072c3239a0b8b6ace857f3538a92d')
147f7bc7da0SCédric Le Goater        image_path = self.fetch_asset(image_url, asset_hash=image_hash,
148f7bc7da0SCédric Le Goater                                      algorithm='sha256')
149f7bc7da0SCédric Le Goater
15061cf757dSCédric Le Goater        self.vm.add_args('-device',
15161cf757dSCédric Le Goater                         'tmp105,bus=aspeed.i2c.bus.3,address=0x4d,id=tmp-test');
1523302184fSCédric Le Goater        self.vm.add_args('-device',
1533302184fSCédric Le Goater                         'ds1338,bus=aspeed.i2c.bus.3,address=0x32');
154f7bc7da0SCédric Le Goater        self.do_test_arm_aspeed_buidroot_start(image_path, '0xf00')
15561cf757dSCédric Le Goater
15661cf757dSCédric Le Goater        exec_command_and_wait_for_pattern(self,
15761cf757dSCédric Le Goater             'echo lm75 0x4d > /sys/class/i2c-dev/i2c-3/device/new_device',
15861cf757dSCédric Le Goater             'i2c i2c-3: new_device: Instantiated device lm75 at 0x4d');
15961cf757dSCédric Le Goater        exec_command_and_wait_for_pattern(self,
16061cf757dSCédric Le Goater                             'cat /sys/class/hwmon/hwmon0/temp1_input', '0')
16161cf757dSCédric Le Goater        self.vm.command('qom-set', path='/machine/peripheral/tmp-test',
16261cf757dSCédric Le Goater                        property='temperature', value=18000);
16361cf757dSCédric Le Goater        exec_command_and_wait_for_pattern(self,
16461cf757dSCédric Le Goater                             'cat /sys/class/hwmon/hwmon0/temp1_input', '18000')
16561cf757dSCédric Le Goater
1663302184fSCédric Le Goater        exec_command_and_wait_for_pattern(self,
1673302184fSCédric Le Goater             'echo ds1307 0x32 > /sys/class/i2c-dev/i2c-3/device/new_device',
1683302184fSCédric Le Goater             'i2c i2c-3: new_device: Instantiated device ds1307 at 0x32');
1693302184fSCédric Le Goater        year = time.strftime("%Y")
1703302184fSCédric Le Goater        exec_command_and_wait_for_pattern(self, 'hwclock -f /dev/rtc1', year);
1713302184fSCédric Le Goater
172f7bc7da0SCédric Le Goater        self.do_test_arm_aspeed_buidroot_poweroff()
173*bceb4d99SCédric Le Goater
174*bceb4d99SCédric Le Goater
175*bceb4d99SCédric Le Goater    def do_test_arm_aspeed_sdk_start(self, image, cpu_id):
176*bceb4d99SCédric Le Goater        self.vm.set_console()
177*bceb4d99SCédric Le Goater        self.vm.add_args('-drive', 'file=' + image + ',if=mtd,format=raw',
178*bceb4d99SCédric Le Goater                         '-net', 'nic', '-net', 'user')
179*bceb4d99SCédric Le Goater        self.vm.launch()
180*bceb4d99SCédric Le Goater
181*bceb4d99SCédric Le Goater        self.wait_for_console_pattern('U-Boot 2019.04')
182*bceb4d99SCédric Le Goater        self.wait_for_console_pattern('## Loading kernel from FIT Image')
183*bceb4d99SCédric Le Goater        self.wait_for_console_pattern('Starting kernel ...')
184*bceb4d99SCédric Le Goater        self.wait_for_console_pattern('Booting Linux on physical CPU ' + cpu_id)
185*bceb4d99SCédric Le Goater
186*bceb4d99SCédric Le Goater    def test_arm_ast2500_evb_sdk(self):
187*bceb4d99SCédric Le Goater        """
188*bceb4d99SCédric Le Goater        :avocado: tags=arch:arm
189*bceb4d99SCédric Le Goater        :avocado: tags=machine:ast2500-evb
190*bceb4d99SCédric Le Goater        """
191*bceb4d99SCédric Le Goater
192*bceb4d99SCédric Le Goater        image_url = ('https://github.com/AspeedTech-BMC/openbmc/releases/'
193*bceb4d99SCédric Le Goater                     'download/v08.01/ast2500-default-obmc.tar.gz')
194*bceb4d99SCédric Le Goater        image_hash = ('5375f82b4c43a79427909342a1e18b4e48bd663e38466862145d27bb358796fd')
195*bceb4d99SCédric Le Goater        image_path = self.fetch_asset(image_url, asset_hash=image_hash,
196*bceb4d99SCédric Le Goater                                      algorithm='sha256')
197*bceb4d99SCédric Le Goater        archive.extract(image_path, self.workdir)
198*bceb4d99SCédric Le Goater
199*bceb4d99SCédric Le Goater        self.do_test_arm_aspeed_sdk_start(
200*bceb4d99SCédric Le Goater            self.workdir + '/ast2500-default/image-bmc', '0x0')
201*bceb4d99SCédric Le Goater        self.wait_for_console_pattern('ast2500-default login:')
202*bceb4d99SCédric Le Goater
203*bceb4d99SCédric Le Goater    def test_arm_ast2600_evb_sdk(self):
204*bceb4d99SCédric Le Goater        """
205*bceb4d99SCédric Le Goater        :avocado: tags=arch:arm
206*bceb4d99SCédric Le Goater        :avocado: tags=machine:ast2600-evb
207*bceb4d99SCédric Le Goater        """
208*bceb4d99SCédric Le Goater
209*bceb4d99SCédric Le Goater        image_url = ('https://github.com/AspeedTech-BMC/openbmc/releases/'
210*bceb4d99SCédric Le Goater                     'download/v08.01/ast2600-default-obmc.tar.gz')
211*bceb4d99SCédric Le Goater        image_hash = ('f12ef15e8c1f03a214df3b91c814515c5e2b2f56119021398c1dbdd626817d15')
212*bceb4d99SCédric Le Goater        image_path = self.fetch_asset(image_url, asset_hash=image_hash,
213*bceb4d99SCédric Le Goater                                      algorithm='sha256')
214*bceb4d99SCédric Le Goater        archive.extract(image_path, self.workdir)
215*bceb4d99SCédric Le Goater
216*bceb4d99SCédric Le Goater        self.vm.add_args('-device',
217*bceb4d99SCédric Le Goater                         'tmp105,bus=aspeed.i2c.bus.5,address=0x4d,id=tmp-test');
218*bceb4d99SCédric Le Goater        self.vm.add_args('-device',
219*bceb4d99SCédric Le Goater                         'ds1338,bus=aspeed.i2c.bus.5,address=0x32');
220*bceb4d99SCédric Le Goater        self.do_test_arm_aspeed_sdk_start(
221*bceb4d99SCédric Le Goater            self.workdir + '/ast2600-default/image-bmc', '0xf00')
222*bceb4d99SCédric Le Goater        self.wait_for_console_pattern('ast2600-default login:')
223*bceb4d99SCédric Le Goater        exec_command_and_wait_for_pattern(self, 'root', 'Password:')
224*bceb4d99SCédric Le Goater        exec_command_and_wait_for_pattern(self, '0penBmc', 'root@ast2600-default:~#')
225*bceb4d99SCédric Le Goater
226*bceb4d99SCédric Le Goater        exec_command_and_wait_for_pattern(self,
227*bceb4d99SCédric Le Goater             'echo lm75 0x4d > /sys/class/i2c-dev/i2c-5/device/new_device',
228*bceb4d99SCédric Le Goater             'i2c i2c-5: new_device: Instantiated device lm75 at 0x4d');
229*bceb4d99SCédric Le Goater        exec_command_and_wait_for_pattern(self,
230*bceb4d99SCédric Le Goater                             'cat /sys/class/hwmon/hwmon19/temp1_input', '0')
231*bceb4d99SCédric Le Goater        self.vm.command('qom-set', path='/machine/peripheral/tmp-test',
232*bceb4d99SCédric Le Goater                        property='temperature', value=18000);
233*bceb4d99SCédric Le Goater        exec_command_and_wait_for_pattern(self,
234*bceb4d99SCédric Le Goater                             'cat /sys/class/hwmon/hwmon19/temp1_input', '18000')
235*bceb4d99SCédric Le Goater
236*bceb4d99SCédric Le Goater        exec_command_and_wait_for_pattern(self,
237*bceb4d99SCédric Le Goater             'echo ds1307 0x32 > /sys/class/i2c-dev/i2c-5/device/new_device',
238*bceb4d99SCédric Le Goater             'i2c i2c-5: new_device: Instantiated device ds1307 at 0x32');
239*bceb4d99SCédric Le Goater        year = time.strftime("%Y")
240*bceb4d99SCédric Le Goater        exec_command_and_wait_for_pattern(self, 'hwclock -f /dev/rtc1', year);
241