]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/PatchPcdValue/PatchPcdValue.py
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / BaseTools / Source / Python / PatchPcdValue / PatchPcdValue.py
index 0664d6a90fa14ca9a11dadfd644698aa55816467..d35cd792704cc40d3f9ab80f50776f09c9cbd203 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
@@ -17,7 +11,6 @@
 import Common.LongFilePathOs as os\r
 from Common.LongFilePathSupport import OpenLongFilePath as open\r
 import sys\r
-import re\r
 \r
 from optparse import OptionParser\r
 from optparse import make_option\r
@@ -25,18 +18,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 +56,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
@@ -119,7 +113,7 @@ 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
@@ -132,8 +126,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
@@ -147,7 +141,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
@@ -172,7 +166,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
@@ -264,10 +258,10 @@ def Main():
         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