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