| Index: emcore/trunk/tools/libemcore.py |
| — | — | @@ -610,6 +610,7 @@ |
| 611 | 611 | @command()
|
| 612 | 612 | def storage_get_info(self, volume):
|
| 613 | 613 | """ Get information about a storage device """
|
| | 614 | + self.logger.debug("Getting storage information\n")
|
| 614 | 615 | result = self.lib.monitorcommand(struct.pack("IIII", 27, volume, 0, 0), "IIIIIIII", ("version", None, None, "sectorsize", "numsectors", "vendorptr", "productptr", "revisionptr"))
|
| 615 | 616 | if result.version != 1:
|
| 616 | 617 | raise ValueError("Unknown version of storage_info struct: %d" % result.version)
|
| — | — | @@ -616,12 +617,20 @@ |
| 617 | 618 | result.vendor = self.readstring(result.vendorptr)
|
| 618 | 619 | result.product = self.readstring(result.productptr)
|
| 619 | 620 | result.revision = self.readstring(result.revisionptr)
|
| | 621 | + self.logger.debug("Got storage information:\n")
|
| | 622 | + self.logger.debug("Vendor: %s\n" % result.vendor)
|
| | 623 | + self.logger.debug("Product: %s\n" % result.product)
|
| | 624 | + self.logger.debug("Revision: %s\n" % result.revision)
|
| | 625 | + self.logger.debug("Sector size: %d\n" % result.sectorsize)
|
| | 626 | + self.logger.debug("Number of sectors: %d\n" % result.numsectors)
|
| 620 | 627 | return result
|
| 621 | 628 |
|
| 622 | 629 | @command(timeout = 50000)
|
| 623 | 630 | def storage_read_sectors_md(self, volume, sector, count, addr):
|
| 624 | 631 | """ Read sectors from as storage device """
|
| | 632 | + self.logger.debug("Reading %d sectors from disk at volume %d, sector %d to memory at 0x%x\n" % (count, volume, sector, addr)
|
| 625 | 633 | result = self.lib.monitorcommand(struct.pack("IIQIIII", 28, volume, sector, count, addr, 0, 0), "III", ("rc", None, None))
|
| | 634 | + self.logger.debug("Read sectors, result: 0x%x\n" % result.rc)
|
| 626 | 635 | if result.rc > 0x80000000:
|
| 627 | 636 | 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))
|
| 628 | 637 |
|
| — | — | @@ -628,7 +637,9 @@ |
| 629 | 638 | @command(timeout = 50000)
|
| 630 | 639 | def storage_write_sectors_md(self, volume, sector, count, addr):
|
| 631 | 640 | """ Read sectors from as storage device """
|
| | 641 | + self.logger.debug("Writing %d sectors from memory at 0x%x to disk at volume %d, sector %d\n" % (count, addr, volume, sector)
|
| 632 | 642 | result = self.lib.monitorcommand(struct.pack("IIQIIII", 29, volume, sector, count, addr, 0, 0), "III", ("rc", None, None))
|
| | 643 | + self.logger.debug("Wrote sectors, result: 0x%x\n" % result.rc)
|
| 633 | 644 | if result.rc > 0x80000000:
|
| 634 | 645 | 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))
|
| 635 | 646 |
|
| — | — | @@ -635,22 +646,30 @@ |
| 636 | 647 | @command(timeout = 30000)
|
| 637 | 648 | def fat_enable_flushing(self, state):
|
| 638 | 649 | """ Enables/disables flushing the FAT cache after every transaction """
|
| | 650 | + if state != 0: self.logger.debug("Enabling FAT flushing\n")
|
| | 651 | + else: self.logger.debug("Disabling FAT flushing\n")
|
| 639 | 652 | self.lib.monitorcommand(struct.pack("IIII", 58, state, 0, 0), "III", (None, None, None))
|
| | 653 | + if state != 0: self.logger.debug("Enabled FAT flushing\n")
|
| | 654 | + else: self.logger.debug("Disabled FAT flushing\n")
|
| 640 | 655 |
|
| 641 | 656 | @command(timeout = 30000)
|
| 642 | 657 | def file_open(self, filename, mode):
|
| 643 | 658 | """ Opens a file and returns the handle """
|
| | 659 | + self.logger.debug("Opening remote file %s with mode %s\n" % (filename, mode))
|
| 644 | 660 | result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(filename), 30, mode, 0, 0, filename, 0), "III", ("fd", None, None))
|
| 645 | 661 | if result.fd > 0x80000000:
|
| 646 | 662 | raise DeviceError("file_open(filename=\"%s\", mode=0x%X) failed with RC=0x%08X, errno=%d" % (filename, mode, result.fd, self.errno()))
|
| | 663 | + self.logger.debug("Opened file as handle 0x%x\n" % result.fd)
|
| 647 | 664 | return result.fd
|
| 648 | 665 |
|
| 649 | 666 | @command(timeout = 30000)
|
| 650 | 667 | def file_size(self, fd):
|
| 651 | 668 | """ Gets the size of a file referenced by a handle """
|
| | 669 | + self.logger.debug("Getting file size of handle 0x%x\n" % fd)
|
| 652 | 670 | result = self.lib.monitorcommand(struct.pack("IIII", 31, fd, 0, 0), "III", ("size", None, None))
|
| 653 | 671 | if result.size > 0x80000000:
|
| 654 | 672 | raise DeviceError("file_size(fd=%d) failed with RC=0x%08X, errno=%d" % (fd, result.size, self.errno()))
|
| | 673 | + self.logger.debug("Got file size: %d bytes\n" % result.size)
|
| 655 | 674 | return result.size
|
| 656 | 675 |
|
| 657 | 676 | @command(timeout = 30000)
|
| — | — | @@ -661,6 +680,7 @@ |
| 662 | 681 | malloc = True
|
| 663 | 682 | else:
|
| 664 | 683 | malloc = False
|
| | 684 | + self.logger.debug("Reading %d bytes from file handle 0x%x to 0x%x\n" % (size, fd, addr))
|
| 665 | 685 | try:
|
| 666 | 686 | result = self.lib.monitorcommand(struct.pack("IIII", 32, fd, addr, size), "III", ("rc", None, None))
|
| 667 | 687 | if result.rc > 0x80000000:
|
| — | — | @@ -669,91 +689,113 @@ |
| 670 | 690 | if malloc == True:
|
| 671 | 691 | self.free(addr)
|
| 672 | 692 | raise
|
| | 693 | + self.logger.debug("File read result: 0x%x\n" % result.rc)
|
| 673 | 694 | return Bunch(rc = result.rc, addr = addr)
|
| 674 | 695 |
|
| 675 | 696 | @command(timeout = 30000)
|
| 676 | 697 | def file_write(self, fd, size, addr):
|
| 677 | 698 | """ Writes data from a file referenced by a handle. """
|
| | 699 | + self.logger.debug("Writing %d bytes from 0x%x to file handle 0x%x\n" % (size, addr, fd))
|
| 678 | 700 | result = self.lib.monitorcommand(struct.pack("IIII", 33, fd, addr, size), "III", ("rc", None, None))
|
| 679 | 701 | if result.rc > 0x80000000:
|
| 680 | 702 | 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()))
|
| | 703 | + self.logger.debug("File write result: 0x%x\n" % result.rc)
|
| 681 | 704 | return result.rc
|
| 682 | 705 |
|
| 683 | 706 | @command(timeout = 30000)
|
| 684 | 707 | def file_seek(self, fd, offset, whence):
|
| 685 | 708 | """ Seeks the file handle to the specified position in the file """
|
| | 709 | + self.logger.debug("Seeking file handle 0x%x to whence=%d, offset=0x%x\n" % (fd, whence, offset))
|
| 686 | 710 | result = self.lib.monitorcommand(struct.pack("IIII", 34, fd, offset, whence), "III", ("rc", None, None))
|
| 687 | 711 | if result.rc > 0x80000000:
|
| 688 | 712 | 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()))
|
| | 713 | + self.logger.debug("File seek result: 0x%x\n" % (result.rc))
|
| 689 | 714 | return result.rc
|
| 690 | 715 |
|
| 691 | 716 | @command(timeout = 30000)
|
| 692 | 717 | def file_truncate(self, fd, length):
|
| 693 | 718 | """ Truncates a file referenced by a handle to a specified length """
|
| | 719 | + self.logger.debug("Truncating file with handle 0x%x to 0x%x bytes\n" % (fd, length))
|
| 694 | 720 | result = self.lib.monitorcommand(struct.pack("IIII", 35, fd, offset, 0), "III", ("rc", None, None))
|
| 695 | 721 | if result.rc > 0x80000000:
|
| 696 | 722 | raise DeviceError("file_truncate(fd=%d, length=0x%08X) failed with RC=0x%08X, errno=%d" % (fd, length, result.rc, self.errno()))
|
| | 723 | + self.logger.debug("File truncate result: 0x%x\n" % (result.rc))
|
| 697 | 724 | return result.rc
|
| 698 | 725 |
|
| 699 | 726 | @command(timeout = 30000)
|
| 700 | 727 | def file_sync(self, fd):
|
| 701 | 728 | """ Flushes a file handles' buffers """
|
| | 729 | + self.logger.debug("Flushing buffers of file with handle 0x%x\n" % (fd))
|
| 702 | 730 | result = self.lib.monitorcommand(struct.pack("IIII", 36, fd, 0, 0), "III", ("rc", None, None))
|
| 703 | 731 | if result.rc > 0x80000000:
|
| 704 | 732 | raise DeviceError("file_sync(fd=%d) failed with RC=0x%08X, errno=%d" % (fd, result.rc, self.errno()))
|
| | 733 | + self.logger.debug("File flush result: 0x%x\n" % (result.rc))
|
| 705 | 734 | return result.rc
|
| 706 | 735 |
|
| 707 | 736 | @command(timeout = 30000)
|
| 708 | 737 | def file_close(self, fd):
|
| 709 | 738 | """ Closes a file handle """
|
| | 739 | + self.logger.debug("Closing file handle 0x%x\n" % (fd))
|
| 710 | 740 | result = self.lib.monitorcommand(struct.pack("IIII", 37, fd, 0, 0), "III", ("rc", None, None))
|
| 711 | 741 | if result.rc > 0x80000000:
|
| 712 | 742 | raise DeviceError("file_close(fd=%d) failed with RC=0x%08X, errno=%d" % (fd, result.rc, self.errno()))
|
| | 743 | + self.logger.debug("File close result: 0x%x\n" % (result.rc))
|
| 713 | 744 | return result.rc
|
| 714 | 745 |
|
| 715 | 746 | @command(timeout = 30000)
|
| 716 | 747 | def file_close_all(self):
|
| 717 | 748 | """ Closes all file handles opened through the debugger """
|
| | 749 | + self.logger.debug("Closing all files that were opened via USB\n")
|
| 718 | 750 | result = self.lib.monitorcommand(struct.pack("IIII", 38, 0, 0, 0), "III", ("rc", None, None))
|
| 719 | 751 | if result.rc > 0x80000000:
|
| 720 | 752 | raise DeviceError("file_close_all() failed with RC=0x%08X, errno=%d" % (result.rc, self.errno()))
|
| | 753 | + self.logger.debug("Closed %d files\n" % (result.rc))
|
| 721 | 754 | return result.rc
|
| 722 | 755 |
|
| 723 | 756 | @command(timeout = 30000)
|
| 724 | | - def file_kill_all(self):
|
| 725 | | - """ Kills all file handles (in the whole system) """
|
| 726 | | - result = self.lib.monitorcommand(struct.pack("IIII", 39, 0, 0, 0), "III", ("rc", None, None))
|
| | 757 | + def file_kill_all(self, volume):
|
| | 758 | + """ Kills all file handles of a volume (in the whole system) """
|
| | 759 | + self.logger.debug("Killing all file handles of volume %d\n" % (volume))
|
| | 760 | + result = self.lib.monitorcommand(struct.pack("IIII", 39, volume, 0, 0), "III", ("rc", None, None))
|
| 727 | 761 | if result.rc > 0x80000000:
|
| 728 | 762 | raise DeviceError("file_kill_all() failed with RC=0x%08X, errno=%d" % (result.rc, self.errno()))
|
| | 763 | + self.logger.debug("Closed %d files\n" % (result.rc))
|
| 729 | 764 | return result.rc
|
| 730 | 765 |
|
| 731 | 766 | @command(timeout = 30000)
|
| 732 | 767 | def file_unlink(self, filename):
|
| 733 | 768 | """ Removes a file """
|
| | 769 | + self.logger.debug("Deleting file %s\n" % (filename))
|
| 734 | 770 | result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(filename), 40, 0, 0, 0, filename, 0), "III", ("rc", None, None))
|
| 735 | 771 | if result.rc > 0x80000000:
|
| 736 | 772 | raise DeviceError("file_unlink(filename=\"%s\") failed with RC=0x%08X, errno=%d" % (filename, result.rc, self.errno()))
|
| | 773 | + self.logger.debug("Delete file result: 0x%x\n" % (result.rc))
|
| 737 | 774 | return result.rc
|
| 738 | 775 |
|
| 739 | 776 | @command(timeout = 30000)
|
| 740 | 777 | def file_rename(self, oldname, newname):
|
| 741 | 778 | """ Renames a file """
|
| | 779 | + self.logger.debug("Renaming file %s to %s\n" % (oldname, newname))
|
| 742 | 780 | result = self.lib.monitorcommand(struct.pack("IIII248s%dsB" % min(247, len(newname)), 41, 0, 0, 0, oldname, newname, 0), "III", ("rc", None, None))
|
| 743 | 781 | if result.rc > 0x80000000:
|
| 744 | 782 | raise DeviceError("file_rename(oldname=\"%s\", newname=\"%s\") failed with RC=0x%08X, errno=%d" % (oldname, newname, result.rc, self.errno()))
|
| | 783 | + self.logger.debug("Rename file result: 0x%x\n" % (result.rc))
|
| 745 | 784 | return result.rc
|
| 746 | 785 |
|
| 747 | 786 | @command(timeout = 30000)
|
| 748 | 787 | def dir_open(self, dirname):
|
| 749 | 788 | """ Opens a directory and returns the handle """
|
| | 789 | + self.logger.debug("Opening directory %s\n" % (dirname))
|
| 750 | 790 | result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(dirname), 42, 0, 0, 0, dirname, 0), "III", ("handle", None, None))
|
| 751 | 791 | if result.handle == 0:
|
| 752 | 792 | raise DeviceError("dir_open(dirname=\"%s\") failed with RC=0x%08X, errno=%d" % (dirname, result.handle, self.errno()))
|
| | 793 | + self.logger.debug("Opened directory as handle 0x%x\n" % (result.handle))
|
| 753 | 794 | return result.handle
|
| 754 | 795 |
|
| 755 | 796 | @command(timeout = 30000)
|
| 756 | 797 | def dir_read(self, handle):
|
| 757 | 798 | """ Reads the next entry from a directory """
|
| | 799 | + self.logger.debug("Reading next entry of directory handle 0x%x\n" % (handle))
|
| 758 | 800 | result = self.lib.monitorcommand(struct.pack("IIII", 43, handle, 0, 0), "III", ("version", "maxpath", "ptr"))
|
| 759 | 801 | if result.ptr == 0:
|
| 760 | 802 | raise DeviceError("dir_read(handle=0x%08X) failed with RC=0x%08X, errno=%d" % (handle, result.ptr, self.errno()))
|
| — | — | @@ -763,68 +805,91 @@ |
| 764 | 806 | ret = Bunch()
|
| 765 | 807 | (ret.name, ret.attributes, ret.size, ret.startcluster, ret.wrtdate, ret.wrttime) = struct.unpack("%dsIIIHH" % result.maxpath, dirent)
|
| 766 | 808 | ret.name = ret.name[:ret.name.index('\x00')]
|
| | 809 | + self.logger.debug("Read directory entry:\n")
|
| | 810 | + self.logger.debug("Name: %s\n" % ret.name)
|
| | 811 | + self.logger.debug("Attributes: 0x%x\n" % ret.attributes)
|
| | 812 | + self.logger.debug("Size: %d\n" % ret.size)
|
| | 813 | + self.logger.debug("Start cluster: %d\n" % ret.startcluster)
|
| | 814 | + self.logger.debug("Last written date: 0x%x\n" % ret.wrtdate)
|
| | 815 | + self.logger.debug("Last written time: 0x%x\n" % ret.wrttime)
|
| 767 | 816 | return ret
|
| 768 | 817 |
|
| 769 | 818 | @command(timeout = 30000)
|
| 770 | 819 | def dir_close(self, handle):
|
| 771 | 820 | """ Closes a directory handle """
|
| | 821 | + self.logger.debug("Closing directory handle 0x%x\n" % (handle))
|
| 772 | 822 | result = self.lib.monitorcommand(struct.pack("IIII", 44, handle, 0, 0), "III", ("rc", None, None))
|
| 773 | 823 | if result.rc > 0x80000000:
|
| 774 | 824 | raise DeviceError("dir_close(handle=0x%08X) failed with RC=0x%08X, errno=%d" % (handle, result.rc, self.errno()))
|
| | 825 | + self.logger.debug("Close directory result: 0x%x\n" % (result.rc))
|
| 775 | 826 | return result.rc
|
| 776 | 827 |
|
| 777 | 828 | @command(timeout = 30000)
|
| 778 | 829 | def dir_close_all(self):
|
| 779 | 830 | """ Closes all directory handles opened through the debugger """
|
| | 831 | + self.logger.debug("Closing all directories that were opened via USB\n")
|
| 780 | 832 | result = self.lib.monitorcommand(struct.pack("IIII", 45, 0, 0, 0), "III", ("rc", None, None))
|
| 781 | 833 | if result.rc > 0x80000000:
|
| 782 | 834 | raise DeviceError("dir_close_all() failed with RC=0x%08X, errno=%d" % (result.rc, self.errno()))
|
| | 835 | + self.logger.debug("Closed %d directories\n" % (result.rc))
|
| 783 | 836 | return result.rc
|
| 784 | 837 |
|
| 785 | 838 | @command(timeout = 30000)
|
| 786 | | - def dir_kill_all(self):
|
| 787 | | - """ Kills all directory handles (in the whole system) """
|
| 788 | | - result = self.lib.monitorcommand(struct.pack("IIII", 46, 0, 0, 0), "III", ("rc", None, None))
|
| | 839 | + def dir_kill_all(self, volume):
|
| | 840 | + """ Kills all directory handles of a volume (in the whole system) """
|
| | 841 | + self.logger.debug("Closing all directories of volume %d\n" % (volume))
|
| | 842 | + result = self.lib.monitorcommand(struct.pack("IIII", 46, volume, 0, 0), "III", ("rc", None, None))
|
| 789 | 843 | if result.rc > 0x80000000:
|
| 790 | 844 | raise DeviceError("dir_kill_all() failed with RC=0x%08X, errno=%d" % (result.rc, self.errno()))
|
| | 845 | + self.logger.debug("Closed %d directories\n" % (result.rc))
|
| 791 | 846 | return result.rc
|
| 792 | 847 |
|
| 793 | 848 | @command(timeout = 30000)
|
| 794 | 849 | def dir_create(self, dirname):
|
| 795 | 850 | """ Creates a directory """
|
| | 851 | + self.logger.debug("Creating directory %s\n" % (dirname))
|
| 796 | 852 | result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(dirname), 47, 0, 0, 0, dirname, 0), "III", ("rc", None, None))
|
| 797 | 853 | if result.rc > 0x80000000:
|
| 798 | 854 | raise DeviceError("dir_create(dirname=\"%s\") failed with RC=0x%08X, errno=%d" % (dirname, result.rc, self.errno()))
|
| | 855 | + self.logger.debug("Create directory result: 0x%x\n" % (result.rc))
|
| 799 | 856 | return result.rc
|
| 800 | 857 |
|
| 801 | 858 | @command(timeout = 30000)
|
| 802 | 859 | def dir_remove(self, dirname):
|
| 803 | 860 | """ Removes an (empty) directory """
|
| | 861 | + self.logger.debug("Removing directory %s\n" % (dirname))
|
| 804 | 862 | result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(dirname), 48, 0, 0, 0, dirname, 0), "III", ("rc", None, None))
|
| 805 | 863 | if result.rc > 0x80000000:
|
| 806 | 864 | raise DeviceError("dir_remove(dirname=\"%s\") failed with RC=0x%08X, errno=%d" % (dirname, result.rc, self.errno()))
|
| | 865 | + self.logger.debug("Remove directory result: 0x%x\n" % (result.rc))
|
| 807 | 866 | return result.rc
|
| 808 | 867 |
|
| 809 | 868 | @command()
|
| 810 | 869 | def errno(self):
|
| 811 | 870 | """ Returns the number of the last error that happened """
|
| | 871 | + self.logger.debug("Getting last error number\n")
|
| 812 | 872 | result = self.lib.monitorcommand(struct.pack("IIII", 49, 0, 0, 0), "III", ("errno", None, None))
|
| | 873 | + self.logger.debug("Last error: 0x%x\n" % (result.errno))
|
| 813 | 874 | return result.errno
|
| 814 | 875 |
|
| 815 | 876 | @command()
|
| 816 | 877 | def disk_mount(self, volume):
|
| 817 | 878 | """ Mounts a volume """
|
| | 879 | + self.logger.debug("Mounting volume %d\n" % (volume))
|
| 818 | 880 | result = self.lib.monitorcommand(struct.pack("IIII", 50, volume, 0, 0), "III", ("rc", None, None))
|
| 819 | 881 | if result.rc > 0x80000000:
|
| 820 | 882 | raise DeviceError("disk_mount(volume=%d) failed with RC=0x%08X, errno=%d" % (volume, result.rc, self.errno()))
|
| | 883 | + self.logger.debug("Mount volume result: 0x%x\n" % (result.rc))
|
| 821 | 884 | return result.rc
|
| 822 | 885 |
|
| 823 | 886 | @command()
|
| 824 | 887 | def disk_unmount(self, volume):
|
| 825 | 888 | """ Unmounts a volume """
|
| | 889 | + self.logger.debug("Unmounting volume %d\n" % (volume))
|
| 826 | 890 | result = self.lib.monitorcommand(struct.pack("IIII", 51, volume, 0, 0), "III", ("rc", None, None))
|
| 827 | 891 | if result.rc > 0x80000000:
|
| 828 | 892 | raise DeviceError("disk_unmount(volume=%d) failed with RC=0x%08X, errno=%d" % (volume, result.rc, self.errno()))
|
| | 893 | + self.logger.debug("Unmount volume result: 0x%x\n" % (result.rc))
|
| 829 | 894 | return result.rc
|
| 830 | 895 |
|
| 831 | 896 | @command()
|