#include "EfiCompress.h"\r
#include "WinNtInclude.h"\r
\r
-\r
+static UINT32 MaxFfsAlignment = 0;\r
//\r
// Local function prototypes\r
//\r
\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
//\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
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
// 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