X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2FGenFds%2FRegion.py;h=c946758cf549cf7914d8af9c6d9468fb8064e5e6;hb=cf245466a56a7be7405142753c6c6a6689b7461b;hp=6769b39ba7e83ee976a21a54449771c307bd2fb7;hpb=5588565f4845d8138888f436218bc8334c0be54f;p=mirror_edk2.git
diff --git a/BaseTools/Source/Python/GenFds/Region.py b/BaseTools/Source/Python/GenFds/Region.py
index 6769b39ba7..c946758cf5 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 - 2015, Intel Corporation. All rights reserved.
+# Copyright (c) 2007 - 2017, 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 *
@@ -52,11 +53,11 @@ class Region(RegionClassObject):
def PadBuffer(self, Buffer, ErasePolarity, Size):
if Size > 0:
if (ErasePolarity == '1') :
- PadData = 0xFF
+ PadByte = pack('B', 0xFF)
else:
- PadData = 0
- for i in range(0, Size):
- Buffer.write(pack('B', PadData))
+ PadByte = pack('B', 0)
+ PadData = ''.join(PadByte for i in xrange(0, Size))
+ Buffer.write(PadData)
## AddToBuffer()
#
@@ -73,11 +74,14 @@ 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 != 'FV'):
+ return
if self.RegionType == 'FV':
#
@@ -90,7 +94,8 @@ 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 = mws.join (GenFdsGlobalVariable.WorkSpaceDir, RegionData)
if not os.path.exists(RegionData):
@@ -98,7 +103,8 @@ class Region(RegionClassObject):
FileName = RegionData
elif RegionData.upper() + 'fv' in ImageBinDict.keys():
- GenFdsGlobalVariable.InfLogger(' Region Name = FV')
+ if not Flag:
+ GenFdsGlobalVariable.InfLogger(' Region Name = FV')
FileName = ImageBinDict[RegionData.upper() + 'fv']
else:
#
@@ -109,7 +115,8 @@ class Region(RegionClassObject):
FvObj = GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(RegionData.upper())
if FvObj != None :
- GenFdsGlobalVariable.InfLogger(' Region Name = FV')
+ if not Flag:
+ GenFdsGlobalVariable.InfLogger(' Region Name = FV')
#
# Call GenFv tool
#
@@ -123,7 +130,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,
@@ -141,20 +151,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 != 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
#
- self.PadBuffer(Buffer, ErasePolarity, Size)
+ if not Flag:
+ self.PadBuffer(Buffer, ErasePolarity, Size)
if self.RegionType == 'CAPSULE':
#
@@ -200,7 +212,7 @@ 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