]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/Bds/Bds.c
ARM Packages: Replace tabs by spaces for indentation
[mirror_edk2.git] / ArmPlatformPkg / Bds / Bds.c
1 /** @file
2 *
3 * Copyright (c) 2011-2014, ARM Limited. All rights reserved.
4 *
5 * This program and the accompanying materials
6 * are licensed and made available under the terms and conditions of the BSD License
7 * which accompanies this distribution. The full text of the license may be found at
8 * http://opensource.org/licenses/bsd-license.php
9 *
10 * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 *
13 **/
14
15 #include "BdsInternal.h"
16
17 #include <Library/PcdLib.h>
18 #include <Library/PerformanceLib.h>
19
20 #include <Protocol/Bds.h>
21
22 #include <Guid/EventGroup.h>
23
24 #define EFI_SET_TIMER_TO_SECOND 10000000
25
26 STATIC
27 EFI_STATUS
28 GetConsoleDevicePathFromVariable (
29 IN CHAR16* ConsoleVarName,
30 IN CHAR16* DefaultConsolePaths,
31 OUT EFI_DEVICE_PATH** DevicePaths
32 )
33 {
34 EFI_STATUS Status;
35 UINTN Size;
36 EFI_DEVICE_PATH_PROTOCOL* DevicePathInstances;
37 EFI_DEVICE_PATH_PROTOCOL* DevicePathInstance;
38 CHAR16* DevicePathStr;
39 CHAR16* NextDevicePathStr;
40 EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL *EfiDevicePathFromTextProtocol;
41
42 Status = GetGlobalEnvironmentVariable (ConsoleVarName, NULL, NULL, (VOID**)&DevicePathInstances);
43 if (EFI_ERROR(Status)) {
44 // In case no default console device path has been defined we assume a driver handles the console (eg: SimpleTextInOutSerial)
45 if ((DefaultConsolePaths == NULL) || (DefaultConsolePaths[0] == L'\0')) {
46 *DevicePaths = NULL;
47 return EFI_SUCCESS;
48 }
49
50 Status = gBS->LocateProtocol (&gEfiDevicePathFromTextProtocolGuid, NULL, (VOID **)&EfiDevicePathFromTextProtocol);
51 ASSERT_EFI_ERROR(Status);
52
53 DevicePathInstances = NULL;
54
55 // Extract the Device Path instances from the multi-device path string
56 while ((DefaultConsolePaths != NULL) && (DefaultConsolePaths[0] != L'\0')) {
57 NextDevicePathStr = StrStr (DefaultConsolePaths, L";");
58 if (NextDevicePathStr == NULL) {
59 DevicePathStr = DefaultConsolePaths;
60 DefaultConsolePaths = NULL;
61 } else {
62 DevicePathStr = (CHAR16*)AllocateCopyPool ((NextDevicePathStr - DefaultConsolePaths + 1) * sizeof(CHAR16), DefaultConsolePaths);
63 *(DevicePathStr + (NextDevicePathStr - DefaultConsolePaths)) = L'\0';
64 DefaultConsolePaths = NextDevicePathStr;
65 if (DefaultConsolePaths[0] == L';') {
66 DefaultConsolePaths++;
67 }
68 }
69
70 DevicePathInstance = EfiDevicePathFromTextProtocol->ConvertTextToDevicePath (DevicePathStr);
71 ASSERT(DevicePathInstance != NULL);
72 DevicePathInstances = AppendDevicePathInstance (DevicePathInstances, DevicePathInstance);
73
74 if (NextDevicePathStr != NULL) {
75 FreePool (DevicePathStr);
76 }
77 FreePool (DevicePathInstance);
78 }
79
80 // Set the environment variable with this device path multi-instances
81 Size = GetDevicePathSize (DevicePathInstances);
82 if (Size > 0) {
83 gRT->SetVariable (
84 ConsoleVarName,
85 &gEfiGlobalVariableGuid,
86 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
87 Size,
88 DevicePathInstances
89 );
90 } else {
91 Status = EFI_INVALID_PARAMETER;
92 }
93 }
94
95 if (!EFI_ERROR(Status)) {
96 *DevicePaths = DevicePathInstances;
97 }
98 return Status;
99 }
100
101 STATIC
102 EFI_STATUS
103 InitializeConsolePipe (
104 IN EFI_DEVICE_PATH *ConsoleDevicePaths,
105 IN EFI_GUID *Protocol,
106 OUT EFI_HANDLE *Handle,
107 OUT VOID* *Interface
108 )
109 {
110 EFI_STATUS Status;
111 UINTN Size;
112 UINTN NoHandles;
113 EFI_HANDLE *Buffer;
114 EFI_DEVICE_PATH_PROTOCOL* DevicePath;
115
116 // Connect all the Device Path Consoles
117 while (ConsoleDevicePaths != NULL) {
118 DevicePath = GetNextDevicePathInstance (&ConsoleDevicePaths, &Size);
119
120 Status = BdsConnectDevicePath (DevicePath, Handle, NULL);
121 DEBUG_CODE_BEGIN();
122 if (EFI_ERROR(Status)) {
123 // We convert back to the text representation of the device Path
124 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;
125 CHAR16* DevicePathTxt;
126 EFI_STATUS Status;
127
128 Status = gBS->LocateProtocol(&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);
129 if (!EFI_ERROR(Status)) {
130 DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (DevicePath, TRUE, TRUE);
131
132 DEBUG((EFI_D_ERROR,"Fail to start the console with the Device Path '%s'. (Error '%r')\n", DevicePathTxt, Status));
133
134 FreePool (DevicePathTxt);
135 }
136 }
137 DEBUG_CODE_END();
138
139 // If the console splitter driver is not supported by the platform then use the first Device Path
140 // instance for the console interface.
141 if (!EFI_ERROR(Status) && (*Interface == NULL)) {
142 Status = gBS->HandleProtocol (*Handle, Protocol, Interface);
143 }
144 }
145
146 // No Device Path has been defined for this console interface. We take the first protocol implementation
147 if (*Interface == NULL) {
148 Status = gBS->LocateHandleBuffer (ByProtocol, Protocol, NULL, &NoHandles, &Buffer);
149 if (EFI_ERROR (Status)) {
150 BdsConnectAllDrivers();
151 Status = gBS->LocateHandleBuffer (ByProtocol, Protocol, NULL, &NoHandles, &Buffer);
152 }
153
154 if (!EFI_ERROR(Status)) {
155 *Handle = Buffer[0];
156 Status = gBS->HandleProtocol (*Handle, Protocol, Interface);
157 ASSERT_EFI_ERROR(Status);
158 }
159 FreePool (Buffer);
160 } else {
161 Status = EFI_SUCCESS;
162 }
163
164 return Status;
165 }
166
167 EFI_STATUS
168 InitializeConsole (
169 VOID
170 )
171 {
172 EFI_STATUS Status;
173 EFI_DEVICE_PATH* ConOutDevicePaths;
174 EFI_DEVICE_PATH* ConInDevicePaths;
175 EFI_DEVICE_PATH* ConErrDevicePaths;
176
177 // By getting the Console Device Paths from the environment variables before initializing the console pipe, we
178 // create the 3 environment variables (ConIn, ConOut, ConErr) that allows to initialize all the console interface
179 // of newly installed console drivers
180 Status = GetConsoleDevicePathFromVariable (L"ConOut", (CHAR16*)PcdGetPtr(PcdDefaultConOutPaths), &ConOutDevicePaths);
181 ASSERT_EFI_ERROR (Status);
182 Status = GetConsoleDevicePathFromVariable (L"ConIn", (CHAR16*)PcdGetPtr(PcdDefaultConInPaths), &ConInDevicePaths);
183 ASSERT_EFI_ERROR (Status);
184 Status = GetConsoleDevicePathFromVariable (L"ErrOut", (CHAR16*)PcdGetPtr(PcdDefaultConOutPaths), &ConErrDevicePaths);
185 ASSERT_EFI_ERROR (Status);
186
187 // Initialize the Consoles
188 Status = InitializeConsolePipe (ConOutDevicePaths, &gEfiSimpleTextOutProtocolGuid, &gST->ConsoleOutHandle, (VOID **)&gST->ConOut);
189 ASSERT_EFI_ERROR (Status);
190 Status = InitializeConsolePipe (ConInDevicePaths, &gEfiSimpleTextInProtocolGuid, &gST->ConsoleInHandle, (VOID **)&gST->ConIn);
191 ASSERT_EFI_ERROR (Status);
192 Status = InitializeConsolePipe (ConErrDevicePaths, &gEfiSimpleTextOutProtocolGuid, &gST->StandardErrorHandle, (VOID **)&gST->StdErr);
193 if (EFI_ERROR(Status)) {
194 // In case of error, we reuse the console output for the error output
195 gST->StandardErrorHandle = gST->ConsoleOutHandle;
196 gST->StdErr = gST->ConOut;
197 }
198
199 // Free Memory allocated for reading the UEFI Variables
200 if (ConOutDevicePaths) {
201 FreePool (ConOutDevicePaths);
202 }
203 if (ConInDevicePaths) {
204 FreePool (ConInDevicePaths);
205 }
206 if (ConErrDevicePaths) {
207 FreePool (ConErrDevicePaths);
208 }
209
210 return EFI_SUCCESS;
211 }
212
213 EFI_STATUS
214 DefineDefaultBootEntries (
215 VOID
216 )
217 {
218 BDS_LOAD_OPTION* BdsLoadOption;
219 UINTN Size;
220 EFI_STATUS Status;
221 EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL* EfiDevicePathFromTextProtocol;
222 EFI_DEVICE_PATH* BootDevicePath;
223 UINT8* OptionalData;
224 UINTN OptionalDataSize;
225 ARM_BDS_LOADER_ARGUMENTS* BootArguments;
226 ARM_BDS_LOADER_TYPE BootType;
227 EFI_DEVICE_PATH* InitrdPath;
228 UINTN InitrdSize;
229 UINTN CmdLineSize;
230 UINTN CmdLineAsciiSize;
231 CHAR16* DefaultBootArgument;
232 CHAR8* AsciiDefaultBootArgument;
233
234 //
235 // If Boot Order does not exist then create a default entry
236 //
237 Size = 0;
238 Status = gRT->GetVariable (L"BootOrder", &gEfiGlobalVariableGuid, NULL, &Size, NULL);
239 if (Status == EFI_NOT_FOUND) {
240 if ((PcdGetPtr(PcdDefaultBootDevicePath) == NULL) || (StrLen ((CHAR16*)PcdGetPtr(PcdDefaultBootDevicePath)) == 0)) {
241 return EFI_UNSUPPORTED;
242 }
243
244 Status = gBS->LocateProtocol (&gEfiDevicePathFromTextProtocolGuid, NULL, (VOID **)&EfiDevicePathFromTextProtocol);
245 if (EFI_ERROR(Status)) {
246 // You must provide an implementation of DevicePathFromTextProtocol in your firmware (eg: DevicePathDxe)
247 DEBUG((EFI_D_ERROR,"Error: Bds requires DevicePathFromTextProtocol\n"));
248 return Status;
249 }
250 BootDevicePath = EfiDevicePathFromTextProtocol->ConvertTextToDevicePath ((CHAR16*)PcdGetPtr(PcdDefaultBootDevicePath));
251
252 DEBUG_CODE_BEGIN();
253 // We convert back to the text representation of the device Path to see if the initial text is correct
254 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;
255 CHAR16* DevicePathTxt;
256
257 Status = gBS->LocateProtocol(&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);
258 ASSERT_EFI_ERROR(Status);
259 DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (BootDevicePath, TRUE, TRUE);
260
261 ASSERT (StrCmp ((CHAR16*)PcdGetPtr(PcdDefaultBootDevicePath), DevicePathTxt) == 0);
262
263 FreePool (DevicePathTxt);
264 DEBUG_CODE_END();
265
266 // Create the entry is the Default values are correct
267 if (BootDevicePath != NULL) {
268 BootType = (ARM_BDS_LOADER_TYPE)PcdGet32 (PcdDefaultBootType);
269
270 // We do not support NULL pointer
271 ASSERT (PcdGetPtr (PcdDefaultBootArgument) != NULL);
272
273 //
274 // Logic to handle ASCII or Unicode default parameters
275 //
276 if (*(CHAR8*)PcdGetPtr (PcdDefaultBootArgument) == '\0') {
277 CmdLineSize = 0;
278 CmdLineAsciiSize = 0;
279 DefaultBootArgument = NULL;
280 AsciiDefaultBootArgument = NULL;
281 } else if (IsUnicodeString ((CHAR16*)PcdGetPtr (PcdDefaultBootArgument))) {
282 // The command line is a Unicode string
283 DefaultBootArgument = (CHAR16*)PcdGetPtr (PcdDefaultBootArgument);
284 CmdLineSize = StrSize (DefaultBootArgument);
285
286 // Initialize ASCII variables
287 CmdLineAsciiSize = CmdLineSize / 2;
288 AsciiDefaultBootArgument = AllocatePool (CmdLineAsciiSize);
289 if (AsciiDefaultBootArgument == NULL) {
290 return EFI_OUT_OF_RESOURCES;
291 }
292 UnicodeStrToAsciiStr ((CHAR16*)PcdGetPtr (PcdDefaultBootArgument), AsciiDefaultBootArgument);
293 } else {
294 // The command line is a ASCII string
295 AsciiDefaultBootArgument = (CHAR8*)PcdGetPtr (PcdDefaultBootArgument);
296 CmdLineAsciiSize = AsciiStrSize (AsciiDefaultBootArgument);
297
298 // Initialize ASCII variables
299 CmdLineSize = CmdLineAsciiSize * 2;
300 DefaultBootArgument = AllocatePool (CmdLineSize);
301 if (DefaultBootArgument == NULL) {
302 return EFI_OUT_OF_RESOURCES;
303 }
304 AsciiStrToUnicodeStr (AsciiDefaultBootArgument, DefaultBootArgument);
305 }
306
307 if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_FDT)) {
308 InitrdPath = EfiDevicePathFromTextProtocol->ConvertTextToDevicePath ((CHAR16*)PcdGetPtr(PcdDefaultBootInitrdPath));
309 InitrdSize = GetDevicePathSize (InitrdPath);
310
311 OptionalDataSize = sizeof(ARM_BDS_LOADER_ARGUMENTS) + CmdLineAsciiSize + InitrdSize;
312 BootArguments = (ARM_BDS_LOADER_ARGUMENTS*)AllocatePool (OptionalDataSize);
313 if (BootArguments == NULL) {
314 return EFI_OUT_OF_RESOURCES;
315 }
316 BootArguments->LinuxArguments.CmdLineSize = CmdLineAsciiSize;
317 BootArguments->LinuxArguments.InitrdSize = InitrdSize;
318
319 CopyMem ((VOID*)(BootArguments + 1), AsciiDefaultBootArgument, CmdLineAsciiSize);
320 CopyMem ((VOID*)((UINTN)(BootArguments + 1) + CmdLineAsciiSize), InitrdPath, InitrdSize);
321
322 OptionalData = (UINT8*)BootArguments;
323 } else {
324 OptionalData = (UINT8*)DefaultBootArgument;
325 OptionalDataSize = CmdLineSize;
326 }
327
328 BootOptionCreate (LOAD_OPTION_ACTIVE | LOAD_OPTION_CATEGORY_BOOT,
329 (CHAR16*)PcdGetPtr(PcdDefaultBootDescription),
330 BootDevicePath,
331 BootType,
332 OptionalData,
333 OptionalDataSize,
334 &BdsLoadOption
335 );
336 FreePool (BdsLoadOption);
337
338 if (DefaultBootArgument == (CHAR16*)PcdGetPtr (PcdDefaultBootArgument)) {
339 FreePool (AsciiDefaultBootArgument);
340 } else if (DefaultBootArgument != NULL) {
341 FreePool (DefaultBootArgument);
342 }
343 } else {
344 Status = EFI_UNSUPPORTED;
345 }
346 }
347
348 return Status;
349 }
350
351 EFI_STATUS
352 StartDefaultBootOnTimeout (
353 VOID
354 )
355 {
356 UINTN Size;
357 UINT16 Timeout;
358 UINT16 *TimeoutPtr;
359 EFI_EVENT WaitList[2];
360 UINTN WaitIndex;
361 UINT16 *BootOrder;
362 UINTN BootOrderSize;
363 UINTN Index;
364 CHAR16 BootVariableName[9];
365 EFI_STATUS Status;
366 EFI_INPUT_KEY Key;
367
368 Size = sizeof(UINT16);
369 Timeout = (UINT16)PcdGet16 (PcdPlatformBootTimeOut);
370 Status = GetGlobalEnvironmentVariable (L"Timeout", &Timeout, &Size, (VOID**)&TimeoutPtr);
371 if (!EFI_ERROR (Status)) {
372 Timeout = *TimeoutPtr;
373 FreePool (TimeoutPtr);
374 }
375
376 if (Timeout != 0xFFFF) {
377 if (Timeout > 0) {
378 // Create the waiting events (keystroke and 1sec timer)
379 gBS->CreateEvent (EVT_TIMER, 0, NULL, NULL, &WaitList[0]);
380 gBS->SetTimer (WaitList[0], TimerPeriodic, EFI_SET_TIMER_TO_SECOND);
381 WaitList[1] = gST->ConIn->WaitForKey;
382
383 // Start the timer
384 WaitIndex = 0;
385 Print(L"The default boot selection will start in ");
386 while ((Timeout > 0) && (WaitIndex == 0)) {
387 Print(L"%3d seconds",Timeout);
388 gBS->WaitForEvent (2, WaitList, &WaitIndex);
389 if (WaitIndex == 0) {
390 Print(L"\b\b\b\b\b\b\b\b\b\b\b");
391 Timeout--;
392 }
393 }
394 // Discard key in the buffer
395 do {
396 Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
397 } while(!EFI_ERROR(Status));
398 gBS->CloseEvent (WaitList[0]);
399 Print(L"\n\r");
400 }
401
402 // In case of Timeout we start the default boot selection
403 if (Timeout == 0) {
404 // Get the Boot Option Order from the environment variable (a default value should have been created)
405 GetGlobalEnvironmentVariable (L"BootOrder", NULL, &BootOrderSize, (VOID**)&BootOrder);
406
407 for (Index = 0; Index < BootOrderSize / sizeof (UINT16); Index++) {
408 UnicodeSPrint (BootVariableName, 9 * sizeof(CHAR16), L"Boot%04X", BootOrder[Index]);
409 Status = BdsStartBootOption (BootVariableName);
410 if(!EFI_ERROR(Status)){
411 // Boot option returned successfully, hence don't need to start next boot option
412 break;
413 }
414 // In case of success, we should not return from this call.
415 }
416 FreePool (BootOrder);
417 }
418 }
419 return EFI_SUCCESS;
420 }
421
422 /**
423 An empty function to pass error checking of CreateEventEx ().
424
425 @param Event Event whose notification function is being invoked.
426 @param Context Pointer to the notification function's context,
427 which is implementation-dependent.
428
429 **/
430 STATIC
431 VOID
432 EFIAPI
433 EmptyCallbackFunction (
434 IN EFI_EVENT Event,
435 IN VOID *Context
436 )
437 {
438 return;
439 }
440
441 /**
442 This function uses policy data from the platform to determine what operating
443 system or system utility should be loaded and invoked. This function call
444 also optionally make the use of user input to determine the operating system
445 or system utility to be loaded and invoked. When the DXE Core has dispatched
446 all the drivers on the dispatch queue, this function is called. This
447 function will attempt to connect the boot devices required to load and invoke
448 the selected operating system or system utility. During this process,
449 additional firmware volumes may be discovered that may contain addition DXE
450 drivers that can be dispatched by the DXE Core. If a boot device cannot be
451 fully connected, this function calls the DXE Service Dispatch() to allow the
452 DXE drivers from any newly discovered firmware volumes to be dispatched.
453 Then the boot device connection can be attempted again. If the same boot
454 device connection operation fails twice in a row, then that boot device has
455 failed, and should be skipped. This function should never return.
456
457 @param This The EFI_BDS_ARCH_PROTOCOL instance.
458
459 @return None.
460
461 **/
462 VOID
463 EFIAPI
464 BdsEntry (
465 IN EFI_BDS_ARCH_PROTOCOL *This
466 )
467 {
468 UINTN Size;
469 EFI_STATUS Status;
470 UINT16 *BootNext;
471 UINTN BootNextSize;
472 CHAR16 BootVariableName[9];
473 EFI_EVENT EndOfDxeEvent;
474
475 //
476 // Signal EndOfDxe PI Event
477 //
478 Status = gBS->CreateEventEx (
479 EVT_NOTIFY_SIGNAL,
480 TPL_NOTIFY,
481 EmptyCallbackFunction,
482 NULL,
483 &gEfiEndOfDxeEventGroupGuid,
484 &EndOfDxeEvent
485 );
486 if (!EFI_ERROR (Status)) {
487 gBS->SignalEvent (EndOfDxeEvent);
488 }
489
490 PERF_END (NULL, "DXE", NULL, 0);
491
492 //
493 // Declare the Firmware Vendor
494 //
495 if (FixedPcdGetPtr(PcdFirmwareVendor) != NULL) {
496 Size = 0x100;
497 gST->FirmwareVendor = AllocateRuntimePool (Size);
498 ASSERT (gST->FirmwareVendor != NULL);
499 UnicodeSPrint (gST->FirmwareVendor, Size, L"%a EFI %a %a", PcdGetPtr(PcdFirmwareVendor), __DATE__, __TIME__);
500 }
501
502 //
503 // Fixup Table CRC after we updated Firmware Vendor
504 //
505 gST->Hdr.CRC32 = 0;
506 Status = gBS->CalculateCrc32 ((VOID*)gST, gST->Hdr.HeaderSize, &gST->Hdr.CRC32);
507 ASSERT_EFI_ERROR (Status);
508
509 // If BootNext environment variable is defined then we just load it !
510 BootNextSize = sizeof(UINT16);
511 Status = GetGlobalEnvironmentVariable (L"BootNext", NULL, &BootNextSize, (VOID**)&BootNext);
512 if (!EFI_ERROR(Status)) {
513 ASSERT(BootNextSize == sizeof(UINT16));
514
515 // Generate the requested Boot Entry variable name
516 UnicodeSPrint (BootVariableName, 9 * sizeof(CHAR16), L"Boot%04X", *BootNext);
517
518 // Set BootCurrent variable
519 gRT->SetVariable (L"BootCurrent", &gEfiGlobalVariableGuid,
520 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
521 BootNextSize, BootNext);
522
523 FreePool (BootNext);
524
525 // Start the requested Boot Entry
526 Status = BdsStartBootOption (BootVariableName);
527 if (Status != EFI_NOT_FOUND) {
528 // BootNext has not been succeeded launched
529 if (EFI_ERROR(Status)) {
530 Print(L"Fail to start BootNext.\n");
531 }
532
533 // Delete the BootNext environment variable
534 gRT->SetVariable (L"BootNext", &gEfiGlobalVariableGuid,
535 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
536 0, NULL);
537 }
538
539 // Clear BootCurrent variable
540 gRT->SetVariable (L"BootCurrent", &gEfiGlobalVariableGuid,
541 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
542 0, NULL);
543 }
544
545 // If Boot Order does not exist then create a default entry
546 DefineDefaultBootEntries ();
547
548 // Now we need to setup the EFI System Table with information about the console devices.
549 InitializeConsole ();
550
551 //
552 // Update the CRC32 in the EFI System Table header
553 //
554 gST->Hdr.CRC32 = 0;
555 Status = gBS->CalculateCrc32 ((VOID*)gST, gST->Hdr.HeaderSize, &gST->Hdr.CRC32);
556 ASSERT_EFI_ERROR (Status);
557
558 // Timer before initiating the default boot selection
559 StartDefaultBootOnTimeout ();
560
561 // Start the Boot Menu
562 Status = BootMenuMain ();
563 ASSERT_EFI_ERROR (Status);
564
565 }
566
567 EFI_BDS_ARCH_PROTOCOL gBdsProtocol = {
568 BdsEntry,
569 };
570
571 EFI_STATUS
572 EFIAPI
573 BdsInitialize (
574 IN EFI_HANDLE ImageHandle,
575 IN EFI_SYSTEM_TABLE *SystemTable
576 )
577 {
578 EFI_STATUS Status;
579
580 Status = gBS->InstallMultipleProtocolInterfaces (
581 &ImageHandle,
582 &gEfiBdsArchProtocolGuid, &gBdsProtocol,
583 NULL
584 );
585 ASSERT_EFI_ERROR (Status);
586
587 return Status;
588 }