]>
Commit | Line | Data |
---|---|---|
f9a9d2dc AB |
1 | /** @file\r |
2 | *\r | |
3 | * Copyright (c) 2011-2014, ARM Limited. All rights reserved.\r | |
4 | *\r | |
9792fb0e | 5 | * SPDX-License-Identifier: BSD-2-Clause-Patent\r |
f9a9d2dc AB |
6 | *\r |
7 | **/\r | |
8 | \r | |
9 | #include <PiPei.h>\r | |
0ae69a2e | 10 | #include <Pi/PiBootMode.h>\r |
f9a9d2dc | 11 | \r |
b16fd231 | 12 | #include <Library/PeCoffLib.h>\r |
f9a9d2dc AB |
13 | #include <Library/PrePiLib.h>\r |
14 | #include <Library/PrintLib.h>\r | |
f9a9d2dc AB |
15 | #include <Library/PrePiHobListPointerLib.h>\r |
16 | #include <Library/TimerLib.h>\r | |
17 | #include <Library/PerformanceLib.h>\r | |
c9e5618f | 18 | #include <Library/CacheMaintenanceLib.h>\r |
f9a9d2dc AB |
19 | \r |
20 | #include <Ppi/GuidedSectionExtraction.h>\r | |
21 | #include <Ppi/ArmMpCoreInfo.h>\r | |
f9a9d2dc AB |
22 | \r |
23 | #include "PrePi.h"\r | |
f9a9d2dc | 24 | \r |
af47c618 | 25 | VOID\r |
f9a9d2dc | 26 | EFIAPI\r |
af47c618 | 27 | ProcessLibraryConstructorList (\r |
f9a9d2dc AB |
28 | VOID\r |
29 | );\r | |
30 | \r | |
f9a9d2dc AB |
31 | VOID\r |
32 | PrePiMain (\r | |
33 | IN UINTN UefiMemoryBase,\r | |
34 | IN UINTN StacksBase,\r | |
f9a9d2dc AB |
35 | IN UINT64 StartTimeStamp\r |
36 | )\r | |
37 | {\r | |
38 | EFI_HOB_HANDOFF_INFO_TABLE* HobList;\r | |
39 | EFI_STATUS Status;\r | |
40 | CHAR8 Buffer[100];\r | |
41 | UINTN CharCount;\r | |
42 | UINTN StacksSize;\r | |
43 | \r | |
44 | // Initialize the architecture specific bits\r | |
45 | ArchInitialize ();\r | |
46 | \r | |
f9a9d2dc AB |
47 | // Declare the PI/UEFI memory region\r |
48 | HobList = HobConstructor (\r | |
49 | (VOID*)UefiMemoryBase,\r | |
50 | FixedPcdGet32 (PcdSystemMemoryUefiRegionSize),\r | |
51 | (VOID*)UefiMemoryBase,\r | |
52 | (VOID*)StacksBase // The top of the UEFI Memory is reserved for the stacks\r | |
53 | );\r | |
54 | PrePeiSetHobList (HobList);\r | |
55 | \r | |
c9e5618f AB |
56 | //\r |
57 | // Ensure that the loaded image is invalidated in the caches, so that any\r | |
58 | // modifications we made with the caches and MMU off (such as the applied\r | |
59 | // relocations) don't become invisible once we turn them on.\r | |
60 | //\r | |
61 | InvalidateDataCacheRange((VOID *)(UINTN)PcdGet64 (PcdFdBaseAddress), PcdGet32 (PcdFdSize));\r | |
62 | \r | |
f9a9d2dc AB |
63 | // Initialize MMU and Memory HOBs (Resource Descriptor HOBs)\r |
64 | Status = MemoryPeim (UefiMemoryBase, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize));\r | |
65 | ASSERT_EFI_ERROR (Status);\r | |
66 | \r | |
c9e5618f AB |
67 | // Initialize the Serial Port\r |
68 | SerialPortInitialize ();\r | |
69 | CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"UEFI firmware (version %s built at %a on %a)\n\r",\r | |
70 | (CHAR16*)PcdGetPtr(PcdFirmwareVersionString), __TIME__, __DATE__);\r | |
71 | SerialPortWrite ((UINT8 *) Buffer, CharCount);\r | |
72 | \r | |
f9a9d2dc AB |
73 | // Create the Stacks HOB (reserve the memory for all stacks)\r |
74 | StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize);\r | |
75 | BuildStackHob (StacksBase, StacksSize);\r | |
76 | \r | |
f9a9d2dc | 77 | //TODO: Call CpuPei as a library\r |
ff3c9780 | 78 | BuildCpuHob (ArmGetPhysicalAddressBits (), PcdGet8 (PcdPrePiCpuIoSize));\r |
f9a9d2dc AB |
79 | \r |
80 | // Set the Boot Mode\r | |
0ae69a2e | 81 | SetBootMode (BOOT_WITH_FULL_CONFIGURATION);\r |
f9a9d2dc AB |
82 | \r |
83 | // Initialize Platform HOBs (CpuHob and FvHob)\r | |
84 | Status = PlatformPeim ();\r | |
85 | ASSERT_EFI_ERROR (Status);\r | |
86 | \r | |
87 | // Now, the HOB List has been initialized, we can register performance information\r | |
88 | PERF_START (NULL, "PEI", NULL, StartTimeStamp);\r | |
89 | \r | |
90 | // SEC phase needs to run library constructors by hand.\r | |
af47c618 | 91 | ProcessLibraryConstructorList ();\r |
f9a9d2dc | 92 | \r |
f9a9d2dc AB |
93 | // Assume the FV that contains the SEC (our code) also contains a compressed FV.\r |
94 | Status = DecompressFirstFv ();\r | |
95 | ASSERT_EFI_ERROR (Status);\r | |
96 | \r | |
97 | // Load the DXE Core and transfer control to it\r | |
98 | Status = LoadDxeCoreFromFv (NULL, 0);\r | |
99 | ASSERT_EFI_ERROR (Status);\r | |
100 | }\r | |
101 | \r | |
102 | VOID\r | |
103 | CEntryPoint (\r | |
104 | IN UINTN MpId,\r | |
105 | IN UINTN UefiMemoryBase,\r | |
5eeba3b7 | 106 | IN UINTN StacksBase\r |
f9a9d2dc AB |
107 | )\r |
108 | {\r | |
109 | UINT64 StartTimeStamp;\r | |
110 | \r | |
f9a9d2dc AB |
111 | if (PerformanceMeasurementEnabled ()) {\r |
112 | // Initialize the Timer Library to setup the Timer HW controller\r | |
113 | TimerConstructor ();\r | |
114 | // We cannot call yet the PerformanceLib because the HOB List has not been initialized\r | |
115 | StartTimeStamp = GetPerformanceCounter ();\r | |
116 | } else {\r | |
117 | StartTimeStamp = 0;\r | |
118 | }\r | |
119 | \r | |
120 | // Data Cache enabled on Primary core when MMU is enabled.\r | |
121 | ArmDisableDataCache ();\r | |
f9a9d2dc AB |
122 | // Invalidate instruction cache\r |
123 | ArmInvalidateInstructionCache ();\r | |
124 | // Enable Instruction Caches on all cores.\r | |
125 | ArmEnableInstructionCache ();\r | |
126 | \r | |
5eeba3b7 | 127 | PrePiMain (UefiMemoryBase, StacksBase, StartTimeStamp);\r |
f9a9d2dc AB |
128 | \r |
129 | // DXE Core should always load and never return\r | |
130 | ASSERT (FALSE);\r | |
131 | }\r | |
b16fd231 AB |
132 | \r |
133 | VOID\r | |
134 | RelocatePeCoffImage (\r | |
135 | IN EFI_PEI_FV_HANDLE FwVolHeader,\r | |
136 | IN PE_COFF_LOADER_READ_FILE ImageRead\r | |
137 | )\r | |
138 | {\r | |
139 | EFI_PEI_FILE_HANDLE FileHandle;\r | |
140 | VOID *SectionData;\r | |
141 | PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;\r | |
142 | EFI_STATUS Status;\r | |
143 | \r | |
144 | FileHandle = NULL;\r | |
145 | Status = FfsFindNextFile (EFI_FV_FILETYPE_SECURITY_CORE, FwVolHeader,\r | |
146 | &FileHandle);\r | |
147 | ASSERT_EFI_ERROR (Status);\r | |
148 | \r | |
149 | Status = FfsFindSectionData (EFI_SECTION_PE32, FileHandle, &SectionData);\r | |
150 | if (EFI_ERROR (Status)) {\r | |
151 | Status = FfsFindSectionData (EFI_SECTION_TE, FileHandle, &SectionData);\r | |
152 | }\r | |
153 | ASSERT_EFI_ERROR (Status);\r | |
154 | \r | |
155 | ZeroMem (&ImageContext, sizeof ImageContext);\r | |
156 | \r | |
157 | ImageContext.Handle = (EFI_HANDLE)SectionData;\r | |
158 | ImageContext.ImageRead = ImageRead;\r | |
159 | PeCoffLoaderGetImageInfo (&ImageContext);\r | |
160 | \r | |
161 | if (ImageContext.ImageAddress != (UINTN)SectionData) {\r | |
162 | ImageContext.ImageAddress = (UINTN)SectionData;\r | |
163 | PeCoffLoaderRelocateImage (&ImageContext);\r | |
164 | }\r | |
165 | }\r |