2010-11-16 23:36:37 +01:00
|
|
|
/** @file
|
|
|
|
Main file for DmpStore shell Debug1 function.
|
2014-06-30 22:14:24 +02:00
|
|
|
|
2015-02-04 23:25:01 +01:00
|
|
|
(C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>
|
2017-02-21 10:20:54 +01:00
|
|
|
Copyright (c) 2005 - 2017, 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"
|
|
|
|
|
2014-01-10 02:52:24 +01:00
|
|
|
typedef enum {
|
|
|
|
DmpStoreDisplay,
|
|
|
|
DmpStoreDelete,
|
|
|
|
DmpStoreSave,
|
|
|
|
DmpStoreLoad
|
|
|
|
} DMP_STORE_TYPE;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
UINT32 Signature;
|
|
|
|
CHAR16 *Name;
|
|
|
|
EFI_GUID Guid;
|
|
|
|
UINT32 Attributes;
|
|
|
|
UINT32 DataSize;
|
|
|
|
UINT8 *Data;
|
|
|
|
LIST_ENTRY Link;
|
|
|
|
} DMP_STORE_VARIABLE;
|
|
|
|
|
|
|
|
#define DMP_STORE_VARIABLE_SIGNATURE SIGNATURE_32 ('_', 'd', 's', 's')
|
|
|
|
|
2012-08-07 02:44:28 +02:00
|
|
|
/**
|
|
|
|
Base on the input attribute value to return the attribute string.
|
|
|
|
|
|
|
|
@param[in] Atts The input attribute value
|
|
|
|
|
|
|
|
@retval The attribute string info.
|
|
|
|
**/
|
2012-09-03 03:59:05 +02:00
|
|
|
CHAR16 *
|
2012-07-26 09:15:31 +02:00
|
|
|
GetAttrType (
|
2012-09-03 03:59:05 +02:00
|
|
|
IN CONST UINT32 Atts
|
2012-07-26 09:15:31 +02:00
|
|
|
)
|
|
|
|
{
|
2012-09-04 10:35:16 +02:00
|
|
|
UINTN BufLen;
|
2012-09-03 03:59:05 +02:00
|
|
|
CHAR16 *RetString;
|
2012-07-26 09:15:31 +02:00
|
|
|
|
2012-09-03 03:59:05 +02:00
|
|
|
BufLen = 0;
|
|
|
|
RetString = NULL;
|
|
|
|
|
2012-08-07 02:44:28 +02:00
|
|
|
if ((Atts & EFI_VARIABLE_NON_VOLATILE) != 0) {
|
2012-09-03 03:59:05 +02:00
|
|
|
StrnCatGrow (&RetString, &BufLen, L"+NV", 0);
|
2012-07-26 09:15:31 +02:00
|
|
|
}
|
2012-08-07 02:44:28 +02:00
|
|
|
if ((Atts & EFI_VARIABLE_RUNTIME_ACCESS) != 0) {
|
2014-01-23 01:29:53 +01:00
|
|
|
StrnCatGrow (&RetString, &BufLen, L"+RT+BS", 0);
|
2012-08-07 02:44:28 +02:00
|
|
|
} else if ((Atts & EFI_VARIABLE_BOOTSERVICE_ACCESS) != 0) {
|
2012-09-03 03:59:05 +02:00
|
|
|
StrnCatGrow (&RetString, &BufLen, L"+BS", 0);
|
2012-07-26 09:15:31 +02:00
|
|
|
}
|
2012-08-07 02:44:28 +02:00
|
|
|
if ((Atts & EFI_VARIABLE_HARDWARE_ERROR_RECORD) != 0) {
|
2012-09-03 03:59:05 +02:00
|
|
|
StrnCatGrow (&RetString, &BufLen, L"+HR", 0);
|
2012-07-26 09:15:31 +02:00
|
|
|
}
|
2012-08-07 02:44:28 +02:00
|
|
|
if ((Atts & EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS) != 0) {
|
2012-09-03 03:59:05 +02:00
|
|
|
StrnCatGrow (&RetString, &BufLen, L"+AW", 0);
|
2012-07-26 09:15:31 +02:00
|
|
|
}
|
2012-08-07 02:44:28 +02:00
|
|
|
if ((Atts & EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) != 0) {
|
2012-09-03 03:59:05 +02:00
|
|
|
StrnCatGrow (&RetString, &BufLen, L"+AT", 0);
|
2012-07-26 09:15:31 +02:00
|
|
|
}
|
|
|
|
|
2012-09-03 03:59:05 +02:00
|
|
|
if (RetString == NULL) {
|
|
|
|
RetString = StrnCatGrow(&RetString, &BufLen, L"Invalid", 0);
|
2012-07-26 09:15:31 +02:00
|
|
|
}
|
2012-09-03 03:59:05 +02:00
|
|
|
|
2012-09-10 11:35:43 +02:00
|
|
|
if ((RetString != NULL) && (RetString[0] == L'+')) {
|
2012-09-03 03:59:05 +02:00
|
|
|
CopyMem(RetString, RetString + 1, StrSize(RetString + 1));
|
2012-07-26 09:15:31 +02:00
|
|
|
}
|
2012-09-03 03:59:05 +02:00
|
|
|
|
|
|
|
return RetString;
|
2012-07-26 09:15:31 +02:00
|
|
|
}
|
2010-11-16 23:36:37 +01:00
|
|
|
|
ShellPkg/dmpstore: Support "-sfo"
The patch adds the "-sfo" support to "dmpstore" command.
When -l or -d is specified, -sfo is not supported.
When the variable specified by name and GUID cannot be found,
an error message is displayed; Otherwise, the SFO is displayed.
E.g.: "dmpstore -guid GuidThatDoesntExist -sfo" produces output
as:
ShellCommand,"dmpstore"
VariableInfo,"","GuidThatDoesntExist","","",""
"dmpstore NameThatDoesntExist -guid GuidThatDoesntExist -sfo"
produces output as:
ShellCommand,"dmpstore"
dmpstore: No matching variables found. Guid GuidThatDoesntExist, Name
NameThatDoesntExist
The difference between the above 2 cases is that former one only
specifies the GUID, but the latter one specifies both name and GUID.
Since not specifying GUID means to use GlobalVariableGuid,
"dmpstore NameThatDoesntExist -sfo" produces the similar output as
latter one.
I personally prefer to always produce SFO output for both cases.
But the above behavior is the discussion result between HPE engineers.
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Signed-off-by: Chen A Chen <chen.a.chen@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Tapan Shah <tapandshah@hpe.com>
2016-11-11 05:12:51 +01:00
|
|
|
/**
|
|
|
|
Convert binary to hex format string.
|
|
|
|
|
|
|
|
@param[in] Buffer The binary data.
|
2016-12-12 07:11:14 +01:00
|
|
|
@param[in] BufferSize The size in bytes of the binary data.
|
ShellPkg/dmpstore: Support "-sfo"
The patch adds the "-sfo" support to "dmpstore" command.
When -l or -d is specified, -sfo is not supported.
When the variable specified by name and GUID cannot be found,
an error message is displayed; Otherwise, the SFO is displayed.
E.g.: "dmpstore -guid GuidThatDoesntExist -sfo" produces output
as:
ShellCommand,"dmpstore"
VariableInfo,"","GuidThatDoesntExist","","",""
"dmpstore NameThatDoesntExist -guid GuidThatDoesntExist -sfo"
produces output as:
ShellCommand,"dmpstore"
dmpstore: No matching variables found. Guid GuidThatDoesntExist, Name
NameThatDoesntExist
The difference between the above 2 cases is that former one only
specifies the GUID, but the latter one specifies both name and GUID.
Since not specifying GUID means to use GlobalVariableGuid,
"dmpstore NameThatDoesntExist -sfo" produces the similar output as
latter one.
I personally prefer to always produce SFO output for both cases.
But the above behavior is the discussion result between HPE engineers.
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Signed-off-by: Chen A Chen <chen.a.chen@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Tapan Shah <tapandshah@hpe.com>
2016-11-11 05:12:51 +01:00
|
|
|
@param[in, out] HexString Hex format string.
|
|
|
|
@param[in] HexStringSize The size in bytes of the string.
|
|
|
|
|
|
|
|
@return The hex format string.
|
|
|
|
**/
|
|
|
|
CHAR16*
|
|
|
|
BinaryToHexString (
|
|
|
|
IN VOID *Buffer,
|
|
|
|
IN UINTN BufferSize,
|
|
|
|
IN OUT CHAR16 *HexString,
|
|
|
|
IN UINTN HexStringSize
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UINTN Index;
|
|
|
|
UINTN StringIndex;
|
|
|
|
|
|
|
|
ASSERT (Buffer != NULL);
|
|
|
|
ASSERT ((BufferSize * 2 + 1) * sizeof (CHAR16) <= HexStringSize);
|
|
|
|
|
|
|
|
for (Index = 0, StringIndex = 0; Index < BufferSize; Index += 1) {
|
|
|
|
StringIndex +=
|
|
|
|
UnicodeSPrint (
|
|
|
|
&HexString[StringIndex],
|
|
|
|
HexStringSize - StringIndex * sizeof (CHAR16),
|
|
|
|
L"%02x",
|
|
|
|
((UINT8 *) Buffer)[Index]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return HexString;
|
|
|
|
}
|
|
|
|
|
2014-01-10 02:52:24 +01:00
|
|
|
/**
|
|
|
|
Load the variable data from file and set to variable data base.
|
|
|
|
|
|
|
|
@param[in] FileHandle The file to be read.
|
|
|
|
@param[in] Name The name of the variables to be loaded.
|
|
|
|
@param[in] Guid The guid of the variables to be loaded.
|
|
|
|
@param[out] Found TRUE when at least one variable was loaded and set.
|
|
|
|
|
2014-01-14 08:30:50 +01:00
|
|
|
@retval SHELL_DEVICE_ERROR Cannot access the file.
|
|
|
|
@retval SHELL_VOLUME_CORRUPTED The file is in bad format.
|
|
|
|
@retval SHELL_OUT_OF_RESOURCES There is not enough memory to perform the operation.
|
|
|
|
@retval SHELL_SUCCESS Successfully load and set the variables.
|
2014-01-10 02:52:24 +01:00
|
|
|
**/
|
2014-01-14 08:30:50 +01:00
|
|
|
SHELL_STATUS
|
2014-01-10 02:52:24 +01:00
|
|
|
LoadVariablesFromFile (
|
|
|
|
IN SHELL_FILE_HANDLE FileHandle,
|
|
|
|
IN CONST CHAR16 *Name,
|
|
|
|
IN CONST EFI_GUID *Guid,
|
|
|
|
OUT BOOLEAN *Found
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
2014-01-14 08:30:50 +01:00
|
|
|
SHELL_STATUS ShellStatus;
|
2014-01-10 02:52:24 +01:00
|
|
|
UINT32 NameSize;
|
|
|
|
UINT32 DataSize;
|
|
|
|
UINTN BufferSize;
|
|
|
|
UINTN RemainingSize;
|
|
|
|
UINT64 Position;
|
|
|
|
UINT64 FileSize;
|
|
|
|
LIST_ENTRY List;
|
|
|
|
DMP_STORE_VARIABLE *Variable;
|
|
|
|
LIST_ENTRY *Link;
|
|
|
|
CHAR16 *Attributes;
|
|
|
|
UINT8 *Buffer;
|
|
|
|
UINT32 Crc32;
|
|
|
|
|
|
|
|
Status = ShellGetFileSize (FileHandle, &FileSize);
|
|
|
|
if (EFI_ERROR (Status)) {
|
2014-01-14 08:30:50 +01:00
|
|
|
return SHELL_DEVICE_ERROR;
|
2014-01-10 02:52:24 +01:00
|
|
|
}
|
2014-01-14 08:30:50 +01:00
|
|
|
|
|
|
|
ShellStatus = SHELL_SUCCESS;
|
|
|
|
|
2014-01-10 02:52:24 +01:00
|
|
|
InitializeListHead (&List);
|
|
|
|
|
|
|
|
Position = 0;
|
|
|
|
while (Position < FileSize) {
|
|
|
|
//
|
|
|
|
// NameSize
|
|
|
|
//
|
|
|
|
BufferSize = sizeof (NameSize);
|
|
|
|
Status = ShellReadFile (FileHandle, &BufferSize, &NameSize);
|
|
|
|
if (EFI_ERROR (Status) || (BufferSize != sizeof (NameSize))) {
|
2014-01-14 08:30:50 +01:00
|
|
|
ShellStatus = SHELL_VOLUME_CORRUPTED;
|
2014-01-10 02:52:24 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// DataSize
|
|
|
|
//
|
|
|
|
BufferSize = sizeof (DataSize);
|
|
|
|
Status = ShellReadFile (FileHandle, &BufferSize, &DataSize);
|
|
|
|
if (EFI_ERROR (Status) || (BufferSize != sizeof (DataSize))) {
|
2014-01-14 08:30:50 +01:00
|
|
|
ShellStatus = SHELL_VOLUME_CORRUPTED;
|
2014-01-10 02:52:24 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Name, Guid, Attributes, Data, Crc32
|
|
|
|
//
|
|
|
|
RemainingSize = NameSize + sizeof (EFI_GUID) + sizeof (UINT32) + DataSize + sizeof (Crc32);
|
|
|
|
BufferSize = sizeof (NameSize) + sizeof (DataSize) + RemainingSize;
|
|
|
|
Buffer = AllocatePool (BufferSize);
|
|
|
|
if (Buffer == NULL) {
|
2014-01-14 08:30:50 +01:00
|
|
|
ShellStatus = SHELL_OUT_OF_RESOURCES;
|
2014-01-10 02:52:24 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
BufferSize = RemainingSize;
|
|
|
|
Status = ShellReadFile (FileHandle, &BufferSize, (UINT32 *) Buffer + 2);
|
|
|
|
if (EFI_ERROR (Status) || (BufferSize != RemainingSize)) {
|
2014-01-14 08:30:50 +01:00
|
|
|
ShellStatus = SHELL_VOLUME_CORRUPTED;
|
2014-01-10 02:52:24 +01:00
|
|
|
FreePool (Buffer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Check Crc32
|
|
|
|
//
|
|
|
|
* (UINT32 *) Buffer = NameSize;
|
|
|
|
* ((UINT32 *) Buffer + 1) = DataSize;
|
|
|
|
BufferSize = RemainingSize + sizeof (NameSize) + sizeof (DataSize) - sizeof (Crc32);
|
|
|
|
gBS->CalculateCrc32 (
|
|
|
|
Buffer,
|
|
|
|
BufferSize,
|
|
|
|
&Crc32
|
|
|
|
);
|
|
|
|
if (Crc32 != * (UINT32 *) (Buffer + BufferSize)) {
|
|
|
|
FreePool (Buffer);
|
2014-01-14 08:30:50 +01:00
|
|
|
ShellStatus = SHELL_VOLUME_CORRUPTED;
|
2014-01-10 02:52:24 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Position += BufferSize + sizeof (Crc32);
|
|
|
|
|
|
|
|
Variable = AllocateZeroPool (sizeof (*Variable) + NameSize + DataSize);
|
|
|
|
if (Variable == NULL) {
|
|
|
|
FreePool (Buffer);
|
2014-01-14 08:30:50 +01:00
|
|
|
ShellStatus = SHELL_OUT_OF_RESOURCES;
|
2014-01-10 02:52:24 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
Variable->Signature = DMP_STORE_VARIABLE_SIGNATURE;
|
|
|
|
Variable->Name = (CHAR16 *) (Variable + 1);
|
|
|
|
Variable->DataSize = DataSize;
|
|
|
|
Variable->Data = (UINT8 *) Variable->Name + NameSize;
|
|
|
|
CopyMem (Variable->Name, Buffer + sizeof (NameSize) + sizeof (DataSize), NameSize);
|
|
|
|
CopyMem (&Variable->Guid, Buffer + sizeof (NameSize) + sizeof (DataSize) + NameSize, sizeof (EFI_GUID));
|
|
|
|
CopyMem (&Variable->Attributes, Buffer + sizeof (NameSize) + sizeof (DataSize) + NameSize + sizeof (EFI_GUID), sizeof (UINT32));
|
|
|
|
CopyMem (Variable->Data, Buffer + sizeof (NameSize) + sizeof (DataSize) + NameSize + sizeof (EFI_GUID) + sizeof (UINT32), DataSize);
|
|
|
|
|
|
|
|
InsertTailList (&List, &Variable->Link);
|
|
|
|
FreePool (Buffer);
|
|
|
|
}
|
|
|
|
|
2014-01-14 08:30:50 +01:00
|
|
|
if ((Position != FileSize) || (ShellStatus != SHELL_SUCCESS)) {
|
2015-02-03 22:22:53 +01:00
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_LOAD_BAD_FILE), gShellDebug1HiiHandle, L"dmpstore");
|
2014-01-14 08:30:50 +01:00
|
|
|
if (Position != FileSize) {
|
|
|
|
ShellStatus = SHELL_VOLUME_CORRUPTED;
|
|
|
|
}
|
2014-01-10 02:52:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for ( Link = GetFirstNode (&List)
|
2014-01-14 08:30:50 +01:00
|
|
|
; !IsNull (&List, Link) && (ShellStatus == SHELL_SUCCESS)
|
2014-01-10 02:52:24 +01:00
|
|
|
; Link = GetNextNode (&List, Link)
|
|
|
|
) {
|
|
|
|
Variable = CR (Link, DMP_STORE_VARIABLE, Link, DMP_STORE_VARIABLE_SIGNATURE);
|
|
|
|
|
|
|
|
if (((Name == NULL) || gUnicodeCollation->MetaiMatch (gUnicodeCollation, Variable->Name, (CHAR16 *) Name)) &&
|
|
|
|
((Guid == NULL) || CompareGuid (&Variable->Guid, Guid))
|
|
|
|
) {
|
|
|
|
Attributes = GetAttrType (Variable->Attributes);
|
|
|
|
ShellPrintHiiEx (
|
|
|
|
-1, -1, NULL, STRING_TOKEN(STR_DMPSTORE_HEADER_LINE), gShellDebug1HiiHandle,
|
|
|
|
Attributes, &Variable->Guid, Variable->Name, Variable->DataSize
|
|
|
|
);
|
|
|
|
SHELL_FREE_NON_NULL(Attributes);
|
|
|
|
|
|
|
|
*Found = TRUE;
|
|
|
|
Status = gRT->SetVariable (
|
|
|
|
Variable->Name,
|
|
|
|
&Variable->Guid,
|
|
|
|
Variable->Attributes,
|
|
|
|
Variable->DataSize,
|
|
|
|
Variable->Data
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
2015-02-03 22:22:53 +01:00
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_LOAD_GEN_FAIL), gShellDebug1HiiHandle, L"dmpstore", Variable->Name, Status);
|
2014-01-10 02:52:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Link = GetFirstNode (&List); !IsNull (&List, Link); ) {
|
|
|
|
Variable = CR (Link, DMP_STORE_VARIABLE, Link, DMP_STORE_VARIABLE_SIGNATURE);
|
|
|
|
Link = RemoveEntryList (&Variable->Link);
|
|
|
|
FreePool (Variable);
|
|
|
|
}
|
|
|
|
|
2014-01-14 08:30:50 +01:00
|
|
|
return ShellStatus;
|
2014-01-10 02:52:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Append one variable to file.
|
|
|
|
|
|
|
|
@param[in] FileHandle The file to be appended.
|
|
|
|
@param[in] Name The variable name.
|
|
|
|
@param[in] Guid The variable GUID.
|
|
|
|
@param[in] Attributes The variable attributes.
|
|
|
|
@param[in] DataSize The variable data size.
|
|
|
|
@param[in] Data The variable data.
|
|
|
|
|
|
|
|
@retval EFI_OUT_OF_RESOURCES There is not enough memory to perform the operation.
|
|
|
|
@retval EFI_SUCCESS The variable is appended to file successfully.
|
|
|
|
@retval others Failed to append the variable to file.
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
AppendSingleVariableToFile (
|
|
|
|
IN SHELL_FILE_HANDLE FileHandle,
|
|
|
|
IN CONST CHAR16 *Name,
|
|
|
|
IN CONST EFI_GUID *Guid,
|
|
|
|
IN UINT32 Attributes,
|
|
|
|
IN UINT32 DataSize,
|
|
|
|
IN CONST UINT8 *Data
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UINT32 NameSize;
|
|
|
|
UINT8 *Buffer;
|
|
|
|
UINT8 *Ptr;
|
|
|
|
UINTN BufferSize;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
NameSize = (UINT32) StrSize (Name);
|
|
|
|
BufferSize = sizeof (NameSize) + sizeof (DataSize)
|
|
|
|
+ sizeof (*Guid)
|
|
|
|
+ sizeof (Attributes)
|
|
|
|
+ NameSize + DataSize
|
|
|
|
+ sizeof (UINT32);
|
|
|
|
|
|
|
|
Buffer = AllocatePool (BufferSize);
|
|
|
|
if (Buffer == NULL) {
|
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ptr = Buffer;
|
|
|
|
//
|
|
|
|
// NameSize and DataSize
|
|
|
|
//
|
|
|
|
* (UINT32 *) Ptr = NameSize;
|
|
|
|
Ptr += sizeof (NameSize);
|
|
|
|
*(UINT32 *) Ptr = DataSize;
|
|
|
|
Ptr += sizeof (DataSize);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Name
|
|
|
|
//
|
|
|
|
CopyMem (Ptr, Name, NameSize);
|
|
|
|
Ptr += NameSize;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Guid
|
|
|
|
//
|
|
|
|
CopyMem (Ptr, Guid, sizeof (*Guid));
|
|
|
|
Ptr += sizeof (*Guid);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Attributes
|
|
|
|
//
|
|
|
|
* (UINT32 *) Ptr = Attributes;
|
|
|
|
Ptr += sizeof (Attributes);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Data
|
|
|
|
//
|
|
|
|
CopyMem (Ptr, Data, DataSize);
|
|
|
|
Ptr += DataSize;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Crc32
|
|
|
|
//
|
ShellPkg: Refine type cast for pointer subtraction
For pointer subtraction, the result is of type "ptrdiff_t". According to
the C11 standard (Committee Draft - April 12, 2011):
"When two pointers are subtracted, both shall point to elements of the
same array object, or one past the last element of the array object; the
result is the difference of the subscripts of the two array elements. The
size of the result is implementation-defined, and its type (a signed
integer type) is ptrdiff_t defined in the <stddef.h> header. If the result
is not representable in an object of that type, the behavior is
undefined."
In our codes, there are cases that the pointer subtraction is not
performed by pointers to elements of the same array object. This might
lead to potential issues, since the behavior is undefined according to C11
standard.
Also, since the size of type "ptrdiff_t" is implementation-defined. Some
static code checkers may warn that the pointer subtraction might underflow
first and then being cast to a bigger size. For example:
UINT8 *Ptr1, *Ptr2;
UINTN PtrDiff;
...
PtrDiff = (UINTN) (Ptr1 - Ptr2);
The commit will refine the pointer subtraction expressions by casting each
pointer to UINTN first and then perform the subtraction:
PtrDiff = (UINTN) Ptr1 - (UINTN) Ptr2;
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
2017-01-23 07:38:43 +01:00
|
|
|
gBS->CalculateCrc32 (Buffer, (UINTN) Ptr - (UINTN) Buffer, (UINT32 *) Ptr);
|
2014-01-10 02:52:24 +01:00
|
|
|
|
|
|
|
Status = ShellWriteFile (FileHandle, &BufferSize, Buffer);
|
|
|
|
FreePool (Buffer);
|
|
|
|
|
|
|
|
if (!EFI_ERROR (Status) &&
|
2014-10-07 21:57:23 +02:00
|
|
|
(BufferSize != sizeof (NameSize) + sizeof (DataSize) + sizeof (*Guid) + sizeof (Attributes) + NameSize + DataSize + sizeof (UINT32))
|
2014-01-10 02:52:24 +01:00
|
|
|
) {
|
|
|
|
Status = EFI_DEVICE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2011-03-25 22:22:20 +01:00
|
|
|
/**
|
2013-12-20 23:33:01 +01:00
|
|
|
Recursive function to display or delete variables.
|
|
|
|
|
|
|
|
This function will call itself to create a stack-based list of allt he variables to process,
|
|
|
|
then fromt he last to the first, they will do either printing or deleting.
|
|
|
|
|
|
|
|
This is necessary since once a delete happens GetNextVariableName() will work.
|
2011-03-25 22:22:20 +01:00
|
|
|
|
ShellPkg/dmpstore: Support "-sfo"
The patch adds the "-sfo" support to "dmpstore" command.
When -l or -d is specified, -sfo is not supported.
When the variable specified by name and GUID cannot be found,
an error message is displayed; Otherwise, the SFO is displayed.
E.g.: "dmpstore -guid GuidThatDoesntExist -sfo" produces output
as:
ShellCommand,"dmpstore"
VariableInfo,"","GuidThatDoesntExist","","",""
"dmpstore NameThatDoesntExist -guid GuidThatDoesntExist -sfo"
produces output as:
ShellCommand,"dmpstore"
dmpstore: No matching variables found. Guid GuidThatDoesntExist, Name
NameThatDoesntExist
The difference between the above 2 cases is that former one only
specifies the GUID, but the latter one specifies both name and GUID.
Since not specifying GUID means to use GlobalVariableGuid,
"dmpstore NameThatDoesntExist -sfo" produces the similar output as
latter one.
I personally prefer to always produce SFO output for both cases.
But the above behavior is the discussion result between HPE engineers.
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Signed-off-by: Chen A Chen <chen.a.chen@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Tapan Shah <tapandshah@hpe.com>
2016-11-11 05:12:51 +01:00
|
|
|
@param[in] Name The variable name of the EFI variable (or NULL).
|
|
|
|
@param[in] Guid The GUID of the variable set (or NULL).
|
|
|
|
@param[in] Type The operation type.
|
|
|
|
@param[in] FileHandle The file to operate on (or NULL).
|
|
|
|
@param[in] PrevName The previous variable name from GetNextVariableName. L"" to start.
|
|
|
|
@param[in] FoundVarGuid The previous GUID from GetNextVariableName. ignored at start.
|
|
|
|
@param[in] FoundOne If a VariableName or Guid was specified and one was printed or
|
|
|
|
deleted, then set this to TRUE, otherwise ignored.
|
|
|
|
@param[in] StandardFormatOutput TRUE indicates Standard-Format Output.
|
2011-03-25 22:22:20 +01:00
|
|
|
|
|
|
|
@retval SHELL_SUCCESS The operation was successful.
|
|
|
|
@retval SHELL_OUT_OF_RESOURCES A memorty allocation failed.
|
|
|
|
@retval SHELL_ABORTED The abort message was received.
|
|
|
|
@retval SHELL_DEVICE_ERROR UEFI Variable Services returned an error.
|
|
|
|
@retval SHELL_NOT_FOUND the Name/Guid pair could not be found.
|
|
|
|
**/
|
2010-11-16 23:36:37 +01:00
|
|
|
SHELL_STATUS
|
2013-12-20 23:33:01 +01:00
|
|
|
CascadeProcessVariables (
|
2014-01-10 02:52:24 +01:00
|
|
|
IN CONST CHAR16 *Name OPTIONAL,
|
|
|
|
IN CONST EFI_GUID *Guid OPTIONAL,
|
|
|
|
IN DMP_STORE_TYPE Type,
|
|
|
|
IN EFI_FILE_PROTOCOL *FileHandle OPTIONAL,
|
|
|
|
IN CONST CHAR16 * CONST PrevName,
|
|
|
|
IN EFI_GUID FoundVarGuid,
|
ShellPkg/dmpstore: Support "-sfo"
The patch adds the "-sfo" support to "dmpstore" command.
When -l or -d is specified, -sfo is not supported.
When the variable specified by name and GUID cannot be found,
an error message is displayed; Otherwise, the SFO is displayed.
E.g.: "dmpstore -guid GuidThatDoesntExist -sfo" produces output
as:
ShellCommand,"dmpstore"
VariableInfo,"","GuidThatDoesntExist","","",""
"dmpstore NameThatDoesntExist -guid GuidThatDoesntExist -sfo"
produces output as:
ShellCommand,"dmpstore"
dmpstore: No matching variables found. Guid GuidThatDoesntExist, Name
NameThatDoesntExist
The difference between the above 2 cases is that former one only
specifies the GUID, but the latter one specifies both name and GUID.
Since not specifying GUID means to use GlobalVariableGuid,
"dmpstore NameThatDoesntExist -sfo" produces the similar output as
latter one.
I personally prefer to always produce SFO output for both cases.
But the above behavior is the discussion result between HPE engineers.
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Signed-off-by: Chen A Chen <chen.a.chen@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Tapan Shah <tapandshah@hpe.com>
2016-11-11 05:12:51 +01:00
|
|
|
IN BOOLEAN *FoundOne,
|
|
|
|
IN BOOLEAN StandardFormatOutput
|
2010-11-16 23:36:37 +01:00
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
CHAR16 *FoundVarName;
|
|
|
|
UINT8 *DataBuffer;
|
|
|
|
UINTN DataSize;
|
|
|
|
UINT32 Atts;
|
|
|
|
SHELL_STATUS ShellStatus;
|
2012-07-26 09:15:31 +02:00
|
|
|
UINTN NameSize;
|
ShellPkg/dmpstore: Support "-sfo"
The patch adds the "-sfo" support to "dmpstore" command.
When -l or -d is specified, -sfo is not supported.
When the variable specified by name and GUID cannot be found,
an error message is displayed; Otherwise, the SFO is displayed.
E.g.: "dmpstore -guid GuidThatDoesntExist -sfo" produces output
as:
ShellCommand,"dmpstore"
VariableInfo,"","GuidThatDoesntExist","","",""
"dmpstore NameThatDoesntExist -guid GuidThatDoesntExist -sfo"
produces output as:
ShellCommand,"dmpstore"
dmpstore: No matching variables found. Guid GuidThatDoesntExist, Name
NameThatDoesntExist
The difference between the above 2 cases is that former one only
specifies the GUID, but the latter one specifies both name and GUID.
Since not specifying GUID means to use GlobalVariableGuid,
"dmpstore NameThatDoesntExist -sfo" produces the similar output as
latter one.
I personally prefer to always produce SFO output for both cases.
But the above behavior is the discussion result between HPE engineers.
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Signed-off-by: Chen A Chen <chen.a.chen@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Tapan Shah <tapandshah@hpe.com>
2016-11-11 05:12:51 +01:00
|
|
|
CHAR16 *AttrString;
|
|
|
|
CHAR16 *HexString;
|
2016-12-12 07:11:14 +01:00
|
|
|
EFI_STATUS SetStatus;
|
2017-09-22 15:18:58 +02:00
|
|
|
CONST CHAR16 *GuidName;
|
2010-11-16 23:36:37 +01:00
|
|
|
|
2013-12-20 23:33:01 +01:00
|
|
|
if (ShellGetExecutionBreakFlag()) {
|
|
|
|
return (SHELL_ABORTED);
|
2010-11-16 23:36:37 +01:00
|
|
|
}
|
|
|
|
|
2013-12-20 23:33:01 +01:00
|
|
|
NameSize = 0;
|
|
|
|
FoundVarName = NULL;
|
2010-11-16 23:36:37 +01:00
|
|
|
|
2013-12-20 23:33:01 +01:00
|
|
|
if (PrevName!=NULL) {
|
|
|
|
StrnCatGrow(&FoundVarName, &NameSize, PrevName, 0);
|
|
|
|
} else {
|
|
|
|
FoundVarName = AllocateZeroPool(sizeof(CHAR16));
|
2017-06-22 09:22:33 +02:00
|
|
|
NameSize = sizeof(CHAR16);
|
2013-12-20 23:33:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Status = gRT->GetNextVariableName (&NameSize, FoundVarName, &FoundVarGuid);
|
|
|
|
if (Status == EFI_BUFFER_TOO_SMALL) {
|
|
|
|
SHELL_FREE_NON_NULL(FoundVarName);
|
|
|
|
FoundVarName = AllocateZeroPool (NameSize);
|
2014-01-09 01:30:27 +01:00
|
|
|
if (FoundVarName != NULL) {
|
|
|
|
if (PrevName != NULL) {
|
2015-07-09 05:19:06 +02:00
|
|
|
StrnCpyS(FoundVarName, NameSize/sizeof(CHAR16), PrevName, NameSize/sizeof(CHAR16) - 1);
|
2014-01-09 01:30:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Status = gRT->GetNextVariableName (&NameSize, FoundVarName, &FoundVarGuid);
|
|
|
|
} else {
|
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
2010-11-16 23:36:37 +01:00
|
|
|
}
|
2013-12-20 23:33:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// No more is fine.
|
|
|
|
//
|
|
|
|
if (Status == EFI_NOT_FOUND) {
|
|
|
|
SHELL_FREE_NON_NULL(FoundVarName);
|
|
|
|
return (SHELL_SUCCESS);
|
|
|
|
} else if (EFI_ERROR(Status)) {
|
|
|
|
SHELL_FREE_NON_NULL(FoundVarName);
|
|
|
|
return (SHELL_DEVICE_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Recurse to the next iteration. We know "our" variable's name.
|
|
|
|
//
|
ShellPkg/dmpstore: Support "-sfo"
The patch adds the "-sfo" support to "dmpstore" command.
When -l or -d is specified, -sfo is not supported.
When the variable specified by name and GUID cannot be found,
an error message is displayed; Otherwise, the SFO is displayed.
E.g.: "dmpstore -guid GuidThatDoesntExist -sfo" produces output
as:
ShellCommand,"dmpstore"
VariableInfo,"","GuidThatDoesntExist","","",""
"dmpstore NameThatDoesntExist -guid GuidThatDoesntExist -sfo"
produces output as:
ShellCommand,"dmpstore"
dmpstore: No matching variables found. Guid GuidThatDoesntExist, Name
NameThatDoesntExist
The difference between the above 2 cases is that former one only
specifies the GUID, but the latter one specifies both name and GUID.
Since not specifying GUID means to use GlobalVariableGuid,
"dmpstore NameThatDoesntExist -sfo" produces the similar output as
latter one.
I personally prefer to always produce SFO output for both cases.
But the above behavior is the discussion result between HPE engineers.
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Signed-off-by: Chen A Chen <chen.a.chen@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Tapan Shah <tapandshah@hpe.com>
2016-11-11 05:12:51 +01:00
|
|
|
ShellStatus = CascadeProcessVariables (Name, Guid, Type, FileHandle, FoundVarName, FoundVarGuid, FoundOne, StandardFormatOutput);
|
2013-12-20 23:33:01 +01:00
|
|
|
|
2014-06-30 22:14:24 +02:00
|
|
|
if (ShellGetExecutionBreakFlag() || (ShellStatus == SHELL_ABORTED)) {
|
|
|
|
SHELL_FREE_NON_NULL(FoundVarName);
|
|
|
|
return (SHELL_ABORTED);
|
|
|
|
}
|
|
|
|
|
2013-12-20 23:33:01 +01:00
|
|
|
//
|
|
|
|
// No matter what happened we process our own variable
|
|
|
|
// Only continue if Guid and VariableName are each either NULL or a match
|
|
|
|
//
|
2014-01-10 02:52:24 +01:00
|
|
|
if ( ( Name == NULL
|
|
|
|
|| gUnicodeCollation->MetaiMatch(gUnicodeCollation, FoundVarName, (CHAR16*) Name) )
|
2013-12-20 23:33:01 +01:00
|
|
|
&& ( Guid == NULL
|
|
|
|
|| CompareGuid(&FoundVarGuid, Guid) )
|
|
|
|
) {
|
|
|
|
DataSize = 0;
|
|
|
|
DataBuffer = NULL;
|
2010-11-16 23:36:37 +01:00
|
|
|
//
|
2013-12-20 23:33:01 +01:00
|
|
|
// do the print or delete
|
2010-11-16 23:36:37 +01:00
|
|
|
//
|
2013-12-20 23:33:01 +01:00
|
|
|
*FoundOne = TRUE;
|
|
|
|
Status = gRT->GetVariable (FoundVarName, &FoundVarGuid, &Atts, &DataSize, DataBuffer);
|
2012-07-26 09:15:31 +02:00
|
|
|
if (Status == EFI_BUFFER_TOO_SMALL) {
|
2013-12-20 23:33:01 +01:00
|
|
|
SHELL_FREE_NON_NULL (DataBuffer);
|
|
|
|
DataBuffer = AllocatePool (DataSize);
|
2012-07-26 09:15:31 +02:00
|
|
|
if (DataBuffer == NULL) {
|
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
2013-12-20 23:33:01 +01:00
|
|
|
} else {
|
|
|
|
Status = gRT->GetVariable (FoundVarName, &FoundVarGuid, &Atts, &DataSize, DataBuffer);
|
2012-07-26 09:15:31 +02:00
|
|
|
}
|
2013-12-20 23:33:01 +01:00
|
|
|
}
|
|
|
|
//
|
|
|
|
// Last error check then print this variable out.
|
|
|
|
//
|
ShellPkg/dmpstore: Support "-sfo"
The patch adds the "-sfo" support to "dmpstore" command.
When -l or -d is specified, -sfo is not supported.
When the variable specified by name and GUID cannot be found,
an error message is displayed; Otherwise, the SFO is displayed.
E.g.: "dmpstore -guid GuidThatDoesntExist -sfo" produces output
as:
ShellCommand,"dmpstore"
VariableInfo,"","GuidThatDoesntExist","","",""
"dmpstore NameThatDoesntExist -guid GuidThatDoesntExist -sfo"
produces output as:
ShellCommand,"dmpstore"
dmpstore: No matching variables found. Guid GuidThatDoesntExist, Name
NameThatDoesntExist
The difference between the above 2 cases is that former one only
specifies the GUID, but the latter one specifies both name and GUID.
Since not specifying GUID means to use GlobalVariableGuid,
"dmpstore NameThatDoesntExist -sfo" produces the similar output as
latter one.
I personally prefer to always produce SFO output for both cases.
But the above behavior is the discussion result between HPE engineers.
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Signed-off-by: Chen A Chen <chen.a.chen@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Tapan Shah <tapandshah@hpe.com>
2016-11-11 05:12:51 +01:00
|
|
|
if (Type == DmpStoreDisplay) {
|
2014-01-14 08:30:50 +01:00
|
|
|
if (!EFI_ERROR(Status) && (DataBuffer != NULL) && (FoundVarName != NULL)) {
|
ShellPkg/dmpstore: Support "-sfo"
The patch adds the "-sfo" support to "dmpstore" command.
When -l or -d is specified, -sfo is not supported.
When the variable specified by name and GUID cannot be found,
an error message is displayed; Otherwise, the SFO is displayed.
E.g.: "dmpstore -guid GuidThatDoesntExist -sfo" produces output
as:
ShellCommand,"dmpstore"
VariableInfo,"","GuidThatDoesntExist","","",""
"dmpstore NameThatDoesntExist -guid GuidThatDoesntExist -sfo"
produces output as:
ShellCommand,"dmpstore"
dmpstore: No matching variables found. Guid GuidThatDoesntExist, Name
NameThatDoesntExist
The difference between the above 2 cases is that former one only
specifies the GUID, but the latter one specifies both name and GUID.
Since not specifying GUID means to use GlobalVariableGuid,
"dmpstore NameThatDoesntExist -sfo" produces the similar output as
latter one.
I personally prefer to always produce SFO output for both cases.
But the above behavior is the discussion result between HPE engineers.
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Signed-off-by: Chen A Chen <chen.a.chen@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Tapan Shah <tapandshah@hpe.com>
2016-11-11 05:12:51 +01:00
|
|
|
AttrString = GetAttrType(Atts);
|
|
|
|
if (StandardFormatOutput) {
|
|
|
|
HexString = AllocatePool ((DataSize * 2 + 1) * sizeof (CHAR16));
|
|
|
|
if (HexString != NULL) {
|
|
|
|
ShellPrintHiiEx (
|
|
|
|
-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_VAR_SFO), gShellDebug1HiiHandle,
|
|
|
|
FoundVarName, &FoundVarGuid, Atts, DataSize,
|
|
|
|
BinaryToHexString (
|
|
|
|
DataBuffer, DataSize, HexString, (DataSize * 2 + 1) * sizeof (CHAR16)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
FreePool (HexString);
|
|
|
|
} else {
|
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
2014-01-10 02:52:24 +01:00
|
|
|
} else {
|
2017-09-15 04:39:33 +02:00
|
|
|
Status = gEfiShellProtocol->GetGuidName(&FoundVarGuid, &GuidName);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
ShellPrintHiiEx (
|
|
|
|
-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_HEADER_LINE), gShellDebug1HiiHandle,
|
|
|
|
AttrString, &FoundVarGuid, FoundVarName, DataSize
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
ShellPrintHiiEx (
|
|
|
|
-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_HEADER_LINE2), gShellDebug1HiiHandle,
|
|
|
|
AttrString, GuidName, FoundVarName, DataSize
|
|
|
|
);
|
|
|
|
}
|
ShellPkg/dmpstore: Support "-sfo"
The patch adds the "-sfo" support to "dmpstore" command.
When -l or -d is specified, -sfo is not supported.
When the variable specified by name and GUID cannot be found,
an error message is displayed; Otherwise, the SFO is displayed.
E.g.: "dmpstore -guid GuidThatDoesntExist -sfo" produces output
as:
ShellCommand,"dmpstore"
VariableInfo,"","GuidThatDoesntExist","","",""
"dmpstore NameThatDoesntExist -guid GuidThatDoesntExist -sfo"
produces output as:
ShellCommand,"dmpstore"
dmpstore: No matching variables found. Guid GuidThatDoesntExist, Name
NameThatDoesntExist
The difference between the above 2 cases is that former one only
specifies the GUID, but the latter one specifies both name and GUID.
Since not specifying GUID means to use GlobalVariableGuid,
"dmpstore NameThatDoesntExist -sfo" produces the similar output as
latter one.
I personally prefer to always produce SFO output for both cases.
But the above behavior is the discussion result between HPE engineers.
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Signed-off-by: Chen A Chen <chen.a.chen@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Tapan Shah <tapandshah@hpe.com>
2016-11-11 05:12:51 +01:00
|
|
|
DumpHex (2, 0, DataSize, DataBuffer);
|
2014-01-10 02:52:24 +01:00
|
|
|
}
|
ShellPkg/dmpstore: Support "-sfo"
The patch adds the "-sfo" support to "dmpstore" command.
When -l or -d is specified, -sfo is not supported.
When the variable specified by name and GUID cannot be found,
an error message is displayed; Otherwise, the SFO is displayed.
E.g.: "dmpstore -guid GuidThatDoesntExist -sfo" produces output
as:
ShellCommand,"dmpstore"
VariableInfo,"","GuidThatDoesntExist","","",""
"dmpstore NameThatDoesntExist -guid GuidThatDoesntExist -sfo"
produces output as:
ShellCommand,"dmpstore"
dmpstore: No matching variables found. Guid GuidThatDoesntExist, Name
NameThatDoesntExist
The difference between the above 2 cases is that former one only
specifies the GUID, but the latter one specifies both name and GUID.
Since not specifying GUID means to use GlobalVariableGuid,
"dmpstore NameThatDoesntExist -sfo" produces the similar output as
latter one.
I personally prefer to always produce SFO output for both cases.
But the above behavior is the discussion result between HPE engineers.
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Signed-off-by: Chen A Chen <chen.a.chen@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Tapan Shah <tapandshah@hpe.com>
2016-11-11 05:12:51 +01:00
|
|
|
SHELL_FREE_NON_NULL (AttrString);
|
|
|
|
}
|
|
|
|
} else if (Type == DmpStoreSave) {
|
|
|
|
if (!EFI_ERROR(Status) && (DataBuffer != NULL) && (FoundVarName != NULL)) {
|
|
|
|
AttrString = GetAttrType (Atts);
|
|
|
|
ShellPrintHiiEx (
|
|
|
|
-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_HEADER_LINE), gShellDebug1HiiHandle,
|
|
|
|
AttrString, &FoundVarGuid, FoundVarName, DataSize
|
|
|
|
);
|
|
|
|
Status = AppendSingleVariableToFile (
|
|
|
|
FileHandle,
|
|
|
|
FoundVarName,
|
|
|
|
&FoundVarGuid,
|
|
|
|
Atts,
|
|
|
|
(UINT32) DataSize,
|
|
|
|
DataBuffer
|
|
|
|
);
|
|
|
|
SHELL_FREE_NON_NULL (AttrString);
|
2013-12-20 23:33:01 +01:00
|
|
|
}
|
2014-01-10 02:52:24 +01:00
|
|
|
} else if (Type == DmpStoreDelete) {
|
2013-12-20 23:33:01 +01:00
|
|
|
//
|
|
|
|
// We only need name to delete it...
|
|
|
|
//
|
2016-12-12 07:11:14 +01:00
|
|
|
SetStatus = gRT->SetVariable (FoundVarName, &FoundVarGuid, Atts, 0, NULL);
|
ShellPkg/dmpstore: Support "-sfo"
The patch adds the "-sfo" support to "dmpstore" command.
When -l or -d is specified, -sfo is not supported.
When the variable specified by name and GUID cannot be found,
an error message is displayed; Otherwise, the SFO is displayed.
E.g.: "dmpstore -guid GuidThatDoesntExist -sfo" produces output
as:
ShellCommand,"dmpstore"
VariableInfo,"","GuidThatDoesntExist","","",""
"dmpstore NameThatDoesntExist -guid GuidThatDoesntExist -sfo"
produces output as:
ShellCommand,"dmpstore"
dmpstore: No matching variables found. Guid GuidThatDoesntExist, Name
NameThatDoesntExist
The difference between the above 2 cases is that former one only
specifies the GUID, but the latter one specifies both name and GUID.
Since not specifying GUID means to use GlobalVariableGuid,
"dmpstore NameThatDoesntExist -sfo" produces the similar output as
latter one.
I personally prefer to always produce SFO output for both cases.
But the above behavior is the discussion result between HPE engineers.
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Signed-off-by: Chen A Chen <chen.a.chen@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Tapan Shah <tapandshah@hpe.com>
2016-11-11 05:12:51 +01:00
|
|
|
if (StandardFormatOutput) {
|
|
|
|
if (SetStatus == EFI_SUCCESS) {
|
|
|
|
ShellPrintHiiEx (
|
|
|
|
-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_NG_SFO), gShellDebug1HiiHandle,
|
|
|
|
FoundVarName, &FoundVarGuid
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ShellPrintHiiEx (
|
|
|
|
-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_DELETE_LINE), gShellDebug1HiiHandle,
|
|
|
|
&FoundVarGuid, FoundVarName, SetStatus
|
|
|
|
);
|
|
|
|
}
|
2012-09-03 03:59:05 +02:00
|
|
|
}
|
2013-12-20 23:33:01 +01:00
|
|
|
SHELL_FREE_NON_NULL(DataBuffer);
|
2010-11-16 23:36:37 +01:00
|
|
|
}
|
|
|
|
|
2013-12-20 23:33:01 +01:00
|
|
|
SHELL_FREE_NON_NULL(FoundVarName);
|
|
|
|
|
|
|
|
if (Status == EFI_DEVICE_ERROR) {
|
|
|
|
ShellStatus = SHELL_DEVICE_ERROR;
|
|
|
|
} else if (Status == EFI_SECURITY_VIOLATION) {
|
|
|
|
ShellStatus = SHELL_SECURITY_VIOLATION;
|
|
|
|
} else if (EFI_ERROR(Status)) {
|
|
|
|
ShellStatus = SHELL_NOT_READY;
|
2010-11-16 23:36:37 +01:00
|
|
|
}
|
2013-12-20 23:33:01 +01:00
|
|
|
|
|
|
|
return (ShellStatus);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Function to display or delete variables. This will set up and call into the recursive function.
|
|
|
|
|
ShellPkg/dmpstore: Support "-sfo"
The patch adds the "-sfo" support to "dmpstore" command.
When -l or -d is specified, -sfo is not supported.
When the variable specified by name and GUID cannot be found,
an error message is displayed; Otherwise, the SFO is displayed.
E.g.: "dmpstore -guid GuidThatDoesntExist -sfo" produces output
as:
ShellCommand,"dmpstore"
VariableInfo,"","GuidThatDoesntExist","","",""
"dmpstore NameThatDoesntExist -guid GuidThatDoesntExist -sfo"
produces output as:
ShellCommand,"dmpstore"
dmpstore: No matching variables found. Guid GuidThatDoesntExist, Name
NameThatDoesntExist
The difference between the above 2 cases is that former one only
specifies the GUID, but the latter one specifies both name and GUID.
Since not specifying GUID means to use GlobalVariableGuid,
"dmpstore NameThatDoesntExist -sfo" produces the similar output as
latter one.
I personally prefer to always produce SFO output for both cases.
But the above behavior is the discussion result between HPE engineers.
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Signed-off-by: Chen A Chen <chen.a.chen@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Tapan Shah <tapandshah@hpe.com>
2016-11-11 05:12:51 +01:00
|
|
|
@param[in] Name The variable name of the EFI variable (or NULL).
|
|
|
|
@param[in] Guid The GUID of the variable set (or NULL).
|
|
|
|
@param[in] Type The operation type.
|
|
|
|
@param[in] FileHandle The file to save or load variables.
|
|
|
|
@param[in] StandardFormatOutput TRUE indicates Standard-Format Output.
|
2013-12-20 23:33:01 +01:00
|
|
|
|
|
|
|
@retval SHELL_SUCCESS The operation was successful.
|
|
|
|
@retval SHELL_OUT_OF_RESOURCES A memorty allocation failed.
|
|
|
|
@retval SHELL_ABORTED The abort message was received.
|
|
|
|
@retval SHELL_DEVICE_ERROR UEFI Variable Services returned an error.
|
|
|
|
@retval SHELL_NOT_FOUND the Name/Guid pair could not be found.
|
|
|
|
**/
|
|
|
|
SHELL_STATUS
|
|
|
|
ProcessVariables (
|
2014-01-10 02:52:24 +01:00
|
|
|
IN CONST CHAR16 *Name OPTIONAL,
|
|
|
|
IN CONST EFI_GUID *Guid OPTIONAL,
|
|
|
|
IN DMP_STORE_TYPE Type,
|
ShellPkg/dmpstore: Support "-sfo"
The patch adds the "-sfo" support to "dmpstore" command.
When -l or -d is specified, -sfo is not supported.
When the variable specified by name and GUID cannot be found,
an error message is displayed; Otherwise, the SFO is displayed.
E.g.: "dmpstore -guid GuidThatDoesntExist -sfo" produces output
as:
ShellCommand,"dmpstore"
VariableInfo,"","GuidThatDoesntExist","","",""
"dmpstore NameThatDoesntExist -guid GuidThatDoesntExist -sfo"
produces output as:
ShellCommand,"dmpstore"
dmpstore: No matching variables found. Guid GuidThatDoesntExist, Name
NameThatDoesntExist
The difference between the above 2 cases is that former one only
specifies the GUID, but the latter one specifies both name and GUID.
Since not specifying GUID means to use GlobalVariableGuid,
"dmpstore NameThatDoesntExist -sfo" produces the similar output as
latter one.
I personally prefer to always produce SFO output for both cases.
But the above behavior is the discussion result between HPE engineers.
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Signed-off-by: Chen A Chen <chen.a.chen@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Tapan Shah <tapandshah@hpe.com>
2016-11-11 05:12:51 +01:00
|
|
|
IN SHELL_FILE_HANDLE FileHandle OPTIONAL,
|
|
|
|
IN BOOLEAN StandardFormatOutput
|
2013-12-20 23:33:01 +01:00
|
|
|
)
|
|
|
|
{
|
|
|
|
SHELL_STATUS ShellStatus;
|
|
|
|
BOOLEAN Found;
|
|
|
|
EFI_GUID FoundVarGuid;
|
|
|
|
|
|
|
|
Found = FALSE;
|
|
|
|
ShellStatus = SHELL_SUCCESS;
|
|
|
|
ZeroMem (&FoundVarGuid, sizeof(EFI_GUID));
|
|
|
|
|
ShellPkg/dmpstore: Support "-sfo"
The patch adds the "-sfo" support to "dmpstore" command.
When -l or -d is specified, -sfo is not supported.
When the variable specified by name and GUID cannot be found,
an error message is displayed; Otherwise, the SFO is displayed.
E.g.: "dmpstore -guid GuidThatDoesntExist -sfo" produces output
as:
ShellCommand,"dmpstore"
VariableInfo,"","GuidThatDoesntExist","","",""
"dmpstore NameThatDoesntExist -guid GuidThatDoesntExist -sfo"
produces output as:
ShellCommand,"dmpstore"
dmpstore: No matching variables found. Guid GuidThatDoesntExist, Name
NameThatDoesntExist
The difference between the above 2 cases is that former one only
specifies the GUID, but the latter one specifies both name and GUID.
Since not specifying GUID means to use GlobalVariableGuid,
"dmpstore NameThatDoesntExist -sfo" produces the similar output as
latter one.
I personally prefer to always produce SFO output for both cases.
But the above behavior is the discussion result between HPE engineers.
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Signed-off-by: Chen A Chen <chen.a.chen@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Tapan Shah <tapandshah@hpe.com>
2016-11-11 05:12:51 +01:00
|
|
|
if (StandardFormatOutput) {
|
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_GEN_SFO_HEADER), gShellDebug1HiiHandle, L"dmpstore");
|
|
|
|
}
|
|
|
|
|
2014-01-10 02:52:24 +01:00
|
|
|
if (Type == DmpStoreLoad) {
|
2014-01-14 08:30:50 +01:00
|
|
|
ShellStatus = LoadVariablesFromFile (FileHandle, Name, Guid, &Found);
|
2014-01-10 02:52:24 +01:00
|
|
|
} else {
|
ShellPkg/dmpstore: Support "-sfo"
The patch adds the "-sfo" support to "dmpstore" command.
When -l or -d is specified, -sfo is not supported.
When the variable specified by name and GUID cannot be found,
an error message is displayed; Otherwise, the SFO is displayed.
E.g.: "dmpstore -guid GuidThatDoesntExist -sfo" produces output
as:
ShellCommand,"dmpstore"
VariableInfo,"","GuidThatDoesntExist","","",""
"dmpstore NameThatDoesntExist -guid GuidThatDoesntExist -sfo"
produces output as:
ShellCommand,"dmpstore"
dmpstore: No matching variables found. Guid GuidThatDoesntExist, Name
NameThatDoesntExist
The difference between the above 2 cases is that former one only
specifies the GUID, but the latter one specifies both name and GUID.
Since not specifying GUID means to use GlobalVariableGuid,
"dmpstore NameThatDoesntExist -sfo" produces the similar output as
latter one.
I personally prefer to always produce SFO output for both cases.
But the above behavior is the discussion result between HPE engineers.
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Signed-off-by: Chen A Chen <chen.a.chen@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Tapan Shah <tapandshah@hpe.com>
2016-11-11 05:12:51 +01:00
|
|
|
ShellStatus = CascadeProcessVariables (Name, Guid, Type, FileHandle, NULL, FoundVarGuid, &Found, StandardFormatOutput);
|
2014-01-10 02:52:24 +01:00
|
|
|
}
|
2013-12-20 23:33:01 +01:00
|
|
|
|
2011-03-25 22:22:20 +01:00
|
|
|
if (!Found) {
|
2013-12-20 23:33:01 +01:00
|
|
|
if (ShellStatus == SHELL_OUT_OF_RESOURCES) {
|
2015-02-03 22:22:53 +01:00
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"dmpstore");
|
2013-12-20 23:33:01 +01:00
|
|
|
return (ShellStatus);
|
2014-01-10 02:52:24 +01:00
|
|
|
} else if (Name != NULL && Guid == NULL) {
|
ShellPkg/dmpstore: Support "-sfo"
The patch adds the "-sfo" support to "dmpstore" command.
When -l or -d is specified, -sfo is not supported.
When the variable specified by name and GUID cannot be found,
an error message is displayed; Otherwise, the SFO is displayed.
E.g.: "dmpstore -guid GuidThatDoesntExist -sfo" produces output
as:
ShellCommand,"dmpstore"
VariableInfo,"","GuidThatDoesntExist","","",""
"dmpstore NameThatDoesntExist -guid GuidThatDoesntExist -sfo"
produces output as:
ShellCommand,"dmpstore"
dmpstore: No matching variables found. Guid GuidThatDoesntExist, Name
NameThatDoesntExist
The difference between the above 2 cases is that former one only
specifies the GUID, but the latter one specifies both name and GUID.
Since not specifying GUID means to use GlobalVariableGuid,
"dmpstore NameThatDoesntExist -sfo" produces the similar output as
latter one.
I personally prefer to always produce SFO output for both cases.
But the above behavior is the discussion result between HPE engineers.
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Signed-off-by: Chen A Chen <chen.a.chen@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Tapan Shah <tapandshah@hpe.com>
2016-11-11 05:12:51 +01:00
|
|
|
if (StandardFormatOutput) {
|
|
|
|
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_N_SFO), gShellDebug1HiiHandle, Name);
|
|
|
|
} else {
|
|
|
|
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_N), gShellDebug1HiiHandle, L"dmpstore", Name);
|
|
|
|
}
|
2014-01-10 02:52:24 +01:00
|
|
|
} else if (Name != NULL && Guid != NULL) {
|
2015-02-03 22:22:53 +01:00
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_GN), gShellDebug1HiiHandle, L"dmpstore", Guid, Name);
|
2014-01-10 02:52:24 +01:00
|
|
|
} else if (Name == NULL && Guid == NULL) {
|
ShellPkg/dmpstore: Support "-sfo"
The patch adds the "-sfo" support to "dmpstore" command.
When -l or -d is specified, -sfo is not supported.
When the variable specified by name and GUID cannot be found,
an error message is displayed; Otherwise, the SFO is displayed.
E.g.: "dmpstore -guid GuidThatDoesntExist -sfo" produces output
as:
ShellCommand,"dmpstore"
VariableInfo,"","GuidThatDoesntExist","","",""
"dmpstore NameThatDoesntExist -guid GuidThatDoesntExist -sfo"
produces output as:
ShellCommand,"dmpstore"
dmpstore: No matching variables found. Guid GuidThatDoesntExist, Name
NameThatDoesntExist
The difference between the above 2 cases is that former one only
specifies the GUID, but the latter one specifies both name and GUID.
Since not specifying GUID means to use GlobalVariableGuid,
"dmpstore NameThatDoesntExist -sfo" produces the similar output as
latter one.
I personally prefer to always produce SFO output for both cases.
But the above behavior is the discussion result between HPE engineers.
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Signed-off-by: Chen A Chen <chen.a.chen@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Tapan Shah <tapandshah@hpe.com>
2016-11-11 05:12:51 +01:00
|
|
|
if (StandardFormatOutput) {
|
|
|
|
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_SFO), gShellDebug1HiiHandle);
|
|
|
|
} else {
|
|
|
|
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND), gShellDebug1HiiHandle, L"dmpstore");
|
|
|
|
}
|
2014-01-10 02:52:24 +01:00
|
|
|
} else if (Name == NULL && Guid != NULL) {
|
ShellPkg/dmpstore: Support "-sfo"
The patch adds the "-sfo" support to "dmpstore" command.
When -l or -d is specified, -sfo is not supported.
When the variable specified by name and GUID cannot be found,
an error message is displayed; Otherwise, the SFO is displayed.
E.g.: "dmpstore -guid GuidThatDoesntExist -sfo" produces output
as:
ShellCommand,"dmpstore"
VariableInfo,"","GuidThatDoesntExist","","",""
"dmpstore NameThatDoesntExist -guid GuidThatDoesntExist -sfo"
produces output as:
ShellCommand,"dmpstore"
dmpstore: No matching variables found. Guid GuidThatDoesntExist, Name
NameThatDoesntExist
The difference between the above 2 cases is that former one only
specifies the GUID, but the latter one specifies both name and GUID.
Since not specifying GUID means to use GlobalVariableGuid,
"dmpstore NameThatDoesntExist -sfo" produces the similar output as
latter one.
I personally prefer to always produce SFO output for both cases.
But the above behavior is the discussion result between HPE engineers.
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Signed-off-by: Chen A Chen <chen.a.chen@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Tapan Shah <tapandshah@hpe.com>
2016-11-11 05:12:51 +01:00
|
|
|
if (StandardFormatOutput) {
|
|
|
|
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_G_SFO), gShellDebug1HiiHandle, Guid);
|
|
|
|
} else {
|
|
|
|
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_G), gShellDebug1HiiHandle, L"dmpstore", Guid);
|
|
|
|
}
|
2011-03-25 22:22:20 +01:00
|
|
|
}
|
|
|
|
return (SHELL_NOT_FOUND);
|
|
|
|
}
|
2013-05-09 18:16:21 +02:00
|
|
|
return (ShellStatus);
|
2010-11-16 23:36:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
|
|
|
|
{L"-d", TypeFlag},
|
2014-01-10 02:52:24 +01:00
|
|
|
{L"-l", TypeValue},
|
|
|
|
{L"-s", TypeValue},
|
2010-11-16 23:36:37 +01:00
|
|
|
{L"-all", TypeFlag},
|
|
|
|
{L"-guid", TypeValue},
|
ShellPkg/dmpstore: Support "-sfo"
The patch adds the "-sfo" support to "dmpstore" command.
When -l or -d is specified, -sfo is not supported.
When the variable specified by name and GUID cannot be found,
an error message is displayed; Otherwise, the SFO is displayed.
E.g.: "dmpstore -guid GuidThatDoesntExist -sfo" produces output
as:
ShellCommand,"dmpstore"
VariableInfo,"","GuidThatDoesntExist","","",""
"dmpstore NameThatDoesntExist -guid GuidThatDoesntExist -sfo"
produces output as:
ShellCommand,"dmpstore"
dmpstore: No matching variables found. Guid GuidThatDoesntExist, Name
NameThatDoesntExist
The difference between the above 2 cases is that former one only
specifies the GUID, but the latter one specifies both name and GUID.
Since not specifying GUID means to use GlobalVariableGuid,
"dmpstore NameThatDoesntExist -sfo" produces the similar output as
latter one.
I personally prefer to always produce SFO output for both cases.
But the above behavior is the discussion result between HPE engineers.
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Signed-off-by: Chen A Chen <chen.a.chen@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Tapan Shah <tapandshah@hpe.com>
2016-11-11 05:12:51 +01:00
|
|
|
{L"-sfo", TypeFlag},
|
2010-11-16 23:36:37 +01:00
|
|
|
{NULL, TypeMax}
|
|
|
|
};
|
|
|
|
|
2011-03-25 22:22:20 +01:00
|
|
|
/**
|
|
|
|
Function for 'dmpstore' 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
|
|
|
|
ShellCommandRunDmpStore (
|
|
|
|
IN EFI_HANDLE ImageHandle,
|
|
|
|
IN EFI_SYSTEM_TABLE *SystemTable
|
|
|
|
)
|
|
|
|
{
|
2014-01-10 02:52:24 +01:00
|
|
|
EFI_STATUS Status;
|
2017-02-21 10:20:54 +01:00
|
|
|
RETURN_STATUS RStatus;
|
2014-01-10 02:52:24 +01:00
|
|
|
LIST_ENTRY *Package;
|
|
|
|
CHAR16 *ProblemParam;
|
|
|
|
SHELL_STATUS ShellStatus;
|
|
|
|
CONST CHAR16 *GuidStr;
|
|
|
|
CONST CHAR16 *File;
|
|
|
|
EFI_GUID *Guid;
|
|
|
|
EFI_GUID GuidData;
|
|
|
|
CONST CHAR16 *Name;
|
|
|
|
DMP_STORE_TYPE Type;
|
|
|
|
SHELL_FILE_HANDLE FileHandle;
|
|
|
|
EFI_FILE_INFO *FileInfo;
|
ShellPkg/dmpstore: Support "-sfo"
The patch adds the "-sfo" support to "dmpstore" command.
When -l or -d is specified, -sfo is not supported.
When the variable specified by name and GUID cannot be found,
an error message is displayed; Otherwise, the SFO is displayed.
E.g.: "dmpstore -guid GuidThatDoesntExist -sfo" produces output
as:
ShellCommand,"dmpstore"
VariableInfo,"","GuidThatDoesntExist","","",""
"dmpstore NameThatDoesntExist -guid GuidThatDoesntExist -sfo"
produces output as:
ShellCommand,"dmpstore"
dmpstore: No matching variables found. Guid GuidThatDoesntExist, Name
NameThatDoesntExist
The difference between the above 2 cases is that former one only
specifies the GUID, but the latter one specifies both name and GUID.
Since not specifying GUID means to use GlobalVariableGuid,
"dmpstore NameThatDoesntExist -sfo" produces the similar output as
latter one.
I personally prefer to always produce SFO output for both cases.
But the above behavior is the discussion result between HPE engineers.
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Signed-off-by: Chen A Chen <chen.a.chen@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Tapan Shah <tapandshah@hpe.com>
2016-11-11 05:12:51 +01:00
|
|
|
BOOLEAN StandardFormatOutput;
|
2010-11-16 23:36:37 +01:00
|
|
|
|
ShellPkg/dmpstore: Support "-sfo"
The patch adds the "-sfo" support to "dmpstore" command.
When -l or -d is specified, -sfo is not supported.
When the variable specified by name and GUID cannot be found,
an error message is displayed; Otherwise, the SFO is displayed.
E.g.: "dmpstore -guid GuidThatDoesntExist -sfo" produces output
as:
ShellCommand,"dmpstore"
VariableInfo,"","GuidThatDoesntExist","","",""
"dmpstore NameThatDoesntExist -guid GuidThatDoesntExist -sfo"
produces output as:
ShellCommand,"dmpstore"
dmpstore: No matching variables found. Guid GuidThatDoesntExist, Name
NameThatDoesntExist
The difference between the above 2 cases is that former one only
specifies the GUID, but the latter one specifies both name and GUID.
Since not specifying GUID means to use GlobalVariableGuid,
"dmpstore NameThatDoesntExist -sfo" produces the similar output as
latter one.
I personally prefer to always produce SFO output for both cases.
But the above behavior is the discussion result between HPE engineers.
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Signed-off-by: Chen A Chen <chen.a.chen@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Tapan Shah <tapandshah@hpe.com>
2016-11-11 05:12:51 +01:00
|
|
|
ShellStatus = SHELL_SUCCESS;
|
|
|
|
Package = NULL;
|
|
|
|
FileHandle = NULL;
|
|
|
|
File = NULL;
|
|
|
|
Type = DmpStoreDisplay;
|
|
|
|
StandardFormatOutput = FALSE;
|
2010-11-16 23:36:37 +01:00
|
|
|
|
|
|
|
Status = ShellCommandLineParse (ParamList, &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"dmpstore", 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) > 2) {
|
2015-02-03 22:22:53 +01:00
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"dmpstore");
|
2010-11-16 23:36:37 +01:00
|
|
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
|
|
|
} else if (ShellCommandLineGetFlag(Package, L"-all") && ShellCommandLineGetFlag(Package, L"-guid")) {
|
2015-02-03 22:22:53 +01:00
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CONFLICT), gShellDebug1HiiHandle, L"dmpstore", L"-all", L"-guid");
|
2010-11-16 23:36:37 +01:00
|
|
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
2014-01-10 02:52:24 +01:00
|
|
|
} else if (ShellCommandLineGetFlag(Package, L"-s") && ShellCommandLineGetFlag(Package, L"-l")) {
|
2015-02-03 22:22:53 +01:00
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CONFLICT), gShellDebug1HiiHandle, L"dmpstore", L"-l", L"-s");
|
2014-01-10 02:52:24 +01:00
|
|
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
2010-11-16 23:36:37 +01:00
|
|
|
} else if ((ShellCommandLineGetFlag(Package, L"-s") || ShellCommandLineGetFlag(Package, L"-l")) && ShellCommandLineGetFlag(Package, L"-d")) {
|
2015-02-03 22:22:53 +01:00
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CONFLICT), gShellDebug1HiiHandle, L"dmpstore", L"-l or -s", L"-d");
|
2010-11-16 23:36:37 +01:00
|
|
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
ShellPkg/dmpstore: Support "-sfo"
The patch adds the "-sfo" support to "dmpstore" command.
When -l or -d is specified, -sfo is not supported.
When the variable specified by name and GUID cannot be found,
an error message is displayed; Otherwise, the SFO is displayed.
E.g.: "dmpstore -guid GuidThatDoesntExist -sfo" produces output
as:
ShellCommand,"dmpstore"
VariableInfo,"","GuidThatDoesntExist","","",""
"dmpstore NameThatDoesntExist -guid GuidThatDoesntExist -sfo"
produces output as:
ShellCommand,"dmpstore"
dmpstore: No matching variables found. Guid GuidThatDoesntExist, Name
NameThatDoesntExist
The difference between the above 2 cases is that former one only
specifies the GUID, but the latter one specifies both name and GUID.
Since not specifying GUID means to use GlobalVariableGuid,
"dmpstore NameThatDoesntExist -sfo" produces the similar output as
latter one.
I personally prefer to always produce SFO output for both cases.
But the above behavior is the discussion result between HPE engineers.
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Signed-off-by: Chen A Chen <chen.a.chen@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Tapan Shah <tapandshah@hpe.com>
2016-11-11 05:12:51 +01:00
|
|
|
} else if ((ShellCommandLineGetFlag(Package, L"-s") || ShellCommandLineGetFlag(Package, L"-l")) && ShellCommandLineGetFlag(Package, L"-sfo")) {
|
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CONFLICT), gShellDebug1HiiHandle, L"dmpstore", L"-l or -s", L"-sfo");
|
|
|
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
2010-11-16 23:36:37 +01:00
|
|
|
} else {
|
2014-08-05 22:56:40 +02:00
|
|
|
//
|
|
|
|
// Determine the GUID to search for based on -all and -guid parameters
|
|
|
|
//
|
2010-11-16 23:36:37 +01:00
|
|
|
if (!ShellCommandLineGetFlag(Package, L"-all")) {
|
2014-01-10 02:52:24 +01:00
|
|
|
GuidStr = ShellCommandLineGetValue(Package, L"-guid");
|
|
|
|
if (GuidStr != NULL) {
|
2017-02-21 10:20:54 +01:00
|
|
|
RStatus = StrToGuid (GuidStr, &GuidData);
|
|
|
|
if (RETURN_ERROR (RStatus) || (GuidStr[GUID_STRING_LENGTH] != L'\0')) {
|
2015-02-03 22:22:53 +01:00
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"dmpstore", GuidStr);
|
2010-11-16 23:36:37 +01:00
|
|
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
Guid = &GuidData;
|
|
|
|
} else {
|
|
|
|
Guid = &gEfiGlobalVariableGuid;
|
|
|
|
}
|
|
|
|
} else {
|
2014-01-10 02:52:24 +01:00
|
|
|
Guid = NULL;
|
2010-11-16 23:36:37 +01:00
|
|
|
}
|
2014-08-05 22:56:40 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Get the Name of the variable to find
|
|
|
|
//
|
|
|
|
Name = ShellCommandLineGetRawValue(Package, 1);
|
|
|
|
|
2010-11-16 23:36:37 +01:00
|
|
|
if (ShellStatus == SHELL_SUCCESS) {
|
2014-01-10 02:52:24 +01:00
|
|
|
if (ShellCommandLineGetFlag(Package, L"-s")) {
|
|
|
|
Type = DmpStoreSave;
|
|
|
|
File = ShellCommandLineGetValue(Package, L"-s");
|
|
|
|
if (File == NULL) {
|
2015-02-03 22:22:53 +01:00
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"dmpstore", L"-s");
|
2014-01-10 02:52:24 +01:00
|
|
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
|
|
|
} else {
|
|
|
|
Status = ShellOpenFileByName (File, &FileHandle, EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ, 0);
|
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
//
|
|
|
|
// Delete existing file, but do not delete existing directory
|
|
|
|
//
|
|
|
|
FileInfo = ShellGetFileInfo (FileHandle);
|
|
|
|
if (FileInfo == NULL) {
|
2015-02-03 22:22:53 +01:00
|
|
|
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"dmpstore", File);
|
2014-01-10 02:52:24 +01:00
|
|
|
Status = EFI_DEVICE_ERROR;
|
|
|
|
} else {
|
|
|
|
if ((FileInfo->Attribute & EFI_FILE_DIRECTORY) == EFI_FILE_DIRECTORY) {
|
2015-02-03 22:22:53 +01:00
|
|
|
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_IS_DIRECTORY), gShellDebug1HiiHandle, L"dmpstore", File);
|
2014-01-10 02:52:24 +01:00
|
|
|
Status = EFI_INVALID_PARAMETER;
|
|
|
|
} else {
|
|
|
|
Status = ShellDeleteFile (&FileHandle);
|
|
|
|
if (EFI_ERROR (Status)) {
|
2015-02-03 22:22:53 +01:00
|
|
|
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_DELETE_FAIL), gShellDebug1HiiHandle, L"dmpstore", File);
|
2014-01-10 02:52:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
FreePool (FileInfo);
|
|
|
|
}
|
|
|
|
} else if (Status == EFI_NOT_FOUND) {
|
|
|
|
//
|
|
|
|
// Good when file doesn't exist
|
|
|
|
//
|
|
|
|
Status = EFI_SUCCESS;
|
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// Otherwise it's bad.
|
|
|
|
//
|
2015-02-03 22:22:53 +01:00
|
|
|
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"dmpstore", File);
|
2014-01-10 02:52:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
Status = ShellOpenFileByName (File, &FileHandle, EFI_FILE_MODE_CREATE | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ, 0);
|
|
|
|
if (EFI_ERROR (Status)) {
|
2015-02-03 22:22:53 +01:00
|
|
|
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"dmpstore", File);
|
2014-01-10 02:52:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (ShellCommandLineGetFlag(Package, L"-l")) {
|
|
|
|
Type = DmpStoreLoad;
|
|
|
|
File = ShellCommandLineGetValue(Package, L"-l");
|
|
|
|
if (File == NULL) {
|
2015-02-03 22:22:53 +01:00
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"dmpstore", L"-l");
|
2014-01-10 02:52:24 +01:00
|
|
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
|
|
|
} else {
|
|
|
|
Status = ShellOpenFileByName (File, &FileHandle, EFI_FILE_MODE_READ, 0);
|
|
|
|
if (EFI_ERROR (Status)) {
|
2015-02-03 22:22:53 +01:00
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"dmpstore", File);
|
2014-01-10 02:52:24 +01:00
|
|
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
|
|
|
} else {
|
|
|
|
FileInfo = ShellGetFileInfo (FileHandle);
|
|
|
|
if (FileInfo == NULL) {
|
2015-02-03 22:22:53 +01:00
|
|
|
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"dmpstore", File);
|
2014-01-10 02:52:24 +01:00
|
|
|
ShellStatus = SHELL_DEVICE_ERROR;
|
|
|
|
} else {
|
|
|
|
if ((FileInfo->Attribute & EFI_FILE_DIRECTORY) == EFI_FILE_DIRECTORY) {
|
2015-02-03 22:22:53 +01:00
|
|
|
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_IS_DIRECTORY), gShellDebug1HiiHandle, L"dmpstore", File);
|
2014-01-10 02:52:24 +01:00
|
|
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
FreePool (FileInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (ShellCommandLineGetFlag(Package, L"-d")) {
|
|
|
|
Type = DmpStoreDelete;
|
|
|
|
}
|
ShellPkg/dmpstore: Support "-sfo"
The patch adds the "-sfo" support to "dmpstore" command.
When -l or -d is specified, -sfo is not supported.
When the variable specified by name and GUID cannot be found,
an error message is displayed; Otherwise, the SFO is displayed.
E.g.: "dmpstore -guid GuidThatDoesntExist -sfo" produces output
as:
ShellCommand,"dmpstore"
VariableInfo,"","GuidThatDoesntExist","","",""
"dmpstore NameThatDoesntExist -guid GuidThatDoesntExist -sfo"
produces output as:
ShellCommand,"dmpstore"
dmpstore: No matching variables found. Guid GuidThatDoesntExist, Name
NameThatDoesntExist
The difference between the above 2 cases is that former one only
specifies the GUID, but the latter one specifies both name and GUID.
Since not specifying GUID means to use GlobalVariableGuid,
"dmpstore NameThatDoesntExist -sfo" produces the similar output as
latter one.
I personally prefer to always produce SFO output for both cases.
But the above behavior is the discussion result between HPE engineers.
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Signed-off-by: Chen A Chen <chen.a.chen@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Tapan Shah <tapandshah@hpe.com>
2016-11-11 05:12:51 +01:00
|
|
|
|
|
|
|
if (ShellCommandLineGetFlag (Package,L"-sfo")) {
|
|
|
|
StandardFormatOutput = TRUE;
|
|
|
|
}
|
2014-01-10 02:52:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ShellStatus == SHELL_SUCCESS) {
|
|
|
|
if (Type == DmpStoreSave) {
|
|
|
|
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_SAVE), gShellDebug1HiiHandle, File);
|
|
|
|
} else if (Type == DmpStoreLoad) {
|
|
|
|
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_LOAD), gShellDebug1HiiHandle, File);
|
|
|
|
}
|
ShellPkg/dmpstore: Support "-sfo"
The patch adds the "-sfo" support to "dmpstore" command.
When -l or -d is specified, -sfo is not supported.
When the variable specified by name and GUID cannot be found,
an error message is displayed; Otherwise, the SFO is displayed.
E.g.: "dmpstore -guid GuidThatDoesntExist -sfo" produces output
as:
ShellCommand,"dmpstore"
VariableInfo,"","GuidThatDoesntExist","","",""
"dmpstore NameThatDoesntExist -guid GuidThatDoesntExist -sfo"
produces output as:
ShellCommand,"dmpstore"
dmpstore: No matching variables found. Guid GuidThatDoesntExist, Name
NameThatDoesntExist
The difference between the above 2 cases is that former one only
specifies the GUID, but the latter one specifies both name and GUID.
Since not specifying GUID means to use GlobalVariableGuid,
"dmpstore NameThatDoesntExist -sfo" produces the similar output as
latter one.
I personally prefer to always produce SFO output for both cases.
But the above behavior is the discussion result between HPE engineers.
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Signed-off-by: Chen A Chen <chen.a.chen@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Tapan Shah <tapandshah@hpe.com>
2016-11-11 05:12:51 +01:00
|
|
|
ShellStatus = ProcessVariables (Name, Guid, Type, FileHandle, StandardFormatOutput);
|
2014-01-10 02:52:24 +01:00
|
|
|
if ((Type == DmpStoreLoad) || (Type == DmpStoreSave)) {
|
|
|
|
ShellCloseFile (&FileHandle);
|
2010-11-16 23:36:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Package != NULL) {
|
|
|
|
ShellCommandLineFreeVarList (Package);
|
|
|
|
}
|
|
|
|
return ShellStatus;
|
|
|
|
}
|
|
|
|
|