]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - IntelFspWrapperPkg/FspWrapperSecCore/FindPeiCore.c
IntelFspWrapperPkg: Fix typos in comments
[mirror_edk2.git] / IntelFspWrapperPkg / FspWrapperSecCore / FindPeiCore.c
... / ...
CommitLineData
1/** @file\r
2 Locate the entry point for the PEI Core\r
3\r
4 Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>\r
5 This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php.\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include <PiPei.h>\r
16#include <Library/BaseLib.h>\r
17#include <Library/PeCoffGetEntryPointLib.h>\r
18\r
19#include "SecMain.h"\r
20\r
21/**\r
22 Find core image base.\r
23\r
24 @param[in] BootFirmwareVolumePtr Point to the boot firmware volume.\r
25 @param[out] SecCoreImageBase The base address of the SEC core image.\r
26 @param[out] PeiCoreImageBase The base address of the PEI core image.\r
27\r
28**/\r
29EFI_STATUS\r
30EFIAPI\r
31FindImageBase (\r
32 IN EFI_FIRMWARE_VOLUME_HEADER *BootFirmwareVolumePtr,\r
33 OUT EFI_PHYSICAL_ADDRESS *SecCoreImageBase,\r
34 OUT EFI_PHYSICAL_ADDRESS *PeiCoreImageBase\r
35 )\r
36{\r
37 EFI_PHYSICAL_ADDRESS CurrentAddress;\r
38 EFI_PHYSICAL_ADDRESS EndOfFirmwareVolume;\r
39 EFI_FFS_FILE_HEADER *File;\r
40 UINT32 Size;\r
41 EFI_PHYSICAL_ADDRESS EndOfFile;\r
42 EFI_COMMON_SECTION_HEADER *Section;\r
43 EFI_PHYSICAL_ADDRESS EndOfSection;\r
44\r
45 *SecCoreImageBase = 0;\r
46 *PeiCoreImageBase = 0;\r
47\r
48 CurrentAddress = (EFI_PHYSICAL_ADDRESS)(UINTN) BootFirmwareVolumePtr;\r
49 EndOfFirmwareVolume = CurrentAddress + BootFirmwareVolumePtr->FvLength;\r
50\r
51 //\r
52 // Loop through the FFS files in the Boot Firmware Volume\r
53 //\r
54 for (EndOfFile = CurrentAddress + BootFirmwareVolumePtr->HeaderLength; ; ) {\r
55\r
56 CurrentAddress = (EndOfFile + 7) & 0xfffffffffffffff8ULL;\r
57 if (CurrentAddress > EndOfFirmwareVolume) {\r
58 return EFI_NOT_FOUND;\r
59 }\r
60\r
61 File = (EFI_FFS_FILE_HEADER*)(UINTN) CurrentAddress;\r
62 if (IS_FFS_FILE2 (File)) {\r
63 Size = FFS_FILE2_SIZE (File);\r
64 if (Size <= 0x00FFFFFF) {\r
65 return EFI_NOT_FOUND;\r
66 }\r
67 } else {\r
68 Size = FFS_FILE_SIZE (File);\r
69 if (Size < sizeof (EFI_FFS_FILE_HEADER)) {\r
70 return EFI_NOT_FOUND;\r
71 }\r
72 }\r
73\r
74 EndOfFile = CurrentAddress + Size;\r
75 if (EndOfFile > EndOfFirmwareVolume) {\r
76 return EFI_NOT_FOUND;\r
77 }\r
78\r
79 //\r
80 // Look for SEC Core / PEI Core files\r
81 //\r
82 if (File->Type != EFI_FV_FILETYPE_SECURITY_CORE &&\r
83 File->Type != EFI_FV_FILETYPE_PEI_CORE) {\r
84 continue;\r
85 }\r
86\r
87 //\r
88 // Loop through the FFS file sections within the FFS file\r
89 //\r
90 if (IS_FFS_FILE2 (File)) {\r
91 EndOfSection = (EFI_PHYSICAL_ADDRESS) (UINTN) ((UINT8 *) File + sizeof (EFI_FFS_FILE_HEADER2));\r
92 } else {\r
93 EndOfSection = (EFI_PHYSICAL_ADDRESS) (UINTN) ((UINT8 *) File + sizeof (EFI_FFS_FILE_HEADER));\r
94 }\r
95 for (;;) {\r
96 CurrentAddress = (EndOfSection + 3) & 0xfffffffffffffffcULL;\r
97 Section = (EFI_COMMON_SECTION_HEADER*)(UINTN) CurrentAddress;\r
98\r
99 if (IS_SECTION2 (Section)) {\r
100 Size = SECTION2_SIZE (Section);\r
101 if (Size <= 0x00FFFFFF) {\r
102 return EFI_NOT_FOUND;\r
103 }\r
104 } else {\r
105 Size = SECTION_SIZE (Section);\r
106 if (Size < sizeof (EFI_COMMON_SECTION_HEADER)) {\r
107 return EFI_NOT_FOUND;\r
108 }\r
109 }\r
110\r
111 EndOfSection = CurrentAddress + Size;\r
112 if (EndOfSection > EndOfFile) {\r
113 return EFI_NOT_FOUND;\r
114 }\r
115\r
116 //\r
117 // Look for executable sections\r
118 //\r
119 if (Section->Type == EFI_SECTION_PE32 || Section->Type == EFI_SECTION_TE) {\r
120 if (File->Type == EFI_FV_FILETYPE_SECURITY_CORE) {\r
121 if (IS_SECTION2 (Section)) {\r
122 *SecCoreImageBase = (PHYSICAL_ADDRESS) (UINTN) ((UINT8 *) Section + sizeof (EFI_COMMON_SECTION_HEADER2));\r
123 } else {\r
124 *SecCoreImageBase = (PHYSICAL_ADDRESS) (UINTN) ((UINT8 *) Section + sizeof (EFI_COMMON_SECTION_HEADER));\r
125 }\r
126 } else {\r
127 if (IS_SECTION2 (Section)) {\r
128 *PeiCoreImageBase = (PHYSICAL_ADDRESS) (UINTN) ((UINT8 *) Section + sizeof (EFI_COMMON_SECTION_HEADER2));\r
129 } else {\r
130 *PeiCoreImageBase = (PHYSICAL_ADDRESS) (UINTN) ((UINT8 *) Section + sizeof (EFI_COMMON_SECTION_HEADER));\r
131 }\r
132 }\r
133 break;\r
134 }\r
135 }\r
136\r
137 //\r
138 // Both SEC Core and PEI Core images found\r
139 //\r
140 if (*SecCoreImageBase != 0 && *PeiCoreImageBase != 0) {\r
141 return EFI_SUCCESS;\r
142 }\r
143 }\r
144}\r
145\r
146/**\r
147 Find and return Pei Core entry point.\r
148\r
149 It also find SEC and PEI Core file debug information. It will report them if\r
150 remote debug is enabled.\r
151\r
152 @param[in] BootFirmwareVolumePtr Point to the boot firmware volume.\r
153 @param[out] PeiCoreEntryPoint The entry point of the PEI core.\r
154\r
155**/\r
156VOID\r
157EFIAPI\r
158FindAndReportEntryPoints (\r
159 IN EFI_FIRMWARE_VOLUME_HEADER *BootFirmwareVolumePtr,\r
160 OUT EFI_PEI_CORE_ENTRY_POINT *PeiCoreEntryPoint\r
161 )\r
162{\r
163 EFI_STATUS Status;\r
164 EFI_PHYSICAL_ADDRESS SecCoreImageBase;\r
165 EFI_PHYSICAL_ADDRESS PeiCoreImageBase;\r
166 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;\r
167\r
168 //\r
169 // Find SEC Core and PEI Core image base\r
170 //\r
171 Status = FindImageBase (BootFirmwareVolumePtr, &SecCoreImageBase, &PeiCoreImageBase);\r
172 ASSERT_EFI_ERROR (Status);\r
173\r
174 ZeroMem ((VOID *) &ImageContext, sizeof (PE_COFF_LOADER_IMAGE_CONTEXT));\r
175 //\r
176 // Report SEC Core debug information when remote debug is enabled\r
177 //\r
178 ImageContext.ImageAddress = SecCoreImageBase;\r
179 ImageContext.PdbPointer = PeCoffLoaderGetPdbPointer ((VOID*) (UINTN) ImageContext.ImageAddress);\r
180 PeCoffLoaderRelocateImageExtraAction (&ImageContext);\r
181\r
182 //\r
183 // Report PEI Core debug information when remote debug is enabled\r
184 //\r
185 ImageContext.ImageAddress = PeiCoreImageBase;\r
186 ImageContext.PdbPointer = PeCoffLoaderGetPdbPointer ((VOID*) (UINTN) ImageContext.ImageAddress);\r
187 PeCoffLoaderRelocateImageExtraAction (&ImageContext);\r
188\r
189 //\r
190 // Find PEI Core entry point\r
191 //\r
192 Status = PeCoffLoaderGetEntryPoint ((VOID *) (UINTN) PeiCoreImageBase, (VOID**) PeiCoreEntryPoint);\r
193 if (EFI_ERROR (Status)) {\r
194 *PeiCoreEntryPoint = 0;\r
195 }\r
196\r
197 return;\r
198}\r
199\r