summaryrefslogtreecommitdiffstats
path: root/BaseTools
diff options
context:
space:
mode:
authorCarsey, Jaben <jaben.carsey@intel.com>2018-04-28 06:32:32 +0800
committerYonghong Zhu <yonghong.zhu@intel.com>2018-05-04 13:03:05 +0800
commit5565a8c4d2196b5e55e702169feefeeb07a330d9 (patch)
tree209dad0eab7b1fe7d3993ddaff977249b4efa0b3 /BaseTools
parent88252a90d1ca7846731cd2e4e8e860454f7d97a3 (diff)
downloadedk2-5565a8c4d2196b5e55e702169feefeeb07a330d9.tar.gz
edk2-5565a8c4d2196b5e55e702169feefeeb07a330d9.tar.bz2
edk2-5565a8c4d2196b5e55e702169feefeeb07a330d9.zip
BaseTools: move PCD size calculation functions to PcdClassObject
move both GetPcdMaxSize and GetPcdSize to the PcdClassObject. fix MAX_SIZE_TYPE to have int values 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>
Diffstat (limited to 'BaseTools')
-rw-r--r--BaseTools/Source/Python/AutoGen/GenC.py37
-rw-r--r--BaseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py2
-rw-r--r--BaseTools/Source/Python/Common/DataType.py2
-rw-r--r--BaseTools/Source/Python/Common/VpdInfoFile.py2
-rw-r--r--BaseTools/Source/Python/Workspace/BuildClassObject.py31
-rw-r--r--BaseTools/Source/Python/Workspace/DscBuildData.py19
6 files changed, 41 insertions, 52 deletions
diff --git a/BaseTools/Source/Python/AutoGen/GenC.py b/BaseTools/Source/Python/AutoGen/GenC.py
index 6a2ea924f6..d062588882 100644
--- a/BaseTools/Source/Python/AutoGen/GenC.py
+++ b/BaseTools/Source/Python/AutoGen/GenC.py
@@ -863,31 +863,6 @@ def DynExPcdTokenNumberMapping(Info, AutoGenH):
% (RealTokenCName, RealTokenCName, RealTokenCName, RealTokenCName))
TokenCNameList.add(TokenCName)
-def GetPcdSize(Pcd):
- if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:
- Value = Pcd.DefaultValue
- if not Value:
- return 1
- elif Value[0] == 'L':
- return (len(Value) - 2) * 2
- elif Value[0] == '{':
- return len(Value.split(','))
- else:
- return len(Value) - 1
- if Pcd.DatumType == TAB_UINT64:
- return 8
- if Pcd.DatumType == TAB_UINT32:
- return 4
- if Pcd.DatumType == TAB_UINT16:
- return 2
- if Pcd.DatumType == TAB_UINT8:
- return 1
- if Pcd.DatumType == 'BOOLEAN':
- return 1
- else:
- return Pcd.MaxDatumSize
-
-
## Create code for module PCDs
#
# @param Info The ModuleAutoGen object
@@ -1110,7 +1085,7 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
"The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, TokenCName),
ExtraData="[%s]" % str(Info))
else:
- ArraySize = GetPcdSize(Pcd)
+ ArraySize = Pcd.GetPcdSize()
if Unicode:
ArraySize = ArraySize / 2
Value = NewValue + '0 }'
@@ -1150,7 +1125,7 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
AutoGenH.Append('extern %s UINT8 %s%s;\n' %(Const, PcdVariableName, Array))
AutoGenH.Append('#define %s %s%s\n' %(GetModeName, Type, PcdVariableName))
- PcdDataSize = GetPcdSize(Pcd)
+ PcdDataSize = Pcd.GetPcdSize()
if Pcd.Type == TAB_PCDS_FIXED_AT_BUILD:
AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, PcdDataSize))
AutoGenH.Append('#define %s %s \n' % (GetModeSizeName,FixPcdSizeTokenName))
@@ -1167,14 +1142,14 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
AutoGenH.Append('extern volatile %s %s %s%s;\n' % (Const, Pcd.DatumType, PcdVariableName, Array))
AutoGenH.Append('#define %s %s%s\n' % (GetModeName, Type, PcdVariableName))
- PcdDataSize = GetPcdSize(Pcd)
+ PcdDataSize = Pcd.GetPcdSize()
AutoGenH.Append('#define %s %s\n' % (PatchPcdSizeTokenName, PcdDataSize))
AutoGenH.Append('#define %s %s \n' % (GetModeSizeName,PatchPcdSizeVariableName))
AutoGenH.Append('extern UINTN %s; \n' % PatchPcdSizeVariableName)
AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED UINTN %s = %s;\n' % (PatchPcdSizeVariableName,PcdDataSize))
else:
- PcdDataSize = GetPcdSize(Pcd)
+ PcdDataSize = Pcd.GetPcdSize()
AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, PcdDataSize))
AutoGenH.Append('#define %s %s \n' % (GetModeSizeName,FixPcdSizeTokenName))
@@ -1333,7 +1308,7 @@ def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd):
else:
AutoGenH.Append('extern volatile %s %s%s;\n' % (DatumType, PcdVariableName, Array))
AutoGenH.Append('#define %s %s_gPcd_BinaryPatch_%s\n' %(GetModeName, Type, TokenCName))
- PcdDataSize = GetPcdSize(Pcd)
+ PcdDataSize = Pcd.GetPcdSize()
if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:
AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPatchPcdSetPtrAndSize((VOID *)_gPcd_BinaryPatch_%s, &%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, TokenCName, PatchPcdSizeVariableName, PatchPcdMaxSizeVariable))
AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPatchPcdSetPtrAndSizeS((VOID *)_gPcd_BinaryPatch_%s, &%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, TokenCName, PatchPcdSizeVariableName, PatchPcdMaxSizeVariable))
@@ -1367,7 +1342,7 @@ def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd):
AutoGenH.Append('#define _PCD_VALUE_%s %s%s\n' %(TokenCName, Type, PcdVariableName))
else:
AutoGenH.Append('#define _PCD_VALUE_%s %s\n' %(TokenCName, Pcd.DefaultValue))
- PcdDataSize = GetPcdSize(Pcd)
+ PcdDataSize = Pcd.GetPcdSize()
if PcdItemType == TAB_PCDS_FIXED_AT_BUILD:
if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:
if ConstFixedPcd:
diff --git a/BaseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py b/BaseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py
index dd78dc5200..2f8f4fac23 100644
--- a/BaseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py
+++ b/BaseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py
@@ -253,7 +253,7 @@ class VAR_CHECK_PCD_VALID_OBJ(object):
def updateStorageWidth(self):
try:
- self.StorageWidth = int(MAX_SIZE_TYPE[self.PcdDataType])
+ self.StorageWidth = MAX_SIZE_TYPE[self.PcdDataType]
except:
self.StorageWidth = 0
self.ValidData = False
diff --git a/BaseTools/Source/Python/Common/DataType.py b/BaseTools/Source/Python/Common/DataType.py
index 5030df27b4..50d582a3f6 100644
--- a/BaseTools/Source/Python/Common/DataType.py
+++ b/BaseTools/Source/Python/Common/DataType.py
@@ -292,7 +292,7 @@ TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_SET = {TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_
## The mapping dictionary from datum type to its maximum number.
MAX_VAL_TYPE = {"BOOLEAN":0x01, TAB_UINT8:0xFF, TAB_UINT16:0xFFFF, TAB_UINT32:0xFFFFFFFF, TAB_UINT64:0xFFFFFFFFFFFFFFFF}
## The mapping dictionary from datum type to size string.
-MAX_SIZE_TYPE = {"BOOLEAN":"1", TAB_UINT8:"1", TAB_UINT16:"2", TAB_UINT32:"4", TAB_UINT64:"8"}
+MAX_SIZE_TYPE = {"BOOLEAN":1, TAB_UINT8:1, TAB_UINT16:2, TAB_UINT32:4, TAB_UINT64:8}
TAB_DEPEX = 'Depex'
TAB_DEPEX_COMMON = TAB_DEPEX + TAB_SPLIT + TAB_ARCH_COMMON
diff --git a/BaseTools/Source/Python/Common/VpdInfoFile.py b/BaseTools/Source/Python/Common/VpdInfoFile.py
index 155693740f..32895deb5d 100644
--- a/BaseTools/Source/Python/Common/VpdInfoFile.py
+++ b/BaseTools/Source/Python/Common/VpdInfoFile.py
@@ -99,7 +99,7 @@ class VpdInfoFile:
EdkLogger.error("VpdInfoFile", BuildToolError.PARAMETER_INVALID,
"Invalid max datum size for VPD PCD %s.%s" % (Vpd.TokenSpaceGuidCName, Vpd.TokenCName))
elif Vpd.DatumType in TAB_PCD_NUMERIC_TYPES:
- if Vpd.MaxDatumSize is None or Vpd.MaxDatumSize == "":
+ if not Vpd.MaxDatumSize:
Vpd.MaxDatumSize = MAX_SIZE_TYPE[Vpd.DatumType]
else:
if Vpd.MaxDatumSize <= 0:
diff --git a/BaseTools/Source/Python/Workspace/BuildClassObject.py b/BaseTools/Source/Python/Workspace/BuildClassObject.py
index 258905e80f..209315d901 100644
--- a/BaseTools/Source/Python/Workspace/BuildClassObject.py
+++ b/BaseTools/Source/Python/Workspace/BuildClassObject.py
@@ -72,6 +72,37 @@ class PcdClassObject(object):
self.PcdValueFromComm = ""
self.DefinitionPosition = ("","")
+ ## Get the maximum number of bytes
+ def GetPcdMaxSize(self):
+ if self.DatumType in TAB_PCD_NUMERIC_TYPES:
+ return MAX_SIZE_TYPE[self.DatumType]
+
+ MaxSize = int(self.MaxDatumSize,10) if self.MaxDatumSize else 0
+ if self.PcdValueFromComm:
+ if self.PcdValueFromComm.startswith("{") and self.PcdValueFromComm.endswith("}"):
+ return max([len(self.PcdValueFromComm.split(",")),MaxSize])
+ elif self.PcdValueFromComm.startswith("\"") or self.PcdValueFromComm.startswith("\'"):
+ return max([len(self.PcdValueFromComm)-2+1,MaxSize])
+ elif self.PcdValueFromComm.startswith("L\""):
+ return max([2*(len(self.PcdValueFromComm)-3+1),MaxSize])
+ else:
+ return max([len(self.PcdValueFromComm),MaxSize])
+ return MaxSize
+
+ ## Get the number of bytes
+ def GetPcdSize(self):
+ if self.DatumType in TAB_PCD_NUMERIC_TYPES:
+ return MAX_SIZE_TYPE[self.DatumType]
+ if not self.DefaultValue:
+ return 1
+ elif self.DefaultValue[0] == 'L':
+ return (len(self.DefaultValue) - 2) * 2
+ elif self.DefaultValue[0] == '{':
+ return len(self.DefaultValue.split(','))
+ else:
+ return len(self.DefaultValue) - 1
+
+
## Convert the class to a string
#
# Convert each member of the class to string
diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/Source/Python/Workspace/DscBuildData.py
index bb35ed44aa..06ea7b05a3 100644
--- a/BaseTools/Source/Python/Workspace/DscBuildData.py
+++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
@@ -1535,23 +1535,6 @@ class DscBuildData(PlatformBuildClassObject):
Result = Result + '"'
return Result
- @staticmethod
- def GetPcdMaxSize(Pcd):
- if Pcd.DatumType in TAB_PCD_NUMERIC_TYPES:
- return MAX_SIZE_TYPE[Pcd.DatumType]
-
- MaxSize = int(Pcd.MaxDatumSize,10) if Pcd.MaxDatumSize else 0
- if Pcd.PcdValueFromComm:
- if Pcd.PcdValueFromComm.startswith("{") and Pcd.PcdValueFromComm.endswith("}"):
- return max([len(Pcd.PcdValueFromComm.split(",")),MaxSize])
- elif Pcd.PcdValueFromComm.startswith("\"") or Pcd.PcdValueFromComm.startswith("\'"):
- return max([len(Pcd.PcdValueFromComm)-2+1,MaxSize])
- elif Pcd.PcdValueFromComm.startswith("L\""):
- return max([2*(len(Pcd.PcdValueFromComm)-3+1),MaxSize])
- else:
- return max([len(Pcd.PcdValueFromComm),MaxSize])
- return MaxSize
-
def GenerateSizeFunction(self,Pcd):
CApp = "// Default Value in Dec \n"
CApp = CApp + "void Cal_%s_%s_Size(UINT32 *Size){\n" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName)
@@ -1634,7 +1617,7 @@ class DscBuildData(PlatformBuildClassObject):
while '[' in FieldName:
FieldName = FieldName.rsplit('[', 1)[0]
CApp = CApp + ' __FLEXIBLE_SIZE(*Size, %s, %s, %d); // From %s Line %d Value %s \n' % (Pcd.DatumType, FieldName.strip("."), ArrayIndex + 1, Pcd.PcdFieldValueFromComm[FieldName_ori][1], Pcd.PcdFieldValueFromComm[FieldName_ori][2], Pcd.PcdFieldValueFromComm[FieldName_ori][0])
- CApp = CApp + " *Size = (%d > *Size ? %d : *Size); // The Pcd maxsize is %d \n" % (DscBuildData.GetPcdMaxSize(Pcd),DscBuildData.GetPcdMaxSize(Pcd),DscBuildData.GetPcdMaxSize(Pcd))
+ CApp = CApp + " *Size = (%d > *Size ? %d : *Size); // The Pcd maxsize is %d \n" % (Pcd.GetPcdMaxSize(),Pcd.GetPcdMaxSize(),Pcd.GetPcdMaxSize())
CApp = CApp + "}\n"
return CApp