From nobody Mon Nov 25 21:35:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+63906+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+63906+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1597050636; cv=none; d=zohomail.com; s=zohoarc; b=l9+S1PplYKUchRbResv2rPIBmfwxUF0DnD2Eof1H/D4FPDrIfGwe2DOCXC0nZZntHtgFcXFn4vHZ8LELezQMHn5DhwW37tySEreMHrHQMuNrZg71bV2YAsTb9ARA7+IYkFFxi6tfjuM2+Dcla6nhHGOmmIJBGZLMAUkRfroQR7E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597050636; h=Content-Transfer-Encoding:Cc:Date:From:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=0BFjuHLXEmGY3neqxUTjfI8V4OZbCWOYKvFim5dWEVo=; b=P637rNRvzR5KjUR1LYA7LlgRFWBaUcZp/8InLOl14cvFCqdHmzwh/wptuLDrapNIuw2SaE+2bGnDPT7Z7gnbNvhDU96AWjaJyYXLa/rHX/LIvOHNe9BM2qfckVuahVksSol1vvCCxofcAEGrVfrrlH7UAVYnP4LQE6u/a9rwV7o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+63906+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1597050636377133.1778751243029; Mon, 10 Aug 2020 02:10:36 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id uo0xYY1788612xoOoNi6vxqh; Mon, 10 Aug 2020 02:10:34 -0700 X-Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by mx.groups.io with SMTP id smtpd.web10.41338.1597050633325791147 for ; Mon, 10 Aug 2020 02:10:33 -0700 IronPort-SDR: 57WEM0PpkK6WeouUg17F57Jm/c7dfeLpoYgsKw0s8XgduLFm+eqS3GOe4Yh1vSV6BuZqvmRXOV 1jAFIt7/jeXw== X-IronPort-AV: E=McAfee;i="6000,8403,9708"; a="153465378" X-IronPort-AV: E=Sophos;i="5.75,457,1589266800"; d="scan'208";a="153465378" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Aug 2020 02:10:32 -0700 IronPort-SDR: Wny4qekbQ6G11QZRzuM4R9nt3wbWcHu46pUvmTy33mKK6JSgyfWk8gpyPo4RdgVCpog+hNjTsY vdUer0rySAHg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,457,1589266800"; d="scan'208";a="317283206" X-Received: from shwdepsi1121.ccr.corp.intel.com ([10.239.158.66]) by fmsmga004.fm.intel.com with ESMTP; 10 Aug 2020 02:10:30 -0700 From: "Bob Feng" To: devel@edk2.groups.io Cc: Liming Gao , Yuwei Chen Subject: [edk2-devel] [Patch] BaseTools: Enable Module Scope Structure Pcd Date: Mon, 10 Aug 2020 17:10:26 +0800 Message-Id: <20200810091026.37276-1-bob.c.feng@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,bob.c.feng@intel.com X-Gm-Message-State: adC1fXJ8P1DfUTEDRDzbd8H3x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1597050634; bh=P+HM0qqAXBEGm5KHI4+aYQVk2HDdRE1+oDlCU3++Ilo=; h=Cc:Date:From:Reply-To:Subject:To; b=TehNt5XVHeZwLFXkKkKrBWDy7MXGRjq1M6u2m4hv3Uy3UppNSQ3FzQRQixNZU4GLJjP yd2UM5ykgukjyZLaWKdYscqAIIISmVcAgnu9yOeCGllsqfsMDKJyIZIoSkIOjowCrgjuy frfAFz4U+8qsDeCdvftfoZBZe9t5E3pfRh4= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" This patch is to enable the Module scoped Structure Pcd usage. User can set structure pcd field value in module scope. For example, under the [components] section of a dsc file, user can override some field value for a specific module. Package/Module.inf{ gUefiTokenSpaceGuid.StructurePcdModule.FieldName | 5 } Signed-off-by: Bob Feng Cc: Liming Gao Cc: Yuwei Chen --- BaseTools/Source/Python/AutoGen/DataPipe.py | 5 +- .../Source/Python/AutoGen/ModuleAutoGen.py | 4 +- .../Python/AutoGen/ModuleAutoGenHelper.py | 10 +- .../Source/Python/AutoGen/PlatformAutoGen.py | 8 +- .../Python/Workspace/BuildClassObject.py | 12 + .../Source/Python/Workspace/DscBuildData.py | 242 ++++++++++++++++-- 6 files changed, 256 insertions(+), 25 deletions(-) diff --git a/BaseTools/Source/Python/AutoGen/DataPipe.py b/BaseTools/Source= /Python/AutoGen/DataPipe.py index 50403fbfb5..86ac2b928d 100755 --- a/BaseTools/Source/Python/AutoGen/DataPipe.py +++ b/BaseTools/Source/Python/AutoGen/DataPipe.py @@ -70,13 +70,14 @@ class MemoryDataPipe(DataPipe): } =20 #Platform Module Pcds ModulePcds =3D {} for m in PlatformInfo.Platform.Modules: - m_pcds =3D PlatformInfo.Platform.Modules[m].Pcds + module =3D PlatformInfo.Platform.Modules[m] + m_pcds =3D module.Pcds if m_pcds: - ModulePcds[(m.File,m.Root,m.Arch)] =3D [PCD_DATA( + ModulePcds[module.Guid] =3D [PCD_DATA( pcd.TokenCName,pcd.TokenSpaceGuidCName,pcd.Type, pcd.DatumType,pcd.SkuInfoList,pcd.DefaultValue, pcd.MaxDatumSize,pcd.UserDefinedDefaultStoresFlag,pcd.validate= ranges, pcd.validlists,pcd.expressions,pcd.CustomAttribute,pcd.To= kenValue) for pcd in PlatformInfo.Platform.Modules[m].Pcds.values()] diff --git a/BaseTools/Source/Python/AutoGen/ModuleAutoGen.py b/BaseTools/S= ource/Python/AutoGen/ModuleAutoGen.py index dc8b1fe3d1..273bde117f 100755 --- a/BaseTools/Source/Python/AutoGen/ModuleAutoGen.py +++ b/BaseTools/Source/Python/AutoGen/ModuleAutoGen.py @@ -1030,11 +1030,11 @@ class ModuleAutoGen(AutoGen): # @retval list The list of PCD # @cached_property def ModulePcdList(self): # apply PCD settings from platform - RetVal =3D self.PlatformInfo.ApplyPcdSetting(self.Module, self.Mod= ule.Pcds) + RetVal =3D self.PlatformInfo.ApplyPcdSetting(self, self.Module.Pcd= s) =20 return RetVal @cached_property def _PcdComments(self): ReVal =3D OrderedListDict() @@ -1061,11 +1061,11 @@ class ModuleAutoGen(AutoGen): # skip duplicated PCDs if Key in self.Module.Pcds or Key in Pcds: continue Pcds.add(Key) PcdsInLibrary[Key] =3D copy.copy(Library.Pcds[Key]) - RetVal.extend(self.PlatformInfo.ApplyPcdSetting(self.Module, P= cdsInLibrary, Library=3DLibrary)) + RetVal.extend(self.PlatformInfo.ApplyPcdSetting(self, PcdsInLi= brary, Library=3DLibrary)) return RetVal =20 ## Get the GUID value mapping # # @retval dict The mapping between GUID cname and its value diff --git a/BaseTools/Source/Python/AutoGen/ModuleAutoGenHelper.py b/BaseT= ools/Source/Python/AutoGen/ModuleAutoGenHelper.py index 9dd93b9beb..8e60643d1f 100644 --- a/BaseTools/Source/Python/AutoGen/ModuleAutoGenHelper.py +++ b/BaseTools/Source/Python/AutoGen/ModuleAutoGenHelper.py @@ -477,12 +477,13 @@ class PlatformInfo(AutoGenInfo): SkuName =3D TAB_DEFAULT ToPcd.SkuInfoList =3D { SkuName : SkuInfoClass(SkuName, self.Platform.SkuIds[SkuNa= me][0], '', '', '', '', '', ToPcd.DefaultValue) } =20 - def ApplyPcdSetting(self, Module, Pcds, Library=3D""): + def ApplyPcdSetting(self, Ma, Pcds, Library=3D""): # for each PCD in module + Module=3DMa.Module for Name, Guid in Pcds: PcdInModule =3D Pcds[Name, Guid] # find out the PCD setting in platform if (Name, Guid) in self.Pcds: PcdInPlatform =3D self.Pcds[Name, Guid] @@ -505,13 +506,16 @@ class PlatformInfo(AutoGenInfo): % (Guid, Name, str= (Module)), File=3Dself.MetaFile ) =20 # override PCD settings with module specific setting + ModuleScopePcds =3D self.DataPipe.Get("MOL_PCDS") if Module in self.Platform.Modules: PlatformModule =3D self.Platform.Modules[str(Module)] - for Key in PlatformModule.Pcds: + PCD_DATA =3D ModuleScopePcds.get(Ma.Guid,{}) + mPcds =3D {(pcd.TokenCName,pcd.TokenSpaceGuidCName): pcd for p= cd in PCD_DATA} + for Key in mPcds: if self.BuildOptionPcd: for pcd in self.BuildOptionPcd: (TokenSpaceGuidCName, TokenCName, FieldName, pcdva= lue, _) =3D pcd if (TokenCName, TokenSpaceGuidCName) =3D=3D Key an= d FieldName =3D=3D"": PlatformModule.Pcds[Key].DefaultValue =3D pcdv= alue @@ -526,11 +530,11 @@ class PlatformInfo(AutoGenInfo): if PcdItem in Pcds: ToPcd =3D Pcds[PcdItem] Flag =3D True break if Flag: - self._OverridePcd(ToPcd, PlatformModule.Pcds[Key], Mod= ule, Msg=3D"DSC Components Module scoped PCD section", Library=3DLibrary) + self._OverridePcd(ToPcd, mPcds[Key], Module, Msg=3D"DS= C Components Module scoped PCD section", Library=3DLibrary) # use PCD value to calculate the MaxDatumSize when it is not speci= fied for Name, Guid in Pcds: Pcd =3D Pcds[Name, Guid] if Pcd.DatumType =3D=3D TAB_VOID and not Pcd.MaxDatumSize: Pcd.MaxSizeUserSet =3D None diff --git a/BaseTools/Source/Python/AutoGen/PlatformAutoGen.py b/BaseTools= /Source/Python/AutoGen/PlatformAutoGen.py index af66c48c7d..b64dce86bf 100644 --- a/BaseTools/Source/Python/AutoGen/PlatformAutoGen.py +++ b/BaseTools/Source/Python/AutoGen/PlatformAutoGen.py @@ -1041,11 +1041,17 @@ class PlatformAutoGen(AutoGen): TokenNumber +=3D 1 return RetVal =20 @cached_property def _MbList(self): - return [self.BuildDatabase[m, self.Arch, self.BuildTarget, self.To= olChain] for m in self.Platform.Modules] + mlist =3D [] + for m in self.Platform.Modules: + component =3D self.Platform.Modules[m] + module =3D self.BuildDatabase[m, self.Arch, self.BuildTarget, = self.ToolChain] + module.Guid =3D component.Guid + mlist.append(module) + return mlist =20 @cached_property def _MaList(self): for ModuleFile in self.Platform.Modules: Ma =3D ModuleAutoGen( diff --git a/BaseTools/Source/Python/Workspace/BuildClassObject.py b/BaseTo= ols/Source/Python/Workspace/BuildClassObject.py index db40e3b10c..ebb65fc2fe 100644 --- a/BaseTools/Source/Python/Workspace/BuildClassObject.py +++ b/BaseTools/Source/Python/Workspace/BuildClassObject.py @@ -68,10 +68,11 @@ class PcdClassObject(object): self.DscRawValueInfo =3D {} if IsDsc: self.DscDefaultValue =3D Value self.PcdValueFromComm =3D "" self.PcdValueFromFdf =3D "" + self.PcdValueFromComponents =3D {} #{ModuleGuid:value, file_path,l= ineNo} self.CustomAttribute =3D {} self.UserDefinedDefaultStoresFlag =3D UserDefinedDefaultStoresFlag self._Capacity =3D None =20 @property @@ -296,10 +297,11 @@ class StructurePcd(PcdClassObject): self.DefaultValueFromDecInfo =3D None self.ValueChain =3D set() self.PcdFieldValueFromComm =3D OrderedDict() self.PcdFieldValueFromFdf =3D OrderedDict() self.DefaultFromDSC=3DNone + self.PcdFiledValueFromDscComponent =3D OrderedDict() def __repr__(self): return self.TypeName =20 def AddDefaultValue (self, FieldName, Value, FileName=3D"", LineNo=3D0= ,DimensionAttr =3D"-1"): if DimensionAttr not in self.DefaultValues: @@ -322,10 +324,16 @@ class StructurePcd(PcdClassObject): if FieldName in self.SkuOverrideValues[SkuName][DefaultStoreName][= DimensionAttr]: del self.SkuOverrideValues[SkuName][DefaultStoreName][Dimensio= nAttr][FieldName] self.SkuOverrideValues[SkuName][DefaultStoreName][DimensionAttr][F= ieldName] =3D [Value.strip(), FileName, LineNo] return self.SkuOverrideValues[SkuName][DefaultStoreName][Dimension= Attr][FieldName] =20 + def AddComponentOverrideValue(self,FieldName, Value, ModuleGuid, FileN= ame=3D"", LineNo=3D0, DimensionAttr =3D '-1'): + self.PcdFiledValueFromDscComponent.setdefault(ModuleGuid, OrderedD= ict()) + self.PcdFiledValueFromDscComponent[ModuleGuid].setdefault(Dimensio= nAttr,OrderedDict()) + self.PcdFiledValueFromDscComponent[ModuleGuid][DimensionAttr][Fiel= dName] =3D [Value.strip(), FileName, LineNo] + return self.PcdFiledValueFromDscComponent[ModuleGuid][DimensionAtt= r][FieldName] + def SetPcdMode (self, PcdMode): self.PcdMode =3D PcdMode =20 def copy(self, PcdObject): self.TokenCName =3D PcdObject.TokenCName if PcdObject.TokenCName e= lse self.TokenCName @@ -363,10 +371,11 @@ class StructurePcd(PcdClassObject): self.PcdDefineLineNo =3D PcdObject.PcdDefineLineNo if PcdObjec= t.PcdDefineLineNo else self.PcdDefineLineNo self.PkgPath =3D PcdObject.PkgPath if PcdObject.PkgPath else s= elf.PkgPath self.ValueChain =3D PcdObject.ValueChain if PcdObject.ValueCha= in else self.ValueChain self.PcdFieldValueFromComm =3D PcdObject.PcdFieldValueFromComm= if PcdObject.PcdFieldValueFromComm else self.PcdFieldValueFromComm self.PcdFieldValueFromFdf =3D PcdObject.PcdFieldValueFromFdf i= f PcdObject.PcdFieldValueFromFdf else self.PcdFieldValueFromFdf + self.PcdFiledValueFromDscComponent =3D PcdObject.PcdFiledValue= FromDscComponent if PcdObject.PcdFiledValueFromDscComponent else self.PcdFi= ledValueFromDscComponent =20 def __deepcopy__(self,memo): new_pcd =3D StructurePcd() self.sharedcopy(new_pcd) =20 @@ -381,10 +390,11 @@ class StructurePcd(PcdClassObject): new_pcd.DefaultValues =3D CopyDict(self.DefaultValues) new_pcd.DefaultFromDSC=3DCopyDict(self.DefaultFromDSC) new_pcd.SkuOverrideValues =3D CopyDict(self.SkuOverrideValues) new_pcd.PcdFieldValueFromComm =3D CopyDict(self.PcdFieldValueFromC= omm) new_pcd.PcdFieldValueFromFdf =3D CopyDict(self.PcdFieldValueFromFd= f) + new_pcd.PcdFiledValueFromDscComponent =3D CopyDict(self.PcdFiledVa= lueFromDscComponent) new_pcd.ValueChain =3D {item for item in self.ValueChain} return new_pcd =20 LibraryClassObject =3D namedtuple('LibraryClassObject', ['LibraryClass','S= upModList']) =20 @@ -461,10 +471,12 @@ class ModuleBuildClassObject(object): self.Includes =3D [] self.Packages =3D [] self.Pcds =3D {} self.BuildOptions =3D {} self.Depex =3D {} + self.StrPcdSet =3D [] + self.StrPcdOverallValue =3D {} =20 ## Convert the class to a string # # Convert member MetaFile of the class to a string # diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/= Source/Python/Workspace/DscBuildData.py index 1afbd3eefc..14ba0a6cd5 100644 --- a/BaseTools/Source/Python/Workspace/DscBuildData.py +++ b/BaseTools/Source/Python/Workspace/DscBuildData.py @@ -753,13 +753,14 @@ class DscBuildData(PlatformBuildClassObject): ErrorCode, ErrorInfo =3D ModuleFile.Validate('.inf') if ErrorCode !=3D 0: EdkLogger.error('build', ErrorCode, File=3Dself.MetaFile, = Line=3DLineNo, ExtraData=3DErrorInfo) =20 + ModuleBuildData =3D self._Bdb[ModuleFile, self._Arch, self._Ta= rget, self._Toolchain] Module =3D ModuleBuildClassObject() Module.MetaFile =3D ModuleFile - + Module.Guid =3D ModuleBuildData.Guid # get module private library instance RecordList =3D self._RawData[MODEL_EFI_LIBRARY_CLASS, self._Ar= ch, None, ModuleId] for Record in RecordList: LibraryClass =3D Record[0] LibraryPath =3D PathClass(NormPath(Record[1], Macros), Glo= balData.gWorkspace, Arch=3Dself._Arch) @@ -776,11 +777,11 @@ class DscBuildData(PlatformBuildClassObject): LibraryClass =3D 'NULL%d' % self._NullLibraryNumber EdkLogger.verbose("Found forced library for %s\n\t%s [= %s]" % (ModuleFile, LibraryPath, LibraryClass)) Module.LibraryClasses[LibraryClass] =3D LibraryPath if LibraryPath not in self.LibraryInstances: self.LibraryInstances.append(LibraryPath) - + S_PcdSet =3D [] # get module private PCD setting for Type in [MODEL_PCD_FIXED_AT_BUILD, MODEL_PCD_PATCHABLE_IN_= MODULE, \ MODEL_PCD_FEATURE_FLAG, MODEL_PCD_DYNAMIC, MODEL_= PCD_DYNAMIC_EX]: RecordList =3D self._RawData[Type, self._Arch, None, Modul= eId] for TokenSpaceGuid, PcdCName, Setting, Dummy1, Dummy2, Dum= my3, Dummy4, Dummy5 in RecordList: @@ -790,24 +791,35 @@ class DscBuildData(PlatformBuildClassObject): if len(TokenList) > 2: MaxDatumSize =3D TokenList[2] else: MaxDatumSize =3D '' TypeString =3D self._PCD_TYPE_STRING_[Type] - Pcd =3D PcdClassObject( - PcdCName, - TokenSpaceGuid, - TypeString, - '', - DefaultValue, - '', - MaxDatumSize, - {}, - False, - None - ) - Module.Pcds[PcdCName, TokenSpaceGuid] =3D Pcd =20 + TCName,PCName,DimensionAttr,Field =3D self.ParsePcdNam= eStruct(TokenSpaceGuid, PcdCName) + + if ("." in TokenSpaceGuid or "[" in PcdCName): + S_PcdSet.append([ TCName,PCName,DimensionAttr,Fiel= d, ModuleBuildData.Guid, "", Dummy5, AnalyzePcdExpression(Setting)[0]]) + DefaultValue =3D '' + if ( PCName,TCName) not in Module.Pcds: + Pcd =3D PcdClassObject( + PCName, + TCName, + TypeString, + '', + DefaultValue, + '', + MaxDatumSize, + {}, + False, + None + ) + Module.Pcds[PCName, TCName] =3D Pcd + + Module.StrPcdSet =3D S_PcdSet + for TCName,PCName, _,_,_,_,_,_ in S_PcdSet: + if (PCName,TCName) in Module.Pcds: + Module.StrPcdOverallValue[(PCName,TCName)] =3D Module.= Pcds[(PCName,TCName)].DefaultValue, self.MetaFile,Dummy5 # get module private build options RecordList =3D self._RawData[MODEL_META_DATA_BUILD_OPTION, sel= f._Arch, None, ModuleId] for ToolChainFamily, ToolChain, Option, Dummy1, Dummy2, Dummy3= , Dummy4, Dummy5 in RecordList: if (ToolChainFamily, ToolChain) not in Module.BuildOptions: Module.BuildOptions[ToolChainFamily, ToolChain] =3D Op= tion @@ -820,11 +832,13 @@ class DscBuildData(PlatformBuildClassObject): if len(RecordList) !=3D 1: EdkLogger.error('build', OPTION_UNKNOWN, 'Only FILE_GU= ID can be listed in section.', File=3Dself.MetaFile, ExtraData=3Dstr(= ModuleFile), Line=3DLineNo) ModuleFile =3D ProcessDuplicatedInf(ModuleFile, RecordList= [0][2], GlobalData.gWorkspace) ModuleFile.Arch =3D self._Arch - + Module.Guid =3D RecordList[0][2] + for item in Module.StrPcdSet: + item[4] =3D RecordList[0][2] self._Modules[ModuleFile] =3D Module return self._Modules =20 ## Retrieve all possible library instances used in this platform @property @@ -1497,11 +1511,19 @@ class DscBuildData(PlatformBuildClassObject): EdkLogger.error('build', PARSER_ERROR, "Pcd (%s.%s) is not declared as Structure = PCD in DEC files. Arch: ['%s']" % (TCName, PCName, self._Arch), File=3Dself.MetaFile, Line =3D Dummy5) =20 S_PcdSet.append([ TCName,PCName,DimensionAttr,Field, SkuNa= me, default_store, Dummy5, AnalyzePcdExpression(Setting)[0]]) - + ModuleScopeOverallValue =3D {} + for m in self.Modules.values(): + mguid =3D m.Guid + if m.StrPcdSet: + S_PcdSet.extend(m.StrPcdSet) + mguid =3D m.StrPcdSet[0][4] + for (PCName,TCName) in m.StrPcdOverallValue: + Value, dsc_file, lineNo =3D m.StrPcdOverallValue[(PCName,T= CName)] + ModuleScopeOverallValue.setdefault((PCName,TCName),{})[mgu= id] =3D Value, dsc_file, lineNo # handle pcd value override StrPcdSet =3D DscBuildData.GetStructurePcdInfo(S_PcdSet) S_pcd_set =3D OrderedDict() for str_pcd in StrPcdSet: str_pcd_obj =3D Pcds.get((str_pcd[1], str_pcd[0]), None) @@ -1515,10 +1537,15 @@ class DscBuildData(PlatformBuildClassObject): else: str_pcd_obj_str.DefaultFromDSC =3D {skuname:{defaultst= ore: str_pcd_obj.SkuInfoList[skuname].DefaultStoreDict.get(defaultstore, st= r_pcd_obj.SkuInfoList[skuname].DefaultValue) for defaultstore in DefaultSto= res} for skuname in str_pcd_obj.SkuInfoList} for str_pcd_data in StrPcdSet[str_pcd]: if str_pcd_data[4] in SkuIds: str_pcd_obj_str.AddOverrideValue(str_pcd_data[3], str(= str_pcd_data[7]), TAB_DEFAULT if str_pcd_data[4] =3D=3D TAB_COMMON else str= _pcd_data[4], TAB_DEFAULT_STORES_DEFAULT if str_pcd_data[5] =3D=3D TAB_COMM= ON else str_pcd_data[5], self.MetaFile.File if self.WorkspaceDir not in sel= f.MetaFile.File else self.MetaFile.File[len(self.WorkspaceDir) if self.Work= spaceDir.endswith(os.path.sep) else len(self.WorkspaceDir)+1:], LineNo=3Dst= r_pcd_data[6],DimensionAttr =3D str_pcd_data[2]) + elif GlobalData.gGuidPattern.match(str_pcd_data[4]): + str_pcd_obj_str.AddComponentOverrideValue(str_pcd_data= [3], str(str_pcd_data[7]), str_pcd_data[4].replace("-","S"), self.MetaFile.= File if self.WorkspaceDir not in self.MetaFile.File else self.MetaFile.File= [len(self.WorkspaceDir) if self.WorkspaceDir.endswith(os.path.sep) else len= (self.WorkspaceDir)+1:], LineNo=3Dstr_pcd_data[6],DimensionAttr =3D str_pcd= _data[2]) + PcdComponentValue =3D ModuleScopeOverallValue.get((str= _pcd_obj_str.TokenCName,str_pcd_obj_str.TokenSpaceGuidCName)) + for module_guid in PcdComponentValue: + str_pcd_obj_str.PcdValueFromComponents[module_guid= .replace("-","S")] =3D PcdComponentValue[module_guid] S_pcd_set[str_pcd[1], str_pcd[0]] =3D str_pcd_obj_str =20 # Add the Structure PCD that only defined in DEC, don't have overr= ide in DSC file for Pcd in self.DecPcds: if isinstance(self._DecPcds[Pcd], StructurePcd): @@ -1573,10 +1600,12 @@ class DscBuildData(PlatformBuildClassObject): if defaultstoreid not in stru_pcd.SkuOverrideValue= s[skuid]: stru_pcd.SkuOverrideValues[skuid][defaultstore= id] =3D CopyDict(stru_pcd.SkuOverrideValues[nextskuid][mindefaultstorename]) stru_pcd.ValueChain.add((skuid, defaultstoreid= )) S_pcd_set =3D DscBuildData.OverrideByFdf(S_pcd_set,self.WorkspaceD= ir) S_pcd_set =3D DscBuildData.OverrideByComm(S_pcd_set) + + # Create a tool to caculate structure pcd value Str_Pcd_Values =3D self.GenerateByteArrayValue(S_pcd_set) if Str_Pcd_Values: for (skuname, StoreName, PcdGuid, PcdName, PcdValue) in Str_Pc= d_Values: str_pcd_obj =3D S_pcd_set.get((PcdName, PcdGuid)) if str_pcd_obj is None: @@ -1591,10 +1620,18 @@ class DscBuildData(PlatformBuildClassObject): str_pcd_obj.SkuInfoList[skuname].DefaultStoreDict.= update({StoreName:PcdValue}) elif str_pcd_obj.Type in [self._PCD_TYPE_STRING_[MODEL_PCD= _FIXED_AT_BUILD], self._PCD_TYPE_STRING_[MODEL_PCD_P= ATCHABLE_IN_MODULE]]: if skuname in (self.SkuIdMgr.SystemSkuId, TAB_DEFAULT,= TAB_COMMON): str_pcd_obj.DefaultValue =3D PcdValue + else: + #Module Scope Structure Pcd + moduleguid =3D skuname.replace("S","-") + if GlobalData.gGuidPattern.match(moduleguid): + for component in self.Modules.values(): + if component.Guid =3D=3D moduleguid: + component.Pcds[(PcdName, PcdGuid)].Def= aultValue =3D PcdValue + else: if skuname not in str_pcd_obj.SkuInfoList: nextskuid =3D self.SkuIdMgr.GetNextSkuId(skuname) NoDefault =3D False while nextskuid not in str_pcd_obj.SkuInfoList: @@ -2339,10 +2376,79 @@ class DscBuildData(PlatformBuildClassObject): else: CApp =3D CApp + ' Pcd->%s =3D %d; // From %s Line= %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[Fie= ldName][2], FieldList[FieldName][0]) CApp =3D CApp + "}\n" return CApp =20 + def GenerateModuleScopeValue(self, Pcd): + CApp =3D "// Value in Dsc Module scope \n" + for ModuleGuid in Pcd.PcdFiledValueFromDscComponent: + + CApp =3D CApp + "void Assign_%s_%s_%s_Value(%s *Pcd){\n" % (Pc= d.TokenSpaceGuidCName, Pcd.TokenCName, ModuleGuid,Pcd.BaseDatumType) + CApp =3D CApp + ' UINT32 FieldSize;\n' + CApp =3D CApp + ' CHAR8 *Value;\n' + pcddefaultvalue, file_path,lineNo =3D Pcd.PcdValueFromComponen= ts.get(ModuleGuid,(None,None,None)) + + if pcddefaultvalue: + IsArray =3D _IsFieldValueAnArray(pcddefaultvalue) + if IsArray: + try: + FieldList =3D ValueExpressionEx(pcddefaultvalue, T= AB_VOID)(True) + except BadExpression: + EdkLogger.error("Build", FORMAT_INVALID, "Invalid = value format for %s.%s, from %s Line %s: %s" % + (Pcd.TokenSpaceGuidCName, Pcd.Toke= nCName, file_path, lineNo, FieldList)) + Value, ValueSize =3D ParseFieldValue (FieldList) + + if isinstance(Value, str): + CApp =3D CApp + ' Pcd =3D %s; // From %s Line %s \n' = % (Value, file_path, lineNo) + elif IsArray: + # + # Use memcpy() to copy value into field + # + CApp =3D CApp + ' Value =3D %s; // From %s Line %= s.\n' % (DscBuildData.IntToCString(Value, ValueSize), file_path, lineNo) + CApp =3D CApp + ' memcpy (Pcd, Value, %d);\n' % (Valu= eSize) + + + PcdFiledValue =3D Pcd.PcdFiledValueFromDscComponent.get(Module= Guid) + for index in PcdFiledValue: + FieldList =3D PcdFiledValue[index] + if not FieldList: + continue + for FieldName in FieldList: + IsArray =3D _IsFieldValueAnArray(FieldList[FieldName][= 0]) + if IsArray: + try: + FieldList[FieldName][0] =3D ValueExpressionEx(= FieldList[FieldName][0], TAB_VOID, self._GuidDict)(True) + except BadExpression: + EdkLogger.error('Build', FORMAT_INVALID, "Inva= lid value format for %s. From %s Line %d " % + (".".join((Pcd.TokenSpaceGuidC= Name, Pcd.TokenCName, FieldName)), FieldList[FieldName][1], FieldList[Field= Name][2])) + except: + print("error") + try: + Value, ValueSize =3D ParseFieldValue (FieldList[Fi= eldName][0]) + except Exception: + EdkLogger.error('Build', FORMAT_INVALID, "Invalid = value format for %s. From %s Line %d " % (".".join((Pcd.TokenSpaceGuidCName= , Pcd.TokenCName, FieldName)), FieldList[FieldName][1], FieldList[FieldName= ][2])) + if isinstance(Value, str): + CApp =3D CApp + ' Pcd->%s =3D %s; // From %s Line= %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[Fie= ldName][2], FieldList[FieldName][0]) + elif IsArray: + # + # Use memcpy() to copy value into field + # + CApp =3D CApp + ' FieldSize =3D __FIELD_SIZE(%s, = %s);\n' % (Pcd.BaseDatumType, FieldName) + CApp =3D CApp + ' Value =3D %s; // From %s Li= ne %d Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), FieldList= [FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0]) + CApp =3D CApp + ' __STATIC_ASSERT((__FIELD_SIZE(%= s, %s) >=3D %d) || (__FIELD_SIZE(%s, %s) =3D=3D 0), "Input buffer exceeds t= he buffer array"); // From %s Line %d Value %s\n' % (Pcd.BaseDatumType, Fie= ldName, ValueSize, Pcd.BaseDatumType, FieldName, FieldList[FieldName][1], F= ieldList[FieldName][2], FieldList[FieldName][0]) + CApp =3D CApp + ' memcpy (&Pcd->%s, Value, (Field= Size > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, = ValueSize) + else: + if '[' in FieldName and ']' in FieldName: + Index =3D int(FieldName.split('[')[1].split(']= ')[0]) + CApp =3D CApp + ' __STATIC_ASSERT((%d < __ARR= AY_SIZE(Pcd->%s)) || (__ARRAY_SIZE(Pcd->%s) =3D=3D 0), "array index exceeds= the array number"); // From %s Line %d Index of %s\n' % (Index, FieldName.= split('[')[0], FieldName.split('[')[0], FieldList[FieldName][1], FieldList[= FieldName][2], FieldName) + if ValueSize > 4: + CApp =3D CApp + ' Pcd->%s =3D %dULL; // From = %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldL= ist[FieldName][2], FieldList[FieldName][0]) + else: + CApp =3D CApp + ' Pcd->%s =3D %d; // From %s = Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList= [FieldName][2], FieldList[FieldName][0]) + CApp =3D CApp + "}\n" + return CApp + @staticmethod def GenerateCommandLineValueStatement(Pcd): CApp =3D ' Assign_%s_%s_CommandLine_Value(Pcd);\n' % (Pcd.TokenSp= aceGuidCName, Pcd.TokenCName) return CApp def GenerateFdfValue(self,Pcd): @@ -2412,10 +2518,88 @@ class DscBuildData(PlatformBuildClassObject): @staticmethod def GenerateFdfValueStatement(Pcd): CApp =3D ' Assign_%s_%s_Fdf_Value(Pcd);\n' % (Pcd.TokenSpaceGuidC= Name, Pcd.TokenCName) return CApp =20 + @staticmethod + def GenerateModuleValueStatement(module_guid, Pcd): + CApp =3D " Assign_%s_%s_%s_Value(Pcd);\n" % (Pcd.TokenSpaceGuidCN= ame, Pcd.TokenCName, module_guid) + return CApp + def GenerateModuleScopeInitializeFunc(self,SkuName, Pcd, InitByteValu= e, CApp): + for module_guid in Pcd.PcdFiledValueFromDscComponent: + CApp =3D CApp + 'void\n' + CApp =3D CApp + 'Initialize_%s_%s_%s_%s(\n' % (module_guid, TA= B_DEFAULT_STORES_DEFAULT, Pcd.TokenSpaceGuidCName, Pcd.TokenCName) + 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 + ' CHAR8 *Value;\n' + CApp =3D CApp + ' UINT32 OriginalSize;\n' + CApp =3D CApp + ' VOID *OriginalPcd;\n' + + CApp =3D CApp + ' %s *Pcd; // From %s Line %d \n' % (Pc= d.BaseDatumType,Pcd.PkgPath, Pcd.PcdDefineLineNo) + + CApp =3D CApp + '\n' + + PcdDefaultValue =3D StringToArray(Pcd.DefaultValueFromDec.stri= p()) + InitByteValue +=3D '%s.%s.%s.%s|%s|%s\n' % (module_guid, TAB_D= EFAULT_STORES_DEFAULT, Pcd.TokenSpaceGuidCName, Pcd.TokenCName, Pcd.DatumTy= pe, PcdDefaultValue) + # + # Get current PCD value and size + # + CApp =3D CApp + ' OriginalPcd =3D PcdGetPtr (%s, %s, %s, %s, = &OriginalSize);\n' % (module_guid, TAB_DEFAULT_STORES_DEFAULT, Pcd.TokenSpa= ceGuidCName, Pcd.TokenCName) + + # + # Determine the size of the PCD. For simple structures, sizeo= f(TYPE) provides + # the correct value. For structures with a flexible array mem= ber, the flexible + # array member is detected, and the size is based on the highe= st index used with + # the flexible array member. The flexible array member must b= e the last field + # in a structure. The size formula for this case is: + # OFFSET_OF(FlexbleArrayField) + sizeof(FlexibleArray[0]) * (H= ighestIndex + 1) + # + CApp =3D CApp + DscBuildData.GenerateSizeStatments(Pcd,SkuName= ,TAB_DEFAULT_STORES_DEFAULT) + if Pcd.IsArray() and Pcd.Capacity[-1] !=3D "-1": + CApp =3D CApp + ' OriginalSize =3D OriginalSize < sizeof(= %s) * %d? OriginalSize:sizeof(%s) * %d; \n' % (Pcd.BaseDatumType,Pcd.PcdArr= aySize(),Pcd.BaseDatumType,Pcd.PcdArraySize()) + CApp =3D CApp + ' Size =3D sizeof(%s) * %d; \n' % (Pcd.Ba= seDatumType,Pcd.PcdArraySize()) + + # + # 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 ? OriginalSiz= e : Size);\n' + CApp =3D CApp + ' Pcd =3D (%s *)malloc (Size);\n' % (Pcd.= BaseDatumType,) + 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 + # + CApp =3D CApp + DscBuildData.GenerateDefaultValueAssignStateme= nt(Pcd) + + CApp =3D CApp + "// SkuName: %s, DefaultStoreName: STANDARD \= n" % self.SkuIdMgr.SystemSkuId + CApp =3D CApp + DscBuildData.GenerateInitValueStatement(Pcd, s= elf.SkuIdMgr.SystemSkuId, TAB_DEFAULT_STORES_DEFAULT) + CApp =3D CApp + DscBuildData.GenerateFdfValueStatement(Pcd) + CApp =3D CApp + DscBuildData.GenerateCommandLineValueStatement= (Pcd) + CApp =3D CApp + DscBuildData.GenerateModuleValueStatement(modu= le_guid,Pcd) + # + # Set new PCD value and size + # + CApp =3D CApp + ' PcdSetPtr (%s, %s, %s, %s, Size, (void *)Pc= d);\n' % (module_guid, TAB_DEFAULT_STORES_DEFAULT, Pcd.TokenSpaceGuidCName,= Pcd.TokenCName) + + # + # Free PCD + # + CApp =3D CApp + ' free (Pcd);\n' + CApp =3D CApp + '}\n' + CApp =3D CApp + '\n' + return InitByteValue,CApp + def GenerateInitializeFunc(self, SkuName, DefaultStore, Pcd, InitByteV= alue, CApp): OverrideValues =3D {DefaultStore:{}} if Pcd.SkuOverrideValues: OverrideValues =3D Pcd.SkuOverrideValues[SkuName] if not OverrideValues: @@ -2584,26 +2768,42 @@ class DscBuildData(PlatformBuildClassObject): CApp =3D CApp + '\n' for Pcd in StructuredPcds.values(): CApp =3D CApp + self.GenerateArrayAssignment(Pcd) for PcdName in StructuredPcds: Pcd =3D StructuredPcds[PcdName] + + #create void void Cal_tocken_cname_Size functions CApp =3D CApp + self.GenerateSizeFunction(Pcd) + + #create void Assign_ functions + + # From DEC CApp =3D CApp + self.GenerateDefaultValueAssignFunction(Pcd) + # From Fdf CApp =3D CApp + self.GenerateFdfValue(Pcd) + # From CommandLine CApp =3D CApp + self.GenerateCommandLineValue(Pcd) + + # From Dsc Global setting if self.SkuOverrideValuesEmpty(Pcd.SkuOverrideValues) or Pcd.T= ype in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD], self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODU= LE]]: CApp =3D CApp + self.GenerateInitValueFunction(Pcd, self.S= kuIdMgr.SystemSkuId, TAB_DEFAULT_STORES_DEFAULT) else: for SkuName in self.SkuIdMgr.SkuOverrideOrder(): if SkuName not in Pcd.SkuOverrideValues: continue for DefaultStoreName in Pcd.SkuOverrideValues[SkuName]: CApp =3D CApp + self.GenerateInitValueFunction(Pcd= , SkuName, DefaultStoreName) + + # From Dsc module scope setting + CApp =3D CApp + self.GenerateModuleScopeValue(Pcd) + + #create Initialize_ functions if self.SkuOverrideValuesEmpty(Pcd.SkuOverrideValues) or Pcd.T= ype in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD], self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODU= LE]]: InitByteValue, CApp =3D self.GenerateInitializeFunc(self.S= kuIdMgr.SystemSkuId, TAB_DEFAULT_STORES_DEFAULT, Pcd, InitByteValue, CApp) + InitByteValue, CApp =3D self.GenerateModuleScopeInitializ= eFunc(self.SkuIdMgr.SystemSkuId,Pcd,InitByteValue,CApp) else: for SkuName in self.SkuIdMgr.SkuOverrideOrder(): if SkuName not in Pcd.SkuOverrideValues: continue for DefaultStoreName in Pcd.DefaultStoreName: @@ -2616,10 +2816,12 @@ class DscBuildData(PlatformBuildClassObject): CApp =3D CApp + ' )\n' CApp =3D CApp + '{\n' for Pcd in StructuredPcds.values(): if self.SkuOverrideValuesEmpty(Pcd.SkuOverrideValues) or Pcd.T= ype in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD], self._PCD_TYPE_ST= RING_[MODEL_PCD_PATCHABLE_IN_MODULE]]: CApp =3D CApp + ' Initialize_%s_%s_%s_%s();\n' % (self.Sk= uIdMgr.SystemSkuId, TAB_DEFAULT_STORES_DEFAULT, Pcd.TokenSpaceGuidCName, Pc= d.TokenCName) + for ModuleGuid in Pcd.PcdFiledValueFromDscComponent: + CApp +=3D " Initialize_%s_%s_%s_%s();\n" % (ModuleGui= d,TAB_DEFAULT_STORES_DEFAULT ,Pcd.TokenSpaceGuidCName, Pcd.TokenCName) else: for SkuName in self.SkuIdMgr.SkuOverrideOrder(): if SkuName not in self.SkuIdMgr.AvailableSkuIdSet: continue for DefaultStoreName in Pcd.SkuOverrideValues[SkuName]: @@ -2631,10 +2833,11 @@ class DscBuildData(PlatformBuildClassObject): if not os.path.exists(self.OutputPath): os.makedirs(self.OutputPath) CAppBaseFileName =3D os.path.join(self.OutputPath, PcdValueInitNam= e) SaveFileOnChange(CAppBaseFileName + '.c', CApp, False) =20 + # start generating makefile MakeApp =3D PcdMakefileHeader if sys.platform =3D=3D "win32": MakeApp =3D MakeApp + 'APPFILE =3D %s\%s.exe\n' % (self.Output= Path, PcdValueInitName) + 'APPNAME =3D %s\n' % (PcdValueInitName) + 'OBJECT= S =3D %s\%s.obj %s.obj\n' % (self.OutputPath, PcdValueInitName, os.path.joi= n(self.OutputPath, PcdValueCommonName)) + 'INC =3D ' else: MakeApp =3D MakeApp + PcdGccMakefile @@ -2753,19 +2956,22 @@ class DscBuildData(PlatformBuildClassObject): MakeApp =3D MakeApp + '\tcp -f %s %s/PcdValueCommon.c\n' % (Pc= dValueCommonPath, self.OutputPath) MakeFileName =3D os.path.join(self.OutputPath, 'Makefile') MakeApp +=3D "$(OBJECTS) : %s\n" % MakeFileName SaveFileOnChange(MakeFileName, MakeApp, False) =20 + # start generating input file InputValueFile =3D os.path.join(self.OutputPath, 'Input.txt') OutputValueFile =3D os.path.join(self.OutputPath, 'Output.txt') SaveFileOnChange(InputValueFile, InitByteValue, False) =20 Dest_PcdValueInitExe =3D PcdValueInitName if not sys.platform =3D=3D "win32": Dest_PcdValueInitExe =3D os.path.join(self.OutputPath, PcdValu= eInitName) else: Dest_PcdValueInitExe =3D os.path.join(self.OutputPath, PcdValu= eInitName) +".exe" + + #start building the structure pcd value tool Messages =3D '' if sys.platform =3D=3D "win32": MakeCommand =3D 'nmake -f %s' % (MakeFileName) returncode, StdOut, StdErr =3D DscBuildData.ExecuteCommand (Ma= keCommand) Messages =3D StdOut @@ -2824,17 +3030,19 @@ class DscBuildData(PlatformBuildClassObject): if MessageGroup: EdkLogger.error("build", PCD_STRUCTURE_PCD_ERROR, "\n".joi= n(MessageGroup) ) else: EdkLogger.error('Build', COMMAND_FAILURE, 'Can not execute= command: %s\n%s\n%s' % (MakeCommand, StdOut, StdErr)) =20 + #start executing the structure pcd value tool if DscBuildData.NeedUpdateOutput(OutputValueFile, Dest_PcdValueIni= tExe, InputValueFile): Command =3D Dest_PcdValueInitExe + ' -i %s -o %s' % (InputValu= eFile, OutputValueFile) returncode, StdOut, StdErr =3D DscBuildData.ExecuteCommand (Co= mmand) EdkLogger.verbose ('%s\n%s\n%s' % (Command, StdOut, StdErr)) if returncode !=3D 0: EdkLogger.warn('Build', COMMAND_FAILURE, 'Can not collect = output from command: %s\n%s\n' % (Command, StdOut, StdErr)) =20 + #start update structure pcd final value File =3D open (OutputValueFile, 'r') FileBuffer =3D File.readlines() File.close() =20 StructurePcdSet =3D [] --=20 2.20.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63906): https://edk2.groups.io/g/devel/message/63906 Mute This Topic: https://groups.io/mt/76101016/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-