1
// This Source Code Form is subject to the terms of the Mozilla Public
2
// License, v. 2.0. If a copy of the MPL was not distributed with this
3
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
12
// Arch abstracts away differences between different architectures.
17
ArchAmd64 Arch = "amd64"
18
ArchArm64 Arch = "arm64"
21
// Valid checks whether the architecture is supported.
22
func (arch Arch) Valid() bool {
24
case ArchAmd64, ArchArm64:
31
// QemuArch defines which qemu binary to use.
32
func (arch Arch) QemuArch() string {
39
panic("unsupported architecture")
43
// QemuMachine defines the machine type for qemu.
44
func (arch Arch) QemuMachine() string {
49
return "virt,gic-version=max"
51
panic("unsupported architecture")
55
// Console defines proper argument for the kernel to send logs to serial console.
56
func (arch Arch) Console() string {
61
return "ttyAMA0,115200n8"
63
panic("unsupported architecture")
67
// PFlash for UEFI boot.
73
// PFlash returns settings for parallel flash.
74
func (arch Arch) PFlash(uefiEnabled bool, extraUEFISearchPaths []string) []PFlash {
77
uefiSourcePaths := []string{"/usr/share/qemu-efi-aarch64/QEMU_EFI.fd", "/usr/share/OVMF/QEMU_EFI.fd"}
78
for _, p := range extraUEFISearchPaths {
79
uefiSourcePaths = append(uefiSourcePaths, filepath.Join(p, "QEMU_EFI.fd"))
84
Size: 64 * 1024 * 1024,
85
SourcePaths: uefiSourcePaths,
88
Size: 64 * 1024 * 1024,
96
// Default search paths
97
uefiSourcePathPrefixes := []string{
103
// Secure boot enabled firmware files
104
uefiSourceFiles := []string{
105
"OVMF_CODE_4M.secboot.fd",
106
"OVMF_CODE.secboot.fd",
108
"edk2-x86_64-secure-code.fd", // Alpine Linux
109
"ovmf-x86_64-ms-4m-code.bin",
112
// Non-secure boot firmware files
113
uefiSourceFilesInsecure := []string{
117
"ovmf-x86_64-4m-code.bin",
121
uefiVarsFiles := []string{
124
"ovmf-x86_64-4m-vars.bin",
127
uefiSourceFiles = append(uefiSourceFiles, uefiSourceFilesInsecure...)
129
// Append extra search paths
130
uefiSourcePathPrefixes = append(uefiSourcePathPrefixes, extraUEFISearchPaths...)
132
var uefiSourcePaths []string
134
var uefiVarsPaths []string
136
for _, p := range uefiSourcePathPrefixes {
137
for _, f := range uefiSourceFiles {
138
uefiSourcePaths = append(uefiSourcePaths, filepath.Join(p, f))
141
for _, f := range uefiVarsFiles {
142
uefiVarsPaths = append(uefiVarsPaths, filepath.Join(p, f))
149
SourcePaths: uefiSourcePaths,
153
SourcePaths: uefiVarsPaths,
161
// QemuExecutable returns name of qemu executable for the arch.
162
func (arch Arch) QemuExecutable() string {
163
binaries := []string{
164
"qemu-system-" + arch.QemuArch(),
166
"/usr/libexec/qemu-kvm",
169
for _, binary := range binaries {
170
if path, err := exec.LookPath(binary); err == nil {