3 * Copyright (c) 2011-2014, ARM Limited. All rights reserved.
5 * SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include <Pi/PiBootMode.h>
12 #include <Library/PeCoffLib.h>
13 #include <Library/PrePiLib.h>
14 #include <Library/PrintLib.h>
15 #include <Library/PrePiHobListPointerLib.h>
16 #include <Library/TimerLib.h>
17 #include <Library/PerformanceLib.h>
18 #include <Library/CacheMaintenanceLib.h>
20 #include <Ppi/GuidedSectionExtraction.h>
21 #include <Ppi/ArmMpCoreInfo.h>
27 ProcessLibraryConstructorList (
33 IN UINTN UefiMemoryBase
,
35 IN UINT64 StartTimeStamp
38 EFI_HOB_HANDOFF_INFO_TABLE
* HobList
;
44 // Initialize the architecture specific bits
47 // Declare the PI/UEFI memory region
48 HobList
= HobConstructor (
49 (VOID
*)UefiMemoryBase
,
50 FixedPcdGet32 (PcdSystemMemoryUefiRegionSize
),
51 (VOID
*)UefiMemoryBase
,
52 (VOID
*)StacksBase
// The top of the UEFI Memory is reserved for the stacks
54 PrePeiSetHobList (HobList
);
57 // Ensure that the loaded image is invalidated in the caches, so that any
58 // modifications we made with the caches and MMU off (such as the applied
59 // relocations) don't become invisible once we turn them on.
61 InvalidateDataCacheRange((VOID
*)(UINTN
)PcdGet64 (PcdFdBaseAddress
), PcdGet32 (PcdFdSize
));
63 // Initialize MMU and Memory HOBs (Resource Descriptor HOBs)
64 Status
= MemoryPeim (UefiMemoryBase
, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize
));
65 ASSERT_EFI_ERROR (Status
);
67 // Initialize the Serial Port
68 SerialPortInitialize ();
69 CharCount
= AsciiSPrint (Buffer
,sizeof (Buffer
),"UEFI firmware (version %s built at %a on %a)\n\r",
70 (CHAR16
*)PcdGetPtr(PcdFirmwareVersionString
), __TIME__
, __DATE__
);
71 SerialPortWrite ((UINT8
*) Buffer
, CharCount
);
73 // Create the Stacks HOB (reserve the memory for all stacks)
74 StacksSize
= PcdGet32 (PcdCPUCorePrimaryStackSize
);
75 BuildStackHob (StacksBase
, StacksSize
);
77 //TODO: Call CpuPei as a library
78 BuildCpuHob (ArmGetPhysicalAddressBits (), PcdGet8 (PcdPrePiCpuIoSize
));
81 SetBootMode (BOOT_WITH_FULL_CONFIGURATION
);
83 // Initialize Platform HOBs (CpuHob and FvHob)
84 Status
= PlatformPeim ();
85 ASSERT_EFI_ERROR (Status
);
87 // Now, the HOB List has been initialized, we can register performance information
88 PERF_START (NULL
, "PEI", NULL
, StartTimeStamp
);
90 // SEC phase needs to run library constructors by hand.
91 ProcessLibraryConstructorList ();
93 // Assume the FV that contains the SEC (our code) also contains a compressed FV.
94 Status
= DecompressFirstFv ();
95 ASSERT_EFI_ERROR (Status
);
97 // Load the DXE Core and transfer control to it
98 Status
= LoadDxeCoreFromFv (NULL
, 0);
99 ASSERT_EFI_ERROR (Status
);
105 IN UINTN UefiMemoryBase
,
109 UINT64 StartTimeStamp
;
111 if (PerformanceMeasurementEnabled ()) {
112 // Initialize the Timer Library to setup the Timer HW controller
114 // We cannot call yet the PerformanceLib because the HOB List has not been initialized
115 StartTimeStamp
= GetPerformanceCounter ();
120 // Data Cache enabled on Primary core when MMU is enabled.
121 ArmDisableDataCache ();
122 // Invalidate instruction cache
123 ArmInvalidateInstructionCache ();
124 // Enable Instruction Caches on all cores.
125 ArmEnableInstructionCache ();
127 PrePiMain (UefiMemoryBase
, StacksBase
, StartTimeStamp
);
129 // DXE Core should always load and never return
134 RelocatePeCoffImage (
135 IN EFI_PEI_FV_HANDLE FwVolHeader
,
136 IN PE_COFF_LOADER_READ_FILE ImageRead
139 EFI_PEI_FILE_HANDLE FileHandle
;
141 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext
;
145 Status
= FfsFindNextFile (EFI_FV_FILETYPE_SECURITY_CORE
, FwVolHeader
,
147 ASSERT_EFI_ERROR (Status
);
149 Status
= FfsFindSectionData (EFI_SECTION_PE32
, FileHandle
, &SectionData
);
150 if (EFI_ERROR (Status
)) {
151 Status
= FfsFindSectionData (EFI_SECTION_TE
, FileHandle
, &SectionData
);
153 ASSERT_EFI_ERROR (Status
);
155 ZeroMem (&ImageContext
, sizeof ImageContext
);
157 ImageContext
.Handle
= (EFI_HANDLE
)SectionData
;
158 ImageContext
.ImageRead
= ImageRead
;
159 PeCoffLoaderGetImageInfo (&ImageContext
);
161 if (ImageContext
.ImageAddress
!= (UINTN
)SectionData
) {
162 ImageContext
.ImageAddress
= (UINTN
)SectionData
;
163 PeCoffLoaderRelocateImage (&ImageContext
);