]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg/AcpiView: Move parameter parsing
authorTomas Pilar <Tomas.Pilar@arm.com>
Fri, 19 Jun 2020 11:59:54 +0000 (12:59 +0100)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Tue, 30 Jun 2020 01:39:50 +0000 (01:39 +0000)
Parsing command line parameters is done in the shell
command wrapper. This declutters the core code and improves
modular design.

Cc: Ray Ni <ray.ni@intel.com>
Cc: Zhichao Gao <zhichao.gao@intel.com>
Reviewed-by: Zhichao Gao <zhichao.gao@intel.com>
Signed-off-by: Tomas Pilar <tomas.pilar@arm.com>
ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c
ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.h
ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.c
ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.h

index 40778374af452c08c4b287d0e1fd3dab304b0734..e524fcb0b27ace37a5148615d6c12d4f6876c59f 100644 (file)
@@ -32,19 +32,6 @@ EFI_HII_HANDLE gShellAcpiViewHiiHandle = NULL;
 STATIC UINT32             mTableCount;\r
 STATIC UINT32             mBinTableCount;\r
 \r
-/**\r
-  An array of acpiview command line parameters.\r
-**/\r
-STATIC CONST SHELL_PARAM_ITEM ParamList[] = {\r
-  {L"-q", TypeFlag},\r
-  {L"-d", TypeFlag},\r
-  {L"-h", TypeFlag},\r
-  {L"-l", TypeFlag},\r
-  {L"-s", TypeValue},\r
-  {L"-r", TypeValue},\r
-  {NULL, TypeMax}\r
-};\r
-\r
 /**\r
   This function dumps the ACPI table to a file.\r
 \r
@@ -228,7 +215,6 @@ ProcessTableReportOptions (
           Returns EFI_UNSUPPORTED if the RSDP version is less than 2.\r
           Returns EFI_SUCCESS     if successful.\r
 **/\r
-STATIC\r
 EFI_STATUS\r
 EFIAPI\r
 AcpiView (\r
@@ -372,194 +358,3 @@ AcpiView (
   }\r
   return EFI_SUCCESS;\r
 }\r
-\r
-/**\r
-  Function for 'acpiview' command.\r
-\r
-  @param[in] ImageHandle  Handle to the Image (NULL if Internal).\r
-  @param[in] SystemTable  Pointer to the System Table (NULL if Internal).\r
-**/\r
-SHELL_STATUS\r
-EFIAPI\r
-ShellCommandRunAcpiView (\r
-  IN EFI_HANDLE        ImageHandle,\r
-  IN EFI_SYSTEM_TABLE* SystemTable\r
-  )\r
-{\r
-  EFI_STATUS         Status;\r
-  SHELL_STATUS       ShellStatus;\r
-  LIST_ENTRY*        Package;\r
-  CHAR16*            ProblemParam;\r
-  SHELL_FILE_HANDLE  TmpDumpFileHandle;\r
-  CONST CHAR16*      MandatoryTableSpecStr;\r
-  CONST CHAR16       *SelectedTableName;\r
-\r
-  // Set configuration defaults\r
-  AcpiConfigSetDefaults ();\r
-\r
-  ShellStatus = SHELL_SUCCESS;\r
-  Package = NULL;\r
-  TmpDumpFileHandle = NULL;\r
-\r
-  Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);\r
-  if (EFI_ERROR (Status)) {\r
-    if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {\r
-      ShellPrintHiiEx (\r
-        -1,\r
-        -1,\r
-        NULL,\r
-        STRING_TOKEN (STR_GEN_PROBLEM),\r
-        gShellAcpiViewHiiHandle,\r
-        L"acpiview",\r
-        ProblemParam\r
-        );\r
-      FreePool (ProblemParam);\r
-    } else {\r
-      Print (L"acpiview: Error processing input parameter(s)\n");\r
-    }\r
-    ShellStatus = SHELL_INVALID_PARAMETER;\r
-  } else {\r
-    if (ShellCommandLineGetCount (Package) > 1) {\r
-      ShellPrintHiiEx (\r
-        -1,\r
-        -1,\r
-        NULL,\r
-        STRING_TOKEN (STR_GEN_TOO_MANY),\r
-        gShellAcpiViewHiiHandle,\r
-        L"acpiview"\r
-        );\r
-      ShellStatus = SHELL_INVALID_PARAMETER;\r
-    } else if (ShellCommandLineGetFlag (Package, L"-?")) {\r
-      ShellPrintHiiEx (\r
-        -1,\r
-        -1,\r
-        NULL,\r
-        STRING_TOKEN (STR_GET_HELP_ACPIVIEW),\r
-        gShellAcpiViewHiiHandle,\r
-        L"acpiview"\r
-        );\r
-    } else if (ShellCommandLineGetFlag (Package, L"-s") &&\r
-               ShellCommandLineGetValue (Package, L"-s") == NULL) {\r
-      ShellPrintHiiEx (\r
-        -1,\r
-        -1,\r
-        NULL,\r
-        STRING_TOKEN (STR_GEN_NO_VALUE),\r
-        gShellAcpiViewHiiHandle,\r
-        L"acpiview",\r
-        L"-s"\r
-        );\r
-      ShellStatus = SHELL_INVALID_PARAMETER;\r
-    } else if (ShellCommandLineGetFlag (Package, L"-r") &&\r
-               ShellCommandLineGetValue (Package, L"-r") == NULL) {\r
-      ShellPrintHiiEx (\r
-        -1,\r
-        -1,\r
-        NULL,\r
-        STRING_TOKEN (STR_GEN_NO_VALUE),\r
-        gShellAcpiViewHiiHandle,\r
-        L"acpiview",\r
-        L"-r"\r
-        );\r
-      ShellStatus = SHELL_INVALID_PARAMETER;\r
-    } else if ((ShellCommandLineGetFlag (Package, L"-s") &&\r
-                ShellCommandLineGetFlag (Package, L"-l"))) {\r
-      ShellPrintHiiEx (\r
-        -1,\r
-        -1,\r
-        NULL,\r
-        STRING_TOKEN (STR_GEN_TOO_MANY),\r
-        gShellAcpiViewHiiHandle,\r
-        L"acpiview"\r
-        );\r
-      ShellStatus = SHELL_INVALID_PARAMETER;\r
-    } else if (ShellCommandLineGetFlag (Package, L"-d") &&\r
-               !ShellCommandLineGetFlag (Package, L"-s")) {\r
-        ShellPrintHiiEx (\r
-          -1,\r
-          -1,\r
-          NULL,\r
-          STRING_TOKEN (STR_GEN_MISSING_OPTION),\r
-          gShellAcpiViewHiiHandle,\r
-          L"acpiview",\r
-          L"-s",\r
-          L"-d"\r
-          );\r
-        ShellStatus = SHELL_INVALID_PARAMETER;\r
-    } else {\r
-      // Turn on colour highlighting if requested\r
-      SetColourHighlighting (ShellCommandLineGetFlag (Package, L"-h"));\r
-\r
-      // Surpress consistency checking if requested\r
-      SetConsistencyChecking (!ShellCommandLineGetFlag (Package, L"-q"));\r
-\r
-      // Evaluate the parameters for mandatory ACPI table presence checks\r
-      SetMandatoryTableValidate (ShellCommandLineGetFlag (Package, L"-r"));\r
-      MandatoryTableSpecStr = ShellCommandLineGetValue (Package, L"-r");\r
-\r
-      if (MandatoryTableSpecStr != NULL) {\r
-        SetMandatoryTableSpec (ShellHexStrToUintn (MandatoryTableSpecStr));\r
-      }\r
-\r
-      if (ShellCommandLineGetFlag (Package, L"-l")) {\r
-        SetReportOption (ReportTableList);\r
-      } else {\r
-        SelectedTableName = ShellCommandLineGetValue (Package, L"-s");\r
-        if (SelectedTableName != NULL) {\r
-          SelectAcpiTable (SelectedTableName);\r
-          SetReportOption (ReportSelected);\r
-\r
-          if (ShellCommandLineGetFlag (Package, L"-d"))  {\r
-            // Create a temporary file to check if the media is writable.\r
-            CHAR16 FileNameBuffer[MAX_FILE_NAME_LEN];\r
-            SetReportOption (ReportDumpBinFile);\r
-\r
-            UnicodeSPrint (\r
-              FileNameBuffer,\r
-              sizeof (FileNameBuffer),\r
-              L".\\%s%04d.tmp",\r
-              SelectedTableName,\r
-              mBinTableCount\r
-              );\r
-\r
-            Status = ShellOpenFileByName (\r
-                       FileNameBuffer,\r
-                       &TmpDumpFileHandle,\r
-                       EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE |\r
-                       EFI_FILE_MODE_CREATE,\r
-                       0\r
-                       );\r
-\r
-            if (EFI_ERROR (Status)) {\r
-              ShellStatus = SHELL_INVALID_PARAMETER;\r
-              TmpDumpFileHandle = NULL;\r
-              ShellPrintHiiEx (\r
-                -1,\r
-                -1,\r
-                NULL,\r
-                STRING_TOKEN (STR_GEN_READONLY_MEDIA),\r
-                gShellAcpiViewHiiHandle,\r
-                L"acpiview"\r
-                );\r
-              goto Done;\r
-            }\r
-            // Delete Temporary file.\r
-            ShellDeleteFile (&TmpDumpFileHandle);\r
-          } // -d\r
-        } // -s\r
-      }\r
-\r
-      // Parse ACPI Table information\r
-      Status = AcpiView (SystemTable);\r
-      if (EFI_ERROR (Status)) {\r
-        ShellStatus = SHELL_NOT_FOUND;\r
-      }\r
-    }\r
-  }\r
-\r
-Done:\r
-  if (Package != NULL) {\r
-    ShellCommandLineFreeVarList (Package);\r
-  }\r
-  return ShellStatus;\r
-}\r
index 92d64a88814d0af0ba08d2e9da6b87e7d204125d..d5b95f5ee707de18be1879b3cd235d6c5db11d9f 100644 (file)
@@ -64,7 +64,7 @@ GetWarningCount (
 \r
   @param [in] Signature The ACPI table Signature.\r
   @param [in] TablePtr  Pointer to the ACPI table data.\r
-  @param [in] Length    The length fo the ACPI table.\r
+  @param [in] Length    The length of the ACPI table.\r
 \r
   @retval Returns TRUE if the ACPI table should be traced.\r
 **/\r
@@ -75,4 +75,20 @@ ProcessTableReportOptions (
   IN CONST UINT32  Length\r
   );\r
 \r
+/**\r
+  This function iterates the configuration table entries in the\r
+  system table, retrieves the RSDP pointer and starts parsing the ACPI tables.\r
+\r
+  @param [in] SystemTable Pointer to the EFI system table.\r
+\r
+  @retval EFI_NOT_FOUND   The RSDP pointer was not found.\r
+  @retval EFI_UNSUPPORTED The RSDP version was less than 2.\r
+  @retval EFI_SUCCESS     The command was successful.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+AcpiView (\r
+  IN EFI_SYSTEM_TABLE* SystemTable\r
+  );\r
+\r
 #endif // ACPIVIEW_H_\r
index e0d5a81085525a91110d9a25279adf3376286342..c3942ad24e5b9c885dc78fbe97434a87147e306e 100644 (file)
@@ -1,24 +1,44 @@
 /** @file\r
   Main file for 'acpiview' Shell command function.\r
 \r
-  Copyright (c) 2016 - 2019, ARM Limited. All rights reserved.<BR>\r
+  Copyright (c) 2016 - 2020, ARM Limited. All rights reserved.<BR>\r
   SPDX-License-Identifier: BSD-2-Clause-Patent\r
 **/\r
 \r
 #include <Guid/ShellLibHiiGuid.h>\r
 #include <IndustryStandard/Acpi.h>\r
+\r
+#include <Library/BaseMemoryLib.h>\r
 #include <Library/HiiLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/PrintLib.h>\r
 #include <Library/ShellCommandLib.h>\r
-#include <Library/UefiLib.h>\r
+#include <Library/ShellLib.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiLib.h>\r
 #include <Uefi.h>\r
+\r
 #include "AcpiParser.h"\r
 #include "AcpiTableParser.h"\r
 #include "AcpiView.h"\r
+#include "AcpiViewConfig.h"\r
 #include "UefiShellAcpiViewCommandLib.h"\r
 \r
 CONST CHAR16 gShellAcpiViewFileName[] = L"ShellCommand";\r
 \r
+/**\r
+  An array of acpiview command line parameters.\r
+**/\r
+STATIC CONST SHELL_PARAM_ITEM ParamList[] = {\r
+  {L"-q", TypeFlag},\r
+  {L"-d", TypeFlag},\r
+  {L"-h", TypeFlag},\r
+  {L"-l", TypeFlag},\r
+  {L"-s", TypeValue},\r
+  {L"-r", TypeValue},\r
+  {NULL, TypeMax}\r
+};\r
+\r
 /**\r
   A list of available table parsers.\r
 */\r
@@ -92,6 +112,200 @@ ShellCommandGetManFileNameAcpiView (
   return gShellAcpiViewFileName;\r
 }\r
 \r
+/**\r
+  Function for 'acpiview' command.\r
+\r
+  @param[in] ImageHandle  Handle to the Image (NULL if internal).\r
+  @param[in] SystemTable  Pointer to the System Table (NULL if internal).\r
+\r
+  @retval SHELL_INVALID_PARAMETER The command line invocation could not be parsed\r
+  @retval SHELL_NOT_FOUND         The command failed\r
+  @retval SHELL_SUCCESS           The command was successful\r
+**/\r
+SHELL_STATUS\r
+EFIAPI\r
+ShellCommandRunAcpiView (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE* SystemTable\r
+  )\r
+{\r
+  EFI_STATUS         Status;\r
+  SHELL_STATUS       ShellStatus;\r
+  LIST_ENTRY*        Package;\r
+  CHAR16*            ProblemParam;\r
+  SHELL_FILE_HANDLE  TmpDumpFileHandle;\r
+  CONST CHAR16*      MandatoryTableSpecStr;\r
+  CONST CHAR16*      SelectedTableName;\r
+\r
+  // Set configuration defaults\r
+  AcpiConfigSetDefaults ();\r
+\r
+  ShellStatus = SHELL_SUCCESS;\r
+  Package = NULL;\r
+  TmpDumpFileHandle = NULL;\r
+\r
+  Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);\r
+  if (EFI_ERROR (Status)) {\r
+    if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {\r
+      ShellPrintHiiEx (\r
+        -1,\r
+        -1,\r
+        NULL,\r
+        STRING_TOKEN (STR_GEN_PROBLEM),\r
+        gShellAcpiViewHiiHandle,\r
+        L"acpiview",\r
+        ProblemParam\r
+        );\r
+      FreePool (ProblemParam);\r
+    } else {\r
+      Print (L"acpiview: Error processing input parameter(s)\n");\r
+    }\r
+    ShellStatus = SHELL_INVALID_PARAMETER;\r
+  } else {\r
+    if (ShellCommandLineGetCount (Package) > 1) {\r
+      ShellPrintHiiEx (\r
+        -1,\r
+        -1,\r
+        NULL,\r
+        STRING_TOKEN (STR_GEN_TOO_MANY),\r
+        gShellAcpiViewHiiHandle,\r
+        L"acpiview"\r
+        );\r
+      ShellStatus = SHELL_INVALID_PARAMETER;\r
+    } else if (ShellCommandLineGetFlag (Package, L"-?")) {\r
+      ShellPrintHiiEx (\r
+        -1,\r
+        -1,\r
+        NULL,\r
+        STRING_TOKEN (STR_GET_HELP_ACPIVIEW),\r
+        gShellAcpiViewHiiHandle,\r
+        L"acpiview"\r
+        );\r
+    } else if (ShellCommandLineGetFlag (Package, L"-s") &&\r
+               ShellCommandLineGetValue (Package, L"-s") == NULL) {\r
+      ShellPrintHiiEx (\r
+        -1,\r
+        -1,\r
+        NULL,\r
+        STRING_TOKEN (STR_GEN_NO_VALUE),\r
+        gShellAcpiViewHiiHandle,\r
+        L"acpiview",\r
+        L"-s"\r
+        );\r
+      ShellStatus = SHELL_INVALID_PARAMETER;\r
+    } else if (ShellCommandLineGetFlag (Package, L"-r") &&\r
+               ShellCommandLineGetValue (Package, L"-r") == NULL) {\r
+      ShellPrintHiiEx (\r
+        -1,\r
+        -1,\r
+        NULL,\r
+        STRING_TOKEN (STR_GEN_NO_VALUE),\r
+        gShellAcpiViewHiiHandle,\r
+        L"acpiview",\r
+        L"-r"\r
+        );\r
+      ShellStatus = SHELL_INVALID_PARAMETER;\r
+    } else if ((ShellCommandLineGetFlag (Package, L"-s") &&\r
+                ShellCommandLineGetFlag (Package, L"-l"))) {\r
+      ShellPrintHiiEx (\r
+        -1,\r
+        -1,\r
+        NULL,\r
+        STRING_TOKEN (STR_GEN_TOO_MANY),\r
+        gShellAcpiViewHiiHandle,\r
+        L"acpiview"\r
+        );\r
+      ShellStatus = SHELL_INVALID_PARAMETER;\r
+    } else if (ShellCommandLineGetFlag (Package, L"-d") &&\r
+               !ShellCommandLineGetFlag (Package, L"-s")) {\r
+        ShellPrintHiiEx (\r
+          -1,\r
+          -1,\r
+          NULL,\r
+          STRING_TOKEN (STR_GEN_MISSING_OPTION),\r
+          gShellAcpiViewHiiHandle,\r
+          L"acpiview",\r
+          L"-s",\r
+          L"-d"\r
+          );\r
+        ShellStatus = SHELL_INVALID_PARAMETER;\r
+    } else {\r
+      // Turn on colour highlighting if requested\r
+      SetColourHighlighting (ShellCommandLineGetFlag (Package, L"-h"));\r
+\r
+      // Surpress consistency checking if requested\r
+      SetConsistencyChecking (!ShellCommandLineGetFlag (Package, L"-q"));\r
+\r
+      // Evaluate the parameters for mandatory ACPI table presence checks\r
+      SetMandatoryTableValidate (ShellCommandLineGetFlag (Package, L"-r"));\r
+      MandatoryTableSpecStr = ShellCommandLineGetValue (Package, L"-r");\r
+\r
+      if (MandatoryTableSpecStr != NULL) {\r
+        SetMandatoryTableSpec (ShellHexStrToUintn (MandatoryTableSpecStr));\r
+      }\r
+\r
+      if (ShellCommandLineGetFlag (Package, L"-l")) {\r
+        SetReportOption (ReportTableList);\r
+      } else {\r
+        SelectedTableName = ShellCommandLineGetValue (Package, L"-s");\r
+        if (SelectedTableName != NULL) {\r
+          SelectAcpiTable (SelectedTableName);\r
+          SetReportOption (ReportSelected);\r
+\r
+          if (ShellCommandLineGetFlag (Package, L"-d"))  {\r
+            // Create a temporary file to check if the media is writable.\r
+            CHAR16 FileNameBuffer[MAX_FILE_NAME_LEN];\r
+            SetReportOption (ReportDumpBinFile);\r
+\r
+            UnicodeSPrint (\r
+              FileNameBuffer,\r
+              sizeof (FileNameBuffer),\r
+              L".\\%s0000.tmp",\r
+              SelectedTableName\r
+              );\r
+\r
+            Status = ShellOpenFileByName (\r
+                       FileNameBuffer,\r
+                       &TmpDumpFileHandle,\r
+                       EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE |\r
+                       EFI_FILE_MODE_CREATE,\r
+                       0\r
+                       );\r
+\r
+            if (EFI_ERROR (Status)) {\r
+              ShellStatus = SHELL_INVALID_PARAMETER;\r
+              TmpDumpFileHandle = NULL;\r
+              ShellPrintHiiEx (\r
+                -1,\r
+                -1,\r
+                NULL,\r
+                STRING_TOKEN (STR_GEN_READONLY_MEDIA),\r
+                gShellAcpiViewHiiHandle,\r
+                L"acpiview"\r
+                );\r
+              goto Done;\r
+            }\r
+            // Delete Temporary file.\r
+            ShellDeleteFile (&TmpDumpFileHandle);\r
+          } // -d\r
+        } // -s\r
+      }\r
+\r
+      // Parse ACPI Table information\r
+      Status = AcpiView (SystemTable);\r
+      if (EFI_ERROR (Status)) {\r
+        ShellStatus = SHELL_NOT_FOUND;\r
+      }\r
+    }\r
+  }\r
+\r
+Done:\r
+  if (Package != NULL) {\r
+    ShellCommandLineFreeVarList (Package);\r
+  }\r
+  return ShellStatus;\r
+}\r
+\r
 /**\r
   Constructor for the Shell AcpiView Command library.\r
 \r
index c1cf7a57af7a64202832063400efb61756bd2727..a3a29164004d6b424ad1860442d56c25bc0ac131 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Header file for 'acpiview' Shell command functions.\r
 \r
-  Copyright (c) 2016 - 2017, ARM Limited. All rights reserved.<BR>\r
+  Copyright (c) 2016 - 2020, ARM Limited. All rights reserved.<BR>\r
   SPDX-License-Identifier: BSD-2-Clause-Patent\r
 **/\r
 \r
@@ -13,8 +13,12 @@ extern EFI_HII_HANDLE gShellAcpiViewHiiHandle;
 /**\r
   Function for 'acpiview' command.\r
 \r
-  @param[in] ImageHandle  Handle to the Image (NULL if Internal).\r
-  @param[in] SystemTable  Pointer to the System Table (NULL if Internal).\r
+  @param[in] ImageHandle  Handle to the Image (NULL if internal).\r
+  @param[in] SystemTable  Pointer to the System Table (NULL if internal).\r
+\r
+  @retval SHELL_INVALID_PARAMETER The command line invocation could not be parsed\r
+  @retval SHELL_NOT_FOUND         The command failed\r
+  @retval SHELL_SUCCESS           The command was successful\r
 **/\r
 SHELL_STATUS\r
 EFIAPI\r