From nobody Mon Dec 23 05:16:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1519386458684723.6710244807371; Fri, 23 Feb 2018 03:47:38 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 70C1B22436950; Fri, 23 Feb 2018 03:41:35 -0800 (PST) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (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 9A3722243693C for ; Fri, 23 Feb 2018 03:41:33 -0800 (PST) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Feb 2018 03:47:34 -0800 Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by fmsmga001.fm.intel.com with ESMTP; 23 Feb 2018 03:47:34 -0800 Received: from fmsmsx116.amr.corp.intel.com (10.18.116.20) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 23 Feb 2018 03:47:34 -0800 Received: from shsmsx103.ccr.corp.intel.com (10.239.4.69) by fmsmsx116.amr.corp.intel.com (10.18.116.20) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 23 Feb 2018 03:47:33 -0800 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.124]) by SHSMSX103.ccr.corp.intel.com ([169.254.4.116]) with mapi id 14.03.0319.002; Fri, 23 Feb 2018 19:47:31 +0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.20; helo=mga02.intel.com; envelope-from=yunhuax.feng@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,383,1515484800"; d="dat'59?scan'59,208,59";a="33017897" From: "Feng, YunhuaX" To: "edk2-devel@lists.01.org" Thread-Topic: [PATCH] BaseTools: Update ValueExpressionEx for flexible PCD Thread-Index: AdOsnBUsn+duQDfEQI+eCHmr4Gh8Mw== Date: Fri, 23 Feb 2018 11:47:30 +0000 Message-ID: <47C64442C08CCD4089DC43B6B5E46BC482B186@shsmsx102.ccr.corp.intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: <47C64442C08CCD4089DC43B6B5E46BC482B186@shsmsx102.ccr.corp.intel.com> x-originating-ip: [10.239.127.40] MIME-Version: 1.0 X-Content-Filtered-By: Mailman/MimeDel 2.1.23 Subject: [edk2] [PATCH] BaseTools: Update ValueExpressionEx for flexible PCD X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Gao, Liming" Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 1. Byte array number should less than 0xFF. 2. Add SplitPcdValueString for PCD split Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Yunhua Feng Reviewed-by: Yonghong Zhu =20 --- BaseTools/Source/Python/Common/Expression.py | 205 +++++++++++++++++------= ---- 1 file changed, 130 insertions(+), 75 deletions(-) diff --git a/BaseTools/Source/Python/Common/Expression.py b/BaseTools/Sourc= e/Python/Common/Expression.py index 28320d78a9..edb0a60de6 100644 --- a/BaseTools/Source/Python/Common/Expression.py +++ b/BaseTools/Source/Python/Common/Expression.py @@ -66,10 +66,48 @@ def SplitString(String): raise BadExpression(ERR_STRING_TOKEN % Item) if Item: RetList.append(Item) return RetList =20 +def SplitPcdValueString(String): + # There might be escaped comma in GUID() or DEVICE_PATH() or " " + # or ' ' or L' ' or L" " + Str =3D String + RetList =3D [] + InParenthesis =3D 0 + InSingleQuote =3D False + InDoubleQuote =3D False + Item =3D '' + for i, ch in enumerate(Str): + if ch =3D=3D '(': + InParenthesis +=3D 1 + if ch =3D=3D ')': + if InParenthesis: + InParenthesis -=3D 1 + else: + raise BadExpression(ERR_STRING_TOKEN % Item) + if ch =3D=3D '"' and not InSingleQuote: + if String[i-1] !=3D '\\': + InDoubleQuote =3D not InDoubleQuote + if ch =3D=3D "'" and not InDoubleQuote: + if String[i-1] !=3D '\\': + InSingleQuote =3D not InSingleQuote + if ch =3D=3D ',': + if InParenthesis or InSingleQuote or InDoubleQuote: + Item +=3D String[i] + continue + elif Item: + RetList.append(Item) + Item =3D '' + continue + Item +=3D String[i] + if InSingleQuote or InDoubleQuote or InParenthesis: + raise BadExpression(ERR_STRING_TOKEN % Item) + if Item: + RetList.append(Item) + return RetList + ## ReplaceExprMacro # def ReplaceExprMacro(String, Macros, ExceptionList =3D None): StrList =3D SplitString(String) for i, String in enumerate(StrList): @@ -731,28 +769,46 @@ class ValueExpressionEx(ValueExpression): PcdValue =3D Value.result except BadExpression, Value: if self.PcdType in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BO= OLEAN']: PcdValue =3D PcdValue.strip() if type(PcdValue) =3D=3D type('') and PcdValue.startswith(= '{') and PcdValue.endswith('}'): - PcdValue =3D PcdValue[1:-1].split(',') + PcdValue =3D SplitPcdValueString(PcdValue[1:-1]) if type(PcdValue) =3D=3D type([]): TmpValue =3D 0 Size =3D 0 + ValueType =3D '' for Item in PcdValue: + Item =3D Item.strip() if Item.startswith('UINT8'): ItemSize =3D 1 - if Item.startswith('UINT16'): + ValueType =3D 'UINT8' + elif Item.startswith('UINT16'): ItemSize =3D 2 + ValueType =3D 'UINT16' elif Item.startswith('UINT32'): ItemSize =3D 4 + ValueType =3D 'UINT32' elif Item.startswith('UINT64'): ItemSize =3D 8 + ValueType =3D 'UINT64' + elif Item.startswith('"') or Item.startswith("'") = or Item.startswith('L'): + ItemSize =3D 0 + ValueType =3D 'VOID*' else: ItemSize =3D 0 - Item =3D ValueExpressionEx(Item, self.PcdType, sel= f._Symb)(True) + ValueType =3D 'UINT8' + Item =3D ValueExpressionEx(Item, ValueType, self._= Symb)(True) =20 if ItemSize =3D=3D 0: + try: + tmpValue =3D int(Item, 16) if Item.upper()= .startswith('0X') else int(Item, 0) + if tmpValue > 255: + raise BadExpression("Byte array numbe= r %s should less than 0xFF." % Item) + except BadExpression, Value: + raise BadExpression(Value) + except ValueError: + pass ItemValue, ItemSize =3D ParseFieldValue(Item) else: ItemValue =3D ParseFieldValue(Item)[0] =20 if type(ItemValue) =3D=3D type(''): @@ -792,88 +848,85 @@ class ValueExpressionEx(ValueExpression): for I in range((TmpValue.bit_length() + 7) / 8): TmpList.append('0x%02x' % ((TmpValue >> I * 8)= & 0xff)) PcdValue =3D '{' + ', '.join(TmpList) + '}' except: if PcdValue.strip().startswith('{'): - PcdValue =3D PcdValue.strip()[1:-1].strip() - Size =3D 0 - ValueStr =3D '' - TokenSpaceGuidName =3D '' - if PcdValue.startswith('GUID') and PcdValue.endswi= th(')'): + PcdValueList =3D SplitPcdValueString(PcdValue.stri= p()[1:-1]) + LabelDict =3D {} + NewPcdValueList =3D [] + ReLabel =3D re.compile('LABEL\((\w+)\)') + ReOffset =3D re.compile('OFFSET_OF\((\w+)\)') + LabelOffset =3D 0 + for Index, Item in enumerate(PcdValueList): + # compute byte offset of every LABEL + Item =3D Item.strip() try: - TokenSpaceGuidName =3D re.search('GUID\((\= w+)\)', PcdValue).group(1) + LabelList =3D ReLabel.findall(Item) + for Label in LabelList: + if Label not in LabelDict.keys(): + LabelDict[Label] =3D str(LabelOffs= et) except: pass - if TokenSpaceGuidName and TokenSpaceGuidName i= n self._Symb: - PcdValue =3D 'GUID(' + self._Symb[TokenSpa= ceGuidName] + ')' - elif TokenSpaceGuidName: - raise BadExpression('%s not found in DEC f= ile' % TokenSpaceGuidName) - - ListItem, Size =3D ParseFieldValue(PcdValue) - elif PcdValue.startswith('DEVICE_PATH') and PcdVal= ue.endswith(')'): - ListItem, Size =3D ParseFieldValue(PcdValue) - else: - ListItem =3D PcdValue.split(',') - - if type(ListItem) =3D=3D type(0) or type(ListItem)= =3D=3D type(0L): - for Index in range(0, Size): - ValueStr +=3D '0x%02X' % (int(ListItem) & = 255) - ListItem >>=3D 8 - ValueStr +=3D ', ' - PcdValue =3D '{' + ValueStr[:-2] + '}' - elif type(ListItem) =3D=3D type(''): - if ListItem.startswith('{') and ListItem.endsw= ith('}'): - PcdValue =3D ListItem - else: - LabelDict =3D {} - ReLabel =3D re.compile('LABEL\((\w+)\)') - ReOffset =3D re.compile('OFFSET_OF\((\w+)\)') - LabelOffset =3D 0 - for Index, Item in enumerate(ListItem): - # compute byte offset of every LABEL - Item =3D Item.strip() + if Item.startswith('UINT8'): + LabelOffset =3D LabelOffset + 1 + elif Item.startswith('UINT16'): + LabelOffset =3D LabelOffset + 2 + elif Item.startswith('UINT32'): + LabelOffset =3D LabelOffset + 4 + elif Item.startswith('UINT64'): + LabelOffset =3D LabelOffset + 8 + else: try: - LabelList =3D ReLabel.findall(Item) - for Label in LabelList: - if Label not in LabelDict.keys(): - LabelDict[Label] =3D str(Label= Offset) - Item =3D ReLabel.sub('', Item) - except: - pass - if Item.startswith('UINT8'): - LabelOffset =3D LabelOffset + 1 - elif Item.startswith('UINT16'): - LabelOffset =3D LabelOffset + 2 - elif Item.startswith('UINT32'): - LabelOffset =3D LabelOffset + 4 - elif Item.startswith('UINT64'): - LabelOffset =3D LabelOffset + 8 - else: ItemValue, ItemSize =3D ParseFieldValu= e(Item) LabelOffset =3D LabelOffset + ItemSize - - for Index, Item in enumerate(ListItem): - # for LABEL parse - Item =3D Item.strip() - try: - LabelList =3D ReLabel.findall(Item) - for Label in LabelList: - if Label not in LabelDict.keys(): - LabelDict[Label] =3D str(Index) - Item =3D ReLabel.sub('', Item) except: - pass + LabelOffset =3D LabelOffset + 1 + + for Index, Item in enumerate(PcdValueList): + # for LABEL parse + Item =3D Item.strip() + try: + Item =3D ReLabel.sub('', Item) + except: + pass + try: + OffsetList =3D ReOffset.findall(Item) + except: + pass + for Offset in OffsetList: + if Offset in LabelDict.keys(): + Re =3D re.compile('OFFSET_OF\(%s\)' % = Offset) + Item =3D Re.sub(LabelDict[Offset], Ite= m) + else: + raise BadExpression('%s not defined' %= Offset) + NewPcdValueList.append(Item) + + AllPcdValueList =3D [] + for Item in NewPcdValueList: + Size =3D 0 + ValueStr =3D '' + TokenSpaceGuidName =3D '' + if Item.startswith('GUID') and Item.endswith('= )'): try: - OffsetList =3D ReOffset.findall(Item) + TokenSpaceGuidName =3D re.search('GUID= \((\w+)\)', Item).group(1) except: pass - for Offset in OffsetList: - if Offset in LabelDict.keys(): - Re =3D re.compile('OFFSET_OF\(%s\)= '% Offset) - Item =3D Re.sub(LabelDict[Offset],= Item) - else: - raise BadExpression('%s not define= d' % Offset) + if TokenSpaceGuidName and TokenSpaceGuidNa= me in self._Symb: + Item =3D 'GUID(' + self._Symb[TokenSpa= ceGuidName] + ')' + elif TokenSpaceGuidName: + raise BadExpression('%s not found in D= EC file' % TokenSpaceGuidName) + Item, Size =3D ParseFieldValue(Item) + for Index in range(0, Size): + ValueStr =3D '0x%02X' % (int(Item) & 2= 55) + Item >>=3D 8 + AllPcdValueList.append(ValueStr) + continue + elif Item.startswith('DEVICE_PATH') and Item.e= ndswith(')'): + Item, Size =3D ParseFieldValue(Item) + AllPcdValueList.append(Item[1:-1]) + continue + else: ValueType =3D "" if Item.startswith('UINT8'): ItemSize =3D 1 ValueType =3D "UINT8" elif Item.startswith('UINT16'): @@ -892,20 +945,22 @@ class ValueExpressionEx(ValueExpression): else: TmpValue =3D ValueExpressionEx(Item, s= elf.PcdType, self._Symb)(True) Item =3D '0x%x' % TmpValue if type(TmpValu= e) !=3D type('') else TmpValue if ItemSize =3D=3D 0: ItemValue, ItemSize =3D ParseFieldValu= e(Item) + if not (Item.startswith('"') or Item.s= tartswith('L') or Item.startswith('{')) and ItemSize > 1: + raise BadExpression("Byte array n= umber %s should less than 0xFF." % Item) else: ItemValue =3D ParseFieldValue(Item)[0] for I in range(0, ItemSize): - ValueStr +=3D '0x%02X' % (int(ItemValu= e) & 255) + ValueStr =3D '0x%02X' % (int(ItemValue= ) & 255) ItemValue >>=3D 8 - ValueStr +=3D ', ' + AllPcdValueList.append(ValueStr) Size +=3D ItemSize =20 - if Size > 0: - PcdValue =3D '{' + ValueStr[:-2] + '}' + if Size > 0: + PcdValue =3D '{' + ','.join(AllPcdValueList) += '}' else: raise BadExpression("Type: %s, Value: %s, %s"%(se= lf.PcdType, PcdValue, Value)) =20 if PcdValue =3D=3D 'True': PcdValue =3D '1' --=20 2.12.2.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel