OVMF, open virtual machine firmware, is a project from EDK-II which to support UEFI for virtual machines. It contains a sample firmware for QEMU and KVM
Its source is under the OvmfPkg directory within the EDK-II source code. it could run UEFI shell and boot Linux in UEFI boot.
1. Building OVMF
check edk2 build process, you will find the binaries under Build/*/*/FV directory. and file OVMF.FD, this is a UEFI virtual version. Sample command like below:
OvmfPkg/build.sh -a X64 qemu
For arm architecture, use this
/uefi-tools/uefi-build.sh -b DEBUG -b RELEASE qemu64
and the firmware image is at
Build/ArmVirtualizationQemu-AARCH64/{DEBUG,RELEASE}_GCC48/FV/QEMU_EFI.fd
2. Running OVMF
It could use option -pflash to flash0.img or -bios or -L to OVMF.FD. Detail check reference 2. Sample command line like below:
$ qemu-system-aarch64 \ -m 1024 \ -cpu cortex-a57 \ -M virt \ -pflash flash0.img \ -pflash flash1.img \ -serial stdio
3. Booting order for OVMF
3.1 SEC - Security
When pushing the power button, the system gets in the SEC phase, no ram memory could be used now. So its CAM(cache as memory), CPU becomes protect mode, no necessary for real-mode like bios. It evolves Assembly operation here.
3.2 PEI - Pre-EFI Initialization Environment
Initialize memory, CPU and chipset. It works on ROM.
it needs to know the boot path, system ram and firmware volume. and enable DXEIPL(DXE Initial Program Loader) which could lead to the next phase.
3.3 DXE - Driver Execution Environment
Important phase. Most work is done here. Create Boot Services Runtime Services and DXE Services, will disappear getting in RT phase. Initialize UEFI platform and provide all services to load system kernel.
3.4 BDS - Boot Device Select
Trying to load all drivers list in Driver and booting OS. When loading drivers, it needs to interact with DXE, once all drivers are ready, it starts booting os, and close DXE totally.
3.5 TSL - Transient System Load
OS boot loader shell.
3.6 RT - RunTime
Only left EFI Runtime Service and EFI System Table could be used.
3.7 AL - After Life
EFI Runtime Service ResetSystem() or ACPI Sleep State.
4. ACPI - Advanced Configuration and Power Interface
UEFI + ACPI is a new boot mode for modern computer architecture. One important part of UEFI is to pass the ACPI table created by firmware to the OS kernel, and these tables will be used for OS to do power management for all physical devices. Detail will be introduced in other wiki links soon.
OVMS is still a new technique in QEMU, there are still some problems, especially in ARM architecture. But with the help of QEMU, it will apply UEFI to the real physical environment very soon.
Reference
1.http://www.tianocore.org/ovmf/
2.http://blog.eciton.net/uefi/qemu-arm-uefi.html
3.https://github.com/tianocore/tianocore.github.io/wiki/OVMF-Boot%20Overview