Adds new boot option with data specified in BootOption, * to be at BootIndex in the list of options (0 based). * BootOption should be populated with: Attributes, FilePathListLength, * FilePathList, Description, OptionalData and OptionalDataSize. * BootOption->BootNum will contain XXXX from added BootXXXX var * on success. */
| 923 | * on success. |
| 924 | */ |
| 925 | EFI_STATUS |
| 926 | AddBootOption ( |
| 927 | IN BO_BOOT_OPTION *BootOption, |
| 928 | IN UINTN BootIndex |
| 929 | ) |
| 930 | { |
| 931 | EFI_STATUS Status; |
| 932 | CHAR16 VarName[16]; |
| 933 | |
| 934 | |
| 935 | DBG("AddBootOption: %ls\n", BootOption->Description); |
| 936 | DBG(" FilePath: %ls\n", FileDevicePathToXStringW(BootOption->FilePathList).wc_str()); |
| 937 | DBG(" BootIndex: %llu\n", BootIndex); |
| 938 | |
| 939 | // |
| 940 | // Find free BootXXXX var slot. |
| 941 | // |
| 942 | Status = FindFreeBootNum (&BootOption->BootNum); |
| 943 | if (EFI_ERROR(Status)) { |
| 944 | DBG("FindFreeBootNum: %s\n", efiStrError(Status)); |
| 945 | return Status; |
| 946 | } |
| 947 | DBG(" Found BootNum: %04hX\n", BootOption->BootNum); |
| 948 | snwprintf(VarName, sizeof(VarName), "Boot%04hX", BootOption->BootNum); |
| 949 | |
| 950 | // |
| 951 | // Prepare BootOption variable |
| 952 | // |
| 953 | Status = CompileBootOption (BootOption); |
| 954 | if (EFI_ERROR(Status)) { |
| 955 | return Status; |
| 956 | } |
| 957 | |
| 958 | // |
| 959 | // Save BootXXXX var |
| 960 | // |
| 961 | Status = gRT->SetVariable (VarName, |
| 962 | &gEfiGlobalVariableGuid, |
| 963 | EFI_VARIABLE_NON_VOLATILE |
| 964 | | EFI_VARIABLE_BOOTSERVICE_ACCESS |
| 965 | | EFI_VARIABLE_RUNTIME_ACCESS, |
| 966 | BootOption->VariableSize, |
| 967 | BootOption->Variable |
| 968 | ); |
| 969 | if (EFI_ERROR(Status)) { |
| 970 | DBG("SetVariable: %ls = %s\n", VarName, efiStrError(Status)); |
| 971 | return Status; |
| 972 | } |
| 973 | DBG(" %ls saved\n", VarName); |
| 974 | |
| 975 | // |
| 976 | // Free allocated space |
| 977 | // |
| 978 | FreePool(BootOption->Variable); |
| 979 | |
| 980 | // |
| 981 | // Update BootOrder - add our new boot option as BootIndex in the list |
| 982 | // |
no test coverage detected