public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Yonghong Zhu <yonghong.zhu@intel.com>
To: edk2-devel@lists.01.org
Cc: Liming Gao <liming.gao@intel.com>
Subject: [Patch] BaseTools: Extend FMP to support FV statement and FD statement
Date: Sun,  9 Oct 2016 10:24:48 +0800	[thread overview]
Message-ID: <1475979888-27736-1-git-send-email-yonghong.zhu@intel.com> (raw)

This patch extend the <FmpFileData> to support <FvStatements> and
<FdStatenents>, just like the normal [Capsule] section format.
In order to fix the bug https://bugzilla.tianocore.org/show_bug.cgi?id=132

Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Yonghong Zhu <yonghong.zhu@intel.com>
---
 BaseTools/Source/Python/GenFds/Capsule.py     |  6 +++
 BaseTools/Source/Python/GenFds/CapsuleData.py |  4 +-
 BaseTools/Source/Python/GenFds/FdfParser.py   | 59 ++++++++++++++++++++-------
 3 files changed, 53 insertions(+), 16 deletions(-)

diff --git a/BaseTools/Source/Python/GenFds/Capsule.py b/BaseTools/Source/Python/GenFds/Capsule.py
index c98c054..d025f0c 100644
--- a/BaseTools/Source/Python/GenFds/Capsule.py
+++ b/BaseTools/Source/Python/GenFds/Capsule.py
@@ -139,10 +139,16 @@ class Capsule (CapsuleClassObject) :
             PreSize += os.path.getsize(FileName)
             File = open(FileName, 'rb')
             Content.write(File.read())
             File.close()
         for fmp in self.FmpPayloadList:
+            if fmp.ImageFile:
+                for Obj in fmp.ImageFile:
+                    fmp.ImageFile = Obj.GenCapsuleSubItem()
+            if fmp.VendorCodeFile:
+                for Obj in fmp.VendorCodeFile:
+                    fmp.VendorCodeFile = Obj.GenCapsuleSubItem()
             if fmp.Certificate_Guid:
                 ExternalTool, ExternalOption = FindExtendTool([], GenFdsGlobalVariable.ArchList, fmp.Certificate_Guid)
                 CmdOption = ''
                 CapInputFile = fmp.ImageFile
                 if not os.path.isabs(fmp.ImageFile):
diff --git a/BaseTools/Source/Python/GenFds/CapsuleData.py b/BaseTools/Source/Python/GenFds/CapsuleData.py
index 07cc198..d7a6d54 100644
--- a/BaseTools/Source/Python/GenFds/CapsuleData.py
+++ b/BaseTools/Source/Python/GenFds/CapsuleData.py
@@ -177,12 +177,12 @@ class CapsulePayload(CapsuleData):
         self.UiName = None
         self.Version = None
         self.ImageTypeId = None
         self.ImageIndex = None
         self.HardwareInstance = None
-        self.ImageFile = None
-        self.VendorCodeFile = None
+        self.ImageFile = []
+        self.VendorCodeFile = []
         self.Certificate_Guid = None
         self.MonotonicCount = None
 
     def GenCapsuleSubItem(self, AuthData=[]):
         if not self.Version:
diff --git a/BaseTools/Source/Python/GenFds/FdfParser.py b/BaseTools/Source/Python/GenFds/FdfParser.py
index 02ae7c9..64f634f 100644
--- a/BaseTools/Source/Python/GenFds/FdfParser.py
+++ b/BaseTools/Source/Python/GenFds/FdfParser.py
@@ -3257,19 +3257,16 @@ class FdfParser:
             FmpKeyList.remove('CERTIFICATE_GUID')
         if 'MONOTONIC_COUNT' in FmpKeyList:
             FmpKeyList.remove('MONOTONIC_COUNT')
         if FmpKeyList:
             raise Warning("Missing keywords %s in FMP payload section." % ', '.join(FmpKeyList), self.FileName, self.CurrentLineNumber)
-        ImageFile = self.__ParseRawFileStatement()
-        if not ImageFile:
+        # get the Image file and Vendor code file
+        self.__GetFMPCapsuleData(FmpData)
+        if not FmpData.ImageFile:
             raise Warning("Missing image file in FMP payload section.", self.FileName, self.CurrentLineNumber)
-        FmpData.ImageFile = ImageFile
-        VendorCodeFile = self.__ParseRawFileStatement()
-        if VendorCodeFile:
-            FmpData.VendorCodeFile = VendorCodeFile
-        AdditionalFile = self.__ParseRawFileStatement()
-        if AdditionalFile:
+        # check whether more than one Vendor code file
+        if len(FmpData.VendorCodeFile) > 1:
             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
         return True
 
     ## __GetCapsule() method
@@ -3398,20 +3395,36 @@ class FdfParser:
             IsAfile = self.__GetAfileStatement(Obj)
             IsFmp = self.__GetFmpStatement(Obj)
             if not (IsInf or IsFile or IsFv or IsFd or IsAnyFile or IsAfile or IsFmp):
                 break
 
+    ## __GetFMPCapsuleData() method
+    #
+    #   Get capsule data for FMP capsule
+    #
+    #   @param  self        The object pointer
+    #   @param  Obj         for whom capsule data are got
+    #
+    def __GetFMPCapsuleData(self, Obj):
+
+        while True:
+            IsFv = self.__GetFvStatement(Obj, True)
+            IsFd = self.__GetFdStatement(Obj, True)
+            IsAnyFile = self.__GetAnyFileStatement(Obj, True)
+            if not (IsFv or IsFd or IsAnyFile):
+                break
+
     ## __GetFvStatement() method
     #
     #   Get FV for capsule
     #
     #   @param  self        The object pointer
     #   @param  CapsuleObj  for whom FV is got
     #   @retval True        Successfully find a FV statement
     #   @retval False       Not able to find a FV statement
     #
-    def __GetFvStatement(self, CapsuleObj):
+    def __GetFvStatement(self, CapsuleObj, FMPCapsule = False):
 
         if not self.__IsKeyword("FV"):
             return False
 
         if not self.__IsToken("="):
@@ -3423,11 +3436,17 @@ class FdfParser:
         if self.__Token.upper() not in self.Profile.FvDict.keys():
             raise Warning("FV name does not exist", self.FileName, self.CurrentLineNumber)
 
         CapsuleFv = CapsuleData.CapsuleFv()
         CapsuleFv.FvName = self.__Token
-        CapsuleObj.CapsuleDataList.append(CapsuleFv)
+        if FMPCapsule:
+            if not CapsuleObj.ImageFile:
+                CapsuleObj.ImageFile.append(CapsuleFv)
+            else:
+                CapsuleObj.VendorCodeFile.append(CapsuleFv)
+        else:
+            CapsuleObj.CapsuleDataList.append(CapsuleFv)
         return True
 
     ## __GetFdStatement() method
     #
     #   Get FD for capsule
@@ -3435,11 +3454,11 @@ class FdfParser:
     #   @param  self        The object pointer
     #   @param  CapsuleObj  for whom FD is got
     #   @retval True        Successfully find a FD statement
     #   @retval False       Not able to find a FD statement
     #
-    def __GetFdStatement(self, CapsuleObj):
+    def __GetFdStatement(self, CapsuleObj, FMPCapsule = False):
 
         if not self.__IsKeyword("FD"):
             return False
 
         if not self.__IsToken("="):
@@ -3451,11 +3470,17 @@ class FdfParser:
         if self.__Token.upper() not in self.Profile.FdDict.keys():
             raise Warning("FD name does not exist", self.FileName, self.CurrentLineNumber)
 
         CapsuleFd = CapsuleData.CapsuleFd()
         CapsuleFd.FdName = self.__Token
-        CapsuleObj.CapsuleDataList.append(CapsuleFd)
+        if FMPCapsule:
+            if not CapsuleObj.ImageFile:
+                CapsuleObj.ImageFile.append(CapsuleFd)
+            else:
+                CapsuleObj.VendorCodeFile.append(CapsuleFd)
+        else:
+            CapsuleObj.CapsuleDataList.append(CapsuleFd)
         return True
 
     def __GetFmpStatement(self, CapsuleObj):
         if not self.__IsKeyword("FMP_PAYLOAD"):
             if not self.__IsKeyword("FMP"):
@@ -3502,18 +3527,24 @@ class FdfParser:
     #   @param  self        The object pointer
     #   @param  CapsuleObj  for whom AnyFile is got
     #   @retval True        Successfully find a Anyfile statement
     #   @retval False       Not able to find a AnyFile statement
     #
-    def __GetAnyFileStatement(self, CapsuleObj):
+    def __GetAnyFileStatement(self, CapsuleObj, FMPCapsule = False):
         AnyFileName = self.__ParseRawFileStatement()
         if not AnyFileName:
             return False
 
         CapsuleAnyFile = CapsuleData.CapsuleAnyFile()
         CapsuleAnyFile.FileName = AnyFileName
-        CapsuleObj.CapsuleDataList.append(CapsuleAnyFile)
+        if FMPCapsule:
+            if not CapsuleObj.ImageFile:
+                CapsuleObj.ImageFile.append(CapsuleAnyFile)
+            else:
+                CapsuleObj.VendorCodeFile.append(CapsuleAnyFile)
+        else:
+            CapsuleObj.CapsuleDataList.append(CapsuleAnyFile)
         return True
     
     ## __GetAfileStatement() method
     #
     #   Get Afile for capsule
-- 
2.6.1.windows.1



             reply	other threads:[~2016-10-09  2:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-09  2:24 Yonghong Zhu [this message]
2016-10-10  2:36 ` [Patch] BaseTools: Extend FMP to support FV statement and FD statement Gao, Liming

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1475979888-27736-1-git-send-email-yonghong.zhu@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox