ArmPkg Compression - lzeng14/tianocore GitHub Wiki
To reduce the size of the firmware and also to speed up the boot process (it is sometimes faster to decompress a compressed file than to copy the original file from a block storage), it is often common to compress the DXE & BDS modules.
To speed up the boot process on platform with slow CPU (eg: FPGA platform), it might help to disable the decompression and copy the image directly into DRAM.
This section will use ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-RTSM-AEMv8Ax4.fdf as an example.
At the end of the build process you will see these three FVs (Firmware Volume):
FV Space Information FVMAIN_SEC [14%Full] 524288 total, 77504 used, 446784 free FVMAIN_COMPACT [45%Full] 2621440 total, 1184312 used, 1437128 free FVMAIN [99%Full] 4004224 total, 4004168 used, 56 freeFVMAIN_SEC is the secure part of the firmware that should live into Trusted Memory.
FVMAIN is the compressed image. This FV image is added in FVMAIN_COMPACT.
The compression is driven by the Guided Section in the FDF file. See the section '[FV.FVMAIN_COMPACT]':
FILE FV_IMAGE = 9E21FD93-9C72-4c15-8C4B-E77F1DB2D792 { SECTION GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF PROCESSING_REQUIRED = TRUE { SECTION FV_IMAGE = FVMAIN } }
The GUID 'EE4E5898-3914-4259-9D6E-DC7BD79403CF' corresponds to the LZMA decompression (defined in IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec).
This section says it will compress the FV image named 'FVMAIN' into a file named 'FV_IMAGE'.
The FVMAIN FV image is defined above by the section '[FV.FvMain]'.
1. Flatten the FDF file: Move the content of FVMAIN into FVMAIN_COMPACT:
- - remove FV_IMAGE file from FVMAIN_COMPACT
- - move all the files from FVMAIN to FVMAIN_COMPACT
Generating FVMAIN_COMPACT FV ######################################## ######################################## ######################################## ###Return Value = 2 GenFv: ERROR 3000: Invalid the required fv image size 0x46ede8 exceeds the set fv image size 0x280000
2. Increase the size of the FDF file
From:
[FD.RTSM_VE_AEMv8_EFI] BaseAddress = 0x00000000|gArmTokenSpaceGuid.PcdFdBaseAddress # The base address of the Firmware in NOR Flash. Size = 0x00300000|gArmTokenSpaceGuid.PcdFdSize # The size in bytes of the FLASH Device (...) BlockSize = 0x00001000 NumBlocks = 0x300 (...) 0x00080000|0x00280000 gArmTokenSpaceGuid.PcdFvBaseAddress|gArmTokenSpaceGuid.PcdFvSize
To:
[FD.RTSM_VE_AEMv8_EFI] BaseAddress = 0x00000000|gArmTokenSpaceGuid.PcdFdBaseAddress # The base address of the Firmware in NOR Flash. Size = 0x00580000|gArmTokenSpaceGuid.PcdFdSize # The size in bytes of the FLASH Device (...) BlockSize = 0x00001000 NumBlocks = 0x580 (...) 0x00080000|0x00500000 gArmTokenSpaceGuid.PcdFvBaseAddress|gArmTokenSpaceGuid.PcdFvSize
3. Build the new firmware:
FV Space Information FVMAIN_SEC [14%Full] 524288 total, 77504 used, 446784 free FVMAIN_COMPACT [88%Full] 5242880 total, 4648424 used, 594456 free