2018-04-16 15:52:13 +02:00
|
|
|
# Copyright (c) 2017 - 2018, Intel Corporation. All rights reserved.<BR>
|
2019-04-04 01:03:11 +02:00
|
|
|
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
2017-11-24 07:46:58 +01:00
|
|
|
|
|
|
|
#
|
|
|
|
# This file is used to collect the Variable checking information
|
|
|
|
#
|
|
|
|
|
|
|
|
# #
|
|
|
|
# Import Modules
|
|
|
|
#
|
2018-06-25 12:31:33 +02:00
|
|
|
from struct import pack, unpack
|
2017-11-24 07:46:58 +01:00
|
|
|
import collections
|
|
|
|
import copy
|
|
|
|
from Common.VariableAttributes import VariableAttributes
|
|
|
|
from Common.Misc import *
|
|
|
|
import collections
|
2018-04-11 01:17:20 +02:00
|
|
|
import Common.DataType as DataType
|
2017-11-24 07:46:58 +01:00
|
|
|
|
2018-09-25 04:55:30 +02:00
|
|
|
var_info = collections.namedtuple("uefi_var", "pcdindex,pcdname,defaultstoragename,skuname,var_name, var_guid, var_offset,var_attribute,pcd_default_value, default_value, data_type,PcdDscLine,StructurePcd")
|
2017-11-24 07:46:58 +01:00
|
|
|
NvStorageHeaderSize = 28
|
|
|
|
VariableHeaderSize = 32
|
|
|
|
|
2017-12-22 13:46:15 +01:00
|
|
|
class VariableMgr(object):
|
2018-06-25 12:31:33 +02:00
|
|
|
def __init__(self, DefaultStoreMap, SkuIdMap):
|
2017-11-24 07:46:58 +01:00
|
|
|
self.VarInfo = []
|
2017-12-22 13:46:15 +01:00
|
|
|
self.DefaultStoreMap = DefaultStoreMap
|
|
|
|
self.SkuIdMap = SkuIdMap
|
2017-12-22 13:14:29 +01:00
|
|
|
self.VpdRegionSize = 0
|
|
|
|
self.VpdRegionOffset = 0
|
|
|
|
self.NVHeaderBuff = None
|
|
|
|
self.VarDefaultBuff = None
|
|
|
|
self.VarDeltaBuff = None
|
2017-11-24 07:46:58 +01:00
|
|
|
|
2018-06-25 12:31:33 +02:00
|
|
|
def append_variable(self, uefi_var):
|
2017-11-24 07:46:58 +01:00
|
|
|
self.VarInfo.append(uefi_var)
|
|
|
|
|
2018-06-25 12:31:33 +02:00
|
|
|
def SetVpdRegionMaxSize(self, maxsize):
|
2017-12-22 13:14:29 +01:00
|
|
|
self.VpdRegionSize = maxsize
|
|
|
|
|
2018-06-25 12:31:33 +02:00
|
|
|
def SetVpdRegionOffset(self, vpdoffset):
|
2017-12-22 13:14:29 +01:00
|
|
|
self.VpdRegionOffset = vpdoffset
|
|
|
|
|
2018-06-25 12:31:33 +02:00
|
|
|
def PatchNVStoreDefaultMaxSize(self, maxsize):
|
2017-12-22 13:14:29 +01:00
|
|
|
if not self.NVHeaderBuff:
|
|
|
|
return ""
|
2018-06-25 12:31:33 +02:00
|
|
|
self.NVHeaderBuff = self.NVHeaderBuff[:8] + pack("=Q", maxsize)
|
2018-04-28 00:32:21 +02:00
|
|
|
default_var_bin = VariableMgr.format_data(self.NVHeaderBuff + self.VarDefaultBuff + self.VarDeltaBuff)
|
2017-12-22 13:14:29 +01:00
|
|
|
value_str = "{"
|
|
|
|
default_var_bin_strip = [ data.strip("""'""") for data in default_var_bin]
|
|
|
|
value_str += ",".join(default_var_bin_strip)
|
|
|
|
value_str += "}"
|
|
|
|
return value_str
|
2018-10-10 10:27:02 +02:00
|
|
|
|
2018-01-23 03:18:53 +01:00
|
|
|
def combine_variable(self):
|
|
|
|
indexedvarinfo = collections.OrderedDict()
|
|
|
|
for item in self.VarInfo:
|
2018-06-25 12:31:33 +02:00
|
|
|
if (item.skuname, item.defaultstoragename, item.var_name, item.var_guid) not in indexedvarinfo:
|
|
|
|
indexedvarinfo[(item.skuname, item.defaultstoragename, item.var_name, item.var_guid) ] = []
|
|
|
|
indexedvarinfo[(item.skuname, item.defaultstoragename, item.var_name, item.var_guid)].append(item)
|
2018-01-23 03:18:53 +01:00
|
|
|
for key in indexedvarinfo:
|
|
|
|
sku_var_info_offset_list = indexedvarinfo[key]
|
2018-10-10 10:27:02 +02:00
|
|
|
sku_var_info_offset_list.sort(key=lambda x:x.PcdDscLine)
|
|
|
|
FirstOffset = int(sku_var_info_offset_list[0].var_offset, 16) if sku_var_info_offset_list[0].var_offset.upper().startswith("0X") else int(sku_var_info_offset_list[0].var_offset)
|
|
|
|
fisrtvalue_list = sku_var_info_offset_list[0].default_value.strip("{").strip("}").split(",")
|
|
|
|
firstdata_type = sku_var_info_offset_list[0].data_type
|
|
|
|
if firstdata_type in DataType.TAB_PCD_NUMERIC_TYPES:
|
|
|
|
fisrtdata_flag = DataType.PACK_CODE_BY_SIZE[MAX_SIZE_TYPE[firstdata_type]]
|
|
|
|
fisrtdata = fisrtvalue_list[0]
|
|
|
|
fisrtvalue_list = []
|
2019-01-23 03:16:00 +01:00
|
|
|
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]))
|
2018-10-10 10:27:02 +02:00
|
|
|
newvalue_list = ["0x00"] * FirstOffset + fisrtvalue_list
|
|
|
|
|
|
|
|
for var_item in sku_var_info_offset_list[1:]:
|
|
|
|
CurOffset = int(var_item.var_offset, 16) if var_item.var_offset.upper().startswith("0X") else int(var_item.var_offset)
|
|
|
|
CurvalueList = var_item.default_value.strip("{").strip("}").split(",")
|
|
|
|
Curdata_type = var_item.data_type
|
|
|
|
if Curdata_type in DataType.TAB_PCD_NUMERIC_TYPES:
|
|
|
|
data_flag = DataType.PACK_CODE_BY_SIZE[MAX_SIZE_TYPE[Curdata_type]]
|
|
|
|
data = CurvalueList[0]
|
|
|
|
CurvalueList = []
|
2019-01-23 03:16:00 +01:00
|
|
|
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]))
|
2018-10-10 10:27:02 +02:00
|
|
|
if CurOffset > len(newvalue_list):
|
|
|
|
newvalue_list = newvalue_list + ["0x00"] * (CurOffset - len(newvalue_list)) + CurvalueList
|
|
|
|
else:
|
|
|
|
newvalue_list[CurOffset : CurOffset + len(CurvalueList)] = CurvalueList
|
|
|
|
|
|
|
|
newvaluestr = "{" + ",".join(newvalue_list) +"}"
|
2018-01-23 03:18:53 +01:00
|
|
|
n = sku_var_info_offset_list[0]
|
2018-09-25 04:55:30 +02:00
|
|
|
indexedvarinfo[key] = [var_info(n.pcdindex, n.pcdname, n.defaultstoragename, n.skuname, n.var_name, n.var_guid, "0x00", n.var_attribute, newvaluestr, newvaluestr, DataType.TAB_VOID,n.PcdDscLine,n.StructurePcd)]
|
2018-10-10 10:27:02 +02:00
|
|
|
self.VarInfo = [item[0] for item in list(indexedvarinfo.values())]
|
2018-04-28 00:32:19 +02:00
|
|
|
|
2017-11-24 07:46:58 +01:00
|
|
|
def process_variable_data(self):
|
|
|
|
|
2018-04-20 17:51:45 +02:00
|
|
|
var_data = collections.defaultdict(collections.OrderedDict)
|
2017-11-24 07:46:58 +01:00
|
|
|
|
|
|
|
indexedvarinfo = collections.OrderedDict()
|
|
|
|
for item in self.VarInfo:
|
|
|
|
if item.pcdindex not in indexedvarinfo:
|
|
|
|
indexedvarinfo[item.pcdindex] = dict()
|
2018-06-25 12:31:33 +02:00
|
|
|
indexedvarinfo[item.pcdindex][(item.skuname, item.defaultstoragename)] = item
|
2017-11-24 07:46:58 +01:00
|
|
|
|
|
|
|
for index in indexedvarinfo:
|
|
|
|
sku_var_info = indexedvarinfo[index]
|
|
|
|
|
|
|
|
default_data_buffer = ""
|
|
|
|
others_data_buffer = ""
|
|
|
|
tail = None
|
2018-06-25 12:31:33 +02:00
|
|
|
default_sku_default = indexedvarinfo[index].get((DataType.TAB_DEFAULT, DataType.TAB_DEFAULT_STORES_DEFAULT))
|
2017-11-24 07:46:58 +01:00
|
|
|
|
2018-04-11 18:14:05 +02:00
|
|
|
if default_sku_default.data_type not in DataType.TAB_PCD_NUMERIC_TYPES:
|
2018-04-28 00:32:54 +02:00
|
|
|
var_max_len = max(len(var_item.default_value.split(",")) for var_item in sku_var_info.values())
|
2017-11-24 07:46:58 +01:00
|
|
|
if len(default_sku_default.default_value.split(",")) < var_max_len:
|
2018-04-28 00:32:54 +02:00
|
|
|
tail = ",".join("0x00" for i in range(var_max_len-len(default_sku_default.default_value.split(","))))
|
2017-11-24 07:46:58 +01:00
|
|
|
|
2018-06-25 12:31:33 +02:00
|
|
|
default_data_buffer = VariableMgr.PACK_VARIABLES_DATA(default_sku_default.default_value, default_sku_default.data_type, tail)
|
2017-11-24 07:46:58 +01:00
|
|
|
|
|
|
|
default_data_array = ()
|
2019-01-23 03:16:00 +01:00
|
|
|
for item in range(len(default_data_buffer)):
|
|
|
|
default_data_array += unpack("B", default_data_buffer[item:item + 1])
|
2017-11-24 07:46:58 +01:00
|
|
|
|
2018-06-25 12:31:33 +02:00
|
|
|
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)])
|
2017-11-24 07:46:58 +01:00
|
|
|
|
2018-06-25 12:31:33 +02:00
|
|
|
for (skuid, defaultstoragename) in indexedvarinfo[index]:
|
2017-11-24 07:46:58 +01:00
|
|
|
tail = None
|
2018-06-25 12:31:33 +02:00
|
|
|
if (skuid, defaultstoragename) == (DataType.TAB_DEFAULT, DataType.TAB_DEFAULT_STORES_DEFAULT):
|
2017-11-24 07:46:58 +01:00
|
|
|
continue
|
2018-06-25 12:31:33 +02:00
|
|
|
other_sku_other = indexedvarinfo[index][(skuid, defaultstoragename)]
|
2017-11-24 07:46:58 +01:00
|
|
|
|
2018-04-11 18:14:05 +02:00
|
|
|
if default_sku_default.data_type not in DataType.TAB_PCD_NUMERIC_TYPES:
|
2017-11-24 07:46:58 +01:00
|
|
|
if len(other_sku_other.default_value.split(",")) < var_max_len:
|
2018-04-28 00:32:54 +02:00
|
|
|
tail = ",".join("0x00" for i in range(var_max_len-len(other_sku_other.default_value.split(","))))
|
2017-11-24 07:46:58 +01:00
|
|
|
|
2018-06-25 12:31:33 +02:00
|
|
|
others_data_buffer = VariableMgr.PACK_VARIABLES_DATA(other_sku_other.default_value, other_sku_other.data_type, tail)
|
2017-11-24 07:46:58 +01:00
|
|
|
|
|
|
|
others_data_array = ()
|
2019-01-23 03:16:00 +01:00
|
|
|
for item in range(len(others_data_buffer)):
|
|
|
|
others_data_array += unpack("B", others_data_buffer[item:item + 1])
|
2017-11-24 07:46:58 +01:00
|
|
|
|
2018-04-28 00:32:21 +02:00
|
|
|
data_delta = VariableMgr.calculate_delta(default_data_array, others_data_array)
|
2017-11-24 07:46:58 +01:00
|
|
|
|
2018-06-25 12:31:33 +02:00
|
|
|
var_data[(skuid, defaultstoragename)][index] = (data_delta, sku_var_info[(skuid, defaultstoragename)])
|
2017-11-24 07:46:58 +01:00
|
|
|
return var_data
|
|
|
|
|
|
|
|
def new_process_varinfo(self):
|
2018-01-23 03:18:53 +01:00
|
|
|
self.combine_variable()
|
2017-11-24 07:46:58 +01:00
|
|
|
|
|
|
|
var_data = self.process_variable_data()
|
|
|
|
|
2017-12-22 13:04:04 +01:00
|
|
|
if not var_data:
|
|
|
|
return []
|
|
|
|
|
2018-06-25 12:31:33 +02:00
|
|
|
pcds_default_data = var_data.get((DataType.TAB_DEFAULT, DataType.TAB_DEFAULT_STORES_DEFAULT), {})
|
2019-01-23 03:16:00 +01:00
|
|
|
NvStoreDataBuffer = bytearray()
|
2017-11-24 07:46:58 +01:00
|
|
|
var_data_offset = collections.OrderedDict()
|
|
|
|
offset = NvStorageHeaderSize
|
2018-06-25 12:31:33 +02:00
|
|
|
for default_data, default_info in pcds_default_data.values():
|
2018-04-28 00:32:21 +02:00
|
|
|
var_name_buffer = VariableMgr.PACK_VARIABLE_NAME(default_info.var_name)
|
2017-11-24 07:46:58 +01:00
|
|
|
|
|
|
|
vendorguid = default_info.var_guid.split('-')
|
|
|
|
|
|
|
|
if default_info.var_attribute:
|
2018-06-25 12:31:33 +02:00
|
|
|
var_attr_value, _ = VariableAttributes.GetVarAttributes(default_info.var_attribute)
|
2017-11-24 07:46:58 +01:00
|
|
|
else:
|
|
|
|
var_attr_value = 0x07
|
|
|
|
|
2018-04-28 00:32:21 +02:00
|
|
|
DataBuffer = VariableMgr.AlignData(var_name_buffer + default_data)
|
2017-11-24 07:46:58 +01:00
|
|
|
|
|
|
|
data_size = len(DataBuffer)
|
|
|
|
offset += VariableHeaderSize + len(default_info.var_name.split(","))
|
|
|
|
var_data_offset[default_info.pcdindex] = offset
|
|
|
|
offset += data_size - len(default_info.var_name.split(","))
|
|
|
|
|
2018-04-28 00:32:21 +02:00
|
|
|
var_header_buffer = VariableMgr.PACK_VARIABLE_HEADER(var_attr_value, len(default_info.var_name.split(",")), len (default_data), vendorguid)
|
2017-11-24 07:46:58 +01:00
|
|
|
NvStoreDataBuffer += (var_header_buffer + DataBuffer)
|
|
|
|
|
2018-04-28 00:32:21 +02:00
|
|
|
variable_storage_header_buffer = VariableMgr.PACK_VARIABLE_STORE_HEADER(len(NvStoreDataBuffer) + 28)
|
2017-11-24 07:46:58 +01:00
|
|
|
|
2018-04-28 00:32:21 +02:00
|
|
|
nv_default_part = VariableMgr.AlignData(VariableMgr.PACK_DEFAULT_DATA(0, 0, VariableMgr.unpack_data(variable_storage_header_buffer+NvStoreDataBuffer)), 8)
|
2017-11-24 07:46:58 +01:00
|
|
|
|
2019-01-23 03:16:00 +01:00
|
|
|
data_delta_structure_buffer = bytearray()
|
2018-06-25 12:31:33 +02:00
|
|
|
for skuname, defaultstore in var_data:
|
|
|
|
if (skuname, defaultstore) == (DataType.TAB_DEFAULT, DataType.TAB_DEFAULT_STORES_DEFAULT):
|
2017-11-24 07:46:58 +01:00
|
|
|
continue
|
2018-06-25 12:31:33 +02:00
|
|
|
pcds_sku_data = var_data[(skuname, defaultstore)]
|
2017-11-24 07:46:58 +01:00
|
|
|
delta_data_set = []
|
|
|
|
for pcdindex in pcds_sku_data:
|
|
|
|
offset = var_data_offset[pcdindex]
|
2018-06-25 12:31:33 +02:00
|
|
|
delta_data, _ = pcds_sku_data[pcdindex]
|
2017-11-24 07:46:58 +01:00
|
|
|
delta_data = [(item[0] + offset, item[1]) for item in delta_data]
|
|
|
|
delta_data_set.extend(delta_data)
|
|
|
|
|
2018-06-25 12:31:33 +02:00
|
|
|
data_delta_structure_buffer += VariableMgr.AlignData(self.PACK_DELTA_DATA(skuname, defaultstore, delta_data_set), 8)
|
2017-11-24 07:46:58 +01:00
|
|
|
|
2017-12-20 10:16:28 +01:00
|
|
|
size = len(nv_default_part + data_delta_structure_buffer) + 16
|
2017-12-22 13:14:29 +01:00
|
|
|
maxsize = self.VpdRegionSize if self.VpdRegionSize else size
|
2018-06-25 12:31:33 +02:00
|
|
|
NV_Store_Default_Header = VariableMgr.PACK_NV_STORE_DEFAULT_HEADER(size, maxsize)
|
2017-12-22 13:14:29 +01:00
|
|
|
|
|
|
|
self.NVHeaderBuff = NV_Store_Default_Header
|
|
|
|
self.VarDefaultBuff =nv_default_part
|
|
|
|
self.VarDeltaBuff = data_delta_structure_buffer
|
2018-04-28 00:32:21 +02:00
|
|
|
return VariableMgr.format_data(NV_Store_Default_Header + nv_default_part + data_delta_structure_buffer)
|
2017-11-24 07:46:58 +01:00
|
|
|
|
|
|
|
|
2018-04-28 00:32:21 +02:00
|
|
|
@staticmethod
|
|
|
|
def format_data(data):
|
|
|
|
return [hex(item) for item in VariableMgr.unpack_data(data)]
|
2017-11-24 07:46:58 +01:00
|
|
|
|
2018-04-28 00:32:21 +02:00
|
|
|
@staticmethod
|
|
|
|
def unpack_data(data):
|
2017-11-24 07:46:58 +01:00
|
|
|
final_data = ()
|
2019-01-23 03:16:00 +01:00
|
|
|
for item in range(len(data)):
|
|
|
|
final_data += unpack("B", data[item:item + 1])
|
2017-11-24 07:46:58 +01:00
|
|
|
return final_data
|
|
|
|
|
2018-04-28 00:32:21 +02:00
|
|
|
@staticmethod
|
|
|
|
def calculate_delta(default, theother):
|
2017-11-24 07:46:58 +01:00
|
|
|
if len(default) - len(theother) != 0:
|
|
|
|
EdkLogger.error("build", FORMAT_INVALID, 'The variable data length is not the same for the same PCD.')
|
|
|
|
data_delta = []
|
|
|
|
for i in range(len(default)):
|
|
|
|
if default[i] != theother[i]:
|
2018-06-25 12:31:33 +02:00
|
|
|
data_delta.append((i, theother[i]))
|
2017-11-24 07:46:58 +01:00
|
|
|
return data_delta
|
|
|
|
|
|
|
|
def dump(self):
|
|
|
|
|
|
|
|
default_var_bin = self.new_process_varinfo()
|
2017-12-22 13:04:04 +01:00
|
|
|
if default_var_bin:
|
|
|
|
value_str = "{"
|
|
|
|
default_var_bin_strip = [ data.strip("""'""") for data in default_var_bin]
|
|
|
|
value_str += ",".join(default_var_bin_strip)
|
|
|
|
value_str += "}"
|
|
|
|
return value_str
|
|
|
|
return ""
|
2017-11-24 07:46:58 +01:00
|
|
|
|
2018-04-28 00:32:21 +02:00
|
|
|
@staticmethod
|
|
|
|
def PACK_VARIABLE_STORE_HEADER(size):
|
2017-11-24 07:46:58 +01:00
|
|
|
#Signature: gEfiVariableGuid
|
|
|
|
Guid = "{ 0xddcf3616, 0x3275, 0x4164, { 0x98, 0xb6, 0xfe, 0x85, 0x70, 0x7f, 0xfe, 0x7d }}"
|
|
|
|
Guid = GuidStructureStringToGuidString(Guid)
|
|
|
|
GuidBuffer = PackGUID(Guid.split('-'))
|
|
|
|
|
2018-06-25 12:31:33 +02:00
|
|
|
SizeBuffer = pack('=L', size)
|
|
|
|
FormatBuffer = pack('=B', 0x5A)
|
|
|
|
StateBuffer = pack('=B', 0xFE)
|
|
|
|
reservedBuffer = pack('=H', 0)
|
|
|
|
reservedBuffer += pack('=L', 0)
|
2017-11-24 07:46:58 +01:00
|
|
|
|
|
|
|
return GuidBuffer + SizeBuffer + FormatBuffer + StateBuffer + reservedBuffer
|
|
|
|
|
2018-04-28 00:32:21 +02:00
|
|
|
@staticmethod
|
2018-06-25 12:31:33 +02:00
|
|
|
def PACK_NV_STORE_DEFAULT_HEADER(size, maxsize):
|
|
|
|
Signature = pack('=B', ord('N'))
|
|
|
|
Signature += pack("=B", ord('S'))
|
|
|
|
Signature += pack("=B", ord('D'))
|
|
|
|
Signature += pack("=B", ord('B'))
|
2017-12-22 13:14:29 +01:00
|
|
|
|
2018-06-25 12:31:33 +02:00
|
|
|
SizeBuffer = pack("=L", size)
|
|
|
|
MaxSizeBuffer = pack("=Q", maxsize)
|
2017-12-22 13:14:29 +01:00
|
|
|
|
|
|
|
return Signature + SizeBuffer + MaxSizeBuffer
|
2017-11-24 07:46:58 +01:00
|
|
|
|
2018-04-28 00:32:21 +02:00
|
|
|
@staticmethod
|
2018-06-25 12:31:33 +02:00
|
|
|
def PACK_VARIABLE_HEADER(attribute, namesize, datasize, vendorguid):
|
2017-11-24 07:46:58 +01:00
|
|
|
|
2018-06-25 12:31:33 +02:00
|
|
|
Buffer = pack('=H', 0x55AA) # pack StartID
|
|
|
|
Buffer += pack('=B', 0x3F) # pack State
|
|
|
|
Buffer += pack('=B', 0) # pack reserved
|
2017-11-24 07:46:58 +01:00
|
|
|
|
2018-06-25 12:31:33 +02:00
|
|
|
Buffer += pack('=L', attribute)
|
|
|
|
Buffer += pack('=L', namesize)
|
|
|
|
Buffer += pack('=L', datasize)
|
2017-11-24 07:46:58 +01:00
|
|
|
|
|
|
|
Buffer += PackGUID(vendorguid)
|
|
|
|
|
|
|
|
return Buffer
|
|
|
|
|
2018-04-28 00:32:21 +02:00
|
|
|
@staticmethod
|
|
|
|
def PACK_VARIABLES_DATA(var_value,data_type, tail = None):
|
2019-01-23 03:16:00 +01:00
|
|
|
Buffer = bytearray()
|
2017-11-24 07:46:58 +01:00
|
|
|
data_len = 0
|
2018-04-11 18:14:05 +02:00
|
|
|
if data_type == DataType.TAB_VOID:
|
2017-11-24 07:46:58 +01:00
|
|
|
for value_char in var_value.strip("{").strip("}").split(","):
|
2018-06-25 12:31:33 +02:00
|
|
|
Buffer += pack("=B", int(value_char, 16))
|
2017-11-24 07:46:58 +01:00
|
|
|
data_len += len(var_value.split(","))
|
|
|
|
if tail:
|
|
|
|
for value_char in tail.split(","):
|
2018-06-25 12:31:33 +02:00
|
|
|
Buffer += pack("=B", int(value_char, 16))
|
2017-11-24 07:46:58 +01:00
|
|
|
data_len += len(tail.split(","))
|
|
|
|
elif data_type == "BOOLEAN":
|
2018-08-10 10:12:26 +02:00
|
|
|
Buffer += pack("=B", True) if var_value.upper() in ["TRUE","1"] else pack("=B", False)
|
2017-11-24 07:46:58 +01:00
|
|
|
data_len += 1
|
2018-04-11 18:14:05 +02:00
|
|
|
elif data_type == DataType.TAB_UINT8:
|
2018-06-25 12:31:33 +02:00
|
|
|
Buffer += pack("=B", GetIntegerValue(var_value))
|
2017-11-24 07:46:58 +01:00
|
|
|
data_len += 1
|
2018-04-11 18:14:05 +02:00
|
|
|
elif data_type == DataType.TAB_UINT16:
|
2018-06-25 12:31:33 +02:00
|
|
|
Buffer += pack("=H", GetIntegerValue(var_value))
|
2017-11-24 07:46:58 +01:00
|
|
|
data_len += 2
|
2018-04-11 18:14:05 +02:00
|
|
|
elif data_type == DataType.TAB_UINT32:
|
2018-06-25 12:31:33 +02:00
|
|
|
Buffer += pack("=L", GetIntegerValue(var_value))
|
2017-11-24 07:46:58 +01:00
|
|
|
data_len += 4
|
2018-04-11 18:14:05 +02:00
|
|
|
elif data_type == DataType.TAB_UINT64:
|
2018-06-25 12:31:33 +02:00
|
|
|
Buffer += pack("=Q", GetIntegerValue(var_value))
|
2017-11-24 07:46:58 +01:00
|
|
|
data_len += 8
|
|
|
|
|
|
|
|
return Buffer
|
|
|
|
|
2018-04-28 00:32:21 +02:00
|
|
|
@staticmethod
|
2018-06-25 12:31:33 +02:00
|
|
|
def PACK_DEFAULT_DATA(defaultstoragename, skuid, var_value):
|
2019-01-23 03:16:00 +01:00
|
|
|
Buffer = bytearray()
|
2018-06-25 12:31:33 +02:00
|
|
|
Buffer += pack("=L", 4+8+8)
|
|
|
|
Buffer += pack("=Q", int(skuid))
|
|
|
|
Buffer += pack("=Q", int(defaultstoragename))
|
2017-11-24 07:46:58 +01:00
|
|
|
|
|
|
|
for item in var_value:
|
2018-06-25 12:31:33 +02:00
|
|
|
Buffer += pack("=B", item)
|
2017-11-24 07:46:58 +01:00
|
|
|
|
2018-06-25 12:31:33 +02:00
|
|
|
Buffer = pack("=L", len(Buffer)+4) + Buffer
|
2017-11-24 07:46:58 +01:00
|
|
|
|
|
|
|
return Buffer
|
|
|
|
|
2018-06-25 12:31:33 +02:00
|
|
|
def GetSkuId(self, skuname):
|
2017-12-22 13:46:15 +01:00
|
|
|
if skuname not in self.SkuIdMap:
|
|
|
|
return None
|
|
|
|
return self.SkuIdMap.get(skuname)[0]
|
2018-04-28 00:32:21 +02:00
|
|
|
|
2018-06-25 12:31:33 +02:00
|
|
|
def GetDefaultStoreId(self, dname):
|
2017-12-22 13:46:15 +01:00
|
|
|
if dname not in self.DefaultStoreMap:
|
|
|
|
return None
|
|
|
|
return self.DefaultStoreMap.get(dname)[0]
|
2018-04-28 00:32:21 +02:00
|
|
|
|
2018-06-25 12:31:33 +02:00
|
|
|
def PACK_DELTA_DATA(self, skuname, defaultstoragename, delta_list):
|
2017-12-22 13:46:15 +01:00
|
|
|
skuid = self.GetSkuId(skuname)
|
|
|
|
defaultstorageid = self.GetDefaultStoreId(defaultstoragename)
|
2019-01-23 03:16:00 +01:00
|
|
|
Buffer = bytearray()
|
2018-06-25 12:31:33 +02:00
|
|
|
Buffer += pack("=L", 4+8+8)
|
|
|
|
Buffer += pack("=Q", int(skuid))
|
|
|
|
Buffer += pack("=Q", int(defaultstorageid))
|
|
|
|
for (delta_offset, value) in delta_list:
|
|
|
|
Buffer += pack("=L", delta_offset)
|
|
|
|
Buffer = Buffer[:-1] + pack("=B", value)
|
2017-11-24 07:46:58 +01:00
|
|
|
|
2018-06-25 12:31:33 +02:00
|
|
|
Buffer = pack("=L", len(Buffer) + 4) + Buffer
|
2017-11-24 07:46:58 +01:00
|
|
|
|
|
|
|
return Buffer
|
|
|
|
|
2018-04-28 00:32:21 +02:00
|
|
|
@staticmethod
|
|
|
|
def AlignData(data, align = 4):
|
2017-11-24 07:46:58 +01:00
|
|
|
mybuffer = data
|
2017-12-20 10:16:28 +01:00
|
|
|
if (len(data) % align) > 0:
|
|
|
|
for i in range(align - (len(data) % align)):
|
2018-06-25 12:31:33 +02:00
|
|
|
mybuffer += pack("=B", 0)
|
2017-11-24 07:46:58 +01:00
|
|
|
|
|
|
|
return mybuffer
|
|
|
|
|
2018-04-28 00:32:21 +02:00
|
|
|
@staticmethod
|
|
|
|
def PACK_VARIABLE_NAME(var_name):
|
2019-01-23 03:16:00 +01:00
|
|
|
Buffer = bytearray()
|
2017-11-24 07:46:58 +01:00
|
|
|
for name_char in var_name.strip("{").strip("}").split(","):
|
2018-06-25 12:31:33 +02:00
|
|
|
Buffer += pack("=B", int(name_char, 16))
|
2017-11-24 07:46:58 +01:00
|
|
|
|
2017-12-22 13:46:15 +01:00
|
|
|
return Buffer
|