]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/GenFds/EfiSection.py
BaseTools/GenFds: permit stripped MM_CORE_STANDALONE binaries
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / EfiSection.py
index 5029ec7a18232f72dcba257446e02f73acb8fc9f..0be176ec8ae19129511a8053508dcd0030cf663b 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # process rule 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
 ##\r
 # Import Modules\r
 #\r
+from __future__ import absolute_import\r
 from struct import *\r
-import Section\r
-from GenFdsGlobalVariable import GenFdsGlobalVariable\r
+from . import Section\r
+from .GenFdsGlobalVariable import GenFdsGlobalVariable\r
 import subprocess\r
-from Ffs import Ffs\r
+from .Ffs import SectionSuffix\r
 import Common.LongFilePathOs as os\r
 from CommonDataClass.FdfClass import EfiSectionClassObject\r
 from Common import EdkLogger\r
@@ -27,6 +28,7 @@ from Common.BuildToolError import *
 from Common.Misc import PeImageClass\r
 from Common.LongFilePathSupport import OpenLongFilePath as open\r
 from Common.LongFilePathSupport import CopyLongFilePath\r
+from Common.DataType import *\r
 \r
 ## generate rule section\r
 #\r
@@ -54,32 +56,33 @@ class EfiSection (EfiSectionClassObject):
     #   @retval tuple       (Generated file name list, section alignment)\r
     #\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
+\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
             BuildNum = FfsInf.__ExtendMacro__(self.BuildNum)\r
             StringData = FfsInf.__ExtendMacro__(self.StringData)\r
+            ModuleNameStr = FfsInf.__ExtendMacro__('$(MODULE_NAME)')\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.ModuleType in (SUP_MODULE_SEC, SUP_MODULE_PEI_CORE, SUP_MODULE_PEIM, SUP_MODULE_MM_CORE_STANDALONE) and SectionType in (BINARY_FILE_TYPE_TE, BINARY_FILE_TYPE_PE32):\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,8 +94,9 @@ 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
+            elif IsMakefile:\r
+                SuffixMap = FfsInf.GetFinalTargetSuffixMap()\r
+                if '.depex' in SuffixMap:\r
                     FileList.append(Filename)\r
         else:\r
             FileList, IsSect = Section.Section.GetFileList(FfsInf, self.FileType, self.FileExtension, Dict, IsMakefile=IsMakefile)\r
@@ -107,20 +111,20 @@ class EfiSection (EfiSectionClassObject):
         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
 \r
                 Num = SecNum\r
-                OutputFile = os.path.join( OutputPath, ModuleName + 'SEC' + str(Num) + Ffs.SectionSuffix.get(SectionType))\r
+                OutputFile = os.path.join( OutputPath, ModuleName + SUP_MODULE_SEC + str(Num) + SectionSuffix.get(SectionType))\r
                 GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_VERSION',\r
                                                     #Ui=StringData,\r
                                                     Ver=BuildNum,\r
@@ -130,13 +134,13 @@ class EfiSection (EfiSectionClassObject):
             elif FileList != []:\r
                 for File in FileList:\r
                     Index = Index + 1\r
-                    Num = '%s.%d' %(SecNum , Index)\r
-                    OutputFile = os.path.join(OutputPath, ModuleName + 'SEC' + Num + Ffs.SectionSuffix.get(SectionType))\r
+                    Num = '%s.%d' %(SecNum, Index)\r
+                    OutputFile = os.path.join(OutputPath, ModuleName + SUP_MODULE_SEC + Num + SectionSuffix.get(SectionType))\r
                     f = open(File, 'r')\r
                     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
@@ -146,13 +150,13 @@ class EfiSection (EfiSectionClassObject):
 \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
                 BuildNumString = ' ' + ' '.join(BuildNumTuple)\r
 \r
-                #if VerString == '' and \r
+                #if VerString == '' and\r
                 if BuildNumString == '':\r
                     if self.Optional == True :\r
                         GenFdsGlobalVariable.VerboseLogger( "Optional Section don't exist!")\r
@@ -160,7 +164,7 @@ class EfiSection (EfiSectionClassObject):
                     else:\r
                         EdkLogger.error("GenFds", GENFDS_ERROR, "File: %s miss Version Section value" %InfFileName)\r
                 Num = SecNum\r
-                OutputFile = os.path.join( OutputPath, ModuleName + 'SEC' + str(Num) + Ffs.SectionSuffix.get(SectionType))\r
+                OutputFile = os.path.join( OutputPath, ModuleName + SUP_MODULE_SEC + str(Num) + SectionSuffix.get(SectionType))\r
                 GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_VERSION',\r
                                                     #Ui=VerString,\r
                                                     Ver=BuildNum,\r
@@ -168,18 +172,20 @@ class EfiSection (EfiSectionClassObject):
                 OutputFileList.append(OutputFile)\r
 \r
         #\r
-        # If Section Type is 'UI'\r
+        # If Section Type is BINARY_FILE_TYPE_UI\r
         #\r
-        elif SectionType == 'UI':\r
+        elif SectionType == BINARY_FILE_TYPE_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
             if InfOverrideUiString:\r
                 Num = SecNum\r
-                OutputFile = os.path.join( OutputPath, ModuleName + 'SEC' + str(Num) + Ffs.SectionSuffix.get(SectionType))\r
+                if IsMakefile and StringData == ModuleNameStr:\r
+                    StringData = "$(MODULE_NAME)"\r
+                OutputFile = os.path.join( OutputPath, ModuleName + SUP_MODULE_SEC + str(Num) + SectionSuffix.get(SectionType))\r
                 GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_USER_INTERFACE',\r
                                                      Ui=StringData, IsMakefile=IsMakefile)\r
                 OutputFileList.append(OutputFile)\r
@@ -187,16 +193,18 @@ class EfiSection (EfiSectionClassObject):
             elif FileList != []:\r
                 for File in FileList:\r
                     Index = Index + 1\r
-                    Num = '%s.%d' %(SecNum , Index)\r
-                    OutputFile = os.path.join(OutputPath, ModuleName + 'SEC' + Num + Ffs.SectionSuffix.get(SectionType))\r
+                    Num = '%s.%d' %(SecNum, Index)\r
+                    OutputFile = os.path.join(OutputPath, ModuleName + SUP_MODULE_SEC + Num + SectionSuffix.get(SectionType))\r
                     f = open(File, 'r')\r
                     UiString = f.read()\r
                     f.close()\r
+                    if IsMakefile and UiString == ModuleNameStr:\r
+                        UiString = "$(MODULE_NAME)"\r
                     GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_USER_INTERFACE',\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
@@ -208,7 +216,9 @@ class EfiSection (EfiSectionClassObject):
                         EdkLogger.error("GenFds", GENFDS_ERROR, "File: %s miss UI Section value" %InfFileName)\r
 \r
                 Num = SecNum\r
-                OutputFile = os.path.join( OutputPath, ModuleName + 'SEC' + str(Num) + Ffs.SectionSuffix.get(SectionType))\r
+                if IsMakefile and StringData == ModuleNameStr:\r
+                    StringData = "$(MODULE_NAME)"\r
+                OutputFile = os.path.join( OutputPath, ModuleName + SUP_MODULE_SEC + str(Num) + SectionSuffix.get(SectionType))\r
                 GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_USER_INTERFACE',\r
                                                      Ui=StringData, IsMakefile=IsMakefile)\r
                 OutputFileList.append(OutputFile)\r
@@ -228,12 +238,12 @@ class EfiSection (EfiSectionClassObject):
                 for File in FileList:\r
                     """ Copy Map file to FFS output path """\r
                     Index = Index + 1\r
-                    Num = '%s.%d' %(SecNum , Index)\r
-                    OutputFile = os.path.join( OutputPath, ModuleName + 'SEC' + Num + Ffs.SectionSuffix.get(SectionType))\r
+                    Num = '%s.%d' %(SecNum, Index)\r
+                    OutputFile = os.path.join( OutputPath, ModuleName + SUP_MODULE_SEC + Num + SectionSuffix.get(SectionType))\r
                     File = GenFdsGlobalVariable.MacroExtend(File, Dict)\r
-                    \r
+\r
                     #Get PE Section alignment when align is set to AUTO\r
-                    if self.Alignment == 'Auto' and (SectionType == 'PE32' or SectionType == 'TE'):\r
+                    if self.Alignment == 'Auto' and (SectionType == BINARY_FILE_TYPE_PE32 or SectionType == BINARY_FILE_TYPE_TE):\r
                         ImageObj = PeImageClass (File)\r
                         if ImageObj.SectionAlignment < 0x400:\r
                             Align = str (ImageObj.SectionAlignment)\r
@@ -275,10 +285,10 @@ class EfiSection (EfiSectionClassObject):
                                 IsMakefile = IsMakefile\r
                             )\r
                         File = StrippedFile\r
-                    \r
+\r
                     """For TE Section call GenFw to generate TE image"""\r
 \r
-                    if SectionType == 'TE':\r
+                    if SectionType == BINARY_FILE_TYPE_TE:\r
                         TeFile = os.path.join( OutputPath, ModuleName + 'Te.raw')\r
                         GenFdsGlobalVariable.GenerateFirmwareImage(\r
                                 TeFile,\r