Index: emcore/trunk/tools/emcore.py |
— | — | @@ -19,7 +19,7 @@ |
20 | 20 | # You should have received a copy of the GNU General Public License
|
21 | 21 | # along with emCORE. If not, see <http://www.gnu.org/licenses/>.
|
22 | 22 | #
|
23 | | -#
|
| 23 | +#
|
24 | 24 |
|
25 | 25 | """
|
26 | 26 | Command line interface to communicate with emCORE devices.
|
— | — | @@ -896,6 +896,23 @@ |
897 | 897 | self.emcore.free(buf)
|
898 | 898 |
|
899 | 899 | @command
|
| 900 | + def ipodclassic_readbbt(self, filename, tempaddr = None):
|
| 901 | + """
|
| 902 | + Target-specific function: ipodclassic
|
| 903 | + Reads the bad block table from the hard disk to memory at <tempaddr>
|
| 904 | + (or an allocated block if not given) and writes it to <filename>
|
| 905 | + """
|
| 906 | + tempaddr = to_int(tempaddr)
|
| 907 | + try:
|
| 908 | + f = open(filename, 'wb')
|
| 909 | + except IOError:
|
| 910 | + raise ArgumentError("File not writable.")
|
| 911 | + self.logger.info("Reading bad block table from disk...")
|
| 912 | + f.write(self.emcore.ipodclassic_readbbt(tempaddr))
|
| 913 | + f.close()
|
| 914 | + self.logger.info(" done\n")
|
| 915 | +
|
| 916 | + @command
|
900 | 917 | def ipodclassic_writebbt(self, filename, tempaddr = None):
|
901 | 918 | """
|
902 | 919 | Target-specific function: ipodclassic
|
Index: emcore/trunk/tools/libemcore.py |
— | — | @@ -586,6 +586,50 @@ |
587 | 587 | rc = self.lib.monitorcommand(struct.pack("<IIII", 0xffff0004, 0, 0, 0), "III", (None, None, None))
|
588 | 588 |
|
589 | 589 | @command(target = 0x4c435049)
|
| 590 | + def ipodclassic_readbbt(self, tempaddr = None):
|
| 591 | + """ Target-specific function: ipodclassic
|
| 592 | + Read hard drive bad block table
|
| 593 | + """
|
| 594 | + if tempaddr is None:
|
| 595 | + tempaddr = self.memalign(0x10, 4096)
|
| 596 | + malloc = True
|
| 597 | + else:
|
| 598 | + malloc = False
|
| 599 | + try:
|
| 600 | + self.ipodclassic_hddaccess(0, 0, 1, tempaddr)
|
| 601 | + bbt = self.read(tempaddr, 4096)
|
| 602 | + finally:
|
| 603 | + if malloc == True:
|
| 604 | + self.free(tempaddr)
|
| 605 | + try:
|
| 606 | + bbtheader = struct.unpack("<8s2024sQII512I", bbt)
|
| 607 | + except struct.error:
|
| 608 | + raise ArgumentError("There is no emCORE hard disk BBT present on this device")
|
| 609 | + if bbtheader[0] != b"emBIbbth":
|
| 610 | + raise ArgumentError("There is no emCORE hard disk BBT present on this device")
|
| 611 | + bbtsectors = bbtheader[4]
|
| 612 | + if malloc:
|
| 613 | + tempaddr = self.memalign(0x10, 4096 * bbtsectors)
|
| 614 | + try:
|
| 615 | + sector = 1
|
| 616 | + count = 0
|
| 617 | + offset = 0
|
| 618 | + for i in range(0, bbtsectors):
|
| 619 | + if bbtheader[5 + i] == sector + count:
|
| 620 | + count = count + 1
|
| 621 | + else:
|
| 622 | + self.ipodclassic_hddaccess(0, sector, count, tempaddr + offset)
|
| 623 | + offset = offset + count * 4096
|
| 624 | + sector = bbtheader[5 + i]
|
| 625 | + count = 1
|
| 626 | + self.ipodclassic_hddaccess(0, sector, count, tempaddr + offset)
|
| 627 | + bbt += self.read(tempaddr, 4096 * bbtsectors)
|
| 628 | + finally:
|
| 629 | + if malloc == True:
|
| 630 | + self.free(tempaddr)
|
| 631 | + return bbt
|
| 632 | +
|
| 633 | + @command(target = 0x4c435049)
|
590 | 634 | def ipodclassic_writebbt(self, bbt, tempaddr = None):
|
591 | 635 | """ Target-specific function: ipodclassic
|
592 | 636 | Write hard drive bad block table
|
— | — | @@ -594,12 +638,13 @@ |
595 | 639 | bbtheader = struct.unpack("<8s2024sQII512I", bbt[:4096])
|
596 | 640 | except struct.error:
|
597 | 641 | raise ArgumentError("The specified file is not an emCORE hard disk BBT")
|
598 | | - if bbtheader[0] != "emBIbbth":
|
| 642 | + if bbtheader[0] != b"emBIbbth":
|
599 | 643 | raise ArgumentError("The specified file is not an emCORE hard disk BBT")
|
600 | | - virtualsectors = bbtheader[2]
|
601 | 644 | bbtsectors = bbtheader[4]
|
| 645 | + if (bbtsectors + 1) * 4096 != len(bbt):
|
| 646 | + raise ArgumentError("Size of BBT is not consistent: Expected %d bytes, got %d" % ((bbtsectors + 1) * 4096, len(bbt)))
|
602 | 647 | if tempaddr is None:
|
603 | | - tempaddr = self.malloc(len(bbt))
|
| 648 | + tempaddr = self.memalign(0x10, len(bbt))
|
604 | 649 | malloc = True
|
605 | 650 | else:
|
606 | 651 | malloc = False
|
— | — | @@ -615,7 +660,7 @@ |
616 | 661 | else:
|
617 | 662 | self.ipodclassic_hddaccess(1, sector, count, tempaddr + offset)
|
618 | 663 | offset = offset + count * 4096
|
619 | | - sector = bbtheader[5 +i]
|
| 664 | + sector = bbtheader[5 + i]
|
620 | 665 | count = 1
|
621 | 666 | self.ipodclassic_hddaccess(1, sector, count, tempaddr + offset)
|
622 | 667 | self.ipodclassic_reloadbbt()
|