public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-devel] [PATCH] [EmbeddedPkg]:Update PrePiLib to return DxeCoreEntrypoint
@ 2020-08-01 23:52 Guo Dong
  0 siblings, 0 replies; 2+ messages in thread
From: Guo Dong @ 2020-08-01 23:52 UTC (permalink / raw)
  To: devel; +Cc: leif, ard.biesheuvel

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@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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [edk2-devel] [PATCH] [EmbeddedPkg]:Update PrePiLib to return DxeCoreEntrypoint
       [not found] <16274A04AA5F3FDA.22185@groups.io>
@ 2020-08-26 18:34 ` Guo Dong
  0 siblings, 0 replies; 2+ messages in thread
From: Guo Dong @ 2020-08-26 18:34 UTC (permalink / raw)
  To: Dong, Guo, leif@nuviainc.com, ard.biesheuvel@arm.com, Ma, Maurice
  Cc: devel@edk2.groups.io


Hi Leif and Biesheuvel,

Could you help review this patch?

Thanks,
Guo

> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Guo Dong
> Sent: Saturday, August 1, 2020 4:53 PM
> To: devel@edk2.groups.io
> Cc: leif@nuviainc.com; ard.biesheuvel@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@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
> 
> 
> 


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-08-26 18:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <16274A04AA5F3FDA.22185@groups.io>
2020-08-26 18:34 ` [edk2-devel] [PATCH] [EmbeddedPkg]:Update PrePiLib to return DxeCoreEntrypoint Guo Dong
2020-08-01 23:52 Guo Dong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox