OVMF (Open Virtual Machine Firmware) is a project that aim is to enable UEFI support in various virtual machines. According to whitepaper various projects have interest in supporting OVFM ie. VirtualBox, Xen, BHyVe and of course QEMU. Why someone may be interested in OVMF ?
-
IMHO the most important reason is that OVMF give ability to develop UEFI applications without using real hardware. This speeds up development cycle by giving ability to start before hardware prototype arrive. There are also cases when hardware is available only remotely, dealing with remote setup is usually annoying, so part of development can be performed locally.
-
It also improve testing and debugging, because we have full control over execution environment internals. Error injection and corner case analysis can be ineffective in real world. OVMF and qemu open debugging to new levels.
-
It enables training and learning environment. Not every one can obtain UEFI PC and mess with it when there is risk of destroying sth.
-
Many other reason like ability to test/develop UEFI support for various OSes, simplified debugging, lack of dependencies on legacy address space and devices. This and other interesting reasons can be found in Laszlo Ersek whitepaper
What I want to show below is procedure for setting up development environment
for UEFI applications and show how to compile and deploy Hello World
application in that environment.
QEMU
Let’s use upstream version of QEMU:
|
|
Prepare application image
Of course size depends on you application requirements. Usually 128MB is way too much.
|
|
EDK2
First build UEFI firmware with shell:
|
|
Now we need some application that can be delivered over app.disk
to virtual
machine. There are couple examples of UEFI applications in edk2
source code,
but let’s start with classical Hello World
. Source code can be found in
MdeModulePkg/Application/HelloWorld
. This module is built in MdeModulePkg
because of that we can built it as follows:
|
|
Let’s put it into app.disk
:
|
|
OVMF configuration
When we develop UEFI application best way would be to run OVMF to UEFI Shell for test purposes. This is not default option. How to change boot order so we every time will lend in shell ?
On booting screen hit <Esc>
.
You should be in main menu of UEFI setup:
Go through Boot Maintenance Manager -> Boot Options -> Change Boot Order
,
select Change Boot Order
and hit <Enter>
. Then using +/-
keys move
EFI Internal Shell
to the top.
Do not forget to save configuration with <F10>
.
Run HelloWorld.efi
To boot OVMF I’m using Laszlo’s slightly modified script which can be found here.
After booting to UEFI Shell we should look something like this:
Note FS0:
in mapping table list - this is our app.disk
.
Type:
|
|
Result should look like this:
NOTE: If your result is different then make sure to check last lines of
app.ovmf.log
it can give you some hints.
Summary
Hopefully at least part of above article was useful somehow. There are many ways to extend this sample presentation. In example application delivery can be achieved by network transfer. If you have any question or need UEFI support please do not bother to ping me in comments or using any other medium.