]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/GenFds/Fv.py
BaseTools: Enhance GenFv Tool to report error message
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / Fv.py
index d7705823265912eedf2a03dfa314accdb7c2e7e8..df97ccbab6484fd74d85b09c8429d11d26bd5055 100644 (file)
@@ -181,32 +181,59 @@ class FV (FvClassObject):
         #\r
         # Write the Fv contents to Buffer\r
         #\r
-        FvFileObj = open ( FvOutputFile,'r+b')\r
+        if os.path.isfile(FvOutputFile):\r
+            FvFileObj = open ( FvOutputFile,'r+b')\r
 \r
-        GenFdsGlobalVariable.VerboseLogger( "\nGenerate %s FV Successfully" %self.UiFvName)\r
-        GenFdsGlobalVariable.SharpCounter = 0\r
+            GenFdsGlobalVariable.VerboseLogger( "\nGenerate %s FV Successfully" %self.UiFvName)\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
+            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
-                self.FvAlignment = str (FvAlignmentValue / 0x400) + "K"\r
+                # FvAlignmentValue is less than 1K\r
+                self.FvAlignment = str (FvAlignmentValue)\r
+            FvFileObj.close()\r
+            GenFds.ImageBinDict[self.UiFvName.upper() + 'fv'] = FvOutputFile\r
+            GenFdsGlobalVariable.LargeFileInFvFlags.pop()\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
-        GenFdsGlobalVariable.LargeFileInFvFlags.pop()\r
+            GenFdsGlobalVariable.ErrorLogger("Failed to generate %s FV file." %self.UiFvName)\r
         return FvOutputFile\r
 \r
+    ## _GetBlockSize()\r
+    #\r
+    #   Calculate FV's block size\r
+    #   Inherit block size from FD if no block size specified in FV\r
+    #\r
+    def _GetBlockSize(self):\r
+        if self.BlockSizeList:\r
+            return True\r
+\r
+        for FdName in GenFdsGlobalVariable.FdfParser.Profile.FdDict.keys():\r
+            FdObj = GenFdsGlobalVariable.FdfParser.Profile.FdDict[FdName]\r
+            for RegionObj in FdObj.RegionList:\r
+                if RegionObj.RegionType != 'FV':\r
+                    continue\r
+                for RegionData in RegionObj.RegionDataList:\r
+                    #\r
+                    # Found the FD and region that contain this FV\r
+                    #\r
+                    if self.UiFvName.upper() == RegionData.upper():\r
+                        RegionObj.BlockInfoOfRegion(FdObj.BlockSizeList, self)\r
+                        if self.BlockSizeList:\r
+                            return True\r
+        return False\r
+\r
     ## __InitializeInf__()\r
     #\r
     #   Initilize the inf file to create FV\r
@@ -245,8 +272,9 @@ class FV (FvClassObject):
                                       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
+                if not self._GetBlockSize():\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