]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/CCode/Source/GenFvImage/GenFvImageLib.c
Update ParseInf to resolve different line separator between WINDOWS and LINUX (\r...
[mirror_edk2.git] / Tools / CCode / Source / GenFvImage / GenFvImageLib.c
index 888656ad5c9f586aa814dfac6b17d7542b41c77a..06500ef3736d87160df4b1de8e9bac8da6f71e2f 100644 (file)
@@ -48,7 +48,18 @@ Abstract:
 #include "EfiCompress.h"\r
 #include "WinNtInclude.h"\r
 \r
+//\r
+// Different file separater for Linux and Windows\r
+//\r
+#ifdef __GNUC__\r
+#define FILE_SEP_CHAR '/'\r
+#define FILE_SEP_STRING "/"\r
+#else\r
+#define FILE_SEP_CHAR '\\'\r
+#define FILE_SEP_STRING "\\"\r
+#endif\r
 \r
+static UINT32 MaxFfsAlignment = 0;\r
 //\r
 // Local function prototypes\r
 //\r
@@ -1031,9 +1042,9 @@ Returns:
 \r
   case 0:\r
     //\r
-    // 1 byte alignment\r
+    // 8 byte alignment, mini alignment requirement for FFS file. \r
     //\r
-    *Alignment = (1 << 0);\r
+    *Alignment = (1 << 3);\r
     break;\r
 \r
   case 1:\r
@@ -1374,7 +1385,7 @@ Returns:
   // Copy the file name for the path of the sym file and truncate the name portion.\r
   //\r
   strcpy (SymFileName, Buffer);\r
-  Ptr = strrchr (SymFileName, '\\');\r
+  Ptr = strrchr (SymFileName, FILE_SEP_CHAR);\r
   assert (Ptr);\r
   Ptr[0] = 0;\r
 \r
@@ -1411,7 +1422,7 @@ Returns:
     // Add the symbol file name and extension to the file path.\r
     //\r
     strcat (Buffer, ".sym");\r
-    strcat (SymFileName, "\\");\r
+    strcat (SymFileName, FILE_SEP_CHAR);\r
     strcat (SymFileName, Buffer);\r
   } else {\r
     //\r
@@ -1617,15 +1628,7 @@ Returns:
   //\r
   // Get the file size\r
   //\r
-#ifdef __GNUC__\r
-  {\r
-    struct stat stat_buf;\r
-    fstat(fileno(NewFile), &stat_buf);\r
-    FileSize = stat_buf.st_size;\r
-  }\r
-#else\r
   FileSize = _filelength (fileno (NewFile));\r
-#endif\r
 \r
   //\r
   // Read the file into a buffer\r
@@ -1749,6 +1752,13 @@ Returns:
     free (FileBuffer);\r
     return EFI_ABORTED;\r
   }\r
+  \r
+  //\r
+  // Find the largest alignment of all the FFS files in the FV\r
+  //\r
+  if (CurrentFileAlignment > MaxFfsAlignment) {\r
+    MaxFfsAlignment = CurrentFileAlignment;\r
+  }\r
   //\r
   // Add pad file if necessary\r
   //\r
@@ -2652,6 +2662,31 @@ Returns:
   // Determine final Sym file size\r
   //\r
   *SymImageSize = SymImageMemoryFile.CurrentFilePointer - SymImageMemoryFile.FileImage;\r
+  \r
+  //\r
+  // Update FV Alignment attribute to the largest alignment of all the FFS files in the FV\r
+  //\r
+  if (FvHeader->Attributes | EFI_FVB_ALIGNMENT_CAP) {\r
+    for (Index = 1; Index <= 16; Index ++) {\r
+      if ((1 << Index) < MaxFfsAlignment) {\r
+        //\r
+        // Unset the unsupported alignment attribute.\r
+        //\r
+        FvHeader->Attributes = FvHeader->Attributes & ~((1 << Index) * EFI_FVB_ALIGNMENT_CAP);\r
+      } else {\r
+        //\r
+        // Set the supported alignment attribute.\r
+        //\r
+        FvHeader->Attributes = FvHeader->Attributes | ((1 << Index) * EFI_FVB_ALIGNMENT_CAP);\r
+      }\r
+    }\r
+    \r
+    //\r
+    // Update Checksum for FvHeader\r
+    //\r
+    FvHeader->Checksum      = 0;\r
+    FvHeader->Checksum      = CalculateChecksum16 ((UINT16 *) FvHeader, FvHeader->HeaderLength / sizeof (UINT16));\r
+  }\r
 \r
   return EFI_SUCCESS;\r
 }\r