Skip to content

Commit

Permalink
pillar: Add support for predefined OVMF settings based on resolution.
Browse files Browse the repository at this point in the history
Implemented logic to select predefined OVMF_VARS.fd files for specific
screen resolutions. Added pre-saved OVMF settings for 800x600, 1024x768,
1280x800, and 1920x1080 resolutions, ensuring clean boot entries.

Signed-off-by: Nikolay Martyanov <nikolay@zededa.com>
  • Loading branch information
OhmSpectator committed Sep 20, 2024
1 parent ab40145 commit f23e947
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 13 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
35 changes: 22 additions & 13 deletions pkg/pillar/hypervisor/kvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -738,19 +738,36 @@ func getOVMFSettingsFilename(domainName string) (string, error) {
return types.OVMFSettingsDir + "/" + domainUUID.String() + "_OVMF_VARS.fd", nil
}

func prepareOVMFSettings(domainName string) error {
func prepareOVMFSettings(config types.DomainConfig, status types.DomainStatus, globalConfig *types.ConfigItemValueMap) error {
// Create the OVMF settings directory if it does not exist
if err := os.MkdirAll(types.OVMFSettingsDir, 0755); err != nil {
return logError("failed to create OVMF settings directory: %v", err)
}
// Create a copy of the ovmf_vars.bin file in <domainName>_ovmf_vars.bin
ovmfSettingsFile, err := getOVMFSettingsFilename(domainName)
ovmfSettingsFile, err := getOVMFSettingsFilename(status.DomainName)
if err != nil {
return logError("failed to get OVMF settings file: %v", err)
}
// Check if we need custom OVMF settings for the domain (the resolution)
fmlResolution := types.FmlResolutionUnset
if config.VirtualizationMode == types.FML {
// if we are not getting the resolution from the cloud-init, check the
// global config.
fmlResolution = status.FmlCustomResolution
if fmlResolution == types.FmlResolutionUnset {
if fmlResolution, err = getFmlCustomResolution(&status, globalConfig); err != nil {
return logError("failed to get custom resolution for domain %s: %v", status.DomainName, err)
}
}
}
// Find the necessary OVMF settings file
ovmfSettingsFileSrc := types.OVMFSettingsTemplate
if fmlResolution != types.FmlResolutionUnset {
ovmfSettingsFileSrc = types.CustomOVMFSettingsDir + "/OVMF_VARS_" + fmlResolution + ".fd"
}
if _, err := os.Stat(ovmfSettingsFile); os.IsNotExist(err) {
if err := fileutils.CopyFile(types.OVMFSettingsTemplate, ovmfSettingsFile); err != nil {
return logError("failed to copy ovmf_vars.bin file: %v", err)
if err := fileutils.CopyFile(ovmfSettingsFileSrc, ovmfSettingsFile); err != nil {
return logError("failed to copy OVMF_VARS file: %v", err)
}
}
// Set the RW permissions for the OVMF settings file
Expand Down Expand Up @@ -779,14 +796,6 @@ func (ctx KvmContext) Setup(status types.DomainStatus, config types.DomainConfig
domainName := status.DomainName
domainUUID := status.UUIDandVersion.UUID

// this needs to be reworked to fit into the OVMF_VAR changes.
res, err := getFmlCustomResolution(&status, globalConfig)
if err != nil {
logError("failed to get fml custom resolution: %v", err)
} else {
logError("fml custom resolution is set to: %s", res)
}

// check if vTPM is enabled
swtpmCtrlSock := ""
if status.VirtualTPM {
Expand All @@ -800,7 +809,7 @@ func (ctx KvmContext) Setup(status types.DomainStatus, config types.DomainConfig
// 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 {
if err := prepareOVMFSettings(config, status, globalConfig); err != nil {
return logError("failed to setup OVMF settings for domain %s: %v", status.DomainName, err)
}
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/pillar/types/locationconsts.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ const (
OVMFSettingsDir = SealedDirName + "/ovmf"
// OVMFSettingsTemplate - template file for OVMF settings
OVMFSettingsTemplate = "/usr/lib/xen/boot/OVMF_VARS.fd"
// CustomOVMFSettingsDir - directory for custom OVMF settings (for different resolutions)
CustomOVMFSettingsDir = "/hostfs/etc/ovmf"
)

var (
Expand Down

0 comments on commit f23e947

Please sign in to comment.