]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/GenFds/Fv.py
Sync EDKII BaseTools to BaseTools project r1903.
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / Fv.py
index 6190bceba88d439a2969f679a71a15363710541a..8d2ef1d87419c1923a5341fce0470f107c6475bb 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # process FV generation\r
 #\r
 ## @file\r
 # process FV generation\r
 #\r
-#  Copyright (c) 2007, Intel Corporation\r
+#  Copyright (c) 2007 - 2010, Intel Corporation\r
 #\r
 #  All rights reserved. This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
 #\r
 #  All rights reserved. This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -63,7 +63,7 @@ class FV (FvClassObject):
     #\r
     def AddToBuffer (self, Buffer, BaseAddress=None, BlockSize= None, BlockNum=None, ErasePloarity='1', VtfDict=None, MacroDict = {}) :\r
 \r
     #\r
     def AddToBuffer (self, Buffer, BaseAddress=None, BlockSize= None, BlockNum=None, ErasePloarity='1', VtfDict=None, MacroDict = {}) :\r
 \r
-        if self.UiFvName.upper() + 'fv' in GenFds.ImageBinDict.keys():\r
+        if BaseAddress == None and self.UiFvName.upper() + 'fv' in GenFds.ImageBinDict.keys():\r
             return GenFds.ImageBinDict[self.UiFvName.upper() + 'fv']\r
         \r
         #\r
             return GenFds.ImageBinDict[self.UiFvName.upper() + 'fv']\r
         \r
         #\r
@@ -103,7 +103,7 @@ class FV (FvClassObject):
 \r
         # Process Modules in FfsList\r
         for FfsFile in self.FfsList :\r
 \r
         # Process Modules in FfsList\r
         for FfsFile in self.FfsList :\r
-            FileName = FfsFile.GenFfs(MacroDict)\r
+            FileName = FfsFile.GenFfs(MacroDict, FvParentAddr=BaseAddress)\r
             FfsFileList.append(FileName)\r
             self.FvInfFile.writelines("EFI_FILE_NAME = " + \\r
                                        FileName          + \\r
             FfsFileList.append(FileName)\r
             self.FvInfFile.writelines("EFI_FILE_NAME = " + \\r
                                        FileName          + \\r
@@ -122,6 +122,9 @@ class FV (FvClassObject):
 \r
         FvInfoFileName = os.path.join(GenFdsGlobalVariable.FfsDir, self.UiFvName + '.inf')\r
         shutil.copy(GenFdsGlobalVariable.FvAddressFileName, FvInfoFileName)\r
 \r
         FvInfoFileName = os.path.join(GenFdsGlobalVariable.FfsDir, self.UiFvName + '.inf')\r
         shutil.copy(GenFdsGlobalVariable.FvAddressFileName, FvInfoFileName)\r
+        OrigFvInfo = None\r
+        if os.path.exists (FvInfoFileName):\r
+            OrigFvInfo = open(FvInfoFileName, 'r').read()\r
         GenFdsGlobalVariable.GenerateFirmwareVolume(\r
                                 FvOutputFile,\r
                                 [self.InfFileName],\r
         GenFdsGlobalVariable.GenerateFirmwareVolume(\r
                                 FvOutputFile,\r
                                 [self.InfFileName],\r
@@ -129,6 +132,35 @@ class FV (FvClassObject):
                                 FfsList=FfsFileList\r
                                 )\r
 \r
                                 FfsList=FfsFileList\r
                                 )\r
 \r
+        NewFvInfo = None\r
+        if os.path.exists (FvInfoFileName):\r
+            NewFvInfo = open(FvInfoFileName, 'r').read()\r
+        if NewFvInfo != None and NewFvInfo != OrigFvInfo:\r
+            FvChildAddr = []\r
+            AddFileObj = open(FvInfoFileName, 'r')\r
+            AddrStrings = AddFileObj.readlines()\r
+            AddrKeyFound = False\r
+            for AddrString in AddrStrings:\r
+                if AddrKeyFound:\r
+                    #get base address for the inside FvImage\r
+                    FvChildAddr.append (AddrString)\r
+                elif AddrString.find ("[FV_BASE_ADDRESS]") != -1:\r
+                    AddrKeyFound = True\r
+            AddFileObj.close()\r
+\r
+            if FvChildAddr != []:\r
+                # Update Ffs again\r
+                for FfsFile in self.FfsList :\r
+                    FileName = FfsFile.GenFfs(MacroDict, FvChildAddr, BaseAddress)\r
+                \r
+                #Update GenFv again\r
+                GenFdsGlobalVariable.GenerateFirmwareVolume(\r
+                                        FvOutputFile,\r
+                                        [self.InfFileName],\r
+                                        AddressFile=FvInfoFileName,\r
+                                        FfsList=FfsFileList\r
+                                        )\r
+\r
         #\r
         # Write the Fv contents to Buffer\r
         #\r
         #\r
         # Write the Fv contents to Buffer\r
         #\r
@@ -138,6 +170,21 @@ class FV (FvClassObject):
         GenFdsGlobalVariable.SharpCounter = 0\r
 \r
         Buffer.write(FvFileObj.read())\r
         GenFdsGlobalVariable.SharpCounter = 0\r
 \r
         Buffer.write(FvFileObj.read())\r
+        FvFileObj.seek(0)\r
+        # PI FvHeader is 0x48 byte\r
+        FvHeaderBuffer = FvFileObj.read(0x48)\r
+        # FV alignment position.\r
+        FvAlignmentValue = 1 << (ord (FvHeaderBuffer[0x2E]) & 0x1F)\r
+        # FvAlignmentValue is larger than or equal to 1K\r
+        if FvAlignmentValue >= 0x400:\r
+            if FvAlignmentValue >= 0x10000:\r
+                #The max alignment supported by FFS is 64K.\r
+                self.FvAlignment = "64K"\r
+            else:\r
+                self.FvAlignment = str (FvAlignmentValue / 0x400) + "K"\r
+        else:\r
+            # FvAlignmentValue is less than 1K\r
+            self.FvAlignment = str (FvAlignmentValue)\r
         FvFileObj.close()\r
         GenFds.ImageBinDict[self.UiFvName.upper() + 'fv'] = FvOutputFile\r
         return FvOutputFile\r
         FvFileObj.close()\r
         GenFds.ImageBinDict[self.UiFvName.upper() + 'fv'] = FvOutputFile\r
         return FvOutputFile\r
@@ -179,6 +226,10 @@ class FV (FvClassObject):
                                       ' 0x%X' %BlockNum    + \\r
                                       T_CHAR_LF)\r
         else:\r
                                       ' 0x%X' %BlockNum    + \\r
                                       T_CHAR_LF)\r
         else:\r
+            if self.BlockSizeList == []:\r
+                #set default block size is 1\r
+                self.FvInfFile.writelines("EFI_BLOCK_SIZE  = 0x1" + T_CHAR_LF)\r
+            \r
             for BlockSize in self.BlockSizeList :\r
                 if BlockSize[0] != None:\r
                     self.FvInfFile.writelines("EFI_BLOCK_SIZE  = "  + \\r
             for BlockSize in self.BlockSizeList :\r
                 if BlockSize[0] != None:\r
                     self.FvInfFile.writelines("EFI_BLOCK_SIZE  = "  + \\r