Skip to content

Commit

Permalink
qemu: implement support for OVMF files
Browse files Browse the repository at this point in the history
Signed-off-by: Morten Linderud <[email protected]>
  • Loading branch information
Foxboron committed Jan 11, 2024
1 parent f6f07ac commit a24a4ca
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions qemu/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,16 @@ func WithTask(t ...Task) Fn {
}
}

func WithOVMF(vars, code string) Fn {

Check failure on line 167 in qemu/qemu.go

View workflow job for this annotation

GitHub Actions / lint

exported: exported function WithOVMF should have comment or be unexported (revive)
return func(alloc *IDAllocator, opts *Options) error {
opts.OVMF = &OVMFFiles{
Secboot: code,
Vars: vars,

Check warning on line 171 in qemu/qemu.go

View check run for this annotation

Codecov / codecov/patch

qemu/qemu.go#L167-L171

Added lines #L167 - L171 were not covered by tests
}
return nil

Check warning on line 173 in qemu/qemu.go

View check run for this annotation

Codecov / codecov/patch

qemu/qemu.go#L173

Added line #L173 was not covered by tests
}
}

// OptionsFor evaluates the given config functions and returns an Options object.
func OptionsFor(arch Arch, fns ...Fn) (*Options, error) {
var vmTimeout time.Duration
Expand Down Expand Up @@ -217,6 +227,11 @@ func StartContext(ctx context.Context, arch Arch, fns ...Fn) (*VM, error) {
return o.Start(ctx)
}

type OVMFFiles struct {

Check failure on line 230 in qemu/qemu.go

View workflow job for this annotation

GitHub Actions / lint

exported: exported type OVMFFiles should have comment or be unexported (revive)
Secboot string
Vars string
}

// Options are VM start-up parameters.
type Options struct {
// arch is the QEMU architecture used.
Expand Down Expand Up @@ -264,6 +279,9 @@ type Options struct {

// ExtraFiles are extra files passed to QEMU on start.
ExtraFiles []*os.File

// OVMF is the OVMF files for UEFI and Secure Boot support.
OVMF *OVMFFiles
}

// AddFile adds the file to the QEMU process and returns the FD it will be in
Expand Down Expand Up @@ -447,6 +465,15 @@ func (o *Options) Cmdline() ([]string, error) {
args = append(args, "-initrd", o.Initramfs)
}

if o.OVMF != nil {
args = append(args, fmt.Sprintf("-drive if=pflash,format=raw,unit=0,file=%s,readonly=on", o.OVMF.Secboot))
args = append(args, fmt.Sprintf("-drive if=pflash,format=raw,unit=1,file=%s", o.OVMF.Vars))

Check warning on line 470 in qemu/qemu.go

View check run for this annotation

Codecov / codecov/patch

qemu/qemu.go#L469-L470

Added lines #L469 - L470 were not covered by tests
// Append 2G of ram just in case
args = append(args, "-m 2G")

Check warning on line 472 in qemu/qemu.go

View check run for this annotation

Codecov / codecov/patch

qemu/qemu.go#L472

Added line #L472 was not covered by tests
// Add specific machine for support
args = append(args, "-machine type=q35,smm=on")

Check warning on line 474 in qemu/qemu.go

View check run for this annotation

Codecov / codecov/patch

qemu/qemu.go#L474

Added line #L474 was not covered by tests
}

return args, nil
}

Expand Down

0 comments on commit a24a4ca

Please sign in to comment.