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
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
):
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.
31 def fetch_firmware(self
):
33 Flash volumes generated using:
35 - Fedora GNU Toolchain version 13.2.1 20230728 (Red Hat 13.2.1-1)
38 https://github.com/ARM-software/arm-trusted-firmware/tree/7c3ff62d
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
46 # Secure BootRom (TF-A code)
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)
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
73 f
"if=pflash,file={fs0_path},format=raw",
75 f
"if=pflash,file={fs1_path},format=raw",
82 def test_sbsaref_edk2_firmware(self
):
84 :avocado: tags=cpu:cortex-a57
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
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()
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()
132 f
"file={iso_path},format=raw",
134 "virtio-rng-pci,rng=rng0",
136 "rng-random,id=rng0,filename=/dev/urandom",
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()
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()
179 f
"file={img_path},format=raw",
181 "virtio-rng-pci,rng=rng0",
183 "rng-random,id=rng0,filename=/dev/urandom",
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")