master
py 99 lines 3 KB
Raw
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
13 from qemu_test import QemuSystemTest, Asset
14 from qemu_test import wait_for_console_pattern
15 from qemu_test import interrupt_interactive_console_until_pattern
16
17
18 def 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, format="xz")
35
36 # Non-secure rom (UEFI and EFI variables)
37 fs1_path = test.uncompress(Aarch64SbsarefMachine.ASSET_FLASH1, format="xz")
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
49 class 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 # SBSA_FLASH0.fd.xz
58 ASSET_FLASH0 = Asset('https://share.linaro.org/downloadFile?id=kyoMLGC9zXa4oA7',
59 '76eb89d42eebe324e4395329f47447cda9ac920aabcf99aca85424609c3384a5')
60
61 # SBSA_FLASH1.fd.xz
62 ASSET_FLASH1 = Asset('https://share.linaro.org/downloadFile?id=Dj1HRXnDnKtU6Nj',
63 'f850f243bd8dbd49c51e061e0f79f1697546938f454aeb59ab7d93e5f0d412fc')
64
65 def test_sbsaref_edk2_firmware(self):
66
67 self.set_machine('sbsa-ref')
68
69 fetch_firmware(self)
70
71 self.vm.set_console()
72 self.vm.add_args('-cpu', 'cortex-a57')
73 self.vm.launch()
74
75 # TF-A boot sequence:
76 #
77 # https://github.com/ARM-software/arm-trusted-firmware/blob/v2.8.0/\
78 # docs/design/trusted-board-boot.rst#trusted-board-boot-sequence
79 # https://trustedfirmware-a.readthedocs.io/en/v2.8/\
80 # design/firmware-design.html#cold-boot
81
82 # AP Trusted ROM
83 wait_for_console_pattern(self, "Booting Trusted Firmware")
84 wait_for_console_pattern(self, "BL1: v2.12.0(release):")
85 wait_for_console_pattern(self, "BL1: Booting BL2")
86
87 # Trusted Boot Firmware
88 wait_for_console_pattern(self, "BL2: v2.12.0(release)")
89 wait_for_console_pattern(self, "Booting BL31")
90
91 # EL3 Runtime Software
92 wait_for_console_pattern(self, "BL31: v2.12.0(release)")
93
94 # Non-trusted Firmware
95 wait_for_console_pattern(self, "UEFI firmware (version 1.0")
96 interrupt_interactive_console_until_pattern(self, "QEMU SBSA-REF Machine")
97
98 if __name__ == '__main__':
99 QemuSystemTest.main()