diff --git a/BaseTools/Source/Python/AutoGen/GenC.py b/BaseTools/Source/Python/AutoGen/GenC.py index f455f831e0..09626d0b96 100644 --- a/BaseTools/Source/Python/AutoGen/GenC.py +++ b/BaseTools/Source/Python/AutoGen/GenC.py @@ -1015,50 +1015,19 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd): EdkLogger.error("build", AUTOGEN_ERROR, "PCD value is not valid dec or hex number for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName), ExtraData="[%s]" % str(Info)) - if Pcd.DatumType == TAB_UINT64: - if ValueNumber < 0: - EdkLogger.error("build", AUTOGEN_ERROR, - "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName), - ExtraData="[%s]" % str(Info)) - elif ValueNumber >= 0x10000000000000000: - EdkLogger.error("build", AUTOGEN_ERROR, - "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName), - ExtraData="[%s]" % str(Info)) - if not Value.endswith('ULL'): - Value += 'ULL' - elif Pcd.DatumType == TAB_UINT32: - if ValueNumber < 0: - EdkLogger.error("build", AUTOGEN_ERROR, - "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName), - ExtraData="[%s]" % str(Info)) - elif ValueNumber >= 0x100000000: - EdkLogger.error("build", AUTOGEN_ERROR, - "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName), - ExtraData="[%s]" % str(Info)) - if not Value.endswith('U'): - Value += 'U' - elif Pcd.DatumType == TAB_UINT16: - if ValueNumber < 0: - EdkLogger.error("build", AUTOGEN_ERROR, - "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName), - ExtraData="[%s]" % str(Info)) - elif ValueNumber >= 0x10000: - EdkLogger.error("build", AUTOGEN_ERROR, - "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName), - ExtraData="[%s]" % str(Info)) - if not Value.endswith('U'): - Value += 'U' - elif Pcd.DatumType == TAB_UINT8: - if ValueNumber < 0: - EdkLogger.error("build", AUTOGEN_ERROR, - "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName), - ExtraData="[%s]" % str(Info)) - elif ValueNumber >= 0x100: - EdkLogger.error("build", AUTOGEN_ERROR, - "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName), - ExtraData="[%s]" % str(Info)) - if not Value.endswith('U'): - Value += 'U' + if ValueNumber < 0: + EdkLogger.error("build", AUTOGEN_ERROR, + "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName), + ExtraData="[%s]" % str(Info)) + elif ValueNumber > MAX_VAL_TYPE[Pcd.DatumType]: + EdkLogger.error("build", AUTOGEN_ERROR, + "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName), + ExtraData="[%s]" % str(Info)) + if Pcd.DatumType == TAB_UINT64 and not Value.endswith('ULL'): + Value += 'ULL' + elif Pcd.DatumType != TAB_UINT64 and not Value.endswith('U'): + Value += 'U' + if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES: if not Pcd.MaxDatumSize: EdkLogger.error("build", AUTOGEN_ERROR, diff --git a/BaseTools/Source/Python/BPDG/GenVpd.py b/BaseTools/Source/Python/BPDG/GenVpd.py index c5e91a3e81..d7852d29ee 100644 --- a/BaseTools/Source/Python/BPDG/GenVpd.py +++ b/BaseTools/Source/Python/BPDG/GenVpd.py @@ -21,6 +21,7 @@ import array import re from Common.LongFilePathSupport import OpenLongFilePath as open from struct import * +from Common.DataType import MAX_SIZE_TYPE, MAX_VAL_TYPE import Common.EdkLogger as EdkLogger import Common.BuildToolError as BuildToolError @@ -125,37 +126,18 @@ class PcdEntry: EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, "Invalid size %d for PCD %s in integer datum size(File: %s Line: %s)." % (Size, self.PcdCName, self.FileName, self.Lineno)) - if Size == 1: - if IntValue < 0: - EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, - "PCD can't be set to negative value %d for PCD %s in UINT8 datum type(File: %s Line: %s)." % (IntValue, self.PcdCName, self.FileName, self.Lineno)) - elif IntValue >= 0x100: - EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, - "Too large PCD value %d for datum type UINT8 for PCD %s(File: %s Line: %s)." % (IntValue, self.PcdCName, self.FileName, self.Lineno)) - elif Size == 2: - if IntValue < 0: - EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, - "PCD can't be set to negative value %d for PCD %s in UINT16 datum type(File: %s Line: %s)." % (IntValue, self.PcdCName, self.FileName, self.Lineno)) - elif IntValue >= 0x10000: - EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, - "Too large PCD value %d for datum type UINT16 for PCD %s(File: %s Line: %s)." % (IntValue, self.PcdCName, self.FileName, self.Lineno)) - elif Size == 4: - if IntValue < 0: - EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, - "PCD can't be set to negative value %d for PCD %s in UINT32 datum type(File: %s Line: %s)." % (IntValue, self.PcdCName, self.FileName, self.Lineno)) - elif IntValue >= 0x100000000: - EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, - "Too large PCD value %d for datum type UINT32 for PCD %s(File: %s Line: %s)." % (IntValue, self.PcdCName, self.FileName, self.Lineno)) - elif Size == 8: - if IntValue < 0: - EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, - "PCD can't be set to negative value %d for PCD %s in UINT32 datum type(File: %s Line: %s)." % (IntValue, self.PcdCName, self.FileName, self.Lineno)) - elif IntValue >= 0x10000000000000000: - EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, - "Too large PCD value %d for datum type UINT32 for PCD %s(File: %s Line: %s)." % (IntValue, self.PcdCName, self.FileName, self.Lineno)) - else: - EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, - "Invalid size %d for PCD %s in integer datum size(File: %s Line: %s)." % (Size, self.PcdCName, self.FileName, self.Lineno)) + for Type, MaxSize in MAX_SIZE_TYPE.items(): + if Type == 'BOOLEAN': + continue + if Size == MaxSize: + if IntValue < 0: + EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, + "PCD can't be set to negative value %d for PCD %s in %s datum type(File: %s Line: %s)." % ( + IntValue, self.PcdCName, Type, self.FileName, self.Lineno)) + elif IntValue > MAX_VAL_TYPE[Type]: + EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, + "Too large PCD value %d for datum type %s for PCD %s(File: %s Line: %s)." % ( + IntValue, Type, self.PcdCName, self.FileName, self.Lineno)) try: self.PcdValue = pack(_FORMAT_CHAR[Size], IntValue) diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Python/Common/Misc.py index fb6a844dd5..0efd8b05a8 100644 --- a/BaseTools/Source/Python/Common/Misc.py +++ b/BaseTools/Source/Python/Common/Misc.py @@ -1589,8 +1589,12 @@ def CheckPcdDatum(Type, Value): return False, "Invalid value [%s] of type [%s]; must be one of TRUE, True, true, 0x1, 0x01, 1"\ ", FALSE, False, false, 0x0, 0x00, 0" % (Value, Type) elif Type in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64]: + if Value and int(Value, 0) < 0: + return False, "PCD can't be set to negative value[%s] for datum type [%s]" % (Value, Type) try: Value = long(Value, 0) + if Value > MAX_VAL_TYPE[Type]: + return False, "Too large PCD value[%s] for datum type [%s]" % (Value, Type) except: return False, "Invalid value [%s] of type [%s];"\ " must be a hexadecimal, decimal or octal in C language format." % (Value, Type)