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 This function attempts to boot for the boot order specified
88 BDS_COMMON_OPTION
*BootOption
;
94 BOOLEAN BootNextExist
;
95 LIST_ENTRY
*LinkBootNext
;
98 // Got the latest boot option
100 BootNextExist
= FALSE
;
102 InitializeListHead (&BootLists
);
105 // First check the boot next option
107 ZeroMem (Buffer
, sizeof (Buffer
));
109 if (mBootNext
!= NULL
) {
111 // Indicate we have the boot next variable, so this time
112 // boot will always have this boot option
114 BootNextExist
= TRUE
;
117 // Clear the this variable so it's only exist in this time boot
121 &gEfiGlobalVariableGuid
,
122 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
128 // Add the boot next boot option
130 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"Boot%04x", *mBootNext
);
131 BootOption
= BdsLibVariableToOption (&BootLists
, Buffer
);
132 BootOption
->BootCurrent
= *mBootNext
;
135 // Parse the boot order to get boot option
137 BdsLibBuildOptionFromVar (&BootLists
, L
"BootOrder");
138 Link
= BootLists
.ForwardLink
;
141 // Parameter check, make sure the loop will be valid
147 // Here we make the boot in a loop, every boot success will
148 // return to the front page
152 // Check the boot option list first
154 if (Link
== &BootLists
) {
156 // There are two ways to enter here:
157 // 1. There is no active boot option, give user chance to
158 // add new boot option
159 // 2. All the active boot option processed, and there is no
160 // one is success to boot, then we back here to allow user
161 // add new active boot option
164 PlatformBdsEnterFrontPage (Timeout
, FALSE
);
165 InitializeListHead (&BootLists
);
166 BdsLibBuildOptionFromVar (&BootLists
, L
"BootOrder");
167 Link
= BootLists
.ForwardLink
;
171 // Get the boot option from the link list
173 BootOption
= CR (Link
, BDS_COMMON_OPTION
, Link
, BDS_LOAD_OPTION_SIGNATURE
);
176 // According to EFI Specification, if a load option is not marked
177 // as LOAD_OPTION_ACTIVE, the boot manager will not automatically
180 if (!IS_LOAD_OPTION_TYPE (BootOption
->Attribute
, LOAD_OPTION_ACTIVE
)) {
182 // skip the header of the link list, becuase it has no boot option
184 Link
= Link
->ForwardLink
;
188 // Make sure the boot option device path connected,
189 // but ignore the BBS device path
191 if (DevicePathType (BootOption
->DevicePath
) != BBS_DEVICE_PATH
) {
193 // Notes: the internal shell can not been connected with device path
194 // so we do not check the status here
196 BdsLibConnectDevicePath (BootOption
->DevicePath
);
199 // All the driver options should have been processed since
200 // now boot will be performed.
202 Status
= BdsLibBootViaBootOption (BootOption
, BootOption
->DevicePath
, &ExitDataSize
, &ExitData
);
203 if (EFI_ERROR (Status
)) {
205 // Call platform action to indicate the boot fail
207 BootOption
->StatusString
= GetStringById (STRING_TOKEN (STR_BOOT_FAILED
));
208 PlatformBdsBootFail (BootOption
, Status
, ExitData
, ExitDataSize
);
211 // Check the next boot option
213 Link
= Link
->ForwardLink
;
217 // Call platform action to indicate the boot success
219 BootOption
->StatusString
= GetStringById (STRING_TOKEN (STR_BOOT_SUCCEEDED
));
220 PlatformBdsBootSuccess (BootOption
);
223 // Boot success, then stop process the boot order, and
224 // present the boot manager menu, front page
227 PlatformBdsEnterFrontPage (Timeout
, FALSE
);
230 // Rescan the boot option list, avoid pertential risk of the boot
231 // option change in front page
234 LinkBootNext
= BootLists
.ForwardLink
;
237 InitializeListHead (&BootLists
);
238 if (LinkBootNext
!= NULL
) {
240 // Reserve the boot next option
242 InsertTailList (&BootLists
, LinkBootNext
);
245 BdsLibBuildOptionFromVar (&BootLists
, L
"BootOrder");
246 Link
= BootLists
.ForwardLink
;
254 Service routine for BdsInstance->Entry(). Devices are connected, the
255 consoles are initialized, and the boot options are tried.
258 @param This - Protocol Instance structure.
260 @retval EFI_SUCEESS BDS->Entry has finished executing.
266 IN EFI_BDS_ARCH_PROTOCOL
*This
269 EFI_BDS_ARCH_PROTOCOL_INSTANCE
*PrivateData
;
270 LIST_ENTRY DriverOptionList
;
271 LIST_ENTRY BootOptionList
;
275 // Insert the performance probe
277 PERF_END (0, DXE_TOK
, NULL
, 0);
278 PERF_START (0, BDS_TOK
, NULL
, 0);
281 // Initialize the global system boot option and driver option
283 InitializeListHead (&DriverOptionList
);
284 InitializeListHead (&BootOptionList
);
287 // Initialize hotkey service
289 InitializeHotkeyService ();
292 // Get the BDS private data
294 PrivateData
= EFI_BDS_ARCH_PROTOCOL_INSTANCE_FROM_THIS (This
);
297 // Do the platform init, can be customized by OEM/IBV
299 PERF_START (0, "PlatformBds", "BDS", 0);
300 PlatformBdsInit (PrivateData
);
302 if (FeaturePcdGet (PcdSupportHardwareErrorRecord
)) {
303 InitializeHwErrRecSupport (PcdGet16 (PcdHardwareErrorRecordLevel
));
306 // bugbug: platform specific code
307 // Initialize the platform specific string and language
309 InitializeStringSupport ();
310 InitializeLanguage (TRUE
);
311 InitializeFrontPage (TRUE
);
314 // Set up the device list based on EFI 1.1 variables
315 // process Driver#### and Load the driver's in the
316 // driver option list
318 BdsLibBuildOptionFromVar (&DriverOptionList
, L
"DriverOrder");
319 if (!IsListEmpty (&DriverOptionList
)) {
320 BdsLibLoadDrivers (&DriverOptionList
);
323 // Check if we have the boot next option
325 mBootNext
= BdsLibGetVariableAndSize (
327 &gEfiGlobalVariableGuid
,
332 // Setup some platform policy here
334 PlatformBdsPolicyBehavior (PrivateData
, &DriverOptionList
, &BootOptionList
);
335 PERF_END (0, "PlatformBds", "BDS", 0);
338 // BDS select the boot device to load OS
340 BdsBootDeviceSelect ();
343 // Only assert here since this is the right behavior, we should never
344 // return back to DxeCore.