Added LoadDxeCore() API to return DxeCore entry point after loading DxeCore
from FV, and del LoadDxeCoreFromFfsFile() as it is replaced by LoadDxeCore().
Update LoadDxeCoreFromFv() to use LoadDxeCore() to reduce code, and its
behavior is same.
Updated FfsProcessSection() to support both IA32 and X64 build.
With this patch, PrePiLib could be used by UefiPayloadPkg to load DxeCore
and get its entry point.
Signed-off-by: Guo Dong
---
EmbeddedPkg/Include/Library/PrePiLib.h | 17 ++---
EmbeddedPkg/Library/PrePiLib/FwVol.c| 2 +-
EmbeddedPkg/Library/PrePiLib/PrePiLib.c | 95
+--
3 files changed, 68 insertions(+), 46 deletions(-)
diff --git a/EmbeddedPkg/Include/Library/PrePiLib.h
b/EmbeddedPkg/Include/Library/PrePiLib.h
index 54f8e1e582..269907108e 100644
--- a/EmbeddedPkg/Include/Library/PrePiLib.h
+++ b/EmbeddedPkg/Include/Library/PrePiLib.h
@@ -735,11 +735,22 @@ LoadPeCoffImage (
OUT EFI_PHYSICAL_ADDRESS *EntryPoint
);
+
+/**
+ Load DXE core from FV and return DXE core entrypoint.
+
+ @param[in] FvInstanceThe FV instance to search DXE core. Will
search all the FVs if it is NULL.
+ @param[out] EntryPointDXE core entrypoint.
+
+ @return EFI_SUCCESS The DxeCore is loaded successfully.
+ @return OthersFailed to load the DxeCore.
+
+**/
EFI_STATUS
EFIAPI
-LoadDxeCoreFromFfsFile (
- IN EFI_PEI_FILE_HANDLE FileHandle,
- IN UINTNStackSize
+LoadDxeCore (
+ IN UINTN *FvInstance, OPTIONAL
+ OUT EFI_PHYSICAL_ADDRESS *EntryPoint
);
EFI_STATUS
diff --git a/EmbeddedPkg/Library/PrePiLib/FwVol.c
b/EmbeddedPkg/Library/PrePiLib/FwVol.c
index 881506eddd..46ea5f733f 100644
--- a/EmbeddedPkg/Library/PrePiLib/FwVol.c
+++ b/EmbeddedPkg/Library/PrePiLib/FwVol.c
@@ -298,7 +298,7 @@ FfsProcessSection (
UINT16 SectionAttribute;
UINT32 AuthenticationStatus;
CHAR8 *CompressedData;
- UINTN CompressedDataLength;
+ UINT32 CompressedDataLength;
*OutputBuffer = NULL;
diff --git a/EmbeddedPkg/Library/PrePiLib/PrePiLib.c
b/EmbeddedPkg/Library/PrePiLib/PrePiLib.c
index afbe146632..c18b30e22e 100644
--- a/EmbeddedPkg/Library/PrePiLib/PrePiLib.c
+++ b/EmbeddedPkg/Library/PrePiLib/PrePiLib.c
@@ -119,30 +119,52 @@ VOID
IN VOID *HobStart
);
+/**
+ Load DXE core from FV and return DXE core entrypoint.
+
+ @param[in] FvInstanceThe FV instance to search DXE core. Will
search all the FVs if it is NULL.
+ @param[out] EntryPointDXE core entrypoint.
+
+ @return EFI_SUCCESS The DxeCore is loaded successfully.
+ @return OthersFailed to load the DxeCore.
+
+**/
EFI_STATUS
EFIAPI
-LoadDxeCoreFromFfsFile (
- IN EFI_PEI_FILE_HANDLE FileHandle,
- IN UINTNStackSize
+LoadDxeCore (
+ IN UINTN *FvInstance, OPTIONAL
+ OUT EFI_PHYSICAL_ADDRESS *EntryPoint
)
{
EFI_STATUS Status;
+ EFI_PEI_FV_HANDLE VolumeHandle;
+ EFI_PEI_FILE_HANDLE FileHandle;
VOID*PeCoffImage;
EFI_PHYSICAL_ADDRESSImageAddress;
UINT64 ImageSize;
- EFI_PHYSICAL_ADDRESSEntryPoint;
- VOID*BaseOfStack;
- VOID*TopOfStack;
- VOID*Hob;
EFI_FV_FILE_INFOFvFileInfo;
+ FileHandle = NULL;
+ if (FvInstance != NULL) {
+//
+// Caller passed in a specific FV to try, so only try that one
+//
+Status = FfsFindNextVolume (*FvInstance, &VolumeHandle);
+if (!EFI_ERROR (Status)) {
+ Status = FfsFindNextFile (EFI_FV_FILETYPE_DXE_CORE, VolumeHandle,
&FileHandle);
+}
+ } else {
+Status = FfsAnyFvFindFirstFile (EFI_FV_FILETYPE_DXE_CORE, &VolumeHandle,
&FileHandle);
+DEBUG ((EFI_D_ERROR, "FfsAnyFvFindFirstFile Status = %r\n", Status));
+ }
+
Status = FfsFindSectionData (EFI_SECTION_PE32, FileHandle, &PeCoffImage);
if (EFI_ERROR (Status)) {
return Status;
}
- Status = LoadPeCoffImage (PeCoffImage, &ImageAddress, &ImageSize,
&EntryPoint);
+ Status = LoadPeCoffImage (PeCoffImage, &ImageAddress, &ImageSize,
EntryPoint);
// For NT32 Debug Status = SecWinNtPeiLoadFile (PeCoffImage, &ImageAddress,
&ImageSize, &EntryPoint);
ASSERT_EFI_ERROR (Status);
@@ -152,13 +174,33 @@ LoadDxeCoreFromFfsFile (
Status = FfsGetFileInfo (FileHandle, &FvFileInfo);
ASSERT_EFI_ERROR (Status);
- BuildModuleHob (&FvFileInfo.FileName,
(EFI_PHYSICAL_ADDRESS)(UINTN)ImageAddress, EFI_SIZE_TO_PAGES ((UINT32)
ImageSize) * EFI_PAGE_SIZE, EntryPoint);
+ BuildModuleHob (&FvFileInfo.FileName,
(EFI_PHYSICAL_ADDRESS)(UINTN)ImageAddress, EFI_SIZE_TO_PAGES ((UINT32)
ImageSize) * EFI_PAGE_SIZE, *Ent