]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Universal/BdsDxe/BdsEntry.c
IntelFrameworkModulePkg: Use EfiEventEmptyFunction from UefiLib
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / BdsDxe / BdsEntry.c
CommitLineData
5c08e117 1/** @file\r
128efbbc 2 This module produce main entry for BDS phase - BdsEntry.\r
5c08e117 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
fe813348 8Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>\r
180a5a35 9This program and the accompanying materials\r
5c08e117 10are licensed and made available under the terms and conditions of the BSD License\r
11which accompanies this distribution. The full text of the license may be found at\r
12http://opensource.org/licenses/bsd-license.php\r
13\r
14THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
15WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
16\r
17**/\r
18\r
19#include "Bds.h"\r
20#include "Language.h"\r
21#include "FrontPage.h"\r
22#include "Hotkey.h"\r
23#include "HwErrRecSupport.h"\r
24\r
25///\r
26/// BDS arch protocol instance initial value.\r
27///\r
28/// Note: Current BDS not directly get the BootMode, DefaultBoot,\r
29/// TimeoutDefault, MemoryTestLevel value from the BDS arch protocol.\r
128efbbc 30/// Please refer to the library useage of BdsLibGetBootMode, BdsLibGetTimeout\r
5c08e117 31/// and PlatformBdsDiagnostics in BdsPlatform.c\r
32///\r
f7cdf5cd 33EFI_HANDLE gBdsHandle = NULL;\r
34\r
35EFI_BDS_ARCH_PROTOCOL gBds = {\r
36 BdsEntry\r
5c08e117 37};\r
38\r
39UINT16 *mBootNext = NULL;\r
40\r
ff843847
RN
41///\r
42/// The read-only variables defined in UEFI Spec.\r
43///\r
44CHAR16 *mReadOnlyVariables[] = {\r
45 L"PlatformLangCodes",\r
46 L"LangCodes",\r
47 L"BootOptionSupport",\r
48 L"HwErrRecSupport",\r
49 L"OsIndicationsSupported"\r
50 };\r
51\r
5c08e117 52/**\r
53\r
54 Install Boot Device Selection Protocol\r
55\r
56 @param ImageHandle The image handle.\r
57 @param SystemTable The system table.\r
58\r
59 @retval EFI_SUCEESS BDS has finished initializing.\r
60 Return the dispatcher and recall BDS.Entry\r
61 @retval Other Return status from AllocatePool() or gBS->InstallProtocolInterface\r
62\r
63**/\r
64EFI_STATUS\r
65EFIAPI\r
66BdsInitialize (\r
67 IN EFI_HANDLE ImageHandle,\r
68 IN EFI_SYSTEM_TABLE *SystemTable\r
69 )\r
70{\r
71 EFI_STATUS Status;\r
72\r
5c08e117 73 //\r
74 // Install protocol interface\r
75 //\r
f7cdf5cd 76 Status = gBS->InstallMultipleProtocolInterfaces (\r
77 &gBdsHandle,\r
78 &gEfiBdsArchProtocolGuid, &gBds,\r
79 NULL\r
5c08e117 80 );\r
81 ASSERT_EFI_ERROR (Status);\r
82\r
83 return Status;\r
84}\r
85\r
86/**\r
87\r
88 This function attempts to boot for the boot order specified\r
89 by platform policy.\r
90\r
91**/\r
92VOID\r
93BdsBootDeviceSelect (\r
94 VOID\r
95 )\r
96{\r
97 EFI_STATUS Status;\r
98 LIST_ENTRY *Link;\r
99 BDS_COMMON_OPTION *BootOption;\r
100 UINTN ExitDataSize;\r
101 CHAR16 *ExitData;\r
102 UINT16 Timeout;\r
103 LIST_ENTRY BootLists;\r
104 CHAR16 Buffer[20];\r
105 BOOLEAN BootNextExist;\r
106 LIST_ENTRY *LinkBootNext;\r
5676ccca 107 EFI_EVENT ConnectConInEvent;\r
5c08e117 108\r
109 //\r
110 // Got the latest boot option\r
111 //\r
112 BootNextExist = FALSE;\r
113 LinkBootNext = NULL;\r
5676ccca 114 ConnectConInEvent = NULL;\r
5c08e117 115 InitializeListHead (&BootLists);\r
116\r
117 //\r
118 // First check the boot next option\r
119 //\r
120 ZeroMem (Buffer, sizeof (Buffer));\r
121\r
5676ccca 122 //\r
123 // Create Event to signal ConIn connection request\r
124 //\r
125 if (PcdGetBool (PcdConInConnectOnDemand)) {\r
126 Status = gBS->CreateEventEx (\r
127 EVT_NOTIFY_SIGNAL,\r
128 TPL_CALLBACK,\r
fe813348 129 EfiEventEmptyFunction,\r
5676ccca 130 NULL,\r
131 &gConnectConInEventGuid,\r
132 &ConnectConInEvent\r
133 );\r
134 if (EFI_ERROR(Status)) {\r
135 ConnectConInEvent = NULL;\r
136 }\r
137 }\r
138\r
5c08e117 139 if (mBootNext != NULL) {\r
140 //\r
141 // Indicate we have the boot next variable, so this time\r
142 // boot will always have this boot option\r
143 //\r
144 BootNextExist = TRUE;\r
145\r
146 //\r
147 // Clear the this variable so it's only exist in this time boot\r
148 //\r
69fc8f08
RN
149 Status = gRT->SetVariable (\r
150 L"BootNext",\r
151 &gEfiGlobalVariableGuid,\r
152 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
153 0,\r
154 NULL\r
155 );\r
156 //\r
157 // Deleting variable with current variable implementation shouldn't fail.\r
158 //\r
159 ASSERT_EFI_ERROR (Status);\r
5c08e117 160\r
161 //\r
162 // Add the boot next boot option\r
163 //\r
164 UnicodeSPrint (Buffer, sizeof (Buffer), L"Boot%04x", *mBootNext);\r
165 BootOption = BdsLibVariableToOption (&BootLists, Buffer);\r
128efbbc 166\r
5c08e117 167 //\r
168 // If fail to get boot option from variable, just return and do nothing.\r
169 //\r
170 if (BootOption == NULL) {\r
171 return;\r
172 }\r
128efbbc 173\r
5c08e117 174 BootOption->BootCurrent = *mBootNext;\r
175 }\r
176 //\r
177 // Parse the boot order to get boot option\r
178 //\r
179 BdsLibBuildOptionFromVar (&BootLists, L"BootOrder");\r
d8600108
RN
180\r
181 //\r
182 // When we didn't have chance to build boot option variables in the first \r
183 // full configuration boot (e.g.: Reset in the first page or in Device Manager),\r
184 // we have no boot options in the following mini configuration boot.\r
185 // Give the last chance to enumerate the boot options.\r
186 //\r
187 if (IsListEmpty (&BootLists)) {\r
188 BdsLibEnumerateAllBootOption (&BootLists);\r
189 }\r
190\r
5c08e117 191 Link = BootLists.ForwardLink;\r
192\r
193 //\r
194 // Parameter check, make sure the loop will be valid\r
195 //\r
196 if (Link == NULL) {\r
197 return ;\r
198 }\r
199 //\r
200 // Here we make the boot in a loop, every boot success will\r
201 // return to the front page\r
202 //\r
203 for (;;) {\r
204 //\r
205 // Check the boot option list first\r
206 //\r
207 if (Link == &BootLists) {\r
5676ccca 208 //\r
209 // When LazyConIn enabled, signal connect ConIn event before enter UI\r
210 //\r
211 if (PcdGetBool (PcdConInConnectOnDemand) && ConnectConInEvent != NULL) {\r
212 gBS->SignalEvent (ConnectConInEvent);\r
213 }\r
214\r
5c08e117 215 //\r
216 // There are two ways to enter here:\r
217 // 1. There is no active boot option, give user chance to\r
218 // add new boot option\r
219 // 2. All the active boot option processed, and there is no\r
220 // one is success to boot, then we back here to allow user\r
221 // add new active boot option\r
222 //\r
223 Timeout = 0xffff;\r
224 PlatformBdsEnterFrontPage (Timeout, FALSE);\r
225 InitializeListHead (&BootLists);\r
226 BdsLibBuildOptionFromVar (&BootLists, L"BootOrder");\r
227 Link = BootLists.ForwardLink;\r
228 continue;\r
229 }\r
230 //\r
231 // Get the boot option from the link list\r
232 //\r
233 BootOption = CR (Link, BDS_COMMON_OPTION, Link, BDS_LOAD_OPTION_SIGNATURE);\r
234\r
235 //\r
236 // According to EFI Specification, if a load option is not marked\r
237 // as LOAD_OPTION_ACTIVE, the boot manager will not automatically\r
238 // load the option.\r
239 //\r
240 if (!IS_LOAD_OPTION_TYPE (BootOption->Attribute, LOAD_OPTION_ACTIVE)) {\r
241 //\r
baf46e70 242 // skip the header of the link list, because it has no boot option\r
5c08e117 243 //\r
244 Link = Link->ForwardLink;\r
245 continue;\r
246 }\r
247 //\r
248 // Make sure the boot option device path connected,\r
249 // but ignore the BBS device path\r
250 //\r
251 if (DevicePathType (BootOption->DevicePath) != BBS_DEVICE_PATH) {\r
252 //\r
253 // Notes: the internal shell can not been connected with device path\r
254 // so we do not check the status here\r
255 //\r
256 BdsLibConnectDevicePath (BootOption->DevicePath);\r
257 }\r
2df686c6 258\r
259 //\r
260 // Restore to original mode before launching boot option.\r
261 //\r
262 BdsSetConsoleMode (FALSE);\r
263 \r
5c08e117 264 //\r
265 // All the driver options should have been processed since\r
266 // now boot will be performed.\r
267 //\r
268 Status = BdsLibBootViaBootOption (BootOption, BootOption->DevicePath, &ExitDataSize, &ExitData);\r
59b9d73e 269 if (Status != EFI_SUCCESS) {\r
5c08e117 270 //\r
271 // Call platform action to indicate the boot fail\r
272 //\r
273 BootOption->StatusString = GetStringById (STRING_TOKEN (STR_BOOT_FAILED));\r
274 PlatformBdsBootFail (BootOption, Status, ExitData, ExitDataSize);\r
275\r
276 //\r
277 // Check the next boot option\r
278 //\r
279 Link = Link->ForwardLink;\r
280\r
281 } else {\r
282 //\r
283 // Call platform action to indicate the boot success\r
284 //\r
128efbbc 285 BootOption->StatusString = GetStringById (STRING_TOKEN (STR_BOOT_SUCCEEDED));\r
5c08e117 286 PlatformBdsBootSuccess (BootOption);\r
287\r
288 //\r
289 // Boot success, then stop process the boot order, and\r
290 // present the boot manager menu, front page\r
291 //\r
5676ccca 292\r
293 //\r
294 // When LazyConIn enabled, signal connect ConIn Event before enter UI\r
295 //\r
296 if (PcdGetBool (PcdConInConnectOnDemand) && ConnectConInEvent != NULL) {\r
297 gBS->SignalEvent (ConnectConInEvent);\r
298 }\r
299\r
5c08e117 300 Timeout = 0xffff;\r
301 PlatformBdsEnterFrontPage (Timeout, FALSE);\r
302\r
303 //\r
baf46e70 304 // Rescan the boot option list, avoid potential risk of the boot\r
5c08e117 305 // option change in front page\r
306 //\r
307 if (BootNextExist) {\r
308 LinkBootNext = BootLists.ForwardLink;\r
309 }\r
310\r
311 InitializeListHead (&BootLists);\r
312 if (LinkBootNext != NULL) {\r
313 //\r
314 // Reserve the boot next option\r
315 //\r
316 InsertTailList (&BootLists, LinkBootNext);\r
317 }\r
318\r
319 BdsLibBuildOptionFromVar (&BootLists, L"BootOrder");\r
320 Link = BootLists.ForwardLink;\r
321 }\r
322 }\r
323\r
324}\r
325\r
7ea22852
ED
326/**\r
327\r
328 Validate input console variable data. \r
329\r
330 If found the device path is not a valid device path, remove the variable.\r
331 \r
332 @param VariableName Input console variable name.\r
333\r
334**/\r
7ea22852
ED
335VOID\r
336BdsFormalizeConsoleVariable (\r
337 IN CHAR16 *VariableName\r
338 )\r
339{\r
340 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
341 UINTN VariableSize;\r
342 EFI_STATUS Status;\r
343\r
344 DevicePath = BdsLibGetVariableAndSize (\r
345 VariableName,\r
346 &gEfiGlobalVariableGuid,\r
347 &VariableSize\r
348 );\r
98b241d6 349 if ((DevicePath != NULL) && !IsDevicePathValid (DevicePath, VariableSize)) { \r
7ea22852
ED
350 Status = gRT->SetVariable (\r
351 VariableName,\r
352 &gEfiGlobalVariableGuid,\r
353 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
354 0,\r
355 NULL\r
356 );\r
69fc8f08
RN
357 //\r
358 // Deleting variable with current variable implementation shouldn't fail.\r
359 //\r
7ea22852
ED
360 ASSERT_EFI_ERROR (Status);\r
361 }\r
362}\r
363\r
364/**\r
365\r
18cf3950 366 Formalize Bds global variables. \r
7ea22852 367\r
18cf3950 368 1. For ConIn/ConOut/ConErr, if found the device path is not a valid device path, remove the variable.\r
369 2. For OsIndicationsSupported, Create a BS/RT/UINT64 variable to report caps \r
370 3. Delete OsIndications variable if it is not NV/BS/RT UINT64\r
371 Item 3 is used to solve case when OS corrupts OsIndications. Here simply delete this NV variable.\r
372 \r
7ea22852
ED
373**/\r
374VOID \r
375BdsFormalizeEfiGlobalVariable (\r
376 VOID\r
377 )\r
378{\r
18cf3950 379 EFI_STATUS Status;\r
380 UINT64 OsIndicationSupport;\r
381 UINT64 OsIndication;\r
382 UINTN DataSize;\r
383 UINT32 Attributes;\r
384 \r
7ea22852
ED
385 //\r
386 // Validate Console variable.\r
387 //\r
388 BdsFormalizeConsoleVariable (L"ConIn");\r
389 BdsFormalizeConsoleVariable (L"ConOut");\r
390 BdsFormalizeConsoleVariable (L"ErrOut");\r
18cf3950 391\r
392 //\r
393 // OS indicater support variable\r
394 //\r
566771b0 395 OsIndicationSupport = EFI_OS_INDICATIONS_BOOT_TO_FW_UI \\r
396 | EFI_OS_INDICATIONS_FMP_CAPSULE_SUPPORTED;\r
397\r
69fc8f08
RN
398 BdsDxeSetVariableAndReportStatusCodeOnError (\r
399 L"OsIndicationsSupported",\r
400 &gEfiGlobalVariableGuid,\r
401 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
402 sizeof(UINT64),\r
403 &OsIndicationSupport\r
404 );\r
18cf3950 405\r
406 //\r
407 // If OsIndications is invalid, remove it.\r
408 // Invalid case\r
409 // 1. Data size != UINT64\r
410 // 2. OsIndication value inconsistence\r
411 // 3. OsIndication attribute inconsistence\r
412 //\r
413 OsIndication = 0;\r
414 Attributes = 0;\r
415 DataSize = sizeof(UINT64);\r
416 Status = gRT->GetVariable (\r
417 L"OsIndications",\r
418 &gEfiGlobalVariableGuid,\r
419 &Attributes,\r
420 &DataSize,\r
421 &OsIndication\r
422 );\r
423\r
424 if (!EFI_ERROR(Status)) {\r
425 if (DataSize != sizeof(UINT64) ||\r
426 (OsIndication & ~OsIndicationSupport) != 0 ||\r
427 Attributes != (EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE)){\r
428\r
429 DEBUG ((EFI_D_ERROR, "Unformalized OsIndications variable exists. Delete it\n"));\r
430 Status = gRT->SetVariable (\r
431 L"OsIndications",\r
432 &gEfiGlobalVariableGuid,\r
18cf3950 433 0,\r
69fc8f08
RN
434 0,\r
435 NULL\r
18cf3950 436 );\r
69fc8f08
RN
437 //\r
438 // Deleting variable with current variable implementation shouldn't fail.\r
439 //\r
18cf3950 440 ASSERT_EFI_ERROR (Status);\r
441 }\r
442 }\r
443\r
7ea22852
ED
444}\r
445\r
f6c07313
SZ
446/**\r
447\r
448 Allocate a block of memory that will contain performance data to OS.\r
449\r
450**/\r
451VOID\r
452BdsAllocateMemoryForPerformanceData (\r
453 VOID\r
454 )\r
455{\r
456 EFI_STATUS Status;\r
457 EFI_PHYSICAL_ADDRESS AcpiLowMemoryBase;\r
458 EDKII_VARIABLE_LOCK_PROTOCOL *VariableLock;\r
459\r
460 AcpiLowMemoryBase = 0x0FFFFFFFFULL;\r
461\r
462 //\r
463 // Allocate a block of memory that will contain performance data to OS.\r
464 //\r
465 Status = gBS->AllocatePages (\r
466 AllocateMaxAddress,\r
467 EfiReservedMemoryType,\r
468 EFI_SIZE_TO_PAGES (PERF_DATA_MAX_LENGTH),\r
469 &AcpiLowMemoryBase\r
470 );\r
471 if (!EFI_ERROR (Status)) {\r
472 //\r
473 // Save the pointer to variable for use in S3 resume.\r
474 //\r
69fc8f08
RN
475 BdsDxeSetVariableAndReportStatusCodeOnError (\r
476 L"PerfDataMemAddr",\r
477 &gPerformanceProtocolGuid,\r
478 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
479 sizeof (EFI_PHYSICAL_ADDRESS),\r
480 &AcpiLowMemoryBase\r
481 );\r
482 if (EFI_ERROR (Status)) {\r
483 DEBUG ((EFI_D_ERROR, "[Bds] PerfDataMemAddr (%08x) cannot be saved to NV storage.\n", AcpiLowMemoryBase));\r
484 }\r
f6c07313
SZ
485 //\r
486 // Mark L"PerfDataMemAddr" variable to read-only if the Variable Lock protocol exists\r
69fc8f08 487 // Still lock it even the variable cannot be saved to prevent it's set by 3rd party code.\r
f6c07313
SZ
488 //\r
489 Status = gBS->LocateProtocol (&gEdkiiVariableLockProtocolGuid, NULL, (VOID **) &VariableLock);\r
490 if (!EFI_ERROR (Status)) {\r
491 Status = VariableLock->RequestToLock (VariableLock, L"PerfDataMemAddr", &gPerformanceProtocolGuid);\r
492 ASSERT_EFI_ERROR (Status);\r
493 }\r
494 }\r
495}\r
496\r
5c08e117 497/**\r
498\r
499 Service routine for BdsInstance->Entry(). Devices are connected, the\r
500 consoles are initialized, and the boot options are tried.\r
501\r
502 @param This Protocol Instance structure.\r
503\r
504**/\r
505VOID\r
506EFIAPI\r
507BdsEntry (\r
508 IN EFI_BDS_ARCH_PROTOCOL *This\r
509 )\r
510{\r
5c08e117 511 LIST_ENTRY DriverOptionList;\r
512 LIST_ENTRY BootOptionList;\r
513 UINTN BootNextSize;\r
9a6b4de2 514 CHAR16 *FirmwareVendor;\r
e1e91b73
SZ
515 EFI_STATUS Status;\r
516 UINT16 BootTimeOut;\r
ff843847
RN
517 UINTN Index;\r
518 EDKII_VARIABLE_LOCK_PROTOCOL *VariableLock;\r
5c08e117 519\r
520 //\r
521 // Insert the performance probe\r
522 //\r
128efbbc 523 PERF_END (NULL, "DXE", NULL, 0);\r
524 PERF_START (NULL, "BDS", NULL, 0);\r
5c08e117 525\r
f6c07313
SZ
526 PERF_CODE (\r
527 BdsAllocateMemoryForPerformanceData ();\r
528 );\r
529\r
5c08e117 530 //\r
531 // Initialize the global system boot option and driver option\r
532 //\r
533 InitializeListHead (&DriverOptionList);\r
534 InitializeListHead (&BootOptionList);\r
535\r
536 //\r
537 // Initialize hotkey service\r
538 //\r
539 InitializeHotkeyService ();\r
540\r
9a6b4de2 541 //\r
542 // Fill in FirmwareVendor and FirmwareRevision from PCDs\r
543 //\r
544 FirmwareVendor = (CHAR16 *)PcdGetPtr (PcdFirmwareVendor);\r
545 gST->FirmwareVendor = AllocateRuntimeCopyPool (StrSize (FirmwareVendor), FirmwareVendor);\r
546 ASSERT (gST->FirmwareVendor != NULL);\r
547 gST->FirmwareRevision = PcdGet32 (PcdFirmwareRevision);\r
548\r
549 //\r
550 // Fixup Tasble CRC after we updated Firmware Vendor and Revision\r
551 //\r
d2b9b337 552 gST->Hdr.CRC32 = 0;\r
9a6b4de2 553 gBS->CalculateCrc32 ((VOID *)gST, sizeof(EFI_SYSTEM_TABLE), &gST->Hdr.CRC32);\r
554\r
7ea22852
ED
555 //\r
556 // Validate Variable.\r
557 //\r
558 BdsFormalizeEfiGlobalVariable();\r
559\r
ff843847
RN
560 //\r
561 // Mark the read-only variables if the Variable Lock protocol exists\r
562 //\r
563 Status = gBS->LocateProtocol (&gEdkiiVariableLockProtocolGuid, NULL, (VOID **) &VariableLock);\r
564 DEBUG ((EFI_D_INFO, "[BdsDxe] Locate Variable Lock protocol - %r\n", Status));\r
565 if (!EFI_ERROR (Status)) {\r
bdb898a5 566 for (Index = 0; Index < ARRAY_SIZE (mReadOnlyVariables); Index++) {\r
ff843847
RN
567 Status = VariableLock->RequestToLock (VariableLock, mReadOnlyVariables[Index], &gEfiGlobalVariableGuid);\r
568 ASSERT_EFI_ERROR (Status);\r
569 }\r
570 }\r
571\r
cb38c322 572 //\r
573 // Report Status Code to indicate connecting drivers will happen\r
574 //\r
575 REPORT_STATUS_CODE (\r
576 EFI_PROGRESS_CODE,\r
577 (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_PC_BEGIN_CONNECTING_DRIVERS)\r
578 );\r
579\r
a2b35995 580 InitializeHwErrRecSupport();\r
128efbbc 581\r
e1e91b73
SZ
582 //\r
583 // Initialize L"Timeout" EFI global variable.\r
584 //\r
585 BootTimeOut = PcdGet16 (PcdPlatformBootTimeOut);\r
586 if (BootTimeOut != 0xFFFF) {\r
587 //\r
588 // If time out value equal 0xFFFF, no need set to 0xFFFF to variable area because UEFI specification\r
589 // define same behavior between no value or 0xFFFF value for L"Timeout".\r
590 //\r
69fc8f08 591 BdsDxeSetVariableAndReportStatusCodeOnError (\r
e1e91b73
SZ
592 L"Timeout",\r
593 &gEfiGlobalVariableGuid,\r
594 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
595 sizeof (UINT16),\r
596 &BootTimeOut\r
597 );\r
e1e91b73
SZ
598 }\r
599\r
5c08e117 600 //\r
601 // bugbug: platform specific code\r
602 // Initialize the platform specific string and language\r
603 //\r
604 InitializeStringSupport ();\r
605 InitializeLanguage (TRUE);\r
606 InitializeFrontPage (TRUE);\r
607\r
ff843847
RN
608 //\r
609 // Do the platform init, can be customized by OEM/IBV\r
610 //\r
611 PERF_START (NULL, "PlatformBds", "BDS", 0);\r
612 PlatformBdsInit ();\r
613\r
5c08e117 614 //\r
615 // Set up the device list based on EFI 1.1 variables\r
616 // process Driver#### and Load the driver's in the\r
617 // driver option list\r
618 //\r
619 BdsLibBuildOptionFromVar (&DriverOptionList, L"DriverOrder");\r
620 if (!IsListEmpty (&DriverOptionList)) {\r
621 BdsLibLoadDrivers (&DriverOptionList);\r
622 }\r
623 //\r
624 // Check if we have the boot next option\r
625 //\r
626 mBootNext = BdsLibGetVariableAndSize (\r
627 L"BootNext",\r
628 &gEfiGlobalVariableGuid,\r
629 &BootNextSize\r
630 );\r
631\r
632 //\r
633 // Setup some platform policy here\r
634 //\r
19bf20e1 635 PlatformBdsPolicyBehavior (&DriverOptionList, &BootOptionList, BdsProcessCapsules, BdsMemoryTest);\r
128efbbc 636 PERF_END (NULL, "PlatformBds", "BDS", 0);\r
5c08e117 637\r
638 //\r
639 // BDS select the boot device to load OS\r
640 //\r
641 BdsBootDeviceSelect ();\r
642\r
643 //\r
644 // Only assert here since this is the right behavior, we should never\r
645 // return back to DxeCore.\r
646 //\r
647 ASSERT (FALSE);\r
648\r
649 return ;\r
650}\r
69fc8f08
RN
651\r
652\r
653/**\r
654 Set the variable and report the error through status code upon failure.\r
655\r
656 @param VariableName A Null-terminated string that is the name of the vendor's variable.\r
657 Each VariableName is unique for each VendorGuid. VariableName must\r
658 contain 1 or more characters. If VariableName is an empty string,\r
659 then EFI_INVALID_PARAMETER is returned.\r
660 @param VendorGuid A unique identifier for the vendor.\r
661 @param Attributes Attributes bitmask to set for the variable.\r
662 @param DataSize The size in bytes of the Data buffer. Unless the EFI_VARIABLE_APPEND_WRITE, \r
663 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS, or \r
664 EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute is set, a size of zero \r
665 causes the variable to be deleted. When the EFI_VARIABLE_APPEND_WRITE attribute is \r
666 set, then a SetVariable() call with a DataSize of zero will not cause any change to \r
667 the variable value (the timestamp associated with the variable may be updated however \r
668 even if no new data value is provided,see the description of the \r
669 EFI_VARIABLE_AUTHENTICATION_2 descriptor below. In this case the DataSize will not \r
670 be zero since the EFI_VARIABLE_AUTHENTICATION_2 descriptor will be populated). \r
671 @param Data The contents for the variable.\r
672\r
673 @retval EFI_SUCCESS The firmware has successfully stored the variable and its data as\r
674 defined by the Attributes.\r
675 @retval EFI_INVALID_PARAMETER An invalid combination of attribute bits, name, and GUID was supplied, or the\r
676 DataSize exceeds the maximum allowed.\r
677 @retval EFI_INVALID_PARAMETER VariableName is an empty string.\r
678 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.\r
679 @retval EFI_DEVICE_ERROR The variable could not be retrieved due to a hardware error.\r
680 @retval EFI_WRITE_PROTECTED The variable in question is read-only.\r
681 @retval EFI_WRITE_PROTECTED The variable in question cannot be deleted.\r
682 @retval EFI_SECURITY_VIOLATION The variable could not be written due to EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS \r
683 or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS being set, but the AuthInfo \r
684 does NOT pass the validation check carried out by the firmware.\r
685\r
686 @retval EFI_NOT_FOUND The variable trying to be updated or deleted was not found.\r
687**/\r
688EFI_STATUS\r
689BdsDxeSetVariableAndReportStatusCodeOnError (\r
690 IN CHAR16 *VariableName,\r
691 IN EFI_GUID *VendorGuid,\r
692 IN UINT32 Attributes,\r
693 IN UINTN DataSize,\r
694 IN VOID *Data\r
695 )\r
696{\r
697 EFI_STATUS Status;\r
698 EDKII_SET_VARIABLE_STATUS *SetVariableStatus;\r
699 UINTN NameSize;\r
700\r
701 Status = gRT->SetVariable (\r
702 VariableName,\r
703 VendorGuid,\r
704 Attributes,\r
705 DataSize,\r
706 Data\r
707 );\r
708 if (EFI_ERROR (Status)) {\r
709 NameSize = StrSize (VariableName);\r
710 SetVariableStatus = AllocatePool (sizeof (EDKII_SET_VARIABLE_STATUS) + NameSize + DataSize);\r
711 if (SetVariableStatus != NULL) {\r
712 CopyGuid (&SetVariableStatus->Guid, VendorGuid);\r
713 SetVariableStatus->NameSize = NameSize;\r
714 SetVariableStatus->DataSize = DataSize;\r
715 SetVariableStatus->SetStatus = Status;\r
716 SetVariableStatus->Attributes = Attributes;\r
717 CopyMem (SetVariableStatus + 1, VariableName, NameSize);\r
718 CopyMem (((UINT8 *) (SetVariableStatus + 1)) + NameSize, Data, DataSize);\r
719\r
720 REPORT_STATUS_CODE_EX (\r
721 EFI_ERROR_CODE,\r
722 PcdGet32 (PcdErrorCodeSetVariable),\r
723 0,\r
724 NULL,\r
725 &gEdkiiStatusCodeDataTypeVariableGuid,\r
726 SetVariableStatus,\r
727 sizeof (EDKII_SET_VARIABLE_STATUS) + NameSize + DataSize\r
728 );\r
729\r
730 FreePool (SetVariableStatus);\r
731 }\r
732 }\r
733\r
734 return Status;\r
735}\r
736\r