forked from Smeat/fusee-launcher
-
Notifications
You must be signed in to change notification settings - Fork 1
/
SoC.py
133 lines (99 loc) · 6.37 KB
/
SoC.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
from rcm_backend import RCMHax
import usb
# Standard Nvidia USB VendorID.
NVIDIA_VID = 0x0955
# USB productID's for various Tegra devices.
T20_PIDS = [0x7820]
T30_PIDS = [0x7030, 0x7130, 0x7330]
T114_PIDS = [0x7335, 0x7535]
T124_PIDS = [0x7140, 0x7f40]
T132_PIDS = [0x7F13]
T210_PIDS = [0x7321, 0x7721]
# RCM Protocol header sizes.
RCM_V1_HEADER_SIZE = 116
RCM_V35_HEADER_SIZE = 628
RCM_V40_HEADER_SIZE = 644
RCM_V4P_HEADER_SIZE = 680
def detect_device(wait_for_device=False, os_override=None, vid=None, pid=None, override_checks=False, debug=False) -> RCMHax:
while True:
if pid is None:
devs = usb.core.find(find_all=1, idVendor=NVIDIA_VID)
else:
devs = usb.core.find(find_all=1, idVendor=NVIDIA_VID, idProduct=pid)
for dev in devs:
try:
if dev.idProduct in T20_PIDS:
return T20(vid=dev.idVendor, pid=dev.idProduct, wait_for_device=wait_for_device, os_override=os_override, override_checks=override_checks, debug=debug)
elif dev.idProduct in T30_PIDS:
return T30(vid=dev.idVendor, pid=dev.idProduct, wait_for_device=wait_for_device, os_override=os_override, override_checks=override_checks, debug=debug)
elif dev.idProduct in T114_PIDS:
return T114(vid=dev.idVendor, pid=dev.idProduct, wait_for_device=wait_for_device, os_override=os_override, override_checks=override_checks, debug=debug)
elif dev.idProduct in T124_PIDS:
return T124(vid=dev.idVendor, pid=dev.idProduct, wait_for_device=wait_for_device, os_override=os_override, override_checks=override_checks, debug=debug)
elif dev.idProduct in T132_PIDS:
return T132(vid=dev.idVendor, pid=dev.idProduct, wait_for_device=wait_for_device, os_override=os_override, override_checks=override_checks, debug=debug)
elif dev.idProduct in T210_PIDS:
return T210(vid=dev.idVendor, pid=dev.idProduct, wait_for_device=wait_for_device, os_override=os_override, override_checks=override_checks, debug=debug)
else:
print("detected an unknown Nvidia device")
print("If this is an error please add the ProductID to SoC.py")
except IOError as e:
print(e)
sys.exit(-1)
if not wait_for_device:
break
return None
class T20(RCMHax):
def __init__(self, wait_for_device=False, os_override=None, vid=None, pid=None, override_checks=False, debug=False):
self.RCM_HEADER_SIZE = RCM_V1_HEADER_SIZE
self.RCM_PAYLOAD_ADDR = 0x40008000
self.COPY_BUFFER_ADDRESSES = [0, 0x40005000] # Lower Buffer doesn't matter
self.STACK_END = self.RCM_PAYLOAD_ADDR
self.STACK_SPRAY_END = self.STACK_END
self.STACK_SPRAY_START = self.STACK_SPRAY_END - 0x200 # 512 Byte should be enough? #0x40009E40
RCMHax.__init__(self, wait_for_device=wait_for_device, os_override=os_override, vid=vid, pid=pid, override_checks=override_checks, debug=debug)
class T30(RCMHax):
def __init__(self, wait_for_device=False, os_override=None, vid=None, pid=None, override_checks=False, debug=False):
self.RCM_HEADER_SIZE = RCM_V1_HEADER_SIZE
self.RCM_PAYLOAD_ADDR = 0x4000A000
self.COPY_BUFFER_ADDRESSES = [0, 0x40005000] # Lower Buffer doesn't matter
self.STACK_END = self.RCM_PAYLOAD_ADDR
self.STACK_SPRAY_END = self.RCM_PAYLOAD_ADDR - 420 # exact position is known.
self.STACK_SPRAY_START = self.STACK_SPRAY_END - 4
RCMHax.__init__(self, wait_for_device=wait_for_device, os_override=os_override, vid=vid, pid=pid, override_checks=override_checks, debug=debug)
class T114(RCMHax):
def __init__(self, wait_for_device=False, os_override=None, vid=None, pid=None, override_checks=False, debug=False):
self.RCM_HEADER_SIZE = RCM_V35_HEADER_SIZE
self.RCM_PAYLOAD_ADDR = 0x4000E000
self.COPY_BUFFER_ADDRESSES = [0, 0x40008000] # Lower Buffer doesn't matter
self.STACK_END = self.RCM_PAYLOAD_ADDR
self.STACK_SPRAY_END = self.STACK_END - 1572 # exact position is known.
self.STACK_SPRAY_START = self.STACK_SPRAY_END - 4
RCMHax.__init__(self, wait_for_device=wait_for_device, os_override=os_override, vid=vid, pid=pid, override_checks=override_checks, debug=debug)
class T124(RCMHax):
def __init__(self, wait_for_device=False, os_override=None, vid=None, pid=None, override_checks=False, debug=False):
self.RCM_HEADER_SIZE = RCM_V40_HEADER_SIZE
self.RCM_PAYLOAD_ADDR = 0x4000E000
self.COPY_BUFFER_ADDRESSES = [0, 0x40008000] # Lower Buffer doesn't matter
self.STACK_END = self.RCM_PAYLOAD_ADDR
self.STACK_SPRAY_END = self.STACK_END
self.STACK_SPRAY_START = self.STACK_SPRAY_END - 0x200 # Might not be enough
RCMHax.__init__(self, wait_for_device=wait_for_device, os_override=os_override, vid=vid, pid=pid, override_checks=override_checks, debug=debug)
class T132(RCMHax):
def __init__(self, wait_for_device=False, os_override=None, vid=None, pid=None, override_checks=False, debug=False):
self.RCM_HEADER_SIZE = RCM_V40_HEADER_SIZE
self.RCM_PAYLOAD_ADDR = 0x4000F000
self.COPY_BUFFER_ADDRESSES = [0, 0x40008000] # Lower Buffer doesn't matter
self.STACK_END = self.RCM_PAYLOAD_ADDR
self.STACK_SPRAY_END = self.STACK_END
self.STACK_SPRAY_START = self.STACK_SPRAY_END - 0x200 # Might not be enough
RCMHax.__init__(self, wait_for_device=wait_for_device, os_override=os_override, vid=vid, pid=pid, override_checks=override_checks, debug=debug)
class T210(RCMHax):
def __init__(self, wait_for_device=False, os_override=None, vid=None, pid=None, override_checks=False, debug=False):
self.RCM_HEADER_SIZE = RCM_V4P_HEADER_SIZE
self.RCM_PAYLOAD_ADDR = 0x40010000
self.COPY_BUFFER_ADDRESSES = [0, 0x40009000] # Lower Buffer doesn't matter
self.STACK_END = self.RCM_PAYLOAD_ADDR
self.STACK_SPRAY_END = self.STACK_END
self.STACK_SPRAY_START = self.STACK_SPRAY_END - 0x200 # Might not be enough
RCMHax.__init__(self, wait_for_device=wait_for_device, os_override=os_override, vid=vid, pid=pid, override_checks=override_checks, debug=debug)