freemyipod r395 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r394‎ | r395 | r396 >
Date:03:12, 29 December 2010
Author:farthen
Status:new
Tags:
Comment:
embios.py/libembios: Move timeouts from embios.py to libembios.py.
Modified paths:
  • /embios/trunk/tools/embios.py (modified) (history)
  • /embios/trunk/tools/libembios.py (modified) (history)

Diff [purge]

Index: embios/trunk/tools/embios.py
@@ -639,7 +639,6 @@
640640 size = self._hexint(size)
641641 self.logger.info("Dumping boot flash addresses "+self._hex(addr_flash)+" - "+
642642 hex(addr_flash+size)+" to "+self._hex(addr_mem)+" - "+self._hex(addr_mem+size)+"\n")
643 - self.embios.lib.dev.timeout = 5000
644643 self.embios.bootflashread(addr_mem, addr_flash, size)
645644
646645 @command
@@ -664,7 +663,6 @@
665664 self.logger.info(".")
666665 time.sleep(1)
667666 self.logger.info("\n")
668 - self.embios.lib.dev.timeout = 30000
669667 self.embios.bootflashwrite(addr_mem, addr_flash, size)
670668
671669 @command
@@ -694,7 +692,6 @@
695693 addr = self._hexint(addr)
696694 size = self._hexint(size)
697695 keyindex = self._hexint(keyindex)
698 - self.embios.lib.dev.timeout = 30000
699696 self.embios.aesencrypt(addr, size, keyindex)
700697
701698 @command
@@ -705,7 +702,6 @@
706703 addr = self._hexint(addr)
707704 size = self._hexint(size)
708705 keyindex = self._hexint(keyindex)
709 - self.embios.lib.dev.timeout = 30000
710706 self.embios.aesdecrypt(addr, size, keyindex)
711707
712708 @command
@@ -720,7 +716,6 @@
721717 self.logger.info("Generating hmac-sha1 hash from the buffer at " + self._hex(addr) + \
722718 " with the size " + self._hex(size) + " and saving it to " + \
723719 self._hex(destination) + " - " + self._hex(destination+sha1size) + "...")
724 - self.embios.lib.dev.timeout = 30000
725720 self.embios.hmac_sha1(addr, size, destination)
726721 self.logger.info("done\n")
727722 data = self.embios.read(destination, sha1size)
@@ -753,7 +748,6 @@
754749 checkempty = int(checkempty)
755750 self.logger.info("Reading " + self._hex(count) + " NAND pages starting at " + \
756751 self._hex(start) + " to " + self._hex(addr) + "...")
757 - self.embios.lib.dev.timeout = 30000
758752 self.embios.ipodnano2g_nandread(addr, start, count, doecc, checkempty)
759753 self.logger.info("done\n")
760754
@@ -769,7 +763,6 @@
770764 doecc = int(doecc)
771765 self.logger.info("Writing " + self._hex(count) + " NAND pages starting at " + \
772766 self._hex(start) + " from " + self._hex(addr) + "...")
773 - self.embios.lib.dev.timeout = 30000
774767 self.embios.ipodnano2g_nandwrite(addr, start, count, doecc)
775768 self.logger.info("done\n")
776769
@@ -784,7 +777,6 @@
785778 count = self._hexint(count)
786779 self.logger.info("Erasing " + self._hex(count) + " NAND blocks starting at " + \
787780 self._hex(start) + " and logging to " + self._hex(addr) + "...")
788 - self.embios.lib.dev.timeout = 30000
789781 self.embios.ipodnano2g_nanderase(addr, start, count)
790782 self.logger.info("done\n")
791783
@@ -808,7 +800,6 @@
809801 infofile.write("Number of blocks: " + str(info["blocks"]) + "\r\n")
810802 infofile.write("Number of user blocks: "+ str(info["userblocks"]) + "\r\n")
811803 infofile.write("Pages per block: " + str(info["pagesperblock"]) + "\r\n")
812 - self.embios.lib.dev.timeout = 30000
813804 for i in range(info["banks"] * info["blocks"] * info["pagesperblock"] / 8192):
814805 self.logger.info(".")
815806 self.embios.ipodnano2g_nandread(0x08000000, i * 8192, 8192, 1, 1)
@@ -841,7 +832,6 @@
842833 statusfile = open(filename, 'wb')
843834 except IOError:
844835 raise ArgumentError("Can not open file for writing!")
845 - self.embios.lib.dev.timeout = 30000
846836 for i in range(info["banks"] * info["blocks"] / 64):
847837 self.logger.info(".")
848838 self.embios.ipodnano2g_nanderase(0x08000000, i * 64, 64)
@@ -861,7 +851,6 @@
862852 f = open(filename, 'rb')
863853 except IOError:
864854 raise ArgumentError("File not readable. Does it exist?")
865 - self.embios.lib.dev.timeout = 30000
866855 self.logger.info("Writing bad block table to disk...")
867856 data = self.embios.ipodclassic_writebbt(f.read(), tempaddr)
868857 f.close()
@@ -890,7 +879,6 @@
891880 count = self._hexint(count)
892881 addr = self._hexint(addr)
893882 self.logger.info("Reading volume %s sectors %X - %X to %08X..." % (volume, sector, sector + count - 1, addr))
894 - self.embios.lib.dev.timeout = 50000
895883 self.embios.storage_read_sectors_md(volume, sector, count, addr)
896884 self.logger.info("done\n")
897885
@@ -904,7 +892,6 @@
905893 count = self._hexint(count)
906894 addr = self._hexint(addr)
907895 self.logger.info("Writing %08X to volume %s sectors %X - %X..." % (addr, volume, sector, sector + count - 1))
908 - self.embios.lib.dev.timeout = 50000
909896 self.embios.storage_write_sectors_md(volume, sector, count, addr)
910897 self.logger.info("done\n")
911898
@@ -925,7 +912,6 @@
926913 except IOError:
927914 raise ArgumentError("Could not open local file for writing.")
928915 self.logger.info("Reading volume %s sectors %X - %X to %s..." % (volume, sector, sector + count - 1, file))
929 - self.embios.lib.dev.timeout = 50000
930916 storageinfo = self.embios.storage_get_info(volume)
931917 while count > 0:
932918 sectors = min(count, int(buffsize / storageinfo.sectorsize))
@@ -953,7 +939,6 @@
954940 except IOError:
955941 raise ArgumentError("Could not open local file for reading.")
956942 self.logger.info("Writing %s to volume %s sectors %X - %X..." % (file, volume, sector, sector + count - 1))
957 - self.embios.lib.dev.timeout = 50000
958943 storageinfo = self.embios.storage_get_info(volume)
959944 while count > 0:
960945 sectors = min(count, int(buffsize / storageinfo.sectorsize))
@@ -973,7 +958,6 @@
974959 """
975960 Creates a directory
976961 """
977 - self.embios.lib.dev.timeout = 30000
978962 self.logger.info("Creating directory " + dirname + "...")
979963 self.embios.dir_create(dirname)
980964 self.logger.info(" done\n")
@@ -983,7 +967,6 @@
984968 """
985969 Removes an empty directory
986970 """
987 - self.embios.lib.dev.timeout = 30000
988971 self.logger.info("Removing directory " + dirname + "...")
989972 self.embios.dir_remove(dirname)
990973 self.logger.info(" done\n")
@@ -993,7 +976,6 @@
994977 """
995978 Removes a file
996979 """
997 - self.embios.lib.dev.timeout = 30000
998980 self.logger.info("Removing file " + filename + "...")
999981 self.embios.file_unlink(filename)
1000982 self.logger.info(" done\n")
@@ -1003,7 +985,6 @@
1004986 """
1005987 Renames or moves a file or directory
1006988 """
1007 - self.embios.lib.dev.timeout = 30000
1008989 self.logger.info("Renaming " + oldname + " to " + newname + "...")
1009990 self.embios.file_rename(oldname, newname)
1010991 self.logger.info(" done\n")
@@ -1020,7 +1001,6 @@
10211002 f = open(localname, 'wb')
10221003 except IOError:
10231004 raise ArgumentError("Could not open local file for writing.")
1024 - self.embios.lib.dev.timeout = 30000
10251005 self.logger.info("Downloading file " + remotename + " to " + localname + "...")
10261006 fd = self.embios.file_open(remotename, 0)
10271007 size = self.embios.file_size(fd)
@@ -1044,7 +1024,6 @@
10451025 f = open(localname, 'rb')
10461026 except IOError:
10471027 raise ArgumentError("Could not open local file for reading.")
1048 - self.embios.lib.dev.timeout = 30000
10491028 self.logger.info("Uploading file " + localname + " to " + remotename + "...")
10501029 fd = self.embios.file_open(remotename, 0x15)
10511030 while True:
@@ -1063,7 +1042,6 @@
10641043 """
10651044 Lists all files in the specified path
10661045 """
1067 - self.embios.lib.dev.timeout = 30000
10681046 handle = self.embios.dir_open(path)
10691047 self.logger.info("Directory listing of " + path + ":\n")
10701048 while True:
Index: embios/trunk/tools/libembios.py
@@ -504,7 +504,7 @@
505505 self.execimage(baseaddr)
506506 return Bunch(baseaddr=baseaddr, name=name)
507507
508 - @command()
 508+ @command(timeout = 5000)
509509 def bootflashread(self, memaddr, flashaddr, size):
510510 """ Copies the data in the bootflash at 'flashaddr' of the specified size
511511 to the memory at addr 'memaddr'
@@ -511,7 +511,7 @@
512512 """
513513 return self.lib.monitorcommand(struct.pack("IIII", 22, memaddr, flashaddr, size), "III", (None, None, None))
514514
515 - @command()
 515+ @command(timeout = 30000)
516516 def bootflashwrite(self, memaddr, flashaddr, size):
517517 """ Copies the data in the memory at 'memaddr' of the specified size
518518 to the boot flash at addr 'flashaddr'
@@ -523,7 +523,7 @@
524524 """ Executes the firmware at 'addr' and passes all control to it. """
525525 return self.lib.monitorcommand(struct.pack("IIII", 24, addr, 0, 0))
526526
527 - @command()
 527+ @command(timeout = 30000)
528528 def aesencrypt(self, addr, size, keyindex):
529529 """ Encrypts the buffer at 'addr' with the specified size
530530 with the hardware AES key index 'keyindex'
@@ -530,7 +530,7 @@
531531 """
532532 return self.lib.monitorcommand(struct.pack("IBBHII", 25, 1, 0, keyindex, addr, size), "III", (None, None, None))
533533
534 - @command()
 534+ @command(timeout = 30000)
535535 def aesdecrypt(self, addr, size, keyindex):
536536 """ Decrypts the buffer at 'addr' with the specified size
537537 with the hardware AES key index 'keyindex'
@@ -537,7 +537,7 @@
538538 """
539539 return self.lib.monitorcommand(struct.pack("IBBHII", 25, 0, 0, keyindex, addr, size), "III", (None, None, None))
540540
541 - @command()
 541+ @command(timeout = 30000)
542542 def hmac_sha1(self, addr, size, destination):
543543 """ Generates a HMAC-SHA1 hash of the buffer and saves it to 'destination' """
544544 return self.lib.monitorcommand(struct.pack("IIII", 26, addr, size, destination), "III", (None, None, None))
@@ -550,7 +550,7 @@
551551 if self.lib.dev.hwtypeid != 0x47324e49: raise DeviceError("Wrong device for target-specific command.")
552552 return self.lib.monitorcommand(struct.pack("IIII", 0xffff0001, 0, 0, 0), "IHHHH", ("type", "pagesperblock", "banks", "userblocks", "blocks"))
553553
554 - @command()
 554+ @command(timeout = 30000)
555555 def ipodnano2g_nandread(self, addr, start, count, doecc, checkempty):
556556 """ Target-specific function: ipodnano2g
557557 Reads data from the NAND chip into memory
@@ -558,7 +558,7 @@
559559 if self.lib.dev.hwtypeid != 0x47324e49: raise DeviceError("Wrong device for target-specific command.")
560560 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))
561561
562 - @command()
 562+ @command(timeout = 30000)
563563 def ipodnano2g_nandwrite(self, addr, start, count, doecc):
564564 """ Target-specific function: ipodnano2g
565565 Writes data to the NAND chip
@@ -566,7 +566,7 @@
567567 if self.lib.dev.hwtypeid != 0x47324e49: raise DeviceError("Wrong device for target-specific command.")
568568 return self.lib.monitorcommand(struct.pack("IIII", 0xffff0003, addr | (0x80000000 if doecc != 0 else 0), start, count), "III", (None, None, None))
569569
570 - @command()
 570+ @command(timeout = 30000)
571571 def ipodnano2g_nanderase(self, addr, start, count):
572572 """ Target-specific function: ipodnano2g
573573 Erases blocks on the NAND chip and stores the results to memory
@@ -582,7 +582,7 @@
583583 if self.lib.dev.hwtypeid != 0x4c435049: raise DeviceError("Wrong device for target-specific command.")
584584 return self.lib.monitorcommand(struct.pack("IIII", 0xffff0001, 0, 0, 0), "IQQII", ("identifyptr", "totalsectors", "virtualsectors", "bbtptr", "bbtsize"))
585585
586 - @command()
 586+ @command(timeout = 30000)
587587 def ipodclassic_hddaccess(self, type, sector, count, addr):
588588 """ Target-specific function: ipodclassic
589589 Access the hard disk, type = 0 (read) / 1 (write)
@@ -631,7 +631,7 @@
632632 result.revision = self.readstring(result.revisionptr)
633633 return result
634634
635 - @command()
 635+ @command(timeout = 50000)
636636 def storage_read_sectors_md(self, volume, sector, count, addr):
637637 """ Read sectors from as storage device """
638638 result = self.lib.monitorcommand(struct.pack("IIQIIII", 28, volume, sector, count, addr, 0, 0), "III", ("rc", None, None, None))
@@ -638,7 +638,7 @@
639639 if result.rc > 0x80000000:
640640 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))
641641
642 - @command()
 642+ @command(timeout = 50000)
643643 def storage_write_sectors_md(self, volume, sector, count, addr):
644644 """ Read sectors from as storage device """
645645 result = self.lib.monitorcommand(struct.pack("IIQIIII", 29, volume, sector, count, addr, 0, 0), "III", ("rc", None, None, None))
@@ -645,7 +645,7 @@
646646 if result.rc > 0x80000000:
647647 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))
648648
649 - @command()
 649+ @command(timeout = 30000)
650650 def file_open(self, filename, mode):
651651 """ Opens a file and returns the handle """
652652 result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(filename), 30, mode, 0, 0, filename, 0), "III", ("fd", None, None))
@@ -653,7 +653,7 @@
654654 raise DeviceError("file_open(filename=\"%s\", mode=0x%X) failed with RC=0x%08X, errno=%d" % (filename, mode, result.fd, self.errno()))
655655 return result.fd
656656
657 - @command()
 657+ @command(timeout = 30000)
658658 def file_size(self, fd):
659659 """ Gets the size of a file referenced by a handle """
660660 result = self.lib.monitorcommand(struct.pack("IIII", 31, fd, 0, 0), "III", ("size", None, None))
@@ -661,7 +661,7 @@
662662 raise DeviceError("file_size(fd=%d) failed with RC=0x%08X, errno=%d" % (fd, result.size, self.errno()))
663663 return result.size
664664
665 - @command()
 665+ @command(timeout = 30000)
666666 def file_read(self, fd, addr, size):
667667 """ Reads data from a file referenced by a handle """
668668 result = self.lib.monitorcommand(struct.pack("IIII", 32, fd, addr, size), "III", ("rc", None, None))
@@ -669,7 +669,7 @@
670670 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()))
671671 return result.rc
672672
673 - @command()
 673+ @command(timeout = 30000)
674674 def file_write(self, fd, addr, size):
675675 """ Writes data from a file referenced by a handle """
676676 result = self.lib.monitorcommand(struct.pack("IIII", 33, fd, addr, size), "III", ("rc", None, None))
@@ -677,7 +677,7 @@
678678 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()))
679679 return result.rc
680680
681 - @command()
 681+ @command(timeout = 30000)
682682 def file_seek(self, fd, offset, whence):
683683 """ Seeks the file handle to the specified position in the file """
684684 result = self.lib.monitorcommand(struct.pack("IIII", 34, fd, offset, whence), "III", ("rc", None, None))
@@ -685,7 +685,7 @@
686686 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()))
687687 return result.rc
688688
689 - @command()
 689+ @command(timeout = 30000)
690690 def file_truncate(self, fd, length):
691691 """ Truncates a file referenced by a handle to a specified length """
692692 result = self.lib.monitorcommand(struct.pack("IIII", 35, fd, offset, 0), "III", ("rc", None, None))
@@ -693,7 +693,7 @@
694694 raise DeviceError("file_truncate(fd=%d, length=0x%08X) failed with RC=0x%08X, errno=%d" % (fd, length, result.rc, self.errno()))
695695 return result.rc
696696
697 - @command()
 697+ @command(timeout = 30000)
698698 def file_sync(self, fd):
699699 """ Flushes a file handles' buffers """
700700 result = self.lib.monitorcommand(struct.pack("IIII", 36, fd, 0, 0), "III", ("rc", None, None))
@@ -701,7 +701,7 @@
702702 raise DeviceError("file_sync(fd=%d) failed with RC=0x%08X, errno=%d" % (fd, result.rc, self.errno()))
703703 return result.rc
704704
705 - @command()
 705+ @command(timeout = 30000)
706706 def file_close(self, fd):
707707 """ Closes a file handle """
708708 result = self.lib.monitorcommand(struct.pack("IIII", 37, fd, 0, 0), "III", ("rc", None, None))
@@ -709,7 +709,7 @@
710710 raise DeviceError("file_close(fd=%d) failed with RC=0x%08X, errno=%d" % (fd, result.rc, self.errno()))
711711 return result.rc
712712
713 - @command()
 713+ @command(timeout = 30000)
714714 def file_close_all(self):
715715 """ Closes all file handles opened through the debugger """
716716 result = self.lib.monitorcommand(struct.pack("IIII", 38, 0, 0, 0), "III", ("rc", None, None))
@@ -717,7 +717,7 @@
718718 raise DeviceError("file_close_all() failed with RC=0x%08X, errno=%d" % (result.rc, self.errno()))
719719 return result.rc
720720
721 - @command()
 721+ @command(timeout = 30000)
722722 def file_kill_all(self):
723723 """ Kills all file handles (in the whole system) """
724724 result = self.lib.monitorcommand(struct.pack("IIII", 39, 0, 0, 0), "III", ("rc", None, None))
@@ -725,7 +725,7 @@
726726 raise DeviceError("file_kill_all() failed with RC=0x%08X, errno=%d" % (result.rc, self.errno()))
727727 return result.rc
728728
729 - @command()
 729+ @command(timeout = 30000)
730730 def file_unlink(self, filename):
731731 """ Removes a file """
732732 result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(filename), 40, 0, 0, 0, filename, 0), "III", ("rc", None, None))
@@ -733,7 +733,7 @@
734734 raise DeviceError("file_unlink(filename=\"%s\") failed with RC=0x%08X, errno=%d" % (filename, result.rc, self.errno()))
735735 return result.rc
736736
737 - @command()
 737+ @command(timeout = 30000)
738738 def file_rename(self, oldname, newname):
739739 """ Renames a file """
740740 result = self.lib.monitorcommand(struct.pack("IIII248s%dsB" % min(247, len(newname)), 41, 0, 0, 0, oldname, newname, 0), "III", ("rc", None, None))
@@ -741,7 +741,7 @@
742742 raise DeviceError("file_rename(oldname=\"%s\", newname=\"%s\") failed with RC=0x%08X, errno=%d" % (oldname, newname, result.rc, self.errno()))
743743 return result.rc
744744
745 - @command()
 745+ @command(timeout = 30000)
746746 def dir_open(self, dirname):
747747 """ Opens a directory and returns the handle """
748748 result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(dirname), 42, 0, 0, 0, dirname, 0), "III", ("handle", None, None))
@@ -749,7 +749,7 @@
750750 raise DeviceError("dir_open(dirname=\"%s\") failed with RC=0x%08X, errno=%d" % (dirname, result.handle, self.errno()))
751751 return result.handle
752752
753 - @command()
 753+ @command(timeout = 30000)
754754 def dir_read(self, handle):
755755 """ Reads the next entry from a directory """
756756 result = self.lib.monitorcommand(struct.pack("IIII", 43, handle, 0, 0), "III", ("version", "maxpath", "ptr"))
@@ -763,7 +763,7 @@
764764 ret.name = ret.name[:ret.name.index('\x00')]
765765 return ret
766766
767 - @command()
 767+ @command(timeout = 30000)
768768 def dir_close(self, handle):
769769 """ Closes a directory handle """
770770 result = self.lib.monitorcommand(struct.pack("IIII", 44, handle, 0, 0), "III", ("rc", None, None))
@@ -771,7 +771,7 @@
772772 raise DeviceError("dir_close(handle=0x%08X) failed with RC=0x%08X, errno=%d" % (handle, result.rc, self.errno()))
773773 return result.rc
774774
775 - @command()
 775+ @command(timeout = 30000)
776776 def dir_close_all(self):
777777 """ Closes all directory handles opened through the debugger """
778778 result = self.lib.monitorcommand(struct.pack("IIII", 45, 0, 0, 0), "III", ("rc", None, None))
@@ -779,7 +779,7 @@
780780 raise DeviceError("dir_close_all() failed with RC=0x%08X, errno=%d" % (result.rc, self.errno()))
781781 return result.rc
782782
783 - @command()
 783+ @command(timeout = 30000)
784784 def dir_kill_all(self):
785785 """ Kills all directory handles (in the whole system) """
786786 result = self.lib.monitorcommand(struct.pack("IIII", 46, 0, 0, 0), "III", ("rc", None, None))
@@ -787,7 +787,7 @@
788788 raise DeviceError("dir_kill_all() failed with RC=0x%08X, errno=%d" % (result.rc, self.errno()))
789789 return result.rc
790790
791 - @command()
 791+ @command(timeout = 30000)
792792 def dir_create(self, dirname):
793793 """ Creates a directory """
794794 result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(dirname), 47, 0, 0, 0, dirname, 0), "III", ("rc", None, None))
@@ -795,7 +795,7 @@
796796 raise DeviceError("dir_create(dirname=\"%s\") failed with RC=0x%08X, errno=%d" % (dirname, result.rc, self.errno()))
797797 return result.rc
798798
799 - @command()
 799+ @command(timeout = 30000)
800800 def dir_remove(self, dirname):
801801 """ Removes an (empty) directory """
802802 result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(dirname), 48, 0, 0, 0, dirname, 0), "III", ("rc", None, None))