Hi Eugene, Thanks for your patch.
Reviewed-by: Yonghong Zhu <[email protected]> Best Regards, Zhu Yonghong -----Original Message----- From: Cohen, Eugene [mailto:[email protected]] Sent: Thursday, January 14, 2016 12:01 AM To: [email protected]; Zhu, Yonghong; Gao, Liming Subject: [PATCH] BaseTools: make build report tolerant of FVs specified by name Check if the FV name is in the FV dictionary before using it which fixes a crash during build report generation when FVs are specified by path in the FDF. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Eugene Cohen <[email protected]> --- BaseTools/Source/Python/build/BuildReport.py | 72 +++++++++++++++------------- 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/BaseTools/Source/Python/build/BuildReport.py b/BaseTools/Source/Python/build/BuildReport.py index d459a01..7311202 100644 --- a/BaseTools/Source/Python/build/BuildReport.py +++ b/BaseTools/Source/Python/build/BuildReport.py @@ -1,4 +1,4 @@ -## @file +?## @file # Routines for generating build report. # # This module contains the functionality to generate build report after @@ -1175,18 +1175,20 @@ class FdRegionReport(object): # @param Wa Workspace context information # def _DiscoverNestedFvList(self, FvName, Wa): - for Ffs in Wa.FdfProfile.FvDict[FvName.upper()].FfsList: - for Section in Ffs.SectionList: - try: - for FvSection in Section.SectionList: - if FvSection.FvName in self.FvList: - continue - self._GuidsDb[Ffs.NameGuid.upper()] = FvSection.FvName - self.FvList.append(FvSection.FvName) - self.FvInfo[FvSection.FvName] = ("Nested FV", 0, 0) - self._DiscoverNestedFvList(FvSection.FvName, Wa) - except AttributeError: - pass + FvDictKey=FvName.upper() + if FvDictKey in Wa.FdfProfile.FvDict: + for Ffs in Wa.FdfProfile.FvDict[FvDictKey].FfsList: + for Section in Ffs.SectionList: + try: + for FvSection in Section.SectionList: + if FvSection.FvName in self.FvList: + continue + self._GuidsDb[Ffs.NameGuid.upper()] = FvSection.FvName + self.FvList.append(FvSection.FvName) + self.FvInfo[FvSection.FvName] = ("Nested FV", 0, 0) + self._DiscoverNestedFvList(FvSection.FvName, Wa) + except AttributeError: + pass ## # Constructor function for class FdRegionReport @@ -1264,27 +1266,29 @@ class FdRegionReport(object): # Collect the GUID map in the FV firmware volume # for FvName in self.FvList: - for Ffs in Wa.FdfProfile.FvDict[FvName.upper()].FfsList: - try: - # - # collect GUID map for binary EFI file in FDF file. - # - Guid = Ffs.NameGuid.upper() - Match = gPcdGuidPattern.match(Ffs.NameGuid) - if Match: - PcdTokenspace = Match.group(1) - PcdToken = Match.group(2) - if (PcdToken, PcdTokenspace) in PlatformPcds: - GuidValue = PlatformPcds[(PcdToken, PcdTokenspace)] - Guid = GuidStructureByteArrayToGuidString(GuidValue).upper() - for Section in Ffs.SectionList: - try: - ModuleSectFile = mws.join(Wa.WorkspaceDir, Section.SectFileName) - self._GuidsDb[Guid] = ModuleSectFile - except AttributeError: - pass - except AttributeError: - pass + FvDictKey=FvName.upper() + if FvDictKey in Wa.FdfProfile.FvDict: + for Ffs in Wa.FdfProfile.FvDict[FvDictKey].FfsList: + try: + # + # collect GUID map for binary EFI file in FDF file. + # + Guid = Ffs.NameGuid.upper() + Match = gPcdGuidPattern.match(Ffs.NameGuid) + if Match: + PcdTokenspace = Match.group(1) + PcdToken = Match.group(2) + if (PcdToken, PcdTokenspace) in PlatformPcds: + GuidValue = PlatformPcds[(PcdToken, PcdTokenspace)] + Guid = GuidStructureByteArrayToGuidString(GuidValue).upper() + for Section in Ffs.SectionList: + try: + ModuleSectFile = mws.join(Wa.WorkspaceDir, Section.SectFileName) + self._GuidsDb[Guid] = ModuleSectFile + except AttributeError: + pass + except AttributeError: + pass ## -- 1.9.5.msysgit.0 > -----Original Message----- > From: edk2-devel [mailto:[email protected]] On Behalf > Of Cohen, Eugene > Sent: Wednesday, January 13, 2016 7:40 AM > To: [email protected]; [email protected]; Gao, Liming > ([email protected]) <[email protected]> > Subject: [edk2] BaseTools: BuildReport.py crashes for FV_IMAGE > provided by file > > Dear Basetools maintainer, > > > > We have an FDF file where we're creating an encapsulated FV where > the FV contents come from the filesystem instead of from a named > FDF section. The FD processing works fine in this case but the build > report generator tool crashes. > > > > Here's an example of how we generate the FV_IMAGE section: > > > [FV.MY_SIGNED_FV] > (fv attributes removed) > > # encapsulated RSA signed FV image > FILE FV_IMAGE = AD1AEEC6-FEF9-4A5C-B5F1-621DE0E72E5D { > SECTION GUIDED A7717414-C616-4977-9420-844712A735BF > AUTH_STATUS_VALID = TRUE { > SECTION FV_IMAGE = $(BUILD_DIR)/MY_FV.FV > } > > } > > > > Note that the SECTION FV_IMAGE is assigned by a filesystem path and > not a "UI Name". > > > > I verified that the FDF syntax we're using is correct per the FDF > specification which states that FV image section data can be provided > either by a UI name or a filesystem path. (There are actually two paths > in the FDF spec for this: one is LeafSections -> FvImgSection which > requires a UI name but the other path is LeafSections -> DataSection -> > KnownSection -> SecData which allows a filesystem path). I'm no > expert in BNF syntax so please correct me if I read the FDF spec wrong. > > > > The path in BuildReport.py that is crashing is in the FdRegioReport > method which is looping through the nested FVs trying to look them > up by name in FvDict: > > > def _DiscoverNestedFvList(self, FvName, Wa): > for Ffs in Wa.FdfProfile.FvDict[FvName.upper()].FfsList: > for Section in Ffs.SectionList: > > try: > > > > It looks like this assumes that all FVs are defined using UI names and > not filesystem paths because when we use the filesystem syntax we > crash due to a key error: > > > File "BuildReport.py", line 1565, in GenerateReport > File "BuildReport.py", line 1448, in __init__ > File "BuildReport.py", line 1389, in __init__ > File "BuildReport.py", line 1227, in __init__ > File "BuildReport.py", line 1187, in _DiscoverNestedFvList > File "BuildReport.py", line 1178, in _DiscoverNestedFvList > KeyError: 'BUILD/MYPLATFORM/DEBUG_GCC49/MY_FV.FV' > > > > Any recommendations on how to fix the FV UI name assumption in > this tool? It could be as simple as tolerating the missing key in the > dictionary or more complicated like keeping track of whether the FV is > a UI name or filesystem path with additional metadata. > > > > Thanks, > > > > Eugene > > > _______________________________________________ > edk2-devel mailing list > [email protected] > https://lists.01.org/mailman/listinfo/edk2-devel _______________________________________________ edk2-devel mailing list [email protected] https://lists.01.org/mailman/listinfo/edk2-devel

