-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmstar_gcistool
executable file
·80 lines (62 loc) · 2.69 KB
/
mstar_gcistool
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python3
from io import BufferedReader
from mstarbintools import gcis
import argparse
if __name__ == '__main__':
parser = argparse.ArgumentParser(
prog='Mstar Bintools - GCIS tool',
description='Tool for creating/viewing MStar GCIS (Global Chip information structure?) blobs',
epilog='')
parser.add_argument('--infile', nargs='?', type=argparse.FileType('rb'))
parser.add_argument('--devicesz', nargs='?', help="The size of the device in bytes")
parser.add_argument('--deviceblocks', nargs='?', help="The size of the device in blocks")
parser.add_argument('--blocksz', nargs='?', help="The size of a block in bytes")
parser.add_argument('--blockpages', nargs='?', help="The size of a block in pages")
parser.add_argument('--pagesz', nargs='?', help='The size of a page in bytes')
parser.add_argument('--sparesz', nargs='?', help='The size of the spare/OOB area')
parser.add_argument('--sectorsz', nargs='?',
help='The size of a sector in bytes -- This seems to be the ECC size..')
parser.add_argument('--bl0offset', nargs='?', type=int, help='The offset of bl0 in bytes')
parser.add_argument('--bl1offset', nargs='?', type=int, help='The offset of bl1 in bytes')
parser.add_argument('--bl0pba', nargs='?', type=int, help='The offset of bl0 in blocks')
parser.add_argument('--bl1pba', nargs='?', type=int, help='The offset of bl1 in block')
parser.add_argument('--outfile', nargs='?', type=argparse.FileType('wb'))
args = parser.parse_args()
if args.bl0offset and args.bl0pba:
print("Don't specify bl0offset and bl0pba")
exit(1)
if args.bl1offset and args.bl1pba:
print("Don't specify bl1offset and bl1pba")
exit(1)
infile: BufferedReader = args.infile
outfile: BufferedReader = args.outfile
# Create default CIS
old_cis = gcis.GCIS()
new_cis = gcis.GCIS()
if infile:
data = infile.read()
print("Dump of input GCIS (%d bytes):" % len(data))
old_cis = gcis.unpack(data)
old_cis.dump()
new_cis = old_cis
# work out if and what to set the bl[0|1] pba to
pagesize = old_cis.page_byte_count
bl0pba = None
bl1pba = None
if args.pagesz:
pagesize = args.pagesz
if args.bl0pba:
bl0pba = args.bl0pba
if args.bl1pba:
bl1pba = args.bl1pba
if bl0pba:
new_cis.bl0_pba = bl0pba
if bl1pba:
new_cis.bl1_pba = bl1pba
if new_cis.validate() is False:
print("WARN: New GCIS probably won't boot")
# Write out the result
if outfile:
print("Writing updated GCIS to output")
new_cis.dump()
outfile.write(new_cis.pack())