UEFI and EDK II

Last update: 2022-04-13 08:27:02 +0800 +0800
tags: Edk-Ii | Firmware | Uefi
Available translations: 日本語 / 中文(简体) / 中文(繁體)

UEFI is the firmware interface between platform firmware and an operating system. The UEFI Forum publishes the UEFI and Platform Initialization (PI) specifications; EDK II is the TianoCore reference implementation and build environment.

Boot Phases #

The PI architecture divides early firmware execution into phases. Pre-EFI Initialization (PEI) begins with little more than the CPU and temporary storage. The PEI Foundation runs PEI modules (PEIMs), publishes PPIs (PEIM-to-PEIM interfaces), and uses hand-off blocks (HOBs) to describe discovered resources. Its central job is to initialize sufficient RAM for the next phase.

The Driver Execution Environment (DXE) then loads drivers and services from firmware volumes, installs UEFI protocols, and constructs the UEFI system tables. Boot Device Selection chooses and loads an operating-system boot option. After ExitBootServices, the operating system owns normal boot-time hardware resources; UEFI runtime services remain available only where the platform supports them. ACPI tables describe hardware and power-management interfaces to the operating system.

Firmware Images #

A flash device (FD) is the physical or logical firmware image. It contains one or more firmware volumes (FVs), which are formatted containers—normally using the Firmware File System (FFS). FFS files package executable sections, raw data, compression sections, and other firmware content. An FDF file describes how these pieces become FFS files, FVs, update capsules, option ROMs, and finally an FD image.

Most modules are relocatable and are loaded into RAM. Execute-in-place modules are linked for a fixed ROM address and can run directly from flash; some modules support both modes.

EDK II Metadata and Build Flow #

EDK II packages use several declarative files:

  • A .dec package declaration publishes GUIDs, protocols, library classes, and include paths.
  • An .inf module-information file describes a module’s sources, dependencies, library classes, packages, and build options. It can describe source, binary, or mixed content; the build produces an AsBuilt INF for source modules.
  • A .dsc platform-description file selects components, library instances, toolchain settings, and platform-wide configuration. .dsc.inc files factor shared fragments.
  • An .fdf flash-definition file lays out the final firmware image.

BaseTools reads this metadata, resolves libraries, and generates AutoGen.c and AutoGen.h. The selected toolchain compiles source files and archives library objects. The linker produces an intermediate image, often named .dll even on a non-Windows host. GenFw converts it to the PE/COFF EFI image (.efi), setting the appropriate EFI subsystem, such as an EFI boot-service driver. Modules are then packaged into FFS files, FVs, and the final FD image.

Human Interface Infrastructure (HII) is the umbrella for firmware resources intended for people: string, font, image, and setup-form (IFR) databases.

Migrated Reference Material #

EFISTUB is a feature of the Linux kernel that allows the vmlinux to be invoked directly as an EFI application, thus eliminating the necessity of using a bootloader e.g. GRUB2.

First, check that your kernel has EFISTUB enabled:

sh
zgrep 'CONFIG_EFI_STUB' /proc/config.gz

Then, create a new UEFI booting entry by:

sh
efibootmgr --create
    --disk ... # device node e.g. /dev/sdX
    --part ... # partition number
    --label ... # Entry Nickname
    --loader '/vmlinuz-linux'    # the executable path under the given partition
    --unicode       # interpret the following string in UCS-2 as argument to the EFI application, in our case, the kernel
    'root=UUID=01a40dd8-28f0-4636-be1e-aeed60c98095 resume=UUID=2d877d5d-4ca1-4d46-a3d6-b6ee94cbbd78 rw rootflags=subvol=@ loglevel=3 quiet initrd=\initramfs-linux-lts.img'        # kernel arguments

efibootmgr is provided by the efibootmgr package; check your distro package manager or visit https://github.com/rhboot/efibootmgr.

Comments

Read or comment on GitHub (sign-in required to comment)