[edk2-devel] [PATCH] [EmbeddedPkg]:Update PrePiLib to return DxeCoreEntrypoint

Guo Dong guo.dong at intel.com
Wed Aug 26 18:34:11 UTC 2020


Hi Leif and Biesheuvel,

Could you help review this patch?

Thanks,
Guo

> -----Original Message-----
> From: devel at edk2.groups.io <devel at edk2.groups.io> On Behalf Of Guo Dong
> Sent: Saturday, August 1, 2020 4:53 PM
> To: devel at edk2.groups.io
> Cc: leif at nuviainc.com; ard.biesheuvel at arm.com
> Subject: [edk2-devel] [PATCH] [EmbeddedPkg]:Update PrePiLib to return
> DxeCoreEntrypoint
> 
> 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 <guo.dong at intel.com>
> ---
>  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]   FvInstance        The FV instance to search DXE core. Will search
> all the FVs if it is NULL.
> +  @param[out]  EntryPoint        DXE core entrypoint.
> +
> +  @return  EFI_SUCCESS           The DxeCore is loaded successfully.
> +  @return  Others                Failed to load the DxeCore.
> +
> +**/
>  EFI_STATUS
>  EFIAPI
> -LoadDxeCoreFromFfsFile (
> -  IN EFI_PEI_FILE_HANDLE  FileHandle,
> -  IN UINTN                StackSize
> +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]   FvInstance        The FV instance to search DXE core. Will search
> all the FVs if it is NULL.
> +  @param[out]  EntryPoint        DXE core entrypoint.
> +
> +  @return  EFI_SUCCESS           The DxeCore is loaded successfully.
> +  @return  Others                Failed to load the DxeCore.
> +
> +**/
>  EFI_STATUS
>  EFIAPI
> -LoadDxeCoreFromFfsFile (
> -  IN EFI_PEI_FILE_HANDLE  FileHandle,
> -  IN UINTN                StackSize
> +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_ADDRESS    ImageAddress;
>    UINT64                  ImageSize;
> -  EFI_PHYSICAL_ADDRESS    EntryPoint;
> -  VOID                    *BaseOfStack;
> -  VOID                    *TopOfStack;
> -  VOID                    *Hob;
>    EFI_FV_FILE_INFO        FvFileInfo;
> 
> +  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, *EntryPoint);
> 
> -  DEBUG ((EFI_D_INFO | EFI_D_LOAD, "Loading DxeCore at 0x%10p
> EntryPoint=0x%10p\n", (VOID *)(UINTN)ImageAddress, (VOID
> *)(UINTN)EntryPoint));
> +  DEBUG ((EFI_D_INFO | EFI_D_LOAD, "Loading DxeCore at 0x%10p
> EntryPoint=0x%10p\n", (VOID *)(UINTN)ImageAddress, (VOID
> *)(UINTN)*EntryPoint));
> +
> +  return EFI_SUCCESS;
> +}
> +
> +
> +EFI_STATUS
> +EFIAPI
> +LoadDxeCoreFromFv (
> +  IN UINTN  *FvInstance,   OPTIONAL
> +  IN UINTN  StackSize
> +  )
> +{
> +  EFI_STATUS              Status;
> +  EFI_PHYSICAL_ADDRESS    EntryPoint;
> +  VOID                    *BaseOfStack;
> +  VOID                    *TopOfStack;
> +  VOID                    *Hob;
> +
> +  Status = LoadDxeCore (FvInstance, &EntryPoint);
> +  ASSERT_EFI_ERROR (Status);
> 
>    Hob = GetHobList ();
>    if (StackSize == 0) {
> -    // User the current stack
> +    // Use the current stack
> 
>      ((DXE_CORE_ENTRY_POINT)(UINTN)EntryPoint) (Hob);
>    } else {
> @@ -199,37 +241,6 @@ LoadDxeCoreFromFfsFile (
> 
> 
> 
> -EFI_STATUS
> -EFIAPI
> -LoadDxeCoreFromFv (
> -  IN UINTN  *FvInstance,   OPTIONAL
> -  IN UINTN  StackSize
> -  )
> -{
> -  EFI_STATUS          Status;
> -  EFI_PEI_FV_HANDLE   VolumeHandle;
> -  EFI_PEI_FILE_HANDLE 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);
> -  }
> -
> -  if (!EFI_ERROR (Status)) {
> -    return LoadDxeCoreFromFfsFile (FileHandle, StackSize);
> -  }
> -
> -  return Status;
> -}
> -
> -
>  EFI_STATUS
>  EFIAPI
>  DecompressFirstFv (
> --
> 2.16.2.windows.1
> 
> 
> 


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#64651): https://edk2.groups.io/g/devel/message/64651
Mute This Topic: https://groups.io/mt/75937184/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-





More information about the edk2-devel-archive mailing list