Calculate FFS file checksum only by FFS data, not the entire FFS file according to...
authorlgao4 <lgao4@7335b38e-4728-0410-8992-fb3ffe349368>
Tue, 27 Oct 2009 08:10:53 +0000 (08:10 +0000)
committerlgao4 <lgao4@7335b38e-4728-0410-8992-fb3ffe349368>
Tue, 27 Oct 2009 08:10:53 +0000 (08:10 +0000)
git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@1728 7335b38e-4728-0410-8992-fb3ffe349368

Source/C/Common/FirmwareVolumeBuffer.c
Source/C/Common/FvLib.c
Source/C/GenFv/GenFvInternalLib.c
Source/C/GenVtf/GenVtf.c
Source/C/VolInfo/VolInfo.c

index d51e359..2d3b135 100644 (file)
@@ -236,8 +236,8 @@ Returns:
 \r
   if (File->Attributes & FFS_ATTRIB_CHECKSUM) {\r
     File->IntegrityCheck.Checksum.File = FvBufCalculateChecksum8 (\r
-                                                (VOID*)File,\r
-                                                FileSize\r
+                                                (VOID*)(File + 1),\r
+                                                FileSize - sizeof (EFI_FFS_FILE_HEADER)\r
                                                 );\r
   } else {\r
     File->IntegrityCheck.Checksum.File = FFS_FIXED_CHECKSUM;\r
index 292b077..5045592 100644 (file)
@@ -703,7 +703,7 @@ Returns:
     // Verify file data checksum\r
     //\r
     FileLength          = GetLength (FfsHeader->Size);\r
-    Checksum            = CalculateSum8 ((UINT8 *) FfsHeader, FileLength);\r
+    Checksum            = CalculateSum8 ((UINT8 *) (FfsHeader + 1), FileLength - sizeof (EFI_FFS_FILE_HEADER));\r
     Checksum            = (UINT8) (Checksum - FfsHeader->State);\r
     if (Checksum != 0) {\r
       Error (NULL, 0, 0006, "invalid FFS file checksum", "Ffs file with Guid %s", FileGuidString);\r
@@ -712,7 +712,7 @@ Returns:
   } else {\r
     //\r
     // File does not have a checksum\r
-    // Verify contents are 0x5A as spec'd\r
+    // Verify contents are 0xAA as spec'd\r
     //\r
     if (FfsHeader->IntegrityCheck.Checksum.File != FFS_FIXED_CHECKSUM) {\r
       Error (NULL, 0, 0006, "invalid fixed FFS file header checksum", "Ffs file with Guid %s", FileGuidString);\r
index 4564f04..6b5d6bd 100644 (file)
@@ -1559,8 +1559,8 @@ Returns:
   VtfFile->State                        = 0;\r
   if (VtfFile->Attributes & FFS_ATTRIB_CHECKSUM) {\r
     VtfFile->IntegrityCheck.Checksum.File = CalculateChecksum8 (\r
-                                              (UINT8 *) VtfFile,\r
-                                              GetLength (VtfFile->Size)\r
+                                              (UINT8 *) (VtfFile + 1),\r
+                                              GetLength (VtfFile->Size) - sizeof (EFI_FFS_FILE_HEADER)\r
                                               );\r
   } else {\r
     VtfFile->IntegrityCheck.Checksum.File = FFS_FIXED_CHECKSUM;\r
@@ -2046,6 +2046,7 @@ Returns:
     //\r
     FvExtHeader = malloc(FileSize);\r
     if (FvExtHeader == NULL) {\r
+      fclose (FvExtHeaderFile);\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
 \r
@@ -2503,7 +2504,7 @@ Returns:
     fclose (fpin);\r
     CurrentOffset += sizeof (EFI_FFS_FILE_HEADER) + FvExtendHeaderSize;\r
     CurrentOffset = (CurrentOffset + 7) & (~7);\r
-  } else if (mFvDataInfo.FvNameGuidSet && (CompareGuid (&mFvDataInfo.FvNameGuid, &mZeroGuid) != 0)) {\r
+  } else if (mFvDataInfo.FvNameGuidSet) {\r
     CurrentOffset += sizeof (EFI_FFS_FILE_HEADER) + sizeof (EFI_FIRMWARE_VOLUME_EXT_HEADER);\r
     CurrentOffset = (CurrentOffset + 7) & (~7);\r
   }\r
@@ -3044,15 +3045,10 @@ Returns:
       SavedState  = FfsFile->State;\r
       FfsFile->IntegrityCheck.Checksum.File = 0;\r
       FfsFile->State                        = 0;\r
-      if (FfsFile->Attributes & FFS_ATTRIB_CHECKSUM) {\r
-        FfsFile->IntegrityCheck.Checksum.File = CalculateChecksum8 (\r
-                                                  (UINT8 *) FfsFile,\r
-                                                  GetLength (FfsFile->Size)\r
-                                                  );\r
-      } else {\r
-        FfsFile->IntegrityCheck.Checksum.File = FFS_FIXED_CHECKSUM;\r
-      }\r
-\r
+      FfsFile->IntegrityCheck.Checksum.File = CalculateChecksum8 (\r
+                                                (UINT8 *) (FfsFile + 1),\r
+                                                GetLength (FfsFile->Size) - sizeof (EFI_FFS_FILE_HEADER)\r
+                                                );\r
       FfsFile->State = SavedState;\r
     }\r
 \r
@@ -3274,15 +3270,10 @@ WritePeMap:
       SavedState  = FfsFile->State;\r
       FfsFile->IntegrityCheck.Checksum.File = 0;\r
       FfsFile->State                        = 0;\r
-      if (FfsFile->Attributes & FFS_ATTRIB_CHECKSUM) {\r
-        FfsFile->IntegrityCheck.Checksum.File = CalculateChecksum8 (\r
-                                                  (UINT8 *) FfsFile,\r
-                                                  GetLength (FfsFile->Size)\r
-                                                  );\r
-      } else {\r
-        FfsFile->IntegrityCheck.Checksum.File = FFS_FIXED_CHECKSUM;\r
-      }\r
-\r
+      FfsFile->IntegrityCheck.Checksum.File = CalculateChecksum8 (\r
+                                                (UINT8 *)(FfsFile + 1),\r
+                                                GetLength (FfsFile->Size) - sizeof (EFI_FFS_FILE_HEADER)\r
+                                                );\r
       FfsFile->State = SavedState;\r
     }\r
     //\r
index 5308485..890cfd9 100644 (file)
@@ -1688,7 +1688,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
index b7237b0..0b51063 100644 (file)
@@ -1055,7 +1055,7 @@ Returns:
       //
       // Calculate file checksum
       //
-      Checksum  = CalculateSum8 ((UINT8 *) FileHeader, FileLength);
+      Checksum  = CalculateSum8 ((UINT8 *) (FileHeader + 1), FileLength - sizeof (EFI_FFS_FILE_HEADER));
       Checksum  = (UINT8) (Checksum - FileHeader->State);
       if (Checksum != 0) {
         Error (NULL, 0, 0003, "error parsing FFS file", "FFS file with Guid %s has invalid file checksum", GuidBuffer);
@@ -1063,7 +1063,7 @@ Returns:
       }
     } else {
       if (FileHeader->IntegrityCheck.Checksum.File != FFS_FIXED_CHECKSUM) {
-        Error (NULL, 0, 0003, "error parsing FFS file", "FFS file with Guid %s has invalid header checksum -- not set to fixed value of 0x5A", GuidBuffer);
+        Error (NULL, 0, 0003, "error parsing FFS file", "FFS file with Guid %s has invalid header checksum -- not set to fixed value of 0xAA", GuidBuffer);
         return EFI_ABORTED;
       }
     }