2 The functions for Boot Maintainence Main menu.
4 Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "BootMaintenanceManager.h"
17 #include "BootMaintenanceManagerCustomizedUiSupport.h"
19 #define UI_HII_DRIVER_LIST_SIZE 0x8
22 EFI_STRING_ID PromptId
;
24 EFI_STRING_ID DevicePathId
;
26 BOOLEAN EmptyLineAfter
;
27 } UI_HII_DRIVER_INSTANCE
;
29 UI_HII_DRIVER_INSTANCE
*gHiiDriverList
;
33 Create the dynamic item to allow user to set the "BootNext" vaule.
35 @param CallbackData The BMM context data.
39 BmmCreateBootNextMenu(
40 IN EFI_HII_HANDLE HiiHandle
,
41 IN VOID
*StartOpCodeHandle
44 BM_MENU_ENTRY
*NewMenuEntry
;
45 BM_LOAD_CONTEXT
*NewLoadContext
;
46 UINTN NumberOfOptions
;
48 VOID
*OptionsOpCodeHandle
;
50 EFI_STRING_ID OptionId
;
52 NumberOfOptions
= BootOptionMenu
.MenuNumber
;
53 if (NumberOfOptions
== 0) {
57 OptionsOpCodeHandle
= HiiAllocateOpCodeHandle ();
58 ASSERT (OptionsOpCodeHandle
!= NULL
);
60 for (Index
= 0; Index
< BootOptionMenu
.MenuNumber
; Index
++) {
61 NewMenuEntry
= BOpt_GetMenuEntry (&BootOptionMenu
, Index
);
62 NewLoadContext
= (BM_LOAD_CONTEXT
*) NewMenuEntry
->VariableContext
;
64 StringBuffer
= HiiGetString (HiiHandle
, NewMenuEntry
->DisplayStringToken
, NULL
);
65 ASSERT (StringBuffer
!= NULL
);
66 OptionId
= HiiSetString (HiiHandle
, 0, StringBuffer
, NULL
);
67 FreePool (StringBuffer
);
69 HiiCreateOneOfOptionOpCode (
73 EFI_IFR_TYPE_NUM_SIZE_16
,
78 StringBuffer
= HiiGetString (HiiHandle
, STRING_TOKEN (STR_NONE
), NULL
);
79 ASSERT (StringBuffer
!= NULL
);
80 OptionId
= HiiSetString (HiiHandle
, 0, StringBuffer
, NULL
);
81 FreePool (StringBuffer
);
84 // Set no Boot Next Value as default.
86 HiiCreateOneOfOptionOpCode (
89 EFI_IFR_OPTION_DEFAULT
,
90 EFI_IFR_TYPE_NUM_SIZE_16
,
94 HiiCreateOneOfOpCode (
96 (EFI_QUESTION_ID
) BOOT_NEXT_QUESTION_ID
,
97 VARSTORE_ID_BOOT_MAINT
,
99 STRING_TOKEN (STR_BOOT_NEXT
),
100 STRING_TOKEN (STR_BOOT_NEXT_HELP
),
102 EFI_IFR_NUMERIC_SIZE_2
,
107 HiiFreeOpCodeHandle (OptionsOpCodeHandle
);
112 Create Time Out Menu in the page.
114 @param[in] HiiHandle The hii handle for the Uiapp driver.
115 @param[in] StartOpCodeHandle The opcode handle to save the new opcode.
116 @param[in] PromptId The Prompt string id.
117 @param[in] HelpId The help string id.
118 @param[in] FormId The Form id for the dest form.
119 @param[in] QuestionId The question id for this goto question.
123 BmmCreateTimeOutMenu (
124 IN EFI_HII_HANDLE HiiHandle
,
125 IN VOID
*StartOpCodeHandle
128 HiiCreateNumericOpCode (
130 (EFI_QUESTION_ID
) FORM_TIME_OUT_ID
,
131 VARSTORE_ID_BOOT_MAINT
,
132 BOOT_TIME_OUT_VAR_OFFSET
,
133 STRING_TOKEN(STR_NUM_AUTO_BOOT
),
134 STRING_TOKEN(STR_HLP_AUTO_BOOT
),
135 EFI_IFR_FLAG_CALLBACK
,
136 EFI_IFR_NUMERIC_SIZE_2
| EFI_IFR_DISPLAY_UINT_DEC
,
145 Create Boot Option menu in the page.
147 @param[in] HiiHandle The hii handle for the Uiapp driver.
148 @param[in] StartOpCodeHandle The opcode handle to save the new opcode.
152 BmmCreateBootOptionMenu (
153 IN EFI_HII_HANDLE HiiHandle
,
154 IN VOID
*StartOpCodeHandle
157 HiiCreateGotoOpCode (
160 STRING_TOKEN (STR_FORM_BOOT_SETUP_TITLE
),
161 STRING_TOKEN (STR_FORM_BOOT_SETUP_HELP
),
162 EFI_IFR_FLAG_CALLBACK
,
168 Create Driver Option menu in the page.
170 @param[in] HiiHandle The hii handle for the Uiapp driver.
171 @param[in] StartOpCodeHandle The opcode handle to save the new opcode.
175 BmmCreateDriverOptionMenu (
176 IN EFI_HII_HANDLE HiiHandle
,
177 IN VOID
*StartOpCodeHandle
180 HiiCreateGotoOpCode (
182 FORM_DRIVER_SETUP_ID
,
183 STRING_TOKEN (STR_FORM_DRIVER_SETUP_TITLE
),
184 STRING_TOKEN (STR_FORM_DRIVER_SETUP_HELP
),
185 EFI_IFR_FLAG_CALLBACK
,
191 Create Com Option menu in the page.
193 @param[in] HiiHandle The hii handle for the Uiapp driver.
194 @param[in] StartOpCodeHandle The opcode handle to save the new opcode.
198 BmmCreateComOptionMenu (
199 IN EFI_HII_HANDLE HiiHandle
,
200 IN VOID
*StartOpCodeHandle
203 HiiCreateGotoOpCode (
206 STRING_TOKEN (STR_FORM_CON_MAIN_TITLE
),
207 STRING_TOKEN (STR_FORM_CON_MAIN_HELP
),
208 EFI_IFR_FLAG_CALLBACK
,
214 Create Com Option menu in the page.
216 @param[in] HiiHandle The hii handle for the Uiapp driver.
217 @param[in] StartOpCodeHandle The opcode handle to save the new opcode.
218 @param[in] PromptId The Prompt string id.
219 @param[in] HelpId The help string id.
220 @param[in] FormId The Form id for the dest form.
221 @param[in] QuestionId The question id for this goto question.
225 BmmCreateBootFromFileMenu (
226 IN EFI_HII_HANDLE HiiHandle
,
227 IN VOID
*StartOpCodeHandle
230 HiiCreateGotoOpCode (
233 STRING_TOKEN (STR_BOOT_FROM_FILE
),
234 STRING_TOKEN (STR_BOOT_FROM_FILE_HELP
),
235 EFI_IFR_FLAG_CALLBACK
,
236 KEY_VALUE_BOOT_FROM_FILE
241 Create empty line menu in the front page.
243 @param HiiHandle The hii handle for the Uiapp driver.
244 @param StartOpCodeHandle The opcode handle to save the new opcode.
249 IN EFI_HII_HANDLE HiiHandle
,
250 IN VOID
*StartOpCodeHandle
253 HiiCreateSubTitleOpCode (StartOpCodeHandle
, STRING_TOKEN (STR_NULL_STRING
), 0, 0, 0);
257 Extract device path for given HII handle and class guid.
259 @param Handle The HII handle.
261 @retval NULL Fail to get the device path string.
262 @return PathString Get the device path string.
266 ExtractDevicePathFromHandle (
267 IN EFI_HII_HANDLE Handle
271 EFI_HANDLE DriverHandle
;
273 ASSERT (Handle
!= NULL
);
275 if (Handle
== NULL
) {
279 Status
= gHiiDatabase
->GetPackageListHandle (gHiiDatabase
, Handle
, &DriverHandle
);
280 if (EFI_ERROR (Status
)) {
284 return ConvertDevicePathToText(DevicePathFromHandle (DriverHandle
), FALSE
, FALSE
);
288 Check whether this driver need to be shown in the front page.
290 @param HiiHandle The hii handle for the driver.
291 @param Guid The special guid for the driver which is the target.
292 @param PromptId Return the prompt string id.
293 @param HelpId Return the help string id.
294 @param FormsetGuid Return the formset guid info.
296 @retval EFI_SUCCESS Search the driver success
301 IN EFI_HII_HANDLE HiiHandle
,
303 OUT EFI_STRING_ID
*PromptId
,
304 OUT EFI_STRING_ID
*HelpId
,
305 OUT VOID
*FormsetGuid
311 EFI_IFR_FORM_SET
*Buffer
;
317 Status
= HiiGetFormSetFromHiiHandle(HiiHandle
, &Buffer
,&BufferSize
);
318 if (EFI_ERROR (Status
)) {
324 Ptr
= (UINT8
*) Buffer
;
325 while(TempSize
< BufferSize
) {
326 TempSize
+= ((EFI_IFR_OP_HEADER
*) Ptr
)->Length
;
328 if (((EFI_IFR_OP_HEADER
*) Ptr
)->Length
<= OFFSET_OF (EFI_IFR_FORM_SET
, Flags
)){
329 Ptr
+= ((EFI_IFR_OP_HEADER
*) Ptr
)->Length
;
333 ClassGuidNum
= (UINT8
) (((EFI_IFR_FORM_SET
*)Ptr
)->Flags
& 0x3);
334 ClassGuid
= (EFI_GUID
*) (VOID
*)(Ptr
+ sizeof (EFI_IFR_FORM_SET
));
335 while (ClassGuidNum
-- > 0) {
336 if (!CompareGuid (Guid
, ClassGuid
)){
341 *PromptId
= ((EFI_IFR_FORM_SET
*)Ptr
)->FormSetTitle
;
342 *HelpId
= ((EFI_IFR_FORM_SET
*)Ptr
)->Help
;
343 CopyMem (FormsetGuid
, &((EFI_IFR_FORM_SET
*) Ptr
)->Guid
, sizeof (EFI_GUID
));
354 Search the drivers in the system which need to show in the front page
355 and insert the menu to the front page.
357 @param HiiHandle The hii handle for the Uiapp driver.
358 @param ClassGuid The class guid for the driver which is the target.
359 @param StartOpCodeHandle The opcode handle to save the new opcode.
360 @param SpecialHandler The pointer to the specail handler function, if any.
362 @retval EFI_SUCCESS Search the driver success
366 BmmListThirdPartyDrivers (
367 IN EFI_HII_HANDLE HiiHandle
,
368 IN EFI_GUID
*ClassGuid
,
369 IN DRIVER_SPECIAL_HANDLER SpecialHandlerFn
,
370 IN VOID
*StartOpCodeHandle
376 EFI_STRING_ID TokenHelp
;
377 EFI_HII_HANDLE
*HiiHandles
;
378 CHAR16
*DevicePathStr
;
381 UI_HII_DRIVER_INSTANCE
*DriverListPtr
;
383 BOOLEAN EmptyLineAfter
;
385 if (gHiiDriverList
!= NULL
) {
386 FreePool (gHiiDriverList
);
389 HiiHandles
= HiiGetHiiHandles (NULL
);
390 ASSERT (HiiHandles
!= NULL
);
392 gHiiDriverList
= AllocateZeroPool (UI_HII_DRIVER_LIST_SIZE
* sizeof (UI_HII_DRIVER_INSTANCE
));
393 ASSERT (gHiiDriverList
!= NULL
);
394 DriverListPtr
= gHiiDriverList
;
395 CurrentSize
= UI_HII_DRIVER_LIST_SIZE
;
397 for (Index
= 0, Count
= 0; HiiHandles
[Index
] != NULL
; Index
++) {
398 if (!IsRequiredDriver (HiiHandles
[Index
], ClassGuid
, &Token
, &TokenHelp
, &gHiiDriverList
[Count
].FormSetGuid
)) {
402 String
= HiiGetString (HiiHandles
[Index
], Token
, NULL
);
403 if (String
== NULL
) {
404 String
= HiiGetString (HiiHandle
, STRING_TOKEN (STR_MISSING_STRING
), NULL
);
405 ASSERT (String
!= NULL
);
406 } else if (SpecialHandlerFn
!= NULL
) {
408 // Check whether need to rename the driver name.
410 EmptyLineAfter
= FALSE
;
411 if (SpecialHandlerFn (String
, &NewName
, &EmptyLineAfter
)) {
414 DriverListPtr
[Count
].EmptyLineAfter
= EmptyLineAfter
;
417 DriverListPtr
[Count
].PromptId
= HiiSetString (HiiHandle
, 0, String
, NULL
);
420 String
= HiiGetString (HiiHandles
[Index
], TokenHelp
, NULL
);
421 if (String
== NULL
) {
422 String
= HiiGetString (HiiHandle
, STRING_TOKEN (STR_MISSING_STRING
), NULL
);
423 ASSERT (String
!= NULL
);
425 DriverListPtr
[Count
].HelpId
= HiiSetString (HiiHandle
, 0, String
, NULL
);
428 DevicePathStr
= ExtractDevicePathFromHandle(HiiHandles
[Index
]);
429 if (DevicePathStr
!= NULL
){
430 DriverListPtr
[Count
].DevicePathId
= HiiSetString (HiiHandle
, 0, DevicePathStr
, NULL
);
431 FreePool (DevicePathStr
);
433 DriverListPtr
[Count
].DevicePathId
= 0;
437 if (Count
>= CurrentSize
) {
438 DriverListPtr
= AllocateCopyPool ((Count
+ UI_HII_DRIVER_LIST_SIZE
) * sizeof (UI_HII_DRIVER_INSTANCE
), gHiiDriverList
);
439 ASSERT (DriverListPtr
!= NULL
);
440 FreePool (gHiiDriverList
);
441 gHiiDriverList
= DriverListPtr
;
442 CurrentSize
+= UI_HII_DRIVER_LIST_SIZE
;
446 FreePool (HiiHandles
);
449 while (gHiiDriverList
[Index
].PromptId
!= 0) {
450 HiiCreateGotoExOpCode (
453 gHiiDriverList
[Index
].PromptId
,
454 gHiiDriverList
[Index
].HelpId
,
458 &gHiiDriverList
[Index
].FormSetGuid
,
459 gHiiDriverList
[Index
].DevicePathId
462 if (gHiiDriverList
[Index
].EmptyLineAfter
) {
463 BmmCreateEmptyLine (HiiHandle
, StartOpCodeHandle
);