A Tour Beyond BIOS Capsule Update and Recovery in EDK II
A Tour Beyond BIOS Capsule Update and Recovery in EDK II
Jiewen Yao
Intel Corporation
Vincent J. Zimmer
Intel Corporation
December 2016
i
This paper is for informational purposes only. THIS DOCUMENT IS PROVIDED "AS IS" WITH NO
WARRANTIES WHATSOEVER, INCLUDING ANY WARRANTY OF MERCHANTABILITY,
NONINFRINGEMENT, FITNESS FOR ANY PARTICULAR PURPOSE, OR ANY WARRANTY
OTHERWISE
ARISING OUT OF ANY PROPOSAL, SPECIFICATION OR SAMPLE. Intel disclaims all liability,
including liability for infringement of any proprietary rights, relating to use of information in this
specification. No license, express or implied, by estoppel or otherwise, to any intellectual
property rights is granted herein.
Intel, the Intel logo, Intel. leap ahead. and Intel. Leap ahead. logo, and other Intel product name
are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United
States and other countries.
*Other names and brands may be claimed as the property of others.
Copyright © 2016 by Intel Corporation. All rights reserved
ii
Executive Summary
Introduction
The firmware update capability represents an important feature for the system
firmware on the mother board and the various device firmware instances, such as a
host bus adapter-attached PCI option ROM, embedded controller (EC), baseboard
management controller (BMC), etc. The firmware recovery is also a feature to support
firmware boot in recovery mode in cases where the main flash image is errant or
corrupt.
In [EDK II Security Design], we described general security design guidelines for
firmware update and firmware recovery. In this paper, we provide more details on how
we implement capsule update and recovery in EDK II.
iii
Table of Contents
Executive Summary ......................................................................................................................... iii
Introduction ................................................................................................................................. iii
Firmware Update............................................................................................................................. 6
NIST Standard .............................................................................................................................. 6
Hardware Compatibility Specification for Systems for Windows 10 .......................................... 6
Windows UEFI Firmware Update Platform ................................................................................. 6
UEFI Specification ........................................................................................................................ 7
PI Specification ............................................................................................................................ 8
Summary.................................................................................................................................. 8
UEFI FMP Capsule Update ............................................................................................................... 9
Capsule Update General Flow ..................................................................................................... 9
Execution Environment ............................................................................................................. 11
Authentication Check ................................................................................................................ 12
FMP Payload check ................................................................................................................ 12
FMP driver check ................................................................................................................... 12
Capsule image not for firmware update ................................................................................... 13
PI Capsule Coalesce ................................................................................................................... 13
Capsule Coalesce Flow .............................................................................................................. 15
Capsule Coalesce for IA32 PEI and X64 DXE .............................................................................. 22
Summary................................................................................................................................ 23
EDK II System FMP Capsule Update .............................................................................................. 24
EDK II System Firmware Binary Update Image Format ............................................................. 24
Authentication Check ................................................................................................................ 25
EDK II System FMP Capsule Update Driver ............................................................................... 26
Pre-Installation Check................................................................................................................ 27
Variable Update Consideration ................................................................................................. 28
Summary................................................................................................................................ 28
EDK II EFI System Resource Table .................................................................................................. 29
EFI System Resource Table Driver ............................................................................................. 29
iv
Summary................................................................................................................................ 30
Microcode Update ......................................................................................................................... 31
EFI_FIRMWARE_MANAGEMENT_PROTOCOL ........................................................................... 31
EFI_FIRMWARE_MANAGEMENT_CAPSULE .............................................................................. 33
EFI System Resource Table ........................................................................................................ 34
UEFI Microcode Update Driver.................................................................................................. 35
Summary................................................................................................................................ 35
Recovery ........................................................................................................................................ 36
Recovery General Flow .............................................................................................................. 36
Authentication Check ................................................................................................................ 37
Summary................................................................................................................................ 38
EDK II System FMP Based Recovery .............................................................................................. 39
EDK II Recovery Image Format .................................................................................................. 39
Authentication Check ................................................................................................................ 39
FMP Capsule Recovery Driver ................................................................................................... 39
Summary................................................................................................................................ 40
Acknowledgments ......................................................................................................................... 41
References ..................................................................................................................................... 42
v
Firmware Update
A system may need to update the firmware image. There are some industry standards
providing the guideline or the definition for the firmware update listed below.
NIST Standard
To begin, the National Institute of Standards and Technology (NIST) provides the security
guidelines on BIOS update, such as 800-147: BIOS Protection Guidelines [NIST-1] and 800-
147B: BIOS Protection Guidelines for Servers [NIST-2]. The summary is below:
– BIOS Update Authentication
– Key storage in Root of Trust for Update (RTU)
– Recovery mechanisms shall also use the authenticated update mechanism unless
the recovery process meets the guidelines for a secure local update.
– Rollbacks of the BIOS to an earlier version are permitted only if the update or
rollback has been authorized by the organization.
– Secure Local Update (optional)
– The local update mechanism be used only to load the first BIOS image or to
recover from a corruption of a system BIOS
– Integrity Protection
– The RTU and the system BIOS shall be protected from unintended modification.
– Non-Bypassability
– Bus mastering that bypasses the main processor (e.g., Direct Memory Access to the
system flash) shall not be capable of directly modifying the firmware.
– Microcontrollers on the system shall not be capable of directly modifying the
firmware.
This document defined the general security requirement for firmware update. It does not
define in detail either the firmware update capsule format or the details of the update process.
In order to maintain the integrity of the platform firmware, Microsoft describes a “Secure
firmware update process” in [Win10 HCS]. The requirement is aligned with the NIST standard,
such as including a signed bios update and rollback protection.
Microsoft provides “Windows UEFI Firmware Update Platform [WFU]” to define how to
perform firmware updates initiated by Windows. The summary is below:
– Support Capsule API
– Firmware updates initiated by Windows
– Specify firmware resource in ESRT
6
This document also defines a set of pre-installation criteria, such as:
– Power Check (25% battery charge)
– Security Check
– Integrity Check
– Version Check
– Storage Check
Figure 1 shows the components involved in a Windows UEFI Firmware Update Platform. This
document defines a capsule package format used in Windows, which is the “Microsoft Signed”
box below. It does not define the capsule image format, which is the “OEM-signed” box below.
UEFI Specification
The platform may consume a system FMP and a device FMP protocol to get the firmware
image information and report the ESRT to a UEFI OS.
An OS agent may call the UEFI service UpdateCapsule() to pass the capsule image from the OS
to the firmware. Based upon the capsule flags, the firmware may process the capsule image
immediately, or the firmware may reset the system and process the capsule image on the next
boot.
The FMP capsule image format is shown in figure 2. It contains the update FMP drivers and the
FMP payloads. The FMP payload contains the binary update image and optional vendor code.
7
The platform may consume a FMP protocol to update the firmware image.
This document defines the detailed processing of the capsule image and the capsule image
format, but it does not define the format of binary update image. The latter can be
implementation choice.
PI Specification
This document defines how to report a capsule image in the firmware. It also does not define
the capsule image format.
Summary
This section introduces the firmware update related specifications.
8
UEFI FMP Capsule Update
For security considerations, the flash device is locked during the system boot. As such, it might
not be possible to update the flash device directly in an operating system.
As an alternative, one possible way is that the operating system sends a firmware image to the
system and lets the system update the flash device before the flash device is locked in next
boot. See figure 4.
This firmware image is called a “capsule”. The UEFI specification defines a set of capsule
services to let operating system pass the information to the firmware. The UEFI specification
also defines the capsule image format for the EFI_FIRMWARE_MANAGEMENT_PROTOCOL
(FMP).
EDK II provides the sample drivers to performance the signed system firmware update via the
capsule interface. It follows the NIST standard, Microsoft design and the UEFI specification.
9
The capsule update general flow is below (See figure 5):
NOTE: In many cases, a capsule is used for firmware update. As such, many platforms
choose BOOT_ON_FLASH_UPDATE as the Boot mode to indicate that there is capsules need
to be processed. However, a capsule might be used for other purposes, such as
information passing, and a capsule is only required to be populated in the
EFI_SYSTEM_TABLE. Care must be taken to handle the capsule images other than
firmware update.
10
2) After the Memory Reference Code (MRC) module initializes system memory, the platform
PEI module (such as
https://github.com/tianocore/edk2/blob/master/QuarkPlatformPkg/Platform/Pei/PlatformInit/Mrc
Wrapper.c) calls PEI_CAPSULE_PPI.Coalesce() to determine the current location of the
various capsule fragments and coalesce them into a contiguous region of system memory.
Then the platform PEI module calls EFI_PEI_SERVICES.InstallPeiMemory(), to register the
found memory configuration with the PEI Foundation. The contiguous region for capsule
must be excluded in the PEI memory. Finally, the platform PEI module calls
PEI_CAPSULE_PPI.CreateState() to copy the capsules into PEI memory and to create a
EFI_HOB_UEFI_CAPSULE. At this point, the following PEI/DXE/SMM modules can know
the location of the coalesced UEFI capsule memory pages.
3) After the platform enters the BDS phase, the BDS detects boot mode (such as
https://github.com/tianocore/edk2/blob/master/QuarkPlatformPkg/Library/PlatformBootManagerL
ib/PlatformBootManager.c) If the current boot mode is BOOT_ON_FLASH_UPDATE, the BDS calls
CapsuleLib:ProcessCapsules()
(https://github.com/tianocore/edk2/tree/master/MdeModulePkg/Library/DxeCapsuleLibFmp) to
process capsule images. BDS should call ProcessCapsules() twice. The first call must be before
EFI_END_OF_DXE_EVENT, because the system flash part is locked after EFI_END_OF_DXE_EVENT.
The system capsule must be processed in first call. If a device capsule FMP protocol is produced and
the device capsule FMP has zero EmbeddedDriverCount, the device capsule is also processed.
4) ProcessCapsules() parses CAPSULE_HOB and processes the satisfied capsule images one
by one. If a Windows UX capsule exists, it is processed first. If the capsule image is a UEFI
defined FMP capsule, the ProcessFmpCapsuleImage() is called.
Execution Environment
Per the NIST guideline, the flash update operation must happen in a secure environment. It
11
could be in firmware boot phase before EndOfDxe, or in SMM. The EDK II Capsule update
solution chooses to update the system firmware before EndOfDxe because the flash region
remains open until the EndOfDxe. This latter usage is sometimes called ‘temporal isolation’
since no 3rd party code should execute prior to the EndOfDxe. Only system board vendor PI
modules and drives should execute.
Authentication Check
The capsule update solution needs to follow NIST standard to verify the image.
Below figure 6 shows a sample of device firmware capsule verification. It has a device update
driver in capsule image. UEFI secure boot needs to verify the device update driver. The device
update driver needs to verify the device firmware payload in the FMP capsule.
12
Figure 6 – FMP capsule Driver and Payload Authentication
The device payload verification is device implementation specific. It may use the UEFI
specification defined EFI_FIRMWARE_IMAGE_AUTHENTICATION or use a hardware
mechanism, such as Intel CPU Microcode Load. (The details of Microcode Update will be
discussed later.)
PI Capsule Coalesce
The capsule contents are designed to be communicated from an OS-present environment into
the system firmware. The OS allocates contiguous virtual address space and describes this
address space to the firmware as a discontinuous set of physical address ranges. The firmware
is passed both physical and virtual addresses and pointers to describe the capsule so the
firmware can process the capsule immediately or defer processing of the capsule until after a
system reset.
See figure 7. The left side of the figure shows the OS view of the capsules as two separate
contiguous virtual memory buffers. The center of the figure shows the layout of the data in
system memory. The right hand side of the figure shows the scatter gather list passed into the
firmware.
EFI_PEI_CAPSULE_PPI.Coalesce() parses the current location of the various capsule
fragments and coalesces them into a contiguous region of system memory.
13
Figure 7 –Scatter-Gather List of UEFI Capsule
The capsule coalesce action needs to parse the scatter gather list, which is an external source.
It must do some basic sanity checking of the scatter gather. The EDK II capsule PEIM driver
does such checks based upon the EFI_RESOURCE_DESCRIPTION_HOB. The memory
initialization component (such as MRC) should report all DRAM regions via
EFI_RESOURCE_DESCRIPTION_HOB. If the capsule fragment is inside of DRAM, it is
considered as valid, or it is invalid and this capsule should be rejected. See figure 8.
14
Capsule Coalesce Flow
See figure 9.0 for the general coalesce flow. The CapsulePeim
(https://github.com/tianocore/edk2/tree/master/MdeModulePkg/Universal/CapsulePei) driver gets
capsule memory from memory initialization component. It parses the capsule scatter gather
list, puts all of the EFI_CAPSULE_BLOCK_DESCRIPTOR entries at the end of capsule memory,
allocates free memory and puts all capsule fragments together in the capsule memory.
15
Figure 9.1 – Capsule Coalesce – FindFreeMem() step 1.1
– Step 1.2: Overlap check for descriptor blocks. It goes through all the descriptor
blocks to see if there is overlap between the free buffer candidate and descriptor
blocks.
– Step 1.3: Move data up in case of overlap. If there is overlap, then the free buffer
candidate is moved up to eliminate the overlap.
16
Figure 9.3 – Capsule Coalesce – FindFreeMem() step 1.3
– Step 1.4: Overlap check for capsule data fragment. It goes through all the capsule
data fragment to see if there is overlap between the free buffer candidate and
capsule data fragment.
– Step 1.5: Move data up in case of overlap. If there is overlap, then the free buffer
candidate is moved up to eliminate the overlap.
17
Figure 9.5 – Capsule Coalesce – FindFreeMem() step 1.5
– Step 2.2: Overlap check. It goes through all the descriptor blocks and capsule
fragments to see if there is overlap between the capsule block descriptor candidate
and descriptor blocks or the capsule fragments.
18
Figure 9.7 – Capsule Coalesce – RelocateBlockDescriptors () step 2.2
– Step 2.3: Move data up in case of overlap. If there is overlap, then the overlapped
descriptor blocks or capsule fragments are moved up to free memory.
FindFreeMem() is used to find out the free memory location. The candidate
memory is still in its original place and untouched.
– Step 2.4: Relocate. Now there is no useful content in candidate memory. The
capsule block descriptors are relocated into the candidate memory.
19
Figure 9.9 – Capsule Coalesce – RelocateBlockDescriptors () step 2.4
– Step 3.2: Overlap check. It goes through all the capsule fragment to see if there is
overlap between the capsule block descriptor candidate and capsule fragment.
20
Figure 9.11 – Capsule Coalesce – CapsuleDataCoalesce () step 3.2
– Step 3.3: Move data down in case of overlap. If there is overlap, then the
overlapped capsule fragment is moved down to free memory. FindFreeMem() is
used to find out the free memory location. The candidate memory is still in original
place and untouched.
– Step 3.4: Relocate. Now there is no useful content in candidate memory. The
capsule data fragments are relocated into the candidate memory.
21
Figure 9.13 – Capsule Coalesce – CapsuleDataCoalesce () step 3.4
22
the memory reported via the UEFI memory map. As such, the capsule images should be
covered by the UEFI memory map. There is a special configuration in Intel X86 firmware - the
PEI phase is 32bit and the DXE phase is 64bit. The mode transition happens in DXE IPL. In
such a case, the 32bit PEI Capsule module should handle the 64bit address space because the
OS may put the capsule block descriptor or data fragments above 4GiB memory.
Summary
This section introduces the capsule update in the UEFI/PI firmware.
23
EDK II System FMP Capsule Update
Because the UEFI specification does not define detailed format for the FMP binary update
image, EDK II defines its own system firmware binary update image format. This format is EDK
II specific. The IBV/OEM may choose different image formats to perform the same function.
EDK II system FMP capsule reuses the UEFI specification defined FMP capsule with
EFI_FIRMWARE_IMAGE_AUTHENTICATION. The payload image is one PI Firmware Volume. It
includes:
– Firmware update configuration file (SysFirmUpdateConfig.ini). This configuration file
describe the content in the system firmware. (Such as
https://github.com/tianocore/edk2/blob/master/QuarkPlatformPkg/Feature/Capsule/SystemFirmw
areUpdateConfig/SystemFirmwareUpdateConfig.ini) The format of the capsule update
configuration is defined at
https://github.com/tianocore/edk2/blob/master/SignedCapsulePkg/Include/Guid/EdkiiSystemFmpC
apsule.h. User may choose to use one entry to describe the whole FD image directly, or to
use multiple entries to describe each FV regions one by one. User must make sure that the
FirmwareType field is filled correctly to describe if the component is used as a variable
region. More detail is discussed in “Variable Update Consideration” later.
– Driver FV. This is a nested FV, which contains a system firmware update FMP driver.
(SysFirmUpdate.efi).
(https://github.com/tianocore/edk2/tree/master/SignedCapsulePkg/Universal/SystemFirmwareUpd
ate)
– System Firmware Binary. This is raw binary data to be updated into flash region.
– Image Description. In FvRecovery of the system firmware, there is an image description
data. It contains the data in EFI_FIRMWARE_IMAGE_DESCRIPTOR. (Such as
https://github.com/tianocore/edk2/tree/master/QuarkPlatformPkg/Feature/Capsule/SystemFirmw
areDescriptor)
See figure 11.
24
Figure 11 – EDK II Signed System FMP capsule format
Authentication Check
Below figure 12 shows EDK II system FMP capsule verification. SysFirmUpdate.efi
(https://github.com/tianocore/edk2/blob/master/SignedCapsulePkg/Universal/SystemFirmwareUpdate
/SystemFirmwareUpdateDxe.inf) is insides of FMP capsule, which supports SetImage() to update
firmware. SysFirmReport.efi
(https://github.com/tianocore/edk2/blob/master/SignedCapsulePkg/Universal/SystemFirmwareUpdate
/SystemFirmwareReportDxe.inf) is in the current firmware, which supports SetImage() to verify and
dispatch the SysFirmUpdate.efi, then pass through the SetImage() request to SystemFirmUpdate.efi. The
SysFirmReport.efi calls EdkiiSystemCapsuleLib to verify the EFI_FIRMWARE_IMAGE_AUTHENTICATION
and version in system FMP capsule image, then load SysFirmUpdate.efi driver to perform the update
request.
25
EDK II System FMP Capsule Update Driver
In the current firmware image, there is a system firmware report driver (SysFirmReport.efi). Its
job is to get the image description and install a simple FMP to report the current firmware
information via EFI_FIRMWARE_MANAGEMENT_PROTOCOL.GetImageInfo().
When the FMP capsule is processed, the system firmware report driver (SysFirmReport.efi)
EFI_FIRMWARE_MANAGEMENT_PROTOCOL.SetImage() function verifies and dispatches the
DriverFv inside of the FMP capsule image. Then the SysFirmUpdate.efi is started. Then the
SysFirmReport.efi passes the SetImage() request to the SysFirmUpdate.efi. Finally,
SysFirmUpdate.efi driver gets the FMP capsule, does the verification again processes the FMP
payload, and update the system firmware image on flash.
26
– Step 1: When a platform BDS detects BOOT_ON_FLASH_UPDATE boot mode, it calls
CapsuleLib
(https://github.com/tianocore/edk2/tree/master/MdeModulePkg/Library/DxeCapsuleLibF
mp) ProcessCapsules() to process the capsules. The ProcessCapsules() need check
capsule images one by one. If a capsule has
CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE flag, this capsule is installed to UEFI
configuration table. If the capsule GUID is WINDOWS_UX_CAPSULE_GUID, this capsule
will be processed at first to display the BMP image on screen. If the capsule GUID is
EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID, this is FMP capsule. It will be
processed by CapsuleLib ProcessCapsuleImage(). The later locates all
EFI_FIRMWARE_MANAGEMENT_PROTOCOL and calls corresponding
EFI_FIRMWARE_MANAGEMENT_PROTOCOL.SetImage() if
EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER.UpdateImageTypeId
matches EFI_FIRMWARE_IMAGE_DESCRIPTOR.ImageTypeId.
– Step 2: If the FMP capsule is an EDK II system FMP capsule, the SetImage() in
SysFirmReport.efi
(https://github.com/tianocore/edk2/blob/master/SignedCapsulePkg/Universal/SystemFir
mwareUpdate/SystemFirmwareReportDxe.c) is invoked. The later will parse and verify the
FMP capsule to check the integrity, because the capsule is treated as an external source
and it is not trusted.
– Step 3: After FMP capsule passes the authentication, this FMP capsule payload is treated
as trusted. The SetImage() in SysFirmReport.efi extracts the driver FV from FMP capsule
payload and calls EFI_DXE_SERVICES.ProcessFirmwareVolume() and
EFI_DXE_SERVICES.Dispatch() to dispatch the drivers inside of the driver FV. If there is a
system firmware update driver - SysFirmUpdate.efi
(https://github.com/tianocore/edk2/blob/master/SignedCapsulePkg/Universal/SystemFir
mwareUpdate/SystemFirmwareUpdateDxe.inf) inside of the capsule, it is started now. This
module installs EFI_FIRMWARE_MANAGEMENT_PROTOCOL with an internal
SYSTEM_FMP_PROTOCOL_GUID.
– Step 4: After CapsuleLib dispatches the FV, the SetImage() in SysFirmReport.efi locates
SYSTEM_FMP_PROTOCOL_GUID and passes through the EDK II system FMP capsule to
the SetImage() in SysFirmUpdate.efi.
– Step 5: Then the SetImage() in SysFirmUpdate.efi parses and verifies payload, and extracts
the real firmware binary.
(https://github.com/tianocore/edk2/blob/master/SignedCapsulePkg/Universal/SystemFir
mwareUpdate/SystemFirmwareUpdateDxe.c)
– Step 6: Finally, the real firmware binary is updated to flash area in PerformUpdate(). A
platform must link a correct PlatformFlashAccessLib to perform the flash update. (Such as
https://github.com/tianocore/edk2/tree/master/QuarkPlatformPkg/Feature/Capsule/Libra
ry/PlatformFlashAccessLib)
Pre-Installation Check
The EDK II system firmware FMP capsule should also support pre-installation check which is
defined by Microsoft [WFU]. The integrity/security/version check requirement is similar to
27
NIST guideline. They are already discussed in “Authentication Check” section. The power
check should be platform specific. If a platform supports battery, we expect the platform BDS
should add such battery check before call CapsuleLib ProcessCapsules().
However, for system firmware update, it becomes a problem, because the variable region
might inside of the system firmware region. If the system firmware update also updates the
variable region, the variable data should never be used after update. The EDK II System
firmware update will hook the variable services and return an error directly to prevent
accessing original variable region.
Then the following question arises: How can the system firmware update driver know if the
variable region is updated or not? This information is recorded in the Firmware update
configuration file. If the firmware type is NvRam, then the update driver knows the variable
region will be updated.
Sometimes, when the system performs an update, it wants to preserve some of the current
configuration setting, such as setup configuration, or the secure boot variable. Because it is
platform policy on which variable should be preserved, the system firmware update driver
leaves the work to the PlatformFlashAccessLib. One possible way is described below:
– When the PlatformFlashAccessLib finds it needs to update the variable region, it copies all
of the UEFI variables to a local cache.
– The PlatformFlashAccessLib selects some of the variables to be preserved based upon the
platform policy.
– The PlatformFlashAccessLib parses the variable region of the new firmware source buffer
and patches the variable region with the preserved variable data.
– The PlatformFlashAccessLib writes the final patched variable region onto the system flash
region.
Summary
This section introduces the EDK II system FMP capsule update solution in EDK II.
28
EDK II EFI System Resource Table
29
On right hand side, the ESRT driver consumes EFI_FIRMWARE_MANAGEMENT_PROTOCOL. A
firmware update driver may produce EFI_FIRMWARE_MANAGEMENT_PROTOCOL. ESRT
driver calls EFI_FIRMWARE_MANAGEMENT_PROTOCOL,GetImageInfo() to get the firmware
information and converts this data into a ESRT entry. The FMP ESRT information is saved to
the L"EsrtFmp" variable.
The reason for caching ESRT information into variable is that the capsule update may cause a
system reset as the last step of the firmware update. As such, the ESRT must record the
update state in the next boot in order to report such information to the OS.
Summary
This section introduces the ESRT solution in EDK II.
30
Microcode Update
“Intel® 64 and IA-32 Architectures Software Developer’s Manual” [IA32SDM] defines an
“Optional Processor Microcode Update Specifications” in the “Microcode Update Facilities”
chapter. An INT15 D042 interface is defined to read and write the Microcode from and to a
system firmware non-volatile area.
The INT15 services is only available on a legacy BIOS, or a UEFI firmware with the
Compatibility Support Module (CSM) to support the legacy OS boot. However, there are more
and more UEFI firmware without CSM because these UEFI firmware support the UEFI OS only
without a CSM. As a result, there is no way to produce the INT15 service in these UEFI OS
instances. We need to define a similar UEFI style interface for the UEFI firmware.
EFI_FIRMWARE_MANAGEMENT_PROTOCOL
The Microcode update module in UEFI firmware produces an
EFI_FIRMWARE_MANAGEMENT_PROTOCOL and returns the
EFI_FIRMWARE_IMAGE_DESCRIPTOR with the below
MICROCODE_FMP_IMAGE_TYPE_ID_GUID as ImageTypeId in GetImageInfo(). If the system
has more than one Microcode, each Microcode maps to one
EFI_FIRMWARE_IMAGE_DESCRIPTOR.
31
The meaning of each field in the EFI_FIRMWARE_IMAGE_DESCRIPTOR is described below:
32
a) Status: EFI_INCOMPATIBLE_VERSION
b) AbortReason: L“InvalidLoaderVersion”
c) LastAttemptVersion: The update version.
d) LastAttemptStatus: LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT
3) The update block must checksum. This checksum is computed as a 32-bit summation of
all double words in the structure, including the header, data, and processor signature
table. The violation causes:
a) Status: EFI_VOLUME_CORRUPTED
b) AbortReason: L“InvalidChecksum”
c) LastAttemptVersion: The update version.
d) LastAttemptStatus: LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT
4) The processor signature in the proposed update must be equal to the current processor
signature. The violation causes:
a) Status: EFI_UNSUPPORTED
b) AbortReason: L“UnsupportedProcessSignature”.
c) LastAttemptVersion: The update version.
d) LastAttemptStatus: LAST_ATTEMPT_STATUS_ERROR_INCORRECT_VERSION
5) The processor flags in the proposed update must match the current platform ID. The
violation causes:
a) Status: EFI_UNSUPPORTED
b) AbortReason: L”UnsupportedProcessorFlags” for the flags mismatch.
c) LastAttemptVersion: The update version.
d) LastAttemptStatus: LAST_ATTEMPT_STATUS_ERROR_INCORRECT_VERSION
6) The update revision in the proposed update should be greater than the update revision in
the header of the current update in NVRAM. The violation causes:
a) Status: EFI_INCOMPATIBLE_VERSION
b) AbortReason: L“IncorrectRevision”
c) LastAttemptVersion: The update version.
d) LastAttemptStatus: LAST_ATTEMPT_STATUS_ERROR_INCORRECT_VERSION
7) The firmware must verify the authenticity of the update via the mechanism described in
IA32 SDM “Microcode Update Loader”. The violation causes:
a) Status: EFI_SECURITY_VIOLATION
b) AbortReason: L“InvalidData”
c) LastAttemptVersion: The update version.
d) LastAttemptStatus: LAST_ATTEMPT_STATUS_ERROR_AUTH_ERROR
EFI_FIRMWARE_MANAGEMENT_CAPSULE
The EFI_FIRMWARE_MANAGEMENT_PROTOCOL is a UEFI boot time protocol, so it cannot be
called at OS runtime. In order to support initiating Microcode update from the OS, a Microcode
FMP capsule can be used.
33
FMP payloads.
An OEM firmware capsule process driver needs to parse the Microcode FMP capsule as a
normal FMP capsule, and uses UpdateImageTypeId to locate the correct Microcode
EFI_FIRMWARE_MANAGEMENT_PROTOCOL. Then the capsule process driver calls
EFI_FIRMWARE_MANAGEMENT_PROTOCOL.SetImage() for the new Microcode in the FMP
payload.
34
The meaning of each field in the EFI_SYSTEM_RESOURCE_ENTRY is below:
NOTE: There might be multiple Microcode on a system firmware non-volatile storage area.
Summary
This section discussed the Microcode Update in a UEFI firmware.
35
Recovery
Firmware recovery is a feature to allow a system to continue booting if the part of flash region
is corrupt or errant. The flash region corruption should not happen, but in case of such an
occurrence, the end user may use a recovery image on a CDROM or a USB key to boot the
system and perform a flash update.
36
BOOT_IN_RECOVERY_MODE.
– Step 2: A RecoveryModule is the producer of EFI_PEI_RECOVERY_MODULE_PPI. It
consumes EFI_PEI_DEVICE_RECOVERY_MODULE_PPI.
– Step 3: The PEI file system driver is the producer of
EFI_PEI_DEVICE_RECOVERY_MODULE_PPI. In EDK II, these modules include CdExpressPei
(https://github.com/tianocore/edk2/tree/master/MdeModulePkg/Universal/Disk/CdExpres
sPei) and FatPei (https://github.com/tianocore/edk2/tree/master/FatPkg/FatPei). They
consume EFI_PEI_RECOVERY_BLOCK_IO_PPI or EFI_PEI_RECOVERY_BLOCK_IO2_PPI.
– Step 4: The PEI block IO driver is the producer of EFI_PEI_RECOVERY_BLOCK_IO_PPI or
EFI_PEI_RECOVERY_BLOCK_IO2_PPI. In EDK II, these modules are UsbBotPei
(https://github.com/tianocore/edk2/tree/master/MdeModulePkg/Bus/Usb/UsbBotPei),
IdeBusPei
(https://github.com/tianocore/edk2/tree/master/MdeModulePkg/Bus/Pci/IdeBusPei),
EmmcBlockIoPei
(https://github.com/tianocore/edk2/tree/master/MdeModulePkg/Bus/Sd/EmmcBlockIoPei
), and UfsBlockIoPei
(https://github.com/tianocore/edk2/tree/master/MdeModulePkg/Bus/Ufs/UfsBlockIoPei).
These PEIM’s are the modules to load the capsule from a storage device into memory.
– Step 5: Once the RecoveryModule retrieves the recovery image, it will parse and verify the
recovery image to check the integrity and extract the Firmware Volume for the DXE phase.
– Step 6: Finally, the RecoveryModule installs the extracted Firmware Volume for DXE. It
builds EFI_HOB_FIRMWARE_VOLUME and installs
EFI_PEI_FIRMWARE_VOLUME_INFO_PPI or EFI_PEI_FIRMWARE_VOLUME_INFO2_PPI.
Authentication Check
The authentication check in the recovery is similar to the one in the firmware update process.
The recovery image should be signed and version should be checked.
– Signing check: The signing check for the recovery is similar to the one for the capsule
update. The UEFI FMP capsule uses the EFI_FIRMWARE_IMAGE_AUTHENTICATION
before the real payload image. However the certificate type can be different one such as
EFI_CERT_TYPE_RSA2048_SHA256_GUID. The reason is that the boot block may only
have limited space to hold the singing verification algorithm. The PKCS1 RSA verification
need smaller runtime memory than the PKCS7 verification. In EDK II, the RSA2048SHA256
signature check is at
https://github.com/tianocore/edk2/tree/master/SecurityPkg/Library/FmpAuthenticationLibRsa2048
Sha256.
– Version check: The version check for recovery is different with the one for the capsule
update. In recovery boot mode, the version in the capsule image must be the same as the
version in current firmware. The reason is that the DXE FV might have a special
dependency on the PEI FV.
1) PCD database: The DXE PCD database is inherited from the PEI PCD database. If the
DXE FV and PEI FV are different, there might be mismatches in the PCD database. In
this case the behavior is undefined.
37
The internal PCD database information can be found at
https://github.com/tianocore/edk2/blob/master/MdeModulePkg/Universal/PCD/Pei/Pcd.inf.
There exists a tool to dump the PCD information and PCD internal database at
https://github.com/jyao1/EdkiiShellTool/tree/master/EdkiiShellToolPkg/PcdDump.
2) Hob: DXE FV may depend on some HOB information produced by the PEI FV.
3) System State: the DXE FV may depend upon some system state initialization in the PEI
phase.
Because of the above known potential issues, it is strongly recommend to use the same BIOS
image for the recovery flow.
In EDK II, one image version check sample for capsule update is done in the
EdkiiSystemCapsuleLib at
https://github.com/tianocore/edk2/tree/master/SignedCapsulePkg/Library/EdkiiSystemCapsuleLib. If
other signed recovery solution is used, it need provide similar function to check the version.
Summary
This section introduces the recovery design in UEFI/PI firmware.
38
EDK II System FMP Based Recovery
Authentication Check
The authentication check in the recovery is similar to the one in the firmware update. We
discussed the difference in previous chapter. RecoveryModuleLoadPeim links
EdkiiSystemCapsuleLib to perform the check.
39
Figure 18 – Recovery Flow
– Once RecoveryModuleLoadPeim
(https://github.com/tianocore/edk2/tree/master/SignedCapsulePkg/Universal/RecoveryModuleLoa
dPei) retrieves the FMP capsule. It will invoke EdkiiSystemCapsuleLib
(https://github.com/tianocore/edk2/tree/master/SignedCapsulePkg/Library/EdkiiSystemCapsuleLib)
to parse and verify the FMP capsule to check the integrity, because the capsule is treated as an
external source and it is not trusted.
– If the verification succeeds, the real recovery binary is extracted. The
RecoveryModuleLoadPeim needs to parse the same capsule configuration file (Such as
https://github.com/tianocore/edk2/blob/master/QuarkPlatformPkg/Feature/Capsule/SystemFirmw
areUpdateConfig/SystemFirmwareUpdateConfig.ini) to know which region is the DXE FV for
recovery.
The format of the recovery configuration is defined at
https://github.com/tianocore/edk2/blob/master/SignedCapsulePkg/Include/Guid/EdkiiSystemFmpC
apsule.h.
– Finally, the DXE FV for recovery is found. The RecoveryModuleLoadPeim builds
EFI_HOB_FIRMWARE_VOLUME and installs EFI_PEI_FIRMWARE_VOLUME_INFO_PPI or
EFI_PEI_FIRMWARE_VOLUME_INFO2_PPI. If there are multiple FVs needed for DXE phase, the
user must define all those regions in the configuration file one by one.
Summary
This section introduces the EDK II system FMP based recovery solution in EDK II.
40
Acknowledgments
We would like to thank Michael D Kinney, Chao Zhang, Liming Gao, Star Zeng, David Wei,
Karunakara Kotary, Nandagopal Sathyanarayanan, Sugumar Govindarajan, Rock Cao, Qing
Huang and Sean Brogan who reviewed the EDK II capsule update solution and gave valuable
technical feedback when we designed the EDK II signed capsule and signed recovery solution.
41
References
[UEFI] Unified Extensible Firmware Interface (UEFI) Specification, Version 2.6 www.uefi.org
[EDK II Security Design] Jiewen Yao, Vincent Zimmer, A Tour Beyond BIOS - Security
Design Guide in EDK II, https://github.com/tianocore-
docs/Docs/raw/master/White_Papers/A_Tour_Beyond_BIOS_Securiy_Enhancement_t
o_Mitigate_Buffer_Overflow_in_UEFI.pdf
[Win10 HCS] Hardware Compatibility Specification for Systems for Windows 10,
https://msdn.microsoft.com/windows/hardware/commercialize/design/compatibility/
systems
42
Authors
Jiewen Yao (jiewen.yao@intel.com ) is EDK II BIOS architect, EDK II FSP package maintainer,
EDK II TPM2 module maintainer, EDK II ACPI S3 module maintainer, with Software and
Services Group at Intel Corporation. Jiewen is member of UEFI Security Sub-team and PI
Security Sub-team in the UEFI Forum.
Vincent J. Zimmer (vincent.zimmer@intel.com ) is a Senior Principal Engineer with the
Software and Services Group at Intel Corporation. Vincent chairs the UEFI Security and
Network Sub-teams in the UEFI Forum.
43