BaseTools: Add support for INF statement in FD region

FD region today can be file or data, but not a patched image.Add support
for an INF statement in an FD region, so the binary from the INF can be
patched prior to being added to the FD region.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Yonghong Zhu <yonghong.zhu@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@19136 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Yonghong Zhu
2015-12-07 08:27:53 +00:00
committed by yzhu52
parent 84c7452165
commit b21a13fbb6
3 changed files with 91 additions and 31 deletions

View File

@ -331,25 +331,63 @@ class FfsInfStatement(FfsInfStatementClassObject):
# If passed in file does not end with efi, return as is
#
def PatchEfiFile(self, EfiFile, FileType):
#
# If the module does not have any patches, then return path to input file
#
if not self.PatchPcds:
return EfiFile
#
# Only patch file if FileType is PE32 or ModuleType is USER_DEFINED
#
if FileType != 'PE32' and self.ModuleType != "USER_DEFINED":
return EfiFile
#
# Generate path to patched output file
#
Basename = os.path.basename(EfiFile)
Output = os.path.normpath (os.path.join(self.OutputPath, Basename))
#
# If this file has already been patched, then return the path to the patched file
#
if self.PatchedBinFile == Output:
return Output
#
# If a different file from the same module has already been patched, then generate an error
#
if self.PatchedBinFile:
EdkLogger.error("GenFds", GENFDS_ERROR,
'Only one binary file can be patched:\n'
' a binary file has been patched: %s\n'
' current file: %s' % (self.PatchedBinFile, EfiFile),
File=self.InfFileName)
Basename = os.path.basename(EfiFile)
Output = os.path.join(self.OutputPath, Basename)
#
# Copy unpatched file contents to output file location to perform patching
#
CopyLongFilePath(EfiFile, Output)
#
# Apply patches to patched output file
#
for Pcd, Value in self.PatchPcds:
RetVal, RetStr = PatchBinaryFile(Output, int(Pcd.Offset, 0), Pcd.DatumType, Value, Pcd.MaxDatumSize)
if RetVal:
EdkLogger.error("GenFds", GENFDS_ERROR, RetStr, File=self.InfFileName)
self.PatchedBinFile = os.path.normpath(EfiFile)
#
# Save the path of the patched output file
#
self.PatchedBinFile = Output
#
# Return path to patched output file
#
return Output
## GenFfs() method
#
# Generate FFS