X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2FGenFds%2FRegion.py;h=83363276d2c40a255e0337c702542c0a80cf37d2;hb=b3e94a06172113991f28a1eff096255c65702a0c;hp=945c5489fdfede83b46ce4f5fadc15f91b7629f0;hpb=f8db6527da8678f1480f08ba99b745279e8d104a;p=mirror_edk2.git
diff --git a/BaseTools/Source/Python/GenFds/Region.py b/BaseTools/Source/Python/GenFds/Region.py
index 945c5489fd..83363276d2 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 - 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
@@ -15,30 +15,36 @@
##
# Import Modules
#
+from __future__ import absolute_import
from struct import *
-from GenFdsGlobalVariable import GenFdsGlobalVariable
-import StringIO
+from .GenFdsGlobalVariable import GenFdsGlobalVariable
+from io import BytesIO
import string
-from CommonDataClass.FdfClass import RegionClassObject
import Common.LongFilePathOs as os
from stat import *
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
#
#
-class Region(RegionClassObject):
+class Region(object):
## The constructor
#
# @param self The object pointer
#
def __init__(self):
- RegionClassObject.__init__(self)
-
+ self.Offset = None # The begin position of the Region
+ self.Size = None # The Size of the Region
+ self.PcdOffset = None
+ self.PcdSize = None
+ self.SetVarDict = {}
+ self.RegionType = None
+ self.RegionDataList = []
## PadBuffer()
#
@@ -56,7 +62,7 @@ class Region(RegionClassObject):
PadByte = pack('B', 0xFF)
else:
PadByte = pack('B', 0)
- PadData = ''.join(PadByte for i in xrange(0, Size))
+ PadData = ''.join(PadByte for i in range(0, Size))
Buffer.write(PadData)
## AddToBuffer()
@@ -69,18 +75,20 @@ class Region(RegionClassObject):
# @param BlockSize block size of region
# @param BlockNum How many blocks in region
# @param ErasePolarity Flash erase polarity
- # @param VtfDict VTF objects
# @param MacroDict macro value pair
# @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, 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
#
@@ -91,41 +99,48 @@ 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):
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
#
self.BlockInfoOfRegion(BlockSizeList, FvObj)
self.FvAddress = self.FvAddress + FvOffset
- FvAlignValue = self.GetFvAlignValue(FvObj.FvAlignment)
+ FvAlignValue = GenFdsGlobalVariable.GetAlignment(FvObj.FvAlignment)
if self.FvAddress % FvAlignValue != 0:
EdkLogger.error("GenFds", GENFDS_ERROR,
"FV (%s) is NOT %s Aligned!" % (FvObj.UiFvName, FvObj.FvAlignment))
- FvBuffer = StringIO.StringIO('')
+ FvBuffer = BytesIO('')
FvBaseAddress = '0x%X' % self.FvAddress
BlockSize = None
BlockNum = None
- FvObj.AddToBuffer(FvBuffer, FvBaseAddress, BlockSize, BlockNum, ErasePolarity, vtfDict)
- if FvBuffer.len > Size:
+ FvObj.AddToBuffer(FvBuffer, FvBaseAddress, BlockSize, BlockNum, ErasePolarity, Flag=Flag)
+ if Flag:
+ continue
+
+ FvBufferLen = len(FvBuffer.getvalue())
+ if FvBufferLen > Size:
FvBuffer.close()
EdkLogger.error("GenFds", GENFDS_ERROR,
"Size of FV (%s) is larger than Region Size 0x%X specified." % (RegionData, Size))
@@ -134,28 +149,30 @@ class Region(RegionClassObject):
#
Buffer.write(FvBuffer.getvalue())
FvBuffer.close()
- FvOffset = FvOffset + FvBuffer.len
- Size = Size - FvBuffer.len
+ FvOffset = FvOffset + FvBufferLen
+ Size = Size - FvBufferLen
continue
else:
EdkLogger.error("GenFds", GENFDS_ERROR, "FV (%s) is NOT described in FDF file!" % (RegionData))
#
# 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, 'rb')
- 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
#
- self.PadBuffer(Buffer, ErasePolarity, Size)
+ if not Flag:
+ self.PadBuffer(Buffer, ErasePolarity, Size)
if self.RegionType == 'CAPSULE':
#
@@ -171,7 +188,7 @@ class Region(RegionClassObject):
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:
@@ -179,10 +196,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')
#
@@ -259,29 +276,10 @@ class Region(RegionClassObject):
#
self.PadBuffer(Buffer, ErasePolarity, Size)
- if self.RegionType == None:
+ if self.RegionType is None:
GenFdsGlobalVariable.InfLogger(' Region Name = None')
self.PadBuffer(Buffer, ErasePolarity, Size)
- def GetFvAlignValue(self, Str):
- AlignValue = 1
- Granu = 1
- Str = Str.strip().upper()
- if Str.endswith('K'):
- Granu = 1024
- Str = Str[:-1]
- elif Str.endswith('M'):
- Granu = 1024 * 1024
- Str = Str[:-1]
- elif Str.endswith('G'):
- Granu = 1024 * 1024 * 1024
- Str = Str[:-1]
- else:
- pass
-
- AlignValue = int(Str) * Granu
- return AlignValue
-
## BlockSizeOfRegion()
#
# @param BlockSizeList List of block information
@@ -298,11 +296,11 @@ class Region(RegionClassObject):
if self.Offset >= End:
Start = End
continue
- # region located in current blocks
+ # region located in current blocks
else:
# region ended within current blocks
if self.Offset + self.Size <= End:
- ExpectedList.append((BlockSize, (RemindingSize + BlockSize - 1) / BlockSize))
+ ExpectedList.append((BlockSize, (RemindingSize + BlockSize - 1) // BlockSize))
break
# region not ended yet
else:
@@ -311,7 +309,7 @@ class Region(RegionClassObject):
UsedBlockNum = BlockNum
# region started in middle of current blocks
else:
- UsedBlockNum = (End - self.Offset) / BlockSize
+ UsedBlockNum = (End - self.Offset) // BlockSize
Start = End
ExpectedList.append((BlockSize, UsedBlockNum))
RemindingSize -= BlockSize * UsedBlockNum
@@ -322,7 +320,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
@@ -350,5 +348,5 @@ class Region(RegionClassObject):
else:
Index += 1
-
+