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
,
35 UINT16
*mBootNext
= NULL
;
37 EFI_HANDLE mBdsImageHandle
;
42 IN EFI_HANDLE ImageHandle
,
43 IN EFI_SYSTEM_TABLE
*SystemTable
49 Install Boot Device Selection Protocol
53 (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)
57 EFI_SUCEESS - BDS has finished initializing.
59 dispatcher and recall BDS.Entry
61 Other - Return value from EfiLibAllocatePool()
62 or gBS->InstallProtocolInterface
68 mBdsImageHandle
= ImageHandle
;
71 // Install protocol interface
73 Status
= gBS
->InstallProtocolInterface (
74 &gBdsInstanceTemplate
.Handle
,
75 &gEfiBdsArchProtocolGuid
,
77 &gBdsInstanceTemplate
.Bds
79 ASSERT_EFI_ERROR (Status
);
92 In the loop of attempt to boot for the boot order
106 BDS_COMMON_OPTION
*BootOption
;
110 LIST_ENTRY BootLists
;
112 BOOLEAN BootNextExist
;
113 LIST_ENTRY
*LinkBootNext
;
116 // Got the latest boot option
118 BootNextExist
= FALSE
;
120 InitializeListHead (&BootLists
);
123 // First check the boot next option
125 ZeroMem (Buffer
, sizeof (Buffer
));
127 if (mBootNext
!= NULL
) {
129 // Indicate we have the boot next variable, so this time
130 // boot will always have this boot option
132 BootNextExist
= TRUE
;
135 // Clear the this variable so it's only exist in this time boot
139 &gEfiGlobalVariableGuid
,
140 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
146 // Add the boot next boot option
148 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"Boot%04x", *mBootNext
);
149 BootOption
= BdsLibVariableToOption (&BootLists
, Buffer
);
152 // Parse the boot order to get boot option
154 BdsLibBuildOptionFromVar (&BootLists
, L
"BootOrder");
155 Link
= BootLists
.ForwardLink
;
158 // Parameter check, make sure the loop will be valid
164 // Here we make the boot in a loop, every boot success will
165 // return to the front page
169 // Check the boot option list first
171 if (Link
== &BootLists
) {
173 // There are two ways to enter here:
174 // 1. There is no active boot option, give user chance to
175 // add new boot option
176 // 2. All the active boot option processed, and there is no
177 // one is success to boot, then we back here to allow user
178 // add new active boot option
181 PlatformBdsEnterFrontPage (Timeout
, FALSE
);
182 InitializeListHead (&BootLists
);
183 BdsLibBuildOptionFromVar (&BootLists
, L
"BootOrder");
184 Link
= BootLists
.ForwardLink
;
188 // Get the boot option from the link list
190 BootOption
= CR (Link
, BDS_COMMON_OPTION
, Link
, BDS_LOAD_OPTION_SIGNATURE
);
193 // According to EFI Specification, if a load option is not marked
194 // as LOAD_OPTION_ACTIVE, the boot manager will not automatically
197 if (!IS_LOAD_OPTION_TYPE (BootOption
->Attribute
, LOAD_OPTION_ACTIVE
)) {
199 // skip the header of the link list, becuase it has no boot option
201 Link
= Link
->ForwardLink
;
205 // Make sure the boot option device path connected,
206 // but ignore the BBS device path
208 if (DevicePathType (BootOption
->DevicePath
) != BBS_DEVICE_PATH
) {
210 // Notes: the internal shell can not been connected with device path
211 // so we do not check the status here
213 BdsLibConnectDevicePath (BootOption
->DevicePath
);
216 // All the driver options should have been processed since
217 // now boot will be performed.
219 Status
= BdsLibBootViaBootOption (BootOption
, BootOption
->DevicePath
, &ExitDataSize
, &ExitData
);
220 if (EFI_ERROR (Status
)) {
222 // Call platform action to indicate the boot fail
224 PlatformBdsBootFail (BootOption
, Status
, ExitData
, ExitDataSize
);
227 // Check the next boot option
229 Link
= Link
->ForwardLink
;
233 // Call platform action to indicate the boot success
235 PlatformBdsBootSuccess (BootOption
);
238 // Boot success, then stop process the boot order, and
239 // present the boot manager menu, front page
242 PlatformBdsEnterFrontPage (Timeout
, FALSE
);
245 // Rescan the boot option list, avoid pertential risk of the boot
246 // option change in front page
249 LinkBootNext
= BootLists
.ForwardLink
;
252 InitializeListHead (&BootLists
);
253 if (LinkBootNext
!= NULL
) {
255 // Reserve the boot next option
257 InsertTailList (&BootLists
, LinkBootNext
);
260 BdsLibBuildOptionFromVar (&BootLists
, L
"BootOrder");
261 Link
= BootLists
.ForwardLink
;
272 IN EFI_BDS_ARCH_PROTOCOL
*This
278 Service routine for BdsInstance->Entry(). Devices are connected, the
279 consoles are initialized, and the boot options are tried.
283 This - Protocol Instance structure.
287 EFI_SUCEESS - BDS->Entry has finished executing.
291 EFI_BDS_ARCH_PROTOCOL_INSTANCE
*PrivateData
;
292 LIST_ENTRY DriverOptionList
;
293 LIST_ENTRY BootOptionList
;
297 // Insert the performance probe
299 PERF_END (0, DXE_TOK
, NULL
, 0);
300 PERF_START (0, BDS_TOK
, NULL
, 0);
303 // Initialize the global system boot option and driver option
305 InitializeListHead (&DriverOptionList
);
306 InitializeListHead (&BootOptionList
);
309 // Get the BDS private data
311 PrivateData
= EFI_BDS_ARCH_PROTOCOL_INSTANCE_FROM_THIS (This
);
314 // Do the platform init, can be customized by OEM/IBV
316 PERF_START (0, "PlatformBds", "BDS", 0);
317 PlatformBdsInit (PrivateData
);
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.