]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg/dmpstore: Support "-sfo"
authorRuiyu Ni <ruiyu.ni@intel.com>
Fri, 11 Nov 2016 04:12:51 +0000 (12:12 +0800)
committerRuiyu Ni <ruiyu.ni@intel.com>
Wed, 16 Nov 2016 04:32:17 +0000 (12:32 +0800)
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>
ShellPkg/Library/UefiShellDebug1CommandsLib/DmpStore.c
ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.uni

index 3427c99fe61ed043713eec5cebee86cabb79fefe..713388150a43ebc1ba21fdf05fc50788a937b052 100644 (file)
@@ -2,7 +2,7 @@
   Main file for DmpStore shell Debug1 function.\r
    \r
   (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>\r
-  Copyright (c) 2005 - 2015, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -81,6 +81,42 @@ GetAttrType (
   return RetString;\r
 }\r
 \r
+/**\r
+  Convert binary to hex format string.\r
+\r
+  @param[in]  BufferSize        The size in bytes of the binary data.\r
+  @param[in]  Buffer            The binary data.\r
+  @param[in, out] HexString     Hex format string.\r
+  @param[in]      HexStringSize The size in bytes of the string.\r
+\r
+  @return The hex format string.\r
+**/\r
+CHAR16*\r
+BinaryToHexString (\r
+  IN     VOID    *Buffer,\r
+  IN     UINTN   BufferSize,\r
+  IN OUT CHAR16  *HexString,\r
+  IN     UINTN   HexStringSize\r
+  )\r
+{\r
+  UINTN Index;\r
+  UINTN StringIndex;\r
+\r
+  ASSERT (Buffer != NULL);\r
+  ASSERT ((BufferSize * 2 + 1) * sizeof (CHAR16) <= HexStringSize);\r
+\r
+  for (Index = 0, StringIndex = 0; Index < BufferSize; Index += 1) {\r
+    StringIndex +=\r
+      UnicodeSPrint (\r
+        &HexString[StringIndex],\r
+        HexStringSize - StringIndex * sizeof (CHAR16),\r
+        L"%02x",\r
+        ((UINT8 *) Buffer)[Index]\r
+        );\r
+  }\r
+  return HexString;\r
+}\r
+\r
 /**\r
   Load the variable data from file and set to variable data base.\r
 \r
@@ -350,14 +386,15 @@ AppendSingleVariableToFile (
 \r
   This is necessary since once a delete happens GetNextVariableName() will work.\r
 \r
-  @param[in] Name           The variable name of the EFI variable (or NULL).\r
-  @param[in] Guid           The GUID of the variable set (or NULL).\r
-  @param[in] Type           The operation type.\r
-  @param[in] FileHandle     The file to operate on (or NULL).\r
-  @param[in] PrevName       The previous variable name from GetNextVariableName. L"" to start.\r
-  @param[in] FoundVarGuid   The previous GUID from GetNextVariableName. ignored at start.\r
-  @param[in] FoundOne       If a VariableName or Guid was specified and one was printed or\r
-                            deleted, then set this to TRUE, otherwise ignored.\r
+  @param[in] Name                 The variable name of the EFI variable (or NULL).\r
+  @param[in] Guid                 The GUID of the variable set (or NULL).\r
+  @param[in] Type                 The operation type.\r
+  @param[in] FileHandle           The file to operate on (or NULL).\r
+  @param[in] PrevName             The previous variable name from GetNextVariableName. L"" to start.\r
+  @param[in] FoundVarGuid         The previous GUID from GetNextVariableName. ignored at start.\r
+  @param[in] FoundOne             If a VariableName or Guid was specified and one was printed or\r
+                                  deleted, then set this to TRUE, otherwise ignored.\r
+  @param[in] StandardFormatOutput TRUE indicates Standard-Format Output.\r
 \r
   @retval SHELL_SUCCESS           The operation was successful.\r
   @retval SHELL_OUT_OF_RESOURCES  A memorty allocation failed.\r
@@ -373,7 +410,8 @@ CascadeProcessVariables (
   IN EFI_FILE_PROTOCOL *FileHandle  OPTIONAL,\r
   IN CONST CHAR16      * CONST PrevName,\r
   IN EFI_GUID          FoundVarGuid,\r
-  IN BOOLEAN           *FoundOne\r
+  IN BOOLEAN           *FoundOne,\r
+  IN BOOLEAN           StandardFormatOutput\r
   )\r
 {\r
   EFI_STATUS                Status;\r
@@ -383,7 +421,8 @@ CascadeProcessVariables (
   UINT32                    Atts;\r
   SHELL_STATUS              ShellStatus;\r
   UINTN                     NameSize;\r
-  CHAR16                    *RetString;\r
+  CHAR16                    *AttrString;\r
+  CHAR16                    *HexString;\r
 \r
   if (ShellGetExecutionBreakFlag()) {\r
     return (SHELL_ABORTED);\r
@@ -427,7 +466,7 @@ CascadeProcessVariables (
   //\r
   // Recurse to the next iteration.  We know "our" variable's name.\r
   //\r
-  ShellStatus = CascadeProcessVariables(Name, Guid, Type, FileHandle, FoundVarName, FoundVarGuid, FoundOne);\r
+  ShellStatus = CascadeProcessVariables (Name, Guid, Type, FileHandle, FoundVarName, FoundVarGuid, FoundOne, StandardFormatOutput);\r
 \r
   if (ShellGetExecutionBreakFlag() || (ShellStatus == SHELL_ABORTED)) {\r
     SHELL_FREE_NON_NULL(FoundVarName);\r
@@ -459,50 +498,70 @@ CascadeProcessVariables (
         Status = gRT->GetVariable (FoundVarName, &FoundVarGuid, &Atts, &DataSize, DataBuffer);\r
       }\r
     }\r
-    if ((Type == DmpStoreDisplay) || (Type == DmpStoreSave)) {\r
       //\r
       // Last error check then print this variable out.\r
       //\r
+    if (Type == DmpStoreDisplay) {\r
       if (!EFI_ERROR(Status) && (DataBuffer != NULL) && (FoundVarName != NULL)) {\r
-        RetString = GetAttrType(Atts);\r
-        ShellPrintHiiEx(\r
-          -1,\r
-          -1,\r
-          NULL,\r
-          STRING_TOKEN(STR_DMPSTORE_HEADER_LINE),\r
-          gShellDebug1HiiHandle,\r
-          RetString,\r
-          &FoundVarGuid,\r
-          FoundVarName,\r
-          DataSize);\r
-        if (Type == DmpStoreDisplay) {\r
-          DumpHex(2, 0, DataSize, DataBuffer);\r
+        AttrString = GetAttrType(Atts);\r
+        if (StandardFormatOutput) {\r
+          HexString = AllocatePool ((DataSize * 2 + 1) * sizeof (CHAR16));\r
+          if (HexString != NULL) {\r
+            ShellPrintHiiEx (\r
+              -1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_VAR_SFO), gShellDebug1HiiHandle,\r
+              FoundVarName, &FoundVarGuid, Atts, DataSize,\r
+              BinaryToHexString (\r
+                DataBuffer, DataSize, HexString, (DataSize * 2 + 1) * sizeof (CHAR16)\r
+                )\r
+              );\r
+            FreePool (HexString);\r
+          } else {\r
+            Status = EFI_OUT_OF_RESOURCES;\r
+          }\r
         } else {\r
-          Status = AppendSingleVariableToFile (\r
-                     FileHandle,\r
-                     FoundVarName,\r
-                     &FoundVarGuid,\r
-                     Atts,\r
-                     (UINT32) DataSize,\r
-                     DataBuffer\r
-                     );\r
+          ShellPrintHiiEx (\r
+            -1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_HEADER_LINE), gShellDebug1HiiHandle,\r
+            AttrString, &FoundVarGuid, FoundVarName, DataSize\r
+            );\r
+          DumpHex (2, 0, DataSize, DataBuffer);\r
         }\r
-        SHELL_FREE_NON_NULL(RetString);\r
+        SHELL_FREE_NON_NULL (AttrString);\r
+      }\r
+    } else if (Type == DmpStoreSave) {\r
+      if (!EFI_ERROR(Status) && (DataBuffer != NULL) && (FoundVarName != NULL)) {\r
+        AttrString = GetAttrType (Atts);\r
+        ShellPrintHiiEx (\r
+          -1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_HEADER_LINE), gShellDebug1HiiHandle,\r
+          AttrString, &FoundVarGuid, FoundVarName, DataSize\r
+          );\r
+        Status = AppendSingleVariableToFile (\r
+                   FileHandle,\r
+                   FoundVarName,\r
+                   &FoundVarGuid,\r
+                   Atts,\r
+                   (UINT32) DataSize,\r
+                   DataBuffer\r
+                   );\r
+        SHELL_FREE_NON_NULL (AttrString);\r
       }\r
     } else if (Type == DmpStoreDelete) {\r
       //\r
       // We only need name to delete it...\r
       //\r
-      ShellPrintHiiEx (\r
-        -1,\r
-        -1,\r
-        NULL,\r
-        STRING_TOKEN(STR_DMPSTORE_DELETE_LINE),\r
-        gShellDebug1HiiHandle,\r
-        &FoundVarGuid,\r
-        FoundVarName,\r
-        gRT->SetVariable (FoundVarName, &FoundVarGuid, Atts, 0, NULL)\r
-        );\r
+      EFI_STATUS SetStatus = gRT->SetVariable (FoundVarName, &FoundVarGuid, Atts, 0, NULL);\r
+      if (StandardFormatOutput) {\r
+        if (SetStatus == EFI_SUCCESS) {\r
+          ShellPrintHiiEx (\r
+            -1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_NG_SFO), gShellDebug1HiiHandle,\r
+            FoundVarName, &FoundVarGuid\r
+            );\r
+        }\r
+      } else {\r
+        ShellPrintHiiEx (\r
+          -1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_DELETE_LINE), gShellDebug1HiiHandle,\r
+          &FoundVarGuid, FoundVarName, SetStatus\r
+          );\r
+      }\r
     }\r
     SHELL_FREE_NON_NULL(DataBuffer);\r
   }\r
@@ -523,10 +582,11 @@ CascadeProcessVariables (
 /**\r
   Function to display or delete variables.  This will set up and call into the recursive function.\r
 \r
-  @param[in] Name        The variable name of the EFI variable (or NULL).\r
-  @param[in] Guid        The GUID of the variable set (or NULL).\r
-  @param[in] Type        The operation type.\r
-  @param[in] FileHandle  The file to save or load variables.\r
+  @param[in] Name                 The variable name of the EFI variable (or NULL).\r
+  @param[in] Guid                 The GUID of the variable set (or NULL).\r
+  @param[in] Type                 The operation type.\r
+  @param[in] FileHandle           The file to save or load variables.\r
+  @param[in] StandardFormatOutput TRUE indicates Standard-Format Output.\r
 \r
   @retval SHELL_SUCCESS           The operation was successful.\r
   @retval SHELL_OUT_OF_RESOURCES  A memorty allocation failed.\r
@@ -539,7 +599,8 @@ ProcessVariables (
   IN CONST CHAR16      *Name      OPTIONAL,\r
   IN CONST EFI_GUID    *Guid      OPTIONAL,\r
   IN DMP_STORE_TYPE    Type,\r
-  IN SHELL_FILE_HANDLE FileHandle OPTIONAL\r
+  IN SHELL_FILE_HANDLE FileHandle OPTIONAL,\r
+  IN BOOLEAN           StandardFormatOutput\r
   )\r
 {\r
   SHELL_STATUS              ShellStatus;\r
@@ -550,10 +611,14 @@ ProcessVariables (
   ShellStatus   = SHELL_SUCCESS;\r
   ZeroMem (&FoundVarGuid, sizeof(EFI_GUID));\r
 \r
+  if (StandardFormatOutput) {\r
+    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_GEN_SFO_HEADER), gShellDebug1HiiHandle, L"dmpstore");\r
+  }\r
+\r
   if (Type == DmpStoreLoad) {\r
     ShellStatus = LoadVariablesFromFile (FileHandle, Name, Guid, &Found);\r
   } else {\r
-    ShellStatus = CascadeProcessVariables(Name, Guid, Type, FileHandle, NULL, FoundVarGuid, &Found);\r
+    ShellStatus = CascadeProcessVariables (Name, Guid, Type, FileHandle, NULL, FoundVarGuid, &Found, StandardFormatOutput);\r
   }\r
 \r
   if (!Found) {\r
@@ -561,13 +626,25 @@ ProcessVariables (
       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"dmpstore");  \r
       return (ShellStatus);\r
     } else if (Name != NULL && Guid == NULL) {\r
-      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_N), gShellDebug1HiiHandle, L"dmpstore", Name);  \r
+      if (StandardFormatOutput) {\r
+        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_N_SFO), gShellDebug1HiiHandle, Name);\r
+      } else {\r
+        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_N), gShellDebug1HiiHandle, L"dmpstore", Name);  \r
+      }\r
     } else if (Name != NULL && Guid != NULL) {\r
       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_GN), gShellDebug1HiiHandle, L"dmpstore", Guid, Name);  \r
     } else if (Name == NULL && Guid == NULL) {\r
-      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND), gShellDebug1HiiHandle, L"dmpstore");  \r
+      if (StandardFormatOutput) {\r
+        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_SFO), gShellDebug1HiiHandle);\r
+      } else {\r
+        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND), gShellDebug1HiiHandle, L"dmpstore");\r
+      }\r
     } else if (Name == NULL && Guid != NULL) {\r
-      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_G), gShellDebug1HiiHandle, L"dmpstore", Guid);  \r
+      if (StandardFormatOutput) {\r
+        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_G_SFO), gShellDebug1HiiHandle, Guid);\r
+      } else {\r
+        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_G), gShellDebug1HiiHandle, L"dmpstore", Guid);\r
+      }\r
     } \r
     return (SHELL_NOT_FOUND);\r
   }\r
@@ -580,6 +657,7 @@ STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
   {L"-s", TypeValue},\r
   {L"-all", TypeFlag},\r
   {L"-guid", TypeValue},\r
+  {L"-sfo", TypeFlag},\r
   {NULL, TypeMax}\r
   };\r
 \r
@@ -608,12 +686,14 @@ ShellCommandRunDmpStore (
   DMP_STORE_TYPE    Type;\r
   SHELL_FILE_HANDLE FileHandle;\r
   EFI_FILE_INFO     *FileInfo;\r
+  BOOLEAN           StandardFormatOutput;\r
 \r
-  ShellStatus   = SHELL_SUCCESS;\r
-  Package       = NULL;\r
-  FileHandle    = NULL;\r
-  File          = NULL;\r
-  Type          = DmpStoreDisplay;\r
+  ShellStatus          = SHELL_SUCCESS;\r
+  Package              = NULL;\r
+  FileHandle           = NULL;\r
+  File                 = NULL;\r
+  Type                 = DmpStoreDisplay;\r
+  StandardFormatOutput = FALSE;\r
 \r
   Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);\r
   if (EFI_ERROR(Status)) {\r
@@ -637,6 +717,9 @@ ShellCommandRunDmpStore (
     } else if ((ShellCommandLineGetFlag(Package, L"-s") || ShellCommandLineGetFlag(Package, L"-l")) && ShellCommandLineGetFlag(Package, L"-d")) {\r
       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CONFLICT), gShellDebug1HiiHandle, L"dmpstore", L"-l or -s", L"-d");  \r
       ShellStatus = SHELL_INVALID_PARAMETER;\r
+    } else if ((ShellCommandLineGetFlag(Package, L"-s") || ShellCommandLineGetFlag(Package, L"-l")) && ShellCommandLineGetFlag(Package, L"-sfo")) {\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CONFLICT), gShellDebug1HiiHandle, L"dmpstore", L"-l or -s", L"-sfo");  \r
+      ShellStatus = SHELL_INVALID_PARAMETER;\r
     } else {\r
       //\r
       // Determine the GUID to search for based on -all and -guid parameters\r
@@ -742,6 +825,10 @@ ShellCommandRunDmpStore (
         } else if (ShellCommandLineGetFlag(Package, L"-d")) {\r
           Type = DmpStoreDelete;\r
         }\r
+\r
+        if (ShellCommandLineGetFlag (Package,L"-sfo")) {\r
+          StandardFormatOutput = TRUE;\r
+        }\r
       }\r
 \r
       if (ShellStatus == SHELL_SUCCESS) {\r
@@ -750,7 +837,7 @@ ShellCommandRunDmpStore (
         } else if (Type == DmpStoreLoad) {\r
           ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_LOAD), gShellDebug1HiiHandle, File);\r
         }\r
-        ShellStatus = ProcessVariables (Name, Guid, Type, FileHandle);\r
+        ShellStatus = ProcessVariables (Name, Guid, Type, FileHandle, StandardFormatOutput);\r
         if ((Type == DmpStoreLoad) || (Type == DmpStoreSave)) {\r
           ShellCloseFile (&FileHandle);\r
         }\r
index 52c2af02a3c44c1fcbd292a92197d109e82dddb6..bd1726bf13bb16ad349e93c8350d53f7d55753d3 100644 (file)
 #string STR_DMPSTORE_HEADER_LINE       #language en-US "Variable %H%s%N '%H%g%N:%H%s%N' DataSize = 0x%02x\r\n"\r
 #string STR_DMPSTORE_DELETE_LINE       #language en-US "Delete variable '%H%g%N:%H%s%N': %r\r\n"\r
 #string STR_DMPSTORE_NO_VAR_FOUND      #language en-US "%H%s%N: No matching variables found.\r\n"\r
+#string STR_DMPSTORE_NO_VAR_FOUND_SFO  #language en-US "VariableInfo,\"\",\"\",\"\",\"\",\"\"\r\n"\r
 #string STR_DMPSTORE_NO_VAR_FOUND_GN   #language en-US "%H%s%N: No matching variables found. Guid %g, Name %s\r\n"\r
+#string STR_DMPSTORE_NO_VAR_FOUND_NG_SFO #language en-US "VariableInfo,\"%s\",\"%g\",\"\",\"\",\"\"\r\n"\r
 #string STR_DMPSTORE_NO_VAR_FOUND_N    #language en-US "%H%s%N: No matching variables found. Name %s\r\n"\r
+#string STR_DMPSTORE_NO_VAR_FOUND_N_SFO #language en-US #language en-US "VariableInfo,\"%s\",\"\",\"\",\"\",\"\"\r\n"\r
 #string STR_DMPSTORE_NO_VAR_FOUND_G    #language en-US "%H%s%N: No matching variables found. Guid %g\r\n"\r
+#string STR_DMPSTORE_NO_VAR_FOUND_G_SFO #language en-US "VariableInfo,\"\",\"%g\",\"\",\"\",\"\"\r\n"\r
+#string STR_DMPSTORE_VAR_SFO           #language en-US "VariableInfo,\"%s\",\"%g\",\"0x%x\",\"0x%x\",\"%s\"\r\n"\r
 \r
 #string STR_GET_HELP_COMP         #language en-US ""\r
 ".TH comp 0 "Compare 2 files"\r\n"\r
 "Manages all UEFI variables.\r\n"\r
 ".SH SYNOPSIS\r\n"\r
 " \r\n"\r
-"DMPSTORE [-b] [-d] [-all | ([variable] [-guid guid])]\r\n"\r
+"DMPSTORE [-b] [-d] [-all | ([variable] [-guid guid])] [-sfo]\r\n"\r
 "DMPSTORE [-all | ([variable] [-guid guid])] [-s file]\r\n"\r
 "DMPSTORE [-all | ([variable] [-guid guid])] [-l file]\r\n"\r
 ".SH OPTIONS\r\n"\r
 "  -guid    - Specifies the GUID of the variables to be displayed in\r\n"\r
 "             standard text format. If not specified and -all is not\r\n"\r
 "             specified, the EFI_GLOBAL_VARIABLE GUID is assumed.\r\n"\r
+"  -sfo     - Displays information as described in Standard-Format Output.\r\n"\r
 "  -all     - Dumps all variables, including those\r\n"\r
 "             with a different GUID than EFI_GLOBAL_VARIABLE.\r\n"\r
 "  -d       - Delete variables.\r\n"\r