Skip to content

Commit 051fc82

Browse files
authored
Merge pull request #820 from jcdickinson/feat/xdg-like-firmware-lookup
feat: look for firmware in $HOME/.local/share/qemu
2 parents 0a5e1b5 + 7559909 commit 051fc82

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

pkg/qemu/qemu.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"io/fs"
88
"os"
99
"os/exec"
10+
"os/user"
1011
"path/filepath"
1112
"runtime"
1213
"strconv"
@@ -615,11 +616,20 @@ func getFirmware(qemuExe string, arch limayaml.Arch) (string, error) {
615616
default:
616617
return "", fmt.Errorf("unexpected architecture: %q", arch)
617618
}
618-
binDir := filepath.Dir(qemuExe) // "/usr/local/bin"
619-
localDir := filepath.Dir(binDir) // "/usr/local"
620619

620+
currentUser, err := user.Current()
621+
if err != nil {
622+
return "", err
623+
}
624+
625+
binDir := filepath.Dir(qemuExe) // "/usr/local/bin"
626+
localDir := filepath.Dir(binDir) // "/usr/local"
627+
userLocalDir := filepath.Join(currentUser.HomeDir, ".local") // "$HOME/.local"
628+
629+
relativePath := fmt.Sprintf("share/qemu/edk2-%s-code.fd", arch)
621630
candidates := []string{
622-
filepath.Join(localDir, fmt.Sprintf("share/qemu/edk2-%s-code.fd", arch)), // macOS (homebrew)
631+
filepath.Join(userLocalDir, relativePath), // XDG-like
632+
filepath.Join(localDir, relativePath), // macOS (homebrew)
623633
}
624634

625635
switch arch {
@@ -648,5 +658,5 @@ func getFirmware(qemuExe string, arch limayaml.Arch) (string, error) {
648658
if arch == limayaml.X8664 {
649659
return "", fmt.Errorf("could not find firmware for %q (hint: try setting `firmware.legacyBIOS` to `true`)", qemuExe)
650660
}
651-
return "", fmt.Errorf("could not find firmware for %q", qemuExe)
661+
return "", fmt.Errorf("could not find firmware for %q (hint: try copying the \"edk-%s-code.fd\" firmware to $HOME/.local/share/qemu/)", arch, qemuExe)
652662
}

0 commit comments

Comments
 (0)