summaryrefslogtreecommitdiff
path: root/Tools/CCode
diff options
context:
space:
mode:
Diffstat (limited to 'Tools/CCode')
-rw-r--r--Tools/CCode/Source/GenFvImage/GenFvImageLib.c38
1 files changed, 35 insertions, 3 deletions
diff --git a/Tools/CCode/Source/GenFvImage/GenFvImageLib.c b/Tools/CCode/Source/GenFvImage/GenFvImageLib.c
index eb36663b8d..45d4c8e848 100644
--- a/Tools/CCode/Source/GenFvImage/GenFvImageLib.c
+++ b/Tools/CCode/Source/GenFvImage/GenFvImageLib.c
@@ -48,7 +48,7 @@ Abstract:
#include "EfiCompress.h"
#include "WinNtInclude.h"
-
+static UINT32 MaxFfsAlignment = 0;
//
// Local function prototypes
//
@@ -1031,9 +1031,9 @@ Returns:
case 0:
//
- // 1 byte alignment
+ // 8 byte alignment, mini alignment requirement for FFS file.
//
- *Alignment = (1 << 0);
+ *Alignment = (1 << 3);
break;
case 1:
@@ -1741,6 +1741,13 @@ Returns:
free (FileBuffer);
return EFI_ABORTED;
}
+
+ //
+ // Find the largest alignment of all the FFS files in the FV
+ //
+ if (CurrentFileAlignment > MaxFfsAlignment) {
+ MaxFfsAlignment = CurrentFileAlignment;
+ }
//
// Add pad file if necessary
//
@@ -2644,6 +2651,31 @@ Returns:
// Determine final Sym file size
//
*SymImageSize = SymImageMemoryFile.CurrentFilePointer - SymImageMemoryFile.FileImage;
+
+ //
+ // Update FV Alignment attribute to the largest alignment of all the FFS files in the FV
+ //
+ if (FvHeader->Attributes | EFI_FVB_ALIGNMENT_CAP) {
+ for (Index = 1; Index <= 16; Index ++) {
+ if ((1 << Index) < MaxFfsAlignment) {
+ //
+ // Unset the unsupported alignment attribute.
+ //
+ FvHeader->Attributes = FvHeader->Attributes & ~((1 << Index) * EFI_FVB_ALIGNMENT_CAP);
+ } else {
+ //
+ // Set the supported alignment attribute.
+ //
+ FvHeader->Attributes = FvHeader->Attributes | ((1 << Index) * EFI_FVB_ALIGNMENT_CAP);
+ }
+ }
+
+ //
+ // Update Checksum for FvHeader
+ //
+ FvHeader->Checksum = 0;
+ FvHeader->Checksum = CalculateChecksum16 ((UINT16 *) FvHeader, FvHeader->HeaderLength / sizeof (UINT16));
+ }
return EFI_SUCCESS;
}