]> git.proxmox.com Git - mirror_edk2.git/commitdiff
IntelFsp2Pkg: Fix FSP binary rebasing issue for PE32+ image
authorMaurice Ma <maurice.ma@intel.com>
Thu, 12 Nov 2020 00:10:32 +0000 (16:10 -0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Sun, 15 Nov 2020 00:17:18 +0000 (00:17 +0000)
Current FSP rebasing script SplitFspBin.py has support for both
PE32 and PE32+ image formats. However, while updating the ImageBase
field in the image header, it always assumed the ImageBase field is
32bit long. Since PE32+ image format defined ImageBase as 64bit,
the current script will only update the lower 32bit value and leave
the upper 32bit untouched. It does not work well for PE32+ image
that requires update in the upper 32bit ImageBase field. The
expected behavior is to update the full 64bit field. This patch
implemented this fix.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Reviewed-by: Chasel Chiu <chasel.chiu@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Nate DeSimone <nathaniel.l.desimone@intel.com>
IntelFsp2Pkg/Tools/SplitFspBin.py

index 3c0d5af1b671920cb34d65f07d0e88189dd52561..24272e82af88cb832ca68a5fa7a3571f31671112 100644 (file)
@@ -677,8 +677,12 @@ class PeTeImage:
         else:\r
             offset  = self.Offset + self.DosHdr.e_lfanew\r
             offset += EFI_IMAGE_NT_HEADERS32.OptionalHeader.offset\r
-            offset += EFI_IMAGE_OPTIONAL_HEADER32.ImageBase.offset\r
-            size    = EFI_IMAGE_OPTIONAL_HEADER32.ImageBase.size\r
+            if self.PeHdr.OptionalHeader.PePlusOptHdr.Magic == 0x20b: # PE32+ image\r
+                offset += EFI_IMAGE_OPTIONAL_HEADER32_PLUS.ImageBase.offset\r
+                size    = EFI_IMAGE_OPTIONAL_HEADER32_PLUS.ImageBase.size\r
+            else:\r
+                offset += EFI_IMAGE_OPTIONAL_HEADER32.ImageBase.offset\r
+                size    = EFI_IMAGE_OPTIONAL_HEADER32.ImageBase.size\r
 \r
         value  = Bytes2Val(fdbin[offset:offset+size]) + delta\r
         fdbin[offset:offset+size] = Val2Bytes(value, size)\r