diff options
Diffstat (limited to 'BaseTools/Source/Python/AutoGen')
-rw-r--r-- | BaseTools/Source/Python/AutoGen/AutoGen.py | 5 | ||||
-rw-r--r-- | BaseTools/Source/Python/AutoGen/GenC.py | 19 | ||||
-rw-r--r-- | BaseTools/Source/Python/AutoGen/GenPcdDb.py | 54 | ||||
-rw-r--r-- | BaseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py | 351 |
4 files changed, 416 insertions, 13 deletions
diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py b/BaseTools/Source/Python/AutoGen/AutoGen.py index cd61e8e758..a1e1818e3b 100644 --- a/BaseTools/Source/Python/AutoGen/AutoGen.py +++ b/BaseTools/Source/Python/AutoGen/AutoGen.py @@ -1,7 +1,7 @@ ## @file
# Generate AutoGen.h, AutoGen.c and *.depex files
#
-# Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR>
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
@@ -1813,6 +1813,9 @@ class PlatformAutoGen(AutoGen): if not IsValid:
EdkLogger.error('build', FORMAT_INVALID, Cause, File=self.MetaFile,
ExtraData="%s.%s" % (ToPcd.TokenSpaceGuidCName, ToPcd.TokenCName))
+ ToPcd.validateranges = FromPcd.validateranges
+ ToPcd.validlists = FromPcd.validlists
+ ToPcd.expressions = FromPcd.expressions
if ToPcd.DatumType == "VOID*" and ToPcd.MaxDatumSize in ['', None]:
EdkLogger.debug(EdkLogger.DEBUG_9, "No MaxDatumSize specified for PCD %s.%s" \
diff --git a/BaseTools/Source/Python/AutoGen/GenC.py b/BaseTools/Source/Python/AutoGen/GenC.py index a140cc80a4..9bdb0363b2 100644 --- a/BaseTools/Source/Python/AutoGen/GenC.py +++ b/BaseTools/Source/Python/AutoGen/GenC.py @@ -1,7 +1,7 @@ ## @file
# Routines for generating AutoGen.h and AutoGen.c
#
-# Copyright (c) 2007 - 2013, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR>
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
@@ -786,6 +786,7 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd): DatumSizeLib = gDatumSizeStringDatabaseLib[Pcd.DatumType]
GetModeName = '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_' + Pcd.TokenCName
SetModeName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_' + Pcd.TokenCName
+ SetModeStatusName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_S_' + Pcd.TokenCName
PcdExCNameList = []
if Pcd.Type in gDynamicExPcd:
@@ -805,21 +806,27 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd): AutoGenH.Append('// #define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
if Pcd.DatumType == 'VOID*':
AutoGenH.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
+ AutoGenH.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
else:
AutoGenH.Append('// #define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
+ AutoGenH.Append('// #define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
else:
AutoGenH.Append('#define %s %s\n' % (PcdTokenName, PcdExTokenName))
AutoGenH.Append('#define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
if Pcd.DatumType == 'VOID*':
AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
+ AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
else:
AutoGenH.Append('#define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
+ AutoGenH.Append('#define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
elif Pcd.Type in gDynamicPcd:
AutoGenH.Append('#define %s LibPcdGet%s(%s)\n' % (GetModeName, DatumSizeLib, PcdTokenName))
if Pcd.DatumType == 'VOID*':
AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%s(%s, (SizeOfBuffer), (Buffer))\n' %(SetModeName, DatumSizeLib, PcdTokenName))
+ AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%sS(%s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, PcdTokenName))
else:
AutoGenH.Append('#define %s(Value) LibPcdSet%s(%s, (Value))\n' % (SetModeName, DatumSizeLib, PcdTokenName))
+ AutoGenH.Append('#define %s(Value) LibPcdSet%sS(%s, (Value))\n' % (SetModeStatusName, DatumSizeLib, PcdTokenName))
else:
PcdVariableName = '_gPcd_' + gItemTypeStringDatabase[Pcd.Type] + '_' + Pcd.TokenCName
Const = 'const'
@@ -963,8 +970,10 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd): if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:
if Pcd.DatumType == 'VOID*':
AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPatchPcdSetPtr(_gPcd_BinaryPatch_%s, (UINTN)_PCD_PATCHABLE_%s_SIZE, (SizeOfBuffer), (Buffer))\n' % (SetModeName, Pcd.TokenCName, Pcd.TokenCName))
+ AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPatchPcdSetPtrS(_gPcd_BinaryPatch_%s, (UINTN)_PCD_PATCHABLE_%s_SIZE, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, Pcd.TokenCName, Pcd.TokenCName))
else:
AutoGenH.Append('#define %s(Value) (%s = (Value))\n' % (SetModeName, PcdVariableName))
+ AutoGenH.Append('#define %s(Value) ((%s = (Value)), RETURN_SUCCESS) \n' % (SetModeStatusName, PcdVariableName))
else:
AutoGenH.Append('//#define %s ASSERT(FALSE) // It is not allowed to set value for a FIXED_AT_BUILD PCD\n' % SetModeName)
@@ -1018,6 +1027,7 @@ def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd): DatumSizeLib= gDatumSizeStringDatabaseLib[DatumType]
GetModeName = '_PCD_GET_MODE_' + DatumSize + '_' + TokenCName
SetModeName = '_PCD_SET_MODE_' + DatumSize + '_' + TokenCName
+ SetModeStatusName = '_PCD_SET_MODE_' + DatumSize + '_S_' + TokenCName
Type = ''
Array = ''
@@ -1046,28 +1056,35 @@ def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd): AutoGenH.Append('// #define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
if Pcd.DatumType == 'VOID*':
AutoGenH.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
+ AutoGenH.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
else:
AutoGenH.Append('// #define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
+ AutoGenH.Append('// #define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
else:
AutoGenH.Append('#define %s %s\n' % (PcdTokenName, PcdExTokenName))
AutoGenH.Append('#define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
if Pcd.DatumType == 'VOID*':
AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
+ AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
else:
AutoGenH.Append('#define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
+ AutoGenH.Append('#define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
else:
AutoGenH.Append('#define _PCD_TOKEN_%s %dU\n' % (TokenCName, TokenNumber))
if PcdItemType in gDynamicPcd:
AutoGenH.Append('#define %s LibPcdGet%s(%s)\n' % (GetModeName, DatumSizeLib, PcdTokenName))
if DatumType == 'VOID*':
AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%s(%s, (SizeOfBuffer), (Buffer))\n' %(SetModeName, DatumSizeLib, PcdTokenName))
+ AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%sS(%s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, PcdTokenName))
else:
AutoGenH.Append('#define %s(Value) LibPcdSet%s(%s, (Value))\n' % (SetModeName, DatumSizeLib, PcdTokenName))
+ AutoGenH.Append('#define %s(Value) LibPcdSet%sS(%s, (Value))\n' % (SetModeStatusName, DatumSizeLib, PcdTokenName))
if PcdItemType == TAB_PCDS_PATCHABLE_IN_MODULE:
PcdVariableName = '_gPcd_' + gItemTypeStringDatabase[TAB_PCDS_PATCHABLE_IN_MODULE] + '_' + TokenCName
AutoGenH.Append('extern volatile %s _gPcd_BinaryPatch_%s%s;\n' %(DatumType, TokenCName, Array) )
AutoGenH.Append('#define %s %s_gPcd_BinaryPatch_%s\n' %(GetModeName, Type, TokenCName))
AutoGenH.Append('#define %s(Value) (%s = (Value))\n' % (SetModeName, PcdVariableName))
+ AutoGenH.Append('#define %s(Value) ((%s = (Value)), RETURN_SUCCESS)\n' % (SetModeStatusName, PcdVariableName))
if PcdItemType == TAB_PCDS_FIXED_AT_BUILD or PcdItemType == TAB_PCDS_FEATURE_FLAG:
key = ".".join((Pcd.TokenSpaceGuidCName,Pcd.TokenCName))
diff --git a/BaseTools/Source/Python/AutoGen/GenPcdDb.py b/BaseTools/Source/Python/AutoGen/GenPcdDb.py index e995e141da..4ccd2d65e3 100644 --- a/BaseTools/Source/Python/AutoGen/GenPcdDb.py +++ b/BaseTools/Source/Python/AutoGen/GenPcdDb.py @@ -1,7 +1,7 @@ ## @file
# Routines for generating Pcd Database
#
-# Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2013 - 2015, Intel Corporation. All rights reserved.<BR>
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
@@ -14,8 +14,12 @@ from StringIO import StringIO from Common.Misc import *
from Common.String import StringToArray
from struct import pack
+from ValidCheckingInfoObject import VAR_CHECK_PCD_VARIABLE_TAB_CONTAINER
+from ValidCheckingInfoObject import VAR_CHECK_PCD_VARIABLE_TAB
+from ValidCheckingInfoObject import VAR_VALID_OBJECT_FACTORY
+from Common.VariableAttributes import VariableAttributes
-DATABASE_VERSION = 4
+DATABASE_VERSION = 5
gPcdDatabaseAutoGenC = TemplateString("""
//
@@ -444,7 +448,7 @@ class DbVariableTableItemList (DbComItemList): RawDataList = []
DbComItemList.__init__(self, ItemSize, DataList, RawDataList)
def PackData(self):
- PackStr = "=LLHH"
+ PackStr = "=LLHHLHH"
Buffer = ''
for DataList in self.RawDataList:
for Data in DataList:
@@ -452,7 +456,10 @@ class DbVariableTableItemList (DbComItemList): GetIntegerValue(Data[0]),
GetIntegerValue(Data[1]),
GetIntegerValue(Data[2]),
- GetIntegerValue(Data[3]))
+ GetIntegerValue(Data[3]),
+ GetIntegerValue(Data[4]),
+ GetIntegerValue(Data[5]),
+ GetIntegerValue(0))
return Buffer
class DbStringHeadTableItemList(DbItemList):
@@ -712,7 +719,7 @@ def BuildExDataBase(Dict): # DbItemList to DbStringHeadTableItemList
DbStringHeadValue = DbStringHeadTableItemList(4, RawDataList = StringHeadValue)
VariableTable = Dict['VARIABLE_DB_VALUE']
- DbVariableTable = DbVariableTableItemList(12, RawDataList = VariableTable)
+ DbVariableTable = DbVariableTableItemList(20, RawDataList = VariableTable)
NumberOfSkuEnabledPcd = GetIntegerValue(Dict['SKU_HEAD_SIZE'])
Dict['SKUHEAD_TABLE_VALUE'] = [(0,0) for i in xrange(NumberOfSkuEnabledPcd)]
SkuTable = Dict['SKUHEAD_TABLE_VALUE'] # Generated later
@@ -852,7 +859,7 @@ def BuildExDataBase(Dict): for VariableEntries in VariableTable:
skuindex = 0
for VariableEntryPerSku in VariableEntries:
- (VariableHeadGuidIndex, VariableHeadStringIndex, SKUVariableOffset, VariableOffset, VariableRefTable) = VariableEntryPerSku[:]
+ (VariableHeadGuidIndex, VariableHeadStringIndex, SKUVariableOffset, VariableOffset, VariableRefTable, VariableAttribute) = VariableEntryPerSku[:]
DbIndex = 0
DbOffset = FixedHeaderLen
for DbIndex in xrange(len(DbTotal)):
@@ -867,8 +874,8 @@ def BuildExDataBase(Dict): skuindex += 1
if DbIndex >= InitTableNum:
assert(False)
-
- VariableEntryPerSku[:] = (VariableHeadStringIndex, DbOffset, VariableHeadGuidIndex, SKUVariableOffset)
+ VarAttr, VarProp = VariableAttributes.GetVarAttributes(VariableAttribute)
+ VariableEntryPerSku[:] = (VariableHeadStringIndex, DbOffset, VariableHeadGuidIndex, SKUVariableOffset, VarAttr, VarProp)
# calculate various table offset now
DbTotalLength = FixedHeaderLen
@@ -1113,6 +1120,7 @@ def CreatePcdDatabasePhaseSpecificAutoGen (Platform, Phase): NumberOfSizeItems = 0
NumberOfSkuEnabledPcd = 0
GuidList = []
+ VarCheckTab = VAR_CHECK_PCD_VARIABLE_TAB_CONTAINER()
i = 0
ReorderedDynPcdList = GetOrderedDynamicPcdList(Platform.DynamicPcdList, Platform.PcdTokenNumber)
for Pcd in ReorderedDynPcdList:
@@ -1182,6 +1190,29 @@ def CreatePcdDatabasePhaseSpecificAutoGen (Platform, Phase): SkuIdIndex += 1
if len(Sku.VariableName) > 0:
+ VariableGuidStructure = Sku.VariableGuidValue
+ VariableGuid = GuidStructureStringToGuidValueName(VariableGuidStructure)
+ if Platform.Platform.VarCheckFlag:
+ var_check_obj = VAR_CHECK_PCD_VARIABLE_TAB(VariableGuidStructure, StringToArray(Sku.VariableName))
+ try:
+ var_check_obj.push_back(VAR_VALID_OBJECT_FACTORY.Get_valid_object(Pcd, Sku.VariableOffset))
+ VarAttr, _ = VariableAttributes.GetVarAttributes(Sku.VariableAttribute)
+ var_check_obj.SetAttributes(VarAttr)
+ var_check_obj.UpdateSize()
+ VarCheckTab.push_back(var_check_obj)
+ except Exception:
+ ValidInfo = ''
+ if Pcd.validateranges:
+ ValidInfo = Pcd.validateranges[0]
+ if Pcd.validlists:
+ ValidInfo = Pcd.validlists[0]
+ if ValidInfo:
+ EdkLogger.error("build", PCD_VALIDATION_INFO_ERROR,
+ "The PCD '%s.%s' Validation information defined in DEC file has incorrect format." % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName),
+ ExtraData = "[%s]" % str(ValidInfo))
+ else:
+ EdkLogger.error("build", PCD_VALIDATION_INFO_ERROR,
+ "The PCD '%s.%s' Validation information defined in DEC file has incorrect format." % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName))
Pcd.TokenTypeList += ['PCD_TYPE_HII']
Pcd.InitString = 'INIT'
# Store all variable names of one HII PCD under different SKU to stringTable
@@ -1215,8 +1246,6 @@ def CreatePcdDatabasePhaseSpecificAutoGen (Platform, Phase): VariableHeadStringIndex = VariableHeadList[SkuIdIndex - 2]
# store VariableGuid to GuidTable and get the VariableHeadGuidIndex
- VariableGuidStructure = Sku.VariableGuidValue
- VariableGuid = GuidStructureStringToGuidValueName(VariableGuidStructure)
if VariableGuid not in GuidList:
GuidList += [VariableGuid]
@@ -1268,7 +1297,7 @@ def CreatePcdDatabasePhaseSpecificAutoGen (Platform, Phase): # the Pcd default value was filled before
VariableOffset = len(Dict['VARDEF_DB_VALUE_' + Pcd.DatumType]) - 1
VariableRefTable = Dict['VARDEF_DB_VALUE_' + Pcd.DatumType]
- VariableDbValueList.append([VariableHeadGuidIndex, VariableHeadStringIndex, Sku.VariableOffset, VariableOffset, VariableRefTable])
+ VariableDbValueList.append([VariableHeadGuidIndex, VariableHeadStringIndex, Sku.VariableOffset, VariableOffset, VariableRefTable, Sku.VariableAttribute])
elif Sku.VpdOffset != '':
Pcd.TokenTypeList += ['PCD_TYPE_VPD']
@@ -1600,6 +1629,9 @@ def CreatePcdDatabasePhaseSpecificAutoGen (Platform, Phase): AutoGenC.Append(gPcdDatabaseAutoGenC.Replace(Dict))
+ if Platform.Platform.VarCheckFlag:
+ dest = os.path.join(Platform.BuildDir, 'FV')
+ VarCheckTab.dump(dest, Phase)
Buffer = BuildExDataBase(Dict)
return AutoGenH, AutoGenC, Buffer
diff --git a/BaseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py b/BaseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py new file mode 100644 index 0000000000..4a6e031053 --- /dev/null +++ b/BaseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py @@ -0,0 +1,351 @@ +# Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+#
+# This file is used to collect the Variable checking information
+#
+
+# #
+# Import Modules
+#
+import os
+from Common.RangeExpression import RangeExpression
+from Common.Misc import *
+from StringIO import StringIO
+from struct import pack
+
+class VAR_CHECK_PCD_VARIABLE_TAB_CONTAINER(object):
+ def __init__(self):
+ self.var_check_info = []
+
+ def push_back(self, var_check_tab):
+ for tab in self.var_check_info:
+ if tab.equal(var_check_tab):
+ tab.merge(var_check_tab)
+ break
+ else:
+ self.var_check_info.append(var_check_tab)
+
+ def dump(self, dest, Phase):
+
+ FormatMap = {}
+ FormatMap[1] = "=B"
+ FormatMap[2] = "=H"
+ FormatMap[4] = "=L"
+ FormatMap[8] = "=Q"
+
+ if not os.path.isabs(dest):
+ return
+ if not os.path.exists(dest):
+ os.mkdir(dest)
+ BinFileName = "PcdVarCheck.bin"
+ BinFilePath = os.path.join(dest, BinFileName)
+ Buffer = ''
+ index = 0
+ for var_check_tab in self.var_check_info:
+ index += 1
+ realLength = 0
+ realLength += 32
+ Name = var_check_tab.Name[1:-1]
+ NameChars = Name.split(",")
+ realLength += len(NameChars)
+ if (index < len(self.var_check_info) and realLength % 4) or (index == len(self.var_check_info) and len(var_check_tab.validtab) > 0 and realLength % 4):
+ realLength += (4 - (realLength % 4))
+ itemIndex = 0
+ for item in var_check_tab.validtab:
+ itemIndex += 1
+ realLength += 5
+ for v_data in item.data:
+ if type(v_data) == type(1):
+ realLength += item.StorageWidth
+ else:
+ realLength += item.StorageWidth
+ realLength += item.StorageWidth
+ if (index == len(self.var_check_info)) :
+ if (itemIndex < len(var_check_tab.validtab)) and realLength % 4:
+ realLength += (4 - (realLength % 4))
+ else:
+ if realLength % 4:
+ realLength += (4 - (realLength % 4))
+ var_check_tab.Length = realLength
+ realLength = 0
+ index = 0
+ for var_check_tab in self.var_check_info:
+ index += 1
+
+ b = pack("=H", var_check_tab.Revision)
+ Buffer += b
+ realLength += 2
+
+ b = pack("=H", var_check_tab.HeaderLength)
+ Buffer += b
+ realLength += 2
+
+ b = pack("=L", var_check_tab.Length)
+ Buffer += b
+ realLength += 4
+
+ b = pack("=B", var_check_tab.Type)
+ Buffer += b
+ realLength += 1
+
+ for i in range(0, 3):
+ b = pack("=B", var_check_tab.Reserved)
+ Buffer += b
+ realLength += 1
+
+ b = pack("=L", var_check_tab.Attributes)
+ Buffer += b
+ realLength += 4
+
+ Guid = var_check_tab.Guid
+ b = pack('=LHHBBBBBBBB',
+ Guid[0],
+ Guid[1],
+ Guid[2],
+ Guid[3],
+ Guid[4],
+ Guid[5],
+ Guid[6],
+ Guid[7],
+ Guid[8],
+ Guid[9],
+ Guid[10],
+ )
+ Buffer += b
+ realLength += 16
+
+ Name = var_check_tab.Name[1:-1]
+ NameChars = Name.split(",")
+ for NameChar in NameChars:
+ NameCharNum = int(NameChar, 16)
+ b = pack("=B", NameCharNum)
+ Buffer += b
+ realLength += 1
+
+ if (index < len(self.var_check_info) and realLength % 4) or (index == len(self.var_check_info) and len(var_check_tab.validtab) > 0 and realLength % 4):
+ for i in range(4 - (realLength % 4)):
+ b = pack("=B", var_check_tab.pad)
+ Buffer += b
+ realLength += 1
+ itemIndex = 0
+ for item in var_check_tab.validtab:
+ itemIndex += 1
+
+ b = pack("=B", item.Type)
+ Buffer += b
+ realLength += 1
+
+ b = pack("=B", item.Length)
+ Buffer += b
+ realLength += 1
+
+ b = pack("=H", int(item.VarOffset, 16))
+ Buffer += b
+ realLength += 2
+
+ b = pack("=B", item.StorageWidth)
+ Buffer += b
+ realLength += 1
+
+ for v_data in item.data:
+ if type(v_data) == type(1):
+ b = pack(FormatMap[item.StorageWidth], v_data)
+ Buffer += b
+ realLength += item.StorageWidth
+ else:
+ b = pack(FormatMap[item.StorageWidth], v_data[0])
+ Buffer += b
+ realLength += item.StorageWidth
+ b = pack(FormatMap[item.StorageWidth], v_data[1])
+ Buffer += b
+ realLength += item.StorageWidth
+
+ if (index == len(self.var_check_info)) :
+ if (itemIndex < len(var_check_tab.validtab)) and realLength % 4:
+ for i in range(4 - (realLength % 4)):
+ b = pack("=B", var_check_tab.pad)
+ Buffer += b
+ realLength += 1
+ else:
+ if realLength % 4:
+ for i in range(4 - (realLength % 4)):
+ b = pack("=B", var_check_tab.pad)
+ Buffer += b
+ realLength += 1
+
+ DbFile = StringIO()
+ if Phase == 'DXE' and os.path.exists(BinFilePath):
+ BinFile = open(BinFilePath, "rb")
+ BinBuffer = BinFile.read()
+ BinFile.close()
+ BinBufferSize = len(BinBuffer)
+ if (BinBufferSize % 4):
+ for i in range(4 - (BinBufferSize % 4)):
+ b = pack("=B", VAR_CHECK_PCD_VARIABLE_TAB.pad)
+ BinBuffer += b
+ Buffer = BinBuffer + Buffer
+ DbFile.write(Buffer)
+ SaveFileOnChange(BinFilePath, DbFile.getvalue(), True)
+
+
+class VAR_CHECK_PCD_VARIABLE_TAB(object):
+ pad = 0xDA
+ def __init__(self, TokenSpaceGuid, PcdCName):
+ self.Revision = 0x0001
+ self.HeaderLength = 0
+ self.Length = 0 # Length include this header
+ self.Type = 0
+ self.Reserved = 0
+ self.Attributes = 0x00000000
+ self.Guid = eval("[" + TokenSpaceGuid.replace("{", "").replace("}", "") + "]")
+ self.Name = PcdCName
+ self.validtab = []
+
+ def UpdateSize(self):
+ self.HeaderLength = 32 + len(self.Name.split(","))
+ self.Length = 32 + len(self.Name.split(",")) + self.GetValidTabLen()
+
+ def GetValidTabLen(self):
+ validtablen = 0
+ for item in self.validtab:
+ validtablen += item.Length
+ return validtablen
+
+ def SetAttributes(self, attributes):
+ self.Attributes = attributes
+
+ def push_back(self, valid_obj):
+ if valid_obj is not None:
+ self.validtab.append(valid_obj)
+
+ def equal(self, varchecktab):
+ if self.Guid == varchecktab.Guid and self.Name == varchecktab.Name:
+ return True
+ else:
+ return False
+
+ def merge(self, varchecktab):
+ for validobj in varchecktab.validtab:
+ if validobj in self.validtab:
+ continue
+ self.validtab.append(validobj)
+ self.UpdateSize()
+
+
+class VAR_CHECK_PCD_VALID_OBJ(object):
+ def __init__(self, VarOffset, data, PcdDataType):
+ self.Type = 1
+ self.Length = 0 # Length include this header
+ self.VarOffset = VarOffset
+ self.StorageWidth = 0
+ self.PcdDataType = PcdDataType.strip()
+ self.rawdata = data
+ self.data = set()
+ self.ValidData = True
+ self.updateStorageWidth()
+ def updateStorageWidth(self):
+ if self.PcdDataType == "UINT8" or self.PcdDataType == "BOOLEAN":
+ self.StorageWidth = 1
+ elif self.PcdDataType == "UINT16":
+ self.StorageWidth = 2
+ elif self.PcdDataType == "UINT32":
+ self.StorageWidth = 4
+ elif self.PcdDataType == "UINT64":
+ self.StorageWidth = 8
+ else:
+ self.StorageWidth = 0
+ self.ValidData = False
+
+ def __eq__(self, validObj):
+ if self.VarOffset == validObj.VarOffset:
+ return True
+ else:
+ return False
+
+class VAR_CHECK_PCD_VALID_LIST(VAR_CHECK_PCD_VALID_OBJ):
+ def __init__(self, VarOffset, validlist, PcdDataType):
+ super(VAR_CHECK_PCD_VALID_LIST, self).__init__(VarOffset, validlist, PcdDataType)
+ self.Type = 1
+ self.update_data()
+ self.update_size()
+ def update_data(self):
+ valid_num_list = []
+ data_list = []
+ for item in self.rawdata:
+ valid_num_list.extend(item.split(','))
+
+ for valid_num in valid_num_list:
+ valid_num = valid_num.strip()
+
+ if valid_num.startswith('0x') or valid_num.startswith('0X'):
+ data_list.append(int(valid_num, 16))
+ else:
+ data_list.append(int(valid_num))
+
+
+ self.data = set(data_list)
+
+ def update_size(self):
+ self.Length = 5 + len(self.data) * self.StorageWidth
+
+
+class VAR_CHECK_PCD_VALID_RANGE(VAR_CHECK_PCD_VALID_OBJ):
+ def __init__(self, VarOffset, validrange, PcdDataType):
+ super(VAR_CHECK_PCD_VALID_RANGE, self).__init__(VarOffset, validrange, PcdDataType)
+ self.Type = 2
+ self.update_data()
+ self.update_size()
+ def update_data(self):
+ RangeExpr = ""
+ data_list = []
+ i = 0
+ for item in self.rawdata:
+ if i == 0:
+ RangeExpr = "( " + item + " )"
+ else:
+ RangeExpr = RangeExpr + "OR ( " + item + " )"
+ range_result = RangeExpression(RangeExpr, self.PcdDataType)(True)
+ for rangelist in range_result:
+ for obj in rangelist.pop():
+ data_list.append((obj.start, obj.end))
+ self.data = set(data_list)
+
+ def update_size(self):
+ self.Length = 5 + len(self.data) * 2 * self.StorageWidth
+
+
+class VAR_VALID_OBJECT_FACTORY(object):
+ def __init__(self):
+ pass
+ @staticmethod
+ def Get_valid_object(PcdClass, VarOffset):
+ if PcdClass.validateranges:
+ return VAR_CHECK_PCD_VALID_RANGE(VarOffset, PcdClass.validateranges, PcdClass.DatumType)
+ if PcdClass.validlists:
+ return VAR_CHECK_PCD_VALID_LIST(VarOffset, PcdClass.validlists, PcdClass.DatumType)
+ else:
+ return None
+
+if __name__ == "__main__":
+ class TestObj(object):
+ def __init__(self, number1):
+ self.number_1 = number1
+ def __eq__(self, testobj):
+ if self.number_1 == testobj.number_1:
+ return True
+ else:
+ return False
+ test1 = TestObj(1)
+ test2 = TestObj(2)
+
+ testarr = [test1, test2]
+ print TestObj(2) in testarr
+ print TestObj(2) == test2
+
|