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