From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.24; helo=mga09.intel.com; envelope-from=yonghong.zhu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 8EDBA220D4BE9 for ; Thu, 16 Nov 2017 01:09:45 -0800 (PST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Nov 2017 01:13:54 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,402,1505804400"; d="scan'208";a="8300884" Received: from shwdeopenpsi168.ccr.corp.intel.com ([10.239.158.121]) by orsmga002.jf.intel.com with ESMTP; 16 Nov 2017 01:13:53 -0800 From: Yonghong Zhu To: edk2-devel@lists.01.org Cc: Liming Gao , Dmitry Antipov Date: Thu, 16 Nov 2017 17:13:51 +0800 Message-Id: <1510823631-4744-1-git-send-email-yonghong.zhu@intel.com> X-Mailer: git-send-email 2.6.1.windows.1 Subject: [Patch] BaseTools: Guid.xref contain information from FILE statements in FDF 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: , X-List-Received-Date: Thu, 16 Nov 2017 09:09:45 -0000 Update Guid.xref to contain information from FILE statements in FDF file. Fixes: https://bugzilla.tianocore.org/show_bug.cgi?id=778 Cc: Liming Gao Cc: Dmitry Antipov Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Yonghong Zhu --- BaseTools/Source/Python/GenFds/GenFds.py | 88 +++++++++++++++++++++++++++++++- 1 file changed, 86 insertions(+), 2 deletions(-) diff --git a/BaseTools/Source/Python/GenFds/GenFds.py b/BaseTools/Source/Python/GenFds/GenFds.py index 277da35..c19dc40 100644 --- a/BaseTools/Source/Python/GenFds/GenFds.py +++ b/BaseTools/Source/Python/GenFds/GenFds.py @@ -40,10 +40,13 @@ from Common.Misc import ClearDuplicatedInf from Common.Misc import GuidStructureStringToGuidString from Common.Misc import CheckPcdDatum from Common.Misc import BuildOptionPcdValueFormat from Common.BuildVersion import gBUILD_VERSION from Common.MultipleWorkspace import MultipleWorkspace as mws +import FfsFileStatement +import glob +from struct import unpack ## Version and Copyright versionNumber = "1.0" + ' ' + gBUILD_VERSION __version__ = "%prog Version " + versionNumber __copyright__ = "Copyright (c) 2007 - 2017, Intel Corporation All rights reserved." @@ -325,11 +328,11 @@ def main(): """Call GenFds""" GenFds.GenFd('', FdfParserObj, BuildWorkSpace, ArchList) """Generate GUID cross reference file""" - GenFds.GenerateGuidXRefFile(BuildWorkSpace, ArchList) + GenFds.GenerateGuidXRefFile(BuildWorkSpace, ArchList, FdfParserObj) """Display FV space info.""" GenFds.DisplayFvSpaceInfo(FdfParserObj) except FdfParser.Warning, X: @@ -722,25 +725,106 @@ class GenFds : ModuleDict = BuildDb.BuildObject[DscFile, 'COMMON', GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag].Modules for Key in ModuleDict: ModuleObj = BuildDb.BuildObject[Key, 'COMMON', GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag] print ModuleObj.BaseName + ' ' + ModuleObj.ModuleType - def GenerateGuidXRefFile(BuildDb, ArchList): + def GenerateGuidXRefFile(BuildDb, ArchList, FdfParserObj): GuidXRefFileName = os.path.join(GenFdsGlobalVariable.FvDir, "Guid.xref") GuidXRefFile = StringIO.StringIO('') GuidDict = {} + ModuleList = [] + FileGuidList = [] for Arch in ArchList: PlatformDataBase = BuildDb.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag] for ModuleFile in PlatformDataBase.Modules: Module = BuildDb.BuildObject[ModuleFile, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag] + if Module in ModuleList: + continue + else: + ModuleList.append(Module) GuidXRefFile.write("%s %s\n" % (Module.Guid, Module.BaseName)) for key, item in Module.Protocols.items(): GuidDict[key] = item for key, item in Module.Guids.items(): GuidDict[key] = item for key, item in Module.Ppis.items(): GuidDict[key] = item + for FvName in FdfParserObj.Profile.FvDict: + for FfsObj in FdfParserObj.Profile.FvDict[FvName].FfsList: + if not isinstance(FfsObj, FfsFileStatement.FileStatement): + InfPath = PathClass(NormPath(mws.join(GenFdsGlobalVariable.WorkSpaceDir, FfsObj.InfFileName))) + FdfModule = BuildDb.BuildObject[InfPath, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag] + if FdfModule in ModuleList: + continue + else: + ModuleList.append(FdfModule) + GuidXRefFile.write("%s %s\n" % (FdfModule.Guid, FdfModule.BaseName)) + for key, item in FdfModule.Protocols.items(): + GuidDict[key] = item + for key, item in FdfModule.Guids.items(): + GuidDict[key] = item + for key, item in FdfModule.Ppis.items(): + GuidDict[key] = item + else: + FileStatementGuid = FfsObj.NameGuid + if FileStatementGuid in FileGuidList: + continue + else: + FileGuidList.append(FileStatementGuid) + Name = [] + FfsPath = os.path.join(GenFdsGlobalVariable.FvDir, 'Ffs') + FfsPath = glob.glob(os.path.join(FfsPath, FileStatementGuid) + '*') + if not FfsPath: + continue + if not os.path.exists(FfsPath[0]): + continue + MatchDict = {} + ReFileEnds = re.compile('\S+(.ui)$|\S+(fv.sec.txt)$|\S+(.pe32.txt)$|\S+(.te.txt)$|\S+(.pic.txt)$|\S+(.raw.txt)$|\S+(.ffs.txt)$') + FileList = os.listdir(FfsPath[0]) + for File in FileList: + Match = ReFileEnds.search(File) + if Match: + for Index in range(1, 8): + if Match.group(Index) and Match.group(Index) in MatchDict: + MatchDict[Match.group(Index)].append(File) + elif Match.group(Index): + MatchDict[Match.group(Index)] = [File] + if not MatchDict: + continue + if '.ui' in MatchDict: + for File in MatchDict['.ui']: + with open(os.path.join(FfsPath[0], File), 'rb') as F: + F.read() + length = F.tell() + F.seek(4) + TmpStr = unpack('%dh' % ((length - 4) / 2), F.read()) + Name = ''.join([chr(c) for c in TmpStr[:-1]]) + else: + FileList = [] + if 'fv.sec.txt' in MatchDict: + FileList = MatchDict['fv.sec.txt'] + elif '.pe32.txt' in MatchDict: + FileList = MatchDict['.pe32.txt'] + elif '.te.txt' in MatchDict: + FileList = MatchDict['.te.txt'] + elif '.pic.txt' in MatchDict: + FileList = MatchDict['.pic.txt'] + elif '.raw.txt' in MatchDict: + FileList = MatchDict['.raw.txt'] + elif '.ffs.txt' in MatchDict: + FileList = MatchDict['.ffs.txt'] + else: + pass + for File in FileList: + with open(os.path.join(FfsPath[0], File), 'r') as F: + Name.append((F.read().split()[-1])) + if not Name: + continue + + Name = ' '.join(Name) if type(Name) == type([]) else Name + GuidXRefFile.write("%s %s\n" %(FileStatementGuid, Name)) + # Append GUIDs, Protocols, and PPIs to the Xref file GuidXRefFile.write("\n") for key, item in GuidDict.items(): GuidXRefFile.write("%s %s\n" % (GuidStructureStringToGuidString(item).upper(), key)) -- 2.6.1.windows.1