1c7bc9cabSCédric Le Goater#!/usr/bin/env python3 2c7bc9cabSCédric Le Goater# 3c7bc9cabSCédric Le Goater# Functional test that boots the ASPEED machines 4c7bc9cabSCédric Le Goater# 5c7bc9cabSCédric Le Goater# SPDX-License-Identifier: GPL-2.0-or-later 6c7bc9cabSCédric Le Goater 7c7bc9cabSCédric Le Goaterimport os 8c7bc9cabSCédric Le Goaterimport time 9c7bc9cabSCédric Le Goaterimport tempfile 10c7bc9cabSCédric Le Goaterimport subprocess 11c7bc9cabSCédric Le Goater 12c7bc9cabSCédric Le Goaterfrom qemu_test import Asset 13c7bc9cabSCédric Le Goaterfrom aspeed import AspeedTest 143d593860SDaniel P. Berrangéfrom qemu_test import exec_command_and_wait_for_pattern, skipIfMissingCommands 153d593860SDaniel P. Berrangé 16c7bc9cabSCédric Le Goater 17c7bc9cabSCédric Le Goaterclass AST2600Machine(AspeedTest): 18c7bc9cabSCédric Le Goater 19f7ae9612SCédric Le Goater ASSET_BR2_202411_AST2600_FLASH = Asset( 20c7bc9cabSCédric Le Goater ('https://github.com/legoater/qemu-aspeed-boot/raw/master/' 21f7ae9612SCédric Le Goater 'images/ast2600-evb/buildroot-2024.11/flash.img'), 22f7ae9612SCédric Le Goater '4bb2f3dfdea31199b51d66b42f686dc5374c144a7346fdc650194a5578b73609') 23c7bc9cabSCédric Le Goater 24c7bc9cabSCédric Le Goater def test_arm_ast2600_evb_buildroot(self): 25c7bc9cabSCédric Le Goater self.set_machine('ast2600-evb') 26c7bc9cabSCédric Le Goater 27f7ae9612SCédric Le Goater image_path = self.ASSET_BR2_202411_AST2600_FLASH.fetch() 28c7bc9cabSCédric Le Goater 29c7bc9cabSCédric Le Goater self.vm.add_args('-device', 30858640eaSThomas Huth 'tmp105,bus=aspeed.i2c.bus.3,address=0x4d,id=tmp-test') 31c7bc9cabSCédric Le Goater self.vm.add_args('-device', 32858640eaSThomas Huth 'ds1338,bus=aspeed.i2c.bus.3,address=0x32') 33c7bc9cabSCédric Le Goater self.vm.add_args('-device', 34858640eaSThomas Huth 'i2c-echo,bus=aspeed.i2c.bus.3,address=0x42') 35c7bc9cabSCédric Le Goater self.do_test_arm_aspeed_buildroot_start(image_path, '0xf00', 36c7bc9cabSCédric Le Goater 'ast2600-evb login:') 37c7bc9cabSCédric Le Goater 38c7bc9cabSCédric Le Goater exec_command_and_wait_for_pattern(self, 39c7bc9cabSCédric Le Goater 'echo lm75 0x4d > /sys/class/i2c-dev/i2c-3/device/new_device', 40858640eaSThomas Huth 'i2c i2c-3: new_device: Instantiated device lm75 at 0x4d') 41c7bc9cabSCédric Le Goater exec_command_and_wait_for_pattern(self, 42c7bc9cabSCédric Le Goater 'cat /sys/class/hwmon/hwmon1/temp1_input', '0') 43c7bc9cabSCédric Le Goater self.vm.cmd('qom-set', path='/machine/peripheral/tmp-test', 44858640eaSThomas Huth property='temperature', value=18000) 45c7bc9cabSCédric Le Goater exec_command_and_wait_for_pattern(self, 46c7bc9cabSCédric Le Goater 'cat /sys/class/hwmon/hwmon1/temp1_input', '18000') 47c7bc9cabSCédric Le Goater 48c7bc9cabSCédric Le Goater exec_command_and_wait_for_pattern(self, 49c7bc9cabSCédric Le Goater 'echo ds1307 0x32 > /sys/class/i2c-dev/i2c-3/device/new_device', 50858640eaSThomas Huth 'i2c i2c-3: new_device: Instantiated device ds1307 at 0x32') 51c7bc9cabSCédric Le Goater year = time.strftime("%Y") 52858640eaSThomas Huth exec_command_and_wait_for_pattern(self, 'hwclock -f /dev/rtc1', year) 53c7bc9cabSCédric Le Goater 54c7bc9cabSCédric Le Goater exec_command_and_wait_for_pattern(self, 55c7bc9cabSCédric Le Goater 'echo slave-24c02 0x1064 > /sys/bus/i2c/devices/i2c-3/new_device', 56858640eaSThomas Huth 'i2c i2c-3: new_device: Instantiated device slave-24c02 at 0x64') 57c7bc9cabSCédric Le Goater exec_command_and_wait_for_pattern(self, 58858640eaSThomas Huth 'i2cset -y 3 0x42 0x64 0x00 0xaa i', '#') 59c7bc9cabSCédric Le Goater exec_command_and_wait_for_pattern(self, 60c7bc9cabSCédric Le Goater 'hexdump /sys/bus/i2c/devices/3-1064/slave-eeprom', 61858640eaSThomas Huth '0000000 ffaa ffff ffff ffff ffff ffff ffff ffff') 62c7bc9cabSCédric Le Goater self.do_test_arm_aspeed_buildroot_poweroff() 63c7bc9cabSCédric Le Goater 64c7bc9cabSCédric Le Goater ASSET_BR2_202302_AST2600_TPM_FLASH = Asset( 65c7bc9cabSCédric Le Goater ('https://github.com/legoater/qemu-aspeed-boot/raw/master/' 66c7bc9cabSCédric Le Goater 'images/ast2600-evb/buildroot-2023.02-tpm/flash.img'), 67c7bc9cabSCédric Le Goater 'a46009ae8a5403a0826d607215e731a8c68d27c14c41e55331706b8f9c7bd997') 68c7bc9cabSCédric Le Goater 693d593860SDaniel P. Berrangé @skipIfMissingCommands('swtpm') 70c7bc9cabSCédric Le Goater def test_arm_ast2600_evb_buildroot_tpm(self): 71c7bc9cabSCédric Le Goater self.set_machine('ast2600-evb') 72c7bc9cabSCédric Le Goater 73c7bc9cabSCédric Le Goater image_path = self.ASSET_BR2_202302_AST2600_TPM_FLASH.fetch() 74c7bc9cabSCédric Le Goater 75c7bc9cabSCédric Le Goater tpmstate_dir = tempfile.TemporaryDirectory(prefix="qemu_") 76c7bc9cabSCédric Le Goater socket = os.path.join(tpmstate_dir.name, 'swtpm-socket') 77c7bc9cabSCédric Le Goater 78c7bc9cabSCédric Le Goater # We must put the TPM state dir in /tmp/, not the build dir, 79c7bc9cabSCédric Le Goater # because some distros use AppArmor to lock down swtpm and 80c7bc9cabSCédric Le Goater # restrict the set of locations it can access files in. 81c7bc9cabSCédric Le Goater subprocess.run(['swtpm', 'socket', '-d', '--tpm2', 82c7bc9cabSCédric Le Goater '--tpmstate', f'dir={tpmstate_dir.name}', 83c7bc9cabSCédric Le Goater '--ctrl', f'type=unixio,path={socket}']) 84c7bc9cabSCédric Le Goater 85c7bc9cabSCédric Le Goater self.vm.add_args('-chardev', f'socket,id=chrtpm,path={socket}') 86c7bc9cabSCédric Le Goater self.vm.add_args('-tpmdev', 'emulator,id=tpm0,chardev=chrtpm') 87c7bc9cabSCédric Le Goater self.vm.add_args('-device', 88c7bc9cabSCédric Le Goater 'tpm-tis-i2c,tpmdev=tpm0,bus=aspeed.i2c.bus.12,address=0x2e') 89c7bc9cabSCédric Le Goater self.do_test_arm_aspeed_buildroot_start(image_path, '0xf00', 'Aspeed AST2600 EVB') 90c7bc9cabSCédric Le Goater 91c7bc9cabSCédric Le Goater exec_command_and_wait_for_pattern(self, 92c7bc9cabSCédric Le Goater 'echo tpm_tis_i2c 0x2e > /sys/bus/i2c/devices/i2c-12/new_device', 93858640eaSThomas Huth 'tpm_tis_i2c 12-002e: 2.0 TPM (device-id 0x1, rev-id 1)') 94c7bc9cabSCédric Le Goater exec_command_and_wait_for_pattern(self, 95c7bc9cabSCédric Le Goater 'cat /sys/class/tpm/tpm0/pcr-sha256/0', 96858640eaSThomas Huth 'B804724EA13F52A9072BA87FE8FDCC497DFC9DF9AA15B9088694639C431688E0') 97c7bc9cabSCédric Le Goater 98c7bc9cabSCédric Le Goater self.do_test_arm_aspeed_buildroot_poweroff() 99c7bc9cabSCédric Le Goater 100*88bff6d5SJamin Lin ASSET_SDK_V906_AST2600 = Asset( 101*88bff6d5SJamin Lin 'https://github.com/AspeedTech-BMC/openbmc/releases/download/v09.06/ast2600-default-obmc.tar.gz', 102*88bff6d5SJamin Lin '768d76e247896ad78c154b9cff4f766da2ce65f217d620b286a4a03a8a4f68f5') 103c7bc9cabSCédric Le Goater 104c7bc9cabSCédric Le Goater def test_arm_ast2600_evb_sdk(self): 105c7bc9cabSCédric Le Goater self.set_machine('ast2600-evb') 106c7bc9cabSCédric Le Goater 107*88bff6d5SJamin Lin self.archive_extract(self.ASSET_SDK_V906_AST2600) 108c7bc9cabSCédric Le Goater 109c7bc9cabSCédric Le Goater self.vm.add_args('-device', 110858640eaSThomas Huth 'tmp105,bus=aspeed.i2c.bus.5,address=0x4d,id=tmp-test') 111c7bc9cabSCédric Le Goater self.vm.add_args('-device', 112858640eaSThomas Huth 'ds1338,bus=aspeed.i2c.bus.5,address=0x32') 113c7bc9cabSCédric Le Goater self.do_test_arm_aspeed_sdk_start( 114*88bff6d5SJamin Lin self.scratch_file("ast2600-default", "image-bmc")) 115c7bc9cabSCédric Le Goater 116*88bff6d5SJamin Lin self.wait_for_console_pattern('ast2600-default login:') 117c7bc9cabSCédric Le Goater 118c7bc9cabSCédric Le Goater exec_command_and_wait_for_pattern(self, 'root', 'Password:') 119*88bff6d5SJamin Lin exec_command_and_wait_for_pattern(self, '0penBmc', 120*88bff6d5SJamin Lin 'root@ast2600-default:~#') 121c7bc9cabSCédric Le Goater 122c7bc9cabSCédric Le Goater exec_command_and_wait_for_pattern(self, 123c7bc9cabSCédric Le Goater 'echo lm75 0x4d > /sys/class/i2c-dev/i2c-5/device/new_device', 124858640eaSThomas Huth 'i2c i2c-5: new_device: Instantiated device lm75 at 0x4d') 125c7bc9cabSCédric Le Goater exec_command_and_wait_for_pattern(self, 126c7bc9cabSCédric Le Goater 'cat /sys/class/hwmon/hwmon19/temp1_input', '0') 127c7bc9cabSCédric Le Goater self.vm.cmd('qom-set', path='/machine/peripheral/tmp-test', 128858640eaSThomas Huth property='temperature', value=18000) 129c7bc9cabSCédric Le Goater exec_command_and_wait_for_pattern(self, 130c7bc9cabSCédric Le Goater 'cat /sys/class/hwmon/hwmon19/temp1_input', '18000') 131c7bc9cabSCédric Le Goater 132c7bc9cabSCédric Le Goater exec_command_and_wait_for_pattern(self, 133c7bc9cabSCédric Le Goater 'echo ds1307 0x32 > /sys/class/i2c-dev/i2c-5/device/new_device', 134858640eaSThomas Huth 'i2c i2c-5: new_device: Instantiated device ds1307 at 0x32') 135c7bc9cabSCédric Le Goater year = time.strftime("%Y") 136c7bc9cabSCédric Le Goater exec_command_and_wait_for_pattern(self, 137858640eaSThomas Huth '/sbin/hwclock -f /dev/rtc1', year) 138c7bc9cabSCédric Le Goater 139c7bc9cabSCédric Le Goaterif __name__ == '__main__': 140c7bc9cabSCédric Le Goater AspeedTest.main() 141