]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/GenFds/EfiSection.py
BaseTools:Make BaseTools support new rules to generate RAW FFS FILE
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / EfiSection.py
index 5405d0a8da135969b309e6035bbe523f619b9c30..74f176cfef2f9833169f1c2b7994ee1c2385ff71 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
+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
@@ -55,7 +50,7 @@ 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
+\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
@@ -67,7 +62,7 @@ class EfiSection (EfiSectionClassObject):
             StringData = FfsInf.__ExtendMacro__(self.StringData)\r
             ModuleNameStr = FfsInf.__ExtendMacro__('$(MODULE_NAME)')\r
             NoStrip = True\r
-            if FfsInf.ModuleType in (SUP_MODULE_SEC, SUP_MODULE_PEI_CORE, SUP_MODULE_PEIM) and SectionType in (BINARY_FILE_TYPE_TE, BINARY_FILE_TYPE_PE32):\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 is not None:\r
@@ -98,7 +93,7 @@ class EfiSection (EfiSectionClassObject):
                 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
+            FileList, IsSect = Section.Section.GetFileList(FfsInf, self.FileType, self.FileExtension, Dict, IsMakefile=IsMakefile, SectionType=SectionType)\r
             if IsSect :\r
                 return FileList, self.Alignment\r
 \r
@@ -123,7 +118,7 @@ class EfiSection (EfiSectionClassObject):
                     BuildNumTuple = tuple()\r
 \r
                 Num = SecNum\r
-                OutputFile = os.path.join( OutputPath, ModuleName + SUP_MODULE_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
@@ -133,8 +128,8 @@ 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 + SUP_MODULE_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
@@ -155,7 +150,7 @@ class EfiSection (EfiSectionClassObject):
                     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
@@ -163,7 +158,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 + SUP_MODULE_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
@@ -184,7 +179,7 @@ class EfiSection (EfiSectionClassObject):
                 Num = SecNum\r
                 if IsMakefile and StringData == ModuleNameStr:\r
                     StringData = "$(MODULE_NAME)"\r
-                OutputFile = os.path.join( OutputPath, ModuleName + SUP_MODULE_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_USER_INTERFACE',\r
                                                      Ui=StringData, IsMakefile=IsMakefile)\r
                 OutputFileList.append(OutputFile)\r
@@ -192,8 +187,8 @@ 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 + SUP_MODULE_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
@@ -217,11 +212,31 @@ class EfiSection (EfiSectionClassObject):
                 Num = SecNum\r
                 if IsMakefile and StringData == ModuleNameStr:\r
                     StringData = "$(MODULE_NAME)"\r
-                OutputFile = os.path.join( OutputPath, ModuleName + SUP_MODULE_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_USER_INTERFACE',\r
                                                      Ui=StringData, IsMakefile=IsMakefile)\r
                 OutputFileList.append(OutputFile)\r
 \r
+        #\r
+        # If Section Type is BINARY_FILE_TYPE_RAW\r
+        #\r
+        elif SectionType == BINARY_FILE_TYPE_RAW:\r
+            """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
+                else:\r
+                    EdkLogger.error("GenFds", GENFDS_ERROR, "Output file for %s section could not be found for %s" % (SectionType, InfFileName))\r
+\r
+            elif len(FileList) > 1:\r
+                EdkLogger.error("GenFds", GENFDS_ERROR,\r
+                                "Files suffixed with %s are not allowed to have more than one file in %s[Binaries] section" % (\r
+                                self.FileExtension, InfFileName))\r
+            else:\r
+                for File in FileList:\r
+                    File = GenFdsGlobalVariable.MacroExtend(File, Dict)\r
+                    OutputFileList.append(File)\r
 \r
         else:\r
             """If File List is empty"""\r
@@ -237,19 +252,19 @@ 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 + SUP_MODULE_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 == 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
                         elif ImageObj.SectionAlignment < 0x100000:\r
-                            Align = str (ImageObj.SectionAlignment / 0x400) + 'K'\r
+                            Align = str (ImageObj.SectionAlignment // 0x400) + 'K'\r
                         else:\r
-                            Align = str (ImageObj.SectionAlignment / 0x100000) + 'M'\r
+                            Align = str (ImageObj.SectionAlignment // 0x100000) + 'M'\r
 \r
                     if File[(len(File)-4):] == '.efi':\r
                         MapFile = File.replace('.efi', '.map')\r
@@ -284,7 +299,7 @@ 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 == BINARY_FILE_TYPE_TE:\r