]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/Bds/Bds.c
ArmPlatformPkg/Bds: Add support to handle Unicode parameters
[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
24EFI_HANDLE mImageHandle;\r
25\r
26STATIC\r
27EFI_STATUS\r
28GetConsoleDevicePathFromVariable (\r
29 IN CHAR16* ConsoleVarName,\r
30 IN CHAR16* DefaultConsolePaths,\r
31 OUT EFI_DEVICE_PATH** DevicePaths\r
32 )\r
33{\r
34 EFI_STATUS Status;\r
35 UINTN Size;\r
36 EFI_DEVICE_PATH_PROTOCOL* DevicePathInstances;\r
37 EFI_DEVICE_PATH_PROTOCOL* DevicePathInstance;\r
38 CHAR16* DevicePathStr;\r
39 CHAR16* NextDevicePathStr;\r
40 EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL *EfiDevicePathFromTextProtocol;\r
41\r
c0b2e477 42 Status = GetGlobalEnvironmentVariable (ConsoleVarName, NULL, NULL, (VOID**)&DevicePathInstances);\r
705b0c03 43 if (EFI_ERROR(Status)) {\r
483bc3d3 44 // In case no default console device path has been defined we assume a driver handles the console (eg: SimpleTextInOutSerial)\r
45 if ((DefaultConsolePaths == NULL) || (DefaultConsolePaths[0] == L'\0')) {\r
46 *DevicePaths = NULL;\r
47 return EFI_SUCCESS;\r
48 }\r
49\r
705b0c03 50 Status = gBS->LocateProtocol (&gEfiDevicePathFromTextProtocolGuid, NULL, (VOID **)&EfiDevicePathFromTextProtocol);\r
51 ASSERT_EFI_ERROR(Status);\r
52\r
53 DevicePathInstances = NULL;\r
54\r
55 // Extract the Device Path instances from the multi-device path string\r
56 while ((DefaultConsolePaths != NULL) && (DefaultConsolePaths[0] != L'\0')) {\r
57 NextDevicePathStr = StrStr (DefaultConsolePaths, L";");\r
58 if (NextDevicePathStr == NULL) {\r
59 DevicePathStr = DefaultConsolePaths;\r
60 DefaultConsolePaths = NULL;\r
61 } else {\r
62 DevicePathStr = (CHAR16*)AllocateCopyPool ((NextDevicePathStr - DefaultConsolePaths + 1) * sizeof(CHAR16), DefaultConsolePaths);\r
63 *(DevicePathStr + (NextDevicePathStr - DefaultConsolePaths)) = L'\0';\r
64 DefaultConsolePaths = NextDevicePathStr;\r
65 if (DefaultConsolePaths[0] == L';') {\r
66 DefaultConsolePaths++;\r
67 }\r
68 }\r
69\r
70 DevicePathInstance = EfiDevicePathFromTextProtocol->ConvertTextToDevicePath (DevicePathStr);\r
71 ASSERT(DevicePathInstance != NULL);\r
72 DevicePathInstances = AppendDevicePathInstance (DevicePathInstances, DevicePathInstance);\r
73\r
74 if (NextDevicePathStr != NULL) {\r
75 FreePool (DevicePathStr);\r
76 }\r
77 FreePool (DevicePathInstance);\r
78 }\r
79\r
80 // Set the environment variable with this device path multi-instances\r
81 Size = GetDevicePathSize (DevicePathInstances);\r
82 if (Size > 0) {\r
83 gRT->SetVariable (\r
84 ConsoleVarName,\r
85 &gEfiGlobalVariableGuid,\r
86 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
87 Size,\r
88 DevicePathInstances\r
89 );\r
90 } else {\r
91 Status = EFI_INVALID_PARAMETER;\r
92 }\r
93 }\r
94\r
95 if (!EFI_ERROR(Status)) {\r
96 *DevicePaths = DevicePathInstances;\r
97 }\r
483bc3d3 98 return Status;\r
705b0c03 99}\r
100\r
101STATIC\r
102EFI_STATUS\r
103InitializeConsolePipe (\r
104 IN EFI_DEVICE_PATH *ConsoleDevicePaths,\r
105 IN EFI_GUID *Protocol,\r
106 OUT EFI_HANDLE *Handle,\r
107 OUT VOID* *Interface\r
108 )\r
109{\r
110 EFI_STATUS Status;\r
111 UINTN Size;\r
112 UINTN NoHandles;\r
113 EFI_HANDLE *Buffer;\r
114 EFI_DEVICE_PATH_PROTOCOL* DevicePath;\r
115\r
116 // Connect all the Device Path Consoles\r
483bc3d3 117 while (ConsoleDevicePaths != NULL) {\r
705b0c03 118 DevicePath = GetNextDevicePathInstance (&ConsoleDevicePaths, &Size);\r
119\r
120 Status = BdsConnectDevicePath (DevicePath, Handle, NULL);\r
121 DEBUG_CODE_BEGIN();\r
122 if (EFI_ERROR(Status)) {\r
123 // We convert back to the text representation of the device Path\r
124 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;\r
125 CHAR16* DevicePathTxt;\r
126 EFI_STATUS Status;\r
c0b2e477 127\r
705b0c03 128 Status = gBS->LocateProtocol(&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);\r
129 if (!EFI_ERROR(Status)) {\r
130 DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (DevicePath, TRUE, TRUE);\r
131\r
132 DEBUG((EFI_D_ERROR,"Fail to start the console with the Device Path '%s'. (Error '%r')\n", DevicePathTxt, Status));\r
133\r
134 FreePool (DevicePathTxt);\r
135 }\r
136 }\r
137 DEBUG_CODE_END();\r
138\r
139 // If the console splitter driver is not supported by the platform then use the first Device Path\r
140 // instance for the console interface.\r
141 if (!EFI_ERROR(Status) && (*Interface == NULL)) {\r
142 Status = gBS->HandleProtocol (*Handle, Protocol, Interface);\r
143 }\r
483bc3d3 144 }\r
705b0c03 145\r
146 // No Device Path has been defined for this console interface. We take the first protocol implementation\r
147 if (*Interface == NULL) {\r
148 Status = gBS->LocateHandleBuffer (ByProtocol, Protocol, NULL, &NoHandles, &Buffer);\r
149 if (EFI_ERROR (Status)) {\r
150 BdsConnectAllDrivers();\r
151 Status = gBS->LocateHandleBuffer (ByProtocol, Protocol, NULL, &NoHandles, &Buffer);\r
152 }\r
153\r
154 if (!EFI_ERROR(Status)) {\r
155 *Handle = Buffer[0];\r
156 Status = gBS->HandleProtocol (*Handle, Protocol, Interface);\r
157 ASSERT_EFI_ERROR(Status);\r
158 }\r
159 FreePool (Buffer);\r
160 } else {\r
161 Status = EFI_SUCCESS;\r
162 }\r
163\r
164 return Status;\r
165}\r
166\r
167EFI_STATUS\r
168InitializeConsole (\r
169 VOID\r
170 )\r
171{\r
172 EFI_STATUS Status;\r
173 EFI_DEVICE_PATH* ConOutDevicePaths;\r
174 EFI_DEVICE_PATH* ConInDevicePaths;\r
175 EFI_DEVICE_PATH* ConErrDevicePaths;\r
176\r
177 // By getting the Console Device Paths from the environment variables before initializing the console pipe, we\r
178 // create the 3 environment variables (ConIn, ConOut, ConErr) that allows to initialize all the console interface\r
179 // of newly installed console drivers\r
483bc3d3 180 Status = GetConsoleDevicePathFromVariable (L"ConOut", (CHAR16*)PcdGetPtr(PcdDefaultConOutPaths), &ConOutDevicePaths);\r
705b0c03 181 ASSERT_EFI_ERROR (Status);\r
483bc3d3 182 Status = GetConsoleDevicePathFromVariable (L"ConIn", (CHAR16*)PcdGetPtr(PcdDefaultConInPaths), &ConInDevicePaths);\r
705b0c03 183 ASSERT_EFI_ERROR (Status);\r
30d1bcd1 184 Status = GetConsoleDevicePathFromVariable (L"ErrOut", (CHAR16*)PcdGetPtr(PcdDefaultConOutPaths), &ConErrDevicePaths);\r
705b0c03 185 ASSERT_EFI_ERROR (Status);\r
186\r
187 // Initialize the Consoles\r
188 Status = InitializeConsolePipe (ConOutDevicePaths, &gEfiSimpleTextOutProtocolGuid, &gST->ConsoleOutHandle, (VOID **)&gST->ConOut);\r
189 ASSERT_EFI_ERROR (Status);\r
190 Status = InitializeConsolePipe (ConInDevicePaths, &gEfiSimpleTextInProtocolGuid, &gST->ConsoleInHandle, (VOID **)&gST->ConIn);\r
191 ASSERT_EFI_ERROR (Status);\r
192 Status = InitializeConsolePipe (ConErrDevicePaths, &gEfiSimpleTextOutProtocolGuid, &gST->StandardErrorHandle, (VOID **)&gST->StdErr);\r
193 if (EFI_ERROR(Status)) {\r
194 // In case of error, we reuse the console output for the error output\r
195 gST->StandardErrorHandle = gST->ConsoleOutHandle;\r
196 gST->StdErr = gST->ConOut;\r
197 }\r
198\r
b148591a 199 // Free Memory allocated for reading the UEFI Variables\r
200 if (ConOutDevicePaths) {\r
201 FreePool (ConOutDevicePaths);\r
202 }\r
203 if (ConInDevicePaths) {\r
204 FreePool (ConInDevicePaths);\r
205 }\r
206 if (ConErrDevicePaths) {\r
207 FreePool (ConErrDevicePaths);\r
208 }\r
209\r
705b0c03 210 return EFI_SUCCESS;\r
211}\r
212\r
213EFI_STATUS\r
214DefineDefaultBootEntries (\r
215 VOID\r
216 )\r
217{\r
218 BDS_LOAD_OPTION* BdsLoadOption;\r
219 UINTN Size;\r
220 EFI_STATUS Status;\r
221 EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL* EfiDevicePathFromTextProtocol;\r
222 EFI_DEVICE_PATH* BootDevicePath;\r
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
9fc9aa46
OM
309 BootArguments = (ARM_BDS_LOADER_ARGUMENTS*)AllocatePool (sizeof(ARM_BDS_LOADER_ARGUMENTS) + CmdLineAsciiSize + InitrdSize);\r
310 if (BootArguments == NULL) {\r
311 return EFI_OUT_OF_RESOURCES;\r
312 }\r
313 BootArguments->LinuxArguments.CmdLineSize = CmdLineAsciiSize;\r
705b0c03 314 BootArguments->LinuxArguments.InitrdSize = InitrdSize;\r
315\r
9fc9aa46
OM
316 CopyMem ((VOID*)(BootArguments + 1), AsciiDefaultBootArgument, CmdLineAsciiSize);\r
317 CopyMem ((VOID*)((UINTN)(BootArguments + 1) + CmdLineAsciiSize), InitrdPath, InitrdSize);\r
705b0c03 318 } else {\r
319 BootArguments = NULL;\r
320 }\r
321\r
322 BootOptionCreate (LOAD_OPTION_ACTIVE | LOAD_OPTION_CATEGORY_BOOT,\r
323 (CHAR16*)PcdGetPtr(PcdDefaultBootDescription),\r
324 BootDevicePath,\r
325 BootType,\r
326 BootArguments,\r
327 &BdsLoadOption\r
328 );\r
329 FreePool (BdsLoadOption);\r
9fc9aa46
OM
330\r
331 if (DefaultBootArgument == (CHAR16*)PcdGetPtr (PcdDefaultBootArgument)) {\r
332 FreePool (AsciiDefaultBootArgument);\r
333 } else {\r
334 FreePool (DefaultBootArgument);\r
335 }\r
705b0c03 336 } else {\r
337 Status = EFI_UNSUPPORTED;\r
338 }\r
339 }\r
340\r
341 return EFI_SUCCESS;\r
342}\r
343\r
344EFI_STATUS\r
345StartDefaultBootOnTimeout (\r
346 VOID\r
347 )\r
348{\r
349 UINTN Size;\r
350 UINT16 Timeout;\r
351 UINT16 *TimeoutPtr;\r
352 EFI_EVENT WaitList[2];\r
353 UINTN WaitIndex;\r
354 UINT16 *BootOrder;\r
355 UINTN BootOrderSize;\r
356 UINTN Index;\r
357 CHAR16 BootVariableName[9];\r
b34e4db3 358 EFI_STATUS Status;\r
359 EFI_INPUT_KEY Key;\r
705b0c03 360\r
361 Size = sizeof(UINT16);\r
362 Timeout = (UINT16)PcdGet16 (PcdPlatformBootTimeOut);\r
363 TimeoutPtr = &Timeout;\r
c0b2e477 364 GetGlobalEnvironmentVariable (L"Timeout", &Timeout, &Size, (VOID**)&TimeoutPtr);\r
705b0c03 365\r
366 if (Timeout != 0xFFFF) {\r
367 if (Timeout > 0) {\r
368 // Create the waiting events (keystroke and 1sec timer)\r
369 gBS->CreateEvent (EVT_TIMER, 0, NULL, NULL, &WaitList[0]);\r
370 gBS->SetTimer (WaitList[0], TimerPeriodic, EFI_SET_TIMER_TO_SECOND);\r
371 WaitList[1] = gST->ConIn->WaitForKey;\r
372\r
373 // Start the timer\r
374 WaitIndex = 0;\r
375 Print(L"The default boot selection will start in ");\r
376 while ((Timeout > 0) && (WaitIndex == 0)) {\r
377 Print(L"%3d seconds",Timeout);\r
378 gBS->WaitForEvent (2, WaitList, &WaitIndex);\r
379 if (WaitIndex == 0) {\r
380 Print(L"\b\b\b\b\b\b\b\b\b\b\b");\r
381 Timeout--;\r
382 }\r
383 }\r
384 // Discard key in the buffer\r
385 do {\r
386 Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
387 } while(!EFI_ERROR(Status));\r
388 gBS->CloseEvent (WaitList[0]);\r
389 Print(L"\n\r");\r
390 }\r
391\r
392 // In case of Timeout we start the default boot selection\r
393 if (Timeout == 0) {\r
394 // Get the Boot Option Order from the environment variable (a default value should have been created)\r
c0b2e477 395 GetGlobalEnvironmentVariable (L"BootOrder", NULL, &BootOrderSize, (VOID**)&BootOrder);\r
705b0c03 396\r
397 for (Index = 0; Index < BootOrderSize / sizeof (UINT16); Index++) {\r
398 UnicodeSPrint (BootVariableName, 9 * sizeof(CHAR16), L"Boot%04X", BootOrder[Index]);\r
399 Status = BdsStartBootOption (BootVariableName);\r
400 if(!EFI_ERROR(Status)){\r
401 // Boot option returned successfully, hence don't need to start next boot option\r
402 break;\r
403 }\r
404 // In case of success, we should not return from this call.\r
405 }\r
b148591a 406 FreePool (BootOrder);\r
705b0c03 407 }\r
408 }\r
409 return EFI_SUCCESS;\r
410}\r
411\r
412/**\r
c0b2e477 413 This function uses policy data from the platform to determine what operating\r
414 system or system utility should be loaded and invoked. This function call\r
415 also optionally make the use of user input to determine the operating system\r
416 or system utility to be loaded and invoked. When the DXE Core has dispatched\r
417 all the drivers on the dispatch queue, this function is called. This\r
418 function will attempt to connect the boot devices required to load and invoke\r
419 the selected operating system or system utility. During this process,\r
420 additional firmware volumes may be discovered that may contain addition DXE\r
421 drivers that can be dispatched by the DXE Core. If a boot device cannot be\r
422 fully connected, this function calls the DXE Service Dispatch() to allow the\r
423 DXE drivers from any newly discovered firmware volumes to be dispatched.\r
424 Then the boot device connection can be attempted again. If the same boot\r
425 device connection operation fails twice in a row, then that boot device has\r
705b0c03 426 failed, and should be skipped. This function should never return.\r
427\r
428 @param This The EFI_BDS_ARCH_PROTOCOL instance.\r
429\r
430 @return None.\r
431\r
432**/\r
433VOID\r
434EFIAPI\r
435BdsEntry (\r
436 IN EFI_BDS_ARCH_PROTOCOL *This\r
437 )\r
438{\r
439 UINTN Size;\r
440 EFI_STATUS Status;\r
0e29bf5c 441 UINT16 *BootNext;\r
442 UINTN BootNextSize;\r
443 CHAR16 BootVariableName[9];\r
705b0c03 444\r
445 PERF_END (NULL, "DXE", NULL, 0);\r
446\r
447 //\r
448 // Declare the Firmware Vendor\r
449 //\r
450 if (FixedPcdGetPtr(PcdFirmwareVendor) != NULL) {\r
451 Size = 0x100;\r
452 gST->FirmwareVendor = AllocateRuntimePool (Size);\r
453 ASSERT (gST->FirmwareVendor != NULL);\r
454 UnicodeSPrint (gST->FirmwareVendor, Size, L"%a EFI %a %a", PcdGetPtr(PcdFirmwareVendor), __DATE__, __TIME__);\r
455 }\r
456\r
53cba4fe 457 //\r
458 // Fixup Table CRC after we updated Firmware Vendor\r
459 //\r
460 gST->Hdr.CRC32 = 0;\r
461 Status = gBS->CalculateCrc32 ((VOID*)gST, gST->Hdr.HeaderSize, &gST->Hdr.CRC32);\r
462 ASSERT_EFI_ERROR (Status);\r
463\r
705b0c03 464 // If BootNext environment variable is defined then we just load it !\r
0e29bf5c 465 BootNextSize = sizeof(UINT16);\r
c0b2e477 466 Status = GetGlobalEnvironmentVariable (L"BootNext", NULL, &BootNextSize, (VOID**)&BootNext);\r
0e29bf5c 467 if (!EFI_ERROR(Status)) {\r
468 ASSERT(BootNextSize == sizeof(UINT16));\r
469\r
470 // Generate the requested Boot Entry variable name\r
471 UnicodeSPrint (BootVariableName, 9 * sizeof(CHAR16), L"Boot%04X", *BootNext);\r
472\r
473 // Set BootCurrent variable\r
474 gRT->SetVariable (L"BootCurrent", &gEfiGlobalVariableGuid,\r
475 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
476 BootNextSize, BootNext);\r
477\r
478 FreePool (BootNext);\r
479\r
480 // Start the requested Boot Entry\r
481 Status = BdsStartBootOption (BootVariableName);\r
482 if (Status != EFI_NOT_FOUND) {\r
483 // BootNext has not been succeeded launched\r
484 if (EFI_ERROR(Status)) {\r
485 Print(L"Fail to start BootNext.\n");\r
486 }\r
487\r
488 // Delete the BootNext environment variable\r
489 gRT->SetVariable (L"BootNext", &gEfiGlobalVariableGuid,\r
490 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
491 0, NULL);\r
705b0c03 492 }\r
493\r
0e29bf5c 494 // Clear BootCurrent variable\r
495 gRT->SetVariable (L"BootCurrent", &gEfiGlobalVariableGuid,\r
496 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
705b0c03 497 0, NULL);\r
498 }\r
499\r
500 // If Boot Order does not exist then create a default entry\r
501 DefineDefaultBootEntries ();\r
502\r
503 // Now we need to setup the EFI System Table with information about the console devices.\r
504 InitializeConsole ();\r
505\r
53cba4fe 506 //\r
507 // Update the CRC32 in the EFI System Table header\r
508 //\r
509 gST->Hdr.CRC32 = 0;\r
510 Status = gBS->CalculateCrc32 ((VOID*)gST, gST->Hdr.HeaderSize, &gST->Hdr.CRC32);\r
511 ASSERT_EFI_ERROR (Status);\r
512\r
705b0c03 513 // Timer before initiating the default boot selection\r
514 StartDefaultBootOnTimeout ();\r
515\r
516 // Start the Boot Menu\r
517 Status = BootMenuMain ();\r
518 ASSERT_EFI_ERROR (Status);\r
519\r
520}\r
521\r
522EFI_BDS_ARCH_PROTOCOL gBdsProtocol = {\r
523 BdsEntry,\r
524};\r
525\r
526EFI_STATUS\r
527EFIAPI\r
528BdsInitialize (\r
529 IN EFI_HANDLE ImageHandle,\r
530 IN EFI_SYSTEM_TABLE *SystemTable\r
531 )\r
532{\r
533 EFI_STATUS Status;\r
534\r
535 mImageHandle = ImageHandle;\r
536\r
537 Status = gBS->InstallMultipleProtocolInterfaces (\r
538 &ImageHandle,\r
539 &gEfiBdsArchProtocolGuid, &gBdsProtocol,\r
540 NULL\r
541 );\r
542 ASSERT_EFI_ERROR (Status);\r
543\r
544 return Status;\r
545}\r