This post records how I build and run an EDK2 HelloWorld on Qemu, based on OVMF UEFI shell.
Prepare environment
Clone edk2:
| 1 | git clone --recursive https://github.com/tianocore/edk2.git | 
Enter edk2 build environment:
| 1 | . edksetup.sh BaseTools | 
Build base tools:
| 1 | make -C <edk2-dir>/BaseTools/Source/C | 
Create and build HelloWorld
Build HelloWorld package for x64 architecture and using GCC:
| 1 | build -a X64 -p HelloWorldPkg/HelloWorldPkg.dsc -t GCC5 | 
The built HelloWorld.efi is under Build/HelloWorldPkg/DEBUG_GCC5/X64, we can run it under UEFI shell on an x64 PC or an emulator.
Build edk2 for OVMF
Modify the following contents in Conf/target.txt:
| 1 | ACTIVE_PLATFORM = OvmfPkg/OvmfPkgX64.dsc | 
Then, build it:
| 1 | build | 
Boot and run Hello World
Make an image to store efi files:
| 1 | dd if=/dev/null of=example.img bs=1M seek=512 | 
Run OVMF as the firmware and mount the images:
| 1 | qemu-system-x86_64 -L . --bios ./ovmf.fd -hda ./example.img | 
In the UEFI shell, list disk mappings:
| 1 | map -r | 
The files are under fs0, list them:
| 1 | ls fs0:\ | 
Run our Hello Wolrd:
| 1 | fs0:\HelloWorld.efi | 
Conclusion
In this post, I noted all the steps to build an edk2 HelloWorld. I will write some interesting UEFI applications sooner.
