]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/C/GenVtf/GenVtf.c
There is a limitation on WINDOWS OS for the length of entire file path can’t be large...
[mirror_edk2.git] / BaseTools / Source / C / GenVtf / GenVtf.c
index 35120f36c1a202c3b2bd6b81361e69373b18be4a..60df34906eb804cab97ff26cddf6289787a92371 100644 (file)
@@ -1,6 +1,6 @@
 /**\r
 \r
-Copyright (c) 1999 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 1999 - 2014, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials are licensed and made available \r
 under the terms and conditions of the BSD License which accompanies this \r
 distribution.  The full text of the license may be found at\r
@@ -105,44 +105,51 @@ ConvertVersionInfo (
 /*++\r
 Routine Description:\r
 \r
-  This function converts GUID string to GUID\r
+  This function split version to major version and minor version\r
 \r
 Arguments:\r
 \r
   Str      - String representing in form XX.XX\r
-  MajorVer - The major vertion\r
-  MinorVer - The minor vertion\r
+  MajorVer - The major version\r
+  MinorVer - The minor version\r
 \r
 Returns:\r
 \r
-  EFI_SUCCESS  - The fuction completed successfully.\r
+  EFI_SUCCESS  - The function completed successfully.\r
 \r
 --*/\r
 {\r
-  CHAR8  StrPtr[40];\r
-  CHAR8  *Token;\r
-  UINTN  Length;\r
+  CHAR8  TemStr[5] = "0000";\r
   unsigned Major;\r
   unsigned Minor;\r
+  UINTN Length;\r
 \r
   Major = 0;\r
   Minor = 0;\r
-  memset (StrPtr, 0, 40);\r
-  Token = strtok (Str, ".");\r
 \r
-  while (Token != NULL) {\r
-    strcat (StrPtr, Token);\r
-    Token = strtok (NULL, ".");\r
+  if (strstr (Str, ".") != NULL) {\r
+    sscanf (\r
+      Str,\r
+      "%02x.%02x",\r
+      &Major,\r
+      &Minor\r
+      );\r
+  } else {\r
+    Length = strlen(Str);\r
+    if (Length < 4) {\r
+      strncpy (TemStr + 4 - Length, Str, Length);\r
+    } else {\r
+      strncpy (TemStr, Str + Length - 4, 4);\r
+    }\r
+  \r
+    sscanf (\r
+      TemStr,\r
+      "%02x%02x",\r
+      &Major,\r
+      &Minor\r
+      );\r
   }\r
 \r
-  Length = strlen (StrPtr);\r
-  sscanf (\r
-    StrPtr,\r
-    "%01x%02x",\r
-    &Major,\r
-    &Minor\r
-    );\r
-\r
   *MajorVer = (UINT8) Major;\r
   *MinorVer = (UINT8) Minor;\r
   return EFI_SUCCESS;\r
@@ -1063,7 +1070,7 @@ Returns:
   CHAR8   Buff5[10];\r
   CHAR8   Token[50];\r
 \r
-  Fp = fopen (VtfInfo->CompSymName, "rb");\r
+  Fp = fopen (LongFilePath (VtfInfo->CompSymName), "rb");\r
 \r
   if (Fp == NULL) {\r
     Error (NULL, 0, 0001, "Error opening file", VtfInfo->CompSymName);\r
@@ -1134,7 +1141,6 @@ Returns:
   EFI_STATUS  Status;\r
   UINT64      CompStartAddress;\r
   UINT64      FileSize;\r
-  UINT64      NumByteRead;\r
   UINT64      NumAdjustByte;\r
   UINT8       *Buffer;\r
   FILE        *Fp;\r
@@ -1146,7 +1152,7 @@ Returns:
     return EFI_SUCCESS;\r
   }\r
 \r
-  Fp = fopen (VtfInfo->CompBinName, "rb");\r
+  Fp = fopen (LongFilePath (VtfInfo->CompBinName), "rb");\r
 \r
   if (Fp == NULL) {\r
     Error (NULL, 0, 0001, "Error opening file", VtfInfo->CompBinName);\r
@@ -1182,7 +1188,7 @@ Returns:
     //\r
     // Read first 64 bytes of PAL header and use it to find version info\r
     //\r
-    NumByteRead = fread (Buffer, sizeof (UINT8), SIZE_OF_PAL_HEADER, Fp);\r
+    fread (Buffer, sizeof (UINT8), SIZE_OF_PAL_HEADER, Fp);\r
 \r
     //\r
     // PAL header contains the version info. Currently, we will use the header\r
@@ -1193,7 +1199,7 @@ Returns:
     }\r
   }\r
 \r
-  NumByteRead = fread (Buffer, sizeof (UINT8), (UINTN) FileSize, Fp);\r
+  fread (Buffer, sizeof (UINT8), (UINTN) FileSize, Fp);\r
   fclose (Fp);\r
 \r
   //\r
@@ -1322,12 +1328,11 @@ Returns:
   UINT64      AbsAddress;\r
   UINTN       RelativeAddress;\r
   UINT64      FileSize;\r
-  UINT64      NumByteRead;\r
   UINT8       *Buffer;\r
   FILE        *Fp;\r
   FIT_TABLE   *PalFitPtr;\r
 \r
-  Fp = fopen (VtfInfo->CompBinName, "rb");\r
+  Fp = fopen (LongFilePath (VtfInfo->CompBinName), "rb");\r
 \r
   if (Fp == NULL) {\r
     Error (NULL, 0, 0001, "Error opening file", VtfInfo->CompBinName);\r
@@ -1360,7 +1365,7 @@ Returns:
   //\r
   // Read, Get version Info and discard the PAL header.\r
   //\r
-  NumByteRead = fread (Buffer, sizeof (UINT8), SIZE_OF_PAL_HEADER, Fp);\r
+  fread (Buffer, sizeof (UINT8), SIZE_OF_PAL_HEADER, Fp);\r
 \r
   //\r
   // Extract the version info from header of PAL_A. Once done, discrad this buffer\r
@@ -1372,7 +1377,7 @@ Returns:
   //\r
   // Read PAL_A file in a buffer\r
   //\r
-  NumByteRead = fread (Buffer, sizeof (UINT8), (UINTN) FileSize, Fp);\r
+  fread (Buffer, sizeof (UINT8), (UINTN) FileSize, Fp);\r
   fclose (Fp);\r
 \r
   PalStartAddress       = Fv1EndAddress - (SIZE_TO_OFFSET_PAL_A_END + FileSize);\r
@@ -1546,7 +1551,7 @@ Returns:
     VtfBuffer = (VOID *) RelativeAddress;\r
   }\r
 \r
-  Fp = fopen (FileName, "wb");\r
+  Fp = fopen (LongFilePath (FileName), "wb");\r
   if (Fp == NULL) {\r
     Error (NULL, 0, 0001, "Error opening file", FileName);\r
     return EFI_ABORTED;\r
@@ -1752,14 +1757,13 @@ Returns:
   UINT8 *Buffer;\r
   UINT8 *LocalVtfBuffer;\r
   UINTN FileSize;\r
-  UINTN NumByteRead;\r
   FILE  *Fp;\r
 \r
   if (!strcmp (FileName, "")) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  Fp = fopen (FileName, "rb");\r
+  Fp = fopen (LongFilePath (FileName), "rb");\r
 \r
   if (Fp == NULL) {\r
     Error (NULL, 0, 0001, "Error opening file", FileName);\r
@@ -1777,7 +1781,7 @@ Returns:
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
-  NumByteRead     = fread (Buffer, sizeof (UINT8), FileSize, Fp);\r
+  fread (Buffer, sizeof (UINT8), FileSize, Fp);\r
 \r
   LocalVtfBuffer  = (UINT8 *) Vtf1EndBuffer - SIZE_IA32_RESET_VECT;\r
   memcpy (LocalVtfBuffer, Buffer, FileSize);\r
@@ -2114,7 +2118,6 @@ Returns:
   FILE        *Fp;\r
   UINT64      *StartAddressPtr;\r
   UINTN       FirstFwVSize;\r
-  UINTN       NumByte;\r
 \r
   StartAddressPtr   = malloc (sizeof (UINT64));\r
   if (StartAddressPtr == NULL) {\r
@@ -2122,7 +2125,7 @@ Returns:
   }\r
   *StartAddressPtr = StartAddress;\r
 \r
-  Fp = fopen (OutFileName1, "rb");\r
+  Fp = fopen (LongFilePath (OutFileName1), "rb");\r
 \r
   if (Fp == NULL) {\r
     Error (NULL, 0, 0001, "Error opening file", OutFileName1);\r
@@ -2134,7 +2137,7 @@ Returns:
 \r
   FirstFwVSize = _filelength (fileno (Fp));\r
   fseek (Fp, (long) (FirstFwVSize - (UINTN) (SIZE_IA32_RESET_VECT + SIZE_SALE_ENTRY_POINT)), SEEK_SET);\r
-  NumByte = fwrite ((VOID *) StartAddressPtr, sizeof (UINT64), 1, Fp);\r
+  fwrite ((VOID *) StartAddressPtr, sizeof (UINT64), 1, Fp);\r
 \r
   if (Fp) {\r
     fclose (Fp);\r
@@ -2180,12 +2183,12 @@ Returns:
 {\r
   FILE    *SourceFile;\r
   FILE    *DestFile;\r
-  CHAR8   Buffer[_MAX_PATH];\r
-  CHAR8   Type[_MAX_PATH];\r
-  CHAR8   Address[_MAX_PATH];\r
-  CHAR8   Section[_MAX_PATH];\r
-  CHAR8   Token[_MAX_PATH];\r
-  CHAR8   BaseToken[_MAX_PATH];\r
+  CHAR8   Buffer[MAX_LONG_FILE_PATH];\r
+  CHAR8   Type[MAX_LONG_FILE_PATH];\r
+  CHAR8   Address[MAX_LONG_FILE_PATH];\r
+  CHAR8   Section[MAX_LONG_FILE_PATH];\r
+  CHAR8   Token[MAX_LONG_FILE_PATH];\r
+  CHAR8   BaseToken[MAX_LONG_FILE_PATH];\r
   UINT64  TokenAddress;\r
   long    StartLocation;\r
 \r
@@ -2199,7 +2202,7 @@ Returns:
   //\r
   // Open the source file\r
   //\r
-  SourceFile = fopen (SourceFileName, "r");\r
+  SourceFile = fopen (LongFilePath (SourceFileName), "r");\r
   if (SourceFile == NULL) {\r
 \r
     //\r
@@ -2218,7 +2221,7 @@ Returns:
   //\r
   // Open the destination file\r
   //\r
-  DestFile = fopen (DestFileName, "a+");\r
+  DestFile = fopen (LongFilePath (DestFileName), "a+");\r
   if (DestFile == NULL) {\r
     fclose (SourceFile);\r
     Error (NULL, 0, 0001, "Error opening file", DestFileName);\r
@@ -2249,7 +2252,7 @@ Returns:
   //\r
   // Read the first line\r
   //\r
-  if (fgets (Buffer, _MAX_PATH, SourceFile) == NULL) {\r
+  if (fgets (Buffer, MAX_LONG_FILE_PATH, SourceFile) == NULL) {\r
     Buffer[0] = 0;\r
   }\r
 \r
@@ -2376,7 +2379,7 @@ Returns:
 \r
 --*/\r
 {\r
-  fprintf (stdout, "%s Version %d.%d\n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION);\r
+  fprintf (stdout, "%s Version %d.%d %s \n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION, __BUILD_VERSION);\r
 }\r
 \r
 VOID\r
@@ -2407,7 +2410,7 @@ Returns:
   //\r
   // Copyright declaration\r
   //\r
-  fprintf (stdout, "Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.\n\n");\r
+  fprintf (stdout, "Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.\n\n");\r
   //\r
   // Details Option\r
   //\r
@@ -2543,7 +2546,7 @@ Returns:
       // Get the input VTF file name\r
       //\r
       VtfFileName = argv[Index+1];\r
-      VtfFP = fopen(VtfFileName, "rb");\r
+      VtfFP = fopen (LongFilePath (VtfFileName), "rb");\r
       if (VtfFP == NULL) {\r
         Error (NULL, 0, 0001, "Error opening file", VtfFileName);\r
         goto ERROR;\r