diff options
author | zhijufan <zhijux.fan@intel.com> | 2018-09-27 14:08:15 +0800 |
---|---|---|
committer | Yonghong Zhu <yonghong.zhu@intel.com> | 2018-09-30 16:05:49 +0800 |
commit | c526dcd40f3a0f3a091684481f9c85f03f6a70a7 (patch) | |
tree | 90991c02eb9127dbb5966867e8b1192b33f01d3c /BaseTools/Source/Python/BPDG/GenVpd.py | |
parent | 5b02be4d9a234d80c7578fc3a0c789d22ce83f38 (diff) | |
download | edk2-c526dcd40f3a0f3a091684481f9c85f03f6a70a7.tar.gz edk2-c526dcd40f3a0f3a091684481f9c85f03f6a70a7.tar.bz2 edk2-c526dcd40f3a0f3a091684481f9c85f03f6a70a7.zip |
BaseTools: refactor the error for PCD value is negative or exceed max
refactor the error handling for the PCD value that is negative or it
exceed the max value.
Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhiju.Fan <zhijux.fan@intel.com>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
Diffstat (limited to 'BaseTools/Source/Python/BPDG/GenVpd.py')
-rw-r--r-- | BaseTools/Source/Python/BPDG/GenVpd.py | 44 |
1 files changed, 13 insertions, 31 deletions
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)
|