/** Get mode number according to column and row @param CallbackData The BMM context data. **/ VOID GetConsoleOutMode ( IN BMM_CALLBACK_DATA *CallbackData ) { UINTN Col; UINTN Row; UINTN CurrentCol; UINTN CurrentRow; UINTN Mode; UINTN MaxMode; EFI_STATUS Status; EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ConOut; ConOut = gST->ConOut; MaxMode = (UINTN) (ConOut->Mode->MaxMode); CurrentCol = PcdGet32 (PcdSetupConOutColumn); CurrentRow = PcdGet32 (PcdSetupConOutRow); 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; } } } }
/** Console-specific helper function for the fstat() function. st_size Set to number of characters read for stdin and number written for stdout and stderr. st_physsize 1 for stdin, 0 if QueryMode error, else max X and Y coordinates for the current mode. st_curpos 0 for stdin, current X & Y coordinates for stdout and stderr st_blksize Set to 1 since this is a character device All other members of the stat structure are left unchanged. **/ static int EFIAPI da_ConStat( struct __filedes *filp, struct stat *Buffer, void *Something ) { ConInstance *Stream; EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Proto; XYoffset CursorPos; INT32 OutMode; UINTN ModeCol; UINTN ModeRow; // ConGetInfo Stream = BASE_CR(filp->f_ops, ConInstance, Abstraction); // Quick check to see if Stream looks reasonable if ((Stream->Cookie != CON_COOKIE) || // Cookie == 'IoAb' (Buffer == NULL)) { EFIerrno = RETURN_INVALID_PARAMETER; return -1; } // All of our parameters are correct, so fill in the information. Buffer->st_blksize = 1; // ConGetPosition if(Stream->InstanceNum == STDIN_FILENO) { // This is stdin Buffer->st_curpos = 0; Buffer->st_size = (off_t)Stream->NumRead; Buffer->st_physsize = 1; } else { Proto = (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)Stream->Dev; CursorPos.XYpos.Column = (UINT32)Proto->Mode->CursorColumn; CursorPos.XYpos.Row = (UINT32)Proto->Mode->CursorRow; Buffer->st_curpos = (off_t)CursorPos.Offset; Buffer->st_size = (off_t)Stream->NumWritten; OutMode = Proto->Mode->Mode; EFIerrno = Proto->QueryMode(Proto, (UINTN)OutMode, &ModeCol, &ModeRow); if(RETURN_ERROR(EFIerrno)) { Buffer->st_physsize = 0; } else { CursorPos.XYpos.Column = (UINT32)ModeCol; CursorPos.XYpos.Row = (UINT32)ModeRow; Buffer->st_physsize = (off_t)CursorPos.Offset; } } return 0; }
/** * Returns information of the screen. * @see text_info */ void gettextinfo (struct text_info * info) { EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Proto; UINTN Columns; UINTN Rows; Proto = gST->ConOut; Proto->QueryMode(Proto, 0, &Columns, &Rows); memset(&settings, 0, sizeof(struct text_info)); // clear settings settings.screenheight = Columns; settings.screenwidth = Rows; settings.attribute = LIGHTGRAY << 4 | LIGHTGRAY; settings.normattr = LIGHTGRAY << 4 | LIGHTGRAY; return; }
/** Get Output screen size and mode. @param[in] fd File descriptor of the output device. @param[out] Col Pointer to where to store the MAX Column, or NULL. @param[out] Row Pointer to where to store the MAX Row, or NULL. @retval <0 An error occurred. The reason is in errno and EFIerrno. * EIO UEFI QueryMode failed * ENOTTY fd does not refer to an interactive output device @retval >=0 Current output mode **/ int EFIAPI IIO_GetOutputSize ( int fd, UINTN *Col, UINTN *Row ) { EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Proto; struct __filedes *pStdOut; EFI_STATUS Status; UINTN TempCol; UINTN TempRow; UINTN TempMode; int RetVal; RetVal = -1; Proto = (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)IIO_GetDeviceProto(fd, &pStdOut); if(Proto != NULL) { if(((pStdOut->f_iflags & _S_ITTY) != 0) && // file is a TTY ((pStdOut->Oflags & O_ACCMODE) != 0)) // and it is open for output { // fd is for a TTY or "Interactive IO" device TempMode = Proto->Mode->Mode; Status = Proto->QueryMode(Proto, TempMode, &TempCol, &TempRow); if(EFI_ERROR(Status)) { EFIerrno = Status; errno = EIO; } else { *Col = TempCol; *Row = TempRow; RetVal = (int)TempMode; } } else { errno = ENOTTY; } } return RetVal; }
/** Returns information for an available text mode that the output device(s) supports. @param[in] This Protocol instance pointer. @param[in] ModeNumber The mode number to return information on. @param[out] Columns Upon return, the number of columns in the selected geometry @param[out] Rows Upon return, the number of rows in the selected geometry @retval EFI_UNSUPPORTED The mode number was not valid. **/ EFI_STATUS EFIAPI FileBasedSimpleTextOutQueryMode ( IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, IN UINTN ModeNumber, OUT UINTN *Columns, OUT UINTN *Rows ) { EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *PassThruProtocol; PassThruProtocol = ((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)This)->OriginalSimpleTextOut; // Pass the QueryMode call thru to the original SimpleTextOutProtocol return (PassThruProtocol->QueryMode( PassThruProtocol, ModeNumber, Columns, Rows)); }
/** This function will change video resolution and text mode according to defined setup mode or defined boot mode @param IsSetupMode Indicate mode is changed to setup mode or boot mode. @retval EFI_SUCCESS Mode is changed successfully. @retval Others Mode failed to be changed. **/ EFI_STATUS EFIAPI BmBdsSetConsoleMode ( BOOLEAN IsSetupMode ) { EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput; EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOut; UINTN SizeOfInfo; EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info; UINT32 MaxGopMode; UINT32 MaxTextMode; UINT32 ModeNumber; UINT32 NewHorizontalResolution; UINT32 NewVerticalResolution; UINT32 NewColumns; UINT32 NewRows; UINTN HandleCount; EFI_HANDLE *HandleBuffer; EFI_STATUS Status; UINTN Index; UINTN CurrentColumn; UINTN CurrentRow; MaxGopMode = 0; MaxTextMode = 0; // // Get current video resolution and text mode // Status = gBS->HandleProtocol ( gST->ConsoleOutHandle, &gEfiGraphicsOutputProtocolGuid, (VOID**)&GraphicsOutput ); if (EFI_ERROR (Status)) { GraphicsOutput = NULL; } Status = gBS->HandleProtocol ( gST->ConsoleOutHandle, &gEfiSimpleTextOutProtocolGuid, (VOID**)&SimpleTextOut ); if (EFI_ERROR (Status)) { SimpleTextOut = NULL; } if ((GraphicsOutput == NULL) || (SimpleTextOut == NULL)) { return EFI_UNSUPPORTED; } if (IsSetupMode) { // // The requried resolution and text mode is setup mode. // NewHorizontalResolution = mBmSetupHorizontalResolution; NewVerticalResolution = mBmSetupVerticalResolution; NewColumns = mBmSetupTextModeColumn; NewRows = mBmSetupTextModeRow; } else { // // The required resolution and text mode is boot mode. // NewHorizontalResolution = mBmBootHorizontalResolution; NewVerticalResolution = mBmBootVerticalResolution; NewColumns = mBmBootTextModeColumn; NewRows = mBmBootTextModeRow; } if (GraphicsOutput != NULL) { MaxGopMode = GraphicsOutput->Mode->MaxMode; } if (SimpleTextOut != NULL) { MaxTextMode = SimpleTextOut->Mode->MaxMode; } // // 1. If current video resolution is same with required video resolution, // video resolution need not be changed. // 1.1. If current text mode is same with required text mode, text mode need not be changed. // 1.2. If current text mode is different from required text mode, text mode need be changed. // 2. If current video resolution is different from required video resolution, we need restart whole console drivers. // for (ModeNumber = 0; ModeNumber < MaxGopMode; ModeNumber++) { Status = GraphicsOutput->QueryMode ( GraphicsOutput, ModeNumber, &SizeOfInfo, &Info ); if (!EFI_ERROR (Status)) { if ((Info->HorizontalResolution == NewHorizontalResolution) && (Info->VerticalResolution == NewVerticalResolution)) { if ((GraphicsOutput->Mode->Info->HorizontalResolution == NewHorizontalResolution) && (GraphicsOutput->Mode->Info->VerticalResolution == NewVerticalResolution)) { // // Current resolution is same with required resolution, check if text mode need be set // Status = SimpleTextOut->QueryMode (SimpleTextOut, SimpleTextOut->Mode->Mode, &CurrentColumn, &CurrentRow); ASSERT_EFI_ERROR (Status); if (CurrentColumn == NewColumns && CurrentRow == NewRows) { // // If current text mode is same with required text mode. Do nothing // FreePool (Info); return EFI_SUCCESS; } else { // // If current text mode is different from requried text mode. Set new video mode // for (Index = 0; Index < MaxTextMode; Index++) { Status = SimpleTextOut->QueryMode (SimpleTextOut, Index, &CurrentColumn, &CurrentRow); if (!EFI_ERROR(Status)) { if ((CurrentColumn == NewColumns) && (CurrentRow == NewRows)) { // // Required text mode is supported, set it. // Status = SimpleTextOut->SetMode (SimpleTextOut, Index); ASSERT_EFI_ERROR (Status); // // Update text mode PCD. // Status = PcdSet32S (PcdConOutColumn, mBmSetupTextModeColumn); ASSERT_EFI_ERROR (Status); Status = PcdSet32S (PcdConOutRow, mBmSetupTextModeRow); ASSERT_EFI_ERROR (Status); FreePool (Info); return EFI_SUCCESS; } } } if (Index == MaxTextMode) { // // If requried text mode is not supported, return error. // FreePool (Info); return EFI_UNSUPPORTED; } } } else { // // If current video resolution is not same with the new one, set new video resolution. // In this case, the driver which produces simple text out need be restarted. // Status = GraphicsOutput->SetMode (GraphicsOutput, ModeNumber); if (!EFI_ERROR (Status)) { FreePool (Info); break; } } } FreePool (Info); } } if (ModeNumber == MaxGopMode) { // // If the resolution is not supported, return error. // return EFI_UNSUPPORTED; } // // Set PCD to Inform GraphicsConsole to change video resolution. // Set PCD to Inform Consplitter to change text mode. // Status = PcdSet32S (PcdVideoHorizontalResolution, NewHorizontalResolution); ASSERT_EFI_ERROR (Status); Status = PcdSet32S (PcdVideoVerticalResolution, NewVerticalResolution); ASSERT_EFI_ERROR (Status); Status = PcdSet32S (PcdConOutColumn, NewColumns); ASSERT_EFI_ERROR (Status); Status = PcdSet32S (PcdConOutRow, NewRows); ASSERT_EFI_ERROR (Status); // // Video mode is changed, so restart graphics console driver and higher level driver. // Reconnect graphics console driver and higher level driver. // Locate all the handles with GOP protocol and reconnect it. // Status = gBS->LocateHandleBuffer ( ByProtocol, &gEfiSimpleTextOutProtocolGuid, NULL, &HandleCount, &HandleBuffer ); if (!EFI_ERROR (Status)) { for (Index = 0; Index < HandleCount; Index++) { gBS->DisconnectController (HandleBuffer[Index], NULL, NULL); } for (Index = 0; Index < HandleCount; Index++) { gBS->ConnectController (HandleBuffer[Index], NULL, NULL, TRUE); } if (HandleBuffer != NULL) { FreePool (HandleBuffer); } } return EFI_SUCCESS; }
/** The user Entry Point for Application. The user code starts with this function as the real entry point for the image goes into a library that calls this function. @param[in] ImageHandle The firmware allocated handle for the EFI image. @param[in] SystemTable A pointer to the EFI System Table. @retval EFI_SUCCESS The entry point is executed successfully. @retval other Some error occurs when executing this entry point. **/ EFI_STATUS EFIAPI InitializeUserInterface ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_HII_HANDLE HiiHandle; EFI_STATUS Status; EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput; EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOut; UINTN BootTextColumn; UINTN BootTextRow; if (!mModeInitialized) { // // After the console is ready, get current video resolution // and text mode before launching setup at first time. // Status = gBS->HandleProtocol ( gST->ConsoleOutHandle, &gEfiGraphicsOutputProtocolGuid, (VOID**)&GraphicsOutput ); if (EFI_ERROR (Status)) { GraphicsOutput = NULL; } Status = gBS->HandleProtocol ( gST->ConsoleOutHandle, &gEfiSimpleTextOutProtocolGuid, (VOID**)&SimpleTextOut ); if (EFI_ERROR (Status)) { SimpleTextOut = NULL; } if (GraphicsOutput != NULL) { // // Get current video resolution and text mode. // mBootHorizontalResolution = GraphicsOutput->Mode->Info->HorizontalResolution; mBootVerticalResolution = GraphicsOutput->Mode->Info->VerticalResolution; } if (SimpleTextOut != NULL) { Status = SimpleTextOut->QueryMode ( SimpleTextOut, SimpleTextOut->Mode->Mode, &BootTextColumn, &BootTextRow ); mBootTextModeColumn = (UINT32)BootTextColumn; mBootTextModeRow = (UINT32)BootTextRow; } // // Get user defined text mode for setup. // mSetupHorizontalResolution = PcdGet32 (PcdSetupVideoHorizontalResolution); mSetupVerticalResolution = PcdGet32 (PcdSetupVideoVerticalResolution); mSetupTextModeColumn = PcdGet32 (PcdSetupConOutColumn); mSetupTextModeRow = PcdGet32 (PcdSetupConOutRow); mModeInitialized = TRUE; } gBS->SetWatchdogTimer (0x0000, 0x0000, 0x0000, NULL); gST->ConOut->ClearScreen (gST->ConOut); // // Install customized fonts needed by Front Page // HiiHandle = ExportFonts (); ASSERT (HiiHandle != NULL); InitializeStringSupport (); UiSetConsoleMode (TRUE); UiEntry (FALSE); UiSetConsoleMode (FALSE); UninitializeStringSupport (); HiiRemovePackages (HiiHandle); return EFI_SUCCESS; }
/** Draws a dialog box to the console output device specified by ConOut defined in the EFI_SYSTEM_TABLE and waits for a keystroke from the console input device specified by ConIn defined in the EFI_SYSTEM_TABLE. If there are no strings in the variable argument list, then ASSERT(). If all the strings in the variable argument list are empty, then ASSERT(). @param[in] Attribute Specifies the foreground and background color of the popup. @param[out] Key A pointer to the EFI_KEY value of the key that was pressed. This is an optional parameter that may be NULL. If it is NULL then no wait for a keypress will be performed. @param[in] ... The variable argument list that contains pointers to Null- terminated Unicode strings to display in the dialog box. The variable argument list is terminated by a NULL. **/ VOID EFIAPI CreatePopUp ( IN UINTN Attribute, OUT EFI_INPUT_KEY *Key, OPTIONAL ... ) { EFI_STATUS Status; VA_LIST Args; EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ConOut; EFI_SIMPLE_TEXT_OUTPUT_MODE SavedConsoleMode; UINTN Columns; UINTN Rows; UINTN Column; UINTN Row; UINTN NumberOfLines; UINTN MaxLength; CHAR16 *String; UINTN Length; CHAR16 *Line; UINTN EventIndex; // // Determine the length of the longest line in the popup and the the total // number of lines in the popup // VA_START (Args, Key); MaxLength = 0; NumberOfLines = 0; while ((String = VA_ARG (Args, CHAR16 *)) != NULL) { MaxLength = MAX (MaxLength, StrLen (String)); NumberOfLines++; } VA_END (Args); // // If the total number of lines in the popup is zero, then ASSERT() // ASSERT (NumberOfLines != 0); // // If the maximum length of all the strings is zero, then ASSERT() // ASSERT (MaxLength != 0); // // Cache a pointer to the Simple Text Output Protocol in the EFI System Table // ConOut = gST->ConOut; // // Save the current console cursor position and attributes // CopyMem (&SavedConsoleMode, ConOut->Mode, sizeof (SavedConsoleMode)); // // Retrieve the number of columns and rows in the current console mode // ConOut->QueryMode (ConOut, SavedConsoleMode.Mode, &Columns, &Rows); // // Disable cursor and set the foreground and background colors specified by Attribute // ConOut->EnableCursor (ConOut, FALSE); ConOut->SetAttribute (ConOut, Attribute); // // Limit NumberOfLines to height of the screen minus 3 rows for the box itself // NumberOfLines = MIN (NumberOfLines, Rows - 3); // // Limit MaxLength to width of the screen minus 2 columns for the box itself // MaxLength = MIN (MaxLength, Columns - 2); // // Compute the starting row and starting column for the popup // Row = (Rows - (NumberOfLines + 3)) / 2; Column = (Columns - (MaxLength + 2)) / 2; // // Allocate a buffer for a single line of the popup with borders and a Null-terminator // Line = AllocateZeroPool ((MaxLength + 3) * sizeof (CHAR16)); ASSERT (Line != NULL); // // Draw top of popup box // SetMem16 (Line, (MaxLength + 2) * 2, BOXDRAW_HORIZONTAL); Line[0] = BOXDRAW_DOWN_RIGHT; Line[MaxLength + 1] = BOXDRAW_DOWN_LEFT; Line[MaxLength + 2] = L'\0'; ConOut->SetCursorPosition (ConOut, Column, Row++); ConOut->OutputString (ConOut, Line); // // Draw middle of the popup with strings // VA_START (Args, Key); while ((String = VA_ARG (Args, CHAR16 *)) != NULL && NumberOfLines > 0) { Length = StrLen (String); SetMem16 (Line, (MaxLength + 2) * 2, L' '); if (Length <= MaxLength) { // // Length <= MaxLength // CopyMem (Line + 1 + (MaxLength - Length) / 2, String , Length * sizeof (CHAR16)); } else { // // Length > MaxLength // CopyMem (Line + 1, String + (Length - MaxLength) / 2 , MaxLength * sizeof (CHAR16)); } Line[0] = BOXDRAW_VERTICAL; Line[MaxLength + 1] = BOXDRAW_VERTICAL; Line[MaxLength + 2] = L'\0'; ConOut->SetCursorPosition (ConOut, Column, Row++); ConOut->OutputString (ConOut, Line); NumberOfLines--; } VA_END (Args); // // Draw bottom of popup box // SetMem16 (Line, (MaxLength + 2) * 2, BOXDRAW_HORIZONTAL); Line[0] = BOXDRAW_UP_RIGHT; Line[MaxLength + 1] = BOXDRAW_UP_LEFT; Line[MaxLength + 2] = L'\0'; ConOut->SetCursorPosition (ConOut, Column, Row++); ConOut->OutputString (ConOut, Line); // // Free the allocated line buffer // FreePool (Line); // // Restore the cursor visibility, position, and attributes // ConOut->EnableCursor (ConOut, SavedConsoleMode.CursorVisible); ConOut->SetCursorPosition (ConOut, SavedConsoleMode.CursorColumn, SavedConsoleMode.CursorRow); ConOut->SetAttribute (ConOut, SavedConsoleMode.Attribute); // // Wait for a keystroke // if (Key != NULL) { while (TRUE) { Status = gST->ConIn->ReadKeyStroke (gST->ConIn, Key); if (!EFI_ERROR (Status)) { break; } // // If we encounter error, continue to read another key in. // if (Status != EFI_NOT_READY) { continue; } gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex); } } }
/** This function is the main entry of the platform setup entry. The function will present the main menu of the system setup, this is the platform reference part and can be customize. @param TimeoutDefault The fault time out value before the system continue to boot. @param ConnectAllHappened The indicater to check if the connect all have already happened. **/ VOID PlatformBdsEnterFrontPage ( IN UINT16 TimeoutDefault, IN BOOLEAN ConnectAllHappened ) { EFI_STATUS Status; EFI_STATUS StatusHotkey; EFI_BOOT_LOGO_PROTOCOL *BootLogo; EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput; EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOut; UINTN BootTextColumn; UINTN BootTextRow; UINT64 OsIndication; UINTN DataSize; EFI_INPUT_KEY Key; GraphicsOutput = NULL; SimpleTextOut = NULL; PERF_START (NULL, "BdsTimeOut", "BDS", 0); // // Indicate if we need connect all in the platform setup // if (ConnectAllHappened) { gConnectAllHappened = TRUE; } if (!mModeInitialized) { // // After the console is ready, get current video resolution // and text mode before launching setup at first time. // Status = gBS->HandleProtocol ( gST->ConsoleOutHandle, &gEfiGraphicsOutputProtocolGuid, (VOID**)&GraphicsOutput ); if (EFI_ERROR (Status)) { GraphicsOutput = NULL; } Status = gBS->HandleProtocol ( gST->ConsoleOutHandle, &gEfiSimpleTextOutProtocolGuid, (VOID**)&SimpleTextOut ); if (EFI_ERROR (Status)) { SimpleTextOut = NULL; } if (GraphicsOutput != NULL) { // // Get current video resolution and text mode. // mBootHorizontalResolution = GraphicsOutput->Mode->Info->HorizontalResolution; mBootVerticalResolution = GraphicsOutput->Mode->Info->VerticalResolution; } if (SimpleTextOut != NULL) { Status = SimpleTextOut->QueryMode ( SimpleTextOut, SimpleTextOut->Mode->Mode, &BootTextColumn, &BootTextRow ); mBootTextModeColumn = (UINT32)BootTextColumn; mBootTextModeRow = (UINT32)BootTextRow; } // // Get user defined text mode for setup. // mSetupHorizontalResolution = PcdGet32 (PcdSetupVideoHorizontalResolution); mSetupVerticalResolution = PcdGet32 (PcdSetupVideoVerticalResolution); mSetupTextModeColumn = PcdGet32 (PcdSetupConOutColumn); mSetupTextModeRow = PcdGet32 (PcdSetupConOutRow); mModeInitialized = TRUE; } // // goto FrontPage directly when EFI_OS_INDICATIONS_BOOT_TO_FW_UI is set // OsIndication = 0; DataSize = sizeof(UINT64); Status = gRT->GetVariable ( L"OsIndications", &gEfiGlobalVariableGuid, NULL, &DataSize, &OsIndication ); // // goto FrontPage directly when EFI_OS_INDICATIONS_BOOT_TO_FW_UI is set. Skip HotkeyBoot // if (!EFI_ERROR(Status) && ((OsIndication & EFI_OS_INDICATIONS_BOOT_TO_FW_UI) != 0)) { // // Clear EFI_OS_INDICATIONS_BOOT_TO_FW_UI to acknowledge OS // OsIndication &= ~((UINT64)EFI_OS_INDICATIONS_BOOT_TO_FW_UI); Status = gRT->SetVariable ( L"OsIndications", &gEfiGlobalVariableGuid, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, sizeof(UINT64), &OsIndication ); // // Changing the content without increasing its size with current variable implementation shouldn't fail. // ASSERT_EFI_ERROR (Status); // // Follow generic rule, Call ReadKeyStroke to connect ConIn before enter UI // if (PcdGetBool (PcdConInConnectOnDemand)) { gST->ConIn->ReadKeyStroke(gST->ConIn, &Key); } // // Ensure screen is clear when switch Console from Graphics mode to Text mode // gST->ConOut->EnableCursor (gST->ConOut, TRUE); gST->ConOut->ClearScreen (gST->ConOut); } else { HotkeyBoot (); if (TimeoutDefault != 0xffff) { Status = ShowProgress (TimeoutDefault); StatusHotkey = HotkeyBoot (); if (!FeaturePcdGet(PcdBootlogoOnlyEnable) || !EFI_ERROR(Status) || !EFI_ERROR(StatusHotkey)){ // // Ensure screen is clear when switch Console from Graphics mode to Text mode // Skip it in normal boot // gST->ConOut->EnableCursor (gST->ConOut, TRUE); gST->ConOut->ClearScreen (gST->ConOut); } if (EFI_ERROR (Status)) { // // Timeout or user press enter to continue // goto Exit; } } } // // Boot Logo is corrupted, report it using Boot Logo protocol. // Status = gBS->LocateProtocol (&gEfiBootLogoProtocolGuid, NULL, (VOID **) &BootLogo); if (!EFI_ERROR (Status) && (BootLogo != NULL)) { BootLogo->SetBootLogo (BootLogo, NULL, 0, 0, 0, 0); } // // Install BM HiiPackages. // Keep BootMaint HiiPackage, so that it can be covered by global setting. // InitBMPackage (); Status = EFI_SUCCESS; do { // // Set proper video resolution and text mode for setup // BdsSetConsoleMode (TRUE); InitializeFrontPage (FALSE); // // Update Front Page strings // UpdateFrontPageStrings (); gCallbackKey = 0; CallFrontPage (); // // If gCallbackKey is greater than 1 and less or equal to 5, // it will launch configuration utilities. // 2 = set language // 3 = boot manager // 4 = device manager // 5 = boot maintenance manager // if (gCallbackKey != 0) { REPORT_STATUS_CODE ( EFI_PROGRESS_CODE, (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_PC_USER_SETUP) ); } // // Based on the key that was set, we can determine what to do // switch (gCallbackKey) { // // The first 4 entries in the Front Page are to be GUARANTEED to remain constant so IHV's can // describe to their customers in documentation how to find their setup information (namely // under the device manager and specific buckets) // // These entries consist of the Continue, Select language, Boot Manager, and Device Manager // case FRONT_PAGE_KEY_CONTINUE: // // User hit continue // break; case FRONT_PAGE_KEY_LANGUAGE: // // User made a language setting change - display front page again // break; case FRONT_PAGE_KEY_BOOT_MANAGER: // // Remove the installed BootMaint HiiPackages when exit. // FreeBMPackage (); // // User chose to run the Boot Manager // CallBootManager (); // // Reinstall BootMaint HiiPackages after exiting from Boot Manager. // InitBMPackage (); break; case FRONT_PAGE_KEY_DEVICE_MANAGER: // // Display the Device Manager // do { CallDeviceManager (); } while (gCallbackKey == FRONT_PAGE_KEY_DEVICE_MANAGER); break; case FRONT_PAGE_KEY_BOOT_MAINTAIN: // // Display the Boot Maintenance Manager // BdsStartBootMaint (); break; } } while ((Status == EFI_SUCCESS) && (gCallbackKey != FRONT_PAGE_KEY_CONTINUE)); if (mLanguageString != NULL) { FreePool (mLanguageString); mLanguageString = NULL; } // //Will leave browser, check any reset required change is applied? if yes, reset system // SetupResetReminder (); // // Remove the installed BootMaint HiiPackages when exit. // FreeBMPackage (); Exit: // // Automatically load current entry // Note: The following lines of code only execute when Auto boot // takes affect // PERF_END (NULL, "BdsTimeOut", "BDS", 0); }
/** Refresh the text mode page. @param CallbackData The BMM context data. **/ VOID UpdateConModePage ( IN BMM_CALLBACK_DATA *CallbackData ) { UINTN Mode; UINTN Index; UINTN Col; UINTN Row; CHAR16 ModeString[50]; CHAR16 *PStr; UINTN MaxMode; UINTN ValidMode; EFI_STRING_ID *ModeToken; EFI_STATUS Status; VOID *OptionsOpCodeHandle; EFI_SIMPLE_TEXT_OUTPUT_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; } OptionsOpCodeHandle = HiiAllocateOpCodeHandle (); ASSERT (OptionsOpCodeHandle != NULL); ModeToken = AllocateZeroPool (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 // UnicodeValueToString (ModeString, 0, Col, 0); PStr = &ModeString[0]; StrnCat (PStr, L" x ", StrLen(L" x ") + 1); PStr = PStr + StrLen (PStr); UnicodeValueToString (PStr , 0, Row, 0); ModeToken[Index] = HiiSetString (CallbackData->BmmHiiHandle, 0, ModeString, NULL); if (Mode == CallbackData->BmmFakeNvData.ConsoleOutMode) { HiiCreateOneOfOptionOpCode ( OptionsOpCodeHandle, ModeToken[Index], EFI_IFR_OPTION_DEFAULT, EFI_IFR_TYPE_NUM_SIZE_16, (UINT16) Mode ); } else { HiiCreateOneOfOptionOpCode ( OptionsOpCodeHandle, ModeToken[Index], 0, EFI_IFR_TYPE_NUM_SIZE_16, (UINT16) Mode ); } Index++; } HiiCreateOneOfOpCode ( mStartOpCodeHandle, (EFI_QUESTION_ID) 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, OptionsOpCodeHandle, NULL ); HiiFreeOpCodeHandle (OptionsOpCodeHandle); FreePool (ModeToken); UpdatePageEnd (CallbackData); }
/** Initial the boot mode related parameters. **/ VOID BmInitialBootModeInfo ( VOID ) { EFI_STATUS Status; EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput; EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOut; UINTN BootTextColumn; UINTN BootTextRow; if (mBmModeInitialized) { return; } // // After the console is ready, get current video resolution // and text mode before launching setup at first time. // Status = gBS->HandleProtocol ( gST->ConsoleOutHandle, &gEfiGraphicsOutputProtocolGuid, (VOID**)&GraphicsOutput ); if (EFI_ERROR (Status)) { GraphicsOutput = NULL; } Status = gBS->HandleProtocol ( gST->ConsoleOutHandle, &gEfiSimpleTextOutProtocolGuid, (VOID**)&SimpleTextOut ); if (EFI_ERROR (Status)) { SimpleTextOut = NULL; } if (GraphicsOutput != NULL) { // // Get current video resolution and text mode. // mBmBootHorizontalResolution = GraphicsOutput->Mode->Info->HorizontalResolution; mBmBootVerticalResolution = GraphicsOutput->Mode->Info->VerticalResolution; } if (SimpleTextOut != NULL) { Status = SimpleTextOut->QueryMode ( SimpleTextOut, SimpleTextOut->Mode->Mode, &BootTextColumn, &BootTextRow ); mBmBootTextModeColumn = (UINT32)BootTextColumn; mBmBootTextModeRow = (UINT32)BootTextRow; } // // Get user defined text mode for setup. // mBmSetupHorizontalResolution = PcdGet32 (PcdSetupVideoHorizontalResolution); mBmSetupVerticalResolution = PcdGet32 (PcdSetupVideoVerticalResolution); mBmSetupTextModeColumn = PcdGet32 (PcdSetupConOutColumn); mBmSetupTextModeRow = PcdGet32 (PcdSetupConOutRow); mBmModeInitialized = TRUE; }