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 19*f7ae9612SCédric Le Goater ASSET_BR2_202411_AST2600_FLASH = Asset( 20c7bc9cabSCédric Le Goater ('https://github.com/legoater/qemu-aspeed-boot/raw/master/' 21*f7ae9612SCédric Le Goater 'images/ast2600-evb/buildroot-2024.11/flash.img'), 22*f7ae9612SCé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 27*f7ae9612SCé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', 30c7bc9cabSCédric Le Goater 'tmp105,bus=aspeed.i2c.bus.3,address=0x4d,id=tmp-test'); 31c7bc9cabSCédric Le Goater self.vm.add_args('-device', 32c7bc9cabSCédric Le Goater 'ds1338,bus=aspeed.i2c.bus.3,address=0x32'); 33c7bc9cabSCédric Le Goater self.vm.add_args('-device', 34c7bc9cabSCédric Le Goater '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', 40c7bc9cabSCédric Le Goater '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', 44c7bc9cabSCédric Le Goater 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', 50c7bc9cabSCédric Le Goater 'i2c i2c-3: new_device: Instantiated device ds1307 at 0x32'); 51c7bc9cabSCédric Le Goater year = time.strftime("%Y") 52c7bc9cabSCédric Le Goater 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', 56c7bc9cabSCédric Le Goater 'i2c i2c-3: new_device: Instantiated device slave-24c02 at 0x64'); 57c7bc9cabSCédric Le Goater exec_command_and_wait_for_pattern(self, 58c7bc9cabSCédric Le Goater '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', 61c7bc9cabSCédric Le Goater '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', 93c7bc9cabSCédric Le Goater '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', 96c7bc9cabSCédric Le Goater 'B804724EA13F52A9072BA87FE8FDCC497DFC9DF9AA15B9088694639C431688E0'); 97c7bc9cabSCédric Le Goater 98c7bc9cabSCédric Le Goater self.do_test_arm_aspeed_buildroot_poweroff() 99c7bc9cabSCédric Le Goater 100c7bc9cabSCédric Le Goater ASSET_SDK_V806_AST2600_A2 = Asset( 101c7bc9cabSCédric Le Goater 'https://github.com/AspeedTech-BMC/openbmc/releases/download/v08.06/ast2600-a2-obmc.tar.gz', 102c7bc9cabSCédric Le Goater '9083506135f622d5e7351fcf7d4e1c7125cee5ba16141220c0ba88931f3681a4') 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 1075831ed84SDaniel P. Berrangé self.archive_extract(self.ASSET_SDK_V806_AST2600_A2) 108c7bc9cabSCédric Le Goater 109c7bc9cabSCédric Le Goater self.vm.add_args('-device', 110c7bc9cabSCédric Le Goater 'tmp105,bus=aspeed.i2c.bus.5,address=0x4d,id=tmp-test'); 111c7bc9cabSCédric Le Goater self.vm.add_args('-device', 112c7bc9cabSCédric Le Goater 'ds1338,bus=aspeed.i2c.bus.5,address=0x32'); 113c7bc9cabSCédric Le Goater self.do_test_arm_aspeed_sdk_start( 114beaf88c8SDaniel P. Berrangé self.scratch_file("ast2600-a2", "image-bmc")) 115c7bc9cabSCédric Le Goater 116c7bc9cabSCédric Le Goater self.wait_for_console_pattern('ast2600-a2 login:') 117c7bc9cabSCédric Le Goater 118c7bc9cabSCédric Le Goater exec_command_and_wait_for_pattern(self, 'root', 'Password:') 119c7bc9cabSCédric Le Goater exec_command_and_wait_for_pattern(self, '0penBmc', 'root@ast2600-a2:~#') 120c7bc9cabSCédric Le Goater 121c7bc9cabSCédric Le Goater exec_command_and_wait_for_pattern(self, 122c7bc9cabSCédric Le Goater 'echo lm75 0x4d > /sys/class/i2c-dev/i2c-5/device/new_device', 123c7bc9cabSCédric Le Goater 'i2c i2c-5: new_device: Instantiated device lm75 at 0x4d'); 124c7bc9cabSCédric Le Goater exec_command_and_wait_for_pattern(self, 125c7bc9cabSCédric Le Goater 'cat /sys/class/hwmon/hwmon19/temp1_input', '0') 126c7bc9cabSCédric Le Goater self.vm.cmd('qom-set', path='/machine/peripheral/tmp-test', 127c7bc9cabSCédric Le Goater property='temperature', value=18000); 128c7bc9cabSCédric Le Goater exec_command_and_wait_for_pattern(self, 129c7bc9cabSCédric Le Goater 'cat /sys/class/hwmon/hwmon19/temp1_input', '18000') 130c7bc9cabSCédric Le Goater 131c7bc9cabSCédric Le Goater exec_command_and_wait_for_pattern(self, 132c7bc9cabSCédric Le Goater 'echo ds1307 0x32 > /sys/class/i2c-dev/i2c-5/device/new_device', 133c7bc9cabSCédric Le Goater 'i2c i2c-5: new_device: Instantiated device ds1307 at 0x32'); 134c7bc9cabSCédric Le Goater year = time.strftime("%Y") 135c7bc9cabSCédric Le Goater exec_command_and_wait_for_pattern(self, 136c7bc9cabSCédric Le Goater '/sbin/hwclock -f /dev/rtc1', year); 137c7bc9cabSCédric Le Goater 138c7bc9cabSCédric Le Goaterif __name__ == '__main__': 139c7bc9cabSCédric Le Goater AspeedTest.main() 140