Subversion Repositories freemyipod

Rev

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

Rev 392 Rev 395
Line 637... Line 637...
637
        addr_flash = self._hexint(addr_flash)
637
        addr_flash = self._hexint(addr_flash)
638
        addr_mem = self._hexint(addr_mem)
638
        addr_mem = self._hexint(addr_mem)
639
        size = self._hexint(size)
639
        size = self._hexint(size)
640
        self.logger.info("Dumping boot flash addresses "+self._hex(addr_flash)+" - "+
640
        self.logger.info("Dumping boot flash addresses "+self._hex(addr_flash)+" - "+
641
                         hex(addr_flash+size)+" to "+self._hex(addr_mem)+" - "+self._hex(addr_mem+size)+"\n")
641
                         hex(addr_flash+size)+" to "+self._hex(addr_mem)+" - "+self._hex(addr_mem+size)+"\n")
642
        self.embios.lib.dev.timeout = 5000
-
 
643
        self.embios.bootflashread(addr_mem, addr_flash, size)
642
        self.embios.bootflashread(addr_mem, addr_flash, size)
644
    
643
    
645
    @command
644
    @command
646
    def writebootflash(self, addr_flash, addr_mem, size, force=False):
645
    def writebootflash(self, addr_flash, addr_mem, size, force=False):
647
        """
646
        """
Line 662... Line 661...
662
            self.logger.warn("If this was not what you intended press Ctrl-C NOW")
661
            self.logger.warn("If this was not what you intended press Ctrl-C NOW")
663
            for i in range(10):
662
            for i in range(10):
664
                self.logger.info(".")
663
                self.logger.info(".")
665
                time.sleep(1)
664
                time.sleep(1)
666
            self.logger.info("\n")
665
            self.logger.info("\n")
667
        self.embios.lib.dev.timeout = 30000
-
 
668
        self.embios.bootflashwrite(addr_mem, addr_flash, size)
666
        self.embios.bootflashwrite(addr_mem, addr_flash, size)
669
    
667
    
670
    @command
668
    @command
671
    def runfirmware(self, addr, filename):
669
    def runfirmware(self, addr, filename):
672
        """
670
        """
Line 692... Line 690...
692
            Encrypts a buffer using a hardware key
690
            Encrypts a buffer using a hardware key
693
        """
691
        """
694
        addr = self._hexint(addr)
692
        addr = self._hexint(addr)
695
        size = self._hexint(size)
693
        size = self._hexint(size)
696
        keyindex = self._hexint(keyindex)
694
        keyindex = self._hexint(keyindex)
697
        self.embios.lib.dev.timeout = 30000
-
 
698
        self.embios.aesencrypt(addr, size, keyindex)
695
        self.embios.aesencrypt(addr, size, keyindex)
699
    
696
    
700
    @command
697
    @command
701
    def aesdecrypt(self, addr, size, keyindex):
698
    def aesdecrypt(self, addr, size, keyindex):
702
        """
699
        """
703
            Decrypts a buffer using a hardware key
700
            Decrypts a buffer using a hardware key
704
        """
701
        """
705
        addr = self._hexint(addr)
702
        addr = self._hexint(addr)
706
        size = self._hexint(size)
703
        size = self._hexint(size)
707
        keyindex = self._hexint(keyindex)
704
        keyindex = self._hexint(keyindex)
708
        self.embios.lib.dev.timeout = 30000
-
 
709
        self.embios.aesdecrypt(addr, size, keyindex)
705
        self.embios.aesdecrypt(addr, size, keyindex)
710
    
706
    
711
    @command
707
    @command
712
    def hmac_sha1(self, addr, size, destination):
708
    def hmac_sha1(self, addr, size, destination):
713
        """
709
        """
Line 718... Line 714...
718
        destination = self._hexint(destination)
714
        destination = self._hexint(destination)
719
        sha1size = 0x14
715
        sha1size = 0x14
720
        self.logger.info("Generating hmac-sha1 hash from the buffer at " + self._hex(addr) + \
716
        self.logger.info("Generating hmac-sha1 hash from the buffer at " + self._hex(addr) + \
721
                         " with the size " + self._hex(size) + " and saving it to " + \
717
                         " with the size " + self._hex(size) + " and saving it to " + \
722
                         self._hex(destination) + " - " + self._hex(destination+sha1size) + "...")
718
                         self._hex(destination) + " - " + self._hex(destination+sha1size) + "...")
723
        self.embios.lib.dev.timeout = 30000
-
 
724
        self.embios.hmac_sha1(addr, size, destination)
719
        self.embios.hmac_sha1(addr, size, destination)
725
        self.logger.info("done\n")
720
        self.logger.info("done\n")
726
        data = self.embios.read(destination, sha1size)
721
        data = self.embios.read(destination, sha1size)
727
        hash = ord(data)
722
        hash = ord(data)
728
        self.logger.info("The generated hash is "+self._hex(hash))
723
        self.logger.info("The generated hash is "+self._hex(hash))
Line 751... Line 746...
751
        count = self._hexint(count)
746
        count = self._hexint(count)
752
        doecc = int(doecc)
747
        doecc = int(doecc)
753
        checkempty = int(checkempty)
748
        checkempty = int(checkempty)
754
        self.logger.info("Reading " + self._hex(count) + " NAND pages starting at " + \
749
        self.logger.info("Reading " + self._hex(count) + " NAND pages starting at " + \
755
                         self._hex(start) + " to " + self._hex(addr) + "...")
750
                         self._hex(start) + " to " + self._hex(addr) + "...")
756
        self.embios.lib.dev.timeout = 30000
-
 
757
        self.embios.ipodnano2g_nandread(addr, start, count, doecc, checkempty)
751
        self.embios.ipodnano2g_nandread(addr, start, count, doecc, checkempty)
758
        self.logger.info("done\n")
752
        self.logger.info("done\n")
759
 
753
 
760
    @command
754
    @command
761
    def ipodnano2g_nandwrite(self, addr, start, count, doecc):
755
    def ipodnano2g_nandwrite(self, addr, start, count, doecc):
Line 767... Line 761...
767
        start = self._hexint(start)
761
        start = self._hexint(start)
768
        count = self._hexint(count)
762
        count = self._hexint(count)
769
        doecc = int(doecc)
763
        doecc = int(doecc)
770
        self.logger.info("Writing " + self._hex(count) + " NAND pages starting at " + \
764
        self.logger.info("Writing " + self._hex(count) + " NAND pages starting at " + \
771
                         self._hex(start) + " from " + self._hex(addr) + "...")
765
                         self._hex(start) + " from " + self._hex(addr) + "...")
772
        self.embios.lib.dev.timeout = 30000
-
 
773
        self.embios.ipodnano2g_nandwrite(addr, start, count, doecc)
766
        self.embios.ipodnano2g_nandwrite(addr, start, count, doecc)
774
        self.logger.info("done\n")
767
        self.logger.info("done\n")
775
 
768
 
776
    @command
769
    @command
777
    def ipodnano2g_nanderase(self, addr, start, count):
770
    def ipodnano2g_nanderase(self, addr, start, count):
Line 782... Line 775...
782
        addr = self._hexint(addr)
775
        addr = self._hexint(addr)
783
        start = self._hexint(start)
776
        start = self._hexint(start)
784
        count = self._hexint(count)
777
        count = self._hexint(count)
785
        self.logger.info("Erasing " + self._hex(count) + " NAND blocks starting at " + \
778
        self.logger.info("Erasing " + self._hex(count) + " NAND blocks starting at " + \
786
                         self._hex(start) + " and logging to " + self._hex(addr) + "...")
779
                         self._hex(start) + " and logging to " + self._hex(addr) + "...")
787
        self.embios.lib.dev.timeout = 30000
-
 
788
        self.embios.ipodnano2g_nanderase(addr, start, count)
780
        self.embios.ipodnano2g_nanderase(addr, start, count)
789
        self.logger.info("done\n")
781
        self.logger.info("done\n")
790
 
782
 
791
    @command
783
    @command
792
    def ipodnano2g_dumpnand(self, filenameprefix):
784
    def ipodnano2g_dumpnand(self, filenameprefix):
Line 806... Line 798...
806
        infofile.write("NAND chip type: "       + self._hex(info["type"]) + "\r\n")
798
        infofile.write("NAND chip type: "       + self._hex(info["type"]) + "\r\n")
807
        infofile.write("Number of banks: "      + str(info["banks"]) + "\r\n")
799
        infofile.write("Number of banks: "      + str(info["banks"]) + "\r\n")
808
        infofile.write("Number of blocks: "     + str(info["blocks"]) + "\r\n")
800
        infofile.write("Number of blocks: "     + str(info["blocks"]) + "\r\n")
809
        infofile.write("Number of user blocks: "+ str(info["userblocks"]) + "\r\n")
801
        infofile.write("Number of user blocks: "+ str(info["userblocks"]) + "\r\n")
810
        infofile.write("Pages per block: "      + str(info["pagesperblock"]) + "\r\n")
802
        infofile.write("Pages per block: "      + str(info["pagesperblock"]) + "\r\n")
811
        self.embios.lib.dev.timeout = 30000
-
 
812
        for i in range(info["banks"] * info["blocks"] * info["pagesperblock"] / 8192):
803
        for i in range(info["banks"] * info["blocks"] * info["pagesperblock"] / 8192):
813
            self.logger.info(".")
804
            self.logger.info(".")
814
            self.embios.ipodnano2g_nandread(0x08000000, i * 8192, 8192, 1, 1)
805
            self.embios.ipodnano2g_nandread(0x08000000, i * 8192, 8192, 1, 1)
815
            datafile.write(self.embios.read(0x08000000, 0x01000000))
806
            datafile.write(self.embios.read(0x08000000, 0x01000000))
816
            sparefile.write(self.embios.read(0x09000000, 0x00080000))
807
            sparefile.write(self.embios.read(0x09000000, 0x00080000))
Line 839... Line 830...
839
        self.logger.info("Wiping NAND contents...")
830
        self.logger.info("Wiping NAND contents...")
840
        try:
831
        try:
841
            statusfile = open(filename, 'wb')
832
            statusfile = open(filename, 'wb')
842
        except IOError:
833
        except IOError:
843
            raise ArgumentError("Can not open file for writing!")
834
            raise ArgumentError("Can not open file for writing!")
844
        self.embios.lib.dev.timeout = 30000
-
 
845
        for i in range(info["banks"] * info["blocks"] / 64):
835
        for i in range(info["banks"] * info["blocks"] / 64):
846
            self.logger.info(".")
836
            self.logger.info(".")
847
            self.embios.ipodnano2g_nanderase(0x08000000, i * 64, 64)
837
            self.embios.ipodnano2g_nanderase(0x08000000, i * 64, 64)
848
            statusfile.write(self.embios.read(0x08000000, 0x00000100))
838
            statusfile.write(self.embios.read(0x08000000, 0x00000100))
849
        statusfile.close()
839
        statusfile.close()
Line 859... Line 849...
859
        tempaddr = self._hexint(tempaddr)
849
        tempaddr = self._hexint(tempaddr)
860
        try:
850
        try:
861
            f = open(filename, 'rb')
851
            f = open(filename, 'rb')
862
        except IOError:
852
        except IOError:
863
            raise ArgumentError("File not readable. Does it exist?")
853
            raise ArgumentError("File not readable. Does it exist?")
864
        self.embios.lib.dev.timeout = 30000
-
 
865
        self.logger.info("Writing bad block table to disk...")
854
        self.logger.info("Writing bad block table to disk...")
866
        data = self.embios.ipodclassic_writebbt(f.read(), tempaddr)
855
        data = self.embios.ipodclassic_writebbt(f.read(), tempaddr)
867
        f.close()
856
        f.close()
868
        self.logger.info(" done\n")
857
        self.logger.info(" done\n")
869
 
858
 
Line 888... Line 877...
888
        volume = self._hexint(volume)
877
        volume = self._hexint(volume)
889
        sector = self._hexint(sector)
878
        sector = self._hexint(sector)
890
        count = self._hexint(count)
879
        count = self._hexint(count)
891
        addr = self._hexint(addr)
880
        addr = self._hexint(addr)
892
        self.logger.info("Reading volume %s sectors %X - %X to %08X..." % (volume, sector, sector + count - 1, addr))
881
        self.logger.info("Reading volume %s sectors %X - %X to %08X..." % (volume, sector, sector + count - 1, addr))
893
        self.embios.lib.dev.timeout = 50000
-
 
894
        self.embios.storage_read_sectors_md(volume, sector, count, addr)
882
        self.embios.storage_read_sectors_md(volume, sector, count, addr)
895
        self.logger.info("done\n")
883
        self.logger.info("done\n")
896
 
884
 
897
    @command
885
    @command
898
    def writerawstorage(self, volume, sector, count, addr):
886
    def writerawstorage(self, volume, sector, count, addr):
Line 902... Line 890...
902
        volume = self._hexint(volume)
890
        volume = self._hexint(volume)
903
        sector = self._hexint(sector)
891
        sector = self._hexint(sector)
904
        count = self._hexint(count)
892
        count = self._hexint(count)
905
        addr = self._hexint(addr)
893
        addr = self._hexint(addr)
906
        self.logger.info("Writing %08X to volume %s sectors %X - %X..." % (addr, volume, sector, sector + count - 1))
894
        self.logger.info("Writing %08X to volume %s sectors %X - %X..." % (addr, volume, sector, sector + count - 1))
907
        self.embios.lib.dev.timeout = 50000
-
 
908
        self.embios.storage_write_sectors_md(volume, sector, count, addr)
895
        self.embios.storage_write_sectors_md(volume, sector, count, addr)
909
        self.logger.info("done\n")
896
        self.logger.info("done\n")
910
 
897
 
911
    @command
898
    @command
912
    def readrawstoragefile(self, volume, sector, count, file, buffer = False, buffsize = "100000"):
899
    def readrawstoragefile(self, volume, sector, count, file, buffer = False, buffsize = "100000"):
Line 923... Line 910...
923
        try:
910
        try:
924
            f = open(file, 'wb')
911
            f = open(file, 'wb')
925
        except IOError:
912
        except IOError:
926
            raise ArgumentError("Could not open local file for writing.")
913
            raise ArgumentError("Could not open local file for writing.")
927
        self.logger.info("Reading volume %s sectors %X - %X to %s..." % (volume, sector, sector + count - 1, file))
914
        self.logger.info("Reading volume %s sectors %X - %X to %s..." % (volume, sector, sector + count - 1, file))
928
        self.embios.lib.dev.timeout = 50000
-
 
929
        storageinfo = self.embios.storage_get_info(volume)
915
        storageinfo = self.embios.storage_get_info(volume)
930
        while count > 0:
916
        while count > 0:
931
            sectors = min(count, int(buffsize / storageinfo.sectorsize))
917
            sectors = min(count, int(buffsize / storageinfo.sectorsize))
932
            self.embios.storage_read_sectors_md(volume, sector, sectors, buffer)
918
            self.embios.storage_read_sectors_md(volume, sector, sectors, buffer)
933
            f.write(self.embios.read(buffer, storageinfo.sectorsize * sectors))
919
            f.write(self.embios.read(buffer, storageinfo.sectorsize * sectors))
Line 951... Line 937...
951
        try:
937
        try:
952
            f = open(file, 'rb')
938
            f = open(file, 'rb')
953
        except IOError:
939
        except IOError:
954
            raise ArgumentError("Could not open local file for reading.")
940
            raise ArgumentError("Could not open local file for reading.")
955
        self.logger.info("Writing %s to volume %s sectors %X - %X..." % (file, volume, sector, sector + count - 1))
941
        self.logger.info("Writing %s to volume %s sectors %X - %X..." % (file, volume, sector, sector + count - 1))
956
        self.embios.lib.dev.timeout = 50000
-
 
957
        storageinfo = self.embios.storage_get_info(volume)
942
        storageinfo = self.embios.storage_get_info(volume)
958
        while count > 0:
943
        while count > 0:
959
            sectors = min(count, int(buffsize / storageinfo.sectorsize))
944
            sectors = min(count, int(buffsize / storageinfo.sectorsize))
960
            bytes = storageinfo.sectorsize * sectors
945
            bytes = storageinfo.sectorsize * sectors
961
            data = f.read(bytes)
946
            data = f.read(bytes)
Line 971... Line 956...
971
    @command
956
    @command
972
    def mkdir(self, dirname):
957
    def mkdir(self, dirname):
973
        """
958
        """
974
            Creates a directory
959
            Creates a directory
975
        """
960
        """
976
        self.embios.lib.dev.timeout = 30000
-
 
977
        self.logger.info("Creating directory " + dirname + "...")
961
        self.logger.info("Creating directory " + dirname + "...")
978
        self.embios.dir_create(dirname)
962
        self.embios.dir_create(dirname)
979
        self.logger.info(" done\n")
963
        self.logger.info(" done\n")
980
 
964
 
981
    @command
965
    @command
982
    def rmdir(self, dirname):
966
    def rmdir(self, dirname):
983
        """
967
        """
984
            Removes an empty directory
968
            Removes an empty directory
985
        """
969
        """
986
        self.embios.lib.dev.timeout = 30000
-
 
987
        self.logger.info("Removing directory " + dirname + "...")
970
        self.logger.info("Removing directory " + dirname + "...")
988
        self.embios.dir_remove(dirname)
971
        self.embios.dir_remove(dirname)
989
        self.logger.info(" done\n")
972
        self.logger.info(" done\n")
990
 
973
 
991
    @command
974
    @command
992
    def rm(self, filename):
975
    def rm(self, filename):
993
        """
976
        """
994
            Removes a file
977
            Removes a file
995
        """
978
        """
996
        self.embios.lib.dev.timeout = 30000
-
 
997
        self.logger.info("Removing file " + filename + "...")
979
        self.logger.info("Removing file " + filename + "...")
998
        self.embios.file_unlink(filename)
980
        self.embios.file_unlink(filename)
999
        self.logger.info(" done\n")
981
        self.logger.info(" done\n")
1000
 
982
 
1001
    @command
983
    @command
1002
    def mv(self, oldname, newname):
984
    def mv(self, oldname, newname):
1003
        """
985
        """
1004
            Renames or moves a file or directory
986
            Renames or moves a file or directory
1005
        """
987
        """
1006
        self.embios.lib.dev.timeout = 30000
-
 
1007
        self.logger.info("Renaming " + oldname + " to " + newname + "...")
988
        self.logger.info("Renaming " + oldname + " to " + newname + "...")
1008
        self.embios.file_rename(oldname, newname)
989
        self.embios.file_rename(oldname, newname)
1009
        self.logger.info(" done\n")
990
        self.logger.info(" done\n")
1010
 
991
 
1011
    @command
992
    @command
Line 1018... Line 999...
1018
        buffsize = self._hexint(buffsize)
999
        buffsize = self._hexint(buffsize)
1019
        try:
1000
        try:
1020
            f = open(localname, 'wb')
1001
            f = open(localname, 'wb')
1021
        except IOError:
1002
        except IOError:
1022
            raise ArgumentError("Could not open local file for writing.")
1003
            raise ArgumentError("Could not open local file for writing.")
1023
        self.embios.lib.dev.timeout = 30000
-
 
1024
        self.logger.info("Downloading file " + remotename + " to " + localname + "...")
1004
        self.logger.info("Downloading file " + remotename + " to " + localname + "...")
1025
        fd = self.embios.file_open(remotename, 0)
1005
        fd = self.embios.file_open(remotename, 0)
1026
        size = self.embios.file_size(fd)
1006
        size = self.embios.file_size(fd)
1027
        while size > 0:
1007
        while size > 0:
1028
            bytes = self.embios.file_read(fd, buffer, buffsize)
1008
            bytes = self.embios.file_read(fd, buffer, buffsize)
Line 1042... Line 1022...
1042
        buffsize = self._hexint(buffsize)
1022
        buffsize = self._hexint(buffsize)
1043
        try:
1023
        try:
1044
            f = open(localname, 'rb')
1024
            f = open(localname, 'rb')
1045
        except IOError:
1025
        except IOError:
1046
            raise ArgumentError("Could not open local file for reading.")
1026
            raise ArgumentError("Could not open local file for reading.")
1047
        self.embios.lib.dev.timeout = 30000
-
 
1048
        self.logger.info("Uploading file " + localname + " to " + remotename + "...")
1027
        self.logger.info("Uploading file " + localname + " to " + remotename + "...")
1049
        fd = self.embios.file_open(remotename, 0x15)
1028
        fd = self.embios.file_open(remotename, 0x15)
1050
        while True:
1029
        while True:
1051
            data = f.read(buffsize)
1030
            data = f.read(buffsize)
1052
            if len(data) == 0: break
1031
            if len(data) == 0: break
Line 1061... Line 1040...
1061
    @command
1040
    @command
1062
    def ls(self, path = "/"):
1041
    def ls(self, path = "/"):
1063
        """
1042
        """
1064
            Lists all files in the specified path
1043
            Lists all files in the specified path
1065
        """
1044
        """
1066
        self.embios.lib.dev.timeout = 30000
-
 
1067
        handle = self.embios.dir_open(path)
1045
        handle = self.embios.dir_open(path)
1068
        self.logger.info("Directory listing of " + path + ":\n")
1046
        self.logger.info("Directory listing of " + path + ":\n")
1069
        while True:
1047
        while True:
1070
            try:
1048
            try:
1071
                entry = self.embios.dir_read(handle)
1049
                entry = self.embios.dir_read(handle)