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é# 5*d6f76422SPhilippe Mathieu-Daudé# Copyright (c) 2023-2024 Linaro Ltd. 6*d6f76422SPhilippe Mathieu-Daudé# 7*d6f76422SPhilippe Mathieu-Daudé# Authors: 8*d6f76422SPhilippe Mathieu-Daudé# Philippe Mathieu-Daudé 9*d6f76422SPhilippe Mathieu-Daudé# Marcin Juszkiewicz 108f16cd80SPhilippe Mathieu-Daudé# 118f16cd80SPhilippe Mathieu-Daudé# SPDX-License-Identifier: GPL-2.0-or-later 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 1665d35a4eSDaniel P. Berrangé 178f16cd80SPhilippe Mathieu-Daudé 189acd3884SThomas Huthdef fetch_firmware(test): 199acd3884SThomas Huth """ 209acd3884SThomas Huth Flash volumes generated using: 219acd3884SThomas Huth 229acd3884SThomas Huth Toolchain from Debian: 239acd3884SThomas Huth aarch64-linux-gnu-gcc (Debian 12.2.0-14) 12.2.0 249acd3884SThomas Huth 259acd3884SThomas Huth Used components: 269acd3884SThomas Huth 27e9125425SMarcin Juszkiewicz - Trusted Firmware v2.12.0 28e9125425SMarcin Juszkiewicz - Tianocore EDK2 edk2-stable202411 29e9125425SMarcin Juszkiewicz - Tianocore EDK2-platforms 4b3530d 309acd3884SThomas Huth 319acd3884SThomas Huth """ 329acd3884SThomas Huth 339acd3884SThomas Huth # Secure BootRom (TF-A code) 3465d35a4eSDaniel P. Berrangé fs0_path = test.uncompress(Aarch64SbsarefMachine.ASSET_FLASH0) 359acd3884SThomas Huth 369acd3884SThomas Huth # Non-secure rom (UEFI and EFI variables) 3765d35a4eSDaniel P. Berrangé fs1_path = test.uncompress(Aarch64SbsarefMachine.ASSET_FLASH1) 389acd3884SThomas Huth 399acd3884SThomas Huth for path in [fs0_path, fs1_path]: 409acd3884SThomas Huth with open(path, "ab+") as fd: 419acd3884SThomas Huth fd.truncate(256 << 20) # Expand volumes to 256MiB 429acd3884SThomas Huth 439acd3884SThomas Huth test.set_machine('sbsa-ref') 449acd3884SThomas Huth test.vm.set_console() 459acd3884SThomas Huth test.vm.add_args( 469acd3884SThomas Huth "-drive", f"if=pflash,file={fs0_path},format=raw", 479acd3884SThomas Huth "-drive", f"if=pflash,file={fs1_path},format=raw", 489acd3884SThomas Huth ) 499acd3884SThomas Huth 508f16cd80SPhilippe Mathieu-Daudé 518f16cd80SPhilippe Mathieu-Daudéclass Aarch64SbsarefMachine(QemuSystemTest): 528f16cd80SPhilippe Mathieu-Daudé """ 538f16cd80SPhilippe Mathieu-Daudé As firmware runs at a higher privilege level than the hypervisor we 548f16cd80SPhilippe Mathieu-Daudé can only run these tests under TCG emulation. 558f16cd80SPhilippe Mathieu-Daudé """ 568f16cd80SPhilippe Mathieu-Daudé 578f16cd80SPhilippe Mathieu-Daudé timeout = 180 588f16cd80SPhilippe Mathieu-Daudé 598f16cd80SPhilippe Mathieu-Daudé ASSET_FLASH0 = Asset( 608f16cd80SPhilippe Mathieu-Daudé ('https://artifacts.codelinaro.org/artifactory/linaro-419-sbsa-ref/' 61e9125425SMarcin Juszkiewicz '20241122-189881/edk2/SBSA_FLASH0.fd.xz'), 62e9125425SMarcin Juszkiewicz '76eb89d42eebe324e4395329f47447cda9ac920aabcf99aca85424609c3384a5') 638f16cd80SPhilippe Mathieu-Daudé 648f16cd80SPhilippe Mathieu-Daudé ASSET_FLASH1 = Asset( 658f16cd80SPhilippe Mathieu-Daudé ('https://artifacts.codelinaro.org/artifactory/linaro-419-sbsa-ref/' 66e9125425SMarcin Juszkiewicz '20241122-189881/edk2/SBSA_FLASH1.fd.xz'), 67e9125425SMarcin Juszkiewicz 'f850f243bd8dbd49c51e061e0f79f1697546938f454aeb59ab7d93e5f0d412fc') 688f16cd80SPhilippe Mathieu-Daudé 698f16cd80SPhilippe Mathieu-Daudé def test_sbsaref_edk2_firmware(self): 708f16cd80SPhilippe Mathieu-Daudé 719acd3884SThomas Huth fetch_firmware(self) 728f16cd80SPhilippe Mathieu-Daudé 738f16cd80SPhilippe Mathieu-Daudé self.vm.add_args('-cpu', 'cortex-a57') 748f16cd80SPhilippe Mathieu-Daudé self.vm.launch() 758f16cd80SPhilippe Mathieu-Daudé 768f16cd80SPhilippe Mathieu-Daudé # TF-A boot sequence: 778f16cd80SPhilippe Mathieu-Daudé # 788f16cd80SPhilippe Mathieu-Daudé # https://github.com/ARM-software/arm-trusted-firmware/blob/v2.8.0/\ 798f16cd80SPhilippe Mathieu-Daudé # docs/design/trusted-board-boot.rst#trusted-board-boot-sequence 808f16cd80SPhilippe Mathieu-Daudé # https://trustedfirmware-a.readthedocs.io/en/v2.8/\ 818f16cd80SPhilippe Mathieu-Daudé # design/firmware-design.html#cold-boot 828f16cd80SPhilippe Mathieu-Daudé 838f16cd80SPhilippe Mathieu-Daudé # AP Trusted ROM 848f16cd80SPhilippe Mathieu-Daudé wait_for_console_pattern(self, "Booting Trusted Firmware") 85e9125425SMarcin Juszkiewicz wait_for_console_pattern(self, "BL1: v2.12.0(release):") 868f16cd80SPhilippe Mathieu-Daudé wait_for_console_pattern(self, "BL1: Booting BL2") 878f16cd80SPhilippe Mathieu-Daudé 888f16cd80SPhilippe Mathieu-Daudé # Trusted Boot Firmware 89e9125425SMarcin Juszkiewicz wait_for_console_pattern(self, "BL2: v2.12.0(release)") 908f16cd80SPhilippe Mathieu-Daudé wait_for_console_pattern(self, "Booting BL31") 918f16cd80SPhilippe Mathieu-Daudé 928f16cd80SPhilippe Mathieu-Daudé # EL3 Runtime Software 93e9125425SMarcin Juszkiewicz wait_for_console_pattern(self, "BL31: v2.12.0(release)") 948f16cd80SPhilippe Mathieu-Daudé 958f16cd80SPhilippe Mathieu-Daudé # Non-trusted Firmware 968f16cd80SPhilippe Mathieu-Daudé wait_for_console_pattern(self, "UEFI firmware (version 1.0") 978f16cd80SPhilippe Mathieu-Daudé interrupt_interactive_console_until_pattern(self, "QEMU SBSA-REF Machine") 988f16cd80SPhilippe Mathieu-Daudé 998f16cd80SPhilippe Mathieu-Daudéif __name__ == '__main__': 1008f16cd80SPhilippe Mathieu-Daudé QemuSystemTest.main() 101