]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/C/VolInfo/VolInfo.c
BaseTool: Fixed the incorrect cache key.
[mirror_edk2.git] / BaseTools / Source / C / VolInfo / VolInfo.c
index 5285acdb97f9ebe4cbfd1ed06fc13a5da983225e..bf00af05669cf2bfef5cc2ddda5e46507778a819 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 The tool dumps the contents of a firmware volume\r
 \r
-Copyright (c) 1999 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 1999 - 2018, 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
@@ -148,6 +148,65 @@ Usage (
   VOID\r
   );\r
 \r
+UINT32\r
+UnicodeStrLen (\r
+  IN CHAR16 *String\r
+  )\r
+  /*++\r
+\r
+  Routine Description:\r
+\r
+  Returns the length of a null-terminated unicode string.\r
+\r
+  Arguments:\r
+\r
+    String - The pointer to a null-terminated unicode string.\r
+\r
+  Returns:\r
+\r
+    N/A\r
+\r
+  --*/\r
+{\r
+  UINT32  Length;\r
+\r
+  for (Length = 0; *String != L'\0'; String++, Length++) {\r
+    ;\r
+  }\r
+  return Length;\r
+}\r
+\r
+VOID\r
+Unicode2AsciiString (\r
+  IN  CHAR16 *Source,\r
+  OUT CHAR8  *Destination\r
+  )\r
+  /*++\r
+\r
+  Routine Description:\r
+\r
+  Convert a null-terminated unicode string to a null-terminated ascii string.\r
+\r
+  Arguments:\r
+\r
+    Source      - The pointer to the null-terminated input unicode string.\r
+    Destination - The pointer to the null-terminated output ascii string.\r
+\r
+  Returns:\r
+\r
+    N/A\r
+\r
+  --*/\r
+{\r
+  while (*Source != '\0') {\r
+    *(Destination++) = (CHAR8) *(Source++);\r
+  }\r
+  //\r
+  // End the ascii with a NULL.\r
+  //\r
+  *Destination = '\0';\r
+}\r
+\r
 int\r
 main (\r
   int       argc,\r
@@ -272,7 +331,10 @@ Returns:
       if (OpenSslEnv == NULL) {\r
         OpenSslPath = OpenSslCommand;\r
       } else {\r
-        OpenSslPath = malloc(strlen(OpenSslEnv)+strlen(OpenSslCommand)+1);\r
+        //\r
+        // We add quotes to the Openssl Path in case it has space characters\r
+        //\r
+        OpenSslPath = malloc(2+strlen(OpenSslEnv)+strlen(OpenSslCommand)+1);\r
         if (OpenSslPath == NULL) {\r
           Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");\r
           return GetUtilityStatus ();\r
@@ -479,16 +541,16 @@ GetOccupiedSize (
 \r
 Routine Description:\r
 \r
-  This function returns the next larger size that meets the alignment \r
+  This function returns the next larger size that meets the alignment\r
   requirement specified.\r
 \r
 Arguments:\r
 \r
   ActualSize      The size.\r
   Alignment       The desired alignment.\r
-    \r
+\r
 Returns:\r
\r
+\r
   EFI_SUCCESS             Function completed successfully.\r
   EFI_ABORTED             The function encountered an error.\r
 \r
@@ -538,7 +600,7 @@ Returns:
     //\r
     // 0x02\r
     //\r
-    "EFI_SECTION_GUID_DEFINED",    \r
+    "EFI_SECTION_GUID_DEFINED",\r
     //\r
     // 0x03\r
     //\r
@@ -602,11 +664,11 @@ Returns:
     //\r
     // 0x12\r
     //\r
-    "EFI_SECTION_TE",    \r
+    "EFI_SECTION_TE",\r
     //\r
     // 0x13\r
     //\r
-    "EFI_SECTION_DXE_DEPEX", \r
+    "EFI_SECTION_DXE_DEPEX",\r
     //\r
     // 0x14\r
     //\r
@@ -673,7 +735,7 @@ ReadHeader (
 \r
 Routine Description:\r
 \r
-  This function determines the size of the FV and the erase polarity.  The \r
+  This function determines the size of the FV and the erase polarity.  The\r
   erase polarity is the FALSE value for file state.\r
 \r
 Arguments:\r
@@ -681,9 +743,9 @@ Arguments:
   InputFile       The file that contains the FV image.\r
   FvSize          The size of the FV.\r
   ErasePolarity   The FV erase polarity.\r
-    \r
+\r
 Returns:\r
\r
+\r
   EFI_SUCCESS             Function completed successfully.\r
   EFI_INVALID_PARAMETER   A required parameter was NULL or is out of range.\r
   EFI_ABORTED             The function encountered an error.\r
@@ -832,7 +894,7 @@ Returns:
   if (VolumeHeader.Attributes & EFI_FVB2_ALIGNMENT_64K) {\r
     printf ("        EFI_FVB2_ALIGNMENT_64K\n");\r
   }\r
-  \r
+\r
 #else\r
 \r
   if (VolumeHeader.Attributes & EFI_FVB2_READ_LOCK_CAP) {\r
@@ -1061,7 +1123,7 @@ Returns:
   EFI_STATUS          Status;\r
   UINT8               GuidBuffer[PRINTED_GUID_BUFFER_SIZE];\r
   UINT32              HeaderSize;\r
-#if (PI_SPECIFICATION_VERSION < 0x00010000) \r
+#if (PI_SPECIFICATION_VERSION < 0x00010000)\r
   UINT16              *Tail;\r
 #endif\r
   //\r
@@ -1163,7 +1225,7 @@ Returns:
         return EFI_ABORTED;\r
       }\r
     }\r
-#if (PI_SPECIFICATION_VERSION < 0x00010000)    \r
+#if (PI_SPECIFICATION_VERSION < 0x00010000)\r
     //\r
     // Verify tail if present\r
     //\r
@@ -1178,7 +1240,7 @@ Returns:
         return EFI_ABORTED;\r
       }\r
     }\r
- #endif   \r
+ #endif\r
     break;\r
 \r
   default:\r
@@ -1242,6 +1304,14 @@ Returns:
     printf ("EFI_FV_FILETYPE_SMM_CORE\n");\r
     break;\r
 \r
+  case EFI_FV_FILETYPE_MM_STANDALONE:\r
+    printf ("EFI_FV_FILETYPE_MM_STANDALONE\n");\r
+    break;\r
+\r
+  case EFI_FV_FILETYPE_MM_CORE_STANDALONE:\r
+    printf ("EFI_FV_FILETYPE_MM_CORE_STANDALONE\n");\r
+    break;\r
+\r
   case EFI_FV_FILETYPE_FFS_PAD:\r
     printf ("EFI_FV_FILETYPE_FFS_PAD\n");\r
     break;\r
@@ -1531,10 +1601,13 @@ CombinePath (
 )\r
 {\r
   UINT32 DefaultPathLen;\r
+  UINT64 Index;\r
+  CHAR8  QuotesStr[] = "\"";\r
+  strcpy(NewPath, QuotesStr);\r
   DefaultPathLen = strlen(DefaultPath);\r
-  strcpy(NewPath, DefaultPath);\r
-  UINT64 Index = 0;\r
-  for (; Index < DefaultPathLen; Index ++) {\r
+  strcat(NewPath, DefaultPath);\r
+  Index = 0;\r
+  for (; Index < DefaultPathLen + 1; Index ++) {\r
     if (NewPath[Index] == '\\' || NewPath[Index] == '/') {\r
       if (NewPath[Index + 1] != '\0') {\r
         NewPath[Index] = '/';\r
@@ -1546,6 +1619,7 @@ CombinePath (
     NewPath[Index + 1] = '\0';\r
   }\r
   strcat(NewPath, AppendPath);\r
+  strcat(NewPath, QuotesStr);\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -1569,7 +1643,7 @@ Returns:
 \r
   EFI_SECTION_ERROR - Problem with section parsing.\r
                       (a) compression errors\r
-                      (b) unrecognized section \r
+                      (b) unrecognized section\r
   EFI_UNSUPPORTED - Do not know how to parse the section.\r
   EFI_SUCCESS - Section successfully parsed.\r
   EFI_OUT_OF_RESOURCES - Memory allocation failed.\r
@@ -1599,7 +1673,6 @@ Returns:
   CHAR8               *ExtractionTool;\r
   CHAR8               *ToolInputFile;\r
   CHAR8               *ToolOutputFile;\r
-  CHAR8               *SystemCommandFormatString;\r
   CHAR8               *SystemCommand;\r
   EFI_GUID            *EfiGuid;\r
   UINT16              DataOffset;\r
@@ -1607,6 +1680,7 @@ Returns:
   UINT32              RealHdrLen;\r
   CHAR8               *ToolInputFileName;\r
   CHAR8               *ToolOutputFileName;\r
+  CHAR8               *UIFileName;\r
 \r
   ParsedLength = 0;\r
   ToolInputFileName = NULL;\r
@@ -1659,9 +1733,8 @@ Returns:
           SectionLength - SectionHeaderLen\r
           );\r
 \r
-        SystemCommandFormatString = "%s sha1 -out %s %s";\r
         SystemCommand = malloc (\r
-          strlen (SystemCommandFormatString) +\r
+          strlen (OPENSSL_COMMAND_FORMAT_STRING) +\r
           strlen (OpenSslPath) +\r
           strlen (ToolInputFileName) +\r
           strlen (ToolOutputFileName) +\r
@@ -1673,7 +1746,7 @@ Returns:
         }\r
         sprintf (\r
           SystemCommand,\r
-          SystemCommandFormatString,\r
+          OPENSSL_COMMAND_FORMAT_STRING,\r
           OpenSslPath,\r
           ToolOutputFileName,\r
           ToolInputFileName\r
@@ -1716,7 +1789,14 @@ Returns:
       break;\r
 \r
     case EFI_SECTION_USER_INTERFACE:\r
-      printf ("  String: %ls\n", (wchar_t *) &((EFI_USER_INTERFACE_SECTION *) Ptr)->FileNameString);\r
+      UIFileName = (CHAR8 *) malloc (UnicodeStrLen (((EFI_USER_INTERFACE_SECTION *) Ptr)->FileNameString) + 1);\r
+      if (UIFileName == NULL) {\r
+        Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");\r
+        return EFI_OUT_OF_RESOURCES;\r
+      }\r
+      Unicode2AsciiString (((EFI_USER_INTERFACE_SECTION *) Ptr)->FileNameString, UIFileName);\r
+      printf ("  String: %s\n", UIFileName);\r
+      free (UIFileName);\r
       break;\r
 \r
     case EFI_SECTION_FIRMWARE_VOLUME_IMAGE:\r
@@ -1891,9 +1971,8 @@ Returns:
         //\r
         // Construction 'system' command string\r
         //\r
-        SystemCommandFormatString = "%s -d -o %s %s";\r
         SystemCommand = malloc (\r
-          strlen (SystemCommandFormatString) +\r
+          strlen (EXTRACT_COMMAND_FORMAT_STRING) +\r
           strlen (ExtractionTool) +\r
           strlen (ToolInputFile) +\r
           strlen (ToolOutputFile) +\r
@@ -1909,7 +1988,7 @@ Returns:
         }\r
         sprintf (\r
           SystemCommand,\r
-          SystemCommandFormatString,\r
+          EXTRACT_COMMAND_FORMAT_STRING,\r
           ExtractionTool,\r
           ToolOutputFile,\r
           ToolInputFile\r
@@ -2178,8 +2257,7 @@ Returns:
 {\r
   FILE              *Fptr;\r
   CHAR8             Line[MAX_LINE_LEN];\r
-  CHAR8             *FormatString;\r
-  INTN              FormatLength;\r
+  CHAR8             FormatString[MAX_LINE_LEN];\r
   GUID_TO_BASENAME  *GPtr;\r
 \r
   if ((Fptr = fopen (LongFilePath (FileName), "r")) == NULL) {\r
@@ -2190,23 +2268,8 @@ Returns:
   //\r
   // Generate the format string for fscanf\r
   //\r
-  FormatLength = snprintf (\r
-                   NULL,\r
-                   0,\r
-                   "%%%us %%%us",\r
-                   (unsigned) sizeof (GPtr->Guid) - 1,\r
-                   (unsigned) sizeof (GPtr->BaseName) - 1\r
-                   ) + 1;\r
-\r
-  FormatString = (CHAR8 *) malloc (FormatLength);\r
-  if (FormatString == NULL) {\r
-    fclose (Fptr);\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
-\r
-  snprintf (\r
+  sprintf (\r
     FormatString,\r
-    FormatLength,\r
     "%%%us %%%us",\r
     (unsigned) sizeof (GPtr->Guid) - 1,\r
     (unsigned) sizeof (GPtr->BaseName) - 1\r
@@ -2218,7 +2281,6 @@ Returns:
     //\r
     GPtr = malloc (sizeof (GUID_TO_BASENAME));\r
     if (GPtr == NULL) {\r
-      free (FormatString);\r
       fclose (Fptr);\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
@@ -2235,7 +2297,6 @@ Returns:
     }\r
   }\r
 \r
-  free (FormatString);\r
   fclose (Fptr);\r
   return EFI_SUCCESS;\r
 }\r
@@ -2331,8 +2392,8 @@ Returns:
 \r
   //\r
   // Copyright declaration\r
-  // \r
-  fprintf (stdout, "Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.\n\n");\r
+  //\r
+  fprintf (stdout, "Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.\n\n");\r
   fprintf (stdout, "  Display Tiano Firmware Volume FFS image information\n\n");\r
 \r
   //\r