1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
|
/*++
Copyright (c) 2006 - 2007, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
BootManager.c
Abstract:
The platform boot manager reference implement
--*/
#include "BootManager.h"
UINT16 mKeyInput;
LIST_ENTRY *mBootOptionsList;
BDS_COMMON_OPTION *gOption;
FRAMEWORK_EFI_HII_HANDLE gBootManagerHandle;
EFI_HANDLE BootManagerCallbackHandle;
EFI_FORM_CALLBACK_PROTOCOL BootManagerCallback;
EFI_GUID gBmGuid = BOOT_MANAGER_GUID;
extern EFI_FORM_BROWSER_PROTOCOL *gBrowser;
extern UINT8 BootManagerVfrBin[];
extern BOOLEAN gConnectAllHappened;
EFI_STATUS
EFIAPI
BootManagerCallbackRoutine (
IN EFI_FORM_CALLBACK_PROTOCOL *This,
IN UINT16 KeyValue,
IN FRAMEWORK_EFI_IFR_DATA_ARRAY *DataArray,
OUT EFI_HII_CALLBACK_PACKET **Packet
)
/*++
Routine Description:
This is the function that is called to provide results data to the driver. This data
consists of a unique key which is used to identify what data is either being passed back
or being asked for.
Arguments:
KeyValue - A unique value which is sent to the original exporting driver so that it
can identify the type of data to expect. The format of the data tends to
vary based on the op-code that geerated the callback.
Data - A pointer to the data being sent to the original exporting driver.
Returns:
--*/
{
BDS_COMMON_OPTION *Option;
LIST_ENTRY *Link;
UINT16 KeyCount;
EFI_HII_CALLBACK_PACKET *DataPacket;
//
// Initialize the key count
//
KeyCount = 0;
for (Link = mBootOptionsList->ForwardLink; Link != mBootOptionsList; Link = Link->ForwardLink) {
Option = CR (Link, BDS_COMMON_OPTION, Link, BDS_LOAD_OPTION_SIGNATURE);
KeyCount++;
gOption = Option;
//
// Is this device the one chosen?
//
if (KeyCount == KeyValue) {
//
// Assigning the returned Key to a global allows the original routine to know what was chosen
//
mKeyInput = KeyValue;
*Packet = AllocateZeroPool (sizeof (EFI_HII_CALLBACK_PACKET) + 2);
ASSERT (*Packet != NULL);
//
// Assign the buffer address to DataPacket
//
DataPacket = *Packet;
DataPacket->DataArray.EntryCount = 1;
DataPacket->DataArray.NvRamMap = NULL;
((FRAMEWORK_EFI_IFR_DATA_ENTRY *) (((FRAMEWORK_EFI_IFR_DATA_ARRAY *)DataPacket) + 1))->Flags = EXIT_REQUIRED | NV_NOT_CHANGED;
return EFI_SUCCESS;
} else {
continue;
}
}
return EFI_SUCCESS;
}
VOID
CallBootManager (
VOID
)
/*++
Routine Description:
Hook to enable UI timeout override behavior.
Arguments:
BdsDeviceList - Device List that BDS needs to connect.
Entry - Pointer to current Boot Entry.
Returns:
NONE
--*/
{
EFI_STATUS Status;
EFI_HII_PACKAGES *PackageList;
BDS_COMMON_OPTION *Option;
LIST_ENTRY *Link;
EFI_HII_UPDATE_DATA *UpdateData;
CHAR16 *ExitData;
UINTN ExitDataSize;
STRING_REF Token;
STRING_REF LastToken;
EFI_INPUT_KEY Key;
UINT8 *Location;
EFI_GUID BmGuid;
LIST_ENTRY BdsBootOptionList;
BOOLEAN BootMngrMenuResetRequired;
gOption = NULL;
InitializeListHead (&BdsBootOptionList);
//
// Connect all prior to entering the platform setup menu.
//
if (!gConnectAllHappened) {
BdsLibConnectAllDriversToAllControllers ();
gConnectAllHappened = TRUE;
}
//
// BugBug: Here we can not remove the legacy refresh macro, so we need
// get the boot order every time from "BootOrder" variable.
// Recreate the boot option list base on the BootOrder variable
//
BdsLibEnumerateAllBootOption (&BdsBootOptionList);
//
// This GUID must be the same as what is defined in BootManagerVfr.vfr
//
BmGuid = gBmGuid;
mBootOptionsList = &BdsBootOptionList;
//
// Post our VFR to the HII database
//
PackageList = PreparePackages (2, &BmGuid, BootManagerVfrBin, PlatformBdsStrings);
Status = gHii->NewPack (gHii, PackageList, &gBootManagerHandle);
FreePool (PackageList);
//
// This example does not implement worker functions
// for the NV accessor functions. Only a callback evaluator
//
BootManagerCallback.NvRead = NULL;
BootManagerCallback.NvWrite = NULL;
BootManagerCallback.Callback = BootManagerCallbackRoutine;
//
// Install protocol interface
//
BootManagerCallbackHandle = NULL;
Status = gBS->InstallProtocolInterface (
&BootManagerCallbackHandle,
&gEfiFormCallbackProtocolGuid,
EFI_NATIVE_INTERFACE,
&BootManagerCallback
);
ASSERT_EFI_ERROR (Status);
LastToken = 0;
gHii->NewString (gHii, NULL, gBootManagerHandle, &LastToken, L" ");
//
// Allocate space for creation of UpdateData Buffer
//
UpdateData = AllocateZeroPool (0x1000);
ASSERT (UpdateData != NULL);
//
// Flag update pending in FormSet
//
UpdateData->FormSetUpdate = TRUE;
//
// Register CallbackHandle data for FormSet
//
UpdateData->FormCallbackHandle = (EFI_PHYSICAL_ADDRESS) (UINTN) BootManagerCallbackHandle;
UpdateData->FormUpdate = FALSE;
UpdateData->FormTitle = 0;
UpdateData->DataCount = 1;
//
// Create blank space. Since when we update the contents of IFR data at a label, it is
// inserted at the location of the label. So if you want to add a string with an empty
// space afterwards, you need to add the space first and then the string like below.
//
Status = CreateSubTitleOpCode (
LastToken, // Token Value for the string
&UpdateData->Data // Buffer containing created op-code
);
gHii->UpdateForm (gHii, gBootManagerHandle, (EFI_FORM_LABEL) 0x0000, TRUE, UpdateData);
//
// Create "Boot Option Menu" title
//
Status = CreateSubTitleOpCode (
STRING_TOKEN (STR_BOOT_OPTION_BANNER), // Token Value for the string
&UpdateData->Data // Buffer containing created op-code
);
gHii->UpdateForm (gHii, gBootManagerHandle, (EFI_FORM_LABEL) 0x0000, TRUE, UpdateData);
Token = LastToken;
mKeyInput = 0;
UpdateData->DataCount = 0;
Location = (UINT8 *) &UpdateData->Data;
for (Link = BdsBootOptionList.ForwardLink; Link != &BdsBootOptionList; Link = Link->ForwardLink) {
Option = CR (Link, BDS_COMMON_OPTION, Link, BDS_LOAD_OPTION_SIGNATURE);
//
// At this stage we are creating a menu entry, thus the Keys are reproduceable
//
mKeyInput++;
Token++;
Status = gHii->NewString (gHii, NULL, gBootManagerHandle, &Token, Option->Description);
//
// If we got an error it is almost certainly due to the token value being invalid.
// Therefore we will set the Token to 0 to automatically add a token.
//
if (EFI_ERROR (Status)) {
Token = 0;
Status = gHii->NewString (gHii, NULL, gBootManagerHandle, &Token, Option->Description);
}
Status = CreateGotoOpCode (
0x1000, // Form ID
Token, // Token Value for the string
0, // Help String (none)
FRAMEWORK_EFI_IFR_FLAG_INTERACTIVE | FRAMEWORK_EFI_IFR_FLAG_NV_ACCESS, // The Op-Code flags
mKeyInput, // The Key to get a callback on
Location // Buffer containing created op-code
);
UpdateData->DataCount++;
Location = Location + ((FRAMEWORK_EFI_IFR_OP_HEADER *) Location)->Length;
}
gHii->UpdateForm (gHii, gBootManagerHandle, (EFI_FORM_LABEL) 0x0001, TRUE, UpdateData);
UpdateData->DataCount = 1;
//
// Create "Boot Option Menu" title
//
Status = CreateSubTitleOpCode (
STRING_TOKEN (STR_HELP_FOOTER), // Token Value for the string
&UpdateData->Data // Buffer containing created op-code
);
gHii->UpdateForm (gHii, gBootManagerHandle, (EFI_FORM_LABEL) 0x0002, TRUE, UpdateData);
Status = CreateSubTitleOpCode (
LastToken, // Token Value for the string
&UpdateData->Data // Buffer containing created op-code
);
gHii->UpdateForm (gHii, gBootManagerHandle, (EFI_FORM_LABEL) 0x0002, TRUE, UpdateData);
FreePool (UpdateData);
ASSERT (gBrowser);
BootMngrMenuResetRequired = FALSE;
gBrowser->SendForm (
gBrowser,
TRUE,
&gBootManagerHandle,
1,
NULL,
NULL,
NULL,
NULL,
&BootMngrMenuResetRequired
);
if (BootMngrMenuResetRequired) {
EnableResetRequired ();
}
gHii->ResetStrings (gHii, gBootManagerHandle);
if (gOption == NULL) {
return ;
}
//
//Will leave browser, check any reset required change is applied? if yes, reset system
//
SetupResetReminder ();
//
// BugBug: This code looks repeated from the BDS. Need to save code space.
//
//
// parse the selected option
//
Status = BdsLibBootViaBootOption (gOption, gOption->DevicePath, &ExitDataSize, &ExitData);
if (!EFI_ERROR (Status)) {
PlatformBdsBootSuccess (gOption);
} else {
PlatformBdsBootFail (gOption, Status, ExitData, ExitDataSize);
gST->ConOut->OutputString (
gST->ConOut,
GetStringById (STRING_TOKEN (STR_ANY_KEY_CONTINUE))
);
//
// BdsLibUiWaitForSingleEvent (gST->ConIn->WaitForKey, 0);
//
gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
}
}
|