From nobody Mon Apr 29 04:13:21 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 1514352231099301.1155124755112; Tue, 26 Dec 2017 21:23:51 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 7263522280C32; Tue, 26 Dec 2017 21:18:54 -0800 (PST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (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 565EB22280C2F for ; Tue, 26 Dec 2017 21:18:51 -0800 (PST) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Dec 2017 21:23:46 -0800 Received: from shwdeopenpsi168.ccr.corp.intel.com ([10.239.158.129]) by fmsmga001.fm.intel.com with ESMTP; 26 Dec 2017 21:23:45 -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=192.55.52.115; helo=mga14.intel.com; envelope-from=yonghong.zhu@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,462,1508828400"; d="scan'208";a="16804298" From: Yonghong Zhu To: edk2-devel@lists.01.org Date: Wed, 27 Dec 2017 13:23:42 +0800 Message-Id: <1514352222-13024-1-git-send-email-yonghong.zhu@intel.com> X-Mailer: git-send-email 2.6.1.windows.1 Subject: [edk2] [Patch] BaseTools: Support PCD flexible values format 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: Yunhua Feng MIME-Version: 1.0 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" https://bugzilla.tianocore.org/show_bug.cgi?id=3D541 Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Yunhua Feng Signed-off-by: Yonghong Zhu Reviewed-by: Liming Gao --- BaseTools/Source/Python/AutoGen/AutoGen.py | 39 ++++ BaseTools/Source/Python/AutoGen/GenC.py | 2 + BaseTools/Source/Python/Common/Expression.py | 246 +++++++++++++++++= +++- BaseTools/Source/Python/Common/Misc.py | 203 +++++++++-------- BaseTools/Source/Python/Workspace/DscBuildData.py | 16 +- BaseTools/Source/Python/Workspace/InfBuildData.py | 7 + .../Source/Python/Workspace/MetaFileParser.py | 17 +- .../Source/Python/Workspace/WorkspaceCommon.py | 8 +- BaseTools/Source/Python/build/BuildReport.py | 6 + 9 files changed, 430 insertions(+), 114 deletions(-) diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py b/BaseTools/Source/= Python/AutoGen/AutoGen.py index cacd009..8be5bfc 100644 --- a/BaseTools/Source/Python/AutoGen/AutoGen.py +++ b/BaseTools/Source/Python/AutoGen/AutoGen.py @@ -269,10 +269,11 @@ class WorkspaceAutoGen(AutoGen): self.AutoGenObjectList =3D [] self._BuildDir =3D None self._FvDir =3D None self._MakeFileDir =3D None self._BuildCommand =3D None + self._GuidDict =3D {} =20 # there's many relative directory operations, so ... os.chdir(self.WorkspaceDir) =20 # @@ -417,24 +418,42 @@ class WorkspaceAutoGen(AutoGen): TokenSpaceGuidCNameList =3D [] FoundFlag =3D False PcdDatumType =3D '' NewValue =3D '' for package in PGen.PackageList: + Guids =3D package.Guids + self._GuidDict.update(Guids) + for package in PGen.PackageList: for key in package.Pcds: PcdItem =3D package.Pcds[key] if HasTokenSpace: if (PcdItem.TokenCName, PcdItem.TokenSpace= GuidCName) =3D=3D (TokenCName, TokenSpaceGuidCName): PcdDatumType =3D PcdItem.DatumType + if pcdvalue.startswith('H'): + try: + pcdvalue =3D ValueExpressionEx= (pcdvalue[1:], PcdDatumType, self._GuidDict)(True) + except BadExpression, Value: + if Value.result > 1: + EdkLogger.error('Parser', = FORMAT_INVALID, 'PCD [%s.%s] Value "%s", %s' % + (TokenSpac= eGuidCName, TokenCName, pcdvalue, Value)) + pcdvalue =3D 'H' + pcdvalue NewValue =3D BuildOptionPcdValueFormat= (TokenSpaceGuidCName, TokenCName, PcdDatumType, pcdvalue) FoundFlag =3D True else: if PcdItem.TokenCName =3D=3D TokenCName: if not PcdItem.TokenSpaceGuidCName in = TokenSpaceGuidCNameList: if len (TokenSpaceGuidCNameList) <= 1: TokenSpaceGuidCNameList.append= (PcdItem.TokenSpaceGuidCName) PcdDatumType =3D PcdItem.Datum= Type TokenSpaceGuidCName =3D PcdIte= m.TokenSpaceGuidCName + if pcdvalue.startswith('H'): + try: + pcdvalue =3D ValueExpr= essionEx(pcdvalue[1:], PcdDatumType, self._GuidDict)(True) + except BadExpression, Valu= e: + EdkLogger.error('Parse= r', FORMAT_INVALID, 'PCD [%s.%s] Value "%s", %s' % + (Token= SpaceGuidCName, TokenCName, pcdvalue, Value)) + pcdvalue =3D 'H' + pcdvalue NewValue =3D BuildOptionPcdVal= ueFormat(TokenSpaceGuidCName, TokenCName, PcdDatumType, pcdvalue) FoundFlag =3D True else: EdkLogger.error( 'build', @@ -2444,10 +2463,30 @@ class PlatformAutoGen(AutoGen): ToPcd.MaxDatumSize =3D FromPcd.MaxDatumSize if FromPcd.DatumType not in [None, '']: ToPcd.DatumType =3D FromPcd.DatumType if FromPcd.SkuInfoList not in [None, '', []]: ToPcd.SkuInfoList =3D FromPcd.SkuInfoList + # Add Flexible PCD format parse + PcdValue =3D ToPcd.DefaultValue + if PcdValue: + try: + ToPcd.DefaultValue =3D ValueExpression(PcdValue)(True) + except WrnExpression, Value: + ToPcd.DefaultValue =3D Value.result + except BadExpression, Value: + EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s]= Value "%s", %s' %(ToPcd.TokenSpaceGuidCName, ToPcd.TokenCName, ToPcd.Defau= ltValue, Value), + File=3Dself.MetaFile) + if ToPcd.DefaultValue: + _GuidDict =3D {} + for Pkg in self.PackageList: + Guids =3D Pkg.Guids + _GuidDict.update(Guids) + try: + ToPcd.DefaultValue =3D ValueExpressionEx(ToPcd.Default= Value, ToPcd.DatumType, _GuidDict)(True) + except BadExpression, Value: + EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s]= Value "%s", %s' %(ToPcd.TokenSpaceGuidCName, ToPcd.TokenCName, ToPcd.Defau= ltValue, Value), + File=3Dself.MetaFile) =20 # check the validation of datum IsValid, Cause =3D CheckPcdDatum(ToPcd.DatumType, ToPcd.Defaul= tValue) if not IsValid: EdkLogger.error('build', FORMAT_INVALID, Cause, File=3Dsel= f.MetaFile, diff --git a/BaseTools/Source/Python/AutoGen/GenC.py b/BaseTools/Source/Pyt= hon/AutoGen/GenC.py index 6b95cd4..3e98506 100644 --- a/BaseTools/Source/Python/AutoGen/GenC.py +++ b/BaseTools/Source/Python/AutoGen/GenC.py @@ -1031,10 +1031,12 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, P= cd): elif BoolValue =3D=3D 'FALSE' or BoolValue =3D=3D '0': Value =3D '0U' =20 if Pcd.DatumType in ['UINT64', 'UINT32', 'UINT16', 'UINT8']: try: + if Value.upper().endswith('L'): + Value =3D Value[:-1] if Value.upper().startswith('0X'): ValueNumber =3D int (Value, 16) else: ValueNumber =3D int (Value) except: diff --git a/BaseTools/Source/Python/Common/Expression.py b/BaseTools/Sourc= e/Python/Common/Expression.py index ba83e02..953a412 100644 --- a/BaseTools/Source/Python/Common/Expression.py +++ b/BaseTools/Source/Python/Common/Expression.py @@ -13,11 +13,13 @@ ## Import Modules # from Common.GlobalData import * from CommonDataClass.Exceptions import BadExpression from CommonDataClass.Exceptions import WrnExpression -from Misc import GuidStringToGuidStructureString +from Misc import GuidStringToGuidStructureString, ParseFieldValue +import Common.EdkLogger as EdkLogger +import copy =20 ERR_STRING_EXPR =3D 'This operator cannot be used in string expres= sion: [%s].' ERR_SNYTAX =3D 'Syntax error, the rest of expression cannot b= e evaluated: [%s].' ERR_MATCH =3D 'No matching right parenthesis.' ERR_STRING_TOKEN =3D 'Bad string token: [%s].' @@ -112,10 +114,19 @@ def ReplaceExprMacro(String, Macros, ExceptionList = =3D None): String =3D RetStr MacroStartPos =3D String.find('$(') StrList[i] =3D RetStr return ''.join(StrList) =20 +# transfer int to string for in/not in expression +def IntToStr(Value): + StrList =3D [] + while Value > 0: + StrList.append(chr(Value & 0xff)) + Value =3D Value >> 8 + Value =3D '"' + ''.join(StrList) + '"' + return Value + SupportedInMacroList =3D ['TARGET', 'TOOL_CHAIN_TAG', 'ARCH', 'FAMILY'] =20 class ValueExpression(object): # Logical operator mapping LogicalOperators =3D { @@ -144,14 +155,28 @@ class ValueExpression(object): =20 @staticmethod def Eval(Operator, Oprand1, Oprand2 =3D None): WrnExp =3D None =20 - if Operator not in ["=3D=3D", "!=3D", ">=3D", "<=3D", ">", "<", "i= n", "not in"] and \ - (type(Oprand1) =3D=3D type('') or type(Oprand2) =3D=3D type(''= )): - raise BadExpression(ERR_STRING_EXPR % Operator) - + if Operator not in ["in", "not in"] and (type(Oprand1) =3D=3D type= ('') or type(Oprand2) =3D=3D type('')): + if type(Oprand1) =3D=3D type(''): + if Oprand1[0] in ['"', "'"] or Oprand1.startswith('L"') or= Oprand1.startswith("L'")or Oprand1.startswith('UINT'): + Oprand1, Size =3D ParseFieldValue(Oprand1) + else: + Oprand1,Size =3D ParseFieldValue('"' + Oprand1 + '"') + if type(Oprand2) =3D=3D type(''): + if Oprand2[0] in ['"', "'", 'L'] or Oprand2.startswith('UI= NT'): + Oprand2, Size =3D ParseFieldValue(Oprand2) + else: + Oprand2, Size =3D ParseFieldValue('"' + Oprand2 + '"') + if type(Oprand1) =3D=3D type('') or type(Oprand2) =3D=3D type(= ''): + raise BadExpression(ERR_STRING_EXPR % Operator) + if Operator in ['in', 'not in']: + if type(Oprand1) !=3D type(''): + Oprand1 =3D IntToStr(Oprand1) + if type(Oprand2) !=3D type(''): + Oprand2 =3D IntToStr(Oprand2) TypeDict =3D { type(0) : 0, type(0L) : 0, type('') : 1, type(True) : 2 @@ -224,10 +249,13 @@ class ValueExpression(object): self._NoProcess =3D False if type(Expression) !=3D type(''): self._Expr =3D Expression self._NoProcess =3D True return + if Expression.strip().startswith('{') and Expression.strip().endsw= ith('}'): + self._Expr =3D Expression + self._NoProcess =3D True =20 self._Expr =3D ReplaceExprMacro(Expression.strip(), SymbolTable, SupportedInMacroList) =20 @@ -235,11 +263,11 @@ class ValueExpression(object): raise BadExpression(ERR_EMPTY_EXPR) =20 # # The symbol table including PCD and macro mapping # - self._Symb =3D SymbolTable + self._Symb =3D copy.deepcopy(SymbolTable) self._Symb.update(self.LogicalOperators) self._Idx =3D 0 self._Len =3D len(self._Expr) self._Token =3D '' self._WarnExcept =3D None @@ -282,11 +310,11 @@ class ValueExpression(object): if Val =3D=3D 'L""': Val =3D False elif not Val: Val =3D False RealVal =3D '""' - elif not Val.startswith('L"') and not Val.startswith('{'): + elif not Val.startswith('L"') and not Val.startswith('{') and = not Val.startswith("L'"): Val =3D True RealVal =3D '"' + RealVal + '"' =20 # The expression has been parsed, but the end of expression is not= reached # It means the rest does not comply EBNF of @@ -424,10 +452,19 @@ class ValueExpression(object): # Try to convert string to number def __IsNumberToken(self): Radix =3D 10 if self._Token.lower()[0:2] =3D=3D '0x' and len(self._Token) > 2: Radix =3D 16 + if self._Token.startswith('"') or self._Token.startswith("'")\ + or self._Token.startswith("L'") or self._Token.startswith('L"'= ): + Flag =3D 0 + for Index in range(len(self._Token)): + if self._Token[Index] in ['"', "'"]: + Flag +=3D 1 + if Flag =3D=3D 2: + self._Token =3D ParseFieldValue(self._Token)[0] + return True try: self._Token =3D int(self._Token, Radix) return True except ValueError: return False @@ -471,14 +508,16 @@ class ValueExpression(object): =20 # Replace escape \\\", \" Expr =3D self._Expr[self._Idx:].replace('\\\\', '//').replace('\\\= "', '\\\'') for Ch in Expr: self._Idx +=3D 1 - if Ch =3D=3D '"': + if Ch =3D=3D '"' or Ch =3D=3D "'": break self._Token =3D self._LiteralToken =3D self._Expr[Idx:self._Idx] - if not self._Token.endswith('"'): + if self._Token.startswith('"') and not self._Token.endswith('"'): + raise BadExpression(ERR_STRING_TOKEN % self._Token) + if self._Token.startswith("'") and not self._Token.endswith("'"): raise BadExpression(ERR_STRING_TOKEN % self._Token) self._Token =3D self._Token[1:-1] return self._Token =20 # Get token that is comprised by alphanumeric, underscore or dot(used = by PCD) @@ -576,11 +615,48 @@ class ValueExpression(object): if Expr.startswith('L"'): # Skip L self._Idx +=3D 1 UStr =3D self.__GetString() self._Token =3D 'L"' + UStr + '"' + self._Token, Size =3D ParseFieldValue(self._Token) + return self._Token + elif Expr.startswith("L'"): + # Skip L + self._Idx +=3D 1 + UStr =3D self.__GetString() + self._Token =3D "L'" + UStr + "'" + self._Token, Size =3D ParseFieldValue(self._Token) + return self._Token + elif Expr.startswith('"'): + UStr =3D self.__GetString() + self._Token =3D '"' + UStr + '"' + self._Token, Size =3D ParseFieldValue(self._Token) return self._Token + elif Expr.startswith("'"): + UStr =3D self.__GetString() + self._Token =3D "'" + UStr + "'" + self._Token, Size =3D ParseFieldValue(self._Token) + return self._Token + elif Expr.startswith('UINT'): + Re =3D re.compile('(?:UINT8|UINT16|UINT32|UINT64)\((.+)\)') + try: + RetValue =3D Re.search(Expr).group(1) + except: + raise BadExpression('Invalid Expression %s' % Expr) + Idx =3D self._Idx + for Ch in Expr: + self._Idx +=3D 1 + if Ch =3D=3D '(': + Prefix =3D self._Expr[Idx:self._Idx - 1] + Idx =3D self._Idx + if Ch =3D=3D ')': + TmpValue =3D self._Expr[Idx :self._Idx - 1] + TmpValue =3D ValueExpression(TmpValue)(True) + TmpValue =3D '0x%x' % int(TmpValue) if type(TmpValue) = !=3D type('') else TmpValue + break + self._Token, Size =3D ParseFieldValue(Prefix + '(' + TmpValue = + ')') + return self._Token =20 self._Token =3D '' if Expr: Ch =3D Expr[0] Match =3D self.RegGuidPattern.match(Expr) @@ -646,10 +722,162 @@ class ValueExpression(object): self._Token =3D self.LogicalOperators[self._Token] return True self._Idx =3D Idx return False =20 +class ValueExpressionEx(ValueExpression): + def __init__(self, PcdValue, PcdType, SymbolTable=3D{}): + ValueExpression.__init__(self, PcdValue, SymbolTable) + self.PcdValue =3D PcdValue + self.PcdType =3D PcdType + + def __call__(self, RealValue=3DFalse, Depth=3D0): + PcdValue =3D self.PcdValue + try: + PcdValue =3D ValueExpression.__call__(self, RealValue, Depth) + except WrnExpression, Value: + PcdValue =3D Value.result + + if PcdValue =3D=3D 'True': + PcdValue =3D '1' + if PcdValue =3D=3D 'False': + PcdValue =3D '0' + if self.PcdType in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEA= N']: + PcdValue =3D PcdValue.strip() + if type(PcdValue) =3D=3D type('') and PcdValue.startswith('{')= and PcdValue.endswith('}'): + PcdValue =3D PcdValue[1:-1].split(',') + if type(PcdValue) =3D=3D type([]): + TmpValue =3D 0 + Size =3D 0 + for Item in PcdValue: + if Item.startswith('UINT16'): + ItemSize =3D 2 + elif Item.startswith('UINT32'): + ItemSize =3D 4 + elif Item.startswith('UINT64'): + ItemSize =3D 8 + else: + ItemSize =3D 0 + Item =3D ValueExpressionEx(Item, self.PcdType, self._S= ymb)(True) + + if ItemSize =3D=3D 0: + ItemValue, ItemSize =3D ParseFieldValue(Item) + else: + ItemValue =3D ParseFieldValue(Item)[0] + + if type(ItemValue) =3D=3D type(''): + ItemValue =3D int(ItemValue, 16) if ItemValue.star= tswith('0x') else int(ItemValue) + + TmpValue =3D (ItemValue << (Size * 8)) | TmpValue + Size =3D Size + ItemSize + else: + TmpValue, Size =3D ParseFieldValue(PcdValue) + if type(TmpValue) =3D=3D type(''): + TmpValue =3D int(TmpValue) + else: + PcdValue =3D '0x%0{}X'.format(Size) % (TmpValue) + if TmpValue < 0: + raise BadExpression('Type %s PCD Value is negative' % sel= f.PcdType) + if self.PcdType =3D=3D 'UINT8' and Size > 1: + raise BadExpression('Type %s PCD Value Size is Larger than= 1 byte' % self.PcdType) + if self.PcdType =3D=3D 'UINT16' and Size > 2: + raise BadExpression('Type %s PCD Value Size is Larger than= 2 byte' % self.PcdType) + if self.PcdType =3D=3D 'UINT32' and Size > 4: + raise BadExpression('Type %s PCD Value Size is Larger than= 4 byte' % self.PcdType) + if self.PcdType =3D=3D 'UINT64' and Size > 8: + raise BadExpression('Type %s PCD Value Size is Larger than= 8 byte' % self.PcdType) + if self.PcdType in ['VOID*']: + try: + TmpValue =3D long(PcdValue) + TmpList =3D [] + if TmpValue.bit_length() =3D=3D 0: + PcdValue =3D '{0x00}' + else: + for I in range((TmpValue.bit_length() + 7) / 8): + TmpList.append('0x%02x' % ((TmpValue >> I * 8) & 0= xff)) + 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.endswith('= )'): + try: + TokenSpaceGuidName =3D re.search('GUID\((\w+)\= )', PcdValue).group(1) + except: + pass + if TokenSpaceGuidName and TokenSpaceGuidName in se= lf._Symb: + PcdValue =3D 'GUID(' + self._Symb[TokenSpaceGu= idName] + ')' + elif TokenSpaceGuidName: + raise BadExpression('%s not found in DEC file'= % TokenSpaceGuidName) + + ListItem, Size =3D ParseFieldValue(PcdValue) + elif PcdValue.startswith('DEVICE_PATH') and PcdValue.e= ndswith(')'): + 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.endswith(= '}'): + PcdValue =3D ListItem + else: + LabelDict =3D {} + ReLabel =3D re.compile('LABEL\((\w+)\)') + ReOffset =3D re.compile('OFFSET_OF\((\w+)\)') + 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 + try: + OffsetList =3D ReOffset.findall(Item) + except: + pass + for Offset in OffsetList: + if Offset in LabelDict.keys(): + Re =3D re.compile('OFFSET_OF\(%s\)'% O= ffset) + Item =3D Re.sub(LabelDict[Offset], Ite= m) + else: + raise BadExpression('%s not defined be= fore use' % Offset) + if Item.startswith('UINT16'): + ItemSize =3D 2 + elif Item.startswith('UINT32'): + ItemSize =3D 4 + elif Item.startswith('UINT64'): + ItemSize =3D 8 + else: + ItemSize =3D 0 + TmpValue =3D ValueExpressionEx(Item, self.PcdT= ype, self._Symb)(True) + Item =3D '0x%x' % TmpValue if type(TmpValue) != =3D type('') else TmpValue + if ItemSize =3D=3D 0: + ItemValue, ItemSize =3D ParseFieldValue(It= em) + else: + ItemValue =3D ParseFieldValue(Item)[0] + for I in range(0, ItemSize): + ValueStr +=3D '0x%02X' % (int(ItemValue) &= 255) + ItemValue >>=3D 8 + ValueStr +=3D ', ' + Size +=3D ItemSize + + if Size > 0: + PcdValue =3D '{' + ValueStr[:-2] + '}' + if RealValue: + return PcdValue + if __name__ =3D=3D '__main__': pass while True: input =3D raw_input('Input expr: ') if input in 'qQ': diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Pyth= on/Common/Misc.py index 0374be0..c51b685 100644 --- a/BaseTools/Source/Python/Common/Misc.py +++ b/BaseTools/Source/Python/Common/Misc.py @@ -35,10 +35,11 @@ from BuildToolError import * from CommonDataClass.DataClass import * from Parsing import GetSplitValueList from Common.LongFilePathSupport import OpenLongFilePath as open from Common.MultipleWorkspace import MultipleWorkspace as mws import uuid +from CommonDataClass.Exceptions import BadExpression =20 ## Regular expression used to find out place holders in string template gPlaceholderPattern =3D re.compile("\$\{([^$()\s]+)\}", re.MULTILINE | re.= UNICODE) =20 ## Dictionary used to store file time stamp for quick re-access @@ -1470,103 +1471,123 @@ def AnalyzePcdExpression(Setting): FieldList.append(Setting[StartPos:Pos].strip()) StartPos =3D Pos + 1 =20 return FieldList =20 +def ParseDevPathValue (Value): + pass + def ParseFieldValue (Value): - if type(Value) =3D=3D type(0): - return Value, (Value.bit_length() + 7) / 8 - if type(Value) <> type(''): - raise ValueError - Value =3D Value.strip() - if Value.startswith('UINT8') and Value.endswith(')'): - Value, Size =3D ParseFieldValue(Value.split('(', 1)[1][:-1]) - if Size > 1: - raise ValueError + if type(Value) =3D=3D type(0): + return Value, (Value.bit_length() + 7) / 8 + if type(Value) <> type(''): + raise BadExpression('Type %s is %s' %(Value, type(Value))) + Value =3D Value.strip() + if Value.startswith('UINT8') and Value.endswith(')'): + Value, Size =3D ParseFieldValue(Value.split('(', 1)[1][:-1]) + if Size > 1: + raise BadExpression('Value (%s) Size larger than %d' %(Value, = Size)) + return Value, 1 + if Value.startswith('UINT16') and Value.endswith(')'): + Value, Size =3D ParseFieldValue(Value.split('(', 1)[1][:-1]) + if Size > 2: + raise BadExpression('Value (%s) Size larger than %d' %(Value, = Size)) + return Value, 2 + if Value.startswith('UINT32') and Value.endswith(')'): + Value, Size =3D ParseFieldValue(Value.split('(', 1)[1][:-1]) + if Size > 4: + raise BadExpression('Value (%s) Size larger than %d' %(Value, = Size)) + return Value, 4 + if Value.startswith('UINT64') and Value.endswith(')'): + Value, Size =3D ParseFieldValue(Value.split('(', 1)[1][:-1]) + if Size > 8: + raise BadExpression('Value (%s) Size larger than %d' % (Value,= Size)) + return Value, 8 + if Value.startswith('GUID') and Value.endswith(')'): + Value =3D Value.split('(', 1)[1][:-1].strip() + if Value[0] =3D=3D '{' and Value[-1] =3D=3D '}': + Value =3D Value[1:-1].strip() + Value =3D Value.split('{', 1) + Value =3D ['%02x' % int(Item, 16) for Item in (Value[0] + Valu= e[1][:-1]).split(',')] + if len(Value[0]) !=3D 8: + Value[0] =3D '%08X' % int(Value[0], 16) + if len(Value[1]) !=3D 4: + Value[1] =3D '%04X' % int(Value[1], 16) + if len(Value[2]) !=3D 4: + Value[2] =3D '%04X' % int(Value[2], 16) + Value =3D '-'.join(Value[0:3]) + '-' + ''.join(Value[3:5]) + '= -' + ''.join(Value[5:11]) + if Value[0] =3D=3D '"' and Value[-1] =3D=3D '"': + Value =3D Value[1:-1] + try: + Value =3D "'" + uuid.UUID(Value).get_bytes_le() + "'" + except ValueError, Message: + raise BadExpression('%s' % Message) + Value, Size =3D ParseFieldValue(Value) + return Value, 16 + if Value.startswith('L"') and Value.endswith('"'): + # Unicode String + List =3D list(Value[2:-1]) + List.reverse() + Value =3D 0 + for Char in List: + Value =3D (Value << 16) | ord(Char) + return Value, (len(List) + 1) * 2 + if Value.startswith('"') and Value.endswith('"'): + # ASCII String + List =3D list(Value[1:-1]) + List.reverse() + Value =3D 0 + for Char in List: + Value =3D (Value << 8) | ord(Char) + return Value, len(List) + 1 + if Value.startswith("L'") and Value.endswith("'"): + # Unicode Character Constant + List =3D list(Value[2:-1]) + List.reverse() + Value =3D 0 + for Char in List: + Value =3D (Value << 16) | ord(Char) + return Value, len(List) * 2 + if Value.startswith("'") and Value.endswith("'"): + # Character constant + List =3D list(Value[1:-1]) + List.reverse() + Value =3D 0 + for Char in List: + Value =3D (Value << 8) | ord(Char) + return Value, len(List) + if Value.startswith('{') and Value.endswith('}'): + # Byte array + Value =3D Value[1:-1] + List =3D [Item.strip() for Item in Value.split(',')] + List.reverse() + Value =3D 0 + RetSize =3D 0 + for Item in List: + ItemValue, Size =3D ParseFieldValue(Item) + RetSize +=3D Size + for I in range(Size): + Value =3D (Value << 8) | ((ItemValue >> 8 * I) & 0xff) + return Value, RetSize + if Value.startswith('DEVICE_PATH(') and Value.endswith(')'): + Value =3D Value.split('"')[1] + return ParseDevPathValue(Value) + if Value.lower().startswith('0x'): + Value =3D int(Value, 16) + if Value =3D=3D 0: + return 0, 1 + return Value, (Value.bit_length() + 7) / 8 + if Value[0].isdigit(): + Value =3D int(Value, 10) + if Value =3D=3D 0: + return 0, 1 + return Value, (Value.bit_length() + 7) / 8 + if Value.lower() =3D=3D 'true': + return 1, 1 + if Value.lower() =3D=3D 'false': + return 0, 1 return Value, 1 - if Value.startswith('UINT16') and Value.endswith(')'): - Value, Size =3D ParseFieldValue(Value.split('(', 1)[1][:-1]) - if Size > 2: - raise ValueError - return Value, 2 - if Value.startswith('UINT32') and Value.endswith(')'): - Value, Size =3D ParseFieldValue(Value.split('(', 1)[1][:-1]) - if Size > 4: - raise ValueError - return Value, 4 - if Value.startswith('UINT64') and Value.endswith(')'): - Value, Size =3D ParseFieldValue(Value.split('(', 1)[1][:-1]) - if Size > 8: - raise ValueError - return Value, 8 - if Value.startswith('GUID') and Value.endswith(')'): - Value =3D Value.split('(', 1)[1][:-1].strip() - if Value[0] =3D=3D '{' and Value[-1] =3D=3D '}': - Value =3D Value[1:-1].strip() - Value =3D Value.split('{', 1) - Value =3D [Item.strip()[2:] for Item in (Value[0] + Value[1][:-1]).s= plit(',')] - Value =3D '-'.join(Value[0:3]) + '-' + ''.join(Value[3:5]) + '-' + '= '.join(Value[5:11]) - if Value[0] =3D=3D '"' and Value[-1] =3D=3D '"': - Value =3D Value[1:-1] - Value =3D "'" + uuid.UUID(Value).get_bytes_le() + "'" - Value, Size =3D ParseFieldValue(Value) - return Value, 16 - if Value.startswith('L"') and Value.endswith('"'): - # Unicode String - List =3D list(Value[2:-1]) - List.reverse() - Value =3D 0 - for Char in List: - Value =3D (Value << 16) | ord(Char) - return Value, (len(List) + 1) * 2 - if Value.startswith('"') and Value.endswith('"'): - # ASCII String - List =3D list(Value[1:-1]) - List.reverse() - Value =3D 0 - for Char in List: - Value =3D (Value << 8) | ord(Char) - return Value, len(List) + 1 - if Value.startswith("L'") and Value.endswith("'"): - # Unicode Character Constant - List =3D list(Value[2:-1]) - List.reverse() - Value =3D 0 - for Char in List: - Value =3D (Value << 16) | ord(Char) - return Value, len(List) * 2 - if Value.startswith("'") and Value.endswith("'"): - # Character constant - List =3D list(Value[1:-1]) - List.reverse() - Value =3D 0 - for Char in List: - Value =3D (Value << 8) | ord(Char) - return Value, len(List) - if Value.startswith('{') and Value.endswith('}'): - # Byte array - Value =3D Value[1:-1] - List =3D [Item.strip() for Item in Value.split(',')] - List.reverse() - Value =3D 0 - for Item in List: - ItemValue, Size =3D ParseFieldValue(Item) - if Size > 1: - raise ValueError - Value =3D (Value << 8) | ItemValue - return Value, len(List) - if Value.lower().startswith('0x'): - Value =3D int(Value, 16) - return Value, (Value.bit_length() + 7) / 8 - if Value[0].isdigit(): - Value =3D int(Value, 10) - return Value, (Value.bit_length() + 7) / 8 - if Value.lower() =3D=3D 'true': - return 1, 1 - if Value.lower() =3D=3D 'false': - return 0, 1 - return Value, 1 =20 ## AnalyzeDscPcd # # Analyze DSC PCD value, since there is no data type info in DSC # This fuction is used to match functions (AnalyzePcdData, AnalyzeHiiPcdD= ata, AnalyzeVpdPcdData) used for retrieving PCD value from database diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/= Source/Python/Workspace/DscBuildData.py index e422100..f9cd429 100644 --- a/BaseTools/Source/Python/Workspace/DscBuildData.py +++ b/BaseTools/Source/Python/Workspace/DscBuildData.py @@ -798,11 +798,11 @@ class DscBuildData(PlatformBuildClassObject): if ModuleFile in self._Modules: continue ModuleData =3D self._Bdb[ModuleFile, self._Arch, self._Tar= get, self._Toolchain] PkgSet.update(ModuleData.Packages) =20 - self._DecPcds =3D GetDeclaredPcd(self, self._Bdb, self._Arch, = self._Target, self._Toolchain,PkgSet) + self._DecPcds, self._GuidDict =3D GetDeclaredPcd(self, self._B= db, self._Arch, self._Target, self._Toolchain,PkgSet) =20 =20 if (PcdCName, TokenSpaceGuid) not in self._DecPcds: EdkLogger.error('build', PARSER_ERROR, "Pcd (%s.%s) defined in DSC is not declared in= DEC files. Arch: ['%s']" % (TokenSpaceGuid, PcdCName, self._Arch), @@ -819,10 +819,12 @@ class DscBuildData(PlatformBuildClassObject): if ValueList[Index] and PcdType not in [MODEL_PCD_FEATURE_FLAG, MO= DEL_PCD_FIXED_AT_BUILD]: try: ValueList[Index] =3D ValueExpression(ValueList[Index], Glo= balData.gPlatformPcds)(True) except WrnExpression, Value: ValueList[Index] =3D Value.result + except BadExpression, Value: + EdkLogger.error('Parser', FORMAT_INVALID, Value, File=3Dse= lf.MetaFile, Line=3Dself._LineIndex + 1) except EvaluationException, Excpt: if hasattr(Excpt, 'Pcd'): if Excpt.Pcd in GlobalData.gPlatformOtherPcds: EdkLogger.error('Parser', FORMAT_INVALID, "Cannot = use this PCD (%s) in an expression as" " it must be defined in a [PcdsFix= edAtBuild] or [PcdsFeatureFlag] section" @@ -832,15 +834,17 @@ class DscBuildData(PlatformBuildClassObject): EdkLogger.error('Parser', FORMAT_INVALID, "PCD (%s= ) is not defined in DSC file" % Excpt.Pcd, File=3Dself.MetaFile, Line=3DLineN= o) else: EdkLogger.error('Parser', FORMAT_INVALID, "Invalid exp= ression: %s" % str(Excpt), File=3Dself.MetaFile, Line=3DLineNo) - if ValueList[Index] =3D=3D 'True': - ValueList[Index] =3D '1' - elif ValueList[Index] =3D=3D 'False': - ValueList[Index] =3D '0' if ValueList[Index]: + DatumType =3D self._DecPcds[PcdCName, TokenSpaceGuid].DatumType + try: + ValueList[Index] =3D ValueExpressionEx(ValueList[Index], D= atumType, self._GuidDict)(True) + except BadExpression, Value: + EdkLogger.error('Parser', FORMAT_INVALID, Value, File=3Dse= lf.MetaFile, Line=3DLineNo, + ExtraData=3D"PCD [%s.%s] Value \"%s\" " % = (TokenSpaceGuid, PcdCName, ValueList[Index])) Valid, ErrStr =3D CheckPcdDatum(self._DecPcds[PcdCName, TokenS= paceGuid].DatumType, ValueList[Index]) if not Valid: EdkLogger.error('build', FORMAT_INVALID, ErrStr, File=3Dse= lf.MetaFile, Line=3DLineNo, ExtraData=3D"%s.%s" % (TokenSpaceGuid, Pcd= CName)) if PcdType in (MODEL_PCD_DYNAMIC_DEFAULT, MODEL_PCD_DYNAMIC_EX= _DEFAULT): @@ -2056,11 +2060,11 @@ class DscBuildData(PlatformBuildClassObject): ModuleFile =3D PathClass(NormPath(Inf), GlobalData.gWorksp= ace, Arch=3Dself._Arch) if ModuleFile in self._Modules: continue ModuleData =3D self._Bdb[ModuleFile, self._Arch, self._Tar= get, self._Toolchain] PkgSet.update(ModuleData.Packages) - self._DecPcds =3D GetDeclaredPcd(self, self._Bdb, self._Arch, = self._Target, self._Toolchain,PkgSet) + self._DecPcds, self._GuidDict =3D GetDeclaredPcd(self, self._B= db, self._Arch, self._Target, self._Toolchain,PkgSet) return self._DecPcds _Macros =3D property(_GetMacros) Arch =3D property(_GetArch, _SetArch) Platform =3D property(_GetPlatformName) PlatformName =3D property(_GetPlatformName) diff --git a/BaseTools/Source/Python/Workspace/InfBuildData.py b/BaseTools/= Source/Python/Workspace/InfBuildData.py index fd94067..7ea9b56 100644 --- a/BaseTools/Source/Python/Workspace/InfBuildData.py +++ b/BaseTools/Source/Python/Workspace/InfBuildData.py @@ -14,10 +14,11 @@ =20 from Common.String import * from Common.DataType import * from Common.Misc import * from types import * +from MetaFileParser import * =20 from Workspace.BuildClassObject import ModuleBuildClassObject, LibraryClas= sObject, PcdClassObject ## Module build information from INF file # # This class is used to retrieve information stored in database and conve= rt them @@ -1142,10 +1143,16 @@ class InfBuildData(ModuleBuildClassObject): Pcd.DatumType =3D PcdInPackage.DatumType Pcd.MaxDatumSize =3D PcdInPackage.MaxDatumSize Pcd.InfDefaultValue =3D Pcd.DefaultValue if Pcd.DefaultValue in [None, '']: Pcd.DefaultValue =3D PcdInPackage.DefaultValue + else: + try: + Pcd.DefaultValue =3D ValueExpressionEx(Pcd.Def= aultValue, Pcd.DatumType, self.Guids)(True) + except BadExpression, Value: + EdkLogger.error('Parser', FORMAT_INVALID, 'PCD= [%s.%s] Value "%s", %s' %(TokenSpaceGuid, PcdRealName, Pcd.DefaultValue, V= alue), + File=3Dself.MetaFile, Line=3DL= ineNo) break else: EdkLogger.error( 'build', FORMAT_INVALID, diff --git a/BaseTools/Source/Python/Workspace/MetaFileParser.py b/BaseTool= s/Source/Python/Workspace/MetaFileParser.py index 3038447..b2b0e28 100644 --- a/BaseTools/Source/Python/Workspace/MetaFileParser.py +++ b/BaseTools/Source/Python/Workspace/MetaFileParser.py @@ -25,11 +25,11 @@ import Common.EdkLogger as EdkLogger import Common.GlobalData as GlobalData =20 from CommonDataClass.DataClass import * from Common.DataType import * from Common.String import * -from Common.Misc import GuidStructureStringToGuidString, CheckPcdDatum, Pa= thClass, AnalyzePcdData, AnalyzeDscPcd, AnalyzePcdExpression +from Common.Misc import GuidStructureStringToGuidString, CheckPcdDatum, Pa= thClass, AnalyzePcdData, AnalyzeDscPcd, AnalyzePcdExpression, ParseFieldVal= ue from Common.Expression import * from CommonDataClass.Exceptions import * from Common.LongFilePathSupport import OpenLongFilePath as open =20 from MetaFileTable import MetaFileStorage @@ -180,10 +180,11 @@ class MetaFileParser(object): self._Enabled =3D 0 self._Finished =3D False self._PostProcessed =3D False # Different version of meta-file has different way to parse. self._Version =3D 0 + self._GuidDict =3D {} # for Parser PCD value {GUID(gTokeSpaceGuid= Name)} =20 ## Store the parsed data in table def _Store(self, *Args): return self._Table.Insert(*Args) =20 @@ -1869,10 +1870,12 @@ class DecParser(MetaFileParser): ExtraData=3Dself._CurrentLine + \ " ( =3D )", File=3Dself.MetaFile, Line=3Dself._LineIndex += 1) self._ValueList[0] =3D TokenList[0] self._ValueList[1] =3D TokenList[1] + if self._ValueList[0] not in self._GuidDict: + self._GuidDict[self._ValueList[0]] =3D self._ValueList[1] =20 ## PCD sections parser # # [PcdsFixedAtBuild] # [PcdsPatchableInModule] @@ -1985,16 +1988,18 @@ class DecParser(MetaFileParser): if PcdValue: try: ValueList[0] =3D ValueExpression(PcdValue, self._AllPc= dDict)(True) except WrnExpression, Value: ValueList[0] =3D Value.result + except BadExpression, Value: + EdkLogger.error('Parser', FORMAT_INVALID, Value, File= =3Dself.MetaFile, Line=3Dself._LineIndex + 1) =20 - if ValueList[0] =3D=3D 'True': - ValueList[0] =3D '1' - if ValueList[0] =3D=3D 'False': - ValueList[0] =3D '0' - + if ValueList[0]: + try: + ValueList[0] =3D ValueExpressionEx(ValueList[0], Value= List[1], self._GuidDict)(True) + except BadExpression, Value: + EdkLogger.error('Parser', FORMAT_INVALID, Value, Extra= Data=3Dself._CurrentLine, File=3Dself.MetaFile, Line=3Dself._LineIndex + 1) # check format of default value against the datum type IsValid, Cause =3D CheckPcdDatum(ValueList[1], ValueList[0]) if not IsValid: EdkLogger.error('Parser', FORMAT_INVALID, Cause, ExtraData= =3Dself._CurrentLine, File=3Dself.MetaFile, Line=3Dself._LineInd= ex + 1) diff --git a/BaseTools/Source/Python/Workspace/WorkspaceCommon.py b/BaseToo= ls/Source/Python/Workspace/WorkspaceCommon.py index c289b9d..c760e57 100644 --- a/BaseTools/Source/Python/Workspace/WorkspaceCommon.py +++ b/BaseTools/Source/Python/Workspace/WorkspaceCommon.py @@ -1,9 +1,9 @@ ## @file # Common routines used by workspace # -# Copyright (c) 2012 - 2016, Intel Corporation. All rights reserved.
+# Copyright (c) 2012 - 2017, Intel Corporation. All rights reserved.
# This program and the accompanying materials # are licensed and made available under the terms and conditions of the BS= D License # which accompanies this distribution. The full text of the license may b= e found at # http://opensource.org/licenses/bsd-license.php # @@ -41,28 +41,32 @@ def GetPackageList(Platform, BuildDatabase, Arch, Targe= t, Toolchain): # @param BuildDatabase: The database saves all data for all metafiles # @param Arch: Current arch # @param Target: Current target # @param Toolchain: Current toolchain # @retval: A dictionary contains instances of PcdClassObject with key (Pc= dCName, TokenSpaceGuid) +# @retval: A dictionary contains real GUIDs of TokenSpaceGuid # def GetDeclaredPcd(Platform, BuildDatabase, Arch, Target, Toolchain,additi= onalPkgs): PkgList =3D GetPackageList(Platform, BuildDatabase, Arch, Target, Tool= chain) PkgList =3D set(PkgList) PkgList |=3D additionalPkgs DecPcds =3D {} + GuidDict =3D {} for Pkg in PkgList: + Guids =3D Pkg.Guids + GuidDict.update(Guids) for Pcd in Pkg.Pcds: PcdCName =3D Pcd[0] PcdTokenName =3D Pcd[1] if GlobalData.MixedPcd: for PcdItem in GlobalData.MixedPcd.keys(): if (PcdCName, PcdTokenName) in GlobalData.MixedPcd[Pcd= Item]: PcdCName =3D PcdItem[0] break if (PcdCName, PcdTokenName) not in DecPcds.keys(): DecPcds[PcdCName, PcdTokenName] =3D Pkg.Pcds[Pcd] - return DecPcds + return DecPcds, GuidDict =20 ## Get all dependent libraries for a module # # @param Module: InfBuildData instance # @param Platform: DscBuildData instance diff --git a/BaseTools/Source/Python/build/BuildReport.py b/BaseTools/Sourc= e/Python/build/BuildReport.py index 75e8ec9..5da9914 100644 --- a/BaseTools/Source/Python/build/BuildReport.py +++ b/BaseTools/Source/Python/build/BuildReport.py @@ -43,10 +43,11 @@ import Common.GlobalData as GlobalData from AutoGen.AutoGen import ModuleAutoGen from Common.Misc import PathClass from Common.String import NormPath from Common.DataType import * import collections +from Common.Expression import ValueExpressionEx =20 ## Pattern to extract contents in EDK DXS files gDxsDependencyPattern =3D re.compile(r"DEPENDENCY_START(.+)DEPENDENCY_END"= , re.DOTALL) =20 ## Pattern to find total FV total size, occupied size in flash report inte= rmediate file @@ -847,12 +848,15 @@ class PcdReport(object): =20 # # Collect PCD DEC default value. # self.DecPcdDefault =3D {} + self._GuidDict =3D {} for Pa in Wa.AutoGenObjectList: for Package in Pa.PackageList: + Guids =3D Package.Guids + self._GuidDict.update(Guids) for (TokenCName, TokenSpaceGuidCName, DecType) in Package.= Pcds: DecDefaultValue =3D Package.Pcds[TokenCName, TokenSpac= eGuidCName, DecType].DefaultValue self.DecPcdDefault.setdefault((TokenCName, TokenSpaceG= uidCName, DecType), DecDefaultValue) # # Collect PCDs defined in DSC common section @@ -941,10 +945,12 @@ class PcdReport(object): # DecDefaultValue =3D self.DecPcdDefault.get((Pcd.TokenC= Name, Pcd.TokenSpaceGuidCName, DecType)) DscDefaultValue =3D self.DscPcdDefault.get((Pcd.TokenC= Name, Pcd.TokenSpaceGuidCName)) DscDefaultValBak=3D DscDefaultValue DscDefaultValue =3D self.FdfPcdSet.get((Pcd.TokenCName= , Key), DscDefaultValue) + if DscDefaultValue: + DscDefaultValue =3D ValueExpressionEx(DscDefaultVa= lue, Pcd.DatumType, self._GuidDict)(True) InfDefaultValue =3D None =20 PcdValue =3D DecDefaultValue if DscDefaultValue: PcdValue =3D DscDefaultValue --=20 2.6.1.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel