Skip to content

Commit

Permalink
pillar: Separate OVMF firmware files and standardize naming.
Browse files Browse the repository at this point in the history
Switch to using separate OVMF_CODE.fd and OVMF_VARS.fd files for FML x86
modes instead of a combined .bin file. This ensures that settings are
stored correctly and maintains consistent naming conventions. These
changes do not affect containers, ARM or Xen.

To support ARM the OVMF build should produce separate files. Currently
it produces QEMU_EFI that incorporates both code and variable sections.

Signed-off-by: Nikolay Martyanov <nikolay@zededa.com>
  • Loading branch information
OhmSpectator authored and eriknordmark committed Sep 22, 2024
1 parent f4e2003 commit e23b37f
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pkg/pillar/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ RUN set -e && for patch in /sys-patches/*.patch; do \
done

RUN mkdir -p /out/usr/lib/xen/boot
COPY --from=uefi-build /OVMF_VARS.fd /out/usr/lib/xen/boot/ovmf_vars.bin
COPY --from=uefi-build /OVMF_VARS.fd /out/usr/lib/xen/boot/OVMF_VARS.fd

COPY --from=zfs /out /out
COPY --from=fscrypt /opt/zededa/bin /out/opt/zededa/bin
Expand Down
2 changes: 1 addition & 1 deletion pkg/pillar/cmd/zedmanager/handledomainmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func MaybeAddDomainConfig(ctx *zedmanagerContext,
}
}
if dc.BootLoader == "" && (dc.VirtualizationModeOrDefault() == types.FML || runtime.GOARCH == "arm64") {
dc.BootLoader = "/usr/lib/xen/boot/ovmf.bin"
dc.BootLoader = "/usr/lib/xen/boot/OVMF_CODE.fd"
}
if ns != nil {
adapterCount := len(ns.AppNetAdapterList)
Expand Down
15 changes: 9 additions & 6 deletions pkg/pillar/hypervisor/kvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const qemuConfTemplate = `# This file is automatically generated by domainmgr
kernel-irqchip = "on"
{{- end -}}
{{- if .DomainConfig.BootLoader }}
{{- if ne .VirtualizationMode "FML" }}
{{- if or (ne .VirtualizationMode "FML") (eq .Machine "virt") }}
firmware = "{{.DomainConfig.BootLoader}}"
{{- end }}
{{- end -}}
Expand Down Expand Up @@ -127,7 +127,7 @@ const qemuConfTemplate = `# This file is automatically generated by domainmgr
caching-mode = "on"
{{- end }}
{{- if eq .VirtualizationMode "FML" }}
{{- if and (eq .VirtualizationMode "FML") (ne .Machine "virt") }}
[drive "drive-ovmf-code"]
if = "pflash"
Expand Down Expand Up @@ -785,8 +785,13 @@ func (ctx KvmContext) Setup(status types.DomainStatus, config types.DomainConfig
swtpmCtrlSock = fmt.Sprintf(types.SwtpmCtrlSocketPath, domainName)
}

// Before we start building the domain config, we need to prepare the OVMF settings
if config.VirtualizationMode == types.FML {
// Before we start building the domain config, we need to prepare the OVMF settings.
// Currently, we only support OVMF settings for FML mode on x86_64 architecture.
// To support OVMF settings for ARM, we need to add fix OVFM build for ARM to
// produce separate OVMF_VARS.fd and OVMF_CODE.fd files. Currently, OVMF build
// for ARM produces a single QEMU_EFI.fd file that contains both OVMF_VARS.fd
// and OVMF_CODE.fd.
if config.VirtualizationMode == types.FML && runtime.GOARCH == "amd64" {
if err := prepareOVMFSettings(domainName); err != nil {
return logError("failed to setup OVMF settings for domain %s: %v", status.DomainName, err)
}
Expand Down Expand Up @@ -1236,8 +1241,6 @@ func (ctx KvmContext) Cleanup(domainName string) error {
}

// Cleanup OVMF settings
// XXX it should be a check for FML mode based on some config/status option. But we have
// only domain name here. So we check if the OVMF settings file exists.
settingsFile, err := getOVMFSettingsFilename(domainName)
if err != nil {
return fmt.Errorf("failed to get OVMF settings file: %v", err)
Expand Down
8 changes: 4 additions & 4 deletions pkg/pillar/hypervisor/kvm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ func TestCreateDomConfigOnlyCom1(t *testing.T) {
})

config.VirtualizationMode = types.FML
config.BootLoader = "/usr/lib/xen/boot/ovmf.bin"
config.BootLoader = "/usr/lib/xen/boot/OVMF_CODE.fd"
t.Run("amd64-fml", func(t *testing.T) {
conf.Seek(0, 0)
if err := kvmIntel.CreateDomConfig(DefaultDomainName, config, types.DomainStatus{},
Expand Down Expand Up @@ -428,7 +428,7 @@ func TestCreateDomConfigOnlyCom1(t *testing.T) {
format = "raw"
readonly = "on"
unit = "0"
file = "/usr/lib/xen/boot/ovmf.bin"
file = "/usr/lib/xen/boot/OVMF_CODE.fd"
[drive "drive-ovmf-vars"]
if = "pflash"
Expand Down Expand Up @@ -976,7 +976,7 @@ func TestCreateDomConfigAmd64Fml(t *testing.T) {
diskConfigs, diskStatuses := qemuDisks()
config, aa := domainConfigAndAssignableAdapters(diskConfigs)
config.VirtualizationMode = types.FML
config.BootLoader = "/usr/lib/xen/boot/ovmf.bin"
config.BootLoader = "/usr/lib/xen/boot/OVMF_CODE.fd"
addNonExistingAdapter(&config, &aa)
if err := kvmIntel.CreateDomConfig(DefaultDomainName, config, types.DomainStatus{},
diskStatuses, &aa, nil, swtpmCtrlSock, conf); err != nil {
Expand Down Expand Up @@ -1451,7 +1451,7 @@ func domConfigAmd64FML() string {
format = "raw"
readonly = "on"
unit = "0"
file = "/usr/lib/xen/boot/ovmf.bin"
file = "/usr/lib/xen/boot/OVMF_CODE.fd"
[drive "drive-ovmf-vars"]
if = "pflash"
Expand Down
2 changes: 1 addition & 1 deletion pkg/pillar/types/locationconsts.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ const (
// OVMFSettingsDir - directory for OVMF settings, they are stored in per-domain files
OVMFSettingsDir = SealedDirName + "/ovmf"
// OVMFSettingsTemplate - template file for OVMF settings
OVMFSettingsTemplate = "/usr/lib/xen/boot/ovmf_vars.bin"
OVMFSettingsTemplate = "/usr/lib/xen/boot/OVMF_VARS.fd"
)

var (
Expand Down
3 changes: 2 additions & 1 deletion pkg/xen-tools/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ RUN if [ "$(uname -m)" = "x86_64" ]; then rm -f qemu-system-i386 && ln -s "qemu-

COPY --from=uefi-build / /uefi/
RUN mkdir -p /out/usr/lib/xen/boot && cp /uefi/OVMF.fd /out/usr/lib/xen/boot/ovmf.bin && \
cp /uefi/OVMF_PVH.fd /out/usr/lib/xen/boot/ovmf-pvh.bin
cp /uefi/OVMF_PVH.fd /out/usr/lib/xen/boot/ovmf-pvh.bin && \
[ -f /uefi/OVMF_CODE.fd ] && cp /uefi/OVMF_CODE.fd /out/usr/lib/xen/boot/OVMF_CODE.fd || :
RUN if [ "$(uname -m)" = "x86_64" ]; then cp /uefi/*.rom /out/usr/lib/xen/boot/;fi

FROM scratch
Expand Down

0 comments on commit e23b37f

Please sign in to comment.