X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2FPatchPcdValue%2FPatchPcdValue.py;h=0664d6a90fa14ca9a11dadfd644698aa55816467;hp=1b3a0ec93d62c1b503e1020082519bb31ff96c88;hb=0944818a1972b07b09b53a2a1e88295cd92361cf;hpb=1be2ed90a20618d71ddf34b8a07d038da0b36854 diff --git a/BaseTools/Source/Python/PatchPcdValue/PatchPcdValue.py b/BaseTools/Source/Python/PatchPcdValue/PatchPcdValue.py index 1b3a0ec93d..0664d6a90f 100644 --- a/BaseTools/Source/Python/PatchPcdValue/PatchPcdValue.py +++ b/BaseTools/Source/Python/PatchPcdValue/PatchPcdValue.py @@ -48,7 +48,7 @@ def PatchBinaryFile(FileName, ValueOffset, TypeName, ValueString, MaxSize=0): # # Length of Binary File # - FileHandle = open (FileName, 'rb') + FileHandle = open(FileName, 'rb') FileHandle.seek (0, 2) FileLength = FileHandle.tell() FileHandle.close() @@ -75,7 +75,7 @@ def PatchBinaryFile(FileName, ValueOffset, TypeName, ValueString, MaxSize=0): return OPTION_MISSING, "PcdMaxSize is not specified for VOID* type PCD." ValueLength = int(MaxSize) else: - return PARAMETER_INVALID, "PCD type %s is not valid." %(CommandOptions.PcdTypeName) + return PARAMETER_INVALID, "PCD type %s is not valid." % (CommandOptions.PcdTypeName) # # Check PcdValue is in the input binary file. # @@ -84,7 +84,7 @@ def PatchBinaryFile(FileName, ValueOffset, TypeName, ValueString, MaxSize=0): # # Read binary file into array # - FileHandle = open (FileName, 'rb') + FileHandle = open(FileName, 'rb') ByteArray = array.array('B') ByteArray.fromfile(FileHandle, FileLength) FileHandle.close() @@ -110,14 +110,11 @@ def PatchBinaryFile(FileName, ValueOffset, TypeName, ValueString, MaxSize=0): ValueNumber = 1 elif ValueString == 'FALSE': ValueNumber = 0 - elif ValueString.startswith('0X'): - ValueNumber = int (ValueString, 16) - else: - ValueNumber = int (ValueString) + ValueNumber = int (ValueString, 0) if ValueNumber != 0: ValueNumber = 1 except: - return PARAMETER_INVALID, "PCD Value %s is not valid dec or hex string." %(ValueString) + return PARAMETER_INVALID, "PCD Value %s is not valid dec or hex string." % (ValueString) # # Set PCD value into binary data # @@ -127,12 +124,9 @@ def PatchBinaryFile(FileName, ValueOffset, TypeName, ValueString, MaxSize=0): # Get PCD value for UINT* data type # try: - if ValueString.startswith('0X'): - ValueNumber = int (ValueString, 16) - else: - ValueNumber = int (ValueString) + ValueNumber = int (ValueString, 0) except: - return PARAMETER_INVALID, "PCD Value %s is not valid dec or hex string." %(ValueString) + return PARAMETER_INVALID, "PCD Value %s is not valid dec or hex string." % (ValueString) # # Set PCD value into binary data # @@ -161,10 +155,11 @@ def PatchBinaryFile(FileName, ValueOffset, TypeName, ValueString, MaxSize=0): # # Patch {0x1, 0x2, ...} byte by byte # - ValueList = ValueString[1 : len(ValueString) - 1].split(', ') + ValueList = ValueString[1 : len(ValueString) - 1].split(',') Index = 0 try: for ByteString in ValueList: + ByteString = ByteString.strip() if ByteString.upper().startswith('0X'): ByteValue = int(ByteString, 16) else: @@ -174,7 +169,7 @@ def PatchBinaryFile(FileName, ValueOffset, TypeName, ValueString, MaxSize=0): if Index >= ValueLength: break except: - return PARAMETER_INVALID, "PCD Value %s is not valid dec or hex string array." %(ValueString) + return PARAMETER_INVALID, "PCD Value %s is not valid dec or hex string array." % (ValueString) else: # # Patch ascii string @@ -197,10 +192,10 @@ def PatchBinaryFile(FileName, ValueOffset, TypeName, ValueString, MaxSize=0): if ByteList != OrigByteList: ByteArray = array.array('B') ByteArray.fromlist(ByteList) - FileHandle = open (FileName, 'wb') + FileHandle = open(FileName, 'wb') ByteArray.tofile(FileHandle) FileHandle.close() - return 0, "Patch Value into File %s successfully." %(FileName) + return 0, "Patch Value into File %s successfully." % (FileName) ## Parse command line options # @@ -266,13 +261,13 @@ def Main(): if not os.path.exists (InputFile): EdkLogger.error("PatchPcdValue", FILE_NOT_FOUND, ExtraData=InputFile) return 1 - if CommandOptions.PcdOffset == None or CommandOptions.PcdValue == None or CommandOptions.PcdTypeName == None: + if CommandOptions.PcdOffset is None or CommandOptions.PcdValue is None or CommandOptions.PcdTypeName is None: EdkLogger.error("PatchPcdValue", OPTION_MISSING, ExtraData="PcdOffset or PcdValue of PcdTypeName is not specified.") return 1 if CommandOptions.PcdTypeName.upper() not in ["BOOLEAN", "UINT8", "UINT16", "UINT32", "UINT64", "VOID*"]: - EdkLogger.error("PatchPcdValue", PARAMETER_INVALID, ExtraData="PCD type %s is not valid." %(CommandOptions.PcdTypeName)) + EdkLogger.error("PatchPcdValue", PARAMETER_INVALID, ExtraData="PCD type %s is not valid." % (CommandOptions.PcdTypeName)) return 1 - if CommandOptions.PcdTypeName.upper() == "VOID*" and CommandOptions.PcdMaxSize == None: + if CommandOptions.PcdTypeName.upper() == "VOID*" and CommandOptions.PcdMaxSize is None: EdkLogger.error("PatchPcdValue", OPTION_MISSING, ExtraData="PcdMaxSize is not specified for VOID* type PCD.") return 1 #