Subversion Repositories freemyipod

Rev

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

Rev 478 Rev 479
Line 220... Line 220...
220
        """
220
        """
221
        cin_maxsize = self.lib.dev.packetsizelimit.cin - self.lib.headersize
221
        cin_maxsize = self.lib.dev.packetsizelimit.cin - self.lib.headersize
222
        din_maxsize = self.lib.dev.packetsizelimit.din
222
        din_maxsize = self.lib.dev.packetsizelimit.din
223
        data = ""
223
        data = ""
224
        (headsize, bodysize, tailsize) = self._alignsplit(addr, size, cin_maxsize, 16)
224
        (headsize, bodysize, tailsize) = self._alignsplit(addr, size, cin_maxsize, 16)
-
 
225
        self.logger.debug("Downloading %d bytes from 0x%x, split as (%d/%d/%d)\n" % (size, addr, headsize, bodysize, tailsize))
225
        if headsize != 0:
226
        if headsize != 0:
226
            data += self._readmem(addr, headsize)
227
            data += self._readmem(addr, headsize)
227
            addr += headsize
228
            addr += headsize
228
        while bodysize > 0:
229
        while bodysize > 0:
229
            if bodysize >= 2 * cin_maxsize:
230
            if bodysize >= 2 * cin_maxsize:
Line 245... Line 246...
245
            and decides whether to use DMA or not.
246
            and decides whether to use DMA or not.
246
        """
247
        """
247
        cout_maxsize = self.lib.dev.packetsizelimit.cout - self.lib.headersize
248
        cout_maxsize = self.lib.dev.packetsizelimit.cout - self.lib.headersize
248
        dout_maxsize = self.lib.dev.packetsizelimit.dout
249
        dout_maxsize = self.lib.dev.packetsizelimit.dout
249
        (headsize, bodysize, tailsize) = self._alignsplit(addr, len(data), cout_maxsize, 16)
250
        (headsize, bodysize, tailsize) = self._alignsplit(addr, len(data), cout_maxsize, 16)
-
 
251
        self.logger.debug("Uploading %d bytes to 0x%x, split as (%d/%d/%d)\n" % (len(data), addr, headsize, bodysize, tailsize))
250
        offset = 0
252
        offset = 0
251
        if headsize != 0:
253
        if headsize != 0:
252
            self._writemem(addr, data[offset:offset+headsize])
254
            self._writemem(addr, data[offset:offset+headsize])
253
            offset += headsize
255
            offset += headsize
254
            addr += headsize
256
            addr += headsize
Line 270... Line 272...
270
    def upload(self, data):
272
    def upload(self, data):
271
        """ Allocates memory of the size of 'data' and uploads 'data' to that memory region.
273
        """ Allocates memory of the size of 'data' and uploads 'data' to that memory region.
272
            Returns the address where 'data' is stored
274
            Returns the address where 'data' is stored
273
        """
275
        """
274
        addr = self.malloc(len(data))
276
        addr = self.malloc(len(data))
275
        self.logger.debug("Uploading %d bytes to 0x%x\n" % (len(data), addr))
-
 
276
        self.write(addr, data)
277
        self.write(addr, data)
277
        return addr
278
        return addr
278
    
279
    
279
    @command()
280
    @command()
280
    def readstring(self, addr, maxlength = 256):
281
    def readstring(self, addr, maxlength = 256):
Line 616... Line 617...
616
        result.product = self.readstring(result.productptr)
617
        result.product = self.readstring(result.productptr)
617
        result.revision = self.readstring(result.revisionptr)
618
        result.revision = self.readstring(result.revisionptr)
618
        return result
619
        return result
619
    
620
    
620
    @command(timeout = 50000)
621
    @command(timeout = 50000)
621
    def storage_read_sectors_md(self, volume, sector, count, size = 0x100000, addr = None):
622
    def storage_read_sectors_md(self, volume, sector, count, addr):
622
        """ Read sectors from as storage device. If addr is not given it allocates a buffer itself. """
623
        """ Read sectors from as storage device """
623
        if addr is None:
-
 
624
            addr = self.malloc(size)
-
 
625
            malloc = True
-
 
626
        else:
-
 
627
            malloc = False
-
 
628
        try:
-
 
629
            result = self.lib.monitorcommand(struct.pack("IIQIIII", 28, volume, sector, count, addr, 0, 0), "III", ("rc", None, None))
624
        result = self.lib.monitorcommand(struct.pack("IIQIIII", 28, volume, sector, count, addr, 0, 0), "III", ("rc", None, None))
630
        finally:
-
 
631
            if malloc == True:
-
 
632
                self.free(addr)
-
 
633
        if result.rc > 0x80000000:
625
        if result.rc > 0x80000000:
634
            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))
626
            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))
635
    
627
 
-
 
628
    @command(timeout = 50000)
636
    def storage_write_sectors_md(self, volume, sector, count, size = 0x100000, addr = None):
629
    def storage_write_sectors_md(self, volume, sector, count, addr):
637
        """ Read sectors from as storage device. If addr is not given it allocates a buffer itself. """
630
        """ Read sectors from as storage device """
638
        if addr is None:
-
 
639
            addr = self.malloc(size)
-
 
640
            malloc = True
-
 
641
        else:
-
 
642
            malloc = False
-
 
643
        try:
-
 
644
            result = self.lib.monitorcommand(struct.pack("IIQIIII", 29, volume, sector, count, addr, 0, 0), "III", ("rc", None, None))
631
        result = self.lib.monitorcommand(struct.pack("IIQIIII", 29, volume, sector, count, addr, 0, 0), "III", ("rc", None, None))
645
        finally:
-
 
646
            if malloc == True:
-
 
647
                self.free(addr)
-
 
648
        if result.rc > 0x80000000:
632
        if result.rc > 0x80000000:
649
            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))
633
            raise DeviceError("storage_write_sectors_md(volume=%d, sector=%d, count=%d, addr=0x%08X) failed with RC 0x%08X" % (volume, sector, count, addr, rc))
650
    
634
    
651
    @command(timeout = 30000)
635
    @command(timeout = 30000)
-
 
636
    def fat_enable_flushing(self, state):
-
 
637
        """ Enables/disables flushing the FAT cache after every transaction """
-
 
638
        self.lib.monitorcommand(struct.pack("IIII", 58, state, 0, 0), "III", (None, None, None))
-
 
639
 
-
 
640
    @command(timeout = 30000)
652
    def file_open(self, filename, mode):
641
    def file_open(self, filename, mode):
653
        """ Opens a file and returns the handle """
642
        """ Opens a file and returns the handle """
654
        result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(filename), 30, mode, 0, 0, filename, 0), "III", ("fd", None, None))
643
        result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(filename), 30, mode, 0, 0, filename, 0), "III", ("fd", None, None))
655
        if result.fd > 0x80000000:
644
        if result.fd > 0x80000000:
656
            raise DeviceError("file_open(filename=\"%s\", mode=0x%X) failed with RC=0x%08X, errno=%d" % (filename, mode, result.fd, self.errno()))
645
            raise DeviceError("file_open(filename=\"%s\", mode=0x%X) failed with RC=0x%08X, errno=%d" % (filename, mode, result.fd, self.errno()))
Line 663... Line 652...
663
        if result.size > 0x80000000:
652
        if result.size > 0x80000000:
664
            raise DeviceError("file_size(fd=%d) failed with RC=0x%08X, errno=%d" % (fd, result.size, self.errno()))
653
            raise DeviceError("file_size(fd=%d) failed with RC=0x%08X, errno=%d" % (fd, result.size, self.errno()))
665
        return result.size
654
        return result.size
666
    
655
    
667
    @command(timeout = 30000)
656
    @command(timeout = 30000)
668
    def file_read(self, fd, size = 0x100000, addr = None):
657
    def file_read(self, fd, size = 0x10000, addr = None):
669
        """ Reads data from a file referenced by a handle. If addr is not given it allocates a buffer itself. """
658
        """ Reads data from a file referenced by a handle. If addr is not given it allocates a buffer itself. """
670
        if addr is None:
659
        if addr is None:
671
            addr = self.malloc(size)
660
            addr = self.malloc(size)
672
            malloc = True
661
            malloc = True
673
        else:
662
        else:
674
            malloc = False
663
            malloc = False
675
        try:
664
        try:
676
            result = self.lib.monitorcommand(struct.pack("IIII", 32, fd, addr, size), "III", ("rc", None, None))
665
            result = self.lib.monitorcommand(struct.pack("IIII", 32, fd, addr, size), "III", ("rc", None, None))
-
 
666
            if result.rc > 0x80000000:
-
 
667
                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()))
677
        finally:
668
        except:
678
            if malloc == True:
669
            if malloc == True:
679
                self.free(addr)
670
                self.free(addr)
680
        if result.rc > 0x80000000:
671
            raise
681
            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()))
-
 
682
        return result.rc
672
        return Bunch(rc = result.rc, addr = addr)
683
    
673
    
684
    @command(timeout = 30000)
674
    @command(timeout = 30000)
685
    def file_write(self, fd, size = 0x100000, addr = None):
675
    def file_write(self, fd, size, addr):
686
        """ Writes data from a file referenced by a handle. If addr is not given it allocates a buffer itself. """
676
        """ Writes data from a file referenced by a handle. """
687
        if addr is None:
-
 
688
            addr = self.malloc(size)
-
 
689
            malloc = True
-
 
690
        else:
-
 
691
            malloc = False
-
 
692
        try:
-
 
693
            result = self.lib.monitorcommand(struct.pack("IIII", 33, fd, addr, size), "III", ("rc", None, None))
677
        result = self.lib.monitorcommand(struct.pack("IIII", 33, fd, addr, size), "III", ("rc", None, None))
694
        finally:
-
 
695
            if malloc == True:
-
 
696
                self.free(addr)
-
 
697
        if result.rc > 0x80000000:
678
        if result.rc > 0x80000000:
698
            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()))
679
            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()))
699
        return result.rc
680
        return result.rc
700
    
681
    
701
    @command(timeout = 30000)
682
    @command(timeout = 30000)