xref: /qemu/tests/functional/test_aarch64_sbsaref.py (revision 453005c01a80bcd12cf6181badac717135b26ec3)
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
14
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.12.0
26    - Tianocore EDK2           edk2-stable202411
27    - Tianocore EDK2-platforms 4b3530d
28
29    """
30
31    # Secure BootRom (TF-A code)
32    fs0_path = test.uncompress(Aarch64SbsarefMachine.ASSET_FLASH0)
33
34    # Non-secure rom (UEFI and EFI variables)
35    fs1_path = test.uncompress(Aarch64SbsarefMachine.ASSET_FLASH1)
36
37    for path in [fs0_path, fs1_path]:
38        with open(path, "ab+") as fd:
39            fd.truncate(256 << 20)  # Expand volumes to 256MiB
40
41    test.set_machine('sbsa-ref')
42    test.vm.set_console()
43    test.vm.add_args(
44        "-drive", f"if=pflash,file={fs0_path},format=raw",
45        "-drive", f"if=pflash,file={fs1_path},format=raw",
46    )
47
48
49class Aarch64SbsarefMachine(QemuSystemTest):
50    """
51    As firmware runs at a higher privilege level than the hypervisor we
52    can only run these tests under TCG emulation.
53    """
54
55    timeout = 180
56
57    ASSET_FLASH0 = Asset(
58        ('https://artifacts.codelinaro.org/artifactory/linaro-419-sbsa-ref/'
59         '20241122-189881/edk2/SBSA_FLASH0.fd.xz'),
60        '76eb89d42eebe324e4395329f47447cda9ac920aabcf99aca85424609c3384a5')
61
62    ASSET_FLASH1 = Asset(
63        ('https://artifacts.codelinaro.org/artifactory/linaro-419-sbsa-ref/'
64         '20241122-189881/edk2/SBSA_FLASH1.fd.xz'),
65        'f850f243bd8dbd49c51e061e0f79f1697546938f454aeb59ab7d93e5f0d412fc')
66
67    def test_sbsaref_edk2_firmware(self):
68
69        fetch_firmware(self)
70
71        self.vm.add_args('-cpu', 'cortex-a57')
72        self.vm.launch()
73
74        # TF-A boot sequence:
75        #
76        # https://github.com/ARM-software/arm-trusted-firmware/blob/v2.8.0/\
77        #     docs/design/trusted-board-boot.rst#trusted-board-boot-sequence
78        # https://trustedfirmware-a.readthedocs.io/en/v2.8/\
79        #     design/firmware-design.html#cold-boot
80
81        # AP Trusted ROM
82        wait_for_console_pattern(self, "Booting Trusted Firmware")
83        wait_for_console_pattern(self, "BL1: v2.12.0(release):")
84        wait_for_console_pattern(self, "BL1: Booting BL2")
85
86        # Trusted Boot Firmware
87        wait_for_console_pattern(self, "BL2: v2.12.0(release)")
88        wait_for_console_pattern(self, "Booting BL31")
89
90        # EL3 Runtime Software
91        wait_for_console_pattern(self, "BL31: v2.12.0(release)")
92
93        # Non-trusted Firmware
94        wait_for_console_pattern(self, "UEFI firmware (version 1.0")
95        interrupt_interactive_console_until_pattern(self, "QEMU SBSA-REF Machine")
96
97if __name__ == '__main__':
98    QemuSystemTest.main()
99