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.24; helo=mga09.intel.com; envelope-from=bob.c.feng@intel.com; receiver=edk2-devel@lists.01.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (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 EFDBE211799C8 for ; Tue, 16 Oct 2018 00:13:16 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Oct 2018 00:13:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,387,1534834800"; d="scan'208";a="271672041" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by fmsmga005.fm.intel.com with ESMTP; 16 Oct 2018 00:13:16 -0700 Received: from fmsmsx101.amr.corp.intel.com (10.18.124.199) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 16 Oct 2018 00:13:14 -0700 Received: from shsmsx103.ccr.corp.intel.com (10.239.4.69) by fmsmsx101.amr.corp.intel.com (10.18.124.199) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 16 Oct 2018 00:13:14 -0700 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.60]) by SHSMSX103.ccr.corp.intel.com ([169.254.4.245]) with mapi id 14.03.0319.002; Tue, 16 Oct 2018 15:13:12 +0800 From: "Feng, Bob C" To: "Zhao, ZhiqiangX" , "edk2-devel@lists.01.org" CC: "Gao, Liming" , "Zhu, Yonghong" , "Feng, Bob C" Thread-Topic: [PATCH] BaseTool: Support different PCDs that refers to the same EFI variable. Thread-Index: AQHUYHUOGyDM8VbU30CHBi96D0Q61aUhfL/g Date: Tue, 16 Oct 2018 07:13:11 +0000 Message-ID: <08650203BA1BD64D8AD9B6D5D74A85D15FFAF3F8@SHSMSX101.ccr.corp.intel.com> References: <20181010084113.23392-1-zhiqiangx.zhao@intel.com> In-Reply-To: <20181010084113.23392-1-zhiqiangx.zhao@intel.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiZGYyZWQ3MjMtYzYwNS00ZTg4LTg1OGEtM2JiYWQ4N2E2NDkwIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiSWE0d0pnbmllNXFtU0dBeVpVcGYxeHJzYmlWZW5cL2kxY0ZydDRSVDI3TTlvQUFYS1wvOEIzSDhCbVBva05vdVBaIn0= 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] 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: Tue, 16 Oct 2018 07:13:17 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Feng, Bob C -----Original Message----- From: Zhao, ZhiqiangX=20 Sent: Wednesday, October 10, 2018 4:41 PM To: edk2-devel@lists.01.org Cc: Zhao, ZhiqiangX ; Gao, Liming ; Zhu, Yonghong ; Feng, Bob C Subject: [PATCH] BaseTool: Support different PCDs that refers to the same E= FI variable. 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 | 96 ++++++++++-----------------= ---- 1 file changed, 30 insertions(+), 66 deletions(-) diff --git a/BaseTools/Source/Python/AutoGen/GenVar.py b/BaseTools/Source/P= ython/AutoGen/GenVar.py index 036f00e2bb..5ce7892d72 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,31 +65,39 @@ 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 [] + fisrtvalue_list.sort(cmp=3DNone, key=3DNone, reverse=3DFal= se) + 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()] =20 - @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 - def process_variable_data(self): =20 var_data =3D collections.defaultdict(collections.OrderedDict) -- 2.14.1.windows.1