diff --git a/ArmPkg/ArmPkg.dsc b/ArmPkg/ArmPkg.dsc index f0f29737f2..70ad2f6122 100644 --- a/ArmPkg/ArmPkg.dsc +++ b/ArmPkg/ArmPkg.dsc @@ -55,7 +55,6 @@ DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf PeCoffLib2|MdePkg/Library/BasePeCoffLib2/BasePeCoffLib2.inf - UefiImageLib|MdePkg/Library/BaseUefiImageLib/BaseUefiImageLibPeCoff.inf UefiImageExtraActionLib|MdePkg/Library/BaseUefiImageExtraActionLibNull/BaseUefiImageExtraActionLibNull.inf CpuArchLib|ArmPkg/Library/CpuArchLib/CpuArchLib.inf diff --git a/ArmPkg/Library/DebugAgentSymbolsBaseLib/DebugAgentSymbolsBaseLib.c b/ArmPkg/Library/DebugAgentSymbolsBaseLib/DebugAgentSymbolsBaseLib.c index dad2dd9d29..525483a440 100644 --- a/ArmPkg/Library/DebugAgentSymbolsBaseLib/DebugAgentSymbolsBaseLib.c +++ b/ArmPkg/Library/DebugAgentSymbolsBaseLib/DebugAgentSymbolsBaseLib.c @@ -214,7 +214,12 @@ GetImageContext ( // Initialize the Image Context // FIXME: Common FFS API with size checks - Status = UefiImageInitializeContext (ImageContext, EfiImage, SectionLength - sizeof (*Section)); + Status = UefiImageInitializeContext ( + ImageContext, + EfiImage, + SectionLength - sizeof (*Section), + UEFI_IMAGE_SOURCE_FV + ); if (!EFI_ERROR(Status)) { Status = UefiImageLoadImageInplace( ImageContext); } diff --git a/ArmPlatformPkg/ArmPlatformPkg.dsc b/ArmPlatformPkg/ArmPlatformPkg.dsc index ab55b557a2..bc922d8d24 100644 --- a/ArmPlatformPkg/ArmPlatformPkg.dsc +++ b/ArmPlatformPkg/ArmPlatformPkg.dsc @@ -58,7 +58,6 @@ PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf UefiImageExtraActionLib|MdePkg/Library/BaseUefiImageExtraActionLibNull/BaseUefiImageExtraActionLibNull.inf PeCoffLib2|MdePkg/Library/BasePeCoffLib2/BasePeCoffLib2.inf - UefiImageLib|MdePkg/Library/BaseUefiImageLib/BaseUefiImageLibPeCoff.inf PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf PL011UartClockLib|ArmPlatformPkg/Library/PL011UartClockLib/PL011UartClockLib.inf PL011UartLib|ArmPlatformPkg/Library/PL011UartLib/PL011UartLib.inf diff --git a/ArmVirtPkg/ArmVirt.dsc.inc b/ArmVirtPkg/ArmVirt.dsc.inc index 9981821d97..5f9387c5c4 100644 --- a/ArmVirtPkg/ArmVirt.dsc.inc +++ b/ArmVirtPkg/ArmVirt.dsc.inc @@ -45,7 +45,6 @@ PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf PeCoffLib2|MdePkg/Library/BasePeCoffLib2/BasePeCoffLib2.inf - UefiImageLib|MdePkg/Library/BaseUefiImageLib/BaseUefiImageLibPeCoff.inf IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicArmVirt.inf UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf CpuLib|MdePkg/Library/BaseCpuLib/BaseCpuLib.inf diff --git a/ArmVirtPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf b/ArmVirtPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf index e49bd8477e..7228b9dd5c 100755 --- a/ArmVirtPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf +++ b/ArmVirtPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf @@ -47,7 +47,7 @@ SerialPortLib ExtractGuidedSectionLib LzmaDecompressLib - UefiImageLib + UefiImageOnlyFvLib PrePiLib MemoryAllocationLib HobLib diff --git a/ArmVirtPkg/PrePi/PrePi.c b/ArmVirtPkg/PrePi/PrePi.c index c9b42379ce..deda3fe7bb 100644 --- a/ArmVirtPkg/PrePi/PrePi.c +++ b/ArmVirtPkg/PrePi/PrePi.c @@ -152,7 +152,12 @@ RelocateUefiImage ( Status = FfsFindSectionData (EFI_SECTION_PE32, FileHandle, &SectionData, &SectionSize); ASSERT_EFI_ERROR (Status); - Status = UefiImageInitializeContext (&ImageContext, SectionData, SectionSize); + Status = UefiImageInitializeContext ( + &ImageContext, + SectionData, + SectionSize, + UEFI_IMAGE_SOURCE_FV + ); ASSERT_RETURN_ERROR (Status); Status = UefiImageRelocateImageInplaceForExecution (&ImageContext); diff --git a/BaseTools/ImageTool/GNUmakefile b/BaseTools/ImageTool/GNUmakefile index f4e13585ef..3765720da8 100644 --- a/BaseTools/ImageTool/GNUmakefile +++ b/BaseTools/ImageTool/GNUmakefile @@ -10,7 +10,7 @@ OBJS = $(PROJECT).o OBJS += Image.o UefiImageScan.o PeEmit32.o PeEmit64.o PeEmitCommon.o PeScan.o ElfScan32.o ElfScan64.o ElfScanCommon.o BinEmit.o ImageToolEmit.o OBJS += UefiImageExtraActionLib.o OBJS += PeCoffInit.o PeCoffInfo.o PeCoffLoad.o PeCoffRelocate.o PeCoffHii.o PeCoffDebug.o PeCoffHash.o -OBJS += UefiImageLibPeCoff.o PeCoffSupport.o CommonSupport.o +OBJS += PeSupport.o UefiImageLib.o CommonSupport.o WERROR = 1 DEBUG = 1 @@ -23,3 +23,5 @@ VPATH += ../../MdePkg/Library/BasePeCoffLib2:$\ ../../MdePkg/Library/BaseUefiImageLib include $(OC_USER)/User/Makefile + +CFLAGS += -DUEFI_IMAGE_FORMAT_SUPPORT_SOURCES=0x02 diff --git a/BaseTools/ImageTool/Makefile b/BaseTools/ImageTool/Makefile index fe1e197b5a..a6a0b6a48c 100644 --- a/BaseTools/ImageTool/Makefile +++ b/BaseTools/ImageTool/Makefile @@ -33,7 +33,7 @@ CMEM = $(UDK_PATH)\MdeModulePkg\Library\CommonMemoryAllocationLib USER = $(OC_USER)\User\Library OBJECTS = $(OBJECTS) {$(BASE)}SafeString.obj String.obj SwapBytes16.obj SwapBytes32.obj CpuDeadLoop.obj CheckSum.obj QuickSort.obj LinkedList.obj OBJECTS = $(OBJECTS) {$(OUT)}DebugLib.obj {$(PRIN)}PrintLib.obj PrintLibInternal.obj {$(ERRO)}BaseDebugPrintErrorLevelLib.obj -OBJECTS = $(OBJECTS) {$(UIMG)}UefiImageLibPeCoff.obj PeCoffSupport.obj CommonSupport.obj +OBJECTS = $(OBJECTS) {$(UIMG)}UefiImageLib.obj PeSupport.obj CommonSupport.obj OBJECTS = $(OBJECTS) {$(USER)}UserFile.obj UserBaseMemoryLib.obj UserMath.obj UserPcd.obj UserMisc.obj UserGlobalVar.obj UserBootServices.obj OBJECTS = $(OBJECTS) {$(BMPN)}BaseMemoryProfileLibNull.obj {$(CMEM)}CommonMemoryAllocationLib.obj {$(CMEM)}CommonMemoryAllocationLibEx.obj @@ -102,7 +102,7 @@ cleanall: @move $@ $(OUT_DIR)\ {$(UIMG)}.c.obj : - $(CC) -c $(CFLAGS) $(INC) $< -Fo$@ + $(CC) -c $(CFLAGS) -DUEFI_IMAGE_FORMAT_SUPPORT_SOURCES=0x02 $(INC) $< -Fo$@ @move $@ $(OUT_DIR)\ {$(USER)}.c.obj : diff --git a/BaseTools/ImageTool/UefiImageScan.c b/BaseTools/ImageTool/UefiImageScan.c index c02a62b7e9..5180be4407 100644 --- a/BaseTools/ImageTool/UefiImageScan.c +++ b/BaseTools/ImageTool/UefiImageScan.c @@ -21,10 +21,7 @@ ScanUefiImageGetHeaderInfo ( RETURN_STATUS Status; UINT64 Address; - assert (HeaderInfo != NULL); - assert (Context != NULL); - - HeaderInfo->BaseAddress = UefiImageGetPreferredAddress (Context); + HeaderInfo->BaseAddress = UefiImageGetBaseAddress (Context); HeaderInfo->EntryPointAddress = UefiImageGetEntryPointAddress (Context); HeaderInfo->Machine = UefiImageGetMachine (Context); HeaderInfo->Subsystem = UefiImageGetSubsystem (Context); @@ -66,10 +63,7 @@ ScanUefiImageGetRelocInfo ( RelocInfo->RelocsStripped = UefiImageGetRelocsStripped (Context); if (FormatIndex == UefiImageFormatPe) { - return ScanPeGetRelocInfo ( - RelocInfo, - (PE_COFF_LOADER_IMAGE_CONTEXT *)Context - ); + return ScanPeGetRelocInfo (RelocInfo, &Context->Ctx.Pe); } fprintf ( @@ -97,10 +91,7 @@ ScanUefiImageGetSegmentInfo ( SegmentInfo->SegmentAlignment = UefiImageGetSegmentAlignment (Context); if (FormatIndex == UefiImageFormatPe) { - return ScanPeGetSegmentInfo ( - SegmentInfo, - (PE_COFF_LOADER_IMAGE_CONTEXT *)Context - ); + return ScanPeGetSegmentInfo (SegmentInfo, &Context->Ctx.Pe); } fprintf ( @@ -211,7 +202,12 @@ ToolContextConstructUefiImage ( return RETURN_UNSUPPORTED; } - Status = UefiImageInitializeContext (&Context, File, (UINT32)FileSize); + Status = UefiImageInitializeContext ( + &Context, + File, + (UINT32)FileSize, + UEFI_IMAGE_SOURCE_FV + ); if (RETURN_ERROR (Status)) { return Status; } diff --git a/BaseTools/Source/C/Common/GNUmakefile b/BaseTools/Source/C/Common/GNUmakefile index 1396c3f578..1166736e43 100644 --- a/BaseTools/Source/C/Common/GNUmakefile +++ b/BaseTools/Source/C/Common/GNUmakefile @@ -122,8 +122,8 @@ OBJECTS += \ OBJECTS += \ $(EDK2_OBJPATH)/MdePkg/Library/BaseUefiImageLib/CommonSupport.o \ - $(EDK2_OBJPATH)/MdePkg/Library/BaseUefiImageLib/PeCoffSupport.o \ - $(EDK2_OBJPATH)/MdePkg/Library/BaseUefiImageLib/UefiImageLibPeCoff.o + $(EDK2_OBJPATH)/MdePkg/Library/BaseUefiImageLib/PeSupport.o \ + $(EDK2_OBJPATH)/MdePkg/Library/BaseUefiImageLib/UefiImageLib.o OBJECTS += \ $(EDK2_OBJPATH)/MdePkg/Library/BaseUefiImageExtraActionLibNull/UefiImageExtraActionLib.o diff --git a/BaseTools/Source/C/Common/Makefile b/BaseTools/Source/C/Common/Makefile index af704876dd..03a9e73539 100644 --- a/BaseTools/Source/C/Common/Makefile +++ b/BaseTools/Source/C/Common/Makefile @@ -121,8 +121,8 @@ OBJECTS = $(OBJECTS) \ OBJECTS = $(OBJECTS) \ $(EDK2_OBJPATH)\MdePkg\Library\BaseUefiImageLib\CommonSupport.obj \ - $(EDK2_OBJPATH)\MdePkg\Library\BaseUefiImageLib\PeCoffSupport.obj \ - $(EDK2_OBJPATH)\MdePkg\Library\BaseUefiImageLib\UefiImageLibPeCoff.obj + $(EDK2_OBJPATH)\MdePkg\Library\BaseUefiImageLib\PeSupport.obj \ + $(EDK2_OBJPATH)\MdePkg\Library\BaseUefiImageLib\UefiImageLib.obj OBJECTS = $(OBJECTS) \ $(EDK2_OBJPATH)\MdePkg\Library\BaseUefiImageExtraActionLibNull\UefiImageExtraActionLib.obj diff --git a/BaseTools/Source/C/EfiRom/EfiRom.c b/BaseTools/Source/C/EfiRom/EfiRom.c index 9a41a34baf..053849202a 100644 --- a/BaseTools/Source/C/EfiRom/EfiRom.c +++ b/BaseTools/Source/C/EfiRom/EfiRom.c @@ -836,7 +836,12 @@ Returns: RETURN_STATUS Status; UEFI_IMAGE_LOADER_IMAGE_CONTEXT Context; - Status = UefiImageInitializeContext (&Context, FileBuffer, FileSize); + Status = UefiImageInitializeContext ( + &Context, + FileBuffer, + FileSize, + UEFI_IMAGE_SOURCE_FV + ); if (RETURN_ERROR (Status)) { Error (NULL, 0, 2000, "Invalid parameter", "Input file does not appear to be an UEFI image - %llu!", Status); return STATUS_ERROR; diff --git a/BaseTools/Source/C/GenFv/GenFvInternalLib.c b/BaseTools/Source/C/GenFv/GenFvInternalLib.c index 210d7ad3cf..b836ef1529 100644 --- a/BaseTools/Source/C/GenFv/GenFvInternalLib.c +++ b/BaseTools/Source/C/GenFv/GenFvInternalLib.c @@ -2389,7 +2389,12 @@ Returns: return EFI_INVALID_PARAMETER; } - RETURN_STATUS Status = UefiImageInitializeContext (&Context, UefiImage, UefiImageSize); + RETURN_STATUS Status = UefiImageInitializeContext ( + &Context, + UefiImage, + UefiImageSize, + UEFI_IMAGE_SOURCE_FV + ); if (RETURN_ERROR (Status)) { Error (NULL, 0, 3000, "Invalid", "Unrecognized UEFI image file."); return Status; @@ -3569,7 +3574,8 @@ Returns: Status = UefiImageInitializeContext ( &ImageContext, (VOID *) ((UINTN) CurrentPe32Section.Pe32Section + CurSecHdrSize), - SectPeSize + SectPeSize, + UEFI_IMAGE_SOURCE_FV ); if (EFI_ERROR (Status)) { Error (NULL, 0, 3000, "Invalid UefiImage", "The input file is %s and the return status is %x", FileName, (int) Status); @@ -3779,7 +3785,8 @@ Returns: Status = UefiImageInitializeContext ( &ImageContext, (VOID *) ((UINTN) CurrentPe32Section.Pe32Section + CurSecHdrSize), - RebasedImageSize + RebasedImageSize, + UEFI_IMAGE_SOURCE_FV ); ASSERT_EFI_ERROR (Status); diff --git a/BaseTools/Source/C/Include/Common/AutoGen.h b/BaseTools/Source/C/Include/Common/AutoGen.h index bf5bc9a063..52135a9977 100644 --- a/BaseTools/Source/C/Include/Common/AutoGen.h +++ b/BaseTools/Source/C/Include/Common/AutoGen.h @@ -163,6 +163,20 @@ extern UINT64 _gPcd_SkuId_Array[]; #define _PCD_GET_MODE_8_PcdDebugRaisePropertyMask _PCD_VALUE_PcdDebugRaisePropertyMask //#define _PCD_SET_MODE_8_PcdDebugRaisePropertyMask ASSERT(FALSE) // It is not allowed to set value for a FIXED_AT_BUILD PCD +#define _PCD_TOKEN_PcdUefiImageFormatSupportNonFv 0U +#define _PCD_VALUE_PcdUefiImageFormatSupportNonFv 0x00 +#define _PCD_SIZE_PcdUefiImageFormatSupportNonFv 1 +#define _PCD_GET_MODE_SIZE_PcdUefiImageFormatSupportNonFv _PCD_SIZE_PcdUefiImageFormatSupportNonFv +#define _PCD_GET_MODE_8_PcdUefiImageFormatSupportNonFv _PCD_VALUE_PcdUefiImageFormatSupportNonFv +//#define _PCD_SET_MODE_8_PcdUefiImageFormatSupportNonFv ASSERT(FALSE) // It is not allowed to set value for a FIXED_AT_BUILD PCD + +#define _PCD_TOKEN_PcdUefiImageFormatSupportFv 0U +#define _PCD_VALUE_PcdUefiImageFormatSupportFv 0x01 +#define _PCD_SIZE_PcdUefiImageFormatSupportFv 1 +#define _PCD_GET_MODE_SIZE_PcdUefiImageFormatSupportFv _PCD_SIZE_PcdUefiImageFormatSupportFv +#define _PCD_GET_MODE_8_PcdUefiImageFormatSupportFv _PCD_VALUE_PcdUefiImageFormatSupportFv +//#define _PCD_SET_MODE_8_PcdUefiImageFormatSupportFv ASSERT(FALSE) // It is not allowed to set value for a FIXED_AT_BUILD PCD + #ifdef __cplusplus } diff --git a/BaseTools/Source/C/Makefiles/header.makefile b/BaseTools/Source/C/Makefiles/header.makefile index f8e0b59d91..df72193b98 100644 --- a/BaseTools/Source/C/Makefiles/header.makefile +++ b/BaseTools/Source/C/Makefiles/header.makefile @@ -138,6 +138,8 @@ ifeq ($(DARWIN),Darwin) endif endif +CFLAGS += -DUEFI_IMAGE_FORMAT_SUPPORT_SOURCES=0x02 + # keep BUILD_OPTFLAGS last CFLAGS += $(BUILD_OPTFLAGS) CXXFLAGS += $(BUILD_OPTFLAGS) diff --git a/BaseTools/Source/C/Makefiles/ms.rule b/BaseTools/Source/C/Makefiles/ms.rule index c00df83714..5b9a90785c 100644 --- a/BaseTools/Source/C/Makefiles/ms.rule +++ b/BaseTools/Source/C/Makefiles/ms.rule @@ -41,7 +41,7 @@ {$(EDK2_PATH)\MdePkg\Library\BaseUefiImageLib\}.c{$(EDK2_OBJPATH)\MdePkg\Library\BaseUefiImageLib\}.obj : -@if not exist $(@D)\ mkdir $(@D) - $(CC) -c $(CFLAGS) $(EDK2_INC) $< -Fo$@ + $(CC) -c $(CFLAGS) -DUEFI_IMAGE_FORMAT_SUPPORT_SOURCES=0x02 $(EDK2_INC) $< -Fo$@ {$(EDK2_PATH)\MdePkg\Library\BaseUefiImageExtraActionLibNull\}.c{$(EDK2_OBJPATH)\MdePkg\Library\BaseUefiImageExtraActionLibNull\}.obj : -@if not exist $(@D)\ mkdir $(@D) diff --git a/EmbeddedPkg/EmbeddedPkg.dsc b/EmbeddedPkg/EmbeddedPkg.dsc index 2adc21c255..30305f237b 100644 --- a/EmbeddedPkg/EmbeddedPkg.dsc +++ b/EmbeddedPkg/EmbeddedPkg.dsc @@ -59,7 +59,6 @@ ReportStatusCodeLib|MdeModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf PeCoffLib2|MdePkg/Library/BasePeCoffLib2/BasePeCoffLib2.inf - UefiImageLib|MdePkg/Library/BaseUefiImageLib/BaseUefiImageLibPeCoff.inf UefiImageExtraActionLib|MdePkg/Library/BaseUefiImageExtraActionLibNull/BaseUefiImageExtraActionLibNull.inf CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf PrePiLib|EmbeddedPkg/Library/PrePiLib/PrePiLib.inf diff --git a/EmbeddedPkg/Library/PrePiLib/PrePiLib.c b/EmbeddedPkg/Library/PrePiLib/PrePiLib.c index 98d5eee1cc..9826e9493e 100644 --- a/EmbeddedPkg/Library/PrePiLib/PrePiLib.c +++ b/EmbeddedPkg/Library/PrePiLib/PrePiLib.c @@ -40,7 +40,12 @@ LoadUefiImage ( UINT32 BufferPages; UINT32 BufferAlignment; - Status = UefiImageInitializeContext (&ImageContext, UefiImage, UefiImageSize); + Status = UefiImageInitializeContext ( + &ImageContext, + UefiImage, + UefiImageSize, + UEFI_IMAGE_SOURCE_FV + ); ASSERT_EFI_ERROR (Status); ImageSize = UefiImageGetImageSize (&ImageContext); diff --git a/EmulatorPkg/EmulatorPkg.dsc b/EmulatorPkg/EmulatorPkg.dsc index 3e0d72f0c5..b0f57fa461 100644 --- a/EmulatorPkg/EmulatorPkg.dsc +++ b/EmulatorPkg/EmulatorPkg.dsc @@ -63,7 +63,6 @@ PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf PeCoffLib2|MdePkg/Library/BasePeCoffLib2/BasePeCoffLib2.inf - UefiImageLib|MdePkg/Library/BaseUefiImageLib/BaseUefiImageLibPeCoff.inf BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf FrameBufferBltLib|MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltLib.inf diff --git a/EmulatorPkg/Unix/Host/Host.c b/EmulatorPkg/Unix/Host/Host.c index b8faa54fdf..5400f8b5ce 100644 --- a/EmulatorPkg/Unix/Host/Host.c +++ b/EmulatorPkg/Unix/Host/Host.c @@ -746,7 +746,12 @@ SecUefiImageGetEntryPoint ( EFI_STATUS Status; UEFI_IMAGE_LOADER_IMAGE_CONTEXT ImageContext; - Status = UefiImageInitializeContext (&ImageContext, Pe32Data, Pe32Size); + Status = UefiImageInitializeContext ( + &ImageContext, + Pe32Data, + Pe32Size, + UEFI_IMAGE_SOURCE_FV + ); if (EFI_ERROR (Status)) { return Status; } diff --git a/EmulatorPkg/Unix/Host/Host.inf b/EmulatorPkg/Unix/Host/Host.inf index 68254addcf..a205cffa3c 100644 --- a/EmulatorPkg/Unix/Host/Host.inf +++ b/EmulatorPkg/Unix/Host/Host.inf @@ -55,7 +55,7 @@ PrintLib BaseMemoryLib BaseLib - UefiImageLib + UefiImageOnlyFvLib ThunkPpiList ThunkProtocolList PpiListLib diff --git a/EmulatorPkg/Win/Host/WinHost.c b/EmulatorPkg/Win/Host/WinHost.c index 041a32a928..f9966dc42d 100644 --- a/EmulatorPkg/Win/Host/WinHost.c +++ b/EmulatorPkg/Win/Host/WinHost.c @@ -804,7 +804,12 @@ SecUefiImageGetEntryPoint ( EFI_STATUS Status; UEFI_IMAGE_LOADER_IMAGE_CONTEXT ImageContext; - Status = UefiImageInitializeContext (&ImageContext, Pe32Data, Pe32Size); + Status = UefiImageInitializeContext ( + &ImageContext, + Pe32Data, + Pe32Size, + UEFI_IMAGE_SOURCE_FV + ); if (EFI_ERROR (Status)) { return Status; } diff --git a/EmulatorPkg/Win/Host/WinHost.inf b/EmulatorPkg/Win/Host/WinHost.inf index 5310992f6c..a48bae4599 100644 --- a/EmulatorPkg/Win/Host/WinHost.inf +++ b/EmulatorPkg/Win/Host/WinHost.inf @@ -49,7 +49,7 @@ PrintLib BaseMemoryLib BaseLib - UefiImageLib + UefiImageOnlyFvLib ThunkPpiList ThunkProtocolList PpiListLib diff --git a/IntelFsp2Pkg/Tools/Tests/QemuFspPkg.dsc b/IntelFsp2Pkg/Tools/Tests/QemuFspPkg.dsc index fa35cf86ab..6d1a84ca26 100644 --- a/IntelFsp2Pkg/Tools/Tests/QemuFspPkg.dsc +++ b/IntelFsp2Pkg/Tools/Tests/QemuFspPkg.dsc @@ -93,7 +93,6 @@ ReportStatusCodeLib|MdeModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf PeCoffLib2|MdePkg/Library/BasePeCoffLib2/BasePeCoffLib2.inf - UefiImageLib|MdePkg/Library/BaseUefiImageLib/BaseUefiImageLibPeCoff.inf UefiImageExtraActionLib|MdePkg/Library/BaseUefiImageExtraActionLibNull/BaseUefiImageExtraActionLibNull.inf UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf diff --git a/IntelFsp2WrapperPkg/FspWrapperNotifyDxe/FspWrapperNotifyDxe.inf b/IntelFsp2WrapperPkg/FspWrapperNotifyDxe/FspWrapperNotifyDxe.inf index 37db0a5a21..c23aff4368 100644 --- a/IntelFsp2WrapperPkg/FspWrapperNotifyDxe/FspWrapperNotifyDxe.inf +++ b/IntelFsp2WrapperPkg/FspWrapperNotifyDxe/FspWrapperNotifyDxe.inf @@ -39,7 +39,7 @@ BaseMemoryLib UefiLib FspWrapperApiLib - UefiImageLib + UefiImageOnlyFvLib CacheMaintenanceLib DxeServicesLib PerformanceLib diff --git a/IntelFsp2WrapperPkg/FspWrapperNotifyDxe/LoadBelow4G.c b/IntelFsp2WrapperPkg/FspWrapperNotifyDxe/LoadBelow4G.c index 1a1d052b4d..17d9ced288 100644 --- a/IntelFsp2WrapperPkg/FspWrapperNotifyDxe/LoadBelow4G.c +++ b/IntelFsp2WrapperPkg/FspWrapperNotifyDxe/LoadBelow4G.c @@ -90,7 +90,12 @@ RelocateImageUnder4GIfNeeded ( // // Get information about the image being loaded // - Status = UefiImageInitializeContext (&ImageContext, Buffer, (UINT32) BufferSize); + Status = UefiImageInitializeContext ( + &ImageContext, + Buffer, + (UINT32) BufferSize, + UEFI_IMAGE_SOURCE_FV + ); ASSERT_EFI_ERROR (Status); ImageSize = UefiImageGetImageSize (&ImageContext); ImageAlignment = UefiImageGetSegmentAlignment (&ImageContext); diff --git a/IntelFsp2WrapperPkg/IntelFsp2WrapperPkg.dsc b/IntelFsp2WrapperPkg/IntelFsp2WrapperPkg.dsc index 04dcd2502c..dd4e315767 100644 --- a/IntelFsp2WrapperPkg/IntelFsp2WrapperPkg.dsc +++ b/IntelFsp2WrapperPkg/IntelFsp2WrapperPkg.dsc @@ -29,7 +29,6 @@ IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf UefiImageExtraActionLib|MdePkg/Library/BaseUefiImageExtraActionLibNull/BaseUefiImageExtraActionLibNull.inf PeCoffLib2|MdePkg/Library/BasePeCoffLib2/BasePeCoffLib2.inf - UefiImageLib|MdePkg/Library/BaseUefiImageLib/BaseUefiImageLibPeCoff.inf CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf diff --git a/MdeModulePkg/Core/Dxe/DxeMain.inf b/MdeModulePkg/Core/Dxe/DxeMain.inf index cc9905a8d9..513f10beee 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain.inf +++ b/MdeModulePkg/Core/Dxe/DxeMain.inf @@ -83,7 +83,7 @@ UefiLib DebugLib DxeCoreEntryPoint - UefiImageLib + UefiImageAllLib UefiImageExtraActionLib ExtractGuidedSectionLib MemoryAllocationLib diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c b/MdeModulePkg/Core/Dxe/Image/Image.c index 380ebec4af..e7950b8f46 100644 --- a/MdeModulePkg/Core/Dxe/Image/Image.c +++ b/MdeModulePkg/Core/Dxe/Image/Image.c @@ -239,12 +239,17 @@ CoreInitializeImageServices ( Status = UefiImageInitializeContext ( ImageContext, (VOID *) (UINTN) DxeCoreImageBaseAddress, - (UINT32) DxeCoreImageLength + (UINT32) DxeCoreImageLength, + UEFI_IMAGE_SOURCE_FV ); ASSERT_EFI_ERROR (Status); // FIXME: DxeCore is dynamically loaded by DxeIpl, can't it pass the context? - ImageContext->ImageBuffer = (VOID *) ImageContext->FileBuffer; + if (ImageContext->FormatIndex == UefiImageFormatPe) { + ImageContext->Ctx.Pe.ImageBuffer = (VOID *) ImageContext->Ctx.Pe.FileBuffer; + } else { + ASSERT (FALSE); + } ASSERT ((UINTN) DxeCoreEntryPoint == UefiImageLoaderGetImageEntryPoint (ImageContext)); @@ -590,7 +595,7 @@ CoreLoadPeImage ( Status = GetUefiImageFixLoadingAssignedAddress (&BufferAddress, ValueInSectionHeader, DstBufSize); if (!EFI_ERROR (Status)) { - if (BufferAddress != UefiImageGetPreferredAddress (ImageContext) && UefiImageGetRelocsStripped (ImageContext)) { + if (BufferAddress != UefiImageGetBaseAddress (ImageContext) && UefiImageGetRelocsStripped (ImageContext)) { Status = EFI_UNSUPPORTED; DEBUG ((EFI_D_INFO|EFI_D_LOAD, "LOADING MODULE FIXED ERROR: Loading module at fixed address failed since relocs have been stripped.\n")); } @@ -602,7 +607,7 @@ CoreLoadPeImage ( } } if (EFI_ERROR (Status)) { - BufferAddress = UefiImageGetPreferredAddress (ImageContext); + BufferAddress = UefiImageGetBaseAddress (ImageContext); if ((BufferAddress >= 0x100000) || UefiImageGetRelocsStripped (ImageContext)) { Status = AllocatePagesEx ( AllocateAddress, @@ -1191,7 +1196,12 @@ CoreLoadImageCommon ( // // Get information about the image being loaded // - Status = UefiImageInitializeContextPreHash (&ImageContext, FHand.Source, (UINT32) FHand.SourceSize); + Status = UefiImageInitializeContextPreHash ( + &ImageContext, + FHand.Source, + (UINT32) FHand.SourceSize, + ImageIsFromFv + ); if (EFI_ERROR (Status)) { ASSERT (FALSE); return Status; diff --git a/MdeModulePkg/Core/Pei/Image/Image.c b/MdeModulePkg/Core/Pei/Image/Image.c index 094fc80fe6..506e3488a0 100644 --- a/MdeModulePkg/Core/Pei/Image/Image.c +++ b/MdeModulePkg/Core/Pei/Image/Image.c @@ -183,7 +183,12 @@ LoadAndRelocateUefiImage ( ReturnStatus = EFI_SUCCESS; - Status = UefiImageInitializeContext (ImageContext, Pe32Data, Pe32DataSize); + Status = UefiImageInitializeContext ( + ImageContext, + Pe32Data, + Pe32DataSize, + UEFI_IMAGE_SOURCE_FV + ); if (EFI_ERROR (Status)) { return Status; } @@ -270,7 +275,7 @@ LoadAndRelocateUefiImage ( } if (!EFI_ERROR (Status)){ - Success = Destination == UefiImageGetPreferredAddress (ImageContext); + Success = Destination == UefiImageGetBaseAddress (ImageContext); if (!Success) { DEBUG ((DEBUG_INFO|DEBUG_LOAD, "LOADING MODULE FIXED ERROR: Loading module at fixed address failed since relocs have been stripped.\n")); @@ -362,7 +367,12 @@ LoadAndRelocateUefiImageInPlace ( CopyMem (ImageAddress, Pe32Data, ImageSize); - Status = UefiImageInitializeContext (&ImageContext, ImageAddress, ImageSize); + Status = UefiImageInitializeContext ( + &ImageContext, + ImageAddress, + ImageSize, + UEFI_IMAGE_SOURCE_FV + ); if (EFI_ERROR (Status)) { ASSERT_EFI_ERROR (Status); return Status; diff --git a/MdeModulePkg/Core/Pei/PeiMain.inf b/MdeModulePkg/Core/Pei/PeiMain.inf index 7be066a731..04a847e561 100644 --- a/MdeModulePkg/Core/Pei/PeiMain.inf +++ b/MdeModulePkg/Core/Pei/PeiMain.inf @@ -62,7 +62,7 @@ DebugLib MemoryAllocationLib CacheMaintenanceLib - UefiImageLib + UefiImageOnlyFvLib PeiServicesTablePointerLib PcdLib diff --git a/MdeModulePkg/Core/Pei/Ppi/Ppi.c b/MdeModulePkg/Core/Pei/Ppi/Ppi.c index 0184f206b9..0ea343c252 100644 --- a/MdeModulePkg/Core/Pei/Ppi/Ppi.c +++ b/MdeModulePkg/Core/Pei/Ppi/Ppi.c @@ -1117,7 +1117,12 @@ ConvertPeiCorePpiPointers ( // Find PEI Core EntryPoint in the BFV in temporary memory. // // FIXME: "Assume" sanity and skip full initialisation? - Status = UefiImageInitializeContext (&ImageContext, (VOID *) (UINTN) PeiCoreImageBase, PeiCoreImageSize); + Status = UefiImageInitializeContext ( + &ImageContext, + (VOID *) (UINTN) PeiCoreImageBase, + PeiCoreImageSize, + UEFI_IMAGE_SOURCE_FV + ); ASSERT_EFI_ERROR (Status); OrgImageBase = (UINTN)PeiCoreImageBase; diff --git a/MdeModulePkg/Core/PiSmmCore/Dispatcher.c b/MdeModulePkg/Core/PiSmmCore/Dispatcher.c index 324140a0b0..068fcee891 100644 --- a/MdeModulePkg/Core/PiSmmCore/Dispatcher.c +++ b/MdeModulePkg/Core/PiSmmCore/Dispatcher.c @@ -339,7 +339,12 @@ SmmLoadImage ( // // Get information about the image being loaded // - Status = UefiImageInitializeContextPreHash (ImageContext, Buffer, (UINT32) Size); + Status = UefiImageInitializeContextPreHash ( + ImageContext, + Buffer, + (UINT32) Size, + UEFI_IMAGE_SOURCE_FV + ); if (EFI_ERROR (Status)) { if (Buffer != NULL) { gBS->FreePool (Buffer); diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf index d14f76b65f..d0cbf48f8d 100644 --- a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf +++ b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf @@ -48,7 +48,7 @@ UefiDriverEntryPoint BaseLib BaseMemoryLib - UefiImageLib + UefiImageOnlyFvLib CacheMaintenanceLib DebugLib ReportStatusCodeLib diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c b/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c index 524a74bdc4..8b78d965af 100644 --- a/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c +++ b/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c @@ -1003,7 +1003,12 @@ ExecuteSmmCoreFromSmram ( // // Get information about the image being loaded // - Status = UefiImageInitializeContext (&gSmmCorePrivate->PiSmmCoreImageContext, SourceBuffer, (UINT32) SourceSize); + Status = UefiImageInitializeContext ( + &gSmmCorePrivate->PiSmmCoreImageContext, + SourceBuffer, + (UINT32) SourceSize, + UEFI_IMAGE_SOURCE_FV + ); if (EFI_ERROR (Status)) { return Status; } diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.inf b/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.inf index 60d14cd59c..a8d0858b51 100644 --- a/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.inf +++ b/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.inf @@ -35,7 +35,7 @@ UefiDriverEntryPoint BaseLib BaseMemoryLib - UefiImageLib + UefiImageOnlyFvLib CacheMaintenanceLib MemoryAllocationLib DebugLib diff --git a/MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf b/MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf index 36d282d69a..1162d54983 100644 --- a/MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf +++ b/MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf @@ -39,7 +39,7 @@ MdePkg/MdePkg.dec [LibraryClasses] - UefiImageLib + UefiImageAllLib CacheMaintenanceLib UefiBootServicesTableLib UefiLib diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc index 6f61afab86..474f3c03e0 100644 --- a/MdeModulePkg/MdeModulePkg.dsc +++ b/MdeModulePkg/MdeModulePkg.dsc @@ -44,7 +44,6 @@ PciSegmentLib|MdePkg/Library/BasePciSegmentLibPci/BasePciSegmentLibPci.inf CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf PeCoffLib2|MdePkg/Library/BasePeCoffLib2/BasePeCoffLib2.inf - UefiImageLib|MdePkg/Library/BaseUefiImageLib/BaseUefiImageLibPeCoff.inf SortLib|MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf # # UEFI & PI diff --git a/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf b/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf index 22a28df8e6..3d25b12748 100644 --- a/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf +++ b/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf @@ -49,7 +49,7 @@ UefiDriverEntryPoint BaseLib S3BootScriptLib - UefiImageLib + UefiImageOnlyFvLib DxeServicesLib UefiBootServicesTableLib CacheMaintenanceLib diff --git a/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/ScriptExecute.c b/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/ScriptExecute.c index 4599425859..04dd595f79 100644 --- a/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/ScriptExecute.c +++ b/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/ScriptExecute.c @@ -310,7 +310,12 @@ ReadyToLockEventNotify ( // // Get information about the image being loaded // - Status = UefiImageInitializeContext (&ImageContext, Buffer, (UINT32) BufferSize); + Status = UefiImageInitializeContext ( + &ImageContext, + Buffer, + (UINT32) BufferSize, + UEFI_IMAGE_SOURCE_FV + ); ASSERT_EFI_ERROR (Status); ImageSize = UefiImageGetImageSize (&ImageContext); ImageAlignment = UefiImageGetSegmentAlignment (&ImageContext); diff --git a/MdePkg/Include/Library/PeCoffLib2.h b/MdePkg/Include/Library/PeCoffLib2.h index 95222dfdef..d1438b8a6a 100644 --- a/MdePkg/Include/Library/PeCoffLib2.h +++ b/MdePkg/Include/Library/PeCoffLib2.h @@ -497,19 +497,6 @@ PeCoffGetSizeOfImage ( IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *Context ); -/** - Retrieves the size, in Bytes, of the Image memory space for in-place loading. - - @param[in,out] Context The context describing the Image. Must have been - initialised by PeCoffInitializeContext(). - - @returns The size of the Image memory space for in-place loading. -**/ -UINT32 -PeCoffGetSizeOfImageInplace ( - IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *Context - ); - /** Retrieves the Image preferred load address. diff --git a/MdePkg/Include/Library/UefiImageLib.h b/MdePkg/Include/Library/UefiImageLib.h index ecdb706fd9..1bd574e775 100644 --- a/MdePkg/Include/Library/UefiImageLib.h +++ b/MdePkg/Include/Library/UefiImageLib.h @@ -2,18 +2,28 @@ #ifndef UEFI_IMAGE_LIB_H_ #define UEFI_IMAGE_LIB_H_ +#include + typedef enum { UefiImageFormatPe = 0, UefiImageFormatMax } UEFI_IMAGE_FORMAT; -// FIXME: Work on reasonable abstraction -#ifndef UEFI_IMAGE_LOADER_IMAGE_CONTEXT - #include +#define UEFI_IMAGE_SOURCE_NON_FV 0U +#define UEFI_IMAGE_SOURCE_FV 1U +#define UEFI_IMAGE_SOURCE_ALL 2U +#define UEFI_IMAGE_SOURCE_MAX 3U - #define UEFI_IMAGE_LOADER_IMAGE_CONTEXT PE_COFF_LOADER_IMAGE_CONTEXT - #define UEFI_IMAGE_LOADER_RUNTIME_CONTEXT PE_COFF_LOADER_RUNTIME_CONTEXT -#endif +typedef UINT8 UEFI_IMAGE_SOURCE; + +typedef struct { + UINT8 FormatIndex; + union { + PE_COFF_LOADER_IMAGE_CONTEXT Pe; + } Ctx; +} UEFI_IMAGE_LOADER_IMAGE_CONTEXT; + +typedef struct UEFI_IMAGE_LOADER_RUNTIME_CONTEXT_ UEFI_IMAGE_LOADER_RUNTIME_CONTEXT; /// /// Image record segment that desribes the UEFI memory permission configuration @@ -95,7 +105,8 @@ RETURN_STATUS UefiImageInitializeContextPreHash ( OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, IN CONST VOID *FileBuffer, - IN UINT32 FileSize + IN UINT32 FileSize, + IN UEFI_IMAGE_SOURCE Source ); RETURN_STATUS @@ -122,7 +133,8 @@ RETURN_STATUS UefiImageInitializeContext ( OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, IN CONST VOID *FileBuffer, - IN UINT32 FileSize + IN UINT32 FileSize, + IN UEFI_IMAGE_SOURCE Source ); /** @@ -235,7 +247,7 @@ UefiImageLoaderGetRuntimeContextSize ( Relocate the Image for boot-time usage. May only be called when UefiImageGetRelocsStripped() returns FALSE, or with - BaseAddress == UefiImageGetPreferredAddress(). + BaseAddress == UefiImageGetBaseAddress(). @param[in,out] Context The context describing the Image. Must have been loaded by UefiImageLoadImage(). @@ -263,7 +275,7 @@ UefiImageRelocateImage ( the Image. May only be called when UefiImageGetRelocsStripped() returns FALSE, or with - BaseAddress == UefiImageGetPreferredAddress(). + BaseAddress == UefiImageGetBaseAddress(). @param[in,out] Context The context describing the Image. Must have been initialised by @@ -296,7 +308,7 @@ UefiImageLoadImageForExecution ( Relocate Image for Runtime usage. May only be called when UefiImageGetRelocsStripped() returns FALSE, or with - BaseAddress == UefiImageGetPreferredAddress(). + BaseAddress == UefiImageGetBaseAddress(). @param[in,out] Image The Image destination memory. Must have been relocated by UefiImageRelocateImage(). @@ -321,7 +333,7 @@ UefiImageRuntimeRelocateImage ( required to execute code from the Image. May only be called when UefiImageGetRelocsStripped() returns FALSE, or with - BaseAddress == UefiImageGetPreferredAddress(). + BaseAddress == UefiImageGetBaseAddress(). @param[in,out] Image The Image destination memory. Must have been relocated by UefiImageRelocateImage(). @@ -521,12 +533,6 @@ UefiImageGetImageSize ( IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context ); -// FIXME: Docs -UINT32 -UefiImageGetImageSizeInplace ( - IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context - ); - /** Retrieves the Image preferred load address. @@ -536,7 +542,7 @@ UefiImageGetImageSizeInplace ( @returns The Image preferred load address. **/ UINT64 -UefiImageGetPreferredAddress ( +UefiImageGetBaseAddress ( IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context ); diff --git a/MdePkg/Library/BasePeCoffLib2/PeCoffInfo.c b/MdePkg/Library/BasePeCoffLib2/PeCoffInfo.c index 5b36cf2794..b6e76b923b 100644 --- a/MdePkg/Library/BasePeCoffLib2/PeCoffInfo.c +++ b/MdePkg/Library/BasePeCoffLib2/PeCoffInfo.c @@ -70,16 +70,6 @@ PeCoffGetSizeOfImage ( return Context->SizeOfImage; } -UINT32 -PeCoffGetSizeOfImageInplace ( - IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *Context - ) -{ - ASSERT (Context != NULL); - - return Context->SizeOfImage; -} - UINT64 PeCoffGetImageBase ( IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *Context diff --git a/MdePkg/Library/BaseUefiImageLib/BaseUefiImageAllLib.inf b/MdePkg/Library/BaseUefiImageLib/BaseUefiImageAllLib.inf new file mode 100644 index 0000000000..6ad64cb959 --- /dev/null +++ b/MdePkg/Library/BaseUefiImageLib/BaseUefiImageAllLib.inf @@ -0,0 +1,48 @@ +## @file +# UEFI Image Loader library implementation for UE FV and PE non-FV Images. +# +# Copyright (c) 2023, Marvin Häuser. All rights reserved.
+# +# SPDX-License-Identifier: BSD-3-Clause +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = BaseUefiImageLibAll + FILE_GUID = 499d294d-9f0f-4e8d-82fa-1892e6378996 + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = UefiImageLib + LIBRARY_CLASS = UefiImageAllLib + +[Sources] + CommonSupport.c + ExecutionSupport.c + PeSupport.c + UefiImageLib.c + +[Packages] + MdePkg/MdePkg.dec + +[LibraryClasses] + BaseLib + BaseOverflowLib + BaseMemoryLib + CacheMaintenanceLib + DebugLib + MemoryAllocationLib + PeCoffLib2 + UefiImageExtraActionLib + +[FixedPcd] + gEfiMdePkgTokenSpaceGuid.PcdImageLoaderAlignmentPolicy + gEfiMdePkgTokenSpaceGuid.PcdImageLoaderLoadHeader + gEfiMdePkgTokenSpaceGuid.PcdImageLoaderRemoveXForWX + gEfiMdePkgTokenSpaceGuid.PcdDebugRaisePropertyMask + + gEfiMdePkgTokenSpaceGuid.PcdUefiImageFormatSupportNonFv + gEfiMdePkgTokenSpaceGuid.PcdUefiImageFormatSupportFv + +[BuildOptions] + *_*_*_CC_FLAGS = -DUEFI_IMAGE_FORMAT_SUPPORT_SOURCES=0x03 + MSFT:*_*_*_CC_FLAGS = /wd4204 diff --git a/MdePkg/Library/BaseUefiImageLib/BaseUefiImageLibPeCoff.inf b/MdePkg/Library/BaseUefiImageLib/BaseUefiImageOnlyFvLib.inf similarity index 53% rename from MdePkg/Library/BaseUefiImageLib/BaseUefiImageLibPeCoff.inf rename to MdePkg/Library/BaseUefiImageLib/BaseUefiImageOnlyFvLib.inf index 4e1cfe6058..cbdcc58644 100644 --- a/MdePkg/Library/BaseUefiImageLib/BaseUefiImageLibPeCoff.inf +++ b/MdePkg/Library/BaseUefiImageLib/BaseUefiImageOnlyFvLib.inf @@ -1,25 +1,25 @@ ## @file -# UEFI Image Loader library implementation for PE/COFF Images. +# UEFI Image Loader library implementation for UE FV Images. # -# Copyright (c) 2021, Marvin Häuser. All rights reserved.
+# Copyright (c) 2023, Marvin Häuser. All rights reserved.
# # SPDX-License-Identifier: BSD-3-Clause ## [Defines] INF_VERSION = 0x00010005 - BASE_NAME = BaseUefiImageLibPeCoff - FILE_GUID = 357AD87E-8D6B-468A-B3FA-0D9CC4C725CD + BASE_NAME = BaseUefiImageLibOnlyFv + FILE_GUID = 11bb7a90-175d-4117-a66f-65b84a9544b7 MODULE_TYPE = BASE VERSION_STRING = 1.0 LIBRARY_CLASS = UefiImageLib + LIBRARY_CLASS = UefiImageOnlyFvLib [Sources] CommonSupport.c ExecutionSupport.c - PeCoffSupport.h - PeCoffSupport.c - UefiImageLibPeCoff.c + PeSupport.c + UefiImageLib.c [Packages] MdePkg/MdePkg.dec @@ -39,3 +39,9 @@ gEfiMdePkgTokenSpaceGuid.PcdImageLoaderLoadHeader gEfiMdePkgTokenSpaceGuid.PcdDebugRaisePropertyMask gEfiMdePkgTokenSpaceGuid.PcdImageLoaderRemoveXForWX + gEfiMdePkgTokenSpaceGuid.PcdUefiImageFormatSupportNonFv + gEfiMdePkgTokenSpaceGuid.PcdUefiImageFormatSupportFv + +[BuildOptions] + *_*_*_CC_FLAGS = -DUEFI_IMAGE_FORMAT_SUPPORT_SOURCES=0x02 + MSFT:*_*_*_CC_FLAGS = /wd4204 diff --git a/MdePkg/Library/BaseUefiImageLib/BaseUefiImageOnlyNonFvLib.inf b/MdePkg/Library/BaseUefiImageLib/BaseUefiImageOnlyNonFvLib.inf new file mode 100644 index 0000000000..3c8f23e895 --- /dev/null +++ b/MdePkg/Library/BaseUefiImageLib/BaseUefiImageOnlyNonFvLib.inf @@ -0,0 +1,48 @@ +## @file +# UEFI Image Loader library implementation for UE non-FV Images. +# +# Copyright (c) 2023, Marvin Häuser. All rights reserved.
+# +# SPDX-License-Identifier: BSD-3-Clause +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = BaseUefiImageLibOnlyNonFv + FILE_GUID = 297b4e3e-2cfa-4350-8fa5-ad11dec48e75 + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = UefiImageLib + LIBRARY_CLASS = UefiImageOnlyNonFvLib + +[Sources] + CommonSupport.c + ExecutionSupport.c + PeSupport.c + UefiImageLib.c + +[Packages] + MdePkg/MdePkg.dec + +[LibraryClasses] + BaseLib + BaseOverflowLib + BaseMemoryLib + CacheMaintenanceLib + DebugLib + MemoryAllocationLib + PeCoffLib2 + UefiImageExtraActionLib + +[FixedPcd] + gEfiMdePkgTokenSpaceGuid.PcdImageLoaderAlignmentPolicy + gEfiMdePkgTokenSpaceGuid.PcdImageLoaderLoadHeader + gEfiMdePkgTokenSpaceGuid.PcdImageLoaderRemoveXForWX + gEfiMdePkgTokenSpaceGuid.PcdDebugRaisePropertyMask + + gEfiMdePkgTokenSpaceGuid.PcdUefiImageFormatSupportNonFv + gEfiMdePkgTokenSpaceGuid.PcdUefiImageFormatSupportFv + +[BuildOptions] + *_*_*_CC_FLAGS = -DUEFI_IMAGE_FORMAT_SUPPORT_SOURCES=0x01 + MSFT:*_*_*_CC_FLAGS = /wd4204 diff --git a/MdePkg/Library/BaseUefiImageLib/CommonSupport.c b/MdePkg/Library/BaseUefiImageLib/CommonSupport.c index 70a191c2af..90124bc7cd 100644 --- a/MdePkg/Library/BaseUefiImageLib/CommonSupport.c +++ b/MdePkg/Library/BaseUefiImageLib/CommonSupport.c @@ -18,12 +18,18 @@ RETURN_STATUS UefiImageInitializeContext ( OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, IN CONST VOID *FileBuffer, - IN UINT32 FileSize + IN UINT32 FileSize, + IN UEFI_IMAGE_SOURCE Source ) { RETURN_STATUS Status; - Status = UefiImageInitializeContextPreHash (Context, FileBuffer, FileSize); + Status = UefiImageInitializeContextPreHash ( + Context, + FileBuffer, + FileSize, + Source + ); if (RETURN_ERROR (Status)) { return Status; } @@ -31,6 +37,14 @@ UefiImageInitializeContext ( return UefiImageInitializeContextPostHash (Context); } +UINT8 +UefiImageGetFormat ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context + ) +{ + return Context->FormatIndex; +} + UINTN UefiImageLoaderGetImageEntryPoint ( IN CONST UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context diff --git a/MdePkg/Library/BaseUefiImageLib/ExecutionSupport.c b/MdePkg/Library/BaseUefiImageLib/ExecutionSupport.c index 63f5b00466..a4a576d3fd 100644 --- a/MdePkg/Library/BaseUefiImageLib/ExecutionSupport.c +++ b/MdePkg/Library/BaseUefiImageLib/ExecutionSupport.c @@ -30,7 +30,7 @@ UefiImageRelocateImageInplaceForExecution ( } ImageAddress = UefiImageLoaderGetImageAddress (Context); - ImageSize = UefiImageGetImageSizeInplace (Context); + ImageSize = UefiImageGetImageSize (Context); // // Flush the instruction cache so the image data is written before // execution. diff --git a/MdePkg/Library/BaseUefiImageLib/PeCoffSupport.h b/MdePkg/Library/BaseUefiImageLib/PeCoffSupport.h deleted file mode 100644 index 6c5098362d..0000000000 --- a/MdePkg/Library/BaseUefiImageLib/PeCoffSupport.h +++ /dev/null @@ -1,37 +0,0 @@ -/** @file - UEFI Image Loader library implementation for PE/COFF Images. - - Copyright (c) 2021, Marvin Häuser. All rights reserved.
- - SPDX-License-Identifier: BSD-3-Clause -**/ - -#ifndef PE_COFF_SUPPORT_H_ -#define PE_COFF_SUPPORT_H_ - -#include -#include - -UEFI_IMAGE_RECORD * -UefiImageLoaderGetImageRecordPeCoff ( - IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *Context - ); - -RETURN_STATUS -UefiImageDebugLocateImagePeCoff ( - OUT PE_COFF_LOADER_IMAGE_CONTEXT *Context, - IN UINTN Address - ); - -RETURN_STATUS -UefiImageGetFixedAddressPeCoff ( - IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *Context, - OUT UINT64 *Address - ); - -VOID -UefiImageDebugPrintSegmentsPeCoff ( - IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *Context - ); - -#endif // PE_COFF_SUPPORT_H_ diff --git a/MdePkg/Library/BaseUefiImageLib/PeCoffSupport.c b/MdePkg/Library/BaseUefiImageLib/PeSupport.c similarity index 66% rename from MdePkg/Library/BaseUefiImageLib/PeCoffSupport.c rename to MdePkg/Library/BaseUefiImageLib/PeSupport.c index 926914e7c9..0698a60461 100644 --- a/MdePkg/Library/BaseUefiImageLib/PeCoffSupport.c +++ b/MdePkg/Library/BaseUefiImageLib/PeSupport.c @@ -19,6 +19,222 @@ #include #include #include +#include + +#include "PeSupport.h" + +RETURN_STATUS +UefiImageInitializeContextPreHashPe ( + OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, + IN CONST VOID *FileBuffer, + IN UINT32 FileSize + ) +{ + return PeCoffInitializeContext (&Context->Ctx.Pe, FileBuffer, FileSize); +} + +BOOLEAN +UefiImageHashImageDefaultPe ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, + IN OUT VOID *HashContext, + IN UEFI_IMAGE_LOADER_HASH_UPDATE HashUpdate + ) +{ + return PeCoffHashImageAuthenticode (&Context->Ctx.Pe, HashContext, HashUpdate); +} + +RETURN_STATUS +UefiImageInitializeContextPostHashPe ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context + ) +{ + return RETURN_SUCCESS; +} + +RETURN_STATUS +UefiImageLoadImagePe ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, + OUT VOID *Destination, + IN UINT32 DestinationSize + ) +{ + return PeCoffLoadImage (&Context->Ctx.Pe, Destination, DestinationSize); +} + +BOOLEAN +UefiImageImageIsInplacePe ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context + ) +{ + return PeCoffImageIsInplace (&Context->Ctx.Pe); +} + +RETURN_STATUS +UefiImageLoadImageInplacePe ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context + ) +{ + return PeCoffLoadImageInplace (&Context->Ctx.Pe); +} + +RETURN_STATUS +UefiImageRelocateImageInplacePe ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context + ) +{ + return PeCoffRelocateImageInplace (&Context->Ctx.Pe); +} + +RETURN_STATUS +UefiImageLoaderGetRuntimeContextSizePe ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, + OUT UINT32 *Size + ) +{ + return PeCoffLoaderGetRuntimeContextSize (&Context->Ctx.Pe, Size); +} + +RETURN_STATUS +UefiImageRelocateImagePe ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, + IN UINT64 BaseAddress, + OUT UEFI_IMAGE_LOADER_RUNTIME_CONTEXT *RuntimeContext OPTIONAL, + IN UINT32 RuntimeContextSize + ) +{ + return PeCoffRelocateImage ( + &Context->Ctx.Pe, + BaseAddress, + (PE_COFF_LOADER_RUNTIME_CONTEXT *)RuntimeContext, + RuntimeContextSize + ); +} + +RETURN_STATUS +UefiImageRuntimeRelocateImagePe ( + IN OUT VOID *Image, + IN UINT32 ImageSize, + IN UINT64 BaseAddress, + IN CONST VOID *RuntimeContext + ) +{ + return PeCoffRuntimeRelocateImage ( + Image, + ImageSize, + BaseAddress, + (CONST PE_COFF_LOADER_RUNTIME_CONTEXT *)RuntimeContext + ); +} + +VOID +UefiImageDiscardSegmentsPe ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context + ) +{ + PeCoffDiscardSections (&Context->Ctx.Pe); +} + +RETURN_STATUS +UefiImageGetSymbolsPathPe ( + IN CONST UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, + OUT CONST CHAR8 **SymbolsPath, + OUT UINT32 *SymbolsPathSize + ) +{ + return PeCoffGetPdbPath (&Context->Ctx.Pe, SymbolsPath, SymbolsPathSize); +} + +RETURN_STATUS +UefiImageGetFirstCertificatePe ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, + OUT CONST WIN_CERTIFICATE **Certificate + ) +{ + return PeCoffGetFirstCertificate (&Context->Ctx.Pe, Certificate); +} + +RETURN_STATUS +UefiImageGetNextCertificatePe ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, + IN OUT CONST WIN_CERTIFICATE **Certificate + ) +{ + return PeCoffGetNextCertificate (&Context->Ctx.Pe, Certificate); +} + +RETURN_STATUS +UefiImageGetHiiDataRvaPe ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, + OUT UINT32 *HiiRva, + OUT UINT32 *HiiSize + ) +{ + return PeCoffGetHiiDataRva (&Context->Ctx.Pe, HiiRva, HiiSize); +} + +UINT32 +UefiImageGetEntryPointAddressPe ( + IN CONST UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context + ) +{ + return PeCoffGetAddressOfEntryPoint (&Context->Ctx.Pe); +} + +UINT16 +UefiImageGetMachinePe ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context + ) +{ + return PeCoffGetMachine (&Context->Ctx.Pe); +} + +UINT16 +UefiImageGetSubsystemPe ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context + ) +{ + return PeCoffGetSubsystem (&Context->Ctx.Pe); +} + +UINT32 +UefiImageGetSegmentAlignmentPe ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context + ) +{ + return PeCoffGetSectionAlignment (&Context->Ctx.Pe); +} + +UINT32 +UefiImageGetImageSizePe ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context + ) +{ + return PeCoffGetSizeOfImage (&Context->Ctx.Pe); +} + +UINT64 +UefiImageGetBaseAddressPe ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context + ) +{ + return PeCoffGetImageBase (&Context->Ctx.Pe); +} + +BOOLEAN +UefiImageGetRelocsStrippedPe ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context + ) +{ + return PeCoffGetRelocsStripped (&Context->Ctx.Pe); +} + +UINTN +UefiImageLoaderGetImageAddressPe ( + IN CONST UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context + ) +{ + return PeCoffLoaderGetImageAddress (&Context->Ctx.Pe); +} /** Retrieves the memory protection attributes corresponding to PE/COFF Image @@ -107,8 +323,8 @@ InternalInsertImageRecordSegmentPadding ( } UEFI_IMAGE_RECORD * -UefiImageLoaderGetImageRecordPeCoff ( - IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *Context +UefiImageLoaderGetImageRecordPe ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context ) { UEFI_IMAGE_RECORD *ImageRecord; @@ -135,7 +351,7 @@ UefiImageLoaderGetImageRecordPeCoff ( // Determine the maximum amount of Image record sections and allocate the // Image record. // - NumberOfSections = PeCoffGetSectionTable (Context, &Sections); + NumberOfSections = PeCoffGetSectionTable (&Context->Ctx.Pe, &Sections); STATIC_ASSERT ( MAX_UINT16 <= MAX_UINT32 / 2 - 1, @@ -162,14 +378,13 @@ UefiImageLoaderGetImageRecordPeCoff ( + MaxNumRecordSegments * sizeof (*ImageRecord->Segments) ); if (ImageRecord == NULL) { - DEBUG_RAISE (); return NULL; } ImageRecord->Signature = UEFI_IMAGE_RECORD_SIGNATURE; InitializeListHead (&ImageRecord->Link); - SectionAlignment = PeCoffGetSectionAlignment (Context); + SectionAlignment = PeCoffGetSectionAlignment (&Context->Ctx.Pe); // // Map the Image Headers as read-only data. If the first Image section is // loaded at the start of the Image memory space, the condition @@ -177,7 +392,7 @@ UefiImageLoaderGetImageRecordPeCoff ( // ignored. // StartAddress = 0; - EndAddress = PeCoffGetSizeOfHeaders (Context); + EndAddress = PeCoffGetSizeOfHeaders (&Context->Ctx.Pe); Characteristics = EFI_IMAGE_SCN_MEM_READ; Attributes = EFI_MEMORY_XP | EFI_MEMORY_RO; ASSERT (Attributes == InternalCharacteristicsToAttributes (Characteristics)); @@ -268,8 +483,8 @@ UefiImageLoaderGetImageRecordPeCoff ( RecordSegment->Attributes = Attributes; ++NumRecordSegments; - ImageAddress = PeCoffLoaderGetImageAddress (Context); - SizeOfImage = PeCoffGetSizeOfImage (Context); + ImageAddress = PeCoffLoaderGetImageAddress (&Context->Ctx.Pe); + SizeOfImage = PeCoffGetSizeOfImage (&Context->Ctx.Pe); // // The Image trailer, if existent, is treated as padding and as such is // reported as read-only data, as intended. Because it is not part of the @@ -318,14 +533,16 @@ InternalDebugLocateImage ( // // Search for the Image Header in 4 Byte steps. All dynamically loaded // Images start at a page boundary to allow for Image section protection, - // but XIP Images may not. + // but XIP Images may not. As all Image Headers are at least 4 Byte aligned + // due to natural alignment, even XIP TE Image Headers should start at a + // 4 Byte boundary. // // Do not attempt to access memory of the first page as it may be protected as // part of NULL dereference detection. // for (; EFI_PAGE_SIZE <= (UINTN) Buffer; Buffer -= 4) { // - // Try to parse the current memory as PE/COFF Image. Pass MAX_UINT32 + // Try to parse the current memory as PE/COFF or TE Image. Pass MAX_UINT32 // as the file size as there isn't any more information available. Only the // Image Header memory will be accessed as part of initialisation. // @@ -362,6 +579,7 @@ InternalDebugLocateImage ( // // We know that (UINTN) Buffer <= Address from the initialisation. // + // FIXME: Set to non-stripped base for XIP TE Images. if (Address < (UINTN) Buffer + PeCoffGetSizeOfImage (Context)) { Context->ImageBuffer = Buffer; // @@ -374,7 +592,7 @@ InternalDebugLocateImage ( return RETURN_SUCCESS; } // - // Continue for the unlikely case that a PE/COFF Image embeds another + // Continue for the unlikely case that a PE/COFF or TE Image embeds another // one within its data, the outer Image may still follow. // } @@ -383,9 +601,9 @@ InternalDebugLocateImage ( } RETURN_STATUS -UefiImageDebugLocateImagePeCoff ( - OUT PE_COFF_LOADER_IMAGE_CONTEXT *Context, - IN UINTN Address +UefiImageDebugLocateImagePe ( + OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, + IN UINTN Address ) { RETURN_STATUS Status; @@ -404,14 +622,15 @@ UefiImageDebugLocateImagePeCoff ( // the Image base to not access too much (potentially protected) memory. // if (!PcdGetBool (PcdImageLoaderLoadHeader)) { - DEBUG_RAISE (); return RETURN_NOT_FOUND; } + + Context->FormatIndex = UefiImageFormatPe; // // Align the search buffer to a 4 Byte boundary. // Status = InternalDebugLocateImage ( - Context, + &Context->Ctx.Pe, (CHAR8 *) (Address & ~(UINTN) 3U), Address, FALSE @@ -423,24 +642,27 @@ UefiImageDebugLocateImagePeCoff ( } RETURN_STATUS -UefiImageGetFixedAddressPeCoff ( - IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *Context, - OUT UINT64 *Address +UefiImageGetFixedAddressPe ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, + OUT UINT64 *Address ) { + UINT32 SectionAlignment; CONST EFI_IMAGE_SECTION_HEADER *Sections; UINT16 NumberOfSections; UINT16 SectionIndex; UINT64 FixedAddress; ASSERT (Address != NULL); + + SectionAlignment = PeCoffGetSectionAlignment (&Context->Ctx.Pe); // // If this feature is enabled, the build tool will save the address in the // PointerToRelocations and PointerToLineNumbers fields of the first Image // section header that doesn't hold code. The 64-bit value across those fields // will be non-zero if and only if the module has been assigned an address. // - NumberOfSections = PeCoffGetSectionTable (Context, &Sections); + NumberOfSections = PeCoffGetSectionTable (&Context->Ctx.Pe, &Sections); for (SectionIndex = 0; SectionIndex < NumberOfSections; ++SectionIndex) { if ((Sections[SectionIndex].Characteristics & EFI_IMAGE_SCN_CNT_CODE) != 0) { continue; @@ -450,7 +672,7 @@ UefiImageGetFixedAddressPeCoff ( (CONST VOID *) &Sections[SectionIndex].PointerToRelocations ); if (FixedAddress != 0) { - if (!IS_ALIGNED (FixedAddress, Context->SectionAlignment)) { + if (!IS_ALIGNED (FixedAddress, SectionAlignment)) { return RETURN_UNSUPPORTED; } @@ -465,8 +687,8 @@ UefiImageGetFixedAddressPeCoff ( } VOID -UefiImageDebugPrintSegmentsPeCoff ( - IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *Context +UefiImageDebugPrintSegmentsPe ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context ) { CONST EFI_IMAGE_SECTION_HEADER *Sections; @@ -474,30 +696,27 @@ UefiImageDebugPrintSegmentsPeCoff ( UINT16 SectionIndex; CONST UINT8 *Name; - NumberOfSections = PeCoffGetSectionTable (Context, &Sections); + NumberOfSections = PeCoffGetSectionTable (&Context->Ctx.Pe, &Sections); for (SectionIndex = 0; SectionIndex < NumberOfSections; ++SectionIndex) { Name = Sections[SectionIndex].Name; DEBUG (( DEBUG_VERBOSE, - " Section - '%c%c%c%c%c%c%c%c'\n" + " Section - '%c%c%c%c%c%c%c%c'\n", " VirtualSize - 0x%08x\n" " VirtualAddress - 0x%08x\n" " SizeOfRawData - 0x%08x\n" - " PointerToRawData - 0x%08x\n", - Name[0], Name[1], Name[2], Name[3], Name[4], Name[5], Name[6], Name[7], - Sections[SectionIndex].VirtualSize, - Sections[SectionIndex].VirtualAddress, - Sections[SectionIndex].SizeOfRawData, - Sections[SectionIndex].PointerToRawData - )); - DEBUG (( - DEBUG_VERBOSE, + " PointerToRawData - 0x%08x\n" " PointerToRelocations - 0x%08x\n" " PointerToLinenumbers - 0x%08x\n" " NumberOfRelocations - 0x%08x\n" " NumberOfLinenumbers - 0x%08x\n" " Characteristics - 0x%08x\n", + Name[0], Name[1], Name[2], Name[3], Name[4], Name[5], Name[6], Name[7], + Sections[SectionIndex].VirtualSize, + Sections[SectionIndex].VirtualAddress, + Sections[SectionIndex].SizeOfRawData, + Sections[SectionIndex].PointerToRawData, Sections[SectionIndex].PointerToRelocations, Sections[SectionIndex].PointerToLinenumbers, Sections[SectionIndex].NumberOfRelocations, @@ -506,3 +725,33 @@ UefiImageDebugPrintSegmentsPeCoff ( )); } } + +GLOBAL_REMOVE_IF_UNREFERENCED CONST UEFI_IMAGE_FORMAT_SUPPORT mPeSupport = { + UefiImageInitializeContextPreHashPe, + UefiImageHashImageDefaultPe, + UefiImageInitializeContextPostHashPe, + UefiImageLoadImagePe, + UefiImageImageIsInplacePe, + UefiImageLoadImageInplacePe, + UefiImageRelocateImageInplacePe, + UefiImageLoaderGetRuntimeContextSizePe, + UefiImageRelocateImagePe, + UefiImageRuntimeRelocateImagePe, + UefiImageDiscardSegmentsPe, + UefiImageGetSymbolsPathPe, + UefiImageGetFirstCertificatePe, + UefiImageGetNextCertificatePe, + UefiImageGetHiiDataRvaPe, + UefiImageGetEntryPointAddressPe, + UefiImageGetMachinePe, + UefiImageGetSubsystemPe, + UefiImageGetSegmentAlignmentPe, + UefiImageGetImageSizePe, + UefiImageGetBaseAddressPe, + UefiImageGetRelocsStrippedPe, + UefiImageLoaderGetImageAddressPe, + UefiImageLoaderGetImageRecordPe, + UefiImageDebugLocateImagePe, + UefiImageGetFixedAddressPe, + UefiImageDebugPrintSegmentsPe +}; diff --git a/MdePkg/Library/BaseUefiImageLib/PeSupport.h b/MdePkg/Library/BaseUefiImageLib/PeSupport.h new file mode 100644 index 0000000000..e25b122972 --- /dev/null +++ b/MdePkg/Library/BaseUefiImageLib/PeSupport.h @@ -0,0 +1,16 @@ +/** @file + UEFI Image Loader library implementation for PE/COFF Images. + + Copyright (c) 2021, Marvin Häuser. All rights reserved.
+ + SPDX-License-Identifier: BSD-3-Clause +**/ + +#ifndef PE_SUPPORT_H +#define PE_SUPPORT_H + +#include "UefiImageFormat.h" + +extern CONST UEFI_IMAGE_FORMAT_SUPPORT mPeSupport; + +#endif // PE_SUPPORT_H diff --git a/MdePkg/Library/BaseUefiImageLib/UefiImageFormat.h b/MdePkg/Library/BaseUefiImageLib/UefiImageFormat.h new file mode 100644 index 0000000000..f9e96287bf --- /dev/null +++ b/MdePkg/Library/BaseUefiImageLib/UefiImageFormat.h @@ -0,0 +1,235 @@ +/** @file + UEFI Image Loader library fornat support infrastructure. + + Copyright (c) 2023, Marvin Häuser. All rights reserved.
+ + SPDX-License-Identifier: BSD-3-Clause +**/ + +#ifndef UEFI_IMAGE_FORMAT_H +#define UEFI_IMAGE_FORMAT_H + +#include + +#include + +typedef +RETURN_STATUS +(*UEFI_IMAGE_INITIALIZE_CONTEXT_PRE_HASH) ( + OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, + IN CONST VOID *FileBuffer, + IN UINT32 FileSize + ); + +typedef +BOOLEAN +(*UEFI_IMAGE_HASH_IMAGE_DEFAULT) ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, + IN OUT VOID *HashContext, + IN UEFI_IMAGE_LOADER_HASH_UPDATE HashUpdate + ); + +typedef +RETURN_STATUS +(*UEFI_IMAGE_INITIALIZE_CONTEXT_POST_HASH) ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context + ); + +typedef +RETURN_STATUS +(*UEFI_IMAGE_LOAD_IMAGE) ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, + OUT VOID *Destination, + IN UINT32 DestinationSize + ); + +typedef +BOOLEAN +(*UEFI_IMAGE_IMAGE_IS_IN_PLACE) ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context + ); + +typedef +RETURN_STATUS +(*UEFI_IMAGE_LOAD_IMAGE_INPLACE) ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context + ); + +typedef +RETURN_STATUS +(*UEFI_IMAGE_RELOCAE_IMAGE_INPLACE) ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context + ); + +typedef +RETURN_STATUS +(*UEFI_IMAGE_LOADER_GET_RUNTIME_CONTEXT_SIZE) ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, + OUT UINT32 *Size + ); + +typedef +RETURN_STATUS +(*UEFI_IMAGE_RELOCARE_IMAGE) ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, + IN UINT64 BaseAddress, + OUT UEFI_IMAGE_LOADER_RUNTIME_CONTEXT *RuntimeContext OPTIONAL, + IN UINT32 RuntimeContextSize + ); + +typedef +RETURN_STATUS +(*UEFI_IMAGE_RUNTIME_RELOCATE_IMAGE) ( + IN OUT VOID *Image, + IN UINT32 ImageSize, + IN UINT64 BaseAddress, + IN CONST VOID *RuntimeContext + ); + +typedef +VOID +(*UEFI_IMAGE_DISCARD_SEGMENTS) ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context + ); + +typedef +RETURN_STATUS +(*UEFI_IMAGE_GET_SYMBOLS_PATH) ( + IN CONST UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, + OUT CONST CHAR8 **SymbolsPath, + OUT UINT32 *SymbolsPathSize + ); + +typedef +RETURN_STATUS +(*UEFI_IMAGE_GET_FIRST_CERTIFICATE) ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, + OUT CONST WIN_CERTIFICATE **Certificate + ); + +typedef +RETURN_STATUS +(*UEFI_IMAGE_GET_NEXT_CERTIFICATE) ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, + IN OUT CONST WIN_CERTIFICATE **Certificate + ); + +typedef +RETURN_STATUS +(*UEFI_IMAGE_GET_HII_DATA_RVA) ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, + OUT UINT32 *HiiRva, + OUT UINT32 *HiiSize + ); + +typedef +UINT32 +(*UEFI_IMAGE_GET_ENTRY_POINT_ADDRESS) ( + IN CONST UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context + ); + +typedef +UINT16 +(*UEFI_IMAGE_GET_MACHINE) ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context + ); + +typedef +UINT16 +(*UEFI_IMAGE_GET_SUBSYSTEM) ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context + ); + +typedef +UINT32 +(*UEFI_IMAGE_GET_SEGMENT_ALIGNMENT) ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context + ); + +typedef +UINT32 +(*UEFI_IMAGE_GET_IMAGE_SIZE) ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context + ); + +typedef +UINT32 +(*UEFI_IMAGE_GET_IMAGE_SIZE_INPLACE) ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context + ); + +typedef +UINT64 +(*UEFI_IMAGE_GET_BASE_ADDRESS) ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context + ); + +typedef +BOOLEAN +(*UEFI_IMAGE_GET_RELOCS_STRIPPED) ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context + ); + +typedef +UINTN +(*UEFI_IMAGE_LOADER_GET_IMAGE_ADDRESS) ( + IN CONST UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context + ); + +typedef +UEFI_IMAGE_RECORD * +(*UEFI_IMAGE_LOADER_GET_IMAGE_RECORD) ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context + ); + +typedef +RETURN_STATUS +(*UEFI_IMAGE_DEBUG_LOCATE_IMAGE) ( + OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, + IN UINTN Address + ); + +typedef +RETURN_STATUS +(*UEFI_IMAGE_GET_FIXED_ADDRESS) ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, + OUT UINT64 *Address + ); + +typedef +VOID +(*UEFI_IMAGE_DEBUG_PRINT_SEGMENTS) ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context + ); + +typedef struct { + UEFI_IMAGE_INITIALIZE_CONTEXT_PRE_HASH InitializeContextPreHash; + UEFI_IMAGE_HASH_IMAGE_DEFAULT HashImageDefault; + UEFI_IMAGE_INITIALIZE_CONTEXT_POST_HASH InitializeContextPostHash; + UEFI_IMAGE_LOAD_IMAGE LoadImage; + UEFI_IMAGE_IMAGE_IS_IN_PLACE ImageIsInplace; + UEFI_IMAGE_LOAD_IMAGE_INPLACE LoadImageInplace; + UEFI_IMAGE_RELOCAE_IMAGE_INPLACE RelocateImageInplace; + UEFI_IMAGE_LOADER_GET_RUNTIME_CONTEXT_SIZE LoaderGetRuntimeContextSize; + UEFI_IMAGE_RELOCARE_IMAGE RelocateImage; + UEFI_IMAGE_RUNTIME_RELOCATE_IMAGE RuntimeRelocateImage; + UEFI_IMAGE_DISCARD_SEGMENTS DiscardSegments; + UEFI_IMAGE_GET_SYMBOLS_PATH GetSymbolsPath; + UEFI_IMAGE_GET_FIRST_CERTIFICATE GetFirstCertificate; + UEFI_IMAGE_GET_NEXT_CERTIFICATE GetNextCertificate; + UEFI_IMAGE_GET_HII_DATA_RVA GetHiiDataRva; + UEFI_IMAGE_GET_ENTRY_POINT_ADDRESS GetEntryPointAddress; + UEFI_IMAGE_GET_MACHINE GetMachine; + UEFI_IMAGE_GET_SUBSYSTEM GetSubsystem; + UEFI_IMAGE_GET_SEGMENT_ALIGNMENT GetSegmentAlignment; + UEFI_IMAGE_GET_IMAGE_SIZE GetImageSize; + UEFI_IMAGE_GET_BASE_ADDRESS GetBaseAddress; + UEFI_IMAGE_GET_RELOCS_STRIPPED GetRelocsStripped; + UEFI_IMAGE_LOADER_GET_IMAGE_ADDRESS LoaderGetImageAddress; + UEFI_IMAGE_LOADER_GET_IMAGE_RECORD LoaderGetImageRecord; + UEFI_IMAGE_DEBUG_LOCATE_IMAGE DebugLocateImage; + UEFI_IMAGE_GET_FIXED_ADDRESS GetFixedAddress; + UEFI_IMAGE_DEBUG_PRINT_SEGMENTS DebugPrintSegments; +} UEFI_IMAGE_FORMAT_SUPPORT; + +#endif // UEFI_IMAGE_FORMAT_H diff --git a/MdePkg/Library/BaseUefiImageLib/UefiImageLib.c b/MdePkg/Library/BaseUefiImageLib/UefiImageLib.c new file mode 100644 index 0000000000..1803b49035 --- /dev/null +++ b/MdePkg/Library/BaseUefiImageLib/UefiImageLib.c @@ -0,0 +1,629 @@ +/** @file + UEFI Image Loader library implementation. + + Copyright (c) 2023, Marvin Häuser. All rights reserved.
+ + SPDX-License-Identifier: BSD-3-Clause +**/ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "PeSupport.h" + +STATIC_ASSERT ( + UEFI_IMAGE_FORMAT_SUPPORT_SOURCES != 0, + "At least one UEFI image format support source must be enabled." + ); + +#if (UEFI_IMAGE_FORMAT_SUPPORT_SOURCES & (1 << UEFI_IMAGE_SOURCE_NON_FV)) != 0 +#define UEFI_IMAGE_FORMAT_SUPPORT_NON_FV PcdGet8 (PcdUefiImageFormatSupportNonFv) +#else +#define UEFI_IMAGE_FORMAT_SUPPORT_NON_FV 0 +#endif + +#if (UEFI_IMAGE_FORMAT_SUPPORT_SOURCES & (1 << UEFI_IMAGE_SOURCE_FV)) != 0 +#define UEFI_IMAGE_FORMAT_SUPPORT_FV PcdGet8 (PcdUefiImageFormatSupportFv) +#else +#define UEFI_IMAGE_FORMAT_SUPPORT_FV 0 +#endif + +#define UEFI_IMAGE_SUPPORT \ + (UEFI_IMAGE_FORMAT_SUPPORT_NON_FV | UEFI_IMAGE_FORMAT_SUPPORT_FV) + +#define FORMAT_EQ(FormatIndex, Format) \ + (UEFI_IMAGE_SUPPORT == (1U << (Format)) || \ + ((UEFI_IMAGE_SUPPORT & (1U << (Format))) != 0 && \ + (FormatIndex) == (Format))) + +#define UEFI_IMAGE_EXEC(Result, FormatIndex, Func, ...) \ + do { \ + ASSERT ((FormatIndex) == UefiImageFormatPe); \ + Result = mPeSupport.Func (__VA_ARGS__); \ + } while (FALSE) + +#define UEFI_IMAGE_EXEC_VOID(FormatIndex, Func, ...) \ + do { \ + ASSERT ((FormatIndex) == UefiImageFormatPe); \ + mPeSupport.Func (__VA_ARGS__); \ + } while (FALSE) + +STATIC_ASSERT ( + UefiImageFormatPe == UefiImageFormatMax - 1, + "Support for more formats needs to be added above." + ); + +#define FORMAT_SUPPORTED(Format, Source) \ + ((UEFI_IMAGE_SUPPORT & (1U << (Format))) != 0 && \ + (mUefiImageSupportSource[Source] & (1U << (Format))) != 0) + +STATIC +RETURN_STATUS +InternalInitializeContextPreHash ( + OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, + IN CONST VOID *FileBuffer, + IN UINT32 FileSize, + IN UINT8 FormatIndex + ) +{ + RETURN_STATUS Status; + + UEFI_IMAGE_EXEC ( + Status, + FormatIndex, + InitializeContextPreHash, + Context, + FileBuffer, + FileSize + ); + + return Status; +} + +RETURN_STATUS +UefiImageInitializeContextPreHash ( + OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, + IN CONST VOID *FileBuffer, + IN UINT32 FileSize, + IN UEFI_IMAGE_SOURCE Source + ) +{ + CONST UINT8 mUefiImageSupportSource[UEFI_IMAGE_SOURCE_MAX] = { + UEFI_IMAGE_FORMAT_SUPPORT_NON_FV, + UEFI_IMAGE_FORMAT_SUPPORT_FV, + UEFI_IMAGE_SUPPORT + }; + + RETURN_STATUS Status; + +#if (UEFI_IMAGE_FORMAT_SUPPORT_SOURCES & (1U << UEFI_IMAGE_SOURCE_NON_FV)) != 0 + ASSERT ((PcdGet8 (PcdUefiImageFormatSupportNonFv) & ~((1ULL << UefiImageFormatMax) - 1ULL)) == 0); + ASSERT (PcdGet8 (PcdUefiImageFormatSupportNonFv) != 0); +#else + ASSERT (Source != UEFI_IMAGE_SOURCE_NON_FV); +#endif + +#if (UEFI_IMAGE_FORMAT_SUPPORT_SOURCES & (1U << UEFI_IMAGE_SOURCE_FV)) != 0 + ASSERT ((PcdGet8 (PcdUefiImageFormatSupportFv) & ~((1ULL << UefiImageFormatMax) - 1ULL)) == 0); + ASSERT (PcdGet8 (PcdUefiImageFormatSupportFv) != 0); +#else + ASSERT (Source != UEFI_IMAGE_SOURCE_FV); +#endif + + Status = RETURN_UNSUPPORTED; + + STATIC_ASSERT ( + UefiImageFormatPe == UefiImageFormatMax - 1, + "Support for more formats needs to be added above." + ); + + if (FORMAT_SUPPORTED (UefiImageFormatPe, Source)) { + Status = InternalInitializeContextPreHash ( + Context, + FileBuffer, + FileSize, + UefiImageFormatPe + ); + if (!RETURN_ERROR (Status)) { + Context->FormatIndex = UefiImageFormatPe; + return RETURN_SUCCESS; + } + } + + return Status; +} + +BOOLEAN +UefiImageHashImageDefault ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, + IN OUT VOID *HashContext, + IN UEFI_IMAGE_LOADER_HASH_UPDATE HashUpdate + ) +{ + BOOLEAN Success; + + UEFI_IMAGE_EXEC ( + Success, + Context->FormatIndex, + HashImageDefault, + Context, + HashContext, + HashUpdate + ); + + return Success; +} + +RETURN_STATUS +UefiImageInitializeContextPostHash ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context + ) +{ + RETURN_STATUS Status; + + UEFI_IMAGE_EXEC ( + Status, + Context->FormatIndex, + InitializeContextPostHash, + Context + ); + + return Status; +} + +RETURN_STATUS +UefiImageLoadImage ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, + OUT VOID *Destination, + IN UINT32 DestinationSize + ) +{ + RETURN_STATUS Status; + + UEFI_IMAGE_EXEC ( + Status, + Context->FormatIndex, + LoadImage, + Context, + Destination, + DestinationSize + ); + + return Status; +} + +BOOLEAN +UefiImageImageIsInplace ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context + ) +{ + BOOLEAN Result; + + UEFI_IMAGE_EXEC ( + Result, + Context->FormatIndex, + ImageIsInplace, + Context + ); + + return Result; +} + +RETURN_STATUS +UefiImageLoadImageInplace ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context + ) +{ + RETURN_STATUS Status; + + UEFI_IMAGE_EXEC ( + Status, + Context->FormatIndex, + LoadImageInplace, + Context + ); + + return Status; +} + +RETURN_STATUS +UefiImageRelocateImageInplace ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context + ) +{ + RETURN_STATUS Status; + + UEFI_IMAGE_EXEC ( + Status, + Context->FormatIndex, + RelocateImageInplace, + Context + ); + + return Status; +} + +RETURN_STATUS +UefiImageLoaderGetRuntimeContextSize ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, + OUT UINT32 *Size + ) +{ + RETURN_STATUS Status; + + UEFI_IMAGE_EXEC ( + Status, + Context->FormatIndex, + LoaderGetRuntimeContextSize, + Context, + Size + ); + if (!RETURN_ERROR (Status)) { + *Size += 8; + } + + return Status; +} + +RETURN_STATUS +UefiImageRelocateImage ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, + IN UINT64 BaseAddress, + OUT UEFI_IMAGE_LOADER_RUNTIME_CONTEXT *RuntimeContext OPTIONAL, + IN UINT32 RuntimeContextSize + ) +{ + RETURN_STATUS Status; + + if (RuntimeContext != NULL) { + *(UINT64 *)RuntimeContext = Context->FormatIndex; + RuntimeContext = (UEFI_IMAGE_LOADER_RUNTIME_CONTEXT *)((UINT64 *)RuntimeContext + 1); + ASSERT (RuntimeContextSize >= 8); + RuntimeContextSize -= 8; + } + + UEFI_IMAGE_EXEC ( + Status, + Context->FormatIndex, + RelocateImage, + Context, + BaseAddress, + RuntimeContext, + RuntimeContextSize + ); + + if (!RETURN_ERROR (Status)) { + UefiImageLoaderRelocateImageExtraAction (Context); + } + + return Status; +} + +RETURN_STATUS +UefiImageRuntimeRelocateImage ( + IN OUT VOID *Image, + IN UINT32 ImageSize, + IN UINT64 BaseAddress, + IN CONST UEFI_IMAGE_LOADER_RUNTIME_CONTEXT *RuntimeContext + ) +{ + RETURN_STATUS Status; + + UEFI_IMAGE_EXEC ( + Status, + *(UINT8 *)RuntimeContext, + RuntimeRelocateImage, + Image, + ImageSize, + BaseAddress, + ((UINT64 *)RuntimeContext + 1) + ); + + return Status; +} + +VOID +UefiImageDiscardSegments ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context + ) +{ + UEFI_IMAGE_EXEC_VOID ( + Context->FormatIndex, + DiscardSegments, + Context + ); +} + +RETURN_STATUS +UefiImageGetSymbolsPath ( + IN CONST UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, + OUT CONST CHAR8 **SymbolsPath, + OUT UINT32 *SymbolsPathSize + ) +{ + RETURN_STATUS Status; + + UEFI_IMAGE_EXEC ( + Status, + Context->FormatIndex, + GetSymbolsPath, + Context, + SymbolsPath, + SymbolsPathSize + ); + + return Status; +} + +RETURN_STATUS +UefiImageGetFirstCertificate ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, + OUT CONST WIN_CERTIFICATE **Certificate + ) +{ + RETURN_STATUS Status; + + UEFI_IMAGE_EXEC ( + Status, + Context->FormatIndex, + GetFirstCertificate, + Context, + Certificate + ); + + return Status; +} + +RETURN_STATUS +UefiImageGetNextCertificate ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, + IN OUT CONST WIN_CERTIFICATE **Certificate + ) +{ + RETURN_STATUS Status; + + UEFI_IMAGE_EXEC ( + Status, + Context->FormatIndex, + GetNextCertificate, + Context, + Certificate + ); + + return Status; +} + +RETURN_STATUS +UefiImageGetHiiDataRva ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, + OUT UINT32 *HiiRva, + OUT UINT32 *HiiSize + ) +{ + RETURN_STATUS Status; + + UEFI_IMAGE_EXEC ( + Status, + Context->FormatIndex, + GetHiiDataRva, + Context, + HiiRva, + HiiSize + ); + + return Status; +} + +UINT32 +UefiImageGetEntryPointAddress ( + IN CONST UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context + ) +{ + UINT32 Result; + + UEFI_IMAGE_EXEC ( + Result, + Context->FormatIndex, + GetEntryPointAddress, + Context + ); + + return Result; +} + +UINT16 +UefiImageGetMachine ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context + ) +{ + UINT16 Result; + + UEFI_IMAGE_EXEC ( + Result, + Context->FormatIndex, + GetMachine, + Context + ); + + return Result; +} + +UINT16 +UefiImageGetSubsystem ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context + ) +{ + UINT16 Result; + + UEFI_IMAGE_EXEC ( + Result, + Context->FormatIndex, + GetSubsystem, + Context + ); + + return Result; +} + +UINT32 +UefiImageGetSegmentAlignment ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context + ) +{ + UINT32 Result; + + UEFI_IMAGE_EXEC ( + Result, + Context->FormatIndex, + GetSegmentAlignment, + Context + ); + + return Result; +} + +UINT32 +UefiImageGetImageSize ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context + ) +{ + UINT32 Result; + + UEFI_IMAGE_EXEC ( + Result, + Context->FormatIndex, + GetImageSize, + Context + ); + + return Result; +} + +UINT64 +UefiImageGetBaseAddress ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context + ) +{ + UINT64 Result; + + UEFI_IMAGE_EXEC ( + Result, + Context->FormatIndex, + GetBaseAddress, + Context + ); + + return Result; +} + +BOOLEAN +UefiImageGetRelocsStripped ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context + ) +{ + BOOLEAN Result; + + UEFI_IMAGE_EXEC ( + Result, + Context->FormatIndex, + GetRelocsStripped, + Context + ); + + return Result; +} + +UINTN +UefiImageLoaderGetImageAddress ( + IN CONST UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context + ) +{ + UINTN Result; + + UEFI_IMAGE_EXEC ( + Result, + Context->FormatIndex, + LoaderGetImageAddress, + Context + ); + + return Result; +} + +UEFI_IMAGE_RECORD * +UefiImageLoaderGetImageRecord ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context + ) +{ + UEFI_IMAGE_RECORD *Result; + + UEFI_IMAGE_EXEC ( + Result, + Context->FormatIndex, + LoaderGetImageRecord, + Context + ); + + return Result; +} + +RETURN_STATUS +UefiImageDebugLocateImage ( + OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, + IN UINTN Address + ) +{ + RETURN_STATUS Status; + + UEFI_IMAGE_EXEC ( + Status, + Context->FormatIndex, + DebugLocateImage, + Context, + Address + ); + + return Status; +} + +RETURN_STATUS +UefiImageGetFixedAddress ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, + OUT UINT64 *Address + ) +{ + RETURN_STATUS Status; + + UEFI_IMAGE_EXEC ( + Status, + Context->FormatIndex, + GetFixedAddress, + Context, + Address + ); + + return Status; +} + +VOID +UefiImageDebugPrintSegments ( + IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context + ) +{ + UEFI_IMAGE_EXEC_VOID ( + Context->FormatIndex, + DebugPrintSegments, + Context + ); +} diff --git a/MdePkg/Library/BaseUefiImageLib/UefiImageLibPeCoff.c b/MdePkg/Library/BaseUefiImageLib/UefiImageLibPeCoff.c deleted file mode 100644 index 3350c92466..0000000000 --- a/MdePkg/Library/BaseUefiImageLib/UefiImageLibPeCoff.c +++ /dev/null @@ -1,299 +0,0 @@ -/** @file - UEFI Image Loader library implementation for PE/COFF Images. - - Copyright (c) 2021, Marvin Häuser. All rights reserved.
- - SPDX-License-Identifier: BSD-3-Clause -**/ - -#define UEFI_IMAGE_LOADER_IMAGE_CONTEXT PE_COFF_LOADER_IMAGE_CONTEXT -#define UEFI_IMAGE_LOADER_RUNTIME_CONTEXT PE_COFF_LOADER_RUNTIME_CONTEXT - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "PeCoffSupport.h" - -RETURN_STATUS -UefiImageInitializeContextPreHash ( - OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, - IN CONST VOID *FileBuffer, - IN UINT32 FileSize - ) -{ - return PeCoffInitializeContext (Context, FileBuffer, FileSize); -} - -RETURN_STATUS -UefiImageInitializeContextPostHash ( - IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context - ) -{ - ASSERT (Context != NULL); - - return RETURN_SUCCESS; -} - -UINT8 -UefiImageGetFormat ( - IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context - ) -{ - return UefiImageFormatPe; -} - -BOOLEAN -UefiImageHashImageDefault ( - IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, - IN OUT VOID *HashContext, - IN UEFI_IMAGE_LOADER_HASH_UPDATE HashUpdate - ) -{ - return PeCoffHashImageAuthenticode (Context, HashContext, HashUpdate); -} - -RETURN_STATUS -UefiImageLoadImage ( - IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, - OUT VOID *Destination, - IN UINT32 DestinationSize - ) -{ - return PeCoffLoadImage (Context, Destination, DestinationSize); -} - -BOOLEAN -UefiImageImageIsInplace ( - IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context - ) -{ - return PeCoffImageIsInplace (Context); -} - -RETURN_STATUS -UefiImageLoadImageInplace ( - IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context - ) -{ - return PeCoffLoadImageInplace (Context); -} - -RETURN_STATUS -UefiImageRelocateImageInplace ( - IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context - ) -{ - return PeCoffRelocateImageInplace (Context); -} - -RETURN_STATUS -UefiImageLoaderGetRuntimeContextSize ( - IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, - OUT UINT32 *Size - ) -{ - return PeCoffLoaderGetRuntimeContextSize (Context, Size); -} - -RETURN_STATUS -UefiImageRelocateImage ( - IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, - IN UINT64 BaseAddress, - OUT UEFI_IMAGE_LOADER_RUNTIME_CONTEXT *RuntimeContext OPTIONAL, - IN UINT32 RuntimeContextSize - ) -{ - RETURN_STATUS Status; - - Status = PeCoffRelocateImage ( - Context, - BaseAddress, - RuntimeContext, - RuntimeContextSize - ); - if (!RETURN_ERROR (Status)) { - UefiImageLoaderRelocateImageExtraAction (Context); - } - - return Status; -} - -RETURN_STATUS -UefiImageRuntimeRelocateImage ( - IN OUT VOID *Image, - IN UINT32 ImageSize, - IN UINT64 BaseAddress, - IN CONST UEFI_IMAGE_LOADER_RUNTIME_CONTEXT *RuntimeContext - ) -{ - return PeCoffRuntimeRelocateImage ( - Image, - ImageSize, - BaseAddress, - RuntimeContext - ); -} - -VOID -UefiImageDiscardSegments ( - IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context - ) -{ - PeCoffDiscardSections (Context); -} - -RETURN_STATUS -UefiImageGetSymbolsPath ( - IN CONST UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, - OUT CONST CHAR8 **SymbolsPath, - OUT UINT32 *SymbolsPathSize - ) -{ - return PeCoffGetPdbPath (Context, SymbolsPath, SymbolsPathSize); -} - -RETURN_STATUS -UefiImageGetFirstCertificate ( - IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, - OUT CONST WIN_CERTIFICATE **Certificate - ) -{ - return PeCoffGetFirstCertificate (Context, Certificate); -} - -RETURN_STATUS -UefiImageGetNextCertificate ( - IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, - IN OUT CONST WIN_CERTIFICATE **Certificate - ) -{ - return PeCoffGetNextCertificate (Context, Certificate); -} - -RETURN_STATUS -UefiImageGetHiiDataRva ( - IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, - OUT UINT32 *HiiRva, - OUT UINT32 *HiiSize - ) -{ - return PeCoffGetHiiDataRva (Context, HiiRva, HiiSize); -} - -UINT32 -UefiImageGetEntryPointAddress ( - IN CONST UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context - ) -{ - return PeCoffGetAddressOfEntryPoint (Context); -} - -UINT16 -UefiImageGetMachine ( - IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context - ) -{ - return PeCoffGetMachine (Context); -} - -UINT16 -UefiImageGetSubsystem ( - IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context - ) -{ - return PeCoffGetSubsystem (Context); -} - -UINT32 -UefiImageGetSegmentAlignment ( - IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context - ) -{ - return PeCoffGetSectionAlignment (Context); -} - -UINT32 -UefiImageGetImageSize ( - IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context - ) -{ - return PeCoffGetSizeOfImage (Context); -} - -UINT32 -UefiImageGetImageSizeInplace ( - IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context - ) -{ - return PeCoffGetSizeOfImageInplace (Context); -} - -UINT64 -UefiImageGetPreferredAddress ( - IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context - ) -{ - return PeCoffGetImageBase (Context); -} - -BOOLEAN -UefiImageGetRelocsStripped ( - IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context - ) -{ - return PeCoffGetRelocsStripped (Context); -} - -UINTN -UefiImageLoaderGetImageAddress ( - IN CONST UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context - ) -{ - return PeCoffLoaderGetImageAddress (Context); -} - -UEFI_IMAGE_RECORD * -UefiImageLoaderGetImageRecord ( - IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context - ) -{ - return UefiImageLoaderGetImageRecordPeCoff (Context); -} - -RETURN_STATUS -UefiImageDebugLocateImage ( - OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, - IN UINTN Address - ) -{ - return UefiImageDebugLocateImagePeCoff (Context, Address); -} - -RETURN_STATUS -UefiImageGetFixedAddress ( - IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context, - OUT UINT64 *Address - ) -{ - return UefiImageGetFixedAddressPeCoff (Context, Address); -} - -VOID -UefiImageDebugPrintSegments ( - IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context - ) -{ - UefiImageDebugPrintSegmentsPeCoff (Context); -} diff --git a/MdePkg/MdeLibs.dsc.inc b/MdePkg/MdeLibs.dsc.inc index c5ad467924..e60c02d2eb 100644 --- a/MdePkg/MdeLibs.dsc.inc +++ b/MdePkg/MdeLibs.dsc.inc @@ -23,3 +23,36 @@ MemoryProfileLib|MdeModulePkg/Library/BaseMemoryProfileLibNull/BaseMemoryProfileLibNull.inf CommonMemoryAllocationLib|MdeModulePkg/Library/CommonMemoryAllocationLib/CommonMemoryAllocationLib.inf + + # + # For security and code size optimization reasons, the UefiImageLib design is + # complicated. To not expose FV-only UEFI image formats via, e.g., DxeCore to + # untrusted sources, UefiImageLib can be configured to support different UEFI + # image formats per source. While compilers generally manage to optimize the + # initial parsing steps, complex control flow can make them lose track of the + # UefiImageLib source property and thus conditionally call into code for UEFI + # image formats that are not required by the module at all (e.g., because it + # only ever deals with FV images). + # + # To have the code for unsupported UEFI image file formats removed, + # UefiImageLib comes in multiple flavours that support FV-only, non-FV-only, + # or all UEFI image formats. These flavours are supposed to be used by + # top-level modules that have a clear scope. As libraries may depend on + # UefiImageLib too, however, they should consume the general UefiImageLib with + # no clear flavour. + # + # If they consume libraries with UefiImageLib dependencies, modules must have + # their general UefiImageLib set to their corresponding flavour for correct + # linkage. In order to make this easier, there is a heuristic below, based on + # module types, to set the most likely instance of UefiImageLib. In rare + # cases, manual overriding in the platform DSC may be necessary. + # + UefiImageOnlyNonFvLib|MdePkg/Library/BaseUefiImageLib/BaseUefiImageOnlyNonFvLib.inf + UefiImageOnlyFvLib|MdePkg/Library/BaseUefiImageLib/BaseUefiImageOnlyFvLib.inf + UefiImageAllLib|MdePkg/Library/BaseUefiImageLib/BaseUefiImageAllLib.inf + +[LibraryClasses.common.USER_DEFINED, LibraryClasses.common.SEC, LibraryClasses.common.PEI_CORE, LibraryClasses.common.PEIM, LibraryClasses.common.SMM_CORE, LibraryClasses.common.MM_CORE_STANDALONE, LibraryClasses.common.DXE_SMM_DRIVER, LibraryClasses.common.MM_STANDALONE] + UefiImageLib|MdePkg/Library/BaseUefiImageLib/BaseUefiImageOnlyFvLib.inf + +[LibraryClasses.common.DXE_CORE, LibraryClasses.common.DXE_DRIVER, LibraryClasses.common.DXE_RUNTIME_DRIVER, LibraryClasses.common.UEFI_DRIVER, LibraryClasses.common.UEFI_APPLICATION] + UefiImageLib|MdePkg/Library/BaseUefiImageLib/BaseUefiImageAllLib.inf diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index b471b33f31..fa30ec88a1 100644 --- a/MdePkg/MdePkg.dec +++ b/MdePkg/MdePkg.dec @@ -2311,6 +2311,16 @@ # @Prompt Remove X permission from WX sections. gEfiMdePkgTokenSpaceGuid.PcdImageLoaderRemoveXForWX|FALSE|BOOLEAN|0x40001021 + ## Indicates the UEFI image file formats supported outside FVs.

+ # BIT0 - PE.
+ # @Prompt Supported UEFI image file formats outside FVs. + gEfiMdePkgTokenSpaceGuid.PcdUefiImageFormatSupportNonFv|0x01|UINT8|0x40002000 + + ## Indicates the UEFI image file formats supported inside FVs.

+ # BIT0 - PE.
+ # @Prompt Supported UEFI image file formats inside FVs. + gEfiMdePkgTokenSpaceGuid.PcdUefiImageFormatSupportFv|0x01|UINT8|0x40002001 + [PcdsFixedAtBuild,PcdsPatchableInModule] ## Indicates the maximum length of unicode string used in the following # BaseLib functions: StrLen(), StrSize(), StrCmp(), StrnCmp(), StrCpy(), StrnCpy()

diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc index a0eefa9b5f..9762821824 100644 --- a/MdePkg/MdePkg.dsc +++ b/MdePkg/MdePkg.dsc @@ -59,7 +59,9 @@ MdePkg/Library/BaseS3PciSegmentLib/BaseS3PciSegmentLib.inf MdePkg/Library/BaseArmTrngLibNull/BaseArmTrngLibNull.inf MdePkg/Library/BasePeCoffLib2/BasePeCoffLib2.inf - MdePkg/Library/BaseUefiImageLib/BaseUefiImageLibPeCoff.inf + MdePkg/Library/BaseUefiImageLib/BaseUefiImageOnlyNonFvLib.inf + MdePkg/Library/BaseUefiImageLib/BaseUefiImageOnlyFvLib.inf + MdePkg/Library/BaseUefiImageLib/BaseUefiImageAllLib.inf MdePkg/Library/BaseUefiImageExtraActionLibNull/BaseUefiImageExtraActionLibNull.inf MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf MdePkg/Library/BasePostCodeLibDebug/BasePostCodeLibDebug.inf diff --git a/NetworkPkg/NetworkPkg.dsc b/NetworkPkg/NetworkPkg.dsc index 486782fa8f..acab5c8d88 100644 --- a/NetworkPkg/NetworkPkg.dsc +++ b/NetworkPkg/NetworkPkg.dsc @@ -47,7 +47,6 @@ RngLib|MdePkg/Library/BaseRngLib/BaseRngLib.inf VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.inf PeCoffLib2|MdePkg/Library/BasePeCoffLib2/BasePeCoffLib2.inf - UefiImageLib|MdePkg/Library/BaseUefiImageLib/BaseUefiImageLibPeCoff.inf CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf UefiImageExtraActionLib|MdePkg/Library/BaseUefiImageExtraActionLibNull/BaseUefiImageExtraActionLibNull.inf diff --git a/OvmfPkg/AmdSev/AmdSevX64.dsc b/OvmfPkg/AmdSev/AmdSevX64.dsc index 8e323bdefd..782218a58f 100644 --- a/OvmfPkg/AmdSev/AmdSevX64.dsc +++ b/OvmfPkg/AmdSev/AmdSevX64.dsc @@ -123,7 +123,6 @@ CpuLib|MdePkg/Library/BaseCpuLib/BaseCpuLib.inf PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf PeCoffLib2|MdePkg/Library/BasePeCoffLib2/BasePeCoffLib2.inf - UefiImageLib|MdePkg/Library/BaseUefiImageLib/BaseUefiImageLibPeCoff.inf CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf @@ -246,7 +245,6 @@ DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformRomDebugLibIoPort.inf !endif PeCoffLib2|MdePkg/Library/BasePeCoffLib2/BasePeCoffLib2.inf - UefiImageLib|MdePkg/Library/BaseUefiImageLib/BaseUefiImageLibPeCoff.inf [LibraryClasses.common.PEIM] HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf @@ -262,7 +260,6 @@ DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformRomDebugLibIoPort.inf !endif PeCoffLib2|MdePkg/Library/BasePeCoffLib2/BasePeCoffLib2.inf - UefiImageLib|MdePkg/Library/BaseUefiImageLib/BaseUefiImageLibPeCoff.inf ResourcePublicationLib|MdePkg/Library/PeiResourcePublicationLib/PeiResourcePublicationLib.inf ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf !if $(SOURCE_DEBUG_ENABLE) == TRUE diff --git a/OvmfPkg/Bhyve/BhyveX64.dsc b/OvmfPkg/Bhyve/BhyveX64.dsc index 4afdbf6780..fdb68f062f 100644 --- a/OvmfPkg/Bhyve/BhyveX64.dsc +++ b/OvmfPkg/Bhyve/BhyveX64.dsc @@ -129,7 +129,6 @@ CpuLib|MdePkg/Library/BaseCpuLib/BaseCpuLib.inf PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf PeCoffLib2|MdePkg/Library/BasePeCoffLib2/BasePeCoffLib2.inf - UefiImageLib|MdePkg/Library/BaseUefiImageLib/BaseUefiImageLibPeCoff.inf CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf @@ -270,7 +269,6 @@ DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformRomDebugLibIoPort.inf !endif PeCoffLib2|MdePkg/Library/BasePeCoffLib2/BasePeCoffLib2.inf - UefiImageLib|MdePkg/Library/BaseUefiImageLib/BaseUefiImageLibPeCoff.inf [LibraryClasses.common.PEIM] HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf @@ -286,7 +284,6 @@ DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformRomDebugLibIoPort.inf !endif PeCoffLib2|MdePkg/Library/BasePeCoffLib2/BasePeCoffLib2.inf - UefiImageLib|MdePkg/Library/BaseUefiImageLib/BaseUefiImageLibPeCoff.inf ResourcePublicationLib|MdePkg/Library/PeiResourcePublicationLib/PeiResourcePublicationLib.inf ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf !if $(SOURCE_DEBUG_ENABLE) == TRUE diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index 4940d75b7c..fdd28d5716 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -133,7 +133,6 @@ CpuLib|MdePkg/Library/BaseCpuLib/BaseCpuLib.inf PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf PeCoffLib2|MdePkg/Library/BasePeCoffLib2/BasePeCoffLib2.inf - UefiImageLib|MdePkg/Library/BaseUefiImageLib/BaseUefiImageLibPeCoff.inf CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf @@ -277,7 +276,6 @@ DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformRomDebugLibIoPort.inf !endif PeCoffLib2|MdePkg/Library/BasePeCoffLib2/BasePeCoffLib2.inf - UefiImageLib|MdePkg/Library/BaseUefiImageLib/BaseUefiImageLibPeCoff.inf [LibraryClasses.common.PEIM] HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf @@ -293,7 +291,6 @@ DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformRomDebugLibIoPort.inf !endif PeCoffLib2|MdePkg/Library/BasePeCoffLib2/BasePeCoffLib2.inf - UefiImageLib|MdePkg/Library/BaseUefiImageLib/BaseUefiImageLibPeCoff.inf ResourcePublicationLib|MdePkg/Library/PeiResourcePublicationLib/PeiResourcePublicationLib.inf ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf !if $(SOURCE_DEBUG_ENABLE) == TRUE diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index c874bf20da..eaa2d2d794 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -138,7 +138,6 @@ CpuLib|MdePkg/Library/BaseCpuLib/BaseCpuLib.inf PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf PeCoffLib2|MdePkg/Library/BasePeCoffLib2/BasePeCoffLib2.inf - UefiImageLib|MdePkg/Library/BaseUefiImageLib/BaseUefiImageLibPeCoff.inf CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf @@ -283,7 +282,6 @@ DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformRomDebugLibIoPort.inf !endif PeCoffLib2|MdePkg/Library/BasePeCoffLib2/BasePeCoffLib2.inf - UefiImageLib|MdePkg/Library/BaseUefiImageLib/BaseUefiImageLibPeCoff.inf [LibraryClasses.common.PEIM] HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf @@ -299,7 +297,6 @@ DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformRomDebugLibIoPort.inf !endif PeCoffLib2|MdePkg/Library/BasePeCoffLib2/BasePeCoffLib2.inf - UefiImageLib|MdePkg/Library/BaseUefiImageLib/BaseUefiImageLibPeCoff.inf ResourcePublicationLib|MdePkg/Library/PeiResourcePublicationLib/PeiResourcePublicationLib.inf ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf !if $(SOURCE_DEBUG_ENABLE) == TRUE diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index 5af9443143..b54445abd2 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -150,7 +150,6 @@ CpuLib|MdePkg/Library/BaseCpuLib/BaseCpuLib.inf PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf PeCoffLib2|MdePkg/Library/BasePeCoffLib2/BasePeCoffLib2.inf - UefiImageLib|MdePkg/Library/BaseUefiImageLib/BaseUefiImageLibPeCoff.inf CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf @@ -300,7 +299,6 @@ DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformRomDebugLibIoPort.inf !endif PeCoffLib2|MdePkg/Library/BasePeCoffLib2/BasePeCoffLib2.inf - UefiImageLib|MdePkg/Library/BaseUefiImageLib/BaseUefiImageLibPeCoff.inf CcProbeLib|OvmfPkg/Library/CcProbeLib/SecPeiCcProbeLib.inf [LibraryClasses.common.PEIM] @@ -317,7 +315,6 @@ DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformRomDebugLibIoPort.inf !endif PeCoffLib2|MdePkg/Library/BasePeCoffLib2/BasePeCoffLib2.inf - UefiImageLib|MdePkg/Library/BaseUefiImageLib/BaseUefiImageLibPeCoff.inf ResourcePublicationLib|MdePkg/Library/PeiResourcePublicationLib/PeiResourcePublicationLib.inf ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf !if $(SOURCE_DEBUG_ENABLE) == TRUE diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc index e87d7b42ba..be9d5073f2 100644 --- a/OvmfPkg/OvmfXen.dsc +++ b/OvmfPkg/OvmfXen.dsc @@ -130,7 +130,6 @@ CpuLib|MdePkg/Library/BaseCpuLib/BaseCpuLib.inf PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf PeCoffLib2|MdePkg/Library/BasePeCoffLib2/BasePeCoffLib2.inf - UefiImageLib|MdePkg/Library/BaseUefiImageLib/BaseUefiImageLibPeCoff.inf CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf @@ -264,7 +263,6 @@ ReportStatusCodeLib|MdeModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf OemHookStatusCodeLib|MdeModulePkg/Library/OemHookStatusCodeLibNull/OemHookStatusCodeLibNull.inf PeCoffLib2|MdePkg/Library/BasePeCoffLib2/BasePeCoffLib2.inf - UefiImageLib|MdePkg/Library/BaseUefiImageLib/BaseUefiImageLibPeCoff.inf [LibraryClasses.common.PEIM] HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf @@ -275,7 +273,6 @@ ReportStatusCodeLib|MdeModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf OemHookStatusCodeLib|MdeModulePkg/Library/OemHookStatusCodeLibNull/OemHookStatusCodeLibNull.inf PeCoffLib2|MdePkg/Library/BasePeCoffLib2/BasePeCoffLib2.inf - UefiImageLib|MdePkg/Library/BaseUefiImageLib/BaseUefiImageLibPeCoff.inf ResourcePublicationLib|MdePkg/Library/PeiResourcePublicationLib/PeiResourcePublicationLib.inf ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf !if $(SOURCE_DEBUG_ENABLE) == TRUE diff --git a/OvmfPkg/Sec/SecMain.c b/OvmfPkg/Sec/SecMain.c index 91ac7a3157..17662559b8 100644 --- a/OvmfPkg/Sec/SecMain.c +++ b/OvmfPkg/Sec/SecMain.c @@ -722,7 +722,12 @@ FindAndReportEntryPoints ( // // Report SEC Core debug information when remote debug is enabled // - Status = UefiImageInitializeContext (&ImageContext, (VOID *) (UINTN) SecCoreImageBase, SecCoreImageSize); + Status = UefiImageInitializeContext ( + &ImageContext, + (VOID *) (UINTN) SecCoreImageBase, + SecCoreImageSize, + UEFI_IMAGE_SOURCE_FV + ); ASSERT_EFI_ERROR (Status); Status = UefiImageLoadImageInplace (&ImageContext); @@ -733,7 +738,12 @@ FindAndReportEntryPoints ( // // Find PEI Core entry point // - Status = UefiImageInitializeContext (&ImageContext, (VOID *) (UINTN) PeiCoreImageBase, PeiCoreImageSize); + Status = UefiImageInitializeContext ( + &ImageContext, + (VOID *) (UINTN) PeiCoreImageBase, + PeiCoreImageSize, + UEFI_IMAGE_SOURCE_FV + ); ASSERT_EFI_ERROR (Status); Status = UefiImageLoadImageInplace (&ImageContext); diff --git a/OvmfPkg/Sec/SecMain.inf b/OvmfPkg/Sec/SecMain.inf index b388acfe2e..66f231f6f3 100644 --- a/OvmfPkg/Sec/SecMain.inf +++ b/OvmfPkg/Sec/SecMain.inf @@ -47,7 +47,7 @@ CpuLib DebugAgentLib IoLib - UefiImageLib + UefiImageOnlyFvLib UefiImageExtraActionLib ExtractGuidedSectionLib LocalApicLib diff --git a/SecurityPkg/SecurityPkg.dsc b/SecurityPkg/SecurityPkg.dsc index d7b7715668..bd27cc95f3 100644 --- a/SecurityPkg/SecurityPkg.dsc +++ b/SecurityPkg/SecurityPkg.dsc @@ -33,7 +33,6 @@ UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf PeCoffLib2|MdePkg/Library/BasePeCoffLib2/BasePeCoffLib2.inf - UefiImageLib|MdePkg/Library/BaseUefiImageLib/BaseUefiImageLibPeCoff.inf UefiImageExtraActionLib|MdePkg/Library/BaseUefiImageExtraActionLibNull/BaseUefiImageExtraActionLibNull.inf # FIXME: ARM? CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf diff --git a/SecurityPkg/Tcg/Tcg2Dxe/MeasureBootUefiImage.c b/SecurityPkg/Tcg/Tcg2Dxe/MeasureBootUefiImage.c index 7d77df60a9..1e31b7e4ed 100644 --- a/SecurityPkg/Tcg/Tcg2Dxe/MeasureBootUefiImage.c +++ b/SecurityPkg/Tcg/Tcg2Dxe/MeasureBootUefiImage.c @@ -62,7 +62,8 @@ MeasureUefiImageAndExtend ( Status = UefiImageInitializeContextPreHash ( &ImageContext, (VOID *) (UINTN) ImageAddress, - (UINT32) ImageSize + (UINT32) ImageSize, + UEFI_IMAGE_SOURCE_ALL ); if (EFI_ERROR (Status)) { // diff --git a/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf b/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf index 3e86b6c999..ad7cbcb7a7 100644 --- a/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf +++ b/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf @@ -63,7 +63,7 @@ PerformanceLib ReportStatusCodeLib Tcg2PhysicalPresenceLib - UefiImageLib + UefiImageAllLib [Guids] ## SOMETIMES_CONSUMES ## Variable:L"SecureBoot" diff --git a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigDxe.inf b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigDxe.inf index ba5775198f..ace9b343c8 100644 --- a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigDxe.inf +++ b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigDxe.inf @@ -53,7 +53,7 @@ PlatformSecureLib DevicePathLib FileExplorerLib - UefiImageLib + UefiImageOnlyNonFvLib SecureBootVariableLib SecureBootVariableProvisionLib diff --git a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c index d135e30386..5c678b1db8 100644 --- a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c +++ b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c @@ -1976,7 +1976,15 @@ EnrollImageSignatureToSigDB ( goto ON_EXIT; } - Status = UefiImageInitializeContextPreHash (&ImageContext, ImageBase, (UINT32)ImageSize); + // + // Secure Boot does not apply to images from FVs. + // + Status = UefiImageInitializeContextPreHash ( + &ImageContext, + ImageBase, + (UINT32)ImageSize, + UEFI_IMAGE_SOURCE_NON_FV + ); if (EFI_ERROR (Status)) { goto ON_EXIT; } diff --git a/SignedCapsulePkg/SignedCapsulePkg.dsc b/SignedCapsulePkg/SignedCapsulePkg.dsc index b0bd023a4c..b363ffb6bb 100644 --- a/SignedCapsulePkg/SignedCapsulePkg.dsc +++ b/SignedCapsulePkg/SignedCapsulePkg.dsc @@ -41,7 +41,6 @@ PciSegmentLib|MdePkg/Library/BasePciSegmentLibPci/BasePciSegmentLibPci.inf CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf PeCoffLib2|MdePkg/Library/BasePeCoffLib2/BasePeCoffLib2.inf - UefiImageLib|MdePkg/Library/BaseUefiImageLib/BaseUefiImageLibPeCoff.inf SortLib|MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf # # UEFI & PI diff --git a/StandaloneMmPkg/Core/Dispatcher.c b/StandaloneMmPkg/Core/Dispatcher.c index 8174e2b71e..b6175490f9 100644 --- a/StandaloneMmPkg/Core/Dispatcher.c +++ b/StandaloneMmPkg/Core/Dispatcher.c @@ -197,7 +197,12 @@ MmLoadImage ( // // Get information about the image being loaded // - Status = UefiImageInitializeContext (&ImageContext, DriverEntry->Pe32Data, DriverEntry->Pe32DataSize); + Status = UefiImageInitializeContext ( + &ImageContext, + DriverEntry->Pe32Data, + DriverEntry->Pe32DataSize, + UEFI_IMAGE_SOURCE_FV + ); if (EFI_ERROR (Status)) { return Status; } diff --git a/StandaloneMmPkg/Core/StandaloneMmCore.inf b/StandaloneMmPkg/Core/StandaloneMmCore.inf index b52534ea6c..fa4f0fd2cf 100644 --- a/StandaloneMmPkg/Core/StandaloneMmCore.inf +++ b/StandaloneMmPkg/Core/StandaloneMmCore.inf @@ -49,7 +49,7 @@ HobLib MemoryAllocationLib MemLib - UefiImageLib + UefiImageOnlyFvLib ReportStatusCodeLib StandaloneMmProtectionLib StandaloneMmCoreEntryPoint diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCoreEntryPoint.c b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCoreEntryPoint.c index 9ae97482f9..ffedc5b4dc 100644 --- a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCoreEntryPoint.c +++ b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCoreEntryPoint.c @@ -374,7 +374,12 @@ _ModuleEntryPoint ( DEBUG ((DEBUG_INFO, "Found Standalone MM PE data - 0x%x\n", TeData)); // Obtain the PE/COFF Section information for the Standalone MM core module - Status = UefiImageInitializeContext (&ImageContext, TeData, TeDataSize); + Status = UefiImageInitializeContext ( + &ImageContext, + TeData, + TeDataSize, + UEFI_IMAGE_SOURCE_FV + ); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "Unable to locate Standalone MM Core PE-COFF Section information - %r\n", Status)); diff --git a/StandaloneMmPkg/StandaloneMmPkg.dsc b/StandaloneMmPkg/StandaloneMmPkg.dsc index 2ec184774c..3598a66e8d 100644 --- a/StandaloneMmPkg/StandaloneMmPkg.dsc +++ b/StandaloneMmPkg/StandaloneMmPkg.dsc @@ -54,7 +54,6 @@ PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf UefiImageExtraActionLib|MdePkg/Library/BaseUefiImageExtraActionLibNull/BaseUefiImageExtraActionLibNull.inf PeCoffLib2|MdePkg/Library/BasePeCoffLib2/BasePeCoffLib2.inf - UefiImageLib|MdePkg/Library/BaseUefiImageLib/BaseUefiImageLibPeCoff.inf PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf ReportStatusCodeLib|MdePkg/Library/BaseReportStatusCodeLibNull/BaseReportStatusCodeLibNull.inf StandaloneMmCoreEntryPoint|StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf diff --git a/UefiCpuPkg/SecCore/FindPeiCore.c b/UefiCpuPkg/SecCore/FindPeiCore.c index 3cded940d3..a5d1686fc2 100644 --- a/UefiCpuPkg/SecCore/FindPeiCore.c +++ b/UefiCpuPkg/SecCore/FindPeiCore.c @@ -172,7 +172,8 @@ FindAndReportEntryPoints ( Status = UefiImageInitializeContext ( &ImageContext, (VOID*) (UINTN) SecCoreImageBase, - SecCoreImageSize + SecCoreImageSize, + UEFI_IMAGE_SOURCE_FV ); ASSERT_EFI_ERROR (Status); @@ -198,7 +199,8 @@ FindAndReportEntryPoints ( Status = UefiImageInitializeContext ( &ImageContext, (VOID*)(UINTN)PeiCoreImageBase, - PeiCoreImageSize + PeiCoreImageSize, + UEFI_IMAGE_SOURCE_FV ); ASSERT_EFI_ERROR (Status); diff --git a/UefiCpuPkg/SecCore/SecCoreNative.inf b/UefiCpuPkg/SecCore/SecCoreNative.inf index 7b4e03b510..9ca9328741 100644 --- a/UefiCpuPkg/SecCore/SecCoreNative.inf +++ b/UefiCpuPkg/SecCore/SecCoreNative.inf @@ -45,7 +45,7 @@ PcdLib DebugAgentLib CpuLib - UefiImageLib + UefiImageOnlyFvLib UefiImageExtraActionLib CpuExceptionHandlerLib ReportStatusCodeLib diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc index ad0b1aa1c8..c42ba9fb0a 100644 --- a/UefiCpuPkg/UefiCpuPkg.dsc +++ b/UefiCpuPkg/UefiCpuPkg.dsc @@ -58,7 +58,6 @@ SmmCpuFeaturesLib|UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf SmmCpuSyncLib|UefiCpuPkg/Library/SmmCpuSyncLib/SmmCpuSyncLib.inf PeCoffLib2|MdePkg/Library/BasePeCoffLib2/BasePeCoffLib2.inf - UefiImageLib|MdePkg/Library/BaseUefiImageLib/BaseUefiImageLibPeCoff.inf UefiImageExtraActionLib|MdePkg/Library/BaseUefiImageExtraActionLibNull/BaseUefiImageExtraActionLibNull.inf TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf CcExitLib|UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.inf diff --git a/UefiPayloadPkg/UefiPayloadEntry/LoadDxeCore.c b/UefiPayloadPkg/UefiPayloadEntry/LoadDxeCore.c index 7d635b9bf3..ea8599aa4d 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/LoadDxeCore.c +++ b/UefiPayloadPkg/UefiPayloadEntry/LoadDxeCore.c @@ -36,7 +36,12 @@ LoadUefiImage ( UINT32 BufferSize; VOID *Buffer; - Status = UefiImageInitializeContext (&ImageContext, UefiImage, UefiImageSize); + Status = UefiImageInitializeContext ( + &ImageContext, + UefiImage, + UefiImageSize, + UEFI_IMAGE_SOURCE_FV + ); if (EFI_ERROR (Status)) { ASSERT_EFI_ERROR (Status); return Status; diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf index 9167850ce4..b0d9eb1b5d 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf +++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf @@ -51,7 +51,7 @@ IoLib BlParseLib HobLib - UefiImageLib + UefiImageOnlyFvLib PlatformSupportLib CpuLib MemoryAllocationLib diff --git a/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.inf b/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.inf index 6da276e6e1..485efbb636 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.inf +++ b/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.inf @@ -51,7 +51,7 @@ IoLib HobLib CpuLib - UefiImageLib + UefiImageOnlyFvLib MemoryAllocationLib [Guids] diff --git a/UefiPayloadPkg/UefiPayloadPkg.dsc b/UefiPayloadPkg/UefiPayloadPkg.dsc index d0d518dfee..48713a3a65 100644 --- a/UefiPayloadPkg/UefiPayloadPkg.dsc +++ b/UefiPayloadPkg/UefiPayloadPkg.dsc @@ -204,7 +204,6 @@ PciSegmentLib|MdePkg/Library/PciSegmentLibSegmentInfo/BasePciSegmentLibSegmentInfo.inf PciSegmentInfoLib|UefiPayloadPkg/Library/PciSegmentInfoLibAcpiBoardInfo/PciSegmentInfoLibAcpiBoardInfo.inf PeCoffLib2|MdePkg/Library/BasePeCoffLib2/BasePeCoffLib2.inf - UefiImageLib|MdePkg/Library/BaseUefiImageLib/BaseUefiImageLibPeCoff.inf CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf DxeHobListLib|UefiPayloadPkg/Library/DxeHobListLib/DxeHobListLib.inf