EDK2: Difference between revisions

From OSDev.wiki
Jump to navigation Jump to search
[unchecked revision][unchecked revision]
Content added Content deleted
(Save draft)
(Fix one bug in code)
Line 18: Line 18:
No matter what you are trying to build from EDK2, these steps must be completed. First, you must decide if you want to only build stuff inside of the main EDK2 repo, or if you also want stuff from edk2-platforms. Note that these guides assume you are on a Linux system (Windows Subsystem for Linux is OK)
No matter what you are trying to build from EDK2, these steps must be completed. First, you must decide if you want to only build stuff inside of the main EDK2 repo, or if you also want stuff from edk2-platforms. Note that these guides assume you are on a Linux system (Windows Subsystem for Linux is OK)
====Building without edk2-platforms====
====Building without edk2-platforms====
If you only want the UEFI library or virtual machine firmware, then this guide will suffice. First, you must create a ''workspace''. An EDK2 workspace is where the source for EDK2 is. Note that your UEFI loader could be in here, but it doesn't have to.
If you only want the UEFI library or virtual machine firmware, then this guide will suffice.
First, we must clone EDK2
To create the workspace:
<source lang="bash">
mkdir edk2
export WORKSPACE=edk2
</source>
Note that exporting the WORKSPACE variable is recommended. We now must clone the source
<source lang="bash">
<source lang="bash">
git clone https://github.com/tianocore/edk2.git
git clone https://github.com/tianocore/edk2.git

Revision as of 00:43, 30 July 2021

EDK2 is the official development environment for UEFI applications. It is developed by the open-source Tianocore project, of which Intel, HP, and Microsoft are the primary contributors. Although it may be bigger the GNU-EFI, it has more features, meaning that some OS developers may prefer it over GNU-EFI.

What is EDK2?

EDK2 is full on implementation of the UEFI spec. It contains the Open Virtual Machine Firmware (OVMF), which is primarily targeted at QEMU, and is used by many OS developers to test out there UEFI applications. It also has ARM and AArch64 firmware packages for QEMU and various other boards, and RISC-V firmware packages for various HiFive boards. It also has tools for UEFI driver developers, but that is for now outside the scope of this wiki.

Of most interest the OS developers is the UEFI library and the EDK2 build system. This article will show you the structure of EDK2, how to build firmware for QEMU and real machines, and how to build UEFI applications.

Structure of EDK2

EDK2 is made up of multiple repos, all of which can be found at [1]. The main ones are: - edk2, which contains the build system, library, OVMF, and ArmVirt firmware - edk2-platforms, which contains firmware for various real hardware platforms, such as the SiFive U450, Raspberry Pi, and quite a few others - edk2-non-osi, which contains proprietary binary blobs for various platforms. EDK2 itself is written in C with some Python, and is licensed under the BSD 2 Clause + Patent license. The blobs are subject to there own licenses.

Directory structure

EDK2 is split up into multiple subdirectories, where each one normally contains a "Package". The OvmfPkg subdirectory contains OVMF, the MdePkg subdirectory contains the UEFI library, and so on. Each one of these contains a file ending in .dsc. This file describes the package inside of the folder, and contains things such as dependencies, different components, and so on. Each component is described its own file that contains sources, application type, and so on. TODO: Describe this in more detail

Building EDK2's base

No matter what you are trying to build from EDK2, these steps must be completed. First, you must decide if you want to only build stuff inside of the main EDK2 repo, or if you also want stuff from edk2-platforms. Note that these guides assume you are on a Linux system (Windows Subsystem for Linux is OK)

Building without edk2-platforms

If you only want the UEFI library or virtual machine firmware, then this guide will suffice. First, we must clone EDK2

git clone https://github.com/tianocore/edk2.git

Note that this is the latest non-stable source. If you want the stable source then run:

git clone https://github.com/tianocore/edk2.git -b"stable/202011"

or whatever is appropriate at the time you are reading this. After that, we now must clone the submodules

git submodule update --init

Then, we need to setup the environment for EDK2

cd edk2
export EDK_TOOLS_PATH=$PWD/BaseTools
# If you are compiling for ARM, then this is needed
sudo apt install gcc-aarch64-linux-gnu        # Or whatever your package manager is
export GCC5_AARCH64_PREFIX=aarch64-linux-gnu-

# Run this no matter what you are compiling for
source edksetup.sh

The last step generates various configuration files and sets up some variables. Note that edksetup.sh must be sourced, as its variables must persist. Now we need to build the base tools

make -C BaseTools

And lastly, we must actually build EDK2 using its Python build script.

build -a YOUR_ARCH -t GCC5 -p YOUR_PACKAGE

YOUR_ARCH can be IA32, X64, AARCH64, or RISCV64. Note that not all packages compile for all architectures. YOUR_PACKAGE must point to a package in the source tree. If you want to build the UEFI library,