Merge tag 'v9.0.0-rc3'
[qemu/ar7.git] / tests / avocado / machine_aarch64_sbsaref.py
blob98c76c1ff70a8e24a83a0f60b575678fca8204ef
1 # Functional test that boots a Linux kernel and checks the console
3 # SPDX-FileCopyrightText: 2023-2024 Linaro Ltd.
4 # SPDX-FileContributor: Philippe Mathieu-Daudé <philmd@linaro.org>
5 # SPDX-FileContributor: Marcin Juszkiewicz <marcin.juszkiewicz@linaro.org>
7 # SPDX-License-Identifier: GPL-2.0-or-later
9 import os
11 from avocado import skipUnless
12 from avocado.utils import archive
14 from avocado_qemu import QemuSystemTest
15 from avocado_qemu import wait_for_console_pattern
16 from avocado_qemu import interrupt_interactive_console_until_pattern
19 class Aarch64SbsarefMachine(QemuSystemTest):
20 """
21 :avocado: tags=arch:aarch64
22 :avocado: tags=machine:sbsa-ref
23 :avocado: tags=accel:tcg
25 As firmware runs at a higher privilege level than the hypervisor we
26 can only run these tests under TCG emulation.
27 """
29 timeout = 180
31 def fetch_firmware(self):
32 """
33 Flash volumes generated using:
35 Toolchain from Debian:
36 aarch64-linux-gnu-gcc (Debian 12.2.0-14) 12.2.0
38 Used components:
40 - Trusted Firmware 2.10.2
41 - Tianocore EDK2 stable202402
42 - Tianocore EDK2-platforms commit 085c2fb
44 """
46 # Secure BootRom (TF-A code)
47 fs0_xz_url = (
48 "https://artifacts.codelinaro.org/artifactory/linaro-419-sbsa-ref/"
49 "20240313-116475/edk2/SBSA_FLASH0.fd.xz"
51 fs0_xz_hash = "637593749cc307dea7dc13265c32e5d020267552f22b18a31850b8429fc5e159"
52 tar_xz_path = self.fetch_asset(fs0_xz_url, asset_hash=fs0_xz_hash,
53 algorithm='sha256')
54 archive.extract(tar_xz_path, self.workdir)
55 fs0_path = os.path.join(self.workdir, "SBSA_FLASH0.fd")
57 # Non-secure rom (UEFI and EFI variables)
58 fs1_xz_url = (
59 "https://artifacts.codelinaro.org/artifactory/linaro-419-sbsa-ref/"
60 "20240313-116475/edk2/SBSA_FLASH1.fd.xz"
62 fs1_xz_hash = "cb0a5e8cf5e303c5d3dc106cfd5943ffe9714b86afddee7164c69ee1dd41991c"
63 tar_xz_path = self.fetch_asset(fs1_xz_url, asset_hash=fs1_xz_hash,
64 algorithm='sha256')
65 archive.extract(tar_xz_path, self.workdir)
66 fs1_path = os.path.join(self.workdir, "SBSA_FLASH1.fd")
68 for path in [fs0_path, fs1_path]:
69 with open(path, "ab+") as fd:
70 fd.truncate(256 << 20) # Expand volumes to 256MiB
72 self.vm.set_console()
73 self.vm.add_args(
74 "-drive",
75 f"if=pflash,file={fs0_path},format=raw",
76 "-drive",
77 f"if=pflash,file={fs1_path},format=raw",
78 "-smp",
79 "1",
80 "-machine",
81 "sbsa-ref",
84 def test_sbsaref_edk2_firmware(self):
85 """
86 :avocado: tags=cpu:cortex-a57
87 """
89 self.fetch_firmware()
90 self.vm.launch()
92 # TF-A boot sequence:
94 # https://github.com/ARM-software/arm-trusted-firmware/blob/v2.8.0/\
95 # docs/design/trusted-board-boot.rst#trusted-board-boot-sequence
96 # https://trustedfirmware-a.readthedocs.io/en/v2.8/\
97 # design/firmware-design.html#cold-boot
99 # AP Trusted ROM
100 wait_for_console_pattern(self, "Booting Trusted Firmware")
101 wait_for_console_pattern(self, "BL1: v2.10.2(release):")
102 wait_for_console_pattern(self, "BL1: Booting BL2")
104 # Trusted Boot Firmware
105 wait_for_console_pattern(self, "BL2: v2.10.2(release)")
106 wait_for_console_pattern(self, "Booting BL31")
108 # EL3 Runtime Software
109 wait_for_console_pattern(self, "BL31: v2.10.2(release)")
111 # Non-trusted Firmware
112 wait_for_console_pattern(self, "UEFI firmware (version 1.0")
113 interrupt_interactive_console_until_pattern(self, "QEMU SBSA-REF Machine")
115 # This tests the whole boot chain from EFI to Userspace
116 # We only boot a whole OS for the current top level CPU and GIC
117 # Other test profiles should use more minimal boots
118 def boot_alpine_linux(self, cpu):
119 self.fetch_firmware()
121 iso_url = (
122 "https://dl-cdn.alpinelinux.org/"
123 "alpine/v3.17/releases/aarch64/alpine-standard-3.17.2-aarch64.iso"
126 iso_hash = "5a36304ecf039292082d92b48152a9ec21009d3a62f459de623e19c4bd9dc027"
127 iso_path = self.fetch_asset(iso_url, algorithm="sha256", asset_hash=iso_hash)
129 self.vm.set_console()
130 self.vm.add_args(
131 "-cpu",
132 cpu,
133 "-drive",
134 f"file={iso_path},format=raw",
137 self.vm.launch()
138 wait_for_console_pattern(self, "Welcome to Alpine Linux 3.17")
140 def test_sbsaref_alpine_linux_cortex_a57(self):
142 :avocado: tags=cpu:cortex-a57
143 :avocado: tags=os:linux
145 self.boot_alpine_linux("cortex-a57")
147 def test_sbsaref_alpine_linux_neoverse_n1(self):
149 :avocado: tags=cpu:neoverse-n1
150 :avocado: tags=os:linux
152 self.boot_alpine_linux("neoverse-n1")
154 def test_sbsaref_alpine_linux_max_pauth_off(self):
156 :avocado: tags=cpu:max
157 :avocado: tags=os:linux
159 self.boot_alpine_linux("max,pauth=off")
161 def test_sbsaref_alpine_linux_max_pauth_impdef(self):
163 :avocado: tags=cpu:max
164 :avocado: tags=os:linux
166 self.boot_alpine_linux("max,pauth-impdef=on")
168 @skipUnless(os.getenv('AVOCADO_TIMEOUT_EXPECTED'), 'Test might timeout')
169 def test_sbsaref_alpine_linux_max(self):
171 :avocado: tags=cpu:max
172 :avocado: tags=os:linux
174 self.boot_alpine_linux("max")
177 # This tests the whole boot chain from EFI to Userspace
178 # We only boot a whole OS for the current top level CPU and GIC
179 # Other test profiles should use more minimal boots
180 def boot_openbsd73(self, cpu):
181 self.fetch_firmware()
183 img_url = (
184 "https://cdn.openbsd.org/pub/OpenBSD/7.3/arm64/miniroot73.img"
187 img_hash = "7fc2c75401d6f01fbfa25f4953f72ad7d7c18650056d30755c44b9c129b707e5"
188 img_path = self.fetch_asset(img_url, algorithm="sha256", asset_hash=img_hash)
190 self.vm.set_console()
191 self.vm.add_args(
192 "-cpu",
193 cpu,
194 "-drive",
195 f"file={img_path},format=raw",
198 self.vm.launch()
199 wait_for_console_pattern(self,
200 "Welcome to the OpenBSD/arm64"
201 " 7.3 installation program.")
203 def test_sbsaref_openbsd73_cortex_a57(self):
205 :avocado: tags=cpu:cortex-a57
206 :avocado: tags=os:openbsd
208 self.boot_openbsd73("cortex-a57")
210 def test_sbsaref_openbsd73_neoverse_n1(self):
212 :avocado: tags=cpu:neoverse-n1
213 :avocado: tags=os:openbsd
215 self.boot_openbsd73("neoverse-n1")
217 def test_sbsaref_openbsd73_max_pauth_off(self):
219 :avocado: tags=cpu:max
220 :avocado: tags=os:openbsd
222 self.boot_openbsd73("max,pauth=off")
224 @skipUnless(os.getenv('AVOCADO_TIMEOUT_EXPECTED'), 'Test might timeout')
225 def test_sbsaref_openbsd73_max_pauth_impdef(self):
227 :avocado: tags=cpu:max
228 :avocado: tags=os:openbsd
230 self.boot_openbsd73("max,pauth-impdef=on")
232 @skipUnless(os.getenv('AVOCADO_TIMEOUT_EXPECTED'), 'Test might timeout')
233 def test_sbsaref_openbsd73_max(self):
235 :avocado: tags=cpu:max
236 :avocado: tags=os:openbsd
238 self.boot_openbsd73("max")