X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2FGenFds%2FRegion.py;h=9d632b6321e2daef8d546f04293d0393c36509ce;hb=92beb1e4c73a40a708c7c0cade5c7cee314b3887;hp=01e998e54c6fb6c5fa2ec1aa5c4d0f8e47622c54;hpb=47fea6afd74af76c7e2a2b03d319b7ac035ac26a;p=mirror_edk2.git
diff --git a/BaseTools/Source/Python/GenFds/Region.py b/BaseTools/Source/Python/GenFds/Region.py
index 01e998e54c..9d632b6321 100644
--- a/BaseTools/Source/Python/GenFds/Region.py
+++ b/BaseTools/Source/Python/GenFds/Region.py
@@ -1,7 +1,7 @@
## @file
# process FD Region generation
#
-# Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.
+# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
@@ -18,6 +18,7 @@
from struct import *
from GenFdsGlobalVariable import GenFdsGlobalVariable
import StringIO
+import string
from CommonDataClass.FdfClass import RegionClassObject
import Common.LongFilePathOs as os
from stat import *
@@ -25,6 +26,7 @@ from Common import EdkLogger
from Common.BuildToolError import *
from Common.LongFilePathSupport import OpenLongFilePath as open
from Common.MultipleWorkspace import MultipleWorkspace as mws
+from Common.DataType import BINARY_FILE_TYPE_FV
## generate Region
#
@@ -39,6 +41,25 @@ class Region(RegionClassObject):
RegionClassObject.__init__(self)
+ ## PadBuffer()
+ #
+ # Add padding bytes to the Buffer
+ #
+ # @param Buffer The buffer the generated region data will be put
+ # in
+ # @param ErasePolarity Flash erase polarity
+ # @param Size Number of padding bytes requested
+ #
+
+ def PadBuffer(self, Buffer, ErasePolarity, Size):
+ if Size > 0:
+ if (ErasePolarity == '1') :
+ PadByte = pack('B', 0xFF)
+ else:
+ PadByte = pack('B', 0)
+ PadData = ''.join(PadByte for i in xrange(0, Size))
+ Buffer.write(PadData)
+
## AddToBuffer()
#
# Add region data to the Buffer
@@ -54,13 +75,16 @@ class Region(RegionClassObject):
# @retval string Generated FV file path
#
- def AddToBuffer(self, Buffer, BaseAddress, BlockSizeList, ErasePolarity, ImageBinDict, vtfDict=None, MacroDict={}):
+ def AddToBuffer(self, Buffer, BaseAddress, BlockSizeList, ErasePolarity, ImageBinDict, vtfDict=None, MacroDict={}, Flag=False):
Size = self.Size
- GenFdsGlobalVariable.InfLogger('\nGenerate Region at Offset 0x%X' % self.Offset)
- GenFdsGlobalVariable.InfLogger(" Region Size = 0x%X" % Size)
+ if not Flag:
+ GenFdsGlobalVariable.InfLogger('\nGenerate Region at Offset 0x%X' % self.Offset)
+ GenFdsGlobalVariable.InfLogger(" Region Size = 0x%X" % Size)
GenFdsGlobalVariable.SharpCounter = 0
+ if Flag and (self.RegionType != BINARY_FILE_TYPE_FV):
+ return
- if self.RegionType == 'FV':
+ if self.RegionType == BINARY_FILE_TYPE_FV:
#
# Get Fv from FvDict
#
@@ -71,26 +95,29 @@ class Region(RegionClassObject):
FileName = None
if RegionData.endswith(".fv"):
RegionData = GenFdsGlobalVariable.MacroExtend(RegionData, MacroDict)
- GenFdsGlobalVariable.InfLogger(' Region FV File Name = .fv : %s' % RegionData)
+ if not Flag:
+ GenFdsGlobalVariable.InfLogger(' Region FV File Name = .fv : %s' % RegionData)
if RegionData[1] != ':' :
- RegionData = os.path.join (GenFdsGlobalVariable.WorkSpaceDir, RegionData)
+ RegionData = mws.join (GenFdsGlobalVariable.WorkSpaceDir, RegionData)
if not os.path.exists(RegionData):
EdkLogger.error("GenFds", FILE_NOT_FOUND, ExtraData=RegionData)
FileName = RegionData
- elif RegionData.upper() + 'fv' in ImageBinDict.keys():
- GenFdsGlobalVariable.InfLogger(' Region Name = FV')
+ elif RegionData.upper() + 'fv' in ImageBinDict:
+ if not Flag:
+ GenFdsGlobalVariable.InfLogger(' Region Name = FV')
FileName = ImageBinDict[RegionData.upper() + 'fv']
else:
#
# Generate FvImage.
#
FvObj = None
- if RegionData.upper() in GenFdsGlobalVariable.FdfParser.Profile.FvDict.keys():
- FvObj = GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(RegionData.upper())
+ if RegionData.upper() in GenFdsGlobalVariable.FdfParser.Profile.FvDict:
+ FvObj = GenFdsGlobalVariable.FdfParser.Profile.FvDict[RegionData.upper()]
- if FvObj != None :
- GenFdsGlobalVariable.InfLogger(' Region Name = FV')
+ if FvObj is not None :
+ if not Flag:
+ GenFdsGlobalVariable.InfLogger(' Region Name = FV')
#
# Call GenFv tool
#
@@ -104,7 +131,10 @@ class Region(RegionClassObject):
FvBaseAddress = '0x%X' % self.FvAddress
BlockSize = None
BlockNum = None
- FvObj.AddToBuffer(FvBuffer, FvBaseAddress, BlockSize, BlockNum, ErasePolarity, vtfDict)
+ FvObj.AddToBuffer(FvBuffer, FvBaseAddress, BlockSize, BlockNum, ErasePolarity, vtfDict, Flag=Flag)
+ if Flag:
+ continue
+
if FvBuffer.len > Size:
FvBuffer.close()
EdkLogger.error("GenFds", GENFDS_ERROR,
@@ -122,26 +152,22 @@ class Region(RegionClassObject):
#
# Add the exist Fv image into FD buffer
#
- if FileName != None:
- FileLength = os.stat(FileName)[ST_SIZE]
- if FileLength > Size:
- EdkLogger.error("GenFds", GENFDS_ERROR,
- "Size of FV File (%s) is larger than Region Size 0x%X specified." \
- % (RegionData, Size))
- BinFile = open(FileName, 'r+b')
- Buffer.write(BinFile.read())
- BinFile.close()
- Size = Size - FileLength
+ if not Flag:
+ if FileName is not None:
+ FileLength = os.stat(FileName)[ST_SIZE]
+ if FileLength > Size:
+ EdkLogger.error("GenFds", GENFDS_ERROR,
+ "Size of FV File (%s) is larger than Region Size 0x%X specified." \
+ % (RegionData, Size))
+ BinFile = open(FileName, 'rb')
+ Buffer.write(BinFile.read())
+ BinFile.close()
+ Size = Size - FileLength
#
# Pad the left buffer
#
- if Size > 0:
- if (ErasePolarity == '1') :
- PadData = 0xFF
- else :
- PadData = 0
- for i in range(0, Size):
- Buffer.write(pack('B', PadData))
+ if not Flag:
+ self.PadBuffer(Buffer, ErasePolarity, Size)
if self.RegionType == 'CAPSULE':
#
@@ -152,12 +178,12 @@ class Region(RegionClassObject):
RegionData = GenFdsGlobalVariable.MacroExtend(RegionData, MacroDict)
GenFdsGlobalVariable.InfLogger(' Region CAPSULE Image Name = .cap : %s' % RegionData)
if RegionData[1] != ':' :
- RegionData = os.path.join (GenFdsGlobalVariable.WorkSpaceDir, RegionData)
+ RegionData = mws.join (GenFdsGlobalVariable.WorkSpaceDir, RegionData)
if not os.path.exists(RegionData):
EdkLogger.error("GenFds", FILE_NOT_FOUND, ExtraData=RegionData)
FileName = RegionData
- elif RegionData.upper() + 'cap' in ImageBinDict.keys():
+ elif RegionData.upper() + 'cap' in ImageBinDict:
GenFdsGlobalVariable.InfLogger(' Region Name = CAPSULE')
FileName = ImageBinDict[RegionData.upper() + 'cap']
else:
@@ -165,10 +191,10 @@ class Region(RegionClassObject):
# Generate Capsule image and Put it into FD buffer
#
CapsuleObj = None
- if RegionData.upper() in GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict.keys():
+ if RegionData.upper() in GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict:
CapsuleObj = GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict[RegionData.upper()]
- if CapsuleObj != None :
+ if CapsuleObj is not None :
CapsuleObj.CapsuleName = RegionData.upper()
GenFdsGlobalVariable.InfLogger(' Region Name = CAPSULE')
#
@@ -187,28 +213,29 @@ class Region(RegionClassObject):
EdkLogger.error("GenFds", GENFDS_ERROR,
"Size 0x%X of Capsule File (%s) is larger than Region Size 0x%X specified." \
% (FileLength, RegionData, Size))
- BinFile = open(FileName, 'r+b')
+ BinFile = open(FileName, 'rb')
Buffer.write(BinFile.read())
BinFile.close()
Size = Size - FileLength
#
# Pad the left buffer
#
- if Size > 0:
- if (ErasePolarity == '1') :
- PadData = 0xFF
- else :
- PadData = 0
- for i in range(0, Size):
- Buffer.write(pack('B', PadData))
+ self.PadBuffer(Buffer, ErasePolarity, Size)
- if self.RegionType == 'FILE':
+ if self.RegionType in ('FILE', 'INF'):
for RegionData in self.RegionDataList:
- RegionData = GenFdsGlobalVariable.MacroExtend(RegionData, MacroDict)
- if RegionData[1] != ':' :
- RegionData = mws.join (GenFdsGlobalVariable.WorkSpaceDir, RegionData)
- if not os.path.exists(RegionData):
- EdkLogger.error("GenFds", FILE_NOT_FOUND, ExtraData=RegionData)
+ if self.RegionType == 'INF':
+ RegionData.__InfParse__(None)
+ if len(RegionData.BinFileList) != 1:
+ EdkLogger.error('GenFds', GENFDS_ERROR, 'INF in FD region can only contain one binary: %s' % RegionData)
+ File = RegionData.BinFileList[0]
+ RegionData = RegionData.PatchEfiFile(File.Path, File.Type)
+ else:
+ RegionData = GenFdsGlobalVariable.MacroExtend(RegionData, MacroDict)
+ if RegionData[1] != ':' :
+ RegionData = mws.join (GenFdsGlobalVariable.WorkSpaceDir, RegionData)
+ if not os.path.exists(RegionData):
+ EdkLogger.error("GenFds", FILE_NOT_FOUND, ExtraData=RegionData)
#
# Add the file image into FD buffer
#
@@ -225,13 +252,7 @@ class Region(RegionClassObject):
#
# Pad the left buffer
#
- if Size > 0:
- if (ErasePolarity == '1') :
- PadData = 0xFF
- else :
- PadData = 0
- for i in range(0, Size):
- Buffer.write(pack('B', PadData))
+ self.PadBuffer(Buffer, ErasePolarity, Size)
if self.RegionType == 'DATA' :
GenFdsGlobalVariable.InfLogger(' Region Name = DATA')
@@ -248,22 +269,11 @@ class Region(RegionClassObject):
#
# Pad the left buffer
#
- if Size > 0:
- if (ErasePolarity == '1') :
- PadData = 0xFF
- else :
- PadData = 0
- for i in range(0, Size):
- Buffer.write(pack('B', PadData))
+ self.PadBuffer(Buffer, ErasePolarity, Size)
- if self.RegionType == None:
+ if self.RegionType is None:
GenFdsGlobalVariable.InfLogger(' Region Name = None')
- if (ErasePolarity == '1') :
- PadData = 0xFF
- else :
- PadData = 0
- for i in range(0, Size):
- Buffer.write(pack('B', PadData))
+ self.PadBuffer(Buffer, ErasePolarity, Size)
def GetFvAlignValue(self, Str):
AlignValue = 1
@@ -324,7 +334,7 @@ class Region(RegionClassObject):
# first check whether FvObj.BlockSizeList items have only "BlockSize" or "NumBlocks",
# if so, use ExpectedList
for Item in FvObj.BlockSizeList:
- if Item[0] == None or Item[1] == None:
+ if Item[0] is None or Item[1] is None:
FvObj.BlockSizeList = ExpectedList
break
# make sure region size is no smaller than the summed block size in FV