xref: /openbmc/qemu/tests/functional/test_aarch64_sbsaref.py (revision beaf88c895a5eda649777757c80ab4171de777ff)
1#!/usr/bin/env python3
2#
3# Functional test that boots a kernel and checks the console
4#
5# SPDX-FileCopyrightText: 2023-2024 Linaro Ltd.
6# SPDX-FileContributor: Philippe Mathieu-Daudé <philmd@linaro.org>
7# SPDX-FileContributor: Marcin Juszkiewicz <marcin.juszkiewicz@linaro.org>
8#
9# SPDX-License-Identifier: GPL-2.0-or-later
10
11from qemu_test import QemuSystemTest, Asset
12from qemu_test import wait_for_console_pattern
13from qemu_test import interrupt_interactive_console_until_pattern
14from qemu_test.utils import lzma_uncompress
15
16def fetch_firmware(test):
17    """
18    Flash volumes generated using:
19
20    Toolchain from Debian:
21    aarch64-linux-gnu-gcc (Debian 12.2.0-14) 12.2.0
22
23    Used components:
24
25    - Trusted Firmware         v2.11.0
26    - Tianocore EDK2           4d4f569924
27    - Tianocore EDK2-platforms 3f08401
28
29    """
30
31    # Secure BootRom (TF-A code)
32    fs0_xz_path = Aarch64SbsarefMachine.ASSET_FLASH0.fetch()
33    fs0_path = test.scratch_file("SBSA_FLASH0.fd")
34    lzma_uncompress(fs0_xz_path, fs0_path)
35
36    # Non-secure rom (UEFI and EFI variables)
37    fs1_xz_path = Aarch64SbsarefMachine.ASSET_FLASH1.fetch()
38    fs1_path = test.scratch_file("SBSA_FLASH1.fd")
39    lzma_uncompress(fs1_xz_path, fs1_path)
40
41    for path in [fs0_path, fs1_path]:
42        with open(path, "ab+") as fd:
43            fd.truncate(256 << 20)  # Expand volumes to 256MiB
44
45    test.set_machine('sbsa-ref')
46    test.vm.set_console()
47    test.vm.add_args(
48        "-drive", f"if=pflash,file={fs0_path},format=raw",
49        "-drive", f"if=pflash,file={fs1_path},format=raw",
50    )
51
52
53class Aarch64SbsarefMachine(QemuSystemTest):
54    """
55    As firmware runs at a higher privilege level than the hypervisor we
56    can only run these tests under TCG emulation.
57    """
58
59    timeout = 180
60
61    ASSET_FLASH0 = Asset(
62        ('https://artifacts.codelinaro.org/artifactory/linaro-419-sbsa-ref/'
63         '20240619-148232/edk2/SBSA_FLASH0.fd.xz'),
64        '0c954842a590988f526984de22e21ae0ab9cb351a0c99a8a58e928f0c7359cf7')
65
66    ASSET_FLASH1 = Asset(
67        ('https://artifacts.codelinaro.org/artifactory/linaro-419-sbsa-ref/'
68         '20240619-148232/edk2/SBSA_FLASH1.fd.xz'),
69        'c6ec39374c4d79bb9e9cdeeb6db44732d90bb4a334cec92002b3f4b9cac4b5ee')
70
71    def test_sbsaref_edk2_firmware(self):
72
73        fetch_firmware(self)
74
75        self.vm.add_args('-cpu', 'cortex-a57')
76        self.vm.launch()
77
78        # TF-A boot sequence:
79        #
80        # https://github.com/ARM-software/arm-trusted-firmware/blob/v2.8.0/\
81        #     docs/design/trusted-board-boot.rst#trusted-board-boot-sequence
82        # https://trustedfirmware-a.readthedocs.io/en/v2.8/\
83        #     design/firmware-design.html#cold-boot
84
85        # AP Trusted ROM
86        wait_for_console_pattern(self, "Booting Trusted Firmware")
87        wait_for_console_pattern(self, "BL1: v2.11.0(release):")
88        wait_for_console_pattern(self, "BL1: Booting BL2")
89
90        # Trusted Boot Firmware
91        wait_for_console_pattern(self, "BL2: v2.11.0(release)")
92        wait_for_console_pattern(self, "Booting BL31")
93
94        # EL3 Runtime Software
95        wait_for_console_pattern(self, "BL31: v2.11.0(release)")
96
97        # Non-trusted Firmware
98        wait_for_console_pattern(self, "UEFI firmware (version 1.0")
99        interrupt_interactive_console_until_pattern(self, "QEMU SBSA-REF Machine")
100
101if __name__ == '__main__':
102    QemuSystemTest.main()
103