target/cris: Prefer fast cpu_env() over slower CPU QOM cast macro
[qemu/ar7.git] / tests / avocado / machine_aarch64_sbsaref.py
blob528c7d2934ab46f86d0475d834151b68ff601c87
1 # Functional test that boots a Linux kernel and checks the console
3 # SPDX-FileCopyrightText: 2023 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 - Fedora GNU Toolchain version 13.2.1 20230728 (Red Hat 13.2.1-1)
37 - Trusted Firmware-A
38 https://github.com/ARM-software/arm-trusted-firmware/tree/7c3ff62d
40 - Tianocore EDK II
41 https://github.com/tianocore/edk2/tree/0f9283429dd4
42 https://github.com/tianocore/edk2/tree/ad1c0394b177
43 https://github.com/tianocore/edk2-platforms/tree/d03a60523a60
44 """
46 # Secure BootRom (TF-A code)
47 fs0_xz_url = (
48 "https://fileserver.linaro.org/s/rE43RJyTfxPtBkc/"
49 "download/SBSA_FLASH0.fd.xz"
51 fs0_xz_hash = "cdb8e4ffdaaa79292b7b465693f9e5fae6b7062d"
52 tar_xz_path = self.fetch_asset(fs0_xz_url, asset_hash=fs0_xz_hash)
53 archive.extract(tar_xz_path, self.workdir)
54 fs0_path = os.path.join(self.workdir, "SBSA_FLASH0.fd")
56 # Non-secure rom (UEFI and EFI variables)
57 fs1_xz_url = (
58 "https://fileserver.linaro.org/s/AGWPDXbcqJTKS4R/"
59 "download/SBSA_FLASH1.fd.xz"
61 fs1_xz_hash = "411155ae6984334714dff08d5d628178e790c875"
62 tar_xz_path = self.fetch_asset(fs1_xz_url, asset_hash=fs1_xz_hash)
63 archive.extract(tar_xz_path, self.workdir)
64 fs1_path = os.path.join(self.workdir, "SBSA_FLASH1.fd")
66 for path in [fs0_path, fs1_path]:
67 with open(path, "ab+") as fd:
68 fd.truncate(256 << 20) # Expand volumes to 256MiB
70 self.vm.set_console()
71 self.vm.add_args(
72 "-drive",
73 f"if=pflash,file={fs0_path},format=raw",
74 "-drive",
75 f"if=pflash,file={fs1_path},format=raw",
76 "-smp",
77 "1",
78 "-machine",
79 "sbsa-ref",
82 def test_sbsaref_edk2_firmware(self):
83 """
84 :avocado: tags=cpu:cortex-a57
85 """
87 self.fetch_firmware()
88 self.vm.launch()
90 # TF-A boot sequence:
92 # https://github.com/ARM-software/arm-trusted-firmware/blob/v2.8.0/\
93 # docs/design/trusted-board-boot.rst#trusted-board-boot-sequence
94 # https://trustedfirmware-a.readthedocs.io/en/v2.8/\
95 # design/firmware-design.html#cold-boot
97 # AP Trusted ROM
98 wait_for_console_pattern(self, "Booting Trusted Firmware")
99 wait_for_console_pattern(self, "BL1: v2.9(release):v2.9")
100 wait_for_console_pattern(self, "BL1: Booting BL2")
102 # Trusted Boot Firmware
103 wait_for_console_pattern(self, "BL2: v2.9(release)")
104 wait_for_console_pattern(self, "Booting BL31")
106 # EL3 Runtime Software
107 wait_for_console_pattern(self, "BL31: v2.9(release)")
109 # Non-trusted Firmware
110 wait_for_console_pattern(self, "UEFI firmware (version 1.0")
111 interrupt_interactive_console_until_pattern(self, "QEMU SBSA-REF Machine")
113 # This tests the whole boot chain from EFI to Userspace
114 # We only boot a whole OS for the current top level CPU and GIC
115 # Other test profiles should use more minimal boots
116 def boot_alpine_linux(self, cpu):
117 self.fetch_firmware()
119 iso_url = (
120 "https://dl-cdn.alpinelinux.org/"
121 "alpine/v3.17/releases/aarch64/alpine-standard-3.17.2-aarch64.iso"
124 iso_hash = "5a36304ecf039292082d92b48152a9ec21009d3a62f459de623e19c4bd9dc027"
125 iso_path = self.fetch_asset(iso_url, algorithm="sha256", asset_hash=iso_hash)
127 self.vm.set_console()
128 self.vm.add_args(
129 "-cpu",
130 cpu,
131 "-drive",
132 f"file={iso_path},format=raw",
133 "-device",
134 "virtio-rng-pci,rng=rng0",
135 "-object",
136 "rng-random,id=rng0,filename=/dev/urandom",
139 self.vm.launch()
140 wait_for_console_pattern(self, "Welcome to Alpine Linux 3.17")
142 def test_sbsaref_alpine_linux_cortex_a57(self):
144 :avocado: tags=cpu:cortex-a57
146 self.boot_alpine_linux("cortex-a57")
148 def test_sbsaref_alpine_linux_neoverse_n1(self):
150 :avocado: tags=cpu:neoverse-n1
152 self.boot_alpine_linux("neoverse-n1")
154 def test_sbsaref_alpine_linux_max(self):
156 :avocado: tags=cpu:max
158 self.boot_alpine_linux("max")
161 # This tests the whole boot chain from EFI to Userspace
162 # We only boot a whole OS for the current top level CPU and GIC
163 # Other test profiles should use more minimal boots
164 def boot_openbsd73(self, cpu):
165 self.fetch_firmware()
167 img_url = (
168 "https://cdn.openbsd.org/pub/OpenBSD/7.3/arm64/miniroot73.img"
171 img_hash = "7fc2c75401d6f01fbfa25f4953f72ad7d7c18650056d30755c44b9c129b707e5"
172 img_path = self.fetch_asset(img_url, algorithm="sha256", asset_hash=img_hash)
174 self.vm.set_console()
175 self.vm.add_args(
176 "-cpu",
177 cpu,
178 "-drive",
179 f"file={img_path},format=raw",
180 "-device",
181 "virtio-rng-pci,rng=rng0",
182 "-object",
183 "rng-random,id=rng0,filename=/dev/urandom",
186 self.vm.launch()
187 wait_for_console_pattern(self,
188 "Welcome to the OpenBSD/arm64"
189 " 7.3 installation program.")
191 def test_sbsaref_openbsd73_cortex_a57(self):
193 :avocado: tags=cpu:cortex-a57
195 self.boot_openbsd73("cortex-a57")
197 def test_sbsaref_openbsd73_neoverse_n1(self):
199 :avocado: tags=cpu:neoverse-n1
201 self.boot_openbsd73("neoverse-n1")
203 def test_sbsaref_openbsd73_max(self):
205 :avocado: tags=cpu:max
207 self.boot_openbsd73("max")