/** Update the device path of "ConOut", "ConIn" and "ErrOut" based on the new BaudRate, Data Bits, parity and Stop Bits set. **/ VOID Var_UpdateAllConsoleOption ( VOID ) { EFI_DEVICE_PATH_PROTOCOL *OutDevicePath; EFI_DEVICE_PATH_PROTOCOL *InpDevicePath; EFI_DEVICE_PATH_PROTOCOL *ErrDevicePath; EFI_STATUS Status; GetEfiGlobalVariable2 (L"ConOut", (VOID**)&OutDevicePath, NULL); GetEfiGlobalVariable2 (L"ConIn", (VOID**)&InpDevicePath, NULL); GetEfiGlobalVariable2 (L"ErrOut", (VOID**)&ErrDevicePath, NULL); if (OutDevicePath != NULL) { ChangeVariableDevicePath (OutDevicePath); Status = gRT->SetVariable ( L"ConOut", &gEfiGlobalVariableGuid, VAR_FLAG, GetDevicePathSize (OutDevicePath), OutDevicePath ); ASSERT (!EFI_ERROR (Status)); } if (InpDevicePath != NULL) { ChangeVariableDevicePath (InpDevicePath); Status = gRT->SetVariable ( L"ConIn", &gEfiGlobalVariableGuid, VAR_FLAG, GetDevicePathSize (InpDevicePath), InpDevicePath ); ASSERT (!EFI_ERROR (Status)); } if (ErrDevicePath != NULL) { ChangeVariableDevicePath (ErrDevicePath); Status = gRT->SetVariable ( L"ErrOut", &gEfiGlobalVariableGuid, VAR_FLAG, GetDevicePathSize (ErrDevicePath), ErrDevicePath ); ASSERT (!EFI_ERROR (Status)); } }
/** 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((EFI_D_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; }
/** Validate input console variable data. If found the device path is not a valid device path, remove the variable. @param VariableName Input console variable name. **/ VOID BdsFormalizeConsoleVariable ( IN CHAR16 *VariableName ) { EFI_DEVICE_PATH_PROTOCOL *DevicePath; UINTN VariableSize; EFI_STATUS Status; GetEfiGlobalVariable2 (VariableName, (VOID **) &DevicePath, &VariableSize); if ((DevicePath != NULL) && !IsDevicePathValid (DevicePath, VariableSize)) { Status = gRT->SetVariable ( VariableName, &gEfiGlobalVariableGuid, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, 0, NULL ); // // Deleting variable with current variable implementation shouldn't fail. // ASSERT_EFI_ERROR (Status); } if (DevicePath != NULL) { FreePool (DevicePath); } }
/** Add the specified device path by DriverIndex to the forbid device path list (mAccessInfo.LoadForbid). @param[in] DriverIndex The index of driver saved in driver options. **/ VOID AddToForbidLoad ( IN UINT16 DriverIndex ) { UINTN DevicePathLen; UINT8 *Var; UINT8 *VarPtr; UINTN NewLen; UINT8 *NewFL; CHAR16 VarName[13]; // // Get loadable driver device path. // UnicodeSPrint (VarName, sizeof (VarName), L"Driver%04x", DriverIndex); GetEfiGlobalVariable2 (VarName, (VOID**)&Var, NULL); if (Var == NULL) { return; } // // Save forbid load driver. // VarPtr = Var; // // Skip attribute. // VarPtr += sizeof (UINT32); DevicePathLen = *(UINT16 *) VarPtr; // // Skip device path length. // VarPtr += sizeof (UINT16); // // Skip description string. // VarPtr += StrSize ((UINT16 *) VarPtr); NewLen = mAccessInfo.LoadForbidLen + DevicePathLen; NewFL = AllocateZeroPool (NewLen); if (NewFL == NULL) { FreePool (Var); return ; } if (mAccessInfo.LoadForbidLen > 0) { CopyMem (NewFL, mAccessInfo.LoadForbid, mAccessInfo.LoadForbidLen); FreePool (mAccessInfo.LoadForbid); } CopyMem (NewFL + mAccessInfo.LoadForbidLen, VarPtr, DevicePathLen); mAccessInfo.LoadForbidLen = NewLen; mAccessInfo.LoadForbid = NewFL; FreePool (Var); }
/** Delete the load option. @param OptionNumber Indicate the option number of load option @param OptionType Indicate the type of load option @retval EFI_INVALID_PARAMETER OptionType or OptionNumber is invalid. @retval EFI_NOT_FOUND The load option cannot be found @retval EFI_SUCCESS The load option was deleted @retval others Status of RT->SetVariable() **/ EFI_STATUS EFIAPI EfiBootManagerDeleteLoadOptionVariable ( IN UINTN OptionNumber, IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE OptionType ) { UINT16 *OptionOrder; UINTN OptionOrderSize; UINTN Index; CHAR16 OptionName[BM_OPTION_NAME_LEN]; if (((UINT32) OptionType >= LoadOptionTypeMax) || (OptionNumber >= LoadOptionNumberMax)) { return EFI_INVALID_PARAMETER; } if (OptionType == LoadOptionTypeDriver || OptionType == LoadOptionTypeSysPrep || OptionType == LoadOptionTypeBoot) { // // If the associated *Order exists, firstly remove the reference in *Order for // Driver####, SysPrep#### and Boot####. // GetEfiGlobalVariable2 (mBmLoadOptionOrderName[OptionType], (VOID **) &OptionOrder, &OptionOrderSize); ASSERT ((OptionOrder != NULL && OptionOrderSize != 0) || (OptionOrder == NULL && OptionOrderSize == 0)); for (Index = 0; Index < OptionOrderSize / sizeof (UINT16); Index++) { if (OptionOrder[Index] == OptionNumber) { OptionOrderSize -= sizeof (UINT16); CopyMem (&OptionOrder[Index], &OptionOrder[Index + 1], OptionOrderSize - Index * sizeof (UINT16)); gRT->SetVariable ( mBmLoadOptionOrderName[OptionType], &gEfiGlobalVariableGuid, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, OptionOrderSize, OptionOrder ); break; } } if (OptionOrder != NULL) { FreePool (OptionOrder); } } // // Remove the Driver####, SysPrep####, Boot#### or PlatformRecovery#### itself. // UnicodeSPrint (OptionName, sizeof (OptionName), L"%s%04x", mBmLoadOptionName[OptionType], OptionNumber); return gRT->SetVariable ( OptionName, &gEfiGlobalVariableGuid, 0, 0, NULL ); }
/** Update order variable . @param OptionOrderName Order variable name which need to be updated. @param OptionNumber Option number for the new option. @param Position Position of the new load option to put in the ****Order variable. @retval EFI_SUCCESS The boot#### or driver#### have been successfully registered. @retval EFI_ALREADY_STARTED The option number of Option is being used already. @retval EFI_STATUS Return the status of gRT->SetVariable (). **/ EFI_STATUS BmAddOptionNumberToOrderVariable ( IN CHAR16 *OptionOrderName, IN UINT16 OptionNumber, IN UINTN Position ) { EFI_STATUS Status; UINTN Index; UINT16 *OptionOrder; UINT16 *NewOptionOrder; UINTN OptionOrderSize; // // Update the option order variable // GetEfiGlobalVariable2 (OptionOrderName, (VOID **) &OptionOrder, &OptionOrderSize); ASSERT ((OptionOrder != NULL && OptionOrderSize != 0) || (OptionOrder == NULL && OptionOrderSize == 0)); Status = EFI_SUCCESS; for (Index = 0; Index < OptionOrderSize / sizeof (UINT16); Index++) { if (OptionOrder[Index] == OptionNumber) { Status = EFI_ALREADY_STARTED; break; } } if (!EFI_ERROR (Status)) { Position = MIN (Position, OptionOrderSize / sizeof (UINT16)); NewOptionOrder = AllocatePool (OptionOrderSize + sizeof (UINT16)); ASSERT (NewOptionOrder != NULL); if (OptionOrderSize != 0) { CopyMem (NewOptionOrder, OptionOrder, Position * sizeof (UINT16)); CopyMem (&NewOptionOrder[Position + 1], &OptionOrder[Position], OptionOrderSize - Position * sizeof (UINT16)); } NewOptionOrder[Position] = OptionNumber; Status = gRT->SetVariable ( OptionOrderName, &gEfiGlobalVariableGuid, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, OptionOrderSize + sizeof (UINT16), NewOptionOrder ); FreePool (NewOptionOrder); } if (OptionOrder != NULL) { FreePool (OptionOrder); } return Status; }
/** This function update the "DriverOrder" EFI Variable based on BMM Formset's NV map. It then refresh DriverOptionMenu with the new "DriverOrder" list. @param CallbackData The BMM context data. @retval EFI_SUCCESS The function complete successfully. @retval EFI_OUT_OF_RESOURCES Not enough memory to complete the function. @return The EFI variable can not be saved. See gRT->SetVariable for detail return information. **/ EFI_STATUS Var_UpdateDriverOrder ( IN BMM_CALLBACK_DATA *CallbackData ) { EFI_STATUS Status; UINT16 Index; UINT16 *DriverOrderList; UINT16 *NewDriverOrderList; UINTN DriverOrderListSize; DriverOrderList = NULL; DriverOrderListSize = 0; // // First check whether DriverOrder is present in current configuration // GetEfiGlobalVariable2 (L"DriverOrder", (VOID **) &DriverOrderList, &DriverOrderListSize); NewDriverOrderList = AllocateZeroPool (DriverOrderListSize); if (NewDriverOrderList == NULL) { return EFI_OUT_OF_RESOURCES; } // // If exists, delete it to hold new DriverOrder // if (DriverOrderList != NULL) { EfiLibDeleteVariable (L"DriverOrder", &gEfiGlobalVariableGuid); FreePool (DriverOrderList); } ASSERT (DriverOptionMenu.MenuNumber <= (sizeof (CallbackData->BmmFakeNvData.DriverOptionOrder) / sizeof (CallbackData->BmmFakeNvData.DriverOptionOrder[0]))); for (Index = 0; Index < DriverOptionMenu.MenuNumber; Index++) { NewDriverOrderList[Index] = (UINT16) (CallbackData->BmmFakeNvData.DriverOptionOrder[Index] - 1); } Status = gRT->SetVariable ( L"DriverOrder", &gEfiGlobalVariableGuid, VAR_FLAG, DriverOrderListSize, NewDriverOrderList ); if (EFI_ERROR (Status)) { return Status; } BOpt_FreeMenu (&DriverOptionMenu); BOpt_GetDriverOptions (CallbackData); return EFI_SUCCESS; }
/** This function update the "BootOrder" EFI Variable based on BMM Formset's NV map. It then refresh BootOptionMenu with the new "BootOrder" list. @param CallbackData The BMM context data. @retval EFI_SUCCESS The function complete successfully. @retval EFI_OUT_OF_RESOURCES Not enough memory to complete the function. @return The EFI variable can not be saved. See gRT->SetVariable for detail return information. **/ EFI_STATUS Var_UpdateBootOrder ( IN BMM_CALLBACK_DATA *CallbackData ) { EFI_STATUS Status; UINT16 Index; UINT16 OrderIndex; UINT16 *BootOrder; UINTN BootOrderSize; UINT16 OptionNumber; // // First check whether BootOrder is present in current configuration // GetEfiGlobalVariable2 (L"BootOrder", (VOID **) &BootOrder, &BootOrderSize); if (BootOrder == NULL) { return EFI_OUT_OF_RESOURCES; } ASSERT (BootOptionMenu.MenuNumber <= (sizeof (CallbackData->BmmFakeNvData.BootOptionOrder) / sizeof (CallbackData->BmmFakeNvData.BootOptionOrder[0]))); // // OptionOrder is subset of BootOrder // for (OrderIndex = 0; (OrderIndex < BootOptionMenu.MenuNumber) && (CallbackData->BmmFakeNvData.BootOptionOrder[OrderIndex] != 0); OrderIndex++) { for (Index = OrderIndex; Index < BootOrderSize / sizeof (UINT16); Index++) { if ((BootOrder[Index] == (UINT16) (CallbackData->BmmFakeNvData.BootOptionOrder[OrderIndex] - 1)) && (OrderIndex != Index)) { OptionNumber = BootOrder[Index]; CopyMem (&BootOrder[OrderIndex + 1], &BootOrder[OrderIndex], (Index - OrderIndex) * sizeof (UINT16)); BootOrder[OrderIndex] = OptionNumber; } } } Status = gRT->SetVariable ( L"BootOrder", &gEfiGlobalVariableGuid, VAR_FLAG, BootOrderSize, BootOrder ); FreePool (BootOrder); BOpt_FreeMenu (&BootOptionMenu); BOpt_GetBootOptions (CallbackData); return Status; }
/** Delete the load option. @param OptionNumber Indicate the option number of load option @param OptionType Indicate the type of load option @retval EFI_INVALID_PARAMETER OptionType or OptionNumber is invalid. @retval EFI_NOT_FOUND The load option cannot be found @retval EFI_SUCCESS The load option was deleted @retval others Status of RT->SetVariable() **/ EFI_STATUS EFIAPI EfiBootManagerDeleteLoadOptionVariable ( IN UINTN OptionNumber, IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE OptionType ) { UINT16 *OptionOrder; UINTN OptionOrderSize; EFI_STATUS Status; UINTN Index; if (((UINT32) OptionType >= LoadOptionTypeMax) || (OptionNumber >= LoadOptionNumberMax)) { return EFI_INVALID_PARAMETER; } Status = EFI_NOT_FOUND; if (OptionType == LoadOptionTypeDriver || OptionType == LoadOptionTypeSysPrep || OptionType == LoadOptionTypeBoot) { // // If the associated *Order exists, just remove the reference in *Order. // GetEfiGlobalVariable2 (mBmLoadOptionOrderName[OptionType], (VOID **) &OptionOrder, &OptionOrderSize); ASSERT ((OptionOrder != NULL && OptionOrderSize != 0) || (OptionOrder == NULL && OptionOrderSize == 0)); for (Index = 0; Index < OptionOrderSize / sizeof (UINT16); Index++) { if (OptionOrder[Index] == OptionNumber) { OptionOrderSize -= sizeof (UINT16); CopyMem (&OptionOrder[Index], &OptionOrder[Index + 1], OptionOrderSize - Index * sizeof (UINT16)); Status = gRT->SetVariable ( mBmLoadOptionOrderName[OptionType], &gEfiGlobalVariableGuid, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, OptionOrderSize, OptionOrder ); break; } } if (OptionOrder != NULL) { FreePool (OptionOrder); } } return Status; }
/** Start the hot key service so that the key press can trigger the boot option. @param HotkeyTriggered Return the waitable event and it will be signaled when a valid hot key is pressed. @retval EFI_SUCCESS The hot key service is started. **/ EFI_STATUS EFIAPI EfiBootManagerStartHotkeyService ( IN EFI_EVENT *HotkeyTriggered ) { EFI_STATUS Status; EFI_BOOT_MANAGER_KEY_OPTION *KeyOptions; UINTN KeyOptionCount; UINTN Index; EFI_EVENT Event; UINT32 *BootOptionSupport; GetEfiGlobalVariable2 (EFI_BOOT_OPTION_SUPPORT_VARIABLE_NAME, (VOID **) &BootOptionSupport, NULL); if (BootOptionSupport != NULL) { if ((*BootOptionSupport & EFI_BOOT_OPTION_SUPPORT_KEY) != 0) { mBmHotkeySupportCount = ((*BootOptionSupport & EFI_BOOT_OPTION_SUPPORT_COUNT) >> LowBitSet32 (EFI_BOOT_OPTION_SUPPORT_COUNT)); } FreePool (BootOptionSupport); }
/** Visitor function to collect the key options from NV storage. @param Name Variable name. @param Guid Variable GUID. @param Context The same context passed to BmForEachVariable. **/ VOID BmCollectKeyOptions ( CHAR16 *Name, EFI_GUID *Guid, VOID *Context ) { UINTN Index; BM_COLLECT_KEY_OPTIONS_PARAM *Param; VOID *KeyOption; UINT16 OptionNumber; UINTN KeyOptionSize; Param = (BM_COLLECT_KEY_OPTIONS_PARAM *) Context; if (BmIsKeyOptionVariable (Name, Guid, &OptionNumber)) { GetEfiGlobalVariable2 (Name, &KeyOption, &KeyOptionSize); ASSERT (KeyOption != NULL); if (BmIsKeyOptionValid (KeyOption, KeyOptionSize)) { Param->KeyOptions = ReallocatePool ( Param->KeyOptionCount * sizeof (EFI_BOOT_MANAGER_KEY_OPTION), (Param->KeyOptionCount + 1) * sizeof (EFI_BOOT_MANAGER_KEY_OPTION), Param->KeyOptions ); ASSERT (Param->KeyOptions != NULL); // // Insert the key option in order // for (Index = 0; Index < Param->KeyOptionCount; Index++) { if (OptionNumber < Param->KeyOptions[Index].OptionNumber) { break; } } CopyMem (&Param->KeyOptions[Index + 1], &Param->KeyOptions[Index], (Param->KeyOptionCount - Index) * sizeof (EFI_BOOT_MANAGER_KEY_OPTION)); CopyMem (&Param->KeyOptions[Index], KeyOption, KeyOptionSize); Param->KeyOptions[Index].OptionNumber = OptionNumber; Param->KeyOptionCount++; } FreePool (KeyOption); } }
/** Initialize Lang or PlatformLang variable, if Lang or PlatformLang variable is not found, or it has been set to an unsupported value(not one of platform supported language codes), set the default language code to it. @param LangName Language name, L"Lang" or L"PlatformLang". @param SupportedLang Platform supported language codes. @param DefaultLang Default language code. @param Iso639Language A bool value to signify if the handler is operated on ISO639 or RFC4646, TRUE for L"Lang" LangName or FALSE for L"PlatformLang" LangName. **/ VOID InitializeLangVariable ( IN CHAR16 *LangName, IN CHAR8 *SupportedLang, IN CHAR8 *DefaultLang, IN BOOLEAN Iso639Language ) { CHAR8 *Lang; // // Find current Lang or PlatformLang from EFI Variable. // GetEfiGlobalVariable2 (LangName, (VOID **) &Lang, NULL); // // If Lang or PlatformLang variable is not found, // or it has been set to an unsupported value(not one of the supported language codes), // set the default language code to it. // if ((Lang == NULL) || !IsLangInSupportedLangCodes (SupportedLang, Lang, Iso639Language)) { // // The default language code should be one of the supported language codes. // ASSERT (IsLangInSupportedLangCodes (SupportedLang, DefaultLang, Iso639Language)); BdsDxeSetVariableAndReportStatusCodeOnError ( LangName, &gEfiGlobalVariableGuid, EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, AsciiStrSize (DefaultLang), DefaultLang ); } if (Lang != NULL) { FreePool (Lang); } }
/** Check whether the input key option is valid. @param KeyOption Key option. @param KeyOptionSize Size of the key option. @retval TRUE Input key option is valid. @retval FALSE Input key option is not valid. **/ BOOLEAN BmIsKeyOptionValid ( IN CONST EFI_BOOT_MANAGER_KEY_OPTION *KeyOption, IN UINTN KeyOptionSize ) { UINT16 OptionName[BM_OPTION_NAME_LEN]; UINT8 *BootOption; UINTN BootOptionSize; UINT32 Crc; if (BmSizeOfKeyOption (KeyOption) != KeyOptionSize) { return FALSE; } // // Check whether corresponding Boot Option exist // UnicodeSPrint ( OptionName, sizeof (OptionName), L"%s%04x", mBmLoadOptionName[LoadOptionTypeBoot], KeyOption->BootOption ); GetEfiGlobalVariable2 (OptionName, (VOID **) &BootOption, &BootOptionSize); if (BootOption == NULL) { return FALSE; } // // Check CRC for Boot Option // gBS->CalculateCrc32 (BootOption, BootOptionSize, &Crc); FreePool (BootOption); return (BOOLEAN) (KeyOption->BootOptionCrc == Crc); }
/** Select the best matching language according to front page policy for best user experience. This function supports both ISO 639-2 and RFC 4646 language codes, but language code types may not be mixed in a single call to this function. @param SupportedLanguages A pointer to a Null-terminated ASCII string that contains a set of language codes in the format specified by Iso639Language. @param Iso639Language If TRUE, then all language codes are assumed to be in ISO 639-2 format. If FALSE, then all language codes are assumed to be in RFC 4646 language format. @retval NULL The best matching language could not be found in SupportedLanguages. @retval NULL There are not enough resources available to return the best matching language. @retval Other A pointer to a Null-terminated ASCII string that is the best matching language in SupportedLanguages. **/ CHAR8 * DriverHealthManagerSelectBestLanguage ( IN CHAR8 *SupportedLanguages, IN BOOLEAN Iso639Language ) { CHAR8 *LanguageVariable; CHAR8 *BestLanguage; GetEfiGlobalVariable2 (Iso639Language ? L"Lang" : L"PlatformLang", (VOID**)&LanguageVariable, NULL); BestLanguage = GetBestLanguage( SupportedLanguages, Iso639Language, (LanguageVariable != NULL) ? LanguageVariable : "", Iso639Language ? "eng" : "en-US", NULL ); if (LanguageVariable != NULL) { FreePool (LanguageVariable); } return BestLanguage; }
/** After any operation on Boot####, there will be a discrepancy in BootOrder. Since some are missing but in BootOrder, while some are present but are not reflected by BootOrder. Then a function rebuild BootOrder from scratch by content from BootOptionMenu is needed. @retval EFI_SUCCESS The boot order is updated successfully. @return EFI_STATUS other than EFI_SUCCESS if failed to Set the "BootOrder" EFI Variable. **/ EFI_STATUS Var_ChangeBootOrder ( VOID ) { EFI_STATUS Status; BM_MENU_ENTRY *NewMenuEntry; UINT16 *BootOrderList; UINT16 *BootOrderListPtr; UINTN BootOrderListSize; UINTN Index; BootOrderList = NULL; BootOrderListSize = 0; // // First check whether BootOrder is present in current configuration // GetEfiGlobalVariable2 (L"BootOrder", (VOID **) &BootOrderList, &BootOrderListSize); // // If exists, delete it to hold new BootOrder // if (BootOrderList != NULL) { EfiLibDeleteVariable (L"BootOrder", &gEfiGlobalVariableGuid); FreePool (BootOrderList); BootOrderList = NULL; } // // Maybe here should be some check method to ensure that // no new added boot options will be added // but the setup engine now will give only one callback // that is to say, user are granted only one chance to // decide whether the boot option will be added or not // there should be no indictor to show whether this // is a "new" boot option // BootOrderListSize = BootOptionMenu.MenuNumber; if (BootOrderListSize > 0) { BootOrderList = AllocateZeroPool (BootOrderListSize * sizeof (UINT16)); ASSERT (BootOrderList != NULL); BootOrderListPtr = BootOrderList; // // Get all current used Boot#### from BootOptionMenu. // OptionNumber in each BM_LOAD_OPTION is really its // #### value. // for (Index = 0; Index < BootOrderListSize; Index++) { NewMenuEntry = BOpt_GetMenuEntry (&BootOptionMenu, Index); *BootOrderList = (UINT16) NewMenuEntry->OptionNumber; BootOrderList++; } BootOrderList = BootOrderListPtr; // // After building the BootOrderList, write it back // Status = gRT->SetVariable ( L"BootOrder", &gEfiGlobalVariableGuid, VAR_FLAG, BootOrderListSize * sizeof (UINT16), BootOrderList ); if (EFI_ERROR (Status)) { return Status; } } return EFI_SUCCESS; }
/** Get a human readable name for an image handle. The following methods will be tried orderly: 1. Image PDB 2. ComponentName2 protocol 3. FFS UI section 4. Image GUID 5. Image DevicePath 6. Unknown Driver Name @param[in] Handle @post The resulting Unicode name string is stored in the mGaugeString global array. **/ VOID GetNameFromHandle ( IN EFI_HANDLE Handle ) { EFI_STATUS Status; EFI_LOADED_IMAGE_PROTOCOL *Image; CHAR8 *PdbFileName; EFI_DRIVER_BINDING_PROTOCOL *DriverBinding; EFI_STRING StringPtr; EFI_DEVICE_PATH_PROTOCOL *LoadedImageDevicePath; EFI_DEVICE_PATH_PROTOCOL *DevicePath; EFI_GUID *NameGuid; CHAR16 *NameString; UINTN StringSize; CHAR8 *PlatformLanguage; CHAR8 *BestLanguage; EFI_COMPONENT_NAME2_PROTOCOL *ComponentName2; BestLanguage = NULL; PlatformLanguage = NULL; // // Method 1: Get the name string from image PDB // Status = gBS->HandleProtocol ( Handle, &gEfiLoadedImageProtocolGuid, (VOID **) &Image ); if (EFI_ERROR (Status)) { Status = gBS->OpenProtocol ( Handle, &gEfiDriverBindingProtocolGuid, (VOID **) &DriverBinding, NULL, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL ); if (!EFI_ERROR (Status)) { Status = gBS->HandleProtocol ( DriverBinding->ImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **) &Image ); } } if (!EFI_ERROR (Status)) { PdbFileName = PeCoffLoaderGetPdbPointer (Image->ImageBase); if (PdbFileName != NULL) { GetShortPdbFileName (PdbFileName, mGaugeString); return; } } // // Method 2: Get the name string from ComponentName2 protocol // Status = gBS->HandleProtocol ( Handle, &gEfiComponentName2ProtocolGuid, (VOID **) &ComponentName2 ); if (!EFI_ERROR (Status)) { // // Get the current platform language setting // GetEfiGlobalVariable2 (L"PlatformLang", (VOID**)&PlatformLanguage, NULL); BestLanguage = GetBestLanguage( ComponentName2->SupportedLanguages, FALSE, PlatformLanguage, ComponentName2->SupportedLanguages, NULL ); SafeFreePool (PlatformLanguage); Status = ComponentName2->GetDriverName ( ComponentName2, BestLanguage, &StringPtr ); SafeFreePool (BestLanguage); if (!EFI_ERROR (Status)) { StrnCpy (mGaugeString, StringPtr, DP_GAUGE_STRING_LENGTH); mGaugeString[DP_GAUGE_STRING_LENGTH] = 0; return; } } Status = gBS->HandleProtocol ( Handle, &gEfiLoadedImageDevicePathProtocolGuid, (VOID **) &LoadedImageDevicePath ); if (!EFI_ERROR (Status) && (LoadedImageDevicePath != NULL)) { DevicePath = LoadedImageDevicePath; // // Try to get image GUID from LoadedImageDevicePath protocol // NameGuid = NULL; while (!IsDevicePathEndType (DevicePath)) { NameGuid = EfiGetNameGuidFromFwVolDevicePathNode ((MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) DevicePath); if (NameGuid != NULL) { break; } DevicePath = NextDevicePathNode (DevicePath); } if (NameGuid != NULL) { // // Try to get the image's FFS UI section by image GUID // NameString = NULL; StringSize = 0; Status = GetSectionFromAnyFv ( NameGuid, EFI_SECTION_USER_INTERFACE, 0, (VOID **) &NameString, &StringSize ); if (!EFI_ERROR (Status)) { // // Method 3. Get the name string from FFS UI section // StrnCpy (mGaugeString, NameString, DP_GAUGE_STRING_LENGTH); mGaugeString[DP_GAUGE_STRING_LENGTH] = 0; FreePool (NameString); } else { // // Method 4: Get the name string from image GUID // UnicodeSPrint (mGaugeString, sizeof (mGaugeString), L"%g", NameGuid); } return; } else { // // Method 5: Get the name string from image DevicePath // NameString = ConvertDevicePathToText (LoadedImageDevicePath, TRUE, FALSE); if (NameString != NULL) { StrnCpy (mGaugeString, NameString, DP_GAUGE_STRING_LENGTH); mGaugeString[DP_GAUGE_STRING_LENGTH] = 0; FreePool (NameString); return; } } } // // Method 6: Unknown Driver Name // StringPtr = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_ERROR_NAME), NULL); ASSERT (StringPtr != NULL); StrCpy (mGaugeString, StringPtr); FreePool (StringPtr); return; }
/** This function create a currently loaded Boot Option from the BMM. It then appends this Boot Option to the end of the "BootOrder" list. It also append this Boot Opotion to the end of BootOptionMenu. @param CallbackData The BMM context data. @retval EFI_OUT_OF_RESOURCES If not enought memory to complete the operation. @retval EFI_SUCCESS If function completes successfully. **/ EFI_STATUS Var_UpdateBootOption ( IN BMM_CALLBACK_DATA *CallbackData ) { UINT16 *BootOrderList; UINT16 *NewBootOrderList; UINTN BootOrderListSize; UINT16 BootString[10]; VOID *Buffer; UINTN BufferSize; UINT8 *Ptr; UINT16 Index; BM_MENU_ENTRY *NewMenuEntry; BM_LOAD_CONTEXT *NewLoadContext; BOOLEAN OptionalDataExist; EFI_STATUS Status; BMM_FAKE_NV_DATA *NvRamMap; OptionalDataExist = FALSE; NvRamMap = &CallbackData->BmmFakeNvData; Index = BOpt_GetBootOptionNumber () ; UnicodeSPrint (BootString, sizeof (BootString), L"Boot%04x", Index); if (NvRamMap->BootDescriptionData[0] == 0x0000) { StrCpyS (NvRamMap->BootDescriptionData, sizeof (NvRamMap->BootDescriptionData) / sizeof (NvRamMap->BootDescriptionData[0]), BootString); } BufferSize = sizeof (UINT32) + sizeof (UINT16) + StrSize (NvRamMap->BootDescriptionData); BufferSize += GetDevicePathSize (CallbackData->LoadContext->FilePathList); if (NvRamMap->BootOptionalData[0] != 0x0000) { OptionalDataExist = TRUE; BufferSize += StrSize (NvRamMap->BootOptionalData); } Buffer = AllocateZeroPool (BufferSize); if (NULL == Buffer) { return EFI_OUT_OF_RESOURCES; } NewMenuEntry = BOpt_CreateMenuEntry (BM_LOAD_CONTEXT_SELECT); if (NULL == NewMenuEntry) { return EFI_OUT_OF_RESOURCES; } NewLoadContext = (BM_LOAD_CONTEXT *) NewMenuEntry->VariableContext; NewLoadContext->Deleted = FALSE; NewLoadContext->LoadOptionSize = BufferSize; Ptr = (UINT8 *) Buffer; NewLoadContext->LoadOption = Ptr; *((UINT32 *) Ptr) = LOAD_OPTION_ACTIVE; NewLoadContext->Attributes = *((UINT32 *) Ptr); NewLoadContext->IsActive = TRUE; NewLoadContext->ForceReconnect = (BOOLEAN) (NewLoadContext->Attributes & LOAD_OPTION_FORCE_RECONNECT); Ptr += sizeof (UINT32); *((UINT16 *) Ptr) = (UINT16) GetDevicePathSize (CallbackData->LoadContext->FilePathList); NewLoadContext->FilePathListLength = *((UINT16 *) Ptr); Ptr += sizeof (UINT16); CopyMem ( Ptr, NvRamMap->BootDescriptionData, StrSize (NvRamMap->BootDescriptionData) ); NewLoadContext->Description = AllocateZeroPool (StrSize (NvRamMap->BootDescriptionData)); ASSERT (NewLoadContext->Description != NULL); NewMenuEntry->DisplayString = NewLoadContext->Description; CopyMem ( NewLoadContext->Description, (VOID *) Ptr, StrSize (NvRamMap->BootDescriptionData) ); Ptr += StrSize (NvRamMap->BootDescriptionData); CopyMem ( Ptr, CallbackData->LoadContext->FilePathList, GetDevicePathSize (CallbackData->LoadContext->FilePathList) ); NewLoadContext->FilePathList = AllocateZeroPool (GetDevicePathSize (CallbackData->LoadContext->FilePathList)); ASSERT (NewLoadContext->FilePathList != NULL); CopyMem ( NewLoadContext->FilePathList, (VOID *) Ptr, GetDevicePathSize (CallbackData->LoadContext->FilePathList) ); NewMenuEntry->HelpString = UiDevicePathToStr (NewLoadContext->FilePathList); NewMenuEntry->OptionNumber = Index; NewMenuEntry->DisplayStringToken = HiiSetString (CallbackData->BmmHiiHandle, 0, NewMenuEntry->DisplayString, NULL); NewMenuEntry->HelpStringToken = HiiSetString (CallbackData->BmmHiiHandle, 0, NewMenuEntry->HelpString, NULL); if (OptionalDataExist) { Ptr += (UINT8) GetDevicePathSize (CallbackData->LoadContext->FilePathList); CopyMem (Ptr, NvRamMap->BootOptionalData, StrSize (NvRamMap->BootOptionalData)); } Status = gRT->SetVariable ( BootString, &gEfiGlobalVariableGuid, VAR_FLAG, BufferSize, Buffer ); ASSERT_EFI_ERROR (Status); GetEfiGlobalVariable2 (L"BootOrder", (VOID **) &BootOrderList, &BootOrderListSize); NewBootOrderList = AllocateZeroPool (BootOrderListSize + sizeof (UINT16)); ASSERT (NewBootOrderList != NULL); if (BootOrderList != NULL){ CopyMem (NewBootOrderList, BootOrderList, BootOrderListSize); } NewBootOrderList[BootOrderListSize / sizeof (UINT16)] = Index; if (BootOrderList != NULL) { FreePool (BootOrderList); } Status = gRT->SetVariable ( L"BootOrder", &gEfiGlobalVariableGuid, VAR_FLAG, BootOrderListSize + sizeof (UINT16), NewBootOrderList ); ASSERT_EFI_ERROR (Status); FreePool (NewBootOrderList); NewBootOrderList = NULL; InsertTailList (&BootOptionMenu.Head, &NewMenuEntry->Link); BootOptionMenu.MenuNumber++; return EFI_SUCCESS; }
/** This function create a currently loaded Drive Option from the BMM. It then appends this Driver Option to the end of the "DriverOrder" list. It append this Driver Opotion to the end of DriverOptionMenu. @param CallbackData The BMM context data. @param HiiHandle The HII handle associated with the BMM formset. @param DescriptionData The description of this driver option. @param OptionalData The optional load option. @param ForceReconnect If to force reconnect. @retval EFI_OUT_OF_RESOURCES If not enought memory to complete the operation. @retval EFI_SUCCESS If function completes successfully. **/ EFI_STATUS Var_UpdateDriverOption ( IN BMM_CALLBACK_DATA *CallbackData, IN EFI_HII_HANDLE HiiHandle, IN UINT16 *DescriptionData, IN UINT16 *OptionalData, IN UINT8 ForceReconnect ) { UINT16 Index; UINT16 *DriverOrderList; UINT16 *NewDriverOrderList; UINT16 DriverString[12]; UINTN DriverOrderListSize; VOID *Buffer; UINTN BufferSize; UINT8 *Ptr; BM_MENU_ENTRY *NewMenuEntry; BM_LOAD_CONTEXT *NewLoadContext; BOOLEAN OptionalDataExist; EFI_STATUS Status; OptionalDataExist = FALSE; Index = BOpt_GetDriverOptionNumber (); UnicodeSPrint ( DriverString, sizeof (DriverString), L"Driver%04x", Index ); if (*DescriptionData == 0x0000) { StrCpyS (DescriptionData, MAX_MENU_NUMBER, DriverString); } BufferSize = sizeof (UINT32) + sizeof (UINT16) + StrSize (DescriptionData); BufferSize += GetDevicePathSize (CallbackData->LoadContext->FilePathList); if (*OptionalData != 0x0000) { OptionalDataExist = TRUE; BufferSize += StrSize (OptionalData); } Buffer = AllocateZeroPool (BufferSize); if (NULL == Buffer) { return EFI_OUT_OF_RESOURCES; } NewMenuEntry = BOpt_CreateMenuEntry (BM_LOAD_CONTEXT_SELECT); if (NULL == NewMenuEntry) { FreePool (Buffer); return EFI_OUT_OF_RESOURCES; } NewLoadContext = (BM_LOAD_CONTEXT *) NewMenuEntry->VariableContext; NewLoadContext->Deleted = FALSE; NewLoadContext->LoadOptionSize = BufferSize; Ptr = (UINT8 *) Buffer; NewLoadContext->LoadOption = Ptr; *((UINT32 *) Ptr) = LOAD_OPTION_ACTIVE | (ForceReconnect << 1); NewLoadContext->Attributes = *((UINT32 *) Ptr); NewLoadContext->IsActive = TRUE; NewLoadContext->ForceReconnect = (BOOLEAN) (NewLoadContext->Attributes & LOAD_OPTION_FORCE_RECONNECT); Ptr += sizeof (UINT32); *((UINT16 *) Ptr) = (UINT16) GetDevicePathSize (CallbackData->LoadContext->FilePathList); NewLoadContext->FilePathListLength = *((UINT16 *) Ptr); Ptr += sizeof (UINT16); CopyMem ( Ptr, DescriptionData, StrSize (DescriptionData) ); NewLoadContext->Description = AllocateZeroPool (StrSize (DescriptionData)); ASSERT (NewLoadContext->Description != NULL); NewMenuEntry->DisplayString = NewLoadContext->Description; CopyMem ( NewLoadContext->Description, (VOID *) Ptr, StrSize (DescriptionData) ); Ptr += StrSize (DescriptionData); CopyMem ( Ptr, CallbackData->LoadContext->FilePathList, GetDevicePathSize (CallbackData->LoadContext->FilePathList) ); NewLoadContext->FilePathList = AllocateZeroPool (GetDevicePathSize (CallbackData->LoadContext->FilePathList)); ASSERT (NewLoadContext->FilePathList != NULL); CopyMem ( NewLoadContext->FilePathList, (VOID *) Ptr, GetDevicePathSize (CallbackData->LoadContext->FilePathList) ); NewMenuEntry->HelpString = UiDevicePathToStr (NewLoadContext->FilePathList); NewMenuEntry->OptionNumber = Index; NewMenuEntry->DisplayStringToken = HiiSetString (HiiHandle, 0, NewMenuEntry->DisplayString, NULL); NewMenuEntry->HelpStringToken = HiiSetString (HiiHandle, 0, NewMenuEntry->HelpString, NULL); if (OptionalDataExist) { Ptr += (UINT8) GetDevicePathSize (CallbackData->LoadContext->FilePathList); CopyMem ( Ptr, OptionalData, StrSize (OptionalData) ); } Status = gRT->SetVariable ( DriverString, &gEfiGlobalVariableGuid, VAR_FLAG, BufferSize, Buffer ); ASSERT_EFI_ERROR (Status); GetEfiGlobalVariable2 (L"DriverOrder", (VOID **) &DriverOrderList, &DriverOrderListSize); NewDriverOrderList = AllocateZeroPool (DriverOrderListSize + sizeof (UINT16)); ASSERT (NewDriverOrderList != NULL); if (DriverOrderList != NULL){ CopyMem (NewDriverOrderList, DriverOrderList, DriverOrderListSize); } NewDriverOrderList[DriverOrderListSize / sizeof (UINT16)] = Index; if (DriverOrderList != NULL) { EfiLibDeleteVariable (L"DriverOrder", &gEfiGlobalVariableGuid); } Status = gRT->SetVariable ( L"DriverOrder", &gEfiGlobalVariableGuid, VAR_FLAG, DriverOrderListSize + sizeof (UINT16), NewDriverOrderList ); ASSERT_EFI_ERROR (Status); if (DriverOrderList != NULL) { FreePool (DriverOrderList); } DriverOrderList = NULL; FreePool (NewDriverOrderList); InsertTailList (&DriverOptionMenu.Head, &NewMenuEntry->Link); DriverOptionMenu.MenuNumber++; return EFI_SUCCESS; }
/** This function delete and build multi-instance device path for specified type of console device. This function clear the EFI variable defined by ConsoleName and gEfiGlobalVariableGuid. It then build the multi-instance device path by appending the device path of the Console (In/Out/Err) instance in ConsoleMenu. Then it scan all corresponding console device by scanning Terminal (built from device supporting Serial I/O instances) devices in TerminalMenu. At last, it save a EFI variable specifed by ConsoleName and gEfiGlobalVariableGuid. @param ConsoleName The name for the console device type. They are usually "ConIn", "ConOut" and "ErrOut". @param ConsoleMenu The console memu which is a list of console devices. @param UpdatePageId The flag specifying which type of console device to be processed. @retval EFI_SUCCESS The function complete successfully. @return The EFI variable can not be saved. See gRT->SetVariable for detail return information. **/ EFI_STATUS Var_UpdateConsoleOption ( IN UINT16 *ConsoleName, IN BM_MENU_OPTION *ConsoleMenu, IN UINT16 UpdatePageId ) { EFI_DEVICE_PATH_PROTOCOL *ConDevicePath; BM_MENU_ENTRY *NewMenuEntry; BM_CONSOLE_CONTEXT *NewConsoleContext; BM_TERMINAL_CONTEXT *NewTerminalContext; EFI_STATUS Status; VENDOR_DEVICE_PATH Vendor; EFI_DEVICE_PATH_PROTOCOL *TerminalDevicePath; UINTN Index; GetEfiGlobalVariable2 (ConsoleName, (VOID**)&ConDevicePath, NULL); if (ConDevicePath != NULL) { EfiLibDeleteVariable (ConsoleName, &gEfiGlobalVariableGuid); FreePool (ConDevicePath); ConDevicePath = NULL; }; // // First add all console input device from console input menu // for (Index = 0; Index < ConsoleMenu->MenuNumber; Index++) { NewMenuEntry = BOpt_GetMenuEntry (ConsoleMenu, Index); NewConsoleContext = (BM_CONSOLE_CONTEXT *) NewMenuEntry->VariableContext; if (NewConsoleContext->IsActive) { ConDevicePath = AppendDevicePathInstance ( ConDevicePath, NewConsoleContext->DevicePath ); } } for (Index = 0; Index < TerminalMenu.MenuNumber; Index++) { NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Index); NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext; if (((NewTerminalContext->IsConIn != 0) && (UpdatePageId == FORM_CON_IN_ID)) || ((NewTerminalContext->IsConOut != 0) && (UpdatePageId == FORM_CON_OUT_ID)) || ((NewTerminalContext->IsStdErr != 0) && (UpdatePageId == FORM_CON_ERR_ID)) ) { Vendor.Header.Type = MESSAGING_DEVICE_PATH; Vendor.Header.SubType = MSG_VENDOR_DP; ASSERT (NewTerminalContext->TerminalType < (sizeof (TerminalTypeGuid) / sizeof (TerminalTypeGuid[0]))); CopyMem ( &Vendor.Guid, &TerminalTypeGuid[NewTerminalContext->TerminalType], sizeof (EFI_GUID) ); SetDevicePathNodeLength (&Vendor.Header, sizeof (VENDOR_DEVICE_PATH)); TerminalDevicePath = AppendDevicePathNode ( NewTerminalContext->DevicePath, (EFI_DEVICE_PATH_PROTOCOL *) &Vendor ); ASSERT (TerminalDevicePath != NULL); ChangeTerminalDevicePath (TerminalDevicePath, TRUE); ConDevicePath = AppendDevicePathInstance ( ConDevicePath, TerminalDevicePath ); } } if (ConDevicePath != NULL) { Status = gRT->SetVariable ( ConsoleName, &gEfiGlobalVariableGuid, VAR_FLAG, GetDevicePathSize (ConDevicePath), ConDevicePath ); if (EFI_ERROR (Status)) { return Status; } } return EFI_SUCCESS; }
/** Create Select language menu in the front page with oneof opcode. @param[in] HiiHandle The hii handle for the Uiapp driver. @param[in] StartOpCodeHandle The opcode handle to save the new opcode. **/ VOID UiCreateLanguageMenu ( IN EFI_HII_HANDLE HiiHandle, IN VOID *StartOpCodeHandle ) { CHAR8 *LangCode; CHAR8 *Lang; UINTN LangSize; CHAR8 *CurrentLang; UINTN OptionCount; CHAR16 *StringBuffer; VOID *OptionsOpCodeHandle; UINTN StringSize; EFI_STATUS Status; EFI_HII_STRING_PROTOCOL *HiiString; Lang = NULL; StringBuffer = NULL; // // Init OpCode Handle and Allocate space for creation of UpdateData Buffer // OptionsOpCodeHandle = HiiAllocateOpCodeHandle (); ASSERT (OptionsOpCodeHandle != NULL); GetEfiGlobalVariable2 (L"PlatformLang", (VOID**)&CurrentLang, NULL); // // Get Support language list from variable. // GetEfiGlobalVariable2 (L"PlatformLangCodes", (VOID**)&gLanguageString, NULL); if (gLanguageString == NULL) { gLanguageString = AllocateCopyPool ( AsciiStrSize ((CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLangCodes)), (CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLangCodes) ); ASSERT (gLanguageString != NULL); } if (gLanguageToken == NULL) { // // Count the language list number. // LangCode = gLanguageString; Lang = AllocatePool (AsciiStrSize (gLanguageString)); ASSERT (Lang != NULL); OptionCount = 0; while (*LangCode != 0) { GetNextLanguage (&LangCode, Lang); OptionCount ++; } // // Allocate extra 1 as the end tag. // gLanguageToken = AllocateZeroPool ((OptionCount + 1) * sizeof (EFI_STRING_ID)); ASSERT (gLanguageToken != NULL); Status = gBS->LocateProtocol (&gEfiHiiStringProtocolGuid, NULL, (VOID **) &HiiString); ASSERT_EFI_ERROR (Status); LangCode = gLanguageString; OptionCount = 0; while (*LangCode != 0) { GetNextLanguage (&LangCode, Lang); StringSize = 0; Status = HiiString->GetString (HiiString, Lang, HiiHandle, PRINTABLE_LANGUAGE_NAME_STRING_ID, StringBuffer, &StringSize, NULL); if (Status == EFI_BUFFER_TOO_SMALL) { StringBuffer = AllocateZeroPool (StringSize); ASSERT (StringBuffer != NULL); Status = HiiString->GetString (HiiString, Lang, HiiHandle, PRINTABLE_LANGUAGE_NAME_STRING_ID, StringBuffer, &StringSize, NULL); ASSERT_EFI_ERROR (Status); } if (EFI_ERROR (Status)) { LangSize = AsciiStrSize (Lang); StringBuffer = AllocatePool (LangSize * sizeof (CHAR16)); ASSERT (StringBuffer != NULL); AsciiStrToUnicodeStrS (Lang, StringBuffer, LangSize); } ASSERT (StringBuffer != NULL); gLanguageToken[OptionCount] = HiiSetString (HiiHandle, 0, StringBuffer, NULL); FreePool (StringBuffer); OptionCount++; } } ASSERT (gLanguageToken != NULL); LangCode = gLanguageString; OptionCount = 0; if (Lang == NULL) { Lang = AllocatePool (AsciiStrSize (gLanguageString)); ASSERT (Lang != NULL); } while (*LangCode != 0) { GetNextLanguage (&LangCode, Lang); if (CurrentLang != NULL && AsciiStrCmp (Lang, CurrentLang) == 0) { HiiCreateOneOfOptionOpCode ( OptionsOpCodeHandle, gLanguageToken[OptionCount], EFI_IFR_OPTION_DEFAULT, EFI_IFR_NUMERIC_SIZE_1, (UINT8) OptionCount ); gCurrentLanguageIndex = (UINT8) OptionCount; } else { HiiCreateOneOfOptionOpCode ( OptionsOpCodeHandle, gLanguageToken[OptionCount], 0, EFI_IFR_NUMERIC_SIZE_1, (UINT8) OptionCount ); } OptionCount++; } if (CurrentLang != NULL) { FreePool (CurrentLang); } FreePool (Lang); HiiCreateOneOfOpCode ( StartOpCodeHandle, FRONT_PAGE_KEY_LANGUAGE, 0, 0, STRING_TOKEN (STR_LANGUAGE_SELECT), STRING_TOKEN (STR_LANGUAGE_SELECT_HELP), EFI_IFR_FLAG_CALLBACK, EFI_IFR_NUMERIC_SIZE_1, OptionsOpCodeHandle, NULL ); }
/** After any operation on Driver####, there will be a discrepancy in DriverOrder. Since some are missing but in DriverOrder, while some are present but are not reflected by DriverOrder. Then a function rebuild DriverOrder from scratch by content from DriverOptionMenu is needed. @retval EFI_SUCCESS The driver order is updated successfully. @return Other status than EFI_SUCCESS if failed to set the "DriverOrder" EFI Variable. **/ EFI_STATUS Var_ChangeDriverOrder ( VOID ) { EFI_STATUS Status; BM_MENU_ENTRY *NewMenuEntry; UINT16 *DriverOrderList; UINT16 *DriverOrderListPtr; UINTN DriverOrderListSize; UINTN Index; DriverOrderList = NULL; DriverOrderListSize = 0; // // First check whether DriverOrder is present in current configuration // GetEfiGlobalVariable2 (L"DriverOrder", (VOID **) &DriverOrderList, &DriverOrderListSize); // // If exists, delete it to hold new DriverOrder // if (DriverOrderList != NULL) { EfiLibDeleteVariable (L"DriverOrder", &gEfiGlobalVariableGuid); FreePool (DriverOrderList); DriverOrderList = NULL; } DriverOrderListSize = DriverOptionMenu.MenuNumber; if (DriverOrderListSize > 0) { DriverOrderList = AllocateZeroPool (DriverOrderListSize * sizeof (UINT16)); ASSERT (DriverOrderList != NULL); DriverOrderListPtr = DriverOrderList; // // Get all current used Driver#### from DriverOptionMenu. // OptionNumber in each BM_LOAD_OPTION is really its // #### value. // for (Index = 0; Index < DriverOrderListSize; Index++) { NewMenuEntry = BOpt_GetMenuEntry (&DriverOptionMenu, Index); *DriverOrderList = (UINT16) NewMenuEntry->OptionNumber; DriverOrderList++; } DriverOrderList = DriverOrderListPtr; // // After building the DriverOrderList, write it back // Status = gRT->SetVariable ( L"DriverOrder", &gEfiGlobalVariableGuid, VAR_FLAG, DriverOrderListSize * sizeof (UINT16), DriverOrderList ); if (EFI_ERROR (Status)) { return Status; } } return EFI_SUCCESS; }
/** Update the legacy BBS boot option. L"LegacyDevOrder" and gEfiLegacyDevOrderVariableGuid EFI Variable is udpated with the new Legacy Boot order. The EFI Variable of "Boot####" and gEfiGlobalVariableGuid is also updated. @param CallbackData The context data for BMM. @return EFI_SUCCESS The function completed successfully. @retval EFI_NOT_FOUND If L"LegacyDevOrder" and gEfiLegacyDevOrderVariableGuid EFI Variable can be found. @retval EFI_OUT_OF_RESOURCES Fail to allocate memory resource **/ EFI_STATUS UpdateBBSOption ( IN LEGACY_BOOT_NV_DATA *NVMapData ) { UINTN Index; UINTN Index2; UINTN CurrentType; VOID *BootOptionVar; CHAR16 VarName[100]; UINTN OptionSize; EFI_STATUS Status; UINT32 *Attribute; LEGACY_MENU_OPTION *OptionMenu; UINT16 *LegacyDev; UINT16 *InitialLegacyDev; UINT8 *VarData; UINTN VarSize; LEGACY_DEV_ORDER_ENTRY *DevOrder; UINT8 *OriginalPtr; UINT8 *DisMap; UINTN Pos; UINTN Bit; UINT16 *NewOrder; UINT16 Tmp; UINT16 *EnBootOption; UINTN EnBootOptionCount; UINT16 *DisBootOption; UINTN DisBootOptionCount; UINTN BufferSize; DisMap = NULL; NewOrder = NULL; CurrentType = 0; DisMap = mLegacyBootOptionPrivate->MaintainMapData->DisableMap; Status = EFI_SUCCESS; // // Update the Variable "LegacyDevOrder" // GetVariable2 (VAR_LEGACY_DEV_ORDER, &gEfiLegacyDevOrderVariableGuid, (VOID **) &VarData, &VarSize); if (VarData == NULL) { return EFI_NOT_FOUND; } OriginalPtr = VarData; while (mBbsType[CurrentType] != BBS_UNKNOWN) { switch (mBbsType[CurrentType]) { case BBS_FLOPPY: OptionMenu = (LEGACY_MENU_OPTION *) &LegacyFDMenu; LegacyDev = NVMapData->LegacyFD; InitialLegacyDev = mLegacyBootOptionPrivate->MaintainMapData->InitialNvData.LegacyFD; BufferSize = sizeof (NVMapData->LegacyFD); break; case BBS_HARDDISK: OptionMenu = (LEGACY_MENU_OPTION *) &LegacyHDMenu; LegacyDev = NVMapData->LegacyHD; InitialLegacyDev = mLegacyBootOptionPrivate->MaintainMapData->InitialNvData.LegacyHD; BufferSize = sizeof (NVMapData->LegacyHD); break; case BBS_CDROM: OptionMenu = (LEGACY_MENU_OPTION *) &LegacyCDMenu; LegacyDev = NVMapData->LegacyCD; InitialLegacyDev = mLegacyBootOptionPrivate->MaintainMapData->InitialNvData.LegacyCD; BufferSize = sizeof (NVMapData->LegacyCD); break; case BBS_EMBED_NETWORK: OptionMenu = (LEGACY_MENU_OPTION *) &LegacyNETMenu; LegacyDev = NVMapData->LegacyNET; InitialLegacyDev = mLegacyBootOptionPrivate->MaintainMapData->InitialNvData.LegacyNET; BufferSize = sizeof (NVMapData->LegacyNET); break; default: ASSERT (mBbsType[CurrentType] == BBS_BEV_DEVICE); OptionMenu = (LEGACY_MENU_OPTION *) &LegacyBEVMenu; LegacyDev = NVMapData->LegacyBEV; InitialLegacyDev = mLegacyBootOptionPrivate->MaintainMapData->InitialNvData.LegacyBEV; BufferSize = sizeof (NVMapData->LegacyBEV); break; } // // Check whether has value changed. // if (CompareMem (LegacyDev, InitialLegacyDev, BufferSize) == 0) { CurrentType++; continue; } DevOrder = (LEGACY_DEV_ORDER_ENTRY *) OriginalPtr; while (VarData < OriginalPtr + VarSize) { if (DevOrder->BbsType == mBbsType[CurrentType]) { break; } VarData += sizeof (BBS_TYPE) + DevOrder->Length; DevOrder = (LEGACY_DEV_ORDER_ENTRY *) VarData; } if (VarData >= OriginalPtr + VarSize) { FreePool (OriginalPtr); return EFI_NOT_FOUND; } NewOrder = AllocateZeroPool (DevOrder->Length - sizeof (DevOrder->Length)); if (NewOrder == NULL) { FreePool (OriginalPtr); return EFI_OUT_OF_RESOURCES; } for (Index = 0; Index < OptionMenu->MenuNumber; Index++) { if (0xFF == LegacyDev[Index]) { break; } NewOrder[Index] = LegacyDev[Index]; } // // Only the enable/disable state of each boot device with same device type can be changed, // so we can count on the index information in DevOrder. // DisMap bit array is the only reliable source to check a device's en/dis state, // so we use DisMap to set en/dis state of each item in NewOrder array // for (Index2 = 0; Index2 < OptionMenu->MenuNumber; Index2++) { Tmp = (UINT16) (DevOrder->Data[Index2] & 0xFF); Pos = Tmp / 8; Bit = 7 - (Tmp % 8); if ((DisMap[Pos] & (1 << Bit)) != 0) { NewOrder[Index] = (UINT16) (0xFF00 | Tmp); Index++; } } CopyMem ( DevOrder->Data, NewOrder, DevOrder->Length - sizeof (DevOrder->Length) ); FreePool (NewOrder); // // Update BootOrder and Boot####.Attribute // // 1. Re-order the Option Number in BootOrder according to Legacy Dev Order // ASSERT (OptionMenu->MenuNumber == DevOrder->Length / sizeof (UINT16) - 1); OrderLegacyBootOption4SameType ( DevOrder->Data, DevOrder->Length / sizeof (UINT16) - 1, &EnBootOption, &EnBootOptionCount, &DisBootOption, &DisBootOptionCount ); // // 2. Deactivate the DisBootOption and activate the EnBootOption // for (Index = 0; Index < DisBootOptionCount; Index++) { UnicodeSPrint (VarName, sizeof (VarName), L"Boot%04x", DisBootOption[Index]); GetEfiGlobalVariable2 (VarName, (VOID **) &BootOptionVar, &OptionSize); if (BootOptionVar != NULL) { Attribute = (UINT32 *) BootOptionVar; *Attribute &= ~LOAD_OPTION_ACTIVE; Status = gRT->SetVariable ( VarName, &gEfiGlobalVariableGuid, VAR_FLAG, OptionSize, BootOptionVar ); FreePool (BootOptionVar); } } for (Index = 0; Index < EnBootOptionCount; Index++) { UnicodeSPrint (VarName, sizeof (VarName), L"Boot%04x", EnBootOption[Index]); GetEfiGlobalVariable2 (VarName, (VOID **) &BootOptionVar, &OptionSize); if (BootOptionVar != NULL) { Attribute = (UINT32 *) BootOptionVar; *Attribute |= LOAD_OPTION_ACTIVE; Status = gRT->SetVariable ( VarName, &gEfiGlobalVariableGuid, VAR_FLAG, OptionSize, BootOptionVar ); FreePool (BootOptionVar); } } FreePool (EnBootOption); FreePool (DisBootOption); CurrentType++; } Status = gRT->SetVariable ( VAR_LEGACY_DEV_ORDER, &gEfiLegacyDevOrderVariableGuid, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE, VarSize, OriginalPtr ); FreePool (OriginalPtr); return Status; }
/** Re-order the Boot Option according to the DevOrder. The routine re-orders the Boot Option in BootOption array according to the order specified by DevOrder. @param DevOrder Pointer to buffer containing the BBS Index, high 8-bit value 0xFF indicating a disabled boot option @param DevOrderCount Count of the BBS Index @param EnBootOption Callee allocated buffer containing the enabled Boot Option Numbers @param EnBootOptionCount Count of the enabled Boot Option Numbers @param DisBootOption Callee allocated buffer containing the disabled Boot Option Numbers @param DisBootOptionCount Count of the disabled Boot Option Numbers **/ VOID OrderLegacyBootOption4SameType ( UINT16 *DevOrder, UINTN DevOrderCount, UINT16 **EnBootOption, UINTN *EnBootOptionCount, UINT16 **DisBootOption, UINTN *DisBootOptionCount ) { EFI_STATUS Status; UINT16 *NewBootOption; UINT16 *BootOrder; UINTN BootOrderSize; UINTN Index; UINTN StartPosition; EFI_BOOT_MANAGER_LOAD_OPTION BootOption; CHAR16 OptionName[sizeof ("Boot####")]; UINT16 *BbsIndexArray; UINT16 *DeviceTypeArray; GetEfiGlobalVariable2 (L"BootOrder", (VOID **) &BootOrder, &BootOrderSize); ASSERT (BootOrder != NULL); BbsIndexArray = AllocatePool (BootOrderSize); DeviceTypeArray = AllocatePool (BootOrderSize); *EnBootOption = AllocatePool (BootOrderSize); *DisBootOption = AllocatePool (BootOrderSize); *DisBootOptionCount = 0; *EnBootOptionCount = 0; Index = 0; ASSERT (*EnBootOption != NULL); ASSERT (*DisBootOption != NULL); for (Index = 0; Index < BootOrderSize / sizeof (UINT16); Index++) { UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", BootOrder[Index]); Status = EfiBootManagerVariableToLoadOption (OptionName, &BootOption); ASSERT_EFI_ERROR (Status); if ((DevicePathType (BootOption.FilePath) == BBS_DEVICE_PATH) && (DevicePathSubType (BootOption.FilePath) == BBS_BBS_DP)) { // // Legacy Boot Option // ASSERT (BootOption.OptionalDataSize == sizeof (LEGACY_BOOT_OPTION_BBS_DATA)); DeviceTypeArray[Index] = ((BBS_BBS_DEVICE_PATH *) BootOption.FilePath)->DeviceType; BbsIndexArray [Index] = ((LEGACY_BOOT_OPTION_BBS_DATA *) BootOption.OptionalData)->BbsIndex; } else { DeviceTypeArray[Index] = BBS_TYPE_UNKNOWN; BbsIndexArray [Index] = 0xFFFF; } EfiBootManagerFreeLoadOption (&BootOption); } // // Record the corresponding Boot Option Numbers according to the DevOrder // Record the EnBootOption and DisBootOption according to the DevOrder // StartPosition = BootOrderSize / sizeof (UINT16); NewBootOption = AllocatePool (DevOrderCount * sizeof (UINT16)); while (DevOrderCount-- != 0) { for (Index = 0; Index < BootOrderSize / sizeof (UINT16); Index++) { if (BbsIndexArray[Index] == (DevOrder[DevOrderCount] & 0xFF)) { StartPosition = MIN (StartPosition, Index); NewBootOption[DevOrderCount] = BootOrder[Index]; if ((DevOrder[DevOrderCount] & 0xFF00) == 0xFF00) { (*DisBootOption)[*DisBootOptionCount] = BootOrder[Index]; (*DisBootOptionCount)++; } else { (*EnBootOption)[*EnBootOptionCount] = BootOrder[Index]; (*EnBootOptionCount)++; } break; } } } // // Overwrite the old BootOption // CopyMem (&BootOrder[StartPosition], NewBootOption, (*DisBootOptionCount + *EnBootOptionCount) * sizeof (UINT16)); Status = gRT->SetVariable ( L"BootOrder", &gEfiGlobalVariableGuid, VAR_FLAG, BootOrderSize, BootOrder ); ASSERT_EFI_ERROR (Status); FreePool (NewBootOption); FreePool (DeviceTypeArray); FreePool (BbsIndexArray); }
/** Worker function to initialize Unicode Collation support. It tries to locate Unicode Collation (2) protocol and matches it with current platform language code. @param AgentHandle The handle used to open Unicode Collation (2) protocol. @param ProtocolGuid The pointer to Unicode Collation (2) protocol GUID. @param VariableName The name of the RFC 4646 or ISO 639-2 language variable. @param DefaultLanguage The default language in case the RFC 4646 or ISO 639-2 language is absent. @retval EFI_SUCCESS The Unicode Collation (2) protocol has been successfully located. @retval Others The Unicode Collation (2) protocol has not been located. **/ EFI_STATUS InitializeUnicodeCollationSupportWorker ( IN EFI_HANDLE AgentHandle, IN EFI_GUID *ProtocolGuid, IN CONST CHAR16 *VariableName, IN CONST CHAR8 *DefaultLanguage ) { EFI_STATUS ReturnStatus; EFI_STATUS Status; UINTN NumHandles; UINTN Index; EFI_HANDLE *Handles; EFI_UNICODE_COLLATION_PROTOCOL *Uci; BOOLEAN Iso639Language; CHAR8 *Language; CHAR8 *BestLanguage; Status = gBS->LocateHandleBuffer ( ByProtocol, ProtocolGuid, NULL, &NumHandles, &Handles ); if (EFI_ERROR (Status)) { return Status; } Iso639Language = (BOOLEAN) (ProtocolGuid == &gEfiUnicodeCollationProtocolGuid); GetEfiGlobalVariable2 (VariableName, (VOID**) &Language, NULL); ReturnStatus = EFI_UNSUPPORTED; for (Index = 0; Index < NumHandles; Index++) { // // Open Unicode Collation Protocol // Status = gBS->OpenProtocol ( Handles[Index], ProtocolGuid, (VOID **) &Uci, AgentHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL ); if (EFI_ERROR (Status)) { continue; } // // Find the best matching matching language from the supported languages // of Unicode Collation (2) protocol. // BestLanguage = GetBestLanguage ( Uci->SupportedLanguages, Iso639Language, (Language == NULL) ? "" : Language, DefaultLanguage, NULL ); if (BestLanguage != NULL) { FreePool (BestLanguage); mUnicodeCollation = Uci; ReturnStatus = EFI_SUCCESS; break; } } if (Language != NULL) { FreePool (Language); } FreePool (Handles); return ReturnStatus; }
/** Initialize HII information for the FrontPage @param InitializeHiiData TRUE if HII elements need to be initialized. @retval EFI_SUCCESS The operation is successful. @retval EFI_DEVICE_ERROR If the dynamic opcode creation failed. **/ EFI_STATUS InitializeFrontPage ( IN BOOLEAN InitializeHiiData ) { EFI_STATUS Status; CHAR8 *LangCode; CHAR8 *Lang; CHAR8 *CurrentLang; UINTN OptionCount; CHAR16 *StringBuffer; EFI_HII_HANDLE HiiHandle; VOID *OptionsOpCodeHandle; VOID *StartOpCodeHandle; VOID *EndOpCodeHandle; EFI_IFR_GUID_LABEL *StartLabel; EFI_IFR_GUID_LABEL *EndLabel; EFI_HII_STRING_PROTOCOL *HiiString; UINTN StringSize; Lang = NULL; StringBuffer = NULL; if (InitializeHiiData) { // // Initialize the Device Manager // InitializeDeviceManager (); // // Initialize the Device Manager // InitializeBootManager (); gCallbackKey = 0; // // Locate Hii relative protocols // Status = gBS->LocateProtocol (&gEfiFormBrowser2ProtocolGuid, NULL, (VOID **) &gFormBrowser2); if (EFI_ERROR (Status)) { return Status; } // // Install Device Path Protocol and Config Access protocol to driver handle // Status = gBS->InstallMultipleProtocolInterfaces ( &gFrontPagePrivate.DriverHandle, &gEfiDevicePathProtocolGuid, &mFrontPageHiiVendorDevicePath, &gEfiHiiConfigAccessProtocolGuid, &gFrontPagePrivate.ConfigAccess, NULL ); ASSERT_EFI_ERROR (Status); // // Publish our HII data // gFrontPagePrivate.HiiHandle = HiiAddPackages ( &gFrontPageFormSetGuid, gFrontPagePrivate.DriverHandle, FrontPageVfrBin, BdsDxeStrings, NULL ); if (gFrontPagePrivate.HiiHandle == NULL) { return EFI_OUT_OF_RESOURCES; } } // // Init OpCode Handle and Allocate space for creation of UpdateData Buffer // StartOpCodeHandle = HiiAllocateOpCodeHandle (); ASSERT (StartOpCodeHandle != NULL); EndOpCodeHandle = HiiAllocateOpCodeHandle (); ASSERT (EndOpCodeHandle != NULL); OptionsOpCodeHandle = HiiAllocateOpCodeHandle (); ASSERT (OptionsOpCodeHandle != NULL); // // Create Hii Extend Label OpCode as the start opcode // StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL)); StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; StartLabel->Number = LABEL_SELECT_LANGUAGE; // // Create Hii Extend Label OpCode as the end opcode // EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL)); EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; EndLabel->Number = LABEL_END; // // Collect the languages from what our current Language support is based on our VFR // HiiHandle = gFrontPagePrivate.HiiHandle; GetEfiGlobalVariable2 (L"PlatformLang", (VOID**)&CurrentLang, NULL); // // Get Support language list from variable. // if (mLanguageString == NULL){ GetEfiGlobalVariable2 (L"PlatformLangCodes", (VOID**)&mLanguageString, NULL); if (mLanguageString == NULL) { mLanguageString = AllocateCopyPool ( AsciiStrSize ((CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLangCodes)), (CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLangCodes) ); ASSERT (mLanguageString != NULL); } } if (gFrontPagePrivate.LanguageToken == NULL) { // // Count the language list number. // LangCode = mLanguageString; Lang = AllocatePool (AsciiStrSize (mLanguageString)); ASSERT (Lang != NULL); OptionCount = 0; while (*LangCode != 0) { GetNextLanguage (&LangCode, Lang); OptionCount ++; } // // Allocate extra 1 as the end tag. // gFrontPagePrivate.LanguageToken = AllocateZeroPool ((OptionCount + 1) * sizeof (EFI_STRING_ID)); ASSERT (gFrontPagePrivate.LanguageToken != NULL); Status = gBS->LocateProtocol (&gEfiHiiStringProtocolGuid, NULL, (VOID **) &HiiString); ASSERT_EFI_ERROR (Status); LangCode = mLanguageString; OptionCount = 0; while (*LangCode != 0) { GetNextLanguage (&LangCode, Lang); StringSize = 0; Status = HiiString->GetString (HiiString, Lang, HiiHandle, PRINTABLE_LANGUAGE_NAME_STRING_ID, StringBuffer, &StringSize, NULL); if (Status == EFI_BUFFER_TOO_SMALL) { StringBuffer = AllocateZeroPool (StringSize); ASSERT (StringBuffer != NULL); Status = HiiString->GetString (HiiString, Lang, HiiHandle, PRINTABLE_LANGUAGE_NAME_STRING_ID, StringBuffer, &StringSize, NULL); ASSERT_EFI_ERROR (Status); } if (EFI_ERROR (Status)) { StringBuffer = AllocatePool (AsciiStrSize (Lang) * sizeof (CHAR16)); ASSERT (StringBuffer != NULL); AsciiStrToUnicodeStr (Lang, StringBuffer); } ASSERT (StringBuffer != NULL); gFrontPagePrivate.LanguageToken[OptionCount] = HiiSetString (HiiHandle, 0, StringBuffer, NULL); FreePool (StringBuffer); OptionCount++; } } ASSERT (gFrontPagePrivate.LanguageToken != NULL); LangCode = mLanguageString; OptionCount = 0; if (Lang == NULL) { Lang = AllocatePool (AsciiStrSize (mLanguageString)); ASSERT (Lang != NULL); } while (*LangCode != 0) { GetNextLanguage (&LangCode, Lang); if (CurrentLang != NULL && AsciiStrCmp (Lang, CurrentLang) == 0) { HiiCreateOneOfOptionOpCode ( OptionsOpCodeHandle, gFrontPagePrivate.LanguageToken[OptionCount], EFI_IFR_OPTION_DEFAULT, EFI_IFR_NUMERIC_SIZE_1, (UINT8) OptionCount ); } else { HiiCreateOneOfOptionOpCode ( OptionsOpCodeHandle, gFrontPagePrivate.LanguageToken[OptionCount], 0, EFI_IFR_NUMERIC_SIZE_1, (UINT8) OptionCount ); } OptionCount++; } if (CurrentLang != NULL) { FreePool (CurrentLang); } FreePool (Lang); HiiCreateOneOfOpCode ( StartOpCodeHandle, FRONT_PAGE_KEY_LANGUAGE, 0, 0, STRING_TOKEN (STR_LANGUAGE_SELECT), STRING_TOKEN (STR_LANGUAGE_SELECT_HELP), EFI_IFR_FLAG_CALLBACK, EFI_IFR_NUMERIC_SIZE_1, OptionsOpCodeHandle, NULL ); Status = HiiUpdateForm ( HiiHandle, &gFrontPageFormSetGuid, FRONT_PAGE_FORM_ID, StartOpCodeHandle, // LABEL_SELECT_LANGUAGE EndOpCodeHandle // LABEL_END ); HiiFreeOpCodeHandle (StartOpCodeHandle); HiiFreeOpCodeHandle (EndOpCodeHandle); HiiFreeOpCodeHandle (OptionsOpCodeHandle); return Status; }
/** Display the permit load device path in the loadable device path list. **/ VOID DisplayLoadPermit( VOID ) { EFI_STATUS Status; CHAR16 *Order; UINTN OrderSize; UINTN ListCount; UINTN Index; UINT8 *Var; UINT8 *VarPtr; CHAR16 VarName[12]; VOID *StartOpCodeHandle; VOID *EndOpCodeHandle; EFI_IFR_GUID_LABEL *StartLabel; EFI_IFR_GUID_LABEL *EndLabel; // // Get DriverOrder. // OrderSize = 0; Status = gRT->GetVariable ( L"DriverOrder", &gEfiGlobalVariableGuid, NULL, &OrderSize, NULL ); if (Status != EFI_BUFFER_TOO_SMALL) { return ; } Order = AllocateZeroPool (OrderSize); if (Order == NULL) { return ; } Status = gRT->GetVariable ( L"DriverOrder", &gEfiGlobalVariableGuid, NULL, &OrderSize, Order ); if (EFI_ERROR (Status)) { return ; } // // Initialize the container for dynamic opcodes. // StartOpCodeHandle = HiiAllocateOpCodeHandle (); ASSERT (StartOpCodeHandle != NULL); EndOpCodeHandle = HiiAllocateOpCodeHandle (); ASSERT (EndOpCodeHandle != NULL); // // Create Hii Extend Label OpCode. // StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode ( StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL) ); StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; StartLabel->Number = LABEL_PERMIT_LOAD_FUNC; EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode ( EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL) ); EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; EndLabel->Number = LABEL_END; // // Add each driver option. // Var = NULL; ListCount = OrderSize / sizeof (UINT16); for (Index = 0; Index < ListCount; Index++) { // // Get driver device path. // UnicodeSPrint (VarName, sizeof (VarName), L"Driver%04x", Order[Index]); GetEfiGlobalVariable2 (VarName, (VOID**)&Var, NULL); if (Var == NULL) { continue; } // // Check whether the driver is already forbidden. // VarPtr = Var; // // Skip attribute. // VarPtr += sizeof (UINT32); // // Skip device path lenth. // VarPtr += sizeof (UINT16); // // Skip descript string. // VarPtr += StrSize ((UINT16 *) VarPtr); if (IsLoadForbidden ((EFI_DEVICE_PATH_PROTOCOL *) VarPtr)) { FreePool (Var); Var = NULL; continue; } AddDevicePath ( KEY_MODIFY_USER | KEY_MODIFY_AP_DP | KEY_LOAD_PERMIT_MODIFY | Order[Index], (EFI_DEVICE_PATH_PROTOCOL *) VarPtr, StartOpCodeHandle ); FreePool (Var); Var = NULL; } HiiUpdateForm ( mCallbackInfo->HiiHandle, // HII handle &gUserProfileManagerGuid, // Formset GUID FORMID_PERMIT_LOAD_DP, // Form ID StartOpCodeHandle, // Label for where to insert opcodes EndOpCodeHandle // Replace data ); HiiFreeOpCodeHandle (StartOpCodeHandle); HiiFreeOpCodeHandle (EndOpCodeHandle); // // Clear Environment. // if (Var != NULL) { FreePool (Var); } FreePool (Order); }
/** Group the legacy boot options in the BootOption. The routine assumes the boot options in the beginning that covers all the device types are ordered properly and re-position the following boot options just after the corresponding boot options with the same device type. For example: 1. Input = [Harddisk1 CdRom2 Efi1 Harddisk0 CdRom0 CdRom1 Harddisk2 Efi0] Assuming [Harddisk1 CdRom2 Efi1] is ordered properly Output = [Harddisk1 Harddisk0 Harddisk2 CdRom2 CdRom0 CdRom1 Efi1 Efi0] 2. Input = [Efi1 Efi0 CdRom1 Harddisk0 Harddisk1 Harddisk2 CdRom0 CdRom2] Assuming [Efi1 Efi0 CdRom1 Harddisk0] is ordered properly Output = [Efi1 Efi0 CdRom1 CdRom0 CdRom2 Harddisk0 Harddisk1 Harddisk2] **/ VOID GroupMultipleLegacyBootOption4SameType ( VOID ) { EFI_STATUS Status; UINTN Index; UINTN DeviceIndex; UINTN DeviceTypeIndex[7]; UINTN *NextIndex; UINT16 OptionNumber; UINT16 *BootOrder; UINTN BootOrderSize; CHAR16 OptionName[sizeof ("Boot####")]; EFI_BOOT_MANAGER_LOAD_OPTION BootOption; SetMem (DeviceTypeIndex, sizeof (DeviceTypeIndex), 0xff); GetEfiGlobalVariable2 (L"BootOrder", (VOID **) &BootOrder, &BootOrderSize); if (BootOrder == NULL) { return; } for (Index = 0; Index < BootOrderSize / sizeof (UINT16); Index++) { UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", BootOrder[Index]); Status = EfiBootManagerVariableToLoadOption (OptionName, &BootOption); ASSERT_EFI_ERROR (Status); if ((DevicePathType (BootOption.FilePath) == BBS_DEVICE_PATH) && (DevicePathSubType (BootOption.FilePath) == BBS_BBS_DP)) { // // Legacy Boot Option // DEBUG ((EFI_D_ERROR, "[BootManagerDxe] ==== Find Legacy Boot Option 0x%x! ==== \n", Index)); ASSERT ((((BBS_BBS_DEVICE_PATH *) BootOption.FilePath)->DeviceType & 0xF) < sizeof (DeviceTypeIndex) / sizeof (DeviceTypeIndex[0])); NextIndex = &DeviceTypeIndex[((BBS_BBS_DEVICE_PATH *) BootOption.FilePath)->DeviceType & 0xF]; if (*NextIndex == (UINTN) -1) { // // *NextIndex is the Index in BootOrder to put the next Option Number for the same type // *NextIndex = Index + 1; } else { // // insert the current boot option before *NextIndex, causing [*Next .. Index] shift right one position // OptionNumber = BootOrder[Index]; CopyMem (&BootOrder[*NextIndex + 1], &BootOrder[*NextIndex], (Index - *NextIndex) * sizeof (UINT16)); BootOrder[*NextIndex] = OptionNumber; // // Update the DeviceTypeIndex array to reflect the right shift operation // for (DeviceIndex = 0; DeviceIndex < sizeof (DeviceTypeIndex) / sizeof (DeviceTypeIndex[0]); DeviceIndex++) { if (DeviceTypeIndex[DeviceIndex] != (UINTN) -1 && DeviceTypeIndex[DeviceIndex] >= *NextIndex) { DeviceTypeIndex[DeviceIndex]++; } } } } EfiBootManagerFreeLoadOption (&BootOption); } gRT->SetVariable ( L"BootOrder", &gEfiGlobalVariableGuid, VAR_FLAG, BootOrderSize, BootOrder ); FreePool (BootOrder); }
/** Get the Option Number that wasn't used. @param LoadOptionType The load option type. @param FreeOptionNumber Return the minimal free option number. @retval EFI_SUCCESS The option number is found and will be returned. @retval EFI_OUT_OF_RESOURCES There is no free option number that can be used. @retval EFI_INVALID_PARAMETER FreeOptionNumber is NULL **/ EFI_STATUS BmGetFreeOptionNumber ( IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE LoadOptionType, OUT UINT16 *FreeOptionNumber ) { UINTN OptionNumber; UINTN Index; UINT16 *OptionOrder; UINTN OptionOrderSize; UINT16 *BootNext; ASSERT (FreeOptionNumber != NULL); ASSERT (LoadOptionType == LoadOptionTypeDriver || LoadOptionType == LoadOptionTypeBoot || LoadOptionType == LoadOptionTypeSysPrep); GetEfiGlobalVariable2 (mBmLoadOptionOrderName[LoadOptionType], (VOID **) &OptionOrder, &OptionOrderSize); ASSERT ((OptionOrder != NULL && OptionOrderSize != 0) || (OptionOrder == NULL && OptionOrderSize == 0)); BootNext = NULL; if (LoadOptionType == LoadOptionTypeBoot) { GetEfiGlobalVariable2 (L"BootNext", (VOID**) &BootNext, NULL); } for (OptionNumber = 0; OptionNumber < OptionOrderSize / sizeof (UINT16) + ((BootNext != NULL) ? 1 : 0); OptionNumber++ ) { // // Search in OptionOrder whether the OptionNumber exists // for (Index = 0; Index < OptionOrderSize / sizeof (UINT16); Index++) { if (OptionNumber == OptionOrder[Index]) { break; } } // // We didn't find it in the ****Order array and it doesn't equal to BootNext // Otherwise, OptionNumber equals to OptionOrderSize / sizeof (UINT16) + 1 // if ((Index == OptionOrderSize / sizeof (UINT16)) && ((BootNext == NULL) || (OptionNumber != *BootNext)) ) { break; } } if (OptionOrder != NULL) { FreePool (OptionOrder); } if (BootNext != NULL) { FreePool (BootNext); } // // When BootOrder & BootNext conver all numbers in the range [0 ... 0xffff], // OptionNumber equals to 0x10000 which is not valid. // ASSERT (OptionNumber <= 0x10000); if (OptionNumber == 0x10000) { return EFI_OUT_OF_RESOURCES; } else { *FreeOptionNumber = (UINT16) OptionNumber; return EFI_SUCCESS; } }
/** Check the image pointed by DevicePath is a boot option or not. @param[in] DevicePath Points to device path. @retval TURE The image pointed by DevicePath is a boot option. @retval FALSE The image pointed by DevicePath is not a boot option. **/ BOOLEAN IsBootOption ( IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath ) { EFI_STATUS Status; UINT16 *BootOrderList; UINTN BootOrderListSize; UINTN Index; CHAR16 StrTemp[20]; UINT8 *OptionBuffer; UINT8 *OptionPtr; EFI_DEVICE_PATH_PROTOCOL *OptionDevicePath; // // Get BootOrder // BootOrderListSize = 0; BootOrderList = NULL; Status = gRT->GetVariable ( L"BootOrder", &gEfiGlobalVariableGuid, NULL, &BootOrderListSize, NULL ); if (Status == EFI_BUFFER_TOO_SMALL) { BootOrderList = AllocateZeroPool (BootOrderListSize); ASSERT (BootOrderList != NULL); Status = gRT->GetVariable ( L"BootOrder", &gEfiGlobalVariableGuid, NULL, &BootOrderListSize, BootOrderList ); } if (EFI_ERROR (Status)) { // // No Boot option // return FALSE; } OptionBuffer = NULL; for (Index = 0; Index < BootOrderListSize / sizeof (UINT16); Index++) { // // Try to find the DevicePath in BootOption // UnicodeSPrint (StrTemp, sizeof (StrTemp), L"Boot%04x", Index); GetEfiGlobalVariable2 (StrTemp, (VOID**)&OptionBuffer, NULL); if (OptionBuffer == NULL) { continue; } // // Check whether the image is forbidden. // OptionPtr = OptionBuffer; // // Skip attribute. // OptionPtr += sizeof (UINT32); // // Skip device path length. // OptionPtr += sizeof (UINT16); // // Skip descript string // OptionPtr += StrSize ((UINT16 *) OptionPtr); // // Now OptionPtr points to Device Path. // OptionDevicePath = (EFI_DEVICE_PATH_PROTOCOL *) OptionPtr; if (CheckDevicePath (DevicePath, OptionDevicePath)) { FreePool (OptionBuffer); OptionBuffer = NULL; return TRUE; } FreePool (OptionBuffer); OptionBuffer = NULL; } if (BootOrderList != NULL) { FreePool (BootOrderList); } return FALSE; }
EFIAPI EfiBootManagerGetLoadOptions ( OUT UINTN *OptionCount, IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE LoadOptionType ) { EFI_STATUS Status; UINT16 *OptionOrder; UINTN OptionOrderSize; UINTN Index; UINTN OptionIndex; EFI_BOOT_MANAGER_LOAD_OPTION *Options; CHAR16 OptionName[BM_OPTION_NAME_LEN]; UINT16 OptionNumber; *OptionCount = 0; if (LoadOptionType == LoadOptionTypeDriver || LoadOptionType == LoadOptionTypeSysPrep || LoadOptionType == LoadOptionTypeBoot) { // // Read the BootOrder, or DriverOrder variable. // GetEfiGlobalVariable2 (mBmLoadOptionOrderName[LoadOptionType], (VOID **) &OptionOrder, &OptionOrderSize); if (OptionOrder == NULL) { return NULL; } *OptionCount = OptionOrderSize / sizeof (UINT16); Options = AllocatePool (*OptionCount * sizeof (EFI_BOOT_MANAGER_LOAD_OPTION)); ASSERT (Options != NULL); OptionIndex = 0; for (Index = 0; Index < *OptionCount; Index++) { OptionNumber = OptionOrder[Index]; UnicodeSPrint (OptionName, sizeof (OptionName), L"%s%04x", mBmLoadOptionName[LoadOptionType], OptionNumber); Status = EfiBootManagerVariableToLoadOption (OptionName, &Options[OptionIndex]); if (EFI_ERROR (Status)) { DEBUG ((EFI_D_INFO, "[Bds] %s doesn't exist - Update ****Order variable to remove the reference!!", OptionName)); EfiBootManagerDeleteLoadOptionVariable (OptionNumber, LoadOptionType); } else { ASSERT (Options[OptionIndex].OptionNumber == OptionNumber); OptionIndex++; } } if (OptionOrder != NULL) { FreePool (OptionOrder); } if (OptionIndex < *OptionCount) { Options = ReallocatePool (*OptionCount * sizeof (EFI_BOOT_MANAGER_LOAD_OPTION), OptionIndex * sizeof (EFI_BOOT_MANAGER_LOAD_OPTION), Options); ASSERT (Options != NULL); *OptionCount = OptionIndex; } } else { return NULL; } return Options; }