xref: /qemu/tests/functional/test_aarch64_sbsaref.py (revision 7698afc42b5af9e55f12ab2236618e38e5a1c23f)
1#!/usr/bin/env python3
2#
3# Functional test that boots a kernel and checks the console
4#
5# Copyright (c) 2023-2024 Linaro Ltd.
6#
7# Authors:
8#   Philippe Mathieu-Daudé
9#   Marcin Juszkiewicz
10#
11# SPDX-License-Identifier: GPL-2.0-or-later
12
13from qemu_test import QemuSystemTest, Asset
14from qemu_test import wait_for_console_pattern
15from qemu_test import interrupt_interactive_console_until_pattern
16
17
18def fetch_firmware(test):
19    """
20    Flash volumes generated using:
21
22    Toolchain from Debian:
23    aarch64-linux-gnu-gcc (Debian 12.2.0-14) 12.2.0
24
25    Used components:
26
27    - Trusted Firmware         v2.12.0
28    - Tianocore EDK2           edk2-stable202411
29    - Tianocore EDK2-platforms 4b3530d
30
31    """
32
33    # Secure BootRom (TF-A code)
34    fs0_path = test.uncompress(Aarch64SbsarefMachine.ASSET_FLASH0)
35
36    # Non-secure rom (UEFI and EFI variables)
37    fs1_path = test.uncompress(Aarch64SbsarefMachine.ASSET_FLASH1)
38
39    for path in [fs0_path, fs1_path]:
40        with open(path, "ab+") as fd:
41            fd.truncate(256 << 20)  # Expand volumes to 256MiB
42
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        self.set_machine('sbsa-ref')
70
71        fetch_firmware(self)
72
73        self.vm.set_console()
74        self.vm.add_args('-cpu', 'cortex-a57')
75        self.vm.launch()
76
77        # TF-A boot sequence:
78        #
79        # https://github.com/ARM-software/arm-trusted-firmware/blob/v2.8.0/\
80        #     docs/design/trusted-board-boot.rst#trusted-board-boot-sequence
81        # https://trustedfirmware-a.readthedocs.io/en/v2.8/\
82        #     design/firmware-design.html#cold-boot
83
84        # AP Trusted ROM
85        wait_for_console_pattern(self, "Booting Trusted Firmware")
86        wait_for_console_pattern(self, "BL1: v2.12.0(release):")
87        wait_for_console_pattern(self, "BL1: Booting BL2")
88
89        # Trusted Boot Firmware
90        wait_for_console_pattern(self, "BL2: v2.12.0(release)")
91        wait_for_console_pattern(self, "Booting BL31")
92
93        # EL3 Runtime Software
94        wait_for_console_pattern(self, "BL31: v2.12.0(release)")
95
96        # Non-trusted Firmware
97        wait_for_console_pattern(self, "UEFI firmware (version 1.0")
98        interrupt_interactive_console_until_pattern(self, "QEMU SBSA-REF Machine")
99
100if __name__ == '__main__':
101    QemuSystemTest.main()
102