0e85a832c12c49665eb00052bc5100f07534aafd
[mirror_edk2.git] / MdeModulePkg / Application / UiApp / BootMaint / UpdatePage.c
1 /** @file
2 Dynamically update the pages.
3
4 Copyright (c) 2004 - 2015, 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
9
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.
12
13 **/
14
15 #include "BootMaint.h"
16
17 /**
18 Refresh the global UpdateData structure.
19
20 **/
21 VOID
22 RefreshUpdateData (
23 VOID
24 )
25 {
26 //
27 // Free current updated date
28 //
29 if (mStartOpCodeHandle != NULL) {
30 HiiFreeOpCodeHandle (mStartOpCodeHandle);
31 }
32
33 //
34 // Create new OpCode Handle
35 //
36 mStartOpCodeHandle = HiiAllocateOpCodeHandle ();
37
38 //
39 // Create Hii Extend Label OpCode as the start opcode
40 //
41 mStartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (mStartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
42 mStartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
43
44 }
45
46 /**
47 Add a "Go back to main page" tag in front of the form when there are no
48 "Apply changes" and "Discard changes" tags in the end of the form.
49
50 @param CallbackData The BMM context data.
51
52 **/
53 VOID
54 UpdatePageStart (
55 IN BMM_CALLBACK_DATA *CallbackData
56 )
57 {
58 RefreshUpdateData ();
59 mStartLabel->Number = CallbackData->BmmCurrentPageId;
60
61 if (!(CallbackData->BmmAskSaveOrNot)) {
62 //
63 // Add a "Go back to main page" tag in front of the form when there are no
64 // "Apply changes" and "Discard changes" tags in the end of the form.
65 //
66 HiiCreateGotoOpCode (
67 mStartOpCodeHandle,
68 FORM_MAIN_ID,
69 STRING_TOKEN (STR_FORM_GOTO_MAIN),
70 STRING_TOKEN (STR_FORM_GOTO_MAIN),
71 0,
72 FORM_MAIN_ID
73 );
74 }
75
76 }
77
78 /**
79 Create the "Apply changes" and "Discard changes" tags. And
80 ensure user can return to the main page.
81
82 @param CallbackData The BMM context data.
83
84 **/
85 VOID
86 UpdatePageEnd (
87 IN BMM_CALLBACK_DATA *CallbackData
88 )
89 {
90 //
91 // Create the "Apply changes" and "Discard changes" tags.
92 //
93 if (CallbackData->BmmAskSaveOrNot) {
94 HiiCreateSubTitleOpCode (
95 mStartOpCodeHandle,
96 STRING_TOKEN (STR_NULL_STRING),
97 0,
98 0,
99 0
100 );
101
102 HiiCreateActionOpCode (
103 mStartOpCodeHandle,
104 KEY_VALUE_SAVE_AND_EXIT,
105 STRING_TOKEN (STR_SAVE_AND_EXIT),
106 STRING_TOKEN (STR_NULL_STRING),
107 EFI_IFR_FLAG_CALLBACK,
108 0
109 );
110 }
111
112 //
113 // Ensure user can return to the main page.
114 //
115 HiiCreateActionOpCode (
116 mStartOpCodeHandle,
117 KEY_VALUE_NO_SAVE_AND_EXIT,
118 STRING_TOKEN (STR_NO_SAVE_AND_EXIT),
119 STRING_TOKEN (STR_NULL_STRING),
120 EFI_IFR_FLAG_CALLBACK,
121 0
122 );
123
124 HiiUpdateForm (
125 CallbackData->BmmHiiHandle,
126 &mBootMaintGuid,
127 CallbackData->BmmCurrentPageId,
128 mStartOpCodeHandle, // Label CallbackData->BmmCurrentPageId
129 mEndOpCodeHandle // LABEL_END
130 );
131 }
132
133 /**
134 Clean up the dynamic opcode at label and form specified by both LabelId.
135
136 @param LabelId It is both the Form ID and Label ID for opcode deletion.
137 @param CallbackData The BMM context data.
138
139 **/
140 VOID
141 CleanUpPage (
142 IN UINT16 LabelId,
143 IN BMM_CALLBACK_DATA *CallbackData
144 )
145 {
146 RefreshUpdateData ();
147
148 //
149 // Remove all op-codes from dynamic page
150 //
151 mStartLabel->Number = LabelId;
152 HiiUpdateForm (
153 CallbackData->BmmHiiHandle,
154 &mBootMaintGuid,
155 LabelId,
156 mStartOpCodeHandle, // Label LabelId
157 mEndOpCodeHandle // LABEL_END
158 );
159 }
160
161 /**
162 Boot a file selected by user at File Expoloer of BMM.
163
164 @param FileContext The file context data, which contains the device path
165 of the file to be boot from.
166
167 @retval EFI_SUCCESS The function completed successfull.
168 @return Other value if the boot from the file fails.
169
170 **/
171 EFI_STATUS
172 BootThisFile (
173 IN BM_FILE_CONTEXT *FileContext
174 )
175 {
176 EFI_BOOT_MANAGER_LOAD_OPTION BootOption;
177
178 EfiBootManagerInitializeLoadOption (
179 &BootOption,
180 0,
181 LoadOptionTypeBoot,
182 LOAD_OPTION_ACTIVE,
183 FileContext->FileName,
184 FileContext->DevicePath,
185 NULL,
186 0
187 );
188 //
189 // Since current no boot from removable media directly is allowed */
190 //
191 gST->ConOut->ClearScreen (gST->ConOut);
192
193 BdsSetConsoleMode (FALSE);
194 EfiBootManagerBoot (&BootOption);
195 BdsSetConsoleMode (TRUE);
196
197 EfiBootManagerFreeLoadOption (&BootOption);
198
199 return BootOption.Status;
200
201 }
202
203 /**
204 Create a list of Goto Opcode for all terminal devices logged
205 by TerminaMenu. This list will be inserted to form FORM_CON_COM_SETUP_ID.
206
207 @param CallbackData The BMM context data.
208 **/
209 VOID
210 UpdateConCOMPage (
211 IN BMM_CALLBACK_DATA *CallbackData
212 )
213 {
214 BM_MENU_ENTRY *NewMenuEntry;
215 UINT16 Index;
216
217 UpdatePageStart (CallbackData);
218
219 for (Index = 0; Index < TerminalMenu.MenuNumber; Index++) {
220 NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Index);
221
222 HiiCreateGotoOpCode (
223 mStartOpCodeHandle,
224 FORM_CON_COM_SETUP_ID,
225 NewMenuEntry->DisplayStringToken,
226 STRING_TOKEN (STR_NULL_STRING),
227 EFI_IFR_FLAG_CALLBACK,
228 (UINT16) (TERMINAL_OPTION_OFFSET + Index)
229 );
230 }
231
232 UpdatePageEnd (CallbackData);
233 }
234
235
236 /**
237 Create a list of boot option from global BootOptionMenu. It
238 allow user to delete the boot option.
239
240 @param CallbackData The BMM context data.
241
242 **/
243 VOID
244 UpdateBootDelPage (
245 IN BMM_CALLBACK_DATA *CallbackData
246 )
247 {
248 BM_MENU_ENTRY *NewMenuEntry;
249 BM_LOAD_CONTEXT *NewLoadContext;
250 UINT16 Index;
251
252 //CallbackData->BmmAskSaveOrNot = TRUE;
253
254 UpdatePageStart (CallbackData);
255 CreateMenuStringToken (CallbackData, CallbackData->BmmHiiHandle, &BootOptionMenu);
256
257 ASSERT (BootOptionMenu.MenuNumber <= (sizeof (CallbackData->BmmFakeNvData.BootOptionDel) / sizeof (CallbackData->BmmFakeNvData.BootOptionDel[0])));
258 for (Index = 0; Index < BootOptionMenu.MenuNumber; Index++) {
259 NewMenuEntry = BOpt_GetMenuEntry (&BootOptionMenu, Index);
260 NewLoadContext = (BM_LOAD_CONTEXT *) NewMenuEntry->VariableContext;
261 if (NewLoadContext->IsLegacy) {
262 continue;
263 }
264
265 //
266 // Check to see if the current boot option devicepath is the ShellDevice
267 // path. If it is keep only UEFI Shell in the delete boot option list
268 // or else continue
269 //
270 //if ((NULL != NewLoadContext->FilePathList) && (TRUE == IsShellNodeDevicePath(NewLoadContext->FilePathList))) {
271 // NewLoadContext->Deleted = FALSE;
272 // CallbackData->BmmFakeNvData.OptionDel[Index] = FALSE;
273
274 HiiCreateCheckBoxOpCode (
275 mStartOpCodeHandle,
276 (EFI_QUESTION_ID) (BOOT_OPTION_DEL_QUESTION_ID + Index),
277 VARSTORE_ID_BOOT_MAINT,
278 (UINT16) (BOOT_OPTION_DEL_VAR_OFFSET + Index),
279 NewMenuEntry->DisplayStringToken,
280 NewMenuEntry->HelpStringToken,
281 0,
282 0,
283 NULL
284 );
285 //} else {
286 // continue;
287 //}
288 }
289 UpdatePageEnd (CallbackData);
290 }
291
292 /**
293 Create a lit of driver option from global DriverMenu.
294
295 @param CallbackData The BMM context data.
296
297 **/
298 VOID
299 UpdateDrvAddHandlePage (
300 IN BMM_CALLBACK_DATA *CallbackData
301 )
302 {
303 BM_MENU_ENTRY *NewMenuEntry;
304 UINT16 Index;
305
306 CallbackData->BmmAskSaveOrNot = FALSE;
307
308 UpdatePageStart (CallbackData);
309
310 for (Index = 0; Index < DriverMenu.MenuNumber; Index++) {
311 NewMenuEntry = BOpt_GetMenuEntry (&DriverMenu, Index);
312
313 HiiCreateGotoOpCode (
314 mStartOpCodeHandle,
315 FORM_DRV_ADD_HANDLE_DESC_ID,
316 NewMenuEntry->DisplayStringToken,
317 STRING_TOKEN (STR_NULL_STRING),
318 EFI_IFR_FLAG_CALLBACK,
319 (UINT16) (HANDLE_OPTION_OFFSET + Index)
320 );
321 }
322
323 UpdatePageEnd (CallbackData);
324 }
325
326 /**
327 Create a lit of driver option from global DriverOptionMenu. It
328 allow user to delete the driver option.
329
330 @param CallbackData The BMM context data.
331
332 **/
333 VOID
334 UpdateDrvDelPage (
335 IN BMM_CALLBACK_DATA *CallbackData
336 )
337 {
338 BM_MENU_ENTRY *NewMenuEntry;
339 BM_LOAD_CONTEXT *NewLoadContext;
340 UINT16 Index;
341
342 CallbackData->BmmAskSaveOrNot = TRUE;
343
344 UpdatePageStart (CallbackData);
345
346 CreateMenuStringToken (CallbackData, CallbackData->BmmHiiHandle, &DriverOptionMenu);
347
348 ASSERT (DriverOptionMenu.MenuNumber <= (sizeof (CallbackData->BmmFakeNvData.DriverOptionDel) / sizeof (CallbackData->BmmFakeNvData.DriverOptionDel[0])));
349 for (Index = 0; Index < DriverOptionMenu.MenuNumber; Index++) {
350 NewMenuEntry = BOpt_GetMenuEntry (&DriverOptionMenu, Index);
351
352 NewLoadContext = (BM_LOAD_CONTEXT *) NewMenuEntry->VariableContext;
353 NewLoadContext->Deleted = FALSE;
354 CallbackData->BmmFakeNvData.DriverOptionDel[Index] = FALSE;
355
356 HiiCreateCheckBoxOpCode (
357 mStartOpCodeHandle,
358 (EFI_QUESTION_ID) (DRIVER_OPTION_DEL_QUESTION_ID + Index),
359 VARSTORE_ID_BOOT_MAINT,
360 (UINT16) (DRIVER_OPTION_DEL_VAR_OFFSET + Index),
361 NewMenuEntry->DisplayStringToken,
362 NewMenuEntry->HelpStringToken,
363 0,
364 0,
365 NULL
366 );
367 }
368
369 UpdatePageEnd (CallbackData);
370 }
371
372 /**
373 Prepare the page to allow user to add description for
374 a Driver Option.
375
376 @param CallbackData The BMM context data.
377
378 **/
379 VOID
380 UpdateDriverAddHandleDescPage (
381 IN BMM_CALLBACK_DATA *CallbackData
382 )
383 {
384 BM_MENU_ENTRY *NewMenuEntry;
385
386 CallbackData->BmmFakeNvData.DriverAddActive = 0x01;
387 CallbackData->BmmFakeNvData.DriverAddForceReconnect = 0x00;
388 CallbackData->BmmAskSaveOrNot = TRUE;
389 NewMenuEntry = CallbackData->MenuEntry;
390
391 UpdatePageStart (CallbackData);
392
393 HiiCreateSubTitleOpCode (
394 mStartOpCodeHandle,
395 NewMenuEntry->DisplayStringToken,
396 0,
397 0,
398 0
399 );
400
401 HiiCreateStringOpCode (
402 mStartOpCodeHandle,
403 (EFI_QUESTION_ID) DRV_ADD_HANDLE_DESC_QUESTION_ID,
404 VARSTORE_ID_BOOT_MAINT,
405 DRV_ADD_HANDLE_DESC_VAR_OFFSET,
406 STRING_TOKEN (STR_LOAD_OPTION_DESC),
407 STRING_TOKEN (STR_NULL_STRING),
408 0,
409 0,
410 6,
411 75,
412 NULL
413 );
414
415 HiiCreateCheckBoxOpCode (
416 mStartOpCodeHandle,
417 (EFI_QUESTION_ID) DRV_ADD_RECON_QUESTION_ID,
418 VARSTORE_ID_BOOT_MAINT,
419 DRV_ADD_RECON_VAR_OFFSET,
420 STRING_TOKEN (STR_LOAD_OPTION_FORCE_RECON),
421 STRING_TOKEN (STR_LOAD_OPTION_FORCE_RECON),
422 0,
423 0,
424 NULL
425 );
426
427 HiiCreateStringOpCode (
428 mStartOpCodeHandle,
429 (EFI_QUESTION_ID) DRIVER_ADD_OPTION_QUESTION_ID,
430 VARSTORE_ID_BOOT_MAINT,
431 DRIVER_ADD_OPTION_VAR_OFFSET,
432 STRING_TOKEN (STR_OPTIONAL_DATA),
433 STRING_TOKEN (STR_NULL_STRING),
434 0,
435 0,
436 6,
437 75,
438 NULL
439 );
440
441 UpdatePageEnd (CallbackData);
442 }
443
444 /**
445 Update console page.
446
447 @param UpdatePageId The form ID to be updated.
448 @param ConsoleMenu The console menu list.
449 @param CallbackData The BMM context data.
450
451 **/
452 VOID
453 UpdateConsolePage (
454 IN UINT16 UpdatePageId,
455 IN BM_MENU_OPTION *ConsoleMenu,
456 IN BMM_CALLBACK_DATA *CallbackData
457 )
458 {
459 BM_MENU_ENTRY *NewMenuEntry;
460 BM_CONSOLE_CONTEXT *NewConsoleContext;
461 BM_TERMINAL_CONTEXT *NewTerminalContext;
462 UINT16 Index;
463 UINT16 Index2;
464 UINT8 CheckFlags;
465
466 CallbackData->BmmAskSaveOrNot = TRUE;
467
468 UpdatePageStart (CallbackData);
469
470 for (Index = 0; ((Index < ConsoleMenu->MenuNumber) && \
471 (Index < (sizeof (CallbackData->BmmFakeNvData.ConsoleCheck) / sizeof (UINT8)))) ; Index++) {
472 NewMenuEntry = BOpt_GetMenuEntry (ConsoleMenu, Index);
473 NewConsoleContext = (BM_CONSOLE_CONTEXT *) NewMenuEntry->VariableContext;
474 CheckFlags = 0;
475 if (NewConsoleContext->IsActive) {
476 CheckFlags |= EFI_IFR_CHECKBOX_DEFAULT;
477 CallbackData->BmmFakeNvData.ConsoleCheck[Index] = TRUE;
478 } else {
479 CallbackData->BmmFakeNvData.ConsoleCheck[Index] = FALSE;
480 }
481
482 HiiCreateCheckBoxOpCode (
483 mStartOpCodeHandle,
484 (EFI_QUESTION_ID) (CON_DEVICE_QUESTION_ID + Index),
485 VARSTORE_ID_BOOT_MAINT,
486 (UINT16) (CON_DEVICE_VAR_OFFSET + Index),
487 NewMenuEntry->DisplayStringToken,
488 NewMenuEntry->HelpStringToken,
489 0,
490 CheckFlags,
491 NULL
492 );
493 }
494
495 for (Index2 = 0; ((Index2 < TerminalMenu.MenuNumber) && \
496 (Index2 < (sizeof (CallbackData->BmmFakeNvData.ConsoleCheck) / sizeof (UINT8)))); Index2++) {
497 CheckFlags = 0;
498 NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Index2);
499 NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext;
500
501 ASSERT (Index < MAX_MENU_NUMBER);
502 if (((NewTerminalContext->IsConIn != 0) && (UpdatePageId == FORM_CON_IN_ID)) ||
503 ((NewTerminalContext->IsConOut != 0) && (UpdatePageId == FORM_CON_OUT_ID)) ||
504 ((NewTerminalContext->IsStdErr != 0) && (UpdatePageId == FORM_CON_ERR_ID))
505 ) {
506 CheckFlags |= EFI_IFR_CHECKBOX_DEFAULT;
507 CallbackData->BmmFakeNvData.ConsoleCheck[Index] = TRUE;
508 } else {
509 CallbackData->BmmFakeNvData.ConsoleCheck[Index] = FALSE;
510 }
511
512 HiiCreateCheckBoxOpCode (
513 mStartOpCodeHandle,
514 (EFI_QUESTION_ID) (CON_DEVICE_QUESTION_ID + Index),
515 VARSTORE_ID_BOOT_MAINT,
516 (UINT16) (CON_DEVICE_VAR_OFFSET + Index),
517 NewMenuEntry->DisplayStringToken,
518 NewMenuEntry->HelpStringToken,
519 0,
520 CheckFlags,
521 NULL
522 );
523
524 Index++;
525 }
526
527 UpdatePageEnd (CallbackData);
528 }
529
530 /**
531 Update the page's NV Map if user has changed the order
532 a list. This list can be Boot Order or Driver Order.
533
534 @param UpdatePageId The form ID to be updated.
535 @param OptionMenu The new list.
536 @param CallbackData The BMM context data.
537
538 **/
539 VOID
540 UpdateOrderPage (
541 IN UINT16 UpdatePageId,
542 IN BM_MENU_OPTION *OptionMenu,
543 IN BMM_CALLBACK_DATA *CallbackData
544 )
545 {
546 BM_MENU_ENTRY *NewMenuEntry;
547 UINT16 Index;
548 UINT16 OptionIndex;
549 VOID *OptionsOpCodeHandle;
550 BM_LOAD_CONTEXT *NewLoadContext;
551 BOOLEAN BootOptionFound;
552 UINT32 *OptionOrder;
553 EFI_QUESTION_ID QuestionId;
554 UINT16 VarOffset;
555
556
557 UpdatePageStart (CallbackData);
558
559 CreateMenuStringToken (CallbackData, CallbackData->BmmHiiHandle, OptionMenu);
560
561 OptionOrder = NULL;
562 QuestionId = 0;
563 VarOffset = 0;
564 switch (UpdatePageId) {
565
566 case FORM_BOOT_CHG_ID:
567 GetBootOrder (CallbackData);
568 OptionOrder = CallbackData->BmmFakeNvData.BootOptionOrder;
569 QuestionId = BOOT_OPTION_ORDER_QUESTION_ID;
570 VarOffset = BOOT_OPTION_ORDER_VAR_OFFSET;
571 break;
572
573 case FORM_DRV_CHG_ID:
574 GetDriverOrder (CallbackData);
575 OptionOrder = CallbackData->BmmFakeNvData.DriverOptionOrder;
576 QuestionId = DRIVER_OPTION_ORDER_QUESTION_ID;
577 VarOffset = DRIVER_OPTION_ORDER_VAR_OFFSET;
578 break;
579 }
580 ASSERT (OptionOrder != NULL);
581
582 OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();
583 ASSERT (OptionsOpCodeHandle != NULL);
584
585 NewMenuEntry = NULL;
586 for (OptionIndex = 0; (OptionOrder[OptionIndex] != 0 && OptionIndex < MAX_MENU_NUMBER); OptionIndex++) {
587 BootOptionFound = FALSE;
588 for (Index = 0; Index < OptionMenu->MenuNumber; Index++) {
589 NewMenuEntry = BOpt_GetMenuEntry (OptionMenu, Index);
590 NewLoadContext = (BM_LOAD_CONTEXT *) NewMenuEntry->VariableContext;
591 if ((UINT32) (NewMenuEntry->OptionNumber + 1) == OptionOrder[OptionIndex]) {
592 BootOptionFound = TRUE;
593 break;
594 }
595 }
596 if (BootOptionFound) {
597 HiiCreateOneOfOptionOpCode (
598 OptionsOpCodeHandle,
599 NewMenuEntry->DisplayStringToken,
600 0,
601 EFI_IFR_TYPE_NUM_SIZE_32,
602 OptionOrder[OptionIndex]
603 );
604 }
605 }
606
607 if (OptionMenu->MenuNumber > 0) {
608 HiiCreateOrderedListOpCode (
609 mStartOpCodeHandle, // Container for dynamic created opcodes
610 QuestionId, // Question ID
611 VARSTORE_ID_BOOT_MAINT, // VarStore ID
612 VarOffset, // Offset in Buffer Storage
613 STRING_TOKEN (STR_CHANGE_ORDER), // Question prompt text
614 STRING_TOKEN (STR_CHANGE_ORDER), // Question help text
615 0, // Question flag
616 0, // Ordered list flag, e.g. EFI_IFR_UNIQUE_SET
617 EFI_IFR_TYPE_NUM_SIZE_32, // Data type of Question value
618 100, // Maximum container
619 OptionsOpCodeHandle, // Option Opcode list
620 NULL // Default Opcode is NULL
621 );
622 }
623
624 HiiFreeOpCodeHandle (OptionsOpCodeHandle);
625
626 UpdatePageEnd (CallbackData);
627
628 }
629
630 /**
631 Create the dynamic page to allow user to set
632 the "BootNext" value.
633
634 @param CallbackData The BMM context data.
635
636 **/
637 VOID
638 UpdateBootNextPage (
639 IN BMM_CALLBACK_DATA *CallbackData
640 )
641 {
642 BM_MENU_ENTRY *NewMenuEntry;
643 BM_LOAD_CONTEXT *NewLoadContext;
644 UINTN NumberOfOptions;
645 UINT16 Index;
646 VOID *OptionsOpCodeHandle;
647
648 NumberOfOptions = BootOptionMenu.MenuNumber;
649 CallbackData->BmmAskSaveOrNot = TRUE;
650
651 UpdatePageStart (CallbackData);
652 CreateMenuStringToken (CallbackData, CallbackData->BmmHiiHandle, &BootOptionMenu);
653
654 if (NumberOfOptions > 0) {
655 OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();
656 ASSERT (OptionsOpCodeHandle != NULL);
657
658 CallbackData->BmmFakeNvData.BootNext = (UINT16) (BootOptionMenu.MenuNumber);
659
660 for (Index = 0; Index < BootOptionMenu.MenuNumber; Index++) {
661 NewMenuEntry = BOpt_GetMenuEntry (&BootOptionMenu, Index);
662 NewLoadContext = (BM_LOAD_CONTEXT *) NewMenuEntry->VariableContext;
663
664 if (NewLoadContext->IsBootNext) {
665 HiiCreateOneOfOptionOpCode (
666 OptionsOpCodeHandle,
667 NewMenuEntry->DisplayStringToken,
668 EFI_IFR_OPTION_DEFAULT,
669 EFI_IFR_TYPE_NUM_SIZE_16,
670 Index
671 );
672 CallbackData->BmmFakeNvData.BootNext = Index;
673 } else {
674 HiiCreateOneOfOptionOpCode (
675 OptionsOpCodeHandle,
676 NewMenuEntry->DisplayStringToken,
677 0,
678 EFI_IFR_TYPE_NUM_SIZE_16,
679 Index
680 );
681 }
682 }
683
684 if (CallbackData->BmmFakeNvData.BootNext == Index) {
685 HiiCreateOneOfOptionOpCode (
686 OptionsOpCodeHandle,
687 STRING_TOKEN (STR_NONE),
688 EFI_IFR_OPTION_DEFAULT,
689 EFI_IFR_TYPE_NUM_SIZE_16,
690 Index
691 );
692 } else {
693 HiiCreateOneOfOptionOpCode (
694 OptionsOpCodeHandle,
695 STRING_TOKEN (STR_NONE),
696 0,
697 EFI_IFR_TYPE_NUM_SIZE_16,
698 Index
699 );
700 }
701
702 HiiCreateOneOfOpCode (
703 mStartOpCodeHandle,
704 (EFI_QUESTION_ID) BOOT_NEXT_QUESTION_ID,
705 VARSTORE_ID_BOOT_MAINT,
706 BOOT_NEXT_VAR_OFFSET,
707 STRING_TOKEN (STR_BOOT_NEXT),
708 STRING_TOKEN (STR_BOOT_NEXT_HELP),
709 0,
710 EFI_IFR_NUMERIC_SIZE_2,
711 OptionsOpCodeHandle,
712 NULL
713 );
714
715 HiiFreeOpCodeHandle (OptionsOpCodeHandle);
716 }
717
718 UpdatePageEnd (CallbackData);
719 }
720
721 /**
722 Create the dynamic page to allow user to set the "TimeOut" value.
723
724 @param CallbackData The BMM context data.
725
726 **/
727 VOID
728 UpdateTimeOutPage (
729 IN BMM_CALLBACK_DATA *CallbackData
730 )
731 {
732 UINT16 BootTimeOut;
733 VOID *DefaultOpCodeHandle;
734
735 CallbackData->BmmAskSaveOrNot = TRUE;
736
737 UpdatePageStart (CallbackData);
738
739 BootTimeOut = PcdGet16 (PcdPlatformBootTimeOut);
740
741 DefaultOpCodeHandle = HiiAllocateOpCodeHandle ();
742 ASSERT (DefaultOpCodeHandle != NULL);
743 HiiCreateDefaultOpCode (DefaultOpCodeHandle, EFI_HII_DEFAULT_CLASS_STANDARD, EFI_IFR_TYPE_NUM_SIZE_16, BootTimeOut);
744
745 HiiCreateNumericOpCode (
746 mStartOpCodeHandle,
747 (EFI_QUESTION_ID) BOOT_TIME_OUT_QUESTION_ID,
748 VARSTORE_ID_BOOT_MAINT,
749 BOOT_TIME_OUT_VAR_OFFSET,
750 STRING_TOKEN (STR_NUM_AUTO_BOOT),
751 STRING_TOKEN (STR_HLP_AUTO_BOOT),
752 0,
753 EFI_IFR_NUMERIC_SIZE_2 | EFI_IFR_DISPLAY_UINT_DEC,
754 0,
755 65535,
756 0,
757 DefaultOpCodeHandle
758 );
759
760 HiiFreeOpCodeHandle (DefaultOpCodeHandle);
761
762 CallbackData->BmmFakeNvData.BootTimeOut = BootTimeOut;
763
764 UpdatePageEnd (CallbackData);
765 }
766
767
768 /**
769 Refresh the text mode page.
770
771 @param CallbackData The BMM context data.
772
773 **/
774 VOID
775 UpdateConModePage (
776 IN BMM_CALLBACK_DATA *CallbackData
777 )
778 {
779 UINTN Mode;
780 UINTN Index;
781 UINTN Col;
782 UINTN Row;
783 CHAR16 ModeString[50];
784 CHAR16 *PStr;
785 UINTN MaxMode;
786 UINTN ValidMode;
787 EFI_STRING_ID *ModeToken;
788 EFI_STATUS Status;
789 VOID *OptionsOpCodeHandle;
790 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ConOut;
791
792 ConOut = gST->ConOut;
793 Index = 0;
794 ValidMode = 0;
795 MaxMode = (UINTN) (ConOut->Mode->MaxMode);
796
797 CallbackData->BmmAskSaveOrNot = TRUE;
798
799 UpdatePageStart (CallbackData);
800
801 //
802 // Check valid mode
803 //
804 for (Mode = 0; Mode < MaxMode; Mode++) {
805 Status = ConOut->QueryMode (ConOut, Mode, &Col, &Row);
806 if (EFI_ERROR (Status)) {
807 continue;
808 }
809 ValidMode++;
810 }
811
812 if (ValidMode == 0) {
813 return;
814 }
815
816 OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();
817 ASSERT (OptionsOpCodeHandle != NULL);
818
819 ModeToken = AllocateZeroPool (sizeof (EFI_STRING_ID) * ValidMode);
820 ASSERT(ModeToken != NULL);
821
822 //
823 // Determin which mode should be the first entry in menu
824 //
825 GetConsoleOutMode (CallbackData);
826
827 //
828 // Build text mode options
829 //
830 for (Mode = 0; Mode < MaxMode; Mode++) {
831 Status = ConOut->QueryMode (ConOut, Mode, &Col, &Row);
832 if (EFI_ERROR (Status)) {
833 continue;
834 }
835
836 //
837 // Build mode string Column x Row
838 //
839 UnicodeValueToString (ModeString, 0, Col, 0);
840 PStr = &ModeString[0];
841 StrnCatS (PStr, sizeof (ModeString) / sizeof (ModeString[0]), L" x ", StrLen(L" x ") + 1);
842 PStr = PStr + StrLen (PStr);
843 UnicodeValueToString (PStr , 0, Row, 0);
844
845 ModeToken[Index] = HiiSetString (CallbackData->BmmHiiHandle, 0, ModeString, NULL);
846
847 if (Mode == CallbackData->BmmFakeNvData.ConsoleOutMode) {
848 HiiCreateOneOfOptionOpCode (
849 OptionsOpCodeHandle,
850 ModeToken[Index],
851 EFI_IFR_OPTION_DEFAULT,
852 EFI_IFR_TYPE_NUM_SIZE_16,
853 (UINT16) Mode
854 );
855 } else {
856 HiiCreateOneOfOptionOpCode (
857 OptionsOpCodeHandle,
858 ModeToken[Index],
859 0,
860 EFI_IFR_TYPE_NUM_SIZE_16,
861 (UINT16) Mode
862 );
863 }
864 Index++;
865 }
866
867 HiiCreateOneOfOpCode (
868 mStartOpCodeHandle,
869 (EFI_QUESTION_ID) CON_MODE_QUESTION_ID,
870 VARSTORE_ID_BOOT_MAINT,
871 CON_MODE_VAR_OFFSET,
872 STRING_TOKEN (STR_CON_MODE_SETUP),
873 STRING_TOKEN (STR_CON_MODE_SETUP),
874 EFI_IFR_FLAG_RESET_REQUIRED,
875 EFI_IFR_NUMERIC_SIZE_2,
876 OptionsOpCodeHandle,
877 NULL
878 );
879
880 HiiFreeOpCodeHandle (OptionsOpCodeHandle);
881 FreePool (ModeToken);
882
883 UpdatePageEnd (CallbackData);
884 }
885
886 /**
887 Create the dynamic page which allows user to set the property such as Baud Rate, Data Bits,
888 Parity, Stop Bits, Terminal Type.
889
890 @param CallbackData The BMM context data.
891
892 **/
893 VOID
894 UpdateTerminalPage (
895 IN BMM_CALLBACK_DATA *CallbackData
896 )
897 {
898 UINT8 Index;
899 UINT8 CheckFlags;
900 BM_MENU_ENTRY *NewMenuEntry;
901 BM_TERMINAL_CONTEXT *NewTerminalContext;
902 VOID *OptionsOpCodeHandle;
903
904 CallbackData->BmmAskSaveOrNot = TRUE;
905
906 UpdatePageStart (CallbackData);
907
908 NewMenuEntry = BOpt_GetMenuEntry (
909 &TerminalMenu,
910 CallbackData->CurrentTerminal
911 );
912
913 if (NewMenuEntry == NULL) {
914 return ;
915 }
916
917 NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext;
918
919 OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();
920 ASSERT (OptionsOpCodeHandle != NULL);
921
922 for (Index = 0; Index < sizeof (BaudRateList) / sizeof (BaudRateList [0]); Index++) {
923 CheckFlags = 0;
924 if (NewTerminalContext->BaudRate == (UINT64) (BaudRateList[Index].Value)) {
925 CheckFlags |= EFI_IFR_OPTION_DEFAULT;
926 NewTerminalContext->BaudRateIndex = Index;
927 CallbackData->BmmFakeNvData.COMBaudRate = NewTerminalContext->BaudRateIndex;
928 }
929
930 HiiCreateOneOfOptionOpCode (
931 OptionsOpCodeHandle,
932 BaudRateList[Index].StringToken,
933 CheckFlags,
934 EFI_IFR_TYPE_NUM_SIZE_8,
935 Index
936 );
937 }
938
939 HiiCreateOneOfOpCode (
940 mStartOpCodeHandle,
941 (EFI_QUESTION_ID) COM_BAUD_RATE_QUESTION_ID,
942 VARSTORE_ID_BOOT_MAINT,
943 COM_BAUD_RATE_VAR_OFFSET,
944 STRING_TOKEN (STR_COM_BAUD_RATE),
945 STRING_TOKEN (STR_COM_BAUD_RATE),
946 0,
947 EFI_IFR_NUMERIC_SIZE_1,
948 OptionsOpCodeHandle,
949 NULL
950 );
951
952 HiiFreeOpCodeHandle (OptionsOpCodeHandle);
953 OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();
954 ASSERT (OptionsOpCodeHandle != NULL);
955
956 for (Index = 0; Index < sizeof (DataBitsList) / sizeof (DataBitsList[0]); Index++) {
957 CheckFlags = 0;
958
959 if (NewTerminalContext->DataBits == DataBitsList[Index].Value) {
960 NewTerminalContext->DataBitsIndex = Index;
961 CallbackData->BmmFakeNvData.COMDataRate = NewTerminalContext->DataBitsIndex;
962 CheckFlags |= EFI_IFR_OPTION_DEFAULT;
963 }
964
965 HiiCreateOneOfOptionOpCode (
966 OptionsOpCodeHandle,
967 DataBitsList[Index].StringToken,
968 CheckFlags,
969 EFI_IFR_TYPE_NUM_SIZE_8,
970 Index
971 );
972 }
973
974 HiiCreateOneOfOpCode (
975 mStartOpCodeHandle,
976 (EFI_QUESTION_ID) COM_DATA_RATE_QUESTION_ID,
977 VARSTORE_ID_BOOT_MAINT,
978 COM_DATA_RATE_VAR_OFFSET,
979 STRING_TOKEN (STR_COM_DATA_BITS),
980 STRING_TOKEN (STR_COM_DATA_BITS),
981 0,
982 EFI_IFR_NUMERIC_SIZE_1,
983 OptionsOpCodeHandle,
984 NULL
985 );
986
987 HiiFreeOpCodeHandle (OptionsOpCodeHandle);
988 OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();
989 ASSERT (OptionsOpCodeHandle != NULL);
990
991 for (Index = 0; Index < sizeof (ParityList) / sizeof (ParityList[0]); Index++) {
992 CheckFlags = 0;
993 if (NewTerminalContext->Parity == ParityList[Index].Value) {
994 CheckFlags |= EFI_IFR_OPTION_DEFAULT;
995 NewTerminalContext->ParityIndex = (UINT8) Index;
996 CallbackData->BmmFakeNvData.COMParity = NewTerminalContext->ParityIndex;
997 }
998
999 HiiCreateOneOfOptionOpCode (
1000 OptionsOpCodeHandle,
1001 ParityList[Index].StringToken,
1002 CheckFlags,
1003 EFI_IFR_TYPE_NUM_SIZE_8,
1004 Index
1005 );
1006 }
1007
1008 HiiCreateOneOfOpCode (
1009 mStartOpCodeHandle,
1010 (EFI_QUESTION_ID) COM_PARITY_QUESTION_ID,
1011 VARSTORE_ID_BOOT_MAINT,
1012 COM_PARITY_VAR_OFFSET,
1013 STRING_TOKEN (STR_COM_PARITY),
1014 STRING_TOKEN (STR_COM_PARITY),
1015 0,
1016 EFI_IFR_NUMERIC_SIZE_1,
1017 OptionsOpCodeHandle,
1018 NULL
1019 );
1020
1021 HiiFreeOpCodeHandle (OptionsOpCodeHandle);
1022 OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();
1023 ASSERT (OptionsOpCodeHandle != NULL);
1024
1025 for (Index = 0; Index < sizeof (StopBitsList) / sizeof (StopBitsList[0]); Index++) {
1026 CheckFlags = 0;
1027 if (NewTerminalContext->StopBits == StopBitsList[Index].Value) {
1028 CheckFlags |= EFI_IFR_OPTION_DEFAULT;
1029 NewTerminalContext->StopBitsIndex = (UINT8) Index;
1030 CallbackData->BmmFakeNvData.COMStopBits = NewTerminalContext->StopBitsIndex;
1031 }
1032
1033 HiiCreateOneOfOptionOpCode (
1034 OptionsOpCodeHandle,
1035 StopBitsList[Index].StringToken,
1036 CheckFlags,
1037 EFI_IFR_TYPE_NUM_SIZE_8,
1038 Index
1039 );
1040 }
1041
1042 HiiCreateOneOfOpCode (
1043 mStartOpCodeHandle,
1044 (EFI_QUESTION_ID) COM_STOP_BITS_QUESTION_ID,
1045 VARSTORE_ID_BOOT_MAINT,
1046 COM_STOP_BITS_VAR_OFFSET,
1047 STRING_TOKEN (STR_COM_STOP_BITS),
1048 STRING_TOKEN (STR_COM_STOP_BITS),
1049 0,
1050 EFI_IFR_NUMERIC_SIZE_1,
1051 OptionsOpCodeHandle,
1052 NULL
1053 );
1054
1055 HiiFreeOpCodeHandle (OptionsOpCodeHandle);
1056 OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();
1057 ASSERT (OptionsOpCodeHandle != NULL);
1058
1059 for (Index = 0; Index < 4; Index++) {
1060 CheckFlags = 0;
1061 if (NewTerminalContext->TerminalType == Index) {
1062 CheckFlags |= EFI_IFR_OPTION_DEFAULT;
1063 CallbackData->BmmFakeNvData.COMTerminalType = NewTerminalContext->TerminalType;
1064 }
1065
1066 HiiCreateOneOfOptionOpCode (
1067 OptionsOpCodeHandle,
1068 (EFI_STRING_ID) TerminalType[Index],
1069 CheckFlags,
1070 EFI_IFR_TYPE_NUM_SIZE_8,
1071 Index
1072 );
1073 }
1074
1075 HiiCreateOneOfOpCode (
1076 mStartOpCodeHandle,
1077 (EFI_QUESTION_ID) COM_TERMINAL_QUESTION_ID,
1078 VARSTORE_ID_BOOT_MAINT,
1079 COM_TERMINAL_VAR_OFFSET,
1080 STRING_TOKEN (STR_COM_TERMI_TYPE),
1081 STRING_TOKEN (STR_COM_TERMI_TYPE),
1082 0,
1083 EFI_IFR_NUMERIC_SIZE_1,
1084 OptionsOpCodeHandle,
1085 NULL
1086 );
1087
1088 HiiFreeOpCodeHandle (OptionsOpCodeHandle);
1089
1090 UpdatePageEnd (CallbackData);
1091 }
1092
1093 /**
1094 Dispatch the correct update page function to call based on
1095 the UpdatePageId.
1096
1097 @param UpdatePageId The form ID.
1098 @param CallbackData The BMM context data.
1099
1100 **/
1101 VOID
1102 UpdatePageBody (
1103 IN UINT16 UpdatePageId,
1104 IN BMM_CALLBACK_DATA *CallbackData
1105 )
1106 {
1107 CleanUpPage (UpdatePageId, CallbackData);
1108 switch (UpdatePageId) {
1109 case FORM_CON_IN_ID:
1110 UpdateConsolePage (UpdatePageId, &ConsoleInpMenu, CallbackData);
1111 break;
1112
1113 case FORM_CON_OUT_ID:
1114 UpdateConsolePage (UpdatePageId, &ConsoleOutMenu, CallbackData);
1115 break;
1116
1117 case FORM_CON_ERR_ID:
1118 UpdateConsolePage (UpdatePageId, &ConsoleErrMenu, CallbackData);
1119 break;
1120
1121 case FORM_BOOT_CHG_ID:
1122 UpdateOrderPage (UpdatePageId, &BootOptionMenu, CallbackData);
1123 break;
1124
1125 case FORM_DRV_CHG_ID:
1126 UpdateOrderPage (UpdatePageId, &DriverOptionMenu, CallbackData);
1127 break;
1128
1129 default:
1130 break;
1131 }
1132 }
1133
1134 /**
1135 Dispatch the display to the next page based on NewPageId.
1136
1137 @param Private The BMM context data.
1138 @param NewPageId The original page ID.
1139
1140 **/
1141 VOID
1142 UpdatePageId (
1143 BMM_CALLBACK_DATA *Private,
1144 UINT16 NewPageId
1145 )
1146 {
1147 if ((NewPageId < FILE_OPTION_OFFSET) && (NewPageId >= HANDLE_OPTION_OFFSET)) {
1148 //
1149 // If we select a handle to add driver option, advance to the add handle description page.
1150 //
1151 NewPageId = FORM_DRV_ADD_HANDLE_DESC_ID;
1152 } else if ((NewPageId == KEY_VALUE_SAVE_AND_EXIT) || (NewPageId == KEY_VALUE_NO_SAVE_AND_EXIT)) {
1153 //
1154 // Return to main page after "Save Changes" or "Discard Changes".
1155 //
1156 NewPageId = FORM_MAIN_ID;
1157 } else if ((NewPageId >= TERMINAL_OPTION_OFFSET) && (NewPageId < CONSOLE_OPTION_OFFSET)) {
1158 NewPageId = FORM_CON_COM_SETUP_ID;
1159 }
1160
1161 if ((NewPageId > 0) && (NewPageId < MAXIMUM_FORM_ID)) {
1162 Private->BmmPreviousPageId = Private->BmmCurrentPageId;
1163 Private->BmmCurrentPageId = NewPageId;
1164 }
1165 }