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