SignedCapsulePkg/SystemFirmwareUpdate: Add SystemFirmwareUpdate.
[mirror_edk2.git] / SignedCapsulePkg / Universal / SystemFirmwareUpdate / SystemFirmwareUpdateDxe.c
CommitLineData
f6f91d38
JY
1/** @file\r
2 SetImage instance to update system firmware.\r
3\r
4 Caution: This module requires additional review when modified.\r
5 This module will have external input - capsule image.\r
6 This external input must be validated carefully to avoid security issue like\r
7 buffer overflow, integer overflow.\r
8\r
9 FmpSetImage() will receive untrusted input and do basic validation.\r
10\r
11 Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
12 This program and the accompanying materials\r
13 are licensed and made available under the terms and conditions of the BSD License\r
14 which accompanies this distribution. The full text of the license may be found at\r
15 http://opensource.org/licenses/bsd-license.php\r
16\r
17 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
18 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
19\r
20**/\r
21\r
22#include "SystemFirmwareDxe.h"\r
23\r
24//\r
25// SystemFmp driver private data\r
26//\r
27SYSTEM_FMP_PRIVATE_DATA *mSystemFmpPrivate = NULL;\r
28\r
29EFI_GUID mCurrentImageTypeId;\r
30\r
31BOOLEAN mNvRamUpdated = FALSE;\r
32\r
33/**\r
34 Parse Config data file to get the updated data array.\r
35\r
36 @param[in] DataBuffer Config raw file buffer.\r
37 @param[in] BufferSize Size of raw buffer.\r
38 @param[in, out] ConfigHeader Pointer to the config header.\r
39 @param[in, out] UpdateArray Pointer to the config of update data.\r
40\r
41 @retval EFI_NOT_FOUND No config data is found.\r
42 @retval EFI_OUT_OF_RESOURCES No enough memory is allocated.\r
43 @retval EFI_SUCCESS Parse the config file successfully.\r
44\r
45**/\r
46EFI_STATUS\r
47ParseUpdateDataFile (\r
48 IN UINT8 *DataBuffer,\r
49 IN UINTN BufferSize,\r
50 IN OUT CONFIG_HEADER *ConfigHeader,\r
51 IN OUT UPDATE_CONFIG_DATA **UpdateArray\r
52 );\r
53\r
54/**\r
55 Update System Firmware image component.\r
56\r
57 @param[in] SystemFirmwareImage Points to the System Firmware image.\r
58 @param[in] SystemFirmwareImageSize The length of the System Firmware image in bytes.\r
59 @param[in] ConfigData Points to the component configuration structure.\r
60 @param[out] LastAttemptVersion The last attempt version, which will be recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
61 @param[out] LastAttemptStatus The last attempt status, which will be recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
62\r
63 @retval EFI_SUCCESS The System Firmware image is updated.\r
64 @retval EFI_WRITE_PROTECTED The flash device is read only.\r
65**/\r
66EFI_STATUS\r
67PerformUpdate (\r
68 IN VOID *SystemFirmwareImage,\r
69 IN UINTN SystemFirmwareImageSize,\r
70 IN UPDATE_CONFIG_DATA *ConfigData,\r
71 OUT UINT32 *LastAttemptVersion,\r
72 OUT UINT32 *LastAttemptStatus\r
73 )\r
74{\r
75 EFI_STATUS Status;\r
76\r
77 DEBUG((DEBUG_INFO, "PlatformUpdate:"));\r
78 DEBUG((DEBUG_INFO, " BaseAddress - 0x%lx,", ConfigData->BaseAddress));\r
79 DEBUG((DEBUG_INFO, " ImageOffset - 0x%x,", ConfigData->ImageOffset));\r
80 DEBUG((DEBUG_INFO, " Legnth - 0x%x\n", ConfigData->Length));\r
81 Status = PerformFlashWrite (\r
82 ConfigData->FirmwareType,\r
83 ConfigData->BaseAddress,\r
84 ConfigData->AddressType,\r
85 (VOID *)((UINTN)SystemFirmwareImage + (UINTN)ConfigData->ImageOffset),\r
86 ConfigData->Length\r
87 );\r
88 if (!EFI_ERROR(Status)) {\r
89 *LastAttemptStatus = LAST_ATTEMPT_STATUS_SUCCESS;\r
90 if (ConfigData->FirmwareType == PlatformFirmwareTypeNvRam) {\r
91 mNvRamUpdated = TRUE;\r
92 }\r
93 } else {\r
94 *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL;\r
95 }\r
96 return Status;\r
97}\r
98\r
99/**\r
100 Update System Firmware image.\r
101\r
102 @param[in] SystemFirmwareImage Points to the System Firmware image.\r
103 @param[in] SystemFirmwareImageSize The length of the System Firmware image in bytes.\r
104 @param[in] ConfigImage Points to the config file image.\r
105 @param[in] ConfigImageSize The length of the config file image in bytes.\r
106 @param[out] LastAttemptVersion The last attempt version, which will be recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
107 @param[out] LastAttemptStatus The last attempt status, which will be recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
108\r
109 @retval EFI_SUCCESS The System Firmware image is updated.\r
110 @retval EFI_WRITE_PROTECTED The flash device is read only.\r
111**/\r
112EFI_STATUS\r
113UpdateImage (\r
114 IN VOID *SystemFirmwareImage,\r
115 IN UINTN SystemFirmwareImageSize,\r
116 IN VOID *ConfigImage,\r
117 IN UINTN ConfigImageSize,\r
118 OUT UINT32 *LastAttemptVersion,\r
119 OUT UINT32 *LastAttemptStatus\r
120 )\r
121{\r
122 EFI_STATUS Status;\r
123 UPDATE_CONFIG_DATA *ConfigData;\r
124 UPDATE_CONFIG_DATA *UpdateConfigData;\r
125 CONFIG_HEADER ConfigHeader;\r
126 UINTN Index;\r
127\r
128 if (ConfigImage == NULL) {\r
129 DEBUG((DEBUG_INFO, "PlatformUpdate (NoConfig):"));\r
130 DEBUG((DEBUG_INFO, " BaseAddress - 0x%x,", 0));\r
131 DEBUG((DEBUG_INFO, " Length - 0x%x\n", SystemFirmwareImageSize));\r
132 // ASSUME the whole System Firmware include NVRAM region.\r
133 Status = PerformFlashWrite (\r
134 PlatformFirmwareTypeNvRam,\r
135 0,\r
136 FlashAddressTypeRelativeAddress,\r
137 SystemFirmwareImage,\r
138 SystemFirmwareImageSize\r
139 );\r
140 if (!EFI_ERROR(Status)) {\r
141 *LastAttemptStatus = LAST_ATTEMPT_STATUS_SUCCESS;\r
142 mNvRamUpdated = TRUE;\r
143 } else {\r
144 *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL;\r
145 }\r
146 return Status;\r
147 }\r
148\r
149 DEBUG((DEBUG_INFO, "PlatformUpdate (With Config):\n"));\r
150 ConfigData = NULL;\r
151 ZeroMem (&ConfigHeader, sizeof(ConfigHeader));\r
152 Status = ParseUpdateDataFile (\r
153 ConfigImage,\r
154 ConfigImageSize,\r
155 &ConfigHeader,\r
156 &ConfigData\r
157 );\r
158 DEBUG((DEBUG_INFO, "ParseUpdateDataFile - %r\n", Status));\r
159 if (EFI_ERROR(Status)) {\r
160 *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL;\r
161 return EFI_INVALID_PARAMETER;\r
162 }\r
163 DEBUG((DEBUG_INFO, "ConfigHeader.NumOfUpdates - 0x%x\n", ConfigHeader.NumOfUpdates));\r
164 DEBUG((DEBUG_INFO, "PcdEdkiiSystemFirmwareFileGuid - %g\n", PcdGetPtr(PcdEdkiiSystemFirmwareFileGuid)));\r
165\r
166 Index = 0;\r
167 UpdateConfigData = ConfigData;\r
168 while (Index < ConfigHeader.NumOfUpdates) {\r
169 if (CompareGuid(&UpdateConfigData->FileGuid, PcdGetPtr(PcdEdkiiSystemFirmwareFileGuid))) {\r
170 DEBUG((DEBUG_INFO, "FileGuid - %g (processing)\n", &UpdateConfigData->FileGuid));\r
171 Status = PerformUpdate (\r
172 SystemFirmwareImage,\r
173 SystemFirmwareImageSize,\r
174 UpdateConfigData,\r
175 LastAttemptVersion,\r
176 LastAttemptStatus\r
177 );\r
178 //\r
179 // Shall updates be serialized so that if an update is not successfully completed,\r
180 // the remaining updates won't be performed.\r
181 //\r
182 if (EFI_ERROR (Status)) {\r
183 break;\r
184 }\r
185 } else {\r
186 DEBUG((DEBUG_INFO, "FileGuid - %g (ignored)\n", &UpdateConfigData->FileGuid));\r
187 }\r
188\r
189 Index++;\r
190 UpdateConfigData++;\r
191 }\r
192\r
193 return Status;\r
194}\r
195\r
196/**\r
197 Authenticate and update System Firmware image.\r
198\r
199 Caution: This function may receive untrusted input.\r
200\r
201 @param[in] Image The EDKII system FMP capsule image.\r
202 @param[in] ImageSize The size of the EDKII system FMP capsule image in bytes.\r
203 @param[out] LastAttemptVersion The last attempt version, which will be recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
204 @param[out] LastAttemptStatus The last attempt status, which will be recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
205\r
206 @retval EFI_SUCCESS EDKII system FMP capsule passes authentication and the System Firmware image is updated.\r
207 @retval EFI_SECURITY_VIOLATION EDKII system FMP capsule fails authentication and the System Firmware image is not updated.\r
208 @retval EFI_WRITE_PROTECTED The flash device is read only.\r
209**/\r
210EFI_STATUS\r
211SystemFirmwareAuthenticatedUpdate (\r
212 IN VOID *Image,\r
213 IN UINTN ImageSize,\r
214 OUT UINT32 *LastAttemptVersion,\r
215 OUT UINT32 *LastAttemptStatus\r
216 )\r
217{\r
218 EFI_STATUS Status;\r
219 VOID *SystemFirmwareImage;\r
220 UINTN SystemFirmwareImageSize;\r
221 VOID *ConfigImage;\r
222 UINTN ConfigImageSize;\r
223 VOID *AuthenticatedImage;\r
224 UINTN AuthenticatedImageSize;\r
225\r
226 DEBUG((DEBUG_INFO, "SystemFirmwareAuthenticatedUpdate...\n"));\r
227\r
228 Status = CapsuleAuthenticateSystemFirmware(Image, ImageSize, FALSE, LastAttemptVersion, LastAttemptStatus, &AuthenticatedImage, &AuthenticatedImageSize);\r
229 if (EFI_ERROR(Status)) {\r
230 DEBUG((DEBUG_INFO, "SystemFirmwareAuthenticateImage - %r\n", Status));\r
231 return Status;\r
232 }\r
233\r
234 DEBUG((DEBUG_INFO, "ExtractSystemFirmwareImage ...\n"));\r
235 ExtractSystemFirmwareImage(AuthenticatedImage, AuthenticatedImageSize, &SystemFirmwareImage, &SystemFirmwareImageSize);\r
236 DEBUG((DEBUG_INFO, "ExtractConfigImage ...\n"));\r
237 ExtractConfigImage(AuthenticatedImage, AuthenticatedImageSize, &ConfigImage, &ConfigImageSize);\r
238\r
239 DEBUG((DEBUG_INFO, "UpdateImage ...\n"));\r
240 Status = UpdateImage(SystemFirmwareImage, SystemFirmwareImageSize, ConfigImage, ConfigImageSize, LastAttemptVersion, LastAttemptStatus);\r
241 if (EFI_ERROR(Status)) {\r
242 DEBUG((DEBUG_INFO, "UpdateImage - %r\n", Status));\r
243 return Status;\r
244 }\r
245\r
246 DEBUG((DEBUG_INFO, "SystemFirmwareAuthenticatedUpdate Done\n"));\r
247\r
248 return EFI_SUCCESS;\r
249}\r
250\r
251/**\r
252\r
253 This code finds variable in storage blocks (Volatile or Non-Volatile).\r
254\r
255 @param[in] VariableName Name of Variable to be found.\r
256 @param[in] VendorGuid Variable vendor GUID.\r
257 @param[out] Attributes Attribute value of the variable found.\r
258 @param[in, out] DataSize Size of Data found. If size is less than the\r
259 data, this value contains the required size.\r
260 @param[out] Data Data pointer.\r
261\r
262 @return EFI_INVALID_PARAMETER Invalid parameter.\r
263 @return EFI_SUCCESS Find the specified variable.\r
264 @return EFI_NOT_FOUND Not found.\r
265 @return EFI_BUFFER_TO_SMALL DataSize is too small for the result.\r
266\r
267**/\r
268EFI_STATUS\r
269EFIAPI\r
270GetVariableHook (\r
271 IN CHAR16 *VariableName,\r
272 IN EFI_GUID *VendorGuid,\r
273 OUT UINT32 *Attributes OPTIONAL,\r
274 IN OUT UINTN *DataSize,\r
275 OUT VOID *Data\r
276 )\r
277{\r
278 DEBUG((DEBUG_INFO, "GetVariableHook - %S, %g\n", VariableName, VendorGuid));\r
279 return EFI_NOT_AVAILABLE_YET;\r
280}\r
281\r
282/**\r
283\r
284 This code Finds the Next available variable.\r
285\r
286 @param[in, out] VariableNameSize Size of the variable name.\r
287 @param[in, out] VariableName Pointer to variable name.\r
288 @param[in, out] VendorGuid Variable Vendor Guid.\r
289\r
290 @return EFI_INVALID_PARAMETER Invalid parameter.\r
291 @return EFI_SUCCESS Find the specified variable.\r
292 @return EFI_NOT_FOUND Not found.\r
293 @return EFI_BUFFER_TO_SMALL DataSize is too small for the result.\r
294\r
295**/\r
296EFI_STATUS\r
297EFIAPI\r
298GetNextVariableNameHook (\r
299 IN OUT UINTN *VariableNameSize,\r
300 IN OUT CHAR16 *VariableName,\r
301 IN OUT EFI_GUID *VendorGuid\r
302 )\r
303{\r
304 DEBUG((DEBUG_INFO, "GetNextVariableNameHook - %S, %g\n", VariableName, VendorGuid));\r
305 return EFI_NOT_AVAILABLE_YET;\r
306}\r
307\r
308/**\r
309\r
310 This code sets variable in storage blocks (Volatile or Non-Volatile).\r
311\r
312 @param[in] VariableName Name of Variable to be found.\r
313 @param[in] VendorGuid Variable vendor GUID.\r
314 @param[in] Attributes Attribute value of the variable found\r
315 @param[in] DataSize Size of Data found. If size is less than the\r
316 data, this value contains the required size.\r
317 @param[in] Data Data pointer.\r
318\r
319 @return EFI_INVALID_PARAMETER Invalid parameter.\r
320 @return EFI_SUCCESS Set successfully.\r
321 @return EFI_OUT_OF_RESOURCES Resource not enough to set variable.\r
322 @return EFI_NOT_FOUND Not found.\r
323 @return EFI_WRITE_PROTECTED Variable is read-only.\r
324\r
325**/\r
326EFI_STATUS\r
327EFIAPI\r
328SetVariableHook (\r
329 IN CHAR16 *VariableName,\r
330 IN EFI_GUID *VendorGuid,\r
331 IN UINT32 Attributes,\r
332 IN UINTN DataSize,\r
333 IN VOID *Data\r
334 )\r
335{\r
336 DEBUG((DEBUG_INFO, "SetVariableHook - %S, %g, 0x%x (0x%x)\n", VariableName, VendorGuid, Attributes, DataSize));\r
337 return EFI_NOT_AVAILABLE_YET;\r
338}\r
339\r
340/**\r
341\r
342 This code returns information about the EFI variables.\r
343\r
344 @param[in] Attributes Attributes bitmask to specify the type of variables\r
345 on which to return information.\r
346 @param[out] MaximumVariableStorageSize Pointer to the maximum size of the storage space available\r
347 for the EFI variables associated with the attributes specified.\r
348 @param[out] RemainingVariableStorageSize Pointer to the remaining size of the storage space available\r
349 for EFI variables associated with the attributes specified.\r
350 @param[out] MaximumVariableSize Pointer to the maximum size of an individual EFI variables\r
351 associated with the attributes specified.\r
352\r
353 @return EFI_SUCCESS Query successfully.\r
354\r
355**/\r
356EFI_STATUS\r
357EFIAPI\r
358QueryVariableInfoHook (\r
359 IN UINT32 Attributes,\r
360 OUT UINT64 *MaximumVariableStorageSize,\r
361 OUT UINT64 *RemainingVariableStorageSize,\r
362 OUT UINT64 *MaximumVariableSize\r
363 )\r
364{\r
365 DEBUG((DEBUG_INFO, "QueryVariableInfoHook - 0x%x\n", Attributes));\r
366 return EFI_NOT_AVAILABLE_YET;\r
367}\r
368\r
369/**\r
370 Updates the firmware image of the device.\r
371\r
372 This function updates the hardware with the new firmware image.\r
373 This function returns EFI_UNSUPPORTED if the firmware image is not updatable.\r
374 If the firmware image is updatable, the function should perform the following minimal validations\r
375 before proceeding to do the firmware image update.\r
376 - Validate the image authentication if image has attribute\r
377 IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED. The function returns\r
378 EFI_SECURITY_VIOLATION if the validation fails.\r
379 - Validate the image is a supported image for this device. The function returns EFI_ABORTED if\r
380 the image is unsupported. The function can optionally provide more detailed information on\r
381 why the image is not a supported image.\r
382 - Validate the data from VendorCode if not null. Image validation must be performed before\r
383 VendorCode data validation. VendorCode data is ignored or considered invalid if image\r
384 validation failed. The function returns EFI_ABORTED if the data is invalid.\r
385\r
386 VendorCode enables vendor to implement vendor-specific firmware image update policy. Null if\r
387 the caller did not specify the policy or use the default policy. As an example, vendor can implement\r
388 a policy to allow an option to force a firmware image update when the abort reason is due to the new\r
389 firmware image version is older than the current firmware image version or bad image checksum.\r
390 Sensitive operations such as those wiping the entire firmware image and render the device to be\r
391 non-functional should be encoded in the image itself rather than passed with the VendorCode.\r
392 AbortReason enables vendor to have the option to provide a more detailed description of the abort\r
393 reason to the caller.\r
394\r
395 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
396 @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.\r
397 The number is between 1 and DescriptorCount.\r
398 @param[in] Image Points to the new image.\r
399 @param[in] ImageSize Size of the new image in bytes.\r
400 @param[in] VendorCode This enables vendor to implement vendor-specific firmware image update policy.\r
401 Null indicates the caller did not specify the policy or use the default policy.\r
402 @param[in] Progress A function used by the driver to report the progress of the firmware update.\r
403 @param[out] AbortReason A pointer to a pointer to a null-terminated string providing more\r
404 details for the aborted operation. The buffer is allocated by this function\r
405 with AllocatePool(), and it is the caller's responsibility to free it with a\r
406 call to FreePool().\r
407\r
408 @retval EFI_SUCCESS The device was successfully updated with the new image.\r
409 @retval EFI_ABORTED The operation is aborted.\r
410 @retval EFI_INVALID_PARAMETER The Image was NULL.\r
411 @retval EFI_UNSUPPORTED The operation is not supported.\r
412 @retval EFI_SECURITY_VIOLATIO The operation could not be performed due to an authentication failure.\r
413\r
414**/\r
415EFI_STATUS\r
416EFIAPI\r
417FmpSetImage (\r
418 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r
419 IN UINT8 ImageIndex,\r
420 IN CONST VOID *Image,\r
421 IN UINTN ImageSize,\r
422 IN CONST VOID *VendorCode,\r
423 IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS Progress,\r
424 OUT CHAR16 **AbortReason\r
425 )\r
426{\r
427 EFI_STATUS Status;\r
428 EFI_STATUS VarStatus;\r
429 SYSTEM_FMP_PRIVATE_DATA *SystemFmpPrivate;\r
430\r
431 if (Image == NULL || ImageSize == 0 || AbortReason == NULL) {\r
432 return EFI_INVALID_PARAMETER;\r
433 }\r
434\r
435 SystemFmpPrivate = SYSTEM_FMP_PRIVATE_DATA_FROM_FMP(This);\r
436 *AbortReason = NULL;\r
437\r
438 if (ImageIndex == 0 || ImageIndex > SystemFmpPrivate->DescriptorCount) {\r
439 return EFI_INVALID_PARAMETER;\r
440 }\r
441\r
442 Status = SystemFirmwareAuthenticatedUpdate((VOID *)Image, ImageSize, &SystemFmpPrivate->LastAttempt.LastAttemptVersion, &SystemFmpPrivate->LastAttempt.LastAttemptStatus);\r
443 DEBUG((DEBUG_INFO, "SetImage - LastAttemp Version - 0x%x, State - 0x%x\n", SystemFmpPrivate->LastAttempt.LastAttemptVersion, SystemFmpPrivate->LastAttempt.LastAttemptStatus));\r
444\r
445 //\r
446 // If NVRAM is updated, we should no longer touch variable services, because\r
447 // the current variable driver may not manage the new NVRAM region.\r
448 //\r
449 if (mNvRamUpdated) {\r
450 DEBUG ((DEBUG_INFO, "NvRamUpdated, Update Variable Serivces\n"));\r
451 gRT->GetVariable = GetVariableHook;\r
452 gRT->GetNextVariableName = GetNextVariableNameHook;\r
453 gRT->SetVariable = SetVariableHook;\r
454 gRT->QueryVariableInfo = QueryVariableInfoHook;\r
455\r
456 gRT->Hdr.CRC32 = 0;\r
457 gBS->CalculateCrc32 (\r
458 (UINT8 *) &gRT->Hdr,\r
459 gRT->Hdr.HeaderSize,\r
460 &gRT->Hdr.CRC32\r
461 );\r
462 }\r
463\r
464 VarStatus = gRT->SetVariable(\r
465 SYSTEM_FMP_LAST_ATTEMPT_VARIABLE_NAME,\r
466 &gSystemFmpLastAttemptVariableGuid,\r
467 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
468 sizeof(SystemFmpPrivate->LastAttempt),\r
469 &SystemFmpPrivate->LastAttempt\r
470 );\r
471 DEBUG((DEBUG_INFO, "SetLastAttemp - %r\n", VarStatus));\r
472\r
473 return Status;\r
474}\r
475\r
476/**\r
477 System FMP module entrypoint\r
478\r
479 @param ImageHandle The firmware allocated handle for the EFI image.\r
480 @param SystemTable A pointer to the EFI System Table.\r
481\r
482 @return EFI_SUCCESS System FMP module is initialized.\r
483**/\r
484EFI_STATUS\r
485EFIAPI\r
486SystemFirmwareUpdateMainDxe (\r
487 IN EFI_HANDLE ImageHandle,\r
488 IN EFI_SYSTEM_TABLE *SystemTable\r
489 )\r
490{\r
491 EFI_STATUS Status;\r
492\r
493 //\r
494 // Initialize SystemFmpPrivateData\r
495 //\r
496 mSystemFmpPrivate = AllocateZeroPool (sizeof(SYSTEM_FMP_PRIVATE_DATA));\r
497 if (mSystemFmpPrivate == NULL) {\r
498 return EFI_OUT_OF_RESOURCES;\r
499 }\r
500\r
501 Status = InitializePrivateData(mSystemFmpPrivate);\r
502 if (EFI_ERROR(Status)) {\r
503 FreePool(mSystemFmpPrivate);\r
504 mSystemFmpPrivate = NULL;\r
505 return Status;\r
506 }\r
507\r
508 //\r
509 // Install FMP protocol.\r
510 //\r
511 Status = gBS->InstallMultipleProtocolInterfaces (\r
512 &mSystemFmpPrivate->Handle,\r
513 &gEfiFirmwareManagementProtocolGuid,\r
514 &mSystemFmpPrivate->Fmp,\r
515 &gSystemFmpProtocolGuid,\r
516 &mSystemFmpPrivate->Fmp,\r
517 NULL\r
518 );\r
519 if (EFI_ERROR (Status)) {\r
520 FreePool(mSystemFmpPrivate);\r
521 mSystemFmpPrivate = NULL;\r
522 return Status;\r
523 }\r
524\r
525 return Status;\r
526}\r