| Line 24... |
Line 24... |
| 24 |
import sys
|
24 |
import sys
|
| 25 |
import struct
|
25 |
import struct
|
| 26 |
import usb.core
|
26 |
import usb.core
|
| 27 |
import libembiosdata
|
27 |
import libembiosdata
|
| 28 |
|
28 |
|
| - |
|
29 |
from functools import wraps
|
| - |
|
30 |
|
| 29 |
class Error(Exception):
|
31 |
class Error(Exception):
|
| 30 |
def __init__(self, value=None):
|
32 |
def __init__(self, value=None):
|
| 31 |
self.value = value
|
33 |
self.value = value
|
| 32 |
def __str__(self):
|
34 |
def __str__(self):
|
| 33 |
if self.value != None:
|
35 |
if self.value != None:
|
| Line 64... |
Line 66... |
| 64 |
def __setstate__(self, state):
|
66 |
def __setstate__(self, state):
|
| 65 |
self.update(state)
|
67 |
self.update(state)
|
| 66 |
self.__dict__ = self
|
68 |
self.__dict__ = self
|
| 67 |
|
69 |
|
| 68 |
|
70 |
|
| - |
|
71 |
def command(timeout = None):
|
| - |
|
72 |
"""
|
| - |
|
73 |
Decorator for all commands.
|
| - |
|
74 |
It adds the "timeout" variable to all commands.
|
| - |
|
75 |
It also provides the possibility to set the timeout directly in the decorator.
|
| - |
|
76 |
It also includes some dirty hacks to not learn from.
|
| - |
|
77 |
"""
|
| - |
|
78 |
time = timeout # dirty hack because otherwise it would raise a scoping problem.
|
| - |
|
79 |
# The reason is probably because I suck but I can't find any good explanation of this.
|
| - |
|
80 |
def decorator(func):
|
| - |
|
81 |
@wraps(func)
|
| - |
|
82 |
def wrapper(*args, **kwargs):
|
| - |
|
83 |
# precommand stuff
|
| - |
|
84 |
self = args[0] # little cheat as it expects self being always the first argument
|
| - |
|
85 |
timeout = None
|
| - |
|
86 |
if "timeout" in kwargs.keys():
|
| - |
|
87 |
timeout = kwargs['timeout']
|
| - |
|
88 |
elif time is not None:
|
| - |
|
89 |
timeout = time
|
| - |
|
90 |
if timeout is not None:
|
| - |
|
91 |
oldtimeout = self.lib.dev.timeout
|
| - |
|
92 |
self.lib.dev.timeout = timeout
|
| - |
|
93 |
# function call
|
| - |
|
94 |
ret = func(*args)
|
| - |
|
95 |
# postcommand stuff
|
| - |
|
96 |
if timeout is not None:
|
| - |
|
97 |
self.lib.dev.timeout = oldtimeout
|
| - |
|
98 |
return ret
|
| - |
|
99 |
return wrapper
|
| - |
|
100 |
return decorator
|
| - |
|
101 |
|
| - |
|
102 |
|
| 69 |
class Embios(object):
|
103 |
class Embios(object):
|
| 70 |
"""
|
104 |
"""
|
| 71 |
Class for all embios functions.
|
105 |
Class for all embios functions.
|
| - |
|
106 |
They all get the "@command()" decorator.
|
| - |
|
107 |
This decorator has a timeout variable that can be set to change the
|
| - |
|
108 |
device timeout for the duration of the function.
|
| - |
|
109 |
It also adds a "timeout" argument to every function to access this
|
| - |
|
110 |
feature from external. So DON'T EVER use a parameter called 'timeout'
|
| - |
|
111 |
in your commands. Variables are ok.
|
| 72 |
"""
|
112 |
"""
|
| 73 |
def __init__(self):
|
113 |
def __init__(self):
|
| 74 |
self.lib = Lib()
|
114 |
self.lib = Lib()
|
| 75 |
|
115 |
|
| 76 |
self.getversioninfo()
|
116 |
self.getversioninfo()
|
| Line 89... |
Line 129... |
| 89 |
tailaddr = (end - min(end - bodyaddr, blksize) + align - 1) & ~(align - 1)
|
129 |
tailaddr = (end - min(end - bodyaddr, blksize) + align - 1) & ~(align - 1)
|
| 90 |
else: tailaddr = end
|
130 |
else: tailaddr = end
|
| 91 |
tailsize = end - tailaddr
|
131 |
tailsize = end - tailaddr
|
| 92 |
return (headsize, tailaddr - bodyaddr, tailsize)
|
132 |
return (headsize, tailaddr - bodyaddr, tailsize)
|
| 93 |
|
133 |
|
| - |
|
134 |
@command()
|
| 94 |
def _readmem(self, addr, size):
|
135 |
def _readmem(self, addr, size):
|
| 95 |
""" Reads the memory from location 'addr' with size 'size'
|
136 |
""" Reads the memory from location 'addr' with size 'size'
|
| 96 |
from the device.
|
137 |
from the device.
|
| 97 |
"""
|
138 |
"""
|
| 98 |
resp = self.lib.monitorcommand(struct.pack("IIII", 4, addr, size, 0), "III%ds" % size, (None, None, None, "data"))
|
139 |
resp = self.lib.monitorcommand(struct.pack("IIII", 4, addr, size, 0), "III%ds" % size, (None, None, None, "data"))
|
| 99 |
return resp.data
|
140 |
return resp.data
|
| 100 |
|
141 |
|
| - |
|
142 |
@command()
|
| 101 |
def _writemem(self, addr, data):
|
143 |
def _writemem(self, addr, data):
|
| 102 |
""" Writes the data in 'data' to the location 'addr'
|
144 |
""" Writes the data in 'data' to the location 'addr'
|
| 103 |
in the memory of the device.
|
145 |
in the memory of the device.
|
| 104 |
"""
|
146 |
"""
|
| 105 |
return self.lib.monitorcommand(struct.pack("IIII%ds" % len(data), 5, addr, len(data), 0, data), "III", (None, None, None))
|
147 |
return self.lib.monitorcommand(struct.pack("IIII%ds" % len(data), 5, addr, len(data), 0, data), "III", (None, None, None))
|
| 106 |
|
148 |
|
| - |
|
149 |
@command()
|
| 107 |
def _readdma(self, addr, size):
|
150 |
def _readdma(self, addr, size):
|
| 108 |
""" Reads the memory from location 'addr' with size 'size'
|
151 |
""" Reads the memory from location 'addr' with size 'size'
|
| 109 |
from the device. This uses DMA and the data in endpoint.
|
152 |
from the device. This uses DMA and the data in endpoint.
|
| 110 |
"""
|
153 |
"""
|
| 111 |
self.lib.monitorcommand(struct.pack("IIII", 6, addr, size, 0), "III", (None, None, None))
|
154 |
self.lib.monitorcommand(struct.pack("IIII", 6, addr, size, 0), "III", (None, None, None))
|
| 112 |
return struct.unpack("%ds" % size, self.lib.dev.din(size))[0]
|
155 |
return struct.unpack("%ds" % size, self.lib.dev.din(size))[0]
|
| 113 |
|
156 |
|
| - |
|
157 |
@command()
|
| 114 |
def _writedma(self, addr, data):
|
158 |
def _writedma(self, addr, data):
|
| 115 |
""" Writes the data in 'data' to the location 'addr'
|
159 |
""" Writes the data in 'data' to the location 'addr'
|
| 116 |
in the memory of the device. This uses DMA and the data out endpoint.
|
160 |
in the memory of the device. This uses DMA and the data out endpoint.
|
| 117 |
"""
|
161 |
"""
|
| 118 |
self.lib.monitorcommand(struct.pack("IIII", 7, addr, len(data), 0), "III", (None, None, None))
|
162 |
self.lib.monitorcommand(struct.pack("IIII", 7, addr, len(data), 0), "III", (None, None, None))
|
| 119 |
return self.lib.dev.dout(data)
|
163 |
return self.lib.dev.dout(data)
|
| 120 |
|
164 |
|
| - |
|
165 |
@command()
|
| 121 |
def getversioninfo(self):
|
166 |
def getversioninfo(self):
|
| 122 |
""" This returns the emBIOS version and device information. """
|
167 |
""" This returns the emBIOS version and device information. """
|
| 123 |
resp = self.lib.monitorcommand(struct.pack("IIII", 1, 0, 0, 0), "IBBBBI", ("revision", "majorv", "minorv", "patchv", "swtypeid", "hwtypeid"))
|
168 |
resp = self.lib.monitorcommand(struct.pack("IIII", 1, 0, 0, 0), "IBBBBI", ("revision", "majorv", "minorv", "patchv", "swtypeid", "hwtypeid"))
|
| 124 |
self.lib.dev.version.revision = resp.revision
|
169 |
self.lib.dev.version.revision = resp.revision
|
| 125 |
self.lib.dev.version.majorv = resp.majorv
|
170 |
self.lib.dev.version.majorv = resp.majorv
|
| Line 127... |
Line 172... |
| 127 |
self.lib.dev.version.patchv = resp.patchv
|
172 |
self.lib.dev.version.patchv = resp.patchv
|
| 128 |
self.lib.dev.swtypeid = resp.swtypeid
|
173 |
self.lib.dev.swtypeid = resp.swtypeid
|
| 129 |
self.lib.dev.hwtypeid = resp.hwtypeid
|
174 |
self.lib.dev.hwtypeid = resp.hwtypeid
|
| 130 |
return resp
|
175 |
return resp
|
| 131 |
|
176 |
|
| - |
|
177 |
@command()
|
| 132 |
def getpacketsizeinfo(self):
|
178 |
def getpacketsizeinfo(self):
|
| 133 |
""" This returns the emBIOS max packet size information.
|
179 |
""" This returns the emBIOS max packet size information.
|
| 134 |
It also sets the properties of the device object accordingly.
|
180 |
It also sets the properties of the device object accordingly.
|
| 135 |
"""
|
181 |
"""
|
| 136 |
resp = self.lib.monitorcommand(struct.pack("IIII", 1, 1, 0, 0), "HHII", ("coutmax", "cinmax", "doutmax", "dinmax"))
|
182 |
resp = self.lib.monitorcommand(struct.pack("IIII", 1, 1, 0, 0), "HHII", ("coutmax", "cinmax", "doutmax", "dinmax"))
|
| Line 138... |
Line 184... |
| 138 |
self.lib.dev.packetsizelimit.cin = resp.cinmax
|
184 |
self.lib.dev.packetsizelimit.cin = resp.cinmax
|
| 139 |
self.lib.dev.packetsizelimit.din = resp.dinmax
|
185 |
self.lib.dev.packetsizelimit.din = resp.dinmax
|
| 140 |
self.lib.dev.packetsizelimit.dout = resp.doutmax
|
186 |
self.lib.dev.packetsizelimit.dout = resp.doutmax
|
| 141 |
return resp
|
187 |
return resp
|
| 142 |
|
188 |
|
| - |
|
189 |
@command()
|
| 143 |
def getusermemrange(self):
|
190 |
def getusermemrange(self):
|
| 144 |
""" This returns the memory range the user has access to. """
|
191 |
""" This returns the memory range the user has access to. """
|
| 145 |
resp = self.lib.monitorcommand(struct.pack("IIII", 1, 2, 0, 0), "III", ("lower", "upper", None))
|
192 |
resp = self.lib.monitorcommand(struct.pack("IIII", 1, 2, 0, 0), "III", ("lower", "upper", None))
|
| 146 |
self.lib.dev.usermem.lower = resp.lower
|
193 |
self.lib.dev.usermem.lower = resp.lower
|
| 147 |
self.lib.dev.usermem.upper = resp.upper
|
194 |
self.lib.dev.usermem.upper = resp.upper
|
| 148 |
return resp
|
195 |
return resp
|
| 149 |
|
196 |
|
| - |
|
197 |
@command()
|
| 150 |
def reset(self, force=False):
|
198 |
def reset(self, force=False):
|
| 151 |
""" Reboot the device """
|
199 |
""" Reboot the device """
|
| 152 |
if force:
|
200 |
if force:
|
| 153 |
return self.lib.monitorcommand(struct.pack("IIII", 2, 0, 0, 0))
|
201 |
return self.lib.monitorcommand(struct.pack("IIII", 2, 0, 0, 0))
|
| 154 |
else:
|
202 |
else:
|
| 155 |
return self.lib.monitorcommand(struct.pack("IIII", 2, 1, 0, 0), "III", (None, None, None))
|
203 |
return self.lib.monitorcommand(struct.pack("IIII", 2, 1, 0, 0), "III", (None, None, None))
|
| 156 |
|
204 |
|
| - |
|
205 |
@command()
|
| 157 |
def poweroff(self, force=False):
|
206 |
def poweroff(self, force=False):
|
| 158 |
""" Powers the device off. """
|
207 |
""" Powers the device off. """
|
| 159 |
if force:
|
208 |
if force:
|
| 160 |
return self.lib.monitorcommand(struct.pack("IIII", 3, 0, 0, 0))
|
209 |
return self.lib.monitorcommand(struct.pack("IIII", 3, 0, 0, 0))
|
| 161 |
else:
|
210 |
else:
|
| 162 |
return self.lib.monitorcommand(struct.pack("IIII", 3, 1, 0, 0), "III", (None, None, None))
|
211 |
return self.lib.monitorcommand(struct.pack("IIII", 3, 1, 0, 0), "III", (None, None, None))
|
| 163 |
|
212 |
|
| - |
|
213 |
@command()
|
| 164 |
def read(self, addr, size):
|
214 |
def read(self, addr, size):
|
| 165 |
""" Reads the memory from location 'addr' with size 'size'
|
215 |
""" Reads the memory from location 'addr' with size 'size'
|
| 166 |
from the device. This cares about too long packages
|
216 |
from the device. This cares about too long packages
|
| 167 |
and decides whether to use DMA or not.
|
217 |
and decides whether to use DMA or not.
|
| 168 |
"""
|
218 |
"""
|
| Line 184... |
Line 234... |
| 184 |
bodysize -= readsize
|
234 |
bodysize -= readsize
|
| 185 |
if tailsize != 0:
|
235 |
if tailsize != 0:
|
| 186 |
data += self._readmem(addr, tailsize)
|
236 |
data += self._readmem(addr, tailsize)
|
| 187 |
return data
|
237 |
return data
|
| 188 |
|
238 |
|
| - |
|
239 |
@command()
|
| 189 |
def write(self, addr, data):
|
240 |
def write(self, addr, data):
|
| 190 |
""" Writes the data in 'data' to the location 'addr'
|
241 |
""" Writes the data in 'data' to the location 'addr'
|
| 191 |
in the memory of the device. This cares about too long packages
|
242 |
in the memory of the device. This cares about too long packages
|
| 192 |
and decides whether to use DMA or not.
|
243 |
and decides whether to use DMA or not.
|
| 193 |
"""
|
244 |
"""
|
| Line 211... |
Line 262... |
| 211 |
bodysize -= writesize
|
262 |
bodysize -= writesize
|
| 212 |
if tailsize != 0:
|
263 |
if tailsize != 0:
|
| 213 |
self._writemem(addr, data[offset:offset+tailsize])
|
264 |
self._writemem(addr, data[offset:offset+tailsize])
|
| 214 |
return data
|
265 |
return data
|
| 215 |
|
266 |
|
| - |
|
267 |
@command()
|
| 216 |
def readstring(self, addr, maxlength = 256):
|
268 |
def readstring(self, addr, maxlength = 256):
|
| 217 |
""" Reads a zero terminated string from memory
|
269 |
""" Reads a zero terminated string from memory
|
| 218 |
Reads only a maximum of 'maxlength' chars.
|
270 |
Reads only a maximum of 'maxlength' chars.
|
| 219 |
"""
|
271 |
"""
|
| 220 |
cin_maxsize = self.lib.dev.packetsizelimit.cin - self.lib.headersize
|
272 |
cin_maxsize = self.lib.dev.packetsizelimit.cin - self.lib.headersize
|
| Line 228... |
Line 280... |
| 228 |
else:
|
280 |
else:
|
| 229 |
string += data
|
281 |
string += data
|
| 230 |
addr += cin_maxsize
|
282 |
addr += cin_maxsize
|
| 231 |
return string
|
283 |
return string
|
| 232 |
|
284 |
|
| - |
|
285 |
@command()
|
| 233 |
def i2cread(self, index, slaveaddr, startaddr, size):
|
286 |
def i2cread(self, index, slaveaddr, startaddr, size):
|
| 234 |
""" Reads data from an i2c slave """
|
287 |
""" Reads data from an i2c slave """
|
| 235 |
data = ""
|
288 |
data = ""
|
| 236 |
for i in range(size):
|
289 |
for i in range(size):
|
| 237 |
resp = self.lib.monitorcommand(struct.pack("IBBBBII", 8, index, slaveaddr, startaddr + i, 1, 0, 0), "III1s", (None, None, None, "data"))
|
290 |
resp = self.lib.monitorcommand(struct.pack("IBBBBII", 8, index, slaveaddr, startaddr + i, 1, 0, 0), "III1s", (None, None, None, "data"))
|
| 238 |
data += resp.data
|
291 |
data += resp.data
|
| 239 |
return data
|
292 |
return data
|
| 240 |
|
293 |
|
| - |
|
294 |
@command()
|
| 241 |
def i2cwrite(self, index, slaveaddr, startaddr, data):
|
295 |
def i2cwrite(self, index, slaveaddr, startaddr, data):
|
| 242 |
""" Writes data to an i2c slave """
|
296 |
""" Writes data to an i2c slave """
|
| 243 |
size = len(data)
|
297 |
size = len(data)
|
| 244 |
if size > 256 or size < 1:
|
298 |
if size > 256 or size < 1:
|
| 245 |
raise ArgumentError("Size must be a number between 1 and 256")
|
299 |
raise ArgumentError("Size must be a number between 1 and 256")
|
| 246 |
if size == 256:
|
300 |
if size == 256:
|
| 247 |
size = 0
|
301 |
size = 0
|
| 248 |
return self.lib.monitorcommand(struct.pack("IBBBBII%ds" % size, 9, index, slaveaddr, startaddr, size, 0, 0, data), "III", (None, None, None))
|
302 |
return self.lib.monitorcommand(struct.pack("IBBBBII%ds" % size, 9, index, slaveaddr, startaddr, size, 0, 0, data), "III", (None, None, None))
|
| 249 |
|
303 |
|
| - |
|
304 |
@command()
|
| 250 |
def usbcread(self):
|
305 |
def usbcread(self):
|
| 251 |
""" Reads one packet with the maximal cin size """
|
306 |
""" Reads one packet with the maximal cin size """
|
| 252 |
cin_maxsize = self.lib.dev.packetsizelimit.cin - self.lib.headersize
|
307 |
cin_maxsize = self.lib.dev.packetsizelimit.cin - self.lib.headersize
|
| 253 |
resp = self.lib.monitorcommand(struct.pack("IIII", 10, cin_maxsize, 0, 0), "III%ds" % cin_maxsize, ("validsize", "buffersize", "queuesize", "data"))
|
308 |
resp = self.lib.monitorcommand(struct.pack("IIII", 10, cin_maxsize, 0, 0), "III%ds" % cin_maxsize, ("validsize", "buffersize", "queuesize", "data"))
|
| 254 |
resp.data = resp.data[:resp.validsize]
|
309 |
resp.data = resp.data[:resp.validsize]
|
| 255 |
resp.maxsize = cin_maxsize
|
310 |
resp.maxsize = cin_maxsize
|
| 256 |
return resp
|
311 |
return resp
|
| 257 |
|
312 |
|
| - |
|
313 |
@command()
|
| 258 |
def usbcwrite(self, data):
|
314 |
def usbcwrite(self, data):
|
| 259 |
""" Writes data to the USB console """
|
315 |
""" Writes data to the USB console """
|
| 260 |
cin_maxsize = self.lib.dev.packetsizelimit.cin - self.lib.headersize
|
316 |
cin_maxsize = self.lib.dev.packetsizelimit.cin - self.lib.headersize
|
| 261 |
size = len(data)
|
317 |
size = len(data)
|
| 262 |
while len(data) > 0:
|
318 |
while len(data) > 0:
|
| 263 |
writesize = min(cin_maxsize, len(data))
|
319 |
writesize = min(cin_maxsize, len(data))
|
| 264 |
resp = self.lib.monitorcommand(struct.pack("IIII%ds" % writesize, 11, writesize, 0, 0, data[:writesize]), "III", ("validsize", "buffersize", "freesize"))
|
320 |
resp = self.lib.monitorcommand(struct.pack("IIII%ds" % writesize, 11, writesize, 0, 0, data[:writesize]), "III", ("validsize", "buffersize", "freesize"))
|
| 265 |
data = data[resp.validsize:]
|
321 |
data = data[resp.validsize:]
|
| 266 |
return size
|
322 |
return size
|
| 267 |
|
323 |
|
| - |
|
324 |
@command()
|
| 268 |
def cread(self, bitmask=0x1):
|
325 |
def cread(self, bitmask=0x1):
|
| 269 |
""" Reads one packet with the maximal cin size from the device consoles
|
326 |
""" Reads one packet with the maximal cin size from the device consoles
|
| 270 |
identified with the specified bitmask
|
327 |
identified with the specified bitmask
|
| 271 |
"""
|
328 |
"""
|
| 272 |
cin_maxsize = self.lib.dev.packetsizelimit.cin - self.lib.headersize
|
329 |
cin_maxsize = self.lib.dev.packetsizelimit.cin - self.lib.headersize
|
| 273 |
resp = self.lib.monitorcommand(struct.pack("IIII", 13, bitmask, cin_maxsize, 0), "III%ds" % cin_maxsize, ("size", None, None))
|
330 |
resp = self.lib.monitorcommand(struct.pack("IIII", 13, bitmask, cin_maxsize, 0), "III%ds" % cin_maxsize, ("size", None, None))
|
| 274 |
resp.data = resp.data[size:]
|
331 |
resp.data = resp.data[size:]
|
| 275 |
resp.maxsize = cin_maxsize
|
332 |
resp.maxsize = cin_maxsize
|
| 276 |
return resp
|
333 |
return resp
|
| 277 |
|
334 |
|
| - |
|
335 |
@command()
|
| 278 |
def cwrite(self, data, bitmask=0x1):
|
336 |
def cwrite(self, data, bitmask=0x1):
|
| 279 |
""" Writes data to the device consoles
|
337 |
""" Writes data to the device consoles
|
| 280 |
identified with the specified bitmask.
|
338 |
identified with the specified bitmask.
|
| 281 |
"""
|
339 |
"""
|
| 282 |
cin_maxsize = self.lib.dev.packetsizelimit.cin - self.lib.headersize
|
340 |
cin_maxsize = self.lib.dev.packetsizelimit.cin - self.lib.headersize
|
| Line 285... |
Line 343... |
| 285 |
writesize = min(cin_maxsize, len(data))
|
343 |
writesize = min(cin_maxsize, len(data))
|
| 286 |
resp = self.lib.monitorcommand(struct.pack("IIII%ds" % writesize, 12, bitmask, writesize, 0, data[:writesize]), "III", (None, None, None))
|
344 |
resp = self.lib.monitorcommand(struct.pack("IIII%ds" % writesize, 12, bitmask, writesize, 0, data[:writesize]), "III", (None, None, None))
|
| 287 |
data = data[writesize:]
|
345 |
data = data[writesize:]
|
| 288 |
return size
|
346 |
return size
|
| 289 |
|
347 |
|
| - |
|
348 |
@command()
|
| 290 |
def cflush(self, bitmask):
|
349 |
def cflush(self, bitmask):
|
| 291 |
""" Flushes the consoles specified with 'bitmask' """
|
350 |
""" Flushes the consoles specified with 'bitmask' """
|
| 292 |
return self.lib.monitorcommand(struct.pack("IIII", 14, bitmask, 0, 0), "III", (None, None, None))
|
351 |
return self.lib.monitorcommand(struct.pack("IIII", 14, bitmask, 0, 0), "III", (None, None, None))
|
| 293 |
|
352 |
|
| - |
|
353 |
@command()
|
| 294 |
def getprocinfo(self):
|
354 |
def getprocinfo(self):
|
| 295 |
""" Gets current state of the scheduler """
|
355 |
""" Gets current state of the scheduler """
|
| 296 |
cin_maxsize = self.lib.dev.packetsizelimit.cin - self.lib.headersize
|
356 |
cin_maxsize = self.lib.dev.packetsizelimit.cin - self.lib.headersize
|
| 297 |
# Get the size
|
357 |
# Get the size
|
| 298 |
schedulerstate = self.lockscheduler()
|
358 |
schedulerstate = self.lockscheduler()
|
| Line 353... |
Line 413... |
| 353 |
info.cpuload = threaddata[31]
|
413 |
info.cpuload = threaddata[31]
|
| 354 |
threads.append(info)
|
414 |
threads.append(info)
|
| 355 |
id += 1
|
415 |
id += 1
|
| 356 |
return threads
|
416 |
return threads
|
| 357 |
|
417 |
|
| - |
|
418 |
@command()
|
| 358 |
def lockscheduler(self, freeze=True):
|
419 |
def lockscheduler(self, freeze=True):
|
| 359 |
""" Freezes/Unfreezes the scheduler """
|
420 |
""" Freezes/Unfreezes the scheduler """
|
| 360 |
resp = self.lib.monitorcommand(struct.pack("IIII", 16, 1 if freeze else 0, 0, 0), "III", ("before", None, None))
|
421 |
resp = self.lib.monitorcommand(struct.pack("IIII", 16, 1 if freeze else 0, 0, 0), "III", ("before", None, None))
|
| 361 |
return True if resp.before == 1 else False
|
422 |
return True if resp.before == 1 else False
|
| 362 |
|
423 |
|
| - |
|
424 |
@command()
|
| 363 |
def unlockscheduler(self):
|
425 |
def unlockscheduler(self):
|
| 364 |
""" Unfreezes the scheduler """
|
426 |
""" Unfreezes the scheduler """
|
| 365 |
return self.lib.monitorcommand(struct.pack("IIII", 16, 0, 0, 0), "III", ("before", None, None))
|
427 |
return self.lib.monitorcommand(struct.pack("IIII", 16, 0, 0, 0), "III", ("before", None, None))
|
| 366 |
|
428 |
|
| - |
|
429 |
@command()
|
| 367 |
def suspendthread(self, id, suspend=True):
|
430 |
def suspendthread(self, id, suspend=True):
|
| 368 |
""" Suspends the thread with the specified id """
|
431 |
""" Suspends the thread with the specified id """
|
| 369 |
resp = self.lib.monitorcommand(struct.pack("IIII", 17, 1 if suspend else 0, id, 0), "III", ("before", None, None))
|
432 |
resp = self.lib.monitorcommand(struct.pack("IIII", 17, 1 if suspend else 0, id, 0), "III", ("before", None, None))
|
| 370 |
return True if resp.before == 1 else False
|
433 |
return True if resp.before == 1 else False
|
| 371 |
|
434 |
|
| - |
|
435 |
@command()
|
| 372 |
def resumethread(self, id):
|
436 |
def resumethread(self, id):
|
| 373 |
""" Resumes the thread with the specified id """
|
437 |
""" Resumes the thread with the specified id """
|
| 374 |
return self.lib.monitorcommand(struct.pack("IIII", 17, 0, id, 0), "III", ("before", None, None))
|
438 |
return self.lib.monitorcommand(struct.pack("IIII", 17, 0, id, 0), "III", ("before", None, None))
|
| 375 |
|
439 |
|
| - |
|
440 |
@command()
|
| 376 |
def killthread(self, id):
|
441 |
def killthread(self, id):
|
| 377 |
""" Kills the thread with the specified id """
|
442 |
""" Kills the thread with the specified id """
|
| 378 |
return self.lib.monitorcommand(struct.pack("IIII", 18, id, 0, 0), "III", ("before", None, None))
|
443 |
return self.lib.monitorcommand(struct.pack("IIII", 18, id, 0, 0), "III", ("before", None, None))
|
| 379 |
|
444 |
|
| - |
|
445 |
@command()
|
| 380 |
def createthread(self, nameptr, entrypoint, stackptr, stacksize, threadtype, priority, state):
|
446 |
def createthread(self, nameptr, entrypoint, stackptr, stacksize, threadtype, priority, state):
|
| 381 |
""" Creates a thread with the specified attributes """
|
447 |
""" Creates a thread with the specified attributes """
|
| 382 |
if threadtype == "user":
|
448 |
if threadtype == "user":
|
| 383 |
threadtype = 0
|
449 |
threadtype = 0
|
| 384 |
elif threadtype == "system":
|
450 |
elif threadtype == "system":
|
| Line 396... |
Line 462... |
| 396 |
resp = self.lib.monitorcommand(struct.pack("IIIIIIII", 19, nameptr, entrypoint, stackptr, stacksize, threadtype, priority, state), "III", (id, None, None))
|
462 |
resp = self.lib.monitorcommand(struct.pack("IIIIIIII", 19, nameptr, entrypoint, stackptr, stacksize, threadtype, priority, state), "III", (id, None, None))
|
| 397 |
if resp.id < 0:
|
463 |
if resp.id < 0:
|
| 398 |
raise DeviceError("The device returned the error code "+str(resp.id))
|
464 |
raise DeviceError("The device returned the error code "+str(resp.id))
|
| 399 |
return resp
|
465 |
return resp
|
| 400 |
|
466 |
|
| - |
|
467 |
@command()
|
| 401 |
def flushcaches(self):
|
468 |
def flushcaches(self):
|
| 402 |
""" Flushes the CPU instruction and data cache """
|
469 |
""" Flushes the CPU instruction and data cache """
|
| 403 |
return self.lib.monitorcommand(struct.pack("IIII", 20, 0, 0, 0), "III", (None, None, None))
|
470 |
return self.lib.monitorcommand(struct.pack("IIII", 20, 0, 0, 0), "III", (None, None, None))
|
| 404 |
|
471 |
|
| - |
|
472 |
@command()
|
| 405 |
def execimage(self, addr):
|
473 |
def execimage(self, addr):
|
| 406 |
""" Runs the emBIOS app at 'addr' """
|
474 |
""" Runs the emBIOS app at 'addr' """
|
| 407 |
return self.lib.monitorcommand(struct.pack("IIII", 21, addr, 0, 0), "III", ("rc", None, None))
|
475 |
return self.lib.monitorcommand(struct.pack("IIII", 21, addr, 0, 0), "III", ("rc", None, None))
|
| 408 |
|
476 |
|
| - |
|
477 |
@command()
|
| 409 |
def run(self, app):
|
478 |
def run(self, app):
|
| 410 |
""" Uploads and runs the emBIOS app in the string 'app' """
|
479 |
""" Uploads and runs the emBIOS app in the string 'app' """
|
| 411 |
try:
|
480 |
try:
|
| 412 |
appheader = struct.unpack("<8sIIIIIIIIII", app[:48])
|
481 |
appheader = struct.unpack("<8sIIIIIIIIII", app[:48])
|
| 413 |
except struct.error:
|
482 |
except struct.error:
|
| Line 433... |
Line 502... |
| 433 |
raise ArgumentError("The baseaddress of the specified emBIOS application is out of range of the user memory range on the device. Are you sure that this application is compatible with your device?")
|
502 |
raise ArgumentError("The baseaddress of the specified emBIOS application is out of range of the user memory range on the device. Are you sure that this application is compatible with your device?")
|
| 434 |
self.write(baseaddr, app)
|
503 |
self.write(baseaddr, app)
|
| 435 |
self.execimage(baseaddr)
|
504 |
self.execimage(baseaddr)
|
| 436 |
return Bunch(baseaddr=baseaddr, name=name)
|
505 |
return Bunch(baseaddr=baseaddr, name=name)
|
| 437 |
|
506 |
|
| - |
|
507 |
@command()
|
| 438 |
def bootflashread(self, memaddr, flashaddr, size):
|
508 |
def bootflashread(self, memaddr, flashaddr, size):
|
| 439 |
""" Copies the data in the bootflash at 'flashaddr' of the specified size
|
509 |
""" Copies the data in the bootflash at 'flashaddr' of the specified size
|
| 440 |
to the memory at addr 'memaddr'
|
510 |
to the memory at addr 'memaddr'
|
| 441 |
"""
|
511 |
"""
|
| 442 |
return self.lib.monitorcommand(struct.pack("IIII", 22, memaddr, flashaddr, size), "III", (None, None, None))
|
512 |
return self.lib.monitorcommand(struct.pack("IIII", 22, memaddr, flashaddr, size), "III", (None, None, None))
|
| 443 |
|
513 |
|
| - |
|
514 |
@command()
|
| 444 |
def bootflashwrite(self, memaddr, flashaddr, size):
|
515 |
def bootflashwrite(self, memaddr, flashaddr, size):
|
| 445 |
""" Copies the data in the memory at 'memaddr' of the specified size
|
516 |
""" Copies the data in the memory at 'memaddr' of the specified size
|
| 446 |
to the boot flash at addr 'flashaddr'
|
517 |
to the boot flash at addr 'flashaddr'
|
| 447 |
"""
|
518 |
"""
|
| 448 |
return self.lib.monitorcommand(struct.pack("IIII", 23, memaddr, flashaddr, size), "III", (None, None, None))
|
519 |
return self.lib.monitorcommand(struct.pack("IIII", 23, memaddr, flashaddr, size), "III", (None, None, None))
|
| 449 |
|
520 |
|
| - |
|
521 |
@command()
|
| 450 |
def execfirmware(self, addr):
|
522 |
def execfirmware(self, addr):
|
| 451 |
""" Executes the firmware at 'addr' and passes all control to it. """
|
523 |
""" Executes the firmware at 'addr' and passes all control to it. """
|
| 452 |
return self.lib.monitorcommand(struct.pack("IIII", 24, addr, 0, 0))
|
524 |
return self.lib.monitorcommand(struct.pack("IIII", 24, addr, 0, 0))
|
| 453 |
|
525 |
|
| - |
|
526 |
@command()
|
| 454 |
def aesencrypt(self, addr, size, keyindex):
|
527 |
def aesencrypt(self, addr, size, keyindex):
|
| 455 |
""" Encrypts the buffer at 'addr' with the specified size
|
528 |
""" Encrypts the buffer at 'addr' with the specified size
|
| 456 |
with the hardware AES key index 'keyindex'
|
529 |
with the hardware AES key index 'keyindex'
|
| 457 |
"""
|
530 |
"""
|
| 458 |
return self.lib.monitorcommand(struct.pack("IBBHII", 25, 1, 0, keyindex, addr, size), "III", (None, None, None))
|
531 |
return self.lib.monitorcommand(struct.pack("IBBHII", 25, 1, 0, keyindex, addr, size), "III", (None, None, None))
|
| 459 |
|
532 |
|
| - |
|
533 |
@command()
|
| 460 |
def aesdecrypt(self, addr, size, keyindex):
|
534 |
def aesdecrypt(self, addr, size, keyindex):
|
| 461 |
""" Decrypts the buffer at 'addr' with the specified size
|
535 |
""" Decrypts the buffer at 'addr' with the specified size
|
| 462 |
with the hardware AES key index 'keyindex'
|
536 |
with the hardware AES key index 'keyindex'
|
| 463 |
"""
|
537 |
"""
|
| 464 |
return self.lib.monitorcommand(struct.pack("IBBHII", 25, 0, 0, keyindex, addr, size), "III", (None, None, None))
|
538 |
return self.lib.monitorcommand(struct.pack("IBBHII", 25, 0, 0, keyindex, addr, size), "III", (None, None, None))
|
| 465 |
|
539 |
|
| - |
|
540 |
@command()
|
| 466 |
def hmac_sha1(self, addr, size, destination):
|
541 |
def hmac_sha1(self, addr, size, destination):
|
| 467 |
""" Generates a HMAC-SHA1 hash of the buffer and saves it to 'destination' """
|
542 |
""" Generates a HMAC-SHA1 hash of the buffer and saves it to 'destination' """
|
| 468 |
return self.lib.monitorcommand(struct.pack("IIII", 26, addr, size, destination), "III", (None, None, None))
|
543 |
return self.lib.monitorcommand(struct.pack("IIII", 26, addr, size, destination), "III", (None, None, None))
|
| 469 |
|
544 |
|
| - |
|
545 |
@command()
|
| 470 |
def ipodnano2g_getnandinfo(self):
|
546 |
def ipodnano2g_getnandinfo(self):
|
| 471 |
""" Target-specific function: ipodnano2g
|
547 |
""" Target-specific function: ipodnano2g
|
| 472 |
Gathers some information about the NAND chip used
|
548 |
Gathers some information about the NAND chip used
|
| 473 |
"""
|
549 |
"""
|
| 474 |
if self.lib.dev.hwtypeid != 0x47324e49: raise DeviceError("Wrong device for target-specific command.")
|
550 |
if self.lib.dev.hwtypeid != 0x47324e49: raise DeviceError("Wrong device for target-specific command.")
|
| 475 |
return self.lib.monitorcommand(struct.pack("IIII", 0xffff0001, 0, 0, 0), "IHHHH", ("type", "pagesperblock", "banks", "userblocks", "blocks"))
|
551 |
return self.lib.monitorcommand(struct.pack("IIII", 0xffff0001, 0, 0, 0), "IHHHH", ("type", "pagesperblock", "banks", "userblocks", "blocks"))
|
| 476 |
|
552 |
|
| - |
|
553 |
@command()
|
| 477 |
def ipodnano2g_nandread(self, addr, start, count, doecc, checkempty):
|
554 |
def ipodnano2g_nandread(self, addr, start, count, doecc, checkempty):
|
| 478 |
""" Target-specific function: ipodnano2g
|
555 |
""" Target-specific function: ipodnano2g
|
| 479 |
Reads data from the NAND chip into memory
|
556 |
Reads data from the NAND chip into memory
|
| 480 |
"""
|
557 |
"""
|
| 481 |
if self.lib.dev.hwtypeid != 0x47324e49: raise DeviceError("Wrong device for target-specific command.")
|
558 |
if self.lib.dev.hwtypeid != 0x47324e49: raise DeviceError("Wrong device for target-specific command.")
|
| 482 |
return self.lib.monitorcommand(struct.pack("IIII", 0xffff0002, addr | (0x80000000 if doecc != 0 else 0) | (0x40000000 if checkempty != 0 else 0), start, count), "III", (None, None, None))
|
559 |
return self.lib.monitorcommand(struct.pack("IIII", 0xffff0002, addr | (0x80000000 if doecc != 0 else 0) | (0x40000000 if checkempty != 0 else 0), start, count), "III", (None, None, None))
|
| 483 |
|
560 |
|
| - |
|
561 |
@command()
|
| 484 |
def ipodnano2g_nandwrite(self, addr, start, count, doecc):
|
562 |
def ipodnano2g_nandwrite(self, addr, start, count, doecc):
|
| 485 |
""" Target-specific function: ipodnano2g
|
563 |
""" Target-specific function: ipodnano2g
|
| 486 |
Writes data to the NAND chip
|
564 |
Writes data to the NAND chip
|
| 487 |
"""
|
565 |
"""
|
| 488 |
if self.lib.dev.hwtypeid != 0x47324e49: raise DeviceError("Wrong device for target-specific command.")
|
566 |
if self.lib.dev.hwtypeid != 0x47324e49: raise DeviceError("Wrong device for target-specific command.")
|
| 489 |
return self.lib.monitorcommand(struct.pack("IIII", 0xffff0003, addr | (0x80000000 if doecc != 0 else 0), start, count), "III", (None, None, None))
|
567 |
return self.lib.monitorcommand(struct.pack("IIII", 0xffff0003, addr | (0x80000000 if doecc != 0 else 0), start, count), "III", (None, None, None))
|
| 490 |
|
568 |
|
| - |
|
569 |
@command()
|
| 491 |
def ipodnano2g_nanderase(self, addr, start, count):
|
570 |
def ipodnano2g_nanderase(self, addr, start, count):
|
| 492 |
""" Target-specific function: ipodnano2g
|
571 |
""" Target-specific function: ipodnano2g
|
| 493 |
Erases blocks on the NAND chip and stores the results to memory
|
572 |
Erases blocks on the NAND chip and stores the results to memory
|
| 494 |
"""
|
573 |
"""
|
| 495 |
if self.lib.dev.hwtypeid != 0x47324e49: raise DeviceError("Wrong device for target-specific command.")
|
574 |
if self.lib.dev.hwtypeid != 0x47324e49: raise DeviceError("Wrong device for target-specific command.")
|
| 496 |
return self.lib.monitorcommand(struct.pack("IIII", 0xffff0004, addr, start, count), "III", (None, None, None))
|
575 |
return self.lib.monitorcommand(struct.pack("IIII", 0xffff0004, addr, start, count), "III", (None, None, None))
|
| 497 |
|
576 |
|
| - |
|
577 |
@command()
|
| 498 |
def ipodclassic_gethddinfo(self):
|
578 |
def ipodclassic_gethddinfo(self):
|
| 499 |
""" Target-specific function: ipodclassic
|
579 |
""" Target-specific function: ipodclassic
|
| 500 |
Gather information about the hard disk drive
|
580 |
Gather information about the hard disk drive
|
| 501 |
"""
|
581 |
"""
|
| 502 |
if self.lib.dev.hwtypeid != 0x4c435049: raise DeviceError("Wrong device for target-specific command.")
|
582 |
if self.lib.dev.hwtypeid != 0x4c435049: raise DeviceError("Wrong device for target-specific command.")
|
| 503 |
return self.lib.monitorcommand(struct.pack("IIII", 0xffff0001, 0, 0, 0), "IQQII", ("identifyptr", "totalsectors", "virtualsectors", "bbtptr", "bbtsize"))
|
583 |
return self.lib.monitorcommand(struct.pack("IIII", 0xffff0001, 0, 0, 0), "IQQII", ("identifyptr", "totalsectors", "virtualsectors", "bbtptr", "bbtsize"))
|
| 504 |
|
584 |
|
| - |
|
585 |
@command()
|
| 505 |
def ipodclassic_hddaccess(self, type, sector, count, addr):
|
586 |
def ipodclassic_hddaccess(self, type, sector, count, addr):
|
| 506 |
""" Target-specific function: ipodclassic
|
587 |
""" Target-specific function: ipodclassic
|
| 507 |
Access the hard disk, type = 0 (read) / 1 (write)
|
588 |
Access the hard disk, type = 0 (read) / 1 (write)
|
| 508 |
"""
|
589 |
"""
|
| 509 |
if self.lib.dev.hwtypeid != 0x4c435049: raise DeviceError("Wrong device for target-specific command.")
|
590 |
if self.lib.dev.hwtypeid != 0x4c435049: raise DeviceError("Wrong device for target-specific command.")
|
| 510 |
rc = self.lib.monitorcommand(struct.pack("IIQIIII", 0xffff0002, type, sector, count, addr, 0, 0), "III", ("rc", None, None))
|
591 |
rc = self.lib.monitorcommand(struct.pack("IIQIIII", 0xffff0002, type, sector, count, addr, 0, 0), "III", ("rc", None, None))
|
| 511 |
if (rc > 0x80000000):
|
592 |
if (rc > 0x80000000):
|
| 512 |
raise DeviceError("HDD access (type=%d, sector=%d, count=%d, addr=0x%08X) failed with RC 0x%08X" % (type, sector, count, addr, rc))
|
593 |
raise DeviceError("HDD access (type=%d, sector=%d, count=%d, addr=0x%08X) failed with RC 0x%08X" % (type, sector, count, addr, rc))
|
| 513 |
|
594 |
|
| - |
|
595 |
@command()
|
| 514 |
def ipodclassic_writebbt(self, bbt, tempaddr):
|
596 |
def ipodclassic_writebbt(self, bbt, tempaddr):
|
| 515 |
""" Target-specific function: ipodclassic
|
597 |
""" Target-specific function: ipodclassic
|
| 516 |
Write hard drive bad block table
|
598 |
Write hard drive bad block table
|
| 517 |
"""
|
599 |
"""
|
| 518 |
if self.lib.dev.hwtypeid != 0x4c435049: raise DeviceError("Wrong device for target-specific command.")
|
600 |
if self.lib.dev.hwtypeid != 0x4c435049: raise DeviceError("Wrong device for target-specific command.")
|
| Line 536... |
Line 618... |
| 536 |
offset = offset + count * 4096
|
618 |
offset = offset + count * 4096
|
| 537 |
sector = bbtheader[4][i]
|
619 |
sector = bbtheader[4][i]
|
| 538 |
count = 1
|
620 |
count = 1
|
| 539 |
self.ipodclassic_hddaccess(1, sector, count, tempaddr + offset)
|
621 |
self.ipodclassic_hddaccess(1, sector, count, tempaddr + offset)
|
| 540 |
|
622 |
|
| - |
|
623 |
@command()
|
| 541 |
def storage_get_info(self, volume):
|
624 |
def storage_get_info(self, volume):
|
| 542 |
""" Get information about a storage device """
|
625 |
""" Get information about a storage device """
|
| 543 |
result = self.lib.monitorcommand(struct.pack("IIII", 27, volume, 0, 0), "IIIIIIII", ("version", None, None, "sectorsize", "numsectors", "vendorptr", "productptr", "revisionptr"))
|
626 |
result = self.lib.monitorcommand(struct.pack("IIII", 27, volume, 0, 0), "IIIIIIII", ("version", None, None, "sectorsize", "numsectors", "vendorptr", "productptr", "revisionptr"))
|
| 544 |
if result.version != 1:
|
627 |
if result.version != 1:
|
| 545 |
raise ValueError("Unknown version of storage_info struct: %d" % result.version)
|
628 |
raise ValueError("Unknown version of storage_info struct: %d" % result.version)
|
| 546 |
result.vendor = self.readstring(result.vendorptr)
|
629 |
result.vendor = self.readstring(result.vendorptr)
|
| 547 |
result.product = self.readstring(result.productptr)
|
630 |
result.product = self.readstring(result.productptr)
|
| 548 |
result.revision = self.readstring(result.revisionptr)
|
631 |
result.revision = self.readstring(result.revisionptr)
|
| 549 |
return result
|
632 |
return result
|
| 550 |
|
633 |
|
| - |
|
634 |
@command()
|
| 551 |
def storage_read_sectors_md(self, volume, sector, count, addr):
|
635 |
def storage_read_sectors_md(self, volume, sector, count, addr):
|
| 552 |
""" Read sectors from as storage device """
|
636 |
""" Read sectors from as storage device """
|
| 553 |
result = self.lib.monitorcommand(struct.pack("IIQIIII", 28, volume, sector, count, addr, 0, 0), "III", ("rc", None, None, None))
|
637 |
result = self.lib.monitorcommand(struct.pack("IIQIIII", 28, volume, sector, count, addr, 0, 0), "III", ("rc", None, None, None))
|
| 554 |
if result.rc > 0x80000000:
|
638 |
if result.rc > 0x80000000:
|
| 555 |
raise DeviceError("storage_read_sectors_md(volume=%d, sector=%d, count=%d, addr=0x%08X) failed with RC 0x%08X" % (volume, sector, count, addr, rc))
|
639 |
raise DeviceError("storage_read_sectors_md(volume=%d, sector=%d, count=%d, addr=0x%08X) failed with RC 0x%08X" % (volume, sector, count, addr, rc))
|
| 556 |
|
640 |
|
| - |
|
641 |
@command()
|
| 557 |
def storage_write_sectors_md(self, volume, sector, count, addr):
|
642 |
def storage_write_sectors_md(self, volume, sector, count, addr):
|
| 558 |
""" Read sectors from as storage device """
|
643 |
""" Read sectors from as storage device """
|
| 559 |
result = self.lib.monitorcommand(struct.pack("IIQIIII", 29, volume, sector, count, addr, 0, 0), "III", ("rc", None, None, None))
|
644 |
result = self.lib.monitorcommand(struct.pack("IIQIIII", 29, volume, sector, count, addr, 0, 0), "III", ("rc", None, None, None))
|
| 560 |
if result.rc > 0x80000000:
|
645 |
if result.rc > 0x80000000:
|
| 561 |
raise DeviceError("storage_read_sectors_md(volume=%d, sector=%d, count=%d, addr=0x%08X) failed with RC 0x%08X" % (volume, sector, count, addr, rc))
|
646 |
raise DeviceError("storage_read_sectors_md(volume=%d, sector=%d, count=%d, addr=0x%08X) failed with RC 0x%08X" % (volume, sector, count, addr, rc))
|
| 562 |
|
647 |
|
| - |
|
648 |
@command()
|
| 563 |
def file_open(self, filename, mode):
|
649 |
def file_open(self, filename, mode):
|
| 564 |
""" Opens a file and returns the handle """
|
650 |
""" Opens a file and returns the handle """
|
| 565 |
result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(filename), 30, mode, 0, 0, filename, 0), "III", ("fd", None, None))
|
651 |
result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(filename), 30, mode, 0, 0, filename, 0), "III", ("fd", None, None))
|
| 566 |
if result.fd > 0x80000000:
|
652 |
if result.fd > 0x80000000:
|
| 567 |
raise DeviceError("file_open(filename=\"%s\", mode=0x%X) failed with RC=0x%08X, errno=%d" % (filename, mode, result.fd, self.errno()))
|
653 |
raise DeviceError("file_open(filename=\"%s\", mode=0x%X) failed with RC=0x%08X, errno=%d" % (filename, mode, result.fd, self.errno()))
|
| 568 |
return result.fd
|
654 |
return result.fd
|
| 569 |
|
655 |
|
| - |
|
656 |
@command()
|
| 570 |
def file_size(self, fd):
|
657 |
def file_size(self, fd):
|
| 571 |
""" Gets the size of a file referenced by a handle """
|
658 |
""" Gets the size of a file referenced by a handle """
|
| 572 |
result = self.lib.monitorcommand(struct.pack("IIII", 31, fd, 0, 0), "III", ("size", None, None))
|
659 |
result = self.lib.monitorcommand(struct.pack("IIII", 31, fd, 0, 0), "III", ("size", None, None))
|
| 573 |
if result.size > 0x80000000:
|
660 |
if result.size > 0x80000000:
|
| 574 |
raise DeviceError("file_size(fd=%d) failed with RC=0x%08X, errno=%d" % (fd, result.size, self.errno()))
|
661 |
raise DeviceError("file_size(fd=%d) failed with RC=0x%08X, errno=%d" % (fd, result.size, self.errno()))
|
| 575 |
return result.size
|
662 |
return result.size
|
| 576 |
|
663 |
|
| - |
|
664 |
@command()
|
| 577 |
def file_read(self, fd, addr, size):
|
665 |
def file_read(self, fd, addr, size):
|
| 578 |
""" Reads data from a file referenced by a handle """
|
666 |
""" Reads data from a file referenced by a handle """
|
| 579 |
result = self.lib.monitorcommand(struct.pack("IIII", 32, fd, addr, size), "III", ("rc", None, None))
|
667 |
result = self.lib.monitorcommand(struct.pack("IIII", 32, fd, addr, size), "III", ("rc", None, None))
|
| 580 |
if result.rc > 0x80000000:
|
668 |
if result.rc > 0x80000000:
|
| 581 |
raise DeviceError("file_read(fd=%d, addr=0x%08X, size=0x%08X) failed with RC=0x%08X, errno=%d" % (fd, addr, size, result.rc, self.errno()))
|
669 |
raise DeviceError("file_read(fd=%d, addr=0x%08X, size=0x%08X) failed with RC=0x%08X, errno=%d" % (fd, addr, size, result.rc, self.errno()))
|
| 582 |
return result.rc
|
670 |
return result.rc
|
| 583 |
|
671 |
|
| - |
|
672 |
@command()
|
| 584 |
def file_write(self, fd, addr, size):
|
673 |
def file_write(self, fd, addr, size):
|
| 585 |
""" Writes data from a file referenced by a handle """
|
674 |
""" Writes data from a file referenced by a handle """
|
| 586 |
result = self.lib.monitorcommand(struct.pack("IIII", 33, fd, addr, size), "III", ("rc", None, None))
|
675 |
result = self.lib.monitorcommand(struct.pack("IIII", 33, fd, addr, size), "III", ("rc", None, None))
|
| 587 |
if result.rc > 0x80000000:
|
676 |
if result.rc > 0x80000000:
|
| 588 |
raise DeviceError("file_write(fd=%d, addr=0x%08X, size=0x%08X) failed with RC=0x%08X, errno=%d" % (fd, addr, size, result.rc, self.errno()))
|
677 |
raise DeviceError("file_write(fd=%d, addr=0x%08X, size=0x%08X) failed with RC=0x%08X, errno=%d" % (fd, addr, size, result.rc, self.errno()))
|
| 589 |
return result.rc
|
678 |
return result.rc
|
| 590 |
|
679 |
|
| - |
|
680 |
@command()
|
| 591 |
def file_seek(self, fd, offset, whence):
|
681 |
def file_seek(self, fd, offset, whence):
|
| 592 |
""" Seeks the file handle to the specified position in the file """
|
682 |
""" Seeks the file handle to the specified position in the file """
|
| 593 |
result = self.lib.monitorcommand(struct.pack("IIII", 34, fd, offset, whence), "III", ("rc", None, None))
|
683 |
result = self.lib.monitorcommand(struct.pack("IIII", 34, fd, offset, whence), "III", ("rc", None, None))
|
| 594 |
if result.rc > 0x80000000:
|
684 |
if result.rc > 0x80000000:
|
| 595 |
raise DeviceError("file_seek(fd=%d, offset=0x%08X, whence=%d) failed with RC=0x%08X, errno=%d" % (fd, offset, whence, result.rc, self.errno()))
|
685 |
raise DeviceError("file_seek(fd=%d, offset=0x%08X, whence=%d) failed with RC=0x%08X, errno=%d" % (fd, offset, whence, result.rc, self.errno()))
|
| 596 |
return result.rc
|
686 |
return result.rc
|
| 597 |
|
687 |
|
| - |
|
688 |
@command()
|
| 598 |
def file_truncate(self, fd, length):
|
689 |
def file_truncate(self, fd, length):
|
| 599 |
""" Truncates a file referenced by a handle to a specified length """
|
690 |
""" Truncates a file referenced by a handle to a specified length """
|
| 600 |
result = self.lib.monitorcommand(struct.pack("IIII", 35, fd, offset, 0), "III", ("rc", None, None))
|
691 |
result = self.lib.monitorcommand(struct.pack("IIII", 35, fd, offset, 0), "III", ("rc", None, None))
|
| 601 |
if result.rc > 0x80000000:
|
692 |
if result.rc > 0x80000000:
|
| 602 |
raise DeviceError("file_truncate(fd=%d, length=0x%08X) failed with RC=0x%08X, errno=%d" % (fd, length, result.rc, self.errno()))
|
693 |
raise DeviceError("file_truncate(fd=%d, length=0x%08X) failed with RC=0x%08X, errno=%d" % (fd, length, result.rc, self.errno()))
|
| 603 |
return result.rc
|
694 |
return result.rc
|
| 604 |
|
695 |
|
| - |
|
696 |
@command()
|
| 605 |
def file_sync(self, fd):
|
697 |
def file_sync(self, fd):
|
| 606 |
""" Flushes a file handles' buffers """
|
698 |
""" Flushes a file handles' buffers """
|
| 607 |
result = self.lib.monitorcommand(struct.pack("IIII", 36, fd, 0, 0), "III", ("rc", None, None))
|
699 |
result = self.lib.monitorcommand(struct.pack("IIII", 36, fd, 0, 0), "III", ("rc", None, None))
|
| 608 |
if result.rc > 0x80000000:
|
700 |
if result.rc > 0x80000000:
|
| 609 |
raise DeviceError("file_sync(fd=%d) failed with RC=0x%08X, errno=%d" % (fd, result.rc, self.errno()))
|
701 |
raise DeviceError("file_sync(fd=%d) failed with RC=0x%08X, errno=%d" % (fd, result.rc, self.errno()))
|
| 610 |
return result.rc
|
702 |
return result.rc
|
| 611 |
|
703 |
|
| - |
|
704 |
@command()
|
| 612 |
def file_close(self, fd):
|
705 |
def file_close(self, fd):
|
| 613 |
""" Closes a file handle """
|
706 |
""" Closes a file handle """
|
| 614 |
result = self.lib.monitorcommand(struct.pack("IIII", 37, fd, 0, 0), "III", ("rc", None, None))
|
707 |
result = self.lib.monitorcommand(struct.pack("IIII", 37, fd, 0, 0), "III", ("rc", None, None))
|
| 615 |
if result.rc > 0x80000000:
|
708 |
if result.rc > 0x80000000:
|
| 616 |
raise DeviceError("file_close(fd=%d) failed with RC=0x%08X, errno=%d" % (fd, result.rc, self.errno()))
|
709 |
raise DeviceError("file_close(fd=%d) failed with RC=0x%08X, errno=%d" % (fd, result.rc, self.errno()))
|
| 617 |
return result.rc
|
710 |
return result.rc
|
| 618 |
|
711 |
|
| - |
|
712 |
@command()
|
| 619 |
def file_close_all(self):
|
713 |
def file_close_all(self):
|
| 620 |
""" Closes all file handles opened through the debugger """
|
714 |
""" Closes all file handles opened through the debugger """
|
| 621 |
result = self.lib.monitorcommand(struct.pack("IIII", 38, 0, 0, 0), "III", ("rc", None, None))
|
715 |
result = self.lib.monitorcommand(struct.pack("IIII", 38, 0, 0, 0), "III", ("rc", None, None))
|
| 622 |
if result.rc > 0x80000000:
|
716 |
if result.rc > 0x80000000:
|
| 623 |
raise DeviceError("file_close_all() failed with RC=0x%08X, errno=%d" % (result.rc, self.errno()))
|
717 |
raise DeviceError("file_close_all() failed with RC=0x%08X, errno=%d" % (result.rc, self.errno()))
|
| 624 |
return result.rc
|
718 |
return result.rc
|
| 625 |
|
719 |
|
| - |
|
720 |
@command()
|
| 626 |
def file_kill_all(self):
|
721 |
def file_kill_all(self):
|
| 627 |
""" Kills all file handles (in the whole system) """
|
722 |
""" Kills all file handles (in the whole system) """
|
| 628 |
result = self.lib.monitorcommand(struct.pack("IIII", 39, 0, 0, 0), "III", ("rc", None, None))
|
723 |
result = self.lib.monitorcommand(struct.pack("IIII", 39, 0, 0, 0), "III", ("rc", None, None))
|
| 629 |
if result.rc > 0x80000000:
|
724 |
if result.rc > 0x80000000:
|
| 630 |
raise DeviceError("file_kill_all() failed with RC=0x%08X, errno=%d" % (result.rc, self.errno()))
|
725 |
raise DeviceError("file_kill_all() failed with RC=0x%08X, errno=%d" % (result.rc, self.errno()))
|
| 631 |
return result.rc
|
726 |
return result.rc
|
| 632 |
|
727 |
|
| - |
|
728 |
@command()
|
| 633 |
def file_unlink(self, filename):
|
729 |
def file_unlink(self, filename):
|
| 634 |
""" Removes a file """
|
730 |
""" Removes a file """
|
| 635 |
result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(filename), 40, 0, 0, 0, filename, 0), "III", ("rc", None, None))
|
731 |
result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(filename), 40, 0, 0, 0, filename, 0), "III", ("rc", None, None))
|
| 636 |
if result.rc > 0x80000000:
|
732 |
if result.rc > 0x80000000:
|
| 637 |
raise DeviceError("file_unlink(filename=\"%s\") failed with RC=0x%08X, errno=%d" % (filename, result.rc, self.errno()))
|
733 |
raise DeviceError("file_unlink(filename=\"%s\") failed with RC=0x%08X, errno=%d" % (filename, result.rc, self.errno()))
|
| 638 |
return result.rc
|
734 |
return result.rc
|
| 639 |
|
735 |
|
| - |
|
736 |
@command()
|
| 640 |
def file_rename(self, oldname, newname):
|
737 |
def file_rename(self, oldname, newname):
|
| 641 |
""" Renames a file """
|
738 |
""" Renames a file """
|
| 642 |
result = self.lib.monitorcommand(struct.pack("IIII248s%dsB" % min(247, len(newname)), 41, 0, 0, 0, oldname, newname, 0), "III", ("rc", None, None))
|
739 |
result = self.lib.monitorcommand(struct.pack("IIII248s%dsB" % min(247, len(newname)), 41, 0, 0, 0, oldname, newname, 0), "III", ("rc", None, None))
|
| 643 |
if result.rc > 0x80000000:
|
740 |
if result.rc > 0x80000000:
|
| 644 |
raise DeviceError("file_rename(oldname=\"%s\", newname=\"%s\") failed with RC=0x%08X, errno=%d" % (oldname, newname, result.rc, self.errno()))
|
741 |
raise DeviceError("file_rename(oldname=\"%s\", newname=\"%s\") failed with RC=0x%08X, errno=%d" % (oldname, newname, result.rc, self.errno()))
|
| 645 |
return result.rc
|
742 |
return result.rc
|
| 646 |
|
743 |
|
| - |
|
744 |
@command()
|
| 647 |
def dir_open(self, dirname):
|
745 |
def dir_open(self, dirname):
|
| 648 |
""" Opens a directory and returns the handle """
|
746 |
""" Opens a directory and returns the handle """
|
| 649 |
result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(dirname), 42, 0, 0, 0, dirname, 0), "III", ("handle", None, None))
|
747 |
result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(dirname), 42, 0, 0, 0, dirname, 0), "III", ("handle", None, None))
|
| 650 |
if result.handle == 0:
|
748 |
if result.handle == 0:
|
| 651 |
raise DeviceError("dir_open(dirname=\"%s\") failed with RC=0x%08X, errno=%d" % (dirname, result.handle, self.errno()))
|
749 |
raise DeviceError("dir_open(dirname=\"%s\") failed with RC=0x%08X, errno=%d" % (dirname, result.handle, self.errno()))
|
| 652 |
return result.handle
|
750 |
return result.handle
|
| 653 |
|
751 |
|
| - |
|
752 |
@command()
|
| 654 |
def dir_read(self, handle):
|
753 |
def dir_read(self, handle):
|
| 655 |
""" Reads the next entry from a directory """
|
754 |
""" Reads the next entry from a directory """
|
| 656 |
result = self.lib.monitorcommand(struct.pack("IIII", 43, handle, 0, 0), "III", ("version", "maxpath", "ptr"))
|
755 |
result = self.lib.monitorcommand(struct.pack("IIII", 43, handle, 0, 0), "III", ("version", "maxpath", "ptr"))
|
| 657 |
if result.ptr == 0:
|
756 |
if result.ptr == 0:
|
| 658 |
raise DeviceError("dir_read(handle=0x%08X) failed with RC=0x%08X, errno=%d" % (handle, result.ptr, self.errno()))
|
757 |
raise DeviceError("dir_read(handle=0x%08X) failed with RC=0x%08X, errno=%d" % (handle, result.ptr, self.errno()))
|
| Line 662... |
Line 761... |
| 662 |
ret = Bunch()
|
761 |
ret = Bunch()
|
| 663 |
(ret.name, ret.attributes, ret.size, ret.startcluster, ret.wrtdate, ret.wrttime) = struct.unpack("%dsIIIHH" % result.maxpath, dirent)
|
762 |
(ret.name, ret.attributes, ret.size, ret.startcluster, ret.wrtdate, ret.wrttime) = struct.unpack("%dsIIIHH" % result.maxpath, dirent)
|
| 664 |
ret.name = ret.name[:ret.name.index('\x00')]
|
763 |
ret.name = ret.name[:ret.name.index('\x00')]
|
| 665 |
return ret
|
764 |
return ret
|
| 666 |
|
765 |
|
| - |
|
766 |
@command()
|
| 667 |
def dir_close(self, handle):
|
767 |
def dir_close(self, handle):
|
| 668 |
""" Closes a directory handle """
|
768 |
""" Closes a directory handle """
|
| 669 |
result = self.lib.monitorcommand(struct.pack("IIII", 44, handle, 0, 0), "III", ("rc", None, None))
|
769 |
result = self.lib.monitorcommand(struct.pack("IIII", 44, handle, 0, 0), "III", ("rc", None, None))
|
| 670 |
if result.rc > 0x80000000:
|
770 |
if result.rc > 0x80000000:
|
| 671 |
raise DeviceError("dir_close(handle=0x%08X) failed with RC=0x%08X, errno=%d" % (handle, result.rc, self.errno()))
|
771 |
raise DeviceError("dir_close(handle=0x%08X) failed with RC=0x%08X, errno=%d" % (handle, result.rc, self.errno()))
|
| 672 |
return result.rc
|
772 |
return result.rc
|
| 673 |
|
773 |
|
| - |
|
774 |
@command()
|
| 674 |
def dir_close_all(self):
|
775 |
def dir_close_all(self):
|
| 675 |
""" Closes all directory handles opened through the debugger """
|
776 |
""" Closes all directory handles opened through the debugger """
|
| 676 |
result = self.lib.monitorcommand(struct.pack("IIII", 45, 0, 0, 0), "III", ("rc", None, None))
|
777 |
result = self.lib.monitorcommand(struct.pack("IIII", 45, 0, 0, 0), "III", ("rc", None, None))
|
| 677 |
if result.rc > 0x80000000:
|
778 |
if result.rc > 0x80000000:
|
| 678 |
raise DeviceError("dir_close_all() failed with RC=0x%08X, errno=%d" % (result.rc, self.errno()))
|
779 |
raise DeviceError("dir_close_all() failed with RC=0x%08X, errno=%d" % (result.rc, self.errno()))
|
| 679 |
return result.rc
|
780 |
return result.rc
|
| 680 |
|
781 |
|
| - |
|
782 |
@command()
|
| 681 |
def dir_kill_all(self):
|
783 |
def dir_kill_all(self):
|
| 682 |
""" Kills all directory handles (in the whole system) """
|
784 |
""" Kills all directory handles (in the whole system) """
|
| 683 |
result = self.lib.monitorcommand(struct.pack("IIII", 46, 0, 0, 0), "III", ("rc", None, None))
|
785 |
result = self.lib.monitorcommand(struct.pack("IIII", 46, 0, 0, 0), "III", ("rc", None, None))
|
| 684 |
if result.rc > 0x80000000:
|
786 |
if result.rc > 0x80000000:
|
| 685 |
raise DeviceError("dir_kill_all() failed with RC=0x%08X, errno=%d" % (result.rc, self.errno()))
|
787 |
raise DeviceError("dir_kill_all() failed with RC=0x%08X, errno=%d" % (result.rc, self.errno()))
|
| 686 |
return result.rc
|
788 |
return result.rc
|
| 687 |
|
789 |
|
| - |
|
790 |
@command()
|
| 688 |
def dir_create(self, dirname):
|
791 |
def dir_create(self, dirname):
|
| 689 |
""" Creates a directory """
|
792 |
""" Creates a directory """
|
| 690 |
result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(dirname), 47, 0, 0, 0, dirname, 0), "III", ("rc", None, None))
|
793 |
result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(dirname), 47, 0, 0, 0, dirname, 0), "III", ("rc", None, None))
|
| 691 |
if result.rc > 0x80000000:
|
794 |
if result.rc > 0x80000000:
|
| 692 |
raise DeviceError("dir_create(dirname=\"%s\") failed with RC=0x%08X, errno=%d" % (dirname, result.rc, self.errno()))
|
795 |
raise DeviceError("dir_create(dirname=\"%s\") failed with RC=0x%08X, errno=%d" % (dirname, result.rc, self.errno()))
|
| 693 |
return result.rc
|
796 |
return result.rc
|
| 694 |
|
797 |
|
| - |
|
798 |
@command()
|
| 695 |
def dir_remove(self, dirname):
|
799 |
def dir_remove(self, dirname):
|
| 696 |
""" Removes an (empty) directory """
|
800 |
""" Removes an (empty) directory """
|
| 697 |
result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(dirname), 48, 0, 0, 0, dirname, 0), "III", ("rc", None, None))
|
801 |
result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(dirname), 48, 0, 0, 0, dirname, 0), "III", ("rc", None, None))
|
| 698 |
if result.rc > 0x80000000:
|
802 |
if result.rc > 0x80000000:
|
| 699 |
raise DeviceError("dir_remove(dirname=\"%s\") failed with RC=0x%08X, errno=%d" % (dirname, result.rc, self.errno()))
|
803 |
raise DeviceError("dir_remove(dirname=\"%s\") failed with RC=0x%08X, errno=%d" % (dirname, result.rc, self.errno()))
|
| 700 |
return result.rc
|
804 |
return result.rc
|
| 701 |
|
805 |
|
| - |
|
806 |
@command()
|
| 702 |
def errno(self):
|
807 |
def errno(self):
|
| 703 |
""" Returns the number of the last error that happened """
|
808 |
""" Returns the number of the last error that happened """
|
| 704 |
result = self.lib.monitorcommand(struct.pack("IIII", 49, 0, 0, 0), "III", ("errno", None, None))
|
809 |
result = self.lib.monitorcommand(struct.pack("IIII", 49, 0, 0, 0), "III", ("errno", None, None))
|
| 705 |
return result.errno
|
810 |
return result.errno
|
| 706 |
|
811 |
|
| - |
|
812 |
@command()
|
| 707 |
def disk_mount(self, volume):
|
813 |
def disk_mount(self, volume):
|
| 708 |
""" Mounts a volume """
|
814 |
""" Mounts a volume """
|
| 709 |
result = self.lib.monitorcommand(struct.pack("IIII", 50, volume, 0, 0), "III", ("rc", None, None))
|
815 |
result = self.lib.monitorcommand(struct.pack("IIII", 50, volume, 0, 0), "III", ("rc", None, None))
|
| 710 |
if result.rc > 0x80000000:
|
816 |
if result.rc > 0x80000000:
|
| 711 |
raise DeviceError("disk_mount(volume=%d) failed with RC=0x%08X, errno=%d" % (volume, result.rc, self.errno()))
|
817 |
raise DeviceError("disk_mount(volume=%d) failed with RC=0x%08X, errno=%d" % (volume, result.rc, self.errno()))
|
| 712 |
return result.rc
|
818 |
return result.rc
|
| 713 |
|
819 |
|
| - |
|
820 |
@command()
|
| 714 |
def disk_unmount(self, volume):
|
821 |
def disk_unmount(self, volume):
|
| 715 |
""" Unmounts a volume """
|
822 |
""" Unmounts a volume """
|
| 716 |
result = self.lib.monitorcommand(struct.pack("IIII", 51, volume, 0, 0), "III", ("rc", None, None))
|
823 |
result = self.lib.monitorcommand(struct.pack("IIII", 51, volume, 0, 0), "III", ("rc", None, None))
|
| 717 |
if result.rc > 0x80000000:
|
824 |
if result.rc > 0x80000000:
|
| 718 |
raise DeviceError("disk_unmount(volume=%d) failed with RC=0x%08X, errno=%d" % (volume, result.rc, self.errno()))
|
825 |
raise DeviceError("disk_unmount(volume=%d) failed with RC=0x%08X, errno=%d" % (volume, result.rc, self.errno()))
|