*\r
* Copyright (c) 2011-2014, ARM Limited. All rights reserved.\r
*\r
-* This program and the accompanying materials\r
-* are licensed and made available under the terms and conditions of the BSD License\r
-* which accompanies this distribution. The full text of the license may be found at\r
-* http://opensource.org/licenses/bsd-license.php\r
-*\r
-* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+* SPDX-License-Identifier: BSD-2-Clause-Patent\r
*\r
**/\r
\r
#include <PiPei.h>\r
#include <Pi/PiBootMode.h>\r
\r
+#include <Library/PeCoffLib.h>\r
#include <Library/PrePiLib.h>\r
#include <Library/PrintLib.h>\r
#include <Library/PrePiHobListPointerLib.h>\r
\r
VOID\r
PrePiMain (\r
- IN UINTN UefiMemoryBase,\r
- IN UINTN StacksBase,\r
- IN UINT64 StartTimeStamp\r
+ IN UINTN UefiMemoryBase,\r
+ IN UINTN StacksBase,\r
+ IN UINT64 StartTimeStamp\r
)\r
{\r
- EFI_HOB_HANDOFF_INFO_TABLE* HobList;\r
- EFI_STATUS Status;\r
- CHAR8 Buffer[100];\r
- UINTN CharCount;\r
- UINTN StacksSize;\r
+ EFI_HOB_HANDOFF_INFO_TABLE *HobList;\r
+ EFI_STATUS Status;\r
+ CHAR8 Buffer[100];\r
+ UINTN CharCount;\r
+ UINTN StacksSize;\r
\r
// Initialize the architecture specific bits\r
ArchInitialize ();\r
\r
// Declare the PI/UEFI memory region\r
HobList = HobConstructor (\r
- (VOID*)UefiMemoryBase,\r
- FixedPcdGet32 (PcdSystemMemoryUefiRegionSize),\r
- (VOID*)UefiMemoryBase,\r
- (VOID*)StacksBase // The top of the UEFI Memory is reserved for the stacks\r
- );\r
+ (VOID *)UefiMemoryBase,\r
+ FixedPcdGet32 (PcdSystemMemoryUefiRegionSize),\r
+ (VOID *)UefiMemoryBase,\r
+ (VOID *)StacksBase // The top of the UEFI Memory is reserved for the stacks\r
+ );\r
PrePeiSetHobList (HobList);\r
\r
//\r
// modifications we made with the caches and MMU off (such as the applied\r
// relocations) don't become invisible once we turn them on.\r
//\r
- InvalidateDataCacheRange((VOID *)(UINTN)PcdGet64 (PcdFdBaseAddress), PcdGet32 (PcdFdSize));\r
+ InvalidateDataCacheRange ((VOID *)(UINTN)PcdGet64 (PcdFdBaseAddress), PcdGet32 (PcdFdSize));\r
+\r
+ // SEC phase needs to run library constructors by hand.\r
+ ProcessLibraryConstructorList ();\r
\r
// Initialize MMU and Memory HOBs (Resource Descriptor HOBs)\r
Status = MemoryPeim (UefiMemoryBase, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize));\r
\r
// Initialize the Serial Port\r
SerialPortInitialize ();\r
- CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"UEFI firmware (version %s built at %a on %a)\n\r",\r
- (CHAR16*)PcdGetPtr(PcdFirmwareVersionString), __TIME__, __DATE__);\r
- SerialPortWrite ((UINT8 *) Buffer, CharCount);\r
+ CharCount = AsciiSPrint (\r
+ Buffer,\r
+ sizeof (Buffer),\r
+ "UEFI firmware (version %s built at %a on %a)\n\r",\r
+ (CHAR16 *)PcdGetPtr (PcdFirmwareVersionString),\r
+ __TIME__,\r
+ __DATE__\r
+ );\r
+ SerialPortWrite ((UINT8 *)Buffer, CharCount);\r
\r
// Create the Stacks HOB (reserve the memory for all stacks)\r
StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize);\r
BuildStackHob (StacksBase, StacksSize);\r
\r
- //TODO: Call CpuPei as a library\r
- BuildCpuHob (PcdGet8 (PcdPrePiCpuMemorySize), PcdGet8 (PcdPrePiCpuIoSize));\r
+ // TODO: Call CpuPei as a library\r
+ BuildCpuHob (ArmGetPhysicalAddressBits (), PcdGet8 (PcdPrePiCpuIoSize));\r
\r
// Set the Boot Mode\r
SetBootMode (BOOT_WITH_FULL_CONFIGURATION);\r
// Now, the HOB List has been initialized, we can register performance information\r
PERF_START (NULL, "PEI", NULL, StartTimeStamp);\r
\r
- // SEC phase needs to run library constructors by hand.\r
- ProcessLibraryConstructorList ();\r
-\r
// Assume the FV that contains the SEC (our code) also contains a compressed FV.\r
Status = DecompressFirstFv ();\r
ASSERT_EFI_ERROR (Status);\r
\r
VOID\r
CEntryPoint (\r
- IN UINTN MpId,\r
- IN UINTN UefiMemoryBase,\r
- IN UINTN StacksBase\r
+ IN UINTN MpId,\r
+ IN UINTN UefiMemoryBase,\r
+ IN UINTN StacksBase\r
)\r
{\r
- UINT64 StartTimeStamp;\r
+ UINT64 StartTimeStamp;\r
\r
if (PerformanceMeasurementEnabled ()) {\r
// Initialize the Timer Library to setup the Timer HW controller\r
// DXE Core should always load and never return\r
ASSERT (FALSE);\r
}\r
+\r
+VOID\r
+RelocatePeCoffImage (\r
+ IN EFI_PEI_FV_HANDLE FwVolHeader,\r
+ IN PE_COFF_LOADER_READ_FILE ImageRead\r
+ )\r
+{\r
+ EFI_PEI_FILE_HANDLE FileHandle;\r
+ VOID *SectionData;\r
+ PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;\r
+ EFI_STATUS Status;\r
+\r
+ FileHandle = NULL;\r
+ Status = FfsFindNextFile (\r
+ EFI_FV_FILETYPE_SECURITY_CORE,\r
+ FwVolHeader,\r
+ &FileHandle\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
+ Status = FfsFindSectionData (EFI_SECTION_PE32, FileHandle, &SectionData);\r
+ if (EFI_ERROR (Status)) {\r
+ Status = FfsFindSectionData (EFI_SECTION_TE, FileHandle, &SectionData);\r
+ }\r
+\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
+ ZeroMem (&ImageContext, sizeof ImageContext);\r
+\r
+ ImageContext.Handle = (EFI_HANDLE)SectionData;\r
+ ImageContext.ImageRead = ImageRead;\r
+ PeCoffLoaderGetImageInfo (&ImageContext);\r
+\r
+ if (ImageContext.ImageAddress != (UINTN)SectionData) {\r
+ ImageContext.ImageAddress = (UINTN)SectionData;\r
+ PeCoffLoaderRelocateImage (&ImageContext);\r
+ }\r
+}\r