Re: [edk2] [PATCH V2] BaseTool: Support different PCDs that refers to the same EFI variable.
Reviewed-by: Bob Feng -Original Message- From: Zhao, ZhiqiangX Sent: Thursday, October 18, 2018 3:12 PM To: edk2-devel@lists.01.org Cc: Zhao, ZhiqiangX ; Gao, Liming ; Zhu, Yonghong ; Feng, Bob C Subject: [PATCH V2] BaseTool: Support different PCDs that refers to the same EFI variable. V2: Make the code of patch both compatible for Python2 and Python3. V1: If different PCDs refer to the same EFI variable, then do EFI variable combination, according to the VariableOffset of different PCDS. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: ZhiqiangX Zhao Cc: Liming Gao Cc: Yonghong Zhu Cc: Bob Feng --- BaseTools/Source/Python/AutoGen/GenVar.py | 97 ++- 1 file changed, 30 insertions(+), 67 deletions(-) diff --git a/BaseTools/Source/Python/AutoGen/GenVar.py b/BaseTools/Source/Python/AutoGen/GenVar.py index 036f00e2bb..98f88e2497 100644 --- a/BaseTools/Source/Python/AutoGen/GenVar.py +++ b/BaseTools/Source/Python/AutoGen/GenVar.py @@ -56,51 +56,7 @@ class VariableMgr(object): value_str += ",".join(default_var_bin_strip) value_str += "}" return value_str -def Do_combine(self,sku_var_info_offset_list): -newvalue = {} -for item in sku_var_info_offset_list: -data_type = item.data_type -value_list = item.default_value.strip("{").strip("}").split(",") -if data_type in DataType.TAB_PCD_NUMERIC_TYPES: -data_flag = DataType.PACK_CODE_BY_SIZE[MAX_SIZE_TYPE[data_type]] -data = value_list[0] -value_list = [] -for data_byte in pack(data_flag, int(data, 16) if data.upper().startswith('0X') else int(data)): -value_list.append(hex(unpack("B", data_byte)[0])) -newvalue[int(item.var_offset, 16) if item.var_offset.upper().startswith("0X") else int(item.var_offset)] = value_list -try: -newvaluestr = "{" + ",".join(VariableMgr.assemble_variable(newvalue)) +"}" -except: -EdkLogger.error("build", AUTOGEN_ERROR, "Variable offset conflict in PCDs: %s \n" % (" and ".join(item.pcdname for item in sku_var_info_offset_list))) -return newvaluestr -def Do_Merge(self,sku_var_info_offset_list): -StructrurePcds = sorted([item for item in sku_var_info_offset_list if item.StructurePcd], key = lambda x: x.PcdDscLine, reverse =True ) -Base = StructrurePcds[0] -BaseValue = Base.default_value.strip("{").strip("}").split(",") -Override = [item for item in sku_var_info_offset_list if not item.StructurePcd and item.PcdDscLine > Base.PcdDscLine] -newvalue = {} -for item in Override: -data_type = item.data_type -value_list = item.default_value.strip("{").strip("}").split(",") -if data_type in DataType.TAB_PCD_NUMERIC_TYPES: -data_flag = DataType.PACK_CODE_BY_SIZE[MAX_SIZE_TYPE[data_type]] -data = value_list[0] -value_list = [] -for data_byte in pack(data_flag, int(data, 16) if data.upper().startswith('0X') else int(data)): -value_list.append(hex(unpack("B", data_byte)[0])) -newvalue[int(item.var_offset, 16) if item.var_offset.upper().startswith("0X") else int(item.var_offset)] = (value_list,item.pcdname,item.PcdDscLine) -for offset in newvalue: -value_list,itemPcdname,itemPcdDscLine = newvalue[offset] -if offset > len(BaseValue) or (offset + len(value_list) > len(BaseValue)): -EdkLogger.error("build", AUTOGEN_ERROR, "The EFI Variable referred by PCD %s in line %s exceeds variable size: %s\n" % (itemPcdname,itemPcdDscLine,hex(len(BaseValue -for i in xrange(len(value_list)): -BaseValue[offset + i] = value_list[i] -newvaluestr = "{" + ",".join(BaseValue) +"}" -return newvaluestr -def NeedMerge(self,sku_var_info_offset_list): -if [item for item in sku_var_info_offset_list if item.StructurePcd]: -return True -return False + def combine_variable(self): indexedvarinfo = collections.OrderedDict() for item in self.VarInfo: @@ -109,30 +65,37 @@ class VariableMgr(object): indexedvarinfo[(item.skuname, item.defaultstoragename, item.var_name, item.var_guid)].append(item) for key in indexedvarinfo: sku_var_info_offset_list = indexedvarinfo[key] -if len(sku_var_info_offset_list) == 1: -continue - +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(",") +
Re: [edk2] [PATCH V2] BaseTool: Support different PCDs that refers to the same EFI variable.
No effect on functionality, but sometimes first is spelled fisrt in below patch. > -Original Message- > From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of > Feng, Bob C > Sent: Sunday, October 21, 2018 3:48 AM > To: Zhao, ZhiqiangX ; edk2-devel@lists.01.org > Cc: Gao, Liming > Subject: Re: [edk2] [PATCH V2] BaseTool: Support different PCDs that refers > to the same EFI variable. > > Reviewed-by: Bob Feng > > -Original Message- > From: Zhao, ZhiqiangX > Sent: Thursday, October 18, 2018 3:12 PM > To: edk2-devel@lists.01.org > Cc: Zhao, ZhiqiangX ; Gao, Liming > ; Zhu, Yonghong ; Feng, > Bob C > Subject: [PATCH V2] BaseTool: Support different PCDs that refers to the > same EFI variable. > > V2: > Make the code of patch both compatible for Python2 and Python3. > > V1: > If different PCDs refer to the same EFI variable, then do EFI variable > combination, according to the VariableOffset of different PCDS. > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: ZhiqiangX Zhao > Cc: Liming Gao > Cc: Yonghong Zhu > Cc: Bob Feng > --- > BaseTools/Source/Python/AutoGen/GenVar.py | 97 ++ > - > 1 file changed, 30 insertions(+), 67 deletions(-) > > diff --git a/BaseTools/Source/Python/AutoGen/GenVar.py > b/BaseTools/Source/Python/AutoGen/GenVar.py > index 036f00e2bb..98f88e2497 100644 > --- a/BaseTools/Source/Python/AutoGen/GenVar.py > +++ b/BaseTools/Source/Python/AutoGen/GenVar.py > @@ -56,51 +56,7 @@ class VariableMgr(object): > value_str += ",".join(default_var_bin_strip) > value_str += "}" > return value_str > -def Do_combine(self,sku_var_info_offset_list): > -newvalue = {} > -for item in sku_var_info_offset_list: > -data_type = item.data_type > -value_list = item.default_value.strip("{").strip("}").split(",") > -if data_type in DataType.TAB_PCD_NUMERIC_TYPES: > -data_flag = > DataType.PACK_CODE_BY_SIZE[MAX_SIZE_TYPE[data_type]] > -data = value_list[0] > -value_list = [] > -for data_byte in pack(data_flag, int(data, 16) if > data.upper().startswith('0X') else int(data)): > -value_list.append(hex(unpack("B", data_byte)[0])) > -newvalue[int(item.var_offset, 16) if > item.var_offset.upper().startswith("0X") else int(item.var_offset)] = > value_list > -try: > -newvaluestr = "{" + > ",".join(VariableMgr.assemble_variable(newvalue)) +"}" > -except: > -EdkLogger.error("build", AUTOGEN_ERROR, "Variable offset > conflict in > PCDs: %s \n" % (" and ".join(item.pcdname for item in > sku_var_info_offset_list))) > -return newvaluestr > -def Do_Merge(self,sku_var_info_offset_list): > -StructrurePcds = sorted([item for item in sku_var_info_offset_list if > item.StructurePcd], key = lambda x: x.PcdDscLine, reverse =True ) > -Base = StructrurePcds[0] > -BaseValue = Base.default_value.strip("{").strip("}").split(",") > -Override = [item for item in sku_var_info_offset_list if not > item.StructurePcd and item.PcdDscLine > Base.PcdDscLine] > -newvalue = {} > -for item in Override: > -data_type = item.data_type > -value_list = item.default_value.strip("{").strip("}").split(",") > -if data_type in DataType.TAB_PCD_NUMERIC_TYPES: > -data_flag = > DataType.PACK_CODE_BY_SIZE[MAX_SIZE_TYPE[data_type]] > -data = value_list[0] > -value_list = [] > -for data_byte in pack(data_flag, int(data, 16) if > data.upper().startswith('0X') else int(data)): > -value_list.append(hex(unpack("B", data_byte)[0])) > -newvalue[int(item.var_offset, 16) if > item.var_offset.upper().startswith("0X") else int(item.var_offset)] = > (value_list,item.pcdname,item.PcdDscLine) > -for offset in newvalue: > -value_list,itemPcdname,itemPcdDscLine = newvalue[offset] > -if offset > len(BaseValue) or (offset + len(value_list) > > len(BaseValue)): > -EdkLogger.error("build", AUTOGEN_ERROR, "The EFI Variable > referred by PCD %s in line %s exceeds variable size: %s\n" % > (itemPcdname,itemPcdDscLine,hex(len(BaseValue > -for i in xrange(len(
Re: [edk2] [PATCH V2] BaseTool: Support different PCDs that refers to the same EFI variable.
Reviewed-by: Bob Feng -Original Message- From: Zhao, ZhiqiangX Sent: Thursday, October 18, 2018 3:12 PM To: edk2-devel@lists.01.org Cc: Zhao, ZhiqiangX ; Gao, Liming ; Zhu, Yonghong ; Feng, Bob C Subject: [PATCH V2] BaseTool: Support different PCDs that refers to the same EFI variable. V2: Make the code of patch both compatible for Python2 and Python3. V1: If different PCDs refer to the same EFI variable, then do EFI variable combination, according to the VariableOffset of different PCDS. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: ZhiqiangX Zhao Cc: Liming Gao Cc: Yonghong Zhu Cc: Bob Feng --- BaseTools/Source/Python/AutoGen/GenVar.py | 97 ++- 1 file changed, 30 insertions(+), 67 deletions(-) diff --git a/BaseTools/Source/Python/AutoGen/GenVar.py b/BaseTools/Source/Python/AutoGen/GenVar.py index 036f00e2bb..98f88e2497 100644 --- a/BaseTools/Source/Python/AutoGen/GenVar.py +++ b/BaseTools/Source/Python/AutoGen/GenVar.py @@ -56,51 +56,7 @@ class VariableMgr(object): value_str += ",".join(default_var_bin_strip) value_str += "}" return value_str -def Do_combine(self,sku_var_info_offset_list): -newvalue = {} -for item in sku_var_info_offset_list: -data_type = item.data_type -value_list = item.default_value.strip("{").strip("}").split(",") -if data_type in DataType.TAB_PCD_NUMERIC_TYPES: -data_flag = DataType.PACK_CODE_BY_SIZE[MAX_SIZE_TYPE[data_type]] -data = value_list[0] -value_list = [] -for data_byte in pack(data_flag, int(data, 16) if data.upper().startswith('0X') else int(data)): -value_list.append(hex(unpack("B", data_byte)[0])) -newvalue[int(item.var_offset, 16) if item.var_offset.upper().startswith("0X") else int(item.var_offset)] = value_list -try: -newvaluestr = "{" + ",".join(VariableMgr.assemble_variable(newvalue)) +"}" -except: -EdkLogger.error("build", AUTOGEN_ERROR, "Variable offset conflict in PCDs: %s \n" % (" and ".join(item.pcdname for item in sku_var_info_offset_list))) -return newvaluestr -def Do_Merge(self,sku_var_info_offset_list): -StructrurePcds = sorted([item for item in sku_var_info_offset_list if item.StructurePcd], key = lambda x: x.PcdDscLine, reverse =True ) -Base = StructrurePcds[0] -BaseValue = Base.default_value.strip("{").strip("}").split(",") -Override = [item for item in sku_var_info_offset_list if not item.StructurePcd and item.PcdDscLine > Base.PcdDscLine] -newvalue = {} -for item in Override: -data_type = item.data_type -value_list = item.default_value.strip("{").strip("}").split(",") -if data_type in DataType.TAB_PCD_NUMERIC_TYPES: -data_flag = DataType.PACK_CODE_BY_SIZE[MAX_SIZE_TYPE[data_type]] -data = value_list[0] -value_list = [] -for data_byte in pack(data_flag, int(data, 16) if data.upper().startswith('0X') else int(data)): -value_list.append(hex(unpack("B", data_byte)[0])) -newvalue[int(item.var_offset, 16) if item.var_offset.upper().startswith("0X") else int(item.var_offset)] = (value_list,item.pcdname,item.PcdDscLine) -for offset in newvalue: -value_list,itemPcdname,itemPcdDscLine = newvalue[offset] -if offset > len(BaseValue) or (offset + len(value_list) > len(BaseValue)): -EdkLogger.error("build", AUTOGEN_ERROR, "The EFI Variable referred by PCD %s in line %s exceeds variable size: %s\n" % (itemPcdname,itemPcdDscLine,hex(len(BaseValue -for i in xrange(len(value_list)): -BaseValue[offset + i] = value_list[i] -newvaluestr = "{" + ",".join(BaseValue) +"}" -return newvaluestr -def NeedMerge(self,sku_var_info_offset_list): -if [item for item in sku_var_info_offset_list if item.StructurePcd]: -return True -return False + def combine_variable(self): indexedvarinfo = collections.OrderedDict() for item in self.VarInfo: @@ -109,30 +65,37 @@ class VariableMgr(object): indexedvarinfo[(item.skuname, item.defaultstoragename, item.var_name, item.var_guid)].append(item) for key in indexedvarinfo: sku_var_info_offset_list = indexedvarinfo[key] -if len(sku_var_info_offset_list) == 1: -continue - +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(",") +
[edk2] [PATCH V2] BaseTool: Support different PCDs that refers to the same EFI variable.
V2: Make the code of patch both compatible for Python2 and Python3. V1: If different PCDs refer to the same EFI variable, then do EFI variable combination, according to the VariableOffset of different PCDS. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: ZhiqiangX Zhao Cc: Liming Gao Cc: Yonghong Zhu Cc: Bob Feng --- BaseTools/Source/Python/AutoGen/GenVar.py | 97 ++- 1 file changed, 30 insertions(+), 67 deletions(-) diff --git a/BaseTools/Source/Python/AutoGen/GenVar.py b/BaseTools/Source/Python/AutoGen/GenVar.py index 036f00e2bb..98f88e2497 100644 --- a/BaseTools/Source/Python/AutoGen/GenVar.py +++ b/BaseTools/Source/Python/AutoGen/GenVar.py @@ -56,51 +56,7 @@ class VariableMgr(object): value_str += ",".join(default_var_bin_strip) value_str += "}" return value_str -def Do_combine(self,sku_var_info_offset_list): -newvalue = {} -for item in sku_var_info_offset_list: -data_type = item.data_type -value_list = item.default_value.strip("{").strip("}").split(",") -if data_type in DataType.TAB_PCD_NUMERIC_TYPES: -data_flag = DataType.PACK_CODE_BY_SIZE[MAX_SIZE_TYPE[data_type]] -data = value_list[0] -value_list = [] -for data_byte in pack(data_flag, int(data, 16) if data.upper().startswith('0X') else int(data)): -value_list.append(hex(unpack("B", data_byte)[0])) -newvalue[int(item.var_offset, 16) if item.var_offset.upper().startswith("0X") else int(item.var_offset)] = value_list -try: -newvaluestr = "{" + ",".join(VariableMgr.assemble_variable(newvalue)) +"}" -except: -EdkLogger.error("build", AUTOGEN_ERROR, "Variable offset conflict in PCDs: %s \n" % (" and ".join(item.pcdname for item in sku_var_info_offset_list))) -return newvaluestr -def Do_Merge(self,sku_var_info_offset_list): -StructrurePcds = sorted([item for item in sku_var_info_offset_list if item.StructurePcd], key = lambda x: x.PcdDscLine, reverse =True ) -Base = StructrurePcds[0] -BaseValue = Base.default_value.strip("{").strip("}").split(",") -Override = [item for item in sku_var_info_offset_list if not item.StructurePcd and item.PcdDscLine > Base.PcdDscLine] -newvalue = {} -for item in Override: -data_type = item.data_type -value_list = item.default_value.strip("{").strip("}").split(",") -if data_type in DataType.TAB_PCD_NUMERIC_TYPES: -data_flag = DataType.PACK_CODE_BY_SIZE[MAX_SIZE_TYPE[data_type]] -data = value_list[0] -value_list = [] -for data_byte in pack(data_flag, int(data, 16) if data.upper().startswith('0X') else int(data)): -value_list.append(hex(unpack("B", data_byte)[0])) -newvalue[int(item.var_offset, 16) if item.var_offset.upper().startswith("0X") else int(item.var_offset)] = (value_list,item.pcdname,item.PcdDscLine) -for offset in newvalue: -value_list,itemPcdname,itemPcdDscLine = newvalue[offset] -if offset > len(BaseValue) or (offset + len(value_list) > len(BaseValue)): -EdkLogger.error("build", AUTOGEN_ERROR, "The EFI Variable referred by PCD %s in line %s exceeds variable size: %s\n" % (itemPcdname,itemPcdDscLine,hex(len(BaseValue -for i in xrange(len(value_list)): -BaseValue[offset + i] = value_list[i] -newvaluestr = "{" + ",".join(BaseValue) +"}" -return newvaluestr -def NeedMerge(self,sku_var_info_offset_list): -if [item for item in sku_var_info_offset_list if item.StructurePcd]: -return True -return False + def combine_variable(self): indexedvarinfo = collections.OrderedDict() for item in self.VarInfo: @@ -109,30 +65,37 @@ class VariableMgr(object): indexedvarinfo[(item.skuname, item.defaultstoragename, item.var_name, item.var_guid)].append(item) for key in indexedvarinfo: sku_var_info_offset_list = indexedvarinfo[key] -if len(sku_var_info_offset_list) == 1: -continue - +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 =