The main issue want to be resolve is that some tools need EfiCompress and other tools...
[mirror_edk2.git] / EdkNt32Pkg / Pei / FlashMap / FlashMap.c
CommitLineData
878ddf1f 1/*++\r
2\r
3Copyright (c) 2006, Intel Corporation \r
4All rights reserved. This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12Module Name:\r
13\r
14 FlashMap.c\r
15 \r
16Abstract:\r
17\r
18 PEIM to build GUIDed HOBs for platform specific flash map\r
19\r
20--*/\r
21\r
22\r
23#include <FlashLayout.h>\r
24\r
25EFI_STATUS\r
26EFIAPI\r
27GetAreaInfo (\r
28 IN EFI_PEI_SERVICES **PeiServices,\r
29 IN PEI_FLASH_MAP_PPI *This,\r
30 IN EFI_FLASH_AREA_TYPE AreaType,\r
31 IN EFI_GUID *AreaTypeGuid,\r
32 OUT UINT32 *NumEntries,\r
33 OUT EFI_FLASH_SUBAREA_ENTRY **Entries\r
34 );\r
35\r
36EFI_STATUS\r
37EFIAPI\r
38MemoryDiscoveredPpiNotifyCallback (\r
39 IN EFI_PEI_SERVICES **PeiServices,\r
40 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,\r
41 IN VOID *Ppi\r
42 );\r
43\r
44//\r
45// Module globals\r
46//\r
47static PEI_FLASH_MAP_PPI mFlashMapPpi = { GetAreaInfo };\r
48\r
49static EFI_PEI_PPI_DESCRIPTOR mPpiListFlashMap = {\r
50 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
51 &gPeiFlashMapPpiGuid,\r
52 &mFlashMapPpi\r
53};\r
54\r
55static EFI_FLASH_AREA_DATA mFlashAreaData[] = {\r
56 //\r
57 // Variable area\r
58 //\r
59 {\r
60 EFI_VARIABLE_STORE_OFFSET,\r
61 EFI_VARIABLE_STORE_LENGTH,\r
62 EFI_FLASH_AREA_SUBFV | EFI_FLASH_AREA_MEMMAPPED_FV,\r
63 EFI_FLASH_AREA_EFI_VARIABLES\r
64 },\r
65 //\r
66 // FTW spare (backup) block\r
67 //\r
68 {\r
69 EFI_WINNT_FTW_SPARE_BLOCK_OFFSET,\r
70 EFI_WINNT_FTW_SPARE_BLOCK_LENGTH,\r
71 EFI_FLASH_AREA_SUBFV | EFI_FLASH_AREA_MEMMAPPED_FV,\r
72 EFI_FLASH_AREA_FTW_BACKUP\r
73 },\r
74 //\r
75 // FTW private working (state) area\r
76 //\r
77 {\r
78 EFI_FTW_WORKING_OFFSET,\r
79 EFI_FTW_WORKING_LENGTH,\r
80 EFI_FLASH_AREA_SUBFV | EFI_FLASH_AREA_MEMMAPPED_FV,\r
81 EFI_FLASH_AREA_FTW_STATE\r
82 },\r
83 //\r
84 // Recovery FV\r
85 //\r
86 {\r
87 EFI_WINNT_FIRMWARE_OFFSET,\r
88 EFI_WINNT_FIRMWARE_LENGTH,\r
89 EFI_FLASH_AREA_FV | EFI_FLASH_AREA_MEMMAPPED_FV,\r
90 EFI_FLASH_AREA_RECOVERY_BIOS\r
91 },\r
92 //\r
93 // System Non-Volatile Storage FV\r
94 //\r
95 {\r
96 EFI_WINNT_RUNTIME_UPDATABLE_OFFSET,\r
97 EFI_WINNT_RUNTIME_UPDATABLE_LENGTH + EFI_WINNT_FTW_SPARE_BLOCK_LENGTH,\r
98 EFI_FLASH_AREA_FV | EFI_FLASH_AREA_MEMMAPPED_FV,\r
99 EFI_FLASH_AREA_GUID_DEFINED\r
100 },\r
101};\r
102\r
103\r
104EFI_STATUS\r
105EFIAPI\r
106PeimInitializeFlashMap (\r
107 IN EFI_FFS_FILE_HEADER *FfsHeader,\r
108 IN EFI_PEI_SERVICES **PeiServices\r
109 )\r
110/*++\r
111\r
112Routine Description:\r
113 Build GUIDed HOBs for platform specific flash map\r
114 \r
115Arguments:\r
116 FfsHeader - A pointer to the EFI_FFS_FILE_HEADER structure.\r
117 PeiServices - General purpose services available to every PEIM.\r
118 \r
119Returns:\r
120 EFI_STATUS\r
121\r
122--*/\r
123// TODO: EFI_SUCCESS - add return value to function comment\r
124{\r
125 EFI_STATUS Status;\r
126 NT_FWH_PPI *NtFwhPpi;\r
127 EFI_PEI_PPI_DESCRIPTOR *PpiDescriptor;\r
128 EFI_PHYSICAL_ADDRESS FdBase;\r
129 UINT64 FdSize;\r
130 UINTN NumOfHobData;\r
131 UINTN Index;\r
132 EFI_FLASH_AREA_HOB_DATA FlashHobData;\r
133\r
134 DEBUG ((EFI_D_ERROR, "NT 32 Flash Map PEIM Loaded\n"));\r
135\r
136 //\r
137 // Install FlashMap PPI\r
138 //\r
84a99d48 139 Status = PeiServicesInstallPpi (&mPpiListFlashMap);\r
878ddf1f 140 ASSERT_EFI_ERROR (Status);\r
141\r
142\r
143 //\r
144 // Get the Fwh Information PPI\r
145 //\r
84a99d48 146 Status = PeiServicesLocatePpi (\r
878ddf1f 147 &gNtFwhPpiGuid, // GUID\r
148 0, // INSTANCE\r
149 &PpiDescriptor, // EFI_PEI_PPI_DESCRIPTOR\r
150 &NtFwhPpi // PPI\r
151 );\r
152 ASSERT_EFI_ERROR (Status);\r
153\r
154 //\r
155 // Assume that FD0 contains the Flash map.\r
156 //\r
157 Status = NtFwhPpi->NtFwh (0, &FdBase, &FdSize);\r
158 if (EFI_ERROR (Status)) {\r
159 return Status;\r
160 }\r
161\r
162 //\r
163 // Get number of types\r
164 //\r
165 NumOfHobData = sizeof (mFlashAreaData) / sizeof (EFI_FLASH_AREA_DATA);\r
166\r
167 //\r
168 // Build flash area entries as GUIDed HOBs.\r
169 //\r
170 for (Index = 0; Index < NumOfHobData; Index++) {\r
171 (*PeiServices)->SetMem (&FlashHobData, sizeof (EFI_FLASH_AREA_HOB_DATA), 0);\r
172\r
173 FlashHobData.AreaType = mFlashAreaData[Index].AreaType;\r
174 FlashHobData.NumberOfEntries = 1;\r
175 FlashHobData.SubAreaData.Attributes = mFlashAreaData[Index].Attributes;\r
176 FlashHobData.SubAreaData.Base = FdBase + (EFI_PHYSICAL_ADDRESS) (UINTN) mFlashAreaData[Index].Base;\r
177 FlashHobData.SubAreaData.Length = (EFI_PHYSICAL_ADDRESS) (UINTN) mFlashAreaData[Index].Length;\r
178\r
202c5d55 179 //\r
180 // We also update a PCD entry so that any driver that depend on\r
181 // PCD entry will get the information.\r
182 //\r
183 if (FlashHobData.AreaType == EFI_FLASH_AREA_EFI_VARIABLES) {\r
184 PcdSet32 (PcdFlashNvStorageVariableBase, (UINT32) FlashHobData.SubAreaData.Base);\r
185 PcdSet32 (PcdFlashNvStorageVariableSize, (UINT32) FlashHobData.SubAreaData.Length);\r
186 }\r
187\r
188 if (FlashHobData.AreaType == EFI_FLASH_AREA_FTW_STATE) {\r
189 PcdSet32 (PcdFlashNvStorageFtwWorkingBase, (UINT32) FlashHobData.SubAreaData.Base);\r
190 PcdSet32 (PcdFlashNvStorageFtwWorkingSize, (UINT32) FlashHobData.SubAreaData.Length);\r
191 }\r
192\r
193 if (FlashHobData.AreaType == EFI_FLASH_AREA_FTW_BACKUP) {\r
194 PcdSet32 (PcdFlashNvStorageFtwSpareBase, (UINT32) FlashHobData.SubAreaData.Base);\r
195 PcdSet32 (PcdFlashNvStorageFtwSpareSize, (UINT32) FlashHobData.SubAreaData.Length);\r
196 }\r
197\r
878ddf1f 198 switch (FlashHobData.AreaType) {\r
199 case EFI_FLASH_AREA_RECOVERY_BIOS:\r
200 case EFI_FLASH_AREA_MAIN_BIOS:\r
201 (*PeiServices)->CopyMem (\r
202 &FlashHobData.AreaTypeGuid,\r
203 &gEfiFirmwareFileSystemGuid,\r
204 sizeof (EFI_GUID)\r
205 );\r
206 (*PeiServices)->CopyMem (\r
207 &FlashHobData.SubAreaData.FileSystem,\r
208 &gEfiFirmwareVolumeBlockProtocolGuid,\r
209 sizeof (EFI_GUID)\r
210 );\r
211 break;\r
212\r
213 case EFI_FLASH_AREA_GUID_DEFINED:\r
214 (*PeiServices)->CopyMem (\r
215 &FlashHobData.AreaTypeGuid,\r
216 &gEfiSystemNvDataHobGuid,\r
217 sizeof (EFI_GUID)\r
218 );\r
219 (*PeiServices)->CopyMem (\r
220 &FlashHobData.SubAreaData.FileSystem,\r
221 &gEfiFirmwareVolumeBlockProtocolGuid,\r
222 sizeof (EFI_GUID)\r
223 );\r
224 break;\r
225\r
226 default:\r
227 break;\r
228 }\r
229\r
230 BuildGuidDataHob (\r
231 &gEfiFlashMapHobGuid,\r
232 &FlashHobData,\r
233 sizeof (EFI_FLASH_AREA_HOB_DATA)\r
234 );\r
235 }\r
236\r
237 return EFI_SUCCESS;\r
238}\r
239\r
240EFI_STATUS\r
241EFIAPI\r
242GetAreaInfo (\r
243 IN EFI_PEI_SERVICES **PeiServices,\r
244 IN PEI_FLASH_MAP_PPI *This,\r
245 IN EFI_FLASH_AREA_TYPE AreaType,\r
246 IN EFI_GUID *AreaTypeGuid,\r
247 OUT UINT32 *NumEntries,\r
248 OUT EFI_FLASH_SUBAREA_ENTRY **Entries\r
249 )\r
250/*++\r
251\r
252 Routine Description: \r
253 Implementation of Flash Map PPI\r
254 \r
255--*/\r
256// TODO: function comment is missing 'Arguments:'\r
257// TODO: function comment is missing 'Returns:'\r
258// TODO: PeiServices - add argument and description to function comment\r
259// TODO: This - add argument and description to function comment\r
260// TODO: AreaType - add argument and description to function comment\r
261// TODO: AreaTypeGuid - add argument and description to function comment\r
262// TODO: NumEntries - add argument and description to function comment\r
263// TODO: Entries - add argument and description to function comment\r
264// TODO: EFI_SUCCESS - add return value to function comment\r
265// TODO: EFI_NOT_FOUND - add return value to function comment\r
266{\r
267 EFI_STATUS Status;\r
268 EFI_PEI_HOB_POINTERS Hob;\r
269 EFI_HOB_FLASH_MAP_ENTRY_TYPE *FlashMapEntry;\r
270\r
84a99d48 271 Status = PeiServicesGetHobList (&Hob.Raw);\r
878ddf1f 272 while (!END_OF_HOB_LIST (Hob)) {\r
273 if (Hob.Header->HobType == EFI_HOB_TYPE_GUID_EXTENSION && CompareGuid (&Hob.Guid->Name, &gEfiFlashMapHobGuid)) {\r
274 FlashMapEntry = (EFI_HOB_FLASH_MAP_ENTRY_TYPE *) Hob.Raw;\r
275 if (AreaType == FlashMapEntry->AreaType) {\r
276 if (AreaType == EFI_FLASH_AREA_GUID_DEFINED) {\r
277 if (!CompareGuid (AreaTypeGuid, &FlashMapEntry->AreaTypeGuid)) {\r
278 continue;\r
279 }\r
280 }\r
281\r
282 *NumEntries = FlashMapEntry->NumEntries;\r
283 *Entries = FlashMapEntry->Entries;\r
284 return EFI_SUCCESS;\r
285 }\r
286 }\r
287\r
288 Hob.Raw = GET_NEXT_HOB (Hob);\r
289 }\r
290\r
291 return EFI_NOT_FOUND;\r
292}\r