| Line 265... |
Line 265... |
| 265 |
if tailsize != 0:
|
265 |
if tailsize != 0:
|
| 266 |
self._writemem(addr, data[offset:offset+tailsize])
|
266 |
self._writemem(addr, data[offset:offset+tailsize])
|
| 267 |
return data
|
267 |
return data
|
| 268 |
|
268 |
|
| 269 |
@command()
|
269 |
@command()
|
| - |
|
270 |
def upload(self, data):
|
| - |
|
271 |
""" Allocates memory of the size of 'data' and uploads 'data' to that memory region.
|
| - |
|
272 |
Returns the address where 'data' is stored
|
| - |
|
273 |
"""
|
| - |
|
274 |
addr = self.malloc(len(data))
|
| - |
|
275 |
self.logger.debug("Uploading %d bytes to 0x%x\n" % (len(data), addr))
|
| - |
|
276 |
self.write(addr, data)
|
| - |
|
277 |
return addr
|
| - |
|
278 |
|
| - |
|
279 |
@command()
|
| 270 |
def readstring(self, addr, maxlength = 256):
|
280 |
def readstring(self, addr, maxlength = 256):
|
| 271 |
""" Reads a zero terminated string from memory
|
281 |
""" Reads a zero terminated string from memory
|
| 272 |
Reads only a maximum of 'maxlength' chars.
|
282 |
Reads only a maximum of 'maxlength' chars.
|
| 273 |
"""
|
283 |
"""
|
| 274 |
cin_maxsize = self.lib.dev.packetsizelimit.cin - self.lib.headersize
|
284 |
cin_maxsize = self.lib.dev.packetsizelimit.cin - self.lib.headersize
|
| Line 519... |
Line 529... |
| 519 |
to the boot flash at addr 'flashaddr'
|
529 |
to the boot flash at addr 'flashaddr'
|
| 520 |
"""
|
530 |
"""
|
| 521 |
return self.lib.monitorcommand(struct.pack("IIII", 23, memaddr, flashaddr, size), "III", (None, None, None))
|
531 |
return self.lib.monitorcommand(struct.pack("IIII", 23, memaddr, flashaddr, size), "III", (None, None, None))
|
| 522 |
|
532 |
|
| 523 |
@command()
|
533 |
@command()
|
| 524 |
def execfirmware(self, addr):
|
534 |
def execfirmware(self, targetaddr, addr, size):
|
| 525 |
""" Executes the firmware at 'addr' and passes all control to it. """
|
535 |
""" Moves the firmware at 'addr' with size 'size' to 'targetaddr' and passes all control to it. """
|
| - |
|
536 |
self.logger.debug("Moving firmware at 0x%x with the size %d to 0x%x and executing it\n" % (addr, size, targetaddr))
|
| 526 |
return self.lib.monitorcommand(struct.pack("IIII", 24, addr, 0, 0))
|
537 |
return self.lib.monitorcommand(struct.pack("IIII", 24, targetaddr, addr, size))
|
| 527 |
|
538 |
|
| 528 |
@command(timeout = 30000)
|
539 |
@command(timeout = 30000)
|
| 529 |
def aesencrypt(self, addr, size, keyindex):
|
540 |
def aesencrypt(self, addr, size, keyindex):
|
| 530 |
""" Encrypts the buffer at 'addr' with the specified size
|
541 |
""" Encrypts the buffer at 'addr' with the specified size
|
| 531 |
with the hardware AES key index 'keyindex'
|
542 |
with the hardware AES key index 'keyindex'
|
| Line 821... |
Line 832... |
| 821 |
return result.rc
|
832 |
return result.rc
|
| 822 |
|
833 |
|
| 823 |
@command()
|
834 |
@command()
|
| 824 |
def malloc(self, size):
|
835 |
def malloc(self, size):
|
| 825 |
""" Allocates 'size' bytes and returns a pointer to the allocated memory """
|
836 |
""" Allocates 'size' bytes and returns a pointer to the allocated memory """
|
| - |
|
837 |
self.logger.debug("Allocating %d bytes of memory\n" % size)
|
| 826 |
result = self.lib.monitorcommand(struct.pack("IIII", 52, size, 0, 0), "III", ("ptr", None, None))
|
838 |
result = self.lib.monitorcommand(struct.pack("IIII", 52, size, 0, 0), "III", ("ptr", None, None))
|
| - |
|
839 |
self.logger.debug("Allocated %d bytes of memory at 0x%x\n" % (size, result.ptr))
|
| 827 |
return result.ptr
|
840 |
return result.ptr
|
| 828 |
|
841 |
|
| 829 |
@command()
|
842 |
@command()
|
| 830 |
def memalign(self, align, size):
|
843 |
def memalign(self, align, size):
|
| 831 |
""" Allocates 'size' bytes aligned to 'align' and returns a pointer to the allocated memory """
|
844 |
""" Allocates 'size' bytes aligned to 'align' and returns a pointer to the allocated memory """
|
| - |
|
845 |
self.logger.debug("Allocating %d bytes of memory aligned to 0x%x\n" % (size, align))
|
| 832 |
result = self.lib.monitorcommand(struct.pack("IIII", 53, align, size, 0), "III", ("ptr", None, None))
|
846 |
result = self.lib.monitorcommand(struct.pack("IIII", 53, align, size, 0), "III", ("ptr", None, None))
|
| - |
|
847 |
self.logger.debug("Allocated %d bytes of memory at 0x%x\n" % (size, result.ptr))
|
| 833 |
return result.ptr
|
848 |
return result.ptr
|
| 834 |
|
849 |
|
| 835 |
@command()
|
850 |
@command()
|
| 836 |
def realloc(self, ptr, size):
|
851 |
def realloc(self, ptr, size):
|
| 837 |
""" The size of the memory block pointed to by 'ptr' is changed to the 'size' bytes,
|
852 |
""" The size of the memory block pointed to by 'ptr' is changed to the 'size' bytes,
|
| 838 |
expanding or reducing the amount of memory available in the block.
|
853 |
expanding or reducing the amount of memory available in the block.
|
| 839 |
Returns a pointer to the reallocated memory.
|
854 |
Returns a pointer to the reallocated memory.
|
| 840 |
"""
|
855 |
"""
|
| - |
|
856 |
self.logger.debug("Reallocating 0x%x to have the new size %d\n" % (ptr, size))
|
| 841 |
result = self.lib.monitorcommand(struct.pack("IIII", 54, ptr, size, 0), "III", ("ptr", None, None))
|
857 |
result = self.lib.monitorcommand(struct.pack("IIII", 54, ptr, size, 0), "III", ("ptr", None, None))
|
| - |
|
858 |
self.logger.debug("Reallocated memory at 0x%x to 0x%x with the new size %d\n" % (ptr, result.ptr, size))
|
| 842 |
return result.ptr
|
859 |
return result.ptr
|
| 843 |
|
860 |
|
| 844 |
@command()
|
861 |
@command()
|
| 845 |
def reownalloc(self, ptr, owner):
|
862 |
def reownalloc(self, ptr, owner):
|
| 846 |
""" Changes the owner of the memory allocation 'ptr' to the thread struct at addr 'owner' """
|
863 |
""" Changes the owner of the memory allocation 'ptr' to the thread struct at addr 'owner' """
|
| - |
|
864 |
self.logger.debug("Changing owner of the memory region 0x%x to 0x%x" % (ptr, owner))
|
| 847 |
return self.lib.monitorcommand(struct.pack("IIII", 55, ptr, owner, 0), "III", (None, None, None))
|
865 |
return self.lib.monitorcommand(struct.pack("IIII", 55, ptr, owner, 0), "III", (None, None, None))
|
| 848 |
|
866 |
|
| 849 |
@command()
|
867 |
@command()
|
| 850 |
def free(self, ptr):
|
868 |
def free(self, ptr):
|
| 851 |
""" Frees the memory space pointed to by 'ptr' """
|
869 |
""" Frees the memory space pointed to by 'ptr' """
|
| - |
|
870 |
self.logger.debug("Freeing the memory region at 0x%x\n" % ptr)
|
| 852 |
return self.lib.monitorcommand(struct.pack("IIII", 56, addr, 0, 0), "III", (None, None, None))
|
871 |
return self.lib.monitorcommand(struct.pack("IIII", 56, addr, 0, 0), "III", (None, None, None))
|
| 853 |
|
872 |
|
| 854 |
|
873 |
|
| 855 |
class Lib(object):
|
874 |
class Lib(object):
|
| 856 |
def __init__(self, logger):
|
875 |
def __init__(self, logger):
|
| Line 866... |
Line 885... |
| 866 |
def connect(self):
|
885 |
def connect(self):
|
| 867 |
self.dev = Dev(self.idVendor, self.idProduct, self.logger)
|
886 |
self.dev = Dev(self.idVendor, self.idProduct, self.logger)
|
| 868 |
self.connected = True
|
887 |
self.connected = True
|
| 869 |
|
888 |
|
| 870 |
def monitorcommand(self, cmd, rcvdatatypes=None, rcvstruct=None):
|
889 |
def monitorcommand(self, cmd, rcvdatatypes=None, rcvstruct=None):
|
| 871 |
self.logger.debug("Sending monitorcommand\n")
|
890 |
self.logger.debug("Sending monitorcommand [0x%s]\n" % cmd[3::-1].encode("hex"))
|
| 872 |
writelen = self.dev.cout(cmd)
|
891 |
writelen = self.dev.cout(cmd)
|
| 873 |
if rcvdatatypes:
|
892 |
if rcvdatatypes:
|
| 874 |
rcvdatatypes = "I" + rcvdatatypes # add the response
|
893 |
rcvdatatypes = "I" + rcvdatatypes # add the response
|
| 875 |
data = self.dev.cin(struct.calcsize(rcvdatatypes))
|
894 |
data = self.dev.cin(struct.calcsize(rcvdatatypes))
|
| 876 |
data = struct.unpack(rcvdatatypes, data)
|
895 |
data = struct.unpack(rcvdatatypes, data)
|