edk2/UefiPayloadPkg
Sergii Dmytruk 68a7665250 UefiPayloadPkg/FmpDeviceSmmLib: Add for full chip flashing via SMMSTOREv2
Part of the functions of the library are left unimplemented (return
EFI_UNSUPPORTED) the rest use information about current firmware
obtained from CBMEM (at this point available in a HOB) and SMMSTOREv2 to
perform flashing.

Flashing is slightly optimized: FmpDeviceSetImageWithStatus() first
reads a block and checks that it differs from the new contents before
initiating erase and write.

On successful flashing runtime APIs for dealing with EFI variables are
replaced with stubs to prevent accesses to SMMSTORE from the currently
running firmware.  The SMMSTORE region's contents and possibly location
and size have been changed as a result of the update and continued use
of it can have unpredictable consequences including corruption of the
newly written firmware image.  A capsule mode always ends with a reboot,
so the variable services are unavailable only for a very short period
after a successful flashing.

Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
2025-08-25 11:54:17 +00:00
..
BlSupportDxe UefiPayloadPkg/BlSupportDxe: Publish ESRT with an entry for system firmware 2025-08-25 11:54:17 +00:00
BlSupportSmm UefiPayloadPkg: Fix a typo in SMM base 2025-04-22 00:32:00 +00:00
FvbRuntimeDxe UefiPayloadPkg: Fix EFI_SUCCESS typos 2025-06-12 17:50:45 +00:00
GraphicsOutputDxe UefiPayloadPkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
Include UefiPayloadPkg/SmmStore: Add API to read/write/erase any flash block 2025-08-25 11:54:17 +00:00
Library UefiPayloadPkg/FmpDeviceSmmLib: Add for full chip flashing via SMMSTOREv2 2025-08-25 11:54:17 +00:00
PayloadLoaderPeim UefiPayloadPkg: Fix EFI_SUCCESS typos 2025-06-12 17:50:45 +00:00
PchSmiDispatchSmm UefiPayloadPkg: Fix calling convention 2025-07-29 17:50:45 +00:00
PciPlatformDxe UefiPayloadPkg: Scan for Option ROMs 2025-08-12 05:42:47 +00:00
PlatformCI UefiPayloadPkg: Add stuart build support. 2025-03-09 02:22:38 +08:00
SmmAccessDxe UefiPayloadPkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
SmmControlRuntimeDxe UefiPayloadPkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
SmmStoreFvb UefiPayloadPkg: Add support for Firmware Volume Block Protocol 2025-04-09 18:12:48 +00:00
Tools UefiPayloadPkg: Update Elf segment/section syncup process 2025-02-02 07:45:14 +00:00
UefiPayloadEntry UefiPayloadPkg: Enable processing of capsules 2025-08-25 11:54:17 +00:00
BuildAndIntegrationInstructions.txt UefiPayloadPkg: Fix architecture in the build instruction 2022-03-29 05:18:43 +00:00
Readme.md UefiPayloadPkg: Enhance ReadMe.md for ELF and FIT 2024-09-23 15:30:20 +00:00
UefiPayloadPkg.ci.yaml UefiPayloadPkg: Add Secure Boot support 2024-10-09 19:14:11 +00:00
UefiPayloadPkg.dec UefiPayloadPkg/BlParseLib: Add parsing of firmware info 2025-08-25 11:54:17 +00:00
UefiPayloadPkg.dsc UefiPayloadPkg/FmpDeviceSmmLib: Add for full chip flashing via SMMSTOREv2 2025-08-25 11:54:17 +00:00
UefiPayloadPkg.fdf UefiPayloadPkg: Enable processing of capsules 2025-08-25 11:54:17 +00:00
UniversalPayloadBuild.py UefiPayloadPkg: Add stuart build support. 2025-03-09 02:22:38 +08:00
UniversalPayloadBuild.sh UefiPayloadPkg: Provide a wrapper for UniversalPayloadBuild.py 2022-09-28 17:52:34 +08:00

UefiPayloadPkg

Provide UEFI Universal Payload for different bootloader to generate EFI environment

Spec

Uefi UniversalPayload Format

Binary Format HandOffPayload - HOB
ELF V (Default)
FIT V

Binary Format

  • ELF

                  +  +-----------------------+
                  |  | UniversalPayloadEntry | <----------- UefiPayloadPkg\UefiPayloadEntry\UniversalPayloadEntry.c:_ModuleEntryPoint (HOB)
                  |  +-----------------------+
                  |  | .upld_info            | patch it directly
    ELF Format    |  +-----------------------+
                  |  | .upld.uefi_fv         | patch it directly
                  |  +-----------------------+
                  |  | .upld.bds_fv          | patch it directly
                  |  +-----------------------+
                  |  | .upld.<afpx>_fv       | patch it directly
                  +  +-----------------------+
    
  • FIT

                  +  +-----------------------+
    FIT Data      |  | FIT Header            | <----------- Generate by pylibfdt
                  +  +-----------------------+
    PECOFF Format |  | UniversalPayloadEntry | <----------- UefiPayloadPkg\UefiPayloadEntry\FitUniversalPayloadEntry.c:_ModuleEntryPoint (HOB)
                  +  +-----------------------+
    Relocate Data |  | reloc-start           |
                  +  +-----------------------+
                  |  | uefi_fv               | patch it directly
                  |  +-----------------------+
    Multi Binary  |  | bds_fv                | patch it directly
                  |  +-----------------------+
                  |  | afp_xxx_fv            | patch it directly
                  |  +-----------------------+
                  |  | afp_xxx_fv            | patch it directly
                  +  +-----------------------+
    

Build Environment

  • ELF
    Install GCC compiler on linux and MSVC compiler on windows
    Install CLANG compiler https://github.com/llvm/llvm-project/releases/tag/llvmorg-10.0.1 on windows and linux
    
  • FIT
    Install GCC compiler on linux and MSVC compiler on windows
    pip3 install pefile
    pip3 install pylibfdt
    

How to build UEFI UniversalPayload

  • Windows

    • edksetup Rebuild
  • Linux

    • make -C BaseTools
    • source edksetup.sh
  • UniversalPayload.elf

    • python UefiPayloadPkg/UniversalPayloadBuild.py -t <TOOL_CHAIN_TAG>
    • llvm-objdump -h Build/UefiPayloadPkgX64/UniversalPayload.elf
  • UniversalPayload.fit

    • python UefiPayloadPkg/UniversalPayloadBuild.py -t <TOOL_CHAIN_TAG> --Fit

How to dump payload binary data

  • UniversalPayload.elf

  • UniversalPayload.fit

    • Install fdtdump tool

      • Windows
        Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
        choco install dtc-msys2
        
      • Linux
        sudo apt install -y u-boot-tools
        
    • fdtdump Build/UefiPayloadPkgX64/UniversalPayload.fit

Edk2boot + UefiUniversalPayload

ELF Edk2boot use below way to support compress and sign.

  • ELF Behavior - Edk2boot + UefiUniversalPayload.elf
    Boot Flow
    +-------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------+-------------------+
    | Platform Init                                                                       | Universal Loader Interface                                                                                | OS                |
    +-------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------+-------------------+
                                                                                                                                                                       HOBs
    SEC -> PEI -> DXE -> DXE IPL -> UefiPayloadPkg\PayloadLoaderPeim\PayloadLoaderPeim.c ------------------------------------------------------------------------------------> Load UniversalPayload.elf -> Operation System
    
    
    | Platform Initialize - Edk2                                                                                                                                                                      | UniversalPayload - Edk2        |
    +-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------+
    
    Binary Format
    
    +-------------------+
    | BIOS.rom          |
    +-------------------+
    | Other Firmware    |
    +-------------------+
    | ...               |  FMMT                                                                                                                                                                        UniversalPayloadBuild.py
    +-------------------+<----------------+-----------------------+  GenFfs    +-----------------------+  Rsa2048Sha256 Sign +-----------------------+  LzmaCompress +----------------------+  GenSec +--------------------------------+
    |                   |                 | EDK2 FFS Header       |<-----------| Rsa2048Sha256 Hash    |<--------------------| UniversalPayload.lzma |<--------------| EDK2 SEC Header      |<--------| UniversalPayload.elf           |
    | RAW Data          |                 +-----------------------+            +-----------------------+                     +-----------------------+               +----------------------+         +--------------------------------+
    |                   |                 | Rsa2048Sha256 Hash    |            | UniversalPayload.lzma |                                                             | UniversalPayload.elf |         | upld_info                      |
    |                   |                 +-----------------------+            +-----------------------+                                                             +----------------------+         +--------------------------------+
    |                   |                 | UniversalPayload.lzma |                                                                                                  | upld_info            |         | upld.uefi_fv                   |
    +-------------------+<----------------+-----------------------+                                                                                                  +----------------------+         +--------------------------------+
    | ...               |                                                                                                                                            | upld.uefi_fv         |         | upld.bds_fv                    |
    +-------------------+                                                                                                                                            +----------------------+         +--------------------------------+
    | Other Firmware    |                                                                                                                                            | upld.bds_fv          |         | upld.AFP1                      |
    +-------------------+                                                                                                                                            +----------------------+         +--------------------------------+
                                                                                                                                                                     | upld.AFP1            |         | upld.AFP2                      |
                                                                                                                                                                     +----------------------+         +--------------------------------+
                                                                                                                                                                     | upld.AFP2            |         | ...                            |
                                                                                                                                                                     +----------------------+         +--------------------------------+
                                                                                                                                                                     | ...                  |         | upld.AFPn                      |
                                                                                                                                                                     +----------------------+         +--------------------------------+
                                                                                                                                                                     | upld.AFPn            |
                                                                                                                                                                     +----------------------+
    

FIT Edk2boot use below way to support compress and sign

  • FIT Behavior - Edk2boot + UefiUniversalPayload.fit
    Boot Flow
    +-------------------------------------------------------------------------------------+------------------------------------------------------------------------+-------------------+
    | Platform Init                                                                       | Universal Loader Interface                                             | OS                |
    +-------------------------------------------------------------------------------------+------------------------------------------------------------------------+-------------------+
                                                                                                        HOBs
    SEC -> PEI -> DXE -> DXE IPL -> *UefiPayloadPkg\PayloadLoaderPeim\PayloadLoaderPeim.c ----------------------------------------------> Load UniversalPayload.fit -> Operation System
    
    Binary Format
    
    | Platform Initialize - Edk2                                                                                                | UniversalPayload - Edk2 (UniversalPayloadBuild.py --Fit)                                |
    +---------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
    
    +-------------------+
    | BIOS.rom          |
    +-------------------+
    | Other Firmware    |
    +-------------------+
    | ...               |  FMMT                                                                                                  UniversalPayloadBuild.py --Fit    tianocore -> data-offset
    +-------------------+<----------------+--------------------------------+  GenFfs +--------------------------------+  GenSec +--------------------------------+ tianocore -> reloc-start +--------------------------+
    |                   |                 | EDK2 FFS Header                |<--------| EDK2 SEC Header                |<--------| FIT Header                     |<-------------------------| UniversalPayload.pecoff  |
    |                   |                 +--------------------------------+         +--------------------------------+         | description = "Uefi Payload";  |                          +--------------------------+
    |                   |                 | EDK2 SEC Header                |         | FIT Header                     |         | ...                            |
    | RAW Data          |                 +--------------------------------+         |                                |         | images {                       | uefi-fv -> data-offset   +--------------------------+
    |                   |                 | FIT Header                     |         |                                |         |   tianocore {...};             |<-------------------------| uefi_fv                  |
    |                   |                 |                                |         +--------------------------------+         |   uefi-fv {...};               | bds-fv -> data-offset    +--------------------------+
    |                   |                 |                                |         | tianocore -> data              |         |   bds-fv {...};                |<-------------------------| bds_fv                   |
    |                   |                 +--------------------------------+         +--------------------------------+         |   afp1-fv {...};               | AFP1 -> data-offset      +--------------------------+
    |                   |                 | tianocore -> data              |         | tianocore -> reloc-start       |         |   ...                          |<-------------------------| AFP1                     |
    |                   |                 +--------------------------------+         +--------------------------------+         |   afpn-fv {...};               | AFP2 -> data-offset      +--------------------------+
    |                   |                 | tianocore -> reloc-start       |         | uefi-fv -> data                |         | }                              |<-------------------------| AFP2                     |
    |                   |                 +--------------------------------+         +--------------------------------+         | configurations {               | ...                      +--------------------------+
    |                   |                 | uefi-fv -> data                |         | bds-fv -> data                 |         |   conf-1 {...}                 |<-------------------------| ...                      |
    |                   |                 +--------------------------------+         +--------------------------------+         | }                              | AFPn -> data-offset      +--------------------------+
    |                   |                 | bds-fv -> data                 |         | AFP1-fv -> data                |         |                                |<-------------------------| AFPn                     |
    |                   |                 +--------------------------------+         +--------------------------------+         |                                |                          +--------------------------+
    |                   |                 | AFP1-fv -> data                |         | AFP2-fv -> data                |         |                                |
    |                   |                 +--------------------------------+         +--------------------------------+         +--------------------------------+
    |                   |                 | AFP2-fv -> data                |         | ...                            |         | tianocore -> data              |
    |                   |                 +--------------------------------+         +--------------------------------+         +--------------------------------+
    |                   |                 | ...                            |         | AFPn-fv -> data                |         | tianocore -> reloc-start       |
    |                   |                 +--------------------------------+         +--------------------------------+         +--------------------------------+
    |                   |                 | AFPn-fv -> data                |                                                    | uefi-fv -> data                |
    +-------------------+<----------------+--------------------------------+                                                    +--------------------------------+
    | ...               |                                                                                                       | bds-fv -> data                 |
    +-------------------+                                                                                                       +--------------------------------+
    | Other Firmware    |                                                                                                       | AFP1-fv -> data                |
    +-------------------+                                                                                                       +--------------------------------+
                                                                                                                                | AFP2-fv -> data                |
                                                                                                                                +--------------------------------+
                                                                                                                                | ...                            |
                                                                                                                                +--------------------------------+
                                                                                                                                | AFPn-fv -> data                |
                                                                                                                                +--------------------------------+