]>
Commit | Line | Data |
---|---|---|
fd6a62f3 | 1 | /** @file\r |
2 | The entry of the bds\r | |
93e3992d | 3 | \r |
fd6a62f3 | 4 | Copyright (c) 2004 - 2008, Intel Corporation. <BR>\r |
93e3992d | 5 | All rights reserved. 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 | |
fd6a62f3 | 13 | **/\r |
93e3992d | 14 | \r |
15 | #include "Bds.h"\r | |
16 | #include "Language.h"\r | |
17 | #include "FrontPage.h"\r | |
18 | #include "Hotkey.h"\r | |
19 | #include "HwErrRecSupport.h"\r | |
20 | \r | |
21 | \r | |
22 | EFI_BDS_ARCH_PROTOCOL_INSTANCE gBdsInstanceTemplate = {\r | |
23 | EFI_BDS_ARCH_PROTOCOL_INSTANCE_SIGNATURE,\r | |
24 | NULL,\r | |
25 | {BdsEntry},\r | |
26 | 0xFFFF,\r | |
27 | TRUE,\r | |
28 | EXTENSIVE\r | |
29 | };\r | |
30 | \r | |
31 | UINT16 *mBootNext = NULL;\r | |
32 | \r | |
33 | EFI_HANDLE mBdsImageHandle;\r | |
34 | \r | |
b30312ba | 35 | /**\r |
93e3992d | 36 | \r |
37 | Install Boot Device Selection Protocol\r | |
38 | \r | |
93e3992d | 39 | \r |
b30312ba | 40 | @param ImageHandle The image handle.\r |
41 | @param SystemTable The system table.\r | |
93e3992d | 42 | \r |
b30312ba | 43 | @retval EFI_SUCEESS BDS has finished initializing.\r |
44 | Rerun the\r | |
45 | dispatcher and recall BDS.Entry\r | |
46 | @retval Other Return value from AllocatePool()\r | |
47 | or gBS->InstallProtocolInterface\r | |
93e3992d | 48 | \r |
b30312ba | 49 | **/\r |
50 | EFI_STATUS\r | |
51 | EFIAPI\r | |
52 | BdsInitialize (\r | |
53 | IN EFI_HANDLE ImageHandle,\r | |
54 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
55 | )\r | |
93e3992d | 56 | {\r |
57 | EFI_STATUS Status;\r | |
58 | \r | |
59 | mBdsImageHandle = ImageHandle;\r | |
60 | \r | |
61 | //\r | |
62 | // Install protocol interface\r | |
63 | //\r | |
64 | Status = gBS->InstallProtocolInterface (\r | |
65 | &gBdsInstanceTemplate.Handle,\r | |
66 | &gEfiBdsArchProtocolGuid,\r | |
67 | EFI_NATIVE_INTERFACE,\r | |
68 | &gBdsInstanceTemplate.Bds\r | |
69 | );\r | |
70 | ASSERT_EFI_ERROR (Status);\r | |
71 | \r | |
72 | return Status;\r | |
73 | }\r | |
74 | \r | |
b30312ba | 75 | /**\r |
93e3992d | 76 | \r |
b4489769 | 77 | This function attempts to boot for the boot order specified\r |
78 | by platform policy.\r | |
93e3992d | 79 | \r |
b30312ba | 80 | **/\r |
81 | VOID\r | |
82 | BdsBootDeviceSelect (\r | |
83 | VOID\r | |
84 | )\r | |
93e3992d | 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 | |
132 | BootOption->BootCurrent = *mBootNext;\r | |
133 | }\r | |
134 | //\r | |
135 | // Parse the boot order to get boot option\r | |
136 | //\r | |
137 | BdsLibBuildOptionFromVar (&BootLists, L"BootOrder");\r | |
138 | Link = BootLists.ForwardLink;\r | |
139 | \r | |
140 | //\r | |
141 | // Parameter check, make sure the loop will be valid\r | |
142 | //\r | |
143 | if (Link == NULL) {\r | |
144 | return ;\r | |
145 | }\r | |
146 | //\r | |
147 | // Here we make the boot in a loop, every boot success will\r | |
148 | // return to the front page\r | |
149 | //\r | |
150 | for (;;) {\r | |
151 | //\r | |
152 | // Check the boot option list first\r | |
153 | //\r | |
154 | if (Link == &BootLists) {\r | |
155 | //\r | |
156 | // There are two ways to enter here:\r | |
157 | // 1. There is no active boot option, give user chance to\r | |
158 | // add new boot option\r | |
159 | // 2. All the active boot option processed, and there is no\r | |
160 | // one is success to boot, then we back here to allow user\r | |
161 | // add new active boot option\r | |
162 | //\r | |
163 | Timeout = 0xffff;\r | |
164 | PlatformBdsEnterFrontPage (Timeout, FALSE);\r | |
165 | InitializeListHead (&BootLists);\r | |
166 | BdsLibBuildOptionFromVar (&BootLists, L"BootOrder");\r | |
167 | Link = BootLists.ForwardLink;\r | |
168 | continue;\r | |
169 | }\r | |
170 | //\r | |
171 | // Get the boot option from the link list\r | |
172 | //\r | |
173 | BootOption = CR (Link, BDS_COMMON_OPTION, Link, BDS_LOAD_OPTION_SIGNATURE);\r | |
174 | \r | |
175 | //\r | |
176 | // According to EFI Specification, if a load option is not marked\r | |
177 | // as LOAD_OPTION_ACTIVE, the boot manager will not automatically\r | |
178 | // load the option.\r | |
179 | //\r | |
180 | if (!IS_LOAD_OPTION_TYPE (BootOption->Attribute, LOAD_OPTION_ACTIVE)) {\r | |
181 | //\r | |
182 | // skip the header of the link list, becuase it has no boot option\r | |
183 | //\r | |
184 | Link = Link->ForwardLink;\r | |
185 | continue;\r | |
186 | }\r | |
187 | //\r | |
188 | // Make sure the boot option device path connected,\r | |
189 | // but ignore the BBS device path\r | |
190 | //\r | |
191 | if (DevicePathType (BootOption->DevicePath) != BBS_DEVICE_PATH) {\r | |
192 | //\r | |
193 | // Notes: the internal shell can not been connected with device path\r | |
194 | // so we do not check the status here\r | |
195 | //\r | |
196 | BdsLibConnectDevicePath (BootOption->DevicePath);\r | |
197 | }\r | |
198 | //\r | |
199 | // All the driver options should have been processed since\r | |
200 | // now boot will be performed.\r | |
201 | //\r | |
202 | Status = BdsLibBootViaBootOption (BootOption, BootOption->DevicePath, &ExitDataSize, &ExitData);\r | |
203 | if (EFI_ERROR (Status)) {\r | |
204 | //\r | |
205 | // Call platform action to indicate the boot fail\r | |
206 | //\r | |
207 | BootOption->StatusString = GetStringById (STRING_TOKEN (STR_BOOT_FAILED));\r | |
208 | PlatformBdsBootFail (BootOption, Status, ExitData, ExitDataSize);\r | |
209 | \r | |
210 | //\r | |
211 | // Check the next boot option\r | |
212 | //\r | |
213 | Link = Link->ForwardLink;\r | |
214 | \r | |
215 | } else {\r | |
216 | //\r | |
217 | // Call platform action to indicate the boot success\r | |
218 | //\r | |
219 | BootOption->StatusString = GetStringById (STRING_TOKEN (STR_BOOT_SUCCEEDED)); \r | |
220 | PlatformBdsBootSuccess (BootOption);\r | |
221 | \r | |
222 | //\r | |
223 | // Boot success, then stop process the boot order, and\r | |
224 | // present the boot manager menu, front page\r | |
225 | //\r | |
226 | Timeout = 0xffff;\r | |
227 | PlatformBdsEnterFrontPage (Timeout, FALSE);\r | |
228 | \r | |
229 | //\r | |
230 | // Rescan the boot option list, avoid pertential risk of the boot\r | |
231 | // option change in front page\r | |
232 | //\r | |
233 | if (BootNextExist) {\r | |
234 | LinkBootNext = BootLists.ForwardLink;\r | |
235 | }\r | |
236 | \r | |
237 | InitializeListHead (&BootLists);\r | |
238 | if (LinkBootNext != NULL) {\r | |
239 | //\r | |
240 | // Reserve the boot next option\r | |
241 | //\r | |
242 | InsertTailList (&BootLists, LinkBootNext);\r | |
243 | }\r | |
244 | \r | |
245 | BdsLibBuildOptionFromVar (&BootLists, L"BootOrder");\r | |
246 | Link = BootLists.ForwardLink;\r | |
247 | }\r | |
248 | }\r | |
249 | \r | |
250 | }\r | |
251 | \r | |
b30312ba | 252 | /**\r |
93e3992d | 253 | \r |
254 | Service routine for BdsInstance->Entry(). Devices are connected, the\r | |
255 | consoles are initialized, and the boot options are tried.\r | |
256 | \r | |
93e3992d | 257 | \r |
b30312ba | 258 | @param This - Protocol Instance structure.\r |
93e3992d | 259 | \r |
b30312ba | 260 | @retval EFI_SUCEESS BDS->Entry has finished executing.\r |
93e3992d | 261 | \r |
b30312ba | 262 | **/\r |
263 | VOID\r | |
264 | EFIAPI\r | |
265 | BdsEntry (\r | |
266 | IN EFI_BDS_ARCH_PROTOCOL *This\r | |
267 | )\r | |
93e3992d | 268 | {\r |
269 | EFI_BDS_ARCH_PROTOCOL_INSTANCE *PrivateData;\r | |
270 | LIST_ENTRY DriverOptionList;\r | |
271 | LIST_ENTRY BootOptionList;\r | |
272 | UINTN BootNextSize;\r | |
273 | \r | |
274 | //\r | |
275 | // Insert the performance probe\r | |
276 | //\r | |
277 | PERF_END (0, DXE_TOK, NULL, 0);\r | |
278 | PERF_START (0, BDS_TOK, NULL, 0);\r | |
279 | \r | |
280 | //\r | |
281 | // Initialize the global system boot option and driver option\r | |
282 | //\r | |
283 | InitializeListHead (&DriverOptionList);\r | |
284 | InitializeListHead (&BootOptionList);\r | |
285 | \r | |
286 | //\r | |
287 | // Initialize hotkey service\r | |
288 | //\r | |
289 | InitializeHotkeyService ();\r | |
290 | \r | |
291 | //\r | |
292 | // Get the BDS private data\r | |
293 | //\r | |
294 | PrivateData = EFI_BDS_ARCH_PROTOCOL_INSTANCE_FROM_THIS (This);\r | |
295 | \r | |
296 | //\r | |
297 | // Do the platform init, can be customized by OEM/IBV\r | |
298 | //\r | |
299 | PERF_START (0, "PlatformBds", "BDS", 0);\r | |
300 | PlatformBdsInit (PrivateData);\r | |
301 | \r | |
302 | if (FeaturePcdGet (PcdSupportHardwareErrorRecord)) {\r | |
303 | InitializeHwErrRecSupport (PcdGet16 (PcdHardwareErrorRecordLevel));\r | |
304 | }\r | |
305 | //\r | |
306 | // bugbug: platform specific code\r | |
307 | // Initialize the platform specific string and language\r | |
308 | //\r | |
309 | InitializeStringSupport ();\r | |
310 | InitializeLanguage (TRUE);\r | |
b30312ba | 311 | InitializeFrontPage (TRUE);\r |
93e3992d | 312 | \r |
313 | //\r | |
314 | // Set up the device list based on EFI 1.1 variables\r | |
315 | // process Driver#### and Load the driver's in the\r | |
316 | // driver option list\r | |
317 | //\r | |
318 | BdsLibBuildOptionFromVar (&DriverOptionList, L"DriverOrder");\r | |
319 | if (!IsListEmpty (&DriverOptionList)) {\r | |
320 | BdsLibLoadDrivers (&DriverOptionList);\r | |
321 | }\r | |
322 | //\r | |
323 | // Check if we have the boot next option\r | |
324 | //\r | |
325 | mBootNext = BdsLibGetVariableAndSize (\r | |
326 | L"BootNext",\r | |
327 | &gEfiGlobalVariableGuid,\r | |
328 | &BootNextSize\r | |
329 | );\r | |
330 | \r | |
331 | //\r | |
332 | // Setup some platform policy here\r | |
333 | //\r | |
334 | PlatformBdsPolicyBehavior (PrivateData, &DriverOptionList, &BootOptionList);\r | |
335 | PERF_END (0, "PlatformBds", "BDS", 0);\r | |
336 | \r | |
337 | //\r | |
338 | // BDS select the boot device to load OS\r | |
339 | //\r | |
340 | BdsBootDeviceSelect ();\r | |
341 | \r | |
342 | //\r | |
343 | // Only assert here since this is the right behavior, we should never\r | |
344 | // return back to DxeCore.\r | |
345 | //\r | |
346 | ASSERT (FALSE);\r | |
347 | \r | |
348 | return ;\r | |
349 | }\r |