]>
git.proxmox.com Git - mirror_edk2.git/blob - IntelFsp2Pkg/Tools/PatchFv.py
3 # Copyright (c) 2014 - 2018, Intel Corporation. All rights reserved.<BR>
4 # SPDX-License-Identifier: BSD-2-Clause-Patent
15 # param [in] binfile Binary file
16 # param [in] offset Offset
17 # param [in] len Length
21 def readDataFromFile (binfile
, offset
, len=1):
22 fd
= open(binfile
, "r+b")
23 fsize
= os
.path
.getsize(binfile
)
24 offval
= offset
& 0xFFFFFFFF
25 if (offval
& 0x80000000):
26 offval
= fsize
- (0xFFFFFFFF - offval
+ 1)
28 bytearray
= [ord(b
) for b
in fd
.read(len)]
32 value
= value
<< 8 | bytearray
[idx
]
38 # Check FSP header is valid or not
40 # param [in] binfile Binary file
42 # retval boolean True: valid; False: invalid
44 def IsFspHeaderValid (binfile
):
45 fd
= open (binfile
, "rb")
46 bindat
= fd
.read(0x200) # only read first 0x200 bytes
48 HeaderList
= ['FSPH' , 'FSPP' , 'FSPE'] # Check 'FSPH', 'FSPP', and 'FSPE' in the FSP header
50 for each
in HeaderList
:
52 idx
= bindat
.index(each
)
55 OffsetList
.append(idx
)
56 if not OffsetList
[0] or not OffsetList
[1]: # If 'FSPH' or 'FSPP' is missing, it will return false
58 Revision
= ord(bindat
[OffsetList
[0] + 0x0B])
60 # if revision is bigger than 1, it means it is FSP v1.1 or greater revision, which must contain 'FSPE'.
62 if Revision
> 1 and not OffsetList
[2]:
63 return False # If FSP v1.1 or greater without 'FSPE', then return false
69 # param [in] binfile Binary file
70 # param [in] offset Offset
71 # param [in] value Patch value
72 # param [in] len Length
76 def patchDataInFile (binfile
, offset
, value
, len=1):
77 fd
= open(binfile
, "r+b")
78 fsize
= os
.path
.getsize(binfile
)
79 offval
= offset
& 0xFFFFFFFF
80 if (offval
& 0x80000000):
81 offval
= fsize
- (0xFFFFFFFF - offval
+ 1)
85 bytearray
.append(value
& 0xFF)
89 fd
.write("".join(chr(b
) for b
in bytearray
))
96 self
.dictSymbolAddress
= {}
97 self
.dictGuidNameXref
= {}
98 self
.dictFfsOffset
= {}
99 self
.dictVariable
= {}
100 self
.dictModBase
= {}
103 self
.fdBase
= 0xFFFFFFFF
107 self
.parenthesisOpenSet
= '([{<'
108 self
.parenthesisCloseSet
= ')]}>'
113 # retval self.fdFile Retrieve FD file
115 def getFdFile (self
):
121 # retval self.fdSize Retrieve the size of FD file
123 def getFdSize (self
):
126 def parseFvInfFile (self
, infFile
):
128 fvFile
= infFile
[0:-4] + ".Fv"
129 fvInfo
['Name'] = os
.path
.splitext(os
.path
.basename(infFile
))[0]
130 fvInfo
['Offset'] = self
.getFvOffsetInFd(fvFile
)
131 fvInfo
['Size'] = readDataFromFile (fvFile
, 0x20, 4)
132 fdIn
= open(infFile
, "r")
133 rptLines
= fdIn
.readlines()
136 for rptLine
in rptLines
:
137 match
= re
.match("^EFI_BASE_ADDRESS\s*=\s*(0x[a-fA-F0-9]+)", rptLine
)
139 fvInfo
['Base'] = int(match
.group(1), 16)
141 self
.fvList
.append(dict(fvInfo
))
145 # Create dictionaries
147 # param [in] fvDir FV's directory
148 # param [in] fvNames All FV's names
150 # retval 0 Created dictionaries successfully
152 def createDicts (self
, fvDir
, fvNames
):
154 # If the fvDir is not a dirctory, then raise an exception
156 if not os
.path
.isdir(fvDir
):
157 raise Exception ("'%s' is not a valid directory!" % FvDir
)
160 # If the Guid.xref is not existing in fvDir, then raise an exception
162 xrefFile
= os
.path
.join(fvDir
, "Guid.xref")
163 if not os
.path
.exists(xrefFile
):
164 raise Exception("Cannot open GUID Xref file '%s'!" % xrefFile
)
167 # Add GUID reference to dictionary
169 self
.dictGuidNameXref
= {}
170 self
.parseGuidXrefFile(xrefFile
)
173 # Split up each FV from fvNames and get the fdBase
175 fvList
= fvNames
.split(":")
176 fdBase
= fvList
.pop()
178 fvList
.append(fdBase
)
181 # If the FD file is not existing, then raise an exception
183 fdFile
= os
.path
.join(fvDir
, fdBase
.strip() + ".fd")
184 if not os
.path
.exists(fdFile
):
185 raise Exception("Cannot open FD file '%s'!" % fdFile
)
188 # Get the size of the FD file
191 self
.fdSize
= os
.path
.getsize(fdFile
)
194 # If the INF file, which is the first element of fvList, is not existing, then raise an exception
196 infFile
= os
.path
.join(fvDir
, fvList
[0].strip()) + ".inf"
197 if not os
.path
.exists(infFile
):
198 raise Exception("Cannot open INF file '%s'!" % infFile
)
201 # Parse INF file in order to get fdBase and then assign those values to dictVariable
203 self
.parseInfFile(infFile
)
204 self
.dictVariable
= {}
205 self
.dictVariable
["FDSIZE"] = self
.fdSize
206 self
.dictVariable
["FDBASE"] = self
.fdBase
209 # Collect information from FV MAP file and FV TXT file then
210 # put them into dictionaries
213 self
.dictSymbolAddress
= {}
214 self
.dictFfsOffset
= {}
218 # If the .Fv.map file is not existing, then raise an exception.
219 # Otherwise, parse FV MAP file
221 fvFile
= os
.path
.join(fvDir
, file.strip()) + ".Fv"
222 mapFile
= fvFile
+ ".map"
223 if not os
.path
.exists(mapFile
):
224 raise Exception("Cannot open MAP file '%s'!" % mapFile
)
226 infFile
= fvFile
[0:-3] + ".inf"
227 self
.parseFvInfFile(infFile
)
228 self
.parseFvMapFile(mapFile
)
231 # If the .Fv.txt file is not existing, then raise an exception.
232 # Otherwise, parse FV TXT file
234 fvTxtFile
= fvFile
+ ".txt"
235 if not os
.path
.exists(fvTxtFile
):
236 raise Exception("Cannot open FV TXT file '%s'!" % fvTxtFile
)
238 self
.parseFvTxtFile(fvTxtFile
)
240 for fv
in self
.fvList
:
241 self
.dictVariable
['_BASE_%s_' % fv
['Name']] = fv
['Base']
243 # Search all MAP files in FFS directory if it exists then parse MOD MAP file
245 ffsDir
= os
.path
.join(fvDir
, "Ffs")
246 if (os
.path
.isdir(ffsDir
)):
247 for item
in os
.listdir(ffsDir
):
248 if len(item
) <= 0x24:
250 mapFile
=os
.path
.join(ffsDir
, item
, "%s.map" % item
[0:0x24])
251 if not os
.path
.exists(mapFile
):
253 self
.parseModMapFile(item
[0x24:], mapFile
)
258 # Get FV offset in FD file
260 # param [in] fvFile FV file
262 # retval offset Got FV offset successfully
264 def getFvOffsetInFd(self
, fvFile
):
266 # Check if the first 0x70 bytes of fvFile can be found in fdFile
268 fvHandle
= open(fvFile
, "r+b")
269 fdHandle
= open(self
.fdFile
, "r+b")
270 offset
= fdHandle
.read().find(fvHandle
.read(0x70))
274 raise Exception("Could not locate FV file %s in FD!" % fvFile
)
280 # param [in] infFile INF file
282 # retval 0 Parsed INF file successfully
284 def parseInfFile(self
, infFile
):
286 # Get FV offset and search EFI_BASE_ADDRESS in the FD file
287 # then assign the value of EFI_BASE_ADDRESS to fdBase
289 fvOffset
= self
.getFvOffsetInFd(infFile
[0:-4] + ".Fv")
290 fdIn
= open(infFile
, "r")
291 rptLine
= fdIn
.readline()
292 self
.fdBase
= 0xFFFFFFFF
293 while (rptLine
!= "" ):
294 #EFI_BASE_ADDRESS = 0xFFFDF400
295 match
= re
.match("^EFI_BASE_ADDRESS\s*=\s*(0x[a-fA-F0-9]+)", rptLine
)
296 if match
is not None:
297 self
.fdBase
= int(match
.group(1), 16) - fvOffset
298 rptLine
= fdIn
.readline()
300 if self
.fdBase
== 0xFFFFFFFF:
301 raise Exception("Could not find EFI_BASE_ADDRESS in INF file!" % fvFile
)
307 # param [in] fvTxtFile .Fv.txt file
309 # retval 0 Parsed FV TXT file successfully
311 def parseFvTxtFile(self
, fvTxtFile
):
312 fvName
= os
.path
.basename(fvTxtFile
)[0:-7].upper()
314 # Get information from .Fv.txt in order to create a dictionary
316 # self.dictFfsOffset[912740BE-2284-4734-B971-84B027353F0C] = 0x000D4078
318 fvOffset
= self
.getFvOffsetInFd(fvTxtFile
[0:-4])
319 fdIn
= open(fvTxtFile
, "r")
320 rptLine
= fdIn
.readline()
321 while (rptLine
!= "" ):
322 match
= re
.match("(0x[a-fA-F0-9]+)\s([0-9a-fA-F\-]+)", rptLine
)
323 if match
is not None:
324 if match
.group(2) in self
.dictFfsOffset
:
325 self
.dictFfsOffset
[fvName
+ ':' + match
.group(2)] = "0x%08X" % (int(match
.group(1), 16) + fvOffset
)
327 self
.dictFfsOffset
[match
.group(2)] = "0x%08X" % (int(match
.group(1), 16) + fvOffset
)
328 rptLine
= fdIn
.readline()
335 # param [in] mapFile .Fv.map file
337 # retval 0 Parsed FV MAP file successfully
339 def parseFvMapFile(self
, mapFile
):
341 # Get information from .Fv.map in order to create dictionaries
343 # self.dictModBase[FspSecCore:BASE] = 4294592776 (0xfffa4908)
344 # self.dictModBase[FspSecCore:ENTRY] = 4294606552 (0xfffa7ed8)
345 # self.dictModBase[FspSecCore:TEXT] = 4294593080 (0xfffa4a38)
346 # self.dictModBase[FspSecCore:DATA] = 4294612280 (0xfffa9538)
347 # self.dictSymbolAddress[FspSecCore:_SecStartup] = 0x00fffa4a38
349 fdIn
= open(mapFile
, "r")
350 rptLine
= fdIn
.readline()
353 while (rptLine
!= "" ):
354 if rptLine
[0] != ' ':
355 #DxeIpl (Fixed Flash Address, BaseAddress=0x00fffb4310, EntryPoint=0x00fffb4958)
356 #(GUID=86D70125-BAA3-4296-A62F-602BEBBB9081 .textbaseaddress=0x00fffb4398 .databaseaddress=0x00fffb4178)
357 match
= re
.match("([_a-zA-Z0-9\-]+)\s\(.+BaseAddress=(0x[0-9a-fA-F]+),\s+EntryPoint=(0x[0-9a-fA-F]+)\)", rptLine
)
358 if match
is not None:
360 modName
= match
.group(1)
361 if len(modName
) == 36:
362 modName
= self
.dictGuidNameXref
[modName
.upper()]
363 self
.dictModBase
['%s:BASE' % modName
] = int (match
.group(2), 16)
364 self
.dictModBase
['%s:ENTRY' % modName
] = int (match
.group(3), 16)
365 match
= re
.match("\(GUID=([A-Z0-9\-]+)\s+\.textbaseaddress=(0x[0-9a-fA-F]+)\s+\.databaseaddress=(0x[0-9a-fA-F]+)\)", rptLine
)
366 if match
is not None:
370 modName
= match
.group(1)
371 if len(modName
) == 36:
372 modName
= self
.dictGuidNameXref
[modName
.upper()]
373 self
.dictModBase
['%s:TEXT' % modName
] = int (match
.group(2), 16)
374 self
.dictModBase
['%s:DATA' % modName
] = int (match
.group(3), 16)
376 # 0x00fff8016c __ModuleEntryPoint
378 match
= re
.match("^\s+(0x[a-z0-9]+)\s+([_a-zA-Z0-9]+)", rptLine
)
379 if match
is not None:
380 self
.dictSymbolAddress
["%s:%s"%(modName
, match
.group(2))] = match
.group(1)
381 rptLine
= fdIn
.readline()
388 # param [in] moduleName Module name
389 # param [in] mapFile .Fv.map file
391 # retval 0 Parsed MOD MAP file successfully
392 # retval 1 There is no moduleEntryPoint in modSymbols
394 def parseModMapFile(self
, moduleName
, mapFile
):
396 # Get information from mapFile by moduleName in order to create a dictionary
398 # self.dictSymbolAddress[FspSecCore:___guard_fids_count] = 0x00fffa4778
401 fdIn
= open(mapFile
, "r")
402 reportLines
= fdIn
.readlines()
405 moduleEntryPoint
= "__ModuleEntryPoint"
406 reportLine
= reportLines
[0]
407 if reportLine
.strip().find("Archive member included") != -1:
409 # 0x0000000000001d55 IoRead8
410 patchMapFileMatchString
= "\s+(0x[0-9a-fA-F]{16})\s+([^\s][^0x][_a-zA-Z0-9\-]+)\s"
411 matchKeyGroupIndex
= 2
412 matchSymbolGroupIndex
= 1
416 #0003:00000190 _gComBase 00007a50 SerialPo
417 patchMapFileMatchString
= "^\s[0-9a-fA-F]{4}:[0-9a-fA-F]{8}\s+(\w+)\s+([0-9a-fA-F]{8}\s+)"
418 matchKeyGroupIndex
= 1
419 matchSymbolGroupIndex
= 2
422 for reportLine
in reportLines
:
423 match
= re
.match(patchMapFileMatchString
, reportLine
)
424 if match
is not None:
425 modSymbols
[prefix
+ match
.group(matchKeyGroupIndex
)] = match
.group(matchSymbolGroupIndex
)
427 # Handle extra module patchable PCD variable in Linux map since it might have different format
428 # .data._gPcd_BinaryPatch_PcdVpdBaseAddress
429 # 0x0000000000003714 0x4 /tmp/ccmytayk.ltrans1.ltrans.o
431 if matchSymbolGroupIndex
== 1:
432 for reportLine
in reportLines
:
435 pcdName
= match
.group(1)
436 match
= re
.match("\s+(0x[0-9a-fA-F]{16})\s+", reportLine
)
437 if match
is not None:
438 modSymbols
[prefix
+ pcdName
] = match
.group(1)
440 match
= re
.match("^\s\.data\.(_gPcd_BinaryPatch[_a-zA-Z0-9\-]+)", reportLine
)
441 if match
is not None:
445 if not moduleEntryPoint
in modSymbols
:
448 modEntry
= '%s:%s' % (moduleName
,moduleEntryPoint
)
449 if not modEntry
in self
.dictSymbolAddress
:
450 modKey
= '%s:ENTRY' % moduleName
451 if modKey
in self
.dictModBase
:
452 baseOffset
= self
.dictModBase
['%s:ENTRY' % moduleName
] - int(modSymbols
[moduleEntryPoint
], 16)
456 baseOffset
= int(self
.dictSymbolAddress
[modEntry
], 16) - int(modSymbols
[moduleEntryPoint
], 16)
457 for symbol
in modSymbols
:
458 fullSym
= "%s:%s" % (moduleName
, symbol
)
459 if not fullSym
in self
.dictSymbolAddress
:
460 self
.dictSymbolAddress
[fullSym
] = "0x00%08x" % (baseOffset
+ int(modSymbols
[symbol
], 16))
464 # Parse Guid.xref file
466 # param [in] xrefFile the full directory of Guid.xref file
468 # retval 0 Parsed Guid.xref file successfully
470 def parseGuidXrefFile(self
, xrefFile
):
472 # Get information from Guid.xref in order to create a GuidNameXref dictionary
473 # The dictGuidNameXref, for example, will be like
474 # dictGuidNameXref [1BA0062E-C779-4582-8566-336AE8F78F09] = FspSecCore
476 fdIn
= open(xrefFile
, "r")
477 rptLine
= fdIn
.readline()
478 while (rptLine
!= "" ):
479 match
= re
.match("([0-9a-fA-F\-]+)\s([_a-zA-Z0-9]+)", rptLine
)
480 if match
is not None:
481 self
.dictGuidNameXref
[match
.group(1).upper()] = match
.group(2)
482 rptLine
= fdIn
.readline()
487 # Get current character
489 # retval elf.string[self.index]
490 # retval '' Exception
494 return self
.string
[self
.index
]
499 # Check to see if it is last index
504 return self
.index
== len(self
.string
)
516 while not self
.isLast():
517 if self
.getCurr() in ' \t':
527 def parseValue(self
):
530 while not self
.isLast():
531 char
= self
.getCurr()
532 if char
.lower() in '_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789:-':
539 partList
= var
.split(':')
540 lenList
= len(partList
)
541 if lenList
!= 2 and lenList
!= 3:
542 raise Exception("Unrecognized expression %s" % var
)
543 modName
= partList
[lenList
-2]
544 modOff
= partList
[lenList
-1]
545 if ('-' not in modName
) and (modOff
[0] in '0123456789'):
547 var
= self
.getModGuid(modName
) + ":" + modOff
548 if '-' in var
: # GUID:OFFSET
549 value
= self
.getGuidOff(var
)
551 value
= self
.getSymbols(var
)
554 if var
[0] in '0123456789':
555 value
= self
.getNumber(var
)
557 value
= self
.getVariable(var
)
561 # Parse single operation
563 # retval ~self.parseBrace() or self.parseValue()
565 def parseSingleOp(self
):
567 char
= self
.getCurr()
570 return ~self
.parseBrace()
572 return self
.parseValue()
575 # Parse symbol of Brace([, {, <)
577 # retval value or self.parseSingleOp()
579 def parseBrace(self
):
581 char
= self
.getCurr()
582 parenthesisType
= self
.parenthesisOpenSet
.find(char
)
583 if parenthesisType
>= 0:
585 value
= self
.parseExpr()
587 if self
.getCurr() != self
.parenthesisCloseSet
[parenthesisType
]:
588 raise Exception("No closing brace")
590 if parenthesisType
== 1: # [ : Get content
591 value
= self
.getContent(value
)
592 elif parenthesisType
== 2: # { : To address
593 value
= self
.toAddress(value
)
594 elif parenthesisType
== 3: # < : To offset
595 value
= self
.toOffset(value
)
598 return self
.parseSingleOp()
601 # Parse symbol of Multiplier(*)
603 # retval value or self.parseSingleOp()
606 values
= [self
.parseBrace()]
609 char
= self
.getCurr()
612 values
.append(self
.parseBrace())
621 # Parse symbol of And(&) and Or(|)
625 def parseAndOr(self
):
626 value
= self
.parseMul()
630 char
= self
.getCurr()
633 value
&= self
.parseMul()
635 div_index
= self
.index
637 value |
= self
.parseMul()
644 # Parse symbol of Add(+) and Minus(-)
648 def parseAddMinus(self
):
649 values
= [self
.parseAndOr()]
652 char
= self
.getCurr()
655 values
.append(self
.parseAndOr())
658 values
.append(-1 * self
.parseAndOr())
666 # retval self.parseAddMinus()
669 return self
.parseAddMinus()
677 value
= self
.parseExpr()
679 if not self
.isLast():
680 raise Exception("Unexpected character found '%s'" % self
.getCurr())
688 def getModGuid(self
, var
):
689 guid
= (guid
for guid
,name
in self
.dictGuidNameXref
.items() if name
==var
)
693 raise Exception("Unknown module name %s !" % var
)
701 def getVariable(self
, var
):
702 value
= self
.dictVariable
.get(var
, None)
704 raise Exception("Unrecognized variable '%s'" % var
)
712 def getNumber(self
, var
):
714 if var
.startswith('0x'): # HEX
727 def getContent(self
, value
):
728 return readDataFromFile (self
.fdFile
, self
.toOffset(value
), 4)
731 # Change value to address
737 def toAddress(self
, value
):
738 if value
< self
.fdSize
:
739 value
= value
+ self
.fdBase
743 # Change value to offset
749 def toOffset(self
, value
):
751 for fvInfo
in self
.fvList
:
752 if (value
>= fvInfo
['Base']) and (value
< fvInfo
['Base'] + fvInfo
['Size']):
753 offset
= value
- fvInfo
['Base'] + fvInfo
['Offset']
755 if (value
>= self
.fdBase
) and (value
< self
.fdBase
+ self
.fdSize
):
756 offset
= value
- self
.fdBase
759 if offset
>= self
.fdSize
:
760 raise Exception("Invalid file offset 0x%08x !" % value
)
770 def getGuidOff(self
, value
):
772 symbolName
= value
.split(':')
773 if len(symbolName
) == 3:
774 fvName
= symbolName
[0].upper()
775 keyName
= '%s:%s' % (fvName
, symbolName
[1])
776 offStr
= symbolName
[2]
777 elif len(symbolName
) == 2:
778 keyName
= symbolName
[0]
779 offStr
= symbolName
[1]
780 if keyName
in self
.dictFfsOffset
:
781 value
= (int(self
.dictFfsOffset
[keyName
], 16) + int(offStr
, 16)) & 0xFFFFFFFF
783 raise Exception("Unknown GUID %s !" % value
)
793 def getSymbols(self
, value
):
794 if self
.dictSymbolAddress
.has_key(value
):
796 ret
= int (self
.dictSymbolAddress
[value
], 16)
798 raise Exception("Unknown symbol %s !" % value
)
804 # param [in] expression
805 # param [in] isOffset
807 # retval value & 0xFFFFFFFF
809 def evaluate(self
, expression
, isOffset
):
812 self
.string
= expression
813 value
= self
.getResult()
816 # Consider it as an address first
817 value
= self
.toOffset(value
)
818 if value
& 0x80000000:
819 # Consider it as a negative offset next
820 offset
= (~value
& 0xFFFFFFFF) + 1
821 if offset
< self
.fdSize
:
822 value
= self
.fdSize
- offset
823 if value
>= self
.fdSize
:
824 raise Exception("Invalid offset expression !")
825 return value
& 0xFFFFFFFF
828 # Print out the usage
831 print "Usage: \n\tPatchFv FvBuildDir [FvFileBaseNames:]FdFileBaseNameToPatch \"Offset, Value\""
835 # Parse the options and args
837 symTables
= Symbols()
840 # If the arguments are less than 4, then return an error.
842 if len(sys
.argv
) < 4:
847 # If it fails to create dictionaries, then return an error.
849 if symTables
.createDicts(sys
.argv
[1], sys
.argv
[2]) != 0:
850 print "ERROR: Failed to create symbol dictionary!!"
854 # Get FD file and size
856 fdFile
= symTables
.getFdFile()
857 fdSize
= symTables
.getFdSize()
861 # Check to see if FSP header is valid
863 ret
= IsFspHeaderValid(fdFile
)
865 raise Exception ("The FSP header is not valid. Stop patching FD.")
867 for fvFile
in sys
.argv
[3:]:
869 # Check to see if it has enough arguments
871 items
= fvFile
.split(",")
873 raise Exception("Expect more arguments for '%s'!" % fvFile
)
880 if item
.startswith("@"):
882 elif item
.startswith("$"):
890 # Parse symbols then append it to params
892 params
.append (symTables
.evaluate(item
, isOffset
))
895 # Patch a new value into FD file if it is not a command
899 if len (params
) == 2:
902 oldvalue
= readDataFromFile(fdFile
, offset
, 4)
903 ret
= patchDataInFile (fdFile
, offset
, value
, 4) - 4
905 raise Exception ("Patch command needs 2 parameters !")
908 raise Exception ("Patch failed for offset 0x%08X" % offset
)
910 print "Patched offset 0x%08X:[%08X] with value 0x%08X # %s" % (offset
, oldvalue
, value
, comment
)
912 elif command
== "COPY":
914 # Copy binary block from source to destination
916 if len (params
) == 3:
917 src
= symTables
.toOffset(params
[0])
918 dest
= symTables
.toOffset(params
[1])
919 clen
= symTables
.toOffset(params
[2])
920 if (dest
+ clen
<= fdSize
) and (src
+ clen
<= fdSize
):
921 oldvalue
= readDataFromFile(fdFile
, src
, clen
)
922 ret
= patchDataInFile (fdFile
, dest
, oldvalue
, clen
) - clen
924 raise Exception ("Copy command OFFSET or LENGTH parameter is invalid !")
926 raise Exception ("Copy command needs 3 parameters !")
929 raise Exception ("Copy failed from offset 0x%08X to offset 0x%08X!" % (src
, dest
))
931 print "Copied %d bytes from offset 0x%08X ~ offset 0x%08X # %s" % (clen
, src
, dest
, comment
)
933 raise Exception ("Unknown command %s!" % command
)
936 except Exception as (ex
):
937 print "ERROR: %s" % ex
940 if __name__
== '__main__':