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