コード例 #1
0
ファイル: Variable.c プロジェクト: jeyaramvrp/edk2
/**
  Update the device path of "ConOut", "ConIn" and "ErrOut" 
  based on the new BaudRate, Data Bits, parity and Stop Bits
  set.

**/
VOID
Var_UpdateAllConsoleOption (
  VOID
  )
{
  EFI_DEVICE_PATH_PROTOCOL  *OutDevicePath;
  EFI_DEVICE_PATH_PROTOCOL  *InpDevicePath;
  EFI_DEVICE_PATH_PROTOCOL  *ErrDevicePath;
  EFI_STATUS                Status;

  OutDevicePath = EfiLibGetVariable (L"ConOut", &gEfiGlobalVariableGuid);
  InpDevicePath = EfiLibGetVariable (L"ConIn", &gEfiGlobalVariableGuid);
  ErrDevicePath = EfiLibGetVariable (L"ErrOut", &gEfiGlobalVariableGuid);
  if (OutDevicePath != NULL) {
    ChangeVariableDevicePath (OutDevicePath);
    Status = gRT->SetVariable (
                    L"ConOut",
                    &gEfiGlobalVariableGuid,
                    EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
                    GetDevicePathSize (OutDevicePath),
                    OutDevicePath
                    );
    //
    // Changing variable without increasing its size with current variable implementation shouldn't fail.
    //
    ASSERT_EFI_ERROR (Status);
  }

  if (InpDevicePath != NULL) {
    ChangeVariableDevicePath (InpDevicePath);
    Status = gRT->SetVariable (
                    L"ConIn",
                    &gEfiGlobalVariableGuid,
                    EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
                    GetDevicePathSize (InpDevicePath),
                    InpDevicePath
                    );
    //
    // Changing variable without increasing its size with current variable implementation shouldn't fail.
    //
    ASSERT_EFI_ERROR (Status);
  }

  if (ErrDevicePath != NULL) {
    ChangeVariableDevicePath (ErrDevicePath);
    Status = gRT->SetVariable (
                    L"ErrOut",
                    &gEfiGlobalVariableGuid,
                    EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
                    GetDevicePathSize (ErrDevicePath),
                    ErrDevicePath
                    );
    //
    // Changing variable without increasing its size with current variable implementation shouldn't fail.
    //
    ASSERT_EFI_ERROR (Status);
  }
}
コード例 #2
0
ファイル: Variable.c プロジェクト: B-Rich/edk2
/**
  Update the device path of "ConOut", "ConIn" and "ErrOut" 
  based on the new BaudRate, Data Bits, parity and Stop Bits
  set.

**/
VOID
Var_UpdateAllConsoleOption (
  VOID
  )
{
  EFI_DEVICE_PATH_PROTOCOL  *OutDevicePath;
  EFI_DEVICE_PATH_PROTOCOL  *InpDevicePath;
  EFI_DEVICE_PATH_PROTOCOL  *ErrDevicePath;
  EFI_STATUS                Status;

  OutDevicePath = EfiLibGetVariable (L"ConOut", &gEfiGlobalVariableGuid);
  InpDevicePath = EfiLibGetVariable (L"ConIn", &gEfiGlobalVariableGuid);
  ErrDevicePath = EfiLibGetVariable (L"ErrOut", &gEfiGlobalVariableGuid);
  if (OutDevicePath != NULL) {
    ChangeVariableDevicePath (OutDevicePath);
    Status = gRT->SetVariable (
                    L"ConOut",
                    &gEfiGlobalVariableGuid,
                    EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
                    GetDevicePathSize (OutDevicePath),
                    OutDevicePath
                    );
    ASSERT (!EFI_ERROR (Status));
  }

  if (InpDevicePath != NULL) {
    ChangeVariableDevicePath (InpDevicePath);
    Status = gRT->SetVariable (
                    L"ConIn",
                    &gEfiGlobalVariableGuid,
                    EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
                    GetDevicePathSize (InpDevicePath),
                    InpDevicePath
                    );
    ASSERT (!EFI_ERROR (Status));
  }

  if (ErrDevicePath != NULL) {
    ChangeVariableDevicePath (ErrDevicePath);
    Status = gRT->SetVariable (
                    L"ErrOut",
                    &gEfiGlobalVariableGuid,
                    EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
                    GetDevicePathSize (ErrDevicePath),
                    ErrDevicePath
                    );
    ASSERT (!EFI_ERROR (Status));
  }
}
コード例 #3
0
ファイル: BmLib.c プロジェクト: hsienchieh/uefilab
/**
  Function deletes the variable specified by VarName and VarGuid.

  @param VarName           A Null-terminated Unicode string that is
                           the name of the vendor's variable.
                         
  @param VarGuid           A unique identifier for the vendor.

  @retval  EFI_SUCCESS           The variable was found and removed
  @retval  EFI_UNSUPPORTED       The variable store was inaccessible
  @retval  EFI_OUT_OF_RESOURCES  The temporary buffer was not available
  @retval  EFI_NOT_FOUND         The variable was not found

**/
EFI_STATUS
EfiLibDeleteVariable (
  IN CHAR16   *VarName,
  IN EFI_GUID *VarGuid
  )
{
  VOID        *VarBuf;
  EFI_STATUS  Status;

  VarBuf  = EfiLibGetVariable (VarName, VarGuid);
  Status  = EFI_NOT_FOUND;

  if (VarBuf != NULL) {
    //
    // Delete variable from Storage
    //
    Status = gRT->SetVariable (
                    VarName,
                    VarGuid,
                    EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
                    0,
                    NULL
                    );
    //
    // Deleting variable with current variable implementation shouldn't fail.
    //
    ASSERT_EFI_ERROR (Status);
    FreePool (VarBuf);
  }

  return Status;
}
コード例 #4
0
ファイル: ConsoleOption.c プロジェクト: Kohrara/edk
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);
}
コード例 #5
0
ファイル: BmLib.c プロジェクト: RafaelRMachado/MinnowBoard
/**
  Function deletes the variable specified by VarName and VarGuid.

  @param VarName           A Null-terminated Unicode string that is
                           the name of the vendor's variable.
                         
  @param VarGuid           A unique identifier for the vendor.

  @retval  EFI_SUCCESS           The variable was found and removed
  @retval  EFI_UNSUPPORTED       The variable store was inaccessible
  @retval  EFI_OUT_OF_RESOURCES  The temporary buffer was not available
  @retval  EFI_NOT_FOUND         The variable was not found

**/
EFI_STATUS
EfiLibDeleteVariable (
  IN CHAR16   *VarName,
  IN EFI_GUID *VarGuid
  )
{
  VOID        *VarBuf;
  EFI_STATUS  Status;

  VarBuf  = EfiLibGetVariable (VarName, VarGuid);
  Status  = EFI_NOT_FOUND;

  if (VarBuf != NULL) {
    //
    // Delete variable from Storage
    //
    Status = gRT->SetVariable (VarName, VarGuid, VAR_FLAG, 0, NULL);
    ASSERT (!EFI_ERROR (Status));
    FreePool (VarBuf);
  }

  return Status;
}
コード例 #6
0
ファイル: ConsoleOption.c プロジェクト: Kohrara/edk
EFI_STATUS
GetConsoleMenu (
    IN UINTN              ConsoleMenuType
)
{
    EFI_DEVICE_PATH_PROTOCOL  *DevicePath;
    EFI_DEVICE_PATH_PROTOCOL  *AllDevicePath;
    EFI_DEVICE_PATH_PROTOCOL  *MultiDevicePath;
    EFI_DEVICE_PATH_PROTOCOL  *DevicePathInst;
    UINTN                     Size;
    UINTN                     AllCount;
    UINTN                     Index;
    UINTN                     Index2;
    BM_MENU_ENTRY             *NewMenuEntry;
    BM_CONSOLE_CONTEXT        *NewConsoleContext;
    BM_TERMINAL_CONTEXT       *NewTerminalContext;
    TYPE_OF_TERMINAL          Terminal;
    BM_MENU_ENTRY             *NewTerminalMenuEntry;
    UINTN                     Com;
    BM_MENU_OPTION            *ConsoleMenu;

    DevicePath    = NULL;
    AllDevicePath = NULL;
    AllCount      = 0;
    switch (ConsoleMenuType) {
    case BM_CONSOLE_IN_CONTEXT_SELECT:
        ConsoleMenu = &ConsoleInpMenu;
        DevicePath = EfiLibGetVariable (
                         L"ConIn",
                         &gEfiGlobalVariableGuid
                     );

        AllDevicePath = EfiLibGetVariable (
                            L"ConInDev",
                            &gEfiGlobalVariableGuid
                        );
        break;

    case BM_CONSOLE_OUT_CONTEXT_SELECT:
        ConsoleMenu = &ConsoleOutMenu;
        DevicePath = EfiLibGetVariable (
                         L"ConOut",
                         &gEfiGlobalVariableGuid
                     );

        AllDevicePath = EfiLibGetVariable (
                            L"ConOutDev",
                            &gEfiGlobalVariableGuid
                        );
        break;

    case BM_CONSOLE_ERR_CONTEXT_SELECT:
        ConsoleMenu = &ConsoleErrMenu;
        DevicePath = EfiLibGetVariable (
                         L"ErrOut",
                         &gEfiGlobalVariableGuid
                     );

        AllDevicePath = EfiLibGetVariable (
                            L"ErrOutDev",
                            &gEfiGlobalVariableGuid
                        );
        break;

    default:
        return EFI_UNSUPPORTED;
    }

    if (NULL == AllDevicePath) {
        return EFI_NOT_FOUND;
    }

    InitializeListHead (&ConsoleMenu->Head);

    AllCount                = EfiDevicePathInstanceCount (AllDevicePath);
    ConsoleMenu->MenuNumber = 0;
    //
    // Following is menu building up for Console Out Devices
    //
    MultiDevicePath = AllDevicePath;
    Index2          = 0;
    for (Index = 0; Index < AllCount; Index++) {
        DevicePathInst  = EfiDevicePathInstance (&MultiDevicePath, &Size);

        NewMenuEntry    = BOpt_CreateMenuEntry (BM_CONSOLE_CONTEXT_SELECT);
        if (NULL == NewMenuEntry) {
            return EFI_OUT_OF_RESOURCES;
        }

        NewConsoleContext             = (BM_CONSOLE_CONTEXT *) NewMenuEntry->VariableContext;
        NewMenuEntry->OptionNumber    = Index2;

        NewConsoleContext->DevicePath = DevicePathInstanceDup (DevicePathInst);
        NewMenuEntry->DisplayString   = EfiLibStrFromDatahub (NewConsoleContext->DevicePath);
        if (NULL == NewMenuEntry->DisplayString) {
            NewMenuEntry->DisplayString = DevicePathToStr (NewConsoleContext->DevicePath);
        }

        NewConsoleContext->IsTerminal = IsTerminalDevicePath (
                                            NewConsoleContext->DevicePath,
                                            &Terminal,
                                            &Com
                                        );

        NewConsoleContext->IsActive = BdsLibMatchDevicePaths (
                                          DevicePath,
                                          NewConsoleContext->DevicePath
                                      );
        NewTerminalMenuEntry  = NULL;
        NewTerminalContext    = NULL;

        if (NewConsoleContext->IsTerminal) {
            BOpt_DestroyMenuEntry (NewMenuEntry);
        } else {
            Index2++;
            ConsoleMenu->MenuNumber++;
            InsertTailList (&ConsoleMenu->Head, &NewMenuEntry->Link);
        }
    }

    return EFI_SUCCESS;
}
コード例 #7
0
ファイル: ConsoleOption.c プロジェクト: Kohrara/edk
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;
}
コード例 #8
0
ファイル: ConsoleOption.c プロジェクト: B-Rich/edk2
/**
  Build a list containing all serial devices.


  @retval EFI_SUCCESS The function complete successfully.
  @retval EFI_UNSUPPORTED No serial ports present.

**/
EFI_STATUS
LocateSerialIo (
  VOID
  )
{
  UINTN                     Index;
  UINTN                     Index2;
  UINTN                     NoHandles;
  EFI_HANDLE                *Handles;
  EFI_STATUS                Status;
  ACPI_HID_DEVICE_PATH      *Acpi;
  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;
  EFI_SERIAL_IO_PROTOCOL    *SerialIo;
  EFI_DEVICE_PATH_PROTOCOL  *Node;
  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;
  UINT32                    FlowControl;
  //
  // 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,
          (VOID **) &DevicePath
          );

    Acpi = NULL;
    for (Node = DevicePath; !IsDevicePathEnd (Node); Node = NextDevicePathNode (Node)) {
      if ((DevicePathType (Node) == MESSAGING_DEVICE_PATH) && (DevicePathSubType (Node) == MSG_UART_DP)) {
        break;
      }
      //
      // Acpi points to the node before Uart node
      //
      Acpi = (ACPI_HID_DEVICE_PATH *) Node;
    }

    if ((Acpi != NULL) && IsIsaSerialNode (Acpi)) {
      NewMenuEntry = BOpt_CreateMenuEntry (BM_TERMINAL_CONTEXT_SELECT);
      if (NewMenuEntry == NULL) {
        FreePool (Handles);
        return EFI_OUT_OF_RESOURCES;
      }

      NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext;
      CopyMem (&NewMenuEntry->OptionNumber, &Acpi->UID, sizeof (UINT32));
      NewTerminalContext->DevicePath = DuplicateDevicePath (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,
            (VOID **) &SerialIo
            );

      CopyMem (
        &NewTerminalContext->BaudRate,
        &SerialIo->Mode->BaudRate,
        sizeof (UINT64)
        );

      CopyMem (
        &NewTerminalContext->DataBits,
        &SerialIo->Mode->DataBits,
        sizeof (UINT8)
        );

      CopyMem (
        &NewTerminalContext->Parity,
        &SerialIo->Mode->Parity,
        sizeof (UINT8)
        );

      CopyMem (
        &NewTerminalContext->StopBits,
        &SerialIo->Mode->StopBits,
        sizeof (UINT8)
        );

      NewTerminalContext->FlowControl = 0;
      SerialIo->GetControl(SerialIo, &FlowControl);
      if ((FlowControl & EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE) != 0) {
        NewTerminalContext->FlowControl = UART_FLOW_CONTROL_HARDWARE;
      }

      InsertTailList (&TerminalMenu.Head, &NewMenuEntry->Link);
      TerminalMenu.MenuNumber++;
    }
  }
  if (Handles != NULL) {
    FreePool (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 != NULL) {
    UpdateComAttributeFromVariable (OutDevicePath);
  }

  if (InpDevicePath != NULL) {
    UpdateComAttributeFromVariable (InpDevicePath);
  }

  if (ErrDevicePath != NULL) {
    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++) {
      CopyMem (&Vendor.Guid, &TerminalTypeGuid[Index2], sizeof (EFI_GUID));
      SetDevicePathNodeLength (&Vendor.Header, sizeof (VENDOR_DEVICE_PATH));
      NewDevicePath = AppendDevicePathNode (
                        NewTerminalContext->DevicePath,
                        (EFI_DEVICE_PATH_PROTOCOL *) &Vendor
                        );
      if (NewMenuEntry->HelpString != NULL) {
        FreePool (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;
}
コード例 #9
0
ファイル: Variable.c プロジェクト: jeyaramvrp/edk2
/**
  This function delete and build multi-instance device path for
  specified type of console device.

  This function clear the EFI variable defined by ConsoleName and
  gEfiGlobalVariableGuid. It then build the multi-instance device
  path by appending the device path of the Console (In/Out/Err) instance 
  in ConsoleMenu. Then it scan all corresponding console device by
  scanning Terminal (built from device supporting Serial I/O instances)
  devices in TerminalMenu. At last, it save a EFI variable specifed
  by ConsoleName and gEfiGlobalVariableGuid.

  @param ConsoleName     The name for the console device type. They are
                         usually "ConIn", "ConOut" and "ErrOut".
  @param ConsoleMenu     The console memu which is a list of console devices.
  @param UpdatePageId    The flag specifying which type of console device
                         to be processed.

  @retval EFI_SUCCESS    The function complete successfully.
  @return The EFI variable can not be saved. See gRT->SetVariable for detail return information.

**/
EFI_STATUS
Var_UpdateConsoleOption (
  IN UINT16                     *ConsoleName,
  IN BM_MENU_OPTION             *ConsoleMenu,
  IN UINT16                     UpdatePageId
  )
{
  EFI_DEVICE_PATH_PROTOCOL  *ConDevicePath;
  BM_MENU_ENTRY             *NewMenuEntry;
  BM_CONSOLE_CONTEXT        *NewConsoleContext;
  BM_TERMINAL_CONTEXT       *NewTerminalContext;
  EFI_STATUS                Status;
  VENDOR_DEVICE_PATH        Vendor;
  EFI_DEVICE_PATH_PROTOCOL  *TerminalDevicePath;
  UINTN                     Index;

  ConDevicePath = EfiLibGetVariable (ConsoleName, &gEfiGlobalVariableGuid);
  if (ConDevicePath != NULL) {
    EfiLibDeleteVariable (ConsoleName, &gEfiGlobalVariableGuid);
    FreePool (ConDevicePath);
    ConDevicePath = NULL;
  };

  //
  // First add all console input device from console input menu
  //
  for (Index = 0; Index < ConsoleMenu->MenuNumber; Index++) {
    NewMenuEntry = BOpt_GetMenuEntry (ConsoleMenu, Index);

    NewConsoleContext = (BM_CONSOLE_CONTEXT *) NewMenuEntry->VariableContext;
    if (NewConsoleContext->IsActive) {
      ConDevicePath = AppendDevicePathInstance (
                        ConDevicePath,
                        NewConsoleContext->DevicePath
                        );
    }
  }

  for (Index = 0; Index < TerminalMenu.MenuNumber; Index++) {
    NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Index);

    NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext;
    if (((NewTerminalContext->IsConIn != 0) && (UpdatePageId == FORM_CON_IN_ID)) ||
        ((NewTerminalContext->IsConOut != 0)  && (UpdatePageId == FORM_CON_OUT_ID)) ||
        ((NewTerminalContext->IsStdErr  != 0) && (UpdatePageId == FORM_CON_ERR_ID))
        ) {
      Vendor.Header.Type    = MESSAGING_DEVICE_PATH;
      Vendor.Header.SubType = MSG_VENDOR_DP;
      
      ASSERT (NewTerminalContext->TerminalType < (sizeof (TerminalTypeGuid) / sizeof (TerminalTypeGuid[0])));
      CopyMem (
        &Vendor.Guid,
        &TerminalTypeGuid[NewTerminalContext->TerminalType],
        sizeof (EFI_GUID)
        );
      SetDevicePathNodeLength (&Vendor.Header, sizeof (VENDOR_DEVICE_PATH));
      TerminalDevicePath = AppendDevicePathNode (
                            NewTerminalContext->DevicePath,
                            (EFI_DEVICE_PATH_PROTOCOL *) &Vendor
                            );
      ASSERT (TerminalDevicePath != NULL);
      ChangeTerminalDevicePath (&TerminalDevicePath, TRUE);
      ConDevicePath = AppendDevicePathInstance (
                        ConDevicePath,
                        TerminalDevicePath
                        );
    }
  }

  if (ConDevicePath != NULL) {
    Status = gRT->SetVariable (
                    ConsoleName,
                    &gEfiGlobalVariableGuid,
                    EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
                    GetDevicePathSize (ConDevicePath),
                    ConDevicePath
                    );
    if (EFI_ERROR (Status)) {
      return Status;
    }
  }

  return EFI_SUCCESS;

}