public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-devel][PATCH v2] IntelFsp2Pkg: Support child FV in SplitFspBin.py
@ 2023-07-20 10:19 Kuo, Ted
  2023-07-21 14:34 ` Chiu, Chasel
  2023-08-28 20:31 ` Chiu, Chasel
  0 siblings, 2 replies; 3+ messages in thread
From: Kuo, Ted @ 2023-07-20 10:19 UTC (permalink / raw)
  To: devel
  Cc: Chasel Chiu, Nate DeSimone, Star Zeng, Ashraf Ali S,
	Chinni B Duggapu, Ray Han Lim Ng, Susovan Mohapatra

https://bugzilla.tianocore.org/show_bug.cgi?id=4502
Update SplitFspBin.py to support child FV in FSP binary. Without the
patch, the tool won't be able to rebase the images in child FV in FSP
binary.

Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Ashraf Ali S <ashraf.ali.s@intel.com>
Cc: Chinni B Duggapu <chinni.b.duggapu@intel.com>
Cc: Ray Han Lim Ng <ray.han.lim.ng@intel.com>
Cc: Susovan Mohapatra <susovan.mohapatra@intel.com>
Signed-off-by: Ted Kuo <ted.kuo@intel.com>
---
 IntelFsp2Pkg/Tools/SplitFspBin.py | 44 ++++++++++++++++++++++++++-----
 1 file changed, 37 insertions(+), 7 deletions(-)

diff --git a/IntelFsp2Pkg/Tools/SplitFspBin.py b/IntelFsp2Pkg/Tools/SplitFspBin.py
index 419e5ba985..558eaf401a 100644
--- a/IntelFsp2Pkg/Tools/SplitFspBin.py
+++ b/IntelFsp2Pkg/Tools/SplitFspBin.py
@@ -469,6 +469,7 @@ class FirmwareVolume:
         else:
             self.FvExtHdr = None
         self.FfsList  = []
+        self.ChildFvList  = []
 
     def ParseFv(self):
         fvsize = len(self.FvData)
@@ -483,8 +484,30 @@ class FirmwareVolume:
                 offset = fvsize
             else:
                 ffs = FirmwareFile (offset, self.FvData[offset:offset + int(ffshdr.Size)])
-                ffs.ParseFfs()
-                self.FfsList.append(ffs)
+                # check if there is child fv
+                childfvfound = 0
+                if (ffs.FfsHdr.Type == EFI_FV_FILETYPE.FIRMWARE_VOLUME_IMAGE):
+                    csoffset = offset + sizeof (EFI_FFS_FILE_HEADER)
+                    csoffset = AlignPtr(csoffset, 4)
+                    # find fv section
+                    while csoffset < (offset + int(ffs.FfsHdr.Size)):
+                        cshdr = EFI_COMMON_SECTION_HEADER.from_buffer (self.FvData, csoffset)
+                        if (cshdr.Type == EFI_SECTION_TYPE.FIRMWARE_VOLUME_IMAGE):
+                            childfvfound = 1
+                            break
+                        else:
+                            # check next section
+                            csoffset += int(cshdr.Size)
+                            csoffset = AlignPtr(csoffset, 4)
+                if (childfvfound):
+                    childfvoffset = csoffset + sizeof (EFI_COMMON_SECTION_HEADER)
+                    childfvhdr = EFI_FIRMWARE_VOLUME_HEADER.from_buffer (self.FvData, childfvoffset)
+                    childfv = FirmwareVolume (childfvoffset, self.FvData[childfvoffset:childfvoffset + int(childfvhdr.FvLength)])
+                    childfv.ParseFv ()
+                    self.ChildFvList.append(childfv)
+                else:
+                    ffs.ParseFfs()
+                    self.FfsList.append(ffs)
                 offset += int(ffshdr.Size)
                 offset = AlignPtr(offset)
 
@@ -789,6 +812,13 @@ def SplitFspBin (fspfile, outdir, nametemplate):
             hfsp.write(fv.FvData)
         hfsp.close()
 
+def GetImageFromFv (fd, parentfvoffset, fv, imglist):
+    for ffs in fv.FfsList:
+        for sec in ffs.SecList:
+            if sec.SecHdr.Type in [EFI_SECTION_TYPE.TE, EFI_SECTION_TYPE.PE32]:   # TE or PE32
+                offset = fd.Offset + parentfvoffset + fv.Offset + ffs.Offset + sec.Offset + sizeof(sec.SecHdr)
+                imglist.append ((offset, len(sec.SecData) - sizeof(sec.SecHdr)))
+
 def RebaseFspBin (FspBinary, FspComponent, FspBase, OutputDir, OutputFile):
     fd = FirmwareDevice(0, FspBinary)
     fd.ParseFd  ()
@@ -832,11 +862,11 @@ def RebaseFspBin (FspBinary, FspComponent, FspBase, OutputDir, OutputFile):
         imglist = []
         for fvidx in fsp.FvIdxList:
             fv = fd.FvList[fvidx]
-            for ffs in fv.FfsList:
-                for sec in ffs.SecList:
-                    if sec.SecHdr.Type in [EFI_SECTION_TYPE.TE, EFI_SECTION_TYPE.PE32]:   # TE or PE32
-                        offset = fd.Offset + fv.Offset + ffs.Offset + sec.Offset + sizeof(sec.SecHdr)
-                        imglist.append ((offset, len(sec.SecData) - sizeof(sec.SecHdr)))
+            GetImageFromFv (fd, 0, fv, imglist)
+            # get image from child fv
+            for childfv in fv.ChildFvList:
+                print ("Get image from child fv of fv%d, parent fv offset: 0x%x" % (fvidx, fv.Offset))
+                GetImageFromFv (fd, fv.Offset, childfv, imglist)
 
         fcount  = 0
         pcount  = 0
-- 
2.40.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#107093): https://edk2.groups.io/g/devel/message/107093
Mute This Topic: https://groups.io/mt/100252890/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [edk2-devel][PATCH v2] IntelFsp2Pkg: Support child FV in SplitFspBin.py
  2023-07-20 10:19 [edk2-devel][PATCH v2] IntelFsp2Pkg: Support child FV in SplitFspBin.py Kuo, Ted
@ 2023-07-21 14:34 ` Chiu, Chasel
  2023-08-28 20:31 ` Chiu, Chasel
  1 sibling, 0 replies; 3+ messages in thread
From: Chiu, Chasel @ 2023-07-21 14:34 UTC (permalink / raw)
  To: Kuo, Ted, devel@edk2.groups.io
  Cc: Desimone, Nathaniel L, Zeng, Star, S, Ashraf Ali,
	Duggapu, Chinni B, Ng, Ray Han Lim, Mohapatra, Susovan


Looks good to me. Thanks Ted!
Reviewed-by: Chasel Chiu <chasel.chiu@intel.com>

> -----Original Message-----
> From: Kuo, Ted <ted.kuo@intel.com>
> Sent: Thursday, July 20, 2023 3:20 AM
> To: devel@edk2.groups.io
> Cc: Chiu, Chasel <chasel.chiu@intel.com>; Desimone, Nathaniel L
> <nathaniel.l.desimone@intel.com>; Zeng, Star <star.zeng@intel.com>; S, Ashraf
> Ali <ashraf.ali.s@intel.com>; Duggapu, Chinni B <chinni.b.duggapu@intel.com>;
> Ng, Ray Han Lim <ray.han.lim.ng@intel.com>; Mohapatra, Susovan
> <susovan.mohapatra@intel.com>
> Subject: [edk2-devel][PATCH v2] IntelFsp2Pkg: Support child FV in SplitFspBin.py
> 
> https://bugzilla.tianocore.org/show_bug.cgi?id=4502
> Update SplitFspBin.py to support child FV in FSP binary. Without the patch, the
> tool won't be able to rebase the images in child FV in FSP binary.
> 
> Cc: Chasel Chiu <chasel.chiu@intel.com>
> Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
> Cc: Star Zeng <star.zeng@intel.com>
> Cc: Ashraf Ali S <ashraf.ali.s@intel.com>
> Cc: Chinni B Duggapu <chinni.b.duggapu@intel.com>
> Cc: Ray Han Lim Ng <ray.han.lim.ng@intel.com>
> Cc: Susovan Mohapatra <susovan.mohapatra@intel.com>
> Signed-off-by: Ted Kuo <ted.kuo@intel.com>
> ---
>  IntelFsp2Pkg/Tools/SplitFspBin.py | 44 ++++++++++++++++++++++++++-----
>  1 file changed, 37 insertions(+), 7 deletions(-)
> 
> diff --git a/IntelFsp2Pkg/Tools/SplitFspBin.py b/IntelFsp2Pkg/Tools/SplitFspBin.py
> index 419e5ba985..558eaf401a 100644
> --- a/IntelFsp2Pkg/Tools/SplitFspBin.py
> +++ b/IntelFsp2Pkg/Tools/SplitFspBin.py
> @@ -469,6 +469,7 @@ class FirmwareVolume:
>          else:             self.FvExtHdr = None         self.FfsList  = []+        self.ChildFvList  =
> []      def ParseFv(self):         fvsize = len(self.FvData)@@ -483,8 +484,30 @@ class
> FirmwareVolume:
>                  offset = fvsize             else:                 ffs = FirmwareFile (offset,
> self.FvData[offset:offset + int(ffshdr.Size)])-                ffs.ParseFfs()-
> self.FfsList.append(ffs)+                # check if there is child fv+                childfvfound
> = 0+                if (ffs.FfsHdr.Type ==
> EFI_FV_FILETYPE.FIRMWARE_VOLUME_IMAGE):+                    csoffset = offset +
> sizeof (EFI_FFS_FILE_HEADER)+                    csoffset = AlignPtr(csoffset, 4)+
> # find fv section+                    while csoffset < (offset + int(ffs.FfsHdr.Size)):+
> cshdr = EFI_COMMON_SECTION_HEADER.from_buffer (self.FvData, csoffset)+
> if (cshdr.Type == EFI_SECTION_TYPE.FIRMWARE_VOLUME_IMAGE):+
> childfvfound = 1+                            break+                        else:+                            #
> check next section+                            csoffset += int(cshdr.Size)+
> csoffset = AlignPtr(csoffset, 4)+                if (childfvfound):+                    childfvoffset
> = csoffset + sizeof (EFI_COMMON_SECTION_HEADER)+                    childfvhdr =
> EFI_FIRMWARE_VOLUME_HEADER.from_buffer (self.FvData, childfvoffset)+
> childfv = FirmwareVolume (childfvoffset, self.FvData[childfvoffset:childfvoffset +
> int(childfvhdr.FvLength)])+                    childfv.ParseFv ()+
> self.ChildFvList.append(childfv)+                else:+                    ffs.ParseFfs()+
> self.FfsList.append(ffs)                 offset += int(ffshdr.Size)                 offset =
> AlignPtr(offset) @@ -789,6 +812,13 @@ def SplitFspBin (fspfile, outdir,
> nametemplate):
>              hfsp.write(fv.FvData)         hfsp.close() +def GetImageFromFv (fd,
> parentfvoffset, fv, imglist):+    for ffs in fv.FfsList:+        for sec in ffs.SecList:+
> if sec.SecHdr.Type in [EFI_SECTION_TYPE.TE, EFI_SECTION_TYPE.PE32]:   # TE or
> PE32+                offset = fd.Offset + parentfvoffset + fv.Offset + ffs.Offset +
> sec.Offset + sizeof(sec.SecHdr)+                imglist.append ((offset, len(sec.SecData)
> - sizeof(sec.SecHdr)))+ def RebaseFspBin (FspBinary, FspComponent, FspBase,
> OutputDir, OutputFile):     fd = FirmwareDevice(0, FspBinary)     fd.ParseFd  ()@@ -
> 832,11 +862,11 @@ def RebaseFspBin (FspBinary, FspComponent, FspBase,
> OutputDir, OutputFile):
>          imglist = []         for fvidx in fsp.FvIdxList:             fv = fd.FvList[fvidx]-            for
> ffs in fv.FfsList:-                for sec in ffs.SecList:-                    if sec.SecHdr.Type in
> [EFI_SECTION_TYPE.TE, EFI_SECTION_TYPE.PE32]:   # TE or PE32-
> offset = fd.Offset + fv.Offset + ffs.Offset + sec.Offset + sizeof(sec.SecHdr)-
> imglist.append ((offset, len(sec.SecData) - sizeof(sec.SecHdr)))+
> GetImageFromFv (fd, 0, fv, imglist)+            # get image from child fv+            for
> childfv in fv.ChildFvList:+                print ("Get image from child fv of fv%d, parent
> fv offset: 0x%x" % (fvidx, fv.Offset))+                GetImageFromFv (fd, fv.Offset,
> childfv, imglist)          fcount  = 0         pcount  = 0--
> 2.40.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#107124): https://edk2.groups.io/g/devel/message/107124
Mute This Topic: https://groups.io/mt/100252890/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [edk2-devel][PATCH v2] IntelFsp2Pkg: Support child FV in SplitFspBin.py
  2023-07-20 10:19 [edk2-devel][PATCH v2] IntelFsp2Pkg: Support child FV in SplitFspBin.py Kuo, Ted
  2023-07-21 14:34 ` Chiu, Chasel
@ 2023-08-28 20:31 ` Chiu, Chasel
  1 sibling, 0 replies; 3+ messages in thread
From: Chiu, Chasel @ 2023-08-28 20:31 UTC (permalink / raw)
  To: Kuo, Ted, devel@edk2.groups.io
  Cc: Desimone, Nathaniel L, Zeng, Star, S, Ashraf Ali,
	Duggapu, Chinni B, Ng, Ray Han Lim, Mohapatra, Susovan


Merged:
https://github.com/tianocore/edk2/commit/2c7fd32676272e22ed44fdfc8fa7e47f5c7a93b8

Thanks,
Chasel


> -----Original Message-----
> From: Kuo, Ted <ted.kuo@intel.com>
> Sent: Thursday, July 20, 2023 3:20 AM
> To: devel@edk2.groups.io
> Cc: Chiu, Chasel <chasel.chiu@intel.com>; Desimone, Nathaniel L
> <nathaniel.l.desimone@intel.com>; Zeng, Star <star.zeng@intel.com>; S, Ashraf
> Ali <ashraf.ali.s@intel.com>; Duggapu, Chinni B <chinni.b.duggapu@intel.com>;
> Ng, Ray Han Lim <ray.han.lim.ng@intel.com>; Mohapatra, Susovan
> <susovan.mohapatra@intel.com>
> Subject: [edk2-devel][PATCH v2] IntelFsp2Pkg: Support child FV in SplitFspBin.py
> 
> https://bugzilla.tianocore.org/show_bug.cgi?id=4502
> Update SplitFspBin.py to support child FV in FSP binary. Without the patch, the
> tool won't be able to rebase the images in child FV in FSP binary.
> 
> Cc: Chasel Chiu <chasel.chiu@intel.com>
> Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
> Cc: Star Zeng <star.zeng@intel.com>
> Cc: Ashraf Ali S <ashraf.ali.s@intel.com>
> Cc: Chinni B Duggapu <chinni.b.duggapu@intel.com>
> Cc: Ray Han Lim Ng <ray.han.lim.ng@intel.com>
> Cc: Susovan Mohapatra <susovan.mohapatra@intel.com>
> Signed-off-by: Ted Kuo <ted.kuo@intel.com>
> ---
>  IntelFsp2Pkg/Tools/SplitFspBin.py | 44 ++++++++++++++++++++++++++-----
>  1 file changed, 37 insertions(+), 7 deletions(-)
> 
> diff --git a/IntelFsp2Pkg/Tools/SplitFspBin.py b/IntelFsp2Pkg/Tools/SplitFspBin.py
> index 419e5ba985..558eaf401a 100644
> --- a/IntelFsp2Pkg/Tools/SplitFspBin.py
> +++ b/IntelFsp2Pkg/Tools/SplitFspBin.py
> @@ -469,6 +469,7 @@ class FirmwareVolume:
>          else:             self.FvExtHdr = None         self.FfsList  = []+        self.ChildFvList  =
> []      def ParseFv(self):         fvsize = len(self.FvData)@@ -483,8 +484,30 @@ class
> FirmwareVolume:
>                  offset = fvsize             else:                 ffs = FirmwareFile (offset,
> self.FvData[offset:offset + int(ffshdr.Size)])-                ffs.ParseFfs()-
> self.FfsList.append(ffs)+                # check if there is child fv+                childfvfound
> = 0+                if (ffs.FfsHdr.Type ==
> EFI_FV_FILETYPE.FIRMWARE_VOLUME_IMAGE):+                    csoffset = offset +
> sizeof (EFI_FFS_FILE_HEADER)+                    csoffset = AlignPtr(csoffset, 4)+
> # find fv section+                    while csoffset < (offset + int(ffs.FfsHdr.Size)):+
> cshdr = EFI_COMMON_SECTION_HEADER.from_buffer (self.FvData, csoffset)+
> if (cshdr.Type == EFI_SECTION_TYPE.FIRMWARE_VOLUME_IMAGE):+
> childfvfound = 1+                            break+                        else:+                            #
> check next section+                            csoffset += int(cshdr.Size)+
> csoffset = AlignPtr(csoffset, 4)+                if (childfvfound):+                    childfvoffset
> = csoffset + sizeof (EFI_COMMON_SECTION_HEADER)+                    childfvhdr =
> EFI_FIRMWARE_VOLUME_HEADER.from_buffer (self.FvData, childfvoffset)+
> childfv = FirmwareVolume (childfvoffset, self.FvData[childfvoffset:childfvoffset +
> int(childfvhdr.FvLength)])+                    childfv.ParseFv ()+
> self.ChildFvList.append(childfv)+                else:+                    ffs.ParseFfs()+
> self.FfsList.append(ffs)                 offset += int(ffshdr.Size)                 offset =
> AlignPtr(offset) @@ -789,6 +812,13 @@ def SplitFspBin (fspfile, outdir,
> nametemplate):
>              hfsp.write(fv.FvData)         hfsp.close() +def GetImageFromFv (fd,
> parentfvoffset, fv, imglist):+    for ffs in fv.FfsList:+        for sec in ffs.SecList:+
> if sec.SecHdr.Type in [EFI_SECTION_TYPE.TE, EFI_SECTION_TYPE.PE32]:   # TE or
> PE32+                offset = fd.Offset + parentfvoffset + fv.Offset + ffs.Offset +
> sec.Offset + sizeof(sec.SecHdr)+                imglist.append ((offset, len(sec.SecData)
> - sizeof(sec.SecHdr)))+ def RebaseFspBin (FspBinary, FspComponent, FspBase,
> OutputDir, OutputFile):     fd = FirmwareDevice(0, FspBinary)     fd.ParseFd  ()@@ -
> 832,11 +862,11 @@ def RebaseFspBin (FspBinary, FspComponent, FspBase,
> OutputDir, OutputFile):
>          imglist = []         for fvidx in fsp.FvIdxList:             fv = fd.FvList[fvidx]-            for
> ffs in fv.FfsList:-                for sec in ffs.SecList:-                    if sec.SecHdr.Type in
> [EFI_SECTION_TYPE.TE, EFI_SECTION_TYPE.PE32]:   # TE or PE32-
> offset = fd.Offset + fv.Offset + ffs.Offset + sec.Offset + sizeof(sec.SecHdr)-
> imglist.append ((offset, len(sec.SecData) - sizeof(sec.SecHdr)))+
> GetImageFromFv (fd, 0, fv, imglist)+            # get image from child fv+            for
> childfv in fv.ChildFvList:+                print ("Get image from child fv of fv%d, parent
> fv offset: 0x%x" % (fvidx, fv.Offset))+                GetImageFromFv (fd, fv.Offset,
> childfv, imglist)          fcount  = 0         pcount  = 0--
> 2.40.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#108066): https://edk2.groups.io/g/devel/message/108066
Mute This Topic: https://groups.io/mt/100252890/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-08-28 20:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-20 10:19 [edk2-devel][PATCH v2] IntelFsp2Pkg: Support child FV in SplitFspBin.py Kuo, Ted
2023-07-21 14:34 ` Chiu, Chasel
2023-08-28 20:31 ` Chiu, Chasel

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