3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
23 // Include common header file for this module.
25 #include "CommonHeader.h"
28 #include "BdsPlatform.h"
29 #include "FrontPage.h"
31 EFI_BDS_ARCH_PROTOCOL_INSTANCE gBdsInstanceTemplate
= {
32 EFI_BDS_ARCH_PROTOCOL_INSTANCE_SIGNATURE
,
40 UINT16
*mBootNext
= NULL
;
42 EFI_HANDLE mBdsImageHandle
;
47 IN EFI_HANDLE ImageHandle
,
48 IN EFI_SYSTEM_TABLE
*SystemTable
54 Install Boot Device Selection Protocol
58 (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)
62 EFI_SUCEESS - BDS has finished initializing.
64 dispatcher and recall BDS.Entry
66 Other - Return value from EfiLibAllocatePool()
67 or gBS->InstallProtocolInterface
73 mBdsImageHandle
= ImageHandle
;
76 // Install protocol interface
78 Status
= gBS
->InstallProtocolInterface (
79 &gBdsInstanceTemplate
.Handle
,
80 &gEfiBdsArchProtocolGuid
,
82 &gBdsInstanceTemplate
.Bds
84 ASSERT_EFI_ERROR (Status
);
97 In the loop of attempt to boot for the boot order
111 BDS_COMMON_OPTION
*BootOption
;
115 LIST_ENTRY BootLists
;
117 BOOLEAN BootNextExist
;
118 LIST_ENTRY
*LinkBootNext
;
121 // Got the latest boot option
123 BootNextExist
= FALSE
;
125 InitializeListHead (&BootLists
);
128 // First check the boot next option
130 ZeroMem (Buffer
, sizeof (Buffer
));
132 if (mBootNext
!= NULL
) {
134 // Indicate we have the boot next variable, so this time
135 // boot will always have this boot option
137 BootNextExist
= TRUE
;
140 // Clear the this variable so it's only exist in this time boot
144 &gEfiGlobalVariableGuid
,
145 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
151 // Add the boot next boot option
153 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"Boot%04x", *mBootNext
);
154 BootOption
= BdsLibVariableToOption (&BootLists
, Buffer
);
157 // Parse the boot order to get boot option
159 BdsLibBuildOptionFromVar (&BootLists
, L
"BootOrder");
160 Link
= BootLists
.ForwardLink
;
163 // Parameter check, make sure the loop will be valid
169 // Here we make the boot in a loop, every boot success will
170 // return to the front page
174 // Check the boot option list first
176 if (Link
== &BootLists
) {
178 // There are two ways to enter here:
179 // 1. There is no active boot option, give user chance to
180 // add new boot option
181 // 2. All the active boot option processed, and there is no
182 // one is success to boot, then we back here to allow user
183 // add new active boot option
186 PlatformBdsEnterFrontPage (Timeout
, FALSE
);
187 InitializeListHead (&BootLists
);
188 BdsLibBuildOptionFromVar (&BootLists
, L
"BootOrder");
189 Link
= BootLists
.ForwardLink
;
193 // Get the boot option from the link list
195 BootOption
= CR (Link
, BDS_COMMON_OPTION
, Link
, BDS_LOAD_OPTION_SIGNATURE
);
198 // According to EFI Specification, if a load option is not marked
199 // as LOAD_OPTION_ACTIVE, the boot manager will not automatically
202 if (!IS_LOAD_OPTION_TYPE (BootOption
->Attribute
, LOAD_OPTION_ACTIVE
)) {
204 // skip the header of the link list, becuase it has no boot option
206 Link
= Link
->ForwardLink
;
210 // Make sure the boot option device path connected,
211 // but ignore the BBS device path
213 if (DevicePathType (BootOption
->DevicePath
) != BBS_DEVICE_PATH
) {
215 // Notes: the internal shell can not been connected with device path
216 // so we do not check the status here
218 BdsLibConnectDevicePath (BootOption
->DevicePath
);
221 // All the driver options should have been processed since
222 // now boot will be performed.
224 Status
= BdsLibBootViaBootOption (BootOption
, BootOption
->DevicePath
, &ExitDataSize
, &ExitData
);
225 if (EFI_ERROR (Status
)) {
227 // Call platform action to indicate the boot fail
229 PlatformBdsBootFail (BootOption
, Status
, ExitData
, ExitDataSize
);
232 // Check the next boot option
234 Link
= Link
->ForwardLink
;
238 // Call platform action to indicate the boot success
240 PlatformBdsBootSuccess (BootOption
);
243 // Boot success, then stop process the boot order, and
244 // present the boot manager menu, front page
247 PlatformBdsEnterFrontPage (Timeout
, FALSE
);
250 // Rescan the boot option list, avoid pertential risk of the boot
251 // option change in front page
254 LinkBootNext
= BootLists
.ForwardLink
;
257 InitializeListHead (&BootLists
);
258 if (LinkBootNext
!= NULL
) {
260 // Reserve the boot next option
262 InsertTailList (&BootLists
, LinkBootNext
);
265 BdsLibBuildOptionFromVar (&BootLists
, L
"BootOrder");
266 Link
= BootLists
.ForwardLink
;
277 IN EFI_BDS_ARCH_PROTOCOL
*This
283 Service routine for BdsInstance->Entry(). Devices are connected, the
284 consoles are initialized, and the boot options are tried.
288 This - Protocol Instance structure.
292 EFI_SUCEESS - BDS->Entry has finished executing.
296 EFI_BDS_ARCH_PROTOCOL_INSTANCE
*PrivateData
;
297 LIST_ENTRY DriverOptionList
;
298 LIST_ENTRY BootOptionList
;
302 // Insert the performance probe
304 PERF_END (0, DXE_TOK
, NULL
, 0);
305 PERF_START (0, BDS_TOK
, NULL
, 0);
308 // Initialize the global system boot option and driver option
310 InitializeListHead (&DriverOptionList
);
311 InitializeListHead (&BootOptionList
);
314 // Get the BDS private data
316 PrivateData
= EFI_BDS_ARCH_PROTOCOL_INSTANCE_FROM_THIS (This
);
319 // Do the platform init, can be customized by OEM/IBV
321 PERF_START (0, "PlatformBds", "BDS", 0);
322 PlatformBdsInit (PrivateData
);
325 // Set up the device list based on EFI 1.1 variables
326 // process Driver#### and Load the driver's in the
327 // driver option list
329 BdsLibBuildOptionFromVar (&DriverOptionList
, L
"DriverOrder");
330 if (!IsListEmpty (&DriverOptionList
)) {
331 BdsLibLoadDrivers (&DriverOptionList
);
334 // Check if we have the boot next option
336 mBootNext
= BdsLibGetVariableAndSize (
338 &gEfiGlobalVariableGuid
,
343 // Setup some platform policy here
345 PlatformBdsPolicyBehavior (PrivateData
, &DriverOptionList
, &BootOptionList
);
346 PERF_END (0, "PlatformBds", "BDS", 0);
349 // BDS select the boot device to load OS
351 BdsBootDeviceSelect ();
354 // Only assert here since this is the right behavior, we should never
355 // return back to DxeCore.