]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/GenFds/FfsInfStatement.py
BaseTools: Fix GenSec can't found the depex file
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / FfsInfStatement.py
index 864e5be7d9e078977e80fc55d2aec1bb926deebc..4b4781755dd41fb0199199a8e73109f5a93b0bde 100644 (file)
@@ -1,8 +1,8 @@
 ## @file\r
 # process FFS generation from INF statement\r
 #\r
-#  Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR>\r
-#  Copyright (c) 2014 Hewlett-Packard Development Company, L.P.<BR>\r
+#  Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2014-2016 Hewlett-Packard Development Company, L.P.<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
@@ -43,6 +43,9 @@ from AutoGen.GenDepex import DependencyExpression
 from PatchPcdValue.PatchPcdValue import PatchBinaryFile\r
 from Common.LongFilePathSupport import CopyLongFilePath\r
 from Common.LongFilePathSupport import OpenLongFilePath as open\r
+import Common.GlobalData as GlobalData\r
+from DepexSection import DepexSection\r
+from Common.Misc import SaveFileOnChange\r
 \r
 ## generate FFS from INF\r
 #\r
@@ -71,6 +74,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
         self.OverrideGuid = None\r
         self.PatchedBinFile = ''\r
         self.MacroDict = {}\r
+        self.Depex = False\r
 \r
     ## GetFinalTargetSuffixMap() method\r
     #\r
@@ -223,6 +227,9 @@ class FfsInfStatement(FfsInfStatementClassObject):
         if self.ModuleType == 'SMM_CORE' and int(self.PiSpecVersion, 16) < 0x0001000A:\r
             EdkLogger.error("GenFds", FORMAT_NOT_SUPPORTED, "SMM_CORE module type can't be used in the module with PI_SPECIFICATION_VERSION less than 0x0001000A", File=self.InfFileName)      \r
 \r
+        if self.ModuleType == 'MM_CORE_STANDALONE' and int(self.PiSpecVersion, 16) < 0x00010032:\r
+            EdkLogger.error("GenFds", FORMAT_NOT_SUPPORTED, "MM_CORE_STANDALONE module type can't be used in the module with PI_SPECIFICATION_VERSION less than 0x00010032", File=self.InfFileName)\r
+\r
         if Inf._Defs != None and len(Inf._Defs) > 0:\r
             self.OptRomDefs.update(Inf._Defs)\r
 \r
@@ -260,7 +267,16 @@ class FfsInfStatement(FfsInfStatementClassObject):
                 DefaultValue = FdfPcdDict[PcdKey]\r
                 FdfOverride = True\r
 \r
-            if not DscOverride and not FdfOverride:\r
+            # Override Patchable PCD value by the value from Build Option\r
+            BuildOptionOverride = False\r
+            if GlobalData.BuildOptionPcd:\r
+                for pcd in GlobalData.BuildOptionPcd:\r
+                    if PcdKey == (pcd[1], pcd[0]):\r
+                        DefaultValue = pcd[2]\r
+                        BuildOptionOverride = True\r
+                        break\r
+\r
+            if not DscOverride and not FdfOverride and not BuildOptionOverride:\r
                 continue\r
             # Check value, if value are equal, no need to patch\r
             if Pcd.DatumType == "VOID*":\r
@@ -307,6 +323,11 @@ class FfsInfStatement(FfsInfStatementClassObject):
         self.InfModule = Inf\r
         self.PcdIsDriver = Inf.PcdIsDriver\r
         self.IsBinaryModule = Inf.IsBinaryModule\r
+        Inf._GetDepex()\r
+        Inf._GetDepexExpression()\r
+        if len(Inf._Depex.data) > 0 and len(Inf._DepexExpression.data) > 0:\r
+            self.Depex = True\r
+\r
         GenFdsGlobalVariable.VerboseLogger("BaseName : %s" % self.BaseName)\r
         GenFdsGlobalVariable.VerboseLogger("ModuleGuid : %s" % self.ModuleGuid)\r
         GenFdsGlobalVariable.VerboseLogger("ModuleType : %s" % self.ModuleType)\r
@@ -322,7 +343,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
         if not os.path.exists(self.OutputPath) :\r
             os.makedirs(self.OutputPath)\r
 \r
-        self.EfiOutputPath = self.__GetEFIOutPutPath__()\r
+        self.EfiOutputPath, self.EfiDebugPath = self.__GetEFIOutPutPath__()\r
         GenFdsGlobalVariable.VerboseLogger( "ModuelEFIPath: " + self.EfiOutputPath)\r
 \r
     ## PatchEfiFile\r
@@ -401,12 +422,13 @@ class FfsInfStatement(FfsInfStatementClassObject):
     #   @param  FvParentAddr Parent Fv base address\r
     #   @retval string       Generated FFS file name\r
     #\r
-    def GenFfs(self, Dict = {}, FvChildAddr = [], FvParentAddr=None):\r
+    def GenFfs(self, Dict = {}, FvChildAddr = [], FvParentAddr=None, IsMakefile=False):\r
         #\r
         # Parse Inf file get Module related information\r
         #\r
 \r
         self.__InfParse__(Dict)\r
+        Arch = self.GetCurrentArch()\r
         SrcFile = mws.join( GenFdsGlobalVariable.WorkSpaceDir , self.InfFileName);\r
         DestFile = os.path.join( self.OutputPath, self.ModuleGuid + '.ffs')\r
         \r
@@ -438,7 +460,9 @@ class FfsInfStatement(FfsInfStatementClassObject):
         if len(self.BinFileList) > 0:\r
             if self.Rule == None or self.Rule == "":\r
                 self.Rule = "BINARY"\r
-                \r
+\r
+        if not IsMakefile and GenFdsGlobalVariable.EnableGenfdsMultiThread and self.Rule != 'BINARY':\r
+            IsMakefile = True\r
         #\r
         # Get the rule of how to generate Ffs file\r
         #\r
@@ -459,17 +483,19 @@ class FfsInfStatement(FfsInfStatementClassObject):
         #\r
         # For the rule only has simpleFile\r
         #\r
+        MakefilePath = None\r
+        if IsMakefile:\r
+            MakefilePath = self.InfFileName, Arch\r
         if isinstance (Rule, RuleSimpleFile.RuleSimpleFile) :\r
-            SectionOutputList = self.__GenSimpleFileSection__(Rule)\r
-            FfsOutput = self.__GenSimpleFileFfs__(Rule, SectionOutputList)\r
+            SectionOutputList = self.__GenSimpleFileSection__(Rule, IsMakefile=IsMakefile)\r
+            FfsOutput = self.__GenSimpleFileFfs__(Rule, SectionOutputList, MakefilePath=MakefilePath)\r
             return FfsOutput\r
         #\r
         # For Rule has ComplexFile\r
         #\r
         elif isinstance(Rule, RuleComplexFile.RuleComplexFile):\r
-            InputSectList, InputSectAlignments = self.__GenComplexFileSection__(Rule, FvChildAddr, FvParentAddr)\r
-            FfsOutput = self.__GenComplexFileFfs__(Rule, InputSectList, InputSectAlignments)\r
-\r
+            InputSectList, InputSectAlignments = self.__GenComplexFileSection__(Rule, FvChildAddr, FvParentAddr, IsMakefile=IsMakefile)\r
+            FfsOutput = self.__GenComplexFileFfs__(Rule, InputSectList, InputSectAlignments, MakefilePath=MakefilePath)\r
             return FfsOutput\r
 \r
     ## __ExtendMacro__() method\r
@@ -555,35 +581,21 @@ class FfsInfStatement(FfsInfStatementClassObject):
 \r
         InfFileKey = os.path.normpath(mws.join(GenFdsGlobalVariable.WorkSpaceDir, self.InfFileName))\r
         DscArchList = []\r
-        PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'IA32', GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
-        if  PlatformDataBase != None:\r
-            if InfFileKey in PlatformDataBase.Modules:\r
-                DscArchList.append ('IA32')\r
-\r
-        PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'X64', GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
-        if  PlatformDataBase != None:\r
-            if InfFileKey in PlatformDataBase.Modules:\r
-                DscArchList.append ('X64')\r
-\r
-        PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'IPF', GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
-        if PlatformDataBase != None:\r
-            if InfFileKey in (PlatformDataBase.Modules):\r
-                DscArchList.append ('IPF')\r
-\r
-        PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'ARM', GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
-        if PlatformDataBase != None:\r
-            if InfFileKey in (PlatformDataBase.Modules):\r
-                DscArchList.append ('ARM')\r
-\r
-        PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'EBC', GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
-        if PlatformDataBase != None:\r
-            if InfFileKey in (PlatformDataBase.Modules):\r
-                DscArchList.append ('EBC')\r
-\r
-        PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'AARCH64', GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
-        if PlatformDataBase != None:\r
-            if InfFileKey in (PlatformDataBase.Modules):\r
-                DscArchList.append ('AARCH64')\r
+        for Arch in GenFdsGlobalVariable.ArchList :\r
+            PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
+            if  PlatformDataBase != None:\r
+                if InfFileKey in PlatformDataBase.Modules:\r
+                    DscArchList.append (Arch)\r
+                else:\r
+                    #\r
+                    # BaseTools support build same module more than once, the module path with FILE_GUID overridden has\r
+                    # the file name FILE_GUIDmodule.inf, then PlatformDataBase.Modules use FILE_GUIDmodule.inf as key,\r
+                    # but the path (self.MetaFile.Path) is the real path\r
+                    #\r
+                    for key in PlatformDataBase.Modules.keys():\r
+                        if InfFileKey == str((PlatformDataBase.Modules[key]).MetaFile.Path):\r
+                            DscArchList.append (Arch)\r
+                            break\r
 \r
         return DscArchList\r
 \r
@@ -652,6 +664,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
     def __GetEFIOutPutPath__(self):\r
         Arch = ''\r
         OutputPath = ''\r
+        DebugPath = ''\r
         (ModulePath, FileName) = os.path.split(self.InfFileName)\r
         Index = FileName.rfind('.')\r
         FileName = FileName[0:Index]\r
@@ -667,8 +680,15 @@ class FfsInfStatement(FfsInfStatementClassObject):
                                   FileName,\r
                                   'OUTPUT'\r
                                   )\r
+        DebugPath = os.path.join(GenFdsGlobalVariable.OutputDirDict[Arch],\r
+                                  Arch ,\r
+                                  ModulePath,\r
+                                  FileName,\r
+                                  'DEBUG'\r
+                                  )\r
         OutputPath = os.path.realpath(OutputPath)\r
-        return OutputPath\r
+        DebugPath = os.path.realpath(DebugPath)\r
+        return OutputPath, DebugPath\r
 \r
     ## __GenSimpleFileSection__() method\r
     #\r
@@ -678,7 +698,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
     #   @param  Rule        The rule object used to generate section\r
     #   @retval string      File name of the generated section file\r
     #\r
-    def __GenSimpleFileSection__(self, Rule):\r
+    def __GenSimpleFileSection__(self, Rule, IsMakefile = False):\r
         #\r
         # Prepare the parameter of GenSection\r
         #\r
@@ -732,8 +752,10 @@ class FfsInfStatement(FfsInfStatementClassObject):
                     ImageObj = PeImageClass (File)\r
                     if ImageObj.SectionAlignment < 0x400:\r
                         self.Alignment = str (ImageObj.SectionAlignment)\r
-                    else:\r
+                    elif ImageObj.SectionAlignment < 0x100000:\r
                         self.Alignment = str (ImageObj.SectionAlignment / 0x400) + 'K'\r
+                    else:\r
+                        self.Alignment = str (ImageObj.SectionAlignment / 0x100000) + 'M'\r
 \r
                 if not NoStrip:\r
                     FileBeforeStrip = os.path.join(self.OutputPath, ModuleName + '.reloc')\r
@@ -742,22 +764,23 @@ class FfsInfStatement(FfsInfStatementClassObject):
                         CopyLongFilePath(File, FileBeforeStrip)\r
                     StrippedFile = os.path.join(self.OutputPath, ModuleName + '.stipped')\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
                 if SectionType == 'TE':\r
                     TeFile = os.path.join( self.OutputPath, self.ModuleGuid + '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
-                GenFdsGlobalVariable.GenerateSection(OutputFile, [File], Section.Section.SectionType[SectionType])\r
+                GenFdsGlobalVariable.GenerateSection(OutputFile, [File], Section.Section.SectionType[SectionType], IsMakefile=IsMakefile)\r
                 OutputFileList.append(OutputFile)\r
         else:\r
             SecNum = '%d' %Index\r
@@ -771,8 +794,10 @@ class FfsInfStatement(FfsInfStatementClassObject):
                 ImageObj = PeImageClass (GenSecInputFile)\r
                 if ImageObj.SectionAlignment < 0x400:\r
                     self.Alignment = str (ImageObj.SectionAlignment)\r
-                else:\r
+                elif ImageObj.SectionAlignment < 0x100000:\r
                     self.Alignment = str (ImageObj.SectionAlignment / 0x400) + 'K'\r
+                else:\r
+                    self.Alignment = str (ImageObj.SectionAlignment / 0x100000) + 'M'\r
 \r
             if not NoStrip:\r
                 FileBeforeStrip = os.path.join(self.OutputPath, ModuleName + '.reloc')\r
@@ -782,22 +807,23 @@ class FfsInfStatement(FfsInfStatementClassObject):
 \r
                 StrippedFile = os.path.join(self.OutputPath, ModuleName + '.stipped')\r
                 GenFdsGlobalVariable.GenerateFirmwareImage(\r
-                                        StrippedFile,\r
-                                        [GenSecInputFile],\r
-                                        Strip=True\r
-                                        )\r
+                        StrippedFile,\r
+                        [GenSecInputFile],\r
+                        Strip=True,\r
+                        IsMakefile=IsMakefile\r
+                    )\r
                 GenSecInputFile = StrippedFile\r
 \r
             if SectionType == 'TE':\r
                 TeFile = os.path.join( self.OutputPath, self.ModuleGuid + 'Te.raw')\r
                 GenFdsGlobalVariable.GenerateFirmwareImage(\r
-                                        TeFile,\r
-                                        [GenSecInputFile],\r
-                                        Type='te'\r
-                                        )\r
+                        TeFile,\r
+                        [GenSecInputFile],\r
+                        Type='te',\r
+                        IsMakefile=IsMakefile\r
+                    )\r
                 GenSecInputFile = TeFile\r
-\r
-            GenFdsGlobalVariable.GenerateSection(OutputFile, [GenSecInputFile], Section.Section.SectionType[SectionType])\r
+            GenFdsGlobalVariable.GenerateSection(OutputFile, [GenSecInputFile], Section.Section.SectionType[SectionType], IsMakefile=IsMakefile)\r
             OutputFileList.append(OutputFile)\r
 \r
         return OutputFileList\r
@@ -811,7 +837,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
     #   @param  InputFileList        The output file list from GenSection\r
     #   @retval string      Generated FFS file name\r
     #\r
-    def __GenSimpleFileFfs__(self, Rule, InputFileList):\r
+    def __GenSimpleFileFfs__(self, Rule, InputFileList, MakefilePath = None):\r
         FfsOutput = self.OutputPath                     + \\r
                     os.sep                              + \\r
                     self.__ExtendMacro__(Rule.NameGuid) + \\r
@@ -837,12 +863,13 @@ class FfsInfStatement(FfsInfStatementClassObject):
                             % (Rule.NameGuid))\r
             self.ModuleGuid = RegistryGuidStr\r
 \r
-        GenFdsGlobalVariable.GenerateFfs(FfsOutput, InputSection,\r
-                                         Ffs.Ffs.FdfFvFileTypeToFileType[Rule.FvFileType],\r
-                                         self.ModuleGuid, Fixed=Rule.Fixed,\r
-                                         CheckSum=Rule.CheckSum, Align=Rule.Alignment,\r
-                                         SectionAlign=SectionAlignments\r
-                                        )\r
+            GenFdsGlobalVariable.GenerateFfs(FfsOutput, InputSection,\r
+                                             Ffs.Ffs.FdfFvFileTypeToFileType[Rule.FvFileType],\r
+                                             self.ModuleGuid, Fixed=Rule.Fixed,\r
+                                             CheckSum=Rule.CheckSum, Align=Rule.Alignment,\r
+                                             SectionAlign=SectionAlignments,\r
+                                             MakefilePath=MakefilePath\r
+                                             )\r
         return FfsOutput\r
 \r
     ## __GenComplexFileSection__() method\r
@@ -855,14 +882,14 @@ class FfsInfStatement(FfsInfStatementClassObject):
     #   @param  FvParentAddr Parent Fv base address\r
     #   @retval string       File name of the generated section file\r
     #\r
-    def __GenComplexFileSection__(self, Rule, FvChildAddr, FvParentAddr):\r
+    def __GenComplexFileSection__(self, Rule, FvChildAddr, FvParentAddr, IsMakefile = False):\r
         if self.ModuleType in ('SEC', 'PEI_CORE', 'PEIM'):\r
             if Rule.KeepReloc != None:\r
                 self.KeepRelocFromRule = Rule.KeepReloc\r
         SectFiles = []\r
         SectAlignments = []\r
         Index = 1\r
-        HasGneratedFlag = False\r
+        HasGeneratedFlag = False\r
         if self.PcdIsDriver == 'PEI_PCD_DRIVER':\r
             if self.IsBinaryModule:\r
                 PcdExDbFileName = os.path.join(GenFdsGlobalVariable.FvDir, "PEIPcdDataBase.raw")\r
@@ -872,6 +899,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
             GenFdsGlobalVariable.GenerateSection(PcdExDbSecName,\r
                                                  [PcdExDbFileName],\r
                                                  "EFI_SECTION_RAW",\r
+                                                 IsMakefile = IsMakefile\r
                                                  )\r
             SectFiles.append(PcdExDbSecName)\r
             SectAlignments.append(None)\r
@@ -882,9 +910,10 @@ class FfsInfStatement(FfsInfStatementClassObject):
                 PcdExDbFileName = os.path.join(self.EfiOutputPath, "DXEPcdDataBase.raw")\r
             PcdExDbSecName = os.path.join(self.OutputPath, "DXEPcdDataBaseSec.raw")\r
             GenFdsGlobalVariable.GenerateSection(PcdExDbSecName,\r
-                                                 [PcdExDbFileName],\r
-                                                 "EFI_SECTION_RAW",\r
-                                                 )\r
+                                                [PcdExDbFileName],\r
+                                                "EFI_SECTION_RAW",\r
+                                                IsMakefile = IsMakefile\r
+                                                )\r
             SectFiles.append(PcdExDbSecName)\r
             SectAlignments.append(None)\r
         for Sect in Rule.SectionList:\r
@@ -914,11 +943,11 @@ class FfsInfStatement(FfsInfStatementClassObject):
                 Sect.FvParentAddr = FvParentAddr\r
             \r
             if Rule.KeyStringList != []:\r
-                SectList, Align = Sect.GenSection(self.OutputPath , self.ModuleGuid, SecIndex, Rule.KeyStringList, self)\r
+                SectList, Align = Sect.GenSection(self.OutputPath , self.ModuleGuid, SecIndex, Rule.KeyStringList, self, IsMakefile = IsMakefile)\r
             else :\r
-                SectList, Align = Sect.GenSection(self.OutputPath , self.ModuleGuid, SecIndex, self.KeyStringList, self)\r
+                SectList, Align = Sect.GenSection(self.OutputPath , self.ModuleGuid, SecIndex, self.KeyStringList, self, IsMakefile = IsMakefile)\r
             \r
-            if not HasGneratedFlag:\r
+            if not HasGeneratedFlag:\r
                 UniVfrOffsetFileSection = ""    \r
                 ModuleFileName = mws.join(GenFdsGlobalVariable.WorkSpaceDir, self.InfFileName)\r
                 InfData = GenFdsGlobalVariable.WorkSpace.BuildObject[PathClass(ModuleFileName), self.CurrentArch]\r
@@ -941,26 +970,40 @@ class FfsInfStatement(FfsInfStatementClassObject):
                     \r
                 \r
                 if len(VfrUniBaseName) > 0:\r
-                    VfrUniOffsetList = self.__GetBuildOutputMapFileVfrUniInfo(VfrUniBaseName)\r
-                    #\r
-                    # Generate the Raw data of raw section\r
-                    #\r
-                    os.path.join( self.OutputPath, self.BaseName + '.offset')\r
-                    UniVfrOffsetFileName    =  os.path.join( self.OutputPath, self.BaseName + '.offset')\r
-                    UniVfrOffsetFileSection =  os.path.join( self.OutputPath, self.BaseName + 'Offset' + '.raw')\r
-                    \r
-                    self.__GenUniVfrOffsetFile (VfrUniOffsetList, UniVfrOffsetFileName)\r
-                    \r
-                    UniVfrOffsetFileNameList = []\r
-                    UniVfrOffsetFileNameList.append(UniVfrOffsetFileName)\r
-                    """Call GenSection"""\r
-                    GenFdsGlobalVariable.GenerateSection(UniVfrOffsetFileSection,\r
-                                                         UniVfrOffsetFileNameList,\r
-                                                         "EFI_SECTION_RAW"\r
-                                                         )\r
-                    os.remove(UniVfrOffsetFileName)         \r
-                    SectList.append(UniVfrOffsetFileSection)\r
-                    HasGneratedFlag = True\r
+                    if IsMakefile:\r
+                        if InfData.BuildType != 'UEFI_HII':\r
+                            UniVfrOffsetFileName = os.path.join(self.OutputPath, self.BaseName + '.offset')\r
+                            UniVfrOffsetFileSection = os.path.join(self.OutputPath, self.BaseName + 'Offset' + '.raw')\r
+                            UniVfrOffsetFileNameList = []\r
+                            UniVfrOffsetFileNameList.append(UniVfrOffsetFileName)\r
+                            TrimCmd = "Trim --Vfr-Uni-Offset -o %s --ModuleName=%s --DebugDir=%s " % (UniVfrOffsetFileName, self.BaseName, self.EfiDebugPath)\r
+                            GenFdsGlobalVariable.SecCmdList.append(TrimCmd)\r
+                            GenFdsGlobalVariable.GenerateSection(UniVfrOffsetFileSection,\r
+                                                                [UniVfrOffsetFileName],\r
+                                                                "EFI_SECTION_RAW",\r
+                                                                IsMakefile = True\r
+                                                                )\r
+                    else:\r
+                        VfrUniOffsetList = self.__GetBuildOutputMapFileVfrUniInfo(VfrUniBaseName)\r
+                        #\r
+                        # Generate the Raw data of raw section\r
+                        #\r
+                        if VfrUniOffsetList:\r
+                            UniVfrOffsetFileName = os.path.join(self.OutputPath, self.BaseName + '.offset')\r
+                            UniVfrOffsetFileSection = os.path.join(self.OutputPath, self.BaseName + 'Offset' + '.raw')\r
+                            self.__GenUniVfrOffsetFile (VfrUniOffsetList, UniVfrOffsetFileName)\r
+                            UniVfrOffsetFileNameList = []\r
+                            UniVfrOffsetFileNameList.append(UniVfrOffsetFileName)\r
+                            """Call GenSection"""\r
+\r
+                            GenFdsGlobalVariable.GenerateSection(UniVfrOffsetFileSection,\r
+                                                                 UniVfrOffsetFileNameList,\r
+                                                                 "EFI_SECTION_RAW"\r
+                                                                 )\r
+                            #os.remove(UniVfrOffsetFileName)\r
+                    if UniVfrOffsetFileSection:\r
+                        SectList.append(UniVfrOffsetFileSection)\r
+                        HasGeneratedFlag = True\r
                 \r
             for SecName in  SectList :\r
                 SectFiles.append(SecName)\r
@@ -977,7 +1020,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
     #   @param  InputFileList        The output file list from GenSection\r
     #   @retval string      Generated FFS file name\r
     #\r
-    def __GenComplexFileFfs__(self, Rule, InputFile, Alignments):\r
+    def __GenComplexFileFfs__(self, Rule, InputFile, Alignments, MakefilePath = None):\r
 \r
         if Rule.NameGuid != None and Rule.NameGuid.startswith('PCD('):\r
             PcdValue = GenFdsGlobalVariable.GetPcdValue(Rule.NameGuid)\r
@@ -994,11 +1037,12 @@ class FfsInfStatement(FfsInfStatementClassObject):
 \r
         FfsOutput = os.path.join( self.OutputPath, self.ModuleGuid + '.ffs')\r
         GenFdsGlobalVariable.GenerateFfs(FfsOutput, InputFile,\r
-                                         Ffs.Ffs.FdfFvFileTypeToFileType[Rule.FvFileType],\r
-                                         self.ModuleGuid, Fixed=Rule.Fixed,\r
-                                         CheckSum=Rule.CheckSum, Align=Rule.Alignment,\r
-                                         SectionAlign=Alignments\r
-                                        )\r
+                                             Ffs.Ffs.FdfFvFileTypeToFileType[Rule.FvFileType],\r
+                                             self.ModuleGuid, Fixed=Rule.Fixed,\r
+                                             CheckSum=Rule.CheckSum, Align=Rule.Alignment,\r
+                                             SectionAlign=Alignments,\r
+                                             MakefilePath=MakefilePath\r
+                                             )\r
         return FfsOutput\r
 \r
     ## __GetGenFfsCmdParameter__() method\r
@@ -1044,12 +1088,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
     #   @param  UniVfrOffsetFileName    The output offset file name.\r
     #\r
     def __GenUniVfrOffsetFile(self, VfrUniOffsetList, UniVfrOffsetFileName):\r
-        \r
-        try:\r
-            fInputfile = open(UniVfrOffsetFileName, "wb+", 0)\r
-        except:\r
-            EdkLogger.error("GenFds", FILE_OPEN_FAILURE, "File open failed for %s" %UniVfrOffsetFileName,None)\r
-            \r
+\r
         # Use a instance of StringIO to cache data\r
         fStringIO = StringIO.StringIO('')  \r
         \r
@@ -1081,18 +1120,11 @@ class FfsInfStatement(FfsInfStatementClassObject):
         #\r
         # write data into file.\r
         #\r
-        try :  \r
-            fInputfile.write (fStringIO.getvalue())\r
+        try :\r
+            SaveFileOnChange(UniVfrOffsetFileName, fStringIO.getvalue())\r
         except:\r
             EdkLogger.error("GenFds", FILE_WRITE_FAILURE, "Write data to file %s failed, please check whether the file been locked or using by other applications." %UniVfrOffsetFileName,None)\r
         \r
         fStringIO.close ()\r
-        fInputfile.close ()\r
-        \r
-                \r
-                    \r
-            \r
-            \r
-        \r
-                                \r
+\r
         \r