[edk2-devel] [PATCH v2 4/6] ShellPkg/AcpiView: Move parameter parsing

Tomas Pilar (tpilar) posted 6 patches 7 weeks ago

[edk2-devel] [PATCH v2 4/6] ShellPkg/AcpiView: Move parameter parsing

Posted by Tomas Pilar (tpilar) 7 weeks ago
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>
Signed-off-by: Tomas Pilar <tomas.pilar@arm.com>
---
 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c                    | 205 -----------------------------------------------------------------
 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.h                    |  18 +++++-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.c | 218 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.h |  10 +++-
 4 files changed, 240 insertions(+), 211 deletions(-)

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



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#60063): https://edk2.groups.io/g/devel/message/60063
Mute This Topic: https://groups.io/mt/74382415/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-

Re: [edk2-devel] [PATCH v2 4/6] ShellPkg/AcpiView: Move parameter parsing

Posted by Gao, Zhichao 4 weeks ago
Reviewed-by: Zhichao Gao <zhichao.gao@intel.com>

Thanks,
Zhichao

> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Tomas Pilar
> (tpilar)
> Sent: Friday, May 22, 2020 2:44 AM
> To: devel@edk2.groups.io
> Cc: nd@arm.com; Ni, Ray <ray.ni@intel.com>; Gao, Zhichao
> <zhichao.gao@intel.com>
> Subject: [edk2-devel] [PATCH v2 4/6] ShellPkg/AcpiView: Move parameter parsing
> 
> 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>
> Signed-off-by: Tomas Pilar <tomas.pilar@arm.com>
> ---
>  ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c                    | 205 ------
> -----------------------------------------------------------
>  ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.h                    |  18
> +++++-
> 
> ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.c
> | 218
> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> ++++-
> 
> ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.
> h |  10 +++-
>  4 files changed, 240 insertions(+), 211 deletions(-)
> 
> diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c
> b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c
> index c9654e52c434..a3160ed6f0a2 100644
> --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c
> +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c
> @@ -32,19 +32,6 @@ EFI_HII_HANDLE gShellAcpiViewHiiHandle = NULL;
>  STATIC UINT32             mTableCount;
>  STATIC UINT32             mBinTableCount;
> 
> -/**
> -  An array of acpiview command line parameters.
> -**/
> -STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
> -  {L"-q", TypeFlag},
> -  {L"-d", TypeFlag},
> -  {L"-h", TypeFlag},
> -  {L"-l", TypeFlag},
> -  {L"-s", TypeValue},
> -  {L"-r", TypeValue},
> -  {NULL, TypeMax}
> -};
> -
>  /**
>    This function dumps the ACPI table to a file.
> 
> @@ -228,7 +215,6 @@ ProcessTableReportOptions (
>            Returns EFI_UNSUPPORTED if the RSDP version is less than 2.
>            Returns EFI_SUCCESS     if successful.
>  **/
> -STATIC
>  EFI_STATUS
>  EFIAPI
>  AcpiView (
> @@ -372,194 +358,3 @@ AcpiView (
>    }
>    return EFI_SUCCESS;
>  }
> -
> -/**
> -  Function for 'acpiview' command.
> -
> -  @param[in] ImageHandle  Handle to the Image (NULL if Internal).
> -  @param[in] SystemTable  Pointer to the System Table (NULL if Internal).
> -**/
> -SHELL_STATUS
> -EFIAPI
> -ShellCommandRunAcpiView (
> -  IN EFI_HANDLE        ImageHandle,
> -  IN EFI_SYSTEM_TABLE* SystemTable
> -  )
> -{
> -  EFI_STATUS         Status;
> -  SHELL_STATUS       ShellStatus;
> -  LIST_ENTRY*        Package;
> -  CHAR16*            ProblemParam;
> -  SHELL_FILE_HANDLE  TmpDumpFileHandle;
> -  CONST CHAR16*      MandatoryTableSpecStr;
> -  CONST CHAR16       *SelectedTableName;
> -
> -  // Set configuration defaults
> -  AcpiConfigSetDefaults ();
> -
> -  ShellStatus = SHELL_SUCCESS;
> -  Package = NULL;
> -  TmpDumpFileHandle = NULL;
> -
> -  Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam,
> TRUE);
> -  if (EFI_ERROR (Status)) {
> -    if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
> -      ShellPrintHiiEx (
> -        -1,
> -        -1,
> -        NULL,
> -        STRING_TOKEN (STR_GEN_PROBLEM),
> -        gShellAcpiViewHiiHandle,
> -        L"acpiview",
> -        ProblemParam
> -        );
> -      FreePool (ProblemParam);
> -    } else {
> -      Print (L"acpiview: Error processing input parameter(s)\n");
> -    }
> -    ShellStatus = SHELL_INVALID_PARAMETER;
> -  } else {
> -    if (ShellCommandLineGetCount (Package) > 1) {
> -      ShellPrintHiiEx (
> -        -1,
> -        -1,
> -        NULL,
> -        STRING_TOKEN (STR_GEN_TOO_MANY),
> -        gShellAcpiViewHiiHandle,
> -        L"acpiview"
> -        );
> -      ShellStatus = SHELL_INVALID_PARAMETER;
> -    } else if (ShellCommandLineGetFlag (Package, L"-?")) {
> -      ShellPrintHiiEx (
> -        -1,
> -        -1,
> -        NULL,
> -        STRING_TOKEN (STR_GET_HELP_ACPIVIEW),
> -        gShellAcpiViewHiiHandle,
> -        L"acpiview"
> -        );
> -    } else if (ShellCommandLineGetFlag (Package, L"-s") &&
> -               ShellCommandLineGetValue (Package, L"-s") == NULL) {
> -      ShellPrintHiiEx (
> -        -1,
> -        -1,
> -        NULL,
> -        STRING_TOKEN (STR_GEN_NO_VALUE),
> -        gShellAcpiViewHiiHandle,
> -        L"acpiview",
> -        L"-s"
> -        );
> -      ShellStatus = SHELL_INVALID_PARAMETER;
> -    } else if (ShellCommandLineGetFlag (Package, L"-r") &&
> -               ShellCommandLineGetValue (Package, L"-r") == NULL) {
> -      ShellPrintHiiEx (
> -        -1,
> -        -1,
> -        NULL,
> -        STRING_TOKEN (STR_GEN_NO_VALUE),
> -        gShellAcpiViewHiiHandle,
> -        L"acpiview",
> -        L"-r"
> -        );
> -      ShellStatus = SHELL_INVALID_PARAMETER;
> -    } else if ((ShellCommandLineGetFlag (Package, L"-s") &&
> -                ShellCommandLineGetFlag (Package, L"-l"))) {
> -      ShellPrintHiiEx (
> -        -1,
> -        -1,
> -        NULL,
> -        STRING_TOKEN (STR_GEN_TOO_MANY),
> -        gShellAcpiViewHiiHandle,
> -        L"acpiview"
> -        );
> -      ShellStatus = SHELL_INVALID_PARAMETER;
> -    } else if (ShellCommandLineGetFlag (Package, L"-d") &&
> -               !ShellCommandLineGetFlag (Package, L"-s")) {
> -        ShellPrintHiiEx (
> -          -1,
> -          -1,
> -          NULL,
> -          STRING_TOKEN (STR_GEN_MISSING_OPTION),
> -          gShellAcpiViewHiiHandle,
> -          L"acpiview",
> -          L"-s",
> -          L"-d"
> -          );
> -        ShellStatus = SHELL_INVALID_PARAMETER;
> -    } else {
> -      // Turn on colour highlighting if requested
> -      SetColourHighlighting (ShellCommandLineGetFlag (Package, L"-h"));
> -
> -      // Surpress consistency checking if requested
> -      SetConsistencyChecking (!ShellCommandLineGetFlag (Package, L"-q"));
> -
> -      // Evaluate the parameters for mandatory ACPI table presence checks
> -      SetMandatoryTableValidate (ShellCommandLineGetFlag (Package, L"-r"));
> -      MandatoryTableSpecStr = ShellCommandLineGetValue (Package, L"-r");
> -
> -      if (MandatoryTableSpecStr != NULL) {
> -        SetMandatoryTableSpec (ShellHexStrToUintn (MandatoryTableSpecStr));
> -      }
> -
> -      if (ShellCommandLineGetFlag (Package, L"-l")) {
> -        SetReportOption (ReportTableList);
> -      } else {
> -        SelectedTableName = ShellCommandLineGetValue (Package, L"-s");
> -        if (SelectedTableName != NULL) {
> -          SelectAcpiTable (SelectedTableName);
> -          SetReportOption (ReportSelected);
> -
> -          if (ShellCommandLineGetFlag (Package, L"-d"))  {
> -            // Create a temporary file to check if the media is writable.
> -            CHAR16 FileNameBuffer[MAX_FILE_NAME_LEN];
> -            SetReportOption (ReportDumpBinFile);
> -
> -            UnicodeSPrint (
> -              FileNameBuffer,
> -              sizeof (FileNameBuffer),
> -              L".\\%s%04d.tmp",
> -              SelectedTableName,
> -              mBinTableCount
> -              );
> -
> -            Status = ShellOpenFileByName (
> -                       FileNameBuffer,
> -                       &TmpDumpFileHandle,
> -                       EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE |
> -                       EFI_FILE_MODE_CREATE,
> -                       0
> -                       );
> -
> -            if (EFI_ERROR (Status)) {
> -              ShellStatus = SHELL_INVALID_PARAMETER;
> -              TmpDumpFileHandle = NULL;
> -              ShellPrintHiiEx (
> -                -1,
> -                -1,
> -                NULL,
> -                STRING_TOKEN (STR_GEN_READONLY_MEDIA),
> -                gShellAcpiViewHiiHandle,
> -                L"acpiview"
> -                );
> -              goto Done;
> -            }
> -            // Delete Temporary file.
> -            ShellDeleteFile (&TmpDumpFileHandle);
> -          } // -d
> -        } // -s
> -      }
> -
> -      // Parse ACPI Table information
> -      Status = AcpiView (SystemTable);
> -      if (EFI_ERROR (Status)) {
> -        ShellStatus = SHELL_NOT_FOUND;
> -      }
> -    }
> -  }
> -
> -Done:
> -  if (Package != NULL) {
> -    ShellCommandLineFreeVarList (Package);
> -  }
> -  return ShellStatus;
> -}
> diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.h
> b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.h
> index 92d64a88814d..d5b95f5ee707 100644
> --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.h
> +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.h
> @@ -64,7 +64,7 @@ GetWarningCount (
> 
>    @param [in] Signature The ACPI table Signature.
>    @param [in] TablePtr  Pointer to the ACPI table data.
> -  @param [in] Length    The length fo the ACPI table.
> +  @param [in] Length    The length of the ACPI table.
> 
>    @retval Returns TRUE if the ACPI table should be traced.
>  **/
> @@ -75,4 +75,20 @@ ProcessTableReportOptions (
>    IN CONST UINT32  Length
>    );
> 
> +/**
> +  This function iterates the configuration table entries in the
> +  system table, retrieves the RSDP pointer and starts parsing the ACPI tables.
> +
> +  @param [in] SystemTable Pointer to the EFI system table.
> +
> +  @retval EFI_NOT_FOUND   The RSDP pointer was not found.
> +  @retval EFI_UNSUPPORTED The RSDP version was less than 2.
> +  @retval EFI_SUCCESS     The command was successful.
> +**/
> +EFI_STATUS
> +EFIAPI
> +AcpiView (
> +  IN EFI_SYSTEM_TABLE* SystemTable
> +  );
> +
>  #endif // ACPIVIEW_H_
> diff --git
> a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLi
> b.c
> b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLi
> b.c
> index e0d5a8108552..c3942ad24e5b 100644
> ---
> a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLi
> b.c
> +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewComm
> +++ andLib.c
> @@ -1,24 +1,44 @@
>  /** @file
>    Main file for 'acpiview' Shell command function.
> 
> -  Copyright (c) 2016 - 2019, ARM Limited. All rights reserved.<BR>
> +  Copyright (c) 2016 - 2020, ARM Limited. All rights reserved.<BR>
>    SPDX-License-Identifier: BSD-2-Clause-Patent  **/
> 
>  #include <Guid/ShellLibHiiGuid.h>
>  #include <IndustryStandard/Acpi.h>
> +
> +#include <Library/BaseMemoryLib.h>
>  #include <Library/HiiLib.h>
> +#include <Library/MemoryAllocationLib.h> #include <Library/PrintLib.h>
>  #include <Library/ShellCommandLib.h>
> -#include <Library/UefiLib.h>
> +#include <Library/ShellLib.h>
>  #include <Library/UefiBootServicesTableLib.h>
> +#include <Library/UefiLib.h>
>  #include <Uefi.h>
> +
>  #include "AcpiParser.h"
>  #include "AcpiTableParser.h"
>  #include "AcpiView.h"
> +#include "AcpiViewConfig.h"
>  #include "UefiShellAcpiViewCommandLib.h"
> 
>  CONST CHAR16 gShellAcpiViewFileName[] = L"ShellCommand";
> 
> +/**
> +  An array of acpiview command line parameters.
> +**/
> +STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
> +  {L"-q", TypeFlag},
> +  {L"-d", TypeFlag},
> +  {L"-h", TypeFlag},
> +  {L"-l", TypeFlag},
> +  {L"-s", TypeValue},
> +  {L"-r", TypeValue},
> +  {NULL, TypeMax}
> +};
> +
>  /**
>    A list of available table parsers.
>  */
> @@ -92,6 +112,200 @@ ShellCommandGetManFileNameAcpiView (
>    return gShellAcpiViewFileName;
>  }
> 
> +/**
> +  Function for 'acpiview' command.
> +
> +  @param[in] ImageHandle  Handle to the Image (NULL if internal).
> +  @param[in] SystemTable  Pointer to the System Table (NULL if internal).
> +
> +  @retval SHELL_INVALID_PARAMETER The command line invocation could not
> be parsed
> +  @retval SHELL_NOT_FOUND         The command failed
> +  @retval SHELL_SUCCESS           The command was successful
> +**/
> +SHELL_STATUS
> +EFIAPI
> +ShellCommandRunAcpiView (
> +  IN EFI_HANDLE        ImageHandle,
> +  IN EFI_SYSTEM_TABLE* SystemTable
> +  )
> +{
> +  EFI_STATUS         Status;
> +  SHELL_STATUS       ShellStatus;
> +  LIST_ENTRY*        Package;
> +  CHAR16*            ProblemParam;
> +  SHELL_FILE_HANDLE  TmpDumpFileHandle;
> +  CONST CHAR16*      MandatoryTableSpecStr;
> +  CONST CHAR16*      SelectedTableName;
> +
> +  // Set configuration defaults
> +  AcpiConfigSetDefaults ();
> +
> +  ShellStatus = SHELL_SUCCESS;
> +  Package = NULL;
> +  TmpDumpFileHandle = NULL;
> +
> +  Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam,
> + TRUE);  if (EFI_ERROR (Status)) {
> +    if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
> +      ShellPrintHiiEx (
> +        -1,
> +        -1,
> +        NULL,
> +        STRING_TOKEN (STR_GEN_PROBLEM),
> +        gShellAcpiViewHiiHandle,
> +        L"acpiview",
> +        ProblemParam
> +        );
> +      FreePool (ProblemParam);
> +    } else {
> +      Print (L"acpiview: Error processing input parameter(s)\n");
> +    }
> +    ShellStatus = SHELL_INVALID_PARAMETER;  } else {
> +    if (ShellCommandLineGetCount (Package) > 1) {
> +      ShellPrintHiiEx (
> +        -1,
> +        -1,
> +        NULL,
> +        STRING_TOKEN (STR_GEN_TOO_MANY),
> +        gShellAcpiViewHiiHandle,
> +        L"acpiview"
> +        );
> +      ShellStatus = SHELL_INVALID_PARAMETER;
> +    } else if (ShellCommandLineGetFlag (Package, L"-?")) {
> +      ShellPrintHiiEx (
> +        -1,
> +        -1,
> +        NULL,
> +        STRING_TOKEN (STR_GET_HELP_ACPIVIEW),
> +        gShellAcpiViewHiiHandle,
> +        L"acpiview"
> +        );
> +    } else if (ShellCommandLineGetFlag (Package, L"-s") &&
> +               ShellCommandLineGetValue (Package, L"-s") == NULL) {
> +      ShellPrintHiiEx (
> +        -1,
> +        -1,
> +        NULL,
> +        STRING_TOKEN (STR_GEN_NO_VALUE),
> +        gShellAcpiViewHiiHandle,
> +        L"acpiview",
> +        L"-s"
> +        );
> +      ShellStatus = SHELL_INVALID_PARAMETER;
> +    } else if (ShellCommandLineGetFlag (Package, L"-r") &&
> +               ShellCommandLineGetValue (Package, L"-r") == NULL) {
> +      ShellPrintHiiEx (
> +        -1,
> +        -1,
> +        NULL,
> +        STRING_TOKEN (STR_GEN_NO_VALUE),
> +        gShellAcpiViewHiiHandle,
> +        L"acpiview",
> +        L"-r"
> +        );
> +      ShellStatus = SHELL_INVALID_PARAMETER;
> +    } else if ((ShellCommandLineGetFlag (Package, L"-s") &&
> +                ShellCommandLineGetFlag (Package, L"-l"))) {
> +      ShellPrintHiiEx (
> +        -1,
> +        -1,
> +        NULL,
> +        STRING_TOKEN (STR_GEN_TOO_MANY),
> +        gShellAcpiViewHiiHandle,
> +        L"acpiview"
> +        );
> +      ShellStatus = SHELL_INVALID_PARAMETER;
> +    } else if (ShellCommandLineGetFlag (Package, L"-d") &&
> +               !ShellCommandLineGetFlag (Package, L"-s")) {
> +        ShellPrintHiiEx (
> +          -1,
> +          -1,
> +          NULL,
> +          STRING_TOKEN (STR_GEN_MISSING_OPTION),
> +          gShellAcpiViewHiiHandle,
> +          L"acpiview",
> +          L"-s",
> +          L"-d"
> +          );
> +        ShellStatus = SHELL_INVALID_PARAMETER;
> +    } else {
> +      // Turn on colour highlighting if requested
> +      SetColourHighlighting (ShellCommandLineGetFlag (Package, L"-h"));
> +
> +      // Surpress consistency checking if requested
> +      SetConsistencyChecking (!ShellCommandLineGetFlag (Package,
> + L"-q"));
> +
> +      // Evaluate the parameters for mandatory ACPI table presence checks
> +      SetMandatoryTableValidate (ShellCommandLineGetFlag (Package, L"-r"));
> +      MandatoryTableSpecStr = ShellCommandLineGetValue (Package,
> + L"-r");
> +
> +      if (MandatoryTableSpecStr != NULL) {
> +        SetMandatoryTableSpec (ShellHexStrToUintn (MandatoryTableSpecStr));
> +      }
> +
> +      if (ShellCommandLineGetFlag (Package, L"-l")) {
> +        SetReportOption (ReportTableList);
> +      } else {
> +        SelectedTableName = ShellCommandLineGetValue (Package, L"-s");
> +        if (SelectedTableName != NULL) {
> +          SelectAcpiTable (SelectedTableName);
> +          SetReportOption (ReportSelected);
> +
> +          if (ShellCommandLineGetFlag (Package, L"-d"))  {
> +            // Create a temporary file to check if the media is writable.
> +            CHAR16 FileNameBuffer[MAX_FILE_NAME_LEN];
> +            SetReportOption (ReportDumpBinFile);
> +
> +            UnicodeSPrint (
> +              FileNameBuffer,
> +              sizeof (FileNameBuffer),
> +              L".\\%s0000.tmp",
> +              SelectedTableName
> +              );
> +
> +            Status = ShellOpenFileByName (
> +                       FileNameBuffer,
> +                       &TmpDumpFileHandle,
> +                       EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE |
> +                       EFI_FILE_MODE_CREATE,
> +                       0
> +                       );
> +
> +            if (EFI_ERROR (Status)) {
> +              ShellStatus = SHELL_INVALID_PARAMETER;
> +              TmpDumpFileHandle = NULL;
> +              ShellPrintHiiEx (
> +                -1,
> +                -1,
> +                NULL,
> +                STRING_TOKEN (STR_GEN_READONLY_MEDIA),
> +                gShellAcpiViewHiiHandle,
> +                L"acpiview"
> +                );
> +              goto Done;
> +            }
> +            // Delete Temporary file.
> +            ShellDeleteFile (&TmpDumpFileHandle);
> +          } // -d
> +        } // -s
> +      }
> +
> +      // Parse ACPI Table information
> +      Status = AcpiView (SystemTable);
> +      if (EFI_ERROR (Status)) {
> +        ShellStatus = SHELL_NOT_FOUND;
> +      }
> +    }
> +  }
> +
> +Done:
> +  if (Package != NULL) {
> +    ShellCommandLineFreeVarList (Package);
> +  }
> +  return ShellStatus;
> +}
> +
>  /**
>    Constructor for the Shell AcpiView Command library.
> 
> diff --git
> a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLi
> b.h
> b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLi
> b.h
> index c1cf7a57af7a..a3a29164004d 100644
> ---
> a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLi
> b.h
> +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewComm
> +++ andLib.h
> @@ -1,7 +1,7 @@
>  /** @file
>    Header file for 'acpiview' Shell command functions.
> 
> -  Copyright (c) 2016 - 2017, ARM Limited. All rights reserved.<BR>
> +  Copyright (c) 2016 - 2020, ARM Limited. All rights reserved.<BR>
>    SPDX-License-Identifier: BSD-2-Clause-Patent  **/
> 
> @@ -13,8 +13,12 @@ extern EFI_HII_HANDLE gShellAcpiViewHiiHandle;
>  /**
>    Function for 'acpiview' command.
> 
> -  @param[in] ImageHandle  Handle to the Image (NULL if Internal).
> -  @param[in] SystemTable  Pointer to the System Table (NULL if Internal).
> +  @param[in] ImageHandle  Handle to the Image (NULL if internal).
> +  @param[in] SystemTable  Pointer to the System Table (NULL if internal).
> +
> +  @retval SHELL_INVALID_PARAMETER The command line invocation could not
> be parsed
> +  @retval SHELL_NOT_FOUND         The command failed
> +  @retval SHELL_SUCCESS           The command was successful
>  **/
>  SHELL_STATUS
>  EFIAPI
> --
> 2.24.1.windows.2
> 
> 
> 
> 


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#61187): https://edk2.groups.io/g/devel/message/61187
Mute This Topic: https://groups.io/mt/74382415/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-