Support incremental build
authorjwang36 <jwang36@7335b38e-4728-0410-8992-fb3ffe349368>
Fri, 9 May 2008 08:52:09 +0000 (08:52 +0000)
committerjwang36 <jwang36@7335b38e-4728-0410-8992-fb3ffe349368>
Fri, 9 May 2008 08:52:09 +0000 (08:52 +0000)
git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@1203 7335b38e-4728-0410-8992-fb3ffe349368

16 files changed:
Source/Python/GenFds/AprioriSection.py
Source/Python/GenFds/Capsule.py
Source/Python/GenFds/CompressSection.py
Source/Python/GenFds/DataSection.py
Source/Python/GenFds/DepexSection.py
Source/Python/GenFds/EfiSection.py
Source/Python/GenFds/FfsFileStatement.py
Source/Python/GenFds/FfsInfStatement.py
Source/Python/GenFds/Fv.py
Source/Python/GenFds/FvImageSection.py
Source/Python/GenFds/GenFdsGlobalVariable.py
Source/Python/GenFds/GuidSection.py
Source/Python/GenFds/Region.py
Source/Python/GenFds/Section.py
Source/Python/GenFds/UiSection.py
Source/Python/GenFds/VerSection.py

index f1e60ec..bd8bb9f 100755 (executable)
@@ -22,6 +22,7 @@ import FfsFileStatement
 from GenFdsGlobalVariable import GenFdsGlobalVariable\r
 from CommonDataClass.FdfClass import AprioriSectionClassObject\r
 from Common.String import *\r
+from Common.Misc import SaveFileOnChange\r
 from Common import EdkLogger\r
 from Common.BuildToolError import *\r
 \r
@@ -64,10 +65,7 @@ class AprioriSection (AprioriSectionClassObject):
         AprFfsFileName = os.path.join (OutputAprFilePath,\\r
                                     AprioriFileGuid + FvName + '.Ffs')\r
 \r
-        OutputAprFile = open(OutputAprFileName, 'w+b')\r
-\r
         Dict.update(self.DefineVarDict)\r
-\r
         for FfsObj in self.FfsList :\r
             Guid = ""\r
             if isinstance(FfsObj, FfsFileStatement.FileStatement):\r
@@ -108,28 +106,13 @@ class AprioriSection (AprioriSectionClassObject):
                 Char = GuidPart[4][Num*2:Num*2+2]\r
                 Buffer.write(pack('B', int(Char, 16)))\r
 \r
-        OutputAprFile.write(Buffer.getvalue())\r
-        OutputAprFile.close()\r
+        SaveFileOnChange(OutputAprFileName, Buffer.getvalue())\r
+\r
         RawSectionFileName = os.path.join( OutputAprFilePath, \\r
                                        AprioriFileGuid + FvName + '.raw' )\r
+        GenFdsGlobalVariable.GenerateSection(RawSectionFileName, [OutputAprFileName], 'EFI_SECTION_RAW')\r
+        GenFdsGlobalVariable.GenerateFfs(AprFfsFileName, [RawSectionFileName],\r
+                                         'EFI_FV_FILETYPE_FREEFORM', AprioriFileGuid)\r
 \r
-        GenSectionCmd = (\r
-            'GenSec',\r
-            '-o', RawSectionFileName,\r
-            '-s', 'EFI_SECTION_RAW',\r
-            OutputAprFileName,\r
-            )\r
-\r
-        GenFdsGlobalVariable.CallExternalTool(GenSectionCmd, "GenSection Failed!")\r
-\r
-        GenFfsCmd = (\r
-            'GenFfs',\r
-            '-t', 'EFI_FV_FILETYPE_FREEFORM',\r
-            '-g', AprioriFileGuid,\r
-            '-o', AprFfsFileName,\r
-            '-i', RawSectionFileName,\r
-            )\r
-\r
-        GenFdsGlobalVariable.CallExternalTool(GenFfsCmd,"GenFfs Failed !")\r
         return AprFfsFileName\r
 \r
index a05ec97..dfd4110 100755 (executable)
@@ -33,10 +33,10 @@ class Capsule (CapsuleClassObject) :
     def __init__(self):\r
         CapsuleClassObject.__init__(self)\r
         # For GenFv\r
-        self.BlockSize = None          \r
+        self.BlockSize = None\r
         # For GenFv\r
-        self.BlockNum = None           \r
-        \r
+        self.BlockNum = None\r
+\r
     ## Generate capsule\r
     #\r
     #   @param  self        The object pointer\r
@@ -44,7 +44,7 @@ class Capsule (CapsuleClassObject) :
     def GenCapsule(self):\r
         CapInfFile = self.GenCapInf()\r
         CapInfFile.writelines("[files]" + T_CHAR_LF)\r
-        \r
+\r
         for CapsuleDataObj in self.CapsuleDataList :\r
             FileName = CapsuleDataObj.GenCapsuleSubItem()\r
             CapInfFile.writelines("EFI_FILE_NAME = " + \\r
@@ -56,13 +56,11 @@ class Capsule (CapsuleClassObject) :
         #\r
         CapOutputFile = os.path.join(GenFdsGlobalVariable.FvDir, self.UiCapsuleName)\r
         CapOutputFile = CapOutputFile + '.Cap'\r
-        Cmd = (\r
-            'GenFv',\r
-            '-i', self.CapInfFileName,\r
-            '-o', CapOutputFile,\r
-            '-c',\r
-            )\r
-        GenFdsGlobalVariable.CallExternalTool(Cmd, "GefFv GenCapsule Failed!")\r
+        GenFdsGlobalVariable.GenerateFirmwareVolume(\r
+                                CapOutputFile,\r
+                                [self.CapInfFileName],\r
+                                Capsule=True\r
+                                )\r
         GenFdsGlobalVariable.SharpCounter = 0\r
 \r
     ## Generate inf file for capsule\r
@@ -74,9 +72,9 @@ class Capsule (CapsuleClassObject) :
         self.CapInfFileName = os.path.join(GenFdsGlobalVariable.FvDir,\r
                                    self.UiCapsuleName +  "_Cap" + '.inf')\r
         CapInfFile = open (self.CapInfFileName , 'w+')\r
-        \r
+\r
         CapInfFile.writelines("[options]" + T_CHAR_LF)\r
-                              \r
+\r
         for Item in self.TokensDict.keys():\r
             CapInfFile.writelines("EFI_"                    + \\r
                                   Item                      + \\r
index 18fad05..4a32ea4 100755 (executable)
@@ -26,20 +26,20 @@ from CommonDataClass.FdfClass import CompressSectionClassObject
 #\r
 #\r
 class CompressSection (CompressSectionClassObject) :\r
-    \r
-    ## compress types: PI standard and non PI standard    \r
+\r
+    ## compress types: PI standard and non PI standard\r
     CompTypeDict = {\r
         'PI_STD'     : 'PI_STD',\r
         'NON_PI_STD' : 'NON_PI_STD'\r
     }\r
-    \r
+\r
     ## The constructor\r
     #\r
     #   @param  self        The object pointer\r
     #\r
     def __init__(self):\r
         CompressSectionClassObject.__init__(self)\r
-        \r
+\r
     ## GenSection() method\r
     #\r
     #   Generate compressed section\r
@@ -54,11 +54,11 @@ class CompressSection (CompressSectionClassObject) :
     #   @retval tuple       (Generated file name, section alignment)\r
     #\r
     def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = {}):\r
-        \r
+\r
         if FfsInf != None:\r
             self.CompType = FfsInf.__ExtendMacro__(self.CompType)\r
             self.Alignment = FfsInf.__ExtendMacro__(self.Alignment)\r
-            \r
+\r
         SectFiles = tuple()\r
         Index = 0\r
         for Sect in self.SectionList:\r
@@ -68,7 +68,7 @@ class CompressSection (CompressSectionClassObject) :
             if ReturnSectList != []:\r
                 for FileData in ReturnSectList:\r
                    SectFiles += (FileData,)\r
-                        \r
+\r
 \r
         OutputFile = OutputPath + \\r
                      os.sep     + \\r
@@ -77,19 +77,11 @@ class CompressSection (CompressSectionClassObject) :
                      SecNum     + \\r
                      Ffs.SectionSuffix['COMPRESS']\r
         OutputFile = os.path.normpath(OutputFile)\r
-        \r
-        GenSectionCmd = (\r
-            'GenSec',\r
-             '-o', OutputFile,\r
-             '-s', Section.Section.SectionType['COMPRESS'],\r
-             '-c', self.CompTypeDict[self.CompType],\r
-            ) + SectFiles\r
-        #\r
-        # Call GenSection\r
-        #\r
-        GenFdsGlobalVariable.CallExternalTool(GenSectionCmd, "GenSection Failed!")\r
+\r
+        GenFdsGlobalVariable.GenerateSection(OutputFile, SectFiles, Section.Section.SectionType['COMPRESS'],\r
+                                             CompressionType=self.CompTypeDict[self.CompType])\r
         OutputFileList = []\r
         OutputFileList.append(OutputFile)\r
         return OutputFileList, self.Alignment\r
 \r
-        \r
+\r
index d7bc8c3..7f24b51 100644 (file)
@@ -52,8 +52,6 @@ class DataSection (DataSectionClassObject):
         # Prepare the parameter of GenSection\r
         #\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
             self.SectFileName = GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict, FfsFile.CurrentArch)\r
         else:\r
@@ -72,9 +70,9 @@ class DataSection (DataSectionClassObject):
             MapFile = Filename.replace('.efi', '.map')\r
             if os.path.exists(MapFile):\r
                 CopyMapFile = os.path.join(OutputPath, ModuleName + '.map')\r
-                if os.path.exists(CopyMapFile):\r
-                    os.remove(CopyMapFile)\r
-                shutil.copyfile(MapFile, CopyMapFile)\r
+                if not os.path.exists(CopyMapFile) or \\r
+                    (os.path.getmtime(MapFile) > os.path.getmtime(CopyMapFile)):\r
+                    shutil.copyfile(MapFile, CopyMapFile)\r
 \r
         NoStrip = True\r
         if self.SecType in ('TE', 'PE32'):\r
@@ -83,44 +81,29 @@ class DataSection (DataSectionClassObject):
 \r
         if not NoStrip:\r
             FileBeforeStrip = os.path.join(OutputPath, ModuleName + '.efi')\r
-            if os.path.exists(FileBeforeStrip):\r
-                os.remove(FileBeforeStrip)\r
-            shutil.copyfile(self.SectFileName, FileBeforeStrip)\r
+            if not os.path.exists(FileBeforeStrip) or \\r
+                (os.path.getmtime(self.SectFileName) > os.path.getmtime(FileBeforeStrip)):\r
+                shutil.copyfile(self.SectFileName, FileBeforeStrip)\r
             StrippedFile = os.path.join(OutputPath, ModuleName + '.stripped')\r
-            StripCmd = (\r
-                'GenFw',\r
-                '-l',\r
-                '-o', StrippedFile,\r
-                GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict),\r
-                )\r
-            GenFdsGlobalVariable.CallExternalTool(StripCmd, "Strip Failed !")\r
+            GenFdsGlobalVariable.GenerateFirmwareImage(\r
+                                    StrippedFile,\r
+                                    [GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict)],\r
+                                    Strip=True\r
+                                    )\r
             self.SectFileName = StrippedFile\r
 \r
         if self.SecType == 'TE':\r
             TeFile = os.path.join( OutputPath, ModuleName + 'Te.raw')\r
-            GenTeCmd = (\r
-                'GenFw',\r
-                '-t',\r
-                '-o', TeFile,\r
-                GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict),\r
-                )\r
-            GenFdsGlobalVariable.CallExternalTool(GenTeCmd, "GenFw Failed !")\r
+            GenFdsGlobalVariable.GenerateFirmwareImage(\r
+                                    TeFile,\r
+                                    [GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict)],\r
+                                    Type='te'\r
+                                    )\r
             self.SectFileName = TeFile\r
 \r
         OutputFile = os.path.join (OutputPath, ModuleName + 'SEC' + SecNum + Ffs.SectionSuffix.get(self.SecType))\r
         OutputFile = os.path.normpath(OutputFile)\r
 \r
-        GenSectionCmd = (\r
-            'GenSec',\r
-             '-o', OutputFile,\r
-             '-s', Section.Section.SectionType.get (self.SecType),\r
-             self.SectFileName,\r
-            )\r
-\r
-        #\r
-        # Call GenSection\r
-        #\r
-\r
-        GenFdsGlobalVariable.CallExternalTool(GenSectionCmd, "GenSection Failed!")\r
+        GenFdsGlobalVariable.GenerateSection(OutputFile, [self.SectFileName], Section.Section.SectionType.get(self.SecType))\r
         FileList = [OutputFile]\r
         return FileList, self.Alignment\r
index bf57aff..32875e3 100644 (file)
@@ -91,17 +91,6 @@ class DepexSection (DepexSectionClassObject):
         OutputFile = os.path.normpath(OutputFile)\r
         SecType = (self.DepexType.startswith('PEI') and ['PEI_DEPEX'] or ['DXE_DEPEX'])[0]\r
 \r
-        GenSectionCmd = (\r
-            'GenSec',\r
-             '-o', OutputFile,\r
-             '-s', Section.Section.SectionType.get (SecType),\r
-             InputFile,\r
-            )\r
-\r
-        #\r
-        # Call GenSection\r
-        #\r
-\r
-        GenFdsGlobalVariable.CallExternalTool(GenSectionCmd, "GenSection Failed!")\r
+        GenFdsGlobalVariable.GenerateSection(OutputFile, [InputFile], Section.Section.SectionType.get (SecType))\r
         FileList = [OutputFile]\r
         return FileList, self.Alignment\r
index b2eb47d..08dd480 100644 (file)
@@ -104,12 +104,8 @@ class EfiSection (EfiSectionClassObject):
 \r
                 Num = SecNum\r
                 OutputFile = os.path.join( OutputPath, ModuleName + 'SEC' + str(Num) + Ffs.SectionSuffix.get(SectionType))\r
-                GenSectionCmd = (\r
-                    'GenSec',\r
-                    '-o', OutputFile,\r
-                    '-s', 'EFI_SECTION_VERSION',\r
-                    ) + VerTuple + BuildNumTuple\r
-                GenFdsGlobalVariable.CallExternalTool(GenSectionCmd, "GenSection Failed !")\r
+                GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_VERSION',\r
+                                                     Ui=StringData, Ver=BuildNum)\r
                 OutputFileList.append(OutputFile)\r
 \r
             elif FileList != []:\r
@@ -123,12 +119,8 @@ class EfiSection (EfiSectionClassObject):
                     VerTuple = ('-n', '"' + VerString + '"')\r
                     if BuildNum != None and BuildNum != '':\r
                         BuildNumTuple = ('-j', BuildNum)\r
-                    GenSectionCmd = (\r
-                        'GenSec',\r
-                        '-o', OutputFile,\r
-                        '-s', 'EFI_SECTION_VERSION',\r
-                        ) + VerTuple + BuildNumTuple\r
-                    GenFdsGlobalVariable.CallExternalTool(GenSectionCmd, "GenSection Failed !")\r
+                    GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_VERSION',\r
+                                                         Ui=VerString, Ver=BuildNum)\r
                     OutputFileList.append(OutputFile)\r
 \r
             else:\r
@@ -152,12 +144,8 @@ class EfiSection (EfiSectionClassObject):
                         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
-                GenSectionCmd = (\r
-                    'GenSec',\r
-                    '-o', OutputFile,\r
-                    '-s', 'EFI_SECTION_VERSION',\r
-                    ) + VerTuple + BuildNumTuple\r
-                GenFdsGlobalVariable.CallExternalTool(GenSectionCmd, "GenSection Failed !")\r
+                GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_VERSION',\r
+                                                     Ui=StringData, Ver=BuildNum)\r
                 OutputFileList.append(OutputFile)\r
 \r
         #\r
@@ -173,14 +161,8 @@ class EfiSection (EfiSectionClassObject):
             if InfOverrideUiString:\r
                 Num = SecNum\r
                 OutputFile = os.path.join( OutputPath, ModuleName + 'SEC' + str(Num) + Ffs.SectionSuffix.get(SectionType))\r
-                GenSectionCmd = (\r
-                    'GenSec',\r
-                    '-o', OutputFile,\r
-                    '-s', 'EFI_SECTION_USER_INTERFACE',\r
-                    '-n', '"' + StringData + '"',\r
-                    )\r
-\r
-                GenFdsGlobalVariable.CallExternalTool(GenSectionCmd, "GenSection Failed !")\r
+                GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_USER_INTERFACE',\r
+                                                     Ui=StringData)\r
                 OutputFileList.append(OutputFile)\r
 \r
             elif FileList != []:\r
@@ -191,14 +173,8 @@ class EfiSection (EfiSectionClassObject):
                     f = open(File, 'r')\r
                     UiString = f.read()\r
                     f.close()\r
-                    GenSectionCmd = (\r
-                        'GenSec',\r
-                        '-o', OutputFile,\r
-                        '-s', 'EFI_SECTION_USER_INTERFACE',\r
-                        '-n', '"' + UiString + '"',\r
-                        )\r
-\r
-                    GenFdsGlobalVariable.CallExternalTool(GenSectionCmd, "GenSection Failed !")\r
+                    GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_USER_INTERFACE',\r
+                                                         Ui=UiString)\r
                     OutputFileList.append(OutputFile)\r
             else:\r
                 if StringData != None and len(StringData) > 0:\r
@@ -214,13 +190,8 @@ class EfiSection (EfiSectionClassObject):
 \r
                 Num = SecNum\r
                 OutputFile = os.path.join( OutputPath, ModuleName + 'SEC' + str(Num) + Ffs.SectionSuffix.get(SectionType))\r
-                GenSectionCmd = (\r
-                    'GenSec',\r
-                    '-o', OutputFile,\r
-                    '-s', 'EFI_SECTION_USER_INTERFACE',\r
-                    ) + UiTuple\r
-\r
-                GenFdsGlobalVariable.CallExternalTool(GenSectionCmd, "GenSection Failed !")\r
+                GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_USER_INTERFACE',\r
+                                                     Ui=StringData)\r
                 OutputFileList.append(OutputFile)\r
 \r
 \r
@@ -245,47 +216,38 @@ class EfiSection (EfiSectionClassObject):
                         MapFile = File.replace('.efi', '.map')\r
                         if os.path.exists(MapFile):\r
                             CopyMapFile = os.path.join(OutputPath, ModuleName + '.map')\r
-                            if os.path.exists(CopyMapFile):\r
-                                os.remove(CopyMapFile)\r
-                            shutil.copyfile(MapFile, CopyMapFile)\r
+                            if not os.path.exists(CopyMapFile) or \\r
+                                (os.path.getmtime(MapFile) > os.path.getmtime(CopyMapFile)):\r
+                                shutil.copyfile(MapFile, CopyMapFile)\r
 \r
                     if not NoStrip:\r
                         FileBeforeStrip = os.path.join(OutputPath, ModuleName + '.efi')\r
-                        if os.path.exists(FileBeforeStrip):\r
-                            os.remove(FileBeforeStrip)\r
-                        shutil.copyfile(File, FileBeforeStrip)\r
+                        if not os.path.exists(FileBeforeStrip) or \\r
+                            (os.path.getmtime(File) > os.path.getmtime(FileBeforeStrip)):\r
+                            shutil.copyfile(File, FileBeforeStrip)\r
                         StrippedFile = os.path.join(OutputPath, ModuleName + '.stripped')\r
-                        StripCmd = (\r
-                            'GenFw',\r
-                            '-l',\r
-                            '-o', StrippedFile,\r
-                            GenFdsGlobalVariable.MacroExtend(File, Dict),\r
-                            )\r
-                        GenFdsGlobalVariable.CallExternalTool(StripCmd, "Strip Failed !")\r
+                        GenFdsGlobalVariable.GenerateFirmwareImage(\r
+                                                StrippedFile,\r
+                                                [GenFdsGlobalVariable.MacroExtend(File, Dict)],\r
+                                                Strip=True\r
+                                                )\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 = (\r
-                            'GenFw',\r
-                            '-t',\r
-                            '-o', TeFile,\r
-                            GenFdsGlobalVariable.MacroExtend(File, Dict),\r
-                            )\r
-                        GenFdsGlobalVariable.CallExternalTool(GenTeCmd, "GenFw Failed !")\r
+                        GenFdsGlobalVariable.GenerateFirmwareImage(\r
+                                                TeFile,\r
+                                                [GenFdsGlobalVariable.MacroExtend(File, Dict)],\r
+                                                Type='te'\r
+                                                )\r
                         File = TeFile\r
 \r
                     """Call GenSection"""\r
-                    GenSectionCmd = (\r
-                        'GenSec',\r
-                        '-o', OutputFile,\r
-                        '-s', Section.Section.SectionType.get (SectionType),\r
-                        GenFdsGlobalVariable.MacroExtend(File)\r
-                        )\r
-\r
-                    GenFdsGlobalVariable.CallExternalTool(GenSectionCmd, "GenSection Failed !")\r
+                    GenFdsGlobalVariable.GenerateSection(OutputFile,\r
+                                                         [GenFdsGlobalVariable.MacroExtend(File)],\r
+                                                         Section.Section.SectionType.get (SectionType)\r
+                                                         )\r
                     OutputFileList.append(OutputFile)\r
 \r
         return OutputFileList, self.Alignment\r
-\r
index 3167d38..2451209 100755 (executable)
@@ -50,14 +50,14 @@ class FileStatement (FileStatementClassObject) :
              os.makedirs(OutputDir)\r
 \r
         Dict.update(self.DefineVarDict)\r
-\r
+        SectionAlignments = None\r
         if self.FvName != None :\r
             Buffer = StringIO.StringIO('')\r
             if self.FvName.upper() not in GenFdsGlobalVariable.FdfParser.Profile.FvDict.keys():\r
                 EdkLogger.error("GenFds", GENFDS_ERROR, "FV (%s) is NOT described in FDF file!" % (self.FvName))\r
             Fv = GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(self.FvName.upper())\r
             FileName = Fv.AddToBuffer(Buffer)\r
-            SectionFiles = ('-i', FileName)\r
+            SectionFiles = [FileName]\r
 \r
         elif self.FdName != None:\r
             if self.FdName.upper() not in GenFdsGlobalVariable.FdfParser.Profile.FdDict.keys():\r
@@ -65,48 +65,38 @@ class FileStatement (FileStatementClassObject) :
             Fd = GenFdsGlobalVariable.FdfParser.Profile.FdDict.get(self.FdName.upper())\r
             FvBin = {}\r
             FileName = Fd.GenFd(FvBin)\r
-            SectionFiles = ('-i', FileName)\r
+            SectionFiles = [FileName]\r
 \r
         elif self.FileName != None:\r
             self.FileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FileName)\r
-            SectionFiles = ('-i', GenFdsGlobalVariable.MacroExtend(self.FileName, Dict))\r
+            SectionFiles = [GenFdsGlobalVariable.MacroExtend(self.FileName, Dict)]\r
 \r
         else:\r
-            SectionFiles = tuple()\r
+            SectionFiles = []\r
             Index = 0\r
+            SectionAlignments = []\r
             for section in self.SectionList :\r
                 Index = Index + 1\r
                 SecIndex = '%d' %Index\r
                 sectList, align = section.GenSection(OutputDir, self.NameGuid, SecIndex, self.KeyStringList, None, Dict)\r
                 if sectList != []:\r
                     for sect in sectList:\r
-                        SectionFiles += ('-i', sect)\r
-                        if align != None:\r
-                            SectionFiles += ('-n', align)\r
+                        SectionFiles.append(sect)\r
+                        SectionAlignments.append(align)\r
 \r
         #\r
         # Prepare the parameter\r
         #\r
-        CmdParams = tuple()\r
-        if self.Fixed != False:\r
-            CmdParams += ('-x',)\r
-        if self.CheckSum != False :\r
-            CmdParams += ('-s',)\r
-        if self.Alignment != None and self.Alignment !='':\r
-            CmdParams += ('-a', self.Alignment)\r
-\r
-        if not (self.FvFileType == None):\r
-            CmdParams += ('-t', Ffs.Ffs.FdfFvFileTypeToFileType.get(self.FvFileType))\r
-\r
         FfsFileOutput = os.path.join(OutputDir, self.NameGuid + '.ffs')\r
+        GenFdsGlobalVariable.GenerateFfs(FfsFileOutput, SectionFiles,\r
+                                         Ffs.Ffs.FdfFvFileTypeToFileType.get(self.FvFileType),\r
+                                         self.NameGuid,\r
+                                         Fixed=self.Fixed,\r
+                                         CheckSum=self.CheckSum,\r
+                                         Align=self.Alignment,\r
+                                         SectionAlign=SectionAlignments\r
+                                        )\r
 \r
-        GenFfsCmd = (\r
-            'GenFfs',\r
-             '-g', self.NameGuid,\r
-             '-o', FfsFileOutput,\r
-            ) + CmdParams + SectionFiles\r
-\r
-        GenFdsGlobalVariable.CallExternalTool(GenFfsCmd,"GenFfs Failed !")\r
         return FfsFileOutput\r
 \r
 \r
index 66c6311..74e1cb1 100644 (file)
@@ -143,9 +143,8 @@ class FfsInfStatement(FfsInfStatementClassObject):
         # For Rule has ComplexFile\r
         #\r
         elif isinstance(Rule, RuleComplexFile.RuleComplexFile):\r
-\r
-            InputSectList = self.__GenComplexFileSection__(Rule)\r
-            FfsOutput = self.__GenComplexFileFfs__(Rule, InputSectList)\r
+            InputSectList, InputSectAlignments = self.__GenComplexFileSection__(Rule)\r
+            FfsOutput = self.__GenComplexFileFfs__(Rule, InputSectList, InputSectAlignments)\r
 \r
             return FfsOutput\r
 \r
@@ -353,40 +352,27 @@ class FfsInfStatement(FfsInfStatementClassObject):
 \r
                 if not NoStrip:\r
                     FileBeforeStrip = os.path.join(self.OutputPath, ModuleName + '.reloc')\r
-                    if os.path.exists(FileBeforeStrip):\r
-                        os.remove(FileBeforeStrip)\r
-                    shutil.copyfile(File, FileBeforeStrip)\r
+                    if not os.path.exists(FileBeforeStrip) or \\r
+                        (os.path.getmtime(File) > os.path.getmtime(FileBeforeStrip)):\r
+                        shutil.copyfile(File, FileBeforeStrip)\r
                     StrippedFile = os.path.join(self.OutputPath, ModuleName + '.stipped')\r
-                    StripCmd = (\r
-                        'GenFw',\r
-                        '-l',\r
-                        '-o', StrippedFile,\r
-                        GenFdsGlobalVariable.MacroExtend(File, Dict, self.CurrentArch),\r
-                        )\r
-                    GenFdsGlobalVariable.CallExternalTool(StripCmd, "Strip Failed !")\r
+                    GenFdsGlobalVariable.GenerateFirmwareImage(\r
+                                            StrippedFile,\r
+                                            [GenFdsGlobalVariable.MacroExtend(File, Dict, self.CurrentArch)],\r
+                                            Strip=True\r
+                                            )\r
                     File = StrippedFile\r
 \r
                 if SectionType == 'TE':\r
                     TeFile = os.path.join( self.OutputPath, self.ModuleGuid + 'Te.raw')\r
-                    GenTeCmd = (\r
-                        'GenFw',\r
-                        '-t',\r
-                        '-o', TeFile,\r
-                        GenFdsGlobalVariable.MacroExtend(File, Dict, self.CurrentArch),\r
-                        )\r
-                    GenFdsGlobalVariable.CallExternalTool(GenTeCmd, "GenFw Failed !")\r
+                    GenFdsGlobalVariable.GenerateFirmwareImage(\r
+                                            TeFile,\r
+                                            [GenFdsGlobalVariable.MacroExtend(File, Dict, self.CurrentArch)],\r
+                                            Type='te'\r
+                                            )\r
                     File = TeFile\r
 \r
-                GenSectionCmd = (\r
-                    'GenSec',\r
-                    '-o', OutputFile,\r
-                    '-s', Section.Section.SectionType[SectionType],\r
-                    File,\r
-                    )\r
-                #\r
-                # Call GenSection\r
-                #\r
-                GenFdsGlobalVariable.CallExternalTool(GenSectionCmd, "Gen section Failed!")\r
+                GenFdsGlobalVariable.GenerateSection(OutputFile, [File], Section.Section.SectionType[SectionType])\r
                 OutputFileList.append(OutputFile)\r
         else:\r
             SecNum = '%d' %Index\r
@@ -396,38 +382,27 @@ class FfsInfStatement(FfsInfStatementClassObject):
 \r
             if not NoStrip:\r
                 FileBeforeStrip = os.path.join(self.OutputPath, ModuleName + '.reloc')\r
-                shutil.copyfile(File, FileBeforeStrip)\r
+                if not os.path.exists(FileBeforeStrip) or \\r
+                    (os.path.getmtime(File) > os.path.getmtime(FileBeforeStrip)):\r
+                    shutil.copyfile(File, FileBeforeStrip)\r
                 StrippedFile = os.path.join(self.OutputPath, ModuleName + '.stipped')\r
-                StripCmd = (\r
-                    'GenFw',\r
-                    '-l',\r
-                    '-o', StrippedFile,\r
-                    GenFdsGlobalVariable.MacroExtend(File, Dict, self.CurrentArch),\r
-                    )\r
-                GenFdsGlobalVariable.CallExternalTool(StripCmd, "Strip Failed !")\r
+                GenFdsGlobalVariable.GenerateFirmwareImage(\r
+                                        StrippedFile,\r
+                                        [GenFdsGlobalVariable.MacroExtend(File, Dict, self.CurrentArch)],\r
+                                        Strip=True\r
+                                        )\r
                 File = StrippedFile\r
 \r
             if SectionType == 'TE':\r
                 TeFile = os.path.join( self.OutputPath, self.ModuleGuid + 'Te.raw')\r
-                GenTeCmd = (\r
-                    'GenFw',\r
-                    '-t',\r
-                    '-o', TeFile,\r
-                    GenFdsGlobalVariable.MacroExtend(File, Dict, self.CurrentArch),\r
-                    )\r
-                GenFdsGlobalVariable.CallExternalTool(GenTeCmd, "GenFw Failed !")\r
+                GenFdsGlobalVariable.GenerateFirmwareImage(\r
+                                        TeFile,\r
+                                        [GenFdsGlobalVariable.MacroExtend(File, Dict, self.CurrentArch)],\r
+                                        Type='te'\r
+                                        )\r
                 GenSecInputFile = TeFile\r
 \r
-            GenSectionCmd = (\r
-                'GenSec',\r
-                '-o', OutputFile,\r
-                '-s', Section.Section.SectionType[SectionType],\r
-                GenSecInputFile,\r
-                )\r
-            #\r
-            # Call GenSection\r
-            #\r
-            GenFdsGlobalVariable.CallExternalTool(GenSectionCmd, "Gen section Failed!")\r
+            GenFdsGlobalVariable.GenerateSection(OutputFile, [GenSecInputFile], Section.Section.SectionType[SectionType])\r
             OutputFileList.append(OutputFile)\r
 \r
         return OutputFileList\r
@@ -442,34 +417,24 @@ class FfsInfStatement(FfsInfStatementClassObject):
     #   @retval string      Generated FFS file name\r
     #\r
     def __GenSimpleFileFfs__(self, Rule, InputFileList):\r
-        #\r
-        # Prepare the parameter of GenFfs\r
-        #\r
-        CmdParams = self.__GetGenFfsCmdParameter__(Rule)\r
-\r
         FfsOutput = self.OutputPath                     + \\r
                     os.sep                              + \\r
                     self.__ExtendMacro__(Rule.NameGuid) + \\r
                     '.ffs'\r
 \r
         GenFdsGlobalVariable.VerboseLogger(self.__ExtendMacro__(Rule.NameGuid))\r
-        InputSection = tuple()\r
+        InputSection = []\r
+        SectionAlignments = []\r
         for InputFile in InputFileList:\r
-            InputSection += ('-i', InputFile)\r
-            for i in range(len(CmdParams) - 1):\r
-                if CmdParams[i] == '-a':\r
-                    InputSection += ('-n', CmdParams[i+1])\r
-                    break\r
-\r
-        GenFfsCmd = (\r
-            'GenFfs',\r
-             '-g', self.NameGuid,\r
-             '-o', FfsOutput,\r
-            ) + CmdParams + InputSection\r
-        #\r
-        # Call GenSection\r
-        #\r
-        GenFdsGlobalVariable.CallExternalTool(GenFfsCmd, "GenFfs Failed!")\r
+            InputSection.append(InputFile)\r
+            SectionAlignments.append(Rule.Alignment)\r
+\r
+        GenFdsGlobalVariable.GenerateFfs(FfsOutput, InputSection,\r
+                                         Ffs.Ffs.FdfFvFileTypeToFileType[Rule.FvFileType],\r
+                                         self.NameGuid, Fixed=Rule.Fixed,\r
+                                         CheckSum=Rule.CheckSum, Align=Rule.Alignment,\r
+                                         SectionAlign=SectionAlignments\r
+                                        )\r
         return FfsOutput\r
 \r
     ## __GenComplexFileSection__() method\r
@@ -481,26 +446,24 @@ 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 = tuple()\r
+        SectFiles = []\r
+        SectAlignments = []\r
         Index = 1\r
         for Sect in Rule.SectionList:\r
-           SecIndex = '%d' %Index\r
-           SectList  = []\r
-           if Rule.KeyStringList != []:\r
-               SectList, Align = Sect.GenSection(self.OutputPath , self.ModuleGuid, SecIndex, Rule.KeyStringList, self)\r
-           else :\r
-               SectList, Align = Sect.GenSection(self.OutputPath , self.ModuleGuid, SecIndex, self.KeyStringList, self)\r
-           for SecName in  SectList :\r
-               SectFiles += ('-i', SecName)\r
-               if Align != None:\r
-                   SectFiles += ('-n', Align)\r
-           Index = Index + 1\r
-        return SectFiles\r
+            SecIndex = '%d' %Index\r
+            SectList  = []\r
+            if Rule.KeyStringList != []:\r
+                SectList, Align = Sect.GenSection(self.OutputPath , self.ModuleGuid, SecIndex, Rule.KeyStringList, self)\r
+            else :\r
+                SectList, Align = Sect.GenSection(self.OutputPath , self.ModuleGuid, SecIndex, self.KeyStringList, self)\r
+            for SecName in  SectList :\r
+                SectFiles.append(SecName)\r
+                SectAlignments.append(Align)\r
+            Index = Index + 1\r
+        return SectFiles, SectAlignments\r
 \r
     ## __GenComplexFileFfs__() method\r
     #\r
@@ -511,19 +474,14 @@ 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):\r
-\r
-        CmdParams = self.__GetGenFfsCmdParameter__(Rule)\r
-\r
+    def __GenComplexFileFfs__(self, Rule, InputFile, Alignments):\r
         FfsOutput = os.path.join( self.OutputPath, self.ModuleGuid + '.ffs')\r
-        GenFfsCmd = (\r
-            'GenFfs',\r
-            ) + CmdParams + (\r
-             '-g', self.ModuleGuid,\r
-             '-o', FfsOutput,\r
-            ) + InputFile\r
-\r
-        GenFdsGlobalVariable.CallExternalTool(GenFfsCmd, "GenFfs Failed !")\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
         return FfsOutput\r
 \r
     ## __GetGenFfsCmdParameter__() method\r
@@ -537,8 +495,6 @@ class FfsInfStatement(FfsInfStatementClassObject):
     def __GetGenFfsCmdParameter__(self, Rule):\r
         result = tuple()\r
         result += ('-t', Ffs.Ffs.FdfFvFileTypeToFileType[Rule.FvFileType])\r
-        #FileType = ' -t ' + \\r
-        #           Ffs.Ffs.FdfFvFileTypeToFileType[Rule.FvFileType]\r
         if Rule.Fixed != False:\r
             result += ('-x',)\r
         if Rule.CheckSum != False:\r
index 536e9fd..eb03d1b 100644 (file)
@@ -56,16 +56,16 @@ class FV (FvClassObject):
     #   @retval string      Generated FV file path\r
     #\r
     def AddToBuffer (self, Buffer, BaseAddress=None, BlockSize= None, BlockNum=None, ErasePloarity='1', VtfDict=None, MacroDict = {}) :\r
-        \r
+\r
         if self.UiFvName.upper() in GenFds.FvBinDict.keys():\r
             return GenFds.FvBinDict[self.UiFvName.upper()]\r
-        \r
+\r
         self.__InitializeInf__(BaseAddress, BlockSize, BlockNum, ErasePloarity, VtfDict)\r
         #\r
         # First Process the Apriori section\r
         #\r
         MacroDict.update(self.DefineVarDict)\r
-        \r
+\r
         GenFdsGlobalVariable.VerboseLogger('First generate Apriori file !')\r
         for AprSection in self.AprioriSectionList:\r
             FileName = AprSection.GenFfs (self.UiFvName, MacroDict)\r
@@ -73,49 +73,44 @@ class FV (FvClassObject):
             self.FvInfFile.writelines("EFI_FILE_NAME = " + \\r
                                        FileName          + \\r
                                            T_CHAR_LF)\r
-        \r
+\r
         # Process Modules in FfsList\r
-        \r
+\r
         for FfsFile in self.FfsList :\r
             FileName = FfsFile.GenFfs(MacroDict)\r
             self.FvInfFile.writelines("EFI_FILE_NAME = " + \\r
                                        FileName          + \\r
                                        T_CHAR_LF)\r
-            \r
+\r
         self.FvInfFile.close()\r
         #\r
-        # Call GenFv tool \r
+        # Call GenFv tool\r
         #\r
-        \r
+\r
         FvOutputFile = os.path.join(GenFdsGlobalVariable.FvDir, self.UiFvName)\r
         FvOutputFile = FvOutputFile + '.Fv'\r
         # BUGBUG: FvOutputFile could be specified from FDF file (FV section, CreateFile statement)\r
         if self.CreateFileName != None:\r
             FvOutputFile = self.CreateFileName\r
+        GenFdsGlobalVariable.GenerateFirmwareVolume(\r
+                                FvOutputFile,\r
+                                [self.InfFileName],\r
+                                AddressFile=GenFdsGlobalVariable.FvAddressFileName\r
+                                )\r
 \r
-        GenFvCmd = (\r
-            'GenFv',\r
-             '-i', self.InfFileName,\r
-             '-o', FvOutputFile,\r
-             '-a', GenFdsGlobalVariable.FvAddressFileName,\r
-            )\r
-        #\r
-        # Call GenFv Tools\r
-        #\r
-        GenFdsGlobalVariable.CallExternalTool(GenFvCmd, "GenFv Failed!")\r
         #\r
         # Write the Fv contents to Buffer\r
         #\r
         FvFileObj = open ( FvOutputFile,'r+b')\r
-                   \r
+\r
         GenFdsGlobalVariable.InfLogger( "\nGenerate %s Fv Successfully" %self.UiFvName)\r
         GenFdsGlobalVariable.SharpCounter = 0\r
-              \r
+\r
         Buffer.write(FvFileObj.read())\r
         FvFileObj.close()\r
         GenFds.FvBinDict[self.UiFvName.upper()] = FvOutputFile\r
         return FvOutputFile\r
-    \r
+\r
     ## __InitializeInf__()\r
     #\r
     #   Initilize the inf file to create FV\r
@@ -134,7 +129,7 @@ class FV (FvClassObject):
         self.InfFileName = os.path.join(GenFdsGlobalVariable.FvDir,\r
                                    self.UiFvName + '.inf')\r
         self.FvInfFile = open (self.InfFileName, 'w')\r
-        \r
+\r
         #\r
         # Add [Options]\r
         #\r
@@ -143,7 +138,7 @@ class FV (FvClassObject):
             self.FvInfFile.writelines("EFI_BASE_ADDRESS = " + \\r
                                        BaseAddress          + \\r
                                        T_CHAR_LF)\r
-                                       \r
+\r
         if BlockSize != None:\r
             self.FvInfFile.writelines("EFI_BLOCK_SIZE = " + \\r
                                       '0x%X' %BlockSize    + \\r
@@ -158,12 +153,12 @@ class FV (FvClassObject):
                     self.FvInfFile.writelines("EFI_BLOCK_SIZE  = "  + \\r
                                           '0x%X' %BlockSize[0]    + \\r
                                           T_CHAR_LF)\r
-                \r
-                if BlockSize[1] != None:                  \r
+\r
+                if BlockSize[1] != None:\r
                     self.FvInfFile.writelines("EFI_NUM_BLOCKS   = "  + \\r
                                           ' 0x%X' %BlockSize[1]    + \\r
                                           T_CHAR_LF)\r
-                                          \r
+\r
         if self.BsBaseAddress != None:\r
             self.FvInfFile.writelines('EFI_BOOT_DRIVER_BASE_ADDRESS = ' + \\r
                                        '0x%X' %self.BsBaseAddress)\r
@@ -174,7 +169,7 @@ class FV (FvClassObject):
         # Add attribute\r
         #\r
         self.FvInfFile.writelines("[attributes]" + T_CHAR_LF)\r
-        \r
+\r
         self.FvInfFile.writelines("EFI_ERASE_POLARITY   = "       + \\r
                                           ' %s' %ErasePloarity    + \\r
                                           T_CHAR_LF)\r
@@ -193,11 +188,11 @@ class FV (FvClassObject):
         #\r
         # Add [Files]\r
         #\r
-            \r
+\r
         self.FvInfFile.writelines("[files]" + T_CHAR_LF)\r
         if VtfDict != None and self.UiFvName in VtfDict.keys():\r
             self.FvInfFile.writelines("EFI_FILE_NAME = "                   + \\r
                                        VtfDict.get(self.UiFvName)          + \\r
                                        T_CHAR_LF)\r
 \r
-        \r
+\r
index 45fd097..978da66 100755 (executable)
@@ -62,14 +62,7 @@ class FvImageSection(FvImageSectionClassObject):
 \r
             for FileName in FileList:\r
                 OutputFile = os.path.join(OutputPath, ModuleName + 'SEC' + Num + Ffs.SectionSuffix.get("FV_IMAGE"))\r
-                GenSectionCmd = (\r
-                    'GenSec',\r
-                    '-o', OutputFile,\r
-                    '-s', 'EFI_SECTION_FIRMWARE_VOLUME_IMAGE',\r
-                    FvFileName,\r
-                    )\r
-\r
-                GenFdsGlobalVariable.CallExternalTool(GenSectionCmd, "GenSection Failed!")\r
+                GenFdsGlobalVariable.GenerateSection(OutputFile, [FvFileName], 'EFI_SECTION_FIRMWARE_VOLUME_IMAGE')\r
                 OutputFileList.append(OutputFile)\r
             return OutputFileList, self.Alignment\r
         #\r
@@ -89,15 +82,7 @@ class FvImageSection(FvImageSectionClassObject):
             # Prepare the parameter of GenSection\r
             #\r
             OutputFile = os.path.join(OutputPath, ModuleName + 'SEC' + SecNum + Ffs.SectionSuffix.get("FV_IMAGE"))\r
-\r
-            GenSectionCmd = (\r
-                'GenSec',\r
-                '-o', OutputFile,\r
-                '-s', 'EFI_SECTION_FIRMWARE_VOLUME_IMAGE',\r
-                FvFileName,\r
-                )\r
-\r
-            GenFdsGlobalVariable.CallExternalTool(GenSectionCmd, "GenSection Failed!")\r
+            GenFdsGlobalVariable.GenerateSection(OutputFile, [FvFileName], 'EFI_SECTION_FIRMWARE_VOLUME_IMAGE')\r
             OutputFileList.append(OutputFile)\r
 \r
             return OutputFileList, self.Alignment\r
index 98b4d5e..1ad2a76 100644 (file)
 import os\r
 import sys\r
 import subprocess\r
+import struct\r
+import array\r
 from Common import BuildToolError\r
 from Common import EdkLogger\r
+from Common.Misc import SaveFileOnChange\r
 \r
 ## Global variables\r
 #\r
@@ -48,6 +51,8 @@ class GenFdsGlobalVariable:
     SharpCounter = 0\r
     SharpNumberPerLine = 40\r
 \r
+    SectionHeader = struct.Struct("3B 1B")\r
+\r
     ## SetDir()\r
     #\r
     #   @param  OutputDir           Output directory\r
@@ -113,6 +118,182 @@ class GenFdsGlobalVariable:
             Str = os.path.join(GenFdsGlobalVariable.WorkSpaceDir, String)\r
         return os.path.normpath(Str)\r
 \r
+    ## Check if the input files are newer than output files\r
+    #\r
+    #   @param  Output          Path of output file\r
+    #   @param  Input           Path list of input files\r
+    #\r
+    #   @retval True            if Output doesn't exist, or any Input is newer\r
+    #   @retval False           if all Input is older than Output\r
+    #\r
+    @staticmethod\r
+    def NeedsUpdate(Output, Input):\r
+        if not os.path.exists(Output):\r
+            return True\r
+        # always update "Output" if no "Input" given\r
+        if Input == None or len(Input) == 0:\r
+            return True\r
+        OutputTime = os.path.getmtime(Output)\r
+        for F in Input:\r
+            # always update "Output" if any "Input" doesn't exist\r
+            if not os.path.exists(F):\r
+                return True\r
+            # always update "Output" if any "Input" is newer than "Output"\r
+            if os.path.getmtime(F) > OutputTime:\r
+                return True\r
+        return False\r
+\r
+    @staticmethod\r
+    def GenerateSection(Output, Input, Type=None, CompressionType=None, Guid=None,\r
+                        GuidHdrLen=None, GuidAttr=None, Ui=None, Ver=None):\r
+        if not GenFdsGlobalVariable.NeedsUpdate(Output, Input):\r
+            return\r
+        GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input))\r
+\r
+        Cmd = ["GenSec"]\r
+        if Type not in [None, '']:\r
+            Cmd += ["-s", Type]\r
+        if CompressionType not in [None, '']:\r
+            Cmd += ["-c", CompressionType]\r
+        if Guid != None:\r
+            Cmd += ["-g", Guid]\r
+        if GuidHdrLen not in [None, '']:\r
+            Cmd += ["-l", GuidHdrLen]\r
+        if GuidAttr not in [None, '']:\r
+            Cmd += ["-r", GuidAttr]\r
+\r
+        if Ui not in [None, '']:\r
+            #Cmd += ["-n", '"' + Ui + '"']\r
+            SectionData = array.array('B', [0,0,0,0])\r
+            SectionData.fromstring(Ui.encode("utf_16_le"))\r
+            SectionData.append(0)\r
+            SectionData.append(0)\r
+            Len = len(SectionData)\r
+            GenFdsGlobalVariable.SectionHeader.pack_into(SectionData, 0, Len & 0xff, (Len >> 8) & 0xff, (Len >> 16) & 0xff, 0x15)\r
+            SaveFileOnChange(Output,  SectionData.tostring())\r
+        elif Ver not in [None, '']:\r
+            #Cmd += ["-j", Ver]\r
+            SectionData = array.array('B', [0,0,0,0])\r
+            SectionData.fromstring(Ver.encode("utf_16_le"))\r
+            SectionData.append(0)\r
+            SectionData.append(0)\r
+            Len = len(SectionData)\r
+            GenFdsGlobalVariable.SectionHeader.pack_into(SectionData, 0, Len & 0xff, (Len >> 8) & 0xff, (Len >> 16) & 0xff, 0x15)\r
+            SaveFileOnChange(Output,  SectionData.tostring())\r
+        else:\r
+            Cmd += ["-o", Output]\r
+            Cmd += Input\r
+            GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate section")\r
+\r
+    @staticmethod\r
+    def GenerateFfs(Output, Input, Type, Guid, Fixed=False, CheckSum=False, Align=None,\r
+                    SectionAlign=None):\r
+        if not GenFdsGlobalVariable.NeedsUpdate(Output, Input):\r
+            return\r
+        GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input))\r
+\r
+        Cmd = ["GenFfs", "-t", Type, "-g", Guid]\r
+        if Fixed == True:\r
+            Cmd += ["-x"]\r
+        if CheckSum:\r
+            Cmd += ["-s"]\r
+        if Align not in [None, '']:\r
+            Cmd += ["-a", Align]\r
+\r
+        Cmd += ["-o", Output]\r
+        for I in range(0, len(Input)):\r
+            Cmd += ("-i", Input[I])\r
+            if SectionAlign not in [None, '', []] and SectionAlign[I] not in [None, '']:\r
+                Cmd += ("-n", SectionAlign[I])\r
+        GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate FFS")\r
+\r
+    @staticmethod\r
+    def GenerateFirmwareVolume(Output, Input, BaseAddress=None, Capsule=False, Dump=False,\r
+                               AddressFile=None, MapFile=None):\r
+        if not GenFdsGlobalVariable.NeedsUpdate(Output, Input):\r
+            return\r
+        GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input))\r
+\r
+        Cmd = ["GenFv"]\r
+        if BaseAddress not in [None, '']:\r
+            Cmd += ["-r", BaseAddress]\r
+        if Capsule:\r
+            Cmd += ["-c"]\r
+        if Dump:\r
+            Cmd += ["-p"]\r
+        if AddressFile not in [None, '']:\r
+            Cmd += ["-a", AddressFile]\r
+        if MapFile not in [None, '']:\r
+            Cmd += ["-m", MapFile]\r
+        Cmd += ["-o", Output]\r
+        for I in Input:\r
+            Cmd += ["-i", I]\r
+\r
+        GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate FV")\r
+\r
+    @staticmethod\r
+    def GenerateVtf(Output, Input, BaseAddress=None, FvSize=None):\r
+        if not GenFdsGlobalVariable.NeedsUpdate(Output, Input):\r
+            return\r
+        GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input))\r
+\r
+        Cmd = ["GenVtf"]\r
+        if BaseAddress not in [None, ''] and FvSize not in [None, ''] \\r
+            and len(BaseAddress) == len(FvSize):\r
+            for I in range(0, len(BaseAddress)):\r
+                Cmd += ["-r", BaseAddress[i], "-s", FvSize[I]]\r
+        Cmd += ["-o", Output]\r
+        for F in Input:\r
+            Cmd += ["-f", F]\r
+\r
+        GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate VTF")\r
+\r
+    @staticmethod\r
+    def GenerateFirmwareImage(Output, Input, Type="efi", SubType=None, Zero=False,\r
+                              Strip=False, Replace=False, TimeStamp=None, Join=False,\r
+                              Align=None, Padding=None, Convert=False):\r
+        if not GenFdsGlobalVariable.NeedsUpdate(Output, Input):\r
+            return\r
+        GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input))\r
+\r
+        Cmd = ["GenFw"]\r
+        if Type.lower() == "te":\r
+            Cmd += ["-t"]\r
+        if SubType not in [None, '']:\r
+            Cmd += ["-e", SubType]\r
+        if TimeStamp not in [None, '']:\r
+            Cmd += ["-s", TimeStamp]\r
+        if Align not in [None, '']:\r
+            Cmd += ["-a", Align]\r
+        if Padding not in [None, '']:\r
+            Cmd += ["-p", Padding]\r
+        if Zero:\r
+            Cmd += ["-z"]\r
+        if Strip:\r
+            Cmd += ["-l"]\r
+        if Replace:\r
+            Cmd += ["-r"]\r
+        if Join:\r
+            Cmd += ["-j"]\r
+        if Convert:\r
+            Cmd += ["-m"]\r
+        Cmd += ["-o", Output]\r
+        Cmd += Input\r
+\r
+        GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate firmware image")\r
+\r
+    @staticmethod\r
+    def GuidTool(Output, Input, ToolPath, Options=''):\r
+        if not GenFdsGlobalVariable.NeedsUpdate(Output, Input):\r
+            return\r
+        GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input))\r
+\r
+        Cmd = [ToolPath, Options]\r
+        Cmd += ["-o", Output]\r
+        Cmd += Input\r
+\r
+        GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to call " + ToolPath)\r
+\r
     def CallExternalTool (cmd, errorMess):\r
 \r
         if type(cmd) not in (tuple, list):\r
@@ -131,7 +312,7 @@ class GenFdsGlobalVariable:
             GenFdsGlobalVariable.SharpCounter = GenFdsGlobalVariable.SharpCounter + 1\r
             if GenFdsGlobalVariable.SharpCounter % GenFdsGlobalVariable.SharpNumberPerLine == 0:\r
                 sys.stdout.write('\n')\r
-        #GenFdsGlobalVariable.VerboseLogger(cmd)\r
+\r
         PopenObject = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr= subprocess.PIPE)\r
         (out, error) = PopenObject.communicate()\r
 \r
index 97688a1..a67aa7a 100755 (executable)
@@ -90,13 +90,7 @@ class GuidSection(GuidSectionClassObject) :
         #\r
         if self.NameGuid == None :\r
             GenFdsGlobalVariable.VerboseLogger( "Use GenSection function Generate CRC32 Section")\r
-            GenSectionCmd = (\r
-                'GenSec',\r
-                 '-o', OutputFile,\r
-                 '-s', Section.Section.SectionType[self.SectionType],\r
-                ) + SectFile\r
-\r
-            GenFdsGlobalVariable.CallExternalTool(GenSectionCmd, "GenSection Failed!")\r
+            GenFdsGlobalVariable.GenerateSection(OutputFile, SectFile, Section.Section.SectionType[self.SectionType])\r
             OutputFileList = []\r
             OutputFileList.append(OutputFile)\r
             return OutputFileList, self.Alignment\r
@@ -107,16 +101,11 @@ class GuidSection(GuidSectionClassObject) :
             #\r
             # Call GenSection with DUMMY section type.\r
             #\r
-            GenSectionCmd = (\r
-                'GenSec',\r
-                '-o', OutputFile,\r
-                ) + SectFile\r
-\r
-            GenFdsGlobalVariable.CallExternalTool(GenSectionCmd, "GenSection Failed!")\r
+            GenFdsGlobalVariable.GenerateSection(OutputFile+".dummy", SectFile)\r
             #\r
             # Use external tool process the Output\r
             #\r
-            InputFile = OutputFile\r
+            InputFile = OutputFile+".dummy"\r
             TempFile = OutputPath + \\r
                        os.sep     + \\r
                        ModuleName + \\r
@@ -135,25 +124,18 @@ class GuidSection(GuidSectionClassObject) :
             #\r
             # Call external tool\r
             #\r
-            GenFdsGlobalVariable.CallExternalTool(ExternalToolCmd, "Gensec Failed!")\r
+            GenFdsGlobalVariable.GuidTool(TempFile, [InputFile], ExternalTool, '-e')\r
+\r
             #\r
             # Call Gensection Add Secntion Header\r
             #\r
-            AttributeTuple = tuple()\r
+            Attribute = None\r
             if self.ProcessRequired == True:\r
-                AttributeTuple += ('-a', 'PROCSSING_REQUIRED')\r
+                Attribute = 'PROCSSING_REQUIRED'\r
             if self.AuthStatusValid == True:\r
-                AttributeTuple += ('-a', 'AUTH_STATUS_VALID')\r
-            GenSectionCmd = (\r
-                'GenSec',\r
-                '-o', OutputFile,\r
-                '-s', Section.Section.SectionType['GUIDED'],\r
-                '-g', self.NameGuid,\r
-                ) + AttributeTuple + (\r
-                TempFile,\r
-                )\r
-\r
-            GenFdsGlobalVariable.CallExternalTool(GenSectionCmd, "GenSection Failed!")\r
+                Attribute = 'AUTH_STATUS_VALID'\r
+            GenFdsGlobalVariable.GenerateSection(OutputFile, [TempFile], Section.Section.SectionType['GUIDED'],\r
+                                                 Guid=self.NameGuid, GuidAttr=Attribute)\r
             OutputFileList = []\r
             OutputFileList.append(OutputFile)\r
             return OutputFileList, self.Alignment\r
index 0980b58..dc03686 100644 (file)
@@ -170,17 +170,20 @@ class Region(RegionClassObject):
                         Buffer.write(pack('B', int(item, 16)))\r
             if DataSize < Size:\r
                 if (ErasePolarity == '1'):\r
-                    Buffer.write(pack(str(Size -DataSize)+'B', *(int('0xFF', 16) for i in range(Size - DataSize))))\r
+                    PadData = 0xFF\r
                 else:\r
-                    Buffer.write(pack(str(Size - DataSize)+'B', *(int('0x00', 16) for i in range(Size - DataSize))))\r
-\r
+                    PadData = 0\r
+                for i in range(Size - DataSize):\r
+                    Buffer.write(pack('B', PadData))\r
 \r
         if self.RegionType == None:\r
             GenFdsGlobalVariable.InfLogger('   Region Name = None')\r
             if (ErasePolarity == '1') :\r
-                Buffer.write(pack(str(Size)+'B', *(int('0xFF', 16) for i in range(0, Size))))\r
+                PadData = 0xFF\r
             else :\r
-                Buffer.write(pack(str(Size)+'B', *(int('0x00', 16) for i in range(0, Size))))\r
+                PadData = 0\r
+            for i in range(0, Size):\r
+                Buffer.write(pack('B', PadData))\r
 \r
     def GetFvAlignValue(self, Str):\r
         AlignValue = 1\r
index 166ccf0..ff884e8 100755 (executable)
@@ -17,7 +17,7 @@
 #\r
 from CommonDataClass.FdfClass import SectionClassObject\r
 from GenFdsGlobalVariable import GenFdsGlobalVariable\r
-import os\r
+import os, glob\r
 from Common import EdkLogger\r
 from Common.BuildToolError import *\r
 \r
@@ -138,11 +138,8 @@ class Section (SectionClassObject):
                 else:\r
                         GenFdsGlobalVariable.InfLogger ("\nCurrent ARCH \'%s\' of File %s is not in the Support Arch Scope of %s specified by INF %s in FDF" %(FfsInf.CurrentArch, File.BinaryFile, File.SupArchList, FfsInf.InfFileName))\r
 \r
-        if os.path.exists(FfsInf.EfiOutputPath):\r
-            for FileName in os.listdir(FfsInf.EfiOutputPath):\r
-                Name, Ext = os.path.splitext(FileName)\r
-                if Ext == Suffix:\r
-                   FileList.append(os.path.join(FfsInf.EfiOutputPath, FileName))\r
+        if Suffix != None and os.path.exists(FfsInf.EfiOutputPath):\r
+            FileList.extend(glob.glob(os.path.join(FfsInf.EfiOutputPath, "*" + Suffix)))\r
 \r
         return FileList, IsSect\r
     GetFileList = staticmethod(GetFileList)\r
index 0cfece6..e660055 100644 (file)
@@ -26,7 +26,7 @@ from CommonDataClass.FdfClass import UiSectionClassObject
 #\r
 #\r
 class UiSection (UiSectionClassObject):\r
-    \r
+\r
     ## The constructor\r
     #\r
     #   @param  self        The object pointer\r
@@ -55,9 +55,9 @@ class UiSection (UiSectionClassObject):
             self.Alignment = FfsInf.__ExtendMacro__(self.Alignment)\r
             self.StringData = FfsInf.__ExtendMacro__(self.StringData)\r
             self.FileName = FfsInf.__ExtendMacro__(self.FileName)\r
-            \r
+\r
         OutputFile = os.path.join(OutputPath, ModuleName + 'SEC' + SecNum + Ffs.SectionSuffix.get('UI'))\r
-                     \r
+\r
         if self.StringData != None :\r
             NameString = self.StringData\r
         elif self.FileName != None:\r
@@ -69,18 +69,9 @@ class UiSection (UiSectionClassObject):
             FileObj.close()\r
         else:\r
             NameString = ''\r
-            \r
-            \r
-        GenSectionCmd = (\r
-            'GenSec',\r
-            '-o', OutputFile,\r
-            '-s', 'EFI_SECTION_USER_INTERFACE',\r
-            '-n', NameString,\r
-            )\r
-        #\r
-        # Call GenSection\r
-        #\r
-        GenFdsGlobalVariable.CallExternalTool(GenSectionCmd,"GenSection Failed!")\r
+\r
+        GenFdsGlobalVariable.GenerateSection(OutputFile, None, 'EFI_SECTION_USER_INTERFACE', Ui=NameString)\r
+\r
         OutputFileList = []\r
         OutputFileList.append(OutputFile)\r
         return OutputFileList, self.Alignment\r
index 7ca3151..e27d0a2 100644 (file)
@@ -26,14 +26,14 @@ from CommonDataClass.FdfClass import VerSectionClassObject
 #\r
 #\r
 class VerSection (VerSectionClassObject):\r
-    \r
+\r
     ## The constructor\r
     #\r
     #   @param  self        The object pointer\r
     #\r
     def __init__(self):\r
         VerSectionClassObject.__init__(self)\r
-        \r
+\r
     ## GenSection() method\r
     #\r
     #   Generate version section\r
@@ -56,16 +56,11 @@ class VerSection (VerSectionClassObject):
             self.BuildNum = FfsInf.__ExtendMacro__(self.BuildNum)\r
             self.StringData = FfsInf.__ExtendMacro__(self.StringData)\r
             self.FileName = FfsInf.__ExtendMacro__(self.FileName)\r
-            \r
+\r
         OutputFile = os.path.join(OutputPath,\r
                                   ModuleName + 'SEC' + SecNum + Ffs.SectionSuffix.get('VERSION'))\r
         OutputFile = os.path.normpath(OutputFile)\r
-        \r
-        # Get Build Num\r
-        BuildNum = tuple()\r
-        if not (self.BuildNum == None) :\r
-            BuildNum = ('-j', ('%d' % self.BuildNum))\r
\r
+\r
         # Get String Data\r
         StringData = ''\r
         if self.StringData != None:\r
@@ -80,17 +75,8 @@ class VerSection (VerSectionClassObject):
         else:\r
             StringData = ''\r
 \r
-        GenSectionCmd = (\r
-            'GenSec',\r
-            '-o', OutputFile,\r
-            '-s', 'EFI_SECTION_VERSION',\r
-            '-n', StringData,\r
-            ) + BuildNum\r
-\r
-        #\r
-        # Call GenSection\r
-        #\r
-        GenFdsGlobalVariable.CallExternalTool(GenSectionCmd, "Gensection Failed!")\r
+        GenFdsGlobalVariable.GenerateSection(OutputFile, None, 'EFI_SECTION_VERSION',\r
+                                             Ui=StringData, Ver=self.BuildNum)\r
         OutputFileList = []\r
         OutputFileList.append(OutputFile)\r
         return OutputFileList, self.Alignment\r