]>
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 | |
43311062 | 8 | Copyright (c) 2004 - 2019, Intel Corporation. All rights reserved.<BR>\r |
b1564648 | 9 | (C) Copyright 2016-2019 Hewlett Packard Enterprise Development LP<BR>\r |
e58f1ae5 | 10 | (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>\r |
9d510e61 | 11 | SPDX-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 | |
26 | EFI_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 | |
33 | EFI_EVENT gConnectConInEvent = NULL;\r | |
34 | \r | |
35 | ///\r | |
36 | /// The read-only variables defined in UEFI Spec.\r | |
37 | ///\r | |
38 | CHAR16 *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 |
46 | CHAR16 *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 | |
61 | VOID\r | |
62 | EFIAPI\r | |
63 | BdsDxeOnConnectConInCallBack (\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 | |
91 | VOID\r | |
92 | EFIAPI\r | |
93 | CheckDeferredLoadImageOnReadyToBoot (\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 | |
171 | EFI_STATUS\r | |
172 | EFIAPI\r | |
173 | BdsInitialize (\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 | |
219 | EFI_STATUS\r | |
220 | BdsWaitForSingleEvent (\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 | |
277 | VOID\r | |
278 | BdsReadKeys (\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 | |
309 | VOID\r | |
310 | BdsWait (\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 | |
4d05a4b7 LE |
344 | \r |
345 | //\r | |
346 | // If the platform configured a nonzero and finite time-out, and we have\r | |
347 | // actually reached that, report 100% completion to the platform.\r | |
348 | //\r | |
349 | // Note that the (TimeoutRemain == 0) condition excludes\r | |
350 | // PcdPlatformBootTimeOut=0xFFFF, and that's deliberate.\r | |
351 | //\r | |
352 | if (PcdGet16 (PcdPlatformBootTimeOut) != 0 && TimeoutRemain == 0) {\r | |
353 | PlatformBootManagerWaitCallback (0);\r | |
354 | }\r | |
f4cd24da RN |
355 | DEBUG ((EFI_D_INFO, "[Bds]Exit the waiting!\n"));\r |
356 | }\r | |
357 | \r | |
358 | /**\r | |
359 | Attempt to boot each boot option in the BootOptions array.\r | |
360 | \r | |
361 | @param BootOptions Input boot option array.\r | |
362 | @param BootOptionCount Input boot option count.\r | |
68456d8a | 363 | @param BootManagerMenu Input boot manager menu.\r |
f4cd24da RN |
364 | \r |
365 | @retval TRUE Successfully boot one of the boot options.\r | |
366 | @retval FALSE Failed boot any of the boot options.\r | |
367 | **/\r | |
368 | BOOLEAN\r | |
68456d8a | 369 | BootBootOptions (\r |
f4cd24da | 370 | IN EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions,\r |
68456d8a | 371 | IN UINTN BootOptionCount,\r |
e58f1ae5 | 372 | IN EFI_BOOT_MANAGER_LOAD_OPTION *BootManagerMenu OPTIONAL\r |
f4cd24da RN |
373 | )\r |
374 | {\r | |
375 | UINTN Index;\r | |
376 | \r | |
45b57c12 DB |
377 | //\r |
378 | // Report Status Code to indicate BDS starts attempting booting from the UEFI BootOrder list.\r | |
379 | //\r | |
380 | REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_PC_ATTEMPT_BOOT_ORDER_EVENT));\r | |
381 | \r | |
f4cd24da RN |
382 | //\r |
383 | // Attempt boot each boot option\r | |
384 | //\r | |
385 | for (Index = 0; Index < BootOptionCount; Index++) {\r | |
386 | //\r | |
387 | // According to EFI Specification, if a load option is not marked\r | |
388 | // as LOAD_OPTION_ACTIVE, the boot manager will not automatically\r | |
389 | // load the option.\r | |
390 | //\r | |
391 | if ((BootOptions[Index].Attributes & LOAD_OPTION_ACTIVE) == 0) {\r | |
392 | continue;\r | |
393 | }\r | |
394 | \r | |
395 | //\r | |
396 | // Boot#### load options with LOAD_OPTION_CATEGORY_APP are executables which are not\r | |
397 | // part of the normal boot processing. Boot options with reserved category values will be\r | |
398 | // ignored by the boot manager.\r | |
399 | //\r | |
400 | if ((BootOptions[Index].Attributes & LOAD_OPTION_CATEGORY) != LOAD_OPTION_CATEGORY_BOOT) {\r | |
401 | continue;\r | |
402 | }\r | |
403 | \r | |
404 | //\r | |
405 | // All the driver options should have been processed since\r | |
406 | // now boot will be performed.\r | |
407 | //\r | |
408 | EfiBootManagerBoot (&BootOptions[Index]);\r | |
409 | \r | |
410 | //\r | |
311b5a6f ED |
411 | // If the boot via Boot#### returns with a status of EFI_SUCCESS, platform firmware\r |
412 | // supports boot manager menu, and if firmware is configured to boot in an\r | |
413 | // interactive mode, the boot manager will stop processing the BootOrder variable and\r | |
414 | // present a boot manager menu to the user.\r | |
f4cd24da | 415 | //\r |
e58f1ae5 | 416 | if ((BootManagerMenu != NULL) && (BootOptions[Index].Status == EFI_SUCCESS)) {\r |
68456d8a | 417 | EfiBootManagerBoot (BootManagerMenu);\r |
f4cd24da RN |
418 | break;\r |
419 | }\r | |
420 | }\r | |
421 | \r | |
422 | return (BOOLEAN) (Index < BootOptionCount);\r | |
423 | }\r | |
424 | \r | |
425 | /**\r | |
68456d8a | 426 | The function will load and start every Driver####, SysPrep#### or PlatformRecovery####.\r |
f4cd24da | 427 | \r |
1634214d RN |
428 | @param LoadOptions Load option array.\r |
429 | @param LoadOptionCount Load option count.\r | |
f4cd24da RN |
430 | **/\r |
431 | VOID\r | |
1634214d RN |
432 | ProcessLoadOptions (\r |
433 | IN EFI_BOOT_MANAGER_LOAD_OPTION *LoadOptions,\r | |
434 | IN UINTN LoadOptionCount\r | |
f4cd24da RN |
435 | )\r |
436 | {\r | |
1634214d RN |
437 | EFI_STATUS Status;\r |
438 | UINTN Index;\r | |
439 | BOOLEAN ReconnectAll;\r | |
440 | EFI_BOOT_MANAGER_LOAD_OPTION_TYPE LoadOptionType;\r | |
f4cd24da | 441 | \r |
68456d8a | 442 | ReconnectAll = FALSE;\r |
1634214d | 443 | LoadOptionType = LoadOptionTypeMax;\r |
f4cd24da RN |
444 | \r |
445 | //\r | |
446 | // Process the driver option\r | |
447 | //\r | |
1634214d | 448 | for (Index = 0; Index < LoadOptionCount; Index++) {\r |
f4cd24da | 449 | //\r |
1634214d | 450 | // All the load options in the array should be of the same type.\r |
f4cd24da | 451 | //\r |
68456d8a | 452 | if (Index == 0) {\r |
1634214d | 453 | LoadOptionType = LoadOptions[Index].OptionType;\r |
f4cd24da | 454 | }\r |
1634214d | 455 | ASSERT (LoadOptionType == LoadOptions[Index].OptionType);\r |
de67c35c | 456 | ASSERT (LoadOptionType != LoadOptionTypeBoot);\r |
f4cd24da | 457 | \r |
1634214d | 458 | Status = EfiBootManagerProcessLoadOption (&LoadOptions[Index]);\r |
f4cd24da | 459 | \r |
de67c35c RN |
460 | //\r |
461 | // Status indicates whether the load option is loaded and executed\r | |
462 | // LoadOptions[Index].Status is what the load option returns\r | |
463 | //\r | |
68456d8a | 464 | if (!EFI_ERROR (Status)) {\r |
de67c35c RN |
465 | //\r |
466 | // Stop processing if any PlatformRecovery#### returns success.\r | |
467 | //\r | |
468 | if ((LoadOptions[Index].Status == EFI_SUCCESS) &&\r | |
469 | (LoadOptionType == LoadOptionTypePlatformRecovery)) {\r | |
68456d8a RN |
470 | break;\r |
471 | }\r | |
de67c35c RN |
472 | \r |
473 | //\r | |
474 | // Only set ReconnectAll flag when the load option executes successfully.\r | |
475 | //\r | |
476 | if (!EFI_ERROR (LoadOptions[Index].Status) &&\r | |
477 | (LoadOptions[Index].Attributes & LOAD_OPTION_FORCE_RECONNECT) != 0) {\r | |
68456d8a RN |
478 | ReconnectAll = TRUE;\r |
479 | }\r | |
f4cd24da RN |
480 | }\r |
481 | }\r | |
1634214d | 482 | \r |
f4cd24da | 483 | //\r |
1634214d RN |
484 | // If a driver load option is marked as LOAD_OPTION_FORCE_RECONNECT,\r |
485 | // then all of the EFI drivers in the system will be disconnected and\r | |
486 | // reconnected after the last driver load option is processed.\r | |
f4cd24da | 487 | //\r |
1634214d | 488 | if (ReconnectAll && LoadOptionType == LoadOptionTypeDriver) {\r |
f4cd24da RN |
489 | EfiBootManagerDisconnectAll ();\r |
490 | EfiBootManagerConnectAll ();\r | |
491 | }\r | |
f4cd24da RN |
492 | }\r |
493 | \r | |
494 | /**\r | |
495 | \r | |
d1102dba | 496 | Validate input console variable data.\r |
f4cd24da RN |
497 | \r |
498 | If found the device path is not a valid device path, remove the variable.\r | |
d1102dba | 499 | \r |
f4cd24da RN |
500 | @param VariableName Input console variable name.\r |
501 | \r | |
502 | **/\r | |
503 | VOID\r | |
504 | BdsFormalizeConsoleVariable (\r | |
505 | IN CHAR16 *VariableName\r | |
506 | )\r | |
507 | {\r | |
508 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
509 | UINTN VariableSize;\r | |
510 | EFI_STATUS Status;\r | |
511 | \r | |
512 | GetEfiGlobalVariable2 (VariableName, (VOID **) &DevicePath, &VariableSize);\r | |
d1102dba | 513 | if ((DevicePath != NULL) && !IsDevicePathValid (DevicePath, VariableSize)) {\r |
f4cd24da RN |
514 | Status = gRT->SetVariable (\r |
515 | VariableName,\r | |
516 | &gEfiGlobalVariableGuid,\r | |
517 | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r | |
518 | 0,\r | |
519 | NULL\r | |
520 | );\r | |
521 | //\r | |
522 | // Deleting variable with current variable implementation shouldn't fail.\r | |
523 | //\r | |
524 | ASSERT_EFI_ERROR (Status);\r | |
525 | }\r | |
526 | \r | |
527 | if (DevicePath != NULL) {\r | |
528 | FreePool (DevicePath);\r | |
529 | }\r | |
530 | }\r | |
531 | \r | |
532 | /**\r | |
d1102dba LG |
533 | Formalize OsIndication related variables.\r |
534 | \r | |
535 | For OsIndicationsSupported, Create a BS/RT/UINT64 variable to report caps\r | |
f4cd24da | 536 | Delete OsIndications variable if it is not NV/BS/RT UINT64.\r |
d1102dba | 537 | \r |
f4cd24da RN |
538 | Item 3 is used to solve case when OS corrupts OsIndications. Here simply delete this NV variable.\r |
539 | \r | |
e58f1ae5 SW |
540 | Create a boot option for BootManagerMenu if it hasn't been created yet\r |
541 | \r | |
f4cd24da | 542 | **/\r |
d1102dba | 543 | VOID\r |
f4cd24da RN |
544 | BdsFormalizeOSIndicationVariable (\r |
545 | VOID\r | |
546 | )\r | |
547 | {\r | |
e58f1ae5 SW |
548 | EFI_STATUS Status;\r |
549 | UINT64 OsIndicationSupport;\r | |
550 | UINT64 OsIndication;\r | |
551 | UINTN DataSize;\r | |
552 | UINT32 Attributes;\r | |
553 | EFI_BOOT_MANAGER_LOAD_OPTION BootManagerMenu;\r | |
f4cd24da RN |
554 | \r |
555 | //\r | |
556 | // OS indicater support variable\r | |
557 | //\r | |
e58f1ae5 SW |
558 | Status = EfiBootManagerGetBootManagerMenu (&BootManagerMenu);\r |
559 | if (Status != EFI_NOT_FOUND) {\r | |
0889500c | 560 | OsIndicationSupport = EFI_OS_INDICATIONS_BOOT_TO_FW_UI;\r |
e58f1ae5 SW |
561 | EfiBootManagerFreeLoadOption (&BootManagerMenu);\r |
562 | } else {\r | |
0889500c ZG |
563 | OsIndicationSupport = 0;\r |
564 | }\r | |
565 | \r | |
566 | if (PcdGetBool (PcdPlatformRecoverySupport)) {\r | |
567 | OsIndicationSupport |= EFI_OS_INDICATIONS_START_PLATFORM_RECOVERY;\r | |
e58f1ae5 SW |
568 | }\r |
569 | \r | |
43311062 WX |
570 | if (PcdGetBool(PcdCapsuleOnDiskSupport)) {\r |
571 | OsIndicationSupport |= EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED;\r | |
572 | }\r | |
573 | \r | |
f4cd24da | 574 | Status = gRT->SetVariable (\r |
cc4812f6 | 575 | EFI_OS_INDICATIONS_SUPPORT_VARIABLE_NAME,\r |
f4cd24da RN |
576 | &gEfiGlobalVariableGuid,\r |
577 | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r | |
578 | sizeof(UINT64),\r | |
579 | &OsIndicationSupport\r | |
580 | );\r | |
581 | //\r | |
582 | // Platform needs to make sure setting volatile variable before calling 3rd party code shouldn't fail.\r | |
583 | //\r | |
584 | ASSERT_EFI_ERROR (Status);\r | |
585 | \r | |
586 | //\r | |
587 | // If OsIndications is invalid, remove it.\r | |
588 | // Invalid case\r | |
589 | // 1. Data size != UINT64\r | |
590 | // 2. OsIndication value inconsistence\r | |
591 | // 3. OsIndication attribute inconsistence\r | |
592 | //\r | |
593 | OsIndication = 0;\r | |
594 | Attributes = 0;\r | |
595 | DataSize = sizeof(UINT64);\r | |
596 | Status = gRT->GetVariable (\r | |
cc4812f6 | 597 | EFI_OS_INDICATIONS_VARIABLE_NAME,\r |
f4cd24da RN |
598 | &gEfiGlobalVariableGuid,\r |
599 | &Attributes,\r | |
600 | &DataSize,\r | |
601 | &OsIndication\r | |
602 | );\r | |
603 | if (Status == EFI_NOT_FOUND) {\r | |
604 | return;\r | |
605 | }\r | |
606 | \r | |
607 | if ((DataSize != sizeof (OsIndication)) ||\r | |
608 | ((OsIndication & ~OsIndicationSupport) != 0) ||\r | |
609 | (Attributes != (EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE))\r | |
610 | ){\r | |
611 | \r | |
612 | DEBUG ((EFI_D_ERROR, "[Bds] Unformalized OsIndications variable exists. Delete it\n"));\r | |
613 | Status = gRT->SetVariable (\r | |
cc4812f6 | 614 | EFI_OS_INDICATIONS_VARIABLE_NAME,\r |
f4cd24da RN |
615 | &gEfiGlobalVariableGuid,\r |
616 | 0,\r | |
617 | 0,\r | |
618 | NULL\r | |
619 | );\r | |
620 | //\r | |
621 | // Deleting variable with current variable implementation shouldn't fail.\r | |
622 | //\r | |
623 | ASSERT_EFI_ERROR(Status);\r | |
624 | }\r | |
625 | }\r | |
626 | \r | |
627 | /**\r | |
628 | \r | |
d1102dba | 629 | Validate variables.\r |
f4cd24da RN |
630 | \r |
631 | **/\r | |
d1102dba | 632 | VOID\r |
f4cd24da RN |
633 | BdsFormalizeEfiGlobalVariable (\r |
634 | VOID\r | |
635 | )\r | |
636 | {\r | |
637 | //\r | |
638 | // Validate Console variable.\r | |
639 | //\r | |
cc4812f6 RN |
640 | BdsFormalizeConsoleVariable (EFI_CON_IN_VARIABLE_NAME);\r |
641 | BdsFormalizeConsoleVariable (EFI_CON_OUT_VARIABLE_NAME);\r | |
642 | BdsFormalizeConsoleVariable (EFI_ERR_OUT_VARIABLE_NAME);\r | |
f4cd24da RN |
643 | \r |
644 | //\r | |
645 | // Validate OSIndication related variable.\r | |
646 | //\r | |
647 | BdsFormalizeOSIndicationVariable ();\r | |
648 | }\r | |
649 | \r | |
f4cd24da RN |
650 | /**\r |
651 | \r | |
652 | Service routine for BdsInstance->Entry(). Devices are connected, the\r | |
653 | consoles are initialized, and the boot options are tried.\r | |
654 | \r | |
655 | @param This Protocol Instance structure.\r | |
656 | \r | |
657 | **/\r | |
658 | VOID\r | |
659 | EFIAPI\r | |
660 | BdsEntry (\r | |
661 | IN EFI_BDS_ARCH_PROTOCOL *This\r | |
662 | )\r | |
663 | {\r | |
1634214d RN |
664 | EFI_BOOT_MANAGER_LOAD_OPTION *LoadOptions;\r |
665 | UINTN LoadOptionCount;\r | |
f4cd24da RN |
666 | CHAR16 *FirmwareVendor;\r |
667 | EFI_EVENT HotkeyTriggered;\r | |
668 | UINT64 OsIndication;\r | |
669 | UINTN DataSize;\r | |
670 | EFI_STATUS Status;\r | |
671 | UINT32 BootOptionSupport;\r | |
672 | UINT16 BootTimeOut;\r | |
673 | EDKII_VARIABLE_LOCK_PROTOCOL *VariableLock;\r | |
674 | UINTN Index;\r | |
d175f4e6 | 675 | EFI_BOOT_MANAGER_LOAD_OPTION LoadOption;\r |
f4cd24da RN |
676 | UINT16 *BootNext;\r |
677 | CHAR16 BootNextVariableName[sizeof ("Boot####")];\r | |
1634214d RN |
678 | EFI_BOOT_MANAGER_LOAD_OPTION BootManagerMenu;\r |
679 | BOOLEAN BootFwUi;\r | |
68456d8a RN |
680 | BOOLEAN PlatformRecovery;\r |
681 | BOOLEAN BootSuccess;\r | |
d175f4e6 | 682 | EFI_DEVICE_PATH_PROTOCOL *FilePath;\r |
e58f1ae5 | 683 | EFI_STATUS BootManagerMenuStatus;\r |
0889500c | 684 | EFI_BOOT_MANAGER_LOAD_OPTION PlatformDefaultBootOption;\r |
f4cd24da RN |
685 | \r |
686 | HotkeyTriggered = NULL;\r | |
687 | Status = EFI_SUCCESS;\r | |
68456d8a | 688 | BootSuccess = FALSE;\r |
f4cd24da RN |
689 | \r |
690 | //\r | |
691 | // Insert the performance probe\r | |
692 | //\r | |
67e9ab84 BD |
693 | PERF_CROSSMODULE_END("DXE");\r |
694 | PERF_CROSSMODULE_BEGIN("BDS");\r | |
f4cd24da RN |
695 | DEBUG ((EFI_D_INFO, "[Bds] Entry...\n"));\r |
696 | \r | |
f4cd24da RN |
697 | //\r |
698 | // Fill in FirmwareVendor and FirmwareRevision from PCDs\r | |
699 | //\r | |
700 | FirmwareVendor = (CHAR16 *) PcdGetPtr (PcdFirmwareVendor);\r | |
701 | gST->FirmwareVendor = AllocateRuntimeCopyPool (StrSize (FirmwareVendor), FirmwareVendor);\r | |
702 | ASSERT (gST->FirmwareVendor != NULL);\r | |
703 | gST->FirmwareRevision = PcdGet32 (PcdFirmwareRevision);\r | |
704 | \r | |
705 | //\r | |
706 | // Fixup Tasble CRC after we updated Firmware Vendor and Revision\r | |
707 | //\r | |
708 | gST->Hdr.CRC32 = 0;\r | |
709 | gBS->CalculateCrc32 ((VOID *) gST, sizeof (EFI_SYSTEM_TABLE), &gST->Hdr.CRC32);\r | |
710 | \r | |
711 | //\r | |
712 | // Validate Variable.\r | |
713 | //\r | |
714 | BdsFormalizeEfiGlobalVariable ();\r | |
715 | \r | |
716 | //\r | |
717 | // Mark the read-only variables if the Variable Lock protocol exists\r | |
718 | //\r | |
719 | Status = gBS->LocateProtocol (&gEdkiiVariableLockProtocolGuid, NULL, (VOID **) &VariableLock);\r | |
720 | DEBUG ((EFI_D_INFO, "[BdsDxe] Locate Variable Lock protocol - %r\n", Status));\r | |
721 | if (!EFI_ERROR (Status)) {\r | |
1a5afd71 | 722 | for (Index = 0; Index < ARRAY_SIZE (mReadOnlyVariables); Index++) {\r |
f4cd24da RN |
723 | Status = VariableLock->RequestToLock (VariableLock, mReadOnlyVariables[Index], &gEfiGlobalVariableGuid);\r |
724 | ASSERT_EFI_ERROR (Status);\r | |
725 | }\r | |
726 | }\r | |
727 | \r | |
728 | InitializeHwErrRecSupport ();\r | |
729 | \r | |
730 | //\r | |
731 | // Initialize L"Timeout" EFI global variable.\r | |
732 | //\r | |
733 | BootTimeOut = PcdGet16 (PcdPlatformBootTimeOut);\r | |
734 | if (BootTimeOut != 0xFFFF) {\r | |
735 | //\r | |
736 | // If time out value equal 0xFFFF, no need set to 0xFFFF to variable area because UEFI specification\r | |
737 | // define same behavior between no value or 0xFFFF value for L"Timeout".\r | |
738 | //\r | |
739 | BdsDxeSetVariableAndReportStatusCodeOnError (\r | |
740 | EFI_TIME_OUT_VARIABLE_NAME,\r | |
741 | &gEfiGlobalVariableGuid,\r | |
742 | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r | |
743 | sizeof (UINT16),\r | |
744 | &BootTimeOut\r | |
745 | );\r | |
746 | }\r | |
747 | \r | |
748 | //\r | |
749 | // Initialize L"BootOptionSupport" EFI global variable.\r | |
750 | // Lazy-ConIn implictly disables BDS hotkey.\r | |
751 | //\r | |
1634214d | 752 | BootOptionSupport = EFI_BOOT_OPTION_SUPPORT_APP | EFI_BOOT_OPTION_SUPPORT_SYSPREP;\r |
f4cd24da RN |
753 | if (!PcdGetBool (PcdConInConnectOnDemand)) {\r |
754 | BootOptionSupport |= EFI_BOOT_OPTION_SUPPORT_KEY;\r | |
755 | SET_BOOT_OPTION_SUPPORT_KEY_COUNT (BootOptionSupport, 3);\r | |
756 | }\r | |
757 | Status = gRT->SetVariable (\r | |
758 | EFI_BOOT_OPTION_SUPPORT_VARIABLE_NAME,\r | |
759 | &gEfiGlobalVariableGuid,\r | |
760 | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r | |
761 | sizeof (BootOptionSupport),\r | |
762 | &BootOptionSupport\r | |
763 | );\r | |
764 | //\r | |
765 | // Platform needs to make sure setting volatile variable before calling 3rd party code shouldn't fail.\r | |
766 | //\r | |
767 | ASSERT_EFI_ERROR (Status);\r | |
768 | \r | |
769 | //\r | |
0e6584e3 RN |
770 | // Cache the "BootNext" NV variable before calling any PlatformBootManagerLib APIs\r |
771 | // This could avoid the "BootNext" set by PlatformBootManagerLib be consumed in this boot.\r | |
f4cd24da RN |
772 | //\r |
773 | GetEfiGlobalVariable2 (EFI_BOOT_NEXT_VARIABLE_NAME, (VOID **) &BootNext, &DataSize);\r | |
774 | if (DataSize != sizeof (UINT16)) {\r | |
775 | if (BootNext != NULL) {\r | |
776 | FreePool (BootNext);\r | |
777 | }\r | |
778 | BootNext = NULL;\r | |
779 | }\r | |
f4cd24da RN |
780 | \r |
781 | //\r | |
782 | // Initialize the platform language variables\r | |
783 | //\r | |
784 | InitializeLanguage (TRUE);\r | |
785 | \r | |
d175f4e6 | 786 | FilePath = FileDevicePath (NULL, EFI_REMOVABLE_MEDIA_FILE_NAME);\r |
0889500c | 787 | if (FilePath == NULL) {\r |
92b96395 | 788 | DEBUG ((DEBUG_ERROR, "Fail to allocate memory for default boot file path. Unable to boot.\n"));\r |
0889500c ZG |
789 | CpuDeadLoop ();\r |
790 | }\r | |
d175f4e6 | 791 | Status = EfiBootManagerInitializeLoadOption (\r |
0889500c | 792 | &PlatformDefaultBootOption,\r |
0dc3fb06 | 793 | LoadOptionNumberUnassigned,\r |
d175f4e6 RN |
794 | LoadOptionTypePlatformRecovery,\r |
795 | LOAD_OPTION_ACTIVE,\r | |
796 | L"Default PlatformRecovery",\r | |
797 | FilePath,\r | |
798 | NULL,\r | |
799 | 0\r | |
800 | );\r | |
801 | ASSERT_EFI_ERROR (Status);\r | |
0889500c ZG |
802 | \r |
803 | //\r | |
804 | // System firmware must include a PlatformRecovery#### variable specifying\r | |
805 | // a short-form File Path Media Device Path containing the platform default\r | |
806 | // file path for removable media if the platform supports Platform Recovery.\r | |
807 | //\r | |
808 | if (PcdGetBool (PcdPlatformRecoverySupport)) {\r | |
809 | LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount, LoadOptionTypePlatformRecovery);\r | |
810 | if (EfiBootManagerFindLoadOption (&PlatformDefaultBootOption, LoadOptions, LoadOptionCount) == -1) {\r | |
811 | for (Index = 0; Index < LoadOptionCount; Index++) {\r | |
812 | //\r | |
813 | // The PlatformRecovery#### options are sorted by OptionNumber.\r | |
814 | // Find the the smallest unused number as the new OptionNumber.\r | |
815 | //\r | |
816 | if (LoadOptions[Index].OptionNumber != Index) {\r | |
817 | break;\r | |
818 | }\r | |
0dc3fb06 | 819 | }\r |
0889500c ZG |
820 | PlatformDefaultBootOption.OptionNumber = Index;\r |
821 | Status = EfiBootManagerLoadOptionToVariable (&PlatformDefaultBootOption);\r | |
822 | ASSERT_EFI_ERROR (Status);\r | |
0dc3fb06 | 823 | }\r |
0889500c | 824 | EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount);\r |
0dc3fb06 | 825 | }\r |
d175f4e6 RN |
826 | FreePool (FilePath);\r |
827 | \r | |
f4cd24da RN |
828 | //\r |
829 | // Report Status Code to indicate connecting drivers will happen\r | |
830 | //\r | |
831 | REPORT_STATUS_CODE (\r | |
832 | EFI_PROGRESS_CODE,\r | |
833 | (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_PC_BEGIN_CONNECTING_DRIVERS)\r | |
834 | );\r | |
835 | \r | |
8537bd7e RN |
836 | //\r |
837 | // Initialize ConnectConIn event before calling platform code.\r | |
838 | //\r | |
839 | if (PcdGetBool (PcdConInConnectOnDemand)) {\r | |
840 | Status = gBS->CreateEventEx (\r | |
841 | EVT_NOTIFY_SIGNAL,\r | |
842 | TPL_CALLBACK,\r | |
843 | BdsDxeOnConnectConInCallBack,\r | |
844 | NULL,\r | |
845 | &gConnectConInEventGuid,\r | |
846 | &gConnectConInEvent\r | |
847 | );\r | |
848 | if (EFI_ERROR (Status)) {\r | |
849 | gConnectConInEvent = NULL;\r | |
850 | }\r | |
851 | }\r | |
852 | \r | |
f4cd24da RN |
853 | //\r |
854 | // Do the platform init, can be customized by OEM/IBV\r | |
855 | // Possible things that can be done in PlatformBootManagerBeforeConsole:\r | |
856 | // > Update console variable: 1. include hot-plug devices; 2. Clear ConIn and add SOL for AMT\r | |
857 | // > Register new Driver#### or Boot####\r | |
d1102dba | 858 | // > Register new Key####: e.g.: F12\r |
f4cd24da RN |
859 | // > Signal ReadyToLock event\r |
860 | // > Authentication action: 1. connect Auth devices; 2. Identify auto logon user.\r | |
861 | //\r | |
67e9ab84 | 862 | PERF_INMODULE_BEGIN("PlatformBootManagerBeforeConsole");\r |
f4cd24da | 863 | PlatformBootManagerBeforeConsole ();\r |
67e9ab84 | 864 | PERF_INMODULE_END("PlatformBootManagerBeforeConsole");\r |
f4cd24da RN |
865 | \r |
866 | //\r | |
867 | // Initialize hotkey service\r | |
868 | //\r | |
869 | EfiBootManagerStartHotkeyService (&HotkeyTriggered);\r | |
870 | \r | |
871 | //\r | |
1634214d | 872 | // Execute Driver Options\r |
f4cd24da | 873 | //\r |
1634214d RN |
874 | LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount, LoadOptionTypeDriver);\r |
875 | ProcessLoadOptions (LoadOptions, LoadOptionCount);\r | |
876 | EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount);\r | |
f4cd24da RN |
877 | \r |
878 | //\r | |
879 | // Connect consoles\r | |
880 | //\r | |
67e9ab84 | 881 | PERF_INMODULE_BEGIN("EfiBootManagerConnectAllDefaultConsoles");\r |
f4cd24da RN |
882 | if (PcdGetBool (PcdConInConnectOnDemand)) {\r |
883 | EfiBootManagerConnectConsoleVariable (ConOut);\r | |
884 | EfiBootManagerConnectConsoleVariable (ErrOut);\r | |
f4cd24da | 885 | //\r |
8537bd7e | 886 | // Do not connect ConIn devices when lazy ConIn feature is ON.\r |
f4cd24da | 887 | //\r |
f4cd24da RN |
888 | } else {\r |
889 | EfiBootManagerConnectAllDefaultConsoles ();\r | |
890 | }\r | |
67e9ab84 | 891 | PERF_INMODULE_END("EfiBootManagerConnectAllDefaultConsoles");\r |
f4cd24da RN |
892 | \r |
893 | //\r | |
894 | // Do the platform specific action after the console is ready\r | |
895 | // Possible things that can be done in PlatformBootManagerAfterConsole:\r | |
896 | // > Console post action:\r | |
897 | // > Dynamically switch output mode from 100x31 to 80x25 for certain senarino\r | |
898 | // > Signal console ready platform customized event\r | |
899 | // > Run diagnostics like memory testing\r | |
900 | // > Connect certain devices\r | |
901 | // > Dispatch aditional option roms\r | |
902 | // > Special boot: e.g.: USB boot, enter UI\r | |
d1102dba | 903 | //\r |
67e9ab84 | 904 | PERF_INMODULE_BEGIN("PlatformBootManagerAfterConsole");\r |
f4cd24da | 905 | PlatformBootManagerAfterConsole ();\r |
67e9ab84 | 906 | PERF_INMODULE_END("PlatformBootManagerAfterConsole");\r |
6fb8b96d KM |
907 | \r |
908 | //\r | |
909 | // If any component set PcdTestKeyUsed to TRUE because use of a test key\r | |
910 | // was detected, then display a warning message on the debug log and the console\r | |
911 | //\r | |
912 | if (PcdGetBool (PcdTestKeyUsed)) {\r | |
913 | DEBUG ((DEBUG_ERROR, "**********************************\n"));\r | |
914 | DEBUG ((DEBUG_ERROR, "** WARNING: Test Key is used. **\n"));\r | |
915 | DEBUG ((DEBUG_ERROR, "**********************************\n"));\r | |
916 | Print (L"** WARNING: Test Key is used. **\n");\r | |
917 | }\r | |
918 | \r | |
68456d8a RN |
919 | //\r |
920 | // Boot to Boot Manager Menu when EFI_OS_INDICATIONS_BOOT_TO_FW_UI is set. Skip HotkeyBoot\r | |
921 | //\r | |
922 | DataSize = sizeof (UINT64);\r | |
923 | Status = gRT->GetVariable (\r | |
924 | EFI_OS_INDICATIONS_VARIABLE_NAME,\r | |
925 | &gEfiGlobalVariableGuid,\r | |
926 | NULL,\r | |
927 | &DataSize,\r | |
928 | &OsIndication\r | |
929 | );\r | |
930 | if (EFI_ERROR (Status)) {\r | |
931 | OsIndication = 0;\r | |
932 | }\r | |
f4cd24da RN |
933 | \r |
934 | DEBUG_CODE (\r | |
1634214d | 935 | EFI_BOOT_MANAGER_LOAD_OPTION_TYPE LoadOptionType;\r |
68456d8a | 936 | DEBUG ((EFI_D_INFO, "[Bds]OsIndication: %016x\n", OsIndication));\r |
1634214d RN |
937 | DEBUG ((EFI_D_INFO, "[Bds]=============Begin Load Options Dumping ...=============\n"));\r |
938 | for (LoadOptionType = 0; LoadOptionType < LoadOptionTypeMax; LoadOptionType++) {\r | |
f4cd24da | 939 | DEBUG ((\r |
1634214d RN |
940 | EFI_D_INFO, " %s Options:\n",\r |
941 | mBdsLoadOptionName[LoadOptionType]\r | |
f4cd24da | 942 | ));\r |
1634214d RN |
943 | LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount, LoadOptionType);\r |
944 | for (Index = 0; Index < LoadOptionCount; Index++) {\r | |
945 | DEBUG ((\r | |
946 | EFI_D_INFO, " %s%04x: %s \t\t 0x%04x\n",\r | |
947 | mBdsLoadOptionName[LoadOptionType],\r | |
948 | LoadOptions[Index].OptionNumber,\r | |
949 | LoadOptions[Index].Description,\r | |
950 | LoadOptions[Index].Attributes\r | |
951 | ));\r | |
952 | }\r | |
953 | EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount);\r | |
f4cd24da | 954 | }\r |
1634214d RN |
955 | DEBUG ((EFI_D_INFO, "[Bds]=============End Load Options Dumping=============\n"));\r |
956 | );\r | |
f4cd24da RN |
957 | \r |
958 | //\r | |
e58f1ae5 | 959 | // BootManagerMenu doesn't contain the correct information when return status is EFI_NOT_FOUND.\r |
f4cd24da | 960 | //\r |
e58f1ae5 | 961 | BootManagerMenuStatus = EfiBootManagerGetBootManagerMenu (&BootManagerMenu);\r |
1634214d | 962 | \r |
68456d8a RN |
963 | BootFwUi = (BOOLEAN) ((OsIndication & EFI_OS_INDICATIONS_BOOT_TO_FW_UI) != 0);\r |
964 | PlatformRecovery = (BOOLEAN) ((OsIndication & EFI_OS_INDICATIONS_START_PLATFORM_RECOVERY) != 0);\r | |
1634214d RN |
965 | //\r |
966 | // Clear EFI_OS_INDICATIONS_BOOT_TO_FW_UI to acknowledge OS\r | |
d1102dba | 967 | //\r |
68456d8a RN |
968 | if (BootFwUi || PlatformRecovery) {\r |
969 | OsIndication &= ~((UINT64) (EFI_OS_INDICATIONS_BOOT_TO_FW_UI | EFI_OS_INDICATIONS_START_PLATFORM_RECOVERY));\r | |
f4cd24da | 970 | Status = gRT->SetVariable (\r |
cc4812f6 | 971 | EFI_OS_INDICATIONS_VARIABLE_NAME,\r |
f4cd24da RN |
972 | &gEfiGlobalVariableGuid,\r |
973 | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r | |
974 | sizeof(UINT64),\r | |
975 | &OsIndication\r | |
976 | );\r | |
977 | //\r | |
978 | // Changing the content without increasing its size with current variable implementation shouldn't fail.\r | |
979 | //\r | |
980 | ASSERT_EFI_ERROR (Status);\r | |
1634214d | 981 | }\r |
f4cd24da | 982 | \r |
1634214d RN |
983 | //\r |
984 | // Launch Boot Manager Menu directly when EFI_OS_INDICATIONS_BOOT_TO_FW_UI is set. Skip HotkeyBoot\r | |
985 | //\r | |
e58f1ae5 | 986 | if (BootFwUi && (BootManagerMenuStatus != EFI_NOT_FOUND)) {\r |
f4cd24da RN |
987 | //\r |
988 | // Follow generic rule, Call BdsDxeOnConnectConInCallBack to connect ConIn before enter UI\r | |
989 | //\r | |
990 | if (PcdGetBool (PcdConInConnectOnDemand)) {\r | |
991 | BdsDxeOnConnectConInCallBack (NULL, NULL);\r | |
992 | }\r | |
993 | \r | |
994 | //\r | |
1634214d | 995 | // Directly enter the setup page.\r |
f4cd24da | 996 | //\r |
1634214d | 997 | EfiBootManagerBoot (&BootManagerMenu);\r |
f4cd24da RN |
998 | }\r |
999 | \r | |
68456d8a RN |
1000 | if (!PlatformRecovery) {\r |
1001 | //\r | |
1002 | // Execute SysPrep####\r | |
1003 | //\r | |
1004 | LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount, LoadOptionTypeSysPrep);\r | |
1005 | ProcessLoadOptions (LoadOptions, LoadOptionCount);\r | |
1006 | EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount);\r | |
1634214d | 1007 | \r |
68456d8a RN |
1008 | //\r |
1009 | // Execute Key####\r | |
1010 | //\r | |
67e9ab84 | 1011 | PERF_INMODULE_BEGIN ("BdsWait");\r |
68456d8a | 1012 | BdsWait (HotkeyTriggered);\r |
67e9ab84 | 1013 | PERF_INMODULE_END ("BdsWait");\r |
68456d8a RN |
1014 | //\r |
1015 | // BdsReadKeys() can be removed after all keyboard drivers invoke callback in timer callback.\r | |
1016 | //\r | |
1017 | BdsReadKeys ();\r | |
1634214d | 1018 | \r |
68456d8a | 1019 | EfiBootManagerHotkeyBoot ();\r |
1634214d | 1020 | \r |
68456d8a | 1021 | if (BootNext != NULL) {\r |
0e6584e3 RN |
1022 | //\r |
1023 | // Delete "BootNext" NV variable before transferring control to it to prevent loops.\r | |
1024 | //\r | |
1025 | Status = gRT->SetVariable (\r | |
1026 | EFI_BOOT_NEXT_VARIABLE_NAME,\r | |
1027 | &gEfiGlobalVariableGuid,\r | |
1028 | 0,\r | |
1029 | 0,\r | |
1030 | NULL\r | |
1031 | );\r | |
1032 | //\r | |
1033 | // Deleting NV variable shouldn't fail unless it doesn't exist.\r | |
1034 | //\r | |
1035 | ASSERT (Status == EFI_SUCCESS || Status == EFI_NOT_FOUND);\r | |
1036 | \r | |
1037 | //\r | |
1038 | // Boot to "BootNext"\r | |
1039 | //\r | |
68456d8a RN |
1040 | UnicodeSPrint (BootNextVariableName, sizeof (BootNextVariableName), L"Boot%04x", *BootNext);\r |
1041 | Status = EfiBootManagerVariableToLoadOption (BootNextVariableName, &LoadOption);\r | |
1042 | if (!EFI_ERROR (Status)) {\r | |
d175f4e6 RN |
1043 | EfiBootManagerBoot (&LoadOption);\r |
1044 | EfiBootManagerFreeLoadOption (&LoadOption);\r | |
d1102dba | 1045 | if ((LoadOption.Status == EFI_SUCCESS) &&\r |
e58f1ae5 SW |
1046 | (BootManagerMenuStatus != EFI_NOT_FOUND) &&\r |
1047 | (LoadOption.OptionNumber != BootManagerMenu.OptionNumber)) {\r | |
68456d8a RN |
1048 | //\r |
1049 | // Boot to Boot Manager Menu upon EFI_SUCCESS\r | |
f5cbc197 | 1050 | // Exception: Do not boot again when the BootNext points to Boot Manager Menu.\r |
68456d8a RN |
1051 | //\r |
1052 | EfiBootManagerBoot (&BootManagerMenu);\r | |
1053 | }\r | |
f4cd24da RN |
1054 | }\r |
1055 | }\r | |
68456d8a RN |
1056 | \r |
1057 | do {\r | |
1058 | //\r | |
1059 | // Retry to boot if any of the boot succeeds\r | |
1060 | //\r | |
1061 | LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount, LoadOptionTypeBoot);\r | |
e58f1ae5 | 1062 | BootSuccess = BootBootOptions (LoadOptions, LoadOptionCount, (BootManagerMenuStatus != EFI_NOT_FOUND) ? &BootManagerMenu : NULL);\r |
68456d8a RN |
1063 | EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount);\r |
1064 | } while (BootSuccess);\r | |
f4cd24da RN |
1065 | }\r |
1066 | \r | |
f50db933 RN |
1067 | if (BootManagerMenuStatus != EFI_NOT_FOUND) {\r |
1068 | EfiBootManagerFreeLoadOption (&BootManagerMenu);\r | |
1069 | }\r | |
1070 | \r | |
68456d8a | 1071 | if (!BootSuccess) {\r |
b1564648 | 1072 | if (PcdGetBool (PcdPlatformRecoverySupport)) {\r |
0889500c ZG |
1073 | LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount, LoadOptionTypePlatformRecovery);\r |
1074 | ProcessLoadOptions (LoadOptions, LoadOptionCount);\r | |
1075 | EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount);\r | |
1076 | } else {\r | |
1077 | //\r | |
1078 | // When platform recovery is not enabled, still boot to platform default file path.\r | |
1079 | //\r | |
1080 | EfiBootManagerProcessLoadOption (&PlatformDefaultBootOption);\r | |
1081 | }\r | |
f4cd24da | 1082 | }\r |
0889500c | 1083 | EfiBootManagerFreeLoadOption (&PlatformDefaultBootOption);\r |
68456d8a RN |
1084 | \r |
1085 | DEBUG ((EFI_D_ERROR, "[Bds] Unable to boot!\n"));\r | |
1010873b | 1086 | PlatformBootManagerUnableToBoot ();\r |
68456d8a | 1087 | CpuDeadLoop ();\r |
f4cd24da RN |
1088 | }\r |
1089 | \r | |
1090 | /**\r | |
1091 | Set the variable and report the error through status code upon failure.\r | |
1092 | \r | |
1093 | @param VariableName A Null-terminated string that is the name of the vendor's variable.\r | |
1094 | Each VariableName is unique for each VendorGuid. VariableName must\r | |
1095 | contain 1 or more characters. If VariableName is an empty string,\r | |
1096 | then EFI_INVALID_PARAMETER is returned.\r | |
1097 | @param VendorGuid A unique identifier for the vendor.\r | |
1098 | @param Attributes Attributes bitmask to set for the variable.\r | |
d1102dba | 1099 | @param DataSize The size in bytes of the Data buffer. Unless the EFI_VARIABLE_APPEND_WRITE,\r |
4073f85d | 1100 | or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute is set, a size of zero\r |
d1102dba LG |
1101 | causes the variable to be deleted. When the EFI_VARIABLE_APPEND_WRITE attribute is\r |
1102 | set, then a SetVariable() call with a DataSize of zero will not cause any change to\r | |
1103 | the variable value (the timestamp associated with the variable may be updated however\r | |
1104 | even if no new data value is provided,see the description of the\r | |
1105 | EFI_VARIABLE_AUTHENTICATION_2 descriptor below. In this case the DataSize will not\r | |
1106 | be zero since the EFI_VARIABLE_AUTHENTICATION_2 descriptor will be populated).\r | |
f4cd24da RN |
1107 | @param Data The contents for the variable.\r |
1108 | \r | |
1109 | @retval EFI_SUCCESS The firmware has successfully stored the variable and its data as\r | |
1110 | defined by the Attributes.\r | |
1111 | @retval EFI_INVALID_PARAMETER An invalid combination of attribute bits, name, and GUID was supplied, or the\r | |
1112 | DataSize exceeds the maximum allowed.\r | |
1113 | @retval EFI_INVALID_PARAMETER VariableName is an empty string.\r | |
1114 | @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.\r | |
1115 | @retval EFI_DEVICE_ERROR The variable could not be retrieved due to a hardware error.\r | |
1116 | @retval EFI_WRITE_PROTECTED The variable in question is read-only.\r | |
1117 | @retval EFI_WRITE_PROTECTED The variable in question cannot be deleted.\r | |
4073f85d ZC |
1118 | @retval EFI_SECURITY_VIOLATION The variable could not be written due to EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS\r |
1119 | being set, but the AuthInfo does NOT pass the validation check carried out by the firmware.\r | |
f4cd24da RN |
1120 | \r |
1121 | @retval EFI_NOT_FOUND The variable trying to be updated or deleted was not found.\r | |
1122 | **/\r | |
1123 | EFI_STATUS\r | |
1124 | BdsDxeSetVariableAndReportStatusCodeOnError (\r | |
1125 | IN CHAR16 *VariableName,\r | |
1126 | IN EFI_GUID *VendorGuid,\r | |
1127 | IN UINT32 Attributes,\r | |
1128 | IN UINTN DataSize,\r | |
1129 | IN VOID *Data\r | |
1130 | )\r | |
1131 | {\r | |
1132 | EFI_STATUS Status;\r | |
1133 | EDKII_SET_VARIABLE_STATUS *SetVariableStatus;\r | |
1134 | UINTN NameSize;\r | |
1135 | \r | |
1136 | Status = gRT->SetVariable (\r | |
1137 | VariableName,\r | |
1138 | VendorGuid,\r | |
1139 | Attributes,\r | |
1140 | DataSize,\r | |
1141 | Data\r | |
1142 | );\r | |
1143 | if (EFI_ERROR (Status)) {\r | |
1144 | NameSize = StrSize (VariableName);\r | |
1145 | SetVariableStatus = AllocatePool (sizeof (EDKII_SET_VARIABLE_STATUS) + NameSize + DataSize);\r | |
1146 | if (SetVariableStatus != NULL) {\r | |
1147 | CopyGuid (&SetVariableStatus->Guid, VendorGuid);\r | |
1148 | SetVariableStatus->NameSize = NameSize;\r | |
1149 | SetVariableStatus->DataSize = DataSize;\r | |
1150 | SetVariableStatus->SetStatus = Status;\r | |
1151 | SetVariableStatus->Attributes = Attributes;\r | |
1152 | CopyMem (SetVariableStatus + 1, VariableName, NameSize);\r | |
1153 | CopyMem (((UINT8 *) (SetVariableStatus + 1)) + NameSize, Data, DataSize);\r | |
1154 | \r | |
1155 | REPORT_STATUS_CODE_EX (\r | |
1156 | EFI_ERROR_CODE,\r | |
1157 | PcdGet32 (PcdErrorCodeSetVariable),\r | |
1158 | 0,\r | |
1159 | NULL,\r | |
1160 | &gEdkiiStatusCodeDataTypeVariableGuid,\r | |
1161 | SetVariableStatus,\r | |
1162 | sizeof (EDKII_SET_VARIABLE_STATUS) + NameSize + DataSize\r | |
1163 | );\r | |
1164 | \r | |
1165 | FreePool (SetVariableStatus);\r | |
1166 | }\r | |
1167 | }\r | |
1168 | \r | |
1169 | return Status;\r | |
1170 | }\r |