]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/GenFds/FvImageSection.py
UefiCpuPkg/CpuDxe: Fix assert issue on IA32 platform
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / FvImageSection.py
index c945ce9b9bdaff70fbc8933e41ea8b126646f65d..68f17c31e8be27207564e330435096b38b423b5c 100644 (file)
@@ -1,9 +1,9 @@
 ## @file\r
 # process FV image section generation\r
 #\r
-#  Copyright (c) 2007, Intel Corporation\r
+#  Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>\r
 #\r
-#  All rights reserved. This program and the accompanying materials\r
+#  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
 #  which accompanies this distribution.  The full text of the license may be found at\r
 #  http://opensource.org/licenses/bsd-license.php\r
@@ -20,7 +20,7 @@ import StringIO
 from Ffs import Ffs\r
 import subprocess\r
 from GenFdsGlobalVariable import GenFdsGlobalVariable\r
-import os\r
+import Common.LongFilePathOs as os\r
 from CommonDataClass.FdfClass import FvImageSectionClassObject\r
 from Common import EdkLogger\r
 from Common.BuildToolError import *\r
@@ -60,10 +60,38 @@ 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,'rb')\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 >= 0x100000:\r
+                    #The max alignment supported by FFS is 16M.\r
+                    if MaxFvAlignment >=1000000:\r
+                        self.Alignment = "16M"\r
+                    else:\r
+                        self.Alignment = str(MaxFvAlignment / 0x100000) + "M"\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
@@ -83,6 +111,27 @@ class FvImageSection(FvImageSectionClassObject):
             else:\r
                 if self.FvFileName != None:\r
                     FvFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FvFileName)\r
+                    if os.path.isfile(FvFileName):\r
+                        FvFileObj = open (FvFileName,'rb')\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
+                        # FvAlignmentValue is larger than or equal to 1K\r
+                        if FvAlignmentValue >= 0x400:\r
+                            if FvAlignmentValue >= 0x100000:\r
+                                #The max alignment supported by FFS is 16M.\r
+                                if FvAlignmentValue >= 0x1000000:\r
+                                    self.Alignment = "16M"\r
+                                else:\r
+                                    self.Alignment = str(FvAlignmentValue / 0x100000) + "M"\r
+                            else:\r
+                                self.Alignment = str (FvAlignmentValue / 0x400) + "K"\r
+                        else:\r
+                            # FvAlignmentValue is less than 1K\r
+                            self.Alignment = str (FvAlignmentValue)\r
+                        FvFileObj.close()\r
                 else:\r
                     EdkLogger.error("GenFds", GENFDS_ERROR, "FvImageSection Failed! %s NOT found in FDF" % self.FvName)\r
 \r