freemyipod r585 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r584‎ | r585 | r586 >
Date:14:30, 12 February 2011
Author:theseven
Status:new
Tags:
Comment:
[lib]emcore.py: Fix ipodclassic_hddaccess and make ipodclassic_writebbt use allocated memory if no buffer is provided
Modified paths:
  • /emcore/trunk/tools/emcore.py (modified) (history)
  • /emcore/trunk/tools/libemcore.py (modified) (history)

Diff [purge]

Index: emcore/trunk/tools/emcore.py
@@ -808,13 +808,14 @@
809809 self.logger.info("done\n")
810810
811811 @command
812 - def ipodclassic_writebbt(self, tempaddr, filename):
 812+ def ipodclassic_writebbt(self, filename, tempaddr = None):
813813 """
814814 Target-specific function: ipodclassic
815 - Uploads the bad block table <filename> to
816 - memory at <tempaddr> and writes it to the hard disk
 815+ Uploads the bad block table <filename> to memory at <tempaddr>
 816+ (or an allocated block if not given) and writes it to the hard disk
817817 """
818 - tempaddr = to_int(tempaddr)
 818+ if tempaddr != None:
 819+ tempaddr = to_int(tempaddr)
819820 try:
820821 f = open(filename, 'rb')
821822 except IOError:
Index: emcore/trunk/tools/libemcore.py
@@ -542,11 +542,11 @@
543543 Access the hard disk, type = 0 (read) / 1 (write)
544544 """
545545 rc = self.lib.monitorcommand(struct.pack("<IIQIIII", 0xffff0002, type, sector, count, addr, 0, 0), "III", ("rc", None, None))
546 - if (rc > 0x80000000):
547 - raise DeviceError("HDD access (type=%d, sector=%d, count=%d, addr=0x%08X) failed with RC 0x%08X" % (type, sector, count, addr, rc))
 546+ if (rc.rc > 0x80000000):
 547+ raise DeviceError("HDD access (type=%d, sector=%d, count=%d, addr=0x%08X) failed with RC 0x%08X" % (type, sector, count, addr, rc.rc))
548548
549549 @command(target = 0x4c435049)
550 - def ipodclassic_writebbt(self, bbt, tempaddr):
 550+ def ipodclassic_writebbt(self, bbt, tempaddr = None):
551551 """ Target-specific function: ipodclassic
552552 Write hard drive bad block table
553553 """
@@ -558,19 +558,29 @@
559559 raise ArgumentError("The specified file is not an emCORE hard disk BBT")
560560 virtualsectors = bbtheader[2]
561561 bbtsectors = bbtheader[3]
562 - self.write(tempaddr, bbt)
563 - sector = 0
564 - count = 1
565 - offset = 0
566 - for i in range(bbtsectors):
567 - if bbtheader[4][i] == sector + count:
568 - count = count + 1
569 - else:
570 - self.ipodclassic_hddaccess(1, sector, count, tempaddr + offset)
571 - offset = offset + count * 4096
572 - sector = bbtheader[4][i]
573 - count = 1
574 - self.ipodclassic_hddaccess(1, sector, count, tempaddr + offset)
 562+ if tempaddr is None:
 563+ tempaddr = self.malloc(len(bbt))
 564+ malloc = True
 565+ else:
 566+ malloc = False
 567+ try:
 568+ self.write(tempaddr, bbt)
 569+ sector = 0
 570+ count = 1
 571+ offset = 0
 572+ for i in range(bbtsectors):
 573+ if bbtheader[4][i] == sector + count:
 574+ count = count + 1
 575+ else:
 576+ self.ipodclassic_hddaccess(1, sector, count, tempaddr + offset)
 577+ offset = offset + count * 4096
 578+ sector = bbtheader[4][i]
 579+ count = 1
 580+ self.ipodclassic_hddaccess(1, sector, count, tempaddr + offset)
 581+ except:
 582+ if malloc == True:
 583+ self.free(tempaddr)
 584+ raise
575585
576586 @command()
577587 def storage_get_info(self, volume):