| 1 | #!/usr/bin/env python3 |
| 2 | # |
| 3 | # Functional test that boots the ASPEED machines |
| 4 | # |
| 5 | # SPDX-License-Identifier: GPL-2.0-or-later |
| 6 | |
| 7 | import os |
| 8 | import time |
| 9 | import tempfile |
| 10 | import subprocess |
| 11 | |
| 12 | from aspeed import AspeedTest |
| 13 | from qemu_test import Asset |
| 14 | from qemu_test import exec_command_and_wait_for_pattern, skipIfMissingCommands |
| 15 | |
| 16 | |
| 17 | class AST2600Machine(AspeedTest): |
| 18 | |
| 19 | ASSET_BR2_202302_AST2600_TPM_FLASH = Asset( |
| 20 | ('https://github.com/legoater/qemu-aspeed-boot/raw/master/' |
| 21 | 'images/ast2600-evb/buildroot-2023.02-tpm/flash.img'), |
| 22 | 'a46009ae8a5403a0826d607215e731a8c68d27c14c41e55331706b8f9c7bd997') |
| 23 | |
| 24 | def _test_arm_ast2600_evb_buildroot_tpm(self, tpmstate_dir): |
| 25 | image_path = self.ASSET_BR2_202302_AST2600_TPM_FLASH.fetch() |
| 26 | |
| 27 | socket = os.path.join(tpmstate_dir, 'swtpm-socket') |
| 28 | |
| 29 | # We must put the TPM state dir in /tmp/, not the build dir, |
| 30 | # because some distros use AppArmor to lock down swtpm and |
| 31 | # restrict the set of locations it can access files in. |
| 32 | subprocess.run(['swtpm', 'socket', '-d', '--tpm2', |
| 33 | '--tpmstate', f'dir={tpmstate_dir}', |
| 34 | '--ctrl', f'type=unixio,path={socket}'], |
| 35 | check=True) |
| 36 | |
| 37 | self.vm.add_args('-chardev', f'socket,id=chrtpm,path={socket}') |
| 38 | self.vm.add_args('-tpmdev', 'emulator,id=tpm0,chardev=chrtpm') |
| 39 | self.vm.add_args('-device', |
| 40 | 'tpm-tis-i2c,tpmdev=tpm0,bus=aspeed.i2c.bus.12,address=0x2e') |
| 41 | self.do_test_arm_aspeed_buildroot_start(image_path, '0xf00', 'Aspeed AST2600 EVB') |
| 42 | |
| 43 | exec_command_and_wait_for_pattern(self, |
| 44 | 'echo tpm_tis_i2c 0x2e > /sys/bus/i2c/devices/i2c-12/new_device', |
| 45 | 'tpm_tis_i2c 12-002e: 2.0 TPM (device-id 0x1, rev-id 1)') |
| 46 | exec_command_and_wait_for_pattern(self, |
| 47 | 'cat /sys/class/tpm/tpm0/pcr-sha256/0', |
| 48 | 'B804724EA13F52A9072BA87FE8FDCC497DFC9DF9AA15B9088694639C431688E0') |
| 49 | |
| 50 | self.do_test_arm_aspeed_buildroot_poweroff() |
| 51 | |
| 52 | @skipIfMissingCommands('swtpm') |
| 53 | def test_arm_ast2600_evb_buildroot_tpm(self): |
| 54 | self.set_machine('ast2600-evb') |
| 55 | with tempfile.TemporaryDirectory(prefix="qemu_") as tpmstate_dir: |
| 56 | self._test_arm_ast2600_evb_buildroot_tpm(tpmstate_dir) |
| 57 | |
| 58 | |
| 59 | if __name__ == '__main__': |
| 60 | AspeedTest.main() |