]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Universal/BdsDxe/BdsEntry.c
Update the license dates
[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
59b9d73e 8Copyright (c) 2004 - 2011, 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
5c08e117 41/**\r
42\r
43 Install Boot Device Selection Protocol\r
44\r
45 @param ImageHandle The image handle.\r
46 @param SystemTable The system table.\r
47\r
48 @retval EFI_SUCEESS BDS has finished initializing.\r
49 Return the dispatcher and recall BDS.Entry\r
50 @retval Other Return status from AllocatePool() or gBS->InstallProtocolInterface\r
51\r
52**/\r
53EFI_STATUS\r
54EFIAPI\r
55BdsInitialize (\r
56 IN EFI_HANDLE ImageHandle,\r
57 IN EFI_SYSTEM_TABLE *SystemTable\r
58 )\r
59{\r
60 EFI_STATUS Status;\r
61\r
5c08e117 62 //\r
63 // Install protocol interface\r
64 //\r
f7cdf5cd 65 Status = gBS->InstallMultipleProtocolInterfaces (\r
66 &gBdsHandle,\r
67 &gEfiBdsArchProtocolGuid, &gBds,\r
68 NULL\r
5c08e117 69 );\r
70 ASSERT_EFI_ERROR (Status);\r
71\r
72 return Status;\r
73}\r
74\r
75/**\r
76\r
77 This function attempts to boot for the boot order specified\r
78 by platform policy.\r
79\r
80**/\r
81VOID\r
82BdsBootDeviceSelect (\r
83 VOID\r
84 )\r
85{\r
86 EFI_STATUS Status;\r
87 LIST_ENTRY *Link;\r
88 BDS_COMMON_OPTION *BootOption;\r
89 UINTN ExitDataSize;\r
90 CHAR16 *ExitData;\r
91 UINT16 Timeout;\r
92 LIST_ENTRY BootLists;\r
93 CHAR16 Buffer[20];\r
94 BOOLEAN BootNextExist;\r
95 LIST_ENTRY *LinkBootNext;\r
96\r
97 //\r
98 // Got the latest boot option\r
99 //\r
100 BootNextExist = FALSE;\r
101 LinkBootNext = NULL;\r
102 InitializeListHead (&BootLists);\r
103\r
104 //\r
105 // First check the boot next option\r
106 //\r
107 ZeroMem (Buffer, sizeof (Buffer));\r
108\r
109 if (mBootNext != NULL) {\r
110 //\r
111 // Indicate we have the boot next variable, so this time\r
112 // boot will always have this boot option\r
113 //\r
114 BootNextExist = TRUE;\r
115\r
116 //\r
117 // Clear the this variable so it's only exist in this time boot\r
118 //\r
119 gRT->SetVariable (\r
120 L"BootNext",\r
121 &gEfiGlobalVariableGuid,\r
122 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
123 0,\r
124 mBootNext\r
125 );\r
126\r
127 //\r
128 // Add the boot next boot option\r
129 //\r
130 UnicodeSPrint (Buffer, sizeof (Buffer), L"Boot%04x", *mBootNext);\r
131 BootOption = BdsLibVariableToOption (&BootLists, Buffer);\r
128efbbc 132\r
5c08e117 133 //\r
134 // If fail to get boot option from variable, just return and do nothing.\r
135 //\r
136 if (BootOption == NULL) {\r
137 return;\r
138 }\r
128efbbc 139\r
5c08e117 140 BootOption->BootCurrent = *mBootNext;\r
141 }\r
142 //\r
143 // Parse the boot order to get boot option\r
144 //\r
145 BdsLibBuildOptionFromVar (&BootLists, L"BootOrder");\r
d8600108
RN
146\r
147 //\r
148 // When we didn't have chance to build boot option variables in the first \r
149 // full configuration boot (e.g.: Reset in the first page or in Device Manager),\r
150 // we have no boot options in the following mini configuration boot.\r
151 // Give the last chance to enumerate the boot options.\r
152 //\r
153 if (IsListEmpty (&BootLists)) {\r
154 BdsLibEnumerateAllBootOption (&BootLists);\r
155 }\r
156\r
5c08e117 157 Link = BootLists.ForwardLink;\r
158\r
159 //\r
160 // Parameter check, make sure the loop will be valid\r
161 //\r
162 if (Link == NULL) {\r
163 return ;\r
164 }\r
165 //\r
166 // Here we make the boot in a loop, every boot success will\r
167 // return to the front page\r
168 //\r
169 for (;;) {\r
170 //\r
171 // Check the boot option list first\r
172 //\r
173 if (Link == &BootLists) {\r
174 //\r
175 // There are two ways to enter here:\r
176 // 1. There is no active boot option, give user chance to\r
177 // add new boot option\r
178 // 2. All the active boot option processed, and there is no\r
179 // one is success to boot, then we back here to allow user\r
180 // add new active boot option\r
181 //\r
182 Timeout = 0xffff;\r
183 PlatformBdsEnterFrontPage (Timeout, FALSE);\r
184 InitializeListHead (&BootLists);\r
185 BdsLibBuildOptionFromVar (&BootLists, L"BootOrder");\r
186 Link = BootLists.ForwardLink;\r
187 continue;\r
188 }\r
189 //\r
190 // Get the boot option from the link list\r
191 //\r
192 BootOption = CR (Link, BDS_COMMON_OPTION, Link, BDS_LOAD_OPTION_SIGNATURE);\r
193\r
194 //\r
195 // According to EFI Specification, if a load option is not marked\r
196 // as LOAD_OPTION_ACTIVE, the boot manager will not automatically\r
197 // load the option.\r
198 //\r
199 if (!IS_LOAD_OPTION_TYPE (BootOption->Attribute, LOAD_OPTION_ACTIVE)) {\r
200 //\r
baf46e70 201 // skip the header of the link list, because it has no boot option\r
5c08e117 202 //\r
203 Link = Link->ForwardLink;\r
204 continue;\r
205 }\r
206 //\r
207 // Make sure the boot option device path connected,\r
208 // but ignore the BBS device path\r
209 //\r
210 if (DevicePathType (BootOption->DevicePath) != BBS_DEVICE_PATH) {\r
211 //\r
212 // Notes: the internal shell can not been connected with device path\r
213 // so we do not check the status here\r
214 //\r
215 BdsLibConnectDevicePath (BootOption->DevicePath);\r
216 }\r
217 //\r
218 // All the driver options should have been processed since\r
219 // now boot will be performed.\r
220 //\r
221 Status = BdsLibBootViaBootOption (BootOption, BootOption->DevicePath, &ExitDataSize, &ExitData);\r
59b9d73e 222 if (Status != EFI_SUCCESS) {\r
5c08e117 223 //\r
224 // Call platform action to indicate the boot fail\r
225 //\r
226 BootOption->StatusString = GetStringById (STRING_TOKEN (STR_BOOT_FAILED));\r
227 PlatformBdsBootFail (BootOption, Status, ExitData, ExitDataSize);\r
228\r
229 //\r
230 // Check the next boot option\r
231 //\r
232 Link = Link->ForwardLink;\r
233\r
234 } else {\r
235 //\r
236 // Call platform action to indicate the boot success\r
237 //\r
128efbbc 238 BootOption->StatusString = GetStringById (STRING_TOKEN (STR_BOOT_SUCCEEDED));\r
5c08e117 239 PlatformBdsBootSuccess (BootOption);\r
240\r
241 //\r
242 // Boot success, then stop process the boot order, and\r
243 // present the boot manager menu, front page\r
244 //\r
245 Timeout = 0xffff;\r
246 PlatformBdsEnterFrontPage (Timeout, FALSE);\r
247\r
248 //\r
baf46e70 249 // Rescan the boot option list, avoid potential risk of the boot\r
5c08e117 250 // option change in front page\r
251 //\r
252 if (BootNextExist) {\r
253 LinkBootNext = BootLists.ForwardLink;\r
254 }\r
255\r
256 InitializeListHead (&BootLists);\r
257 if (LinkBootNext != NULL) {\r
258 //\r
259 // Reserve the boot next option\r
260 //\r
261 InsertTailList (&BootLists, LinkBootNext);\r
262 }\r
263\r
264 BdsLibBuildOptionFromVar (&BootLists, L"BootOrder");\r
265 Link = BootLists.ForwardLink;\r
266 }\r
267 }\r
268\r
269}\r
270\r
271/**\r
272\r
273 Service routine for BdsInstance->Entry(). Devices are connected, the\r
274 consoles are initialized, and the boot options are tried.\r
275\r
276 @param This Protocol Instance structure.\r
277\r
278**/\r
279VOID\r
280EFIAPI\r
281BdsEntry (\r
282 IN EFI_BDS_ARCH_PROTOCOL *This\r
283 )\r
284{\r
5c08e117 285 LIST_ENTRY DriverOptionList;\r
286 LIST_ENTRY BootOptionList;\r
287 UINTN BootNextSize;\r
9a6b4de2 288 CHAR16 *FirmwareVendor;\r
5c08e117 289\r
290 //\r
291 // Insert the performance probe\r
292 //\r
128efbbc 293 PERF_END (NULL, "DXE", NULL, 0);\r
294 PERF_START (NULL, "BDS", NULL, 0);\r
5c08e117 295\r
296 //\r
297 // Initialize the global system boot option and driver option\r
298 //\r
299 InitializeListHead (&DriverOptionList);\r
300 InitializeListHead (&BootOptionList);\r
301\r
302 //\r
303 // Initialize hotkey service\r
304 //\r
305 InitializeHotkeyService ();\r
306\r
9a6b4de2 307 //\r
308 // Fill in FirmwareVendor and FirmwareRevision from PCDs\r
309 //\r
310 FirmwareVendor = (CHAR16 *)PcdGetPtr (PcdFirmwareVendor);\r
311 gST->FirmwareVendor = AllocateRuntimeCopyPool (StrSize (FirmwareVendor), FirmwareVendor);\r
312 ASSERT (gST->FirmwareVendor != NULL);\r
313 gST->FirmwareRevision = PcdGet32 (PcdFirmwareRevision);\r
314\r
315 //\r
316 // Fixup Tasble CRC after we updated Firmware Vendor and Revision\r
317 //\r
318 gBS->CalculateCrc32 ((VOID *)gST, sizeof(EFI_SYSTEM_TABLE), &gST->Hdr.CRC32);\r
319\r
5c08e117 320 //\r
321 // Do the platform init, can be customized by OEM/IBV\r
322 //\r
128efbbc 323 PERF_START (NULL, "PlatformBds", "BDS", 0);\r
f7cdf5cd 324 PlatformBdsInit ();\r
5c08e117 325\r
a2b35995 326 InitializeHwErrRecSupport();\r
128efbbc 327\r
5c08e117 328 //\r
329 // bugbug: platform specific code\r
330 // Initialize the platform specific string and language\r
331 //\r
332 InitializeStringSupport ();\r
333 InitializeLanguage (TRUE);\r
334 InitializeFrontPage (TRUE);\r
335\r
336 //\r
337 // Set up the device list based on EFI 1.1 variables\r
338 // process Driver#### and Load the driver's in the\r
339 // driver option list\r
340 //\r
341 BdsLibBuildOptionFromVar (&DriverOptionList, L"DriverOrder");\r
342 if (!IsListEmpty (&DriverOptionList)) {\r
343 BdsLibLoadDrivers (&DriverOptionList);\r
344 }\r
345 //\r
346 // Check if we have the boot next option\r
347 //\r
348 mBootNext = BdsLibGetVariableAndSize (\r
349 L"BootNext",\r
350 &gEfiGlobalVariableGuid,\r
351 &BootNextSize\r
352 );\r
353\r
354 //\r
355 // Setup some platform policy here\r
356 //\r
19bf20e1 357 PlatformBdsPolicyBehavior (&DriverOptionList, &BootOptionList, BdsProcessCapsules, BdsMemoryTest);\r
128efbbc 358 PERF_END (NULL, "PlatformBds", "BDS", 0);\r
5c08e117 359\r
360 //\r
361 // BDS select the boot device to load OS\r
362 //\r
363 BdsBootDeviceSelect ();\r
364\r
365 //\r
366 // Only assert here since this is the right behavior, we should never\r
367 // return back to DxeCore.\r
368 //\r
369 ASSERT (FALSE);\r
370\r
371 return ;\r
372}\r