Note: A Python for merge KBC(ITE8512)/BIOS image.

import os
import sys
import getopt

SIZE_64K = 65535L
MAX_KBC = SIZE_64K

def MakeFile(bios, kbc, out):
ft = open(out, “w+b")
fkbc = open(kbc, “rb")
ft.write(fkbc.read())
fkbc.close()
for i in range(SIZE_64K-ft.tell()+1):
ft.write(chr(255))
fbios = open(bios, “rb")
fbios.seek(SIZE_64K+1)
ft.write(fbios.read())
fbios.close()
ft.close()

def CheckFiles(bios, kbc):
if not os.path.isfile(bios) :
print “Error: Not found BIOS file, File:",bios
sys.exit(3)
if not os.path.isfile(kbc) :
print “Error: Not found KBC binary, File:", kbc
sys.exit(4)
if os.path.getsize(kbc) > MAX_KBC:
print “Error: The KBC binary size over 64KB, File:", kbc
sys.exit(5)

return 0

def ShowUsage():
print “""Usage: MBK [Option]
The program will embed KBC/ITE8512x binary into BIOS image.
Options:
-h, –help              Display this usage message
-v, –verbose           Show run step information
-b, –bios <file>        Bios image files, MUST assign
-k, –kbc <file>        ITE8512x binary, MUST assign,
the file size must less 64KByte
-o, –output <file>     Output file name
“""

def CheckArgs(argv):
try:
opts, args = getopt.getopt(argv[1:], “hvb:k:o:", [“help", “verbose", “bios=", “kbc=", “output="])
except getopt.error, msg:
print msg
print “for help use –help"
sys.exit(2)

verbose = False
kbc = “"
bios = “"
out = “outbios.bin"
help = False
for o, a in opts:
if o in (“-h", “–help") :
help = True
elif o in (“-v", “–verbose"):
verbose = True
elif o in (“-b", “–bios") :
bios = a
elif o in (“-k", “–kbc") :
kbc = a
elif o in (“-o", “–output") :
out = a

if not bios:
help = True
if not kbc:
help = True
if help :
SignOn(True)
ShowUsage()
sys.exit(2)
return bios, kbc, out, verbose

def SignOn(verbose):
if verbose :
print ‘Embed ITE8512x binary into BIOS v1.0 by KunYi’
def main(argv=sys.argv):
biosFile, kbcFile, outFile, verbose = CheckArgs(argv)
SignOn(verbose)
CheckFiles(biosFile, kbcFile)
MakeFile(biosFile, kbcFile, outFile)
return 0

if __name__ == “__main__":
sys.exit(main())

廣告

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

您的留言將使用 WordPress.com 帳號。 登出 / 變更 )

Twitter picture

您的留言將使用 Twitter 帳號。 登出 / 變更 )

Facebook照片

您的留言將使用 Facebook 帳號。 登出 / 變更 )

Google+ photo

您的留言將使用 Google+ 帳號。 登出 / 變更 )

連結到 %s

%d 位部落客按了讚: