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 "BdsPlatform.h"
24 #include "FrontPage.h"
26 EFI_BDS_ARCH_PROTOCOL_INSTANCE gBdsInstanceTemplate
= {
27 EFI_BDS_ARCH_PROTOCOL_INSTANCE_SIGNATURE
,
37 UINT16
*mBootNext
= NULL
;
39 EFI_HANDLE mBdsImageHandle
;
44 IN EFI_HANDLE ImageHandle
,
45 IN EFI_SYSTEM_TABLE
*SystemTable
51 Install Boot Device Selection Protocol
55 (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)
59 EFI_SUCEESS - BDS has finished initializing.
61 dispatcher and recall BDS.Entry
63 Other - Return value from EfiLibAllocatePool()
64 or gBS->InstallProtocolInterface
70 mBdsImageHandle
= ImageHandle
;
73 // Install protocol interface
75 Status
= gBS
->InstallProtocolInterface (
76 &gBdsInstanceTemplate
.Handle
,
77 &gEfiBdsArchProtocolGuid
,
79 &gBdsInstanceTemplate
.Bds
81 ASSERT_EFI_ERROR (Status
);
94 In the loop of attempt to boot for the boot order
108 BDS_COMMON_OPTION
*BootOption
;
112 LIST_ENTRY BootLists
;
114 BOOLEAN BootNextExist
;
115 LIST_ENTRY
*LinkBootNext
;
118 // Got the latest boot option
120 BootNextExist
= FALSE
;
122 InitializeListHead (&BootLists
);
125 // First check the boot next option
127 ZeroMem (Buffer
, sizeof (Buffer
));
129 if (mBootNext
!= NULL
) {
131 // Indicate we have the boot next variable, so this time
132 // boot will always have this boot option
134 BootNextExist
= TRUE
;
137 // Clear the this variable so it's only exist in this time boot
141 &gEfiGlobalVariableGuid
,
142 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
148 // Add the boot next boot option
150 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"Boot%04x", *mBootNext
);
151 BootOption
= BdsLibVariableToOption (&BootLists
, Buffer
);
154 // Parse the boot order to get boot option
156 BdsLibBuildOptionFromVar (&BootLists
, L
"BootOrder");
157 Link
= BootLists
.ForwardLink
;
160 // Parameter check, make sure the loop will be valid
166 // Here we make the boot in a loop, every boot success will
167 // return to the front page
171 // Check the boot option list first
173 if (Link
== &BootLists
) {
175 // There are two ways to enter here:
176 // 1. There is no active boot option, give user chance to
177 // add new boot option
178 // 2. All the active boot option processed, and there is no
179 // one is success to boot, then we back here to allow user
180 // add new active boot option
183 PlatformBdsEnterFrontPage (Timeout
, FALSE
);
184 InitializeListHead (&BootLists
);
185 BdsLibBuildOptionFromVar (&BootLists
, L
"BootOrder");
186 Link
= BootLists
.ForwardLink
;
190 // Get the boot option from the link list
192 BootOption
= CR (Link
, BDS_COMMON_OPTION
, Link
, BDS_LOAD_OPTION_SIGNATURE
);
195 // According to EFI Specification, if a load option is not marked
196 // as LOAD_OPTION_ACTIVE, the boot manager will not automatically
199 if (!IS_LOAD_OPTION_TYPE (BootOption
->Attribute
, LOAD_OPTION_ACTIVE
)) {
201 // skip the header of the link list, becuase it has no boot option
203 Link
= Link
->ForwardLink
;
207 // Make sure the boot option device path connected,
208 // but ignore the BBS device path
210 if (DevicePathType (BootOption
->DevicePath
) != BBS_DEVICE_PATH
) {
212 // Notes: the internal shell can not been connected with device path
213 // so we do not check the status here
215 BdsLibConnectDevicePath (BootOption
->DevicePath
);
218 // All the driver options should have been processed since
219 // now boot will be performed.
221 PERF_END (0, BDS_TOK
, NULL
, 0);
222 Status
= BdsLibBootViaBootOption (BootOption
, BootOption
->DevicePath
, &ExitDataSize
, &ExitData
);
223 if (EFI_ERROR (Status
)) {
225 // Call platform action to indicate the boot fail
227 PlatformBdsBootFail (BootOption
, Status
, ExitData
, ExitDataSize
);
230 // Check the next boot option
232 Link
= Link
->ForwardLink
;
236 // Call platform action to indicate the boot success
238 PlatformBdsBootSuccess (BootOption
);
241 // Boot success, then stop process the boot order, and
242 // present the boot manager menu, front page
245 PlatformBdsEnterFrontPage (Timeout
, FALSE
);
248 // Rescan the boot option list, avoid pertential risk of the boot
249 // option change in front page
252 LinkBootNext
= BootLists
.ForwardLink
;
255 InitializeListHead (&BootLists
);
256 if (LinkBootNext
!= NULL
) {
258 // Reserve the boot next option
260 InsertTailList (&BootLists
, LinkBootNext
);
263 BdsLibBuildOptionFromVar (&BootLists
, L
"BootOrder");
264 Link
= BootLists
.ForwardLink
;
275 IN EFI_BDS_ARCH_PROTOCOL
*This
281 Service routine for BdsInstance->Entry(). Devices are connected, the
282 consoles are initialized, and the boot options are tried.
286 This - Protocol Instance structure.
290 EFI_SUCEESS - BDS->Entry has finished executing.
294 EFI_BDS_ARCH_PROTOCOL_INSTANCE
*PrivateData
;
295 LIST_ENTRY DriverOptionList
;
296 LIST_ENTRY BootOptionList
;
300 // Insert the performance probe
302 PERF_END (0, DXE_TOK
, NULL
, 0);
303 PERF_START (0, BDS_TOK
, NULL
, 0);
306 // Initialize the global system boot option and driver option
308 InitializeListHead (&DriverOptionList
);
309 InitializeListHead (&BootOptionList
);
312 // Get the BDS private data
314 PrivateData
= EFI_BDS_ARCH_PROTOCOL_INSTANCE_FROM_THIS (This
);
317 // Do the platform init, can be customized by OEM/IBV
319 PERF_START (0, "PlatformBds", "BDS", 0);
320 PlatformBdsInit (PrivateData
);
323 // Set up the device list based on EFI 1.1 variables
324 // process Driver#### and Load the driver's in the
325 // driver option list
327 BdsLibBuildOptionFromVar (&DriverOptionList
, L
"DriverOrder");
328 if (!IsListEmpty (&DriverOptionList
)) {
329 BdsLibLoadDrivers (&DriverOptionList
);
332 // Check if we have the boot next option
334 mBootNext
= BdsLibGetVariableAndSize (
336 &gEfiGlobalVariableGuid
,
341 // Setup some platform policy here
343 PlatformBdsPolicyBehavior (PrivateData
, &DriverOptionList
, &BootOptionList
);
344 PERF_END (0, "PlatformBds", "BDS", 0);
347 // BDS select the boot device to load OS
349 BdsBootDeviceSelect ();
352 // Only assert here since this is the right behavior, we should never
353 // return back to DxeCore.