3 Copyright (c) 2006 - 2007, 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
22 // Include common header file for this module.
24 #include "CommonHeader.h"
26 #include "BootManager.h"
29 LIST_ENTRY
*mBootOptionsList
;
30 BDS_COMMON_OPTION
*gOption
;
31 EFI_HII_HANDLE gBootManagerHandle
;
32 EFI_HANDLE BootManagerCallbackHandle
;
33 EFI_FORM_CALLBACK_PROTOCOL BootManagerCallback
;
34 EFI_GUID gBmGuid
= BOOT_MANAGER_GUID
;
36 extern EFI_FORM_BROWSER_PROTOCOL
*gBrowser
;
37 extern UINT8 BootManagerVfrBin
[];
38 extern UINT8 BdsStrings
[];
39 extern BOOLEAN gConnectAllHappened
;
43 BootManagerCallbackRoutine (
44 IN EFI_FORM_CALLBACK_PROTOCOL
*This
,
46 IN EFI_IFR_DATA_ARRAY
*DataArray
,
47 OUT EFI_HII_CALLBACK_PACKET
**Packet
53 This is the function that is called to provide results data to the driver. This data
54 consists of a unique key which is used to identify what data is either being passed back
59 KeyValue - A unique value which is sent to the original exporting driver so that it
60 can identify the type of data to expect. The format of the data tends to
61 vary based on the op-code that geerated the callback.
63 Data - A pointer to the data being sent to the original exporting driver.
69 BDS_COMMON_OPTION
*Option
;
72 EFI_HII_CALLBACK_PACKET
*DataPacket
;
75 // Initialize the key count
79 for (Link
= mBootOptionsList
->ForwardLink
; Link
!= mBootOptionsList
; Link
= Link
->ForwardLink
) {
80 Option
= CR (Link
, BDS_COMMON_OPTION
, Link
, BDS_LOAD_OPTION_SIGNATURE
);
87 // Is this device the one chosen?
89 if (KeyCount
== KeyValue
) {
91 // Assigning the returned Key to a global allows the original routine to know what was chosen
95 *Packet
= AllocateZeroPool (sizeof (EFI_HII_CALLBACK_PACKET
) + 2);
96 ASSERT (*Packet
!= NULL
);
99 // Assign the buffer address to DataPacket
101 DataPacket
= *Packet
;
103 DataPacket
->DataArray
.EntryCount
= 1;
104 DataPacket
->DataArray
.NvRamMap
= NULL
;
105 ((EFI_IFR_DATA_ENTRY
*) (((EFI_IFR_DATA_ARRAY
*)DataPacket
) + 1))->Flags
= EXIT_REQUIRED
| NV_NOT_CHANGED
;
122 Hook to enable UI timeout override behavior.
125 BdsDeviceList - Device List that BDS needs to connect.
127 Entry - Pointer to current Boot Entry.
135 EFI_HII_PACKAGES
*PackageList
;
136 BDS_COMMON_OPTION
*Option
;
138 EFI_HII_UPDATE_DATA
*UpdateData
;
142 STRING_REF LastToken
;
146 LIST_ENTRY BdsBootOptionList
;
147 BOOLEAN BootMngrMenuResetRequired
;
150 InitializeListHead (&BdsBootOptionList
);
153 // Connect all prior to entering the platform setup menu.
155 if (!gConnectAllHappened
) {
156 BdsLibConnectAllDriversToAllControllers ();
157 gConnectAllHappened
= TRUE
;
160 // BugBug: Here we can not remove the legacy refresh macro, so we need
161 // get the boot order every time from "BootOrder" variable.
162 // Recreate the boot option list base on the BootOrder variable
164 BdsLibEnumerateAllBootOption (&BdsBootOptionList
);
167 // This GUID must be the same as what is defined in BootManagerVfr.vfr
171 mBootOptionsList
= &BdsBootOptionList
;
174 // Post our VFR to the HII database
176 PackageList
= PreparePackages (2, &BmGuid
, BootManagerVfrBin
, BdsStrings
);
177 Status
= Hii
->NewPack (Hii
, PackageList
, &gBootManagerHandle
);
178 FreePool (PackageList
);
181 // This example does not implement worker functions
182 // for the NV accessor functions. Only a callback evaluator
184 BootManagerCallback
.NvRead
= NULL
;
185 BootManagerCallback
.NvWrite
= NULL
;
186 BootManagerCallback
.Callback
= BootManagerCallbackRoutine
;
189 // Install protocol interface
191 BootManagerCallbackHandle
= NULL
;
192 Status
= gBS
->InstallProtocolInterface (
193 &BootManagerCallbackHandle
,
194 &gEfiFormCallbackProtocolGuid
,
195 EFI_NATIVE_INTERFACE
,
198 ASSERT_EFI_ERROR (Status
);
201 Hii
->NewString (Hii
, NULL
, gBootManagerHandle
, &LastToken
, L
" ");
204 // Allocate space for creation of UpdateData Buffer
206 UpdateData
= AllocateZeroPool (0x1000);
207 ASSERT (UpdateData
!= NULL
);
210 // Flag update pending in FormSet
212 UpdateData
->FormSetUpdate
= TRUE
;
214 // Register CallbackHandle data for FormSet
216 UpdateData
->FormCallbackHandle
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) BootManagerCallbackHandle
;
217 UpdateData
->FormUpdate
= FALSE
;
218 UpdateData
->FormTitle
= 0;
219 UpdateData
->DataCount
= 1;
222 // Create blank space. Since when we update the contents of IFR data at a label, it is
223 // inserted at the location of the label. So if you want to add a string with an empty
224 // space afterwards, you need to add the space first and then the string like below.
226 Status
= CreateSubTitleOpCode (
227 LastToken
, // Token Value for the string
228 &UpdateData
->Data
// Buffer containing created op-code
231 Hii
->UpdateForm (Hii
, gBootManagerHandle
, (EFI_FORM_LABEL
) 0x0000, TRUE
, UpdateData
);
234 // Create "Boot Option Menu" title
236 Status
= CreateSubTitleOpCode (
237 STRING_TOKEN (STR_BOOT_OPTION_BANNER
), // Token Value for the string
238 &UpdateData
->Data
// Buffer containing created op-code
241 Hii
->UpdateForm (Hii
, gBootManagerHandle
, (EFI_FORM_LABEL
) 0x0000, TRUE
, UpdateData
);
246 UpdateData
->DataCount
= 0;
247 Location
= (UINT8
*) &UpdateData
->Data
;
249 for (Link
= BdsBootOptionList
.ForwardLink
; Link
!= &BdsBootOptionList
; Link
= Link
->ForwardLink
) {
250 Option
= CR (Link
, BDS_COMMON_OPTION
, Link
, BDS_LOAD_OPTION_SIGNATURE
);
253 // At this stage we are creating a menu entry, thus the Keys are reproduceable
258 Status
= Hii
->NewString (Hii
, NULL
, gBootManagerHandle
, &Token
, Option
->Description
);
261 // If we got an error it is almost certainly due to the token value being invalid.
262 // Therefore we will set the Token to 0 to automatically add a token.
264 if (EFI_ERROR (Status
)) {
266 Status
= Hii
->NewString (Hii
, NULL
, gBootManagerHandle
, &Token
, Option
->Description
);
269 Status
= CreateGotoOpCode (
271 Token
, // Token Value for the string
272 0, // Help String (none)
273 EFI_IFR_FLAG_INTERACTIVE
| EFI_IFR_FLAG_NV_ACCESS
, // The Op-Code flags
274 mKeyInput
, // The Key to get a callback on
275 Location
// Buffer containing created op-code
278 UpdateData
->DataCount
++;
279 Location
= Location
+ ((EFI_IFR_OP_HEADER
*) Location
)->Length
;
283 Hii
->UpdateForm (Hii
, gBootManagerHandle
, (EFI_FORM_LABEL
) 0x0001, TRUE
, UpdateData
);
285 UpdateData
->DataCount
= 1;
288 // Create "Boot Option Menu" title
290 Status
= CreateSubTitleOpCode (
291 STRING_TOKEN (STR_HELP_FOOTER
), // Token Value for the string
292 &UpdateData
->Data
// Buffer containing created op-code
295 Hii
->UpdateForm (Hii
, gBootManagerHandle
, (EFI_FORM_LABEL
) 0x0002, TRUE
, UpdateData
);
297 Status
= CreateSubTitleOpCode (
298 LastToken
, // Token Value for the string
299 &UpdateData
->Data
// Buffer containing created op-code
302 Hii
->UpdateForm (Hii
, gBootManagerHandle
, (EFI_FORM_LABEL
) 0x0002, TRUE
, UpdateData
);
304 FreePool (UpdateData
);
308 BootMngrMenuResetRequired
= FALSE
;
318 &BootMngrMenuResetRequired
321 if (BootMngrMenuResetRequired
) {
322 EnableResetRequired ();
325 Hii
->ResetStrings (Hii
, gBootManagerHandle
);
327 if (gOption
== NULL
) {
332 //Will leave browser, check any reset required change is applied? if yes, reset system
334 SetupResetReminder ();
337 // BugBug: This code looks repeated from the BDS. Need to save code space.
341 // parse the selected option
343 Status
= BdsLibBootViaBootOption (gOption
, gOption
->DevicePath
, &ExitDataSize
, &ExitData
);
345 if (!EFI_ERROR (Status
)) {
346 PlatformBdsBootSuccess (gOption
);
348 PlatformBdsBootFail (gOption
, Status
, ExitData
, ExitDataSize
);
349 gST
->ConOut
->OutputString (
351 GetStringById (STRING_TOKEN (STR_ANY_KEY_CONTINUE
))
355 // BdsLibUiWaitForSingleEvent (gST->ConIn->WaitForKey, 0);
358 gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);