xref: /openbmc/qemu/tests/functional/test_aarch64_sbsaref.py (revision 134b443512825bed401b6e141447b8cdc22d2efe)
18f16cd80SPhilippe Mathieu-Daudé#!/usr/bin/env python3
28f16cd80SPhilippe Mathieu-Daudé#
372b543e6SMarcin Juszkiewicz# Functional test that boots a kernel and checks the console
48f16cd80SPhilippe Mathieu-Daudé#
58f16cd80SPhilippe Mathieu-Daudé# SPDX-FileCopyrightText: 2023-2024 Linaro Ltd.
68f16cd80SPhilippe Mathieu-Daudé# SPDX-FileContributor: Philippe Mathieu-Daudé <philmd@linaro.org>
78f16cd80SPhilippe Mathieu-Daudé# SPDX-FileContributor: Marcin Juszkiewicz <marcin.juszkiewicz@linaro.org>
88f16cd80SPhilippe Mathieu-Daudé#
98f16cd80SPhilippe Mathieu-Daudé# SPDX-License-Identifier: GPL-2.0-or-later
108f16cd80SPhilippe Mathieu-Daudé
118f16cd80SPhilippe Mathieu-Daudéimport os
128f16cd80SPhilippe Mathieu-Daudé
138f16cd80SPhilippe Mathieu-Daudéfrom qemu_test import QemuSystemTest, Asset
148f16cd80SPhilippe Mathieu-Daudéfrom qemu_test import wait_for_console_pattern
158f16cd80SPhilippe Mathieu-Daudéfrom qemu_test import interrupt_interactive_console_until_pattern
168f16cd80SPhilippe Mathieu-Daudéfrom qemu_test.utils import lzma_uncompress
178f16cd80SPhilippe Mathieu-Daudéfrom unittest import skipUnless
188f16cd80SPhilippe Mathieu-Daudé
19*9acd3884SThomas Huthdef fetch_firmware(test):
20*9acd3884SThomas Huth    """
21*9acd3884SThomas Huth    Flash volumes generated using:
22*9acd3884SThomas Huth
23*9acd3884SThomas Huth    Toolchain from Debian:
24*9acd3884SThomas Huth    aarch64-linux-gnu-gcc (Debian 12.2.0-14) 12.2.0
25*9acd3884SThomas Huth
26*9acd3884SThomas Huth    Used components:
27*9acd3884SThomas Huth
28*9acd3884SThomas Huth    - Trusted Firmware         v2.11.0
29*9acd3884SThomas Huth    - Tianocore EDK2           4d4f569924
30*9acd3884SThomas Huth    - Tianocore EDK2-platforms 3f08401
31*9acd3884SThomas Huth
32*9acd3884SThomas Huth    """
33*9acd3884SThomas Huth
34*9acd3884SThomas Huth    # Secure BootRom (TF-A code)
35*9acd3884SThomas Huth    fs0_xz_path = Aarch64SbsarefMachine.ASSET_FLASH0.fetch()
36*9acd3884SThomas Huth    fs0_path = os.path.join(test.workdir, "SBSA_FLASH0.fd")
37*9acd3884SThomas Huth    lzma_uncompress(fs0_xz_path, fs0_path)
38*9acd3884SThomas Huth
39*9acd3884SThomas Huth    # Non-secure rom (UEFI and EFI variables)
40*9acd3884SThomas Huth    fs1_xz_path = Aarch64SbsarefMachine.ASSET_FLASH1.fetch()
41*9acd3884SThomas Huth    fs1_path = os.path.join(test.workdir, "SBSA_FLASH1.fd")
42*9acd3884SThomas Huth    lzma_uncompress(fs1_xz_path, fs1_path)
43*9acd3884SThomas Huth
44*9acd3884SThomas Huth    for path in [fs0_path, fs1_path]:
45*9acd3884SThomas Huth        with open(path, "ab+") as fd:
46*9acd3884SThomas Huth            fd.truncate(256 << 20)  # Expand volumes to 256MiB
47*9acd3884SThomas Huth
48*9acd3884SThomas Huth    test.set_machine('sbsa-ref')
49*9acd3884SThomas Huth    test.vm.set_console()
50*9acd3884SThomas Huth    test.vm.add_args(
51*9acd3884SThomas Huth        "-drive", f"if=pflash,file={fs0_path},format=raw",
52*9acd3884SThomas Huth        "-drive", f"if=pflash,file={fs1_path},format=raw",
53*9acd3884SThomas Huth    )
54*9acd3884SThomas Huth
558f16cd80SPhilippe Mathieu-Daudé
568f16cd80SPhilippe Mathieu-Daudéclass Aarch64SbsarefMachine(QemuSystemTest):
578f16cd80SPhilippe Mathieu-Daudé    """
588f16cd80SPhilippe Mathieu-Daudé    As firmware runs at a higher privilege level than the hypervisor we
598f16cd80SPhilippe Mathieu-Daudé    can only run these tests under TCG emulation.
608f16cd80SPhilippe Mathieu-Daudé    """
618f16cd80SPhilippe Mathieu-Daudé
628f16cd80SPhilippe Mathieu-Daudé    timeout = 180
638f16cd80SPhilippe Mathieu-Daudé
648f16cd80SPhilippe Mathieu-Daudé    ASSET_FLASH0 = Asset(
658f16cd80SPhilippe Mathieu-Daudé        ('https://artifacts.codelinaro.org/artifactory/linaro-419-sbsa-ref/'
668f16cd80SPhilippe Mathieu-Daudé         '20240619-148232/edk2/SBSA_FLASH0.fd.xz'),
678f16cd80SPhilippe Mathieu-Daudé        '0c954842a590988f526984de22e21ae0ab9cb351a0c99a8a58e928f0c7359cf7')
688f16cd80SPhilippe Mathieu-Daudé
698f16cd80SPhilippe Mathieu-Daudé    ASSET_FLASH1 = Asset(
708f16cd80SPhilippe Mathieu-Daudé        ('https://artifacts.codelinaro.org/artifactory/linaro-419-sbsa-ref/'
718f16cd80SPhilippe Mathieu-Daudé         '20240619-148232/edk2/SBSA_FLASH1.fd.xz'),
728f16cd80SPhilippe Mathieu-Daudé        'c6ec39374c4d79bb9e9cdeeb6db44732d90bb4a334cec92002b3f4b9cac4b5ee')
738f16cd80SPhilippe Mathieu-Daudé
748f16cd80SPhilippe Mathieu-Daudé    def test_sbsaref_edk2_firmware(self):
758f16cd80SPhilippe Mathieu-Daudé
76*9acd3884SThomas Huth        fetch_firmware(self)
778f16cd80SPhilippe Mathieu-Daudé
788f16cd80SPhilippe Mathieu-Daudé        self.vm.add_args('-cpu', 'cortex-a57')
798f16cd80SPhilippe Mathieu-Daudé        self.vm.launch()
808f16cd80SPhilippe Mathieu-Daudé
818f16cd80SPhilippe Mathieu-Daudé        # TF-A boot sequence:
828f16cd80SPhilippe Mathieu-Daudé        #
838f16cd80SPhilippe Mathieu-Daudé        # https://github.com/ARM-software/arm-trusted-firmware/blob/v2.8.0/\
848f16cd80SPhilippe Mathieu-Daudé        #     docs/design/trusted-board-boot.rst#trusted-board-boot-sequence
858f16cd80SPhilippe Mathieu-Daudé        # https://trustedfirmware-a.readthedocs.io/en/v2.8/\
868f16cd80SPhilippe Mathieu-Daudé        #     design/firmware-design.html#cold-boot
878f16cd80SPhilippe Mathieu-Daudé
888f16cd80SPhilippe Mathieu-Daudé        # AP Trusted ROM
898f16cd80SPhilippe Mathieu-Daudé        wait_for_console_pattern(self, "Booting Trusted Firmware")
908f16cd80SPhilippe Mathieu-Daudé        wait_for_console_pattern(self, "BL1: v2.11.0(release):")
918f16cd80SPhilippe Mathieu-Daudé        wait_for_console_pattern(self, "BL1: Booting BL2")
928f16cd80SPhilippe Mathieu-Daudé
938f16cd80SPhilippe Mathieu-Daudé        # Trusted Boot Firmware
948f16cd80SPhilippe Mathieu-Daudé        wait_for_console_pattern(self, "BL2: v2.11.0(release)")
958f16cd80SPhilippe Mathieu-Daudé        wait_for_console_pattern(self, "Booting BL31")
968f16cd80SPhilippe Mathieu-Daudé
978f16cd80SPhilippe Mathieu-Daudé        # EL3 Runtime Software
988f16cd80SPhilippe Mathieu-Daudé        wait_for_console_pattern(self, "BL31: v2.11.0(release)")
998f16cd80SPhilippe Mathieu-Daudé
1008f16cd80SPhilippe Mathieu-Daudé        # Non-trusted Firmware
1018f16cd80SPhilippe Mathieu-Daudé        wait_for_console_pattern(self, "UEFI firmware (version 1.0")
1028f16cd80SPhilippe Mathieu-Daudé        interrupt_interactive_console_until_pattern(self, "QEMU SBSA-REF Machine")
1038f16cd80SPhilippe Mathieu-Daudé
1048f16cd80SPhilippe Mathieu-Daudéif __name__ == '__main__':
1058f16cd80SPhilippe Mathieu-Daudé    QemuSystemTest.main()
106