]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/PatchPcdValue/PatchPcdValue.py
BaseTools: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / BaseTools / Source / Python / PatchPcdValue / PatchPcdValue.py
index 942ba88d200f98c70ba163443aa6727140666402..02735e165ca1c22c511012850e16e44c6f65f439 100644 (file)
@@ -1,14 +1,8 @@
 ## @file\r
 # Patch value into the binary file.\r
 #\r
-# Copyright (c) 2010 - 2014, 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
-# http://opensource.org/licenses/bsd-license.php\r
-#\r
-# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+# Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>\r
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
 #\r
 \r
 ##\r
@@ -25,18 +19,19 @@ from Common.BuildToolError import *
 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
@@ -62,15 +57,15 @@ def PatchBinaryFile(FileName, ValueOffset, TypeName, ValueString, MaxSize=0):
     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
@@ -110,10 +105,7 @@ def PatchBinaryFile(FileName, ValueOffset, TypeName, ValueString, MaxSize=0):
                 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
@@ -122,15 +114,12 @@ def PatchBinaryFile(FileName, ValueOffset, TypeName, ValueString, MaxSize=0):
         # 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
@@ -138,8 +127,8 @@ def PatchBinaryFile(FileName, ValueOffset, TypeName, ValueString, MaxSize=0):
         #\r
         for Index in range(ValueLength):\r
             ByteList[ValueOffset + Index] = ValueNumber % 0x100\r
-            ValueNumber = ValueNumber / 0x100\r
-    elif TypeName == 'VOID*':\r
+            ValueNumber = ValueNumber // 0x100\r
+    elif TypeName == TAB_VOID:\r
         ValueString = SavedStr\r
         if ValueString.startswith('L"'):\r
             #\r
@@ -153,7 +142,7 @@ def PatchBinaryFile(FileName, ValueOffset, TypeName, ValueString, MaxSize=0):
                 if Index + 2 >= ValueLength:\r
                     break\r
                 #\r
-                # Set string value one by one\r
+                # Set string value one by one/ 0x100\r
                 #\r
                 ByteList[ValueOffset + Index] = ord(ByteString)\r
                 Index = Index + 2\r
@@ -178,7 +167,7 @@ def PatchBinaryFile(FileName, ValueOffset, TypeName, ValueString, MaxSize=0):
                 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
@@ -267,13 +256,13 @@ def Main():
         if not os.path.exists (InputFile):\r
             EdkLogger.error("PatchPcdValue", FILE_NOT_FOUND, ExtraData=InputFile)\r
             return 1\r
-        if CommandOptions.PcdOffset == None or CommandOptions.PcdValue == None or CommandOptions.PcdTypeName == None:\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 == 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