mirror of
https://github.com/tianocore/edk2
synced 2026-08-27 00:23:19 -04:00
ShellPkg/UefiShellDebug1: Extract MainCmdXXX() function (4/4)
This patch aims to help breaking down the long functions present in the ShellPkg and reduce complexity/nested code and conditions. Extract a MainCmdXXX() function for each shell command. This command contains the possible operations the command aims to operate. The ShellCommandRunXXX() function from which it is extracted is only responsible of: - initializing the shell/command environment - parsing the command parameter and creating a Package - freeing the Package For the MemMap and SetVar commands, ShellCommandLineFreeVarList() calls are removed as the Package is now freed in the caller function: ShellCommandRunXXX(). To avoid having one large commit updating all the UefiShellDebug1 commands, only update these files: - SerMode.c - SetSize.c - SetVar.c - SmbiosView/SmbiosView.c No functional change should be induced by this patch. Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
This commit is contained in:
parent
0b6156b43a
commit
cebf8bc4ae
4 changed files with 211 additions and 130 deletions
|
|
@ -239,17 +239,14 @@ ValidDataBits (
|
|||
return (DataBits == 4) || (DataBits == 7) || (DataBits == 8);
|
||||
}
|
||||
|
||||
/**
|
||||
Function for 'sermode' command.
|
||||
/** Main function of the 'SerMode' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
@param[in] Package List of input parameter for the command.
|
||||
**/
|
||||
STATIC
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunSerMode (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
MainCmdSerMode (
|
||||
LIST_ENTRY *Package
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
|
|
@ -263,8 +260,6 @@ ShellCommandRunSerMode (
|
|||
UINTN BaudRate;
|
||||
UINTN DataBits;
|
||||
EFI_SERIAL_IO_PROTOCOL *SerialIo;
|
||||
LIST_ENTRY *Package;
|
||||
CHAR16 *ProblemParam;
|
||||
CONST CHAR16 *Temp;
|
||||
UINT64 Intermediate;
|
||||
|
||||
|
|
@ -275,19 +270,6 @@ ShellCommandRunSerMode (
|
|||
NoHandles = 0;
|
||||
Index = 0;
|
||||
|
||||
Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);
|
||||
if (EFI_ERROR (Status)) {
|
||||
if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
|
||||
ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"sermode", ProblemParam);
|
||||
FreePool (ProblemParam);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
ASSERT (FALSE);
|
||||
}
|
||||
|
||||
return ShellStatus;
|
||||
}
|
||||
|
||||
if ((ShellCommandLineGetCount (Package) < 6) && (ShellCommandLineGetCount (Package) > 2)) {
|
||||
ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"sermode");
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
|
|
@ -409,11 +391,50 @@ ShellCommandRunSerMode (
|
|||
}
|
||||
|
||||
Done:
|
||||
ShellCommandLineFreeVarList (Package);
|
||||
|
||||
if (Handles != NULL) {
|
||||
FreePool (Handles);
|
||||
}
|
||||
|
||||
return ShellStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
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).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunSerMode (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
SHELL_STATUS ShellStatus;
|
||||
LIST_ENTRY *Package;
|
||||
CHAR16 *ProblemParam;
|
||||
|
||||
ShellStatus = SHELL_SUCCESS;
|
||||
Package = NULL;
|
||||
|
||||
Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);
|
||||
if (EFI_ERROR (Status)) {
|
||||
if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
|
||||
ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"sermode", ProblemParam);
|
||||
FreePool (ProblemParam);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
ASSERT (FALSE);
|
||||
}
|
||||
|
||||
return ShellStatus;
|
||||
}
|
||||
|
||||
ShellStatus = MainCmdSerMode (Package);
|
||||
|
||||
ShellCommandLineFreeVarList (Package);
|
||||
|
||||
return ShellStatus;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,22 +9,17 @@
|
|||
|
||||
#include "UefiShellDebug1CommandsLib.h"
|
||||
|
||||
/**
|
||||
Function for 'setsize' command.
|
||||
/** Main function of the 'SetSize' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
@param[in] Package List of input parameter for the command.
|
||||
**/
|
||||
STATIC
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunSetSize (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
MainCmdSetSize (
|
||||
LIST_ENTRY *Package
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
LIST_ENTRY *Package;
|
||||
CHAR16 *ProblemParam;
|
||||
SHELL_STATUS ShellStatus;
|
||||
CONST CHAR16 *Temp1;
|
||||
UINTN NewSize;
|
||||
|
|
@ -34,31 +29,6 @@ ShellCommandRunSetSize (
|
|||
ShellStatus = SHELL_SUCCESS;
|
||||
Status = EFI_SUCCESS;
|
||||
|
||||
//
|
||||
// initialize the shell lib (we must be in non-auto-init...)
|
||||
//
|
||||
Status = ShellInitialize ();
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
Status = CommandInit ();
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
//
|
||||
// parse the command line
|
||||
//
|
||||
Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);
|
||||
if (EFI_ERROR (Status)) {
|
||||
if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
|
||||
ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"setsize", ProblemParam);
|
||||
FreePool (ProblemParam);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
ASSERT (FALSE);
|
||||
}
|
||||
|
||||
return ShellStatus;
|
||||
}
|
||||
|
||||
if (ShellCommandLineGetCount (Package) < 3) {
|
||||
ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"setsize");
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
|
|
@ -107,6 +77,57 @@ ShellCommandRunSetSize (
|
|||
}
|
||||
}
|
||||
|
||||
return ShellStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
Function for 'setsize' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunSetSize (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
LIST_ENTRY *Package;
|
||||
CHAR16 *ProblemParam;
|
||||
SHELL_STATUS ShellStatus;
|
||||
|
||||
ShellStatus = SHELL_SUCCESS;
|
||||
Status = EFI_SUCCESS;
|
||||
|
||||
//
|
||||
// initialize the shell lib (we must be in non-auto-init...)
|
||||
//
|
||||
Status = ShellInitialize ();
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
Status = CommandInit ();
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
//
|
||||
// parse the command line
|
||||
//
|
||||
Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);
|
||||
if (EFI_ERROR (Status)) {
|
||||
if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
|
||||
ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"setsize", ProblemParam);
|
||||
FreePool (ProblemParam);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
ASSERT (FALSE);
|
||||
}
|
||||
|
||||
return ShellStatus;
|
||||
}
|
||||
|
||||
ShellStatus = MainCmdSetSize (Package);
|
||||
|
||||
ShellCommandLineFreeVarList (Package);
|
||||
|
||||
return (ShellStatus);
|
||||
|
|
|
|||
|
|
@ -341,23 +341,18 @@ GetVariableDataFromParameter (
|
|||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
Function for 'setvar' command.
|
||||
/** Main function of the 'SetVar' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
@param[in] Package List of input parameter for the command.
|
||||
**/
|
||||
STATIC
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunSetVar (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
MainCmdSetVar (
|
||||
LIST_ENTRY *Package
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
RETURN_STATUS RStatus;
|
||||
LIST_ENTRY *Package;
|
||||
CHAR16 *ProblemParam;
|
||||
SHELL_STATUS ShellStatus;
|
||||
CONST CHAR16 *VariableName;
|
||||
EFI_GUID Guid;
|
||||
|
|
@ -373,43 +368,12 @@ ShellCommandRunSetVar (
|
|||
Size = 0;
|
||||
Attributes = 0;
|
||||
|
||||
//
|
||||
// initialize the shell lib (we must be in non-auto-init...)
|
||||
//
|
||||
Status = ShellInitialize ();
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
Status = CommandInit ();
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
//
|
||||
// parse the command line
|
||||
//
|
||||
Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
|
||||
if (EFI_ERROR (Status)) {
|
||||
if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
|
||||
ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"setvar", ProblemParam);
|
||||
FreePool (ProblemParam);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
ASSERT (FALSE);
|
||||
}
|
||||
|
||||
return ShellStatus;
|
||||
} else if (ShellCommandLineCheckDuplicate (Package, &ProblemParam) != EFI_SUCCESS) {
|
||||
ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_DUPLICATE), gShellDebug1HiiHandle, L"setvar", ProblemParam);
|
||||
ShellCommandLineFreeVarList (Package);
|
||||
FreePool (ProblemParam);
|
||||
return SHELL_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (ShellCommandLineGetCount (Package) < 2) {
|
||||
ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"setvar");
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
VariableName = ShellCommandLineGetRawValue (Package, 1);
|
||||
if (VariableName == NULL) {
|
||||
ShellCommandLineFreeVarList (Package);
|
||||
return SHELL_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
|
|
@ -421,7 +385,6 @@ ShellCommandRunSetVar (
|
|||
RStatus = StrToGuid (StringGuid, &Guid);
|
||||
} else {
|
||||
ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"setvar", StringGuid);
|
||||
ShellCommandLineFreeVarList (Package);
|
||||
return SHELL_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
|
|
@ -440,7 +403,6 @@ ShellCommandRunSetVar (
|
|||
Buffer = AllocateZeroPool (Size);
|
||||
if (Buffer == NULL) {
|
||||
ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"setvar");
|
||||
ShellCommandLineFreeVarList (Package);
|
||||
return SHELL_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
|
|
@ -467,7 +429,6 @@ ShellCommandRunSetVar (
|
|||
Buffer = AllocateZeroPool (Size);
|
||||
if (Buffer == NULL) {
|
||||
ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"setvar");
|
||||
ShellCommandLineFreeVarList (Package);
|
||||
return SHELL_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
|
|
@ -510,11 +471,67 @@ ShellCommandRunSetVar (
|
|||
}
|
||||
}
|
||||
|
||||
ShellCommandLineFreeVarList (Package);
|
||||
|
||||
if (Buffer != NULL) {
|
||||
FreePool (Buffer);
|
||||
}
|
||||
|
||||
return ShellStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
Function for 'setvar' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunSetVar (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
LIST_ENTRY *Package;
|
||||
CHAR16 *ProblemParam;
|
||||
SHELL_STATUS ShellStatus;
|
||||
|
||||
ShellStatus = SHELL_SUCCESS;
|
||||
Status = EFI_SUCCESS;
|
||||
|
||||
//
|
||||
// initialize the shell lib (we must be in non-auto-init...)
|
||||
//
|
||||
Status = ShellInitialize ();
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
Status = CommandInit ();
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
//
|
||||
// parse the command line
|
||||
//
|
||||
Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
|
||||
if (EFI_ERROR (Status)) {
|
||||
if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
|
||||
ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"setvar", ProblemParam);
|
||||
FreePool (ProblemParam);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
ASSERT (FALSE);
|
||||
}
|
||||
|
||||
return ShellStatus;
|
||||
} else if (ShellCommandLineCheckDuplicate (Package, &ProblemParam) != EFI_SUCCESS) {
|
||||
ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_DUPLICATE), gShellDebug1HiiHandle, L"setvar", ProblemParam);
|
||||
ShellCommandLineFreeVarList (Package);
|
||||
FreePool (ProblemParam);
|
||||
return SHELL_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ShellStatus = MainCmdSetVar (Package);
|
||||
|
||||
ShellCommandLineFreeVarList (Package);
|
||||
|
||||
return (ShellStatus);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,17 +32,14 @@ STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
|
|||
{ NULL, TypeMax }
|
||||
};
|
||||
|
||||
/**
|
||||
Function for 'smbiosview' command.
|
||||
/** Main function of the 'SmbiosView' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
@param[in] Package List of input parameter for the command.
|
||||
**/
|
||||
STATIC
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunSmbiosView (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
MainCmdSmbiosView (
|
||||
LIST_ENTRY *Package
|
||||
)
|
||||
{
|
||||
UINT8 StructType;
|
||||
|
|
@ -51,8 +48,6 @@ ShellCommandRunSmbiosView (
|
|||
EFI_STATUS Status1;
|
||||
EFI_STATUS Status2;
|
||||
BOOLEAN RandomView;
|
||||
LIST_ENTRY *Package;
|
||||
CHAR16 *ProblemParam;
|
||||
SHELL_STATUS ShellStatus;
|
||||
CONST CHAR16 *Temp;
|
||||
|
||||
|
|
@ -60,19 +55,6 @@ ShellCommandRunSmbiosView (
|
|||
mSmbios64BitStatisticsTable = NULL;
|
||||
ShellStatus = SHELL_SUCCESS;
|
||||
|
||||
Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
|
||||
if (EFI_ERROR (Status)) {
|
||||
if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
|
||||
ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"smbiosview", ProblemParam);
|
||||
FreePool (ProblemParam);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
ASSERT (FALSE);
|
||||
}
|
||||
|
||||
return ShellStatus;
|
||||
}
|
||||
|
||||
if (ShellCommandLineGetCount (Package) > 1) {
|
||||
ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"smbiosview");
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
|
|
@ -220,8 +202,48 @@ Done:
|
|||
mSmbios64BitStatisticsTable = NULL;
|
||||
}
|
||||
|
||||
ShellCommandLineFreeVarList (Package);
|
||||
return ShellStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
Function for 'smbiosview' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunSmbiosView (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
LIST_ENTRY *Package;
|
||||
CHAR16 *ProblemParam;
|
||||
SHELL_STATUS ShellStatus;
|
||||
|
||||
mStatisticsTable = NULL;
|
||||
mSmbios64BitStatisticsTable = NULL;
|
||||
Package = NULL;
|
||||
ShellStatus = SHELL_SUCCESS;
|
||||
|
||||
Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
|
||||
if (EFI_ERROR (Status)) {
|
||||
if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
|
||||
ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"smbiosview", ProblemParam);
|
||||
FreePool (ProblemParam);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
ASSERT (FALSE);
|
||||
}
|
||||
|
||||
return ShellStatus;
|
||||
}
|
||||
|
||||
ShellStatus = MainCmdSmbiosView (Package);
|
||||
|
||||
ShellCommandLineFreeVarList (Package);
|
||||
LibSmbiosCleanup ();
|
||||
LibSmbios64BitCleanup ();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue