Subversion Repositories freemyipod

Rev

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

Rev 780 Rev 787
Line 584... Line 584...
584
            Disable the ATA bbt
584
            Disable the ATA bbt
585
        """
585
        """
586
        rc = self.lib.monitorcommand(struct.pack("<IIII", 0xffff0004, 0, 0, 0), "III", (None, None, None))
586
        rc = self.lib.monitorcommand(struct.pack("<IIII", 0xffff0004, 0, 0, 0), "III", (None, None, None))
587
    
587
    
588
    @command(target = 0x4c435049)
588
    @command(target = 0x4c435049)
-
 
589
    def ipodclassic_readbbt(self, tempaddr = None):
-
 
590
        """ Target-specific function: ipodclassic
-
 
591
            Read hard drive bad block table
-
 
592
        """
-
 
593
        if tempaddr is None:
-
 
594
            tempaddr = self.memalign(0x10, 4096)
-
 
595
            malloc = True
-
 
596
        else:
-
 
597
            malloc = False
-
 
598
        try:
-
 
599
            self.ipodclassic_hddaccess(0, 0, 1, tempaddr)
-
 
600
            bbt = self.read(tempaddr, 4096)
-
 
601
        finally:
-
 
602
            if malloc == True:
-
 
603
                self.free(tempaddr)
-
 
604
        try:
-
 
605
            bbtheader = struct.unpack("<8s2024sQII512I", bbt)
-
 
606
        except struct.error:
-
 
607
            raise ArgumentError("There is no emCORE hard disk BBT present on this device")
-
 
608
        if bbtheader[0] != b"emBIbbth":
-
 
609
            raise ArgumentError("There is no emCORE hard disk BBT present on this device")
-
 
610
        bbtsectors = bbtheader[4]
-
 
611
        if malloc:
-
 
612
            tempaddr = self.memalign(0x10, 4096 * bbtsectors)
-
 
613
        try:
-
 
614
            sector = 1
-
 
615
            count = 0
-
 
616
            offset = 0
-
 
617
            for i in range(0, bbtsectors):
-
 
618
                if bbtheader[5 + i] == sector + count:
-
 
619
                    count = count + 1
-
 
620
                else:
-
 
621
                    self.ipodclassic_hddaccess(0, sector, count, tempaddr + offset)
-
 
622
                    offset = offset + count * 4096
-
 
623
                    sector = bbtheader[5 + i]
-
 
624
                    count = 1
-
 
625
            self.ipodclassic_hddaccess(0, sector, count, tempaddr + offset)
-
 
626
            bbt += self.read(tempaddr, 4096 * bbtsectors)
-
 
627
        finally:
-
 
628
            if malloc == True:
-
 
629
                self.free(tempaddr)
-
 
630
        return bbt
-
 
631
    
-
 
632
    @command(target = 0x4c435049)
589
    def ipodclassic_writebbt(self, bbt, tempaddr = None):
633
    def ipodclassic_writebbt(self, bbt, tempaddr = None):
590
        """ Target-specific function: ipodclassic
634
        """ Target-specific function: ipodclassic
591
            Write hard drive bad block table
635
            Write hard drive bad block table
592
        """
636
        """
593
        try:
637
        try:
594
            bbtheader = struct.unpack("<8s2024sQII512I", bbt[:4096])
638
            bbtheader = struct.unpack("<8s2024sQII512I", bbt[:4096])
595
        except struct.error:
639
        except struct.error:
596
            raise ArgumentError("The specified file is not an emCORE hard disk BBT")
640
            raise ArgumentError("The specified file is not an emCORE hard disk BBT")
597
        if bbtheader[0] != "emBIbbth":
641
        if bbtheader[0] != b"emBIbbth":
598
            raise ArgumentError("The specified file is not an emCORE hard disk BBT")
642
            raise ArgumentError("The specified file is not an emCORE hard disk BBT")
599
        virtualsectors = bbtheader[2]
-
 
600
        bbtsectors = bbtheader[4]
643
        bbtsectors = bbtheader[4]
-
 
644
        if (bbtsectors + 1) * 4096 != len(bbt):
-
 
645
            raise ArgumentError("Size of BBT is not consistent: Expected %d bytes, got %d" % ((bbtsectors + 1) * 4096, len(bbt)))
601
        if tempaddr is None:
646
        if tempaddr is None:
602
            tempaddr = self.malloc(len(bbt))
647
            tempaddr = self.memalign(0x10, len(bbt))
603
            malloc = True
648
            malloc = True
604
        else:
649
        else:
605
            malloc = False
650
            malloc = False
606
        try:
651
        try:
607
            self.write(tempaddr, bbt)
652
            self.write(tempaddr, bbt)
Line 613... Line 658...
613
                if bbtheader[5 + i] == sector + count:
658
                if bbtheader[5 + i] == sector + count:
614
                    count = count + 1
659
                    count = count + 1
615
                else:
660
                else:
616
                    self.ipodclassic_hddaccess(1, sector, count, tempaddr + offset)
661
                    self.ipodclassic_hddaccess(1, sector, count, tempaddr + offset)
617
                    offset = offset + count * 4096
662
                    offset = offset + count * 4096
618
                    sector = bbtheader[5 +i]
663
                    sector = bbtheader[5 + i]
619
                    count = 1
664
                    count = 1
620
            self.ipodclassic_hddaccess(1, sector, count, tempaddr + offset)
665
            self.ipodclassic_hddaccess(1, sector, count, tempaddr + offset)
621
            self.ipodclassic_reloadbbt()
666
            self.ipodclassic_reloadbbt()
622
            self.disk_mount(0)
667
            self.disk_mount(0)
623
        finally:
668
        finally: