Пример #1
0
void
init_password_box (EFI_SYSTEM_TABLE *systab, struct password_box *pwd_box)
{
	EFI_SIMPLE_TEXT_OUT_PROTOCOL *conout = systab->ConOut;
	EFI_SIMPLE_TEXT_IN_PROTOCOL  *conin  = systab->ConIn;

	UINTN max_mode = systab->ConOut->Mode->MaxMode;

	EFI_STATUS error;
	UINTN cols = 0, rows = 0;

	UINTN max_cols = 0;
	UINTN max_rows = 0;
	UINTN best_mode = 0;

	int i;
	for (i = 0; i < max_mode; i++) {
		error = conout->QueryMode(systab->ConOut, i, &cols, &rows);

		if (!error	&&
		    cols != 0	&&
		    cols <= 512	&&
		    rows != 0	&&
		    rows <= 512) {
			if (max_cols < cols) {
				max_cols = cols;
				max_rows = rows;
				best_mode = i;
			} else if (max_cols == cols &&
				   max_rows < rows) {
				max_rows = rows;
				best_mode = i;
			}
		}
	}

	conout->SetMode (conout, best_mode);

	conout->SetAttribute (conout, BACKGROUND);

	conout->ClearScreen(conout);

	conout->EnableCursor(conout, 0);

	UINTN col_offset = (max_cols - PASS_BOX_COLS) / 2;
	UINTN row_offset = (max_rows - PASS_BOX_ROWS) / 2;

	pwd_box->cols = PASS_BOX_COLS;
	pwd_box->rows =	PASS_BOX_ROWS;
	pwd_box->col_offset = col_offset;
	pwd_box->row_offset = row_offset;
}
Пример #2
0
VOID
EFIAPI
SEnvTextOut (
  IN EFI_HANDLE   h,
  IN VOID         *Interface
  )
/*++

Routine Description:

Arguments:

  h         - An EFI handle
  Interface - The interface

Returns:

--*/
{
  EFI_SIMPLE_TEXT_OUT_PROTOCOL  *Dev;
  INTN                          Index;
  UINTN                         Col;
  UINTN                         Row;
  EFI_STATUS                    Status;

  Dev = Interface;

  PrintToken (
    STRING_TOKEN (STR_SHELLENV_DPROT_ATTRIB_X),
    HiiEnvHandle,
    Dev->Mode->Attribute
    );

  //
  // Dump TextOut Info
  //
  for (Index = 0; Index < Dev->Mode->MaxMode; Index++) {
    Status = Dev->QueryMode (Dev, Index, &Col, &Row);
    PrintToken (
      STRING_TOKEN (STR_SHELLENV_DPROT_MODE),
      HiiEnvHandle,
      Index == Dev->Mode->Mode ? '*' : ' ',
      Index
      );

    if (EFI_ERROR (Status)) {
      PrintToken (STRING_TOKEN (STR_SHELLENV_DPROT_ERROR), HiiEnvHandle, Status);
    } else {
      PrintToken (STRING_TOKEN (STR_SHELLENV_DPROT_COL_ROW), HiiEnvHandle, Col, Row);
    }
  }
}
Пример #3
0
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);
}
//
// TDS 4.2.3
//
EFI_STATUS
BBTestQueryModeConformanceAutoTest (
  IN EFI_BB_TEST_PROTOCOL       *This,
  IN VOID                       *ClientInterface,
  IN EFI_TEST_LEVEL             TestLevel,
  IN EFI_HANDLE                 SupportHandle
  )
{
  EFI_STANDARD_TEST_LIBRARY_PROTOCOL   *StandardLib;
  EFI_STATUS                           Status;
  EFI_SIMPLE_TEXT_OUT_PROTOCOL         *SimpleOut;
  EFI_TEST_ASSERTION                   AssertionType;

  EFI_SIMPLE_TEXT_OUTPUT_MODE          ModeExpected;
  UINTN                                ModeNumber[5];
  UINTN                                Column, Row;
  UINTN                                Index;

  EFI_GRAPHICS_OUTPUT_PROTOCOL                *GraphicsOutput;
  EFI_DEVICE_PATH_PROTOCOL             *DevicePath;
  CHAR16                               *DevicePathStr;
  //
  // Get the Standard Library Interface
  //
  Status = gtBS->HandleProtocol (
                   SupportHandle,
                   &gEfiStandardTestLibraryGuid,
                   &StandardLib
                   );

  if (EFI_ERROR(Status)) {
    StandardLib->RecordAssertion (
                   StandardLib,
                   EFI_TEST_ASSERTION_FAILED,
                   gTestGenericFailureGuid,
                   L"BS.HandleProtocol - Handle standard test library",
                   L"%a:%d:Status - %r",
                   __FILE__,
                   (UINTN)__LINE__,
                   Status
                   );
    return Status;
  }
   
  SimpleOut = (EFI_SIMPLE_TEXT_OUT_PROTOCOL *)ClientInterface;

  //
  // Get Device Path of current Simple_Text_Output_Protocol
  // And out put device path or device name
  //
  Status = LocateDevicePathFromSimpleTextOut (SimpleOut, &DevicePath, StandardLib);
  if (Status == EFI_SUCCESS) {
    DevicePathStr = DevicePathToStr (DevicePath);
    if (DevicePathStr != NULL) {
      StandardLib->RecordMessage (
                     StandardLib,
                     EFI_VERBOSE_LEVEL_DEFAULT,
                     L"\r\nCurrent Device: %s",
                     DevicePathStr
                     );
      Status = gtBS->FreePool (DevicePathStr);
      if (EFI_ERROR(Status)) {
        StandardLib->RecordAssertion (
                       StandardLib,
                       EFI_TEST_ASSERTION_FAILED,
                       gTestGenericFailureGuid,
                       L"BS.FreePool - Free pool",
                       L"%a:%d:Status - %r",
                       __FILE__,
                       (UINTN)__LINE__,
                       Status
                       );
        return Status;
      }
      DevicePathStr = NULL;
    }
  } else {
    Status = LocateGopFromSimpleTextOut (SimpleOut, &GraphicsOutput, StandardLib);
    if (EFI_ERROR(Status)) {
      //
      // Console Splitter/StdErr
      //
      StandardLib->RecordMessage (
                     StandardLib,
                     EFI_VERBOSE_LEVEL_DEFAULT,
                     L"\r\nCurrent Device: ConsoleSplitter/StdErr"
                     );
    } else {
      //
      // Console Splitter/ConOut
      //
      StandardLib->RecordMessage (
                     StandardLib,
                     EFI_VERBOSE_LEVEL_DEFAULT,
                     L"\r\nCurrent Device: ConsoleSplitter/ConOut"
                     );
    }
  }

  //
  // Prepare test data
  //
  ModeNumber[0] = SimpleOut->Mode->MaxMode;
  ModeNumber[1] = SimpleOut->Mode->MaxMode + 1;
  ModeNumber[2] = SimpleOut->Mode->MaxMode + 2;
  ModeNumber[3] = SimpleOut->Mode->MaxMode + 100;

  Column = 0;
  Row = 0;
  for (Index = 0; Index <= 3; Index++) {
    //
    // Clear Screen
    //
    SimpleOut->ClearScreen (SimpleOut);

    //
    // Prepare expected Mode after call Reset.
    //
    BackupMode (SimpleOut, &ModeExpected);

    //
    // Call QueryMode with invalid ModeNumber
    //
    Status = SimpleOut->QueryMode (SimpleOut, ModeNumber[Index], &Column, &Row);
    //
    // Mode itegrity test
    //
    if (CheckModeIntegrity (&ModeExpected, SimpleOut->Mode) == FALSE) {
      AssertionType = EFI_TEST_ASSERTION_FAILED;
    } else {
      AssertionType = EFI_TEST_ASSERTION_PASSED;
    }
    StandardLib->RecordAssertion (
                   StandardLib,
                   AssertionType,
                   gSimpleTextOutputConformanceTestAssertionGuid001,
                   L"EFI_SIMPLE_TEXT_OUT_PROTOCOL.QueryMode - QueryMode() with invalid ModeNumber, mode position integrity",
                   L"%a:%d: ModeNumber=%d Current: Cursor Position(%d x %d), Mode=%d, MaxMode=%d, Attribute=%d, CursorVisible=%d. "\
                   L" Expected:Cursor Position(%d x %d), Mode=%d, MaxMode=%d, Attribute=%d, CursorVisible=%d.",
                   __FILE__,
                   (UINTN)__LINE__,
                   ModeNumber[Index],
                   SimpleOut->Mode->CursorColumn,
                   SimpleOut->Mode->CursorRow,
                   SimpleOut->Mode->Mode,
                   SimpleOut->Mode->Attribute,
                   SimpleOut->Mode->MaxMode,
                   SimpleOut->Mode->CursorVisible,
                   ModeExpected.CursorColumn,
                   ModeExpected.CursorRow,
                   ModeExpected.Mode,
                   ModeExpected.MaxMode,
                   ModeExpected.Attribute,
                   ModeExpected.CursorVisible
                   );
    //
    // Status check
    //
    if (Status!=EFI_UNSUPPORTED) {
      AssertionType = EFI_TEST_ASSERTION_FAILED;
    } else {
      AssertionType = EFI_TEST_ASSERTION_PASSED;
    }
    StandardLib->RecordAssertion (
                   StandardLib,
                   AssertionType,
                   gSimpleTextOutputConformanceTestAssertionGuid002,
                   L"EFI_SIMPLE_TEXT_OUT_PROTOCOL.QueryMode - QueryMode() with invalid ModeNumber",
                   L"%a:%d: Status = %r, ModeNumber = %d, MaxModeNumber=%d, Column=%d, Row=%d",
                   __FILE__,
                   (UINTN)__LINE__,
                   Status,
                   ModeNumber[Index],
                   SimpleOut->Mode->MaxMode,
                   Column,
                   Row
                   );
  }

  return EFI_SUCCESS;
}
//
// TDS 4.2.6
//
EFI_STATUS
BBTestSetCursorPositionConformanceAutoTest (
    IN EFI_BB_TEST_PROTOCOL       *This,
    IN VOID                       *ClientInterface,
    IN EFI_TEST_LEVEL             TestLevel,
    IN EFI_HANDLE                 SupportHandle
  )
{
  EFI_STANDARD_TEST_LIBRARY_PROTOCOL   *StandardLib;
  EFI_STATUS                           Status;
  EFI_SIMPLE_TEXT_OUT_PROTOCOL         *SimpleOut;
  EFI_TEST_ASSERTION                   AssertionType;

  EFI_SIMPLE_TEXT_OUTPUT_MODE          ModeOrg, ModeExpected;
  INT32                                Mode;
  UINTN                                ColumnTest[10], RowTest[10];
  UINTN                                Column, Row;

  UINTN                                Index;

  EFI_GRAPHICS_OUTPUT_PROTOCOL                *GraphicsOutput;
  EFI_DEVICE_PATH_PROTOCOL             *DevicePath;
  CHAR16                               *DevicePathStr;

  //
  // Get the Standard Library Interface
  //
  Status = gtBS->HandleProtocol (
                   SupportHandle,
                   &gEfiStandardTestLibraryGuid,
                   &StandardLib
                   );

  if (EFI_ERROR(Status)) {
    StandardLib->RecordAssertion (
                   StandardLib,
                   EFI_TEST_ASSERTION_FAILED,
                   gTestGenericFailureGuid,
                   L"BS.HandleProtocol - Handle standard test library",
                   L"%a:%d:Status - %r",
                   __FILE__,
                   (UINTN)__LINE__,
                   Status
                   );
    return Status;
  }

  SimpleOut = (EFI_SIMPLE_TEXT_OUT_PROTOCOL *)ClientInterface;

  //
  // Get Device Path of current Simple_Text_Output_Protocol
  // And out put device path or device name
  //
  Status = LocateDevicePathFromSimpleTextOut (SimpleOut, &DevicePath, StandardLib);
  if (Status == EFI_SUCCESS) {
    DevicePathStr = DevicePathToStr (DevicePath);
    if (DevicePathStr != NULL) {
      StandardLib->RecordMessage (
                     StandardLib,
                     EFI_VERBOSE_LEVEL_DEFAULT,
                     L"\r\nCurrent Device: %s",
                     DevicePathStr
                     );
      Status = gtBS->FreePool (DevicePathStr);
      if (EFI_ERROR(Status)) {
        StandardLib->RecordAssertion (
                       StandardLib,
                       EFI_TEST_ASSERTION_FAILED,
                       gTestGenericFailureGuid,
                       L"BS.FreePool - Free pool",
                       L"%a:%d:Status - %r",
                       __FILE__,
                       (UINTN)__LINE__,
                       Status
                       );
        return Status;
      }
      DevicePathStr = NULL;
    }
  } else {
    Status = LocateGopFromSimpleTextOut (SimpleOut, &GraphicsOutput, StandardLib);
    if (EFI_ERROR(Status)) {
      //
      // Console Splitter/StdErr
      //
      StandardLib->RecordMessage (
                     StandardLib,
                     EFI_VERBOSE_LEVEL_DEFAULT,
                     L"\r\nCurrent Device: ConsoleSplitter/StdErr"
                     );
    } else {
      //
      // Console Splitter/ConOut
      //
      StandardLib->RecordMessage (
                     StandardLib,
                     EFI_VERBOSE_LEVEL_DEFAULT,
                     L"\r\nCurrent Device: ConsoleSplitter/ConOut"
                     );
    }
  }

  //
  // Backup Mode
  //
  BackupMode (SimpleOut, &ModeOrg);

  //
  // For each mode supported!
  //
  for (Mode = 0; Mode < SimpleOut->Mode->MaxMode; Mode++) {
    //
    // Change mode
    //
    Status = SimpleOut->SetMode (SimpleOut, Mode);
    if (EFI_ERROR(Status)) {
      AssertionType = EFI_TEST_ASSERTION_FAILED;
      StandardLib->RecordAssertion (
                     StandardLib,
                     AssertionType,
                     gTestGenericFailureGuid,
                     L"EFI_SIMPLE_TEXT_OUT_PROTOCOL.SetMode - SetMode() with valid mode",
                     L"%a:%d: Status = %r, Mode = %d",
                     __FILE__,
                     (UINTN)__LINE__,
                     Status,
                     Mode
                     );
      continue;
    }

    //
    // Get Mode's screen boundary
    //
    Status = SimpleOut->QueryMode (SimpleOut, Mode, &Column, &Row);
    if (EFI_ERROR(Status)) {
      AssertionType = EFI_TEST_ASSERTION_FAILED;
      StandardLib->RecordAssertion (
                     StandardLib,
                     AssertionType,
                     gTestGenericFailureGuid,
                     L"EFI_SIMPLE_TEXT_OUT_PROTOCOL.QueryMode - QueryMode() with valid mode",
                     L"%a:%d: Status = %r, Mode = %d",
                     __FILE__,
                     (UINTN)__LINE__,
                     Status,
                     Mode
                     );
      continue;
    }

    //
    // Prepare test data
    //
    ColumnTest[0] = Column;
    RowTest[0]    = Row - 1;
    ColumnTest[1] = Column;
    RowTest[1]    = 0;
    ColumnTest[2] = Column + 1;
    RowTest[2]    = Row - 1;
    ColumnTest[3] = Column + 1;
    RowTest[3]    = 0;
    ColumnTest[4] = 0;
    RowTest[4]    = Row;
    ColumnTest[5] = Column - 1;
    RowTest[5]    = Row;
    ColumnTest[6] = Column - 1;
    RowTest[6]    = Row + 1;
    ColumnTest[7] = 0;
    RowTest[7]    = Row + 1;

    for (Index = 0; Index < 8; Index++) {
      //
      // Prepare expected Mode after call Reset.
      //
      BackupMode (SimpleOut, &ModeExpected);

      //
      // Call SetAttribute with invalid Attribute
      //
      Status = SimpleOut->SetCursorPosition (SimpleOut, ColumnTest[Index], RowTest[Index]);

      //
      // Mode itegrity test
      //
      if (CheckModeIntegrity (&ModeExpected, SimpleOut->Mode) == FALSE) {
        AssertionType = EFI_TEST_ASSERTION_FAILED;
      } else {
        AssertionType = EFI_TEST_ASSERTION_PASSED;
      }
      StandardLib->RecordAssertion (
                     StandardLib,
                     AssertionType,
                     gSimpleTextOutputConformanceTestAssertionGuid009,
                     L"EFI_SIMPLE_TEXT_OUT_PROTOCOL.SetCursorPosition - SetCursorPosition() with invalid position, mode position integrity",
                     L"%a:%d: Mode=%d, Positoin=(%d x %d) Current: Cursor Position(%d x %d), Mode=%d, MaxMode=%d, Attribute=%d, CursorVisible=%d. "\
                     L" Expected:Cursor Position(%d x %d), Mode=%d, MaxMode=%d, Attribute=%d, CursorVisible=%d.",
                     __FILE__,
                     (UINTN)__LINE__,
                     Mode,
                     ColumnTest[Index],
                     RowTest[Index],
                     SimpleOut->Mode->CursorColumn,
                     SimpleOut->Mode->CursorRow,
                     SimpleOut->Mode->Mode,
                     SimpleOut->Mode->MaxMode,
                     SimpleOut->Mode->Attribute,
                     SimpleOut->Mode->CursorVisible,
                     ModeExpected.CursorColumn,
                     ModeExpected.CursorRow,
                     ModeExpected.Mode,
                     ModeExpected.MaxMode,
                     ModeExpected.Attribute,
                     ModeExpected.CursorVisible
                     );

      //
      // Status check
      //
      if (Status!=EFI_UNSUPPORTED) {
        AssertionType = EFI_TEST_ASSERTION_FAILED;
      } else {
        AssertionType = EFI_TEST_ASSERTION_PASSED;
      }
      StandardLib->RecordAssertion (
                     StandardLib,
                     AssertionType,
                     gSimpleTextOutputConformanceTestAssertionGuid010,
                     L"EFI_SIMPLE_TEXT_OUT_PROTOCOL.SetCursorPosition - SetCursorPositoin() with invalid Position",
                     L"%a:%d: Status = %r, Mode = %d, Position = (%d x %d)",
                     __FILE__,
                     (UINTN)__LINE__,
                     Status,
                     Mode,
                     ColumnTest[Index],
                     RowTest[Index]
                     );
    }
  }
  return RestoreMode (SimpleOut, &ModeOrg, StandardLib);
}
Пример #6
0
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);
}