Detect region out of order or overlap.
authorjlin16 <jlin16@7335b38e-4728-0410-8992-fb3ffe349368>
Mon, 5 Nov 2007 08:19:44 +0000 (08:19 +0000)
committerjlin16 <jlin16@7335b38e-4728-0410-8992-fb3ffe349368>
Mon, 5 Nov 2007 08:19:44 +0000 (08:19 +0000)
Add relocation section strip feature (need GenFw.exe update).

git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@867 7335b38e-4728-0410-8992-fb3ffe349368

13 files changed:
Source/Python/CommonDataClass/FdfClassObject.py
Source/Python/GenFds/AprioriSection.py
Source/Python/GenFds/CompressSection.py
Source/Python/GenFds/DataSection.py
Source/Python/GenFds/EfiSection.py
Source/Python/GenFds/Fd.py
Source/Python/GenFds/FdfParser.py
Source/Python/GenFds/Ffs.py
Source/Python/GenFds/FfsFileStatement.py
Source/Python/GenFds/FfsInfStatement.py
Source/Python/GenFds/Fv.py
Source/Python/GenFds/GenFds.py
Source/Python/GenFds/Region.py

index ed6099c..01a24f4 100644 (file)
@@ -98,20 +98,21 @@ class FfsClassObject:
 ## FILE statement data in FDF\r
 #\r
 #        \r
-class FileStatementsClassObject (FfsClassObject) :\r
+class FileStatementClassObject (FfsClassObject) :\r
     ## The constructor\r
     #\r
     #   @param  self        The object pointer\r
     #\r
     def __init__(self):\r
         FfsClassObject.__init__(self)\r
-        self.FvType = None\r
+        self.FvFileType = None\r
         self.FileName = None\r
         self.KeyStringList = []\r
         self.FvName = None\r
         self.FdName = None\r
         self.DefineVarDict = {}\r
         self.AprioriSection = None\r
+        self.KeepReloc = None\r
 \r
 ## INF statement data in FDF\r
 #\r
@@ -129,6 +130,7 @@ class FfsInfStatementClassObject(FfsClassObject):
         self.InfFileName = None\r
         self.BuildNum = ''\r
         self.KeyStringList = []\r
+        self.KeepReloc = None\r
 \r
 ## APRIORI section data in FDF\r
 #\r
@@ -180,6 +182,7 @@ class DataSectionClassObject (SectionClassObject):
         self.SecType = None\r
         self.SectFileName = None\r
         self.SectionList = []\r
+        self.KeepReloc = True\r
 \r
 ## Rule section data in FDF\r
 #\r
@@ -198,6 +201,7 @@ class EfiSectionClassObject (SectionClassObject):
         self.FileName = None\r
         self.FileExtension = None\r
         self.BuildNum = None\r
+        self.KeepReloc = None\r
 \r
 ## FV image section data in FDF\r
 #\r
@@ -274,8 +278,9 @@ class RuleClassObject :
         self.Fixed = False\r
         self.Alignment = None\r
         self.CheckSum = False\r
-        self.FvType = None       # for Ffs File Type\r
+        self.FvFileType = None       # for Ffs File Type\r
         self.KeyStringList = []\r
+        self.KeepReloc = None\r
 \r
 ## Complex rule data in FDF\r
 #\r
index ae055c8..03b6a7f 100755 (executable)
@@ -68,7 +68,7 @@ class AprioriSection (AprioriSectionClassObject):
         \r
         for FfsObj in self.FfsList :\r
             Guid = ""\r
-            if isinstance(FfsObj, FfsFileStatement.FileStatements):\r
+            if isinstance(FfsObj, FfsFileStatement.FileStatement):\r
                 Guid = FfsObj.NameGuid\r
             else:\r
                 InfFileName = NormPath(FfsObj.InfFileName)\r
index c8898d3..e9bd947 100755 (executable)
@@ -54,9 +54,7 @@ class CompressSection (CompressSectionClassObject) :
     #   @retval tuple       (Generated file name, section alignment)\r
     #\r
     def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = {}):\r
-        #\r
-        # Generate all section\r
-        #\r
+        \r
         if FfsInf != None:\r
             self.CompType = FfsInf.__ExtendMacro__(self.CompType)\r
             self.Alignment = FfsInf.__ExtendMacro__(self.Alignment)\r
index a1b0995..870422a 100644 (file)
@@ -47,15 +47,16 @@ class DataSection (DataSectionClassObject):
     #   @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, FfsFile = None, Dict = {}):\r
         #\r
         # Prepare the parameter of GenSection\r
         #\r
-        if FfsInf != None:\r
-            self.Alignment = FfsInf.__ExtendMacro__(self.Alignemnt)\r
-            self.SecType = FfsInf.__ExtendMacro__(self.SecType)\r
-            self.SectFileName = FfsInf.__ExtendMacro__(self.SectFileName)\r
+        if FfsFile != None:\r
+#            self.Alignment = FfsInf.__ExtendMacro__(self.Alignemnt)\r
+#            self.SecType = FfsInf.__ExtendMacro__(self.SecType)\r
+            self.SectFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.SectFileName)\r
         else:\r
+#            raise Exception ("Module %s GenDataSection for None!" %ModuleName)\r
             self.SectFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.SectFileName)\r
             \r
         self.SectFileName = GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict)\r
@@ -65,6 +66,24 @@ class DataSection (DataSectionClassObject):
         if not os.path.exists(self.SectFileName):\r
             self.SectFileName = os.path.join (GenFdsGlobalVariable.WorkSpaceDir,\r
                                               self.SectFileName)\r
+        \r
+        NoStrip = True\r
+        if self.SecType in ('TE', 'PE32'):\r
+            if self.KeepReloc != None:\r
+                NoStrip = self.KeepReloc\r
+        \r
+        if not NoStrip:\r
+            FileBeforeStrip = os.path.join(OutputPath, ModuleName + '.reloc')\r
+            shutil.copyfile(self.SectFileName, FileBeforeStrip)\r
+            StrippedFile = os.path.join(OutputPath, ModuleName + '.stipped')\r
+            StripCmd = 'GenFw -l '    + \\r
+                       ' -o '         + \\r
+                        StrippedFile        + \\r
+                        ' '           + \\r
+                        GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict)\r
+            GenFdsGlobalVariable.CallExternalTool(StripCmd, "Strip Failed !")\r
+            self.SectFileName = StrippedFile\r
+        \r
         if self.SecType == 'TE':\r
             TeFile = os.path.join( OutputPath, ModuleName + 'Te.raw')\r
             GenTeCmd = 'GenFW -t '    + \\r
index 18da09e..96554a9 100644 (file)
@@ -54,18 +54,21 @@ class EfiSection (EfiSectionClassObject):
             InfFileName = FfsInf.InfFileName\r
             SectionType = FfsInf.__ExtendMacro__(self.SectionType)\r
             Filename = FfsInf.__ExtendMacro__(self.FileName)\r
-            """print 'Buile Num: %s' %self.BuildNum"""\r
             BuildNum = FfsInf.__ExtendMacro__(self.BuildNum)\r
-            """print 'After extend Build Num: %s' %self.BuildNum"""\r
-            \r
             StringData = FfsInf.__ExtendMacro__(self.StringData)\r
-            \r
+            NoStrip = True\r
+            if FfsInf.ModuleType in ('SEC', 'PEI_CORE', 'PEIM') and SectionType in ('TE', 'PE32'):\r
+                if FfsInf.KeepReloc != None:\r
+                    NoStrip = FfsInf.KeepReloc\r
+                elif FfsInf.KeepRelocFromRule != None:\r
+                    NoStrip = FfsInf.KeepRelocFromRule\r
+                elif self.KeepReloc != None:\r
+                    NoStrip = self.KeepReloc\r
+                elif FfsInf.ShadowFromInfFile != None:\r
+                    NoStrip = FfsInf.ShadowFromInfFile\r
         else:\r
-            SectionType = self.SectionType\r
-            Filename = self.Filename\r
-            BuildNum = self.BuildNum\r
-            \r
-            InfFileName = ''\r
+            raise Exception ("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
@@ -256,11 +259,22 @@ class EfiSection (EfiSectionClassObject):
                             CopyMapFile = os.path.join(OutputPath, ModuleName + '.map')\r
                             shutil.copyfile(MapFile, CopyMapFile)\r
 \r
+                    if not NoStrip:\r
+                        FileBeforeStrip = os.path.join(OutputPath, ModuleName + '.reloc')\r
+                        shutil.copyfile(File, FileBeforeStrip)\r
+                        StrippedFile = os.path.join(OutputPath, ModuleName + '.stipped')\r
+                        StripCmd = 'GenFw -l '    + \\r
+                                   ' -o '         + \\r
+                                    StrippedFile        + \\r
+                                    ' '           + \\r
+                                    GenFdsGlobalVariable.MacroExtend(File, Dict)\r
+                        GenFdsGlobalVariable.CallExternalTool(StripCmd, "Strip Failed !")\r
+                        File = StrippedFile\r
                     """For TE Section call GenFw to generate TE image"""\r
 \r
                     if SectionType == 'TE':\r
                         TeFile = os.path.join( OutputPath, ModuleName + 'Te.raw')\r
-                        GenTeCmd = 'GenFW -t '    + \\r
+                        GenTeCmd = 'GenFw -t '    + \\r
                                    ' -o '         + \\r
                                     TeFile        + \\r
                                     ' '           + \\r
index 64a479b..ab7e577 100644 (file)
@@ -57,12 +57,26 @@ class FD(FDClassObject):
         self.GenVtfFile()\r
         \r
         FdBuffer = StringIO.StringIO('')\r
-        for Regions in self.RegionList :\r
+        PreviousRegionStart = -1\r
+        PreviousRegionSize = 1\r
+        for RegionObj in self.RegionList :\r
+            if RegionObj.Offset + RegionObj.Size <= PreviousRegionStart:\r
+                raise Exception ('Region offset 0x%X in wrong order with Region starting from 0x%X, size 0x%X\nRegions in FDF must have offsets appear in ascending order.' % (RegionObj.Offset, PreviousRegionStart, PreviousRegionSize))\r
+            elif RegionObj.Offset <= PreviousRegionStart or (RegionObj.Offset >=PreviousRegionStart and RegionObj.Offset < PreviousRegionStart + PreviousRegionSize):\r
+                raise Exception ('Region offset 0x%X overlaps with Region starting from 0x%X, size 0x%X' % (RegionObj.Offset, PreviousRegionStart, PreviousRegionSize))\r
+            elif RegionObj.Offset > PreviousRegionStart + PreviousRegionSize:\r
+                GenFdsGlobalVariable.InfLogger('Padding region starting from offset 0x%X, with size 0x%X' %(PreviousRegionStart + PreviousRegionSize, RegionObj.Offset - (PreviousRegionStart + PreviousRegionSize)))\r
+                PadRegion = Region.Region()\r
+                PadRegion.Offset = PreviousRegionStart + PreviousRegionSize\r
+                PadRegion.Size = RegionObj.Offset - PadRegion.Offset\r
+                PadRegion.AddToBuffer(FdBuffer, self.BaseAddress, self.BlockSizeList, self.ErasePolarity, FvBinDict, self.vtfRawDict, self.DefineVarDict)\r
+            PreviousRegionStart = RegionObj.Offset\r
+            PreviousRegionSize = RegionObj.Size\r
             #\r
             # Call each region's AddToBuffer function \r
             #\r
             GenFdsGlobalVariable.VerboseLogger('Call each region\'s AddToBuffer function')\r
-            Regions.AddToBuffer (FdBuffer, self.BaseAddress, self.BlockSizeList, self.ErasePolarity, FvBinDict, self.vtfRawDict, self.DefineVarDict)\r
+            RegionObj.AddToBuffer (FdBuffer, self.BaseAddress, self.BlockSizeList, self.ErasePolarity, FvBinDict, self.vtfRawDict, self.DefineVarDict)\r
         #\r
         # Create a empty Fd file\r
         #\r
index 8e673f1..18ff1b1 100644 (file)
@@ -1033,7 +1033,7 @@ class FdfParser:
         if not self.__GetNextHexNumber():\r
             return False\r
         \r
-        RegionObj = Region.region()\r
+        RegionObj = Region.Region()\r
         RegionObj.Offset = long(self.__Token, 0)\r
         Fd.RegionList.append(RegionObj)\r
         \r
@@ -1147,7 +1147,7 @@ class FdfParser:
     #   @param  self        The object pointer\r
     #   @param  RegionObj   for whom region data is got\r
     #\r
-    def __GetRegionDataType(self, region):\r
+    def __GetRegionDataType(self, RegionObj):\r
         \r
         if not self.__IsKeyword( "DATA"):\r
             raise Warning("expected Region Data type At Line %d" % self.CurrentLineNumber, self.FileName, self.CurrentLineNumber)\r
@@ -1178,8 +1178,8 @@ class FdfParser:
             raise Warning("expected '}' At Line %d" % self.CurrentLineNumber, self.FileName, self.CurrentLineNumber)\r
         \r
         DataString = DataString.rstrip(",")\r
-        region.RegionType = "DATA"\r
-        region.RegionDataList.append( DataString)\r
+        RegionObj.RegionType = "DATA"\r
+        RegionObj.RegionDataList.append( DataString)\r
         \r
         while self.__IsKeyword( "DATA"):\r
 \r
@@ -1209,7 +1209,7 @@ class FdfParser:
                 raise Warning("expected '}' At Line %d" % self.CurrentLineNumber, self.FileName, self.CurrentLineNumber)\r
         \r
             DataString = DataString.rstrip(",")\r
-            region.RegionDataList.append( DataString)\r
+            RegionObj.RegionDataList.append( DataString)\r
     \r
     ## __GetFv() method\r
     #\r
@@ -1402,6 +1402,14 @@ class FdfParser:
         if not ffsInf.InfFileName in self.Profile.InfList:\r
             self.Profile.InfList.append(ffsInf.InfFileName)\r
         \r
+        if self.__IsToken('|'):\r
+            if self.__IsKeyword('RELOCS_STRIPPED'):\r
+                ffsInf.KeepReloc = False\r
+            elif self.__IsKeyword('RELOCS_RETAINED'):\r
+                ffsInf.KeepReloc = True\r
+            else:\r
+                raise Warning("Unknown reloc strip flag At Line %d" % self.CurrentLineNumber, self.FileName, self.CurrentLineNumber)\r
+        \r
         if ForCapsule:\r
             capsuleFfs = CapsuleData.CapsuleFfs()\r
             capsuleFfs.Ffs = ffsInf\r
@@ -1477,11 +1485,11 @@ class FdfParser:
         if not self.__IsKeyword( "FILE"):\r
             return False\r
         \r
-        FfsFileObj = FfsFileStatement.FileStatements()\r
+        FfsFileObj = FfsFileStatement.FileStatement()\r
         \r
         if not self.__GetNextWord():\r
             raise Warning("expected FFS type At Line %d" % self.CurrentLineNumber, self.FileName, self.CurrentLineNumber)\r
-        FfsFileObj.FvType = self.__Token\r
+        FfsFileObj.FvFileType = self.__Token\r
         \r
         if not self.__IsToken( "="):\r
             raise Warning("expected '=' At Line %d" % self.CurrentLineNumber, self.FileName, self.CurrentLineNumber)\r
@@ -1500,6 +1508,38 @@ class FdfParser:
             Obj.FfsList.append(FfsFileObj)\r
                 \r
         return True\r
+    \r
+    ## __FileCouldHaveRelocFlag() method\r
+    #\r
+    #   Check whether reloc strip flag can be set for a file type.\r
+    #\r
+    #   @param  self        The object pointer\r
+    #   @param  FileType    The file type to check with\r
+    #   @retval True        This type could have relocation strip flag\r
+    #   @retval False       No way to have it\r
+    #\r
+    \r
+    def __FileCouldHaveRelocFlag (self, FileType):\r
+        if FileType in ('SEC', 'PEI_CORE', 'PEIM', 'PEI_DXE_COMBO'):\r
+            return True\r
+        else:\r
+            return False\r
+    \r
+    ## __SectionCouldHaveRelocFlag() method\r
+    #\r
+    #   Check whether reloc strip flag can be set for a section type.\r
+    #\r
+    #   @param  self        The object pointer\r
+    #   @param  SectionType The section type to check with\r
+    #   @retval True        This type could have relocation strip flag\r
+    #   @retval False       No way to have it\r
+    #\r
+    \r
+    def __SectionCouldHaveRelocFlag (self, SectionType):\r
+        if SectionType in ('TE', 'PE32'):\r
+            return True\r
+        else:\r
+            return False\r
         \r
     ## __GetFilePart() method\r
     #\r
@@ -1513,8 +1553,18 @@ class FdfParser:
         \r
         self.__GetFileOpts( FfsFileObj)\r
         \r
-        if not self.__IsToken( "{"):\r
-            raise Warning("expected '{' At Line %d" % self.CurrentLineNumber, self.FileName, self.CurrentLineNumber)\r
+        if not self.__IsToken("{"):\r
+#            if self.__IsKeyword('RELOCS_STRIPPED') or self.__IsKeyword('RELOCS_RETAINED'):\r
+#                if self.__FileCouldHaveRelocFlag(FfsFileObj.FvFileType):\r
+#                    if self.__Token == 'RELOCS_STRIPPED':\r
+#                        FfsFileObj.KeepReloc = False\r
+#                    else:\r
+#                        FfsFileObj.KeepReloc = True\r
+#                else:\r
+#                    raise Warning("File type %s could not have reloc strip flag At Line %d" % (FfsFileObj.FvFileType, self.CurrentLineNumber), self.FileName, self.CurrentLineNumber)\r
+#            \r
+#            if not self.__IsToken("{"):\r
+                raise Warning("expected '{' At Line %d" % self.CurrentLineNumber, self.FileName, self.CurrentLineNumber)\r
             \r
         if not self.__GetNextToken():\r
             raise Warning("expected File name or section data At Line %d" % self.CurrentLineNumber, self.FileName, self.CurrentLineNumber)\r
@@ -1575,6 +1625,8 @@ class FdfParser:
             \r
         if self.__GetAlignment():\r
             FfsFileObj.Alignment = self.__Token\r
+            \r
+        \r
     \r
     ## __GetAlignment() method\r
     #\r
@@ -1738,6 +1790,15 @@ class FdfParser:
             DataSectionObj.Alignment = AlignValue\r
             DataSectionObj.SecType = self.__Token\r
             \r
+            if self.__IsKeyword('RELOCS_STRIPPED') or self.__IsKeyword('RELOCS_RETAINED'):\r
+                if self.__FileCouldHaveRelocFlag(Obj.FvFileType) and self.__SectionCouldHaveRelocFlag(DataSectionObj.SecType):\r
+                    if self.__Token == 'RELOCS_STRIPPED':\r
+                        DataSectionObj.KeepReloc = False\r
+                    else:\r
+                        DataSectionObj.KeepReloc = True\r
+                else:\r
+                    raise Warning("File type %s, section type %s, could not have reloc strip flag At Line %d" % (Obj.FvFileType, DataSectionObj.SecType, self.CurrentLineNumber), self.FileName, self.CurrentLineNumber)\r
+            \r
             if self.__IsToken("="):\r
                 if not self.__GetNextToken():\r
                     raise Warning("expected section file path At Line %d" % self.CurrentLineNumber, self.FileName, self.CurrentLineNumber)\r
@@ -2135,6 +2196,16 @@ class FdfParser:
         if not self.__IsKeyword("$(NAMED_GUID)"):\r
             raise Warning("expected $(NAMED_GUID) At Line %d" % self.CurrentLineNumber, self.FileName, self.CurrentLineNumber)\r
 \r
+        KeepReloc = None\r
+        if self.__IsKeyword('RELOCS_STRIPPED') or self.__IsKeyword('RELOCS_RETAINED'):\r
+            if self.__FileCouldHaveRelocFlag(Type):\r
+                if self.__Token == 'RELOCS_STRIPPED':\r
+                    KeepReloc = False\r
+                else:\r
+                    KeepReloc = True\r
+            else:\r
+                raise Warning("File type %s could not have reloc strip flag At Line %d" % (Type, self.CurrentLineNumber), self.FileName, self.CurrentLineNumber)\r
+        \r
         KeyStringList = []\r
         if self.__GetNextToken():\r
             Pattern = re.compile(r'([a-zA-Z0-9\-]+|\$\(TARGET\)|\*)_([a-zA-Z0-9\-]+|\$\(TOOL_CHAIN_TAG\)|\*)_([a-zA-Z0-9\-]+|\$\(ARCH\)|\*)')\r
@@ -2170,11 +2241,13 @@ class FdfParser:
         if self.__IsToken("{"):\r
             # Complex file rule expected\r
             Rule = RuleComplexFile.RuleComplexFile()\r
-            Rule.FvType = Type\r
+            Rule.FvFileType = Type\r
             Rule.Alignment = AlignValue\r
             Rule.CheckSum = CheckSum\r
             Rule.Fixed = Fixed\r
             Rule.KeyStringList = KeyStringList\r
+            if KeepReloc != None:\r
+                Rule.KeepReloc = KeepReloc\r
             \r
             while True:\r
                 IsEncapsulate = self.__GetRuleEncapsulationSection(Rule)\r
@@ -2193,12 +2266,14 @@ class FdfParser:
             \r
             Rule = RuleSimpleFile.RuleSimpleFile()\r
 \r
-            Rule.FvType = Type\r
+            Rule.FvFileType = Type\r
             Rule.Alignment = Alignment\r
             Rule.CheckSum = CheckSum\r
             Rule.Fixed = Fixed\r
             Rule.FileExtension = Ext\r
             Rule.KeyStringList = KeyStringList\r
+            if KeepReloc != None:\r
+                Rule.KeepReloc = KeepReloc\r
             \r
             return Rule\r
             \r
@@ -2230,12 +2305,14 @@ class FdfParser:
             \r
             Rule = RuleSimpleFile.RuleSimpleFile()\r
             Rule.SectionType = SectionName\r
-            Rule.FvType = Type\r
+            Rule.FvFileType = Type\r
             Rule.Alignment = AlignValue\r
             Rule.CheckSum = CheckSum\r
             Rule.Fixed = Fixed\r
             Rule.FileName = self.__Token\r
             Rule.KeyStringList = KeyStringList\r
+            if KeepReloc != None:\r
+                Rule.KeepReloc = KeepReloc\r
             return Rule\r
         \r
     ## __GetEfiSection() method\r
@@ -2367,6 +2444,18 @@ class FdfParser:
         if self.__GetAlignment():\r
             EfiSectionObj.Alignment = self.__Token\r
         \r
+        if self.__IsKeyword('RELOCS_STRIPPED') or self.__IsKeyword('RELOCS_RETAINED'):\r
+            if self.__SectionCouldHaveRelocFlag(EfiSectionObj.SectionType):\r
+                if self.__Token == 'RELOCS_STRIPPED':\r
+                    EfiSectionObj.KeepReloc = False\r
+                else:\r
+                    EfiSectionObj.KeepReloc = True\r
+                if Obj.KeepReloc != None and Obj.KeepReloc != EfiSectionObj.KeepReloc:\r
+                    raise Warning("Section type %s has reloc strip flag conflict with Rule At Line %d" % (EfiSectionObj.SectionType, self.CurrentLineNumber), self.FileName, self.CurrentLineNumber)\r
+            else:\r
+                raise Warning("Section type %s could not have reloc strip flag At Line %d" % (EfiSectionObj.SectionType, self.CurrentLineNumber), self.FileName, self.CurrentLineNumber)\r
+        \r
+        \r
         if self.__IsToken('|'):\r
             EfiSectionObj.FileExtension = self.__GetFileExtension()\r
         elif self.__GetNextToken():\r
@@ -2758,7 +2847,7 @@ class FdfParser:
     def __GetReferencedFdFvTuple(self, FvObj, RefFdList = [], RefFvList = []):\r
         \r
         for FfsObj in FvObj.FfsList:\r
-            if isinstance(FfsObj, FfsFileStatement.FileStatements):\r
+            if isinstance(FfsObj, FfsFileStatement.FileStatement):\r
                 if FfsObj.FvName != None and FfsObj.FvName.upper() not in RefFvList:\r
                     RefFvList.append(FfsObj.FvName.upper())\r
                 elif FfsObj.FdName != None and FfsObj.FdName.upper() not in RefFdList:\r
index 08bf13b..f1fb3fc 100755 (executable)
@@ -37,7 +37,7 @@ class Ffs(FDClassObject):
     }\r
     \r
     # mapping between fv type in FDF and file type for GenFfs\r
-    FvTypeToFileType = {\r
+    FdfFvFileTypeToFileType = {\r
         'SEC'               : 'EFI_FV_FILETYPE_SECURITY_CORE',\r
         'PEI_CORE'          : 'EFI_FV_FILETYPE_PEI_CORE',\r
         'PEIM'              : 'EFI_FV_FILETYPE_PEIM',\r
index 2952ef7..5b417fb 100755 (executable)
@@ -21,18 +21,18 @@ from GenFdsGlobalVariable import GenFdsGlobalVariable
 import os\r
 import StringIO\r
 import subprocess\r
-from CommonDataClass.FdfClassObject import FileStatementsClassObject\r
+from CommonDataClass.FdfClassObject import FileStatementClassObject\r
 \r
 ## generate FFS from FILE\r
 #\r
 #\r
-class FileStatements (FileStatementsClassObject) :\r
+class FileStatement (FileStatementClassObject) :\r
     ## The constructor\r
     #\r
     #   @param  self        The object pointer\r
     #\r
     def __init__(self):\r
-        FileStatementsClassObject.__init__(self)\r
+        FileStatementClassObject.__init__(self)\r
     \r
     ## GenFfs() method\r
     #\r
@@ -102,8 +102,8 @@ class FileStatements (FileStatementsClassObject) :
         else :\r
             Alignment = ''\r
 \r
-        if not (self.FvType == None):\r
-            FileType = ' -t ' + Ffs.Ffs.FvTypeToFileType.get(self.FvType)\r
+        if not (self.FvFileType == None):\r
+            FileType = ' -t ' + Ffs.Ffs.FdfFvFileTypeToFileType.get(self.FvFileType)\r
         else:\r
             FileType = ''\r
 \r
index e38387b..3bda80e 100644 (file)
@@ -17,6 +17,7 @@
 #\r
 import Rule\r
 import os\r
+import shutil\r
 from GenFdsGlobalVariable import GenFdsGlobalVariable\r
 import Ffs\r
 import subprocess\r
@@ -38,6 +39,8 @@ class FfsInfStatement(FfsInfStatementClassObject):
     def __init__(self):\r
         FfsInfStatementClassObject.__init__(self)\r
         self.TargetOverrideList = []\r
+        self.ShadowFromInfFile = None\r
+        self.KeepRelocFromRule = None\r
 \r
     ## __InfParse() method\r
     #\r
@@ -66,6 +69,11 @@ class FfsInfStatement(FfsInfStatementClassObject):
             self.ModuleType = Inf.ModuleType\r
             self.VersionString = Inf.Version\r
             self.BinFileList = Inf.Binaries\r
+            if self.KeepReloc == None and Inf.Shadow != '':\r
+                if Inf.Shadow.upper() == "TRUE":\r
+                    self.ShadowFromInfFile = True\r
+                else:\r
+                    self.ShadowFromInfFile = False \r
         \r
         elif self.InfFileName in GenFdsGlobalVariable.WorkSpace.InfDatabase.keys():\r
             Inf = GenFdsGlobalVariable.WorkSpace.InfDatabase[self.InfFileName]\r
@@ -124,7 +132,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
         # Get the rule of how to generate Ffs file\r
         #\r
         Rule = self.__GetRule__()\r
-        GenFdsGlobalVariable.VerboseLogger( "Packing binaries from INf file : %s" %self.InfFileName)\r
+        GenFdsGlobalVariable.VerboseLogger( "Packing binaries from inf file : %s" %self.InfFileName)\r
         #FileType = Ffs.Ffs.ModuleTypeToFileType[Rule.ModuleType]\r
         #\r
         # For the rule only has simpleFile\r
@@ -327,13 +335,46 @@ class FfsInfStatement(FfsInfStatementClassObject):
 \r
         Index = 1\r
         SectionType     = Rule.SectionType\r
+        NoStrip = True\r
+        if self.ModuleType in ('SEC', 'PEI_CORE', 'PEIM'):\r
+            if self.KeepReloc != None:\r
+                NoStrip = self.KeepReloc\r
+            elif Rule.KeepReloc != None:\r
+                NoStrip = Rule.KeepReloc\r
+            elif self.ShadowFromInfFile != None:\r
+                NoStrip = self.ShadowFromInfFile\r
+                \r
         if FileList != [] :\r
             for File in FileList:\r
+                \r
                 SecNum = '%d' %Index\r
                 GenSecOutputFile= self.__ExtendMacro__(Rule.NameGuid) + \\r
                               Ffs.Ffs.SectionSuffix[SectionType] + 'SEC' + SecNum   \r
                 Index = Index + 1             \r
                 OutputFile = os.path.join(self.OutputPath, GenSecOutputFile)\r
+                \r
+                if not NoStrip:\r
+                    FileBeforeStrip = os.path.join(self.OutputPath, ModuleName + '.reloc')\r
+                    shutil.copyfile(File, FileBeforeStrip)\r
+                    StrippedFile = os.path.join(self.OutputPath, ModuleName + '.stipped')\r
+                    StripCmd = 'GenFw -l '    + \\r
+                               ' -o '         + \\r
+                                StrippedFile        + \\r
+                                ' '           + \\r
+                                GenFdsGlobalVariable.MacroExtend(File, Dict)\r
+                    GenFdsGlobalVariable.CallExternalTool(StripCmd, "Strip Failed !")\r
+                    File = StrippedFile\r
+                    \r
+                if SectionType == 'TE':\r
+                    TeFile = os.path.join( self.OutputPath, self.ModuleGuid + 'Te.raw')\r
+                    GenTeCmd = 'GenFw -t '    + \\r
+                               ' -o '         + \\r
+                                TeFile        + \\r
+                                ' '           + \\r
+                               GenFdsGlobalVariable.MacroExtend(File, Dict)\r
+                    GenFdsGlobalVariable.CallExternalTool(GenTeCmd, "GenFw Failed !")\r
+                    File = TeFile\r
+                \r
                 GenSectionCmd = 'GenSec -o '                                + \\r
                                  OutputFile                                 + \\r
                                  ' -s '                                     + \\r
@@ -344,13 +385,35 @@ class FfsInfStatement(FfsInfStatementClassObject):
                 # Call GenSection\r
                 #\r
                 GenFdsGlobalVariable.CallExternalTool(GenSectionCmd, "Gen section Failed!")\r
-                OutputFileList.append(GenSecOutputFile)\r
+                OutputFileList.append(OutputFile)\r
         else:\r
             SecNum = '%d' %Index\r
             GenSecOutputFile= self.__ExtendMacro__(Rule.NameGuid) + \\r
                               Ffs.Ffs.SectionSuffix[SectionType] + 'SEC' + SecNum\r
             OutputFile = os.path.join(self.OutputPath, GenSecOutputFile)\r
             \r
+            if not NoStrip:\r
+                FileBeforeStrip = os.path.join(self.OutputPath, ModuleName + '.reloc')\r
+                shutil.copyfile(File, FileBeforeStrip)\r
+                StrippedFile = os.path.join(self.OutputPath, ModuleName + '.stipped')\r
+                StripCmd = 'GenFw -l '    + \\r
+                           ' -o '         + \\r
+                            StrippedFile        + \\r
+                            ' '           + \\r
+                            GenFdsGlobalVariable.MacroExtend(File, Dict)\r
+                GenFdsGlobalVariable.CallExternalTool(StripCmd, "Strip Failed !")\r
+                File = StrippedFile\r
+            \r
+            if SectionType == 'TE':\r
+                TeFile = os.path.join( self.OutputPath, self.ModuleGuid + 'Te.raw')\r
+                GenTeCmd = 'GenFw -t '    + \\r
+                           ' -o '         + \\r
+                            TeFile        + \\r
+                            ' '           + \\r
+                           GenFdsGlobalVariable.MacroExtend(File, Dict)\r
+                GenFdsGlobalVariable.CallExternalTool(GenTeCmd, "GenFw Failed !")\r
+                GenSecInputFile = TeFile\r
+            \r
             GenSectionCmd = 'GenSec -o '                                + \\r
                              OutputFile                                 + \\r
                              ' -s '                                     + \\r
@@ -361,9 +424,9 @@ class FfsInfStatement(FfsInfStatementClassObject):
             # Call GenSection\r
             #\r
             GenFdsGlobalVariable.CallExternalTool(GenSectionCmd, "Gen section Failed!")\r
-            OutputFileList.append(GenSecOutputFile)\r
+            OutputFileList.append(OutputFile)\r
 \r
-        return OutputFile\r
+        return OutputFileList\r
     \r
     ## __GenSimpleFileFfs__() method\r
     #\r
@@ -422,6 +485,11 @@ class FfsInfStatement(FfsInfStatementClassObject):
     #   @retval string      File name of the generated section file\r
     #  \r
     def __GenComplexFileSection__(self, Rule):\r
+        \r
+        if self.ModuleType in ('SEC', 'PEI_CORE', 'PEIM'):\r
+            if Rule.KeepReloc != None:\r
+                self.KeepRelocFromRule = Rule.KeepReloc\r
+        \r
         SectFiles = ''\r
         Index = 1\r
         for Sect in Rule.SectionList:\r
@@ -480,7 +548,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
     #\r
     def __GetGenFfsCmdParameter__(self, Rule):\r
         FileType = ' -t ' + \\r
-                   Ffs.Ffs.FvTypeToFileType[Rule.FvType]\r
+                   Ffs.Ffs.FdfFvFileTypeToFileType[Rule.FvFileType]\r
         if Rule.Fixed != False:\r
             Fixed = ' -x '\r
         else :\r
index 70fedc0..7b6fa74 100644 (file)
@@ -146,30 +146,30 @@ class FV (FvClassObject):
                                        \r
         if BlockSize != None:\r
             self.FvInfFile.writelines("EFI_BLOCK_SIZE = " + \\r
-                                      '0x%x' %BlockSize    + \\r
+                                      '0x%X' %BlockSize    + \\r
                                       T_CHAR_LF)\r
             if BlockNum != None:\r
                 self.FvInfFile.writelines("EFI_NUM_BLOCKS   = "  + \\r
-                                      ' 0x%x' %BlockNum    + \\r
+                                      ' 0x%X' %BlockNum    + \\r
                                       T_CHAR_LF)\r
         else:\r
             for BlockSize in self.BlockSizeList :\r
                 if BlockSize[0] != None:\r
                     self.FvInfFile.writelines("EFI_BLOCK_SIZE  = "  + \\r
-                                          '0x%x' %BlockSize[0]    + \\r
+                                          '0x%X' %BlockSize[0]    + \\r
                                           T_CHAR_LF)\r
                 \r
                 if BlockSize[1] != None:                  \r
                     self.FvInfFile.writelines("EFI_NUM_BLOCKS   = "  + \\r
-                                          ' 0x%x' %BlockSize[1]    + \\r
+                                          ' 0x%X' %BlockSize[1]    + \\r
                                           T_CHAR_LF)\r
                                           \r
         if self.BsBaseAddress != None:\r
             self.FvInfFile.writelines('EFI_BOOT_DRIVER_BASE_ADDRESS = ' + \\r
-                                       '0x%x' %self.BsBaseAddress)\r
+                                       '0x%X' %self.BsBaseAddress)\r
         if self.RtBaseAddress != None:\r
             self.FvInfFile.writelines('EFI_RUNTIME_DRIVER_BASE_ADDRESS = ' + \\r
-                                      '0x%x' %self.RtBaseAddress)\r
+                                      '0x%X' %self.RtBaseAddress)\r
         #\r
         # Add attribute\r
         #\r
index 259b86d..0c43f09 100644 (file)
@@ -264,7 +264,7 @@ class GenFds :
         RuleComplexFile1.Arch = 'COMMON'\r
         RuleComplexFile1.CheckSum = True\r
         RuleComplexFile1.Fixed = True\r
-        RuleComplexFile1.FvType = "APPLICATION"\r
+        RuleComplexFile1.FvFileType = "APPLICATION"\r
         RuleComplexFile1.ModuleType = "UEFI_APPLICATION"\r
         RuleComplexFile1.NameGuid = "$(MODULE_NAME)"\r
         RuleComplexFile1.TemplateName = ''\r
index 804f4d4..8922942 100644 (file)
@@ -25,7 +25,7 @@ import os
 ## generate Region\r
 #\r
 #\r
-class region(RegionClassObject):\r
+class Region(RegionClassObject):\r
     \r
     ## The constructor\r
     #\r
@@ -52,8 +52,8 @@ class region(RegionClassObject):
 \r
     def AddToBuffer(self, Buffer, BaseAddress, BlockSizeList, ErasePolarity, FvBinDict, vtfDict = None, MacroDict = {}):\r
         Size = self.Size\r
-        GenFdsGlobalVariable.InfLogger('Generate Region')\r
-        GenFdsGlobalVariable.InfLogger("   Region Size = 0x%x" %Size)\r
+        GenFdsGlobalVariable.InfLogger('Generate Region at Offset 0x%X' % self.Offset)\r
+        GenFdsGlobalVariable.InfLogger("   Region Size = 0x%X" %Size)\r
         GenFdsGlobalVariable.SharpCounter = 0\r
         \r
         if self.RegionType == 'FV':\r
@@ -65,7 +65,7 @@ class region(RegionClassObject):
             RegionBlockNum = self.BlockNumOfRegion(RegionBlockSize)\r
             \r
             self.FvAddress = int(BaseAddress, 16) + self.Offset\r
-            FvBaseAddress = '0x%x' %self.FvAddress\r
+            FvBaseAddress = '0x%X' %self.FvAddress\r
                     \r
             for RegionData in self.RegionDataList:\r
                 \r
@@ -103,7 +103,7 @@ class region(RegionClassObject):
                         if FvObj.BlockSizeList[0][1] != None:\r
                             BlockNum = FvObj.BlockSizeList[0][1]\r
                     self.FvAddress = self.FvAddress + FvBuffer.len                    \r
-                    FvBaseAddress = '0x%x' %self.FvAddress\r
+                    FvBaseAddress = '0x%X' %self.FvAddress\r
                     FileName = FvObj.AddToBuffer(FvBuffer, FvBaseAddress, BlockSize, BlockNum, ErasePolarity, vtfDict)\r
                     \r
                     if FvBuffer.len > Size:\r
@@ -182,12 +182,12 @@ class region(RegionClassObject):
         BlockSize = 0\r
         for item in BlockSizeList:\r
             Offset = Offset + item[0]  * item[1]\r
-            GenFdsGlobalVariable.VerboseLogger ("Offset = 0x%x" %Offset)\r
-            GenFdsGlobalVariable.VerboseLogger ("self.Offset 0x%x" %self.Offset)\r
+            GenFdsGlobalVariable.VerboseLogger ("Offset = 0x%X" %Offset)\r
+            GenFdsGlobalVariable.VerboseLogger ("self.Offset 0x%X" %self.Offset)\r
 \r
             if self.Offset < Offset :\r
                 BlockSize = item[0]\r
-                GenFdsGlobalVariable.VerboseLogger ("BlockSize = %x" %BlockSize)\r
+                GenFdsGlobalVariable.VerboseLogger ("BlockSize = %X" %BlockSize)\r
                 return BlockSize\r
         return BlockSize\r
     \r
@@ -200,6 +200,6 @@ class region(RegionClassObject):
         if BlockSize == 0 :\r
             raise Exception ("Region: %s doesn't in Fd address scope !" %self.Offset)\r
         BlockNum = self.Size / BlockSize\r
-        GenFdsGlobalVariable.VerboseLogger ("BlockNum = 0x%x" %BlockNum)\r
+        GenFdsGlobalVariable.VerboseLogger ("BlockNum = 0x%X" %BlockNum)\r
         return BlockNum\r
                 \r