From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.100; helo=mga07.intel.com; envelope-from=bob.c.feng@intel.com; receiver=edk2-devel@lists.01.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 49FC02117D271 for ; Wed, 24 Oct 2018 00:26:06 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Oct 2018 00:26:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,419,1534834800"; d="scan'208";a="80476937" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by fmsmga007.fm.intel.com with ESMTP; 24 Oct 2018 00:26:05 -0700 Received: from fmsmsx152.amr.corp.intel.com (10.18.125.5) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 24 Oct 2018 00:26:05 -0700 Received: from shsmsx104.ccr.corp.intel.com (10.239.4.70) by FMSMSX152.amr.corp.intel.com (10.18.125.5) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 24 Oct 2018 00:26:04 -0700 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.102]) by SHSMSX104.ccr.corp.intel.com ([169.254.5.117]) with mapi id 14.03.0415.000; Wed, 24 Oct 2018 15:26:02 +0800 From: "Feng, Bob C" To: "Zhao, ZhiqiangX" , "edk2-devel@lists.01.org" CC: "Gao, Liming" , "Zhu, Yonghong" Thread-Topic: [PATCH V2] BaseTool: Support different PCDs that refers to the same EFI variable. Thread-Index: AQHUZrHuNhVuRnfH4kqduHbG/tLzi6UuCDJw Date: Wed, 24 Oct 2018 07:26:01 +0000 Message-ID: <08650203BA1BD64D8AD9B6D5D74A85D15FFE5F2D@SHSMSX101.ccr.corp.intel.com> References: <20181018071211.49332-1-zhiqiangx.zhao@intel.com> In-Reply-To: <20181018071211.49332-1-zhiqiangx.zhao@intel.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiMzQ2YjUxZjktNzVjYi00Y2RhLWIzM2QtZWIzYWUwOGZkZWY1IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiYUZzZFh1UGNrSzZyXC9HbTNldU5YUlBheUh1Y3VZaXhBampqVUNyQW5vOTFkN0Zib0hZN0lHWjVCVFJrWHltajEifQ== x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.0.400.15 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH V2] BaseTool: Support different PCDs that refers to the same EFI variable. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Oct 2018 07:26:06 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Bob Feng -----Original Message----- From: Zhao, ZhiqiangX=20 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 sam= e 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 comb= ination, 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/P= ython/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 +=3D ",".join(default_var_bin_strip) value_str +=3D "}" return value_str - def Do_combine(self,sku_var_info_offset_list): - newvalue =3D {} - for item in sku_var_info_offset_list: - data_type =3D item.data_type - value_list =3D item.default_value.strip("{").strip("}").split(= ",") - if data_type in DataType.TAB_PCD_NUMERIC_TYPES: - data_flag =3D DataType.PACK_CODE_BY_SIZE[MAX_SIZE_TYPE[dat= a_type]] - data =3D value_list[0] - value_list =3D [] - for data_byte in pack(data_flag, int(data, 16) if data.upp= er().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().s= tartswith("0X") else int(item.var_offset)] =3D value_list - try: - newvaluestr =3D "{" + ",".join(VariableMgr.assemble_variable(n= ewvalue)) +"}" - except: - EdkLogger.error("build", AUTOGEN_ERROR, "Variable offset confl= ict in PCDs: %s \n" % (" and ".join(item.pcdname for item in sku_var_info_o= ffset_list))) - return newvaluestr - def Do_Merge(self,sku_var_info_offset_list): - StructrurePcds =3D sorted([item for item in sku_var_info_offset_li= st if item.StructurePcd], key =3D lambda x: x.PcdDscLine, reverse =3DTrue ) - Base =3D StructrurePcds[0] - BaseValue =3D Base.default_value.strip("{").strip("}").split(",") - Override =3D [item for item in sku_var_info_offset_list if not ite= m.StructurePcd and item.PcdDscLine > Base.PcdDscLine] - newvalue =3D {} - for item in Override: - data_type =3D item.data_type - value_list =3D item.default_value.strip("{").strip("}").split(= ",") - if data_type in DataType.TAB_PCD_NUMERIC_TYPES: - data_flag =3D DataType.PACK_CODE_BY_SIZE[MAX_SIZE_TYPE[dat= a_type]] - data =3D value_list[0] - value_list =3D [] - for data_byte in pack(data_flag, int(data, 16) if data.upp= er().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().s= tartswith("0X") else int(item.var_offset)] =3D (value_list,item.pcdname,ite= m.PcdDscLine) - for offset in newvalue: - value_list,itemPcdname,itemPcdDscLine =3D 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,i= temPcdDscLine,hex(len(BaseValue)))) - for i in xrange(len(value_list)): - BaseValue[offset + i] =3D value_list[i] - newvaluestr =3D "{" + ",".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 =3D collections.OrderedDict() for item in self.VarInfo: @@ -109,30 +65,37 @@ class VariableMgr(object): indexedvarinfo[(item.skuname, item.defaultstoragename, item.va= r_name, item.var_guid)].append(item) for key in indexedvarinfo: sku_var_info_offset_list =3D indexedvarinfo[key] - if len(sku_var_info_offset_list) =3D=3D 1: - continue - + sku_var_info_offset_list.sort(key=3Dlambda x:x.PcdDscLine) + FirstOffset =3D int(sku_var_info_offset_list[0].var_offset, 16= ) if sku_var_info_offset_list[0].var_offset.upper().startswith("0X") else i= nt(sku_var_info_offset_list[0].var_offset) + fisrtvalue_list =3D sku_var_info_offset_list[0].default_value.= strip("{").strip("}").split(",") + firstdata_type =3D sku_var_info_offset_list[0].data_type + if firstdata_type in DataType.TAB_PCD_NUMERIC_TYPES: + fisrtdata_flag =3D DataType.PACK_CODE_BY_SIZE[MAX_SIZE_TYP= E[firstdata_type]] + fisrtdata =3D fisrtvalue_list[0] + fisrtvalue_list =3D [] + for data_byte in pack(fisrtdata_flag, int(fisrtdata, 16) i= f fisrtdata.upper().startswith('0X') else int(fisrtdata)): + fisrtvalue_list.append(hex(unpack("B", data_byte)[0])) + newvalue_list =3D ["0x00"] * FirstOffset + fisrtvalue_list + + for var_item in sku_var_info_offset_list[1:]: + CurOffset =3D int(var_item.var_offset, 16) if var_item.var= _offset.upper().startswith("0X") else int(var_item.var_offset) + CurvalueList =3D var_item.default_value.strip("{").strip("= }").split(",") + Curdata_type =3D var_item.data_type + if Curdata_type in DataType.TAB_PCD_NUMERIC_TYPES: + data_flag =3D DataType.PACK_CODE_BY_SIZE[MAX_SIZE_TYPE= [Curdata_type]] + data =3D CurvalueList[0] + CurvalueList =3D [] + 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])= ) + if CurOffset > len(newvalue_list): + newvalue_list =3D newvalue_list + ["0x00"] * (CurOffse= t - len(newvalue_list)) + CurvalueList + else: + newvalue_list[CurOffset : CurOffset +=20 + len(CurvalueList)] =3D CurvalueList + + newvaluestr =3D "{" + ",".join(newvalue_list) +"}" n =3D sku_var_info_offset_list[0] - - if self.NeedMerge(sku_var_info_offset_list): - newvaluestr =3D self.Do_Merge(sku_var_info_offset_list) - else: - newvaluestr =3D self.Do_combine(sku_var_info_offset_list) - indexedvarinfo[key] =3D [var_info(n.pcdindex, n.pcdname, n.de= faultstoragename, n.skuname, n.var_name, n.var_guid, "0x00", n.var_attribut= e, newvaluestr, newvaluestr, DataType.TAB_VOID,n.PcdDscLine,n.StructurePcd)= ] - self.VarInfo =3D [item[0] for item in indexedvarinfo.values()] - - @staticmethod - def assemble_variable(valuedict): - ordered_valuedict_keys =3D sorted(valuedict.keys()) - var_value =3D [] - for current_valuedict_key in ordered_valuedict_keys: - if current_valuedict_key < len(var_value): - raise - for _ in xrange(current_valuedict_key - len(var_value)): - var_value.append('0x00') - var_value +=3D valuedict[current_valuedict_key] - return var_value + self.VarInfo =3D [item[0] for item in=20 + list(indexedvarinfo.values())] =20 def process_variable_data(self): =20 -- 2.14.1.windows.1