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 skip
12 from avocado
import skipUnless
13 from avocado
.utils
import archive
15 from avocado_qemu
import QemuSystemTest
16 from avocado_qemu
import wait_for_console_pattern
17 from avocado_qemu
import interrupt_interactive_console_until_pattern
20 class Aarch64SbsarefMachine(QemuSystemTest
):
22 :avocado: tags=arch:aarch64
23 :avocado: tags=machine:sbsa-ref
28 def fetch_firmware(self
):
30 Flash volumes generated using:
32 - Fedora GNU Toolchain version 12.2.1 20220819 (Red Hat Cross 12.2.1-2)
35 https://github.com/ARM-software/arm-trusted-firmware/tree/5fdb2e54
38 https://github.com/tianocore/edk2/tree/494127613b
39 https://github.com/tianocore/edk2-non-osi/tree/41876073
40 https://github.com/tianocore/edk2-platforms/tree/8efa4f42
43 # Secure BootRom (TF-A code)
45 "https://fileserver.linaro.org/s/ATnSmq6k8SoXgbH/"
46 "download/SBSA_FLASH0.fd.xz"
48 fs0_xz_hash
= "a210a09692bcbe0a3743ffd0df44e80e0c7ad8ab"
49 tar_xz_path
= self
.fetch_asset(fs0_xz_url
, asset_hash
=fs0_xz_hash
)
50 archive
.extract(tar_xz_path
, self
.workdir
)
51 fs0_path
= os
.path
.join(self
.workdir
, "SBSA_FLASH0.fd")
53 # Non-secure rom (UEFI and EFI variables)
55 "https://fileserver.linaro.org/s/t8foNnMPz74DZZy/"
56 "download/SBSA_FLASH1.fd.xz"
58 fs1_xz_hash
= "13a9a262953787c7fc5a9155dfaa26e703631e02"
59 tar_xz_path
= self
.fetch_asset(fs1_xz_url
, asset_hash
=fs1_xz_hash
)
60 archive
.extract(tar_xz_path
, self
.workdir
)
61 fs1_path
= os
.path
.join(self
.workdir
, "SBSA_FLASH1.fd")
63 for path
in [fs0_path
, fs1_path
]:
64 with
open(path
, "ab+") as fd
:
65 fd
.truncate(256 << 20) # Expand volumes to 256MiB
70 f
"if=pflash,file={fs0_path},format=raw",
72 f
"if=pflash,file={fs1_path},format=raw",
79 def test_sbsaref_edk2_firmware(self
):
81 :avocado: tags=cpu:cortex-a57
89 # https://github.com/ARM-software/arm-trusted-firmware/blob/v2.8.0/\
90 # docs/design/trusted-board-boot.rst#trusted-board-boot-sequence
91 # https://trustedfirmware-a.readthedocs.io/en/v2.8/\
92 # design/firmware-design.html#cold-boot
95 wait_for_console_pattern(self
, "Booting Trusted Firmware")
96 wait_for_console_pattern(self
, "BL1: v2.8(release):v2.8")
97 wait_for_console_pattern(self
, "BL1: Booting BL2")
99 # Trusted Boot Firmware
100 wait_for_console_pattern(self
, "BL2: v2.8(release)")
101 wait_for_console_pattern(self
, "Booting BL31")
103 # EL3 Runtime Software
104 wait_for_console_pattern(self
, "BL31: v2.8(release)")
106 # Non-trusted Firmware
107 wait_for_console_pattern(self
, "UEFI firmware (version 1.0")
108 interrupt_interactive_console_until_pattern(self
, "QEMU SBSA-REF Machine")
110 # This tests the whole boot chain from EFI to Userspace
111 # We only boot a whole OS for the current top level CPU and GIC
112 # Other test profiles should use more minimal boots
113 def boot_alpine_linux(self
, cpu
):
114 self
.fetch_firmware()
117 "https://dl-cdn.alpinelinux.org/"
118 "alpine/v3.17/releases/aarch64/alpine-standard-3.17.2-aarch64.iso"
121 iso_hash
= "5a36304ecf039292082d92b48152a9ec21009d3a62f459de623e19c4bd9dc027"
122 iso_path
= self
.fetch_asset(iso_url
, algorithm
="sha256", asset_hash
=iso_hash
)
124 self
.vm
.set_console()
129 f
"file={iso_path},format=raw",
131 "virtio-rng-pci,rng=rng0",
133 "rng-random,id=rng0,filename=/dev/urandom",
137 wait_for_console_pattern(self
, "Welcome to Alpine Linux 3.17")
139 @skipUnless(os
.getenv("AVOCADO_TIMEOUT_EXPECTED"), "Test might timeout")
140 def test_sbsaref_alpine_linux_cortex_a57(self
):
142 :avocado: tags=cpu:cortex-a57
144 self
.boot_alpine_linux("cortex-a57")
146 @skipUnless(os
.getenv("AVOCADO_TIMEOUT_EXPECTED"), "Test might timeout")
147 def test_sbsaref_alpine_linux_neoverse_n1(self
):
149 :avocado: tags=cpu:max
151 self
.boot_alpine_linux("neoverse-n1")
153 @skip("requires TF-A update to handle FEAT_FGT")
154 def test_sbsaref_alpine_linux_max(self
):
156 :avocado: tags=cpu:max
158 self
.boot_alpine_linux("max,pauth-impdef=on")