Subversion Repositories freemyipod

Rev

Rev 516 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 516 Rev 517
Line 83... Line 83...
83
            if docstring and doc[function]['documentation']:
83
            if docstring and doc[function]['documentation']:
84
                logger.write("\n")
84
                logger.write("\n")
85
                logger.write(doc[function]['documentation']+"\n", 4)
85
                logger.write(doc[function]['documentation']+"\n", 4)
86
            logger.write("\n")
86
            logger.write("\n")
87
    logger.write("\n")
87
    logger.write("\n")
88
 
88
    
89
    if errormsg:
89
    if errormsg:
90
        logger.error(str(errormsg)+"\n")
90
        logger.error(str(errormsg)+"\n")
91
    exit(2)
91
    exit(2)
92
 
92
 
93
 
93
 
Line 132... Line 132...
132
            self.emcore = libemcore.Emcore(logger = self.logger)
132
            self.emcore = libemcore.Emcore(logger = self.logger)
133
        except libemcore.DeviceNotFoundError:
133
        except libemcore.DeviceNotFoundError:
134
            self.logger.error("No emCORE device found!\n")
134
            self.logger.error("No emCORE device found!\n")
135
            exit(1)
135
            exit(1)
136
        self.getinfo("version")
136
        self.getinfo("version")
137
        
137
    
138
    def _parsecommand(self, func, args):
138
    def _parsecommand(self, func, args):
139
        # adds self to the commandline args.
139
        # adds self to the commandline args.
140
        # this is needed because the functions need access to their class.
140
        # this is needed because the functions need access to their class.
141
        args.insert(0, self)
141
        args.insert(0, self)
142
        if func in self.cmddict:
142
        if func in self.cmddict:
Line 180... Line 180...
180
            if something.lower() in truelist:
180
            if something.lower() in truelist:
181
                return True
181
                return True
182
            elif something.lower() in falselist:
182
            elif something.lower() in falselist:
183
                return False
183
                return False
184
        raise ArgumentTypeError("bool", "'%s'" % something)
184
        raise ArgumentTypeError("bool", "'%s'" % something)
185
 
185
    
186
    @staticmethod
186
    @staticmethod
187
    def _hexint(something):
187
    def _hexint(something):
188
        """
188
        """
189
            Converts quite everything to a hexadecimal represented integer.
189
            Converts quite everything to a hexadecimal represented integer.
190
            This works for default arguments too, because it returns
190
            This works for default arguments too, because it returns
Line 307... Line 307...
307
                        (addr, size, filename))
307
                        (addr, size, filename))
308
        with f:
308
        with f:
309
            f.write(self.emcore.read(addr, size))
309
            f.write(self.emcore.read(addr, size))
310
        f.close()
310
        f.close()
311
        self.logger.info("done\n")
311
        self.logger.info("done\n")
312
 
312
    
313
    @command
313
    @command
314
    def uploadint(self, addr, integer):
314
    def uploadint(self, addr, integer):
315
        """
315
        """
316
            Uploads a single integer to the device
316
            Uploads a single integer to the device
317
            <addr>: the address to upload the integer to
317
            <addr>: the address to upload the integer to
Line 322... Line 322...
322
        if integer > 0xFFFFFFFF:
322
        if integer > 0xFFFFFFFF:
323
            raise ArgumentError("Specified integer too long")
323
            raise ArgumentError("Specified integer too long")
324
        data = struct.pack("I", integer)
324
        data = struct.pack("I", integer)
325
        self.emcore.write(addr, data)
325
        self.emcore.write(addr, data)
326
        self.logger.info("Integer '0x%X' written successfully to 0x%X\n" % (integer, addr))
326
        self.logger.info("Integer '0x%X' written successfully to 0x%X\n" % (integer, addr))
327
 
327
    
328
    @command
328
    @command
329
    def downloadint(self, addr):
329
    def downloadint(self, addr):
330
        """
330
        """
331
            Downloads a single integer from the device and prints it to the console window
331
            Downloads a single integer from the device and prints it to the console window
332
            <addr>: the address to download the integer from
332
            <addr>: the address to download the integer from
333
        """
333
        """
334
        addr = self._hexint(addr)
334
        addr = self._hexint(addr)
335
        data = self.emcore.read(addr, 4)
335
        data = self.emcore.read(addr, 4)
336
        integer = struct.unpack("I", data)[0]
336
        integer = struct.unpack("I", data)[0]
337
        self.logger.info("Read '0x%X' from address 0x%X\n" % (integer, addr))
337
        self.logger.info("Read '0x%X' from address 0x%X\n" % (integer, addr))
338
 
338
    
339
    @command
339
    @command
340
    def i2cread(self, bus, slave, addr, size):
340
    def i2cread(self, bus, slave, addr, size):
341
        """
341
        """
342
            Reads data from an I2C device
342
            Reads data from an I2C device
343
            <bus>: the bus index
343
            <bus>: the bus index
Line 352... Line 352...
352
        data = self.emcore.i2cread(bus, slave, addr, size)
352
        data = self.emcore.i2cread(bus, slave, addr, size)
353
        bytes = struct.unpack("%dB" % len(data), data)
353
        bytes = struct.unpack("%dB" % len(data), data)
354
        self.logger.info("Data read from I2C:\n")
354
        self.logger.info("Data read from I2C:\n")
355
        for index, byte in enumerate(bytes):
355
        for index, byte in enumerate(bytes):
356
            self.logger.info("%02X: %02X\n" % (index, byte))
356
            self.logger.info("%02X: %02X\n" % (index, byte))
357
 
357
    
358
    @command
358
    @command
359
    def i2cwrite(self, bus, slave, addr, *args):
359
    def i2cwrite(self, bus, slave, addr, *args):
360
        """
360
        """
361
            Writes data to an I2C device
361
            Writes data to an I2C device
362
            <bus>: the bus index
362
            <bus>: the bus index
Line 372... Line 372...
372
        for arg in args:
372
        for arg in args:
373
            data += chr(self._hexint(arg))
373
            data += chr(self._hexint(arg))
374
        self.logger.info("Writing data to I2C...\n")
374
        self.logger.info("Writing data to I2C...\n")
375
        self.emcore.i2cwrite(bus, slave, addr, data)
375
        self.emcore.i2cwrite(bus, slave, addr, data)
376
        self.logger.info("done\n")
376
        self.logger.info("done\n")
377
 
377
    
378
    @command
378
    @command
379
    def console(self):
379
    def console(self):
380
        """
380
        """
381
            Reads data from the USB console continuously
381
            Reads data from the USB console continuously
382
        """
382
        """
383
        while True:
383
        while True:
384
            resp = self.emcore.usbcread()
384
            resp = self.emcore.usbcread()
385
            self.logger.write(resp.data)
385
            self.logger.write(resp.data)
386
            time.sleep(0.1 / resp.maxsize * (resp.maxsize - len(resp.data)))
386
            time.sleep(0.1 / resp.maxsize * (resp.maxsize - len(resp.data)))
387
 
387
    
388
    @command
388
    @command
389
    def writeusbconsole(self, *args):
389
    def writeusbconsole(self, *args):
390
        """
390
        """
391
            Writes the string <db1> ... <dbN> to the USB console.
391
            Writes the string <db1> ... <dbN> to the USB console.
392
        """
392
        """
Line 394... Line 394...
394
        for word in args:
394
        for word in args:
395
            text += word + " "
395
            text += word + " "
396
        text = text[:-1]
396
        text = text[:-1]
397
        self.logger.info("Writing '%s' to the usb console\n" % text)
397
        self.logger.info("Writing '%s' to the usb console\n" % text)
398
        self.emcore.usbcwrite(text)
398
        self.emcore.usbcwrite(text)
399
 
399
    
400
    @command
400
    @command
401
    def readdevconsole(self, bitmask):
401
    def readdevconsole(self, bitmask):
402
        """
402
        """
403
            Reads data continuously from one or more of the device's consoles.
403
            Reads data continuously from one or more of the device's consoles.
404
            <bitmask>: the bitmask of the consoles to read from.
404
            <bitmask>: the bitmask of the consoles to read from.
Line 420... Line 420...
420
        for word in args:
420
        for word in args:
421
            text += word + " "
421
            text += word + " "
422
        text = text[:-1]
422
        text = text[:-1]
423
        self.logger.info("Writing '%s' to the device consoles identified with 0x%X\n" % (text, bitmask))
423
        self.logger.info("Writing '%s' to the device consoles identified with 0x%X\n" % (text, bitmask))
424
        self.emcore.cwrite(text, bitmask)
424
        self.emcore.cwrite(text, bitmask)
425
 
425
    
426
    @command
426
    @command
427
    def flushconsolebuffers(self, bitmask):
427
    def flushconsolebuffers(self, bitmask):
428
        """
428
        """
429
            flushes one or more of the device consoles' buffers.
429
            flushes one or more of the device consoles' buffers.
430
            <bitmask>: the bitmask of the consoles to be flushed
430
            <bitmask>: the bitmask of the consoles to be flushed
431
        """
431
        """
432
        bitmask = self._hexint(bitmask)
432
        bitmask = self._hexint(bitmask)
433
        self.logger.info("Flushing consoles identified with the bitmask 0x%X\n" % bitmask)
433
        self.logger.info("Flushing consoles identified with the bitmask 0x%X\n" % bitmask)
434
        self.emcore.cflush(bitmask)
434
        self.emcore.cflush(bitmask)
435
 
435
    
436
    @command
436
    @command
437
    def getprocinfo(self):
437
    def getprocinfo(self):
438
        """
438
        """
439
            Fetches data on the currently running processes
439
            Fetches data on the currently running processes
440
        """
440
        """
Line 495... Line 495...
495
            Suspends the thread with the thread address <threadaddr>
495
            Suspends the thread with the thread address <threadaddr>
496
        """
496
        """
497
        threadaddr = self._hexint(threadaddr)
497
        threadaddr = self._hexint(threadaddr)
498
        self.logger.info("Suspending the thread with the threadaddr 0x%X\n" % threadaddr)
498
        self.logger.info("Suspending the thread with the threadaddr 0x%X\n" % threadaddr)
499
        self.emcore.suspendthread(threadaddr)
499
        self.emcore.suspendthread(threadaddr)
500
 
500
    
501
    @command
501
    @command
502
    def resumethread(self, threadaddr):
502
    def resumethread(self, threadaddr):
503
        """
503
        """
504
            Resumes the thread with the thread address <threadaddr>
504
            Resumes the thread with the thread address <threadaddr>
505
        """
505
        """
506
        threadaddr = self._hexint(threadaddr)
506
        threadaddr = self._hexint(threadaddr)
507
        self.logger.info("Resuming the thread with the threadaddr 0x%X\n" % threadaddr)
507
        self.logger.info("Resuming the thread with the threadaddr 0x%X\n" % threadaddr)
508
        self.emcore.resumethread(threadaddr)
508
        self.emcore.resumethread(threadaddr)
509
 
509
    
510
    @command
510
    @command
511
    def killthread(self, threadaddr):
511
    def killthread(self, threadaddr):
512
        """
512
        """
513
            Kills the thread with the thread address <threadaddr>
513
            Kills the thread with the thread address <threadaddr>
514
        """
514
        """
515
        threadaddr = self._hexint(threadaddr)
515
        threadaddr = self._hexint(threadaddr)
516
        self.logger.info("Killing the thread with the threadaddr 0x%X\n" % threadaddr)
516
        self.logger.info("Killing the thread with the threadaddr 0x%X\n" % threadaddr)
517
        self.emcore.killthread(threadaddr)
517
        self.emcore.killthread(threadaddr)
518
 
518
    
519
    @command
519
    @command
520
    def createthread(self, nameptr, entrypoint, stackptr, stacksize, threadtype, priority, state):
520
    def createthread(self, nameptr, entrypoint, stackptr, stacksize, threadtype, priority, state):
521
        """
521
        """
522
            Creates a new thread and returns its thread pointer
522
            Creates a new thread and returns its thread pointer
523
            <namepointer>: a pointer to the thread's name
523
            <namepointer>: a pointer to the thread's name
Line 550... Line 550...
550
        except IOError:
550
        except IOError:
551
            raise ArgumentError("File not readable. Does it exist?")
551
            raise ArgumentError("File not readable. Does it exist?")
552
        with f:
552
        with f:
553
            data = self.emcore.run(f.read())
553
            data = self.emcore.run(f.read())
554
        self.logger.info("Executed emCORE application as thread 0x%X\n" % data.thread)
554
        self.logger.info("Executed emCORE application as thread 0x%X\n" % data.thread)
555
 
555
    
556
    @command
556
    @command
557
    def execimage(self, addr):
557
    def execimage(self, addr):
558
        """
558
        """
559
            Executes the emCORE application at <addr>.
559
            Executes the emCORE application at <addr>.
560
        """
560
        """
Line 672... Line 672...
672
        self.emcore.hmac_sha1(addr, size, destination)
672
        self.emcore.hmac_sha1(addr, size, destination)
673
        self.logger.info("done\n")
673
        self.logger.info("done\n")
674
        data = self.emcore.read(destination, sha1size)
674
        data = self.emcore.read(destination, sha1size)
675
        hash = ord(data)
675
        hash = ord(data)
676
        self.logger.info("The generated hash is 0x%X\n" % hash)
676
        self.logger.info("The generated hash is 0x%X\n" % hash)
677
 
677
    
678
    @command
678
    @command
679
    def ipodnano2g_getnandinfo(self):
679
    def ipodnano2g_getnandinfo(self):
680
        """
680
        """
681
            Target-specific function: ipodnano2g
681
            Target-specific function: ipodnano2g
682
            Gathers some information about the NAND chip used
682
            Gathers some information about the NAND chip used
Line 685... Line 685...
685
        self.logger.info("NAND chip type: 0x%X\n" % data["type"])
685
        self.logger.info("NAND chip type: 0x%X\n" % data["type"])
686
        self.logger.info("Number of banks: %d\n" % data["banks"])
686
        self.logger.info("Number of banks: %d\n" % data["banks"])
687
        self.logger.info("Number of blocks: %d\n" % data["blocks"])
687
        self.logger.info("Number of blocks: %d\n" % data["blocks"])
688
        self.logger.info("Number of user blocks: %d\n" % data["userblocks"])
688
        self.logger.info("Number of user blocks: %d\n" % data["userblocks"])
689
        self.logger.info("Pages per block: %d\n" % data["pagesperblock"])
689
        self.logger.info("Pages per block: %d\n" % data["pagesperblock"])
690
 
690
    
691
    @command
691
    @command
692
    def ipodnano2g_nandread(self, addr, start, count, doecc=True, checkempty=True):
692
    def ipodnano2g_nandread(self, addr, start, count, doecc=True, checkempty=True):
693
        """
693
        """
694
            Target-specific function: ipodnano2g
694
            Target-specific function: ipodnano2g
695
            Reads data from the NAND chip into memory
695
            Reads data from the NAND chip into memory
Line 706... Line 706...
706
        checkempty = self._bool(checkempty)
706
        checkempty = self._bool(checkempty)
707
        self.logger.info("Reading 0x%X NAND pages starting at 0x%X to memory at 0x%X..." %
707
        self.logger.info("Reading 0x%X NAND pages starting at 0x%X to memory at 0x%X..." %
708
                        (count, start, addr))
708
                        (count, start, addr))
709
        self.emcore.ipodnano2g_nandread(addr, start, count, doecc, checkempty)
709
        self.emcore.ipodnano2g_nandread(addr, start, count, doecc, checkempty)
710
        self.logger.info("done\n")
710
        self.logger.info("done\n")
711
 
711
    
712
    @command
712
    @command
713
    def ipodnano2g_nandwrite(self, addr, start, count, doecc=True):
713
    def ipodnano2g_nandwrite(self, addr, start, count, doecc=True):
714
        """
714
        """
715
            Target-specific function: ipodnano2g
715
            Target-specific function: ipodnano2g
716
            Writes data to the NAND chip
716
            Writes data to the NAND chip
Line 725... Line 725...
725
        doecc = self._bool(doecc)
725
        doecc = self._bool(doecc)
726
        self.logger.info("Writing 0x%X NAND pages starting at 0x%X from memory at 0x%X..." %
726
        self.logger.info("Writing 0x%X NAND pages starting at 0x%X from memory at 0x%X..." %
727
                        (count, start, addr))
727
                        (count, start, addr))
728
        self.emcore.ipodnano2g_nandwrite(addr, start, count, doecc)
728
        self.emcore.ipodnano2g_nandwrite(addr, start, count, doecc)
729
        self.logger.info("done\n")
729
        self.logger.info("done\n")
730
 
730
    
731
    @command
731
    @command
732
    def ipodnano2g_nanderase(self, addr, start, count):
732
    def ipodnano2g_nanderase(self, addr, start, count):
733
        """
733
        """
734
            Target-specific function: ipodnano2g
734
            Target-specific function: ipodnano2g
735
            Erases blocks on the NAND chip and stores the results to memory
735
            Erases blocks on the NAND chip and stores the results to memory
Line 742... Line 742...
742
        count = self._hexint(count)
742
        count = self._hexint(count)
743
        self.logger.info("Erasing 0x%X NAND pages starting at 0x%X and logging to 0x%X..." %
743
        self.logger.info("Erasing 0x%X NAND pages starting at 0x%X and logging to 0x%X..." %
744
                        (count, start, addr))
744
                        (count, start, addr))
745
        self.emcore.ipodnano2g_nanderase(addr, start, count)
745
        self.emcore.ipodnano2g_nanderase(addr, start, count)
746
        self.logger.info("done\n")
746
        self.logger.info("done\n")
747
 
747
    
748
    @command
748
    @command
749
    def ipodnano2g_dumpnand(self, filenameprefix):
749
    def ipodnano2g_dumpnand(self, filenameprefix):
750
        """
750
        """
751
            Target-specific function: ipodnano2g
751
            Target-specific function: ipodnano2g
752
            Dumps the whole NAND chip to four files
752
            Dumps the whole NAND chip to four files
Line 775... Line 775...
775
        infofile.close()
775
        infofile.close()
776
        datafile.close()
776
        datafile.close()
777
        sparefile.close()
777
        sparefile.close()
778
        statusfile.close()
778
        statusfile.close()
779
        self.logger.info("done\n")
779
        self.logger.info("done\n")
780
 
780
    
781
    @command
781
    @command
782
    def ipodnano2g_wipenand(self, filename, force=False):
782
    def ipodnano2g_wipenand(self, filename, force=False):
783
        """
783
        """
784
            Target-specific function: ipodnano2g
784
            Target-specific function: ipodnano2g
785
            Wipes the whole NAND chip and logs the result to a file
785
            Wipes the whole NAND chip and logs the result to a file
Line 803... Line 803...
803
            self.logger.info(".")
803
            self.logger.info(".")
804
            self.emcore.ipodnano2g_nanderase(0x08000000, i * 64, 64)
804
            self.emcore.ipodnano2g_nanderase(0x08000000, i * 64, 64)
805
            statusfile.write(self.emcore.read(0x08000000, 0x00000100))
805
            statusfile.write(self.emcore.read(0x08000000, 0x00000100))
806
        statusfile.close()
806
        statusfile.close()
807
        self.logger.info("done\n")
807
        self.logger.info("done\n")
808
 
808
    
809
    @command
809
    @command
810
    def ipodclassic_writebbt(self, tempaddr, filename):
810
    def ipodclassic_writebbt(self, tempaddr, filename):
811
        """
811
        """
812
            Target-specific function: ipodclassic
812
            Target-specific function: ipodclassic
813
            Uploads the bad block table <filename> to
813
            Uploads the bad block table <filename> to
Line 820... Line 820...
820
            raise ArgumentError("File not readable. Does it exist?")
820
            raise ArgumentError("File not readable. Does it exist?")
821
        self.logger.info("Writing bad block table to disk...")
821
        self.logger.info("Writing bad block table to disk...")
822
        data = self.emcore.ipodclassic_writebbt(f.read(), tempaddr)
822
        data = self.emcore.ipodclassic_writebbt(f.read(), tempaddr)
823
        f.close()
823
        f.close()
824
        self.logger.info(" done\n")
824
        self.logger.info(" done\n")
825
 
825
    
826
    @command
826
    @command
827
    def getvolumeinfo(self, volume):
827
    def getvolumeinfo(self, volume):
828
        """
828
        """
829
            Gathers some information about a storage volume used
829
            Gathers some information about a storage volume used
830
            <volume>: volume id
830
            <volume>: volume id
Line 834... Line 834...
834
        self.logger.info("Sector size: %d\n" % data["sectorsize"])
834
        self.logger.info("Sector size: %d\n" % data["sectorsize"])
835
        self.logger.info("Number of sectors: %d\n" % data["numsectors"])
835
        self.logger.info("Number of sectors: %d\n" % data["numsectors"])
836
        self.logger.info("Vendor: %s\n" % data["vendor"])
836
        self.logger.info("Vendor: %s\n" % data["vendor"])
837
        self.logger.info("Product: %s\n" % data["product"])
837
        self.logger.info("Product: %s\n" % data["product"])
838
        self.logger.info("Revision: %s\n" % data["revision"])
838
        self.logger.info("Revision: %s\n" % data["revision"])
839
 
839
    
840
    @command
840
    @command
841
    def readrawstorage(self, volume, sector, count, addr):
841
    def readrawstorage(self, volume, sector, count, addr):
842
        """
842
        """
843
            Reads <count> sectors starting at <sector> from storage <volume> to memory at <addr>.
843
            Reads <count> sectors starting at <sector> from storage <volume> to memory at <addr>.
844
        """
844
        """
Line 847... Line 847...
847
        count = self._hexint(count)
847
        count = self._hexint(count)
848
        addr = self._hexint(addr)
848
        addr = self._hexint(addr)
849
        self.logger.info("Reading volume %s sectors %X - %X to %08X..." % (volume, sector, sector + count - 1, addr))
849
        self.logger.info("Reading volume %s sectors %X - %X to %08X..." % (volume, sector, sector + count - 1, addr))
850
        self.emcore.storage_read_sectors_md(volume, sector, count, addr)
850
        self.emcore.storage_read_sectors_md(volume, sector, count, addr)
851
        self.logger.info("done\n")
851
        self.logger.info("done\n")
852
 
852
    
853
    @command
853
    @command
854
    def writerawstorage(self, volume, sector, count, addr):
854
    def writerawstorage(self, volume, sector, count, addr):
855
        """
855
        """
856
            Writes memory contents at <addr> to <count> sectors starting at <sector> on storage <volume>.
856
            Writes memory contents at <addr> to <count> sectors starting at <sector> on storage <volume>.
857
        """
857
        """
Line 860... Line 860...
860
        count = self._hexint(count)
860
        count = self._hexint(count)
861
        addr = self._hexint(addr)
861
        addr = self._hexint(addr)
862
        self.logger.info("Writing %08X to volume %s sectors %X - %X..." % (addr, volume, sector, sector + count - 1))
862
        self.logger.info("Writing %08X to volume %s sectors %X - %X..." % (addr, volume, sector, sector + count - 1))
863
        self.emcore.storage_write_sectors_md(volume, sector, count, addr)
863
        self.emcore.storage_write_sectors_md(volume, sector, count, addr)
864
        self.logger.info("done\n")
864
        self.logger.info("done\n")
865
 
865
    
866
    @command
866
    @command
867
    def readrawstoragefile(self, volume, sector, count, file, buffsize = 0x100000, buffer = None):
867
    def readrawstoragefile(self, volume, sector, count, file, buffsize = 0x100000, buffer = None):
868
        """
868
        """
869
            Reads <count> sectors starting at <sector> from storage <volume> to file <file>,
869
            Reads <count> sectors starting at <sector> from storage <volume> to file <file>,
870
            buffering them in memory at [buffer] in chunks of [buffsize] bytes (both optional).
870
            buffering them in memory at [buffer] in chunks of [buffsize] bytes (both optional).
Line 898... Line 898...
898
                if malloc == True:
898
                if malloc == True:
899
                    self.emcore.free(buffer)
899
                    self.emcore.free(buffer)
900
        finally:
900
        finally:
901
            f.close()
901
            f.close()
902
        self.logger.info("done\n")
902
        self.logger.info("done\n")
903
 
903
    
904
    @command
904
    @command
905
    def writerawstoragefile(self, volume, sector, count, file, buffsize = 0x100000, buffer = None):
905
    def writerawstoragefile(self, volume, sector, count, file, buffsize = 0x100000, buffer = None):
906
        """
906
        """
907
            Writes contents of <file> to <count> sectors starting at <sector> on storage <volume>,
907
            Writes contents of <file> to <count> sectors starting at <sector> on storage <volume>,
908
            buffering them in memory at [buffer] in chunks of [buffsize] bytes (both optional).
908
            buffering them in memory at [buffer] in chunks of [buffsize] bytes (both optional).
Line 940... Line 940...
940
                if malloc == True:
940
                if malloc == True:
941
                    self.emcore.free(buffer)
941
                    self.emcore.free(buffer)
942
        finally:
942
        finally:
943
            f.close()
943
            f.close()
944
        self.logger.info("done\n")
944
        self.logger.info("done\n")
945
 
945
    
946
    @command
946
    @command
947
    def mkdir(self, dirname):
947
    def mkdir(self, dirname):
948
        """
948
        """
949
            Creates a directory with the name <dirname>
949
            Creates a directory with the name <dirname>
950
        """
950
        """
951
        self.logger.info("Creating directory %s..." % dirname)
951
        self.logger.info("Creating directory %s..." % dirname)
952
        self.emcore.dir_create(dirname)
952
        self.emcore.dir_create(dirname)
953
        self.logger.info(" done\n")
953
        self.logger.info(" done\n")
954
 
954
    
955
    @command
955
    @command
956
    def rmdir(self, dirname):
956
    def rmdir(self, dirname):
957
        """
957
        """
958
            Removes an empty directory with the name <dirname>
958
            Removes an empty directory with the name <dirname>
959
        """
959
        """
960
        self.logger.info("Removing directory %s..." % dirname)
960
        self.logger.info("Removing directory %s..." % dirname)
961
        self.emcore.dir_remove(dirname)
961
        self.emcore.dir_remove(dirname)
962
        self.logger.info(" done\n")
962
        self.logger.info(" done\n")
963
 
963
    
964
    @command
964
    @command
965
    def rm(self, filename):
965
    def rm(self, filename):
966
        """
966
        """
967
            Removes a file with the name <filename>
967
            Removes a file with the name <filename>
968
        """
968
        """
969
        self.logger.info("Removing file %s..." % filename)
969
        self.logger.info("Removing file %s..." % filename)
970
        self.emcore.file_unlink(filename)
970
        self.emcore.file_unlink(filename)
971
        self.logger.info(" done\n")
971
        self.logger.info(" done\n")
972
 
972
    
973
    @command
973
    @command
974
    def rmtree(self, path):
974
    def rmtree(self, path):
975
        """
975
        """
976
            Recursively removes a folder
976
            Recursively removes a folder
977
            <path>: the folder to be removed
977
            <path>: the folder to be removed
Line 985... Line 985...
985
                    self.rmtree(path + "/" + entry.name)
985
                    self.rmtree(path + "/" + entry.name)
986
                else: self.rm(path + "/" + entry.name)
986
                else: self.rm(path + "/" + entry.name)
987
            except: break
987
            except: break
988
        self.emcore.dir_close(handle)
988
        self.emcore.dir_close(handle)
989
        self.rmdir(path)
989
        self.rmdir(path)
990
 
990
    
991
    @command
991
    @command
992
    def mv(self, oldname, newname):
992
    def mv(self, oldname, newname):
993
        """
993
        """
994
            Renames or moves file or directory <oldname> to <newname>
994
            Renames or moves file or directory <oldname> to <newname>
995
        """
995
        """
996
        self.logger.info("Renaming %s to %s..." % (oldname, newname))
996
        self.logger.info("Renaming %s to %s..." % (oldname, newname))
997
        self.emcore.file_rename(oldname, newname)
997
        self.emcore.file_rename(oldname, newname)
998
        self.logger.info(" done\n")
998
        self.logger.info(" done\n")
999
 
999
    
1000
    @command
1000
    @command
1001
    def get(self, remotename, localname, buffsize = 0x10000, buffer = None):
1001
    def get(self, remotename, localname, buffsize = 0x10000, buffer = None):
1002
        """
1002
        """
1003
            Downloads a file
1003
            Downloads a file
1004
            <remotename>: filename on the device
1004
            <remotename>: filename on the device
Line 1034... Line 1034...
1034
            finally:
1034
            finally:
1035
                self.emcore.file_close(fd)
1035
                self.emcore.file_close(fd)
1036
        finally:
1036
        finally:
1037
            f.close()
1037
            f.close()
1038
        self.logger.info(" done\n")
1038
        self.logger.info(" done\n")
1039
 
1039
    
1040
    @command
1040
    @command
1041
    def gettree(self, remotepath, localpath, buffsize = 0x10000, buffer = None):
1041
    def gettree(self, remotepath, localpath, buffsize = 0x10000, buffer = None):
1042
        """
1042
        """
1043
            Downloads a directory tree
1043
            Downloads a directory tree
1044
            <remotepath>: path on the device
1044
            <remotepath>: path on the device
Line 1069... Line 1069...
1069
            finally:
1069
            finally:
1070
                if malloc == True:
1070
                if malloc == True:
1071
                    self.emcore.free(buffer)
1071
                    self.emcore.free(buffer)
1072
        finally:
1072
        finally:
1073
            self.emcore.dir_close(handle)
1073
            self.emcore.dir_close(handle)
1074
 
1074
    
1075
    @command
1075
    @command
1076
    def put(self, localname, remotename, buffsize = 0x10000, buffer = None):
1076
    def put(self, localname, remotename, buffsize = 0x10000, buffer = None):
1077
        """
1077
        """
1078
            Uploads a file
1078
            Uploads a file
1079
            <localname>: filename on the computer
1079
            <localname>: filename on the computer
Line 1111... Line 1111...
1111
                if malloc == True:
1111
                if malloc == True:
1112
                    self.emcore.free(buffer)
1112
                    self.emcore.free(buffer)
1113
        finally:
1113
        finally:
1114
            f.close()
1114
            f.close()
1115
        self.logger.info(" done\n")
1115
        self.logger.info(" done\n")
1116
 
1116
    
1117
    @command
1117
    @command
1118
    def puttree(self, localpath, remotepath, buffsize = 0x10000, buffer = None):
1118
    def puttree(self, localpath, remotepath, buffsize = 0x10000, buffer = None):
1119
        """
1119
        """
1120
            Uploads a directory tree
1120
            Uploads a directory tree
1121
            <localpath>: path on the computer
1121
            <localpath>: path on the computer
Line 1144... Line 1144...
1144
                    if prefix.find("/.svn/") == -1:
1144
                    if prefix.find("/.svn/") == -1:
1145
                        self.put(d[0] + "/" + f, prefix + f, buffsize, buffer)
1145
                        self.put(d[0] + "/" + f, prefix + f, buffsize, buffer)
1146
        finally:
1146
        finally:
1147
            if malloc == True:
1147
            if malloc == True:
1148
                self.emcore.free(buffer)
1148
                self.emcore.free(buffer)
1149
 
1149
    
1150
    @command
1150
    @command
1151
    def ls(self, path = "/"):
1151
    def ls(self, path = "/"):
1152
        """
1152
        """
1153
            Lists all files in the specified path
1153
            Lists all files in the specified path
1154
            [path]: the path which is listed
1154
            [path]: the path which is listed