]>
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 | |
2b16a4fb MK |
33 | IN UINTN UefiMemoryBase,\r |
34 | IN UINTN StacksBase,\r | |
35 | IN UINT64 StartTimeStamp\r | |
f9a9d2dc AB |
36 | )\r |
37 | {\r | |
2b16a4fb MK |
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 | |
f9a9d2dc AB |
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 | |
2b16a4fb MK |
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 | |
f9a9d2dc AB |
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 | |
2b16a4fb | 61 | InvalidateDataCacheRange ((VOID *)(UINTN)PcdGet64 (PcdFdBaseAddress), PcdGet32 (PcdFdSize));\r |
c9e5618f | 62 | \r |
6c8a08bd AB |
63 | // SEC phase needs to run library constructors by hand.\r |
64 | ProcessLibraryConstructorList ();\r | |
65 | \r | |
f9a9d2dc AB |
66 | // Initialize MMU and Memory HOBs (Resource Descriptor HOBs)\r |
67 | Status = MemoryPeim (UefiMemoryBase, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize));\r | |
68 | ASSERT_EFI_ERROR (Status);\r | |
69 | \r | |
c9e5618f AB |
70 | // Initialize the Serial Port\r |
71 | SerialPortInitialize ();\r | |
2b16a4fb MK |
72 | CharCount = AsciiSPrint (\r |
73 | Buffer,\r | |
74 | sizeof (Buffer),\r | |
75 | "UEFI firmware (version %s built at %a on %a)\n\r",\r | |
76 | (CHAR16 *)PcdGetPtr (PcdFirmwareVersionString),\r | |
77 | __TIME__,\r | |
78 | __DATE__\r | |
79 | );\r | |
80 | SerialPortWrite ((UINT8 *)Buffer, CharCount);\r | |
c9e5618f | 81 | \r |
f9a9d2dc AB |
82 | // Create the Stacks HOB (reserve the memory for all stacks)\r |
83 | StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize);\r | |
84 | BuildStackHob (StacksBase, StacksSize);\r | |
85 | \r | |
2b16a4fb | 86 | // TODO: Call CpuPei as a library\r |
ff3c9780 | 87 | BuildCpuHob (ArmGetPhysicalAddressBits (), PcdGet8 (PcdPrePiCpuIoSize));\r |
f9a9d2dc AB |
88 | \r |
89 | // Set the Boot Mode\r | |
0ae69a2e | 90 | SetBootMode (BOOT_WITH_FULL_CONFIGURATION);\r |
f9a9d2dc AB |
91 | \r |
92 | // Initialize Platform HOBs (CpuHob and FvHob)\r | |
93 | Status = PlatformPeim ();\r | |
94 | ASSERT_EFI_ERROR (Status);\r | |
95 | \r | |
96 | // Now, the HOB List has been initialized, we can register performance information\r | |
97 | PERF_START (NULL, "PEI", NULL, StartTimeStamp);\r | |
98 | \r | |
f9a9d2dc AB |
99 | // Assume the FV that contains the SEC (our code) also contains a compressed FV.\r |
100 | Status = DecompressFirstFv ();\r | |
101 | ASSERT_EFI_ERROR (Status);\r | |
102 | \r | |
103 | // Load the DXE Core and transfer control to it\r | |
104 | Status = LoadDxeCoreFromFv (NULL, 0);\r | |
105 | ASSERT_EFI_ERROR (Status);\r | |
106 | }\r | |
107 | \r | |
108 | VOID\r | |
109 | CEntryPoint (\r | |
2b16a4fb MK |
110 | IN UINTN MpId,\r |
111 | IN UINTN UefiMemoryBase,\r | |
112 | IN UINTN StacksBase\r | |
f9a9d2dc AB |
113 | )\r |
114 | {\r | |
2b16a4fb | 115 | UINT64 StartTimeStamp;\r |
f9a9d2dc | 116 | \r |
f9a9d2dc AB |
117 | if (PerformanceMeasurementEnabled ()) {\r |
118 | // Initialize the Timer Library to setup the Timer HW controller\r | |
119 | TimerConstructor ();\r | |
120 | // We cannot call yet the PerformanceLib because the HOB List has not been initialized\r | |
121 | StartTimeStamp = GetPerformanceCounter ();\r | |
122 | } else {\r | |
123 | StartTimeStamp = 0;\r | |
124 | }\r | |
125 | \r | |
126 | // Data Cache enabled on Primary core when MMU is enabled.\r | |
127 | ArmDisableDataCache ();\r | |
f9a9d2dc AB |
128 | // Invalidate instruction cache\r |
129 | ArmInvalidateInstructionCache ();\r | |
130 | // Enable Instruction Caches on all cores.\r | |
131 | ArmEnableInstructionCache ();\r | |
132 | \r | |
5eeba3b7 | 133 | PrePiMain (UefiMemoryBase, StacksBase, StartTimeStamp);\r |
f9a9d2dc AB |
134 | \r |
135 | // DXE Core should always load and never return\r | |
136 | ASSERT (FALSE);\r | |
137 | }\r | |
b16fd231 AB |
138 | \r |
139 | VOID\r | |
140 | RelocatePeCoffImage (\r | |
2b16a4fb MK |
141 | IN EFI_PEI_FV_HANDLE FwVolHeader,\r |
142 | IN PE_COFF_LOADER_READ_FILE ImageRead\r | |
b16fd231 AB |
143 | )\r |
144 | {\r | |
145 | EFI_PEI_FILE_HANDLE FileHandle;\r | |
146 | VOID *SectionData;\r | |
147 | PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;\r | |
148 | EFI_STATUS Status;\r | |
149 | \r | |
150 | FileHandle = NULL;\r | |
2b16a4fb MK |
151 | Status = FfsFindNextFile (\r |
152 | EFI_FV_FILETYPE_SECURITY_CORE,\r | |
153 | FwVolHeader,\r | |
154 | &FileHandle\r | |
155 | );\r | |
b16fd231 AB |
156 | ASSERT_EFI_ERROR (Status);\r |
157 | \r | |
158 | Status = FfsFindSectionData (EFI_SECTION_PE32, FileHandle, &SectionData);\r | |
159 | if (EFI_ERROR (Status)) {\r | |
160 | Status = FfsFindSectionData (EFI_SECTION_TE, FileHandle, &SectionData);\r | |
161 | }\r | |
2b16a4fb | 162 | \r |
b16fd231 AB |
163 | ASSERT_EFI_ERROR (Status);\r |
164 | \r | |
165 | ZeroMem (&ImageContext, sizeof ImageContext);\r | |
166 | \r | |
2b16a4fb MK |
167 | ImageContext.Handle = (EFI_HANDLE)SectionData;\r |
168 | ImageContext.ImageRead = ImageRead;\r | |
b16fd231 AB |
169 | PeCoffLoaderGetImageInfo (&ImageContext);\r |
170 | \r | |
171 | if (ImageContext.ImageAddress != (UINTN)SectionData) {\r | |
172 | ImageContext.ImageAddress = (UINTN)SectionData;\r | |
173 | PeCoffLoaderRelocateImage (&ImageContext);\r | |
174 | }\r | |
175 | }\r |