OVMF (Open Virtual Machine Firmware ) 旨在支持虚拟机启动的一套edk2 Package。目前支持如下特性:


Current capabilities:

* IA32 and X64 architectures

* QEMU (0.10.0 or later)

  - Video, keyboard, IDE, CD-ROM, serial

  - Runs UEFI shell

  - Optional NIC support.  Requires QEMU (0.12.2 or later)

* UEFI Linux boots

* UEFI Windows 8 boots

* UEFI Windows 7 & Windows 2008 Server boot (see important notes below!)

由上面可知它支持QEMU模拟器,所以我们可以依靠它来做一些前期项目调试。

常规编译

常规编译方法需要我们配置Conf/target.txt:



 Update Conf/target.txt ACTIVE_PLATFORM for OVMF:

                              PEI arch   DXE arch   UEFI interfaces

 * OvmfPkg/OvmfPkgIa32.dsc      IA32       IA32           IA32

 * OvmfPkg/OvmfPkgIa32X64.dsc   IA32       X64            X64

 * OvmfPkg/OvmfPkgX64.dsc       X64        X64            X64



 Update Conf/target.txt TARGET_ARCH based on the .dsc file:

                              TARGET_ARCH

 * OvmfPkg/OvmfPkgIa32.dsc     IA32

 * OvmfPkg/OvmfPkgIa32X64.dsc  IA32 X64

 * OvmfPkg/OvmfPkgX64.dsc      X64


然后通过build命令进行编译,生成的文件在$WORKSPACE/Build/*/*/FV 目录。


* OVMF.FD

  - Please note!  This filename has changed.  Older releases used OVMF.Fv.

* OvmfVideo.rom

  - This file is not built separately any longer, starting with svn r13520.

接下来,使用qemu加载uefi:


qemu-system-x86_64  -bios  "path/to/OVMF.fd" 

脚本编译

OVMF支持使用自带脚本简化编译流程:


 So, for example, to build + run OVMF X64:

 $ OvmfPkg/build.sh -a X64

 $ OvmfPkg/build.sh -a X64 qemu

按照上面的命令执行,会直接运行qemu来加载生成的uefi固件。

实例

以我的本机为例,本机是Linux amd64系统,安装了GCC4.8编译器,如果我要编译一个X64版本的OVMF UEFI固件,需要配置target.txt如下所示:

 ACTIVE_PLATFORM       = OvmfPkg/OvmfPkgX64.dsc
 TARGET                = DEBUG
 TARGET_ARCH           = X64
 TOOL_CHAIN_CONF       = Conf/tools_def.txt
 TOOL_CHAIN_TAG        = GCC48
 BUILD_RULE_CONF = Conf/build_rule.txt
 MAX_CONCURRENT_THREAD_NUMBER = 3

然后进入edk2根目录,执行:

Linux@x86_64: ~/edk2 $ build
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐