]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Library/PlatformVarCleanupLib/PlatVarCleanupLib.c
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Library / PlatformVarCleanupLib / PlatVarCleanupLib.c
1 /** @file
2 Sample platform variable cleanup library implementation.
3
4 Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include "PlatVarCleanup.h"
10
11 VAR_ERROR_FLAG mLastVarErrorFlag = VAR_ERROR_FLAG_NO_ERROR;
12 EDKII_VAR_CHECK_PROTOCOL *mVarCheck = NULL;
13
14 ///
15 /// The flag to indicate whether the platform has left the DXE phase of execution.
16 ///
17 BOOLEAN mEndOfDxe = FALSE;
18
19 EFI_EVENT mPlatVarCleanupLibEndOfDxeEvent = NULL;
20
21 LIST_ENTRY mUserVariableList = INITIALIZE_LIST_HEAD_VARIABLE (mUserVariableList);
22 UINT16 mUserVariableCount = 0;
23 UINT16 mMarkedUserVariableCount = 0;
24
25 EFI_GUID mVariableCleanupHiiGuid = VARIABLE_CLEANUP_HII_GUID;
26 CHAR16 mVarStoreName[] = L"VariableCleanup";
27
28 HII_VENDOR_DEVICE_PATH mVarCleanupHiiVendorDevicePath = {
29 {
30 {
31 HARDWARE_DEVICE_PATH,
32 HW_VENDOR_DP,
33 {
34 (UINT8) (sizeof (VENDOR_DEVICE_PATH)),
35 (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)
36 }
37 },
38 VARIABLE_CLEANUP_HII_GUID
39 },
40 {
41 END_DEVICE_PATH_TYPE,
42 END_ENTIRE_DEVICE_PATH_SUBTYPE,
43 {
44 (UINT8) (sizeof (EFI_DEVICE_PATH_PROTOCOL)),
45 (UINT8) ((sizeof (EFI_DEVICE_PATH_PROTOCOL)) >> 8)
46 }
47 }
48 };
49
50 /**
51 Internal get variable error flag.
52
53 @return Variable error flag.
54
55 **/
56 VAR_ERROR_FLAG
57 InternalGetVarErrorFlag (
58 VOID
59 )
60 {
61 EFI_STATUS Status;
62 UINTN Size;
63 VAR_ERROR_FLAG ErrorFlag;
64
65 Size = sizeof (ErrorFlag);
66 Status = gRT->GetVariable (
67 VAR_ERROR_FLAG_NAME,
68 &gEdkiiVarErrorFlagGuid,
69 NULL,
70 &Size,
71 &ErrorFlag
72 );
73 if (EFI_ERROR (Status)) {
74 DEBUG ((EFI_D_INFO, "%s - not found\n", VAR_ERROR_FLAG_NAME));
75 return VAR_ERROR_FLAG_NO_ERROR;
76 }
77 return ErrorFlag;
78 }
79
80 /**
81 Is user variable?
82
83 @param[in] Name Pointer to variable name.
84 @param[in] Guid Pointer to vendor guid.
85
86 @retval TRUE User variable.
87 @retval FALSE System variable.
88
89 **/
90 BOOLEAN
91 IsUserVariable (
92 IN CHAR16 *Name,
93 IN EFI_GUID *Guid
94 )
95 {
96 EFI_STATUS Status;
97 VAR_CHECK_VARIABLE_PROPERTY Property;
98
99 if (mVarCheck == NULL) {
100 gBS->LocateProtocol (
101 &gEdkiiVarCheckProtocolGuid,
102 NULL,
103 (VOID **) &mVarCheck
104 );
105 }
106 ASSERT (mVarCheck != NULL);
107
108 ZeroMem (&Property, sizeof (Property));
109 Status = mVarCheck->VariablePropertyGet (
110 Name,
111 Guid,
112 &Property
113 );
114 if (EFI_ERROR (Status)) {
115 //
116 // No property, it is user variable.
117 //
118 DEBUG ((EFI_D_INFO, "PlatformVarCleanup - User variable: %g:%s\n", Guid, Name));
119 return TRUE;
120 }
121
122 // DEBUG ((EFI_D_INFO, "PlatformVarCleanup - Variable Property: %g:%s\n", Guid, Name));
123 // DEBUG ((EFI_D_INFO, " Revision - 0x%04x\n", Property.Revision));
124 // DEBUG ((EFI_D_INFO, " Property - 0x%04x\n", Property.Property));
125 // DEBUG ((EFI_D_INFO, " Attribute - 0x%08x\n", Property.Attributes));
126 // DEBUG ((EFI_D_INFO, " MinSize - 0x%x\n", Property.MinSize));
127 // DEBUG ((EFI_D_INFO, " MaxSize - 0x%x\n", Property.MaxSize));
128
129 return FALSE;
130 }
131
132 /**
133 Find user variable node by variable GUID.
134
135 @param[in] Guid Pointer to vendor guid.
136
137 @return Pointer to user variable node.
138
139 **/
140 USER_VARIABLE_NODE *
141 FindUserVariableNodeByGuid (
142 IN EFI_GUID *Guid
143 )
144 {
145 USER_VARIABLE_NODE *UserVariableNode;
146 LIST_ENTRY *Link;
147
148 for (Link = mUserVariableList.ForwardLink
149 ;Link != &mUserVariableList
150 ;Link = Link->ForwardLink) {
151 UserVariableNode = USER_VARIABLE_FROM_LINK (Link);
152
153 if (CompareGuid (Guid, &UserVariableNode->Guid)) {
154 //
155 // Found it.
156 //
157 return UserVariableNode;
158 }
159 }
160
161 //
162 // Create new one if not found.
163 //
164 UserVariableNode = AllocateZeroPool (sizeof (*UserVariableNode));
165 ASSERT (UserVariableNode != NULL);
166 UserVariableNode->Signature = USER_VARIABLE_NODE_SIGNATURE;
167 CopyGuid (&UserVariableNode->Guid, Guid);
168 //
169 // (36 chars of "########-####-####-####-############" + 1 space + 1 terminator) * sizeof (CHAR16).
170 //
171 UserVariableNode->PromptString = AllocatePool ((36 + 2) * sizeof (CHAR16));
172 ASSERT (UserVariableNode->PromptString != NULL);
173 UnicodeSPrint (UserVariableNode->PromptString, (36 + 2) * sizeof (CHAR16), L" %g", &UserVariableNode->Guid);
174 InitializeListHead (&UserVariableNode->NameLink);
175 InsertTailList (&mUserVariableList, &UserVariableNode->Link);
176 return UserVariableNode;
177 }
178
179 /**
180 Create user variable node.
181
182 **/
183 VOID
184 CreateUserVariableNode (
185 VOID
186 )
187 {
188 EFI_STATUS Status;
189 EFI_STATUS GetVariableStatus;
190 CHAR16 *VarName;
191 UINTN MaxVarNameSize;
192 UINTN VarNameSize;
193 UINTN MaxDataSize;
194 UINTN DataSize;
195 VOID *Data;
196 UINT32 Attributes;
197 EFI_GUID Guid;
198 USER_VARIABLE_NODE *UserVariableNode;
199 USER_VARIABLE_NAME_NODE *UserVariableNameNode;
200 UINT16 Index;
201 UINTN StringSize;
202
203 //
204 // Initialize 128 * sizeof (CHAR16) variable name size.
205 //
206 MaxVarNameSize = 128 * sizeof (CHAR16);
207 VarName = AllocateZeroPool (MaxVarNameSize);
208 ASSERT (VarName != NULL);
209
210 //
211 // Initialize 0x1000 variable data size.
212 //
213 MaxDataSize = 0x1000;
214 Data = AllocateZeroPool (MaxDataSize);
215 ASSERT (Data != NULL);
216
217 Index = 0;
218 do {
219 VarNameSize = MaxVarNameSize;
220 Status = gRT->GetNextVariableName (&VarNameSize, VarName, &Guid);
221 if (Status == EFI_BUFFER_TOO_SMALL) {
222 VarName = ReallocatePool (MaxVarNameSize, VarNameSize, VarName);
223 ASSERT (VarName != NULL);
224 MaxVarNameSize = VarNameSize;
225 Status = gRT->GetNextVariableName (&VarNameSize, VarName, &Guid);
226 }
227
228 if (!EFI_ERROR (Status)) {
229 if (IsUserVariable (VarName, &Guid)) {
230 DataSize = MaxDataSize;
231 GetVariableStatus = gRT->GetVariable (VarName, &Guid, &Attributes, &DataSize, Data);
232 if (GetVariableStatus == EFI_BUFFER_TOO_SMALL) {
233 Data = ReallocatePool (MaxDataSize, DataSize, Data);
234 ASSERT (Data != NULL);
235 MaxDataSize = DataSize;
236 GetVariableStatus = gRT->GetVariable (VarName, &Guid, &Attributes, &DataSize, Data);
237 }
238 ASSERT_EFI_ERROR (GetVariableStatus);
239
240 if ((Attributes & EFI_VARIABLE_NON_VOLATILE) != 0) {
241 UserVariableNode = FindUserVariableNodeByGuid (&Guid);
242 ASSERT (UserVariableNode != NULL);
243
244 //
245 // Different variables that have same variable GUID share same user variable node.
246 //
247 UserVariableNameNode = AllocateZeroPool (sizeof (*UserVariableNameNode));
248 ASSERT (UserVariableNameNode != NULL);
249 UserVariableNameNode->Signature = USER_VARIABLE_NAME_NODE_SIGNATURE;
250 UserVariableNameNode->Name = AllocateCopyPool (VarNameSize, VarName);
251 UserVariableNameNode->Attributes = Attributes;
252 UserVariableNameNode->DataSize = DataSize;
253 UserVariableNameNode->Index = Index;
254 UserVariableNameNode->QuestionId = (EFI_QUESTION_ID) (USER_VARIABLE_QUESTION_ID + Index);
255 //
256 // 2 space * sizeof (CHAR16) + StrSize.
257 //
258 StringSize = 2 * sizeof (CHAR16) + StrSize (UserVariableNameNode->Name);
259 UserVariableNameNode->PromptString = AllocatePool (StringSize);
260 ASSERT (UserVariableNameNode->PromptString != NULL);
261 UnicodeSPrint (UserVariableNameNode->PromptString, StringSize, L" %s", UserVariableNameNode->Name);
262 //
263 // (33 chars of "Attribtues = 0x and DataSize = 0x" + 1 terminator + (sizeof (UINT32) + sizeof (UINTN)) * 2) * sizeof (CHAR16).
264 //
265 StringSize = (33 + 1 + (sizeof (UINT32) + sizeof (UINTN)) * 2) * sizeof (CHAR16);
266 UserVariableNameNode->HelpString = AllocatePool (StringSize);
267 ASSERT (UserVariableNameNode->HelpString != NULL);
268 UnicodeSPrint (UserVariableNameNode->HelpString, StringSize, L"Attribtues = 0x%08x and DataSize = 0x%x", UserVariableNameNode->Attributes, UserVariableNameNode->DataSize);
269 UserVariableNameNode->Deleted = FALSE;
270 InsertTailList (&UserVariableNode->NameLink, &UserVariableNameNode->Link);
271 Index++;
272 }
273 }
274 }
275 } while (Status != EFI_NOT_FOUND);
276
277 mUserVariableCount = Index;
278 ASSERT (mUserVariableCount <= MAX_USER_VARIABLE_COUNT);
279 DEBUG ((EFI_D_INFO, "PlatformVarCleanup - User variable count: 0x%04x\n", mUserVariableCount));
280
281 FreePool (VarName);
282 FreePool (Data);
283 }
284
285 /**
286 Destroy user variable nodes.
287
288 **/
289 VOID
290 DestroyUserVariableNode (
291 VOID
292 )
293 {
294 USER_VARIABLE_NODE *UserVariableNode;
295 LIST_ENTRY *Link;
296 USER_VARIABLE_NAME_NODE *UserVariableNameNode;
297 LIST_ENTRY *NameLink;
298
299 while (mUserVariableList.ForwardLink != &mUserVariableList) {
300 Link = mUserVariableList.ForwardLink;
301 UserVariableNode = USER_VARIABLE_FROM_LINK (Link);
302
303 RemoveEntryList (&UserVariableNode->Link);
304
305 while (UserVariableNode->NameLink.ForwardLink != &UserVariableNode->NameLink) {
306 NameLink = UserVariableNode->NameLink.ForwardLink;
307 UserVariableNameNode = USER_VARIABLE_NAME_FROM_LINK (NameLink);
308
309 RemoveEntryList (&UserVariableNameNode->Link);
310
311 FreePool (UserVariableNameNode->Name);
312 FreePool (UserVariableNameNode->PromptString);
313 FreePool (UserVariableNameNode->HelpString);
314 FreePool (UserVariableNameNode);
315 }
316
317 FreePool (UserVariableNode->PromptString);
318 FreePool (UserVariableNode);
319 }
320 }
321
322 /**
323 Create a time based data payload by concatenating the EFI_VARIABLE_AUTHENTICATION_2
324 descriptor with the input data. NO authentication is required in this function.
325
326 @param[in, out] DataSize On input, the size of Data buffer in bytes.
327 On output, the size of data returned in Data
328 buffer in bytes.
329 @param[in, out] Data On input, Pointer to data buffer to be wrapped or
330 pointer to NULL to wrap an empty payload.
331 On output, Pointer to the new payload date buffer allocated from pool,
332 it's caller's responsibility to free the memory after using it.
333
334 @retval EFI_SUCCESS Create time based payload successfully.
335 @retval EFI_OUT_OF_RESOURCES There are not enough memory resourses to create time based payload.
336 @retval EFI_INVALID_PARAMETER The parameter is invalid.
337 @retval Others Unexpected error happens.
338
339 **/
340 EFI_STATUS
341 CreateTimeBasedPayload (
342 IN OUT UINTN *DataSize,
343 IN OUT UINT8 **Data
344 )
345 {
346 EFI_STATUS Status;
347 UINT8 *NewData;
348 UINT8 *Payload;
349 UINTN PayloadSize;
350 EFI_VARIABLE_AUTHENTICATION_2 *DescriptorData;
351 UINTN DescriptorSize;
352 EFI_TIME Time;
353
354 if (Data == NULL || DataSize == NULL) {
355 return EFI_INVALID_PARAMETER;
356 }
357
358 //
359 // At user physical presence, the variable does not need to be signed but the
360 // parameters to the SetVariable() call still need to be prepared as authenticated
361 // variable. So we create EFI_VARIABLE_AUTHENTICATED_2 descriptor without certificate
362 // data in it.
363 //
364 Payload = *Data;
365 PayloadSize = *DataSize;
366
367 DescriptorSize = OFFSET_OF (EFI_VARIABLE_AUTHENTICATION_2, AuthInfo) + OFFSET_OF (WIN_CERTIFICATE_UEFI_GUID, CertData);
368 NewData = (UINT8 *) AllocateZeroPool (DescriptorSize + PayloadSize);
369 if (NewData == NULL) {
370 return EFI_OUT_OF_RESOURCES;
371 }
372
373 if ((Payload != NULL) && (PayloadSize != 0)) {
374 CopyMem (NewData + DescriptorSize, Payload, PayloadSize);
375 }
376
377 DescriptorData = (EFI_VARIABLE_AUTHENTICATION_2 *) (NewData);
378
379 ZeroMem (&Time, sizeof (EFI_TIME));
380 Status = gRT->GetTime (&Time, NULL);
381 if (EFI_ERROR (Status)) {
382 FreePool (NewData);
383 return Status;
384 }
385 Time.Pad1 = 0;
386 Time.Nanosecond = 0;
387 Time.TimeZone = 0;
388 Time.Daylight = 0;
389 Time.Pad2 = 0;
390 CopyMem (&DescriptorData->TimeStamp, &Time, sizeof (EFI_TIME));
391
392 DescriptorData->AuthInfo.Hdr.dwLength = OFFSET_OF (WIN_CERTIFICATE_UEFI_GUID, CertData);
393 DescriptorData->AuthInfo.Hdr.wRevision = 0x0200;
394 DescriptorData->AuthInfo.Hdr.wCertificateType = WIN_CERT_TYPE_EFI_GUID;
395 CopyGuid (&DescriptorData->AuthInfo.CertType, &gEfiCertPkcs7Guid);
396
397 if (Payload != NULL) {
398 FreePool (Payload);
399 }
400
401 *DataSize = DescriptorSize + PayloadSize;
402 *Data = NewData;
403 return EFI_SUCCESS;
404 }
405
406 /**
407 Create a counter based data payload by concatenating the EFI_VARIABLE_AUTHENTICATION
408 descriptor with the input data. NO authentication is required in this function.
409
410 @param[in, out] DataSize On input, the size of Data buffer in bytes.
411 On output, the size of data returned in Data
412 buffer in bytes.
413 @param[in, out] Data On input, Pointer to data buffer to be wrapped or
414 pointer to NULL to wrap an empty payload.
415 On output, Pointer to the new payload date buffer allocated from pool,
416 it's caller's responsibility to free the memory after using it.
417
418 @retval EFI_SUCCESS Create counter based payload successfully.
419 @retval EFI_OUT_OF_RESOURCES There are not enough memory resourses to create time based payload.
420 @retval EFI_INVALID_PARAMETER The parameter is invalid.
421 @retval Others Unexpected error happens.
422
423 **/
424 EFI_STATUS
425 CreateCounterBasedPayload (
426 IN OUT UINTN *DataSize,
427 IN OUT UINT8 **Data
428 )
429 {
430 EFI_STATUS Status;
431 UINT8 *NewData;
432 UINT8 *Payload;
433 UINTN PayloadSize;
434 EFI_VARIABLE_AUTHENTICATION *DescriptorData;
435 UINTN DescriptorSize;
436 UINT64 MonotonicCount;
437
438 if (Data == NULL || DataSize == NULL) {
439 return EFI_INVALID_PARAMETER;
440 }
441
442 //
443 // At user physical presence, the variable does not need to be signed but the
444 // parameters to the SetVariable() call still need to be prepared as authenticated
445 // variable. So we create EFI_VARIABLE_AUTHENTICATED descriptor without certificate
446 // data in it.
447 //
448 Payload = *Data;
449 PayloadSize = *DataSize;
450
451 DescriptorSize = (OFFSET_OF (EFI_VARIABLE_AUTHENTICATION, AuthInfo)) + \
452 (OFFSET_OF (WIN_CERTIFICATE_UEFI_GUID, CertData)) + \
453 sizeof (EFI_CERT_BLOCK_RSA_2048_SHA256);
454 NewData = (UINT8 *) AllocateZeroPool (DescriptorSize + PayloadSize);
455 if (NewData == NULL) {
456 return EFI_OUT_OF_RESOURCES;
457 }
458
459 if ((Payload != NULL) && (PayloadSize != 0)) {
460 CopyMem (NewData + DescriptorSize, Payload, PayloadSize);
461 }
462
463 DescriptorData = (EFI_VARIABLE_AUTHENTICATION *) (NewData);
464
465 Status = gBS->GetNextMonotonicCount (&MonotonicCount);
466 if (EFI_ERROR (Status)) {
467 FreePool (NewData);
468 return Status;
469 }
470 DescriptorData->MonotonicCount = MonotonicCount;
471
472 DescriptorData->AuthInfo.Hdr.dwLength = OFFSET_OF (WIN_CERTIFICATE_UEFI_GUID, CertData) + sizeof (EFI_CERT_BLOCK_RSA_2048_SHA256);
473 DescriptorData->AuthInfo.Hdr.wRevision = 0x0200;
474 DescriptorData->AuthInfo.Hdr.wCertificateType = WIN_CERT_TYPE_EFI_GUID;
475 CopyGuid (&DescriptorData->AuthInfo.CertType, &gEfiCertTypeRsa2048Sha256Guid);
476
477 if (Payload != NULL) {
478 FreePool (Payload);
479 }
480
481 *DataSize = DescriptorSize + PayloadSize;
482 *Data = NewData;
483 return EFI_SUCCESS;
484 }
485
486 /**
487 Delete user variable.
488
489 @param[in] DeleteAll Delete all user variables.
490 @param[in] VariableCleanupData Pointer to variable cleanup data.
491
492 **/
493 VOID
494 DeleteUserVariable (
495 IN BOOLEAN DeleteAll,
496 IN VARIABLE_CLEANUP_DATA *VariableCleanupData OPTIONAL
497 )
498 {
499 EFI_STATUS Status;
500 USER_VARIABLE_NODE *UserVariableNode;
501 LIST_ENTRY *Link;
502 USER_VARIABLE_NAME_NODE *UserVariableNameNode;
503 LIST_ENTRY *NameLink;
504 UINTN DataSize;
505 UINT8 *Data;
506
507 for (Link = mUserVariableList.ForwardLink
508 ;Link != &mUserVariableList
509 ;Link = Link->ForwardLink) {
510 UserVariableNode = USER_VARIABLE_FROM_LINK (Link);
511
512 for (NameLink = UserVariableNode->NameLink.ForwardLink
513 ;NameLink != &UserVariableNode->NameLink
514 ;NameLink = NameLink->ForwardLink) {
515 UserVariableNameNode = USER_VARIABLE_NAME_FROM_LINK (NameLink);
516
517 if (!UserVariableNameNode->Deleted && (DeleteAll || ((VariableCleanupData != NULL) && (VariableCleanupData->UserVariable[UserVariableNameNode->Index] == TRUE)))) {
518 DEBUG ((EFI_D_INFO, "PlatformVarCleanup - Delete variable: %g:%s\n", &UserVariableNode->Guid, UserVariableNameNode->Name));
519 if ((UserVariableNameNode->Attributes & EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) != 0) {
520 DataSize = 0;
521 Data = NULL;
522 Status = CreateTimeBasedPayload (&DataSize, &Data);
523 if (!EFI_ERROR (Status)) {
524 Status = gRT->SetVariable (UserVariableNameNode->Name, &UserVariableNode->Guid, UserVariableNameNode->Attributes, DataSize, Data);
525 FreePool (Data);
526 }
527 } else if ((UserVariableNameNode->Attributes & EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS) != 0) {
528 DataSize = 0;
529 Data = NULL;
530 Status = CreateCounterBasedPayload (&DataSize, &Data);
531 if (!EFI_ERROR (Status)) {
532 Status = gRT->SetVariable (UserVariableNameNode->Name, &UserVariableNode->Guid, UserVariableNameNode->Attributes, DataSize, Data);
533 FreePool (Data);
534 }
535 } else {
536 Status = gRT->SetVariable (UserVariableNameNode->Name, &UserVariableNode->Guid, 0, 0, NULL);
537 }
538 if (!EFI_ERROR (Status)) {
539 UserVariableNameNode->Deleted = TRUE;
540 } else {
541 DEBUG ((EFI_D_INFO, "PlatformVarCleanup - Delete variable fail: %g:%s\n", &UserVariableNode->Guid, UserVariableNameNode->Name));
542 }
543 }
544 }
545 }
546 }
547
548 /**
549 This function allows a caller to extract the current configuration for one
550 or more named elements from the target driver.
551
552 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
553 @param[in] Request A null-terminated Unicode string in <ConfigRequest> format.
554 @param[out] Progress On return, points to a character in the Request string.
555 Points to the string's null terminator if request was successful.
556 Points to the most recent '&' before the first failing name/value
557 pair (or the beginning of the string if the failure is in the
558 first name/value pair) if the request was not successful.
559 @param[out] Results A null-terminated Unicode string in <ConfigAltResp> format which
560 has all values filled in for the names in the Request string.
561 String to be allocated by the called function.
562
563 @retval EFI_SUCCESS The Results is filled with the requested values.
564 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
565 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
566 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
567
568 **/
569 EFI_STATUS
570 EFIAPI
571 VariableCleanupHiiExtractConfig (
572 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
573 IN CONST EFI_STRING Request,
574 OUT EFI_STRING *Progress,
575 OUT EFI_STRING *Results
576 )
577 {
578 EFI_STATUS Status;
579 VARIABLE_CLEANUP_HII_PRIVATE_DATA *Private;
580 UINTN BufferSize;
581 EFI_STRING ConfigRequestHdr;
582 EFI_STRING ConfigRequest;
583 BOOLEAN AllocatedRequest;
584 UINTN Size;
585
586 if (Progress == NULL || Results == NULL) {
587 return EFI_INVALID_PARAMETER;
588 }
589
590 *Progress = Request;
591 if ((Request != NULL) && !HiiIsConfigHdrMatch (Request, &mVariableCleanupHiiGuid, mVarStoreName)) {
592 return EFI_NOT_FOUND;
593 }
594
595 ConfigRequestHdr = NULL;
596 ConfigRequest = NULL;
597 AllocatedRequest = FALSE;
598 Size = 0;
599
600 Private = VARIABLE_CLEANUP_HII_PRIVATE_FROM_THIS (This);
601 //
602 // Convert buffer data to <ConfigResp> by helper function BlockToConfig().
603 //
604 BufferSize = sizeof (VARIABLE_CLEANUP_DATA);
605 ConfigRequest = Request;
606 if ((Request == NULL) || (StrStr (Request, L"OFFSET") == NULL)) {
607 //
608 // Request has no request element, construct full request string.
609 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
610 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator.
611 //
612 ConfigRequestHdr = HiiConstructConfigHdr (&mVariableCleanupHiiGuid, mVarStoreName, Private->HiiHandle);
613 Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
614 ConfigRequest = AllocateZeroPool (Size);
615 ASSERT (ConfigRequest != NULL);
616 AllocatedRequest = TRUE;
617 UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize);
618 FreePool (ConfigRequestHdr);
619 }
620
621 Status = Private->ConfigRouting->BlockToConfig (
622 Private->ConfigRouting,
623 ConfigRequest,
624 (UINT8 *) &Private->VariableCleanupData,
625 BufferSize,
626 Results,
627 Progress
628 );
629 ASSERT_EFI_ERROR (Status);
630
631 //
632 // Free the allocated config request string.
633 //
634 if (AllocatedRequest) {
635 FreePool (ConfigRequest);
636 ConfigRequest = NULL;
637 }
638 //
639 // Set Progress string to the original request string or the string's null terminator.
640 //
641 if (Request == NULL) {
642 *Progress = NULL;
643 } else if (StrStr (Request, L"OFFSET") == NULL) {
644 *Progress = Request + StrLen (Request);
645 }
646
647 return Status;
648 }
649
650 /**
651 Update user variable form.
652
653 @param[in] Private Points to the VARIABLE_CLEANUP_HII_PRIVATE_DATA.
654
655 **/
656 VOID
657 UpdateUserVariableForm (
658 IN VARIABLE_CLEANUP_HII_PRIVATE_DATA *Private
659 )
660 {
661 EFI_STRING_ID PromptStringToken;
662 EFI_STRING_ID HelpStringToken;
663 VOID *StartOpCodeHandle;
664 VOID *EndOpCodeHandle;
665 EFI_IFR_GUID_LABEL *StartLabel;
666 EFI_IFR_GUID_LABEL *EndLabel;
667 USER_VARIABLE_NODE *UserVariableNode;
668 LIST_ENTRY *Link;
669 USER_VARIABLE_NAME_NODE *UserVariableNameNode;
670 LIST_ENTRY *NameLink;
671 BOOLEAN Created;
672
673 //
674 // Init OpCode Handle.
675 //
676 StartOpCodeHandle = HiiAllocateOpCodeHandle ();
677 ASSERT (StartOpCodeHandle != NULL);
678
679 EndOpCodeHandle = HiiAllocateOpCodeHandle ();
680 ASSERT (EndOpCodeHandle != NULL);
681
682 //
683 // Create Hii Extend Label OpCode as the start opcode.
684 //
685 StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
686 StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
687 StartLabel->Number = LABEL_START;
688
689 //
690 // Create Hii Extend Label OpCode as the end opcode.
691 //
692 EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
693 EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
694 EndLabel->Number = LABEL_END;
695
696 HiiUpdateForm (
697 Private->HiiHandle,
698 &mVariableCleanupHiiGuid,
699 FORM_ID_VARIABLE_CLEANUP,
700 StartOpCodeHandle, // LABEL_START
701 EndOpCodeHandle // LABEL_END
702 );
703
704 for (Link = mUserVariableList.ForwardLink
705 ;Link != &mUserVariableList
706 ;Link = Link->ForwardLink) {
707 UserVariableNode = USER_VARIABLE_FROM_LINK (Link);
708
709 //
710 // Create checkbox opcode for variables in the same variable GUID space.
711 //
712 Created = FALSE;
713 for (NameLink = UserVariableNode->NameLink.ForwardLink
714 ;NameLink != &UserVariableNode->NameLink
715 ;NameLink = NameLink->ForwardLink) {
716 UserVariableNameNode = USER_VARIABLE_NAME_FROM_LINK (NameLink);
717
718 if (!UserVariableNameNode->Deleted) {
719 if (!Created) {
720 //
721 // Create subtitle opcode for variable GUID.
722 //
723 PromptStringToken = HiiSetString (Private->HiiHandle, 0, UserVariableNode->PromptString, NULL);
724 HiiCreateSubTitleOpCode (StartOpCodeHandle, PromptStringToken, 0, 0, 0);
725 Created = TRUE;
726 }
727
728 //
729 // Only create opcode for the non-deleted variables.
730 //
731 PromptStringToken = HiiSetString (Private->HiiHandle, 0, UserVariableNameNode->PromptString, NULL);
732 HelpStringToken = HiiSetString (Private->HiiHandle, 0, UserVariableNameNode->HelpString, NULL);
733 HiiCreateCheckBoxOpCode (
734 StartOpCodeHandle,
735 UserVariableNameNode->QuestionId,
736 VARIABLE_CLEANUP_VARSTORE_ID,
737 (UINT16) (USER_VARIABLE_VAR_OFFSET + UserVariableNameNode->Index),
738 PromptStringToken,
739 HelpStringToken,
740 EFI_IFR_FLAG_CALLBACK,
741 Private->VariableCleanupData.UserVariable[UserVariableNameNode->Index],
742 NULL
743 );
744 }
745 }
746 }
747
748 HiiCreateSubTitleOpCode (
749 StartOpCodeHandle,
750 STRING_TOKEN (STR_NULL_STRING),
751 0,
752 0,
753 0
754 );
755
756 //
757 // Create the "Apply changes" and "Discard changes" tags.
758 //
759 HiiCreateActionOpCode (
760 StartOpCodeHandle,
761 SAVE_AND_EXIT_QUESTION_ID,
762 STRING_TOKEN (STR_SAVE_AND_EXIT),
763 STRING_TOKEN (STR_NULL_STRING),
764 EFI_IFR_FLAG_CALLBACK,
765 0
766 );
767 HiiCreateActionOpCode (
768 StartOpCodeHandle,
769 NO_SAVE_AND_EXIT_QUESTION_ID,
770 STRING_TOKEN (STR_NO_SAVE_AND_EXIT),
771 STRING_TOKEN (STR_NULL_STRING),
772 EFI_IFR_FLAG_CALLBACK,
773 0
774 );
775
776 HiiUpdateForm (
777 Private->HiiHandle,
778 &mVariableCleanupHiiGuid,
779 FORM_ID_VARIABLE_CLEANUP,
780 StartOpCodeHandle, // LABEL_START
781 EndOpCodeHandle // LABEL_END
782 );
783
784 HiiFreeOpCodeHandle (StartOpCodeHandle);
785 HiiFreeOpCodeHandle (EndOpCodeHandle);
786 }
787
788 /**
789 This function applies changes in a driver's configuration.
790 Input is a Configuration, which has the routing data for this
791 driver followed by name / value configuration pairs. The driver
792 must apply those pairs to its configurable storage. If the
793 driver's configuration is stored in a linear block of data
794 and the driver's name / value pairs are in <BlockConfig>
795 format, it may use the ConfigToBlock helper function (above) to
796 simplify the job. Currently not implemented.
797
798 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
799 @param[in] Configuration A null-terminated Unicode string in
800 <ConfigString> format.
801 @param[out] Progress A pointer to a string filled in with the
802 offset of the most recent '&' before the
803 first failing name / value pair (or the
804 beginn ing of the string if the failure
805 is in the first name / value pair) or
806 the terminating NULL if all was
807 successful.
808
809 @retval EFI_SUCCESS The results have been distributed or are
810 awaiting distribution.
811 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the
812 parts of the results that must be
813 stored awaiting possible future
814 protocols.
815 @retval EFI_INVALID_PARAMETERS Passing in a NULL for the
816 Results parameter would result
817 in this type of error.
818 @retval EFI_NOT_FOUND Target for the specified routing data
819 was not found.
820
821 **/
822 EFI_STATUS
823 EFIAPI
824 VariableCleanupHiiRouteConfig (
825 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
826 IN CONST EFI_STRING Configuration,
827 OUT EFI_STRING *Progress
828 )
829 {
830 EFI_STATUS Status;
831 VARIABLE_CLEANUP_HII_PRIVATE_DATA *Private;
832 UINTN BufferSize;
833
834 if (Progress == NULL) {
835 return EFI_INVALID_PARAMETER;
836 }
837 *Progress = Configuration;
838
839 if (Configuration == NULL) {
840 return EFI_INVALID_PARAMETER;
841 }
842
843 //
844 // Check routing data in <ConfigHdr>.
845 // Note: there is no name for Name/Value storage, only GUID will be checked.
846 //
847 if (!HiiIsConfigHdrMatch (Configuration, &mVariableCleanupHiiGuid, mVarStoreName)) {
848 return EFI_NOT_FOUND;
849 }
850
851 Private = VARIABLE_CLEANUP_HII_PRIVATE_FROM_THIS (This);
852 //
853 // Get Buffer Storage data.
854 //
855 BufferSize = sizeof (VARIABLE_CLEANUP_DATA);
856 //
857 // Convert <ConfigResp> to buffer data by helper function ConfigToBlock().
858 //
859 Status = Private->ConfigRouting->ConfigToBlock (
860 Private->ConfigRouting,
861 Configuration,
862 (UINT8 *) &Private->VariableCleanupData,
863 &BufferSize,
864 Progress
865 );
866 ASSERT_EFI_ERROR (Status);
867
868 DeleteUserVariable (FALSE, &Private->VariableCleanupData);
869 //
870 // For "F10" hotkey to refresh the form.
871 //
872 // UpdateUserVariableForm (Private);
873
874 return EFI_SUCCESS;
875 }
876
877 /**
878 This function is called to provide results data to the driver.
879 This data consists of a unique key that is used to identify
880 which data is either being passed back or being asked for.
881
882 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
883 @param[in] Action Specifies the type of action taken by the browser.
884 @param[in] QuestionId A unique value which is sent to the original
885 exporting driver so that it can identify the type
886 of data to expect. The format of the data tends to
887 vary based on the opcode that generated the callback.
888 @param[in] Type The type of value for the question.
889 @param[in] Value A pointer to the data being sent to the original
890 exporting driver.
891 @param[out] ActionRequest On return, points to the action requested by the
892 callback function.
893
894 @retval EFI_SUCCESS The callback successfully handled the action.
895 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
896 variable and its data.
897 @retval EFI_DEVICE_ERROR The variable could not be saved.
898 @retval EFI_UNSUPPORTED The specified Action is not supported by the
899 callback.
900 **/
901 EFI_STATUS
902 EFIAPI
903 VariableCleanupHiiCallback (
904 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
905 IN EFI_BROWSER_ACTION Action,
906 IN EFI_QUESTION_ID QuestionId,
907 IN UINT8 Type,
908 IN EFI_IFR_TYPE_VALUE *Value,
909 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
910 )
911 {
912 VARIABLE_CLEANUP_HII_PRIVATE_DATA *Private;
913 VARIABLE_CLEANUP_DATA *VariableCleanupData;
914
915 Private = VARIABLE_CLEANUP_HII_PRIVATE_FROM_THIS (This);
916
917 if ((Action != EFI_BROWSER_ACTION_CHANGING) && (Action != EFI_BROWSER_ACTION_CHANGED)) {
918 //
919 // All other action return unsupported.
920 //
921 return EFI_UNSUPPORTED;
922 }
923
924 //
925 // Retrieve uncommitted data from Form Browser.
926 //
927 VariableCleanupData = &Private->VariableCleanupData;
928 HiiGetBrowserData (&mVariableCleanupHiiGuid, mVarStoreName, sizeof (VARIABLE_CLEANUP_DATA), (UINT8 *) VariableCleanupData);
929 if (Action == EFI_BROWSER_ACTION_CHANGING) {
930 if (Value == NULL) {
931 return EFI_INVALID_PARAMETER;
932 }
933 } else if (Action == EFI_BROWSER_ACTION_CHANGED) {
934 if ((Value == NULL) || (ActionRequest == NULL)) {
935 return EFI_INVALID_PARAMETER;
936 }
937 if ((QuestionId >= USER_VARIABLE_QUESTION_ID) && (QuestionId < USER_VARIABLE_QUESTION_ID + MAX_USER_VARIABLE_COUNT)) {
938 if (Value->b){
939 //
940 // Means one user variable checkbox is marked to delete but not press F10 or "Commit Changes and Exit" menu.
941 //
942 mMarkedUserVariableCount++;
943 ASSERT (mMarkedUserVariableCount <= mUserVariableCount);
944 if (mMarkedUserVariableCount == mUserVariableCount) {
945 //
946 // All user variables have been marked, then also mark the SelectAll checkbox.
947 //
948 VariableCleanupData->SelectAll = TRUE;
949 }
950 } else {
951 //
952 // Means one user variable checkbox is unmarked.
953 //
954 mMarkedUserVariableCount--;
955 //
956 // Also unmark the SelectAll checkbox.
957 //
958 VariableCleanupData->SelectAll = FALSE;
959 }
960 } else {
961 switch (QuestionId) {
962 case SELECT_ALL_QUESTION_ID:
963 if (Value->b){
964 //
965 // Means the SelectAll checkbox is marked to delete all user variables but not press F10 or "Commit Changes and Exit" menu.
966 //
967 SetMem (VariableCleanupData->UserVariable, sizeof (VariableCleanupData->UserVariable), TRUE);
968 mMarkedUserVariableCount = mUserVariableCount;
969 } else {
970 //
971 // Means the SelectAll checkbox is unmarked.
972 //
973 SetMem (VariableCleanupData->UserVariable, sizeof (VariableCleanupData->UserVariable), FALSE);
974 mMarkedUserVariableCount = 0;
975 }
976 break;
977 case SAVE_AND_EXIT_QUESTION_ID:
978 DeleteUserVariable (FALSE, VariableCleanupData);
979 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT;
980 break;
981
982 case NO_SAVE_AND_EXIT_QUESTION_ID:
983 //
984 // Restore local maintain data.
985 //
986 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT;
987 break;
988
989 default:
990 break;
991 }
992 }
993 }
994
995 //
996 // Pass changed uncommitted data back to Form Browser.
997 //
998 HiiSetBrowserData (&mVariableCleanupHiiGuid, mVarStoreName, sizeof (VARIABLE_CLEANUP_DATA), (UINT8 *) VariableCleanupData, NULL);
999 return EFI_SUCCESS;
1000 }
1001
1002 /**
1003 Platform variable cleanup.
1004
1005 @param[in] Flag Variable error flag.
1006 @param[in] Type Variable cleanup type.
1007 If it is VarCleanupManually, the interface must be called after console connected.
1008
1009 @retval EFI_SUCCESS No error or error processed.
1010 @retval EFI_UNSUPPORTED The specified Flag or Type is not supported.
1011 For example, system error may be not supported to process and Platform should have mechanism to reset system to manufacture mode.
1012 Another, if system and user variables are wanted to be distinguished to process, the interface must be called after EndOfDxe.
1013 @retval EFI_OUT_OF_RESOURCES Not enough resource to process the error.
1014 @retval EFI_INVALID_PARAMETER The specified Flag or Type is an invalid value.
1015 @retval Others Other failure occurs.
1016
1017 **/
1018 EFI_STATUS
1019 EFIAPI
1020 PlatformVarCleanup (
1021 IN VAR_ERROR_FLAG Flag,
1022 IN VAR_CLEANUP_TYPE Type
1023 )
1024 {
1025 EFI_STATUS Status;
1026 EFI_FORM_BROWSER2_PROTOCOL *FormBrowser2;
1027 VARIABLE_CLEANUP_HII_PRIVATE_DATA *Private;
1028
1029 if (!mEndOfDxe) {
1030 //
1031 // This implementation must be called after EndOfDxe.
1032 //
1033 return EFI_UNSUPPORTED;
1034 }
1035
1036 if ((Type >= VarCleanupMax) || ((Flag & ((VAR_ERROR_FLAG) (VAR_ERROR_FLAG_SYSTEM_ERROR & VAR_ERROR_FLAG_USER_ERROR))) == 0)) {
1037 return EFI_INVALID_PARAMETER;
1038 }
1039
1040 if (Flag == VAR_ERROR_FLAG_NO_ERROR) {
1041 //
1042 // Just return success if no error.
1043 //
1044 return EFI_SUCCESS;
1045 }
1046
1047 if ((Flag & (~((VAR_ERROR_FLAG) VAR_ERROR_FLAG_SYSTEM_ERROR))) == 0) {
1048 //
1049 // This sample does not support system variables cleanup.
1050 //
1051 DEBUG ((EFI_D_ERROR, "NOTICE - VAR_ERROR_FLAG_SYSTEM_ERROR\n"));
1052 DEBUG ((EFI_D_ERROR, "Platform should have mechanism to reset system to manufacture mode\n"));
1053 return EFI_UNSUPPORTED;
1054 }
1055
1056 //
1057 // Continue to process VAR_ERROR_FLAG_USER_ERROR.
1058 //
1059
1060 //
1061 // Create user variable nodes for the following processing.
1062 //
1063 CreateUserVariableNode ();
1064
1065 switch (Type) {
1066 case VarCleanupAll:
1067 DeleteUserVariable (TRUE, NULL);
1068 //
1069 // Destroyed the created user variable nodes
1070 //
1071 DestroyUserVariableNode ();
1072 return EFI_SUCCESS;
1073 break;
1074
1075 case VarCleanupManually:
1076 //
1077 // Locate FormBrowser2 protocol.
1078 //
1079 Status = gBS->LocateProtocol (&gEfiFormBrowser2ProtocolGuid, NULL, (VOID **) &FormBrowser2);
1080 if (EFI_ERROR (Status)) {
1081 return Status;
1082 }
1083
1084 Private = AllocateZeroPool (sizeof (VARIABLE_CLEANUP_HII_PRIVATE_DATA));
1085 if (Private == NULL) {
1086 return EFI_OUT_OF_RESOURCES;
1087 }
1088
1089 Private->Signature = VARIABLE_CLEANUP_HII_PRIVATE_SIGNATURE;
1090 Private->ConfigAccess.ExtractConfig = VariableCleanupHiiExtractConfig;
1091 Private->ConfigAccess.RouteConfig = VariableCleanupHiiRouteConfig;
1092 Private->ConfigAccess.Callback = VariableCleanupHiiCallback;
1093
1094 Status = gBS->LocateProtocol (
1095 &gEfiHiiConfigRoutingProtocolGuid,
1096 NULL,
1097 (VOID **) &Private->ConfigRouting
1098 );
1099 if (EFI_ERROR (Status)) {
1100 goto Done;
1101 }
1102
1103 //
1104 // Install Device Path Protocol and Config Access protocol to driver handle.
1105 //
1106 Status = gBS->InstallMultipleProtocolInterfaces (
1107 &Private->DriverHandle,
1108 &gEfiDevicePathProtocolGuid,
1109 &mVarCleanupHiiVendorDevicePath,
1110 &gEfiHiiConfigAccessProtocolGuid,
1111 &Private->ConfigAccess,
1112 NULL
1113 );
1114 if (EFI_ERROR (Status)) {
1115 goto Done;
1116 }
1117
1118 //
1119 // Publish our HII data.
1120 //
1121 Private->HiiHandle = HiiAddPackages (
1122 &mVariableCleanupHiiGuid,
1123 Private->DriverHandle,
1124 PlatformVarCleanupLibStrings,
1125 PlatVarCleanupBin,
1126 NULL
1127 );
1128 if (Private->HiiHandle == NULL) {
1129 Status = EFI_OUT_OF_RESOURCES;
1130 goto Done;
1131 }
1132
1133 UpdateUserVariableForm (Private);
1134
1135 Status = FormBrowser2->SendForm (
1136 FormBrowser2,
1137 &Private->HiiHandle,
1138 1,
1139 NULL,
1140 0,
1141 NULL,
1142 NULL
1143 );
1144 break;
1145
1146 default:
1147 return EFI_UNSUPPORTED;
1148 break;
1149 }
1150
1151 Done:
1152 if (Private->DriverHandle != NULL) {
1153 gBS->UninstallMultipleProtocolInterfaces (
1154 Private->DriverHandle,
1155 &gEfiDevicePathProtocolGuid,
1156 &mVarCleanupHiiVendorDevicePath,
1157 &gEfiHiiConfigAccessProtocolGuid,
1158 &Private->ConfigAccess,
1159 NULL
1160 );
1161 }
1162 if (Private->HiiHandle != NULL) {
1163 HiiRemovePackages (Private->HiiHandle);
1164 }
1165
1166 FreePool (Private);
1167
1168 //
1169 // Destroyed the created user variable nodes
1170 //
1171 DestroyUserVariableNode ();
1172 return Status;
1173 }
1174
1175 /**
1176 Get last boot variable error flag.
1177
1178 @return Last boot variable error flag.
1179
1180 **/
1181 VAR_ERROR_FLAG
1182 EFIAPI
1183 GetLastBootVarErrorFlag (
1184 VOID
1185 )
1186 {
1187 return mLastVarErrorFlag;
1188 }
1189
1190 /**
1191 Notification function of END_OF_DXE.
1192
1193 This is a notification function registered on END_OF_DXE event.
1194
1195 @param[in] Event Event whose notification function is being invoked.
1196 @param[in] Context Pointer to the notification function's context.
1197
1198 **/
1199 VOID
1200 EFIAPI
1201 PlatformVarCleanupEndOfDxeEvent (
1202 IN EFI_EVENT Event,
1203 IN VOID *Context
1204 )
1205 {
1206 mEndOfDxe = TRUE;
1207 }
1208
1209 /**
1210 The constructor function caches the pointer to VarCheck protocol and last boot variable error flag.
1211
1212 The constructor function locates VarCheck protocol from protocol database.
1213 It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.
1214
1215 @param ImageHandle The firmware allocated handle for the EFI image.
1216 @param SystemTable A pointer to the EFI System Table.
1217
1218 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
1219
1220 **/
1221 EFI_STATUS
1222 EFIAPI
1223 PlatformVarCleanupLibConstructor (
1224 IN EFI_HANDLE ImageHandle,
1225 IN EFI_SYSTEM_TABLE *SystemTable
1226 )
1227 {
1228 EFI_STATUS Status;
1229
1230 mLastVarErrorFlag = InternalGetVarErrorFlag ();
1231 DEBUG ((EFI_D_INFO, "mLastVarErrorFlag - 0x%02x\n", mLastVarErrorFlag));
1232
1233 //
1234 // Register EFI_END_OF_DXE_EVENT_GROUP_GUID event.
1235 //
1236 Status = gBS->CreateEventEx (
1237 EVT_NOTIFY_SIGNAL,
1238 TPL_CALLBACK,
1239 PlatformVarCleanupEndOfDxeEvent,
1240 NULL,
1241 &gEfiEndOfDxeEventGroupGuid,
1242 &mPlatVarCleanupLibEndOfDxeEvent
1243 );
1244 ASSERT_EFI_ERROR (Status);
1245
1246 return EFI_SUCCESS;
1247 }
1248
1249 /**
1250 The destructor function closes the End of DXE event.
1251
1252 @param ImageHandle The firmware allocated handle for the EFI image.
1253 @param SystemTable A pointer to the EFI System Table.
1254
1255 @retval EFI_SUCCESS The destructor completed successfully.
1256
1257 **/
1258 EFI_STATUS
1259 EFIAPI
1260 PlatformVarCleanupLibDestructor (
1261 IN EFI_HANDLE ImageHandle,
1262 IN EFI_SYSTEM_TABLE *SystemTable
1263 )
1264 {
1265 EFI_STATUS Status;
1266
1267 //
1268 // Close the End of DXE event.
1269 //
1270 Status = gBS->CloseEvent (mPlatVarCleanupLibEndOfDxeEvent);
1271 ASSERT_EFI_ERROR (Status);
1272
1273 return EFI_SUCCESS;
1274 }