http://blog.csdn.net/xtdumpling/article/details/5569610
Introduction
These are instructions for setting up EDK II build environment on Ubuntu, and building OVMF images for use with qemu.
Initial set up
Recent EDK2 checkouts (as of 2 Sept 2012) are known to build correctly on precise.
Install required packages
sudo apt-get install build-essential git uuid-dev iasl
Get the latest source for EDKII
In a suitable working directory (~/src/ in this case, but you can alter this) checkout the latest EDKII source:
$ mkdir ~/src $ cd ~/src $ git clone git://github.com/tianocore/edk2.git $ cd edk2
The following instructions assume that you remain in the ~/src/edk2 directory
Compile base tools
For MS
Windows, prebuilt binaries of the base tools are shipped with the
source; on Ubuntu the base tools required for building EDKII need to be
built first.
$ make -C BaseTools
Set up build target
To set up the build target you need to modify the conf file Conf/target.txt. This will enable the firmware package to be built and set up the compiler version used.
$ vi Conf/target.txt
Find
ACTIVE_PLATFORM = Nt32Pkg/Nt32Pkg.dsc
and replace it with
ACTIVE_PLATFORM = MdeModulePkg/MdeModulePkg.dsc
Find
TARGET_ARCH = IA32
and replace it with 'X64' for 64bit or 'IA32 X64' to build both architectures.
TARGET_ARCH = X64
Set up build environment
You need to set EDK_TOOLS_PATH and set up the build environment by running the edksetup.sh script provided in the source. This script will copy template and configuration files to edk2/Conf directory.
$ . edksetup.sh
EmulatorPkg provides an environment where a UEFI environment can be
emulated under an environment where a full UEFI compatible
environment is not possible.
On systems with the bash shell you can use EmulatorPkg/build.sh to simplify
building and running EmulatorPkg.
For example, to build + run:
$ EmulatorPkg/build.sh
$ EmulatorPkg/build.sh run
Build a full system firmware image (OVMF)
The Open Virtual Machine Firmware (or "OVMF") can be used to enable UEFI within virtual machines. It provides libraries and drivers related to virtual machines. Currently OVMF support QEMU for emulating UEFI on IA32 and X86-64 based systems. You could also build OVMF with source level debugging enabled.
Set up build target
You can build OVMF for IA32 or X64 architechtures. In this example we will build OVMF for X64 architecture.
You will need to modify Conf/target.txt and replace ACTIVE_PLATFORM with the right dsc file. $ vi Conf/target.txt
Find ACTIVE_PLATFORM = MdeModulePkg/MdeModulePkg.dsc
replace with ACTIVE_PLATFORM = OvmfPkg/OvmfPkgX64.dsc This will set the Target Arch to X64, PEI code to X64 and DXE/UEFI code to X64.
Build a full system firmware image (OVMF)
The Open Virtual Machine Firmware (or "OVMF") can be used to enable UEFI within virtual machines.
It provides libraries and drivers related to virtual machines. Currently OVMF support QEMU for emulating UEFI on IA32 and X86-64 based systems.
You could also build OVMF with source level debugging enabled.
Set up build target
You can build OVMF for IA32 or X64 architechtures. In this example we will build OVMF for X64 architecture. You will need to modify Conf/target.
txt and replace ACTIVE_PLATFORM with the right dsc file.
$ vi Conf/target.txt
Find
ACTIVE_PLATFORM = MdeModulePkg/MdeModulePkg.dsc
replace with
ACTIVE_PLATFORM = OvmfPkg/OvmfPkgX64.dsc
This will set the Target Arch to X64, PEI code to X64 and DXE/UEFI code to X64.
Build OvmfPkg
$ cd OvmfPkg
$ buildOn an i7 with 16GB RAM the total build time is less than 30 seconds. The firmware image produced will be located in Build/OvmfX64/DEBUG_GCC46/FV/OVMF.fd.
If you'd like debug output on the serial console, use the DEBUG_ON_SERIAL_PORT option:
$ build -DDEBUG_ON_SERIAL_PORT=TRUE
Building OvmfPkg with Secure Boot support
If you wish to build OVMF with Secure Boot, you must follow the openssl installation instructions found in CryptoPkg/Library/OpensslLib/Patch-HOWTO.txt,
and build with the SECURE_BOOT_ENABLE option:
$ cd OvmfPkg
$ build -DSECURE_BOOT_ENABLE=TRUE
If you see an error that "the required fv image size exceeds the set fv image size" consult .
This issue has been fixed in recent builds.
Running UEFI in QEMU
See the page for running the OVMF images under qemu.