## @file\r
# process FV generation\r
#\r
-# Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<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
\r
import Ffs\r
import AprioriSection\r
+import FfsFileStatement\r
from GenFdsGlobalVariable import GenFdsGlobalVariable\r
from GenFds import GenFds\r
from CommonDataClass.FdfClass import FvClassObject\r
self.CapsuleName = None\r
self.FvBaseAddress = None\r
self.FvForceRebase = None\r
+ self.FvRegionInFD = None\r
+ self.UsedSizeEnable = False\r
\r
## AddToBuffer()\r
#\r
# @param MacroDict macro value pair\r
# @retval string Generated FV file path\r
#\r
- def AddToBuffer (self, Buffer, BaseAddress=None, BlockSize= None, BlockNum=None, ErasePloarity='1', VtfDict=None, MacroDict = {}) :\r
+ def AddToBuffer (self, Buffer, BaseAddress=None, BlockSize= None, BlockNum=None, ErasePloarity='1', VtfDict=None, MacroDict = {}, Flag=False) :\r
\r
- if BaseAddress == None and self.UiFvName.upper() + 'fv' in GenFds.ImageBinDict.keys():\r
+ if BaseAddress is None and self.UiFvName.upper() + 'fv' in GenFds.ImageBinDict.keys():\r
return GenFds.ImageBinDict[self.UiFvName.upper() + 'fv']\r
\r
#\r
# Check whether FV in Capsule is in FD flash region.\r
# If yes, return error. Doesn't support FV in Capsule image is also in FD flash region.\r
#\r
- if self.CapsuleName != None:\r
+ if self.CapsuleName is not None:\r
for FdName in GenFdsGlobalVariable.FdfParser.Profile.FdDict.keys():\r
FdObj = GenFdsGlobalVariable.FdfParser.Profile.FdDict[FdName]\r
for RegionObj in FdObj.RegionList:\r
continue\r
elif self.UiFvName.upper() == RegionData.upper():\r
GenFdsGlobalVariable.ErrorLogger("Capsule %s in FD region can't contain a FV %s in FD region." % (self.CapsuleName, self.UiFvName.upper()))\r
-\r
- GenFdsGlobalVariable.InfLogger( "\nGenerating %s FV" %self.UiFvName)\r
+ if not Flag:\r
+ GenFdsGlobalVariable.InfLogger( "\nGenerating %s FV" %self.UiFvName)\r
GenFdsGlobalVariable.LargeFileInFvFlags.append(False)\r
FFSGuid = None\r
\r
- if self.FvBaseAddress != None:\r
+ if self.FvBaseAddress is not None:\r
BaseAddress = self.FvBaseAddress\r
-\r
- self.__InitializeInf__(BaseAddress, BlockSize, BlockNum, ErasePloarity, VtfDict)\r
+ if not Flag:\r
+ self.__InitializeInf__(BaseAddress, BlockSize, BlockNum, ErasePloarity, VtfDict)\r
#\r
# First Process the Apriori section\r
#\r
GenFdsGlobalVariable.VerboseLogger('First generate Apriori file !')\r
FfsFileList = []\r
for AprSection in self.AprioriSectionList:\r
- FileName = AprSection.GenFfs (self.UiFvName, MacroDict)\r
+ FileName = AprSection.GenFfs (self.UiFvName, MacroDict, IsMakefile=Flag)\r
FfsFileList.append(FileName)\r
# Add Apriori file name to Inf file\r
- self.FvInfFile.writelines("EFI_FILE_NAME = " + \\r
- FileName + \\r
- T_CHAR_LF)\r
+ if not Flag:\r
+ self.FvInfFile.writelines("EFI_FILE_NAME = " + \\r
+ FileName + \\r
+ T_CHAR_LF)\r
\r
# Process Modules in FfsList\r
for FfsFile in self.FfsList :\r
- FileName = FfsFile.GenFfs(MacroDict, FvParentAddr=BaseAddress)\r
+ if Flag:\r
+ if isinstance(FfsFile, FfsFileStatement.FileStatement):\r
+ continue\r
+ if GenFdsGlobalVariable.EnableGenfdsMultiThread and GenFdsGlobalVariable.ModuleFile and GenFdsGlobalVariable.ModuleFile.Path.find(os.path.normpath(FfsFile.InfFileName)) == -1:\r
+ continue\r
+ FileName = FfsFile.GenFfs(MacroDict, FvParentAddr=BaseAddress, IsMakefile=Flag, FvName=self.UiFvName)\r
FfsFileList.append(FileName)\r
- self.FvInfFile.writelines("EFI_FILE_NAME = " + \\r
- FileName + \\r
- T_CHAR_LF)\r
-\r
- SaveFileOnChange(self.InfFileName, self.FvInfFile.getvalue(), False)\r
- self.FvInfFile.close()\r
+ if not Flag:\r
+ self.FvInfFile.writelines("EFI_FILE_NAME = " + \\r
+ FileName + \\r
+ T_CHAR_LF)\r
+ if not Flag:\r
+ SaveFileOnChange(self.InfFileName, self.FvInfFile.getvalue(), False)\r
+ self.FvInfFile.close()\r
#\r
# Call GenFv tool\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
+ if self.CreateFileName is not None:\r
FvOutputFile = self.CreateFileName\r
\r
+ if Flag:\r
+ GenFds.ImageBinDict[self.UiFvName.upper() + 'fv'] = FvOutputFile\r
+ return FvOutputFile\r
+\r
FvInfoFileName = os.path.join(GenFdsGlobalVariable.FfsDir, self.UiFvName + '.inf')\r
- CopyLongFilePath(GenFdsGlobalVariable.FvAddressFileName, FvInfoFileName)\r
- OrigFvInfo = None\r
- if os.path.exists (FvInfoFileName):\r
- OrigFvInfo = open(FvInfoFileName, 'r').read()\r
- if GenFdsGlobalVariable.LargeFileInFvFlags[-1]:\r
- FFSGuid = GenFdsGlobalVariable.EFI_FIRMWARE_FILE_SYSTEM3_GUID;\r
- GenFdsGlobalVariable.GenerateFirmwareVolume(\r
- FvOutputFile,\r
- [self.InfFileName],\r
- AddressFile=FvInfoFileName,\r
- FfsList=FfsFileList,\r
- ForceRebase=self.FvForceRebase,\r
- FileSystemGuid=FFSGuid\r
- )\r
+ if not Flag:\r
+ CopyLongFilePath(GenFdsGlobalVariable.FvAddressFileName, FvInfoFileName)\r
+ OrigFvInfo = None\r
+ if os.path.exists (FvInfoFileName):\r
+ OrigFvInfo = open(FvInfoFileName, 'r').read()\r
+ if GenFdsGlobalVariable.LargeFileInFvFlags[-1]:\r
+ FFSGuid = GenFdsGlobalVariable.EFI_FIRMWARE_FILE_SYSTEM3_GUID\r
+ GenFdsGlobalVariable.GenerateFirmwareVolume(\r
+ FvOutputFile,\r
+ [self.InfFileName],\r
+ AddressFile=FvInfoFileName,\r
+ FfsList=FfsFileList,\r
+ ForceRebase=self.FvForceRebase,\r
+ FileSystemGuid=FFSGuid\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
+ NewFvInfo = None\r
+ if os.path.exists (FvInfoFileName):\r
+ NewFvInfo = open(FvInfoFileName, 'r').read()\r
+ if NewFvInfo is not 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
- if GenFdsGlobalVariable.LargeFileInFvFlags[-1]:\r
- FFSGuid = GenFdsGlobalVariable.EFI_FIRMWARE_FILE_SYSTEM3_GUID;\r
- #Update GenFv again\r
- GenFdsGlobalVariable.GenerateFirmwareVolume(\r
- FvOutputFile,\r
- [self.InfFileName],\r
- AddressFile=FvInfoFileName,\r
- FfsList=FfsFileList,\r
- ForceRebase=self.FvForceRebase,\r
- FileSystemGuid=FFSGuid\r
- )\r
+ if FvChildAddr != []:\r
+ # Update Ffs again\r
+ for FfsFile in self.FfsList :\r
+ FileName = FfsFile.GenFfs(MacroDict, FvChildAddr, BaseAddress, IsMakefile=Flag, FvName=self.UiFvName)\r
\r
- #\r
- # Write the Fv contents to Buffer\r
- #\r
- if os.path.isfile(FvOutputFile):\r
- FvFileObj = open ( FvOutputFile,'r+b')\r
+ if GenFdsGlobalVariable.LargeFileInFvFlags[-1]:\r
+ FFSGuid = GenFdsGlobalVariable.EFI_FIRMWARE_FILE_SYSTEM3_GUID;\r
+ #Update GenFv again\r
+ GenFdsGlobalVariable.GenerateFirmwareVolume(\r
+ FvOutputFile,\r
+ [self.InfFileName],\r
+ AddressFile=FvInfoFileName,\r
+ FfsList=FfsFileList,\r
+ ForceRebase=self.FvForceRebase,\r
+ FileSystemGuid=FFSGuid\r
+ )\r
\r
- GenFdsGlobalVariable.VerboseLogger( "\nGenerate %s FV Successfully" %self.UiFvName)\r
- GenFdsGlobalVariable.SharpCounter = 0\r
+ #\r
+ # Write the Fv contents to Buffer\r
+ #\r
+ if os.path.isfile(FvOutputFile):\r
+ FvFileObj = open(FvOutputFile, 'rb')\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
+ if FvAlignmentValue >= 0x400:\r
+ if FvAlignmentValue >= 0x100000:\r
+ if FvAlignmentValue >= 0x1000000:\r
+ #The max alignment supported by FFS is 16M.\r
+ self.FvAlignment = "16M"\r
+ else:\r
+ self.FvAlignment = str(FvAlignmentValue / 0x100000) + "M"\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
- else:\r
- GenFdsGlobalVariable.ErrorLogger("Failed to generate %s FV file." %self.UiFvName)\r
+ GenFdsGlobalVariable.ErrorLogger("Failed to generate %s FV file." %self.UiFvName)\r
return FvOutputFile\r
\r
## _GetBlockSize()\r
# Add [Options]\r
#\r
self.FvInfFile.writelines("[options]" + T_CHAR_LF)\r
- if BaseAddress != None :\r
+ if BaseAddress is not None :\r
self.FvInfFile.writelines("EFI_BASE_ADDRESS = " + \\r
BaseAddress + \\r
T_CHAR_LF)\r
\r
- if BlockSize != None:\r
+ if BlockSize is not None:\r
self.FvInfFile.writelines("EFI_BLOCK_SIZE = " + \\r
'0x%X' %BlockSize + \\r
T_CHAR_LF)\r
- if BlockNum != None:\r
+ if BlockNum is not None:\r
self.FvInfFile.writelines("EFI_NUM_BLOCKS = " + \\r
' 0x%X' %BlockNum + \\r
T_CHAR_LF)\r
self.FvInfFile.writelines("EFI_BLOCK_SIZE = 0x1" + T_CHAR_LF)\r
\r
for BlockSize in self.BlockSizeList :\r
- if BlockSize[0] != None:\r
+ if BlockSize[0] is not None:\r
self.FvInfFile.writelines("EFI_BLOCK_SIZE = " + \\r
'0x%X' %BlockSize[0] + \\r
T_CHAR_LF)\r
\r
- if BlockSize[1] != None:\r
+ if BlockSize[1] is not None:\r
self.FvInfFile.writelines("EFI_NUM_BLOCKS = " + \\r
' 0x%X' %BlockSize[1] + \\r
T_CHAR_LF)\r
\r
- if self.BsBaseAddress != None:\r
+ if self.BsBaseAddress is not None:\r
self.FvInfFile.writelines('EFI_BOOT_DRIVER_BASE_ADDRESS = ' + \\r
'0x%X' %self.BsBaseAddress)\r
- if self.RtBaseAddress != None:\r
+ if self.RtBaseAddress is not None:\r
self.FvInfFile.writelines('EFI_RUNTIME_DRIVER_BASE_ADDRESS = ' + \\r
'0x%X' %self.RtBaseAddress)\r
#\r
self.FvInfFile.writelines("EFI_ERASE_POLARITY = " + \\r
' %s' %ErasePloarity + \\r
T_CHAR_LF)\r
- if not (self.FvAttributeDict == None):\r
+ if not (self.FvAttributeDict is None):\r
for FvAttribute in self.FvAttributeDict.keys() :\r
+ if FvAttribute == "FvUsedSizeEnable":\r
+ if self.FvAttributeDict[FvAttribute].upper() in ('TRUE', '1') :\r
+ self.UsedSizeEnable = True\r
+ continue\r
self.FvInfFile.writelines("EFI_" + \\r
FvAttribute + \\r
' = ' + \\r
self.FvAttributeDict[FvAttribute] + \\r
T_CHAR_LF )\r
- if self.FvAlignment != None:\r
+ if self.FvAlignment is not None:\r
self.FvInfFile.writelines("EFI_FVB2_ALIGNMENT_" + \\r
self.FvAlignment.strip() + \\r
" = TRUE" + \\r
#\r
# Generate FV extension header file\r
#\r
- if self.FvNameGuid == None or self.FvNameGuid == '':\r
- if len(self.FvExtEntryType) > 0:\r
+ if self.FvNameGuid is None or self.FvNameGuid == '':\r
+ if len(self.FvExtEntryType) > 0 or self.UsedSizeEnable:\r
GenFdsGlobalVariable.ErrorLogger("FV Extension Header Entries declared for %s with no FvNameGuid declaration." % (self.UiFvName))\r
\r
if self.FvNameGuid <> None and self.FvNameGuid <> '':\r
TotalSize = 16 + 4\r
Buffer = ''\r
+ if self.UsedSizeEnable:\r
+ TotalSize += (4 + 4)\r
+ ## define EFI_FV_EXT_TYPE_USED_SIZE_TYPE 0x03\r
+ #typedef struct\r
+ # {\r
+ # EFI_FIRMWARE_VOLUME_EXT_ENTRY Hdr;\r
+ # UINT32 UsedSize;\r
+ # } EFI_FIRMWARE_VOLUME_EXT_ENTRY_USED_SIZE_TYPE;\r
+ Buffer += pack('HHL', 8, 3, 0)\r
+\r
if self.FvNameString == 'TRUE':\r
#\r
# Create EXT entry for FV UI name\r
# Add [Files]\r
#\r
self.FvInfFile.writelines("[files]" + T_CHAR_LF)\r
- if VtfDict != None and self.UiFvName in VtfDict.keys():\r
+ if VtfDict is not None and self.UiFvName in VtfDict.keys():\r
self.FvInfFile.writelines("EFI_FILE_NAME = " + \\r
VtfDict.get(self.UiFvName) + \\r
T_CHAR_LF)\r