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.set_machine('sbsa-ref') 44 test.vm.set_console() 45 test.vm.add_args( 46 "-drive", f"if=pflash,file={fs0_path},format=raw", 47 "-drive", f"if=pflash,file={fs1_path},format=raw", 48 ) 49 50 51class Aarch64SbsarefMachine(QemuSystemTest): 52 """ 53 As firmware runs at a higher privilege level than the hypervisor we 54 can only run these tests under TCG emulation. 55 """ 56 57 timeout = 180 58 59 ASSET_FLASH0 = Asset( 60 ('https://artifacts.codelinaro.org/artifactory/linaro-419-sbsa-ref/' 61 '20241122-189881/edk2/SBSA_FLASH0.fd.xz'), 62 '76eb89d42eebe324e4395329f47447cda9ac920aabcf99aca85424609c3384a5') 63 64 ASSET_FLASH1 = Asset( 65 ('https://artifacts.codelinaro.org/artifactory/linaro-419-sbsa-ref/' 66 '20241122-189881/edk2/SBSA_FLASH1.fd.xz'), 67 'f850f243bd8dbd49c51e061e0f79f1697546938f454aeb59ab7d93e5f0d412fc') 68 69 def test_sbsaref_edk2_firmware(self): 70 71 fetch_firmware(self) 72 73 self.vm.add_args('-cpu', 'cortex-a57') 74 self.vm.launch() 75 76 # TF-A boot sequence: 77 # 78 # https://github.com/ARM-software/arm-trusted-firmware/blob/v2.8.0/\ 79 # docs/design/trusted-board-boot.rst#trusted-board-boot-sequence 80 # https://trustedfirmware-a.readthedocs.io/en/v2.8/\ 81 # design/firmware-design.html#cold-boot 82 83 # AP Trusted ROM 84 wait_for_console_pattern(self, "Booting Trusted Firmware") 85 wait_for_console_pattern(self, "BL1: v2.12.0(release):") 86 wait_for_console_pattern(self, "BL1: Booting BL2") 87 88 # Trusted Boot Firmware 89 wait_for_console_pattern(self, "BL2: v2.12.0(release)") 90 wait_for_console_pattern(self, "Booting BL31") 91 92 # EL3 Runtime Software 93 wait_for_console_pattern(self, "BL31: v2.12.0(release)") 94 95 # Non-trusted Firmware 96 wait_for_console_pattern(self, "UEFI firmware (version 1.0") 97 interrupt_interactive_console_until_pattern(self, "QEMU SBSA-REF Machine") 98 99if __name__ == '__main__': 100 QemuSystemTest.main() 101