]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/BdsDxe/BdsEntry.c
BaseTools: Fix a bug of genffs command generation
[mirror_edk2.git] / MdeModulePkg / Universal / BdsDxe / BdsEntry.c
CommitLineData
f4cd24da
RN
1/** @file\r
2 This module produce main entry for BDS phase - BdsEntry.\r
3 When this module was dispatched by DxeCore, gEfiBdsArchProtocolGuid will be installed\r
4 which contains interface of BdsEntry.\r
5 After DxeCore finish DXE phase, gEfiBdsArchProtocolGuid->BdsEntry will be invoked\r
6 to enter BDS phase.\r
7\r
43311062 8Copyright (c) 2004 - 2019, Intel Corporation. All rights reserved.<BR>\r
e58f1ae5
SW
9(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
10(C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>\r
9d510e61 11SPDX-License-Identifier: BSD-2-Clause-Patent\r
f4cd24da
RN
12\r
13**/\r
14\r
15#include "Bds.h"\r
16#include "Language.h"\r
17#include "HwErrRecSupport.h"\r
18\r
19#define SET_BOOT_OPTION_SUPPORT_KEY_COUNT(a, c) { \\r
20 (a) = ((a) & ~EFI_BOOT_OPTION_SUPPORT_COUNT) | (((c) << LowBitSet32 (EFI_BOOT_OPTION_SUPPORT_COUNT)) & EFI_BOOT_OPTION_SUPPORT_COUNT); \\r
21 }\r
22\r
23///\r
24/// BDS arch protocol instance initial value.\r
25///\r
26EFI_BDS_ARCH_PROTOCOL gBds = {\r
27 BdsEntry\r
28};\r
29\r
30//\r
31// gConnectConInEvent - Event which is signaled when ConIn connection is required\r
32//\r
33EFI_EVENT gConnectConInEvent = NULL;\r
34\r
35///\r
36/// The read-only variables defined in UEFI Spec.\r
37///\r
38CHAR16 *mReadOnlyVariables[] = {\r
39 EFI_PLATFORM_LANG_CODES_VARIABLE_NAME,\r
40 EFI_LANG_CODES_VARIABLE_NAME,\r
41 EFI_BOOT_OPTION_SUPPORT_VARIABLE_NAME,\r
42 EFI_HW_ERR_REC_SUPPORT_VARIABLE_NAME,\r
43 EFI_OS_INDICATIONS_SUPPORT_VARIABLE_NAME\r
44 };\r
45\r
1634214d
RN
46CHAR16 *mBdsLoadOptionName[] = {\r
47 L"Driver",\r
48 L"SysPrep",\r
68456d8a
RN
49 L"Boot",\r
50 L"PlatformRecovery"\r
1634214d
RN
51};\r
52\r
f4cd24da
RN
53/**\r
54 Event to Connect ConIn.\r
55\r
56 @param Event Event whose notification function is being invoked.\r
57 @param Context Pointer to the notification function's context,\r
58 which is implementation-dependent.\r
59\r
60**/\r
61VOID\r
62EFIAPI\r
63BdsDxeOnConnectConInCallBack (\r
64 IN EFI_EVENT Event,\r
65 IN VOID *Context\r
66 )\r
67{\r
68 EFI_STATUS Status;\r
69\r
70 //\r
71 // When Osloader call ReadKeyStroke to signal this event\r
72 // no driver dependency is assumed existing. So use a non-dispatch version\r
73 //\r
74 Status = EfiBootManagerConnectConsoleVariable (ConIn);\r
75 if (EFI_ERROR (Status)) {\r
76 //\r
77 // Should not enter this case, if enter, the keyboard will not work.\r
78 // May need platfrom policy to connect keyboard.\r
79 //\r
1634214d 80 DEBUG ((EFI_D_WARN, "[Bds] Connect ConIn failed - %r!!!\n", Status));\r
f4cd24da
RN
81 }\r
82}\r
048bcba1
RN
83/**\r
84 Notify function for event group EFI_EVENT_GROUP_READY_TO_BOOT. This is used to\r
85 check whether there is remaining deferred load images.\r
86\r
87 @param[in] Event The Event that is being processed.\r
88 @param[in] Context The Event Context.\r
89\r
90**/\r
91VOID\r
92EFIAPI\r
93CheckDeferredLoadImageOnReadyToBoot (\r
94 IN EFI_EVENT Event,\r
95 IN VOID *Context\r
96 )\r
97{\r
98 EFI_STATUS Status;\r
99 EFI_DEFERRED_IMAGE_LOAD_PROTOCOL *DeferredImage;\r
100 UINTN HandleCount;\r
101 EFI_HANDLE *Handles;\r
102 UINTN Index;\r
103 UINTN ImageIndex;\r
104 EFI_DEVICE_PATH_PROTOCOL *ImageDevicePath;\r
105 VOID *Image;\r
106 UINTN ImageSize;\r
107 BOOLEAN BootOption;\r
108 CHAR16 *DevicePathStr;\r
109\r
110 //\r
111 // Find all the deferred image load protocols.\r
112 //\r
113 HandleCount = 0;\r
114 Handles = NULL;\r
115 Status = gBS->LocateHandleBuffer (\r
116 ByProtocol,\r
117 &gEfiDeferredImageLoadProtocolGuid,\r
118 NULL,\r
119 &HandleCount,\r
120 &Handles\r
121 );\r
122 if (EFI_ERROR (Status)) {\r
123 return;\r
124 }\r
125\r
126 for (Index = 0; Index < HandleCount; Index++) {\r
127 Status = gBS->HandleProtocol (Handles[Index], &gEfiDeferredImageLoadProtocolGuid, (VOID **) &DeferredImage);\r
128 if (EFI_ERROR (Status)) {\r
129 continue;\r
130 }\r
131\r
132 for (ImageIndex = 0; ; ImageIndex++) {\r
133 //\r
134 // Load all the deferred images in this protocol instance.\r
135 //\r
136 Status = DeferredImage->GetImageInfo (\r
137 DeferredImage,\r
138 ImageIndex,\r
139 &ImageDevicePath,\r
140 (VOID **) &Image,\r
141 &ImageSize,\r
142 &BootOption\r
143 );\r
144 if (EFI_ERROR (Status)) {\r
145 break;\r
146 }\r
147 DevicePathStr = ConvertDevicePathToText (ImageDevicePath, FALSE, FALSE);\r
148 DEBUG ((DEBUG_LOAD, "[Bds] Image was deferred but not loaded: %s.\n", DevicePathStr));\r
149 if (DevicePathStr != NULL) {\r
150 FreePool (DevicePathStr);\r
151 }\r
152 }\r
153 }\r
154 if (Handles != NULL) {\r
155 FreePool (Handles);\r
156 }\r
157}\r
f4cd24da
RN
158\r
159/**\r
160\r
161 Install Boot Device Selection Protocol\r
162\r
163 @param ImageHandle The image handle.\r
164 @param SystemTable The system table.\r
165\r
166 @retval EFI_SUCEESS BDS has finished initializing.\r
167 Return the dispatcher and recall BDS.Entry\r
168 @retval Other Return status from AllocatePool() or gBS->InstallProtocolInterface\r
169\r
170**/\r
171EFI_STATUS\r
172EFIAPI\r
173BdsInitialize (\r
174 IN EFI_HANDLE ImageHandle,\r
175 IN EFI_SYSTEM_TABLE *SystemTable\r
176 )\r
177{\r
178 EFI_STATUS Status;\r
179 EFI_HANDLE Handle;\r
180 //\r
181 // Install protocol interface\r
182 //\r
183 Handle = NULL;\r
184 Status = gBS->InstallMultipleProtocolInterfaces (\r
185 &Handle,\r
186 &gEfiBdsArchProtocolGuid, &gBds,\r
187 NULL\r
188 );\r
189 ASSERT_EFI_ERROR (Status);\r
190\r
048bcba1
RN
191 DEBUG_CODE (\r
192 EFI_EVENT Event;\r
193 //\r
194 // Register notify function to check deferred images on ReadyToBoot Event.\r
195 //\r
196 Status = gBS->CreateEventEx (\r
197 EVT_NOTIFY_SIGNAL,\r
198 TPL_CALLBACK,\r
199 CheckDeferredLoadImageOnReadyToBoot,\r
200 NULL,\r
201 &gEfiEventReadyToBootGuid,\r
202 &Event\r
203 );\r
204 ASSERT_EFI_ERROR (Status);\r
205 );\r
f4cd24da
RN
206 return Status;\r
207}\r
208\r
f4cd24da
RN
209/**\r
210 Function waits for a given event to fire, or for an optional timeout to expire.\r
211\r
212 @param Event The event to wait for\r
213 @param Timeout An optional timeout value in 100 ns units.\r
214\r
215 @retval EFI_SUCCESS Event fired before Timeout expired.\r
216 @retval EFI_TIME_OUT Timout expired before Event fired..\r
217\r
218**/\r
219EFI_STATUS\r
220BdsWaitForSingleEvent (\r
221 IN EFI_EVENT Event,\r
222 IN UINT64 Timeout OPTIONAL\r
223 )\r
224{\r
225 UINTN Index;\r
226 EFI_STATUS Status;\r
227 EFI_EVENT TimerEvent;\r
228 EFI_EVENT WaitList[2];\r
229\r
230 if (Timeout != 0) {\r
231 //\r
232 // Create a timer event\r
233 //\r
234 Status = gBS->CreateEvent (EVT_TIMER, 0, NULL, NULL, &TimerEvent);\r
235 if (!EFI_ERROR (Status)) {\r
236 //\r
237 // Set the timer event\r
238 //\r
239 gBS->SetTimer (\r
240 TimerEvent,\r
241 TimerRelative,\r
242 Timeout\r
243 );\r
244\r
245 //\r
246 // Wait for the original event or the timer\r
247 //\r
248 WaitList[0] = Event;\r
249 WaitList[1] = TimerEvent;\r
250 Status = gBS->WaitForEvent (2, WaitList, &Index);\r
251 ASSERT_EFI_ERROR (Status);\r
252 gBS->CloseEvent (TimerEvent);\r
253\r
254 //\r
255 // If the timer expired, change the return to timed out\r
256 //\r
257 if (Index == 1) {\r
258 Status = EFI_TIMEOUT;\r
259 }\r
260 }\r
261 } else {\r
262 //\r
263 // No timeout... just wait on the event\r
264 //\r
265 Status = gBS->WaitForEvent (1, &Event, &Index);\r
266 ASSERT (!EFI_ERROR (Status));\r
267 ASSERT (Index == 0);\r
268 }\r
269\r
270 return Status;\r
271}\r
272\r
273/**\r
274 The function reads user inputs.\r
275\r
276**/\r
277VOID\r
278BdsReadKeys (\r
279 VOID\r
280 )\r
281{\r
282 EFI_STATUS Status;\r
283 EFI_INPUT_KEY Key;\r
284\r
285 if (PcdGetBool (PcdConInConnectOnDemand)) {\r
286 return;\r
287 }\r
288\r
289 while (gST->ConIn != NULL) {\r
d1102dba 290\r
f4cd24da 291 Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
d1102dba 292\r
f4cd24da
RN
293 if (EFI_ERROR (Status)) {\r
294 //\r
295 // No more keys.\r
296 //\r
297 break;\r
298 }\r
299 }\r
300}\r
301\r
302/**\r
303 The function waits for the boot manager timeout expires or hotkey is pressed.\r
304\r
305 It calls PlatformBootManagerWaitCallback each second.\r
306\r
307 @param HotkeyTriggered Input hotkey event.\r
308**/\r
309VOID\r
310BdsWait (\r
311 IN EFI_EVENT HotkeyTriggered\r
312 )\r
313{\r
314 EFI_STATUS Status;\r
315 UINT16 TimeoutRemain;\r
316\r
317 DEBUG ((EFI_D_INFO, "[Bds]BdsWait ...Zzzzzzzzzzzz...\n"));\r
318\r
319 TimeoutRemain = PcdGet16 (PcdPlatformBootTimeOut);\r
320 while (TimeoutRemain != 0) {\r
321 DEBUG ((EFI_D_INFO, "[Bds]BdsWait(%d)..Zzzz...\n", (UINTN) TimeoutRemain));\r
322 PlatformBootManagerWaitCallback (TimeoutRemain);\r
323\r
324 BdsReadKeys (); // BUGBUG: Only reading can signal HotkeyTriggered\r
325 // Can be removed after all keyboard drivers invoke callback in timer callback.\r
326\r
327 if (HotkeyTriggered != NULL) {\r
328 Status = BdsWaitForSingleEvent (HotkeyTriggered, EFI_TIMER_PERIOD_SECONDS (1));\r
329 if (!EFI_ERROR (Status)) {\r
330 break;\r
331 }\r
332 } else {\r
333 gBS->Stall (1000000);\r
334 }\r
335\r
336 //\r
337 // 0xffff means waiting forever\r
338 // BDS with no hotkey provided and 0xffff as timeout will "hang" in the loop\r
339 //\r
340 if (TimeoutRemain != 0xffff) {\r
341 TimeoutRemain--;\r
342 }\r
343 }\r
2de1f611 344 PlatformBootManagerWaitCallback (0);\r
f4cd24da
RN
345 DEBUG ((EFI_D_INFO, "[Bds]Exit the waiting!\n"));\r
346}\r
347\r
348/**\r
349 Attempt to boot each boot option in the BootOptions array.\r
350\r
351 @param BootOptions Input boot option array.\r
352 @param BootOptionCount Input boot option count.\r
68456d8a 353 @param BootManagerMenu Input boot manager menu.\r
f4cd24da
RN
354\r
355 @retval TRUE Successfully boot one of the boot options.\r
356 @retval FALSE Failed boot any of the boot options.\r
357**/\r
358BOOLEAN\r
68456d8a 359BootBootOptions (\r
f4cd24da 360 IN EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions,\r
68456d8a 361 IN UINTN BootOptionCount,\r
e58f1ae5 362 IN EFI_BOOT_MANAGER_LOAD_OPTION *BootManagerMenu OPTIONAL\r
f4cd24da
RN
363 )\r
364{\r
365 UINTN Index;\r
366\r
45b57c12
DB
367 //\r
368 // Report Status Code to indicate BDS starts attempting booting from the UEFI BootOrder list.\r
369 //\r
370 REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_PC_ATTEMPT_BOOT_ORDER_EVENT));\r
371\r
f4cd24da
RN
372 //\r
373 // Attempt boot each boot option\r
374 //\r
375 for (Index = 0; Index < BootOptionCount; Index++) {\r
376 //\r
377 // According to EFI Specification, if a load option is not marked\r
378 // as LOAD_OPTION_ACTIVE, the boot manager will not automatically\r
379 // load the option.\r
380 //\r
381 if ((BootOptions[Index].Attributes & LOAD_OPTION_ACTIVE) == 0) {\r
382 continue;\r
383 }\r
384\r
385 //\r
386 // Boot#### load options with LOAD_OPTION_CATEGORY_APP are executables which are not\r
387 // part of the normal boot processing. Boot options with reserved category values will be\r
388 // ignored by the boot manager.\r
389 //\r
390 if ((BootOptions[Index].Attributes & LOAD_OPTION_CATEGORY) != LOAD_OPTION_CATEGORY_BOOT) {\r
391 continue;\r
392 }\r
393\r
394 //\r
395 // All the driver options should have been processed since\r
396 // now boot will be performed.\r
397 //\r
398 EfiBootManagerBoot (&BootOptions[Index]);\r
399\r
400 //\r
311b5a6f
ED
401 // If the boot via Boot#### returns with a status of EFI_SUCCESS, platform firmware\r
402 // supports boot manager menu, and if firmware is configured to boot in an\r
403 // interactive mode, the boot manager will stop processing the BootOrder variable and\r
404 // present a boot manager menu to the user.\r
f4cd24da 405 //\r
e58f1ae5 406 if ((BootManagerMenu != NULL) && (BootOptions[Index].Status == EFI_SUCCESS)) {\r
68456d8a 407 EfiBootManagerBoot (BootManagerMenu);\r
f4cd24da
RN
408 break;\r
409 }\r
410 }\r
411\r
412 return (BOOLEAN) (Index < BootOptionCount);\r
413}\r
414\r
415/**\r
68456d8a 416 The function will load and start every Driver####, SysPrep#### or PlatformRecovery####.\r
f4cd24da 417\r
1634214d
RN
418 @param LoadOptions Load option array.\r
419 @param LoadOptionCount Load option count.\r
f4cd24da
RN
420**/\r
421VOID\r
1634214d
RN
422ProcessLoadOptions (\r
423 IN EFI_BOOT_MANAGER_LOAD_OPTION *LoadOptions,\r
424 IN UINTN LoadOptionCount\r
f4cd24da
RN
425 )\r
426{\r
1634214d
RN
427 EFI_STATUS Status;\r
428 UINTN Index;\r
429 BOOLEAN ReconnectAll;\r
430 EFI_BOOT_MANAGER_LOAD_OPTION_TYPE LoadOptionType;\r
f4cd24da 431\r
68456d8a 432 ReconnectAll = FALSE;\r
1634214d 433 LoadOptionType = LoadOptionTypeMax;\r
f4cd24da
RN
434\r
435 //\r
436 // Process the driver option\r
437 //\r
1634214d 438 for (Index = 0; Index < LoadOptionCount; Index++) {\r
f4cd24da 439 //\r
1634214d 440 // All the load options in the array should be of the same type.\r
f4cd24da 441 //\r
68456d8a 442 if (Index == 0) {\r
1634214d 443 LoadOptionType = LoadOptions[Index].OptionType;\r
f4cd24da 444 }\r
1634214d 445 ASSERT (LoadOptionType == LoadOptions[Index].OptionType);\r
de67c35c 446 ASSERT (LoadOptionType != LoadOptionTypeBoot);\r
f4cd24da 447\r
1634214d 448 Status = EfiBootManagerProcessLoadOption (&LoadOptions[Index]);\r
f4cd24da 449\r
de67c35c
RN
450 //\r
451 // Status indicates whether the load option is loaded and executed\r
452 // LoadOptions[Index].Status is what the load option returns\r
453 //\r
68456d8a 454 if (!EFI_ERROR (Status)) {\r
de67c35c
RN
455 //\r
456 // Stop processing if any PlatformRecovery#### returns success.\r
457 //\r
458 if ((LoadOptions[Index].Status == EFI_SUCCESS) &&\r
459 (LoadOptionType == LoadOptionTypePlatformRecovery)) {\r
68456d8a
RN
460 break;\r
461 }\r
de67c35c
RN
462\r
463 //\r
464 // Only set ReconnectAll flag when the load option executes successfully.\r
465 //\r
466 if (!EFI_ERROR (LoadOptions[Index].Status) &&\r
467 (LoadOptions[Index].Attributes & LOAD_OPTION_FORCE_RECONNECT) != 0) {\r
68456d8a
RN
468 ReconnectAll = TRUE;\r
469 }\r
f4cd24da
RN
470 }\r
471 }\r
1634214d 472\r
f4cd24da 473 //\r
1634214d
RN
474 // If a driver load option is marked as LOAD_OPTION_FORCE_RECONNECT,\r
475 // then all of the EFI drivers in the system will be disconnected and\r
476 // reconnected after the last driver load option is processed.\r
f4cd24da 477 //\r
1634214d 478 if (ReconnectAll && LoadOptionType == LoadOptionTypeDriver) {\r
f4cd24da
RN
479 EfiBootManagerDisconnectAll ();\r
480 EfiBootManagerConnectAll ();\r
481 }\r
f4cd24da
RN
482}\r
483\r
484/**\r
485\r
d1102dba 486 Validate input console variable data.\r
f4cd24da
RN
487\r
488 If found the device path is not a valid device path, remove the variable.\r
d1102dba 489\r
f4cd24da
RN
490 @param VariableName Input console variable name.\r
491\r
492**/\r
493VOID\r
494BdsFormalizeConsoleVariable (\r
495 IN CHAR16 *VariableName\r
496 )\r
497{\r
498 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
499 UINTN VariableSize;\r
500 EFI_STATUS Status;\r
501\r
502 GetEfiGlobalVariable2 (VariableName, (VOID **) &DevicePath, &VariableSize);\r
d1102dba 503 if ((DevicePath != NULL) && !IsDevicePathValid (DevicePath, VariableSize)) {\r
f4cd24da
RN
504 Status = gRT->SetVariable (\r
505 VariableName,\r
506 &gEfiGlobalVariableGuid,\r
507 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
508 0,\r
509 NULL\r
510 );\r
511 //\r
512 // Deleting variable with current variable implementation shouldn't fail.\r
513 //\r
514 ASSERT_EFI_ERROR (Status);\r
515 }\r
516\r
517 if (DevicePath != NULL) {\r
518 FreePool (DevicePath);\r
519 }\r
520}\r
521\r
522/**\r
d1102dba
LG
523 Formalize OsIndication related variables.\r
524\r
525 For OsIndicationsSupported, Create a BS/RT/UINT64 variable to report caps\r
f4cd24da 526 Delete OsIndications variable if it is not NV/BS/RT UINT64.\r
d1102dba 527\r
f4cd24da
RN
528 Item 3 is used to solve case when OS corrupts OsIndications. Here simply delete this NV variable.\r
529\r
e58f1ae5
SW
530 Create a boot option for BootManagerMenu if it hasn't been created yet\r
531\r
f4cd24da 532**/\r
d1102dba 533VOID\r
f4cd24da
RN
534BdsFormalizeOSIndicationVariable (\r
535 VOID\r
536 )\r
537{\r
e58f1ae5
SW
538 EFI_STATUS Status;\r
539 UINT64 OsIndicationSupport;\r
540 UINT64 OsIndication;\r
541 UINTN DataSize;\r
542 UINT32 Attributes;\r
543 EFI_BOOT_MANAGER_LOAD_OPTION BootManagerMenu;\r
f4cd24da
RN
544\r
545 //\r
546 // OS indicater support variable\r
547 //\r
e58f1ae5
SW
548 Status = EfiBootManagerGetBootManagerMenu (&BootManagerMenu);\r
549 if (Status != EFI_NOT_FOUND) {\r
0889500c 550 OsIndicationSupport = EFI_OS_INDICATIONS_BOOT_TO_FW_UI;\r
e58f1ae5
SW
551 EfiBootManagerFreeLoadOption (&BootManagerMenu);\r
552 } else {\r
0889500c
ZG
553 OsIndicationSupport = 0;\r
554 }\r
555\r
556 if (PcdGetBool (PcdPlatformRecoverySupport)) {\r
557 OsIndicationSupport |= EFI_OS_INDICATIONS_START_PLATFORM_RECOVERY;\r
e58f1ae5
SW
558 }\r
559\r
43311062
WX
560 if (PcdGetBool(PcdCapsuleOnDiskSupport)) {\r
561 OsIndicationSupport |= EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED;\r
562 }\r
563\r
f4cd24da 564 Status = gRT->SetVariable (\r
cc4812f6 565 EFI_OS_INDICATIONS_SUPPORT_VARIABLE_NAME,\r
f4cd24da
RN
566 &gEfiGlobalVariableGuid,\r
567 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
568 sizeof(UINT64),\r
569 &OsIndicationSupport\r
570 );\r
571 //\r
572 // Platform needs to make sure setting volatile variable before calling 3rd party code shouldn't fail.\r
573 //\r
574 ASSERT_EFI_ERROR (Status);\r
575\r
576 //\r
577 // If OsIndications is invalid, remove it.\r
578 // Invalid case\r
579 // 1. Data size != UINT64\r
580 // 2. OsIndication value inconsistence\r
581 // 3. OsIndication attribute inconsistence\r
582 //\r
583 OsIndication = 0;\r
584 Attributes = 0;\r
585 DataSize = sizeof(UINT64);\r
586 Status = gRT->GetVariable (\r
cc4812f6 587 EFI_OS_INDICATIONS_VARIABLE_NAME,\r
f4cd24da
RN
588 &gEfiGlobalVariableGuid,\r
589 &Attributes,\r
590 &DataSize,\r
591 &OsIndication\r
592 );\r
593 if (Status == EFI_NOT_FOUND) {\r
594 return;\r
595 }\r
596\r
597 if ((DataSize != sizeof (OsIndication)) ||\r
598 ((OsIndication & ~OsIndicationSupport) != 0) ||\r
599 (Attributes != (EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE))\r
600 ){\r
601\r
602 DEBUG ((EFI_D_ERROR, "[Bds] Unformalized OsIndications variable exists. Delete it\n"));\r
603 Status = gRT->SetVariable (\r
cc4812f6 604 EFI_OS_INDICATIONS_VARIABLE_NAME,\r
f4cd24da
RN
605 &gEfiGlobalVariableGuid,\r
606 0,\r
607 0,\r
608 NULL\r
609 );\r
610 //\r
611 // Deleting variable with current variable implementation shouldn't fail.\r
612 //\r
613 ASSERT_EFI_ERROR(Status);\r
614 }\r
615}\r
616\r
617/**\r
618\r
d1102dba 619 Validate variables.\r
f4cd24da
RN
620\r
621**/\r
d1102dba 622VOID\r
f4cd24da
RN
623BdsFormalizeEfiGlobalVariable (\r
624 VOID\r
625 )\r
626{\r
627 //\r
628 // Validate Console variable.\r
629 //\r
cc4812f6
RN
630 BdsFormalizeConsoleVariable (EFI_CON_IN_VARIABLE_NAME);\r
631 BdsFormalizeConsoleVariable (EFI_CON_OUT_VARIABLE_NAME);\r
632 BdsFormalizeConsoleVariable (EFI_ERR_OUT_VARIABLE_NAME);\r
f4cd24da
RN
633\r
634 //\r
635 // Validate OSIndication related variable.\r
636 //\r
637 BdsFormalizeOSIndicationVariable ();\r
638}\r
639\r
f4cd24da
RN
640/**\r
641\r
642 Service routine for BdsInstance->Entry(). Devices are connected, the\r
643 consoles are initialized, and the boot options are tried.\r
644\r
645 @param This Protocol Instance structure.\r
646\r
647**/\r
648VOID\r
649EFIAPI\r
650BdsEntry (\r
651 IN EFI_BDS_ARCH_PROTOCOL *This\r
652 )\r
653{\r
1634214d
RN
654 EFI_BOOT_MANAGER_LOAD_OPTION *LoadOptions;\r
655 UINTN LoadOptionCount;\r
f4cd24da
RN
656 CHAR16 *FirmwareVendor;\r
657 EFI_EVENT HotkeyTriggered;\r
658 UINT64 OsIndication;\r
659 UINTN DataSize;\r
660 EFI_STATUS Status;\r
661 UINT32 BootOptionSupport;\r
662 UINT16 BootTimeOut;\r
663 EDKII_VARIABLE_LOCK_PROTOCOL *VariableLock;\r
664 UINTN Index;\r
d175f4e6 665 EFI_BOOT_MANAGER_LOAD_OPTION LoadOption;\r
f4cd24da
RN
666 UINT16 *BootNext;\r
667 CHAR16 BootNextVariableName[sizeof ("Boot####")];\r
1634214d
RN
668 EFI_BOOT_MANAGER_LOAD_OPTION BootManagerMenu;\r
669 BOOLEAN BootFwUi;\r
68456d8a
RN
670 BOOLEAN PlatformRecovery;\r
671 BOOLEAN BootSuccess;\r
d175f4e6 672 EFI_DEVICE_PATH_PROTOCOL *FilePath;\r
e58f1ae5 673 EFI_STATUS BootManagerMenuStatus;\r
0889500c 674 EFI_BOOT_MANAGER_LOAD_OPTION PlatformDefaultBootOption;\r
f4cd24da
RN
675\r
676 HotkeyTriggered = NULL;\r
677 Status = EFI_SUCCESS;\r
68456d8a 678 BootSuccess = FALSE;\r
f4cd24da
RN
679\r
680 //\r
681 // Insert the performance probe\r
682 //\r
67e9ab84
BD
683 PERF_CROSSMODULE_END("DXE");\r
684 PERF_CROSSMODULE_BEGIN("BDS");\r
f4cd24da
RN
685 DEBUG ((EFI_D_INFO, "[Bds] Entry...\n"));\r
686\r
f4cd24da
RN
687 //\r
688 // Fill in FirmwareVendor and FirmwareRevision from PCDs\r
689 //\r
690 FirmwareVendor = (CHAR16 *) PcdGetPtr (PcdFirmwareVendor);\r
691 gST->FirmwareVendor = AllocateRuntimeCopyPool (StrSize (FirmwareVendor), FirmwareVendor);\r
692 ASSERT (gST->FirmwareVendor != NULL);\r
693 gST->FirmwareRevision = PcdGet32 (PcdFirmwareRevision);\r
694\r
695 //\r
696 // Fixup Tasble CRC after we updated Firmware Vendor and Revision\r
697 //\r
698 gST->Hdr.CRC32 = 0;\r
699 gBS->CalculateCrc32 ((VOID *) gST, sizeof (EFI_SYSTEM_TABLE), &gST->Hdr.CRC32);\r
700\r
701 //\r
702 // Validate Variable.\r
703 //\r
704 BdsFormalizeEfiGlobalVariable ();\r
705\r
706 //\r
707 // Mark the read-only variables if the Variable Lock protocol exists\r
708 //\r
709 Status = gBS->LocateProtocol (&gEdkiiVariableLockProtocolGuid, NULL, (VOID **) &VariableLock);\r
710 DEBUG ((EFI_D_INFO, "[BdsDxe] Locate Variable Lock protocol - %r\n", Status));\r
711 if (!EFI_ERROR (Status)) {\r
1a5afd71 712 for (Index = 0; Index < ARRAY_SIZE (mReadOnlyVariables); Index++) {\r
f4cd24da
RN
713 Status = VariableLock->RequestToLock (VariableLock, mReadOnlyVariables[Index], &gEfiGlobalVariableGuid);\r
714 ASSERT_EFI_ERROR (Status);\r
715 }\r
716 }\r
717\r
718 InitializeHwErrRecSupport ();\r
719\r
720 //\r
721 // Initialize L"Timeout" EFI global variable.\r
722 //\r
723 BootTimeOut = PcdGet16 (PcdPlatformBootTimeOut);\r
724 if (BootTimeOut != 0xFFFF) {\r
725 //\r
726 // If time out value equal 0xFFFF, no need set to 0xFFFF to variable area because UEFI specification\r
727 // define same behavior between no value or 0xFFFF value for L"Timeout".\r
728 //\r
729 BdsDxeSetVariableAndReportStatusCodeOnError (\r
730 EFI_TIME_OUT_VARIABLE_NAME,\r
731 &gEfiGlobalVariableGuid,\r
732 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
733 sizeof (UINT16),\r
734 &BootTimeOut\r
735 );\r
736 }\r
737\r
738 //\r
739 // Initialize L"BootOptionSupport" EFI global variable.\r
740 // Lazy-ConIn implictly disables BDS hotkey.\r
741 //\r
1634214d 742 BootOptionSupport = EFI_BOOT_OPTION_SUPPORT_APP | EFI_BOOT_OPTION_SUPPORT_SYSPREP;\r
f4cd24da
RN
743 if (!PcdGetBool (PcdConInConnectOnDemand)) {\r
744 BootOptionSupport |= EFI_BOOT_OPTION_SUPPORT_KEY;\r
745 SET_BOOT_OPTION_SUPPORT_KEY_COUNT (BootOptionSupport, 3);\r
746 }\r
747 Status = gRT->SetVariable (\r
748 EFI_BOOT_OPTION_SUPPORT_VARIABLE_NAME,\r
749 &gEfiGlobalVariableGuid,\r
750 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
751 sizeof (BootOptionSupport),\r
752 &BootOptionSupport\r
753 );\r
754 //\r
755 // Platform needs to make sure setting volatile variable before calling 3rd party code shouldn't fail.\r
756 //\r
757 ASSERT_EFI_ERROR (Status);\r
758\r
759 //\r
0e6584e3
RN
760 // Cache the "BootNext" NV variable before calling any PlatformBootManagerLib APIs\r
761 // This could avoid the "BootNext" set by PlatformBootManagerLib be consumed in this boot.\r
f4cd24da
RN
762 //\r
763 GetEfiGlobalVariable2 (EFI_BOOT_NEXT_VARIABLE_NAME, (VOID **) &BootNext, &DataSize);\r
764 if (DataSize != sizeof (UINT16)) {\r
765 if (BootNext != NULL) {\r
766 FreePool (BootNext);\r
767 }\r
768 BootNext = NULL;\r
769 }\r
f4cd24da
RN
770\r
771 //\r
772 // Initialize the platform language variables\r
773 //\r
774 InitializeLanguage (TRUE);\r
775\r
d175f4e6 776 FilePath = FileDevicePath (NULL, EFI_REMOVABLE_MEDIA_FILE_NAME);\r
0889500c
ZG
777 if (FilePath == NULL) {\r
778 DEBUG ((DEBUG_ERROR, "Fail to allocate memory for defualt boot file path. Unable to boot.\n"));\r
779 CpuDeadLoop ();\r
780 }\r
d175f4e6 781 Status = EfiBootManagerInitializeLoadOption (\r
0889500c 782 &PlatformDefaultBootOption,\r
0dc3fb06 783 LoadOptionNumberUnassigned,\r
d175f4e6
RN
784 LoadOptionTypePlatformRecovery,\r
785 LOAD_OPTION_ACTIVE,\r
786 L"Default PlatformRecovery",\r
787 FilePath,\r
788 NULL,\r
789 0\r
790 );\r
791 ASSERT_EFI_ERROR (Status);\r
0889500c
ZG
792\r
793 //\r
794 // System firmware must include a PlatformRecovery#### variable specifying\r
795 // a short-form File Path Media Device Path containing the platform default\r
796 // file path for removable media if the platform supports Platform Recovery.\r
797 //\r
798 if (PcdGetBool (PcdPlatformRecoverySupport)) {\r
799 LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount, LoadOptionTypePlatformRecovery);\r
800 if (EfiBootManagerFindLoadOption (&PlatformDefaultBootOption, LoadOptions, LoadOptionCount) == -1) {\r
801 for (Index = 0; Index < LoadOptionCount; Index++) {\r
802 //\r
803 // The PlatformRecovery#### options are sorted by OptionNumber.\r
804 // Find the the smallest unused number as the new OptionNumber.\r
805 //\r
806 if (LoadOptions[Index].OptionNumber != Index) {\r
807 break;\r
808 }\r
0dc3fb06 809 }\r
0889500c
ZG
810 PlatformDefaultBootOption.OptionNumber = Index;\r
811 Status = EfiBootManagerLoadOptionToVariable (&PlatformDefaultBootOption);\r
812 ASSERT_EFI_ERROR (Status);\r
0dc3fb06 813 }\r
0889500c 814 EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount);\r
0dc3fb06 815 }\r
d175f4e6
RN
816 FreePool (FilePath);\r
817\r
f4cd24da
RN
818 //\r
819 // Report Status Code to indicate connecting drivers will happen\r
820 //\r
821 REPORT_STATUS_CODE (\r
822 EFI_PROGRESS_CODE,\r
823 (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_PC_BEGIN_CONNECTING_DRIVERS)\r
824 );\r
825\r
8537bd7e
RN
826 //\r
827 // Initialize ConnectConIn event before calling platform code.\r
828 //\r
829 if (PcdGetBool (PcdConInConnectOnDemand)) {\r
830 Status = gBS->CreateEventEx (\r
831 EVT_NOTIFY_SIGNAL,\r
832 TPL_CALLBACK,\r
833 BdsDxeOnConnectConInCallBack,\r
834 NULL,\r
835 &gConnectConInEventGuid,\r
836 &gConnectConInEvent\r
837 );\r
838 if (EFI_ERROR (Status)) {\r
839 gConnectConInEvent = NULL;\r
840 }\r
841 }\r
842\r
f4cd24da
RN
843 //\r
844 // Do the platform init, can be customized by OEM/IBV\r
845 // Possible things that can be done in PlatformBootManagerBeforeConsole:\r
846 // > Update console variable: 1. include hot-plug devices; 2. Clear ConIn and add SOL for AMT\r
847 // > Register new Driver#### or Boot####\r
d1102dba 848 // > Register new Key####: e.g.: F12\r
f4cd24da
RN
849 // > Signal ReadyToLock event\r
850 // > Authentication action: 1. connect Auth devices; 2. Identify auto logon user.\r
851 //\r
67e9ab84 852 PERF_INMODULE_BEGIN("PlatformBootManagerBeforeConsole");\r
f4cd24da 853 PlatformBootManagerBeforeConsole ();\r
67e9ab84 854 PERF_INMODULE_END("PlatformBootManagerBeforeConsole");\r
f4cd24da
RN
855\r
856 //\r
857 // Initialize hotkey service\r
858 //\r
859 EfiBootManagerStartHotkeyService (&HotkeyTriggered);\r
860\r
861 //\r
1634214d 862 // Execute Driver Options\r
f4cd24da 863 //\r
1634214d
RN
864 LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount, LoadOptionTypeDriver);\r
865 ProcessLoadOptions (LoadOptions, LoadOptionCount);\r
866 EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount);\r
f4cd24da
RN
867\r
868 //\r
869 // Connect consoles\r
870 //\r
67e9ab84 871 PERF_INMODULE_BEGIN("EfiBootManagerConnectAllDefaultConsoles");\r
f4cd24da
RN
872 if (PcdGetBool (PcdConInConnectOnDemand)) {\r
873 EfiBootManagerConnectConsoleVariable (ConOut);\r
874 EfiBootManagerConnectConsoleVariable (ErrOut);\r
f4cd24da 875 //\r
8537bd7e 876 // Do not connect ConIn devices when lazy ConIn feature is ON.\r
f4cd24da 877 //\r
f4cd24da
RN
878 } else {\r
879 EfiBootManagerConnectAllDefaultConsoles ();\r
880 }\r
67e9ab84 881 PERF_INMODULE_END("EfiBootManagerConnectAllDefaultConsoles");\r
f4cd24da
RN
882\r
883 //\r
884 // Do the platform specific action after the console is ready\r
885 // Possible things that can be done in PlatformBootManagerAfterConsole:\r
886 // > Console post action:\r
887 // > Dynamically switch output mode from 100x31 to 80x25 for certain senarino\r
888 // > Signal console ready platform customized event\r
889 // > Run diagnostics like memory testing\r
890 // > Connect certain devices\r
891 // > Dispatch aditional option roms\r
892 // > Special boot: e.g.: USB boot, enter UI\r
d1102dba 893 //\r
67e9ab84 894 PERF_INMODULE_BEGIN("PlatformBootManagerAfterConsole");\r
f4cd24da 895 PlatformBootManagerAfterConsole ();\r
67e9ab84 896 PERF_INMODULE_END("PlatformBootManagerAfterConsole");\r
6fb8b96d
KM
897\r
898 //\r
899 // If any component set PcdTestKeyUsed to TRUE because use of a test key\r
900 // was detected, then display a warning message on the debug log and the console\r
901 //\r
902 if (PcdGetBool (PcdTestKeyUsed)) {\r
903 DEBUG ((DEBUG_ERROR, "**********************************\n"));\r
904 DEBUG ((DEBUG_ERROR, "** WARNING: Test Key is used. **\n"));\r
905 DEBUG ((DEBUG_ERROR, "**********************************\n"));\r
906 Print (L"** WARNING: Test Key is used. **\n");\r
907 }\r
908\r
68456d8a
RN
909 //\r
910 // Boot to Boot Manager Menu when EFI_OS_INDICATIONS_BOOT_TO_FW_UI is set. Skip HotkeyBoot\r
911 //\r
912 DataSize = sizeof (UINT64);\r
913 Status = gRT->GetVariable (\r
914 EFI_OS_INDICATIONS_VARIABLE_NAME,\r
915 &gEfiGlobalVariableGuid,\r
916 NULL,\r
917 &DataSize,\r
918 &OsIndication\r
919 );\r
920 if (EFI_ERROR (Status)) {\r
921 OsIndication = 0;\r
922 }\r
f4cd24da
RN
923\r
924 DEBUG_CODE (\r
1634214d 925 EFI_BOOT_MANAGER_LOAD_OPTION_TYPE LoadOptionType;\r
68456d8a 926 DEBUG ((EFI_D_INFO, "[Bds]OsIndication: %016x\n", OsIndication));\r
1634214d
RN
927 DEBUG ((EFI_D_INFO, "[Bds]=============Begin Load Options Dumping ...=============\n"));\r
928 for (LoadOptionType = 0; LoadOptionType < LoadOptionTypeMax; LoadOptionType++) {\r
f4cd24da 929 DEBUG ((\r
1634214d
RN
930 EFI_D_INFO, " %s Options:\n",\r
931 mBdsLoadOptionName[LoadOptionType]\r
f4cd24da 932 ));\r
1634214d
RN
933 LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount, LoadOptionType);\r
934 for (Index = 0; Index < LoadOptionCount; Index++) {\r
935 DEBUG ((\r
936 EFI_D_INFO, " %s%04x: %s \t\t 0x%04x\n",\r
937 mBdsLoadOptionName[LoadOptionType],\r
938 LoadOptions[Index].OptionNumber,\r
939 LoadOptions[Index].Description,\r
940 LoadOptions[Index].Attributes\r
941 ));\r
942 }\r
943 EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount);\r
f4cd24da 944 }\r
1634214d
RN
945 DEBUG ((EFI_D_INFO, "[Bds]=============End Load Options Dumping=============\n"));\r
946 );\r
f4cd24da
RN
947\r
948 //\r
e58f1ae5 949 // BootManagerMenu doesn't contain the correct information when return status is EFI_NOT_FOUND.\r
f4cd24da 950 //\r
e58f1ae5 951 BootManagerMenuStatus = EfiBootManagerGetBootManagerMenu (&BootManagerMenu);\r
1634214d 952\r
68456d8a
RN
953 BootFwUi = (BOOLEAN) ((OsIndication & EFI_OS_INDICATIONS_BOOT_TO_FW_UI) != 0);\r
954 PlatformRecovery = (BOOLEAN) ((OsIndication & EFI_OS_INDICATIONS_START_PLATFORM_RECOVERY) != 0);\r
1634214d
RN
955 //\r
956 // Clear EFI_OS_INDICATIONS_BOOT_TO_FW_UI to acknowledge OS\r
d1102dba 957 //\r
68456d8a
RN
958 if (BootFwUi || PlatformRecovery) {\r
959 OsIndication &= ~((UINT64) (EFI_OS_INDICATIONS_BOOT_TO_FW_UI | EFI_OS_INDICATIONS_START_PLATFORM_RECOVERY));\r
f4cd24da 960 Status = gRT->SetVariable (\r
cc4812f6 961 EFI_OS_INDICATIONS_VARIABLE_NAME,\r
f4cd24da
RN
962 &gEfiGlobalVariableGuid,\r
963 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
964 sizeof(UINT64),\r
965 &OsIndication\r
966 );\r
967 //\r
968 // Changing the content without increasing its size with current variable implementation shouldn't fail.\r
969 //\r
970 ASSERT_EFI_ERROR (Status);\r
1634214d 971 }\r
f4cd24da 972\r
1634214d
RN
973 //\r
974 // Launch Boot Manager Menu directly when EFI_OS_INDICATIONS_BOOT_TO_FW_UI is set. Skip HotkeyBoot\r
975 //\r
e58f1ae5 976 if (BootFwUi && (BootManagerMenuStatus != EFI_NOT_FOUND)) {\r
f4cd24da
RN
977 //\r
978 // Follow generic rule, Call BdsDxeOnConnectConInCallBack to connect ConIn before enter UI\r
979 //\r
980 if (PcdGetBool (PcdConInConnectOnDemand)) {\r
981 BdsDxeOnConnectConInCallBack (NULL, NULL);\r
982 }\r
983\r
984 //\r
1634214d 985 // Directly enter the setup page.\r
f4cd24da 986 //\r
1634214d 987 EfiBootManagerBoot (&BootManagerMenu);\r
f4cd24da
RN
988 }\r
989\r
68456d8a
RN
990 if (!PlatformRecovery) {\r
991 //\r
992 // Execute SysPrep####\r
993 //\r
994 LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount, LoadOptionTypeSysPrep);\r
995 ProcessLoadOptions (LoadOptions, LoadOptionCount);\r
996 EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount);\r
1634214d 997\r
68456d8a
RN
998 //\r
999 // Execute Key####\r
1000 //\r
67e9ab84 1001 PERF_INMODULE_BEGIN ("BdsWait");\r
68456d8a 1002 BdsWait (HotkeyTriggered);\r
67e9ab84 1003 PERF_INMODULE_END ("BdsWait");\r
68456d8a
RN
1004 //\r
1005 // BdsReadKeys() can be removed after all keyboard drivers invoke callback in timer callback.\r
1006 //\r
1007 BdsReadKeys ();\r
1634214d 1008\r
68456d8a 1009 EfiBootManagerHotkeyBoot ();\r
1634214d 1010\r
68456d8a 1011 if (BootNext != NULL) {\r
0e6584e3
RN
1012 //\r
1013 // Delete "BootNext" NV variable before transferring control to it to prevent loops.\r
1014 //\r
1015 Status = gRT->SetVariable (\r
1016 EFI_BOOT_NEXT_VARIABLE_NAME,\r
1017 &gEfiGlobalVariableGuid,\r
1018 0,\r
1019 0,\r
1020 NULL\r
1021 );\r
1022 //\r
1023 // Deleting NV variable shouldn't fail unless it doesn't exist.\r
1024 //\r
1025 ASSERT (Status == EFI_SUCCESS || Status == EFI_NOT_FOUND);\r
1026\r
1027 //\r
1028 // Boot to "BootNext"\r
1029 //\r
68456d8a
RN
1030 UnicodeSPrint (BootNextVariableName, sizeof (BootNextVariableName), L"Boot%04x", *BootNext);\r
1031 Status = EfiBootManagerVariableToLoadOption (BootNextVariableName, &LoadOption);\r
1032 if (!EFI_ERROR (Status)) {\r
d175f4e6
RN
1033 EfiBootManagerBoot (&LoadOption);\r
1034 EfiBootManagerFreeLoadOption (&LoadOption);\r
d1102dba 1035 if ((LoadOption.Status == EFI_SUCCESS) &&\r
e58f1ae5
SW
1036 (BootManagerMenuStatus != EFI_NOT_FOUND) &&\r
1037 (LoadOption.OptionNumber != BootManagerMenu.OptionNumber)) {\r
68456d8a
RN
1038 //\r
1039 // Boot to Boot Manager Menu upon EFI_SUCCESS\r
f5cbc197 1040 // Exception: Do not boot again when the BootNext points to Boot Manager Menu.\r
68456d8a
RN
1041 //\r
1042 EfiBootManagerBoot (&BootManagerMenu);\r
1043 }\r
f4cd24da
RN
1044 }\r
1045 }\r
68456d8a
RN
1046\r
1047 do {\r
1048 //\r
1049 // Retry to boot if any of the boot succeeds\r
1050 //\r
1051 LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount, LoadOptionTypeBoot);\r
e58f1ae5 1052 BootSuccess = BootBootOptions (LoadOptions, LoadOptionCount, (BootManagerMenuStatus != EFI_NOT_FOUND) ? &BootManagerMenu : NULL);\r
68456d8a
RN
1053 EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount);\r
1054 } while (BootSuccess);\r
f4cd24da
RN
1055 }\r
1056\r
f50db933
RN
1057 if (BootManagerMenuStatus != EFI_NOT_FOUND) {\r
1058 EfiBootManagerFreeLoadOption (&BootManagerMenu);\r
1059 }\r
1060\r
68456d8a 1061 if (!BootSuccess) {\r
0889500c
ZG
1062 if (PlatformRecovery) {\r
1063 LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount, LoadOptionTypePlatformRecovery);\r
1064 ProcessLoadOptions (LoadOptions, LoadOptionCount);\r
1065 EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount);\r
1066 } else {\r
1067 //\r
1068 // When platform recovery is not enabled, still boot to platform default file path.\r
1069 //\r
1070 EfiBootManagerProcessLoadOption (&PlatformDefaultBootOption);\r
1071 }\r
f4cd24da 1072 }\r
0889500c 1073 EfiBootManagerFreeLoadOption (&PlatformDefaultBootOption);\r
68456d8a
RN
1074\r
1075 DEBUG ((EFI_D_ERROR, "[Bds] Unable to boot!\n"));\r
1010873b 1076 PlatformBootManagerUnableToBoot ();\r
68456d8a 1077 CpuDeadLoop ();\r
f4cd24da
RN
1078}\r
1079\r
1080/**\r
1081 Set the variable and report the error through status code upon failure.\r
1082\r
1083 @param VariableName A Null-terminated string that is the name of the vendor's variable.\r
1084 Each VariableName is unique for each VendorGuid. VariableName must\r
1085 contain 1 or more characters. If VariableName is an empty string,\r
1086 then EFI_INVALID_PARAMETER is returned.\r
1087 @param VendorGuid A unique identifier for the vendor.\r
1088 @param Attributes Attributes bitmask to set for the variable.\r
d1102dba 1089 @param DataSize The size in bytes of the Data buffer. Unless the EFI_VARIABLE_APPEND_WRITE,\r
4073f85d 1090 or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute is set, a size of zero\r
d1102dba
LG
1091 causes the variable to be deleted. When the EFI_VARIABLE_APPEND_WRITE attribute is\r
1092 set, then a SetVariable() call with a DataSize of zero will not cause any change to\r
1093 the variable value (the timestamp associated with the variable may be updated however\r
1094 even if no new data value is provided,see the description of the\r
1095 EFI_VARIABLE_AUTHENTICATION_2 descriptor below. In this case the DataSize will not\r
1096 be zero since the EFI_VARIABLE_AUTHENTICATION_2 descriptor will be populated).\r
f4cd24da
RN
1097 @param Data The contents for the variable.\r
1098\r
1099 @retval EFI_SUCCESS The firmware has successfully stored the variable and its data as\r
1100 defined by the Attributes.\r
1101 @retval EFI_INVALID_PARAMETER An invalid combination of attribute bits, name, and GUID was supplied, or the\r
1102 DataSize exceeds the maximum allowed.\r
1103 @retval EFI_INVALID_PARAMETER VariableName is an empty string.\r
1104 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.\r
1105 @retval EFI_DEVICE_ERROR The variable could not be retrieved due to a hardware error.\r
1106 @retval EFI_WRITE_PROTECTED The variable in question is read-only.\r
1107 @retval EFI_WRITE_PROTECTED The variable in question cannot be deleted.\r
4073f85d
ZC
1108 @retval EFI_SECURITY_VIOLATION The variable could not be written due to EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS\r
1109 being set, but the AuthInfo does NOT pass the validation check carried out by the firmware.\r
f4cd24da
RN
1110\r
1111 @retval EFI_NOT_FOUND The variable trying to be updated or deleted was not found.\r
1112**/\r
1113EFI_STATUS\r
1114BdsDxeSetVariableAndReportStatusCodeOnError (\r
1115 IN CHAR16 *VariableName,\r
1116 IN EFI_GUID *VendorGuid,\r
1117 IN UINT32 Attributes,\r
1118 IN UINTN DataSize,\r
1119 IN VOID *Data\r
1120 )\r
1121{\r
1122 EFI_STATUS Status;\r
1123 EDKII_SET_VARIABLE_STATUS *SetVariableStatus;\r
1124 UINTN NameSize;\r
1125\r
1126 Status = gRT->SetVariable (\r
1127 VariableName,\r
1128 VendorGuid,\r
1129 Attributes,\r
1130 DataSize,\r
1131 Data\r
1132 );\r
1133 if (EFI_ERROR (Status)) {\r
1134 NameSize = StrSize (VariableName);\r
1135 SetVariableStatus = AllocatePool (sizeof (EDKII_SET_VARIABLE_STATUS) + NameSize + DataSize);\r
1136 if (SetVariableStatus != NULL) {\r
1137 CopyGuid (&SetVariableStatus->Guid, VendorGuid);\r
1138 SetVariableStatus->NameSize = NameSize;\r
1139 SetVariableStatus->DataSize = DataSize;\r
1140 SetVariableStatus->SetStatus = Status;\r
1141 SetVariableStatus->Attributes = Attributes;\r
1142 CopyMem (SetVariableStatus + 1, VariableName, NameSize);\r
1143 CopyMem (((UINT8 *) (SetVariableStatus + 1)) + NameSize, Data, DataSize);\r
1144\r
1145 REPORT_STATUS_CODE_EX (\r
1146 EFI_ERROR_CODE,\r
1147 PcdGet32 (PcdErrorCodeSetVariable),\r
1148 0,\r
1149 NULL,\r
1150 &gEdkiiStatusCodeDataTypeVariableGuid,\r
1151 SetVariableStatus,\r
1152 sizeof (EDKII_SET_VARIABLE_STATUS) + NameSize + DataSize\r
1153 );\r
1154\r
1155 FreePool (SetVariableStatus);\r
1156 }\r
1157 }\r
1158\r
1159 return Status;\r
1160}\r