]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools/VolInfo: add some generic options
authorYonghong Zhu <yonghong.zhu@intel.com>
Wed, 17 Feb 2016 03:24:47 +0000 (11:24 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Thu, 18 Feb 2016 03:39:15 +0000 (11:39 +0800)
The Help information provided by VolInfo does not follow the EDK II Tools
Design doc, so this patch update the help text and add the generic
options: -d, -v, -q, -s.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Yonghong Zhu <yonghong.zhu@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
BaseTools/Source/C/VolInfo/VolInfo.c

index 4fa87d41eea0e0b64ee2df141cffd199c010ff9b..4fb634fe099b0205eddd90fe9595cc8f916f8bbf 100644 (file)
@@ -39,6 +39,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include "OsPath.h"\r
 #include "ParseGuidedSectionTools.h"\r
 #include "StringFuncs.h"\r
+#include "ParseInf.h"\r
 \r
 //\r
 // Utility global variables\r
@@ -163,6 +164,7 @@ Returns:
   EFI_STATUS                  Status;\r
   int                         Offset;\r
   BOOLEAN                     ErasePolarity;\r
+  UINT64                      LogLevel;\r
 \r
   SetUtilityName (UTILITY_NAME);\r
   //\r
@@ -175,28 +177,46 @@ Returns:
     __BUILD_VERSION
     );\r
 \r
-  //\r
-  // Save, and then skip filename arg\r
-  //\r
-  mUtilityFilename = argv[0];\r
+  if (argc == 1) {\r
+    Usage ();\r
+    return -1;\r
+  }\r
+\r
   argc--;\r
   argv++;\r
-\r
+  LogLevel = 0;\r
   Offset = 0;\r
 \r
+  //\r
+  // Look for help options\r
+  //\r
+  if ((strcmp(argv[0], "-h") == 0) || (strcmp(argv[0], "--help") == 0) ||\r
+      (strcmp(argv[0], "-?") == 0) || (strcmp(argv[0], "/?") == 0)) {\r
+    Usage();\r
+    return  STATUS_SUCCESS;\r
+  }\r
+  //\r
+  // Version has already be printed, so just return success\r
+  //\r
+  if (strcmp(argv[0], "--version") == 0) {\r
+    return  STATUS_SUCCESS;\r
+  }\r
+\r
   //\r
   // If they specified -x xref guid/basename cross-reference files, process it.\r
   // This will print the basename beside each file guid. To use it, specify\r
   // -x xref_filename to processdsc, then use xref_filename as a parameter\r
   // here.\r
   //\r
-  while (argc > 2) {\r
+  while (argc > 0) {\r
     if ((strcmp(argv[0], "-x") == 0) || (strcmp(argv[0], "--xref") == 0)) {\r
       ParseGuidBaseNameFile (argv[1]);\r
       printf("ParseGuidBaseNameFile: %s\n", argv[1]);\r
       argc -= 2;\r
       argv += 2;\r
-    } else if (strcmp(argv[0], "--offset") == 0) {\r
+      continue;\r
+    }\r
+    if (strcmp(argv[0], "--offset") == 0) {\r
       //\r
       // Hex or decimal?\r
       //\r
@@ -220,38 +240,55 @@ Returns:
 \r
       argc -= 2;\r
       argv += 2;\r
-    } else {\r
-      Usage ();\r
-      return -1;\r
+      continue;\r
     }\r
+\r
+    if ((stricmp (argv[0], "-v") == 0) || (stricmp (argv[0], "--verbose") == 0)) {\r
+      SetPrintLevel (VERBOSE_LOG_LEVEL);\r
+      argc --;\r
+      argv ++;\r
+      continue;\r
+    }\r
+\r
+    if ((stricmp (argv[0], "-q") == 0) || (stricmp (argv[0], "--quiet") == 0)) {\r
+      SetPrintLevel (KEY_LOG_LEVEL);\r
+      argc --;\r
+      argv ++;\r
+      continue;\r
+    }\r
+\r
+    if ((stricmp (argv[0], "-d") == 0) || (stricmp (argv[0], "--debug") == 0)) {\r
+      Status = AsciiStringToUint64 (argv[1], FALSE, &LogLevel);\r
+      if (EFI_ERROR (Status)) {\r
+        Error (NULL, 0, 1003, "Invalid option value", "%s = %s", argv[0], argv[1]);\r
+        return -1;\r
+      }\r
+      if (LogLevel > 9) {\r
+        Error (NULL, 0, 1003, "Invalid option value", "Debug Level range is 0-9, current input level is %d", (int) LogLevel);\r
+        return -1;\r
+      }\r
+      SetPrintLevel (LogLevel);\r
+      DebugMsg (NULL, 0, 9, "Debug Mode Set", "Debug Output Mode Level %s is set!", argv[1]);\r
+      argc -= 2;\r
+      argv += 2;\r
+      continue;\r
+    }\r
+\r
+    mUtilityFilename = argv[0];\r
+    argc --;\r
+    argv ++;\r
   }\r
-  //\r
-  // Check for proper number of arguments\r
-  //\r
-  if (argc != 1) {\r
-    Usage ();\r
-    return STATUS_ERROR;
-  }\r
-  //\r
-  // Look for help options\r
-  //\r
-  if ((strcmp(argv[0], "-h") == 0) || (strcmp(argv[0], "--help") == 0) || \r
-      (strcmp(argv[0], "-?") == 0) || (strcmp(argv[0], "/?") == 0)) {\r
-    Usage();\r
-    return STATUS_SUCCESS;
-  }
-  //
-  // Version has already been printed, return success.
-  //
-  if (strcmp(argv[0], "--version") == 0) {
-    return STATUS_SUCCESS;
-  }\r
+\r
   //\r
   // Open the file containing the FV\r
   //\r
-  InputFile = fopen (LongFilePath (argv[0]), "rb");\r
+  if (mUtilityFilename == NULL) {\r
+    Error (NULL, 0, 1001, "Missing option", "Input files are not specified");\r
+    return GetUtilityStatus ();\r
+  }\r
+  InputFile = fopen (LongFilePath (mUtilityFilename), "rb");\r
   if (InputFile == NULL) {\r
-    Error (NULL, 0, 0001, "Error opening the input file", argv[0]);\r
+    Error (NULL, 0, 0001, "Error opening the input file", mUtilityFilename);\r
     return GetUtilityStatus ();\r
   }\r
   //\r
@@ -266,7 +303,7 @@ Returns:
   //\r
   Status = ReadHeader (InputFile, &FvSize, &ErasePolarity);\r
   if (EFI_ERROR (Status)) {\r
-    Error (NULL, 0, 0003, "error parsing FV image", "%s Header is invalid", argv[0]);\r
+    Error (NULL, 0, 0003, "error parsing FV image", "%s Header is invalid", mUtilityFilename);\r
     fclose (InputFile);\r
     return GetUtilityStatus ();\r
   }\r
@@ -286,12 +323,12 @@ Returns:
   BytesRead = fread (FvImage, 1, FvSize, InputFile);\r
   fclose (InputFile);\r
   if ((unsigned int) BytesRead != FvSize) {\r
-    Error (NULL, 0, 0004, "error reading FvImage from", argv[0]);\r
+    Error (NULL, 0, 0004, "error reading FvImage from", mUtilityFilename);\r
     free (FvImage);\r
     return GetUtilityStatus ();\r
   }\r
 \r
-  LoadGuidedSectionToolsTxt (argv[0]);\r
+  LoadGuidedSectionToolsTxt (mUtilityFilename);\r
 \r
   PrintFvInfo (FvImage, FALSE);\r
 \r
@@ -1291,8 +1328,7 @@ Returns:
       break;\r
 \r
     case EFI_SECTION_USER_INTERFACE:\r
-      // name = &((EFI_USER_INTERFACE_SECTION *) Ptr)->FileNameString;\r
-      // printf ("  String: %s\n", &name);\r
+      printf ("  String: %ls\n", (CHAR16 *) &((EFI_USER_INTERFACE_SECTION *) Ptr)->FileNameString);\r
       break;\r
 \r
     case EFI_SECTION_FIRMWARE_VOLUME_IMAGE:\r
@@ -1856,15 +1892,26 @@ Returns:
   //\r
   // Details Option\r
   //\r
-  fprintf (stdout, "Options:\n");\r
-  fprintf (stdout, "  -x xref, --xref xref\n\\r
-            Parse basename to file-guid cross reference file(s).\n");\r
-  fprintf (stdout, "  --offset offset\n\\r
-            Offset of file to start processing FV at.\n");\r
-  fprintf (stdout, "  --version\n\
-            Display version of this tool and exit.\n");
+  fprintf (stdout, "optional arguments:\n");\r
   fprintf (stdout, "  -h, --help\n\\r
-            Show this help message and exit.\n");\r
-\r
+            Show this help message and exit\n");\r
+  fprintf (stdout, "  --version\n\\r
+           Show program's version number and exit\n");\r
+  fprintf (stdout, "  -d [DEBUG], --debug [DEBUG]\n\\r
+            Output DEBUG statements, where DEBUG_LEVEL is 0 (min) - 9 (max)\n");\r
+  fprintf (stdout, "  -v, --verbose\n\\r
+            Print informational statements\n");\r
+  fprintf (stdout, "  -q, --quiet\n\\r
+            Returns the exit code, error messages will be displayed\n");\r
+  fprintf (stdout, "  -s, --silent\n\\r
+            Returns only the exit code; informational and error\n\\r
+            messages are not displayed\n");\r
+  fprintf (stdout, "  -x XREF_FILENAME, --xref XREF_FILENAME\n\\r
+            Parse the basename to file-guid cross reference file(s)\n");\r
+  fprintf (stdout, "  -f OFFSET, --offset OFFSET\n\\r
+            The offset from the start of the input file to start \n\\r
+            processing an FV\n");\r
+  fprintf (stdout, "  --sfo\n\\r
+            Reserved for future use\n");\r
 }\r
 \r