]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/GenFds/EfiSection.py
BaseTools: Remove equality operator with None
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / EfiSection.py
index 15ebac5705d6b0bf20750cba71168e8f6d88686e..7e6c88a0594e643c97766feb76216c781c0b4714 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # process rule section generation\r
 #\r
-#  Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2007 - 2017, 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
@@ -53,12 +53,12 @@ class EfiSection (EfiSectionClassObject):
     #   @param  Dict        dictionary contains macro and its value\r
     #   @retval tuple       (Generated file name list, section alignment)\r
     #\r
-    def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = {}) :\r
+    def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = {}, IsMakefile = False) :\r
         \r
-        if self.FileName != None and self.FileName.startswith('PCD('):\r
+        if self.FileName is not None and self.FileName.startswith('PCD('):\r
             self.FileName = GenFdsGlobalVariable.GetPcdValue(self.FileName)\r
         """Prepare the parameter of GenSection"""\r
-        if FfsInf != None :\r
+        if FfsInf is not None :\r
             InfFileName = FfsInf.InfFileName\r
             SectionType = FfsInf.__ExtendMacro__(self.SectionType)\r
             Filename = FfsInf.__ExtendMacro__(self.FileName)\r
@@ -66,20 +66,20 @@ class EfiSection (EfiSectionClassObject):
             StringData = FfsInf.__ExtendMacro__(self.StringData)\r
             NoStrip = True\r
             if FfsInf.ModuleType in ('SEC', 'PEI_CORE', 'PEIM') and SectionType in ('TE', 'PE32'):\r
-                if FfsInf.KeepReloc != None:\r
+                if FfsInf.KeepReloc is not None:\r
                     NoStrip = FfsInf.KeepReloc\r
-                elif FfsInf.KeepRelocFromRule != None:\r
+                elif FfsInf.KeepRelocFromRule is not None:\r
                     NoStrip = FfsInf.KeepRelocFromRule\r
-                elif self.KeepReloc != None:\r
+                elif self.KeepReloc is not None:\r
                     NoStrip = self.KeepReloc\r
-                elif FfsInf.ShadowFromInfFile != None:\r
+                elif FfsInf.ShadowFromInfFile is not None:\r
                     NoStrip = FfsInf.ShadowFromInfFile\r
         else:\r
             EdkLogger.error("GenFds", GENFDS_ERROR, "Module %s apply rule for None!" %ModuleName)\r
 \r
         """If the file name was pointed out, add it in FileList"""\r
         FileList = []\r
-        if Filename != None:\r
+        if Filename is not None:\r
             Filename = GenFdsGlobalVariable.MacroExtend(Filename, Dict)\r
             # check if the path is absolute or relative\r
             if os.path.isabs(Filename):\r
@@ -91,26 +91,30 @@ class EfiSection (EfiSectionClassObject):
                 FileList.append(Filename)\r
             elif os.path.exists(Filename):\r
                 FileList.append(Filename)\r
+            elif '.depex' in FfsInf.FinalTargetSuffixMap or FfsInf.Depex:\r
+                if IsMakefile:\r
+                    FileList.append(Filename)\r
         else:\r
-            FileList, IsSect = Section.Section.GetFileList(FfsInf, self.FileType, self.FileExtension, Dict)\r
+            FileList, IsSect = Section.Section.GetFileList(FfsInf, self.FileType, self.FileExtension, Dict, IsMakefile=IsMakefile)\r
             if IsSect :\r
                 return FileList, self.Alignment\r
 \r
         Index = 0\r
+        Align = self.Alignment\r
 \r
         """ If Section type is 'VERSION'"""\r
         OutputFileList = []\r
         if SectionType == 'VERSION':\r
 \r
             InfOverrideVerString = False\r
-            if FfsInf.Version != None:\r
+            if FfsInf.Version is not None:\r
                 #StringData = FfsInf.Version\r
                 BuildNum = FfsInf.Version\r
                 InfOverrideVerString = True\r
 \r
             if InfOverrideVerString:\r
                 #VerTuple = ('-n', '"' + StringData + '"')\r
-                if BuildNum != None and BuildNum != '':\r
+                if BuildNum is not None and BuildNum != '':\r
                     BuildNumTuple = ('-j', BuildNum)\r
                 else:\r
                     BuildNumTuple = tuple()\r
@@ -118,8 +122,9 @@ class EfiSection (EfiSectionClassObject):
                 Num = SecNum\r
                 OutputFile = os.path.join( OutputPath, ModuleName + 'SEC' + str(Num) + Ffs.SectionSuffix.get(SectionType))\r
                 GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_VERSION',\r
-                                                     #Ui=StringData, \r
-                                                     Ver=BuildNum)\r
+                                                    #Ui=StringData,\r
+                                                    Ver=BuildNum,\r
+                                                    IsMakefile=IsMakefile)\r
                 OutputFileList.append(OutputFile)\r
 \r
             elif FileList != []:\r
@@ -131,16 +136,17 @@ class EfiSection (EfiSectionClassObject):
                     VerString = f.read()\r
                     f.close()\r
                     BuildNum = VerString\r
-                    if BuildNum != None and BuildNum != '':\r
+                    if BuildNum is not None and BuildNum != '':\r
                         BuildNumTuple = ('-j', BuildNum)\r
                     GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_VERSION',\r
-                                                         #Ui=VerString, \r
-                                                         Ver=BuildNum)\r
+                                                        #Ui=VerString,\r
+                                                        Ver=BuildNum,\r
+                                                        IsMakefile=IsMakefile)\r
                     OutputFileList.append(OutputFile)\r
 \r
             else:\r
                 BuildNum = StringData\r
-                if BuildNum != None and BuildNum != '':\r
+                if BuildNum is not None and BuildNum != '':\r
                     BuildNumTuple = ('-j', BuildNum)\r
                 else:\r
                     BuildNumTuple = tuple()\r
@@ -156,8 +162,9 @@ class EfiSection (EfiSectionClassObject):
                 Num = SecNum\r
                 OutputFile = os.path.join( OutputPath, ModuleName + 'SEC' + str(Num) + Ffs.SectionSuffix.get(SectionType))\r
                 GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_VERSION',\r
-                                                     #Ui=VerString, \r
-                                                     Ver=BuildNum)\r
+                                                    #Ui=VerString,\r
+                                                    Ver=BuildNum,\r
+                                                    IsMakefile=IsMakefile)\r
                 OutputFileList.append(OutputFile)\r
 \r
         #\r
@@ -166,7 +173,7 @@ class EfiSection (EfiSectionClassObject):
         elif SectionType == 'UI':\r
 \r
             InfOverrideUiString = False\r
-            if FfsInf.Ui != None:\r
+            if FfsInf.Ui is not None:\r
                 StringData = FfsInf.Ui\r
                 InfOverrideUiString = True\r
 \r
@@ -174,7 +181,7 @@ class EfiSection (EfiSectionClassObject):
                 Num = SecNum\r
                 OutputFile = os.path.join( OutputPath, ModuleName + 'SEC' + str(Num) + Ffs.SectionSuffix.get(SectionType))\r
                 GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_USER_INTERFACE',\r
-                                                     Ui=StringData)\r
+                                                     Ui=StringData, IsMakefile=IsMakefile)\r
                 OutputFileList.append(OutputFile)\r
 \r
             elif FileList != []:\r
@@ -186,10 +193,10 @@ class EfiSection (EfiSectionClassObject):
                     UiString = f.read()\r
                     f.close()\r
                     GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_USER_INTERFACE',\r
-                                                         Ui=UiString)\r
+                                                        Ui=UiString, IsMakefile=IsMakefile)\r
                     OutputFileList.append(OutputFile)\r
             else:\r
-                if StringData != None and len(StringData) > 0:\r
+                if StringData is not None and len(StringData) > 0:\r
                     UiTuple = ('-n', '"' + StringData + '"')\r
                 else:\r
                     UiTuple = tuple()\r
@@ -203,7 +210,7 @@ class EfiSection (EfiSectionClassObject):
                 Num = SecNum\r
                 OutputFile = os.path.join( OutputPath, ModuleName + 'SEC' + str(Num) + Ffs.SectionSuffix.get(SectionType))\r
                 GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_USER_INTERFACE',\r
-                                                     Ui=StringData)\r
+                                                     Ui=StringData, IsMakefile=IsMakefile)\r
                 OutputFileList.append(OutputFile)\r
 \r
 \r
@@ -211,10 +218,10 @@ class EfiSection (EfiSectionClassObject):
             """If File List is empty"""\r
             if FileList == [] :\r
                 if self.Optional == True:\r
-                     GenFdsGlobalVariable.VerboseLogger( "Optional Section don't exist!")\r
-                     return [], None\r
+                    GenFdsGlobalVariable.VerboseLogger("Optional Section don't exist!")\r
+                    return [], None\r
                 else:\r
-                     EdkLogger.error("GenFds", GENFDS_ERROR, "Output file for %s section could not be found for %s" % (SectionType, InfFileName))\r
+                    EdkLogger.error("GenFds", GENFDS_ERROR, "Output file for %s section could not be found for %s" % (SectionType, InfFileName))\r
 \r
             else:\r
                 """Convert the File to Section file one by one """\r
@@ -229,29 +236,44 @@ class EfiSection (EfiSectionClassObject):
                     if self.Alignment == 'Auto' and (SectionType == 'PE32' or SectionType == 'TE'):\r
                         ImageObj = PeImageClass (File)\r
                         if ImageObj.SectionAlignment < 0x400:\r
-                            self.Alignment = str (ImageObj.SectionAlignment)\r
+                            Align = str (ImageObj.SectionAlignment)\r
+                        elif ImageObj.SectionAlignment < 0x100000:\r
+                            Align = str (ImageObj.SectionAlignment / 0x400) + 'K'\r
                         else:\r
-                            self.Alignment = str (ImageObj.SectionAlignment / 0x400) + 'K'\r
+                            Align = str (ImageObj.SectionAlignment / 0x100000) + 'M'\r
 \r
                     if File[(len(File)-4):] == '.efi':\r
                         MapFile = File.replace('.efi', '.map')\r
-                        if os.path.exists(MapFile):\r
-                            CopyMapFile = os.path.join(OutputPath, ModuleName + '.map')\r
-                            if not os.path.exists(CopyMapFile) or \\r
-                                   (os.path.getmtime(MapFile) > os.path.getmtime(CopyMapFile)):\r
-                                CopyLongFilePath(MapFile, CopyMapFile)\r
+                        CopyMapFile = os.path.join(OutputPath, ModuleName + '.map')\r
+                        if IsMakefile:\r
+                            if GenFdsGlobalVariable.CopyList == []:\r
+                                GenFdsGlobalVariable.CopyList = [(MapFile, CopyMapFile)]\r
+                            else:\r
+                                GenFdsGlobalVariable.CopyList.append((MapFile, CopyMapFile))\r
+                        else:\r
+                            if os.path.exists(MapFile):\r
+                                if not os.path.exists(CopyMapFile) or \\r
+                                       (os.path.getmtime(MapFile) > os.path.getmtime(CopyMapFile)):\r
+                                    CopyLongFilePath(MapFile, CopyMapFile)\r
 \r
                     if not NoStrip:\r
                         FileBeforeStrip = os.path.join(OutputPath, ModuleName + '.efi')\r
-                        if not os.path.exists(FileBeforeStrip) or \\r
-                            (os.path.getmtime(File) > os.path.getmtime(FileBeforeStrip)):\r
-                            CopyLongFilePath(File, FileBeforeStrip)\r
+                        if IsMakefile:\r
+                            if GenFdsGlobalVariable.CopyList == []:\r
+                                GenFdsGlobalVariable.CopyList = [(File, FileBeforeStrip)]\r
+                            else:\r
+                                GenFdsGlobalVariable.CopyList.append((File, FileBeforeStrip))\r
+                        else:\r
+                            if not os.path.exists(FileBeforeStrip) or \\r
+                                (os.path.getmtime(File) > os.path.getmtime(FileBeforeStrip)):\r
+                                CopyLongFilePath(File, FileBeforeStrip)\r
                         StrippedFile = os.path.join(OutputPath, ModuleName + '.stripped')\r
                         GenFdsGlobalVariable.GenerateFirmwareImage(\r
-                                                StrippedFile,\r
-                                                [File],\r
-                                                Strip=True\r
-                                                )\r
+                                StrippedFile,\r
+                                [File],\r
+                                Strip=True,\r
+                                IsMakefile = IsMakefile\r
+                            )\r
                         File = StrippedFile\r
                     \r
                     """For TE Section call GenFw to generate TE image"""\r
@@ -259,17 +281,19 @@ class EfiSection (EfiSectionClassObject):
                     if SectionType == 'TE':\r
                         TeFile = os.path.join( OutputPath, ModuleName + 'Te.raw')\r
                         GenFdsGlobalVariable.GenerateFirmwareImage(\r
-                                                TeFile,\r
-                                                [File],\r
-                                                Type='te'\r
-                                                )\r
+                                TeFile,\r
+                                [File],\r
+                                Type='te',\r
+                                IsMakefile = IsMakefile\r
+                            )\r
                         File = TeFile\r
 \r
                     """Call GenSection"""\r
                     GenFdsGlobalVariable.GenerateSection(OutputFile,\r
-                                                         [File],\r
-                                                         Section.Section.SectionType.get (SectionType)\r
-                                                         )\r
+                                                        [File],\r
+                                                        Section.Section.SectionType.get (SectionType),\r
+                                                        IsMakefile=IsMakefile\r
+                                                        )\r
                     OutputFileList.append(OutputFile)\r
 \r
-        return OutputFileList, self.Alignment\r
+        return OutputFileList, Align\r