2 This module produce main entry for BDS phase - BdsEntry.
3 When this module was dispatched by DxeCore, gEfiBdsArchProtocolGuid will be installed
4 which contains interface of BdsEntry.
5 After DxeCore finish DXE phase, gEfiBdsArchProtocolGuid->BdsEntry will be invoked
8 Copyright (c) 2004 - 2008, Intel Corporation. <BR>
9 All rights reserved. This program and the accompanying materials
10 are licensed and made available under the terms and conditions of the BSD License
11 which accompanies this distribution. The full text of the license may be found at
12 http://opensource.org/licenses/bsd-license.php
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
21 #include "FrontPage.h"
23 #include "HwErrRecSupport.h"
26 /// BDS arch protocol instance initial value.
28 /// Note: Current BDS not directly get the BootMode, DefaultBoot,
29 /// TimeoutDefault, MemoryTestLevel value from the BDS arch protocol.
30 /// Please refer to the library useage of BdsLibGetBootMode, BdsLibGetTimeout
31 /// and PlatformBdsDiagnostics in BdsPlatform.c
33 EFI_BDS_ARCH_PROTOCOL_INSTANCE gBdsInstanceTemplate
= {
34 EFI_BDS_ARCH_PROTOCOL_INSTANCE_SIGNATURE
,
43 UINT16
*mBootNext
= NULL
;
45 EFI_HANDLE mBdsImageHandle
;
49 Install Boot Device Selection Protocol
51 @param ImageHandle The image handle.
52 @param SystemTable The system table.
54 @retval EFI_SUCEESS BDS has finished initializing.
55 Return the dispatcher and recall BDS.Entry
56 @retval Other Return status from AllocatePool() or gBS->InstallProtocolInterface
62 IN EFI_HANDLE ImageHandle
,
63 IN EFI_SYSTEM_TABLE
*SystemTable
68 mBdsImageHandle
= ImageHandle
;
71 // Install protocol interface
73 Status
= gBS
->InstallProtocolInterface (
74 &gBdsInstanceTemplate
.Handle
,
75 &gEfiBdsArchProtocolGuid
,
77 &gBdsInstanceTemplate
.Bds
79 ASSERT_EFI_ERROR (Status
);
86 This function attempts to boot for the boot order specified
97 BDS_COMMON_OPTION
*BootOption
;
101 LIST_ENTRY BootLists
;
103 BOOLEAN BootNextExist
;
104 LIST_ENTRY
*LinkBootNext
;
107 // Got the latest boot option
109 BootNextExist
= FALSE
;
111 InitializeListHead (&BootLists
);
114 // First check the boot next option
116 ZeroMem (Buffer
, sizeof (Buffer
));
118 if (mBootNext
!= NULL
) {
120 // Indicate we have the boot next variable, so this time
121 // boot will always have this boot option
123 BootNextExist
= TRUE
;
126 // Clear the this variable so it's only exist in this time boot
130 &gEfiGlobalVariableGuid
,
131 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
137 // Add the boot next boot option
139 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"Boot%04x", *mBootNext
);
140 BootOption
= BdsLibVariableToOption (&BootLists
, Buffer
);
141 BootOption
->BootCurrent
= *mBootNext
;
144 // Parse the boot order to get boot option
146 BdsLibBuildOptionFromVar (&BootLists
, L
"BootOrder");
147 Link
= BootLists
.ForwardLink
;
150 // Parameter check, make sure the loop will be valid
156 // Here we make the boot in a loop, every boot success will
157 // return to the front page
161 // Check the boot option list first
163 if (Link
== &BootLists
) {
165 // There are two ways to enter here:
166 // 1. There is no active boot option, give user chance to
167 // add new boot option
168 // 2. All the active boot option processed, and there is no
169 // one is success to boot, then we back here to allow user
170 // add new active boot option
173 PlatformBdsEnterFrontPage (Timeout
, FALSE
);
174 InitializeListHead (&BootLists
);
175 BdsLibBuildOptionFromVar (&BootLists
, L
"BootOrder");
176 Link
= BootLists
.ForwardLink
;
180 // Get the boot option from the link list
182 BootOption
= CR (Link
, BDS_COMMON_OPTION
, Link
, BDS_LOAD_OPTION_SIGNATURE
);
185 // According to EFI Specification, if a load option is not marked
186 // as LOAD_OPTION_ACTIVE, the boot manager will not automatically
189 if (!IS_LOAD_OPTION_TYPE (BootOption
->Attribute
, LOAD_OPTION_ACTIVE
)) {
191 // skip the header of the link list, becuase it has no boot option
193 Link
= Link
->ForwardLink
;
197 // Make sure the boot option device path connected,
198 // but ignore the BBS device path
200 if (DevicePathType (BootOption
->DevicePath
) != BBS_DEVICE_PATH
) {
202 // Notes: the internal shell can not been connected with device path
203 // so we do not check the status here
205 BdsLibConnectDevicePath (BootOption
->DevicePath
);
208 // All the driver options should have been processed since
209 // now boot will be performed.
211 Status
= BdsLibBootViaBootOption (BootOption
, BootOption
->DevicePath
, &ExitDataSize
, &ExitData
);
212 if (EFI_ERROR (Status
)) {
214 // Call platform action to indicate the boot fail
216 BootOption
->StatusString
= GetStringById (STRING_TOKEN (STR_BOOT_FAILED
));
217 PlatformBdsBootFail (BootOption
, Status
, ExitData
, ExitDataSize
);
220 // Check the next boot option
222 Link
= Link
->ForwardLink
;
226 // Call platform action to indicate the boot success
228 BootOption
->StatusString
= GetStringById (STRING_TOKEN (STR_BOOT_SUCCEEDED
));
229 PlatformBdsBootSuccess (BootOption
);
232 // Boot success, then stop process the boot order, and
233 // present the boot manager menu, front page
236 PlatformBdsEnterFrontPage (Timeout
, FALSE
);
239 // Rescan the boot option list, avoid pertential risk of the boot
240 // option change in front page
243 LinkBootNext
= BootLists
.ForwardLink
;
246 InitializeListHead (&BootLists
);
247 if (LinkBootNext
!= NULL
) {
249 // Reserve the boot next option
251 InsertTailList (&BootLists
, LinkBootNext
);
254 BdsLibBuildOptionFromVar (&BootLists
, L
"BootOrder");
255 Link
= BootLists
.ForwardLink
;
263 Service routine for BdsInstance->Entry(). Devices are connected, the
264 consoles are initialized, and the boot options are tried.
266 @param This Protocol Instance structure.
272 IN EFI_BDS_ARCH_PROTOCOL
*This
275 EFI_BDS_ARCH_PROTOCOL_INSTANCE
*PrivateData
;
276 LIST_ENTRY DriverOptionList
;
277 LIST_ENTRY BootOptionList
;
281 // Insert the performance probe
283 PERF_END (0, DXE_TOK
, NULL
, 0);
284 PERF_START (0, BDS_TOK
, NULL
, 0);
287 // Initialize the global system boot option and driver option
289 InitializeListHead (&DriverOptionList
);
290 InitializeListHead (&BootOptionList
);
293 // Initialize hotkey service
295 InitializeHotkeyService ();
298 // Get the BDS private data
300 PrivateData
= EFI_BDS_ARCH_PROTOCOL_INSTANCE_FROM_THIS (This
);
303 // Do the platform init, can be customized by OEM/IBV
305 PERF_START (0, "PlatformBds", "BDS", 0);
306 PlatformBdsInit (PrivateData
);
308 if (FeaturePcdGet (PcdSupportHardwareErrorRecord
)) {
309 InitializeHwErrRecSupport (PcdGet16 (PcdHardwareErrorRecordLevel
));
312 // bugbug: platform specific code
313 // Initialize the platform specific string and language
315 InitializeStringSupport ();
316 InitializeLanguage (TRUE
);
317 InitializeFrontPage (TRUE
);
320 // Set up the device list based on EFI 1.1 variables
321 // process Driver#### and Load the driver's in the
322 // driver option list
324 BdsLibBuildOptionFromVar (&DriverOptionList
, L
"DriverOrder");
325 if (!IsListEmpty (&DriverOptionList
)) {
326 BdsLibLoadDrivers (&DriverOptionList
);
329 // Check if we have the boot next option
331 mBootNext
= BdsLibGetVariableAndSize (
333 &gEfiGlobalVariableGuid
,
338 // Setup some platform policy here
340 PlatformBdsPolicyBehavior (PrivateData
, &DriverOptionList
, &BootOptionList
);
341 PERF_END (0, "PlatformBds", "BDS", 0);
344 // BDS select the boot device to load OS
346 BdsBootDeviceSelect ();
349 // Only assert here since this is the right behavior, we should never
350 // return back to DxeCore.