Subversion Repositories freemyipod

Rev

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

Rev 394 Rev 395
Line 502... Line 502...
502
            raise ArgumentError("The baseaddress of the specified emBIOS application is out of range of the user memory range on the device. Are you sure that this application is compatible with your device?")
502
            raise ArgumentError("The baseaddress of the specified emBIOS application is out of range of the user memory range on the device. Are you sure that this application is compatible with your device?")
503
        self.write(baseaddr, app)
503
        self.write(baseaddr, app)
504
        self.execimage(baseaddr)
504
        self.execimage(baseaddr)
505
        return Bunch(baseaddr=baseaddr, name=name)
505
        return Bunch(baseaddr=baseaddr, name=name)
506
    
506
    
507
    @command()
507
    @command(timeout = 5000)
508
    def bootflashread(self, memaddr, flashaddr, size):
508
    def bootflashread(self, memaddr, flashaddr, size):
509
        """ Copies the data in the bootflash at 'flashaddr' of the specified size
509
        """ Copies the data in the bootflash at 'flashaddr' of the specified size
510
            to the memory at addr 'memaddr'
510
            to the memory at addr 'memaddr'
511
        """
511
        """
512
        return self.lib.monitorcommand(struct.pack("IIII", 22, memaddr, flashaddr, size), "III", (None, None, None))
512
        return self.lib.monitorcommand(struct.pack("IIII", 22, memaddr, flashaddr, size), "III", (None, None, None))
513
    
513
    
514
    @command()
514
    @command(timeout = 30000)
515
    def bootflashwrite(self, memaddr, flashaddr, size):
515
    def bootflashwrite(self, memaddr, flashaddr, size):
516
        """ Copies the data in the memory at 'memaddr' of the specified size
516
        """ Copies the data in the memory at 'memaddr' of the specified size
517
            to the boot flash at addr 'flashaddr'
517
            to the boot flash at addr 'flashaddr'
518
        """
518
        """
519
        return self.lib.monitorcommand(struct.pack("IIII", 23, memaddr, flashaddr, size), "III", (None, None, None))
519
        return self.lib.monitorcommand(struct.pack("IIII", 23, memaddr, flashaddr, size), "III", (None, None, None))
Line 521... Line 521...
521
    @command()
521
    @command()
522
    def execfirmware(self, addr):
522
    def execfirmware(self, addr):
523
        """ Executes the firmware at 'addr' and passes all control to it. """
523
        """ Executes the firmware at 'addr' and passes all control to it. """
524
        return self.lib.monitorcommand(struct.pack("IIII", 24, addr, 0, 0))
524
        return self.lib.monitorcommand(struct.pack("IIII", 24, addr, 0, 0))
525
    
525
    
526
    @command()
526
    @command(timeout = 30000)
527
    def aesencrypt(self, addr, size, keyindex):
527
    def aesencrypt(self, addr, size, keyindex):
528
        """ Encrypts the buffer at 'addr' with the specified size
528
        """ Encrypts the buffer at 'addr' with the specified size
529
            with the hardware AES key index 'keyindex'
529
            with the hardware AES key index 'keyindex'
530
        """
530
        """
531
        return self.lib.monitorcommand(struct.pack("IBBHII", 25, 1, 0, keyindex, addr, size), "III", (None, None, None))
531
        return self.lib.monitorcommand(struct.pack("IBBHII", 25, 1, 0, keyindex, addr, size), "III", (None, None, None))
532
    
532
    
533
    @command()
533
    @command(timeout = 30000)
534
    def aesdecrypt(self, addr, size, keyindex):
534
    def aesdecrypt(self, addr, size, keyindex):
535
        """ Decrypts the buffer at 'addr' with the specified size
535
        """ Decrypts the buffer at 'addr' with the specified size
536
            with the hardware AES key index 'keyindex'
536
            with the hardware AES key index 'keyindex'
537
        """
537
        """
538
        return self.lib.monitorcommand(struct.pack("IBBHII", 25, 0, 0, keyindex, addr, size), "III", (None, None, None))
538
        return self.lib.monitorcommand(struct.pack("IBBHII", 25, 0, 0, keyindex, addr, size), "III", (None, None, None))
539
    
539
    
540
    @command()
540
    @command(timeout = 30000)
541
    def hmac_sha1(self, addr, size, destination):
541
    def hmac_sha1(self, addr, size, destination):
542
        """ Generates a HMAC-SHA1 hash of the buffer and saves it to 'destination' """
542
        """ Generates a HMAC-SHA1 hash of the buffer and saves it to 'destination' """
543
        return self.lib.monitorcommand(struct.pack("IIII", 26, addr, size, destination), "III", (None, None, None))
543
        return self.lib.monitorcommand(struct.pack("IIII", 26, addr, size, destination), "III", (None, None, None))
544
 
544
 
545
    @command()
545
    @command()
Line 548... Line 548...
548
            Gathers some information about the NAND chip used
548
            Gathers some information about the NAND chip used
549
        """
549
        """
550
        if self.lib.dev.hwtypeid != 0x47324e49: raise DeviceError("Wrong device for target-specific command.")
550
        if self.lib.dev.hwtypeid != 0x47324e49: raise DeviceError("Wrong device for target-specific command.")
551
        return self.lib.monitorcommand(struct.pack("IIII", 0xffff0001, 0, 0, 0), "IHHHH", ("type", "pagesperblock", "banks", "userblocks", "blocks"))
551
        return self.lib.monitorcommand(struct.pack("IIII", 0xffff0001, 0, 0, 0), "IHHHH", ("type", "pagesperblock", "banks", "userblocks", "blocks"))
552
    
552
    
553
    @command()
553
    @command(timeout = 30000)
554
    def ipodnano2g_nandread(self, addr, start, count, doecc, checkempty):
554
    def ipodnano2g_nandread(self, addr, start, count, doecc, checkempty):
555
        """ Target-specific function: ipodnano2g
555
        """ Target-specific function: ipodnano2g
556
            Reads data from the NAND chip into memory
556
            Reads data from the NAND chip into memory
557
        """
557
        """
558
        if self.lib.dev.hwtypeid != 0x47324e49: raise DeviceError("Wrong device for target-specific command.")
558
        if self.lib.dev.hwtypeid != 0x47324e49: raise DeviceError("Wrong device for target-specific command.")
559
        return self.lib.monitorcommand(struct.pack("IIII", 0xffff0002, addr | (0x80000000 if doecc != 0 else 0) | (0x40000000 if checkempty != 0 else 0), start, count), "III", (None, None, None))
559
        return self.lib.monitorcommand(struct.pack("IIII", 0xffff0002, addr | (0x80000000 if doecc != 0 else 0) | (0x40000000 if checkempty != 0 else 0), start, count), "III", (None, None, None))
560
    
560
    
561
    @command()
561
    @command(timeout = 30000)
562
    def ipodnano2g_nandwrite(self, addr, start, count, doecc):
562
    def ipodnano2g_nandwrite(self, addr, start, count, doecc):
563
        """ Target-specific function: ipodnano2g
563
        """ Target-specific function: ipodnano2g
564
            Writes data to the NAND chip
564
            Writes data to the NAND chip
565
        """
565
        """
566
        if self.lib.dev.hwtypeid != 0x47324e49: raise DeviceError("Wrong device for target-specific command.")
566
        if self.lib.dev.hwtypeid != 0x47324e49: raise DeviceError("Wrong device for target-specific command.")
567
        return self.lib.monitorcommand(struct.pack("IIII", 0xffff0003, addr | (0x80000000 if doecc != 0 else 0), start, count), "III", (None, None, None))
567
        return self.lib.monitorcommand(struct.pack("IIII", 0xffff0003, addr | (0x80000000 if doecc != 0 else 0), start, count), "III", (None, None, None))
568
    
568
    
569
    @command()
569
    @command(timeout = 30000)
570
    def ipodnano2g_nanderase(self, addr, start, count):
570
    def ipodnano2g_nanderase(self, addr, start, count):
571
        """ Target-specific function: ipodnano2g
571
        """ Target-specific function: ipodnano2g
572
            Erases blocks on the NAND chip and stores the results to memory
572
            Erases blocks on the NAND chip and stores the results to memory
573
        """
573
        """
574
        if self.lib.dev.hwtypeid != 0x47324e49: raise DeviceError("Wrong device for target-specific command.")
574
        if self.lib.dev.hwtypeid != 0x47324e49: raise DeviceError("Wrong device for target-specific command.")
Line 580... Line 580...
580
            Gather information about the hard disk drive
580
            Gather information about the hard disk drive
581
        """
581
        """
582
        if self.lib.dev.hwtypeid != 0x4c435049: raise DeviceError("Wrong device for target-specific command.")
582
        if self.lib.dev.hwtypeid != 0x4c435049: raise DeviceError("Wrong device for target-specific command.")
583
        return self.lib.monitorcommand(struct.pack("IIII", 0xffff0001, 0, 0, 0), "IQQII", ("identifyptr", "totalsectors", "virtualsectors", "bbtptr", "bbtsize"))
583
        return self.lib.monitorcommand(struct.pack("IIII", 0xffff0001, 0, 0, 0), "IQQII", ("identifyptr", "totalsectors", "virtualsectors", "bbtptr", "bbtsize"))
584
    
584
    
585
    @command()
585
    @command(timeout = 30000)
586
    def ipodclassic_hddaccess(self, type, sector, count, addr):
586
    def ipodclassic_hddaccess(self, type, sector, count, addr):
587
        """ Target-specific function: ipodclassic
587
        """ Target-specific function: ipodclassic
588
            Access the hard disk, type = 0 (read) / 1 (write)
588
            Access the hard disk, type = 0 (read) / 1 (write)
589
        """
589
        """
590
        if self.lib.dev.hwtypeid != 0x4c435049: raise DeviceError("Wrong device for target-specific command.")
590
        if self.lib.dev.hwtypeid != 0x4c435049: raise DeviceError("Wrong device for target-specific command.")
Line 629... Line 629...
629
        result.vendor = self.readstring(result.vendorptr)
629
        result.vendor = self.readstring(result.vendorptr)
630
        result.product = self.readstring(result.productptr)
630
        result.product = self.readstring(result.productptr)
631
        result.revision = self.readstring(result.revisionptr)
631
        result.revision = self.readstring(result.revisionptr)
632
        return result
632
        return result
633
    
633
    
634
    @command()
634
    @command(timeout = 50000)
635
    def storage_read_sectors_md(self, volume, sector, count, addr):
635
    def storage_read_sectors_md(self, volume, sector, count, addr):
636
        """ Read sectors from as storage device """
636
        """ Read sectors from as storage device """
637
        result = self.lib.monitorcommand(struct.pack("IIQIIII", 28, volume, sector, count, addr, 0, 0), "III", ("rc", None, None, None))
637
        result = self.lib.monitorcommand(struct.pack("IIQIIII", 28, volume, sector, count, addr, 0, 0), "III", ("rc", None, None, None))
638
        if result.rc > 0x80000000:
638
        if result.rc > 0x80000000:
639
            raise DeviceError("storage_read_sectors_md(volume=%d, sector=%d, count=%d, addr=0x%08X) failed with RC 0x%08X" % (volume, sector, count, addr, rc))
639
            raise DeviceError("storage_read_sectors_md(volume=%d, sector=%d, count=%d, addr=0x%08X) failed with RC 0x%08X" % (volume, sector, count, addr, rc))
640
    
640
    
641
    @command()
641
    @command(timeout = 50000)
642
    def storage_write_sectors_md(self, volume, sector, count, addr):
642
    def storage_write_sectors_md(self, volume, sector, count, addr):
643
        """ Read sectors from as storage device """
643
        """ Read sectors from as storage device """
644
        result = self.lib.monitorcommand(struct.pack("IIQIIII", 29, volume, sector, count, addr, 0, 0), "III", ("rc", None, None, None))
644
        result = self.lib.monitorcommand(struct.pack("IIQIIII", 29, volume, sector, count, addr, 0, 0), "III", ("rc", None, None, None))
645
        if result.rc > 0x80000000:
645
        if result.rc > 0x80000000:
646
            raise DeviceError("storage_read_sectors_md(volume=%d, sector=%d, count=%d, addr=0x%08X) failed with RC 0x%08X" % (volume, sector, count, addr, rc))
646
            raise DeviceError("storage_read_sectors_md(volume=%d, sector=%d, count=%d, addr=0x%08X) failed with RC 0x%08X" % (volume, sector, count, addr, rc))
647
    
647
    
648
    @command()
648
    @command(timeout = 30000)
649
    def file_open(self, filename, mode):
649
    def file_open(self, filename, mode):
650
        """ Opens a file and returns the handle """
650
        """ Opens a file and returns the handle """
651
        result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(filename), 30, mode, 0, 0, filename, 0), "III", ("fd", None, None))
651
        result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(filename), 30, mode, 0, 0, filename, 0), "III", ("fd", None, None))
652
        if result.fd > 0x80000000:
652
        if result.fd > 0x80000000:
653
            raise DeviceError("file_open(filename=\"%s\", mode=0x%X) failed with RC=0x%08X, errno=%d" % (filename, mode, result.fd, self.errno()))
653
            raise DeviceError("file_open(filename=\"%s\", mode=0x%X) failed with RC=0x%08X, errno=%d" % (filename, mode, result.fd, self.errno()))
654
        return result.fd
654
        return result.fd
655
    
655
    
656
    @command()
656
    @command(timeout = 30000)
657
    def file_size(self, fd):
657
    def file_size(self, fd):
658
        """ Gets the size of a file referenced by a handle """
658
        """ Gets the size of a file referenced by a handle """
659
        result = self.lib.monitorcommand(struct.pack("IIII", 31, fd, 0, 0), "III", ("size", None, None))
659
        result = self.lib.monitorcommand(struct.pack("IIII", 31, fd, 0, 0), "III", ("size", None, None))
660
        if result.size > 0x80000000:
660
        if result.size > 0x80000000:
661
            raise DeviceError("file_size(fd=%d) failed with RC=0x%08X, errno=%d" % (fd, result.size, self.errno()))
661
            raise DeviceError("file_size(fd=%d) failed with RC=0x%08X, errno=%d" % (fd, result.size, self.errno()))
662
        return result.size
662
        return result.size
663
    
663
    
664
    @command()
664
    @command(timeout = 30000)
665
    def file_read(self, fd, addr, size):
665
    def file_read(self, fd, addr, size):
666
        """ Reads data from a file referenced by a handle """
666
        """ Reads data from a file referenced by a handle """
667
        result = self.lib.monitorcommand(struct.pack("IIII", 32, fd, addr, size), "III", ("rc", None, None))
667
        result = self.lib.monitorcommand(struct.pack("IIII", 32, fd, addr, size), "III", ("rc", None, None))
668
        if result.rc > 0x80000000:
668
        if result.rc > 0x80000000:
669
            raise DeviceError("file_read(fd=%d, addr=0x%08X, size=0x%08X) failed with RC=0x%08X, errno=%d" % (fd, addr, size, result.rc, self.errno()))
669
            raise DeviceError("file_read(fd=%d, addr=0x%08X, size=0x%08X) failed with RC=0x%08X, errno=%d" % (fd, addr, size, result.rc, self.errno()))
670
        return result.rc
670
        return result.rc
671
    
671
    
672
    @command()
672
    @command(timeout = 30000)
673
    def file_write(self, fd, addr, size):
673
    def file_write(self, fd, addr, size):
674
        """ Writes data from a file referenced by a handle """
674
        """ Writes data from a file referenced by a handle """
675
        result = self.lib.monitorcommand(struct.pack("IIII", 33, fd, addr, size), "III", ("rc", None, None))
675
        result = self.lib.monitorcommand(struct.pack("IIII", 33, fd, addr, size), "III", ("rc", None, None))
676
        if result.rc > 0x80000000:
676
        if result.rc > 0x80000000:
677
            raise DeviceError("file_write(fd=%d, addr=0x%08X, size=0x%08X) failed with RC=0x%08X, errno=%d" % (fd, addr, size, result.rc, self.errno()))
677
            raise DeviceError("file_write(fd=%d, addr=0x%08X, size=0x%08X) failed with RC=0x%08X, errno=%d" % (fd, addr, size, result.rc, self.errno()))
678
        return result.rc
678
        return result.rc
679
    
679
    
680
    @command()
680
    @command(timeout = 30000)
681
    def file_seek(self, fd, offset, whence):
681
    def file_seek(self, fd, offset, whence):
682
        """ Seeks the file handle to the specified position in the file """
682
        """ Seeks the file handle to the specified position in the file """
683
        result = self.lib.monitorcommand(struct.pack("IIII", 34, fd, offset, whence), "III", ("rc", None, None))
683
        result = self.lib.monitorcommand(struct.pack("IIII", 34, fd, offset, whence), "III", ("rc", None, None))
684
        if result.rc > 0x80000000:
684
        if result.rc > 0x80000000:
685
            raise DeviceError("file_seek(fd=%d, offset=0x%08X, whence=%d) failed with RC=0x%08X, errno=%d" % (fd, offset, whence, result.rc, self.errno()))
685
            raise DeviceError("file_seek(fd=%d, offset=0x%08X, whence=%d) failed with RC=0x%08X, errno=%d" % (fd, offset, whence, result.rc, self.errno()))
686
        return result.rc
686
        return result.rc
687
    
687
    
688
    @command()
688
    @command(timeout = 30000)
689
    def file_truncate(self, fd, length):
689
    def file_truncate(self, fd, length):
690
        """ Truncates a file referenced by a handle to a specified length """
690
        """ Truncates a file referenced by a handle to a specified length """
691
        result = self.lib.monitorcommand(struct.pack("IIII", 35, fd, offset, 0), "III", ("rc", None, None))
691
        result = self.lib.monitorcommand(struct.pack("IIII", 35, fd, offset, 0), "III", ("rc", None, None))
692
        if result.rc > 0x80000000:
692
        if result.rc > 0x80000000:
693
            raise DeviceError("file_truncate(fd=%d, length=0x%08X) failed with RC=0x%08X, errno=%d" % (fd, length, result.rc, self.errno()))
693
            raise DeviceError("file_truncate(fd=%d, length=0x%08X) failed with RC=0x%08X, errno=%d" % (fd, length, result.rc, self.errno()))
694
        return result.rc
694
        return result.rc
695
    
695
    
696
    @command()
696
    @command(timeout = 30000)
697
    def file_sync(self, fd):
697
    def file_sync(self, fd):
698
        """ Flushes a file handles' buffers """
698
        """ Flushes a file handles' buffers """
699
        result = self.lib.monitorcommand(struct.pack("IIII", 36, fd, 0, 0), "III", ("rc", None, None))
699
        result = self.lib.monitorcommand(struct.pack("IIII", 36, fd, 0, 0), "III", ("rc", None, None))
700
        if result.rc > 0x80000000:
700
        if result.rc > 0x80000000:
701
            raise DeviceError("file_sync(fd=%d) failed with RC=0x%08X, errno=%d" % (fd, result.rc, self.errno()))
701
            raise DeviceError("file_sync(fd=%d) failed with RC=0x%08X, errno=%d" % (fd, result.rc, self.errno()))
702
        return result.rc
702
        return result.rc
703
    
703
    
704
    @command()
704
    @command(timeout = 30000)
705
    def file_close(self, fd):
705
    def file_close(self, fd):
706
        """ Closes a file handle """
706
        """ Closes a file handle """
707
        result = self.lib.monitorcommand(struct.pack("IIII", 37, fd, 0, 0), "III", ("rc", None, None))
707
        result = self.lib.monitorcommand(struct.pack("IIII", 37, fd, 0, 0), "III", ("rc", None, None))
708
        if result.rc > 0x80000000:
708
        if result.rc > 0x80000000:
709
            raise DeviceError("file_close(fd=%d) failed with RC=0x%08X, errno=%d" % (fd, result.rc, self.errno()))
709
            raise DeviceError("file_close(fd=%d) failed with RC=0x%08X, errno=%d" % (fd, result.rc, self.errno()))
710
        return result.rc
710
        return result.rc
711
    
711
    
712
    @command()
712
    @command(timeout = 30000)
713
    def file_close_all(self):
713
    def file_close_all(self):
714
        """ Closes all file handles opened through the debugger """
714
        """ Closes all file handles opened through the debugger """
715
        result = self.lib.monitorcommand(struct.pack("IIII", 38, 0, 0, 0), "III", ("rc", None, None))
715
        result = self.lib.monitorcommand(struct.pack("IIII", 38, 0, 0, 0), "III", ("rc", None, None))
716
        if result.rc > 0x80000000:
716
        if result.rc > 0x80000000:
717
            raise DeviceError("file_close_all() failed with RC=0x%08X, errno=%d" % (result.rc, self.errno()))
717
            raise DeviceError("file_close_all() failed with RC=0x%08X, errno=%d" % (result.rc, self.errno()))
718
        return result.rc
718
        return result.rc
719
    
719
    
720
    @command()
720
    @command(timeout = 30000)
721
    def file_kill_all(self):
721
    def file_kill_all(self):
722
        """ Kills all file handles (in the whole system) """
722
        """ Kills all file handles (in the whole system) """
723
        result = self.lib.monitorcommand(struct.pack("IIII", 39, 0, 0, 0), "III", ("rc", None, None))
723
        result = self.lib.monitorcommand(struct.pack("IIII", 39, 0, 0, 0), "III", ("rc", None, None))
724
        if result.rc > 0x80000000:
724
        if result.rc > 0x80000000:
725
            raise DeviceError("file_kill_all() failed with RC=0x%08X, errno=%d" % (result.rc, self.errno()))
725
            raise DeviceError("file_kill_all() failed with RC=0x%08X, errno=%d" % (result.rc, self.errno()))
726
        return result.rc
726
        return result.rc
727
    
727
    
728
    @command()
728
    @command(timeout = 30000)
729
    def file_unlink(self, filename):
729
    def file_unlink(self, filename):
730
        """ Removes a file """
730
        """ Removes a file """
731
        result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(filename), 40, 0, 0, 0, filename, 0), "III", ("rc", None, None))
731
        result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(filename), 40, 0, 0, 0, filename, 0), "III", ("rc", None, None))
732
        if result.rc > 0x80000000:
732
        if result.rc > 0x80000000:
733
            raise DeviceError("file_unlink(filename=\"%s\") failed with RC=0x%08X, errno=%d" % (filename, result.rc, self.errno()))
733
            raise DeviceError("file_unlink(filename=\"%s\") failed with RC=0x%08X, errno=%d" % (filename, result.rc, self.errno()))
734
        return result.rc
734
        return result.rc
735
    
735
    
736
    @command()
736
    @command(timeout = 30000)
737
    def file_rename(self, oldname, newname):
737
    def file_rename(self, oldname, newname):
738
        """ Renames a file """
738
        """ Renames a file """
739
        result = self.lib.monitorcommand(struct.pack("IIII248s%dsB" % min(247, len(newname)), 41, 0, 0, 0, oldname, newname, 0), "III", ("rc", None, None))
739
        result = self.lib.monitorcommand(struct.pack("IIII248s%dsB" % min(247, len(newname)), 41, 0, 0, 0, oldname, newname, 0), "III", ("rc", None, None))
740
        if result.rc > 0x80000000:
740
        if result.rc > 0x80000000:
741
            raise DeviceError("file_rename(oldname=\"%s\", newname=\"%s\") failed with RC=0x%08X, errno=%d" % (oldname, newname, result.rc, self.errno()))
741
            raise DeviceError("file_rename(oldname=\"%s\", newname=\"%s\") failed with RC=0x%08X, errno=%d" % (oldname, newname, result.rc, self.errno()))
742
        return result.rc
742
        return result.rc
743
    
743
    
744
    @command()
744
    @command(timeout = 30000)
745
    def dir_open(self, dirname):
745
    def dir_open(self, dirname):
746
        """ Opens a directory and returns the handle """
746
        """ Opens a directory and returns the handle """
747
        result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(dirname), 42, 0, 0, 0, dirname, 0), "III", ("handle", None, None))
747
        result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(dirname), 42, 0, 0, 0, dirname, 0), "III", ("handle", None, None))
748
        if result.handle == 0:
748
        if result.handle == 0:
749
            raise DeviceError("dir_open(dirname=\"%s\") failed with RC=0x%08X, errno=%d" % (dirname, result.handle, self.errno()))
749
            raise DeviceError("dir_open(dirname=\"%s\") failed with RC=0x%08X, errno=%d" % (dirname, result.handle, self.errno()))
750
        return result.handle
750
        return result.handle
751
    
751
    
752
    @command()
752
    @command(timeout = 30000)
753
    def dir_read(self, handle):
753
    def dir_read(self, handle):
754
        """ Reads the next entry from a directory """
754
        """ Reads the next entry from a directory """
755
        result = self.lib.monitorcommand(struct.pack("IIII", 43, handle, 0, 0), "III", ("version", "maxpath", "ptr"))
755
        result = self.lib.monitorcommand(struct.pack("IIII", 43, handle, 0, 0), "III", ("version", "maxpath", "ptr"))
756
        if result.ptr == 0:
756
        if result.ptr == 0:
757
            raise DeviceError("dir_read(handle=0x%08X) failed with RC=0x%08X, errno=%d" % (handle, result.ptr, self.errno()))
757
            raise DeviceError("dir_read(handle=0x%08X) failed with RC=0x%08X, errno=%d" % (handle, result.ptr, self.errno()))
Line 761... Line 761...
761
        ret = Bunch()
761
        ret = Bunch()
762
        (ret.name, ret.attributes, ret.size, ret.startcluster, ret.wrtdate, ret.wrttime) = struct.unpack("%dsIIIHH" % result.maxpath, dirent)
762
        (ret.name, ret.attributes, ret.size, ret.startcluster, ret.wrtdate, ret.wrttime) = struct.unpack("%dsIIIHH" % result.maxpath, dirent)
763
        ret.name = ret.name[:ret.name.index('\x00')]
763
        ret.name = ret.name[:ret.name.index('\x00')]
764
        return ret
764
        return ret
765
    
765
    
766
    @command()
766
    @command(timeout = 30000)
767
    def dir_close(self, handle):
767
    def dir_close(self, handle):
768
        """ Closes a directory handle """
768
        """ Closes a directory handle """
769
        result = self.lib.monitorcommand(struct.pack("IIII", 44, handle, 0, 0), "III", ("rc", None, None))
769
        result = self.lib.monitorcommand(struct.pack("IIII", 44, handle, 0, 0), "III", ("rc", None, None))
770
        if result.rc > 0x80000000:
770
        if result.rc > 0x80000000:
771
            raise DeviceError("dir_close(handle=0x%08X) failed with RC=0x%08X, errno=%d" % (handle, result.rc, self.errno()))
771
            raise DeviceError("dir_close(handle=0x%08X) failed with RC=0x%08X, errno=%d" % (handle, result.rc, self.errno()))
772
        return result.rc
772
        return result.rc
773
    
773
    
774
    @command()
774
    @command(timeout = 30000)
775
    def dir_close_all(self):
775
    def dir_close_all(self):
776
        """ Closes all directory handles opened through the debugger """
776
        """ Closes all directory handles opened through the debugger """
777
        result = self.lib.monitorcommand(struct.pack("IIII", 45, 0, 0, 0), "III", ("rc", None, None))
777
        result = self.lib.monitorcommand(struct.pack("IIII", 45, 0, 0, 0), "III", ("rc", None, None))
778
        if result.rc > 0x80000000:
778
        if result.rc > 0x80000000:
779
            raise DeviceError("dir_close_all() failed with RC=0x%08X, errno=%d" % (result.rc, self.errno()))
779
            raise DeviceError("dir_close_all() failed with RC=0x%08X, errno=%d" % (result.rc, self.errno()))
780
        return result.rc
780
        return result.rc
781
    
781
    
782
    @command()
782
    @command(timeout = 30000)
783
    def dir_kill_all(self):
783
    def dir_kill_all(self):
784
        """ Kills all directory handles (in the whole system) """
784
        """ Kills all directory handles (in the whole system) """
785
        result = self.lib.monitorcommand(struct.pack("IIII", 46, 0, 0, 0), "III", ("rc", None, None))
785
        result = self.lib.monitorcommand(struct.pack("IIII", 46, 0, 0, 0), "III", ("rc", None, None))
786
        if result.rc > 0x80000000:
786
        if result.rc > 0x80000000:
787
            raise DeviceError("dir_kill_all() failed with RC=0x%08X, errno=%d" % (result.rc, self.errno()))
787
            raise DeviceError("dir_kill_all() failed with RC=0x%08X, errno=%d" % (result.rc, self.errno()))
788
        return result.rc
788
        return result.rc
789
    
789
    
790
    @command()
790
    @command(timeout = 30000)
791
    def dir_create(self, dirname):
791
    def dir_create(self, dirname):
792
        """ Creates a directory """
792
        """ Creates a directory """
793
        result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(dirname), 47, 0, 0, 0, dirname, 0), "III", ("rc", None, None))
793
        result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(dirname), 47, 0, 0, 0, dirname, 0), "III", ("rc", None, None))
794
        if result.rc > 0x80000000:
794
        if result.rc > 0x80000000:
795
            raise DeviceError("dir_create(dirname=\"%s\") failed with RC=0x%08X, errno=%d" % (dirname, result.rc, self.errno()))
795
            raise DeviceError("dir_create(dirname=\"%s\") failed with RC=0x%08X, errno=%d" % (dirname, result.rc, self.errno()))
796
        return result.rc
796
        return result.rc
797
    
797
    
798
    @command()
798
    @command(timeout = 30000)
799
    def dir_remove(self, dirname):
799
    def dir_remove(self, dirname):
800
        """ Removes an (empty) directory """
800
        """ Removes an (empty) directory """
801
        result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(dirname), 48, 0, 0, 0, dirname, 0), "III", ("rc", None, None))
801
        result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(dirname), 48, 0, 0, 0, dirname, 0), "III", ("rc", None, None))
802
        if result.rc > 0x80000000:
802
        if result.rc > 0x80000000:
803
            raise DeviceError("dir_remove(dirname=\"%s\") failed with RC=0x%08X, errno=%d" % (dirname, result.rc, self.errno()))
803
            raise DeviceError("dir_remove(dirname=\"%s\") failed with RC=0x%08X, errno=%d" % (dirname, result.rc, self.errno()))