| Line 65... |
Line 65... |
| 65 |
def wrapper(*args, **kwargs):
|
65 |
def wrapper(*args, **kwargs):
|
| 66 |
self = args[0] # little cheat as it expects self being always the first argument
|
66 |
self = args[0] # little cheat as it expects self being always the first argument
|
| 67 |
# precommand stuff
|
67 |
# precommand stuff
|
| 68 |
if target is not None:
|
68 |
if target is not None:
|
| 69 |
if self.lib.dev.hwtypeid != target:
|
69 |
if self.lib.dev.hwtypeid != target:
|
| 70 |
raise DeviceError("Wrong device for target-specific command. Expected \'" + gethwname(target) + "\' but got \'" + gethwname(self.lib.dev.hwtypeid) + "\'")
|
70 |
raise DeviceError("Wrong device for target-specific command. Expected \'%s\' but got \'%s\'" %
|
| - |
|
71 |
(gethwname(target), gethwname(self.lib.dev.hwtypeid)))
|
| 71 |
timeout = None
|
72 |
timeout = None
|
| 72 |
if "timeout" in kwargs.keys():
|
73 |
if "timeout" in kwargs.keys():
|
| 73 |
timeout = kwargs['timeout']
|
74 |
timeout = kwargs['timeout']
|
| 74 |
elif time is not None:
|
75 |
elif time is not None:
|
| 75 |
timeout = time
|
76 |
timeout = time
|
| Line 167... |
Line 168... |
| 167 |
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"))
|
| 168 |
self.lib.dev.version.revision = resp.revision
|
169 |
self.lib.dev.version.revision = resp.revision
|
| 169 |
self.lib.dev.version.majorv = resp.majorv
|
170 |
self.lib.dev.version.majorv = resp.majorv
|
| 170 |
self.lib.dev.version.minorv = resp.minorv
|
171 |
self.lib.dev.version.minorv = resp.minorv
|
| 171 |
self.lib.dev.version.patchv = resp.patchv
|
172 |
self.lib.dev.version.patchv = resp.patchv
|
| 172 |
self.logger.debug("Device Software Type ID = " + str(resp.swtypeid) + "\n")
|
173 |
self.logger.debug("Device Software Type ID = 0x%X\n" % resp.swtypeid)
|
| 173 |
self.lib.dev.swtypeid = resp.swtypeid
|
174 |
self.lib.dev.swtypeid = resp.swtypeid
|
| 174 |
self.logger.debug("Device Hardware Type ID = " + str(resp.hwtypeid) + "\n")
|
175 |
self.logger.debug("Device Hardware Type ID = 0x%X\n" % resp.hwtypeid)
|
| 175 |
self.lib.dev.hwtypeid = resp.hwtypeid
|
176 |
self.lib.dev.hwtypeid = resp.hwtypeid
|
| 176 |
return resp
|
177 |
return resp
|
| 177 |
|
178 |
|
| 178 |
@command()
|
179 |
@command()
|
| 179 |
def getpacketsizeinfo(self):
|
180 |
def getpacketsizeinfo(self):
|
| 180 |
""" This returns the emCORE max packet size information.
|
181 |
""" This returns the emCORE max packet size information.
|
| 181 |
It also sets the properties of the device object accordingly.
|
182 |
It also sets the properties of the device object accordingly.
|
| 182 |
"""
|
183 |
"""
|
| 183 |
resp = self.lib.monitorcommand(struct.pack("IIII", 1, 1, 0, 0), "HHII", ("coutmax", "cinmax", "doutmax", "dinmax"))
|
184 |
resp = self.lib.monitorcommand(struct.pack("IIII", 1, 1, 0, 0), "HHII", ("coutmax", "cinmax", "doutmax", "dinmax"))
|
| 184 |
self.logger.debug("Device cout packet size limit = " + str(resp.coutmax) + "\n")
|
185 |
self.logger.debug("Device cout packet size limit = %d\n" % resp.coutmax)
|
| 185 |
self.lib.dev.packetsizelimit.cout = resp.coutmax
|
186 |
self.lib.dev.packetsizelimit.cout = resp.coutmax
|
| 186 |
self.logger.debug("Device cin packet size limit = " + str(resp.cinmax) + "\n")
|
187 |
self.logger.debug("Device cin packet size limit = %d\n" % resp.cinmax)
|
| 187 |
self.lib.dev.packetsizelimit.cin = resp.cinmax
|
188 |
self.lib.dev.packetsizelimit.cin = resp.cinmax
|
| 188 |
self.logger.debug("Device din packet size limit = " + str(resp.doutmax) + "\n")
|
189 |
self.logger.debug("Device din packet size limit = %d\n" % resp.doutmax)
|
| 189 |
self.lib.dev.packetsizelimit.din = resp.dinmax
|
190 |
self.lib.dev.packetsizelimit.din = resp.dinmax
|
| 190 |
self.logger.debug("Device dout packet size limit = " + str(resp.dinmax) + "\n")
|
191 |
self.logger.debug("Device dout packet size limit = %d\n" % resp.dinmax)
|
| 191 |
self.lib.dev.packetsizelimit.dout = resp.doutmax
|
192 |
self.lib.dev.packetsizelimit.dout = resp.doutmax
|
| 192 |
return resp
|
193 |
return resp
|
| 193 |
|
194 |
|
| 194 |
@command()
|
195 |
@command()
|
| 195 |
def getusermemrange(self):
|
196 |
def getusermemrange(self):
|
| 196 |
""" This returns the memory range the user has access to. """
|
197 |
""" This returns the memory range the user has access to. """
|
| 197 |
resp = self.lib.monitorcommand(struct.pack("IIII", 1, 2, 0, 0), "III", ("lower", "upper", None))
|
198 |
resp = self.lib.monitorcommand(struct.pack("IIII", 1, 2, 0, 0), "III", ("lower", "upper", None))
|
| 198 |
self.logger.debug("Device user memory = 0x%x - 0x%x\n" % (resp.lower, resp.upper))
|
199 |
self.logger.debug("Device user memory = 0x%X - 0x%X\n" % (resp.lower, resp.upper))
|
| 199 |
self.lib.dev.usermem.lower = resp.lower
|
200 |
self.lib.dev.usermem.lower = resp.lower
|
| 200 |
self.lib.dev.usermem.upper = resp.upper
|
201 |
self.lib.dev.usermem.upper = resp.upper
|
| 201 |
return resp
|
202 |
return resp
|
| 202 |
|
203 |
|
| 203 |
@command()
|
204 |
@command()
|
| Line 224... |
Line 225... |
| 224 |
"""
|
225 |
"""
|
| 225 |
cin_maxsize = self.lib.dev.packetsizelimit.cin - self.lib.headersize
|
226 |
cin_maxsize = self.lib.dev.packetsizelimit.cin - self.lib.headersize
|
| 226 |
din_maxsize = self.lib.dev.packetsizelimit.din
|
227 |
din_maxsize = self.lib.dev.packetsizelimit.din
|
| 227 |
data = ""
|
228 |
data = ""
|
| 228 |
(headsize, bodysize, tailsize) = self._alignsplit(addr, size, cin_maxsize, 16)
|
229 |
(headsize, bodysize, tailsize) = self._alignsplit(addr, size, cin_maxsize, 16)
|
| 229 |
self.logger.debug("Downloading %d bytes from 0x%x, split as (%d/%d/%d)\n" % (size, addr, headsize, bodysize, tailsize))
|
230 |
self.logger.debug("Downloading %d bytes from 0x%X, split as (%d/%d/%d)\n" % (size, addr, headsize, bodysize, tailsize))
|
| 230 |
if headsize != 0:
|
231 |
if headsize != 0:
|
| 231 |
data += self._readmem(addr, headsize)
|
232 |
data += self._readmem(addr, headsize)
|
| 232 |
addr += headsize
|
233 |
addr += headsize
|
| 233 |
while bodysize > 0:
|
234 |
while bodysize > 0:
|
| 234 |
if bodysize >= 2 * cin_maxsize:
|
235 |
if bodysize >= 2 * cin_maxsize:
|
| Line 250... |
Line 251... |
| 250 |
and decides whether to use DMA or not.
|
251 |
and decides whether to use DMA or not.
|
| 251 |
"""
|
252 |
"""
|
| 252 |
cout_maxsize = self.lib.dev.packetsizelimit.cout - self.lib.headersize
|
253 |
cout_maxsize = self.lib.dev.packetsizelimit.cout - self.lib.headersize
|
| 253 |
dout_maxsize = self.lib.dev.packetsizelimit.dout
|
254 |
dout_maxsize = self.lib.dev.packetsizelimit.dout
|
| 254 |
(headsize, bodysize, tailsize) = self._alignsplit(addr, len(data), cout_maxsize, 16)
|
255 |
(headsize, bodysize, tailsize) = self._alignsplit(addr, len(data), cout_maxsize, 16)
|
| 255 |
self.logger.debug("Uploading %d bytes to 0x%x, split as (%d/%d/%d)\n" % (len(data), addr, headsize, bodysize, tailsize))
|
256 |
self.logger.debug("Uploading %d bytes to 0x%X, split as (%d/%d/%d)\n" % (len(data), addr, headsize, bodysize, tailsize))
|
| 256 |
offset = 0
|
257 |
offset = 0
|
| 257 |
if headsize != 0:
|
258 |
if headsize != 0:
|
| 258 |
self._writemem(addr, data[offset:offset+headsize])
|
259 |
self._writemem(addr, data[offset:offset+headsize])
|
| 259 |
offset += headsize
|
260 |
offset += headsize
|
| 260 |
addr += headsize
|
261 |
addr += headsize
|
| Line 378... |
Line 379... |
| 378 |
threads = []
|
379 |
threads = []
|
| 379 |
structptr = resp.structptr
|
380 |
structptr = resp.structptr
|
| 380 |
id = 0
|
381 |
id = 0
|
| 381 |
while structptr != 0:
|
382 |
while structptr != 0:
|
| 382 |
threadstruct = scheduler_thread()
|
383 |
threadstruct = scheduler_thread()
|
| 383 |
self.logger.debug("Reading thread struct of thread at 0x%x\n" % structptr)
|
384 |
self.logger.debug("Reading thread struct of thread at 0x%X\n" % structptr)
|
| 384 |
threaddata = self.read(structptr, ctypes.sizeof(scheduler_thread))
|
385 |
threaddata = self.read(structptr, ctypes.sizeof(scheduler_thread))
|
| 385 |
threadstruct._from_string(threaddata)
|
386 |
threadstruct._from_string(threaddata)
|
| 386 |
threadstruct = threadstruct._to_bunch()
|
387 |
threadstruct = threadstruct._to_bunch()
|
| 387 |
threadstruct.id = id # only for the purpose of detecting the idle thread as it is always the first one
|
388 |
threadstruct.id = id # only for the purpose of detecting the idle thread as it is always the first one
|
| 388 |
threadstruct.addr = structptr
|
389 |
threadstruct.addr = structptr
|
| Line 438... |
Line 439... |
| 438 |
state = 1
|
439 |
state = 1
|
| 439 |
else:
|
440 |
else:
|
| 440 |
raise ArgumentError("State must be either 'ready' or 'suspended'")
|
441 |
raise ArgumentError("State must be either 'ready' or 'suspended'")
|
| 441 |
resp = self.lib.monitorcommand(struct.pack("IIIIIIII", 19, nameptr, entrypoint, stackptr, stacksize, threadtype, priority, state), "III", ("threadptr", None, None))
|
442 |
resp = self.lib.monitorcommand(struct.pack("IIIIIIII", 19, nameptr, entrypoint, stackptr, stacksize, threadtype, priority, state), "III", ("threadptr", None, None))
|
| 442 |
if resp.threadptr < 0:
|
443 |
if resp.threadptr < 0:
|
| 443 |
raise DeviceError("The device returned the error code "+str(resp.threadptr))
|
444 |
raise DeviceError("The device returned the error code %d" % resp.threadptr)
|
| 444 |
return resp
|
445 |
return resp
|
| 445 |
|
446 |
|
| 446 |
@command()
|
447 |
@command()
|
| 447 |
def flushcaches(self):
|
448 |
def flushcaches(self):
|
| 448 |
""" Flushes the CPU instruction and data cache """
|
449 |
""" Flushes the CPU instruction and data cache """
|
| Line 478... |
Line 479... |
| 478 |
return self.lib.monitorcommand(struct.pack("IIII", 23, memaddr, flashaddr, size), "III", (None, None, None))
|
479 |
return self.lib.monitorcommand(struct.pack("IIII", 23, memaddr, flashaddr, size), "III", (None, None, None))
|
| 479 |
|
480 |
|
| 480 |
@command()
|
481 |
@command()
|
| 481 |
def execfirmware(self, targetaddr, addr, size):
|
482 |
def execfirmware(self, targetaddr, addr, size):
|
| 482 |
""" Moves the firmware at 'addr' with size 'size' to 'targetaddr' and passes all control to it. """
|
483 |
""" Moves the firmware at 'addr' with size 'size' to 'targetaddr' and passes all control to it. """
|
| 483 |
self.logger.debug("Moving firmware at 0x%x with the size %d to 0x%x and executing it\n" % (addr, size, targetaddr))
|
484 |
self.logger.debug("Moving firmware at 0x%X with the size %d to 0x%X and executing it\n" % (addr, size, targetaddr))
|
| 484 |
return self.lib.monitorcommand(struct.pack("IIII", 24, targetaddr, addr, size))
|
485 |
return self.lib.monitorcommand(struct.pack("IIII", 24, targetaddr, addr, size))
|
| 485 |
|
486 |
|
| 486 |
@command(timeout = 30000)
|
487 |
@command(timeout = 30000)
|
| 487 |
def aesencrypt(self, addr, size, keyindex):
|
488 |
def aesencrypt(self, addr, size, keyindex):
|
| 488 |
""" Encrypts the buffer at 'addr' with the specified size
|
489 |
""" Encrypts the buffer at 'addr' with the specified size
|
| Line 592... |
Line 593... |
| 592 |
return result
|
593 |
return result
|
| 593 |
|
594 |
|
| 594 |
@command(timeout = 50000)
|
595 |
@command(timeout = 50000)
|
| 595 |
def storage_read_sectors_md(self, volume, sector, count, addr):
|
596 |
def storage_read_sectors_md(self, volume, sector, count, addr):
|
| 596 |
""" Read sectors from as storage device """
|
597 |
""" Read sectors from as storage device """
|
| 597 |
self.logger.debug("Reading %d sectors from disk at volume %d, sector %d to memory at 0x%x\n" % (count, volume, sector, addr))
|
598 |
self.logger.debug("Reading %d sectors from disk at volume %d, sector %d to memory at 0x%X\n" % (count, volume, sector, addr))
|
| 598 |
result = self.lib.monitorcommand(struct.pack("IIQIIII", 28, volume, sector, count, addr, 0, 0), "III", ("rc", None, None))
|
599 |
result = self.lib.monitorcommand(struct.pack("IIQIIII", 28, volume, sector, count, addr, 0, 0), "III", ("rc", None, None))
|
| 599 |
self.logger.debug("Read sectors, result: 0x%x\n" % result.rc)
|
600 |
self.logger.debug("Read sectors, result: 0x%X\n" % result.rc)
|
| 600 |
if result.rc > 0x80000000:
|
601 |
if result.rc > 0x80000000:
|
| 601 |
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))
|
602 |
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))
|
| 602 |
|
603 |
|
| 603 |
@command(timeout = 50000)
|
604 |
@command(timeout = 50000)
|
| 604 |
def storage_write_sectors_md(self, volume, sector, count, addr):
|
605 |
def storage_write_sectors_md(self, volume, sector, count, addr):
|
| 605 |
""" Read sectors from as storage device """
|
606 |
""" Read sectors from as storage device """
|
| 606 |
self.logger.debug("Writing %d sectors from memory at 0x%x to disk at volume %d, sector %d\n" % (count, addr, volume, sector))
|
607 |
self.logger.debug("Writing %d sectors from memory at 0x%X to disk at volume %d, sector %d\n" % (count, addr, volume, sector))
|
| 607 |
result = self.lib.monitorcommand(struct.pack("IIQIIII", 29, volume, sector, count, addr, 0, 0), "III", ("rc", None, None))
|
608 |
result = self.lib.monitorcommand(struct.pack("IIQIIII", 29, volume, sector, count, addr, 0, 0), "III", ("rc", None, None))
|
| 608 |
self.logger.debug("Wrote sectors, result: 0x%x\n" % result.rc)
|
609 |
self.logger.debug("Wrote sectors, result: 0x%X\n" % result.rc)
|
| 609 |
if result.rc > 0x80000000:
|
610 |
if result.rc > 0x80000000:
|
| 610 |
raise DeviceError("storage_write_sectors_md(volume=%d, sector=%d, count=%d, addr=0x%08X) failed with RC 0x%08X" % (volume, sector, count, addr, rc))
|
611 |
raise DeviceError("storage_write_sectors_md(volume=%d, sector=%d, count=%d, addr=0x%08X) failed with RC 0x%08X" % (volume, sector, count, addr, rc))
|
| 611 |
|
612 |
|
| 612 |
@command(timeout = 30000)
|
613 |
@command(timeout = 30000)
|
| 613 |
def fat_enable_flushing(self, state):
|
614 |
def fat_enable_flushing(self, state):
|
| Line 623... |
Line 624... |
| 623 |
""" Opens a file and returns the handle """
|
624 |
""" Opens a file and returns the handle """
|
| 624 |
self.logger.debug("Opening remote file %s with mode %d\n" % (filename, mode))
|
625 |
self.logger.debug("Opening remote file %s with mode %d\n" % (filename, mode))
|
| 625 |
result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(filename), 30, mode, 0, 0, filename, 0), "III", ("fd", None, None))
|
626 |
result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(filename), 30, mode, 0, 0, filename, 0), "III", ("fd", None, None))
|
| 626 |
if result.fd > 0x80000000:
|
627 |
if result.fd > 0x80000000:
|
| 627 |
raise DeviceError("file_open(filename=\"%s\", mode=0x%X) failed with RC=0x%08X, errno=%d" % (filename, mode, result.fd, self.errno()))
|
628 |
raise DeviceError("file_open(filename=\"%s\", mode=0x%X) failed with RC=0x%08X, errno=%d" % (filename, mode, result.fd, self.errno()))
|
| 628 |
self.logger.debug("Opened file as handle 0x%x\n" % result.fd)
|
629 |
self.logger.debug("Opened file as handle 0x%X\n" % result.fd)
|
| 629 |
return result.fd
|
630 |
return result.fd
|
| 630 |
|
631 |
|
| 631 |
@command(timeout = 30000)
|
632 |
@command(timeout = 30000)
|
| 632 |
def file_size(self, fd):
|
633 |
def file_size(self, fd):
|
| 633 |
""" Gets the size of a file referenced by a handle """
|
634 |
""" Gets the size of a file referenced by a handle """
|
| 634 |
self.logger.debug("Getting file size of handle 0x%x\n" % fd)
|
635 |
self.logger.debug("Getting file size of handle 0x%X\n" % fd)
|
| 635 |
result = self.lib.monitorcommand(struct.pack("IIII", 31, fd, 0, 0), "III", ("size", None, None))
|
636 |
result = self.lib.monitorcommand(struct.pack("IIII", 31, fd, 0, 0), "III", ("size", None, None))
|
| 636 |
if result.size > 0x80000000:
|
637 |
if result.size > 0x80000000:
|
| 637 |
raise DeviceError("file_size(fd=%d) failed with RC=0x%08X, errno=%d" % (fd, result.size, self.errno()))
|
638 |
raise DeviceError("file_size(fd=%d) failed with RC=0x%08X, errno=%d" % (fd, result.size, self.errno()))
|
| 638 |
self.logger.debug("Got file size: %d bytes\n" % result.size)
|
639 |
self.logger.debug("Got file size: %d bytes\n" % result.size)
|
| 639 |
return result.size
|
640 |
return result.size
|
| Line 644... |
Line 645... |
| 644 |
if addr is None:
|
645 |
if addr is None:
|
| 645 |
addr = self.malloc(size)
|
646 |
addr = self.malloc(size)
|
| 646 |
malloc = True
|
647 |
malloc = True
|
| 647 |
else:
|
648 |
else:
|
| 648 |
malloc = False
|
649 |
malloc = False
|
| 649 |
self.logger.debug("Reading %d bytes from file handle 0x%x to 0x%x\n" % (size, fd, addr))
|
650 |
self.logger.debug("Reading %d bytes from file handle 0x%X to 0x%X\n" % (size, fd, addr))
|
| 650 |
try:
|
651 |
try:
|
| 651 |
result = self.lib.monitorcommand(struct.pack("IIII", 32, fd, addr, size), "III", ("rc", None, None))
|
652 |
result = self.lib.monitorcommand(struct.pack("IIII", 32, fd, addr, size), "III", ("rc", None, None))
|
| 652 |
if result.rc > 0x80000000:
|
653 |
if result.rc > 0x80000000:
|
| 653 |
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()))
|
654 |
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()))
|
| 654 |
except:
|
655 |
except:
|
| 655 |
if malloc == True:
|
656 |
if malloc == True:
|
| 656 |
self.free(addr)
|
657 |
self.free(addr)
|
| 657 |
raise
|
658 |
raise
|
| 658 |
self.logger.debug("File read result: 0x%x\n" % result.rc)
|
659 |
self.logger.debug("File read result: 0x%X\n" % result.rc)
|
| 659 |
return Bunch(rc = result.rc, addr = addr)
|
660 |
return Bunch(rc = result.rc, addr = addr)
|
| 660 |
|
661 |
|
| 661 |
@command(timeout = 30000)
|
662 |
@command(timeout = 30000)
|
| 662 |
def file_write(self, fd, size, addr):
|
663 |
def file_write(self, fd, size, addr):
|
| 663 |
""" Writes data from a file referenced by a handle. """
|
664 |
""" Writes data from a file referenced by a handle. """
|
| 664 |
self.logger.debug("Writing %d bytes from 0x%x to file handle 0x%x\n" % (size, addr, fd))
|
665 |
self.logger.debug("Writing %d bytes from 0x%X to file handle 0x%X\n" % (size, addr, fd))
|
| 665 |
result = self.lib.monitorcommand(struct.pack("IIII", 33, fd, addr, size), "III", ("rc", None, None))
|
666 |
result = self.lib.monitorcommand(struct.pack("IIII", 33, fd, addr, size), "III", ("rc", None, None))
|
| 666 |
if result.rc > 0x80000000:
|
667 |
if result.rc > 0x80000000:
|
| 667 |
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()))
|
668 |
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()))
|
| 668 |
self.logger.debug("File write result: 0x%x\n" % result.rc)
|
669 |
self.logger.debug("File write result: 0x%X\n" % result.rc)
|
| 669 |
return result.rc
|
670 |
return result.rc
|
| 670 |
|
671 |
|
| 671 |
@command(timeout = 30000)
|
672 |
@command(timeout = 30000)
|
| 672 |
def file_seek(self, fd, offset, whence):
|
673 |
def file_seek(self, fd, offset, whence):
|
| 673 |
""" Seeks the file handle to the specified position in the file """
|
674 |
""" Seeks the file handle to the specified position in the file """
|
| 674 |
self.logger.debug("Seeking file handle 0x%x to whence=%d, offset=0x%x\n" % (fd, whence, offset))
|
675 |
self.logger.debug("Seeking file handle 0x%X to whence=%d, offset=0x%X\n" % (fd, whence, offset))
|
| 675 |
result = self.lib.monitorcommand(struct.pack("IIII", 34, fd, offset, whence), "III", ("rc", None, None))
|
676 |
result = self.lib.monitorcommand(struct.pack("IIII", 34, fd, offset, whence), "III", ("rc", None, None))
|
| 676 |
if result.rc > 0x80000000:
|
677 |
if result.rc > 0x80000000:
|
| 677 |
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()))
|
678 |
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()))
|
| 678 |
self.logger.debug("File seek result: 0x%x\n" % (result.rc))
|
679 |
self.logger.debug("File seek result: 0x%X\n" % (result.rc))
|
| 679 |
return result.rc
|
680 |
return result.rc
|
| 680 |
|
681 |
|
| 681 |
@command(timeout = 30000)
|
682 |
@command(timeout = 30000)
|
| 682 |
def file_truncate(self, fd, length):
|
683 |
def file_truncate(self, fd, length):
|
| 683 |
""" Truncates a file referenced by a handle to a specified length """
|
684 |
""" Truncates a file referenced by a handle to a specified length """
|
| 684 |
self.logger.debug("Truncating file with handle 0x%x to 0x%x bytes\n" % (fd, length))
|
685 |
self.logger.debug("Truncating file with handle 0x%X to 0x%X bytes\n" % (fd, length))
|
| 685 |
result = self.lib.monitorcommand(struct.pack("IIII", 35, fd, offset, 0), "III", ("rc", None, None))
|
686 |
result = self.lib.monitorcommand(struct.pack("IIII", 35, fd, offset, 0), "III", ("rc", None, None))
|
| 686 |
if result.rc > 0x80000000:
|
687 |
if result.rc > 0x80000000:
|
| 687 |
raise DeviceError("file_truncate(fd=%d, length=0x%08X) failed with RC=0x%08X, errno=%d" % (fd, length, result.rc, self.errno()))
|
688 |
raise DeviceError("file_truncate(fd=%d, length=0x%08X) failed with RC=0x%08X, errno=%d" % (fd, length, result.rc, self.errno()))
|
| 688 |
self.logger.debug("File truncate result: 0x%x\n" % (result.rc))
|
689 |
self.logger.debug("File truncate result: 0x%X\n" % (result.rc))
|
| 689 |
return result.rc
|
690 |
return result.rc
|
| 690 |
|
691 |
|
| 691 |
@command(timeout = 30000)
|
692 |
@command(timeout = 30000)
|
| 692 |
def file_sync(self, fd):
|
693 |
def file_sync(self, fd):
|
| 693 |
""" Flushes a file handles' buffers """
|
694 |
""" Flushes a file handles' buffers """
|
| 694 |
self.logger.debug("Flushing buffers of file with handle 0x%x\n" % (fd))
|
695 |
self.logger.debug("Flushing buffers of file with handle 0x%X\n" % (fd))
|
| 695 |
result = self.lib.monitorcommand(struct.pack("IIII", 36, fd, 0, 0), "III", ("rc", None, None))
|
696 |
result = self.lib.monitorcommand(struct.pack("IIII", 36, fd, 0, 0), "III", ("rc", None, None))
|
| 696 |
if result.rc > 0x80000000:
|
697 |
if result.rc > 0x80000000:
|
| 697 |
raise DeviceError("file_sync(fd=%d) failed with RC=0x%08X, errno=%d" % (fd, result.rc, self.errno()))
|
698 |
raise DeviceError("file_sync(fd=%d) failed with RC=0x%08X, errno=%d" % (fd, result.rc, self.errno()))
|
| 698 |
self.logger.debug("File flush result: 0x%x\n" % (result.rc))
|
699 |
self.logger.debug("File flush result: 0x%X\n" % (result.rc))
|
| 699 |
return result.rc
|
700 |
return result.rc
|
| 700 |
|
701 |
|
| 701 |
@command(timeout = 30000)
|
702 |
@command(timeout = 30000)
|
| 702 |
def file_close(self, fd):
|
703 |
def file_close(self, fd):
|
| 703 |
""" Closes a file handle """
|
704 |
""" Closes a file handle """
|
| 704 |
self.logger.debug("Closing file handle 0x%x\n" % (fd))
|
705 |
self.logger.debug("Closing file handle 0x%X\n" % (fd))
|
| 705 |
result = self.lib.monitorcommand(struct.pack("IIII", 37, fd, 0, 0), "III", ("rc", None, None))
|
706 |
result = self.lib.monitorcommand(struct.pack("IIII", 37, fd, 0, 0), "III", ("rc", None, None))
|
| 706 |
if result.rc > 0x80000000:
|
707 |
if result.rc > 0x80000000:
|
| 707 |
raise DeviceError("file_close(fd=%d) failed with RC=0x%08X, errno=%d" % (fd, result.rc, self.errno()))
|
708 |
raise DeviceError("file_close(fd=%d) failed with RC=0x%08X, errno=%d" % (fd, result.rc, self.errno()))
|
| 708 |
self.logger.debug("File close result: 0x%x\n" % (result.rc))
|
709 |
self.logger.debug("File close result: 0x%X\n" % (result.rc))
|
| 709 |
return result.rc
|
710 |
return result.rc
|
| 710 |
|
711 |
|
| 711 |
@command(timeout = 30000)
|
712 |
@command(timeout = 30000)
|
| 712 |
def file_close_all(self):
|
713 |
def file_close_all(self):
|
| 713 |
""" Closes all file handles opened through the debugger """
|
714 |
""" Closes all file handles opened through the debugger """
|
| Line 733... |
Line 734... |
| 733 |
""" Removes a file """
|
734 |
""" Removes a file """
|
| 734 |
self.logger.debug("Deleting file %s\n" % (filename))
|
735 |
self.logger.debug("Deleting file %s\n" % (filename))
|
| 735 |
result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(filename), 40, 0, 0, 0, filename, 0), "III", ("rc", None, None))
|
736 |
result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(filename), 40, 0, 0, 0, filename, 0), "III", ("rc", None, None))
|
| 736 |
if result.rc > 0x80000000:
|
737 |
if result.rc > 0x80000000:
|
| 737 |
raise DeviceError("file_unlink(filename=\"%s\") failed with RC=0x%08X, errno=%d" % (filename, result.rc, self.errno()))
|
738 |
raise DeviceError("file_unlink(filename=\"%s\") failed with RC=0x%08X, errno=%d" % (filename, result.rc, self.errno()))
|
| 738 |
self.logger.debug("Delete file result: 0x%x\n" % (result.rc))
|
739 |
self.logger.debug("Delete file result: 0x%X\n" % (result.rc))
|
| 739 |
return result.rc
|
740 |
return result.rc
|
| 740 |
|
741 |
|
| 741 |
@command(timeout = 30000)
|
742 |
@command(timeout = 30000)
|
| 742 |
def file_rename(self, oldname, newname):
|
743 |
def file_rename(self, oldname, newname):
|
| 743 |
""" Renames a file """
|
744 |
""" Renames a file """
|
| 744 |
self.logger.debug("Renaming file %s to %s\n" % (oldname, newname))
|
745 |
self.logger.debug("Renaming file %s to %s\n" % (oldname, newname))
|
| 745 |
result = self.lib.monitorcommand(struct.pack("IIII248s%dsB" % min(247, len(newname)), 41, 0, 0, 0, oldname, newname, 0), "III", ("rc", None, None))
|
746 |
result = self.lib.monitorcommand(struct.pack("IIII248s%dsB" % min(247, len(newname)), 41, 0, 0, 0, oldname, newname, 0), "III", ("rc", None, None))
|
| 746 |
if result.rc > 0x80000000:
|
747 |
if result.rc > 0x80000000:
|
| 747 |
raise DeviceError("file_rename(oldname=\"%s\", newname=\"%s\") failed with RC=0x%08X, errno=%d" % (oldname, newname, result.rc, self.errno()))
|
748 |
raise DeviceError("file_rename(oldname=\"%s\", newname=\"%s\") failed with RC=0x%08X, errno=%d" % (oldname, newname, result.rc, self.errno()))
|
| 748 |
self.logger.debug("Rename file result: 0x%x\n" % (result.rc))
|
749 |
self.logger.debug("Rename file result: 0x%X\n" % (result.rc))
|
| 749 |
return result.rc
|
750 |
return result.rc
|
| 750 |
|
751 |
|
| 751 |
@command(timeout = 30000)
|
752 |
@command(timeout = 30000)
|
| 752 |
def dir_open(self, dirname):
|
753 |
def dir_open(self, dirname):
|
| 753 |
""" Opens a directory and returns the handle """
|
754 |
""" Opens a directory and returns the handle """
|
| 754 |
self.logger.debug("Opening directory %s\n" % (dirname))
|
755 |
self.logger.debug("Opening directory %s\n" % (dirname))
|
| 755 |
result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(dirname), 42, 0, 0, 0, dirname, 0), "III", ("handle", None, None))
|
756 |
result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(dirname), 42, 0, 0, 0, dirname, 0), "III", ("handle", None, None))
|
| 756 |
if result.handle == 0:
|
757 |
if result.handle == 0:
|
| 757 |
raise DeviceError("dir_open(dirname=\"%s\") failed with RC=0x%08X, errno=%d" % (dirname, result.handle, self.errno()))
|
758 |
raise DeviceError("dir_open(dirname=\"%s\") failed with RC=0x%08X, errno=%d" % (dirname, result.handle, self.errno()))
|
| 758 |
self.logger.debug("Opened directory as handle 0x%x\n" % (result.handle))
|
759 |
self.logger.debug("Opened directory as handle 0x%X\n" % (result.handle))
|
| 759 |
return result.handle
|
760 |
return result.handle
|
| 760 |
|
761 |
|
| 761 |
@command(timeout = 30000)
|
762 |
@command(timeout = 30000)
|
| 762 |
def dir_read(self, handle):
|
763 |
def dir_read(self, handle):
|
| 763 |
""" Reads the next entry from a directory """
|
764 |
""" Reads the next entry from a directory """
|
| 764 |
self.logger.debug("Reading next entry of directory handle 0x%x\n" % (handle))
|
765 |
self.logger.debug("Reading next entry of directory handle 0x%X\n" % (handle))
|
| 765 |
result = self.lib.monitorcommand(struct.pack("IIII", 43, handle, 0, 0), "III", ("version", "maxpath", "ptr"))
|
766 |
result = self.lib.monitorcommand(struct.pack("IIII", 43, handle, 0, 0), "III", ("version", "maxpath", "ptr"))
|
| 766 |
if result.ptr == 0:
|
767 |
if result.ptr == 0:
|
| 767 |
raise DeviceError("dir_read(handle=0x%08X) failed with RC=0x%08X, errno=%d" % (handle, result.ptr, self.errno()))
|
768 |
raise DeviceError("dir_read(handle=0x%08X) failed with RC=0x%08X, errno=%d" % (handle, result.ptr, self.errno()))
|
| 768 |
if result.version != 1:
|
769 |
if result.version != 1:
|
| 769 |
raise ValueError("Unknown version of dirent struct: %d" % result.version)
|
770 |
raise ValueError("Unknown version of dirent struct: %d" % result.version)
|
| Line 771... |
Line 772... |
| 771 |
ret = Bunch()
|
772 |
ret = Bunch()
|
| 772 |
(ret.name, ret.attributes, ret.size, ret.startcluster, ret.wrtdate, ret.wrttime) = struct.unpack("%dsIIIHH" % result.maxpath, dirent)
|
773 |
(ret.name, ret.attributes, ret.size, ret.startcluster, ret.wrtdate, ret.wrttime) = struct.unpack("%dsIIIHH" % result.maxpath, dirent)
|
| 773 |
ret.name = ret.name[:ret.name.index('\x00')]
|
774 |
ret.name = ret.name[:ret.name.index('\x00')]
|
| 774 |
self.logger.debug("Read directory entry:\n")
|
775 |
self.logger.debug("Read directory entry:\n")
|
| 775 |
self.logger.debug("Name: %s\n" % ret.name)
|
776 |
self.logger.debug("Name: %s\n" % ret.name)
|
| 776 |
self.logger.debug("Attributes: 0x%x\n" % ret.attributes)
|
777 |
self.logger.debug("Attributes: 0x%X\n" % ret.attributes)
|
| 777 |
self.logger.debug("Size: %d\n" % ret.size)
|
778 |
self.logger.debug("Size: %d\n" % ret.size)
|
| 778 |
self.logger.debug("Start cluster: %d\n" % ret.startcluster)
|
779 |
self.logger.debug("Start cluster: %d\n" % ret.startcluster)
|
| 779 |
self.logger.debug("Last written date: 0x%x\n" % ret.wrtdate)
|
780 |
self.logger.debug("Last written date: 0x%X\n" % ret.wrtdate)
|
| 780 |
self.logger.debug("Last written time: 0x%x\n" % ret.wrttime)
|
781 |
self.logger.debug("Last written time: 0x%X\n" % ret.wrttime)
|
| 781 |
return ret
|
782 |
return ret
|
| 782 |
|
783 |
|
| 783 |
@command(timeout = 30000)
|
784 |
@command(timeout = 30000)
|
| 784 |
def dir_close(self, handle):
|
785 |
def dir_close(self, handle):
|
| 785 |
""" Closes a directory handle """
|
786 |
""" Closes a directory handle """
|
| 786 |
self.logger.debug("Closing directory handle 0x%x\n" % (handle))
|
787 |
self.logger.debug("Closing directory handle 0x%X\n" % (handle))
|
| 787 |
result = self.lib.monitorcommand(struct.pack("IIII", 44, handle, 0, 0), "III", ("rc", None, None))
|
788 |
result = self.lib.monitorcommand(struct.pack("IIII", 44, handle, 0, 0), "III", ("rc", None, None))
|
| 788 |
if result.rc > 0x80000000:
|
789 |
if result.rc > 0x80000000:
|
| 789 |
raise DeviceError("dir_close(handle=0x%08X) failed with RC=0x%08X, errno=%d" % (handle, result.rc, self.errno()))
|
790 |
raise DeviceError("dir_close(handle=0x%08X) failed with RC=0x%08X, errno=%d" % (handle, result.rc, self.errno()))
|
| 790 |
self.logger.debug("Close directory result: 0x%x\n" % (result.rc))
|
791 |
self.logger.debug("Close directory result: 0x%X\n" % (result.rc))
|
| 791 |
return result.rc
|
792 |
return result.rc
|
| 792 |
|
793 |
|
| 793 |
@command(timeout = 30000)
|
794 |
@command(timeout = 30000)
|
| 794 |
def dir_close_all(self):
|
795 |
def dir_close_all(self):
|
| 795 |
""" Closes all directory handles opened through the debugger """
|
796 |
""" Closes all directory handles opened through the debugger """
|
| Line 815... |
Line 816... |
| 815 |
""" Creates a directory """
|
816 |
""" Creates a directory """
|
| 816 |
self.logger.debug("Creating directory %s\n" % (dirname))
|
817 |
self.logger.debug("Creating directory %s\n" % (dirname))
|
| 817 |
result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(dirname), 47, 0, 0, 0, dirname, 0), "III", ("rc", None, None))
|
818 |
result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(dirname), 47, 0, 0, 0, dirname, 0), "III", ("rc", None, None))
|
| 818 |
if result.rc > 0x80000000:
|
819 |
if result.rc > 0x80000000:
|
| 819 |
raise DeviceError("dir_create(dirname=\"%s\") failed with RC=0x%08X, errno=%d" % (dirname, result.rc, self.errno()))
|
820 |
raise DeviceError("dir_create(dirname=\"%s\") failed with RC=0x%08X, errno=%d" % (dirname, result.rc, self.errno()))
|
| 820 |
self.logger.debug("Create directory result: 0x%x\n" % (result.rc))
|
821 |
self.logger.debug("Create directory result: 0x%X\n" % (result.rc))
|
| 821 |
return result.rc
|
822 |
return result.rc
|
| 822 |
|
823 |
|
| 823 |
@command(timeout = 30000)
|
824 |
@command(timeout = 30000)
|
| 824 |
def dir_remove(self, dirname):
|
825 |
def dir_remove(self, dirname):
|
| 825 |
""" Removes an (empty) directory """
|
826 |
""" Removes an (empty) directory """
|
| 826 |
self.logger.debug("Removing directory %s\n" % (dirname))
|
827 |
self.logger.debug("Removing directory %s\n" % (dirname))
|
| 827 |
result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(dirname), 48, 0, 0, 0, dirname, 0), "III", ("rc", None, None))
|
828 |
result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(dirname), 48, 0, 0, 0, dirname, 0), "III", ("rc", None, None))
|
| 828 |
if result.rc > 0x80000000:
|
829 |
if result.rc > 0x80000000:
|
| 829 |
raise DeviceError("dir_remove(dirname=\"%s\") failed with RC=0x%08X, errno=%d" % (dirname, result.rc, self.errno()))
|
830 |
raise DeviceError("dir_remove(dirname=\"%s\") failed with RC=0x%08X, errno=%d" % (dirname, result.rc, self.errno()))
|
| 830 |
self.logger.debug("Remove directory result: 0x%x\n" % (result.rc))
|
831 |
self.logger.debug("Remove directory result: 0x%X\n" % (result.rc))
|
| 831 |
return result.rc
|
832 |
return result.rc
|
| 832 |
|
833 |
|
| 833 |
@command()
|
834 |
@command()
|
| 834 |
def errno(self):
|
835 |
def errno(self):
|
| 835 |
""" Returns the number of the last error that happened """
|
836 |
""" Returns the number of the last error that happened """
|
| 836 |
self.logger.debug("Getting last error number\n")
|
837 |
self.logger.debug("Getting last error number\n")
|
| 837 |
result = self.lib.monitorcommand(struct.pack("IIII", 49, 0, 0, 0), "III", ("errno", None, None))
|
838 |
result = self.lib.monitorcommand(struct.pack("IIII", 49, 0, 0, 0), "III", ("errno", None, None))
|
| 838 |
self.logger.debug("Last error: 0x%x\n" % (result.errno))
|
839 |
self.logger.debug("Last error: 0x%X\n" % (result.errno))
|
| 839 |
return result.errno
|
840 |
return result.errno
|
| 840 |
|
841 |
|
| 841 |
@command()
|
842 |
@command()
|
| 842 |
def disk_mount(self, volume):
|
843 |
def disk_mount(self, volume):
|
| 843 |
""" Mounts a volume """
|
844 |
""" Mounts a volume """
|
| 844 |
self.logger.debug("Mounting volume %d\n" % (volume))
|
845 |
self.logger.debug("Mounting volume %d\n" % (volume))
|
| 845 |
result = self.lib.monitorcommand(struct.pack("IIII", 50, volume, 0, 0), "III", ("rc", None, None))
|
846 |
result = self.lib.monitorcommand(struct.pack("IIII", 50, volume, 0, 0), "III", ("rc", None, None))
|
| 846 |
if result.rc > 0x80000000:
|
847 |
if result.rc > 0x80000000:
|
| 847 |
raise DeviceError("disk_mount(volume=%d) failed with RC=0x%08X, errno=%d" % (volume, result.rc, self.errno()))
|
848 |
raise DeviceError("disk_mount(volume=%d) failed with RC=0x%08X, errno=%d" % (volume, result.rc, self.errno()))
|
| 848 |
self.logger.debug("Mount volume result: 0x%x\n" % (result.rc))
|
849 |
self.logger.debug("Mount volume result: 0x%X\n" % (result.rc))
|
| 849 |
return result.rc
|
850 |
return result.rc
|
| 850 |
|
851 |
|
| 851 |
@command()
|
852 |
@command()
|
| 852 |
def disk_unmount(self, volume):
|
853 |
def disk_unmount(self, volume):
|
| 853 |
""" Unmounts a volume """
|
854 |
""" Unmounts a volume """
|
| 854 |
self.logger.debug("Unmounting volume %d\n" % (volume))
|
855 |
self.logger.debug("Unmounting volume %d\n" % (volume))
|
| 855 |
result = self.lib.monitorcommand(struct.pack("IIII", 51, volume, 0, 0), "III", ("rc", None, None))
|
856 |
result = self.lib.monitorcommand(struct.pack("IIII", 51, volume, 0, 0), "III", ("rc", None, None))
|
| 856 |
if result.rc > 0x80000000:
|
857 |
if result.rc > 0x80000000:
|
| 857 |
raise DeviceError("disk_unmount(volume=%d) failed with RC=0x%08X, errno=%d" % (volume, result.rc, self.errno()))
|
858 |
raise DeviceError("disk_unmount(volume=%d) failed with RC=0x%08X, errno=%d" % (volume, result.rc, self.errno()))
|
| 858 |
self.logger.debug("Unmount volume result: 0x%x\n" % (result.rc))
|
859 |
self.logger.debug("Unmount volume result: 0x%X\n" % (result.rc))
|
| 859 |
return result.rc
|
860 |
return result.rc
|
| 860 |
|
861 |
|
| 861 |
@command()
|
862 |
@command()
|
| 862 |
def malloc(self, size):
|
863 |
def malloc(self, size):
|
| 863 |
""" Allocates 'size' bytes and returns a pointer to the allocated memory """
|
864 |
""" Allocates 'size' bytes and returns a pointer to the allocated memory """
|
| 864 |
self.logger.debug("Allocating %d bytes of memory\n" % size)
|
865 |
self.logger.debug("Allocating %d bytes of memory\n" % size)
|
| 865 |
result = self.lib.monitorcommand(struct.pack("IIII", 52, size, 0, 0), "III", ("ptr", None, None))
|
866 |
result = self.lib.monitorcommand(struct.pack("IIII", 52, size, 0, 0), "III", ("ptr", None, None))
|
| 866 |
self.logger.debug("Allocated %d bytes of memory at 0x%x\n" % (size, result.ptr))
|
867 |
self.logger.debug("Allocated %d bytes of memory at 0x%X\n" % (size, result.ptr))
|
| 867 |
return result.ptr
|
868 |
return result.ptr
|
| 868 |
|
869 |
|
| 869 |
@command()
|
870 |
@command()
|
| 870 |
def memalign(self, align, size):
|
871 |
def memalign(self, align, size):
|
| 871 |
""" Allocates 'size' bytes aligned to 'align' and returns a pointer to the allocated memory """
|
872 |
""" Allocates 'size' bytes aligned to 'align' and returns a pointer to the allocated memory """
|
| 872 |
self.logger.debug("Allocating %d bytes of memory aligned to 0x%x\n" % (size, align))
|
873 |
self.logger.debug("Allocating %d bytes of memory aligned to 0x%X\n" % (size, align))
|
| 873 |
result = self.lib.monitorcommand(struct.pack("IIII", 53, align, size, 0), "III", ("ptr", None, None))
|
874 |
result = self.lib.monitorcommand(struct.pack("IIII", 53, align, size, 0), "III", ("ptr", None, None))
|
| 874 |
self.logger.debug("Allocated %d bytes of memory at 0x%x\n" % (size, result.ptr))
|
875 |
self.logger.debug("Allocated %d bytes of memory at 0x%X\n" % (size, result.ptr))
|
| 875 |
return result.ptr
|
876 |
return result.ptr
|
| 876 |
|
877 |
|
| 877 |
@command()
|
878 |
@command()
|
| 878 |
def realloc(self, ptr, size):
|
879 |
def realloc(self, ptr, size):
|
| 879 |
""" The size of the memory block pointed to by 'ptr' is changed to the 'size' bytes,
|
880 |
""" The size of the memory block pointed to by 'ptr' is changed to the 'size' bytes,
|
| 880 |
expanding or reducing the amount of memory available in the block.
|
881 |
expanding or reducing the amount of memory available in the block.
|
| 881 |
Returns a pointer to the reallocated memory.
|
882 |
Returns a pointer to the reallocated memory.
|
| 882 |
"""
|
883 |
"""
|
| 883 |
self.logger.debug("Reallocating 0x%x to have the new size %d\n" % (ptr, size))
|
884 |
self.logger.debug("Reallocating 0x%X to have the new size %d\n" % (ptr, size))
|
| 884 |
result = self.lib.monitorcommand(struct.pack("IIII", 54, ptr, size, 0), "III", ("ptr", None, None))
|
885 |
result = self.lib.monitorcommand(struct.pack("IIII", 54, ptr, size, 0), "III", ("ptr", None, None))
|
| 885 |
self.logger.debug("Reallocated memory at 0x%x to 0x%x with the new size %d\n" % (ptr, result.ptr, size))
|
886 |
self.logger.debug("Reallocated memory at 0x%X to 0x%X with the new size %d\n" % (ptr, result.ptr, size))
|
| 886 |
return result.ptr
|
887 |
return result.ptr
|
| 887 |
|
888 |
|
| 888 |
@command()
|
889 |
@command()
|
| 889 |
def reownalloc(self, ptr, owner):
|
890 |
def reownalloc(self, ptr, owner):
|
| 890 |
""" Changes the owner of the memory allocation 'ptr' to the thread struct at addr 'owner' """
|
891 |
""" Changes the owner of the memory allocation 'ptr' to the thread struct at addr 'owner' """
|
| 891 |
self.logger.debug("Changing owner of the memory region 0x%x to 0x%x\n" % (ptr, owner))
|
892 |
self.logger.debug("Changing owner of the memory region 0x%X to 0x%X\n" % (ptr, owner))
|
| 892 |
return self.lib.monitorcommand(struct.pack("IIII", 55, ptr, owner, 0), "III", (None, None, None))
|
893 |
return self.lib.monitorcommand(struct.pack("IIII", 55, ptr, owner, 0), "III", (None, None, None))
|
| 893 |
|
894 |
|
| 894 |
@command()
|
895 |
@command()
|
| 895 |
def free(self, ptr):
|
896 |
def free(self, ptr):
|
| 896 |
""" Frees the memory space pointed to by 'ptr' """
|
897 |
""" Frees the memory space pointed to by 'ptr' """
|
| 897 |
self.logger.debug("Freeing the memory region at 0x%x\n" % ptr)
|
898 |
self.logger.debug("Freeing the memory region at 0x%X\n" % ptr)
|
| 898 |
return self.lib.monitorcommand(struct.pack("IIII", 56, ptr, 0, 0), "III", (None, None, None))
|
899 |
return self.lib.monitorcommand(struct.pack("IIII", 56, ptr, 0, 0), "III", (None, None, None))
|
| 899 |
|
900 |
|
| 900 |
@command()
|
901 |
@command()
|
| 901 |
def free_all(self):
|
902 |
def free_all(self):
|
| 902 |
""" Frees all memory allocations created by the monitor thread """
|
903 |
""" Frees all memory allocations created by the monitor thread """
|
| Line 1000... |
Line 1001... |
| 1000 |
self.endpoint = Bunch()
|
1001 |
self.endpoint = Bunch()
|
| 1001 |
for cfg in self.dev:
|
1002 |
for cfg in self.dev:
|
| 1002 |
for intf in cfg:
|
1003 |
for intf in cfg:
|
| 1003 |
for ep in intf:
|
1004 |
for ep in intf:
|
| 1004 |
if epcounter == 0:
|
1005 |
if epcounter == 0:
|
| 1005 |
self.logger.debug("Found cout endpoint at 0x%x\n" % ep.bEndpointAddress)
|
1006 |
self.logger.debug("Found cout endpoint at 0x%X\n" % ep.bEndpointAddress)
|
| 1006 |
self.endpoint.cout = ep.bEndpointAddress
|
1007 |
self.endpoint.cout = ep.bEndpointAddress
|
| 1007 |
elif epcounter == 1:
|
1008 |
elif epcounter == 1:
|
| 1008 |
self.logger.debug("Found cin endpoint at 0x%x\n" % ep.bEndpointAddress)
|
1009 |
self.logger.debug("Found cin endpoint at 0x%X\n" % ep.bEndpointAddress)
|
| 1009 |
self.endpoint.cin = ep.bEndpointAddress
|
1010 |
self.endpoint.cin = ep.bEndpointAddress
|
| 1010 |
elif epcounter == 2:
|
1011 |
elif epcounter == 2:
|
| 1011 |
self.logger.debug("Found dout endpoint at 0x%x\n" % ep.bEndpointAddress)
|
1012 |
self.logger.debug("Found dout endpoint at 0x%X\n" % ep.bEndpointAddress)
|
| 1012 |
self.endpoint.dout = ep.bEndpointAddress
|
1013 |
self.endpoint.dout = ep.bEndpointAddress
|
| 1013 |
elif epcounter == 3:
|
1014 |
elif epcounter == 3:
|
| 1014 |
self.logger.debug("Found din endpoint at 0x%x\n" % ep.bEndpointAddress)
|
1015 |
self.logger.debug("Found din endpoint at 0x%X\n" % ep.bEndpointAddress)
|
| 1015 |
self.endpoint.din = ep.bEndpointAddress
|
1016 |
self.endpoint.din = ep.bEndpointAddress
|
| 1016 |
epcounter += 1
|
1017 |
epcounter += 1
|
| 1017 |
if epcounter <= 3:
|
1018 |
if epcounter <= 3:
|
| 1018 |
raise DeviceError("Not all endpoints found in the descriptor. Only "+str(epcounter)+" found, we need 4")
|
1019 |
raise DeviceError("Not all endpoints found in the descriptor. Only %d endpoints found, at least 4 endpoints were expeceted" % epcounter)
|
| 1019 |
|
1020 |
|
| 1020 |
def connect(self):
|
1021 |
def connect(self):
|
| 1021 |
self.logger.debug("Looking for emCORE device\n")
|
1022 |
self.logger.debug("Looking for emCORE device\n")
|
| 1022 |
self.dev = usb.core.find(idVendor=self.idVendor, idProduct=self.idProduct)
|
1023 |
self.dev = usb.core.find(idVendor=self.idVendor, idProduct=self.idProduct)
|
| 1023 |
if self.dev is None:
|
1024 |
if self.dev is None:
|
| Line 1040... |
Line 1041... |
| 1040 |
if len(read) != size:
|
1041 |
if len(read) != size:
|
| 1041 |
raise ReceiveError("Requested size and read size don't match!")
|
1042 |
raise ReceiveError("Requested size and read size don't match!")
|
| 1042 |
return read
|
1043 |
return read
|
| 1043 |
|
1044 |
|
| 1044 |
def cout(self, data):
|
1045 |
def cout(self, data):
|
| 1045 |
self.logger.debug("Sending data to cout endpoint with the size " + str(len(data)) + "\n")
|
1046 |
self.logger.debug("Sending data to cout endpoint with the size %d\n" % len(data))
|
| 1046 |
if self.packetsizelimit.cout and len(data) > self.packetsizelimit.cout:
|
1047 |
if self.packetsizelimit.cout and len(data) > self.packetsizelimit.cout:
|
| 1047 |
raise SendError("Packet too big")
|
1048 |
raise SendError("Packet too big")
|
| 1048 |
return self.send(self.endpoint.cout, data)
|
1049 |
return self.send(self.endpoint.cout, data)
|
| 1049 |
|
1050 |
|
| 1050 |
def cin(self, size):
|
1051 |
def cin(self, size):
|
| 1051 |
self.logger.debug("Receiving data on the cin endpoint with the size " + str(size) + "\n")
|
1052 |
self.logger.debug("Receiving data on the cin endpoint with the size %d\n" % size)
|
| 1052 |
if self.packetsizelimit.cin and size > self.packetsizelimit.cin:
|
1053 |
if self.packetsizelimit.cin and size > self.packetsizelimit.cin:
|
| 1053 |
raise ReceiveError("Packet too big")
|
1054 |
raise ReceiveError("Packet too big")
|
| 1054 |
return self.receive(self.endpoint.cin, size)
|
1055 |
return self.receive(self.endpoint.cin, size)
|
| 1055 |
|
1056 |
|
| 1056 |
def dout(self, data):
|
1057 |
def dout(self, data):
|
| 1057 |
self.logger.debug("Sending data to cout endpoint with the size " + str(len(data)) + "\n")
|
1058 |
self.logger.debug("Sending data to cout endpoint with the size %d\n" % len(data))
|
| 1058 |
if self.packetsizelimit.dout and len(data) > self.packetsizelimit.dout:
|
1059 |
if self.packetsizelimit.dout and len(data) > self.packetsizelimit.dout:
|
| 1059 |
raise SendError("Packet too big")
|
1060 |
raise SendError("Packet too big")
|
| 1060 |
return self.send(self.endpoint.dout, data)
|
1061 |
return self.send(self.endpoint.dout, data)
|
| 1061 |
|
1062 |
|
| 1062 |
def din(self, size):
|
1063 |
def din(self, size):
|
| 1063 |
self.logger.debug("Receiving data on the din endpoint with the size " + str(size) + "\n")
|
1064 |
self.logger.debug("Receiving data on the din endpoint with the size %d\n" % size)
|
| 1064 |
if self.packetsizelimit.din and size > self.packetsizelimit.din:
|
1065 |
if self.packetsizelimit.din and size > self.packetsizelimit.din:
|
| 1065 |
raise ReceiveError("Packet too big")
|
1066 |
raise ReceiveError("Packet too big")
|
| 1066 |
return self.receive(self.endpoint.din, size)
|
1067 |
return self.receive(self.endpoint.din, size)
|
| 1067 |
|
1068 |
|
| 1068 |
|
1069 |
|
| Line 1083... |
Line 1084... |
| 1083 |
|
1084 |
|
| 1084 |
elif sys.argv[1] == "malloctest":
|
1085 |
elif sys.argv[1] == "malloctest":
|
| 1085 |
emcore = Emcore()
|
1086 |
emcore = Emcore()
|
| 1086 |
logger.write("Allocating 200 bytes of memory: ")
|
1087 |
logger.write("Allocating 200 bytes of memory: ")
|
| 1087 |
addr = emcore.malloc(200)
|
1088 |
addr = emcore.malloc(200)
|
| 1088 |
logger.write("0x%x\n" % addr)
|
1089 |
logger.write("0x%X\n" % addr)
|
| 1089 |
logger.write("Reallocating to 2000 bytes: ")
|
1090 |
logger.write("Reallocating to 2000 bytes: ")
|
| 1090 |
addr = emcore.realloc(addr, 2000)
|
1091 |
addr = emcore.realloc(addr, 2000)
|
| 1091 |
logger.write("0x%x\n" % addr)
|
1092 |
logger.write("0x%X\n" % addr)
|
| 1092 |
logger.write("Freeing 0x%x\n" % addr)
|
1093 |
logger.write("Freeing 0x%X\n" % addr)
|
| 1093 |
emcore.free(addr)
|
1094 |
emcore.free(addr)
|
| 1094 |
logger.write("Allocating 1000 bytes of memory aligned to 100 bytes: ")
|
1095 |
logger.write("Allocating 1000 bytes of memory aligned to 100 bytes: ")
|
| 1095 |
addr = emcore.memalign(100, 1000)
|
1096 |
addr = emcore.memalign(100, 1000)
|
| 1096 |
logger.write("0x%x\n" % addr)
|
1097 |
logger.write("0x%X\n" % addr)
|
| 1097 |
logger.write("Freeing 0x%x\n" % addr)
|
1098 |
logger.write("Freeing 0x%X\n" % addr)
|
| 1098 |
emcore.free(addr)
|
1099 |
emcore.free(addr)
|
| 1099 |
|
1100 |
|