VOID UpdateOrderPage ( IN UINT16 UpdatePageId, IN BM_MENU_OPTION *OptionMenu, IN BMM_CALLBACK_DATA *CallbackData ) { BM_MENU_ENTRY *NewMenuEntry; UINT16 Index; IFR_OPTION *IfrOptionList; CallbackData->BmmAskSaveOrNot = TRUE; UpdatePageStart (CallbackData); CreateMenuStringToken (CallbackData, CallbackData->BmmHiiHandle, OptionMenu); EfiZeroMem (CallbackData->BmmFakeNvData.OptionOrder, 100); IfrOptionList = EfiAllocateZeroPool (sizeof (IFR_OPTION) * OptionMenu->MenuNumber); if (NULL == IfrOptionList) { return ; } for (Index = 0; Index < OptionMenu->MenuNumber; Index++) { NewMenuEntry = BOpt_GetMenuEntry (OptionMenu, Index); IfrOptionList[Index].StringToken = NewMenuEntry->DisplayStringToken; IfrOptionList[Index].Value.u8 = (UINT8) (NewMenuEntry->OptionNumber + 1); IfrOptionList[Index].Flags = 0; CallbackData->BmmFakeNvData.OptionOrder[Index] = IfrOptionList[Index].Value.u8; } if (OptionMenu->MenuNumber > 0) { CreateOrderedListOpCode ( OPTION_ORDER_QUESTION_ID, VARSTORE_ID_BOOT_MAINT, OPTION_ORDER_VAR_OFFSET, STRING_TOKEN (STR_CHANGE_ORDER), STRING_TOKEN (STR_CHANGE_ORDER), 0, 0, EFI_IFR_NUMERIC_SIZE_1, 100, IfrOptionList, OptionMenu->MenuNumber, &gUpdateData ); } SafeFreePool (IfrOptionList); UpdatePageEnd (CallbackData); EfiCopyMem ( CallbackData->BmmOldFakeNVData.OptionOrder, CallbackData->BmmFakeNvData.OptionOrder, 100 ); }
VOID GetConsoleOutMode ( IN BMM_CALLBACK_DATA *CallbackData ) /*++ Routine Description: Get mode number according to column and row Arguments: CallbackData - BMM_CALLBACK_DATA Returns: None. --*/ { UINTN Col; UINTN Row; UINTN CurrentCol; UINTN CurrentRow; UINTN Mode; UINTN MaxMode; EFI_STATUS Status; CONSOLE_OUT_MODE *ModeInfo; EFI_SIMPLE_TEXT_OUT_PROTOCOL *ConOut; ConOut = gST->ConOut; MaxMode = (UINTN) (ConOut->Mode->MaxMode); ModeInfo = EfiLibGetVariable (VarConOutMode, &gEfiGenericVariableGuid); if (ModeInfo != NULL) { CurrentCol = ModeInfo->Column; CurrentRow = ModeInfo->Row; for (Mode = 0; Mode < MaxMode; Mode++) { Status = ConOut->QueryMode (ConOut, Mode, &Col, &Row); if (!EFI_ERROR(Status)) { if (CurrentCol == Col && CurrentRow == Row) { CallbackData->BmmFakeNvData.ConsoleOutMode = (UINT16) Mode; break; } } } } SafeFreePool (ModeInfo); }
EFI_STATUS BOpt_FindFileSystem ( IN BMM_CALLBACK_DATA *CallbackData ) /*++ Routine Description Find file systems for current Extensible Firmware Including Handles that support Simple File System protocol, Load File protocol. Building up the FileSystem Menu for user selection All file system will be stored in FsOptionMenu for future use. Arguments: CallbackData - BMM context data Returns: EFI_SUCCESS - Success find the file system EFI_OUT_OF_RESOURCES - Can not create menu entry --*/ { UINTN NoBlkIoHandles; UINTN NoSimpleFsHandles; UINTN NoLoadFileHandles; EFI_HANDLE *BlkIoHandle; EFI_HANDLE *SimpleFsHandle; EFI_HANDLE *LoadFileHandle; UINT16 *VolumeLabel; EFI_BLOCK_IO_PROTOCOL *BlkIo; UINTN Index; EFI_STATUS Status; BM_MENU_ENTRY *MenuEntry; BM_FILE_CONTEXT *FileContext; UINT16 *TempStr; UINTN OptionNumber; VOID *Buffer; EFI_LEGACY_BIOS_PROTOCOL *LegacyBios; UINT16 DeviceType; BBS_BBS_DEVICE_PATH BbsDevicePathNode; EFI_DEVICE_PATH_PROTOCOL *DevicePath; BOOLEAN RemovableMedia; NoSimpleFsHandles = 0; NoLoadFileHandles = 0; OptionNumber = 0; InitializeListHead (&FsOptionMenu.Head); // // Locate Handles that support BlockIo protocol // Status = gBS->LocateHandleBuffer ( ByProtocol, &gEfiBlockIoProtocolGuid, NULL, &NoBlkIoHandles, &BlkIoHandle ); if (!EFI_ERROR (Status)) { for (Index = 0; Index < NoBlkIoHandles; Index++) { Status = gBS->HandleProtocol ( BlkIoHandle[Index], &gEfiBlockIoProtocolGuid, &BlkIo ); if (EFI_ERROR (Status)) { continue; } // // Issue a dummy read to trigger reinstall of BlockIo protocol for removable media // if (BlkIo->Media->RemovableMedia) { Buffer = EfiAllocateZeroPool (BlkIo->Media->BlockSize); if (NULL == Buffer) { SafeFreePool (BlkIoHandle); return EFI_OUT_OF_RESOURCES; } BlkIo->ReadBlocks ( BlkIo, BlkIo->Media->MediaId, 0, BlkIo->Media->BlockSize, Buffer ); SafeFreePool (Buffer); } } SafeFreePool (BlkIoHandle); } // // Locate Handles that support Simple File System protocol // Status = gBS->LocateHandleBuffer ( ByProtocol, &gEfiSimpleFileSystemProtocolGuid, NULL, &NoSimpleFsHandles, &SimpleFsHandle ); if (!EFI_ERROR (Status)) { // // Find all the instances of the File System prototocol // for (Index = 0; Index < NoSimpleFsHandles; Index++) { Status = gBS->HandleProtocol ( SimpleFsHandle[Index], &gEfiBlockIoProtocolGuid, &BlkIo ); if (EFI_ERROR (Status)) { // // If no block IO exists assume it's NOT a removable media // RemovableMedia = FALSE; } else { // // If block IO exists check to see if it's remobable media // RemovableMedia = BlkIo->Media->RemovableMedia; } // // Allocate pool for this load option // MenuEntry = BOpt_CreateMenuEntry (BM_FILE_CONTEXT_SELECT); if (NULL == MenuEntry) { SafeFreePool (SimpleFsHandle); return EFI_OUT_OF_RESOURCES; } FileContext = (BM_FILE_CONTEXT *) MenuEntry->VariableContext; FileContext->Handle = SimpleFsHandle[Index]; MenuEntry->OptionNumber = Index; FileContext->FHandle = EfiLibOpenRoot (FileContext->Handle); if (!FileContext->FHandle) { BOpt_DestroyMenuEntry (MenuEntry); continue; } MenuEntry->HelpString = DevicePathToStr (EfiDevicePathFromHandle (FileContext->Handle)); FileContext->Info = EfiLibFileSystemVolumeLabelInfo (FileContext->FHandle); FileContext->FileName = EfiStrDuplicate (L"\\"); FileContext->DevicePath = EfiFileDevicePath ( FileContext->Handle, FileContext->FileName ); FileContext->IsDir = TRUE; FileContext->IsRoot = TRUE; FileContext->IsRemovableMedia = FALSE; FileContext->IsLoadFile = FALSE; // // Get current file system's Volume Label // if (FileContext->Info == NULL) { VolumeLabel = L"NO FILE SYSTEM INFO"; } else { if (FileContext->Info->VolumeLabel == NULL) { VolumeLabel = L"NULL VOLUME LABEL"; } else { VolumeLabel = FileContext->Info->VolumeLabel; if (*VolumeLabel == 0x0000) { VolumeLabel = L"NO VOLUME LABEL"; } } } TempStr = MenuEntry->HelpString; MenuEntry->DisplayString = EfiAllocateZeroPool (MAX_CHAR); ASSERT (MenuEntry->DisplayString != NULL); SPrint ( MenuEntry->DisplayString, MAX_CHAR, L"%s, [%s]", VolumeLabel, TempStr ); OptionNumber++; InsertTailList (&FsOptionMenu.Head, &MenuEntry->Link); } } if (NoSimpleFsHandles != 0) { SafeFreePool (SimpleFsHandle); } // // Searching for handles that support Load File protocol // Status = gBS->LocateHandleBuffer ( ByProtocol, &gEfiLoadFileProtocolGuid, NULL, &NoLoadFileHandles, &LoadFileHandle ); if (!EFI_ERROR (Status)) { for (Index = 0; Index < NoLoadFileHandles; Index++) { MenuEntry = BOpt_CreateMenuEntry (BM_FILE_CONTEXT_SELECT); if (NULL == MenuEntry) { SafeFreePool (LoadFileHandle); return EFI_OUT_OF_RESOURCES; } FileContext = (BM_FILE_CONTEXT *) MenuEntry->VariableContext; FileContext->IsRemovableMedia = FALSE; FileContext->IsLoadFile = TRUE; FileContext->Handle = LoadFileHandle[Index]; FileContext->IsRoot = TRUE; FileContext->DevicePath = EfiDevicePathFromHandle (FileContext->Handle); MenuEntry->HelpString = DevicePathToStr (FileContext->DevicePath); TempStr = MenuEntry->HelpString; MenuEntry->DisplayString = EfiAllocateZeroPool (MAX_CHAR); ASSERT (MenuEntry->DisplayString != NULL); SPrint ( MenuEntry->DisplayString, MAX_CHAR, L"Load File [%s]", TempStr ); MenuEntry->OptionNumber = OptionNumber; OptionNumber++; InsertTailList (&FsOptionMenu.Head, &MenuEntry->Link); } } if (NoLoadFileHandles != 0) { SafeFreePool (LoadFileHandle); } // // Add Legacy Boot Option Support Here // Status = gBS->LocateProtocol ( &gEfiLegacyBiosProtocolGuid, NULL, &LegacyBios ); if (!EFI_ERROR (Status)) { for (Index = BBS_TYPE_FLOPPY; Index <= BBS_TYPE_EMBEDDED_NETWORK; Index++) { MenuEntry = BOpt_CreateMenuEntry (BM_FILE_CONTEXT_SELECT); if (NULL == MenuEntry) { return EFI_OUT_OF_RESOURCES; } FileContext = (BM_FILE_CONTEXT *) MenuEntry->VariableContext; FileContext->IsRemovableMedia = FALSE; FileContext->IsLoadFile = TRUE; FileContext->IsBootLegacy = TRUE; DeviceType = (UINT16) Index; BbsDevicePathNode.Header.Type = BBS_DEVICE_PATH; BbsDevicePathNode.Header.SubType = BBS_BBS_DP; SetDevicePathNodeLength ( &BbsDevicePathNode.Header, sizeof (BBS_BBS_DEVICE_PATH) ); BbsDevicePathNode.DeviceType = DeviceType; BbsDevicePathNode.StatusFlag = 0; BbsDevicePathNode.String[0] = 0; DevicePath = EfiAppendDevicePathNode ( EndDevicePath, (EFI_DEVICE_PATH_PROTOCOL *) &BbsDevicePathNode ); FileContext->DevicePath = DevicePath; MenuEntry->HelpString = DevicePathToStr (FileContext->DevicePath); TempStr = MenuEntry->HelpString; MenuEntry->DisplayString = EfiAllocateZeroPool (MAX_CHAR); ASSERT (MenuEntry->DisplayString != NULL); SPrint ( MenuEntry->DisplayString, MAX_CHAR, L"Boot Legacy [%s]", TempStr ); MenuEntry->OptionNumber = OptionNumber; OptionNumber++; InsertTailList (&FsOptionMenu.Head, &MenuEntry->Link); } } // // Remember how many file system options are here // FsOptionMenu.MenuNumber = OptionNumber; return EFI_SUCCESS; }
/** Dump performance data. @param[in] ImageHandle The image handle. @param[in] SystemTable The system table. @retval EFI_SUCCESS Command completed successfully. @retval EFI_INVALID_PARAMETER Command usage error. @retval EFI_ABORTED The user aborts the operation. @retval value Unknown error. **/ EFI_STATUS EFIAPI InitializeDp ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { UINT64 Freq; UINT64 Ticker; UINT32 ListIndex; LIST_ENTRY *ParamPackage; CONST CHAR16 *CmdLineArg; EFI_STRING StringPtr; UINTN Number2Display; EFI_STATUS Status; BOOLEAN SummaryMode; BOOLEAN VerboseMode; BOOLEAN AllMode; BOOLEAN RawMode; BOOLEAN TraceMode; BOOLEAN ProfileMode; BOOLEAN ExcludeMode; BOOLEAN CumulativeMode; CONST CHAR16 *CustomCumulativeToken; PERF_CUM_DATA *CustomCumulativeData; EFI_STRING StringDpOptionQh; EFI_STRING StringDpOptionLh; EFI_STRING StringDpOptionUh; EFI_STRING StringDpOptionLv; EFI_STRING StringDpOptionUs; EFI_STRING StringDpOptionLs; EFI_STRING StringDpOptionUa; EFI_STRING StringDpOptionUr; EFI_STRING StringDpOptionUt; EFI_STRING StringDpOptionUp; EFI_STRING StringDpOptionLx; EFI_STRING StringDpOptionLn; EFI_STRING StringDpOptionLt; EFI_STRING StringDpOptionLi; EFI_STRING StringDpOptionLc; SummaryMode = FALSE; VerboseMode = FALSE; AllMode = FALSE; RawMode = FALSE; TraceMode = FALSE; ProfileMode = FALSE; ExcludeMode = FALSE; CumulativeMode = FALSE; CustomCumulativeData = NULL; StringDpOptionQh = NULL; StringDpOptionLh = NULL; StringDpOptionUh = NULL; StringDpOptionLv = NULL; StringDpOptionUs = NULL; StringDpOptionLs = NULL; StringDpOptionUa = NULL; StringDpOptionUr = NULL; StringDpOptionUt = NULL; StringDpOptionUp = NULL; StringDpOptionLx = NULL; StringDpOptionLn = NULL; StringDpOptionLt = NULL; StringDpOptionLi = NULL; StringDpOptionLc = NULL; StringPtr = NULL; // Get DP's entry time as soon as possible. // This is used as the Shell-Phase end time. // Ticker = GetPerformanceCounter (); // Register our string package with HII and return the handle to it. // gHiiHandle = HiiAddPackages (&gEfiCallerIdGuid, ImageHandle, DPStrings, NULL); ASSERT (gHiiHandle != NULL); // Initial the command list // InitialShellParamList (); /**************************************************************************** **** Process Command Line arguments **** ****************************************************************************/ Status = ShellCommandLineParse (DpParamList, &ParamPackage, NULL, TRUE); if (EFI_ERROR(Status)) { PrintToken (STRING_TOKEN (STR_DP_INVALID_ARG)); ShowHelp(); } else { StringDpOptionQh = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_QH), NULL); StringDpOptionLh = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_LH), NULL); StringDpOptionUh = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_UH), NULL); if (ShellCommandLineGetFlag (ParamPackage, StringDpOptionQh) || ShellCommandLineGetFlag (ParamPackage, StringDpOptionLh) || ShellCommandLineGetFlag (ParamPackage, StringDpOptionUh)) { ShowHelp(); } else { StringDpOptionLv = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_LV), NULL); StringDpOptionUs = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_US), NULL); StringDpOptionLs = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_LS), NULL); StringDpOptionUa = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_UA), NULL); StringDpOptionUr = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_UR), NULL); StringDpOptionUt = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_UT), NULL); StringDpOptionUp = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_UP), NULL); StringDpOptionLx = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_LX), NULL); StringDpOptionLn = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_LN), NULL); StringDpOptionLt = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_LT), NULL); StringDpOptionLi = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_LI), NULL); StringDpOptionLc = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_LC), NULL); // Boolean Options // VerboseMode = ShellCommandLineGetFlag (ParamPackage, StringDpOptionLv); SummaryMode = (BOOLEAN) (ShellCommandLineGetFlag (ParamPackage, StringDpOptionUs) || ShellCommandLineGetFlag (ParamPackage, StringDpOptionLs)); AllMode = ShellCommandLineGetFlag (ParamPackage, StringDpOptionUa); RawMode = ShellCommandLineGetFlag (ParamPackage, StringDpOptionUr); #if PROFILING_IMPLEMENTED TraceMode = ShellCommandLineGetFlag (ParamPackage, StringDpOptionUt); ProfileMode = ShellCommandLineGetFlag (ParamPackage, StringDpOptionUp); #endif // PROFILING_IMPLEMENTED ExcludeMode = ShellCommandLineGetFlag (ParamPackage, StringDpOptionLx); mShowId = ShellCommandLineGetFlag (ParamPackage, StringDpOptionLi); CumulativeMode = ShellCommandLineGetFlag (ParamPackage, StringDpOptionLc); // Options with Values CmdLineArg = ShellCommandLineGetValue (ParamPackage, StringDpOptionLn); if (CmdLineArg == NULL) { Number2Display = DEFAULT_DISPLAYCOUNT; } else { Number2Display = StrDecimalToUintn(CmdLineArg); if (Number2Display == 0) { Number2Display = MAXIMUM_DISPLAYCOUNT; } } CmdLineArg = ShellCommandLineGetValue (ParamPackage, StringDpOptionLt); if (CmdLineArg == NULL) { mInterestThreshold = DEFAULT_THRESHOLD; // 1ms := 1,000 us } else { mInterestThreshold = StrDecimalToUint64(CmdLineArg); } // Handle Flag combinations and default behaviors // If both TraceMode and ProfileMode are FALSE, set them both to TRUE if ((! TraceMode) && (! ProfileMode)) { TraceMode = TRUE; #if PROFILING_IMPLEMENTED ProfileMode = TRUE; #endif // PROFILING_IMPLEMENTED } // // Init the custom cumulative data. // CustomCumulativeToken = ShellCommandLineGetValue (ParamPackage, StringDpOptionLc); if (CustomCumulativeToken != NULL) { CustomCumulativeData = AllocateZeroPool (sizeof (PERF_CUM_DATA)); ASSERT (CustomCumulativeData != NULL); CustomCumulativeData->MinDur = 0; CustomCumulativeData->MaxDur = 0; CustomCumulativeData->Count = 0; CustomCumulativeData->Duration = 0; CustomCumulativeData->Name = AllocateZeroPool (StrLen (CustomCumulativeToken) + 1); UnicodeStrToAsciiStr (CustomCumulativeToken, CustomCumulativeData->Name); } /**************************************************************************** **** Timer specific processing **** ****************************************************************************/ // Get the Performance counter characteristics: // Freq = Frequency in Hz // StartCount = Value loaded into the counter when it starts counting // EndCount = Value counter counts to before it needs to be reset // Freq = GetPerformanceCounterProperties (&TimerInfo.StartCount, &TimerInfo.EndCount); // Convert the Frequency from Hz to KHz TimerInfo.Frequency = (UINT32)DivU64x32 (Freq, 1000); // Determine in which direction the performance counter counts. TimerInfo.CountUp = (BOOLEAN) (TimerInfo.EndCount >= TimerInfo.StartCount); /**************************************************************************** **** Print heading **** ****************************************************************************/ // print DP's build version PrintToken (STRING_TOKEN (STR_DP_BUILD_REVISION), DP_MAJOR_VERSION, DP_MINOR_VERSION); // print performance timer characteristics PrintToken (STRING_TOKEN (STR_DP_KHZ), TimerInfo.Frequency); // Print Timer frequency in KHz if ((VerboseMode) && (! RawMode) ) { StringPtr = HiiGetString (gHiiHandle, (EFI_STRING_ID) (TimerInfo.CountUp ? STRING_TOKEN (STR_DP_UP) : STRING_TOKEN (STR_DP_DOWN)), NULL); ASSERT (StringPtr != NULL); PrintToken (STRING_TOKEN (STR_DP_TIMER_PROPERTIES), // Print Timer count range and direction StringPtr, TimerInfo.StartCount, TimerInfo.EndCount ); PrintToken (STRING_TOKEN (STR_DP_VERBOSE_THRESHOLD), mInterestThreshold); } /* ************************************************************************** **** Print Sections based on command line options **** **** Option modes have the following priority: **** v Verbose -- Valid in combination with any other options **** t Threshold -- Modifies All, Raw, and Cooked output **** Default is 0 for All and Raw mode **** Default is DEFAULT_THRESHOLD for "Cooked" mode **** n Number2Display Used by All and Raw mode. Otherwise ignored. **** A All -- R and S options are ignored **** R Raw -- S option is ignored **** s Summary -- Modifies "Cooked" output only **** Cooked (Default) **** **** The All, Raw, and Cooked modes are modified by the Trace and Profile **** options. **** !T && !P := (0) Default, Both are displayed **** T && !P := (1) Only Trace records are displayed **** !T && P := (2) Only Profile records are displayed **** T && P := (3) Same as Default, both are displayed ****************************************************************************/ GatherStatistics (CustomCumulativeData); if (CumulativeMode) { ProcessCumulative (CustomCumulativeData); } else if (AllMode) { if (TraceMode) { Status = DumpAllTrace( Number2Display, ExcludeMode); if (Status == EFI_ABORTED) { goto Done; } } if (ProfileMode) { DumpAllProfile( Number2Display, ExcludeMode); } } else if (RawMode) { if (TraceMode) { Status = DumpRawTrace( Number2Display, ExcludeMode); if (Status == EFI_ABORTED) { goto Done; } } if (ProfileMode) { DumpRawProfile( Number2Display, ExcludeMode); } } else { //------------- Begin Cooked Mode Processing if (TraceMode) { ProcessPhases ( Ticker ); if ( ! SummaryMode) { Status = ProcessHandles ( ExcludeMode); if (Status == EFI_ABORTED) { goto Done; } Status = ProcessPeims (); if (Status == EFI_ABORTED) { goto Done; } Status = ProcessGlobal (); if (Status == EFI_ABORTED) { goto Done; } ProcessCumulative (NULL); } } if (ProfileMode) { DumpAllProfile( Number2Display, ExcludeMode); } } //------------- End of Cooked Mode Processing if ( VerboseMode || SummaryMode) { DumpStatistics(); } } } Done: // // Free the memory allocate from HiiGetString // ListIndex = 0; while (DpParamList[ListIndex].Name != NULL) { FreePool (DpParamList[ListIndex].Name); ListIndex ++; } FreePool (DpParamList); SafeFreePool (StringDpOptionQh); SafeFreePool (StringDpOptionLh); SafeFreePool (StringDpOptionUh); SafeFreePool (StringDpOptionLv); SafeFreePool (StringDpOptionUs); SafeFreePool (StringDpOptionLs); SafeFreePool (StringDpOptionUa); SafeFreePool (StringDpOptionUr); SafeFreePool (StringDpOptionUt); SafeFreePool (StringDpOptionUp); SafeFreePool (StringDpOptionLx); SafeFreePool (StringDpOptionLn); SafeFreePool (StringDpOptionLt); SafeFreePool (StringDpOptionLi); SafeFreePool (StringDpOptionLc); SafeFreePool (StringPtr); SafeFreePool (mPrintTokenBuffer); if (CustomCumulativeData != NULL) { SafeFreePool (CustomCumulativeData->Name); } SafeFreePool (CustomCumulativeData); HiiRemovePackages (gHiiHandle); return Status; }
EFI_STATUS LocateSerialIo ( VOID ) /*++ Routine Description: Build a list containing all serial devices Arguments: Returns: --*/ { UINT8 *Ptr; UINTN Index; UINTN Index2; UINTN NoHandles; EFI_HANDLE *Handles; EFI_STATUS Status; ACPI_HID_DEVICE_PATH *Acpi; EFI_DEVICE_PATH_PROTOCOL *DevicePath; UINT32 Match; EFI_SERIAL_IO_PROTOCOL *SerialIo; EFI_DEVICE_PATH_PROTOCOL *OutDevicePath; EFI_DEVICE_PATH_PROTOCOL *InpDevicePath; EFI_DEVICE_PATH_PROTOCOL *ErrDevicePath; BM_MENU_ENTRY *NewMenuEntry; BM_TERMINAL_CONTEXT *NewTerminalContext; EFI_DEVICE_PATH_PROTOCOL *NewDevicePath; VENDOR_DEVICE_PATH Vendor; // // Get all handles that have SerialIo protocol installed // InitializeListHead (&TerminalMenu.Head); TerminalMenu.MenuNumber = 0; Status = gBS->LocateHandleBuffer ( ByProtocol, &gEfiSerialIoProtocolGuid, NULL, &NoHandles, &Handles ); if (EFI_ERROR (Status)) { // // No serial ports present // return EFI_UNSUPPORTED; } // // Sort Uart handles array with Acpi->UID from low to high // then Terminal menu can be built from low Acpi->UID to high Acpi->UID // SortedUartHandle (Handles, NoHandles); for (Index = 0; Index < NoHandles; Index++) { // // Check to see whether the handle has DevicePath Protocol installed // gBS->HandleProtocol ( Handles[Index], &gEfiDevicePathProtocolGuid, &DevicePath ); Ptr = (UINT8 *) DevicePath; while (*Ptr != END_DEVICE_PATH_TYPE) { Ptr++; } Ptr = Ptr - sizeof (UART_DEVICE_PATH) - sizeof (ACPI_HID_DEVICE_PATH); Acpi = (ACPI_HID_DEVICE_PATH *) Ptr; Match = EISA_PNP_ID (0x0501); if (EfiCompareMem (&Acpi->HID, &Match, sizeof (UINT32)) == 0) { NewMenuEntry = BOpt_CreateMenuEntry (BM_TERMINAL_CONTEXT_SELECT); if (!NewMenuEntry) { SafeFreePool (Handles); return EFI_OUT_OF_RESOURCES; } NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext; EfiCopyMem (&NewMenuEntry->OptionNumber, &Acpi->UID, sizeof (UINT32)); NewTerminalContext->DevicePath = DevicePathInstanceDup (DevicePath); // // BugBug: I have no choice, calling EfiLibStrFromDatahub will hang the system! // coz' the misc data for each platform is not correct, actually it's the device path stored in // datahub which is not completed, so a searching for end of device path will enter a // dead-loop. // NewMenuEntry->DisplayString = EfiLibStrFromDatahub (DevicePath); if (NULL == NewMenuEntry->DisplayString) { NewMenuEntry->DisplayString = DevicePathToStr (DevicePath); } NewMenuEntry->HelpString = NULL; gBS->HandleProtocol ( Handles[Index], &gEfiSerialIoProtocolGuid, &SerialIo ); EfiCopyMem ( &NewTerminalContext->BaudRate, &SerialIo->Mode->BaudRate, sizeof (UINT64) ); EfiCopyMem ( &NewTerminalContext->DataBits, &SerialIo->Mode->DataBits, sizeof (UINT8) ); EfiCopyMem ( &NewTerminalContext->Parity, &SerialIo->Mode->Parity, sizeof (UINT8) ); EfiCopyMem ( &NewTerminalContext->StopBits, &SerialIo->Mode->StopBits, sizeof (UINT8) ); InsertTailList (&TerminalMenu.Head, &NewMenuEntry->Link); TerminalMenu.MenuNumber++; } } SafeFreePool (Handles); // // Get L"ConOut", L"ConIn" and L"ErrOut" from the Var // OutDevicePath = EfiLibGetVariable (L"ConOut", &gEfiGlobalVariableGuid); InpDevicePath = EfiLibGetVariable (L"ConIn", &gEfiGlobalVariableGuid); ErrDevicePath = EfiLibGetVariable (L"ErrOut", &gEfiGlobalVariableGuid); if (OutDevicePath) { UpdateComAttributeFromVariable (OutDevicePath); } if (InpDevicePath) { UpdateComAttributeFromVariable (InpDevicePath); } if (ErrDevicePath) { UpdateComAttributeFromVariable (ErrDevicePath); } for (Index = 0; Index < TerminalMenu.MenuNumber; Index++) { NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Index); if (NULL == NewMenuEntry) { return EFI_NOT_FOUND; } NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext; NewTerminalContext->TerminalType = 0; NewTerminalContext->IsConIn = FALSE; NewTerminalContext->IsConOut = FALSE; NewTerminalContext->IsStdErr = FALSE; Vendor.Header.Type = MESSAGING_DEVICE_PATH; Vendor.Header.SubType = MSG_VENDOR_DP; for (Index2 = 0; Index2 < 4; Index2++) { EfiCopyMem (&Vendor.Guid, &Guid[Index2], sizeof (EFI_GUID)); SetDevicePathNodeLength (&Vendor.Header, sizeof (VENDOR_DEVICE_PATH)); NewDevicePath = EfiAppendDevicePathNode ( NewTerminalContext->DevicePath, (EFI_DEVICE_PATH_PROTOCOL *) &Vendor ); SafeFreePool (NewMenuEntry->HelpString); // // NewMenuEntry->HelpString = DevicePathToStr (NewDevicePath); // NewMenuEntry->DisplayString = NewMenuEntry->HelpString; // NewMenuEntry->HelpString = NULL; if (BdsLibMatchDevicePaths (OutDevicePath, NewDevicePath)) { NewTerminalContext->IsConOut = TRUE; NewTerminalContext->TerminalType = (UINT8) Index2; } if (BdsLibMatchDevicePaths (InpDevicePath, NewDevicePath)) { NewTerminalContext->IsConIn = TRUE; NewTerminalContext->TerminalType = (UINT8) Index2; } if (BdsLibMatchDevicePaths (ErrDevicePath, NewDevicePath)) { NewTerminalContext->IsStdErr = TRUE; NewTerminalContext->TerminalType = (UINT8) Index2; } } } 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; }
/** Gather and print ALL Trace Records. Displays all "interesting" Trace measurements in order.<BR> The number of records displayed is controlled by: - records with a duration less than mInterestThreshold microseconds are not displayed. - No more than Limit records are displayed. A Limit of zero will not limit the output. - If the ExcludeFlag is TRUE, records matching entries in the CumData array are not displayed. @pre The mInterestThreshold global variable is set to the shortest duration to be printed. The mGaugeString and mUnicodeToken global arrays are used for temporary string storage. They must not be in use by a calling function. @param[in] Limit The number of records to print. Zero is ALL. @param[in] ExcludeFlag TRUE to exclude individual Cumulative items from display. **/ VOID DumpAllTrace( IN UINTN Limit, IN BOOLEAN ExcludeFlag ) { MEASUREMENT_RECORD Measurement; UINT64 ElapsedTime; UINT64 Duration; const CHAR16 *IncFlag; UINTN LogEntryKey; UINTN Count; UINTN Index; UINTN TIndex; EFI_HANDLE *HandleBuffer; UINTN Size; EFI_HANDLE TempHandle; EFI_STATUS Status; EFI_STRING StringPtrUnknown; StringPtrUnknown = HiiGetString (gHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL); IncFlag = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_SECTION_ALL), NULL); PrintToken( STRING_TOKEN (STR_DP_SECTION_HEADER), (IncFlag == NULL) ? StringPtrUnknown : IncFlag); FreePool (StringPtrUnknown); // Get Handle information // Size = 0; HandleBuffer = &TempHandle; Status = gBS->LocateHandle (AllHandles, NULL, NULL, &Size, &TempHandle); if (Status == EFI_BUFFER_TOO_SMALL) { HandleBuffer = AllocatePool (Size); ASSERT (HandleBuffer != NULL); if (HandleBuffer == NULL) { return; } Status = gBS->LocateHandle (AllHandles, NULL, NULL, &Size, HandleBuffer); } if (EFI_ERROR (Status)) { PrintToken (STRING_TOKEN (STR_DP_HANDLES_ERROR), Status); } else { // We have successfully populated the HandleBuffer // Display ALL Measurement Records // Up to Limit lines displayed // Display only records with Elapsed times >= mInterestThreshold // Display driver names in Module field for records with Handles. // if (mShowId) { PrintToken (STRING_TOKEN (STR_DP_ALL_HEADR2) ); PrintToken (STRING_TOKEN (STR_DP_ALL_DASHES2) ); } else { PrintToken (STRING_TOKEN (STR_DP_ALL_HEADR) ); PrintToken (STRING_TOKEN (STR_DP_DASHES) ); } LogEntryKey = 0; Count = 0; Index = 0; while ( WITHIN_LIMIT(Count, Limit) && ((LogEntryKey = GetPerformanceMeasurementEx ( LogEntryKey, &Measurement.Handle, &Measurement.Token, &Measurement.Module, &Measurement.StartTimeStamp, &Measurement.EndTimeStamp, &Measurement.Identifier)) != 0) ) { ++Index; // Count every record. First record is 1. ElapsedTime = 0; SafeFreePool ((VOID *) IncFlag); if (Measurement.EndTimeStamp != 0) { Duration = GetDuration (&Measurement); ElapsedTime = DurationInMicroSeconds ( Duration ); IncFlag = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_COMPLETE), NULL); } else { IncFlag = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_INCOMPLETE), NULL); // Mark incomplete records } if (((Measurement.EndTimeStamp != 0) && (ElapsedTime < mInterestThreshold)) || ((ExcludeFlag) && (GetCumulativeItem(&Measurement) >= 0)) ) { // Ignore "uninteresting" or excluded records continue; } ++Count; // Count the number of records printed // If Handle is non-zero, see if we can determine a name for the driver AsciiStrToUnicodeStr (Measurement.Module, mGaugeString); // Use Module by default AsciiStrToUnicodeStr (Measurement.Token, mUnicodeToken); if (Measurement.Handle != NULL) { // See if the Handle is in the HandleBuffer for (TIndex = 0; TIndex < (Size / sizeof(HandleBuffer[0])); TIndex++) { if (Measurement.Handle == HandleBuffer[TIndex]) { GetNameFromHandle (HandleBuffer[TIndex]); break; } } } if (AsciiStrnCmp (Measurement.Token, ALit_PEIM, PERF_TOKEN_LENGTH) == 0) { UnicodeSPrint (mGaugeString, sizeof (mGaugeString), L"%g", Measurement.Handle); } // Ensure that the argument strings are not too long. mGaugeString[DP_GAUGE_STRING_LENGTH] = 0; mUnicodeToken[13] = 0; if (mShowId) { PrintToken( STRING_TOKEN (STR_DP_ALL_VARS2), Index, // 1 based, Which measurement record is being printed IncFlag, Measurement.Handle, mGaugeString, mUnicodeToken, ElapsedTime, Measurement.Identifier ); } else { PrintToken( STRING_TOKEN (STR_DP_ALL_VARS), Index, // 1 based, Which measurement record is being printed IncFlag, Measurement.Handle, mGaugeString, mUnicodeToken, ElapsedTime ); } } } if (HandleBuffer != &TempHandle) { FreePool (HandleBuffer); } SafeFreePool ((VOID *) IncFlag); }
EFI_STATUS BOpt_FindFiles ( IN BMM_CALLBACK_DATA *CallbackData, IN BM_MENU_ENTRY *MenuEntry ) /*++ Routine Description Find files under current directory All files and sub-directories in current directory will be stored in DirectoryMenu for future use. Arguments: FileOption -- Pointer for Dir to explore Returns: TRUE -- Get files from current dir successfully FALSE -- Can't get files from current dir --*/ { EFI_FILE_HANDLE NewDir; EFI_FILE_HANDLE Dir; EFI_FILE_INFO *DirInfo; UINTN BufferSize; UINTN DirBufferSize; BM_MENU_ENTRY *NewMenuEntry; BM_FILE_CONTEXT *FileContext; BM_FILE_CONTEXT *NewFileContext; UINTN Pass; EFI_STATUS Status; UINTN OptionNumber; FileContext = (BM_FILE_CONTEXT *) MenuEntry->VariableContext; Dir = FileContext->FHandle; OptionNumber = 0; // // Open current directory to get files from it // Status = Dir->Open ( Dir, &NewDir, FileContext->FileName, EFI_FILE_READ_ONLY, 0 ); if (!FileContext->IsRoot) { Dir->Close (Dir); } if (EFI_ERROR (Status)) { return Status; } DirInfo = EfiLibFileInfo (NewDir); if (!DirInfo) { return EFI_NOT_FOUND; } if (!(DirInfo->Attribute & EFI_FILE_DIRECTORY)) { return EFI_INVALID_PARAMETER; } FileContext->DevicePath = EfiFileDevicePath ( FileContext->Handle, FileContext->FileName ); DirBufferSize = sizeof (EFI_FILE_INFO) + 1024; DirInfo = EfiAllocateZeroPool (DirBufferSize); if (!DirInfo) { return EFI_OUT_OF_RESOURCES; } // // Get all files in current directory // Pass 1 to get Directories // Pass 2 to get files that are EFI images // for (Pass = 1; Pass <= 2; Pass++) { NewDir->SetPosition (NewDir, 0); for (;;) { BufferSize = DirBufferSize; Status = NewDir->Read (NewDir, &BufferSize, DirInfo); if (EFI_ERROR (Status) || BufferSize == 0) { break; } if ((DirInfo->Attribute & EFI_FILE_DIRECTORY && Pass == 2) || (!(DirInfo->Attribute & EFI_FILE_DIRECTORY) && Pass == 1) ) { // // Pass 1 is for Directories // Pass 2 is for file names // continue; } if (!(BOpt_IsEfiImageName (DirInfo->FileName) || DirInfo->Attribute & EFI_FILE_DIRECTORY)) { // // Slip file unless it is a directory entry or a .EFI file // continue; } NewMenuEntry = BOpt_CreateMenuEntry (BM_FILE_CONTEXT_SELECT); if (NULL == NewMenuEntry) { return EFI_OUT_OF_RESOURCES; } NewFileContext = (BM_FILE_CONTEXT *) NewMenuEntry->VariableContext; NewFileContext->Handle = FileContext->Handle; NewFileContext->FileName = BOpt_AppendFileName ( FileContext->FileName, DirInfo->FileName ); NewFileContext->FHandle = NewDir; NewFileContext->DevicePath = EfiFileDevicePath ( NewFileContext->Handle, NewFileContext->FileName ); NewMenuEntry->HelpString = NULL; MenuEntry->DisplayStringToken = GetStringTokenFromDepository ( CallbackData, FileOptionStrDepository ); NewFileContext->IsDir = (BOOLEAN) ((DirInfo->Attribute & EFI_FILE_DIRECTORY) == EFI_FILE_DIRECTORY); if (NewFileContext->IsDir) { BufferSize = EfiStrLen (DirInfo->FileName) * 2 + 6; NewMenuEntry->DisplayString = EfiAllocateZeroPool (BufferSize); SPrint ( NewMenuEntry->DisplayString, BufferSize, L"<%s>", DirInfo->FileName ); } else { NewMenuEntry->DisplayString = EfiStrDuplicate (DirInfo->FileName); } NewFileContext->IsRoot = FALSE; NewFileContext->IsLoadFile = FALSE; NewFileContext->IsRemovableMedia = FALSE; NewMenuEntry->OptionNumber = OptionNumber; OptionNumber++; InsertTailList (&DirectoryMenu.Head, &NewMenuEntry->Link); } } DirectoryMenu.MenuNumber = OptionNumber; SafeFreePool (DirInfo); return EFI_SUCCESS; }
EFI_STATUS BOpt_GetBootOptions ( IN BMM_CALLBACK_DATA *CallbackData ) /*++ Routine Description: Build the BootOptionMenu according to BootOrder Variable. This Routine will access the Boot#### to get EFI_LOAD_OPTION Arguments: None Returns: The number of the Var Boot#### --*/ { UINTN Index; UINT16 BootString[10]; UINT8 *LoadOptionFromVar; UINT8 *LoadOption; 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; MenuCount = 0; BootOrderListSize = 0; BootNextSize = 0; BootOrderList = NULL; BootNext = NULL; LoadOptionFromVar = NULL; BOpt_FreeMenu (&BootOptionMenu); InitializeListHead (&BootOptionMenu.Head); // // Get the BootOrder from the Var // BootOrderList = BdsLibGetVariableAndSize ( L"BootOrder", &gEfiGlobalVariableGuid, &BootOrderListSize ); // // Get the BootNext from the Var // BootNext = BdsLibGetVariableAndSize ( L"BootNext", &gEfiGlobalVariableGuid, &BootNextSize ); if (BootNext) { if (BootNextSize != sizeof (UINT16)) { SafeFreePool (BootNext); BootNext = NULL; } } for (Index = 0; Index < BootOrderListSize / sizeof (UINT16); Index++) { SPrint (BootString, sizeof (BootString), L"Boot%04x", BootOrderList[Index]); // // Get all loadoptions from the VAR // LoadOptionFromVar = BdsLibGetVariableAndSize ( BootString, &gEfiGlobalVariableGuid, &BootOptionSize ); if (!LoadOptionFromVar) { continue; } LoadOption = EfiAllocateZeroPool (BootOptionSize); if (!LoadOption) { continue; } EfiCopyMem (LoadOption, LoadOptionFromVar, BootOptionSize); SafeFreePool (LoadOptionFromVar); if (BootNext) { BootNextFlag = (BOOLEAN) (*BootNext == BootOrderList[Index]); } else { BootNextFlag = FALSE; } if (0 == (*((UINT32 *) LoadOption) & LOAD_OPTION_ACTIVE)) { SafeFreePool (LoadOption); continue; } // // BUGBUG: could not return EFI_OUT_OF_RESOURCES here directly. // the buffer allocated already should be freed before returning. // NewMenuEntry = BOpt_CreateMenuEntry (BM_LOAD_CONTEXT_SELECT); if (NULL == NewMenuEntry) { return EFI_OUT_OF_RESOURCES; } NewLoadContext = (BM_LOAD_CONTEXT *) NewMenuEntry->VariableContext; LoadOptionPtr = LoadOption; LoadOptionEnd = LoadOption + BootOptionSize; NewMenuEntry->OptionNumber = BootOrderList[Index]; NewLoadContext->LoadOptionModified = FALSE; NewLoadContext->Deleted = FALSE; NewLoadContext->IsBootNext = BootNextFlag; // // Is a Legacy Device? // Ptr = (UINT8 *) LoadOption; // // Attribute = *(UINT32 *)Ptr; // Ptr += sizeof (UINT32); // // FilePathSize = *(UINT16 *)Ptr; // Ptr += sizeof (UINT16); // // Description = (CHAR16 *)Ptr; // Ptr += EfiStrSize ((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->LoadOption = LoadOption; NewLoadContext->LoadOptionSize = BootOptionSize; NewLoadContext->Attributes = *(UINT32 *) LoadOptionPtr; NewLoadContext->IsActive = (BOOLEAN) (NewLoadContext->Attributes & LOAD_OPTION_ACTIVE); NewLoadContext->ForceReconnect = (BOOLEAN) (NewLoadContext->Attributes & LOAD_OPTION_FORCE_RECONNECT); LoadOptionPtr += sizeof (UINT32); NewLoadContext->FilePathListLength = *(UINT16 *) LoadOptionPtr; LoadOptionPtr += sizeof (UINT16); StringSize = EfiStrSize ((UINT16 *) LoadOptionPtr); NewLoadContext->Description = EfiAllocateZeroPool (StringSize); ASSERT (NewLoadContext->Description != NULL); EfiCopyMem ( NewLoadContext->Description, (UINT16 *) LoadOptionPtr, StringSize ); NewMenuEntry->DisplayString = NewLoadContext->Description; LoadOptionPtr += StringSize; NewLoadContext->FilePathList = EfiAllocateZeroPool (NewLoadContext->FilePathListLength); ASSERT (NewLoadContext->FilePathList != NULL); EfiCopyMem ( NewLoadContext->FilePathList, (EFI_DEVICE_PATH_PROTOCOL *) LoadOptionPtr, NewLoadContext->FilePathListLength ); NewMenuEntry->HelpString = DevicePathToStr (NewLoadContext->FilePathList); NewMenuEntry->DisplayStringToken = GetStringTokenFromDepository ( CallbackData, BootOptionStrDepository ); NewMenuEntry->HelpStringToken = GetStringTokenFromDepository ( CallbackData, BootOptionHelpStrDepository ); LoadOptionPtr += NewLoadContext->FilePathListLength; if (LoadOptionPtr < LoadOptionEnd) { OptionalDataSize = BootOptionSize - sizeof (UINT32) - sizeof (UINT16) - StringSize - NewLoadContext->FilePathListLength; NewLoadContext->OptionalData = EfiAllocateZeroPool (OptionalDataSize); ASSERT (NewLoadContext->OptionalData != NULL); EfiCopyMem ( NewLoadContext->OptionalData, LoadOptionPtr, OptionalDataSize ); NewLoadContext->OptionalDataSize = OptionalDataSize; } InsertTailList (&BootOptionMenu.Head, &NewMenuEntry->Link); MenuCount++; } SafeFreePool (BootNext); SafeFreePool (BootOrderList); BootOptionMenu.MenuNumber = MenuCount; return MenuCount; }
VOID UpdateBootNextPage ( IN BMM_CALLBACK_DATA *CallbackData ) { BM_MENU_ENTRY *NewMenuEntry; BM_LOAD_CONTEXT *NewLoadContext; IFR_OPTION *IfrOptionList; UINTN NumberOfOptions; UINT16 Index; IfrOptionList = NULL; NumberOfOptions = BootOptionMenu.MenuNumber; CallbackData->BmmAskSaveOrNot = TRUE; UpdatePageStart (CallbackData); CreateMenuStringToken (CallbackData, CallbackData->BmmHiiHandle, &BootOptionMenu); if (NumberOfOptions > 0) { IfrOptionList = EfiAllocateZeroPool ((NumberOfOptions + 1) * sizeof (IFR_OPTION)); ASSERT (IfrOptionList); CallbackData->BmmFakeNvData.BootNext = (UINT16) (BootOptionMenu.MenuNumber); for (Index = 0; Index < BootOptionMenu.MenuNumber; Index++) { NewMenuEntry = BOpt_GetMenuEntry (&BootOptionMenu, Index); NewLoadContext = (BM_LOAD_CONTEXT *) NewMenuEntry->VariableContext; if (NewLoadContext->IsBootNext) { IfrOptionList[Index].Flags = EFI_IFR_OPTION_DEFAULT; CallbackData->BmmFakeNvData.BootNext = Index; } else { IfrOptionList[Index].Flags = 0; } IfrOptionList[Index].Value.u16 = Index; IfrOptionList[Index].StringToken = NewMenuEntry->DisplayStringToken; } IfrOptionList[Index].Value.u16 = Index; IfrOptionList[Index].StringToken = STRING_TOKEN (STR_NONE); IfrOptionList[Index].Flags = 0; if (CallbackData->BmmFakeNvData.BootNext == Index) { IfrOptionList[Index].Flags |= EFI_IFR_OPTION_DEFAULT; } CreateOneOfOpCode ( BOOT_NEXT_QUESTION_ID, VARSTORE_ID_BOOT_MAINT, BOOT_NEXT_VAR_OFFSET, STRING_TOKEN (STR_BOOT_NEXT), STRING_TOKEN (STR_BOOT_NEXT_HELP), 0, EFI_IFR_NUMERIC_SIZE_2, IfrOptionList, (UINTN) (NumberOfOptions + 1), &gUpdateData ); SafeFreePool (IfrOptionList); } UpdatePageEnd (CallbackData); }
BM_MENU_ENTRY * BOpt_CreateMenuEntry ( UINTN MenuType ) /*++ Routine Description Create Menu Entry for future use, make all types together in order to reduce code size Arguments: MenuType Use this parameter to identify current Menu type Returns: NULL Cannot allocate memory for current menu entry Others A valid pointer pointing to the allocated memory pool for current menu entry --*/ { BM_MENU_ENTRY *MenuEntry; UINTN ContextSize; 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; case BM_LEGACY_DEV_CONTEXT_SELECT: ContextSize = sizeof (BM_LEGACY_DEVICE_CONTEXT); break; default: ContextSize = 0; break; } if (0 == ContextSize) { return NULL; } MenuEntry = EfiAllocateZeroPool (sizeof (BM_MENU_ENTRY)); if (NULL == MenuEntry) { return MenuEntry; } MenuEntry->VariableContext = EfiAllocateZeroPool (ContextSize); if (NULL == MenuEntry->VariableContext) { SafeFreePool (MenuEntry); MenuEntry = NULL; return MenuEntry; } MenuEntry->Signature = BM_MENU_ENTRY_SIGNATURE; MenuEntry->ContextSelection = MenuType; return MenuEntry; }
EFI_STATUS BOpt_FindDrivers ( VOID ) /*++ Routine Description 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. Arguments: None Returns: EFI_SUCCESS Others --*/ { 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]; // // Check whether this handle support // driver binding // Status = gBS->HandleProtocol ( CurHandle, &gEfiSimpleFileSystemProtocolGuid, &SimpleFs ); if (Status == EFI_SUCCESS) { continue; } Status = gBS->HandleProtocol ( CurHandle, &gEfiLoadFileProtocolGuid, &LoadFile ); if (Status == EFI_SUCCESS) { continue; } NewMenuEntry = BOpt_CreateMenuEntry (BM_HANDLE_CONTEXT_SELECT); if (NULL == NewMenuEntry) { SafeFreePool (DevicePathHandle); return EFI_OUT_OF_RESOURCES; } NewHandleContext = (BM_HANDLE_CONTEXT *) NewMenuEntry->VariableContext; NewHandleContext->Handle = CurHandle; NewHandleContext->DevicePath = EfiDevicePathFromHandle (CurHandle); NewMenuEntry->DisplayString = DevicePathToStr (NewHandleContext->DevicePath); NewMenuEntry->HelpString = NULL; NewMenuEntry->OptionNumber = OptionNumber; OptionNumber++; InsertTailList (&DriverMenu.Head, &NewMenuEntry->Link); } SafeFreePool (DevicePathHandle); DriverMenu.MenuNumber = OptionNumber; return EFI_SUCCESS; }
EFI_STATUS BOpt_GetDriverOptions ( IN BMM_CALLBACK_DATA *CallbackData ) /*++ Routine Description: Build up all DriverOptionMenu Arguments: Returns: The Option Number --*/ { UINTN Index; UINT16 DriverString[12]; UINT8 *LoadOptionFromVar; UINT8 *LoadOption; 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 // DriverOrderList = BdsLibGetVariableAndSize ( L"DriverOrder", &gEfiGlobalVariableGuid, &DriverOrderListSize ); for (Index = 0; Index < DriverOrderListSize / sizeof (UINT16); Index++) { SPrint ( DriverString, sizeof (DriverString), L"Driver%04x", DriverOrderList[Index] ); // // Get all loadoptions from the VAR // LoadOptionFromVar = BdsLibGetVariableAndSize ( DriverString, &gEfiGlobalVariableGuid, &DriverOptionSize ); if (!LoadOptionFromVar) { continue; } LoadOption = EfiAllocateZeroPool (DriverOptionSize); if (!LoadOption) { continue; } EfiCopyMem (LoadOption, LoadOptionFromVar, DriverOptionSize); SafeFreePool (LoadOptionFromVar); NewMenuEntry = BOpt_CreateMenuEntry (BM_LOAD_CONTEXT_SELECT); if (NULL == NewMenuEntry) { return EFI_OUT_OF_RESOURCES; } NewLoadContext = (BM_LOAD_CONTEXT *) NewMenuEntry->VariableContext; LoadOptionPtr = LoadOption; LoadOptionEnd = LoadOption + DriverOptionSize; NewMenuEntry->OptionNumber = DriverOrderList[Index]; NewLoadContext->LoadOptionModified = FALSE; 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->LoadOption = LoadOption; NewLoadContext->LoadOptionSize = DriverOptionSize; NewLoadContext->Attributes = *(UINT32 *) LoadOptionPtr; NewLoadContext->IsActive = (BOOLEAN) (NewLoadContext->Attributes & LOAD_OPTION_ACTIVE); NewLoadContext->ForceReconnect = (BOOLEAN) (NewLoadContext->Attributes & LOAD_OPTION_FORCE_RECONNECT); LoadOptionPtr += sizeof (UINT32); NewLoadContext->FilePathListLength = *(UINT16 *) LoadOptionPtr; LoadOptionPtr += sizeof (UINT16); StringSize = EfiStrSize ((UINT16 *) LoadOptionPtr); NewLoadContext->Description = EfiAllocateZeroPool (StringSize); ASSERT (NewLoadContext->Description != NULL); EfiCopyMem ( NewLoadContext->Description, (UINT16 *) LoadOptionPtr, StringSize ); NewMenuEntry->DisplayString = NewLoadContext->Description; LoadOptionPtr += StringSize; NewLoadContext->FilePathList = EfiAllocateZeroPool (NewLoadContext->FilePathListLength); ASSERT (NewLoadContext->FilePathList != NULL); EfiCopyMem ( NewLoadContext->FilePathList, (EFI_DEVICE_PATH_PROTOCOL *) LoadOptionPtr, NewLoadContext->FilePathListLength ); NewMenuEntry->HelpString = DevicePathToStr (NewLoadContext->FilePathList); NewMenuEntry->DisplayStringToken = GetStringTokenFromDepository ( CallbackData, DriverOptionStrDepository ); NewMenuEntry->HelpStringToken = GetStringTokenFromDepository ( CallbackData, DriverOptionHelpStrDepository ); LoadOptionPtr += NewLoadContext->FilePathListLength; if (LoadOptionPtr < LoadOptionEnd) { OptionalDataSize = DriverOptionSize - sizeof (UINT32) - sizeof (UINT16) - StringSize - NewLoadContext->FilePathListLength; NewLoadContext->OptionalData = EfiAllocateZeroPool (OptionalDataSize); ASSERT (NewLoadContext->OptionalData != NULL); EfiCopyMem ( NewLoadContext->OptionalData, LoadOptionPtr, OptionalDataSize ); NewLoadContext->OptionalDataSize = OptionalDataSize; } InsertTailList (&DriverOptionMenu.Head, &NewMenuEntry->Link); } SafeFreePool (DriverOrderList); DriverOptionMenu.MenuNumber = Index; return EFI_SUCCESS; }
VOID BOpt_DestroyMenuEntry ( BM_MENU_ENTRY *MenuEntry ) /*++ Routine Description : Destroy the menu entry passed in Arguments : The menu entry need to be destroyed Returns : None --*/ { BM_LOAD_CONTEXT *LoadContext; BM_FILE_CONTEXT *FileContext; BM_CONSOLE_CONTEXT *ConsoleContext; BM_TERMINAL_CONTEXT *TerminalContext; BM_HANDLE_CONTEXT *HandleContext; BM_LEGACY_DEVICE_CONTEXT *LegacyDevContext; // // 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; SafeFreePool (LoadContext->FilePathList); SafeFreePool (LoadContext->LoadOption); SafeFreePool (LoadContext->OptionalData); SafeFreePool (LoadContext); break; case BM_FILE_CONTEXT_SELECT: FileContext = (BM_FILE_CONTEXT *) MenuEntry->VariableContext; if (!FileContext->IsRoot) { SafeFreePool (FileContext->DevicePath); } else { if (FileContext->FHandle != NULL) { FileContext->FHandle->Close (FileContext->FHandle); } } SafeFreePool (FileContext->FileName); SafeFreePool (FileContext->Info); SafeFreePool (FileContext); break; case BM_CONSOLE_CONTEXT_SELECT: ConsoleContext = (BM_CONSOLE_CONTEXT *) MenuEntry->VariableContext; SafeFreePool (ConsoleContext->DevicePath); SafeFreePool (ConsoleContext); break; case BM_TERMINAL_CONTEXT_SELECT: TerminalContext = (BM_TERMINAL_CONTEXT *) MenuEntry->VariableContext; SafeFreePool (TerminalContext->DevicePath); SafeFreePool (TerminalContext); break; case BM_HANDLE_CONTEXT_SELECT: HandleContext = (BM_HANDLE_CONTEXT *) MenuEntry->VariableContext; SafeFreePool (HandleContext); break; case BM_LEGACY_DEV_CONTEXT_SELECT: LegacyDevContext = (BM_LEGACY_DEVICE_CONTEXT *) MenuEntry->VariableContext; SafeFreePool (LegacyDevContext); default: break; } SafeFreePool (MenuEntry->DisplayString); if (NULL != MenuEntry->HelpString) { SafeFreePool (MenuEntry->HelpString); } SafeFreePool (MenuEntry); }
VOID UpdateSetLegacyDeviceOrderPage ( IN UINT16 UpdatePageId, IN BMM_CALLBACK_DATA *CallbackData ) { BM_LEGACY_DEV_ORDER_CONTEXT *DevOrder; BM_MENU_OPTION *OptionMenu; BM_MENU_ENTRY *NewMenuEntry; IFR_OPTION *IfrOptionList; EFI_STRING_ID StrRef; EFI_STRING_ID StrRefHelp; BBS_TYPE BbsType; UINTN VarSize; UINTN Pos; UINTN Bit; UINT16 Index; UINT16 Key; CHAR16 String[100]; CHAR16 *TypeStr; CHAR16 *TypeStrHelp; UINT16 VarDevOrder; UINT8 *VarData; UINT8 *OriginalPtr; UINT8 *LegacyOrder; UINT8 *OldData; UINT8 *DisMap; OptionMenu = NULL; Key = 0; StrRef = 0; StrRefHelp = 0; TypeStr = NULL; TypeStrHelp = NULL; BbsType = BBS_FLOPPY; LegacyOrder = NULL; OldData = NULL; DisMap = NULL; CallbackData->BmmAskSaveOrNot = TRUE; UpdatePageStart (CallbackData); DisMap = CallbackData->BmmOldFakeNVData.DisableMap; EfiSetMem (DisMap, 32, 0); // // Create oneof option list // switch (UpdatePageId) { case FORM_SET_FD_ORDER_ID: OptionMenu = (BM_MENU_OPTION *) &LegacyFDMenu; Key = LEGACY_FD_QUESTION_ID; TypeStr = StrFloppy; TypeStrHelp = StrFloppyHelp; BbsType = BBS_FLOPPY; LegacyOrder = CallbackData->BmmFakeNvData.LegacyFD; OldData = CallbackData->BmmOldFakeNVData.LegacyFD; break; case FORM_SET_HD_ORDER_ID: OptionMenu = (BM_MENU_OPTION *) &LegacyHDMenu; Key = LEGACY_HD_QUESTION_ID; TypeStr = StrHardDisk; TypeStrHelp = StrHardDiskHelp; BbsType = BBS_HARDDISK; LegacyOrder = CallbackData->BmmFakeNvData.LegacyHD; OldData = CallbackData->BmmOldFakeNVData.LegacyHD; break; case FORM_SET_CD_ORDER_ID: OptionMenu = (BM_MENU_OPTION *) &LegacyCDMenu; Key = LEGACY_CD_QUESTION_ID; TypeStr = StrCDROM; TypeStrHelp = StrCDROMHelp; BbsType = BBS_CDROM; LegacyOrder = CallbackData->BmmFakeNvData.LegacyCD; OldData = CallbackData->BmmOldFakeNVData.LegacyCD; break; case FORM_SET_NET_ORDER_ID: OptionMenu = (BM_MENU_OPTION *) &LegacyNETMenu; Key = LEGACY_NET_QUESTION_ID; TypeStr = StrNET; TypeStrHelp = StrNETHelp; BbsType = BBS_EMBED_NETWORK; LegacyOrder = CallbackData->BmmFakeNvData.LegacyNET; OldData = CallbackData->BmmOldFakeNVData.LegacyNET; break; case FORM_SET_BEV_ORDER_ID: OptionMenu = (BM_MENU_OPTION *) &LegacyBEVMenu; Key = LEGACY_BEV_QUESTION_ID; TypeStr = StrBEV; TypeStrHelp = StrBEVHelp; BbsType = BBS_BEV_DEVICE; LegacyOrder = CallbackData->BmmFakeNvData.LegacyBEV; OldData = CallbackData->BmmOldFakeNVData.LegacyBEV; break; } CreateMenuStringToken (CallbackData, CallbackData->BmmHiiHandle, OptionMenu); IfrOptionList = EfiAllocateZeroPool (sizeof (IFR_OPTION) * (OptionMenu->MenuNumber + 1)); if (NULL == IfrOptionList) { return ; } for (Index = 0; Index < OptionMenu->MenuNumber; Index++) { NewMenuEntry = BOpt_GetMenuEntry (OptionMenu, Index); IfrOptionList[Index].Flags = 0; if (0 == Index) { IfrOptionList[Index].Flags |= EFI_IFR_OPTION_DEFAULT; } IfrOptionList[Index].StringToken = NewMenuEntry->DisplayStringToken; IfrOptionList[Index].Value.u8 = (UINT8) ((BM_LEGACY_DEVICE_CONTEXT *) NewMenuEntry->VariableContext)->Index; } // // for item "Disabled" // IfrOptionList[Index].Flags = 0; IfrOptionList[Index].StringToken = STRING_TOKEN (STR_DISABLE_LEGACY_DEVICE); IfrOptionList[Index].Value.u8 = 0xFF; // // Get Device Order from variable // VarData = BdsLibGetVariableAndSize ( VarLegacyDevOrder, &EfiLegacyDevOrderGuid, &VarSize ); if (NULL != VarData) { OriginalPtr = VarData; DevOrder = (BM_LEGACY_DEV_ORDER_CONTEXT *) VarData; while (VarData < VarData + VarSize) { if (DevOrder->BbsType == BbsType) { break; } VarData += sizeof (BBS_TYPE); VarData += *(UINT16 *) VarData; DevOrder = (BM_LEGACY_DEV_ORDER_CONTEXT *) VarData; } // // Create oneof tag here for FD/HD/CD #1 #2 // for (Index = 0; Index < OptionMenu->MenuNumber; Index++) { // // Create the string for oneof tag // SPrint (String, sizeof (String), TypeStr, Index); StrRef = 0; IfrLibNewString (CallbackData->BmmHiiHandle, &StrRef, String); SPrint (String, sizeof (String), TypeStrHelp, Index); StrRefHelp = 0; IfrLibNewString (CallbackData->BmmHiiHandle, &StrRefHelp, String); CreateOneOfOpCode ( Key + Index, VARSTORE_ID_BOOT_MAINT, Key + Index - CONFIG_OPTION_OFFSET, StrRef, StrRefHelp, EFI_IFR_FLAG_CALLBACK, EFI_IFR_NUMERIC_SIZE_1, IfrOptionList, OptionMenu->MenuNumber + 1, &gUpdateData ); VarDevOrder = *(UINT16 *) ((UINT8 *) DevOrder + sizeof (BBS_TYPE) + sizeof (UINT16) + Index * sizeof (UINT16)); if (0xFF00 == (VarDevOrder & 0xFF00)) { LegacyOrder[Index] = 0xFF; Pos = (VarDevOrder & 0xFF) / 8; Bit = 7 - ((VarDevOrder & 0xFF) % 8); DisMap[Pos] |= (UINT8) (1 << Bit); } else { LegacyOrder[Index] = (UINT8) (VarDevOrder & 0xFF); } } } EfiCopyMem (OldData, LegacyOrder, 100); if (IfrOptionList != NULL) { SafeFreePool (IfrOptionList); IfrOptionList = NULL; } UpdatePageEnd (CallbackData); }
VOID * GetLegacyBootOptionVar ( IN UINTN DeviceType, OUT UINTN *OptionIndex, OUT UINTN *OptionSize ) { EFI_DEVICE_PATH_PROTOCOL *DevicePath; VOID *OptionBuffer; UINTN OrderSize; UINTN Index; UINT32 Attribute; UINT16 *OrderBuffer; CHAR16 StrTemp[100]; UINT16 FilePathSize; CHAR16 *Description; UINT8 *Ptr; UINT8 *OptionalData; // // Get Boot Option number from the size of BootOrder // OrderBuffer = BdsLibGetVariableAndSize ( L"BootOrder", &gEfiGlobalVariableGuid, &OrderSize ); for (Index = 0; Index < OrderSize / sizeof (UINT16); Index++) { SPrint (StrTemp, 100, L"Boot%04x", OrderBuffer[Index]); OptionBuffer = BdsLibGetVariableAndSize ( StrTemp, &gEfiGlobalVariableGuid, OptionSize ); if (NULL == OptionBuffer) { continue; } Ptr = (UINT8 *) OptionBuffer; Attribute = *(UINT32 *) Ptr; Ptr += sizeof (UINT32); FilePathSize = *(UINT16 *) Ptr; Ptr += sizeof (UINT16); Description = (CHAR16 *) Ptr; Ptr += EfiStrSize ((CHAR16 *) Ptr); // // Now Ptr point to Device Path // DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) Ptr; Ptr += FilePathSize; // // Now Ptr point to Optional Data // OptionalData = Ptr; if ((DeviceType == ((BBS_TABLE *) OptionalData)->DeviceType) && (BBS_DEVICE_PATH == DevicePath->Type) && (BBS_BBS_DP == DevicePath->SubType) ) { *OptionIndex = OrderBuffer[Index]; SafeFreePool (OrderBuffer); return OptionBuffer; } else { SafeFreePool (OptionBuffer); } } SafeFreePool (OrderBuffer); return NULL; }
VOID UpdateTerminalPage ( IN BMM_CALLBACK_DATA *CallbackData ) { UINT8 Index; UINT8 CheckFlags; IFR_OPTION *IfrOptionList; BM_MENU_ENTRY *NewMenuEntry; BM_TERMINAL_CONTEXT *NewTerminalContext; CallbackData->BmmAskSaveOrNot = TRUE; UpdatePageStart (CallbackData); NewMenuEntry = BOpt_GetMenuEntry ( &TerminalMenu, CallbackData->CurrentTerminal ); if (NewMenuEntry == NULL) { return ; } NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext; IfrOptionList = EfiAllocateZeroPool (sizeof (IFR_OPTION) * 19); if (IfrOptionList == NULL) { return ; } for (Index = 0; Index < 19; Index++) { CheckFlags = 0; if (NewTerminalContext->BaudRate == (UINT64) (BaudRateList[Index].Value)) { CheckFlags |= EFI_IFR_OPTION_DEFAULT; NewTerminalContext->BaudRateIndex = Index; CallbackData->BmmFakeNvData.COMBaudRate = NewTerminalContext->BaudRateIndex; } IfrOptionList[Index].Flags = CheckFlags; IfrOptionList[Index].StringToken = BaudRateList[Index].StringToken; IfrOptionList[Index].Value.u8 = Index; } CreateOneOfOpCode ( COM_BAUD_RATE_QUESTION_ID, VARSTORE_ID_BOOT_MAINT, COM_BAUD_RATE_VAR_OFFSET, STRING_TOKEN (STR_COM_BAUD_RATE), STRING_TOKEN (STR_COM_BAUD_RATE), 0, EFI_IFR_NUMERIC_SIZE_1, IfrOptionList, 19, &gUpdateData ); for (Index = 0; Index < 4; Index++) { CheckFlags = 0; if (NewTerminalContext->DataBits == DataBitsList[Index].Value) { NewTerminalContext->DataBitsIndex = Index; CallbackData->BmmFakeNvData.COMDataRate = NewTerminalContext->DataBitsIndex; CheckFlags |= EFI_IFR_OPTION_DEFAULT; } IfrOptionList[Index].Flags = CheckFlags; IfrOptionList[Index].StringToken = DataBitsList[Index].StringToken; IfrOptionList[Index].Value.u8 = Index; } CreateOneOfOpCode ( COM_DATA_RATE_QUESTION_ID, VARSTORE_ID_BOOT_MAINT, COM_DATA_RATE_VAR_OFFSET, STRING_TOKEN (STR_COM_DATA_BITS), STRING_TOKEN (STR_COM_DATA_BITS), 0, EFI_IFR_NUMERIC_SIZE_1, IfrOptionList, 4, &gUpdateData ); for (Index = 0; Index < 5; Index++) { CheckFlags = 0; if (NewTerminalContext->Parity == ParityList[Index].Value) { CheckFlags |= EFI_IFR_OPTION_DEFAULT; NewTerminalContext->ParityIndex = (UINT8) Index; CallbackData->BmmFakeNvData.COMParity = NewTerminalContext->ParityIndex; } IfrOptionList[Index].Flags = CheckFlags; IfrOptionList[Index].StringToken = ParityList[Index].StringToken; IfrOptionList[Index].Value.u8 = Index; } CreateOneOfOpCode ( COM_PARITY_QUESTION_ID, VARSTORE_ID_BOOT_MAINT, COM_PARITY_VAR_OFFSET, STRING_TOKEN (STR_COM_PARITY), STRING_TOKEN (STR_COM_PARITY), 0, EFI_IFR_NUMERIC_SIZE_1, IfrOptionList, 5, &gUpdateData ); for (Index = 0; Index < 3; Index++) { CheckFlags = 0; if (NewTerminalContext->StopBits == StopBitsList[Index].Value) { CheckFlags |= EFI_IFR_OPTION_DEFAULT; NewTerminalContext->StopBitsIndex = (UINT8) Index; CallbackData->BmmFakeNvData.COMStopBits = NewTerminalContext->StopBitsIndex; } IfrOptionList[Index].Flags = CheckFlags; IfrOptionList[Index].StringToken = StopBitsList[Index].StringToken; IfrOptionList[Index].Value.u8 = Index; } CreateOneOfOpCode ( COM_STOP_BITS_QUESTION_ID, VARSTORE_ID_BOOT_MAINT, COM_STOP_BITS_VAR_OFFSET, STRING_TOKEN (STR_COM_STOP_BITS), STRING_TOKEN (STR_COM_STOP_BITS), 0, EFI_IFR_NUMERIC_SIZE_1, IfrOptionList, 3, &gUpdateData ); for (Index = 0; Index < 4; Index++) { CheckFlags = 0; if (NewTerminalContext->TerminalType == Index) { CheckFlags |= EFI_IFR_OPTION_DEFAULT; CallbackData->BmmFakeNvData.COMTerminalType = NewTerminalContext->TerminalType; } IfrOptionList[Index].Flags = CheckFlags; IfrOptionList[Index].StringToken = (EFI_STRING_ID) TerminalType[Index]; IfrOptionList[Index].Value.u8 = Index; } CreateOneOfOpCode ( COM_TERMINAL_QUESTION_ID, VARSTORE_ID_BOOT_MAINT, COM_TERMINAL_VAR_OFFSET, STRING_TOKEN (STR_COM_TERMI_TYPE), STRING_TOKEN (STR_COM_TERMI_TYPE), 0, EFI_IFR_NUMERIC_SIZE_1, IfrOptionList, 4, &gUpdateData ); SafeFreePool (IfrOptionList); UpdatePageEnd (CallbackData); }
VOID UpdateConModePage ( IN BMM_CALLBACK_DATA *CallbackData ) /*++ Routine Description: Refresh the text mode page Arguments: CallbackData - BMM_CALLBACK_DATA Returns: None. --*/ { UINTN Mode; UINTN Index; UINTN Col; UINTN Row; CHAR16 RowString[50]; CHAR16 ModeString[50]; UINTN MaxMode; UINTN ValidMode; EFI_STRING_ID *ModeToken; IFR_OPTION *IfrOptionList; EFI_STATUS Status; EFI_SIMPLE_TEXT_OUT_PROTOCOL *ConOut; ConOut = gST->ConOut; Index = 0; ValidMode = 0; MaxMode = (UINTN) (ConOut->Mode->MaxMode); CallbackData->BmmAskSaveOrNot = TRUE; UpdatePageStart (CallbackData); // // Check valid mode // for (Mode = 0; Mode < MaxMode; Mode++) { Status = ConOut->QueryMode (ConOut, Mode, &Col, &Row); if (EFI_ERROR (Status)) { continue; } ValidMode++; } if (ValidMode == 0) { return; } IfrOptionList = EfiAllocateZeroPool (sizeof (IFR_OPTION) * ValidMode); ASSERT(IfrOptionList != NULL); ModeToken = EfiAllocateZeroPool (sizeof (EFI_STRING_ID) * ValidMode); ASSERT(ModeToken != NULL); // // Determin which mode should be the first entry in menu // GetConsoleOutMode (CallbackData); // // Build text mode options // for (Mode = 0; Mode < MaxMode; Mode++) { Status = ConOut->QueryMode (ConOut, Mode, &Col, &Row); if (EFI_ERROR (Status)) { continue; } // // Build mode string Column x Row // EfiValueToString (ModeString, Col, 0, 0); EfiStrCat (ModeString, L" x "); EfiValueToString (RowString, Row, 0, 0); EfiStrCat (ModeString, RowString); IfrLibNewString (CallbackData->BmmHiiHandle, &ModeToken[Index], ModeString); IfrOptionList[Index].StringToken = ModeToken[Index]; IfrOptionList[Index].Value.u16 = (UINT16) Mode; if (Mode == CallbackData->BmmFakeNvData.ConsoleOutMode) { IfrOptionList[Index].Flags = EFI_IFR_OPTION_DEFAULT; } else { IfrOptionList[Index].Flags = 0; } Index++; } CreateOneOfOpCode ( CON_MODE_QUESTION_ID, VARSTORE_ID_BOOT_MAINT, CON_MODE_VAR_OFFSET, STRING_TOKEN (STR_CON_MODE_SETUP), STRING_TOKEN (STR_CON_MODE_SETUP), EFI_IFR_FLAG_RESET_REQUIRED, EFI_IFR_NUMERIC_SIZE_2, IfrOptionList, ValidMode, &gUpdateData ); SafeFreePool (IfrOptionList); SafeFreePool (ModeToken); UpdatePageEnd (CallbackData); }