mirror of https://github.com/acidanthera/audk.git
BaseTools: standardize GUID and pack size
currently GUID packing and pack size determination is spread throughout the code. This introduces a shared function and dict and routes all code paths through them. Cc: Liming Gao <liming.gao@intel.com> Cc: Yonghong Zhu <yonghong.zhu@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jaben Carsey <jaben.carsey@intel.com> Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
This commit is contained in:
parent
31ff1c443e
commit
d0a0c52c22
|
@ -21,7 +21,6 @@ from Common.VariableAttributes import VariableAttributes
|
||||||
import copy
|
import copy
|
||||||
from struct import unpack
|
from struct import unpack
|
||||||
from Common.DataType import *
|
from Common.DataType import *
|
||||||
from GenVar import PackGUID
|
|
||||||
|
|
||||||
DATABASE_VERSION = 7
|
DATABASE_VERSION = 7
|
||||||
|
|
||||||
|
@ -290,22 +289,7 @@ class DbItemList:
|
||||||
GuidString = GuidStructureStringToGuidString(GuidStructureValue)
|
GuidString = GuidStructureStringToGuidString(GuidStructureValue)
|
||||||
return PackGUID(GuidString.split('-'))
|
return PackGUID(GuidString.split('-'))
|
||||||
|
|
||||||
if self.ItemSize == 8:
|
PackStr = PACK_CODE_BY_SIZE[self.ItemSize]
|
||||||
PackStr = "=Q"
|
|
||||||
elif self.ItemSize == 4:
|
|
||||||
PackStr = "=L"
|
|
||||||
elif self.ItemSize == 2:
|
|
||||||
PackStr = "=H"
|
|
||||||
elif self.ItemSize == 1:
|
|
||||||
PackStr = "=B"
|
|
||||||
elif self.ItemSize == 0:
|
|
||||||
PackStr = "=B"
|
|
||||||
elif self.ItemSize == 16:
|
|
||||||
# pack Guid
|
|
||||||
PackStr = ''
|
|
||||||
else:
|
|
||||||
# should not reach here
|
|
||||||
assert(False)
|
|
||||||
|
|
||||||
Buffer = ''
|
Buffer = ''
|
||||||
for Datas in self.RawDataList:
|
for Datas in self.RawDataList:
|
||||||
|
@ -379,18 +363,7 @@ class DbComItemList (DbItemList):
|
||||||
return self.ListSize
|
return self.ListSize
|
||||||
|
|
||||||
def PackData(self):
|
def PackData(self):
|
||||||
if self.ItemSize == 8:
|
PackStr = PACK_CODE_BY_SIZE[self.ItemSize]
|
||||||
PackStr = "=Q"
|
|
||||||
elif self.ItemSize == 4:
|
|
||||||
PackStr = "=L"
|
|
||||||
elif self.ItemSize == 2:
|
|
||||||
PackStr = "=H"
|
|
||||||
elif self.ItemSize == 1:
|
|
||||||
PackStr = "=B"
|
|
||||||
elif self.ItemSize == 0:
|
|
||||||
PackStr = "=B"
|
|
||||||
else:
|
|
||||||
assert(False)
|
|
||||||
|
|
||||||
Buffer = ''
|
Buffer = ''
|
||||||
for DataList in self.RawDataList:
|
for DataList in self.RawDataList:
|
||||||
|
@ -818,19 +791,7 @@ def BuildExDataBase(Dict):
|
||||||
# Construct the database buffer
|
# Construct the database buffer
|
||||||
Guid = "{0x3c7d193c, 0x682c, 0x4c14, 0xa6, 0x8f, 0x55, 0x2d, 0xea, 0x4f, 0x43, 0x7e}"
|
Guid = "{0x3c7d193c, 0x682c, 0x4c14, 0xa6, 0x8f, 0x55, 0x2d, 0xea, 0x4f, 0x43, 0x7e}"
|
||||||
Guid = StringArrayToList(Guid)
|
Guid = StringArrayToList(Guid)
|
||||||
Buffer = pack('=LHHBBBBBBBB',
|
Buffer = PackByteFormatGUID(Guid)
|
||||||
Guid[0],
|
|
||||||
Guid[1],
|
|
||||||
Guid[2],
|
|
||||||
Guid[3],
|
|
||||||
Guid[4],
|
|
||||||
Guid[5],
|
|
||||||
Guid[6],
|
|
||||||
Guid[7],
|
|
||||||
Guid[8],
|
|
||||||
Guid[9],
|
|
||||||
Guid[10],
|
|
||||||
)
|
|
||||||
|
|
||||||
b = pack("=L", DATABASE_VERSION)
|
b = pack("=L", DATABASE_VERSION)
|
||||||
Buffer += b
|
Buffer += b
|
||||||
|
|
|
@ -26,22 +26,6 @@ var_info = collections.namedtuple("uefi_var", "pcdindex,pcdname,defaultstoragena
|
||||||
NvStorageHeaderSize = 28
|
NvStorageHeaderSize = 28
|
||||||
VariableHeaderSize = 32
|
VariableHeaderSize = 32
|
||||||
|
|
||||||
def PackGUID(Guid):
|
|
||||||
GuidBuffer = pack('=LHHBBBBBBBB',
|
|
||||||
int(Guid[0], 16),
|
|
||||||
int(Guid[1], 16),
|
|
||||||
int(Guid[2], 16),
|
|
||||||
int(Guid[3][-4:-2], 16),
|
|
||||||
int(Guid[3][-2:], 16),
|
|
||||||
int(Guid[4][-12:-10], 16),
|
|
||||||
int(Guid[4][-10:-8], 16),
|
|
||||||
int(Guid[4][-8:-6], 16),
|
|
||||||
int(Guid[4][-6:-4], 16),
|
|
||||||
int(Guid[4][-4:-2], 16),
|
|
||||||
int(Guid[4][-2:], 16)
|
|
||||||
)
|
|
||||||
return GuidBuffer
|
|
||||||
|
|
||||||
class VariableMgr(object):
|
class VariableMgr(object):
|
||||||
def __init__(self, DefaultStoreMap,SkuIdMap):
|
def __init__(self, DefaultStoreMap,SkuIdMap):
|
||||||
self.VarInfo = []
|
self.VarInfo = []
|
||||||
|
@ -87,14 +71,7 @@ class VariableMgr(object):
|
||||||
data_type = item.data_type
|
data_type = item.data_type
|
||||||
value_list = item.default_value.strip("{").strip("}").split(",")
|
value_list = item.default_value.strip("{").strip("}").split(",")
|
||||||
if data_type in DataType.TAB_PCD_NUMERIC_TYPES:
|
if data_type in DataType.TAB_PCD_NUMERIC_TYPES:
|
||||||
if data_type == ["BOOLEAN", DataType.TAB_UINT8]:
|
data_flag = DataType.PACK_CODE_BY_SIZE[MAX_SIZE_TYPE[data_type]]
|
||||||
data_flag = "=B"
|
|
||||||
elif data_type == DataType.TAB_UINT16:
|
|
||||||
data_flag = "=H"
|
|
||||||
elif data_type == DataType.TAB_UINT32:
|
|
||||||
data_flag = "=L"
|
|
||||||
elif data_type == DataType.TAB_UINT64:
|
|
||||||
data_flag = "=Q"
|
|
||||||
data = value_list[0]
|
data = value_list[0]
|
||||||
value_list = []
|
value_list = []
|
||||||
for data_byte in pack(data_flag,int(data,16) if data.upper().startswith('0X') else int(data)):
|
for data_byte in pack(data_flag,int(data,16) if data.upper().startswith('0X') else int(data)):
|
||||||
|
|
|
@ -35,12 +35,6 @@ class VAR_CHECK_PCD_VARIABLE_TAB_CONTAINER(object):
|
||||||
|
|
||||||
def dump(self, dest, Phase):
|
def dump(self, dest, Phase):
|
||||||
|
|
||||||
FormatMap = {}
|
|
||||||
FormatMap[1] = "=B"
|
|
||||||
FormatMap[2] = "=H"
|
|
||||||
FormatMap[4] = "=L"
|
|
||||||
FormatMap[8] = "=Q"
|
|
||||||
|
|
||||||
if not os.path.isabs(dest):
|
if not os.path.isabs(dest):
|
||||||
return
|
return
|
||||||
if not os.path.exists(dest):
|
if not os.path.exists(dest):
|
||||||
|
@ -106,19 +100,7 @@ class VAR_CHECK_PCD_VARIABLE_TAB_CONTAINER(object):
|
||||||
realLength += 4
|
realLength += 4
|
||||||
|
|
||||||
Guid = var_check_tab.Guid
|
Guid = var_check_tab.Guid
|
||||||
b = pack('=LHHBBBBBBBB',
|
b = PackByteFormatGUID(Guid)
|
||||||
Guid[0],
|
|
||||||
Guid[1],
|
|
||||||
Guid[2],
|
|
||||||
Guid[3],
|
|
||||||
Guid[4],
|
|
||||||
Guid[5],
|
|
||||||
Guid[6],
|
|
||||||
Guid[7],
|
|
||||||
Guid[8],
|
|
||||||
Guid[9],
|
|
||||||
Guid[10],
|
|
||||||
)
|
|
||||||
Buffer += b
|
Buffer += b
|
||||||
realLength += 16
|
realLength += 16
|
||||||
|
|
||||||
|
@ -156,14 +138,14 @@ class VAR_CHECK_PCD_VARIABLE_TAB_CONTAINER(object):
|
||||||
realLength += 1
|
realLength += 1
|
||||||
for v_data in item.data:
|
for v_data in item.data:
|
||||||
if type(v_data) in (int, long):
|
if type(v_data) in (int, long):
|
||||||
b = pack(FormatMap[item.StorageWidth], v_data)
|
b = pack(PACK_CODE_BY_SIZE[item.StorageWidth], v_data)
|
||||||
Buffer += b
|
Buffer += b
|
||||||
realLength += item.StorageWidth
|
realLength += item.StorageWidth
|
||||||
else:
|
else:
|
||||||
b = pack(FormatMap[item.StorageWidth], v_data[0])
|
b = pack(PACK_CODE_BY_SIZE[item.StorageWidth], v_data[0])
|
||||||
Buffer += b
|
Buffer += b
|
||||||
realLength += item.StorageWidth
|
realLength += item.StorageWidth
|
||||||
b = pack(FormatMap[item.StorageWidth], v_data[1])
|
b = pack(PACK_CODE_BY_SIZE[item.StorageWidth], v_data[1])
|
||||||
Buffer += b
|
Buffer += b
|
||||||
realLength += item.StorageWidth
|
realLength += item.StorageWidth
|
||||||
|
|
||||||
|
|
|
@ -544,3 +544,14 @@ SECTIONS_HAVE_ITEM_AFTER_ARCH_SET = {TAB_LIBRARY_CLASSES.upper(), TAB_DEPEX.uppe
|
||||||
PCDS_DYNAMICEX_HII.upper(),
|
PCDS_DYNAMICEX_HII.upper(),
|
||||||
TAB_BUILD_OPTIONS.upper(),
|
TAB_BUILD_OPTIONS.upper(),
|
||||||
TAB_INCLUDES.upper()}
|
TAB_INCLUDES.upper()}
|
||||||
|
|
||||||
|
#
|
||||||
|
# pack codes as used in PcdDb and elsewhere
|
||||||
|
#
|
||||||
|
PACK_PATTERN_GUID = '=LHHBBBBBBBB'
|
||||||
|
PACK_CODE_BY_SIZE = {8:'=Q',
|
||||||
|
4:'=L',
|
||||||
|
2:'=H',
|
||||||
|
1:'=B',
|
||||||
|
0:'=B',
|
||||||
|
16:""}
|
||||||
|
|
|
@ -2087,20 +2087,7 @@ class SkuClass():
|
||||||
# Pack a registry format GUID
|
# Pack a registry format GUID
|
||||||
#
|
#
|
||||||
def PackRegistryFormatGuid(Guid):
|
def PackRegistryFormatGuid(Guid):
|
||||||
Guid = Guid.split('-')
|
return PackGUID(Guid.split('-'))
|
||||||
return pack('=LHHBBBBBBBB',
|
|
||||||
int(Guid[0], 16),
|
|
||||||
int(Guid[1], 16),
|
|
||||||
int(Guid[2], 16),
|
|
||||||
int(Guid[3][-4:-2], 16),
|
|
||||||
int(Guid[3][-2:], 16),
|
|
||||||
int(Guid[4][-12:-10], 16),
|
|
||||||
int(Guid[4][-10:-8], 16),
|
|
||||||
int(Guid[4][-8:-6], 16),
|
|
||||||
int(Guid[4][-6:-4], 16),
|
|
||||||
int(Guid[4][-4:-2], 16),
|
|
||||||
int(Guid[4][-2:], 16)
|
|
||||||
)
|
|
||||||
|
|
||||||
## Get the integer value from string like "14U" or integer like 2
|
## Get the integer value from string like "14U" or integer like 2
|
||||||
#
|
#
|
||||||
|
@ -2126,6 +2113,42 @@ def GetIntegerValue(Input):
|
||||||
else:
|
else:
|
||||||
return int(String)
|
return int(String)
|
||||||
|
|
||||||
|
#
|
||||||
|
# Pack a GUID (registry format) list into a buffer and return it
|
||||||
|
#
|
||||||
|
def PackGUID(Guid):
|
||||||
|
return pack(PACK_PATTERN_GUID,
|
||||||
|
int(Guid[0], 16),
|
||||||
|
int(Guid[1], 16),
|
||||||
|
int(Guid[2], 16),
|
||||||
|
int(Guid[3][-4:-2], 16),
|
||||||
|
int(Guid[3][-2:], 16),
|
||||||
|
int(Guid[4][-12:-10], 16),
|
||||||
|
int(Guid[4][-10:-8], 16),
|
||||||
|
int(Guid[4][-8:-6], 16),
|
||||||
|
int(Guid[4][-6:-4], 16),
|
||||||
|
int(Guid[4][-4:-2], 16),
|
||||||
|
int(Guid[4][-2:], 16)
|
||||||
|
)
|
||||||
|
|
||||||
|
#
|
||||||
|
# Pack a GUID (byte) list into a buffer and return it
|
||||||
|
#
|
||||||
|
def PackByteFormatGUID(Guid):
|
||||||
|
return pack(PACK_PATTERN_GUID,
|
||||||
|
Guid[0],
|
||||||
|
Guid[1],
|
||||||
|
Guid[2],
|
||||||
|
Guid[3],
|
||||||
|
Guid[4],
|
||||||
|
Guid[5],
|
||||||
|
Guid[6],
|
||||||
|
Guid[7],
|
||||||
|
Guid[8],
|
||||||
|
Guid[9],
|
||||||
|
Guid[10],
|
||||||
|
)
|
||||||
|
|
||||||
##
|
##
|
||||||
#
|
#
|
||||||
# This acts like the main() function for the script, unless it is 'import'ed into another
|
# This acts like the main() function for the script, unless it is 'import'ed into another
|
||||||
|
|
|
@ -26,7 +26,7 @@ import FfsFileStatement
|
||||||
from GenFdsGlobalVariable import GenFdsGlobalVariable
|
from GenFdsGlobalVariable import GenFdsGlobalVariable
|
||||||
from GenFds import GenFds
|
from GenFds import GenFds
|
||||||
from CommonDataClass.FdfClass import FvClassObject
|
from CommonDataClass.FdfClass import FvClassObject
|
||||||
from Common.Misc import SaveFileOnChange
|
from Common.Misc import SaveFileOnChange, PackGUID
|
||||||
from Common.LongFilePathSupport import CopyLongFilePath
|
from Common.LongFilePathSupport import CopyLongFilePath
|
||||||
from Common.LongFilePathSupport import OpenLongFilePath as open
|
from Common.LongFilePathSupport import OpenLongFilePath as open
|
||||||
from Common.DataType import *
|
from Common.DataType import *
|
||||||
|
@ -367,10 +367,7 @@ class FV (FvClassObject):
|
||||||
# FV UI name
|
# FV UI name
|
||||||
#
|
#
|
||||||
Buffer += (pack('HH', (FvUiLen + 16 + 4), 0x0002)
|
Buffer += (pack('HH', (FvUiLen + 16 + 4), 0x0002)
|
||||||
+ pack('=LHHBBBBBBBB', int(Guid[0], 16), int(Guid[1], 16), int(Guid[2], 16),
|
+ PackGUID(Guid)
|
||||||
int(Guid[3][-4:-2], 16), int(Guid[3][-2:], 16), int(Guid[4][-12:-10], 16),
|
|
||||||
int(Guid[4][-10:-8], 16), int(Guid[4][-8:-6], 16), int(Guid[4][-6:-4], 16),
|
|
||||||
int(Guid[4][-4:-2], 16), int(Guid[4][-2:], 16))
|
|
||||||
+ self.UiFvName)
|
+ self.UiFvName)
|
||||||
|
|
||||||
for Index in range (0, len(self.FvExtEntryType)):
|
for Index in range (0, len(self.FvExtEntryType)):
|
||||||
|
@ -404,20 +401,7 @@ class FV (FvClassObject):
|
||||||
Buffer += pack('B', int(ByteList[Index1], 16))
|
Buffer += pack('B', int(ByteList[Index1], 16))
|
||||||
|
|
||||||
Guid = self.FvNameGuid.split('-')
|
Guid = self.FvNameGuid.split('-')
|
||||||
Buffer = pack('=LHHBBBBBBBBL',
|
Buffer = PackGUID(Guid) + pack('=L', TotalSize) + Buffer
|
||||||
int(Guid[0], 16),
|
|
||||||
int(Guid[1], 16),
|
|
||||||
int(Guid[2], 16),
|
|
||||||
int(Guid[3][-4:-2], 16),
|
|
||||||
int(Guid[3][-2:], 16),
|
|
||||||
int(Guid[4][-12:-10], 16),
|
|
||||||
int(Guid[4][-10:-8], 16),
|
|
||||||
int(Guid[4][-8:-6], 16),
|
|
||||||
int(Guid[4][-6:-4], 16),
|
|
||||||
int(Guid[4][-4:-2], 16),
|
|
||||||
int(Guid[4][-2:], 16),
|
|
||||||
TotalSize
|
|
||||||
) + Buffer
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Generate FV extension header file if the total size is not zero
|
# Generate FV extension header file if the total size is not zero
|
||||||
|
|
|
@ -298,7 +298,7 @@ class DepexParser(object):
|
||||||
Statement = gOpCodeList[struct.unpack("B", OpCode)[0]]
|
Statement = gOpCodeList[struct.unpack("B", OpCode)[0]]
|
||||||
if Statement in ["BEFORE", "AFTER", "PUSH"]:
|
if Statement in ["BEFORE", "AFTER", "PUSH"]:
|
||||||
GuidValue = "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X" % \
|
GuidValue = "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X" % \
|
||||||
struct.unpack("=LHHBBBBBBBB", DepexFile.read(16))
|
struct.unpack(PACK_PATTERN_GUID, DepexFile.read(16))
|
||||||
GuidString = self._GuidDb.get(GuidValue, GuidValue)
|
GuidString = self._GuidDb.get(GuidValue, GuidValue)
|
||||||
Statement = "%s %s" % (Statement, GuidString)
|
Statement = "%s %s" % (Statement, GuidString)
|
||||||
DepexStatement.append(Statement)
|
DepexStatement.append(Statement)
|
||||||
|
|
Loading…
Reference in New Issue