+#\r
+# Check FSP header is valid or not\r
+#\r
+# param [in] binfile Binary file\r
+#\r
+# retval boolean True: valid; False: invalid\r
+#\r
+def IsFspHeaderValid (binfile):\r
+ fd = open (binfile, "rb")\r
+ bindat = fd.read(0x200) # only read first 0x200 bytes\r
+ fd.close()\r
+ HeaderList = ['FSPH' , 'FSPP' , 'FSPE'] # Check 'FSPH', 'FSPP', and 'FSPE' in the FSP header\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]: # If 'FSPH' or 'FSPP' is missing, it will return false\r
+ return False\r
+ Revision = ord(bindat[OffsetList[0] + 0x0B])\r
+ #\r
+ # if revision is bigger than 1, it means it is FSP v1.1 or greater revision, which must contain 'FSPE'.\r
+ #\r
+ if Revision > 1 and not OffsetList[2]:\r
+ return False # If FSP v1.1 or greater without 'FSPE', then return false\r
+ return True\r
+\r
+#\r
+# Patch data in file\r
+#\r
+# param [in] binfile Binary file\r
+# param [in] offset Offset\r
+# param [in] value Patch value\r
+# param [in] len Length\r
+#\r
+# retval len Length\r
+#\r