diff --git a/MdeModulePkg/Core/DxeIplPeim/DxeIpl.h b/MdeModulePkg/Core/DxeIplPeim/DxeIpl.h index 151f28d222..99968d4438 100644 --- a/MdeModulePkg/Core/DxeIplPeim/DxeIpl.h +++ b/MdeModulePkg/Core/DxeIplPeim/DxeIpl.h @@ -61,6 +61,13 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. // extern BOOLEAN gInMemory; +// +// This PPI is installed to indicate the end of the PEI usage of memory +// +extern CONST EFI_PEI_PPI_DESCRIPTOR gEndOfPeiSignalPpi; + + + /** Loads and relocates a PE/COFF image into memory. @@ -84,21 +91,19 @@ PeiLoadFile ( /** - Find DxeCore driver from all First Volumes. + Searches DxeCore in all firmware Volumes and loads the first instance that contains DxeCore. - @param FileHandle Pointer to FFS file to search. + @param DxeCoreFileName A Pointer to the EFI_GUID to contain the output DxeCore GUID file name. + + @return FileHandle of DxeCore to load DxeCore. - @return EFI_SUCESS Success to find the FFS in specificed FV - @return others Fail to find the FFS in specificed FV - **/ -EFI_STATUS +EFI_PEI_FILE_HANDLE DxeIplFindDxeCore ( - OUT EFI_PEI_FILE_HANDLE *FileHandle + OUT EFI_GUID *DxeCoreFileName ); - /** This function simply retrieves the function pointer of ImageRead in ImageContext structure. @@ -145,14 +150,12 @@ DxeLoadCore ( @param DxeCoreEntryPoint The entrypoint of DxeCore. @param HobList The start of HobList passed to DxeCore. - @param EndOfPeiSignal The PPI descriptor for EFI_END_OF_PEI_PPI. **/ VOID HandOffToDxeCore ( IN EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint, - IN EFI_PEI_HOB_POINTERS HobList, - IN EFI_PEI_PPI_DESCRIPTOR *EndOfPeiSignal + IN EFI_PEI_HOB_POINTERS HobList ); diff --git a/MdeModulePkg/Core/DxeIplPeim/DxeLoad.c b/MdeModulePkg/Core/DxeIplPeim/DxeLoad.c index fff08b33a0..5cd6b2cb17 100644 --- a/MdeModulePkg/Core/DxeIplPeim/DxeLoad.c +++ b/MdeModulePkg/Core/DxeIplPeim/DxeLoad.c @@ -25,32 +25,32 @@ BOOLEAN gInMemory = FALSE; // Module Globals used in the DXE to PEI handoff // These must be module globals, so the stack can be switched // -EFI_DXE_IPL_PPI mDxeIplPpi = { +CONST EFI_DXE_IPL_PPI mDxeIplPpi = { DxeLoadCore }; -EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI mCustomGuidedSectionExtractionPpi = { +CONST EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI mCustomGuidedSectionExtractionPpi = { CustomGuidedSectionExtract }; -EFI_PEI_DECOMPRESS_PPI mDecompressPpi = { +CONST EFI_PEI_DECOMPRESS_PPI mDecompressPpi = { Decompress }; -EFI_PEI_PPI_DESCRIPTOR mPpiList[] = { +CONST EFI_PEI_PPI_DESCRIPTOR mPpiList[] = { { EFI_PEI_PPI_DESCRIPTOR_PPI, &gEfiDxeIplPpiGuid, - &mDxeIplPpi + (VOID *) &mDxeIplPpi }, { (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST), &gEfiPeiDecompressPpiGuid, - &mDecompressPpi + (VOID *) &mDecompressPpi } }; -EFI_PEI_PPI_DESCRIPTOR mPpiSignal = { +CONST EFI_PEI_PPI_DESCRIPTOR gEndOfPeiSignalPpi = { (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST), &gEfiEndOfPeiSignalPpiGuid, NULL @@ -102,7 +102,7 @@ PeimInitializeDxeIpl ( ASSERT (GuidPpi != NULL); while (ExtractHandlerNumber-- > 0) { GuidPpi->Flags = EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST; - GuidPpi->Ppi = &mCustomGuidedSectionExtractionPpi; + GuidPpi->Ppi = (VOID *) &mCustomGuidedSectionExtractionPpi; GuidPpi->Guid = &(ExtractHandlerGuidTable [ExtractHandlerNumber]); Status = PeiServicesInstallPpi (GuidPpi++); ASSERT_EFI_ERROR(Status); @@ -203,11 +203,7 @@ DxeLoadCore ( // // Look in all the FVs present in PEI and find the DXE Core // - FileHandle = NULL; - Status = DxeIplFindDxeCore (&FileHandle); - ASSERT_EFI_ERROR (Status); - - CopyGuid(&DxeCoreFileName, &(((EFI_FFS_FILE_HEADER*)FileHandle)->Name)); + FileHandle = DxeIplFindDxeCore (&DxeCoreFileName); // // Load the DXE Core from a Firmware Volume, may use LoadFile ppi to do this for save code size. @@ -244,7 +240,7 @@ DxeLoadCore ( // Transfer control to the DXE Core // The handoff state is simply a pointer to the HOB list // - HandOffToDxeCore (DxeCoreEntryPoint, HobList, &mPpiSignal); + HandOffToDxeCore (DxeCoreEntryPoint, HobList); // // If we get here, then the DXE Core returned. This is an error // Dxe Core should not return. @@ -256,41 +252,67 @@ DxeLoadCore ( } - - /** - Find DxeCore driver from all First Volumes. + Searches DxeCore in all firmware Volumes and loads the first + instance that contains DxeCore. - @param FileHandle Pointer to FFS file to search. + @param DxeCoreFileName A Pointer to the EFI_GUID to contain + the output DxeCore GUID file name. + + @return FileHandle of DxeCore to load DxeCore. - @return EFI_SUCESS Success to find the FFS in specificed FV - @return others Fail to find the FFS in specificed FV - **/ -EFI_STATUS +EFI_PEI_FILE_HANDLE DxeIplFindDxeCore ( - OUT EFI_PEI_FILE_HANDLE *FileHandle + OUT EFI_GUID *DxeCoreFileName ) { - EFI_STATUS Status; - EFI_STATUS FileStatus; - UINTN Instance; - EFI_PEI_FV_HANDLE VolumeHandle; + EFI_STATUS Status; + UINTN Instance; + EFI_PEI_FV_HANDLE VolumeHandle; + EFI_PEI_FILE_HANDLE FileHandle; + EFI_FV_FILE_INFO FvFileInfo; Instance = 0; - *FileHandle = NULL; - - do { - Status = PeiServicesFfsFindNextVolume (Instance++, &VolumeHandle); + while (TRUE) { + // + // Traverse all firmware volume instances + // + Status = PeiServicesFfsFindNextVolume (Instance, &VolumeHandle); + // + // If some error occurs here, then we cannot find any firmware + // volume that may contain DxeCore. + // + ASSERT_EFI_ERROR (Status); + + // + // Find the DxeCore file type from the beginning in this firmware volume. + // + FileHandle = NULL; + Status = PeiServicesFfsFindNextFile (EFI_FV_FILETYPE_DXE_CORE, VolumeHandle, &FileHandle); if (!EFI_ERROR (Status)) { - FileStatus = PeiServicesFfsFindNextFile (EFI_FV_FILETYPE_DXE_CORE, VolumeHandle, FileHandle); - if (!EFI_ERROR (FileStatus)) { - return FileStatus; - } + // + // Find DxeCore FileHandle in this volume, then we skip other firmware volume. + // + break; } - } while (!EFI_ERROR (Status)); + // + // We cannot find DxeCore in this firmware volume, then search the next volume. + // + Instance++; + } - return EFI_NOT_FOUND; + // + // Extract the DxeCore GUID file name. + // + Status = PeiServicesFfsGetFileInfo (FileHandle, &FvFileInfo); + ASSERT_EFI_ERROR (Status); + CopyGuid (DxeCoreFileName, &FvFileInfo.FileName); + + // + // Return the FileHandle to load DxeCore from this volume. + // + return FileHandle; } diff --git a/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c b/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c index 4458ddd8ff..65c7ceac17 100644 --- a/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c +++ b/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c @@ -53,14 +53,12 @@ GLOBAL_REMOVE_IF_UNREFERENCED IA32_DESCRIPTOR gLidtDescriptor = { @param DxeCoreEntryPoint The entrypoint of DxeCore. @param HobList The start of HobList passed to DxeCore. - @param EndOfPeiSignal The PPI descriptor for EFI_END_OF_PEI_PPI. **/ VOID HandOffToDxeCore ( IN EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint, - IN EFI_PEI_HOB_POINTERS HobList, - IN EFI_PEI_PPI_DESCRIPTOR *EndOfPeiSignal + IN EFI_PEI_HOB_POINTERS HobList ) { EFI_STATUS Status; @@ -106,7 +104,7 @@ HandOffToDxeCore ( // // End of PEI phase singal // - Status = PeiServicesInstallPpi (EndOfPeiSignal); + Status = PeiServicesInstallPpi (&gEndOfPeiSignalPpi); ASSERT_EFI_ERROR (Status); AsmWriteCr3 (PageTables); @@ -169,7 +167,7 @@ HandOffToDxeCore ( // // End of PEI phase singal // - Status = PeiServicesInstallPpi (EndOfPeiSignal); + Status = PeiServicesInstallPpi (&gEndOfPeiSignalPpi); ASSERT_EFI_ERROR (Status); // diff --git a/MdeModulePkg/Core/DxeIplPeim/Ia32/ImageRead.c b/MdeModulePkg/Core/DxeIplPeim/Ia32/ImageRead.c index a303c90721..747026364e 100644 --- a/MdeModulePkg/Core/DxeIplPeim/Ia32/ImageRead.c +++ b/MdeModulePkg/Core/DxeIplPeim/Ia32/ImageRead.c @@ -56,9 +56,6 @@ PeiImageRead ( } - - - /** This function simply retrieves the function pointer of ImageRead in ImageContext structure. diff --git a/MdeModulePkg/Core/DxeIplPeim/Ipf/DxeLoadFunc.c b/MdeModulePkg/Core/DxeIplPeim/Ipf/DxeLoadFunc.c index 2c94dc70b7..5c9611e5c2 100644 --- a/MdeModulePkg/Core/DxeIplPeim/Ipf/DxeLoadFunc.c +++ b/MdeModulePkg/Core/DxeIplPeim/Ipf/DxeLoadFunc.c @@ -25,14 +25,12 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. @param DxeCoreEntryPoint The entrypoint of DxeCore. @param HobList The start of HobList passed to DxeCore. - @param EndOfPeiSignal The PPI descriptor for EFI_END_OF_PEI_PPI. **/ VOID HandOffToDxeCore ( IN EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint, - IN EFI_PEI_HOB_POINTERS HobList, - IN EFI_PEI_PPI_DESCRIPTOR *EndOfPeiSignal + IN EFI_PEI_HOB_POINTERS HobList ) { VOID *BaseOfStack; @@ -66,7 +64,7 @@ HandOffToDxeCore ( // // End of PEI phase singal // - Status = PeiServicesInstallPpi (EndOfPeiSignal); + Status = PeiServicesInstallPpi (&gEndOfPeiSignalPpi); ASSERT_EFI_ERROR (Status); // diff --git a/MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c b/MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c index c871dbe41f..51055e157a 100644 --- a/MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c +++ b/MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c @@ -25,14 +25,12 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. @param DxeCoreEntryPoint The entrypoint of DxeCore. @param HobList The start of HobList passed to DxeCore. - @param EndOfPeiSignal The PPI descriptor for EFI_END_OF_PEI_PPI. **/ VOID HandOffToDxeCore ( IN EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint, - IN EFI_PEI_HOB_POINTERS HobList, - IN EFI_PEI_PPI_DESCRIPTOR *EndOfPeiSignal + IN EFI_PEI_HOB_POINTERS HobList ) { VOID *BaseOfStack; @@ -55,7 +53,7 @@ HandOffToDxeCore ( // // End of PEI phase singal // - Status = PeiServicesInstallPpi (EndOfPeiSignal); + Status = PeiServicesInstallPpi (&gEndOfPeiSignalPpi); ASSERT_EFI_ERROR (Status); //