From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mx.groups.io with SMTP id smtpd.web10.342.1596325976445472649 for ; Sat, 01 Aug 2020 16:52:56 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.88, mailfrom: guo.dong@intel.com) IronPort-SDR: RbaNqEsxs8EY/odZFYcC6gpzd76q2sbMVDE9UJruxogdnNvzU+ILXe40sokXyNKOGOd+KdwyR0 dEU9mb2WgMAA== X-IronPort-AV: E=McAfee;i="6000,8403,9700"; a="170069308" X-IronPort-AV: E=Sophos;i="5.75,424,1589266800"; d="scan'208";a="170069308" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Aug 2020 16:52:55 -0700 IronPort-SDR: yuO0HCDtS01VrEn4RmMikmBLAeb661hITB9ibWSB/wSczuhtHbjCQVmdMB351RnQS/8cbRlda1 m5OzhY61HcZg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,424,1589266800"; d="scan'208";a="321814439" Received: from gdong1-mobl.amr.corp.intel.com ([10.212.131.71]) by orsmga008.jf.intel.com with ESMTP; 01 Aug 2020 16:52:54 -0700 From: "Guo Dong" To: devel@edk2.groups.io Cc: leif@nuviainc.com, ard.biesheuvel@arm.com Subject: [edk2-devel] [PATCH] [EmbeddedPkg]:Update PrePiLib to return DxeCoreEntrypoint Date: Sat, 1 Aug 2020 16:52:33 -0700 Message-Id: <20200801235233.11428-1-guo.dong@intel.com> X-Mailer: git-send-email 2.16.2.windows.1 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] 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