]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/BdsDxe/BdsEntry.c
Update BootSectImage and GenBootSector tools' binary for DUET platform.
[mirror_edk2.git] / MdeModulePkg / Universal / BdsDxe / BdsEntry.c
CommitLineData
fd6a62f3 1/** @file\r
2 The entry of the bds\r
93e3992d 3\r
fd6a62f3 4Copyright (c) 2004 - 2008, Intel Corporation. <BR>\r
93e3992d 5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT 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
22EFI_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
31UINT16 *mBootNext = NULL;\r
32\r
33EFI_HANDLE mBdsImageHandle;\r
34\r
35EFI_STATUS\r
36EFIAPI\r
37BdsInitialize (\r
38 IN EFI_HANDLE ImageHandle,\r
39 IN EFI_SYSTEM_TABLE *SystemTable\r
40 )\r
41/*++\r
42\r
43Routine Description:\r
44\r
45 Install Boot Device Selection Protocol\r
46\r
47Arguments:\r
48\r
49 (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)\r
50\r
51Returns:\r
52\r
53 EFI_SUCEESS - BDS has finished initializing.\r
54 Rerun the\r
55 dispatcher and recall BDS.Entry\r
56\r
57 Other - Return value from AllocatePool()\r
58 or gBS->InstallProtocolInterface\r
59\r
60--*/\r
61{\r
62 EFI_STATUS Status;\r
63\r
64 mBdsImageHandle = ImageHandle;\r
65\r
66 //\r
67 // Install protocol interface\r
68 //\r
69 Status = gBS->InstallProtocolInterface (\r
70 &gBdsInstanceTemplate.Handle,\r
71 &gEfiBdsArchProtocolGuid,\r
72 EFI_NATIVE_INTERFACE,\r
73 &gBdsInstanceTemplate.Bds\r
74 );\r
75 ASSERT_EFI_ERROR (Status);\r
76\r
77 return Status;\r
78}\r
79\r
80VOID\r
81BdsBootDeviceSelect (\r
82 VOID\r
83 )\r
84/*++\r
85\r
86Routine Description:\r
87\r
88 In the loop of attempt to boot for the boot order\r
89\r
90Arguments:\r
91\r
92 None.\r
93\r
94Returns:\r
95\r
96 None.\r
97\r
98--*/\r
99{\r
100 EFI_STATUS Status;\r
101 LIST_ENTRY *Link;\r
102 BDS_COMMON_OPTION *BootOption;\r
103 UINTN ExitDataSize;\r
104 CHAR16 *ExitData;\r
105 UINT16 Timeout;\r
106 LIST_ENTRY BootLists;\r
107 CHAR16 Buffer[20];\r
108 BOOLEAN BootNextExist;\r
109 LIST_ENTRY *LinkBootNext;\r
110\r
111 //\r
112 // Got the latest boot option\r
113 //\r
114 BootNextExist = FALSE;\r
115 LinkBootNext = NULL;\r
116 InitializeListHead (&BootLists);\r
117\r
118 //\r
119 // First check the boot next option\r
120 //\r
121 ZeroMem (Buffer, sizeof (Buffer));\r
122\r
123 if (mBootNext != NULL) {\r
124 //\r
125 // Indicate we have the boot next variable, so this time\r
126 // boot will always have this boot option\r
127 //\r
128 BootNextExist = TRUE;\r
129\r
130 //\r
131 // Clear the this variable so it's only exist in this time boot\r
132 //\r
133 gRT->SetVariable (\r
134 L"BootNext",\r
135 &gEfiGlobalVariableGuid,\r
136 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
137 0,\r
138 mBootNext\r
139 );\r
140\r
141 //\r
142 // Add the boot next boot option\r
143 //\r
144 UnicodeSPrint (Buffer, sizeof (Buffer), L"Boot%04x", *mBootNext);\r
145 BootOption = BdsLibVariableToOption (&BootLists, Buffer);\r
146 BootOption->BootCurrent = *mBootNext;\r
147 }\r
148 //\r
149 // Parse the boot order to get boot option\r
150 //\r
151 BdsLibBuildOptionFromVar (&BootLists, L"BootOrder");\r
152 Link = BootLists.ForwardLink;\r
153\r
154 //\r
155 // Parameter check, make sure the loop will be valid\r
156 //\r
157 if (Link == NULL) {\r
158 return ;\r
159 }\r
160 //\r
161 // Here we make the boot in a loop, every boot success will\r
162 // return to the front page\r
163 //\r
164 for (;;) {\r
165 //\r
166 // Check the boot option list first\r
167 //\r
168 if (Link == &BootLists) {\r
169 //\r
170 // There are two ways to enter here:\r
171 // 1. There is no active boot option, give user chance to\r
172 // add new boot option\r
173 // 2. All the active boot option processed, and there is no\r
174 // one is success to boot, then we back here to allow user\r
175 // add new active boot option\r
176 //\r
177 Timeout = 0xffff;\r
178 PlatformBdsEnterFrontPage (Timeout, FALSE);\r
179 InitializeListHead (&BootLists);\r
180 BdsLibBuildOptionFromVar (&BootLists, L"BootOrder");\r
181 Link = BootLists.ForwardLink;\r
182 continue;\r
183 }\r
184 //\r
185 // Get the boot option from the link list\r
186 //\r
187 BootOption = CR (Link, BDS_COMMON_OPTION, Link, BDS_LOAD_OPTION_SIGNATURE);\r
188\r
189 //\r
190 // According to EFI Specification, if a load option is not marked\r
191 // as LOAD_OPTION_ACTIVE, the boot manager will not automatically\r
192 // load the option.\r
193 //\r
194 if (!IS_LOAD_OPTION_TYPE (BootOption->Attribute, LOAD_OPTION_ACTIVE)) {\r
195 //\r
196 // skip the header of the link list, becuase it has no boot option\r
197 //\r
198 Link = Link->ForwardLink;\r
199 continue;\r
200 }\r
201 //\r
202 // Make sure the boot option device path connected,\r
203 // but ignore the BBS device path\r
204 //\r
205 if (DevicePathType (BootOption->DevicePath) != BBS_DEVICE_PATH) {\r
206 //\r
207 // Notes: the internal shell can not been connected with device path\r
208 // so we do not check the status here\r
209 //\r
210 BdsLibConnectDevicePath (BootOption->DevicePath);\r
211 }\r
212 //\r
213 // All the driver options should have been processed since\r
214 // now boot will be performed.\r
215 //\r
216 Status = BdsLibBootViaBootOption (BootOption, BootOption->DevicePath, &ExitDataSize, &ExitData);\r
217 if (EFI_ERROR (Status)) {\r
218 //\r
219 // Call platform action to indicate the boot fail\r
220 //\r
221 BootOption->StatusString = GetStringById (STRING_TOKEN (STR_BOOT_FAILED));\r
222 PlatformBdsBootFail (BootOption, Status, ExitData, ExitDataSize);\r
223\r
224 //\r
225 // Check the next boot option\r
226 //\r
227 Link = Link->ForwardLink;\r
228\r
229 } else {\r
230 //\r
231 // Call platform action to indicate the boot success\r
232 //\r
233 BootOption->StatusString = GetStringById (STRING_TOKEN (STR_BOOT_SUCCEEDED)); \r
234 PlatformBdsBootSuccess (BootOption);\r
235\r
236 //\r
237 // Boot success, then stop process the boot order, and\r
238 // present the boot manager menu, front page\r
239 //\r
240 Timeout = 0xffff;\r
241 PlatformBdsEnterFrontPage (Timeout, FALSE);\r
242\r
243 //\r
244 // Rescan the boot option list, avoid pertential risk of the boot\r
245 // option change in front page\r
246 //\r
247 if (BootNextExist) {\r
248 LinkBootNext = BootLists.ForwardLink;\r
249 }\r
250\r
251 InitializeListHead (&BootLists);\r
252 if (LinkBootNext != NULL) {\r
253 //\r
254 // Reserve the boot next option\r
255 //\r
256 InsertTailList (&BootLists, LinkBootNext);\r
257 }\r
258\r
259 BdsLibBuildOptionFromVar (&BootLists, L"BootOrder");\r
260 Link = BootLists.ForwardLink;\r
261 }\r
262 }\r
263\r
264}\r
265\r
266VOID\r
267EFIAPI\r
268BdsEntry (\r
269 IN EFI_BDS_ARCH_PROTOCOL *This\r
270 )\r
271/*++\r
272\r
273Routine Description:\r
274\r
275 Service routine for BdsInstance->Entry(). Devices are connected, the\r
276 consoles are initialized, and the boot options are tried.\r
277\r
278Arguments:\r
279\r
280 This - Protocol Instance structure.\r
281\r
282Returns:\r
283\r
284 EFI_SUCEESS - BDS->Entry has finished executing.\r
285\r
286--*/\r
287{\r
288 EFI_BDS_ARCH_PROTOCOL_INSTANCE *PrivateData;\r
289 LIST_ENTRY DriverOptionList;\r
290 LIST_ENTRY BootOptionList;\r
291 UINTN BootNextSize;\r
292\r
293 //\r
294 // Insert the performance probe\r
295 //\r
296 PERF_END (0, DXE_TOK, NULL, 0);\r
297 PERF_START (0, BDS_TOK, NULL, 0);\r
298\r
299 //\r
300 // Initialize the global system boot option and driver option\r
301 //\r
302 InitializeListHead (&DriverOptionList);\r
303 InitializeListHead (&BootOptionList);\r
304\r
305 //\r
306 // Initialize hotkey service\r
307 //\r
308 InitializeHotkeyService ();\r
309\r
310 //\r
311 // Get the BDS private data\r
312 //\r
313 PrivateData = EFI_BDS_ARCH_PROTOCOL_INSTANCE_FROM_THIS (This);\r
314\r
315 //\r
316 // Do the platform init, can be customized by OEM/IBV\r
317 //\r
318 PERF_START (0, "PlatformBds", "BDS", 0);\r
319 PlatformBdsInit (PrivateData);\r
320\r
321 if (FeaturePcdGet (PcdSupportHardwareErrorRecord)) {\r
322 InitializeHwErrRecSupport (PcdGet16 (PcdHardwareErrorRecordLevel));\r
323 }\r
324 //\r
325 // bugbug: platform specific code\r
326 // Initialize the platform specific string and language\r
327 //\r
328 InitializeStringSupport ();\r
329 InitializeLanguage (TRUE);\r
330 InitializeFrontPage (FALSE);\r
331\r
332 //\r
333 // Set up the device list based on EFI 1.1 variables\r
334 // process Driver#### and Load the driver's in the\r
335 // driver option list\r
336 //\r
337 BdsLibBuildOptionFromVar (&DriverOptionList, L"DriverOrder");\r
338 if (!IsListEmpty (&DriverOptionList)) {\r
339 BdsLibLoadDrivers (&DriverOptionList);\r
340 }\r
341 //\r
342 // Check if we have the boot next option\r
343 //\r
344 mBootNext = BdsLibGetVariableAndSize (\r
345 L"BootNext",\r
346 &gEfiGlobalVariableGuid,\r
347 &BootNextSize\r
348 );\r
349\r
350 //\r
351 // Setup some platform policy here\r
352 //\r
353 PlatformBdsPolicyBehavior (PrivateData, &DriverOptionList, &BootOptionList);\r
354 PERF_END (0, "PlatformBds", "BDS", 0);\r
355\r
356 //\r
357 // BDS select the boot device to load OS\r
358 //\r
359 BdsBootDeviceSelect ();\r
360\r
361 //\r
362 // Only assert here since this is the right behavior, we should never\r
363 // return back to DxeCore.\r
364 //\r
365 ASSERT (FALSE);\r
366\r
367 return ;\r
368}\r