forked from superna9999/pyamlboot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
boot-g12.py
executable file
·79 lines (60 loc) · 2.5 KB
/
boot-g12.py
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import argparse
import time
import os
import pkg_resources
from pyamlboot import pyamlboot
def list_boards(p):
return [ d for d in os.listdir(p) if os.path.isdir(os.path.join(p, d)) and os.path.isfile(os.path.join(p, d, "u-boot.bin")) ]
def parse_cmdline(fpath):
boards = list_boards(fpath)
parser = argparse.ArgumentParser(description="USB boot tool for Amlogic G12 SoCs",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--version', '-v', action='version', version='%(prog)s 1.0')
parser.add_argument('binary', action='store',
help="binary to load or name of board")
parser.add_argument('--board-name', '-b', dest='bname', action='store_true',
help="main argument becomes the name of the board to load (%s)" % boards)
args = parser.parse_args()
return args
if __name__ == '__main__':
try:
dist = pkg_resources.get_distribution('pyamlboot')
fpath = os.path.join(dist.get_resource_filename(pkg_resources.ResourceManager(), "files"))
except:
fpath = os.path.join(os.path.dirname(os.path.realpath(__file__)), "files")
args = parse_cmdline(fpath)
if args.bname:
bpath = os.path.join(fpath, args.binary, "u-boot.bin")
else:
bpath = args.binary
dev = pyamlboot.AmlogicSoC()
socid = dev.identify()
print("Firmware Version :")
print("ROM: %d.%d Stage: %d.%d" % (ord(socid[0]), ord(socid[1]), ord(socid[2]), ord(socid[3])))
print("Need Password: %d Password OK: %d" % (ord(socid[4]), ord(socid[5])))
loadAddr = 0xfffa0000
with open(bpath, "rb") as f:
seq = 0
data = f.read()
print("Writing %s at 0x%x..." % (bpath, loadAddr))
dev.writeLargeMemory(0xfffa0000, data[0:0x10000], 4096)
print("[DONE]")
print("Running at 0x%x..." % loadAddr)
dev.run(0xfffa0000)
print("[DONE]")
time.sleep(2)
prevLength = -1
prevOffset = -1
while True:
(length, offset) = dev.getBootAMLC()
if length == prevLength and offset == prevOffset:
print("[BL2 END]")
break
prevLength = length
prevOffset = offset
print("AMLC dataSize=%d, offset=%d, seq=%d..." % (length, offset, seq))
dev.writeAMLCData(seq, offset, data[offset:offset+length])
print("[DONE]")
seq = seq + 1