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 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017
|
/** @file
Provide boot option support for Application "BootMaint"
Include file system navigation, system handle selection
Boot option manipulation
Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include "BootMaintenanceManager.h"
///
/// Define the maximum characters that will be accepted.
///
#define MAX_CHAR 480
/**
Check whether a reset is needed, if reset is needed, Popup a menu to notice user.
**/
VOID
BmmSetupResetReminder (
VOID
)
{
EFI_INPUT_KEY Key;
CHAR16 *StringBuffer1;
CHAR16 *StringBuffer2;
EFI_STATUS Status;
EDKII_FORM_BROWSER_EXTENSION2_PROTOCOL *FormBrowserEx2;
//
// Use BrowserEx2 protocol to check whether reset is required.
//
Status = gBS->LocateProtocol (&gEdkiiFormBrowserEx2ProtocolGuid, NULL, (VOID **)&FormBrowserEx2);
//
// check any reset required change is applied? if yes, reset system
//
if (!EFI_ERROR (Status) && FormBrowserEx2->IsResetRequired ()) {
StringBuffer1 = AllocateZeroPool (MAX_CHAR * sizeof (CHAR16));
ASSERT (StringBuffer1 != NULL);
StringBuffer2 = AllocateZeroPool (MAX_CHAR * sizeof (CHAR16));
ASSERT (StringBuffer2 != NULL);
StrCpyS (StringBuffer1, MAX_CHAR, L"Configuration changed. Reset to apply it Now.");
StrCpyS (StringBuffer2, MAX_CHAR, L"Press ENTER to reset");
//
// Popup a menu to notice user
//
do {
CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, StringBuffer1, StringBuffer2, NULL);
} while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
FreePool (StringBuffer1);
FreePool (StringBuffer2);
gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL);
}
}
/**
Create a menu entry by given menu type.
@param MenuType The Menu type to be created.
@retval NULL If failed to create the menu.
@return the new menu entry.
**/
BM_MENU_ENTRY *
BOpt_CreateMenuEntry (
UINTN MenuType
)
{
BM_MENU_ENTRY *MenuEntry;
UINTN ContextSize;
//
// Get context size according to menu type
//
switch (MenuType) {
case BM_LOAD_CONTEXT_SELECT:
ContextSize = sizeof (BM_LOAD_CONTEXT);
break;
case BM_FILE_CONTEXT_SELECT:
ContextSize = sizeof (BM_FILE_CONTEXT);
break;
case BM_CONSOLE_CONTEXT_SELECT:
ContextSize = sizeof (BM_CONSOLE_CONTEXT);
break;
case BM_TERMINAL_CONTEXT_SELECT:
ContextSize = sizeof (BM_TERMINAL_CONTEXT);
break;
case BM_HANDLE_CONTEXT_SELECT:
ContextSize = sizeof (BM_HANDLE_CONTEXT);
break;
default:
ContextSize = 0;
break;
}
if (ContextSize == 0) {
return NULL;
}
//
// Create new menu entry
//
MenuEntry = AllocateZeroPool (sizeof (BM_MENU_ENTRY));
if (MenuEntry == NULL) {
return NULL;
}
MenuEntry->VariableContext = AllocateZeroPool (ContextSize);
if (MenuEntry->VariableContext == NULL) {
FreePool (MenuEntry);
return NULL;
}
MenuEntry->Signature = BM_MENU_ENTRY_SIGNATURE;
MenuEntry->ContextSelection = MenuType;
return MenuEntry;
}
/**
Free up all resource allocated for a BM_MENU_ENTRY.
@param MenuEntry A pointer to BM_MENU_ENTRY.
**/
VOID
BOpt_DestroyMenuEntry (
BM_MENU_ENTRY *MenuEntry
)
{
BM_LOAD_CONTEXT *LoadContext;
BM_FILE_CONTEXT *FileContext;
BM_CONSOLE_CONTEXT *ConsoleContext;
BM_TERMINAL_CONTEXT *TerminalContext;
BM_HANDLE_CONTEXT *HandleContext;
//
// Select by the type in Menu entry for current context type
//
switch (MenuEntry->ContextSelection) {
case BM_LOAD_CONTEXT_SELECT:
LoadContext = (BM_LOAD_CONTEXT *)MenuEntry->VariableContext;
FreePool (LoadContext->FilePathList);
if (LoadContext->OptionalData != NULL) {
FreePool (LoadContext->OptionalData);
}
FreePool (LoadContext);
break;
case BM_FILE_CONTEXT_SELECT:
FileContext = (BM_FILE_CONTEXT *)MenuEntry->VariableContext;
if (!FileContext->IsRoot) {
FreePool (FileContext->DevicePath);
} else {
if (FileContext->FHandle != NULL) {
FileContext->FHandle->Close (FileContext->FHandle);
}
}
if (FileContext->FileName != NULL) {
FreePool (FileContext->FileName);
}
if (FileContext->Info != NULL) {
FreePool (FileContext->Info);
}
FreePool (FileContext);
break;
case BM_CONSOLE_CONTEXT_SELECT:
ConsoleContext = (BM_CONSOLE_CONTEXT *)MenuEntry->VariableContext;
FreePool (ConsoleContext->DevicePath);
FreePool (ConsoleContext);
break;
case BM_TERMINAL_CONTEXT_SELECT:
TerminalContext = (BM_TERMINAL_CONTEXT *)MenuEntry->VariableContext;
FreePool (TerminalContext->DevicePath);
FreePool (TerminalContext);
break;
case BM_HANDLE_CONTEXT_SELECT:
HandleContext = (BM_HANDLE_CONTEXT *)MenuEntry->VariableContext;
FreePool (HandleContext);
break;
default:
break;
}
FreePool (MenuEntry->DisplayString);
if (MenuEntry->HelpString != NULL) {
FreePool (MenuEntry->HelpString);
}
FreePool (MenuEntry);
}
/**
Get the Menu Entry from the list in Menu Entry List.
If MenuNumber is great or equal to the number of Menu
Entry in the list, then ASSERT.
@param MenuOption The Menu Entry List to read the menu entry.
@param MenuNumber The index of Menu Entry.
@return The Menu Entry.
**/
BM_MENU_ENTRY *
BOpt_GetMenuEntry (
BM_MENU_OPTION *MenuOption,
UINTN MenuNumber
)
{
BM_MENU_ENTRY *NewMenuEntry;
UINTN Index;
LIST_ENTRY *List;
ASSERT (MenuNumber < MenuOption->MenuNumber);
List = MenuOption->Head.ForwardLink;
for (Index = 0; Index < MenuNumber; Index++) {
List = List->ForwardLink;
}
NewMenuEntry = CR (List, BM_MENU_ENTRY, Link, BM_MENU_ENTRY_SIGNATURE);
return NewMenuEntry;
}
/**
Free resources allocated in Allocate Rountine.
@param FreeMenu Menu to be freed
**/
VOID
BOpt_FreeMenu (
BM_MENU_OPTION *FreeMenu
)
{
BM_MENU_ENTRY *MenuEntry;
while (!IsListEmpty (&FreeMenu->Head)) {
MenuEntry = CR (
FreeMenu->Head.ForwardLink,
BM_MENU_ENTRY,
Link,
BM_MENU_ENTRY_SIGNATURE
);
RemoveEntryList (&MenuEntry->Link);
BOpt_DestroyMenuEntry (MenuEntry);
}
FreeMenu->MenuNumber = 0;
}
/**
Build the BootOptionMenu according to BootOrder Variable.
This Routine will access the Boot#### to get EFI_LOAD_OPTION.
@param CallbackData The BMM context data.
@return EFI_NOT_FOUND Fail to find "BootOrder" variable.
@return EFI_SUCCESS Success build boot option menu.
**/
EFI_STATUS
BOpt_GetBootOptions (
IN BMM_CALLBACK_DATA *CallbackData
)
{
UINTN Index;
UINT16 BootString[10];
UINT8 *LoadOptionFromVar;
UINTN BootOptionSize;
BOOLEAN BootNextFlag;
UINT16 *BootOrderList;
UINTN BootOrderListSize;
UINT16 *BootNext;
UINTN BootNextSize;
BM_MENU_ENTRY *NewMenuEntry;
BM_LOAD_CONTEXT *NewLoadContext;
UINT8 *LoadOptionPtr;
UINTN StringSize;
UINTN OptionalDataSize;
UINT8 *LoadOptionEnd;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
UINTN MenuCount;
UINT8 *Ptr;
EFI_BOOT_MANAGER_LOAD_OPTION *BootOption;
UINTN BootOptionCount;
MenuCount = 0;
BootOrderListSize = 0;
BootNextSize = 0;
BootOrderList = NULL;
BootNext = NULL;
LoadOptionFromVar = NULL;
BOpt_FreeMenu (&BootOptionMenu);
InitializeListHead (&BootOptionMenu.Head);
//
// Get the BootOrder from the Var
//
GetEfiGlobalVariable2 (L"BootOrder", (VOID **)&BootOrderList, &BootOrderListSize);
if (BootOrderList == NULL) {
return EFI_NOT_FOUND;
}
//
// Get the BootNext from the Var
//
GetEfiGlobalVariable2 (L"BootNext", (VOID **)&BootNext, &BootNextSize);
if (BootNext != NULL) {
if (BootNextSize != sizeof (UINT16)) {
FreePool (BootNext);
BootNext = NULL;
}
}
BootOption = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot);
for (Index = 0; Index < BootOrderListSize / sizeof (UINT16); Index++) {
//
// Don't display the hidden/inactive boot option
//
if (((BootOption[Index].Attributes & LOAD_OPTION_HIDDEN) != 0) || ((BootOption[Index].Attributes & LOAD_OPTION_ACTIVE) == 0)) {
continue;
}
UnicodeSPrint (BootString, sizeof (BootString), L"Boot%04x", BootOrderList[Index]);
//
// Get all loadoptions from the VAR
//
GetEfiGlobalVariable2 (BootString, (VOID **)&LoadOptionFromVar, &BootOptionSize);
if (LoadOptionFromVar == NULL) {
continue;
}
if (BootNext != NULL) {
BootNextFlag = (BOOLEAN)(*BootNext == BootOrderList[Index]);
} else {
BootNextFlag = FALSE;
}
NewMenuEntry = BOpt_CreateMenuEntry (BM_LOAD_CONTEXT_SELECT);
ASSERT (NULL != NewMenuEntry);
NewLoadContext = (BM_LOAD_CONTEXT *)NewMenuEntry->VariableContext;
LoadOptionPtr = LoadOptionFromVar;
LoadOptionEnd = LoadOptionFromVar + BootOptionSize;
NewMenuEntry->OptionNumber = BootOrderList[Index];
NewLoadContext->Deleted = FALSE;
NewLoadContext->IsBootNext = BootNextFlag;
//
// Is a Legacy Device?
//
Ptr = (UINT8 *)LoadOptionFromVar;
//
// Attribute = *(UINT32 *)Ptr;
//
Ptr += sizeof (UINT32);
//
// FilePathSize = *(UINT16 *)Ptr;
//
Ptr += sizeof (UINT16);
//
// Description = (CHAR16 *)Ptr;
//
Ptr += StrSize ((CHAR16 *)Ptr);
//
// Now Ptr point to Device Path
//
DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)Ptr;
if ((BBS_DEVICE_PATH == DevicePath->Type) && (BBS_BBS_DP == DevicePath->SubType)) {
NewLoadContext->IsLegacy = TRUE;
} else {
NewLoadContext->IsLegacy = FALSE;
}
//
// LoadOption is a pointer type of UINT8
// for easy use with following LOAD_OPTION
// embedded in this struct
//
NewLoadContext->Attributes = *(UINT32 *)LoadOptionPtr;
LoadOptionPtr += sizeof (UINT32);
NewLoadContext->FilePathListLength = *(UINT16 *)LoadOptionPtr;
LoadOptionPtr += sizeof (UINT16);
StringSize = StrSize ((UINT16 *)LoadOptionPtr);
NewLoadContext->Description = AllocateZeroPool (StrSize ((UINT16 *)LoadOptionPtr));
ASSERT (NewLoadContext->Description != NULL);
StrCpyS (NewLoadContext->Description, StrSize ((UINT16 *)LoadOptionPtr) / sizeof (UINT16), (UINT16 *)LoadOptionPtr);
ASSERT (NewLoadContext->Description != NULL);
NewMenuEntry->DisplayString = NewLoadContext->Description;
NewMenuEntry->DisplayStringToken = HiiSetString (CallbackData->BmmHiiHandle, 0, NewMenuEntry->DisplayString, NULL);
LoadOptionPtr += StringSize;
NewLoadContext->FilePathList = AllocateZeroPool (NewLoadContext->FilePathListLength);
ASSERT (NewLoadContext->FilePathList != NULL);
CopyMem (
NewLoadContext->FilePathList,
(EFI_DEVICE_PATH_PROTOCOL *)LoadOptionPtr,
NewLoadContext->FilePathListLength
);
NewMenuEntry->HelpString = UiDevicePathToStr (NewLoadContext->FilePathList);
NewMenuEntry->HelpStringToken = HiiSetString (CallbackData->BmmHiiHandle, 0, NewMenuEntry->HelpString, NULL);
LoadOptionPtr += NewLoadContext->FilePathListLength;
if (LoadOptionPtr < LoadOptionEnd) {
OptionalDataSize = BootOptionSize -
sizeof (UINT32) -
sizeof (UINT16) -
StringSize -
NewLoadContext->FilePathListLength;
NewLoadContext->OptionalData = AllocateZeroPool (OptionalDataSize);
ASSERT (NewLoadContext->OptionalData != NULL);
CopyMem (
NewLoadContext->OptionalData,
LoadOptionPtr,
OptionalDataSize
);
}
InsertTailList (&BootOptionMenu.Head, &NewMenuEntry->Link);
MenuCount++;
FreePool (LoadOptionFromVar);
}
EfiBootManagerFreeLoadOptions (BootOption, BootOptionCount);
if (BootNext != NULL) {
FreePool (BootNext);
}
if (BootOrderList != NULL) {
FreePool (BootOrderList);
}
BootOptionMenu.MenuNumber = MenuCount;
return EFI_SUCCESS;
}
/**
Find drivers that will be added as Driver#### variables from handles
in current system environment
All valid handles in the system except those consume SimpleFs, LoadFile
are stored in DriverMenu for future use.
@retval EFI_SUCCESS The function complets successfully.
@return Other value if failed to build the DriverMenu.
**/
EFI_STATUS
BOpt_FindDrivers (
VOID
)
{
UINTN NoDevicePathHandles;
EFI_HANDLE *DevicePathHandle;
UINTN Index;
EFI_STATUS Status;
BM_MENU_ENTRY *NewMenuEntry;
BM_HANDLE_CONTEXT *NewHandleContext;
EFI_HANDLE CurHandle;
UINTN OptionNumber;
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *SimpleFs;
EFI_LOAD_FILE_PROTOCOL *LoadFile;
SimpleFs = NULL;
LoadFile = NULL;
InitializeListHead (&DriverMenu.Head);
//
// At first, get all handles that support Device Path
// protocol which is the basic requirement for
// Driver####
//
Status = gBS->LocateHandleBuffer (
ByProtocol,
&gEfiDevicePathProtocolGuid,
NULL,
&NoDevicePathHandles,
&DevicePathHandle
);
if (EFI_ERROR (Status)) {
return Status;
}
OptionNumber = 0;
for (Index = 0; Index < NoDevicePathHandles; Index++) {
CurHandle = DevicePathHandle[Index];
Status = gBS->HandleProtocol (
CurHandle,
&gEfiSimpleFileSystemProtocolGuid,
(VOID **)&SimpleFs
);
if (Status == EFI_SUCCESS) {
continue;
}
Status = gBS->HandleProtocol (
CurHandle,
&gEfiLoadFileProtocolGuid,
(VOID **)&LoadFile
);
if (Status == EFI_SUCCESS) {
continue;
}
NewMenuEntry = BOpt_CreateMenuEntry (BM_HANDLE_CONTEXT_SELECT);
if (NULL == NewMenuEntry) {
FreePool (DevicePathHandle);
return EFI_OUT_OF_RESOURCES;
}
NewHandleContext = (BM_HANDLE_CONTEXT *)NewMenuEntry->VariableContext;
NewHandleContext->Handle = CurHandle;
NewHandleContext->DevicePath = DevicePathFromHandle (CurHandle);
NewMenuEntry->DisplayString = UiDevicePathToStr (NewHandleContext->DevicePath);
NewMenuEntry->DisplayStringToken = HiiSetString (mBmmCallbackInfo->BmmHiiHandle, 0, NewMenuEntry->DisplayString, NULL);
NewMenuEntry->HelpString = NULL;
NewMenuEntry->HelpStringToken = NewMenuEntry->DisplayStringToken;
NewMenuEntry->OptionNumber = OptionNumber;
OptionNumber++;
InsertTailList (&DriverMenu.Head, &NewMenuEntry->Link);
}
if (DevicePathHandle != NULL) {
FreePool (DevicePathHandle);
}
DriverMenu.MenuNumber = OptionNumber;
return EFI_SUCCESS;
}
/**
Get the Option Number that has not been allocated for use.
@param Type The type of Option.
@return The available Option Number.
**/
UINT16
BOpt_GetOptionNumber (
CHAR16 *Type
)
{
UINT16 *OrderList;
UINTN OrderListSize;
UINTN Index;
CHAR16 StrTemp[20];
UINT16 *OptionBuffer;
UINT16 OptionNumber;
UINTN OptionSize;
OrderListSize = 0;
OrderList = NULL;
OptionNumber = 0;
Index = 0;
UnicodeSPrint (StrTemp, sizeof (StrTemp), L"%sOrder", Type);
GetEfiGlobalVariable2 (StrTemp, (VOID **)&OrderList, &OrderListSize);
for (OptionNumber = 0; ; OptionNumber++) {
if (OrderList != NULL) {
for (Index = 0; Index < OrderListSize / sizeof (UINT16); Index++) {
if (OptionNumber == OrderList[Index]) {
break;
}
}
}
if (Index < OrderListSize / sizeof (UINT16)) {
//
// The OptionNumber occurs in the OrderList, continue to use next one
//
continue;
}
UnicodeSPrint (StrTemp, sizeof (StrTemp), L"%s%04x", Type, (UINTN)OptionNumber);
DEBUG ((DEBUG_ERROR, "Option = %s\n", StrTemp));
GetEfiGlobalVariable2 (StrTemp, (VOID **)&OptionBuffer, &OptionSize);
if (NULL == OptionBuffer) {
//
// The Boot[OptionNumber] / Driver[OptionNumber] NOT occurs, we found it
//
break;
}
}
return OptionNumber;
}
/**
Get the Option Number for Boot#### that does not used.
@return The available Option Number.
**/
UINT16
BOpt_GetBootOptionNumber (
VOID
)
{
return BOpt_GetOptionNumber (L"Boot");
}
/**
Get the Option Number for Driver#### that does not used.
@return The unused Option Number.
**/
UINT16
BOpt_GetDriverOptionNumber (
VOID
)
{
return BOpt_GetOptionNumber (L"Driver");
}
/**
Build up all DriverOptionMenu
@param CallbackData The BMM context data.
@retval EFI_SUCCESS The function completes successfully.
@retval EFI_OUT_OF_RESOURCES Not enough memory to compete the operation.
@retval EFI_NOT_FOUND Fail to get "DriverOrder" variable.
**/
EFI_STATUS
BOpt_GetDriverOptions (
IN BMM_CALLBACK_DATA *CallbackData
)
{
UINTN Index;
UINT16 DriverString[12];
UINT8 *LoadOptionFromVar;
UINTN DriverOptionSize;
UINT16 *DriverOrderList;
UINTN DriverOrderListSize;
BM_MENU_ENTRY *NewMenuEntry;
BM_LOAD_CONTEXT *NewLoadContext;
UINT8 *LoadOptionPtr;
UINTN StringSize;
UINTN OptionalDataSize;
UINT8 *LoadOptionEnd;
DriverOrderListSize = 0;
DriverOrderList = NULL;
DriverOptionSize = 0;
LoadOptionFromVar = NULL;
BOpt_FreeMenu (&DriverOptionMenu);
InitializeListHead (&DriverOptionMenu.Head);
//
// Get the DriverOrder from the Var
//
GetEfiGlobalVariable2 (L"DriverOrder", (VOID **)&DriverOrderList, &DriverOrderListSize);
if (DriverOrderList == NULL) {
return EFI_NOT_FOUND;
}
for (Index = 0; Index < DriverOrderListSize / sizeof (UINT16); Index++) {
UnicodeSPrint (
DriverString,
sizeof (DriverString),
L"Driver%04x",
DriverOrderList[Index]
);
//
// Get all loadoptions from the VAR
//
GetEfiGlobalVariable2 (DriverString, (VOID **)&LoadOptionFromVar, &DriverOptionSize);
if (LoadOptionFromVar == NULL) {
continue;
}
NewMenuEntry = BOpt_CreateMenuEntry (BM_LOAD_CONTEXT_SELECT);
if (NULL == NewMenuEntry) {
return EFI_OUT_OF_RESOURCES;
}
NewLoadContext = (BM_LOAD_CONTEXT *)NewMenuEntry->VariableContext;
LoadOptionPtr = LoadOptionFromVar;
LoadOptionEnd = LoadOptionFromVar + DriverOptionSize;
NewMenuEntry->OptionNumber = DriverOrderList[Index];
NewLoadContext->Deleted = FALSE;
NewLoadContext->IsLegacy = FALSE;
//
// LoadOption is a pointer type of UINT8
// for easy use with following LOAD_OPTION
// embedded in this struct
//
NewLoadContext->Attributes = *(UINT32 *)LoadOptionPtr;
LoadOptionPtr += sizeof (UINT32);
NewLoadContext->FilePathListLength = *(UINT16 *)LoadOptionPtr;
LoadOptionPtr += sizeof (UINT16);
StringSize = StrSize ((UINT16 *)LoadOptionPtr);
NewLoadContext->Description = AllocateZeroPool (StringSize);
ASSERT (NewLoadContext->Description != NULL);
CopyMem (
NewLoadContext->Description,
(UINT16 *)LoadOptionPtr,
StringSize
);
NewMenuEntry->DisplayString = NewLoadContext->Description;
NewMenuEntry->DisplayStringToken = HiiSetString (CallbackData->BmmHiiHandle, 0, NewMenuEntry->DisplayString, NULL);
LoadOptionPtr += StringSize;
NewLoadContext->FilePathList = AllocateZeroPool (NewLoadContext->FilePathListLength);
ASSERT (NewLoadContext->FilePathList != NULL);
CopyMem (
NewLoadContext->FilePathList,
(EFI_DEVICE_PATH_PROTOCOL *)LoadOptionPtr,
NewLoadContext->FilePathListLength
);
NewMenuEntry->HelpString = UiDevicePathToStr (NewLoadContext->FilePathList);
NewMenuEntry->HelpStringToken = HiiSetString (CallbackData->BmmHiiHandle, 0, NewMenuEntry->HelpString, NULL);
LoadOptionPtr += NewLoadContext->FilePathListLength;
if (LoadOptionPtr < LoadOptionEnd) {
OptionalDataSize = DriverOptionSize -
sizeof (UINT32) -
sizeof (UINT16) -
StringSize -
NewLoadContext->FilePathListLength;
NewLoadContext->OptionalData = AllocateZeroPool (OptionalDataSize);
ASSERT (NewLoadContext->OptionalData != NULL);
CopyMem (
NewLoadContext->OptionalData,
LoadOptionPtr,
OptionalDataSize
);
}
InsertTailList (&DriverOptionMenu.Head, &NewMenuEntry->Link);
FreePool (LoadOptionFromVar);
}
if (DriverOrderList != NULL) {
FreePool (DriverOrderList);
}
DriverOptionMenu.MenuNumber = Index;
return EFI_SUCCESS;
}
/**
Get option number according to Boot#### and BootOrder variable.
The value is saved as #### + 1.
@param CallbackData The BMM context data.
**/
VOID
GetBootOrder (
IN BMM_CALLBACK_DATA *CallbackData
)
{
BMM_FAKE_NV_DATA *BmmConfig;
UINT16 Index;
UINT16 OptionOrderIndex;
UINTN DeviceType;
BM_MENU_ENTRY *NewMenuEntry;
BM_LOAD_CONTEXT *NewLoadContext;
ASSERT (CallbackData != NULL);
DeviceType = (UINTN)-1;
BmmConfig = &CallbackData->BmmFakeNvData;
ZeroMem (BmmConfig->BootOptionOrder, sizeof (BmmConfig->BootOptionOrder));
for (Index = 0, OptionOrderIndex = 0; ((Index < BootOptionMenu.MenuNumber) &&
(OptionOrderIndex < (sizeof (BmmConfig->BootOptionOrder) / sizeof (BmmConfig->BootOptionOrder[0]))));
Index++)
{
NewMenuEntry = BOpt_GetMenuEntry (&BootOptionMenu, Index);
NewLoadContext = (BM_LOAD_CONTEXT *)NewMenuEntry->VariableContext;
if (NewLoadContext->IsLegacy) {
if (((BBS_BBS_DEVICE_PATH *)NewLoadContext->FilePathList)->DeviceType != DeviceType) {
DeviceType = ((BBS_BBS_DEVICE_PATH *)NewLoadContext->FilePathList)->DeviceType;
} else {
//
// Only show one legacy boot option for the same device type
// assuming the boot options are grouped by the device type
//
continue;
}
}
BmmConfig->BootOptionOrder[OptionOrderIndex++] = (UINT32)(NewMenuEntry->OptionNumber + 1);
}
}
/**
Get driver option order from globalc DriverOptionMenu.
@param CallbackData The BMM context data.
**/
VOID
GetDriverOrder (
IN BMM_CALLBACK_DATA *CallbackData
)
{
BMM_FAKE_NV_DATA *BmmConfig;
UINT16 Index;
UINT16 OptionOrderIndex;
UINTN DeviceType;
BM_MENU_ENTRY *NewMenuEntry;
BM_LOAD_CONTEXT *NewLoadContext;
ASSERT (CallbackData != NULL);
DeviceType = (UINTN)-1;
BmmConfig = &CallbackData->BmmFakeNvData;
ZeroMem (BmmConfig->DriverOptionOrder, sizeof (BmmConfig->DriverOptionOrder));
for (Index = 0, OptionOrderIndex = 0; ((Index < DriverOptionMenu.MenuNumber) &&
(OptionOrderIndex < (sizeof (BmmConfig->DriverOptionOrder) / sizeof (BmmConfig->DriverOptionOrder[0]))));
Index++)
{
NewMenuEntry = BOpt_GetMenuEntry (&DriverOptionMenu, Index);
NewLoadContext = (BM_LOAD_CONTEXT *)NewMenuEntry->VariableContext;
if (NewLoadContext->IsLegacy) {
if (((BBS_BBS_DEVICE_PATH *)NewLoadContext->FilePathList)->DeviceType != DeviceType) {
DeviceType = ((BBS_BBS_DEVICE_PATH *)NewLoadContext->FilePathList)->DeviceType;
} else {
//
// Only show one legacy boot option for the same device type
// assuming the boot options are grouped by the device type
//
continue;
}
}
BmmConfig->DriverOptionOrder[OptionOrderIndex++] = (UINT32)(NewMenuEntry->OptionNumber + 1);
}
}
/**
Boot the file specified by the input file path info.
@param FilePath Point to the file path.
@retval TRUE Exit caller function.
@retval FALSE Not exit caller function.
**/
BOOLEAN
EFIAPI
BootFromFile (
IN EFI_DEVICE_PATH_PROTOCOL *FilePath
)
{
EFI_STATUS Status;
EFI_BOOT_MANAGER_LOAD_OPTION BootOption;
CHAR16 *FileName;
Status = EFI_NOT_STARTED;
FileName = NULL;
FileName = ExtractFileNameFromDevicePath (FilePath);
if (FileName != NULL) {
Status = EfiBootManagerInitializeLoadOption (
&BootOption,
0,
LoadOptionTypeBoot,
LOAD_OPTION_ACTIVE,
FileName,
FilePath,
NULL,
0
);
}
if (!EFI_ERROR (Status)) {
//
// Since current no boot from removable media directly is allowed */
//
gST->ConOut->ClearScreen (gST->ConOut);
//
// Check whether need to reset system.
//
BmmSetupResetReminder ();
BmmSetConsoleMode (FALSE);
EfiBootManagerBoot (&BootOption);
BmmSetConsoleMode (TRUE);
FreePool (FileName);
EfiBootManagerFreeLoadOption (&BootOption);
}
return FALSE;
}
/**
Display the form base on the selected file.
@param FilePath Point to the file path.
@param FormId The form need to display.
**/
BOOLEAN
ReSendForm (
IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
IN EFI_FORM_ID FormId
)
{
gBootMaintenancePrivate.LoadContext->FilePathList = FilePath;
UpdateOptionPage (&gBootMaintenancePrivate, FormId, FilePath);
gBootMaintenancePrivate.FormBrowser2->SendForm (
gBootMaintenancePrivate.FormBrowser2,
&gBootMaintenancePrivate.BmmHiiHandle,
1,
&mBootMaintGuid,
FormId,
NULL,
NULL
);
return TRUE;
}
/**
Create boot option base on the input file path info.
@param FilePath Point to the file path.
@retval TRUE Exit caller function.
@retval FALSE Not exit caller function.
**/
BOOLEAN
EFIAPI
CreateBootOptionFromFile (
IN EFI_DEVICE_PATH_PROTOCOL *FilePath
)
{
return ReSendForm (FilePath, FORM_BOOT_ADD_ID);
}
/**
Create driver option base on the input file path info.
@param FilePath Point to the file path.
@retval TRUE Exit caller function.
@retval FALSE Not exit caller function.
**/
BOOLEAN
EFIAPI
CreateDriverOptionFromFile (
IN EFI_DEVICE_PATH_PROTOCOL *FilePath
)
{
return ReSendForm (FilePath, FORM_DRV_ADD_FILE_ID);
}
|