From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.151; helo=mga17.intel.com; envelope-from=yonghong.zhu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) (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 612B221180F4F for ; Thu, 1 Nov 2018 20:25:30 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Nov 2018 20:25:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,454,1534834800"; d="scan'208";a="83427408" Received: from fmsmsx104.amr.corp.intel.com ([10.18.124.202]) by fmsmga008.fm.intel.com with ESMTP; 01 Nov 2018 20:25:29 -0700 Received: from fmsmsx102.amr.corp.intel.com (10.18.124.200) by fmsmsx104.amr.corp.intel.com (10.18.124.202) with Microsoft SMTP Server (TLS) id 14.3.408.0; Thu, 1 Nov 2018 20:25:29 -0700 Received: from shsmsx104.ccr.corp.intel.com (10.239.4.70) by FMSMSX102.amr.corp.intel.com (10.18.124.200) with Microsoft SMTP Server (TLS) id 14.3.408.0; Thu, 1 Nov 2018 20:25:28 -0700 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.161]) by SHSMSX104.ccr.corp.intel.com ([169.254.5.117]) with mapi id 14.03.0415.000; Fri, 2 Nov 2018 11:25:27 +0800 From: "Zhu, Yonghong" To: "Zhu, Yonghong" , "edk2-devel@lists.01.org" CC: "Chen, Hesheng" , "Zhu, Yonghong" Thread-Topic: [edk2] [PATCH] BaseTools/Eot: Remove a duplication code in EotMain class Thread-Index: AQHUcO49L1Rcivsww0Gm5dzlr0pqM6U71XTw Date: Fri, 2 Nov 2018 03:25:27 +0000 Message-ID: References: <1540972148-21708-1-git-send-email-yonghong.zhu@intel.com> In-Reply-To: <1540972148-21708-1-git-send-email-yonghong.zhu@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH] BaseTools/Eot: Remove a duplication code in EotMain class X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 02 Nov 2018 03:25:30 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Yonghong Zhu =20 Best Regards, Zhu Yonghong -----Original Message----- From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Yong= hong Zhu Sent: Wednesday, October 31, 2018 3:49 PM To: edk2-devel@lists.01.org Cc: Chen, Hesheng Subject: [edk2] [PATCH] BaseTools/Eot: Remove a duplication code in EotMain= class From: Hess Chen Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Hess Chen --- BaseTools/Source/Python/Eot/EotMain.py | 365 -----------------------------= ---- 1 file changed, 365 deletions(-) diff --git a/BaseTools/Source/Python/Eot/EotMain.py b/BaseTools/Source/Pyth= on/Eot/EotMain.py index 2ad93cc6b4..7eae4ac672 100644 --- a/BaseTools/Source/Python/Eot/EotMain.py +++ b/BaseTools/Source/Python/Eot/EotMain.py @@ -1083,371 +1083,6 @@ class Ffs(Image): State =3D property(_GetState, _SetState) =20 =20 - _FfsGuid =3D "8C8CE578-8A3D-4F1C-9935-896185C32DD3" - - _GUID_ =3D struct.Struct("16x 1I2H8B") - _LENGTH_ =3D struct.Struct("16x 16x 1Q") - _SIG_ =3D struct.Struct("16x 16x 8x 1I") - _ATTR_ =3D struct.Struct("16x 16x 8x 4x 1I") - _HLEN_ =3D struct.Struct("16x 16x 8x 4x 4x 1H") - _CHECKSUM_ =3D struct.Struct("16x 16x 8x 4x 4x 2x 1H") - - def __init__(self, Name=3D''): - Image.__init__(self) - self.Name =3D Name - self.FfsDict =3D sdict() - self.OrderedFfsDict =3D sdict() - self.UnDispatchedFfsDict =3D sdict() - self.ProtocolList =3D sdict() - - def CheckArchProtocol(self): - for Item in EotGlobalData.gArchProtocolGuids: - if Item.lower() not in EotGlobalData.gProtocolList: - return False - return True - - def ParseDepex(self, Depex, Type): - List =3D None - if Type =3D=3D 'Ppi': - List =3D EotGlobalData.gPpiList - if Type =3D=3D 'Protocol': - List =3D EotGlobalData.gProtocolList - DepexStack =3D [] - DepexList =3D [] - DepexString =3D '' - FileDepex =3D None - CouldBeLoaded =3D True - for Index in range(0, len(Depex.Expression)): - Item =3D Depex.Expression[Index] - if Item =3D=3D 0x00: - Index =3D Index + 1 - Guid =3D gGuidStringFormat % Depex.Expression[Index] - if Guid in self.OrderedFfsDict and Depex.Expression[Index = + 1] =3D=3D 0x08: - return (True, 'BEFORE %s' % Guid, [Guid, 'BEFORE']) - elif Item =3D=3D 0x01: - Index =3D Index + 1 - Guid =3D gGuidStringFormat % Depex.Expression[Index] - if Guid in self.OrderedFfsDict and Depex.Expression[Index = + 1] =3D=3D 0x08: - return (True, 'AFTER %s' % Guid, [Guid, 'AFTER']) - elif Item =3D=3D 0x02: - Index =3D Index + 1 - Guid =3D gGuidStringFormat % Depex.Expression[Index] - if Guid.lower() in List: - DepexStack.append(True) - DepexList.append(Guid) - else: - DepexStack.append(False) - DepexList.append(Guid) - continue - elif Item =3D=3D 0x03 or Item =3D=3D 0x04: - DepexStack.append(eval(str(DepexStack.pop()) + ' ' + Depex= ._OPCODE_STRING_[Item].lower() + ' ' + str(DepexStack.pop()))) - DepexList.append(str(DepexList.pop()) + ' ' + Depex._OPCOD= E_STRING_[Item].upper() + ' ' + str(DepexList.pop())) - elif Item =3D=3D 0x05: - DepexStack.append(eval(Depex._OPCODE_STRING_[Item].lower()= + ' ' + str(DepexStack.pop()))) - DepexList.append(Depex._OPCODE_STRING_[Item].lower() + ' '= + str(DepexList.pop())) - elif Item =3D=3D 0x06: - DepexStack.append(True) - DepexList.append('TRUE') - DepexString =3D DepexString + 'TRUE' + ' ' - elif Item =3D=3D 0x07: - DepexStack.append(False) - DepexList.append('False') - DepexString =3D DepexString + 'FALSE' + ' ' - elif Item =3D=3D 0x08: - if Index !=3D len(Depex.Expression) - 1: - CouldBeLoaded =3D False - else: - CouldBeLoaded =3D DepexStack.pop() - else: - CouldBeLoaded =3D False - if DepexList !=3D []: - DepexString =3D DepexList[0].strip() - return (CouldBeLoaded, DepexString, FileDepex) - - def Dispatch(self, Db =3D None): - if Db is None: - return False - self.UnDispatchedFfsDict =3D copy.copy(self.FfsDict) - # Find PeiCore, DexCore, PeiPriori, DxePriori first - FfsSecCoreGuid =3D None - FfsPeiCoreGuid =3D None - FfsDxeCoreGuid =3D None - FfsPeiPrioriGuid =3D None - FfsDxePrioriGuid =3D None - for FfsID in self.UnDispatchedFfsDict: - Ffs =3D self.UnDispatchedFfsDict[FfsID] - if Ffs.Type =3D=3D 0x03: - FfsSecCoreGuid =3D FfsID - continue - if Ffs.Type =3D=3D 0x04: - FfsPeiCoreGuid =3D FfsID - continue - if Ffs.Type =3D=3D 0x05: - FfsDxeCoreGuid =3D FfsID - continue - if Ffs.Guid.lower() =3D=3D PEI_APRIORI_GUID.lower(): - FfsPeiPrioriGuid =3D FfsID - continue - if Ffs.Guid.lower() =3D=3D DXE_APRIORI_GUID.lower(): - FfsDxePrioriGuid =3D FfsID - continue - - # Parse SEC_CORE first - if FfsSecCoreGuid is not None: - self.OrderedFfsDict[FfsSecCoreGuid] =3D self.UnDispatchedFfsDi= ct.pop(FfsSecCoreGuid) - self.LoadPpi(Db, FfsSecCoreGuid) - - # Parse PEI first - if FfsPeiCoreGuid is not None: - self.OrderedFfsDict[FfsPeiCoreGuid] =3D self.UnDispatchedFfsDi= ct.pop(FfsPeiCoreGuid) - self.LoadPpi(Db, FfsPeiCoreGuid) - if FfsPeiPrioriGuid is not None: - # Load PEIM described in priori file - FfsPeiPriori =3D self.UnDispatchedFfsDict.pop(FfsPeiPriori= Guid) - if len(FfsPeiPriori.Sections) =3D=3D 1: - Section =3D FfsPeiPriori.Sections.popitem()[1] - if Section.Type =3D=3D 0x19: - GuidStruct =3D struct.Struct('1I2H8B') - Start =3D 4 - while len(Section) > Start: - Guid =3D GuidStruct.unpack_from(Section[Start = : Start + 16]) - GuidString =3D gGuidStringFormat % Guid - Start =3D Start + 16 - if GuidString in self.UnDispatchedFfsDict: - self.OrderedFfsDict[GuidString] =3D self.U= nDispatchedFfsDict.pop(GuidString) - self.LoadPpi(Db, GuidString) - - self.DisPatchPei(Db) - - # Parse DXE then - if FfsDxeCoreGuid is not None: - self.OrderedFfsDict[FfsDxeCoreGuid] =3D self.UnDispatchedFfsDi= ct.pop(FfsDxeCoreGuid) - self.LoadProtocol(Db, FfsDxeCoreGuid) - if FfsDxePrioriGuid is not None: - # Load PEIM described in priori file - FfsDxePriori =3D self.UnDispatchedFfsDict.pop(FfsDxePriori= Guid) - if len(FfsDxePriori.Sections) =3D=3D 1: - Section =3D FfsDxePriori.Sections.popitem()[1] - if Section.Type =3D=3D 0x19: - GuidStruct =3D struct.Struct('1I2H8B') - Start =3D 4 - while len(Section) > Start: - Guid =3D GuidStruct.unpack_from(Section[Start = : Start + 16]) - GuidString =3D gGuidStringFormat % Guid - Start =3D Start + 16 - if GuidString in self.UnDispatchedFfsDict: - self.OrderedFfsDict[GuidString] =3D self.U= nDispatchedFfsDict.pop(GuidString) - self.LoadProtocol(Db, GuidString) - - self.DisPatchDxe(Db) - - def LoadProtocol(self, Db, ModuleGuid): - SqlCommand =3D """select GuidValue from Report - where SourceFileFullPath in - (select Value1 from Inf where BelongsToFile =3D - (select BelongsToFile from Inf - where Value1 =3D 'FILE_GUID' and Value2 like '%s' = and Model =3D %s) - and Model =3D %s) - and ItemType =3D 'Protocol' and ItemMode =3D 'Prod= uced'""" \ - % (ModuleGuid, 5001, 3007) - RecordSet =3D Db.TblReport.Exec(SqlCommand) - for Record in RecordSet: - SqlCommand =3D """select Value2 from Inf where BelongsToFile = =3D - (select DISTINCT BelongsToFile from Inf - where Value1 =3D - (select SourceFileFullPath from Report - where GuidValue like '%s' and ItemMode =3D 'Ca= llback')) - and Value1 =3D 'FILE_GUID'""" % Record[0] - CallBackSet =3D Db.TblReport.Exec(SqlCommand) - if CallBackSet !=3D []: - EotGlobalData.gProtocolList[Record[0].lower()] =3D ModuleG= uid - else: - EotGlobalData.gProtocolList[Record[0].lower()] =3D ModuleG= uid - - def LoadPpi(self, Db, ModuleGuid): - SqlCommand =3D """select GuidValue from Report - where SourceFileFullPath in - (select Value1 from Inf where BelongsToFile =3D - (select BelongsToFile from Inf - where Value1 =3D 'FILE_GUID' and Value2 like '%s' = and Model =3D %s) - and Model =3D %s) - and ItemType =3D 'Ppi' and ItemMode =3D 'Produced'= """ \ - % (ModuleGuid, 5001, 3007) - RecordSet =3D Db.TblReport.Exec(SqlCommand) - for Record in RecordSet: - EotGlobalData.gPpiList[Record[0].lower()] =3D ModuleGuid - - def DisPatchDxe(self, Db): - IsInstalled =3D False - ScheduleList =3D sdict() - for FfsID in self.UnDispatchedFfsDict: - CouldBeLoaded =3D False - DepexString =3D '' - FileDepex =3D None - Ffs =3D self.UnDispatchedFfsDict[FfsID] - if Ffs.Type =3D=3D 0x07: - # Get Depex - IsFoundDepex =3D False - for Section in Ffs.Sections.values(): - # Find Depex - if Section.Type =3D=3D 0x13: - IsFoundDepex =3D True - CouldBeLoaded, DepexString, FileDepex =3D self.Par= seDepex(Section._SubImages[4], 'Protocol') - break - if Section.Type =3D=3D 0x01: - CompressSections =3D Section._SubImages[4] - for CompressSection in CompressSections.Sections: - if CompressSection.Type =3D=3D 0x13: - IsFoundDepex =3D True - CouldBeLoaded, DepexString, FileDepex =3D = self.ParseDepex(CompressSection._SubImages[4], 'Protocol') - break - if CompressSection.Type =3D=3D 0x02: - NewSections =3D CompressSection._SubImages= [4] - for NewSection in NewSections.Sections: - if NewSection.Type =3D=3D 0x13: - IsFoundDepex =3D True - CouldBeLoaded, DepexString, FileDe= pex =3D self.ParseDepex(NewSection._SubImages[4], 'Protocol') - break - - # Not find Depex - if not IsFoundDepex: - CouldBeLoaded =3D self.CheckArchProtocol() - DepexString =3D '' - FileDepex =3D None - - # Append New Ffs - if CouldBeLoaded: - IsInstalled =3D True - NewFfs =3D self.UnDispatchedFfsDict.pop(FfsID) - NewFfs.Depex =3D DepexString - if FileDepex is not None: - ScheduleList.insert(FileDepex[1], FfsID, NewFfs, F= ileDepex[0]) - else: - ScheduleList[FfsID] =3D NewFfs - else: - self.UnDispatchedFfsDict[FfsID].Depex =3D DepexString - - for FfsID in ScheduleList: - NewFfs =3D ScheduleList.pop(FfsID) - FfsName =3D 'UnKnown' - self.OrderedFfsDict[FfsID] =3D NewFfs - self.LoadProtocol(Db, FfsID) - - SqlCommand =3D """select Value2 from Inf - where BelongsToFile =3D (select BelongsToFile = from Inf where Value1 =3D 'FILE_GUID' and lower(Value2) =3D lower('%s') and= Model =3D %s) - and Model =3D %s and Value1=3D'BASE_NAME'""" %= (FfsID, 5001, 5001) - RecordSet =3D Db.TblReport.Exec(SqlCommand) - if RecordSet !=3D []: - FfsName =3D RecordSet[0][0] - - if IsInstalled: - self.DisPatchDxe(Db) - - def DisPatchPei(self, Db): - IsInstalled =3D False - for FfsID in self.UnDispatchedFfsDict: - CouldBeLoaded =3D True - DepexString =3D '' - FileDepex =3D None - Ffs =3D self.UnDispatchedFfsDict[FfsID] - if Ffs.Type =3D=3D 0x06 or Ffs.Type =3D=3D 0x08: - # Get Depex - for Section in Ffs.Sections.values(): - if Section.Type =3D=3D 0x1B: - CouldBeLoaded, DepexString, FileDepex =3D self.Par= seDepex(Section._SubImages[4], 'Ppi') - break - if Section.Type =3D=3D 0x01: - CompressSections =3D Section._SubImages[4] - for CompressSection in CompressSections.Sections: - if CompressSection.Type =3D=3D 0x1B: - CouldBeLoaded, DepexString, FileDepex =3D = self.ParseDepex(CompressSection._SubImages[4], 'Ppi') - break - if CompressSection.Type =3D=3D 0x02: - NewSections =3D CompressSection._SubImages= [4] - for NewSection in NewSections.Sections: - if NewSection.Type =3D=3D 0x1B: - CouldBeLoaded, DepexString, FileDe= pex =3D self.ParseDepex(NewSection._SubImages[4], 'Ppi') - break - - # Append New Ffs - if CouldBeLoaded: - IsInstalled =3D True - NewFfs =3D self.UnDispatchedFfsDict.pop(FfsID) - NewFfs.Depex =3D DepexString - self.OrderedFfsDict[FfsID] =3D NewFfs - self.LoadPpi(Db, FfsID) - else: - self.UnDispatchedFfsDict[FfsID].Depex =3D DepexString - - if IsInstalled: - self.DisPatchPei(Db) - - - def __str__(self): - global gIndention - gIndention +=3D 4 - FvInfo =3D '\n' + ' ' * gIndention - FvInfo +=3D "[FV:%s] file_system=3D%s size=3D%x checksum=3D%s\n" = % (self.Name, self.FileSystemGuid, self.Size, self.Checksum) - FfsInfo =3D "\n".join([str(self.FfsDict[FfsId]) for FfsId in self.= FfsDict]) - gIndention -=3D 4 - return FvInfo + FfsInfo - - def _Unpack(self): - Size =3D self._LENGTH_.unpack_from(self._BUF_, self._OFF_)[0] - self.empty() - self.extend(self._BUF_[self._OFF_:self._OFF_+Size]) - - # traverse the FFS - EndOfFv =3D Size - FfsStartAddress =3D self.HeaderSize - LastFfsObj =3D None - while FfsStartAddress < EndOfFv: - FfsObj =3D Ffs() - FfsObj.frombuffer(self, FfsStartAddress) - FfsId =3D repr(FfsObj) - if ((self.Attributes & 0x00000800) !=3D 0 and len(FfsObj) =3D= =3D 0xFFFFFF) \ - or ((self.Attributes & 0x00000800) =3D=3D 0 and len(FfsObj= ) =3D=3D 0): - if LastFfsObj is not None: - LastFfsObj.FreeSpace =3D EndOfFv - LastFfsObj._OFF_ - = len(LastFfsObj) - else: - if FfsId in self.FfsDict: - EdkLogger.error("FV", 0, "Duplicate GUID in FFS", - ExtraData=3D"\t%s @ %s\n\t%s @ %s" \ - % (FfsObj.Guid, FfsObj.Offset, - self.FfsDict[FfsId].Guid, self.FfsD= ict[FfsId].Offset)) - self.FfsDict[FfsId] =3D FfsObj - if LastFfsObj is not None: - LastFfsObj.FreeSpace =3D FfsStartAddress - LastFfsObj.= _OFF_ - len(LastFfsObj) - - FfsStartAddress +=3D len(FfsObj) - # - # align to next 8-byte aligned address: A =3D (A + 8 - 1) & (~= (8 - 1)) - # The next FFS must be at the latest next 8-byte aligned addre= ss - # - FfsStartAddress =3D (FfsStartAddress + 7) & (~7) - LastFfsObj =3D FfsObj - - def _GetAttributes(self): - return self.GetField(self._ATTR_, 0)[0] - - def _GetSize(self): - return self.GetField(self._LENGTH_, 0)[0] - - def _GetChecksum(self): - return self.GetField(self._CHECKSUM_, 0)[0] - - def _GetHeaderLength(self): - return self.GetField(self._HLEN_, 0)[0] - - def _GetFileSystemGuid(self): - return gGuidStringFormat % self.GetField(self._GUID_, 0) - - Attributes =3D property(_GetAttributes) - Size =3D property(_GetSize) - Checksum =3D property(_GetChecksum) - HeaderSize =3D property(_GetHeaderLength) - FileSystemGuid =3D property(_GetFileSystemGuid) - ## MultipleFv() class # # A class for Multiple FV --=20 2.14.2.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel