4 Copyright (c) 2004 - 2008, Intel Corporation. <BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include "FrontPage.h"
19 #include "HwErrRecSupport.h"
22 EFI_BDS_ARCH_PROTOCOL_INSTANCE gBdsInstanceTemplate
= {
23 EFI_BDS_ARCH_PROTOCOL_INSTANCE_SIGNATURE
,
31 UINT16
*mBootNext
= NULL
;
33 EFI_HANDLE mBdsImageHandle
;
37 Install Boot Device Selection Protocol
40 @param ImageHandle The image handle.
41 @param SystemTable The system table.
43 @retval EFI_SUCEESS BDS has finished initializing.
45 dispatcher and recall BDS.Entry
46 @retval Other Return value from AllocatePool()
47 or gBS->InstallProtocolInterface
53 IN EFI_HANDLE ImageHandle
,
54 IN EFI_SYSTEM_TABLE
*SystemTable
59 mBdsImageHandle
= ImageHandle
;
62 // Install protocol interface
64 Status
= gBS
->InstallProtocolInterface (
65 &gBdsInstanceTemplate
.Handle
,
66 &gEfiBdsArchProtocolGuid
,
68 &gBdsInstanceTemplate
.Bds
70 ASSERT_EFI_ERROR (Status
);
77 In the loop of attempt to boot for the boot order
80 @param VOID No input parameter.
82 @retval VOID No returns.
92 BDS_COMMON_OPTION
*BootOption
;
98 BOOLEAN BootNextExist
;
99 LIST_ENTRY
*LinkBootNext
;
102 // Got the latest boot option
104 BootNextExist
= FALSE
;
106 InitializeListHead (&BootLists
);
109 // First check the boot next option
111 ZeroMem (Buffer
, sizeof (Buffer
));
113 if (mBootNext
!= NULL
) {
115 // Indicate we have the boot next variable, so this time
116 // boot will always have this boot option
118 BootNextExist
= TRUE
;
121 // Clear the this variable so it's only exist in this time boot
125 &gEfiGlobalVariableGuid
,
126 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
132 // Add the boot next boot option
134 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"Boot%04x", *mBootNext
);
135 BootOption
= BdsLibVariableToOption (&BootLists
, Buffer
);
136 BootOption
->BootCurrent
= *mBootNext
;
139 // Parse the boot order to get boot option
141 BdsLibBuildOptionFromVar (&BootLists
, L
"BootOrder");
142 Link
= BootLists
.ForwardLink
;
145 // Parameter check, make sure the loop will be valid
151 // Here we make the boot in a loop, every boot success will
152 // return to the front page
156 // Check the boot option list first
158 if (Link
== &BootLists
) {
160 // There are two ways to enter here:
161 // 1. There is no active boot option, give user chance to
162 // add new boot option
163 // 2. All the active boot option processed, and there is no
164 // one is success to boot, then we back here to allow user
165 // add new active boot option
168 PlatformBdsEnterFrontPage (Timeout
, FALSE
);
169 InitializeListHead (&BootLists
);
170 BdsLibBuildOptionFromVar (&BootLists
, L
"BootOrder");
171 Link
= BootLists
.ForwardLink
;
175 // Get the boot option from the link list
177 BootOption
= CR (Link
, BDS_COMMON_OPTION
, Link
, BDS_LOAD_OPTION_SIGNATURE
);
180 // According to EFI Specification, if a load option is not marked
181 // as LOAD_OPTION_ACTIVE, the boot manager will not automatically
184 if (!IS_LOAD_OPTION_TYPE (BootOption
->Attribute
, LOAD_OPTION_ACTIVE
)) {
186 // skip the header of the link list, becuase it has no boot option
188 Link
= Link
->ForwardLink
;
192 // Make sure the boot option device path connected,
193 // but ignore the BBS device path
195 if (DevicePathType (BootOption
->DevicePath
) != BBS_DEVICE_PATH
) {
197 // Notes: the internal shell can not been connected with device path
198 // so we do not check the status here
200 BdsLibConnectDevicePath (BootOption
->DevicePath
);
203 // All the driver options should have been processed since
204 // now boot will be performed.
206 Status
= BdsLibBootViaBootOption (BootOption
, BootOption
->DevicePath
, &ExitDataSize
, &ExitData
);
207 if (EFI_ERROR (Status
)) {
209 // Call platform action to indicate the boot fail
211 BootOption
->StatusString
= GetStringById (STRING_TOKEN (STR_BOOT_FAILED
));
212 PlatformBdsBootFail (BootOption
, Status
, ExitData
, ExitDataSize
);
215 // Check the next boot option
217 Link
= Link
->ForwardLink
;
221 // Call platform action to indicate the boot success
223 BootOption
->StatusString
= GetStringById (STRING_TOKEN (STR_BOOT_SUCCEEDED
));
224 PlatformBdsBootSuccess (BootOption
);
227 // Boot success, then stop process the boot order, and
228 // present the boot manager menu, front page
231 PlatformBdsEnterFrontPage (Timeout
, FALSE
);
234 // Rescan the boot option list, avoid pertential risk of the boot
235 // option change in front page
238 LinkBootNext
= BootLists
.ForwardLink
;
241 InitializeListHead (&BootLists
);
242 if (LinkBootNext
!= NULL
) {
244 // Reserve the boot next option
246 InsertTailList (&BootLists
, LinkBootNext
);
249 BdsLibBuildOptionFromVar (&BootLists
, L
"BootOrder");
250 Link
= BootLists
.ForwardLink
;
258 Service routine for BdsInstance->Entry(). Devices are connected, the
259 consoles are initialized, and the boot options are tried.
262 @param This - Protocol Instance structure.
264 @retval EFI_SUCEESS BDS->Entry has finished executing.
270 IN EFI_BDS_ARCH_PROTOCOL
*This
273 EFI_BDS_ARCH_PROTOCOL_INSTANCE
*PrivateData
;
274 LIST_ENTRY DriverOptionList
;
275 LIST_ENTRY BootOptionList
;
279 // Insert the performance probe
281 PERF_END (0, DXE_TOK
, NULL
, 0);
282 PERF_START (0, BDS_TOK
, NULL
, 0);
285 // Initialize the global system boot option and driver option
287 InitializeListHead (&DriverOptionList
);
288 InitializeListHead (&BootOptionList
);
291 // Initialize hotkey service
293 InitializeHotkeyService ();
296 // Get the BDS private data
298 PrivateData
= EFI_BDS_ARCH_PROTOCOL_INSTANCE_FROM_THIS (This
);
301 // Do the platform init, can be customized by OEM/IBV
303 PERF_START (0, "PlatformBds", "BDS", 0);
304 PlatformBdsInit (PrivateData
);
306 if (FeaturePcdGet (PcdSupportHardwareErrorRecord
)) {
307 InitializeHwErrRecSupport (PcdGet16 (PcdHardwareErrorRecordLevel
));
310 // bugbug: platform specific code
311 // Initialize the platform specific string and language
313 InitializeStringSupport ();
314 InitializeLanguage (TRUE
);
315 InitializeFrontPage (TRUE
);
318 // Set up the device list based on EFI 1.1 variables
319 // process Driver#### and Load the driver's in the
320 // driver option list
322 BdsLibBuildOptionFromVar (&DriverOptionList
, L
"DriverOrder");
323 if (!IsListEmpty (&DriverOptionList
)) {
324 BdsLibLoadDrivers (&DriverOptionList
);
327 // Check if we have the boot next option
329 mBootNext
= BdsLibGetVariableAndSize (
331 &gEfiGlobalVariableGuid
,
336 // Setup some platform policy here
338 PlatformBdsPolicyBehavior (PrivateData
, &DriverOptionList
, &BootOptionList
);
339 PERF_END (0, "PlatformBds", "BDS", 0);
342 // BDS select the boot device to load OS
344 BdsBootDeviceSelect ();
347 // Only assert here since this is the right behavior, we should never
348 // return back to DxeCore.