| Index: emcore/trunk/tools/emcore.py | 
| — | — | @@ -170,6 +170,8 @@ | 
| 171 | 171 | """ | 
| 172 | 172 | if type(something) == bool: | 
| 173 | 173 | return something | 
|  | 174 | +        if something is None: | 
|  | 175 | +            return False | 
| 174 | 176 | elif type(something) == int or type(something) == long: | 
| 175 | 177 | return bool(something) | 
| 176 | 178 | elif type(something == str): | 
| — | — | @@ -195,7 +197,7 @@ | 
| 196 | 198 | return int(something, 16) | 
| 197 | 199 | except ValueError: | 
| 198 | 200 | raise ArgumentTypeError("hexadecimal coded integer", "'"+str(something)+"'") | 
| 199 |  | -        elif type(something) == NoneType:
 | 
|  | 201 | +        elif something is None: | 
| 200 | 202 | return None | 
| 201 | 203 | else: | 
| 202 | 204 | raise ArgumentTypeError("hexadecimal coded integer", "'"+str(something)+"'") | 
| — | — | @@ -261,11 +263,11 @@ | 
| 262 | 264 | self.emcore.poweroff(force) | 
| 263 | 265 |  | 
| 264 | 266 | @command | 
| 265 |  | -    def uploadfile(self, addr, filename):
 | 
|  | 267 | +    def uploadfile(self, filename, addr = None): | 
| 266 | 268 | """ | 
| 267 | 269 | Uploads a file to the device | 
| 268 |  | -            <offset>: the address to upload the file to
 | 
| 269 |  | -            <filename>: the path to the file
 | 
|  | 270 | +            <filename>: The path to the file | 
|  | 271 | +            [addr]: The address to upload the file to. Allocates a chunk of memory if not given. | 
| 270 | 272 | """ | 
| 271 | 273 | addr = self._hexint(addr) | 
| 272 | 274 | try: | 
| — | — | @@ -272,12 +274,20 @@ | 
| 273 | 275 | f = open(filename, 'rb') | 
| 274 | 276 | except IOError: | 
| 275 | 277 | raise ArgumentError("File not readable. Does it exist?") | 
| 276 |  | -        self.logger.info("Writing file '" + filename + \
 | 
| 277 |  | -                         "' to memory at " + self._hex(addr) + "...")
 | 
|  | 278 | +        if addr is not None: | 
|  | 279 | +            self.logger.info("Writing file '" + filename + \ | 
|  | 280 | +                            "' to memory at " + self._hex(addr) + "...\n") | 
|  | 281 | +        else: | 
|  | 282 | +            self.logger.info("Writing file '" + filename + " to an allocated memory region...\n") | 
| 278 | 283 | with f: | 
| 279 |  | -            self.emcore.write(addr, f.read())
 | 
|  | 284 | +            if addr is not None: | 
|  | 285 | +                self.emcore.write(addr, f.read()) | 
|  | 286 | +            else: | 
|  | 287 | +                addr = self.emcore.upload(f.read()) | 
|  | 288 | +            size = f.tell() | 
| 280 | 289 | f.close() | 
| 281 |  | -        self.logger.info("done\n")
 | 
|  | 290 | +        self.logger.info("Done uploading " + str(size) + " bytes to 0x" + self._hex(addr) + "\n") | 
|  | 291 | +        return addr, size | 
| 282 | 292 |  | 
| 283 | 293 | @command | 
| 284 | 294 | def downloadfile(self, addr, size, filename): | 
| — | — | @@ -608,23 +618,23 @@ | 
| 609 | 619 | self.emcore.bootflashwrite(addr_mem, addr_flash, size) | 
| 610 | 620 |  | 
| 611 | 621 | @command | 
| 612 |  | -    def runfirmware(self, addr, filename):
 | 
|  | 622 | +    def runfirmware(self, targetaddr, filename): | 
| 613 | 623 | """ | 
| 614 | 624 | Uploads the firmware in <filename> | 
| 615 |  | -            to the address at <addr> and executes it.
 | 
|  | 625 | +            to an allocated buffer and executes it at <targetaddr>. | 
| 616 | 626 | """ | 
| 617 |  | -        addr = self._hexint(addr)
 | 
| 618 |  | -        self.uploadfile(addr, filename)
 | 
| 619 |  | -        self.execfirmware(addr)
 | 
|  | 627 | +        targetaddr = self._hexint(targetaddr) | 
|  | 628 | +        addr, size = self.uploadfile(filename) | 
|  | 629 | +        self.execfirmware(targetaddr, addr, size) | 
| 620 | 630 |  | 
| 621 | 631 | @command | 
| 622 |  | -    def execfirmware(self, addr):
 | 
|  | 632 | +    def execfirmware(self, targetaddr, addr, size): | 
| 623 | 633 | """ | 
| 624 |  | -            Executes the firmware at <addr>
 | 
|  | 634 | +            Moves the firmware at <addr> with <size> to <targetaddr> and executes it | 
| 625 | 635 | """ | 
| 626 | 636 | addr = self._hexint(addr) | 
| 627 |  | -        self.logger.info("Running firmware at "+self._hex(addr)+". Bye.")
 | 
| 628 |  | -        self.emcore.execfirmware(addr)
 | 
|  | 637 | +        self.logger.info("Running firmware at "+self._hex(targetaddr)+". Bye.\n") | 
|  | 638 | +        self.emcore.execfirmware(targetaddr, addr, size) | 
| 629 | 639 |  | 
| 630 | 640 | @command | 
| 631 | 641 | def aesencrypt(self, addr, size, keyindex): | 
| Index: emcore/trunk/tools/libemcore.py | 
| — | — | @@ -267,6 +267,16 @@ | 
| 268 | 268 | return data | 
| 269 | 269 |  | 
| 270 | 270 | @command() | 
|  | 271 | +    def upload(self, data): | 
|  | 272 | +        """ Allocates memory of the size of 'data' and uploads 'data' to that memory region. | 
|  | 273 | +            Returns the address where 'data' is stored | 
|  | 274 | +        """ | 
|  | 275 | +        addr = self.malloc(len(data)) | 
|  | 276 | +        self.logger.debug("Uploading %d bytes to 0x%x\n" % (len(data), addr)) | 
|  | 277 | +        self.write(addr, data) | 
|  | 278 | +        return addr | 
|  | 279 | + | 
|  | 280 | +    @command() | 
| 271 | 281 | def readstring(self, addr, maxlength = 256): | 
| 272 | 282 | """ Reads a zero terminated string from memory | 
| 273 | 283 | Reads only a maximum of 'maxlength' chars. | 
| — | — | @@ -521,9 +531,10 @@ | 
| 522 | 532 | return self.lib.monitorcommand(struct.pack("IIII", 23, memaddr, flashaddr, size), "III", (None, None, None)) | 
| 523 | 533 |  | 
| 524 | 534 | @command() | 
| 525 |  | -    def execfirmware(self, addr):
 | 
| 526 |  | -        """ Executes the firmware at 'addr' and passes all control to it. """
 | 
| 527 |  | -        return self.lib.monitorcommand(struct.pack("IIII", 24, addr, 0, 0))
 | 
|  | 535 | +    def execfirmware(self, targetaddr, addr, size): | 
|  | 536 | +        """ Moves the firmware at 'addr' with size 'size' to 'targetaddr' and passes all control to it. """ | 
|  | 537 | +        self.logger.debug("Moving firmware at 0x%x with the size %d to 0x%x and executing it\n" % (addr, size, targetaddr)) | 
|  | 538 | +        return self.lib.monitorcommand(struct.pack("IIII", 24, targetaddr, addr, size)) | 
| 528 | 539 |  | 
| 529 | 540 | @command(timeout = 30000) | 
| 530 | 541 | def aesencrypt(self, addr, size, keyindex): | 
| — | — | @@ -823,13 +834,17 @@ | 
| 824 | 835 | @command() | 
| 825 | 836 | def malloc(self, size): | 
| 826 | 837 | """ Allocates 'size' bytes and returns a pointer to the allocated memory """ | 
|  | 838 | +        self.logger.debug("Allocating %d bytes of memory\n" % size) | 
| 827 | 839 | result = self.lib.monitorcommand(struct.pack("IIII", 52, size, 0, 0), "III", ("ptr", None, None)) | 
|  | 840 | +        self.logger.debug("Allocated %d bytes of memory at 0x%x\n" % (size, result.ptr)) | 
| 828 | 841 | return result.ptr | 
| 829 | 842 |  | 
| 830 | 843 | @command() | 
| 831 | 844 | def memalign(self, align, size): | 
| 832 | 845 | """ Allocates 'size' bytes aligned to 'align' and returns a pointer to the allocated memory """ | 
|  | 846 | +        self.logger.debug("Allocating %d bytes of memory aligned to 0x%x\n" % (size, align)) | 
| 833 | 847 | result = self.lib.monitorcommand(struct.pack("IIII", 53, align, size, 0), "III", ("ptr", None, None)) | 
|  | 848 | +        self.logger.debug("Allocated %d bytes of memory at 0x%x\n" % (size, result.ptr)) | 
| 834 | 849 | return result.ptr | 
| 835 | 850 |  | 
| 836 | 851 | @command() | 
| — | — | @@ -838,17 +853,21 @@ | 
| 839 | 854 | expanding or reducing the amount of memory available in the block. | 
| 840 | 855 | Returns a pointer to the reallocated memory. | 
| 841 | 856 | """ | 
|  | 857 | +        self.logger.debug("Reallocating 0x%x to have the new size %d\n" % (ptr, size)) | 
| 842 | 858 | result = self.lib.monitorcommand(struct.pack("IIII", 54, ptr, size, 0), "III", ("ptr", None, None)) | 
|  | 859 | +        self.logger.debug("Reallocated memory at 0x%x to 0x%x with the new size %d\n" % (ptr, result.ptr, size)) | 
| 843 | 860 | return result.ptr | 
| 844 | 861 |  | 
| 845 | 862 | @command() | 
| 846 | 863 | def reownalloc(self, ptr, owner): | 
| 847 | 864 | """ Changes the owner of the memory allocation 'ptr' to the thread struct at addr 'owner' """ | 
|  | 865 | +        self.logger.debug("Changing owner of the memory region 0x%x to 0x%x" % (ptr, owner)) | 
| 848 | 866 | return self.lib.monitorcommand(struct.pack("IIII", 55, ptr, owner, 0), "III", (None, None, None)) | 
| 849 | 867 |  | 
| 850 | 868 | @command() | 
| 851 | 869 | def free(self, ptr): | 
| 852 | 870 | """ Frees the memory space pointed to by 'ptr' """ | 
|  | 871 | +        self.logger.debug("Freeing the memory region at 0x%x\n" % ptr) | 
| 853 | 872 | return self.lib.monitorcommand(struct.pack("IIII", 56, addr, 0, 0), "III", (None, None, None)) | 
| 854 | 873 |  | 
| 855 | 874 |  | 
| — | — | @@ -868,7 +887,7 @@ | 
| 869 | 888 | self.connected = True | 
| 870 | 889 |  | 
| 871 | 890 | def monitorcommand(self, cmd, rcvdatatypes=None, rcvstruct=None): | 
| 872 |  | -        self.logger.debug("Sending monitorcommand\n")
 | 
|  | 891 | +        self.logger.debug("Sending monitorcommand [0x%s]\n" % cmd[3::-1].encode("hex")) | 
| 873 | 892 | writelen = self.dev.cout(cmd) | 
| 874 | 893 | if rcvdatatypes: | 
| 875 | 894 | rcvdatatypes = "I" + rcvdatatypes # add the response |