2010-11-16 23:36:37 +01:00
|
|
|
/** @file
|
|
|
|
Main file for SerMode shell Debug1 function.
|
|
|
|
|
2015-02-04 23:25:01 +01:00
|
|
|
(C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
|
2011-03-25 22:22:20 +01:00
|
|
|
Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved.<BR>
|
2010-11-16 23:36:37 +01:00
|
|
|
This program and the accompanying materials
|
|
|
|
are licensed and made available under the terms and conditions of the BSD License
|
|
|
|
which accompanies this distribution. The full text of the license may be found at
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include "UefiShellDebug1CommandsLib.h"
|
|
|
|
#include <Library/ShellLib.h>
|
|
|
|
#include <Protocol/SerialIo.h>
|
|
|
|
|
2011-03-25 22:22:20 +01:00
|
|
|
/**
|
|
|
|
Display information about a serial device by it's handle.
|
|
|
|
|
|
|
|
If HandleValid is FALSE, do all devices.
|
|
|
|
|
|
|
|
@param[in] HandleIdx The handle index for the device.
|
|
|
|
@param[in] HandleValid TRUE if HandleIdx is valid.
|
|
|
|
|
|
|
|
@retval SHELL_INVALID_PARAMETER A parameter was invalid.
|
|
|
|
@retval SHELL_SUCCESS The operation was successful.
|
|
|
|
**/
|
2010-11-16 23:36:37 +01:00
|
|
|
SHELL_STATUS
|
|
|
|
EFIAPI
|
2011-03-25 22:22:20 +01:00
|
|
|
DisplaySettings (
|
2010-11-16 23:36:37 +01:00
|
|
|
IN UINTN HandleIdx,
|
|
|
|
IN BOOLEAN HandleValid
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_SERIAL_IO_PROTOCOL *SerialIo;
|
|
|
|
UINTN NoHandles;
|
|
|
|
EFI_HANDLE *Handles;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINTN Index;
|
|
|
|
CHAR16 *StopBits;
|
|
|
|
CHAR16 Parity;
|
|
|
|
SHELL_STATUS ShellStatus;
|
|
|
|
|
|
|
|
Handles = NULL;
|
|
|
|
StopBits = NULL;
|
|
|
|
|
|
|
|
ShellStatus = SHELL_SUCCESS;
|
|
|
|
|
|
|
|
Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiSerialIoProtocolGuid, NULL, &NoHandles, &Handles);
|
|
|
|
if (EFI_ERROR (Status)) {
|
2015-02-03 22:22:53 +01:00
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SERMODE_NO_FOUND), gShellDebug1HiiHandle, L"sermode");
|
2010-11-16 23:36:37 +01:00
|
|
|
return SHELL_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Index = 0; Index < NoHandles; Index++) {
|
|
|
|
if (HandleValid) {
|
|
|
|
if (ConvertHandleIndexToHandle(HandleIdx) != Handles[Index]) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = gBS->HandleProtocol (Handles[Index], &gEfiSerialIoProtocolGuid, (VOID**)&SerialIo);
|
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
switch (SerialIo->Mode->Parity) {
|
|
|
|
case DefaultParity:
|
|
|
|
|
|
|
|
Parity = 'D';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NoParity:
|
|
|
|
|
|
|
|
Parity = 'N';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EvenParity:
|
|
|
|
|
|
|
|
Parity = 'E';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OddParity:
|
|
|
|
|
|
|
|
Parity = 'O';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MarkParity:
|
|
|
|
|
|
|
|
Parity = 'M';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SpaceParity:
|
|
|
|
|
|
|
|
Parity = 'S';
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
Parity = 'U';
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (SerialIo->Mode->StopBits) {
|
|
|
|
case DefaultStopBits:
|
|
|
|
|
|
|
|
StopBits = L"Default";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OneStopBit:
|
|
|
|
|
|
|
|
StopBits = L"1";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TwoStopBits:
|
|
|
|
|
|
|
|
StopBits = L"2";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OneFiveStopBits:
|
|
|
|
|
|
|
|
StopBits = L"1.5";
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
StopBits = L"Unknown";
|
|
|
|
}
|
|
|
|
ShellPrintHiiEx(
|
|
|
|
-1,
|
|
|
|
-1,
|
|
|
|
NULL,
|
|
|
|
STRING_TOKEN (STR_SERMODE_DISPLAY),
|
|
|
|
gShellDebug1HiiHandle,
|
|
|
|
ConvertHandleToHandleIndex (Handles[Index]),
|
|
|
|
Handles[Index],
|
|
|
|
SerialIo->Mode->BaudRate,
|
|
|
|
Parity,
|
|
|
|
SerialIo->Mode->DataBits,
|
|
|
|
StopBits
|
|
|
|
);
|
|
|
|
} else {
|
2015-02-03 22:22:53 +01:00
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SERMODE_NO_FOUND), gShellDebug1HiiHandle, L"sermode");
|
2010-11-16 23:36:37 +01:00
|
|
|
ShellStatus = SHELL_NOT_FOUND;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (HandleValid) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Index == NoHandles) {
|
|
|
|
if ((NoHandles != 0 && HandleValid) || 0 == NoHandles) {
|
2015-02-03 22:22:53 +01:00
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SERMODE_NOT_FOUND), gShellDebug1HiiHandle, L"sermode");
|
2010-11-16 23:36:37 +01:00
|
|
|
ShellStatus = SHELL_NOT_FOUND;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ShellStatus;
|
|
|
|
}
|
|
|
|
|
2011-03-25 22:22:20 +01:00
|
|
|
/**
|
|
|
|
Function for 'sermode' command.
|
|
|
|
|
|
|
|
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
|
|
|
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
|
|
|
**/
|
2010-11-16 23:36:37 +01:00
|
|
|
SHELL_STATUS
|
|
|
|
EFIAPI
|
|
|
|
ShellCommandRunSerMode (
|
|
|
|
IN EFI_HANDLE ImageHandle,
|
|
|
|
IN EFI_SYSTEM_TABLE *SystemTable
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
SHELL_STATUS ShellStatus;
|
|
|
|
UINTN Index;
|
|
|
|
UINTN NoHandles;
|
|
|
|
EFI_HANDLE *Handles;
|
|
|
|
EFI_PARITY_TYPE Parity;
|
|
|
|
EFI_STOP_BITS_TYPE StopBits;
|
|
|
|
UINTN HandleIdx;
|
|
|
|
UINTN BaudRate;
|
|
|
|
UINTN DataBits;
|
|
|
|
UINTN Value;
|
|
|
|
EFI_SERIAL_IO_PROTOCOL *SerialIo;
|
|
|
|
LIST_ENTRY *Package;
|
|
|
|
CHAR16 *ProblemParam;
|
|
|
|
CONST CHAR16 *Temp;
|
2011-03-25 22:22:20 +01:00
|
|
|
UINT64 Intermediate;
|
2010-11-16 23:36:37 +01:00
|
|
|
|
|
|
|
ShellStatus = SHELL_SUCCESS;
|
|
|
|
HandleIdx = 0;
|
|
|
|
Parity = DefaultParity;
|
|
|
|
Handles = NULL;
|
|
|
|
NoHandles = 0;
|
|
|
|
Index = 0;
|
|
|
|
Package = NULL;
|
|
|
|
|
|
|
|
Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);
|
|
|
|
if (EFI_ERROR(Status)) {
|
|
|
|
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
|
2015-02-03 22:22:53 +01:00
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"sermode", ProblemParam);
|
2010-11-16 23:36:37 +01:00
|
|
|
FreePool(ProblemParam);
|
|
|
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
|
|
|
} else {
|
|
|
|
ASSERT(FALSE);
|
|
|
|
}
|
|
|
|
} else {
|
2011-03-25 22:22:20 +01:00
|
|
|
if (ShellCommandLineGetCount(Package) < 6 && ShellCommandLineGetCount(Package) > 2) {
|
2015-02-03 22:22:53 +01:00
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"sermode");
|
2010-11-16 23:36:37 +01:00
|
|
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
2011-03-25 22:22:20 +01:00
|
|
|
} else if (ShellCommandLineGetCount(Package) > 6) {
|
2015-02-03 22:22:53 +01:00
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"sermode");
|
2010-11-16 23:36:37 +01:00
|
|
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
|
|
|
} else {
|
|
|
|
Temp = ShellCommandLineGetRawValue(Package, 1);
|
|
|
|
if (Temp != NULL) {
|
2011-03-25 22:22:20 +01:00
|
|
|
Status = ShellConvertStringToUint64(Temp, &Intermediate, TRUE, FALSE);
|
|
|
|
HandleIdx = (UINTN)Intermediate;
|
2010-11-16 23:36:37 +01:00
|
|
|
Temp = ShellCommandLineGetRawValue(Package, 2);
|
|
|
|
if (Temp == NULL) {
|
2011-03-25 22:22:20 +01:00
|
|
|
ShellStatus = DisplaySettings (HandleIdx, TRUE);
|
2010-11-16 23:36:37 +01:00
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
} else {
|
2011-03-25 22:22:20 +01:00
|
|
|
ShellStatus = DisplaySettings (0, FALSE);
|
2010-11-16 23:36:37 +01:00
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
Temp = ShellCommandLineGetRawValue(Package, 2);
|
|
|
|
if (Temp != NULL) {
|
2011-03-25 22:22:20 +01:00
|
|
|
BaudRate = ShellStrToUintn(Temp);
|
2010-11-16 23:36:37 +01:00
|
|
|
} else {
|
|
|
|
ASSERT(FALSE);
|
|
|
|
BaudRate = 0;
|
|
|
|
}
|
|
|
|
Temp = ShellCommandLineGetRawValue(Package, 3);
|
|
|
|
if (Temp == NULL || StrLen(Temp)>1) {
|
2015-02-03 22:22:53 +01:00
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"sermode", Temp);
|
2010-11-16 23:36:37 +01:00
|
|
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
|
|
|
} else {
|
|
|
|
switch(Temp[0]){
|
|
|
|
case 'd':
|
|
|
|
case 'D':
|
|
|
|
Parity = DefaultParity;
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
case 'N':
|
|
|
|
Parity = NoParity;
|
|
|
|
break;
|
|
|
|
case 'e':
|
|
|
|
case 'E':
|
|
|
|
Parity = EvenParity;
|
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
case 'O':
|
|
|
|
Parity = OddParity;
|
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
case 'M':
|
|
|
|
Parity = MarkParity;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
case 'S':
|
|
|
|
Parity = SpaceParity;
|
|
|
|
break;
|
|
|
|
default:
|
2015-02-03 22:22:53 +01:00
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"sermode", Temp);
|
2010-11-16 23:36:37 +01:00
|
|
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Temp = ShellCommandLineGetRawValue(Package, 4);
|
|
|
|
if (Temp != NULL) {
|
2011-03-25 22:22:20 +01:00
|
|
|
DataBits = ShellStrToUintn(Temp);
|
2010-11-16 23:36:37 +01:00
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// make sure this is some number not in the list below.
|
|
|
|
//
|
|
|
|
DataBits = 0;
|
|
|
|
}
|
|
|
|
switch (DataBits) {
|
|
|
|
case 4:
|
|
|
|
case 7:
|
|
|
|
case 8:
|
|
|
|
break;
|
|
|
|
default:
|
2015-02-03 22:22:53 +01:00
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"sermode", Temp);
|
2010-11-16 23:36:37 +01:00
|
|
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
Temp = ShellCommandLineGetRawValue(Package, 5);
|
2011-03-25 22:22:20 +01:00
|
|
|
Value = ShellStrToUintn(Temp);
|
2010-11-16 23:36:37 +01:00
|
|
|
switch (Value) {
|
|
|
|
case 0:
|
|
|
|
StopBits = DefaultStopBits;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
StopBits = OneStopBit;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
StopBits = TwoStopBits;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 15:
|
|
|
|
StopBits = OneFiveStopBits;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2015-02-03 22:22:53 +01:00
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"sermode", Temp);
|
2010-11-16 23:36:37 +01:00
|
|
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiSerialIoProtocolGuid, NULL, &NoHandles, &Handles);
|
|
|
|
if (EFI_ERROR (Status)) {
|
2015-02-03 22:22:53 +01:00
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SERMODE_NO_FOUND), gShellDebug1HiiHandle, L"sermode");
|
2010-11-16 23:36:37 +01:00
|
|
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Index = 0; Index < NoHandles; Index++) {
|
|
|
|
if (ConvertHandleIndexToHandle (HandleIdx) != Handles[Index]) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = gBS->HandleProtocol (Handles[Index], &gEfiSerialIoProtocolGuid, (VOID**)&SerialIo);
|
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
Status = SerialIo->SetAttributes (
|
|
|
|
SerialIo,
|
|
|
|
(UINT64) BaudRate,
|
|
|
|
SerialIo->Mode->ReceiveFifoDepth,
|
|
|
|
SerialIo->Mode->Timeout,
|
|
|
|
Parity,
|
|
|
|
(UINT8) DataBits,
|
|
|
|
StopBits
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
2015-02-03 22:22:53 +01:00
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SERMODE_SET_FAIL), gShellDebug1HiiHandle, L"sermode", ConvertHandleToHandleIndex(Handles[Index]));
|
2010-11-16 23:36:37 +01:00
|
|
|
ShellStatus = SHELL_ACCESS_DENIED;
|
|
|
|
} else {
|
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SERMODE_SET_HANDLE), gShellDebug1HiiHandle, ConvertHandleToHandleIndex(Handles[Index]));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-25 22:22:20 +01:00
|
|
|
if (ShellStatus == SHELL_SUCCESS && Index == NoHandles) {
|
2015-02-03 22:22:53 +01:00
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SERMODE_BAD_HANDLE), gShellDebug1HiiHandle, L"sermode", HandleIdx);
|
2010-11-16 23:36:37 +01:00
|
|
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
Done:
|
|
|
|
if (Package != NULL) {
|
|
|
|
ShellCommandLineFreeVarList (Package);
|
|
|
|
}
|
|
|
|
if (Handles != NULL) {
|
|
|
|
FreePool (Handles);
|
|
|
|
}
|
|
|
|
return ShellStatus;
|
|
|
|
}
|