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