]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/GenFds/FvImageSection.py
BaseTools: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / FvImageSection.py
index 3a4d8fb91b70cf47ad25f065c8e6fc12049df147..2d38ff60969d020a92d556a152733a8d61b91c6f 100644 (file)
@@ -3,23 +3,18 @@
 #\r
 #  Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
 #\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
-#\r
-#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 #\r
 \r
 ##\r
 # Import Modules\r
 #\r
-import Section\r
-import StringIO\r
-from Ffs import Ffs\r
+from __future__ import absolute_import\r
+from . import Section\r
+from io import BytesIO\r
+from .Ffs import SectionSuffix\r
 import subprocess\r
-from GenFdsGlobalVariable import GenFdsGlobalVariable\r
+from .GenFdsGlobalVariable import GenFdsGlobalVariable\r
 import Common.LongFilePathOs as os\r
 from CommonDataClass.FdfClass import FvImageSectionClassObject\r
 from Common import EdkLogger\r
@@ -65,17 +60,20 @@ class FvImageSection(FvImageSectionClassObject):
             for FvFileName in FileList:\r
                 FvAlignmentValue = 0\r
                 if os.path.isfile(FvFileName):\r
-                    FvFileObj = open (FvFileName,'rb')\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
+                    if isinstance(FvHeaderBuffer[0x2E], str):\r
+                        FvAlignmentValue = 1 << (ord(FvHeaderBuffer[0x2E]) & 0x1F)\r
+                    else:\r
+                        FvAlignmentValue = 1 << (FvHeaderBuffer[0x2E] & 0x1F)\r
                     FvFileObj.close()\r
                 if FvAlignmentValue > MaxFvAlignment:\r
                     MaxFvAlignment = FvAlignmentValue\r
 \r
-                OutputFile = os.path.join(OutputPath, ModuleName + SUP_MODULE_SEC + Num + Ffs.SectionSuffix.get("FV_IMAGE"))\r
+                OutputFile = os.path.join(OutputPath, ModuleName + SUP_MODULE_SEC + Num + SectionSuffix.get("FV_IMAGE"))\r
                 GenFdsGlobalVariable.GenerateSection(OutputFile, [FvFileName], 'EFI_SECTION_FIRMWARE_VOLUME_IMAGE', IsMakefile=IsMakefile)\r
                 OutputFileList.append(OutputFile)\r
 \r
@@ -86,9 +84,9 @@ class FvImageSection(FvImageSectionClassObject):
                     if MaxFvAlignment >= 0x1000000:\r
                         self.Alignment = "16M"\r
                     else:\r
-                        self.Alignment = str(MaxFvAlignment / 0x100000) + "M"\r
+                        self.Alignment = str(MaxFvAlignment // 0x100000) + "M"\r
                 else:\r
-                    self.Alignment = str (MaxFvAlignment / 0x400) + "K"\r
+                    self.Alignment = str (MaxFvAlignment // 0x400) + "K"\r
             else:\r
                 # MaxFvAlignment is less than 1K\r
                 self.Alignment = str (MaxFvAlignment)\r
@@ -98,10 +96,12 @@ class FvImageSection(FvImageSectionClassObject):
         # Generate Fv\r
         #\r
         if self.FvName is not None:\r
-            Buffer = StringIO.StringIO('')\r
+            Buffer = BytesIO()\r
             Fv = GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(self.FvName)\r
             if Fv is not None:\r
                 self.Fv = Fv\r
+                if not self.FvAddr and self.Fv.BaseAddress:\r
+                    self.FvAddr = self.Fv.BaseAddress\r
                 FvFileName = Fv.AddToBuffer(Buffer, self.FvAddr, MacroDict = Dict, Flag=IsMakefile)\r
                 if Fv.FvAlignment is not None:\r
                     if self.Alignment is None:\r
@@ -113,12 +113,15 @@ class FvImageSection(FvImageSectionClassObject):
                 if self.FvFileName is not None:\r
                     FvFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FvFileName)\r
                     if os.path.isfile(FvFileName):\r
-                        FvFileObj = open (FvFileName,'rb')\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
+                        if isinstance(FvHeaderBuffer[0x2E], str):\r
+                            FvAlignmentValue = 1 << (ord(FvHeaderBuffer[0x2E]) & 0x1F)\r
+                        else:\r
+                            FvAlignmentValue = 1 << (FvHeaderBuffer[0x2E] & 0x1F)\r
                         # FvAlignmentValue is larger than or equal to 1K\r
                         if FvAlignmentValue >= 0x400:\r
                             if FvAlignmentValue >= 0x100000:\r
@@ -126,9 +129,9 @@ class FvImageSection(FvImageSectionClassObject):
                                 if FvAlignmentValue >= 0x1000000:\r
                                     self.Alignment = "16M"\r
                                 else:\r
-                                    self.Alignment = str(FvAlignmentValue / 0x100000) + "M"\r
+                                    self.Alignment = str(FvAlignmentValue // 0x100000) + "M"\r
                             else:\r
-                                self.Alignment = str (FvAlignmentValue / 0x400) + "K"\r
+                                self.Alignment = str (FvAlignmentValue // 0x400) + "K"\r
                         else:\r
                             # FvAlignmentValue is less than 1K\r
                             self.Alignment = str (FvAlignmentValue)\r
@@ -145,7 +148,7 @@ class FvImageSection(FvImageSectionClassObject):
             #\r
             # Prepare the parameter of GenSection\r
             #\r
-            OutputFile = os.path.join(OutputPath, ModuleName + SUP_MODULE_SEC + SecNum + Ffs.SectionSuffix.get("FV_IMAGE"))\r
+            OutputFile = os.path.join(OutputPath, ModuleName + SUP_MODULE_SEC + SecNum + SectionSuffix.get("FV_IMAGE"))\r
             GenFdsGlobalVariable.GenerateSection(OutputFile, [FvFileName], 'EFI_SECTION_FIRMWARE_VOLUME_IMAGE', IsMakefile=IsMakefile)\r
             OutputFileList.append(OutputFile)\r
 \r