## @file\r
# Patch value into the binary file.\r
#\r
-# Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>\r
# This program and the accompanying materials\r
# are licensed and made available under the terms and conditions of the BSD License\r
# which accompanies this distribution. The full text of the license may be found at\r
import Common.EdkLogger as EdkLogger\r
from Common.BuildVersion import gBUILD_VERSION\r
import array\r
+from Common.DataType import *\r
\r
# Version and Copyright\r
__version_number__ = ("0.10" + " " + gBUILD_VERSION)\r
__version__ = "%prog Version " + __version_number__\r
-__copyright__ = "Copyright (c) 2010, Intel Corporation. All rights reserved."\r
+__copyright__ = "Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved."\r
\r
## PatchBinaryFile method\r
#\r
# This method mainly patches the data into binary file.\r
-# \r
+#\r
# @param FileName File path of the binary file\r
-# @param ValueOffset Offset value \r
+# @param ValueOffset Offset value\r
# @param TypeName DataType Name\r
# @param Value Value String\r
# @param MaxSize MaxSize value\r
ValueLength = 0\r
if TypeName == 'BOOLEAN':\r
ValueLength = 1\r
- elif TypeName == 'UINT8':\r
+ elif TypeName == TAB_UINT8:\r
ValueLength = 1\r
- elif TypeName == 'UINT16':\r
+ elif TypeName == TAB_UINT16:\r
ValueLength = 2\r
- elif TypeName == 'UINT32':\r
+ elif TypeName == TAB_UINT32:\r
ValueLength = 4\r
- elif TypeName == 'UINT64':\r
+ elif TypeName == TAB_UINT64:\r
ValueLength = 8\r
- elif TypeName == 'VOID*':\r
+ elif TypeName == TAB_VOID:\r
if MaxSize == 0:\r
return OPTION_MISSING, "PcdMaxSize is not specified for VOID* type PCD."\r
ValueLength = int(MaxSize)\r
ValueNumber = 1\r
elif ValueString == 'FALSE':\r
ValueNumber = 0\r
- elif ValueString.startswith('0X'):\r
- ValueNumber = int (ValueString, 16)\r
- else:\r
- ValueNumber = int (ValueString)\r
+ ValueNumber = int (ValueString, 0)\r
if ValueNumber != 0:\r
ValueNumber = 1\r
except:\r
# Set PCD value into binary data\r
#\r
ByteList[ValueOffset] = ValueNumber\r
- elif TypeName in ['UINT8', 'UINT16', 'UINT32', 'UINT64']:\r
+ elif TypeName in TAB_PCD_CLEAN_NUMERIC_TYPES:\r
#\r
# Get PCD value for UINT* data type\r
#\r
try:\r
- if ValueString.startswith('0X'):\r
- ValueNumber = int (ValueString, 16)\r
- else:\r
- ValueNumber = int (ValueString)\r
+ ValueNumber = int (ValueString, 0)\r
except:\r
return PARAMETER_INVALID, "PCD Value %s is not valid dec or hex string." % (ValueString)\r
#\r
for Index in range(ValueLength):\r
ByteList[ValueOffset + Index] = ValueNumber % 0x100\r
ValueNumber = ValueNumber / 0x100\r
- elif TypeName == 'VOID*':\r
+ elif TypeName == TAB_VOID:\r
ValueString = SavedStr\r
if ValueString.startswith('L"'):\r
#\r
return PARAMETER_INVALID, "PCD Value %s is not valid dec or hex string array." % (ValueString)\r
else:\r
#\r
- # Patch ascii string \r
+ # Patch ascii string\r
#\r
Index = 0\r
for ByteString in ValueString[1:-1]:\r
if CommandOptions.PcdOffset is None or CommandOptions.PcdValue is None or CommandOptions.PcdTypeName is None:\r
EdkLogger.error("PatchPcdValue", OPTION_MISSING, ExtraData="PcdOffset or PcdValue of PcdTypeName is not specified.")\r
return 1\r
- if CommandOptions.PcdTypeName.upper() not in ["BOOLEAN", "UINT8", "UINT16", "UINT32", "UINT64", "VOID*"]:\r
+ if CommandOptions.PcdTypeName.upper() not in TAB_PCD_NUMERIC_TYPES_VOID:\r
EdkLogger.error("PatchPcdValue", PARAMETER_INVALID, ExtraData="PCD type %s is not valid." % (CommandOptions.PcdTypeName))\r
return 1\r
- if CommandOptions.PcdTypeName.upper() == "VOID*" and CommandOptions.PcdMaxSize is None:\r
+ if CommandOptions.PcdTypeName.upper() == TAB_VOID and CommandOptions.PcdMaxSize is None:\r
EdkLogger.error("PatchPcdValue", OPTION_MISSING, ExtraData="PcdMaxSize is not specified for VOID* type PCD.")\r
return 1\r
#\r