From nobody Sat Nov 2 12:27:51 2024 Delivered-To: importer@patchew.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; Authentication-Results: mx.zoho.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 1491923843455280.88017326350246; Tue, 11 Apr 2017 08:17:23 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 2223F2095C3CF; Tue, 11 Apr 2017 08:17:15 -0700 (PDT) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (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 F257121939304 for ; Tue, 11 Apr 2017 08:17:12 -0700 (PDT) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga104.jf.intel.com with ESMTP; 11 Apr 2017 08:17:11 -0700 Received: from shwde7172.ccr.corp.intel.com ([10.239.9.14]) by orsmga002.jf.intel.com with ESMTP; 11 Apr 2017 08:17:10 -0700 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,186,1488873600"; d="scan'208";a="72592980" From: Liming Gao To: edk2-devel@lists.01.org Date: Tue, 11 Apr 2017 23:16:43 +0800 Message-Id: <1491923803-12124-4-git-send-email-liming.gao@intel.com> X-Mailer: git-send-email 2.8.0.windows.1 In-Reply-To: <1491923803-12124-1-git-send-email-liming.gao@intel.com> References: <1491923803-12124-1-git-send-email-liming.gao@intel.com> Subject: [edk2] [RFC 3/3] TestPkg: Show Structure PCD value assignment X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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" Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Liming Gao --- TestPkg/Include/Guid/Test.h | 31 ++ TestPkg/StructuredPcdValueGenerator.py | 702 +++++++++++++++++++++++++++++= ++++ TestPkg/TestPkg.dec | 44 +++ TestPkg/TestPkg.dsc | 69 ++++ 4 files changed, 846 insertions(+) create mode 100644 TestPkg/Include/Guid/Test.h create mode 100644 TestPkg/StructuredPcdValueGenerator.py create mode 100644 TestPkg/TestPkg.dec create mode 100644 TestPkg/TestPkg.dsc diff --git a/TestPkg/Include/Guid/Test.h b/TestPkg/Include/Guid/Test.h new file mode 100644 index 0000000..e988954 --- /dev/null +++ b/TestPkg/Include/Guid/Test.h @@ -0,0 +1,31 @@ +//#pragma pack(1) + +#define MacroTest2 10 + +typedef struct { + BOOLEAN Bool; =20 + UINT8 A:4;=20 + UINT8 B:4; + UINT32 Unaligned32; + UINT16 C; + UINT16 D; + UINT32 E; + UINT32 F; + UINT64 G; + UINT64 H; + UINT8 Reserved; + UINT8 Hidden; =20 + UINT8 OneLine8; =20 + UINT16 OneLine16; =20 + UINT32 OneLine32; =20 + UINT64 OneLine64; =20 + BOOLEAN OneLineBoolA; =20 + BOOLEAN OneLineBoolB; =20 + BOOLEAN OneLineBoolC; =20 + BOOLEAN OneLineBoolD; =20 + UINT32 Array[10]; + UINT8 Array2[2]; + UINT8 FlexibleArray[0]; +} TEST; + +//#pragma pack() diff --git a/TestPkg/StructuredPcdValueGenerator.py b/TestPkg/StructuredPcd= ValueGenerator.py new file mode 100644 index 0000000..a24ccf3 --- /dev/null +++ b/TestPkg/StructuredPcdValueGenerator.py @@ -0,0 +1,702 @@ +# +# Generate C program to convert structure PCD value to byte array. +# + +import os +import sys +import argparse +import subprocess +from collections import OrderedDict +import uuid + +# +# Globals for help information +# +__prog__ =3D 'StructuredPcdValueGenerator' +__version__ =3D '%s Version %s' % (__prog__, '0.1 ') +__copyright__ =3D 'Copyright (c) 2017, Intel Corporation. All rights reser= ved.' +__usage__ =3D '%s [options]' % (__prog__) + +# +# Treat CHAR16 as a synonym for UINT16. CHAR16 support is required for VF= R C structs +# +PcdValueInitName =3D 'PcdValueInit' +PcdSupportedBaseTypes =3D ['BOOLEAN', 'UINT8', 'UINT16', 'UINT32', 'UINT= 64', 'CHAR16'] +PcdSupportedBaseTypeWidth =3D {'BOOLEAN':8, 'UINT8':8, 'UINT16':16, 'UINT3= 2':32, 'UINT64':64} +PcdUnsupportedBaseTypes =3D ['INT8', 'INT16', 'INT32', 'INT64', 'CHAR8', '= UINTN', 'INTN', 'VOID'] + +PcdMainCHeader =3D ''' +/** + DO NOT EDIT + FILE auto-generated +**/ + +#include +#include +#include +''' + +PcdMainCEntry =3D ''' +int +main ( + int argc, + char *argv[] + ) +{ + return PcdValueMain (argc, argv); +} +''' + +PcdMakefileHeader =3D ''' +# +# DO NOT EDIT +# This file is auto-generated by build utility +# + +''' + +PcdMakefileEnd =3D ''' +!INCLUDE $(BASE_TOOLS_PATH)\Source\C\Makefiles\ms.common + +CFLAGS =3D $(CFLAGS) /wd4200 /wd4034 + +LIBS =3D $(LIB_PATH)\Common.lib + +!INCLUDE $(BASE_TOOLS_PATH)\Source\C\Makefiles\ms.app +''' + +PcdGccMakefile =3D ''' +ARCH ?=3D IA32 +MAKEROOT ?=3D $(EDK_TOOLS_PATH)/Source/C +LIBS =3D -lCommon +''' + +def GetBitField(Value, Start, Width): + Mask =3D (1 << Width) - 1 + return (Value >> Start) & Mask + +def SetBitField(Value, Start, Width, BitFieldValue): + Mask =3D (1 << Width) - 1 + if BitFieldValue & (~Mask) <> 0: + raise ValueError + BitFieldValue =3D BitFieldValue & Mask + Value =3D (Value & (~(Mask << Start))) | (BitFieldValue << Start) + return Value + +def IntToArray(Value, Size, Stride =3D 1, ValuesPerLine =3D 16, AsciiComme= nt =3D False): + if Stride not in [1,2,4,8]: + return '' + PostFix =3D '' + if Stride =3D=3D 8: + PostFix =3D 'ULL' + Value =3D Value & ((1 << Size * 8) - 1) + Output =3D '{\n' + Shift =3D Stride * 8 + Mask =3D (1 << Shift) - 1 + NumValues =3D 0 + Ascii =3D '' + for Index in range (0, Size, Stride): + Output =3D Output + '0x%0*X%s' % (Stride * 2, Value & Mask, PostFix) + if Index + Stride < Size: + Output =3D Output + ', ' + else: =20 + Output =3D Output + ' ' + for CharIndex in range (0, Stride): + Char =3D Value & 0xff + if Char in range(0x20, 0x7F): + Ascii =3D Ascii + chr(Value & 0xff) + else: + Ascii =3D Ascii + '.' + Value =3D Value >> 8 + if (NumValues % ValuesPerLine) =3D=3D (ValuesPerLine - 1): + if AsciiComment: + Output =3D Output + ' // %s' % (Ascii) + Output =3D Output + '\n' + Ascii =3D '' + NumValues =3D NumValues + 1 + if AsciiComment and (NumValues % ValuesPerLine) <> 0: + for Index in range((NumValues % ValuesPerLine), ValuesPerLine): + Output =3D Output + ' %*s%*s ' % (Stride * 2, '', len(PostFix), '') + Output =3D Output + ' // %s\n' % (Ascii) + Output =3D Output + '}' + return Output + +def IntToCString(Value, ValueSize): + Result =3D '"' + if not isinstance (Value, str): + for Index in range(0, ValueSize): + Result =3D Result + '\\x%02x' % (Value & 0xff) + Value =3D Value >> 8 + Result =3D Result + '"' + return Result =20 + =20 +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 + return Value, 1 =20 + if Value.startswith('UINT16') and Value.endswith(')'): + Value, Size =3D ParseFieldValue(Value.split('(',1)[1][:-1]) + if Size > 2: + raise ValueError + return Value, 2 =20 + if Value.startswith('UINT32') and Value.endswith(')'): + Value, Size =3D ParseFieldValue(Value.split('(',1)[1][:-1]) + if Size > 4: + raise ValueError + return Value, 4 =20 + if Value.startswith('UINT64') and Value.endswith(')'): + Value, Size =3D ParseFieldValue(Value.split('(',1)[1][:-1]) + if Size > 8: + raise ValueError + return Value, 8 =20 + 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 =20 + 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 =20 + 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) =20 + 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) =20 + if Value.lower().startswith('0x'): + Value =3D int(Value, 16) + return Value, (Value.bit_length() + 7) / 8=20 + if Value[0].isdigit(): + Value =3D int(Value, 10) + return Value, (Value.bit_length() + 7) / 8=20 + if Value.lower() =3D=3D 'true': + return 1, 1 + if Value.lower() =3D=3D 'false': + return 0, 1 + return Value, 1 + +def IsFieldValueAnArray (Value): + Value =3D Value.strip() + if Value.startswith('GUID') and Value.endswith(')'): + return True + if Value.startswith('L"') and Value.endswith('"'): + return True + if Value[0] =3D=3D '"' and Value[-1] =3D=3D '"': + return True + if Value[0] =3D=3D '{' and Value[-1] =3D=3D '}': + return True + if Value.startswith("L'") and Value.endswith("'") and len(list(Value[2:-= 1])) > 1: + print 'foo =3D ', list(Value[2:-1]) + return True + if Value[0] =3D=3D "'" and Value[-1] =3D=3D "'" and len(list(Value[1:-1]= )) > 1: + print 'bar =3D ', list(Value[1:-1]) + return True + return False =20 + +def ConvertValueToString (Value): + Result =3D '' + if Value.startswith('L"') and Value.endswith('"'): + for Char in Value[2:-1]: + Result =3D Result + '\\x%02x\\x00' % (ord(Char)) + Result =3D Result + '\\x00\\x00' + if Value[0] =3D=3D '"' and Value[-1] =3D=3D '"': + for Char in Value[1:-1]: + Result =3D Result + '\\x%02x' % (ord(Char)) + Result =3D Result + '\\x00' + if Value[0] =3D=3D '{' and Value[-1] =3D=3D '}': + Value =3D [int(Item.strip(),16) for Item in Value[1:-1].split(',')] + for Item in Value: + Result =3D Result + '\\x%02x' % (Item) + return Result + =20 +def ExecuteCommand (Command): + try: + Process =3D subprocess.Popen(Command, stdout=3Dsubprocess.PIPE, st= derr=3Dsubprocess.PIPE, shell=3DTrue) + except: =20 + print 'ERROR: Can not execute command:', Command + sys.exit(1) + Result =3D Process.communicate() + if Process.returncode <> 0: + print 'ERROR: Can not collect output from command:', Command + return Result[0], Result[1] + =20 +class StructuredPcdField: + def __init__(self, FieldName, DefaultValue): + self.FieldName =3D FieldName + self.DefaultValue =3D DefaultValue + + def __repr__(self): + return self.FieldName + =20 +class StructuredPcd: + def __init__(self, StructuredPcdIncludeFile, Packages, TokenSpaceGuidNam= e, TokenName, TypeName): + self.StructuredPcdIncludeFile =3D StructuredPcdIncludeFile + self.PackageDecs =3D Packages + self.SkuName =3D 'DEFAULT' + self.DefaultStoreName =3D 'DEFAULT' + self.TokenSpaceGuidName =3D TokenSpaceGuidName + self.TokenName =3D TokenName + self.TypeName =3D TypeName + self.DefaultValues =3D OrderedDict({}) + self.PcdMode =3D None + self.OverrideValues =3D OrderedDict({}) + self.FlexibleFieldName =3D None + + def __repr__(self): + return self.TypeName + + def AddDefaultValue (self, FieldName, Value, FileName=3D"", LineNo=3D0): + self.DefaultValues[FieldName] =3D [Value.strip(), FileName, LineNo] + return self.DefaultValues[FieldName] + + def AddOverrideValue (self, FieldName, Value, FileName=3D"", LineNo=3D0): + self.OverrideValues[FieldName] =3D [Value.strip(), FileName, LineNo] + return self.OverrideValues[FieldName] + + def SetPcdMode (self, PcdMode): + self.PcdMode =3D PcdMode + + def SetFlexibleFieldName (self, FlexibleFieldName): + self.FlexibleFieldName =3D FlexibleFieldName + =20 +class Build: + def __init__(self, args): + self.args =3D args + self.DecFile =3D args.DecFile + self.DscFile =3D args.DscFile + self.Quiet =3D args.Quiet + self.StructuredPcds =3D [] + self.PackagePath =3D os.path.dirname(self.DecFile) + if os.getenv("WORKSPACE"): + self.OutputPath =3D os.path.join(os.getenv("WORKSPACE"), 'Buil= d', PcdValueInitName) + else: + self.OutputPath =3D os.path.dirname(self.DscFile) + + def __repr__(self): + return self.DscFile + + def AddStructuredPcd (self, Include, Packages, TokenSpaceGuidName, Token= Name, Type): + Pcd =3D StructuredPcd(Include, Packages, TokenSpaceGuidName, TokenName= , Type) + self.StructuredPcds.append(Pcd) + return Pcd + + def LookupPcd(self, TokenSpaceGuidName, TokenName): + for Pcd in self.StructuredPcds: + if Pcd.TokenSpaceGuidName =3D=3D TokenSpaceGuidName and Pcd.TokenNam= e =3D=3D TokenName: + return Pcd + return None + + def LookupPcdByTypeName(self, TypeName): + for Pcd in self.StructuredPcds: + if Pcd.TypeName =3D=3D TypeName: + return Pcd + return None + =20 + def ParseDecFile (self): + print 'Parse DEC File', self.DecFile + File =3D open (self.DecFile, mode=3D'r') + DecFileBuffer =3D File.readlines() + File.close() + DecLineNumber =3D 0 + Include =3D None + PcdObject =3D None + while (DecLineNumber < len (DecFileBuffer)): + Line =3D DecFileBuffer[DecLineNumber] + DecLineNumber =3D DecLineNumber + 1 + Line =3D Line.strip() + if Line.startswith('#'): + continue + if len(Line.split('|')) =3D=3D 4: + Line =3D Line [:(len(Line)-1)] + Line =3D [Item.strip() for Item in Line.strip().split('|')] + Pcd =3D [Item.strip() for Item in Line[0].split('.',2)] + if len(Pcd) < 2: + print 'Error: PCD field sytnax error', DecLineNumber, Line + sys.exit() + elif len(Pcd) =3D=3D 2: + TokenSpaceGuidName =3D Pcd[0] + TokenName =3D Pcd[1] + Type =3D Line[2] + Packages =3D [] + NextLine =3D DecFileBuffer[DecLineNumber].strip() + DecLineNumber =3D DecLineNumber + 1 + while (NextLine[0] !=3D "}"): + if NextLine =3D=3D "": + Include =3D DecFileBuffer[DecLineNumber].strip() + DecLineNumber =3D DecLineNumber + 1 + NextLine =3D DecFileBuffer[DecLineNumber].strip() + if NextLine =3D=3D "": + DecLineNumber =3D DecLineNumber + 1 + NextLine =3D DecFileBuffer[DecLineNumber].strip() + while (NextLine[0] !=3D "}" and NextLine[0] !=3D "= <"): + Packages.append (NextLine.strip().replace ('\\= ', '/')) + DecLineNumber =3D DecLineNumber + 1 + NextLine =3D DecFileBuffer[DecLineNumber].stri= p() + DecLineNumber =3D DecLineNumber + 1 + PcdObject =3D self.AddStructuredPcd (Include, Packages, To= kenSpaceGuidName, TokenName, Type) + PcdObject.AddDefaultValue(Line[2], Line[1], self.DecFile, = DecLineNumber) + elif PcdObject <> None: + Line =3D [Item.strip() for Item in Line.strip().split('|')] + Pcd =3D [Item.strip() for Item in Line[0].split('.',2)] + if len (Line) =3D=3D 2 and len (Pcd) > 2: + if Pcd[0] <> PcdObject.TokenSpaceGuidName or Pcd[1] <> PcdOb= ject.TokenName: + print 'Error: PCD does not match parent Structured PCD', P= cd[0], Pcd[1], TokenSpaceGuidName, TokenName + sys.exit() + PcdObject.AddDefaultValue('.' + Pcd[2], Line[1], self.DecFil= e, DecLineNumber) + if not self.args.Quiet: + for Pcd in self.StructuredPcds: + print 'Include : ', Pcd.StructuredPcdIncludeFile + print 'Type : ', Pcd.TypeName + print 'SkuName : ', Pcd.SkuName + print 'DefaultStoreName : ', Pcd.DefaultStoreName + print 'TokenSpaceGuid : ', Pcd.TokenSpaceGuidName + print 'TokenName : ', Pcd.TokenName + for Field in Pcd.DefaultValues: + print ' %40s : %s' % (Field, Pcd.DefaultValues[Field][0]) + print '' + =20 + def ParseDscFile (self): + print 'Parse DSC File', self.DscFile + File =3D open (self.DscFile, mode=3D'r') + DscFileBuffer =3D File.readlines() + File.close() + PcdMode =3D None + PcdFieldSettings =3D OrderedDict({}) + DscLineNumber =3D 0 + for Line in DscFileBuffer: + DscLineNumber =3D DscLineNumber + 1 + if Line.startswith('#'): + continue + if Line.startswith('['): + Mode =3D Line[1:].split('.',1)[0].split(']',1)[0] + continue + Line =3D [Item.strip() for Item in Line.split('|')] + Pcd =3D [Item.strip() for Item in Line[0].split('.',2)] + if len(Pcd) >=3D 2 and len(Line) > 1: + PcdObject =3D self.LookupPcd (Pcd[0], Pcd[1]) + if not PcdObject: + print 'ERROR: DSC file references structured PCD that is not dec= lared in DEC file', Pcd[0], Pcd[1] + sys.exit() + if len (Pcd) =3D=3D 2: + PcdObject.AddDefaultValue (PcdObject.TypeName, Line[1], self.D= scFile, DscLineNumber) + else: + PcdObject.AddOverrideValue ('.' + Pcd[2], Line[1], self.DscFil= e, DscLineNumber) + if PcdMode and PcdMode <> Mode: + print '%d: %s: ERROR: PCD %s.%s has more than one mode %s %s.' %= (DscLineNumber, self.DscFile, Pcd[0], Pcd[1], PcdMode, Mode) + sys.exit() + PcdMode =3D Mode + PcdObject.SetPcdMode(Mode) + if not self.args.Quiet: + for Pcd in self.StructuredPcds: + print 'Include : ', Pcd.StructuredPcdIncludeFile + print 'Type : ', Pcd.TypeName + print 'SkuName : ', Pcd.SkuName + print 'DefaultStoreName : ', Pcd.DefaultStoreName + print 'TokenSpaceGuid : ', Pcd.TokenSpaceGuidName + print 'TokenName : ', Pcd.TokenName + print 'PcdMode : ', Pcd.PcdMode + for Field in Pcd.DefaultValues: + print ' D %40s : %s' % (Field, Pcd.DefaultValues[Field][0]) + for Field in Pcd.OverrideValues: + print ' O %40s : %s' % (Field, Pcd.OverrideValues[Field][0]) + print '' =20 + + def GenerateByteArrayValue (self): + # + # Generate/Compile/Run C application to determine if there are any fle= xible array members + # + InitByteValue =3D "" + CApp =3D PcdMainCHeader + =20 + Includes =3D {} + for Pcd in self.StructuredPcds: + IncludeFile =3D Pcd.StructuredPcdIncludeFile + if IncludeFile not in Includes: + Includes[IncludeFile] =3D True + CApp =3D CApp + '#include <%s>\n' % (IncludeFile) + CApp =3D CApp + '\n' + =20 + FieldNames =3D {} + for Pcd in self.StructuredPcds: + CApp =3D CApp + 'void\n' + CApp =3D CApp + 'Initialize_%s_%s_%s_%s(\n' % (Pcd.SkuName, Pcd.Defa= ultStoreName, Pcd.TokenSpaceGuidName, Pcd.TokenName) + CApp =3D CApp + ' void\n' + CApp =3D CApp + ' )\n' + CApp =3D CApp + '{\n' + CApp =3D CApp + ' UINT32 Size;\n' + CApp =3D CApp + ' UINT32 FieldSize;\n' + CApp =3D CApp + ' UINT8 *Value;\n' + CApp =3D CApp + ' %s *Pcd;\n' % (Pcd.TypeName) + CApp =3D CApp + ' UINT32 OriginalSize;\n' + CApp =3D CApp + ' VOID *OriginalPcd;\n' + CApp =3D CApp + '\n' + InitByteValue =3D '%s.%s.%s.%s|%s|' %(Pcd.SkuName, Pcd.DefaultStoreN= ame, Pcd.TokenSpaceGuidName, Pcd.TokenName, Pcd.TypeName) + + # + # Get current PCD value and size + # + CApp =3D CApp + ' OriginalPcd =3D PcdGetPtr (%s, %s, %s, %s, &Origi= nalSize);\n' % (Pcd.SkuName, Pcd.DefaultStoreName, Pcd.TokenSpaceGuidName, = Pcd.TokenName) + CApp =3D CApp + ' printf("OriginalSize =3D %d\\n", OriginalSize);\n' + =20 + =20 + # + # Determine the size of the PCD. For simple structures, sizeof(TYPE= ) provides + # the correct value. For structures with a flexible array member, t= he flexible + # array member is detected, and the size is based on the highest ind= ex used with + # the flexible array member. The flexible array member must be the = last field + # in a structure. The size formula for this case is:=20 + # OFFSET_OF(FlexbleArrayField) + sizeof(FlexibleArray[0]) * (Highest= Index + 1) + # + CApp =3D CApp + ' Size =3D sizeof(%s);\n' % (Pcd.TypeName) + CApp =3D CApp + ' printf("Size =3D %d\\n", Size);\n' + for FieldList in [Pcd.DefaultValues, Pcd.OverrideValues]: + for FieldName in FieldList: + if not FieldName.startswith('.'): + continue + IsArray =3D IsFieldValueAnArray(FieldList[FieldName][0]) + if IsArray: + Value, ValueSize =3D ParseFieldValue (FieldList[FieldName][0]) + CApp =3D CApp + ' __FLEXIBLE_SIZE(Size, %s, %s, %d / __ARRAY_= ELEMENT_SIZE(%s, %s));\n' % (Pcd.TypeName, FieldName[1:], ValueSize, Pcd.Ty= peName, FieldName[1:]); + CApp =3D CApp + ' printf("Size =3D %d\\n", Size);\n' + else: =20 + NewFieldName =3D '' + while '[' in FieldName: + NewFieldName =3D NewFieldName + FieldName.split('[',1)[0] + = '[0]' + ArrayIndex =3D int(FieldName.split('[',1)[1].split(']',1)[= 0]) + FieldName =3D FieldName.split(']',1)[1] + FieldName =3D NewFieldName + FieldName + while '[' in FieldName: + FieldName =3D FieldName.rsplit('[',1)[0] + #if not self.args.Quiet: + # print 'PCD Field: %40s' % (FieldName) + if Pcd.TypeName + FieldName not in FieldNames: + FieldNames[Pcd.TypeName + FieldName] =3D True + CApp =3D CApp + ' __FLEXIBLE_SIZE(Size, %s, %s, %d);\n' %= (Pcd.TypeName, FieldName[1:], ArrayIndex + 1) + CApp =3D CApp + ' printf("Size =3D %d\\n", Size);\n' + CApp =3D CApp + ' printf("Size =3D %d\\n", Size);\n' + + # + # Allocate and zero buffer for the PCD + # Must handle cases where current value is smaller, larger, or same = size + # Always keep that larger one as the current size + # + CApp =3D CApp + ' Size =3D (OriginalSize > Size ? OriginalSize : Si= ze);\n' + CApp =3D CApp + ' printf("Size =3D %d\\n", Size);\n' + CApp =3D CApp + ' Pcd =3D (%s *)malloc (Size);\n' % (Pcd.TypeNa= me) + CApp =3D CApp + ' memset (Pcd, 0, Size);\n' + + # + # Copy current PCD value into allocated buffer. + # + CApp =3D CApp + ' memcpy (Pcd, OriginalPcd, OriginalSize);\n' + + # + # Assign field values in PCD + # + for FieldList in [Pcd.DefaultValues, Pcd.OverrideValues]: + for FieldName in FieldList: + if not FieldName.startswith('.'): + InitByteValue =3D InitByteValue + '%s\n'%(FieldList[FieldName= ][0]) + continue + IsArray =3D IsFieldValueAnArray(FieldList[FieldName][0]) + Value, ValueSize =3D ParseFieldValue (FieldList[FieldName][0]) + #print FieldName, Value, ValueSize, IntToCString(Value, ValueSiz= e) + if isinstance(Value, str): + CApp =3D CApp + ' Pcd->%s =3D %s; // From %s Line %d Value = %s\n' % (FieldName[1:], Value, FieldList[FieldName][1], FieldList[FieldName= ][2], FieldList[FieldName][0]) + elif IsArray: + # + # Use memcpy() to copy value into field + # + CApp =3D CApp + ' FieldSize =3D __FIELD_SIZE(%s, %s);\n' % (P= cd.TypeName, FieldName[1:]) + CApp =3D CApp + ' printf("FieldSize =3D %d\\n", FieldSize);\n' + CApp =3D CApp + ' Value =3D %s; // From %s Line %d Value = %s\n' % (IntToCString(Value, ValueSize), FieldList[FieldName][1], FieldList= [FieldName][2], FieldList[FieldName][0]) + CApp =3D CApp + ' memcpy (&Pcd->%s[0], Value, (FieldSize > 0 = && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName[1:], ValueSize, Value= Size) + else: + if ValueSize > 4: + CApp =3D CApp + ' Pcd->%s =3D %dULL; // From %s Line %d Val= ue %s\n' % (FieldName[1:], Value, FieldList[FieldName][1], FieldList[FieldN= ame][2], FieldList[FieldName][0]) + else: + CApp =3D CApp + ' Pcd->%s =3D %d; // From %s Line %d Value = %s\n' % (FieldName[1:], Value, FieldList[FieldName][1], FieldList[FieldName= ][2], FieldList[FieldName][0]) + + # + # Set new PCD value and size + # + CApp =3D CApp + ' PcdSetPtr (%s, %s, %s, %s, Size, (UINT8 *)Pcd);\n= ' % (Pcd.SkuName, Pcd.DefaultStoreName, Pcd.TokenSpaceGuidName, Pcd.TokenNa= me) + + # + # Free PCD + # + CApp =3D CApp + ' free (Pcd);\n' + =20 + CApp =3D CApp + '}\n' + CApp =3D CApp + '\n' + + CApp =3D CApp + 'VOID\n' + CApp =3D CApp + 'PcdEntryPoint(\n' + CApp =3D CApp + ' VOID\n' + CApp =3D CApp + ' )\n' + CApp =3D CApp + '{\n' + for Pcd in self.StructuredPcds: + CApp =3D CApp + ' Initialize_%s_%s_%s_%s();\n' % (Pcd.SkuName, Pcd.= DefaultStoreName, Pcd.TokenSpaceGuidName, Pcd.TokenName) + CApp =3D CApp + '}\n' + =20 + CApp =3D CApp + PcdMainCEntry + '\n' + =20 + if not os.path.exists(self.OutputPath): + os.makedirs(self.OutputPath) + CAppBaseFileName =3D os.path.join(self.OutputPath, PcdValueInitName) + File =3D open (CAppBaseFileName + '.c', mode=3D'w') + File.write(CApp) + File.close() + =20 + MakeApp =3D PcdMakefileHeader + if sys.platform =3D=3D "win32": + MakeApp =3D MakeApp + 'APPNAME =3D %s\n' %(PcdValueInitName) + 'OB= JECTS =3D %s\%s.obj\n' %(self.OutputPath, PcdValueInitName) + 'INC =3D $(IN= C)' + else: + MakeApp =3D MakeApp + PcdGccMakefile + MakeApp =3D MakeApp + 'APPNAME =3D %s\n' %(PcdValueInitName) + 'OB= JECTS =3D %s/%s.o\n' %(self.OutputPath, PcdValueInitName) + \ + 'include $(MAKEROOT)/Makefiles/app.makefile\n' + 'BUILD_= CFLAGS +=3D -Wno-error\n' + 'INCLUDE +=3D' + Packages =3D {} + for Pcd in self.StructuredPcds: + for PackageDec in Pcd.PackageDecs: + Package =3D PackageDec.split('/')[0] + if Package not in Packages: + Packages[Package] =3D True + MakeApp =3D MakeApp + ' -I $(WORKSPACE)/%s/Include' %(Pack= age) + if Package =3D=3D 'MdePkg': + MakeApp =3D MakeApp + ' -I $(WORKSPACE)/%s/Include/Ia3= 2' %(Package) + MakeApp =3D MakeApp + '\n'=20 + if sys.platform =3D=3D "win32": + MakeApp =3D MakeApp + PcdMakefileEnd + MakeFileName =3D os.path.join(self.OutputPath, 'Makefile') + File =3D open (MakeFileName, mode=3D'w') + File.write(MakeApp) + File.close() + + InputValueFile =3D os.path.join(self.OutputPath, 'Input.txt') + OutputValueFile =3D os.path.join(self.OutputPath, 'Output.txt') + File =3D open (InputValueFile, mode=3D'w') + File.write(InitByteValue) + File.close() + + if sys.platform =3D=3D "win32": + StdOut, StdErr =3D ExecuteCommand ('nmake -f %s' % (MakeFileName)) + else: + StdOut, StdErr =3D ExecuteCommand ('make -f %s' % (MakeFileName)) + Messages =3D StdOut.split('\r') + for Message in Messages: + if " error " in Message: + FileInfo =3D Message.strip().split('(') + if len (FileInfo) > 0: + FileName =3D FileInfo [0] + FileLine =3D FileInfo [1].split (')')[0] + else: + FileInfo =3D Message.strip().split(':') + FileName =3D FileInfo [0] + FileLine =3D FileInfo [1] + =20 + File =3D open (FileName, mode=3D'r') + FileData =3D File.readlines() + File.close() + print Message + print FileData[int (FileLine) - 1] + return + =20 + PcdValueInitExe =3D PcdValueInitName + if not sys.platform =3D=3D "win32": + PcdValueInitExe =3D os.path.join(os.getenv("EDK_TOOLS_PATH"), 'Sou= rce', 'C', 'bin', PcdValueInitName)=20 + =20 + StdOut, StdErr =3D ExecuteCommand (PcdValueInitExe + ' -i %s -o %s' % = (InputValueFile, OutputValueFile)) + File =3D open (OutputValueFile, mode=3D'r') + FileBuffer =3D File.readlines() + File.close() + =20 + print 'Final Value Output:' + for Pcd in FileBuffer: + PcdValue =3D Pcd.split ('|') + PcdInfo =3D PcdValue[0].split ('.') + print 'SkuName : ', PcdInfo[0] + print 'TokenSpaceGuid : ', PcdInfo[2] + print 'TokenName : ', PcdInfo[3] + print 'Value : ', PcdValue[2] + +def main(): + # + # Create command line argument parser object + # + parser =3D argparse.ArgumentParser(prog=3D__prog__, version=3D__versio= n__, usage=3D__usage__, description=3D__copyright__, conflict_handler=3D're= solve') + parser.add_argument("-p", "--dec-file", dest=3D'DecFile', help=3D"DEC = File", required =3D True) + parser.add_argument("-d", "--dsc-file", dest=3D'DscFile', help=3D"DSC = File", required =3D True) + parser.add_argument("-v", "--verbose", dest=3D'Verbose', action=3D"sto= re_true", help=3D"increase output messages") + parser.add_argument("-q", "--quiet", dest=3D'Quiet', action=3D"store_t= rue", help=3D"reduce output messages") + parser.add_argument("--debug", dest=3D'Debug', type=3Dint, metavar=3D'= [0-9]', choices=3Drange(0,10), default=3D0, help=3D"set debug level") + =20 + # + # Parse command line arguments + # + args =3D parser.parse_args() + =20 + # + # Get absolute paths + # + args.DecFile =3D os.path.abspath(args.DecFile) + args.DscFile =3D os.path.abspath(args.DscFile) + =20 + # + # + # + BuildObject =3D Build(args) + BuildObject.ParseDecFile() + BuildObject.ParseDscFile() + BuildObject.GenerateByteArrayValue() + +if __name__ =3D=3D '__main__': + main() diff --git a/TestPkg/TestPkg.dec b/TestPkg/TestPkg.dec new file mode 100644 index 0000000..622678e --- /dev/null +++ b/TestPkg/TestPkg.dec @@ -0,0 +1,44 @@ +## @file TestPkg.dec +# +# Copyright (c) 2016, Intel Corporation. All rights reserved.
+# This program and the accompanying materials are licensed and made availa= ble under +# the terms and conditions of the BSD License that accompanies this distri= bution. +# The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php. +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. +# +## + + +[Defines] + DEC_SPECIFICATION =3D 0x00010005 + PACKAGE_NAME =3D TestPkg + PACKAGE_GUID =3D F05BB314-CD00-4705-BD04-59B1CD9630E1 + PACKAGE_VERSION =3D 0.1 + +[Includes] + Include + +[LibraryClasses] + +[Guids] + ## MdeModule package token space guid + # Include/Guid/MdeModulePkgTokenSpace.h + gEfiStructuredPcdPkgTokenSpaceGuid =3D { 0x11a81069, 0xa6a2, 0x420= a, { 0xa0, 0xe, 0x30, 0xc5, 0xb, 0xfb, 0xe8, 0x13 } } + +[PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx] + # @Prompt Test Strucutre + gEfiStructuredPcdPkgTokenSpaceGuid.Test|{0xFF, 0xFF}|TEST|0x00010071 { + + Guid/Test.h + + MdePkg/MdePkg.dec + TestPkg/TestPkg.dec + } + gEfiStructuredPcdPkgTokenSpaceGuid.Test.A|2 + gEfiStructuredPcdPkgTokenSpaceGuid.Test.C|20 + gEfiStructuredPcdPkgTokenSpaceGuid.Test.Array[4]|1 + gEfiStructuredPcdPkgTokenSpaceGuid.Test.Array2[0]|2 + gEfiStructuredPcdPkgTokenSpaceGuid.Test.FlexibleArray[7]|5 diff --git a/TestPkg/TestPkg.dsc b/TestPkg/TestPkg.dsc new file mode 100644 index 0000000..fc61979 --- /dev/null +++ b/TestPkg/TestPkg.dsc @@ -0,0 +1,69 @@ +## @file +# EFI/PI Reference Module Package for All Architectures +# +# (C) Copyright 2014 Hewlett-Packard Development Company, L.P.
+# Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.
+# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the= BSD License +# which accompanies this distribution. The full text of the license may= be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR = IMPLIED. +# +## + +[Defines] + PLATFORM_NAME =3D StructuredPcdPkg + PLATFORM_GUID =3D 35B4419B-4CF6-46FA-9A5D-741D0D29CD61 + PLATFORM_VERSION =3D 0.1 + DSC_SPECIFICATION =3D 0x00010005 + OUTPUT_DIRECTORY =3D Build/StructuredPcdPkg + SUPPORTED_ARCHITECTURES =3D IA32|IPF|X64|EBC|ARM|AARCH64 + BUILD_TARGETS =3D DEBUG|RELEASE|NOOPT + SKUID_IDENTIFIER =3D DEFAULT + +[LibraryClasses] + +##########################################################################= ######################### +# +# Components Section - list of the modules and components that will be pro= cessed by compilation +# tools and the EDK II tools to generate PE32/PE32+/C= off image files. +# +# Note: The EDK II DSC file is not used to specify how compiled binary ima= ges get placed +# into firmware volume images. This section is just a list of module= s to compile from +# source into UEFI-compliant binaries. +# It is the FDF file that contains information on combining binary f= iles into firmware +# volume images, whose concept is beyond UEFI and is described in PI= specification. +# Binary modules do not need to be listed in this section, as they s= hould be +# specified in the FDF file. For example: Shell binary (Shell_Full.e= fi), FAT binary (Fat.efi), +# Logo (Logo.bmp), and etc. +# There may also be modules listed in this section that are not requ= ired in the FDF file, +# When a module listed here is excluded from FDF file, then UEFI-com= pliant binary will be +# generated for it, but the binary will not be put into any firmware= volume. +# +##########################################################################= ######################### + +[PcdsFixedAtBuild] + gEfiStructuredPcdPkgTokenSpaceGuid.Test|{0xFF, 0xFF} + gEfiStructuredPcdPkgTokenSpaceGuid.Test.A|MacroTest2 + gEfiStructuredPcdPkgTokenSpaceGuid.Test.C|'a' + gEfiStructuredPcdPkgTokenSpaceGuid.Test.Array[4]|1 + gEfiStructuredPcdPkgTokenSpaceGuid.Test.Array2[0]|2 + gEfiStructuredPcdPkgTokenSpaceGuid.Test.FlexibleArray[7]|5 + gEfiStructuredPcdPkgTokenSpaceGuid.Test.FlexibleArray[4]|L'C' + gEfiStructuredPcdPkgTokenSpaceGuid.Test.FlexibleArray[3]|'b' + gEfiStructuredPcdPkgTokenSpaceGuid.Test.Array|"Hello" + gEfiStructuredPcdPkgTokenSpaceGuid.Test.Array|L"Hello" + gEfiStructuredPcdPkgTokenSpaceGuid.Test.Array|'Hello' + gEfiStructuredPcdPkgTokenSpaceGuid.Test.Array|L'Hello' + gEfiStructuredPcdPkgTokenSpaceGuid.Test.Array|GUID("6F08F62E-5C19-498E-9= 157-B59CE6F362F1") +# gEfiStructuredPcdPkgTokenSpaceGuid.Test.Array|GUID({ 0x827495c7, 0x636f= , 0x4e0c, { 0x9c, 0xcc, 0x93, 0x5e, 0xfb, 0x67, 0xf2, 0x7c } }) +# gEfiStructuredPcdPkgTokenSpaceGuid.Test.Array|{1,2,3} + gEfiStructuredPcdPkgTokenSpaceGuid.Test.FlexibleArray|"World" + gEfiStructuredPcdPkgTokenSpaceGuid.Test.FlexibleArray|L"World" +# gEfiStructuredPcdPkgTokenSpaceGuid.Test.FlexibleArray|{4, 5, 6} + + +[Components] --=20 2.8.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel