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
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
|
/** @file
The functions for Boot Maintainence Main menu.
Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>
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.
**/
#include "BootMaintenanceManager.h"
#include "BootMaintenanceManagerCustomizedUiSupport.h"
#define UI_HII_DRIVER_LIST_SIZE 0x8
typedef struct {
EFI_STRING_ID PromptId;
EFI_STRING_ID HelpId;
EFI_STRING_ID DevicePathId;
EFI_GUID FormSetGuid;
BOOLEAN EmptyLineAfter;
} UI_HII_DRIVER_INSTANCE;
STATIC UI_HII_DRIVER_INSTANCE *gHiiDriverList;
/**
Create the dynamic item to allow user to set the "BootNext" vaule.
@param[in] HiiHandle The hii handle for the Uiapp driver.
@param[in] StartOpCodeHandle The opcode handle to save the new opcode.
**/
VOID
BmmCreateBootNextMenu(
IN EFI_HII_HANDLE HiiHandle,
IN VOID *StartOpCodeHandle
)
{
BM_MENU_ENTRY *NewMenuEntry;
BM_LOAD_CONTEXT *NewLoadContext;
UINT16 Index;
VOID *OptionsOpCodeHandle;
UINT32 BootNextIndex;
if (BootOptionMenu.MenuNumber == 0) {
return;
}
BootNextIndex = NONE_BOOTNEXT_VALUE;
OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();
ASSERT (OptionsOpCodeHandle != NULL);
for (Index = 0; Index < BootOptionMenu.MenuNumber; Index++) {
NewMenuEntry = BOpt_GetMenuEntry (&BootOptionMenu, Index);
NewLoadContext = (BM_LOAD_CONTEXT *) NewMenuEntry->VariableContext;
if (NewLoadContext->IsBootNext) {
HiiCreateOneOfOptionOpCode (
OptionsOpCodeHandle,
NewMenuEntry->DisplayStringToken,
EFI_IFR_OPTION_DEFAULT,
EFI_IFR_TYPE_NUM_SIZE_32,
Index
);
BootNextIndex = Index;
} else {
HiiCreateOneOfOptionOpCode (
OptionsOpCodeHandle,
NewMenuEntry->DisplayStringToken,
0,
EFI_IFR_TYPE_NUM_SIZE_32,
Index
);
}
}
if (BootNextIndex == NONE_BOOTNEXT_VALUE) {
HiiCreateOneOfOptionOpCode (
OptionsOpCodeHandle,
STRING_TOKEN (STR_NONE),
EFI_IFR_OPTION_DEFAULT,
EFI_IFR_TYPE_NUM_SIZE_32,
NONE_BOOTNEXT_VALUE
);
} else {
HiiCreateOneOfOptionOpCode (
OptionsOpCodeHandle,
STRING_TOKEN (STR_NONE),
0,
EFI_IFR_TYPE_NUM_SIZE_32,
NONE_BOOTNEXT_VALUE
);
}
HiiCreateOneOfOpCode (
StartOpCodeHandle,
(EFI_QUESTION_ID) BOOT_NEXT_QUESTION_ID,
VARSTORE_ID_BOOT_MAINT,
BOOT_NEXT_VAR_OFFSET,
STRING_TOKEN (STR_BOOT_NEXT),
STRING_TOKEN (STR_BOOT_NEXT_HELP),
0,
EFI_IFR_NUMERIC_SIZE_4,
OptionsOpCodeHandle,
NULL
);
HiiFreeOpCodeHandle (OptionsOpCodeHandle);
}
/**
Create Time Out Menu in the page.
@param[in] HiiHandle The hii handle for the Uiapp driver.
@param[in] StartOpCodeHandle The opcode handle to save the new opcode.
**/
VOID
BmmCreateTimeOutMenu (
IN EFI_HII_HANDLE HiiHandle,
IN VOID *StartOpCodeHandle
)
{
HiiCreateNumericOpCode (
StartOpCodeHandle,
(EFI_QUESTION_ID) FORM_TIME_OUT_ID,
VARSTORE_ID_BOOT_MAINT,
BOOT_TIME_OUT_VAR_OFFSET,
STRING_TOKEN(STR_NUM_AUTO_BOOT),
STRING_TOKEN(STR_HLP_AUTO_BOOT),
EFI_IFR_FLAG_CALLBACK,
EFI_IFR_NUMERIC_SIZE_2 | EFI_IFR_DISPLAY_UINT_DEC,
0,
65535,
0,
NULL
);
}
/**
Create Boot Option menu in the page.
@param[in] HiiHandle The hii handle for the Uiapp driver.
@param[in] StartOpCodeHandle The opcode handle to save the new opcode.
**/
VOID
BmmCreateBootOptionMenu (
IN EFI_HII_HANDLE HiiHandle,
IN VOID *StartOpCodeHandle
)
{
HiiCreateGotoOpCode (
StartOpCodeHandle,
FORM_BOOT_SETUP_ID,
STRING_TOKEN (STR_FORM_BOOT_SETUP_TITLE),
STRING_TOKEN (STR_FORM_BOOT_SETUP_HELP),
EFI_IFR_FLAG_CALLBACK,
FORM_BOOT_SETUP_ID
);
}
/**
Create Driver Option menu in the page.
@param[in] HiiHandle The hii handle for the Uiapp driver.
@param[in] StartOpCodeHandle The opcode handle to save the new opcode.
**/
VOID
BmmCreateDriverOptionMenu (
IN EFI_HII_HANDLE HiiHandle,
IN VOID *StartOpCodeHandle
)
{
HiiCreateGotoOpCode (
StartOpCodeHandle,
FORM_DRIVER_SETUP_ID,
STRING_TOKEN (STR_FORM_DRIVER_SETUP_TITLE),
STRING_TOKEN (STR_FORM_DRIVER_SETUP_HELP),
EFI_IFR_FLAG_CALLBACK,
FORM_DRIVER_SETUP_ID
);
}
/**
Create Com Option menu in the page.
@param[in] HiiHandle The hii handle for the Uiapp driver.
@param[in] StartOpCodeHandle The opcode handle to save the new opcode.
**/
VOID
BmmCreateComOptionMenu (
IN EFI_HII_HANDLE HiiHandle,
IN VOID *StartOpCodeHandle
)
{
HiiCreateGotoOpCode (
StartOpCodeHandle,
FORM_CON_MAIN_ID,
STRING_TOKEN (STR_FORM_CON_MAIN_TITLE),
STRING_TOKEN (STR_FORM_CON_MAIN_HELP),
EFI_IFR_FLAG_CALLBACK,
FORM_CON_MAIN_ID
);
}
/**
Create Com Option menu in the page.
@param[in] HiiHandle The hii handle for the Uiapp driver.
@param[in] StartOpCodeHandle The opcode handle to save the new opcode.
**/
VOID
BmmCreateBootFromFileMenu (
IN EFI_HII_HANDLE HiiHandle,
IN VOID *StartOpCodeHandle
)
{
HiiCreateGotoOpCode (
StartOpCodeHandle,
FORM_MAIN_ID,
STRING_TOKEN (STR_BOOT_FROM_FILE),
STRING_TOKEN (STR_BOOT_FROM_FILE_HELP),
EFI_IFR_FLAG_CALLBACK,
KEY_VALUE_BOOT_FROM_FILE
);
}
/**
Create empty line menu in the front page.
@param HiiHandle The hii handle for the Uiapp driver.
@param StartOpCodeHandle The opcode handle to save the new opcode.
**/
VOID
BmmCreateEmptyLine (
IN EFI_HII_HANDLE HiiHandle,
IN VOID *StartOpCodeHandle
)
{
HiiCreateSubTitleOpCode (StartOpCodeHandle, STRING_TOKEN (STR_NULL_STRING), 0, 0, 0);
}
/**
Extract device path for given HII handle and class guid.
@param Handle The HII handle.
@retval NULL Fail to get the device path string.
@return PathString Get the device path string.
**/
CHAR16 *
ExtractDevicePathFromHandle (
IN EFI_HII_HANDLE Handle
)
{
EFI_STATUS Status;
EFI_HANDLE DriverHandle;
ASSERT (Handle != NULL);
if (Handle == NULL) {
return NULL;
}
Status = gHiiDatabase->GetPackageListHandle (gHiiDatabase, Handle, &DriverHandle);
if (EFI_ERROR (Status)) {
return NULL;
}
return ConvertDevicePathToText(DevicePathFromHandle (DriverHandle), FALSE, FALSE);
}
/**
Check whether this driver need to be shown in the front page.
@param HiiHandle The hii handle for the driver.
@param Guid The special guid for the driver which is the target.
@param PromptId Return the prompt string id.
@param HelpId Return the help string id.
@param FormsetGuid Return the formset guid info.
@retval EFI_SUCCESS Search the driver success
**/
BOOLEAN
IsRequiredDriver (
IN EFI_HII_HANDLE HiiHandle,
IN EFI_GUID *Guid,
OUT EFI_STRING_ID *PromptId,
OUT EFI_STRING_ID *HelpId,
OUT VOID *FormsetGuid
)
{
EFI_STATUS Status;
UINT8 ClassGuidNum;
EFI_GUID *ClassGuid;
EFI_IFR_FORM_SET *Buffer;
UINTN BufferSize;
UINT8 *Ptr;
UINTN TempSize;
BOOLEAN RetVal;
Status = HiiGetFormSetFromHiiHandle(HiiHandle, &Buffer,&BufferSize);
if (EFI_ERROR (Status)) {
return FALSE;
}
RetVal = FALSE;
TempSize = 0;
Ptr = (UINT8 *) Buffer;
while(TempSize < BufferSize) {
TempSize += ((EFI_IFR_OP_HEADER *) Ptr)->Length;
if (((EFI_IFR_OP_HEADER *) Ptr)->Length <= OFFSET_OF (EFI_IFR_FORM_SET, Flags)){
Ptr += ((EFI_IFR_OP_HEADER *) Ptr)->Length;
continue;
}
ClassGuidNum = (UINT8) (((EFI_IFR_FORM_SET *)Ptr)->Flags & 0x3);
ClassGuid = (EFI_GUID *) (VOID *)(Ptr + sizeof (EFI_IFR_FORM_SET));
while (ClassGuidNum-- > 0) {
if (!CompareGuid (Guid, ClassGuid)){
ClassGuid ++;
continue;
}
*PromptId = ((EFI_IFR_FORM_SET *)Ptr)->FormSetTitle;
*HelpId = ((EFI_IFR_FORM_SET *)Ptr)->Help;
CopyMem (FormsetGuid, &((EFI_IFR_FORM_SET *) Ptr)->Guid, sizeof (EFI_GUID));
RetVal = TRUE;
}
}
FreePool (Buffer);
return RetVal;
}
/**
Search the drivers in the system which need to show in the front page
and insert the menu to the front page.
@param HiiHandle The hii handle for the Uiapp driver.
@param ClassGuid The class guid for the driver which is the target.
@param SpecialHandlerFn The pointer to the specail handler function, if any.
@param StartOpCodeHandle The opcode handle to save the new opcode.
@retval EFI_SUCCESS Search the driver success
**/
EFI_STATUS
BmmListThirdPartyDrivers (
IN EFI_HII_HANDLE HiiHandle,
IN EFI_GUID *ClassGuid,
IN DRIVER_SPECIAL_HANDLER SpecialHandlerFn,
IN VOID *StartOpCodeHandle
)
{
UINTN Index;
EFI_STRING String;
EFI_STRING_ID Token;
EFI_STRING_ID TokenHelp;
EFI_HII_HANDLE *HiiHandles;
CHAR16 *DevicePathStr;
UINTN Count;
UINTN CurrentSize;
UI_HII_DRIVER_INSTANCE *DriverListPtr;
EFI_STRING NewName;
BOOLEAN EmptyLineAfter;
if (gHiiDriverList != NULL) {
FreePool (gHiiDriverList);
}
HiiHandles = HiiGetHiiHandles (NULL);
ASSERT (HiiHandles != NULL);
gHiiDriverList = AllocateZeroPool (UI_HII_DRIVER_LIST_SIZE * sizeof (UI_HII_DRIVER_INSTANCE));
ASSERT (gHiiDriverList != NULL);
DriverListPtr = gHiiDriverList;
CurrentSize = UI_HII_DRIVER_LIST_SIZE;
for (Index = 0, Count = 0; HiiHandles[Index] != NULL; Index++) {
if (!IsRequiredDriver (HiiHandles[Index], ClassGuid, &Token, &TokenHelp, &gHiiDriverList[Count].FormSetGuid)) {
continue;
}
String = HiiGetString (HiiHandles[Index], Token, NULL);
if (String == NULL) {
String = HiiGetString (HiiHandle, STRING_TOKEN (STR_MISSING_STRING), NULL);
ASSERT (String != NULL);
} else if (SpecialHandlerFn != NULL) {
//
// Check whether need to rename the driver name.
//
EmptyLineAfter = FALSE;
if (SpecialHandlerFn (String, &NewName, &EmptyLineAfter)) {
FreePool (String);
String = NewName;
DriverListPtr[Count].EmptyLineAfter = EmptyLineAfter;
}
}
DriverListPtr[Count].PromptId = HiiSetString (HiiHandle, 0, String, NULL);
FreePool (String);
String = HiiGetString (HiiHandles[Index], TokenHelp, NULL);
if (String == NULL) {
String = HiiGetString (HiiHandle, STRING_TOKEN (STR_MISSING_STRING), NULL);
ASSERT (String != NULL);
}
DriverListPtr[Count].HelpId = HiiSetString (HiiHandle, 0, String, NULL);
FreePool (String);
DevicePathStr = ExtractDevicePathFromHandle(HiiHandles[Index]);
if (DevicePathStr != NULL){
DriverListPtr[Count].DevicePathId = HiiSetString (HiiHandle, 0, DevicePathStr, NULL);
FreePool (DevicePathStr);
} else {
DriverListPtr[Count].DevicePathId = 0;
}
Count++;
if (Count >= CurrentSize) {
DriverListPtr = AllocateCopyPool ((Count + UI_HII_DRIVER_LIST_SIZE) * sizeof (UI_HII_DRIVER_INSTANCE), gHiiDriverList);
ASSERT (DriverListPtr != NULL);
FreePool (gHiiDriverList);
gHiiDriverList = DriverListPtr;
CurrentSize += UI_HII_DRIVER_LIST_SIZE;
}
}
FreePool (HiiHandles);
Index = 0;
while (gHiiDriverList[Index].PromptId != 0) {
HiiCreateGotoExOpCode (
StartOpCodeHandle,
0,
gHiiDriverList[Index].PromptId,
gHiiDriverList[Index].HelpId,
0,
0,
0,
&gHiiDriverList[Index].FormSetGuid,
gHiiDriverList[Index].DevicePathId
);
if (gHiiDriverList[Index].EmptyLineAfter) {
BmmCreateEmptyLine (HiiHandle, StartOpCodeHandle);
}
Index ++;
}
return EFI_SUCCESS;
}
|