]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools: Fix bug in GenFds to handle FV image alignment
authorYonghong Zhu <yonghong.zhu@intel.com>
Fri, 6 May 2016 09:14:26 +0000 (17:14 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Wed, 11 May 2016 04:25:44 +0000 (12:25 +0800)
Cover the case that .fv file in the [Binaries] section.

Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Yonghong Zhu <yonghong.zhu@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
BaseTools/Source/Python/GenFds/FvImageSection.py

index b577de263c533ac6dc9b6c4c50cea58fc2213d37..748d02f7000304bd03b49651f4305b3d994d5b75 100644 (file)
@@ -60,10 +60,35 @@ class FvImageSection(FvImageSectionClassObject):
 \r
             Num = SecNum\r
 \r
-            for FileName in FileList:\r
+            MaxFvAlignment = 0\r
+            for FvFileName in FileList:\r
+                FvAlignmentValue = 0\r
+                if os.path.isfile(FvFileName):\r
+                    FvFileObj = open (FvFileName,'r+b')\r
+                    FvFileObj.seek(0)\r
+                    # PI FvHeader is 0x48 byte\r
+                    FvHeaderBuffer = FvFileObj.read(0x48)\r
+                    # FV alignment position.\r
+                    FvAlignmentValue = 1 << (ord (FvHeaderBuffer[0x2E]) & 0x1F)\r
+                    FvFileObj.close()\r
+                if FvAlignmentValue > MaxFvAlignment:\r
+                    MaxFvAlignment = FvAlignmentValue\r
+\r
                 OutputFile = os.path.join(OutputPath, ModuleName + 'SEC' + Num + Ffs.SectionSuffix.get("FV_IMAGE"))\r
                 GenFdsGlobalVariable.GenerateSection(OutputFile, [FvFileName], 'EFI_SECTION_FIRMWARE_VOLUME_IMAGE')\r
                 OutputFileList.append(OutputFile)\r
+\r
+            # MaxFvAlignment is larger than or equal to 1K\r
+            if MaxFvAlignment >= 0x400:\r
+                if MaxFvAlignment >= 0x10000:\r
+                    #The max alignment supported by FFS is 64K.\r
+                    self.Alignment = "64K"\r
+                else:\r
+                    self.Alignment = str (MaxFvAlignment / 0x400) + "K"\r
+            else:\r
+                # MaxFvAlignment is less than 1K\r
+                self.Alignment = str (MaxFvAlignment)\r
+\r
             return OutputFileList, self.Alignment\r
         #\r
         # Generate Fv\r