BaseTools: Handle the bytes and str difference
Deal with bytes and str is different, remove the unicode(), correct open file parameter. Using utcfromtimestamp instead of fromtimestamp. Cc: Bob Feng <bob.c.feng@intel.com> 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> Tested-by: Laszlo Ersek <lersek@redhat.com> Tested-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Reviewed-by: Liming Gao <liming.gao@intel.com> Reviewed-by: Bob Feng <bob.c.feng@intel.com>
This commit is contained in:
@ -73,8 +73,9 @@ class VariableMgr(object):
|
||||
fisrtdata_flag = DataType.PACK_CODE_BY_SIZE[MAX_SIZE_TYPE[firstdata_type]]
|
||||
fisrtdata = fisrtvalue_list[0]
|
||||
fisrtvalue_list = []
|
||||
for data_byte in pack(fisrtdata_flag, int(fisrtdata, 16) if fisrtdata.upper().startswith('0X') else int(fisrtdata)):
|
||||
fisrtvalue_list.append(hex(unpack("B", data_byte)[0]))
|
||||
pack_data = pack(fisrtdata_flag, int(fisrtdata, 0))
|
||||
for data_byte in range(len(pack_data)):
|
||||
fisrtvalue_list.append(hex(unpack("B", pack_data[data_byte:data_byte + 1])[0]))
|
||||
newvalue_list = ["0x00"] * FirstOffset + fisrtvalue_list
|
||||
|
||||
for var_item in sku_var_info_offset_list[1:]:
|
||||
@ -85,8 +86,9 @@ class VariableMgr(object):
|
||||
data_flag = DataType.PACK_CODE_BY_SIZE[MAX_SIZE_TYPE[Curdata_type]]
|
||||
data = CurvalueList[0]
|
||||
CurvalueList = []
|
||||
for data_byte in pack(data_flag, int(data, 16) if data.upper().startswith('0X') else int(data)):
|
||||
CurvalueList.append(hex(unpack("B", data_byte)[0]))
|
||||
pack_data = pack(data_flag, int(data, 0))
|
||||
for data_byte in range(len(pack_data)):
|
||||
CurvalueList.append(hex(unpack("B", pack_data[data_byte:data_byte + 1])[0]))
|
||||
if CurOffset > len(newvalue_list):
|
||||
newvalue_list = newvalue_list + ["0x00"] * (CurOffset - len(newvalue_list)) + CurvalueList
|
||||
else:
|
||||
@ -123,8 +125,8 @@ class VariableMgr(object):
|
||||
default_data_buffer = VariableMgr.PACK_VARIABLES_DATA(default_sku_default.default_value, default_sku_default.data_type, tail)
|
||||
|
||||
default_data_array = ()
|
||||
for item in default_data_buffer:
|
||||
default_data_array += unpack("B", item)
|
||||
for item in range(len(default_data_buffer)):
|
||||
default_data_array += unpack("B", default_data_buffer[item:item + 1])
|
||||
|
||||
var_data[(DataType.TAB_DEFAULT, DataType.TAB_DEFAULT_STORES_DEFAULT)][index] = (default_data_buffer, sku_var_info[(DataType.TAB_DEFAULT, DataType.TAB_DEFAULT_STORES_DEFAULT)])
|
||||
|
||||
@ -141,8 +143,8 @@ class VariableMgr(object):
|
||||
others_data_buffer = VariableMgr.PACK_VARIABLES_DATA(other_sku_other.default_value, other_sku_other.data_type, tail)
|
||||
|
||||
others_data_array = ()
|
||||
for item in others_data_buffer:
|
||||
others_data_array += unpack("B", item)
|
||||
for item in range(len(others_data_buffer)):
|
||||
others_data_array += unpack("B", others_data_buffer[item:item + 1])
|
||||
|
||||
data_delta = VariableMgr.calculate_delta(default_data_array, others_data_array)
|
||||
|
||||
@ -158,7 +160,7 @@ class VariableMgr(object):
|
||||
return []
|
||||
|
||||
pcds_default_data = var_data.get((DataType.TAB_DEFAULT, DataType.TAB_DEFAULT_STORES_DEFAULT), {})
|
||||
NvStoreDataBuffer = ""
|
||||
NvStoreDataBuffer = bytearray()
|
||||
var_data_offset = collections.OrderedDict()
|
||||
offset = NvStorageHeaderSize
|
||||
for default_data, default_info in pcds_default_data.values():
|
||||
@ -185,7 +187,7 @@ class VariableMgr(object):
|
||||
|
||||
nv_default_part = VariableMgr.AlignData(VariableMgr.PACK_DEFAULT_DATA(0, 0, VariableMgr.unpack_data(variable_storage_header_buffer+NvStoreDataBuffer)), 8)
|
||||
|
||||
data_delta_structure_buffer = ""
|
||||
data_delta_structure_buffer = bytearray()
|
||||
for skuname, defaultstore in var_data:
|
||||
if (skuname, defaultstore) == (DataType.TAB_DEFAULT, DataType.TAB_DEFAULT_STORES_DEFAULT):
|
||||
continue
|
||||
@ -216,8 +218,8 @@ class VariableMgr(object):
|
||||
@staticmethod
|
||||
def unpack_data(data):
|
||||
final_data = ()
|
||||
for item in data:
|
||||
final_data += unpack("B", item)
|
||||
for item in range(len(data)):
|
||||
final_data += unpack("B", data[item:item + 1])
|
||||
return final_data
|
||||
|
||||
@staticmethod
|
||||
@ -285,7 +287,7 @@ class VariableMgr(object):
|
||||
|
||||
@staticmethod
|
||||
def PACK_VARIABLES_DATA(var_value,data_type, tail = None):
|
||||
Buffer = ""
|
||||
Buffer = bytearray()
|
||||
data_len = 0
|
||||
if data_type == DataType.TAB_VOID:
|
||||
for value_char in var_value.strip("{").strip("}").split(","):
|
||||
@ -315,7 +317,7 @@ class VariableMgr(object):
|
||||
|
||||
@staticmethod
|
||||
def PACK_DEFAULT_DATA(defaultstoragename, skuid, var_value):
|
||||
Buffer = ""
|
||||
Buffer = bytearray()
|
||||
Buffer += pack("=L", 4+8+8)
|
||||
Buffer += pack("=Q", int(skuid))
|
||||
Buffer += pack("=Q", int(defaultstoragename))
|
||||
@ -340,7 +342,7 @@ class VariableMgr(object):
|
||||
def PACK_DELTA_DATA(self, skuname, defaultstoragename, delta_list):
|
||||
skuid = self.GetSkuId(skuname)
|
||||
defaultstorageid = self.GetDefaultStoreId(defaultstoragename)
|
||||
Buffer = ""
|
||||
Buffer = bytearray()
|
||||
Buffer += pack("=L", 4+8+8)
|
||||
Buffer += pack("=Q", int(skuid))
|
||||
Buffer += pack("=Q", int(defaultstorageid))
|
||||
@ -363,7 +365,7 @@ class VariableMgr(object):
|
||||
|
||||
@staticmethod
|
||||
def PACK_VARIABLE_NAME(var_name):
|
||||
Buffer = ""
|
||||
Buffer = bytearray()
|
||||
for name_char in var_name.strip("{").strip("}").split(","):
|
||||
Buffer += pack("=B", int(name_char, 16))
|
||||
|
||||
|
Reference in New Issue
Block a user