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.
18 The platform boot manager reference implement
21 #include "BootManager.h"
24 LIST_ENTRY
*mBootOptionsList
;
25 BDS_COMMON_OPTION
*gOption
;
26 EFI_HII_HANDLE gBootManagerHandle
;
27 EFI_HANDLE BootManagerCallbackHandle
;
28 EFI_FORM_CALLBACK_PROTOCOL BootManagerCallback
;
29 EFI_GUID gBmGuid
= BOOT_MANAGER_GUID
;
31 extern EFI_FORM_BROWSER_PROTOCOL
*gBrowser
;
32 extern UINT8 BootManagerVfrBin
[];
33 extern UINT8 EdkGenericPlatformBdsLibStrings
[];
34 extern BOOLEAN gConnectAllHappened
;
38 BootManagerCallbackRoutine (
39 IN EFI_FORM_CALLBACK_PROTOCOL
*This
,
41 IN EFI_IFR_DATA_ARRAY
*DataArray
,
42 OUT EFI_HII_CALLBACK_PACKET
**Packet
48 This is the function that is called to provide results data to the driver. This data
49 consists of a unique key which is used to identify what data is either being passed back
54 KeyValue - A unique value which is sent to the original exporting driver so that it
55 can identify the type of data to expect. The format of the data tends to
56 vary based on the op-code that geerated the callback.
58 Data - A pointer to the data being sent to the original exporting driver.
64 BDS_COMMON_OPTION
*Option
;
67 EFI_HII_CALLBACK_PACKET
*DataPacket
;
70 // Initialize the key count
74 for (Link
= mBootOptionsList
->ForwardLink
; Link
!= mBootOptionsList
; Link
= Link
->ForwardLink
) {
75 Option
= CR (Link
, BDS_COMMON_OPTION
, Link
, BDS_LOAD_OPTION_SIGNATURE
);
82 // Is this device the one chosen?
84 if (KeyCount
== KeyValue
) {
86 // Assigning the returned Key to a global allows the original routine to know what was chosen
90 *Packet
= AllocateZeroPool (sizeof (EFI_HII_CALLBACK_PACKET
) + 2);
91 ASSERT (*Packet
!= NULL
);
94 // Assign the buffer address to DataPacket
98 DataPacket
->DataArray
.EntryCount
= 1;
99 DataPacket
->DataArray
.NvRamMap
= NULL
;
100 ((EFI_IFR_DATA_ENTRY
*) (((EFI_IFR_DATA_ARRAY
*)DataPacket
) + 1))->Flags
= EXIT_REQUIRED
| NV_NOT_CHANGED
;
117 Hook to enable UI timeout override behavior.
120 BdsDeviceList - Device List that BDS needs to connect.
122 Entry - Pointer to current Boot Entry.
130 EFI_HII_PACKAGES
*PackageList
;
131 BDS_COMMON_OPTION
*Option
;
133 EFI_HII_UPDATE_DATA
*UpdateData
;
137 STRING_REF LastToken
;
141 LIST_ENTRY BdsBootOptionList
;
142 BOOLEAN BootMngrMenuResetRequired
;
145 InitializeListHead (&BdsBootOptionList
);
148 // Connect all prior to entering the platform setup menu.
150 if (!gConnectAllHappened
) {
151 BdsLibConnectAllDriversToAllControllers ();
152 gConnectAllHappened
= TRUE
;
155 // BugBug: Here we can not remove the legacy refresh macro, so we need
156 // get the boot order every time from "BootOrder" variable.
157 // Recreate the boot option list base on the BootOrder variable
159 BdsLibEnumerateAllBootOption (&BdsBootOptionList
);
162 // This GUID must be the same as what is defined in BootManagerVfr.vfr
166 mBootOptionsList
= &BdsBootOptionList
;
169 // Post our VFR to the HII database
171 PackageList
= PreparePackages (2, &BmGuid
, BootManagerVfrBin
, EdkGenericPlatformBdsLibStrings
);
172 Status
= Hii
->NewPack (Hii
, PackageList
, &gBootManagerHandle
);
173 gBS
->FreePool (PackageList
);
176 // This example does not implement worker functions
177 // for the NV accessor functions. Only a callback evaluator
179 BootManagerCallback
.NvRead
= NULL
;
180 BootManagerCallback
.NvWrite
= NULL
;
181 BootManagerCallback
.Callback
= BootManagerCallbackRoutine
;
184 // Install protocol interface
186 BootManagerCallbackHandle
= NULL
;
187 Status
= gBS
->InstallProtocolInterface (
188 &BootManagerCallbackHandle
,
189 &gEfiFormCallbackProtocolGuid
,
190 EFI_NATIVE_INTERFACE
,
193 ASSERT_EFI_ERROR (Status
);
196 Hii
->NewString (Hii
, NULL
, gBootManagerHandle
, &LastToken
, L
" ");
199 // Allocate space for creation of UpdateData Buffer
201 UpdateData
= AllocateZeroPool (0x1000);
202 ASSERT (UpdateData
!= NULL
);
205 // Flag update pending in FormSet
207 UpdateData
->FormSetUpdate
= TRUE
;
209 // Register CallbackHandle data for FormSet
211 UpdateData
->FormCallbackHandle
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) BootManagerCallbackHandle
;
212 UpdateData
->FormUpdate
= FALSE
;
213 UpdateData
->FormTitle
= 0;
214 UpdateData
->DataCount
= 1;
217 // Create blank space. Since when we update the contents of IFR data at a label, it is
218 // inserted at the location of the label. So if you want to add a string with an empty
219 // space afterwards, you need to add the space first and then the string like below.
221 Status
= CreateSubTitleOpCode (
222 LastToken
, // Token Value for the string
223 &UpdateData
->Data
// Buffer containing created op-code
226 Hii
->UpdateForm (Hii
, gBootManagerHandle
, (EFI_FORM_LABEL
) 0x0000, TRUE
, UpdateData
);
229 // Create "Boot Option Menu" title
231 Status
= CreateSubTitleOpCode (
232 STRING_TOKEN (STR_BOOT_OPTION_BANNER
), // Token Value for the string
233 &UpdateData
->Data
// Buffer containing created op-code
236 Hii
->UpdateForm (Hii
, gBootManagerHandle
, (EFI_FORM_LABEL
) 0x0000, TRUE
, UpdateData
);
241 UpdateData
->DataCount
= 0;
242 Location
= (UINT8
*) &UpdateData
->Data
;
244 for (Link
= BdsBootOptionList
.ForwardLink
; Link
!= &BdsBootOptionList
; Link
= Link
->ForwardLink
) {
245 Option
= CR (Link
, BDS_COMMON_OPTION
, Link
, BDS_LOAD_OPTION_SIGNATURE
);
248 // At this stage we are creating a menu entry, thus the Keys are reproduceable
253 Status
= Hii
->NewString (Hii
, NULL
, gBootManagerHandle
, &Token
, Option
->Description
);
256 // If we got an error it is almost certainly due to the token value being invalid.
257 // Therefore we will set the Token to 0 to automatically add a token.
259 if (EFI_ERROR (Status
)) {
261 Status
= Hii
->NewString (Hii
, NULL
, gBootManagerHandle
, &Token
, Option
->Description
);
264 Status
= CreateGotoOpCode (
266 Token
, // Token Value for the string
267 0, // Help String (none)
268 EFI_IFR_FLAG_INTERACTIVE
| EFI_IFR_FLAG_NV_ACCESS
, // The Op-Code flags
269 mKeyInput
, // The Key to get a callback on
270 Location
// Buffer containing created op-code
273 UpdateData
->DataCount
++;
274 Location
= Location
+ ((EFI_IFR_OP_HEADER
*) Location
)->Length
;
278 Hii
->UpdateForm (Hii
, gBootManagerHandle
, (EFI_FORM_LABEL
) 0x0001, TRUE
, UpdateData
);
280 UpdateData
->DataCount
= 1;
283 // Create "Boot Option Menu" title
285 Status
= CreateSubTitleOpCode (
286 STRING_TOKEN (STR_HELP_FOOTER
), // Token Value for the string
287 &UpdateData
->Data
// Buffer containing created op-code
290 Hii
->UpdateForm (Hii
, gBootManagerHandle
, (EFI_FORM_LABEL
) 0x0002, TRUE
, UpdateData
);
292 Status
= CreateSubTitleOpCode (
293 LastToken
, // Token Value for the string
294 &UpdateData
->Data
// Buffer containing created op-code
297 Hii
->UpdateForm (Hii
, gBootManagerHandle
, (EFI_FORM_LABEL
) 0x0002, TRUE
, UpdateData
);
299 gBS
->FreePool (UpdateData
);
303 BootMngrMenuResetRequired
= FALSE
;
313 &BootMngrMenuResetRequired
316 if (BootMngrMenuResetRequired
) {
317 EnableResetRequired ();
320 Hii
->ResetStrings (Hii
, gBootManagerHandle
);
322 if (gOption
== NULL
) {
327 //Will leave browser, check any reset required change is applied? if yes, reset system
329 SetupResetReminder ();
332 // BugBug: This code looks repeated from the BDS. Need to save code space.
336 // parse the selected option
338 Status
= BdsLibBootViaBootOption (gOption
, gOption
->DevicePath
, &ExitDataSize
, &ExitData
);
340 if (!EFI_ERROR (Status
)) {
341 PlatformBdsBootSuccess (gOption
);
343 PlatformBdsBootFail (gOption
, Status
, ExitData
, ExitDataSize
);
344 gST
->ConOut
->OutputString (
346 GetStringById (STRING_TOKEN (STR_ANY_KEY_CONTINUE
))
350 // BdsLibUiWaitForSingleEvent (gST->ConIn->WaitForKey, 0);
353 gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);