public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [Patch] BaseTools/GenFds: Support FMP Payload files generated during build
@ 2016-10-05 23:46 Michael Kinney
  0 siblings, 0 replies; only message in thread
From: Michael Kinney @ 2016-10-05 23:46 UTC (permalink / raw)
  To: edk2-devel; +Cc: Kelly Steele, Yonghong Zhu, Liming Gao

https://bugzilla.tianocore.org/show_bug.cgi?id=132

This patch allows FILE DATA statements in [FmpPayload] sections
to refer to a file that does not exist at the time the FDF file
is parsed.  There are cases where these FILE DATA statements refer
to FD or FV images that are generated as part of the build and those
FD or FV image files are not present when FDF file is parsed.  These
files are required to be present when the FMP Payload is
generated.

Skip the file present verification step for FILE DATA statements in
[FmpPayload] sections if the file path referenced is in the
$(OUTPUT_DIRECTORY).  Perform this verification step when the
FMP Payload is generated.

Cc: Kelly Steele <kelly.steele@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Michael Kinney <michael.d.kinney@intel.com>
---
 BaseTools/Source/Python/GenFds/Capsule.py     |  8 ++++++
 BaseTools/Source/Python/GenFds/CapsuleData.py |  9 +++++++
 BaseTools/Source/Python/GenFds/FdfParser.py   | 38 ++++++++++++++++++---------
 3 files changed, 43 insertions(+), 12 deletions(-)

diff --git a/BaseTools/Source/Python/GenFds/Capsule.py b/BaseTools/Source/Python/GenFds/Capsule.py
index c98c054..31c414f 100644
--- a/BaseTools/Source/Python/GenFds/Capsule.py
+++ b/BaseTools/Source/Python/GenFds/Capsule.py
@@ -28,6 +28,8 @@ from struct import pack
 from GenFds import FindExtendTool
 from Common import EdkLogger
 from Common.BuildToolError import *
+from Common.Misc import PathClass
+from Common.String import NormPath
 
 
 T_CHAR_LF = '\n'
@@ -142,6 +144,12 @@ class Capsule (CapsuleClassObject) :
             File.close()
         for fmp in self.FmpPayloadList:
             if fmp.Certificate_Guid:
+                #
+                # Verify that ImageFile exists
+                #
+                ErrorCode, ErrorInfo = PathClass(NormPath(fmp.ImageFile), GenFdsGlobalVariable.WorkSpaceDir).Validate()
+                if ErrorCode != 0:
+                    EdkLogger.error("GenFds", ErrorCode, ExtraData=ErrorInfo)
                 ExternalTool, ExternalOption = FindExtendTool([], GenFdsGlobalVariable.ArchList, fmp.Certificate_Guid)
                 CmdOption = ''
                 CapInputFile = fmp.ImageFile
diff --git a/BaseTools/Source/Python/GenFds/CapsuleData.py b/BaseTools/Source/Python/GenFds/CapsuleData.py
index 07cc198..7cbe351 100644
--- a/BaseTools/Source/Python/GenFds/CapsuleData.py
+++ b/BaseTools/Source/Python/GenFds/CapsuleData.py
@@ -22,6 +22,9 @@ from struct import pack
 import os
 from Common.Misc import SaveFileOnChange
 import uuid
+from Common import EdkLogger
+from Common.Misc import PathClass
+from Common.String import NormPath
 
 ## base class for capsule data
 #
@@ -194,6 +197,12 @@ class CapsulePayload(CapsuleData):
             ImageFileSize += 32
         VendorFileSize = 0
         if self.VendorCodeFile:
+            #
+            # Verify that VendorCodeFile exists
+            #
+            ErrorCode, ErrorInfo = PathClass(NormPath(self.VendorCodeFile), GenFdsGlobalVariable.WorkSpaceDir).Validate()
+            if ErrorCode != 0:
+                EdkLogger.error("GenFds", ErrorCode, ExtraData=ErrorInfo)
             VendorFileSize = os.path.getsize(self.VendorCodeFile)
 
         #
diff --git a/BaseTools/Source/Python/GenFds/FdfParser.py b/BaseTools/Source/Python/GenFds/FdfParser.py
index 02ae7c9..2038a37 100644
--- a/BaseTools/Source/Python/GenFds/FdfParser.py
+++ b/BaseTools/Source/Python/GenFds/FdfParser.py
@@ -3037,17 +3037,21 @@ class FdfParser:
     ## __VerifyFile
     #
     #    Check if file exists or not:
-    #      If current phase if GenFds, the file must exist;
-    #      If current phase is AutoGen and the file is not in $(OUTPUT_DIRECTORY), the file must exist
+    #      If current phase is AutoGen or FmpPayload is True, and the file is not in $(OUTPUT_DIRECTORY),
+    #      then the file must exist
     #    @param FileName: File path to be verified.
+    #    @param FmpPayload: If True, then FileName is from a raw file statement in an [FmpPayload] section
+    #                       and FileName is only required to be present if FileName is not in OUTPUT_DIRECTORY
     #
-    def __VerifyFile(self, FileName):
+    def __VerifyFile(self, FileName, FmpPayload = False):
         if FileName.replace('$(WORKSPACE)', '').find('$') != -1:
             return
-        if not GlobalData.gAutoGenPhase or not self.__GetMacroValue("OUTPUT_DIRECTORY") in FileName:
-            ErrorCode, ErrorInfo = PathClass(NormPath(FileName), GenFdsGlobalVariable.WorkSpaceDir).Validate()
-            if ErrorCode != 0:
-                EdkLogger.error("GenFds", ErrorCode, ExtraData=ErrorInfo)
+        if GlobalData.gAutoGenPhase or FmpPayload:
+            if self.__GetMacroValue("OUTPUT_DIRECTORY") in FileName:
+                return
+        ErrorCode, ErrorInfo = PathClass(NormPath(FileName), GenFdsGlobalVariable.WorkSpaceDir).Validate()
+        if ErrorCode != 0:
+            EdkLogger.error("GenFds", ErrorCode, ExtraData=ErrorInfo)
 
     ## __GetCglSection() method
     #
@@ -3259,14 +3263,14 @@ class FdfParser:
             FmpKeyList.remove('MONOTONIC_COUNT')
         if FmpKeyList:
             raise Warning("Missing keywords %s in FMP payload section." % ', '.join(FmpKeyList), self.FileName, self.CurrentLineNumber)
-        ImageFile = self.__ParseRawFileStatement()
+        ImageFile = self.__ParseRawFileStatement(FmpPayload = True)
         if not ImageFile:
             raise Warning("Missing image file in FMP payload section.", self.FileName, self.CurrentLineNumber)
         FmpData.ImageFile = ImageFile
-        VendorCodeFile = self.__ParseRawFileStatement()
+        VendorCodeFile = self.__ParseRawFileStatement(FmpPayload = True)
         if VendorCodeFile:
             FmpData.VendorCodeFile = VendorCodeFile
-        AdditionalFile = self.__ParseRawFileStatement()
+        AdditionalFile = self.__ParseRawFileStatement(FmpPayload = True)
         if AdditionalFile:
             raise Warning("At most one Image file and one Vendor code file are allowed in FMP payload section.", self.FileName, self.CurrentLineNumber)
         self.Profile.FmpPayloadDict[FmpUiName] = FmpData
@@ -3476,7 +3480,17 @@ class FdfParser:
         CapsuleObj.FmpPayloadList.append(self.Profile.FmpPayloadDict[Payload])
         return True
 
-    def __ParseRawFileStatement(self):
+    ## __ParseRawFileStatement() method
+    #
+    #   Parse and return the file path from a raw file statement of the form
+    #
+    #     FILE DATA = <File Path>
+    #
+    #   @param  self        The object pointer
+    #   @param  FmpPayload  If True, then the raw file statement being parsed
+    #                       is from an [FmpPayload] section.
+    #
+    def __ParseRawFileStatement(self, FmpPayload = False):
         if not self.__IsKeyword("FILE"):
             return None
 
@@ -3491,7 +3505,7 @@ class FdfParser:
             raise Warning("expected File name", self.FileName, self.CurrentLineNumber)
         
         AnyFileName = self.__Token
-        self.__VerifyFile(AnyFileName)
+        self.__VerifyFile(AnyFileName, FmpPayload)
 
         return AnyFileName
 
-- 
2.6.3.windows.1



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2016-10-05 23:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-05 23:46 [Patch] BaseTools/GenFds: Support FMP Payload files generated during build Michael Kinney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox