## @ 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
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
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
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
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
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
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