]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | *\r | |
3 | * Copyright (c) 2011-2014, ARM Limited. All rights reserved.\r | |
4 | *\r | |
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 | |
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 | #include <Guid/EventGroup.h>\r | |
23 | \r | |
24 | #define EFI_SET_TIMER_TO_SECOND 10000000\r | |
25 | \r | |
26 | STATIC\r | |
27 | EFI_STATUS\r | |
28 | GetConsoleDevicePathFromVariable (\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 | |
42 | Status = GetGlobalEnvironmentVariable (ConsoleVarName, NULL, NULL, (VOID**)&DevicePathInstances);\r | |
43 | if (EFI_ERROR(Status)) {\r | |
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 | |
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 | |
98 | return Status;\r | |
99 | }\r | |
100 | \r | |
101 | STATIC\r | |
102 | EFI_STATUS\r | |
103 | InitializeConsolePipe (\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 | |
117 | while (ConsoleDevicePaths != NULL) {\r | |
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 | |
127 | \r | |
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 | |
144 | }\r | |
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 | |
167 | EFI_STATUS\r | |
168 | InitializeConsole (\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 | |
180 | Status = GetConsoleDevicePathFromVariable (L"ConOut", (CHAR16*)PcdGetPtr(PcdDefaultConOutPaths), &ConOutDevicePaths);\r | |
181 | ASSERT_EFI_ERROR (Status);\r | |
182 | Status = GetConsoleDevicePathFromVariable (L"ConIn", (CHAR16*)PcdGetPtr(PcdDefaultConInPaths), &ConInDevicePaths);\r | |
183 | ASSERT_EFI_ERROR (Status);\r | |
184 | Status = GetConsoleDevicePathFromVariable (L"ErrOut", (CHAR16*)PcdGetPtr(PcdDefaultConOutPaths), &ConErrDevicePaths);\r | |
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 | |
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 | |
210 | return EFI_SUCCESS;\r | |
211 | }\r | |
212 | \r | |
213 | EFI_STATUS\r | |
214 | DefineDefaultBootEntries (\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 | UINT8* OptionalData;\r | |
224 | UINTN OptionalDataSize;\r | |
225 | ARM_BDS_LOADER_ARGUMENTS* BootArguments;\r | |
226 | ARM_BDS_LOADER_TYPE BootType;\r | |
227 | EFI_DEVICE_PATH* InitrdPath;\r | |
228 | UINTN InitrdSize;\r | |
229 | UINTN CmdLineSize;\r | |
230 | UINTN CmdLineAsciiSize;\r | |
231 | CHAR16* DefaultBootArgument;\r | |
232 | CHAR8* AsciiDefaultBootArgument;\r | |
233 | \r | |
234 | //\r | |
235 | // If Boot Order does not exist then create a default entry\r | |
236 | //\r | |
237 | Size = 0;\r | |
238 | Status = gRT->GetVariable (L"BootOrder", &gEfiGlobalVariableGuid, NULL, &Size, NULL);\r | |
239 | if (Status == EFI_NOT_FOUND) {\r | |
240 | if ((PcdGetPtr(PcdDefaultBootDevicePath) == NULL) || (StrLen ((CHAR16*)PcdGetPtr(PcdDefaultBootDevicePath)) == 0)) {\r | |
241 | return EFI_UNSUPPORTED;\r | |
242 | }\r | |
243 | \r | |
244 | Status = gBS->LocateProtocol (&gEfiDevicePathFromTextProtocolGuid, NULL, (VOID **)&EfiDevicePathFromTextProtocol);\r | |
245 | if (EFI_ERROR(Status)) {\r | |
246 | // You must provide an implementation of DevicePathFromTextProtocol in your firmware (eg: DevicePathDxe)\r | |
247 | DEBUG((EFI_D_ERROR,"Error: Bds requires DevicePathFromTextProtocol\n"));\r | |
248 | return Status;\r | |
249 | }\r | |
250 | BootDevicePath = EfiDevicePathFromTextProtocol->ConvertTextToDevicePath ((CHAR16*)PcdGetPtr(PcdDefaultBootDevicePath));\r | |
251 | \r | |
252 | DEBUG_CODE_BEGIN();\r | |
253 | // We convert back to the text representation of the device Path to see if the initial text is correct\r | |
254 | EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;\r | |
255 | CHAR16* DevicePathTxt;\r | |
256 | \r | |
257 | Status = gBS->LocateProtocol(&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);\r | |
258 | ASSERT_EFI_ERROR(Status);\r | |
259 | DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (BootDevicePath, TRUE, TRUE);\r | |
260 | \r | |
261 | ASSERT (StrCmp ((CHAR16*)PcdGetPtr(PcdDefaultBootDevicePath), DevicePathTxt) == 0);\r | |
262 | \r | |
263 | FreePool (DevicePathTxt);\r | |
264 | DEBUG_CODE_END();\r | |
265 | \r | |
266 | // Create the entry is the Default values are correct\r | |
267 | if (BootDevicePath != NULL) {\r | |
268 | BootType = (ARM_BDS_LOADER_TYPE)PcdGet32 (PcdDefaultBootType);\r | |
269 | \r | |
270 | // We do not support NULL pointer\r | |
271 | ASSERT (PcdGetPtr (PcdDefaultBootArgument) != NULL);\r | |
272 | \r | |
273 | //\r | |
274 | // Logic to handle ASCII or Unicode default parameters\r | |
275 | //\r | |
276 | if (*(CHAR8*)PcdGetPtr (PcdDefaultBootArgument) == '\0') {\r | |
277 | CmdLineSize = 0;\r | |
278 | CmdLineAsciiSize = 0;\r | |
279 | DefaultBootArgument = NULL;\r | |
280 | AsciiDefaultBootArgument = NULL;\r | |
281 | } else if (IsUnicodeString ((CHAR16*)PcdGetPtr (PcdDefaultBootArgument))) {\r | |
282 | // The command line is a Unicode string\r | |
283 | DefaultBootArgument = (CHAR16*)PcdGetPtr (PcdDefaultBootArgument);\r | |
284 | CmdLineSize = StrSize (DefaultBootArgument);\r | |
285 | \r | |
286 | // Initialize ASCII variables\r | |
287 | CmdLineAsciiSize = CmdLineSize / 2;\r | |
288 | AsciiDefaultBootArgument = AllocatePool (CmdLineAsciiSize);\r | |
289 | if (AsciiDefaultBootArgument == NULL) {\r | |
290 | return EFI_OUT_OF_RESOURCES;\r | |
291 | }\r | |
292 | UnicodeStrToAsciiStr ((CHAR16*)PcdGetPtr (PcdDefaultBootArgument), AsciiDefaultBootArgument);\r | |
293 | } else {\r | |
294 | // The command line is a ASCII string\r | |
295 | AsciiDefaultBootArgument = (CHAR8*)PcdGetPtr (PcdDefaultBootArgument);\r | |
296 | CmdLineAsciiSize = AsciiStrSize (AsciiDefaultBootArgument);\r | |
297 | \r | |
298 | // Initialize ASCII variables\r | |
299 | CmdLineSize = CmdLineAsciiSize * 2;\r | |
300 | DefaultBootArgument = AllocatePool (CmdLineSize);\r | |
301 | if (DefaultBootArgument == NULL) {\r | |
302 | return EFI_OUT_OF_RESOURCES;\r | |
303 | }\r | |
304 | AsciiStrToUnicodeStr (AsciiDefaultBootArgument, DefaultBootArgument);\r | |
305 | }\r | |
306 | \r | |
307 | if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_FDT)) {\r | |
308 | InitrdPath = EfiDevicePathFromTextProtocol->ConvertTextToDevicePath ((CHAR16*)PcdGetPtr(PcdDefaultBootInitrdPath));\r | |
309 | InitrdSize = GetDevicePathSize (InitrdPath);\r | |
310 | \r | |
311 | OptionalDataSize = sizeof(ARM_BDS_LOADER_ARGUMENTS) + CmdLineAsciiSize + InitrdSize;\r | |
312 | BootArguments = (ARM_BDS_LOADER_ARGUMENTS*)AllocatePool (OptionalDataSize);\r | |
313 | if (BootArguments == NULL) {\r | |
314 | return EFI_OUT_OF_RESOURCES;\r | |
315 | }\r | |
316 | BootArguments->LinuxArguments.CmdLineSize = CmdLineAsciiSize;\r | |
317 | BootArguments->LinuxArguments.InitrdSize = InitrdSize;\r | |
318 | \r | |
319 | CopyMem ((VOID*)(BootArguments + 1), AsciiDefaultBootArgument, CmdLineAsciiSize);\r | |
320 | CopyMem ((VOID*)((UINTN)(BootArguments + 1) + CmdLineAsciiSize), InitrdPath, InitrdSize);\r | |
321 | \r | |
322 | OptionalData = (UINT8*)BootArguments;\r | |
323 | } else {\r | |
324 | OptionalData = (UINT8*)DefaultBootArgument;\r | |
325 | OptionalDataSize = CmdLineSize;\r | |
326 | }\r | |
327 | \r | |
328 | BootOptionCreate (LOAD_OPTION_ACTIVE | LOAD_OPTION_CATEGORY_BOOT,\r | |
329 | (CHAR16*)PcdGetPtr(PcdDefaultBootDescription),\r | |
330 | BootDevicePath,\r | |
331 | BootType,\r | |
332 | OptionalData,\r | |
333 | OptionalDataSize,\r | |
334 | &BdsLoadOption\r | |
335 | );\r | |
336 | FreePool (BdsLoadOption);\r | |
337 | \r | |
338 | if (DefaultBootArgument == (CHAR16*)PcdGetPtr (PcdDefaultBootArgument)) {\r | |
339 | FreePool (AsciiDefaultBootArgument);\r | |
340 | } else if (DefaultBootArgument != NULL) {\r | |
341 | FreePool (DefaultBootArgument);\r | |
342 | }\r | |
343 | } else {\r | |
344 | Status = EFI_UNSUPPORTED;\r | |
345 | }\r | |
346 | }\r | |
347 | \r | |
348 | return Status;\r | |
349 | }\r | |
350 | \r | |
351 | EFI_STATUS\r | |
352 | StartDefaultBootOnTimeout (\r | |
353 | VOID\r | |
354 | )\r | |
355 | {\r | |
356 | UINTN Size;\r | |
357 | UINT16 Timeout;\r | |
358 | UINT16 *TimeoutPtr;\r | |
359 | EFI_EVENT WaitList[2];\r | |
360 | UINTN WaitIndex;\r | |
361 | UINT16 *BootOrder;\r | |
362 | UINTN BootOrderSize;\r | |
363 | UINTN Index;\r | |
364 | CHAR16 BootVariableName[9];\r | |
365 | EFI_STATUS Status;\r | |
366 | EFI_INPUT_KEY Key;\r | |
367 | \r | |
368 | Size = sizeof(UINT16);\r | |
369 | Timeout = (UINT16)PcdGet16 (PcdPlatformBootTimeOut);\r | |
370 | Status = GetGlobalEnvironmentVariable (L"Timeout", &Timeout, &Size, (VOID**)&TimeoutPtr);\r | |
371 | if (!EFI_ERROR (Status)) {\r | |
372 | Timeout = *TimeoutPtr;\r | |
373 | FreePool (TimeoutPtr);\r | |
374 | }\r | |
375 | \r | |
376 | if (Timeout != 0xFFFF) {\r | |
377 | if (Timeout > 0) {\r | |
378 | // Create the waiting events (keystroke and 1sec timer)\r | |
379 | gBS->CreateEvent (EVT_TIMER, 0, NULL, NULL, &WaitList[0]);\r | |
380 | gBS->SetTimer (WaitList[0], TimerPeriodic, EFI_SET_TIMER_TO_SECOND);\r | |
381 | WaitList[1] = gST->ConIn->WaitForKey;\r | |
382 | \r | |
383 | // Start the timer\r | |
384 | WaitIndex = 0;\r | |
385 | Print(L"The default boot selection will start in ");\r | |
386 | while ((Timeout > 0) && (WaitIndex == 0)) {\r | |
387 | Print(L"%3d seconds",Timeout);\r | |
388 | gBS->WaitForEvent (2, WaitList, &WaitIndex);\r | |
389 | if (WaitIndex == 0) {\r | |
390 | Print(L"\b\b\b\b\b\b\b\b\b\b\b");\r | |
391 | Timeout--;\r | |
392 | }\r | |
393 | }\r | |
394 | // Discard key in the buffer\r | |
395 | do {\r | |
396 | Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r | |
397 | } while(!EFI_ERROR(Status));\r | |
398 | gBS->CloseEvent (WaitList[0]);\r | |
399 | Print(L"\n\r");\r | |
400 | }\r | |
401 | \r | |
402 | // In case of Timeout we start the default boot selection\r | |
403 | if (Timeout == 0) {\r | |
404 | // Get the Boot Option Order from the environment variable (a default value should have been created)\r | |
405 | GetGlobalEnvironmentVariable (L"BootOrder", NULL, &BootOrderSize, (VOID**)&BootOrder);\r | |
406 | \r | |
407 | for (Index = 0; Index < BootOrderSize / sizeof (UINT16); Index++) {\r | |
408 | UnicodeSPrint (BootVariableName, 9 * sizeof(CHAR16), L"Boot%04X", BootOrder[Index]);\r | |
409 | Status = BdsStartBootOption (BootVariableName);\r | |
410 | if(!EFI_ERROR(Status)){\r | |
411 | // Boot option returned successfully, hence don't need to start next boot option\r | |
412 | break;\r | |
413 | }\r | |
414 | // In case of success, we should not return from this call.\r | |
415 | }\r | |
416 | FreePool (BootOrder);\r | |
417 | }\r | |
418 | }\r | |
419 | return EFI_SUCCESS;\r | |
420 | }\r | |
421 | \r | |
422 | /**\r | |
423 | An empty function to pass error checking of CreateEventEx ().\r | |
424 | \r | |
425 | @param Event Event whose notification function is being invoked.\r | |
426 | @param Context Pointer to the notification function's context,\r | |
427 | which is implementation-dependent.\r | |
428 | \r | |
429 | **/\r | |
430 | STATIC\r | |
431 | VOID\r | |
432 | EFIAPI\r | |
433 | EmptyCallbackFunction (\r | |
434 | IN EFI_EVENT Event,\r | |
435 | IN VOID *Context\r | |
436 | )\r | |
437 | {\r | |
438 | return;\r | |
439 | }\r | |
440 | \r | |
441 | /**\r | |
442 | This function uses policy data from the platform to determine what operating\r | |
443 | system or system utility should be loaded and invoked. This function call\r | |
444 | also optionally make the use of user input to determine the operating system\r | |
445 | or system utility to be loaded and invoked. When the DXE Core has dispatched\r | |
446 | all the drivers on the dispatch queue, this function is called. This\r | |
447 | function will attempt to connect the boot devices required to load and invoke\r | |
448 | the selected operating system or system utility. During this process,\r | |
449 | additional firmware volumes may be discovered that may contain addition DXE\r | |
450 | drivers that can be dispatched by the DXE Core. If a boot device cannot be\r | |
451 | fully connected, this function calls the DXE Service Dispatch() to allow the\r | |
452 | DXE drivers from any newly discovered firmware volumes to be dispatched.\r | |
453 | Then the boot device connection can be attempted again. If the same boot\r | |
454 | device connection operation fails twice in a row, then that boot device has\r | |
455 | failed, and should be skipped. This function should never return.\r | |
456 | \r | |
457 | @param This The EFI_BDS_ARCH_PROTOCOL instance.\r | |
458 | \r | |
459 | @return None.\r | |
460 | \r | |
461 | **/\r | |
462 | VOID\r | |
463 | EFIAPI\r | |
464 | BdsEntry (\r | |
465 | IN EFI_BDS_ARCH_PROTOCOL *This\r | |
466 | )\r | |
467 | {\r | |
468 | UINTN Size;\r | |
469 | EFI_STATUS Status;\r | |
470 | UINT16 *BootNext;\r | |
471 | UINTN BootNextSize;\r | |
472 | CHAR16 BootVariableName[9];\r | |
473 | EFI_EVENT EndOfDxeEvent;\r | |
474 | \r | |
475 | //\r | |
476 | // Signal EndOfDxe PI Event\r | |
477 | //\r | |
478 | Status = gBS->CreateEventEx (\r | |
479 | EVT_NOTIFY_SIGNAL,\r | |
480 | TPL_NOTIFY,\r | |
481 | EmptyCallbackFunction,\r | |
482 | NULL,\r | |
483 | &gEfiEndOfDxeEventGroupGuid,\r | |
484 | &EndOfDxeEvent\r | |
485 | );\r | |
486 | if (!EFI_ERROR (Status)) {\r | |
487 | gBS->SignalEvent (EndOfDxeEvent);\r | |
488 | }\r | |
489 | \r | |
490 | PERF_END (NULL, "DXE", NULL, 0);\r | |
491 | \r | |
492 | //\r | |
493 | // Declare the Firmware Vendor\r | |
494 | //\r | |
495 | if (FixedPcdGetPtr(PcdFirmwareVendor) != NULL) {\r | |
496 | Size = 0x100;\r | |
497 | gST->FirmwareVendor = AllocateRuntimePool (Size);\r | |
498 | ASSERT (gST->FirmwareVendor != NULL);\r | |
499 | UnicodeSPrint (gST->FirmwareVendor, Size, L"%a EFI %a %a", PcdGetPtr(PcdFirmwareVendor), __DATE__, __TIME__);\r | |
500 | }\r | |
501 | \r | |
502 | //\r | |
503 | // Fixup Table CRC after we updated Firmware Vendor\r | |
504 | //\r | |
505 | gST->Hdr.CRC32 = 0;\r | |
506 | Status = gBS->CalculateCrc32 ((VOID*)gST, gST->Hdr.HeaderSize, &gST->Hdr.CRC32);\r | |
507 | ASSERT_EFI_ERROR (Status);\r | |
508 | \r | |
509 | // If BootNext environment variable is defined then we just load it !\r | |
510 | BootNextSize = sizeof(UINT16);\r | |
511 | Status = GetGlobalEnvironmentVariable (L"BootNext", NULL, &BootNextSize, (VOID**)&BootNext);\r | |
512 | if (!EFI_ERROR(Status)) {\r | |
513 | ASSERT(BootNextSize == sizeof(UINT16));\r | |
514 | \r | |
515 | // Generate the requested Boot Entry variable name\r | |
516 | UnicodeSPrint (BootVariableName, 9 * sizeof(CHAR16), L"Boot%04X", *BootNext);\r | |
517 | \r | |
518 | // Set BootCurrent variable\r | |
519 | gRT->SetVariable (L"BootCurrent", &gEfiGlobalVariableGuid,\r | |
520 | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r | |
521 | BootNextSize, BootNext);\r | |
522 | \r | |
523 | FreePool (BootNext);\r | |
524 | \r | |
525 | // Start the requested Boot Entry\r | |
526 | Status = BdsStartBootOption (BootVariableName);\r | |
527 | if (Status != EFI_NOT_FOUND) {\r | |
528 | // BootNext has not been succeeded launched\r | |
529 | if (EFI_ERROR(Status)) {\r | |
530 | Print(L"Fail to start BootNext.\n");\r | |
531 | }\r | |
532 | \r | |
533 | // Delete the BootNext environment variable\r | |
534 | gRT->SetVariable (L"BootNext", &gEfiGlobalVariableGuid,\r | |
535 | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r | |
536 | 0, NULL);\r | |
537 | }\r | |
538 | \r | |
539 | // Clear BootCurrent variable\r | |
540 | gRT->SetVariable (L"BootCurrent", &gEfiGlobalVariableGuid,\r | |
541 | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r | |
542 | 0, NULL);\r | |
543 | }\r | |
544 | \r | |
545 | // If Boot Order does not exist then create a default entry\r | |
546 | DefineDefaultBootEntries ();\r | |
547 | \r | |
548 | // Now we need to setup the EFI System Table with information about the console devices.\r | |
549 | InitializeConsole ();\r | |
550 | \r | |
551 | //\r | |
552 | // Update the CRC32 in the EFI System Table header\r | |
553 | //\r | |
554 | gST->Hdr.CRC32 = 0;\r | |
555 | Status = gBS->CalculateCrc32 ((VOID*)gST, gST->Hdr.HeaderSize, &gST->Hdr.CRC32);\r | |
556 | ASSERT_EFI_ERROR (Status);\r | |
557 | \r | |
558 | // Timer before initiating the default boot selection\r | |
559 | StartDefaultBootOnTimeout ();\r | |
560 | \r | |
561 | // Start the Boot Menu\r | |
562 | Status = BootMenuMain ();\r | |
563 | ASSERT_EFI_ERROR (Status);\r | |
564 | \r | |
565 | }\r | |
566 | \r | |
567 | EFI_BDS_ARCH_PROTOCOL gBdsProtocol = {\r | |
568 | BdsEntry,\r | |
569 | };\r | |
570 | \r | |
571 | EFI_STATUS\r | |
572 | EFIAPI\r | |
573 | BdsInitialize (\r | |
574 | IN EFI_HANDLE ImageHandle,\r | |
575 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
576 | )\r | |
577 | {\r | |
578 | EFI_STATUS Status;\r | |
579 | \r | |
580 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
581 | &ImageHandle,\r | |
582 | &gEfiBdsArchProtocolGuid, &gBdsProtocol,\r | |
583 | NULL\r | |
584 | );\r | |
585 | ASSERT_EFI_ERROR (Status);\r | |
586 | \r | |
587 | return Status;\r | |
588 | }\r |