]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFspPkg/Tools/PatchFv.py
Update IntelFspPkg to support FSP1.1
[mirror_edk2.git] / IntelFspPkg / Tools / PatchFv.py
index cc22cc201e3dbd9501a023d4528d43114409666f..2143161d2c204184d3ccce16e45cb2aead9df391 100644 (file)
@@ -1,6 +1,6 @@
 ## @ PatchFv.py\r
 #\r
-# Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.<BR>\r
 # This program and the accompanying materials are licensed and made available under\r
 # the terms and conditions of the BSD License that accompanies this distribution.\r
 # The full text of the license may be found at\r
@@ -23,14 +23,33 @@ def readDataFromFile (binfile, offset, len=1):
         offval = fsize - (0xFFFFFFFF - offval + 1)\r
     fd.seek(offval)\r
     bytearray = [ord(b) for b in fd.read(len)]\r
-    value = 0;\r
-    idx   = len - 1;\r
+    value = 0\r
+    idx   = len - 1\r
     while  idx >= 0:\r
         value = value << 8 | bytearray[idx]\r
         idx = idx - 1\r
     fd.close()\r
     return value\r
 \r
+def IsFspHeaderValid (binfile):\r
+    fd     = open (binfile, "rb")\r
+    bindat = fd.read(0x200)\r
+    fd.close()\r
+    HeaderList = ['FSPH' , 'FSPP' , 'FSPE']\r
+    OffsetList = []\r
+    for each in HeaderList:\r
+        if each in bindat:\r
+            idx = bindat.index(each)\r
+        else:\r
+            idx = 0\r
+        OffsetList.append(idx)\r
+    if not OffsetList[0] or not OffsetList[1]:\r
+        return False\r
+    Revision = ord(bindat[OffsetList[0] + 0x0B])\r
+    if Revision > 1 and not OffsetList[2]:\r
+        return False\r
+    return True\r
+\r
 def patchDataInFile (binfile, offset, value, len=1):\r
     fd     = open(binfile, "r+b")\r
     fsize  = os.path.getsize(binfile)\r
@@ -38,7 +57,7 @@ def patchDataInFile (binfile, offset, value, len=1):
     if (offval & 0x80000000):\r
         offval = fsize - (0xFFFFFFFF - offval + 1)\r
     bytearray = []\r
-    idx = 0;\r
+    idx = 0\r
     while  idx < len:\r
         bytearray.append(value & 0xFF)\r
         value          = value >> 8\r
@@ -46,7 +65,7 @@ def patchDataInFile (binfile, offset, value, len=1):
     fd.seek(offval)\r
     fd.write("".join(chr(b) for b in bytearray))\r
     fd.close()\r
-    return len;\r
+    return len\r
 \r
 \r
 class Symbols:\r
@@ -346,7 +365,7 @@ class Symbols:
                 values.append(self.parseBrace())\r
             else:\r
                 break\r
-        value  = 1;\r
+        value  = 1\r
         for each in values:\r
             value *= each\r
         return value\r
@@ -354,7 +373,7 @@ class Symbols:
     def parseAndOr(self):\r
         values = [self.parseMul()]\r
         op     = None\r
-        value  = 0xFFFFFFFF;\r
+        value  = 0xFFFFFFFF\r
         while True:\r
             self.skipSpace()\r
             char = self.getCurr()\r
@@ -500,6 +519,9 @@ def main():
     fdSize = symTables.getFdSize()\r
 \r
     try:\r
+        ret = IsFspHeaderValid(fdFile)\r
+        if ret == False:\r
+          raise Exception ("The FSP header is not valid. Stop patching FD.")\r
         comment = ""\r
         for fvFile in  sys.argv[3:]:\r
             items = fvFile.split(",")\r