Skip to content

Commit cc85e16

Browse files
authored
Merge pull request #2592 from AkihiroSuda/riscv64-edk2
qemu: riscv64: switch from u-boot to EDK2
2 parents b3e785e + 762e510 commit cc85e16

File tree

5 files changed

+30
-18
lines changed

5 files changed

+30
-18
lines changed

.github/workflows/test.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ jobs:
2525
steps:
2626
- uses: actions/checkout@v4
2727
with:
28-
fetch-depth: 1
28+
# To avoid "failed to load YAML file \"templates/experimental/riscv64.yaml\": can't parse builtin Lima version \"3f3a6f6\": 3f3a6f6 is not in dotted-tri format"
29+
fetch-depth: 0
2930
- uses: actions/setup-go@v5
3031
with:
3132
go-version: 1.23.x
@@ -158,7 +159,8 @@ jobs:
158159
steps:
159160
- uses: actions/checkout@v4
160161
with:
161-
fetch-depth: 1
162+
# To avoid "failed to load YAML file \"templates/experimental/riscv64.yaml\": can't parse builtin Lima version \"3f3a6f6\": 3f3a6f6 is not in dotted-tri format"
163+
fetch-depth: 0
162164
- uses: actions/setup-go@v5
163165
with:
164166
go-version: 1.23.x

examples/experimental/riscv64.yaml

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
1-
# This template requires Lima v0.11.0 or later.
1+
# Lima v0.x users should use https://raw.githubusercontent.com/lima-vm/lima/v0.23.2/examples/experimental/riscv64.yaml
2+
minimumLimaVersion: "1.0.0"
3+
vmOpts:
4+
qemu:
5+
minimumVersion: "9.1.0"
26

37
arch: "riscv64"
48
images:
59
- location: "https://cloud-images.ubuntu.com/releases/24.04/release-20240821/ubuntu-24.04-server-cloudimg-riscv64.img"
610
arch: "riscv64"
711
digest: "sha256:f5886ad4e405e689585dfef0e96c31b06478e0cb12bc7f3fae965759a32d729e"
8-
kernel:
9-
# Extracted from http://http.us.debian.org/debian/pool/main/u/u-boot/u-boot-qemu_2023.07+dfsg-1_all.deb (GPL-2.0)
10-
location: "https://github.com/lima-vm/u-boot-qemu-mirror/releases/download/2023.07%2Bdfsg-7/qemu-riscv64_smode_uboot.elf"
11-
digest: "sha256:d4b3a10c3ef04219641802a586dca905e768805f5a5164fb68520887df54f33c"
1212
# Fallback to the latest release image.
1313
# Hint: run `limactl prune` to invalidate the cache
1414
- location: "https://cloud-images.ubuntu.com/releases/24.04/release/ubuntu-24.04-server-cloudimg-riscv64.img"
1515
arch: "riscv64"
16-
kernel:
17-
# Extracted from http://http.us.debian.org/debian/pool/main/u/u-boot/u-boot-qemu_2023.07+dfsg-1_all.deb (GPL-2.0)
18-
location: "https://github.com/lima-vm/u-boot-qemu-mirror/releases/download/2023.07%2Bdfsg-1/qemu-riscv64_smode_uboot.elf"
19-
digest: "sha256:d4b3a10c3ef04219641802a586dca905e768805f5a5164fb68520887df54f33c"
2016

2117
mounts:
2218
- location: "~"

pkg/limayaml/validate.go

-2
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,6 @@ func Validate(y *LimaYAML, warn bool) error {
101101
if f.Kernel.Arch != f.Arch {
102102
return fmt.Errorf("images[%d].kernel has unexpected architecture %q, must be %q", i, f.Kernel.Arch, f.Arch)
103103
}
104-
} else if f.Arch == RISCV64 {
105-
return errors.New("riscv64 needs the kernel (e.g., \"uboot.elf\") to be specified")
106104
}
107105
if f.Initrd != nil {
108106
if err := validateFileObject(*f.Initrd, fmt.Sprintf("images[%d].initrd", i)); err != nil {

pkg/qemu/qemu.go

+19-4
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,12 @@ func Cmdline(ctx context.Context, cfg Config) (exe string, args []string, err er
573573
}
574574
args = appendArgsIfNoConflict(args, "-machine", machine)
575575
case limayaml.RISCV64:
576-
machine := "virt,accel=" + accel
576+
// https://github.com/tianocore/edk2/blob/edk2-stable202408/OvmfPkg/RiscVVirt/README.md#test
577+
// > Note: the `acpi=off` machine property is specified because Linux guest
578+
// > support for ACPI (that is, the ACPI consumer side) is a work in progress.
579+
// > Currently, `acpi=off` is recommended unless you are developing ACPI support
580+
// > yourself.
581+
machine := "virt,acpi=off,accel=" + accel
577582
args = appendArgsIfNoConflict(args, "-machine", machine)
578583
case limayaml.ARMV7L:
579584
machine := "virt,accel=" + accel
@@ -613,7 +618,7 @@ func Cmdline(ctx context.Context, cfg Config) (exe string, args []string, err er
613618
firmware = downloadedFirmware
614619
logrus.Infof("Using existing firmware (%q)", firmware)
615620
}
616-
if firmware == "" && *y.Arch != limayaml.RISCV64 {
621+
if firmware == "" {
617622
firmware, err = getFirmware(exe, *y.Arch)
618623
if err != nil {
619624
return "", nil, err
@@ -1031,6 +1036,14 @@ func qemuArch(arch limayaml.Arch) string {
10311036
return arch
10321037
}
10331038

1039+
// qemuEdk2 returns the arch string used by `/usr/local/share/qemu/edk2-*-code.fd`.
1040+
func qemuEdk2Arch(arch limayaml.Arch) string {
1041+
if arch == limayaml.RISCV64 {
1042+
return "riscv"
1043+
}
1044+
return qemuArch(arch)
1045+
}
1046+
10341047
func Exe(arch limayaml.Arch) (exe string, args []string, err error) {
10351048
exeBase := "qemu-system-" + qemuArch(arch)
10361049
envK := "QEMU_SYSTEM_" + strings.ToUpper(qemuArch(arch))
@@ -1094,7 +1107,7 @@ func getQemuVersion(qemuExe string) (*semver.Version, error) {
10941107

10951108
func getFirmware(qemuExe string, arch limayaml.Arch) (string, error) {
10961109
switch arch {
1097-
case limayaml.X8664, limayaml.AARCH64, limayaml.ARMV7L:
1110+
case limayaml.X8664, limayaml.AARCH64, limayaml.ARMV7L, limayaml.RISCV64:
10981111
default:
10991112
return "", fmt.Errorf("unexpected architecture: %q", arch)
11001113
}
@@ -1108,7 +1121,7 @@ func getFirmware(qemuExe string, arch limayaml.Arch) (string, error) {
11081121
localDir := filepath.Dir(binDir) // "/usr/local"
11091122
userLocalDir := filepath.Join(currentUser.HomeDir, ".local") // "$HOME/.local"
11101123

1111-
relativePath := fmt.Sprintf("share/qemu/edk2-%s-code.fd", qemuArch(arch))
1124+
relativePath := fmt.Sprintf("share/qemu/edk2-%s-code.fd", qemuEdk2Arch(arch))
11121125
candidates := []string{
11131126
filepath.Join(userLocalDir, relativePath), // XDG-like
11141127
filepath.Join(localDir, relativePath), // macOS (homebrew)
@@ -1135,6 +1148,8 @@ func getFirmware(qemuExe string, arch limayaml.Arch) (string, error) {
11351148
// Debian package "qemu-efi-arm"
11361149
// Fedora package "edk2-arm"
11371150
candidates = append(candidates, "/usr/share/AAVMF/AAVMF32_CODE.fd")
1151+
case limayaml.RISCV64:
1152+
// NOP, as EDK2 for RISCV64 is not packaged yet in well-known distros.
11381153
}
11391154

11401155
logrus.Debugf("firmware candidates = %v", candidates)

pkg/qemu/qemu_driver.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,8 @@ func (l *LimaQemuDriver) killVhosts() error {
296296
}
297297

298298
func (l *LimaQemuDriver) shutdownQEMU(ctx context.Context, timeout time.Duration, qCmd *exec.Cmd, qWaitCh <-chan error) error {
299-
logrus.Info("Shutting down QEMU with ACPI")
299+
// "power button" refers to ACPI on the most archs, except RISC-V
300+
logrus.Info("Shutting down QEMU with the power button")
300301
if usernetIndex := limayaml.FirstUsernetIndex(l.Instance.Config); usernetIndex != -1 {
301302
client := usernet.NewClientByName(l.Instance.Config.Networks[usernetIndex].Lima)
302303
err := client.UnExposeSSH(l.SSHLocalPort)

0 commit comments

Comments
 (0)