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
… (2/2)

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
shjala authored and OhmSpectator committed Sep 19, 2024
1 parent 14c4cd5 commit ddead4c
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions pkg/pillar/hypervisor/kvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,19 +509,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)
}
// Check if we need custom OVMF settings for the domain (the resolution)
fmlResolution := types.FmlResolutionUnset
if config.VirtualizationMode == types.FML {
fmlRes, err := getFmlCustomResolution(&status, globalConfig)
if err != nil {
return logError("failed to get FML custom resolution: %v", err)
}

fmlResolution = fmlRes
logError("[info] FmlResolution is set to: %s", fmlResolution)
}
// Find the necessary OVMF settings file
ovmfSettingsFileSrc := types.OVMFSettingsTemplate
if fmlResolution != types.FmlResolutionUnset {
ovmfSettingsFileSrc = types.CustomOVMFSettingsDir + "/OVMF_VARS_" + fmlResolution + ".fd"
}

// 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)
}
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 @@ -698,7 +715,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 Expand Up @@ -801,12 +818,6 @@ func (ctx kvmContext) CreateDomConfig(domainName string, config types.DomainConf
tmplCtx.DomainConfig.Memory = (config.Memory + 1023) / 1024
tmplCtx.DomainConfig.DisplayName = domainName

fmlRes, err := getFmlCustomResolution(&status, globalConfig)
if err != nil {
return logError("failed to get FML custom resolution: %v", err)
}
logError("CreateDomConfig -> FmlResolution is set to: %s", fmlRes)

// render global device model settings
t, _ := template.New("qemu").Parse(qemuConfTemplate)
if err := t.Execute(file, tmplCtx); err != nil {
Expand Down

0 comments on commit ddead4c

Please sign in to comment.