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 "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 Status
= BdsLibBootViaBootOption (BootOption
, BootOption
->DevicePath
, &ExitDataSize
, &ExitData
);
222 if (EFI_ERROR (Status
)) {
224 // Call platform action to indicate the boot fail
226 PlatformBdsBootFail (BootOption
, Status
, ExitData
, ExitDataSize
);
229 // Check the next boot option
231 Link
= Link
->ForwardLink
;
235 // Call platform action to indicate the boot success
237 PlatformBdsBootSuccess (BootOption
);
240 // Boot success, then stop process the boot order, and
241 // present the boot manager menu, front page
244 PlatformBdsEnterFrontPage (Timeout
, FALSE
);
247 // Rescan the boot option list, avoid pertential risk of the boot
248 // option change in front page
251 LinkBootNext
= BootLists
.ForwardLink
;
254 InitializeListHead (&BootLists
);
255 if (LinkBootNext
!= NULL
) {
257 // Reserve the boot next option
259 InsertTailList (&BootLists
, LinkBootNext
);
262 BdsLibBuildOptionFromVar (&BootLists
, L
"BootOrder");
263 Link
= BootLists
.ForwardLink
;
274 IN EFI_BDS_ARCH_PROTOCOL
*This
280 Service routine for BdsInstance->Entry(). Devices are connected, the
281 consoles are initialized, and the boot options are tried.
285 This - Protocol Instance structure.
289 EFI_SUCEESS - BDS->Entry has finished executing.
293 EFI_BDS_ARCH_PROTOCOL_INSTANCE
*PrivateData
;
294 LIST_ENTRY DriverOptionList
;
295 LIST_ENTRY BootOptionList
;
299 // Insert the performance probe
301 PERF_END (0, DXE_TOK
, NULL
, 0);
302 PERF_START (0, BDS_TOK
, NULL
, 0);
305 // Initialize the global system boot option and driver option
307 InitializeListHead (&DriverOptionList
);
308 InitializeListHead (&BootOptionList
);
311 // Get the BDS private data
313 PrivateData
= EFI_BDS_ARCH_PROTOCOL_INSTANCE_FROM_THIS (This
);
316 // Do the platform init, can be customized by OEM/IBV
318 PERF_START (0, "PlatformBds", "BDS", 0);
319 PlatformBdsInit (PrivateData
);
322 // Initialize the platform specific string and language
324 InitializeStringSupport ();
325 InitializeLanguage (TRUE
);
326 InitializeFrontPage (FALSE
);
328 // Set up the device list based on EFI 1.1 variables
329 // process Driver#### and Load the driver's in the
330 // driver option list
332 BdsLibBuildOptionFromVar (&DriverOptionList
, L
"DriverOrder");
333 if (!IsListEmpty (&DriverOptionList
)) {
334 BdsLibLoadDrivers (&DriverOptionList
);
337 // Check if we have the boot next option
339 mBootNext
= BdsLibGetVariableAndSize (
341 &gEfiGlobalVariableGuid
,
346 // Setup some platform policy here
348 PlatformBdsPolicyBehavior (PrivateData
, &DriverOptionList
, &BootOptionList
);
349 PERF_END (0, "PlatformBds", "BDS", 0);
352 // BDS select the boot device to load OS
354 BdsBootDeviceSelect ();
357 // Only assert here since this is the right behavior, we should never
358 // return back to DxeCore.