]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/C/GenVtf/GenVtf.c
Sync EDKII BaseTools to BaseTools project r1971
[mirror_edk2.git] / BaseTools / Source / C / GenVtf / GenVtf.c
index e633b7ccf83a0d61d6d5fee4525c6b95ec9b0a95..35120f36c1a202c3b2bd6b81361e69373b18be4a 100644 (file)
@@ -1,13 +1,13 @@
 /**\r
 \r
-Copyright (c)  1999 - 2008, Intel Corporation. All rights reserved\r
-This software and associated documentation (if any) is furnished\r
-under a license and may only be used or copied in accordance\r
-with the terms of the license. Except as permitted by such\r
-license, no part of this software or documentation may be\r
-reproduced, stored in a retrieval system, or transmitted in any\r
-form or by any means without the express written consent of\r
-Intel Corporation.\r
+Copyright (c) 1999 - 2010, 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
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
 \r
 Module Name:\r
@@ -122,8 +122,8 @@ Returns:
   CHAR8  StrPtr[40];\r
   CHAR8  *Token;\r
   UINTN  Length;\r
-  UINT32 Major;\r
-  UINT32 Minor;\r
+  unsigned Major;\r
+  unsigned Minor;\r
 \r
   Major = 0;\r
   Minor = 0;\r
@@ -278,7 +278,7 @@ InitializeComps (
 \r
 Routine Description:\r
 \r
-  This function intializes the relevant global variable which is being\r
+  This function initializes the relevant global variable which is being\r
   used to store the information retrieved from INF file.  This also initializes\r
   the VTF symbol file.\r
 \r
@@ -316,7 +316,7 @@ ParseAndUpdateComponents (
 \r
 Routine Description:\r
 \r
-  This function intializes the relevant global variable which is being\r
+  This function initializes the relevant global variable which is being\r
   used to store the information retrieved from INF file.\r
 \r
 Arguments:\r
@@ -342,12 +342,11 @@ Returns:
         VtfInfo->LocationType = SECOND_VTF;\r
       } else {\r
         VtfInfo->LocationType = NONE;\r
-        Warning(UTILITY_NAME, 0, 0001, "Unknown location for component.", VtfInfo->CompName);\r
       }\r
     } else if (strnicmp (*TokenStr, "COMP_TYPE", 9) == 0) {\r
       TokenStr++;\r
       if (AsciiStringToUint64 (*TokenStr, FALSE, &StringValue) != EFI_SUCCESS) {\r
-        Error (NULL, 0, 5001, "Cannot get: \"0x%x\".", *TokenStr);\r
+        Error (NULL, 0, 5001, "Cannot get: \"0x%s\".", *TokenStr);\r
         return ;\r
       }\r
 \r
@@ -1267,7 +1266,7 @@ Returns:
   //\r
   // Update the SYM file for this component based on it's start address.\r
   //\r
-  Status = UpdateSymFile (CompStartAddress, SymFileName, VtfInfo->CompSymName);\r
+  Status = UpdateSymFile (CompStartAddress, SymFileName, VtfInfo->CompSymName, FileSize);\r
   if (EFI_ERROR (Status)) {\r
 \r
     //\r
@@ -1406,7 +1405,7 @@ Returns:
   //\r
   // Update the SYM file for this component based on it's start address.\r
   //\r
-  Status = UpdateSymFile (PalStartAddress, SymFileName, VtfInfo->CompSymName);\r
+  Status = UpdateSymFile (PalStartAddress, SymFileName, VtfInfo->CompSymName, FileSize);\r
   if (EFI_ERROR (Status)) {\r
 \r
     //\r
@@ -1688,7 +1687,7 @@ Returns:
   FileHeader->IntegrityCheck.Checksum.File    = 0;\r
   FileHeader->State                           = 0;\r
   FileHeader->IntegrityCheck.Checksum.Header  = CalculateChecksum8 ((UINT8 *) FileHeader, sizeof (EFI_FFS_FILE_HEADER));\r
-  FileHeader->IntegrityCheck.Checksum.File    = CalculateChecksum8 ((UINT8 *) FileHeader, TotalVtfSize);\r
+  FileHeader->IntegrityCheck.Checksum.File    = CalculateChecksum8 ((UINT8 *) (FileHeader + 1), TotalVtfSize - sizeof (EFI_FFS_FILE_HEADER));\r
   FileHeader->State                           = EFI_FILE_HEADER_CONSTRUCTION | EFI_FILE_HEADER_VALID | EFI_FILE_DATA_VALID;\r
 \r
   return EFI_SUCCESS;\r
@@ -1970,7 +1969,7 @@ Returns:
 \r
   Fv1BaseAddress        = StartAddress1;\r
   Fv1EndAddress         = Fv1BaseAddress + Size1;\r
-  if (Fv1EndAddress != 0x100000000 || Size1 < 0x100000) {\r
+  if (Fv1EndAddress != 0x100000000ULL || Size1 < 0x100000) {\r
     Error (NULL, 0, 2000, "Invalid parameter", "Error BaseAddress and Size parameters!");\r
     if (Size1 < 0x100000) {\r
       Error (NULL, 0, 2000, "Invalid parameter", "The FwVolumeSize must be larger than 1M!");\r
@@ -2153,7 +2152,9 @@ EFI_STATUS
 UpdateSymFile (\r
   IN UINT64 BaseAddress,\r
   IN CHAR8  *DestFileName,\r
-  IN CHAR8  *SourceFileName\r
+  IN CHAR8  *SourceFileName,\r
+  IN UINT64 FileSize\r
+\r
   )\r
 /*++\r
 \r
@@ -2167,6 +2168,7 @@ Arguments:
   BaseAddress    - The base address for the new SYM tokens.\r
   DestFileName   - The destination file.\r
   SourceFileName - The source file.\r
+  FileSize       - Size of bin file.\r
 \r
 Returns:\r
 \r
@@ -2185,7 +2187,7 @@ Returns:
   CHAR8   Token[_MAX_PATH];\r
   CHAR8   BaseToken[_MAX_PATH];\r
   UINT64  TokenAddress;\r
-  long      StartLocation;\r
+  long    StartLocation;\r
 \r
   //\r
   // Verify input parameters.\r
@@ -2275,17 +2277,20 @@ Returns:
       // Get the token address\r
       //\r
       AsciiStringToUint64 (Address, TRUE, &TokenAddress);\r
+      if (TokenAddress > FileSize) {\r
+        //\r
+        // Symbol offset larger than FileSize. This Symbol can't be in Bin file. Don't print them.\r
+        //\r
+        break;\r
+      }\r
 \r
       //\r
       // Add the base address, the size of the FFS file header and the size of the peim header.\r
       //\r
       TokenAddress += BaseAddress &~IPF_CACHE_BIT;\r
 \r
-#ifdef __GNUC__\r
-      fprintf (DestFile, "%s | %016lX | %s | %s%s\n", Type, TokenAddress, Section, BaseToken, Token);\r
-#else\r
-       fprintf (DestFile, "%s | %016I64X | %s | %s%s\n", Type, TokenAddress, Section, BaseToken, Token);\r
-#endif\r
+      fprintf (DestFile, "%s | %016llX | ", Type, (unsigned long long) TokenAddress);\r
+      fprintf (DestFile, "%s | %s\n    %s\n", Section, Token, BaseToken); \r
     }\r
   }\r
 \r
@@ -2402,7 +2407,7 @@ Returns:
   //\r
   // Copyright declaration\r
   //\r
-  fprintf (stdout, "Copyright (c) 2007 - 2009, Intel Corporation. All rights reserved.\n\n");\r
+  fprintf (stdout, "Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.\n\n");\r
   //\r
   // Details Option\r
   //\r
@@ -2689,7 +2694,7 @@ Returns:
       break;\r
 \r
     case EFI_ABORTED:\r
-      Error (NULL, 0, 3000, "Invaild", "Error detected while creating the file image.");\r
+      Error (NULL, 0, 3000, "Invalid", "Error detected while creating the file image.");\r
       break;\r
 \r
     case EFI_OUT_OF_RESOURCES:\r
@@ -2697,11 +2702,11 @@ Returns:
       break;\r
 \r
     case EFI_VOLUME_CORRUPTED:\r
-      Error (NULL, 0, 3000, "Invaild", "No base address was specified.");\r
+      Error (NULL, 0, 3000, "Invalid", "No base address was specified.");\r
       break;\r
 \r
     default:\r
-      Error (NULL, 0, 3000, "Invaild", "GenVtfImage function returned unknown status %x.",Status );\r
+      Error (NULL, 0, 3000, "Invalid", "GenVtfImage function returned unknown status %x.", (int) Status );\r
       break;\r
     }\r
   }\r