]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/GenFds/FvImageSection.py
BaseTools: Replace StringIO.StringIO with io.BytesIO
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / FvImageSection.py
index 5026a3ffca2f2bedd0ebce3497b250c35d4ed638..b4f1f3340e99c9f61ff29d4a1602fb817f05e476 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # process FV image section generation\r
 #\r
-#  Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>\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
@@ -16,7 +16,7 @@
 # Import Modules\r
 #\r
 import Section\r
-import StringIO\r
+from io import BytesIO\r
 from Ffs import Ffs\r
 import subprocess\r
 from GenFdsGlobalVariable import GenFdsGlobalVariable\r
@@ -24,6 +24,7 @@ import Common.LongFilePathOs as os
 from CommonDataClass.FdfClass import FvImageSectionClassObject\r
 from Common import EdkLogger\r
 from Common.BuildToolError import *\r
+from Common.DataType import *\r
 \r
 ## generate FV image section\r
 #\r
@@ -64,7 +65,7 @@ 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
@@ -74,7 +75,7 @@ class FvImageSection(FvImageSectionClassObject):
                 if FvAlignmentValue > MaxFvAlignment:\r
                     MaxFvAlignment = FvAlignmentValue\r
 \r
-                OutputFile = os.path.join(OutputPath, ModuleName + 'SEC' + Num + Ffs.SectionSuffix.get("FV_IMAGE"))\r
+                OutputFile = os.path.join(OutputPath, ModuleName + SUP_MODULE_SEC + Num + Ffs.SectionSuffix.get("FV_IMAGE"))\r
                 GenFdsGlobalVariable.GenerateSection(OutputFile, [FvFileName], 'EFI_SECTION_FIRMWARE_VOLUME_IMAGE', IsMakefile=IsMakefile)\r
                 OutputFileList.append(OutputFile)\r
 \r
@@ -82,7 +83,7 @@ class FvImageSection(FvImageSectionClassObject):
             if MaxFvAlignment >= 0x400:\r
                 if MaxFvAlignment >= 0x100000:\r
                     #The max alignment supported by FFS is 16M.\r
-                    if MaxFvAlignment >=1000000:\r
+                    if MaxFvAlignment >= 0x1000000:\r
                         self.Alignment = "16M"\r
                     else:\r
                         self.Alignment = str(MaxFvAlignment / 0x100000) + "M"\r
@@ -97,7 +98,7 @@ 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
@@ -112,7 +113,7 @@ 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
@@ -132,13 +133,19 @@ class FvImageSection(FvImageSectionClassObject):
                             # FvAlignmentValue is less than 1K\r
                             self.Alignment = str (FvAlignmentValue)\r
                         FvFileObj.close()\r
+                    else:\r
+                        if len (mws.getPkgPath()) == 0:\r
+                            EdkLogger.error("GenFds", FILE_NOT_FOUND, "%s is not found in WORKSPACE: %s" % self.FvFileName, GenFdsGlobalVariable.WorkSpaceDir)\r
+                        else:\r
+                            EdkLogger.error("GenFds", FILE_NOT_FOUND, "%s is not found in packages path:\n\t%s" % (self.FvFileName, '\n\t'.join(mws.getPkgPath())))\r
+\r
                 else:\r
                     EdkLogger.error("GenFds", GENFDS_ERROR, "FvImageSection Failed! %s NOT found in FDF" % self.FvName)\r
 \r
             #\r
             # Prepare the parameter of GenSection\r
             #\r
-            OutputFile = os.path.join(OutputPath, ModuleName + 'SEC' + SecNum + Ffs.SectionSuffix.get("FV_IMAGE"))\r
+            OutputFile = os.path.join(OutputPath, ModuleName + SUP_MODULE_SEC + SecNum + Ffs.SectionSuffix.get("FV_IMAGE"))\r
             GenFdsGlobalVariable.GenerateSection(OutputFile, [FvFileName], 'EFI_SECTION_FIRMWARE_VOLUME_IMAGE', IsMakefile=IsMakefile)\r
             OutputFileList.append(OutputFile)\r
 \r