Subversion Repositories freemyipod

Rev

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

Rev 477 Rev 478
Line 129... Line 129...
129
    def __init__(self):
129
    def __init__(self):
130
        self.logger = Logger()
130
        self.logger = Logger()
131
        try:
131
        try:
132
            self.emcore = libemcore.Emcore(loglevel = 2)
132
            self.emcore = libemcore.Emcore(loglevel = 2)
133
        except libemcore.DeviceNotFoundError:
133
        except libemcore.DeviceNotFoundError:
134
            self.logger.error("No emCORE device found!")
134
            self.logger.error("No emCORE device found!\n")
135
            exit(1)
135
            exit(1)
136
        self.getinfo("version")
136
        self.getinfo("version")
137
        
137
        
138
    def _parsecommand(self, func, args):
138
    def _parsecommand(self, func, args):
139
        # adds self to the commandline args.
139
        # adds self to the commandline args.
Line 147... Line 147...
147
            except (ArgumentError, libemcore.ArgumentError):
147
            except (ArgumentError, libemcore.ArgumentError):
148
                usage("Syntax Error in function '" + func + "'", specific=func)
148
                usage("Syntax Error in function '" + func + "'", specific=func)
149
            except ArgumentTypeError, e:
149
            except ArgumentTypeError, e:
150
                usage(e, specific=func)
150
                usage(e, specific=func)
151
            except NotImplementedError:
151
            except NotImplementedError:
152
                self.logger.error("This function is not implemented yet!")
152
                self.logger.error("This function is not implemented yet!\n")
153
            except libemcore.DeviceError, e:
153
            except libemcore.DeviceError, e:
154
                self.logger.error(str(e))
154
                self.logger.error(str(e) + "\n")
155
            except TypeError, e:
155
            except TypeError, e:
156
                # Only act on TypeErrors for the function we called, not on TypeErrors raised by another function.
156
                # Only act on TypeErrors for the function we called, not on TypeErrors raised by another function.
157
                if str(e).split(" ", 1)[0] == func + "()":
157
                if str(e).split(" ", 1)[0] == func + "()":
158
                    self.logger.error(usage("Argument Error in '" + func + "': Wrong argument count", specific=func))
158
                    self.logger.error(usage("Argument Error in '" + func + "': Wrong argument count", specific=func) + "\n")
159
                else:
159
                else:
160
                    raise
160
                    raise
161
            except libemcore.usb.core.USBError:
161
            except libemcore.usb.core.USBError:
162
                self.logger.error("There is a problem with the USB connection.")
162
                self.logger.error("There is a problem with the USB connection.\n")
163
        else:
163
        else:
164
            usage("No such command")
164
            usage("No such command")
165
    
165
    
166
    @staticmethod
166
    @staticmethod
167
    def _bool(something):
167
    def _bool(something):
Line 229... Line 229...
229
        
229
        
230
        elif infotype == "packetsize":
230
        elif infotype == "packetsize":
231
            self.logger.info("Maximum packet sizes: \n command out: " + str(self.emcore.lib.dev.packetsizelimit.cout) + \
231
            self.logger.info("Maximum packet sizes: \n command out: " + str(self.emcore.lib.dev.packetsizelimit.cout) + \
232
                             "\n command in: " + str(self.emcore.lib.dev.packetsizelimit.cin) + \
232
                             "\n command in: " + str(self.emcore.lib.dev.packetsizelimit.cin) + \
233
                             "\n data in: " + str(self.emcore.lib.dev.packetsizelimit.din) + \
233
                             "\n data in: " + str(self.emcore.lib.dev.packetsizelimit.din) + \
234
                             "\n data out: " + str(self.emcore.lib.dev.packetsizelimit.dout))
234
                             "\n data out: " + str(self.emcore.lib.dev.packetsizelimit.dout)+ "\n")
235
        
235
        
236
        elif infotype == "usermemrange":
236
        elif infotype == "usermemrange":
237
            resp = self.emcore.getusermemrange()
237
            resp = self.emcore.getusermemrange()
238
            self.logger.info("The user memory range is " + \
238
            self.logger.info("The user memory range is " + \
239
                             self._hex(self.emcore.lib.dev.usermem.lower) + \
239
                             self._hex(self.emcore.lib.dev.usermem.lower) + \
240
                             " - " + \
240
                             " - " + \
241
                             self._hex(self.emcore.lib.dev.usermem.upper - 1))
241
                             self._hex(self.emcore.lib.dev.usermem.upper - 1) + "\n")
242
        
242
        
243
        else:
243
        else:
244
            raise ArgumentTypeError("one out of 'version', 'packetsize', 'usermemrange'", infotype)
244
            raise ArgumentTypeError("one out of 'version', 'packetsize', 'usermemrange'", infotype)
245
    
245
    
246
    @command
246
    @command
Line 562... Line 562...
562
            f = open(filename, 'rb')
562
            f = open(filename, 'rb')
563
        except IOError:
563
        except IOError:
564
            raise ArgumentError("File not readable. Does it exist?")
564
            raise ArgumentError("File not readable. Does it exist?")
565
        with f:
565
        with f:
566
            data = self.emcore.run(f.read())
566
            data = self.emcore.run(f.read())
567
        self.logger.info("Executed emCORE application as thread " + self._hex(data.thread))
567
        self.logger.info("Executed emCORE application as thread " + self._hex(data.thread) + "\n")
568
 
568
 
569
    @command
569
    @command
570
    def execimage(self, addr):
570
    def execimage(self, addr):
571
        """
571
        """
572
            Executes the emCORE application at <addr>.
572
            Executes the emCORE application at <addr>.
Line 684... Line 684...
684
                         self._hex(destination) + " - " + self._hex(destination+sha1size) + "...")
684
                         self._hex(destination) + " - " + self._hex(destination+sha1size) + "...")
685
        self.emcore.hmac_sha1(addr, size, destination)
685
        self.emcore.hmac_sha1(addr, size, destination)
686
        self.logger.info("done\n")
686
        self.logger.info("done\n")
687
        data = self.emcore.read(destination, sha1size)
687
        data = self.emcore.read(destination, sha1size)
688
        hash = ord(data)
688
        hash = ord(data)
689
        self.logger.info("The generated hash is "+self._hex(hash))
689
        self.logger.info("The generated hash is "+self._hex(hash)+"\n")
690
 
690
 
691
    @command
691
    @command
692
    def ipodnano2g_getnandinfo(self):
692
    def ipodnano2g_getnandinfo(self):
693
        """
693
        """
694
            Target-specific function: ipodnano2g
694
            Target-specific function: ipodnano2g
Line 697... Line 697...
697
        data = self.emcore.ipodnano2g_getnandinfo()
697
        data = self.emcore.ipodnano2g_getnandinfo()
698
        self.logger.info("NAND chip type: "         + self._hex(data["type"])+"\n")
698
        self.logger.info("NAND chip type: "         + self._hex(data["type"])+"\n")
699
        self.logger.info("Number of banks: "        + str(data["banks"])+"\n")
699
        self.logger.info("Number of banks: "        + str(data["banks"])+"\n")
700
        self.logger.info("Number of blocks: "       + str(data["blocks"])+"\n")
700
        self.logger.info("Number of blocks: "       + str(data["blocks"])+"\n")
701
        self.logger.info("Number of user blocks: "  + str(data["userblocks"])+"\n")
701
        self.logger.info("Number of user blocks: "  + str(data["userblocks"])+"\n")
702
        self.logger.info("Pages per block: "        + str(data["pagesperblock"]))
702
        self.logger.info("Pages per block: "        + str(data["pagesperblock"])+"\n")
703
 
703
 
704
    @command
704
    @command
705
    def ipodnano2g_nandread(self, addr, start, count, doecc=True, checkempty=True):
705
    def ipodnano2g_nandread(self, addr, start, count, doecc=True, checkempty=True):
706
        """
706
        """
707
            Target-specific function: ipodnano2g
707
            Target-specific function: ipodnano2g
Line 846... Line 846...
846
        data = self.emcore.storage_get_info(volume)
846
        data = self.emcore.storage_get_info(volume)
847
        self.logger.info("Sector size: "+str(data["sectorsize"])+"\n")
847
        self.logger.info("Sector size: "+str(data["sectorsize"])+"\n")
848
        self.logger.info("Number of sectors: "+str(data["numsectors"])+"\n")
848
        self.logger.info("Number of sectors: "+str(data["numsectors"])+"\n")
849
        self.logger.info("Vendor: "+data["vendor"]+"\n")
849
        self.logger.info("Vendor: "+data["vendor"]+"\n")
850
        self.logger.info("Product: "+data["product"]+"\n")
850
        self.logger.info("Product: "+data["product"]+"\n")
851
        self.logger.info("Revision: "+data["revision"])
851
        self.logger.info("Revision: "+data["revision"]+"\n")
852
 
852
 
853
    @command
853
    @command
854
    def readrawstorage(self, volume, sector, count, addr):
854
    def readrawstorage(self, volume, sector, count, addr):
855
        """
855
        """
856
            Reads <count> sectors starting at <sector> from storage <volume> to memory at <addr>.
856
            Reads <count> sectors starting at <sector> from storage <volume> to memory at <addr>.
Line 1092... Line 1092...
1092
        try:
1092
        try:
1093
            try:
1093
            try:
1094
                f = open(localname, 'rb')
1094
                f = open(localname, 'rb')
1095
            except IOError:
1095
            except IOError:
1096
                raise ArgumentError("Could not open local file for reading.")
1096
                raise ArgumentError("Could not open local file for reading.")
1097
            self.logger.info("Uploading file " + localname + " to " + remotename + "...")
1097
            self.logger.info("Uploading file " + localname + " to " + remotename + "...\n")
1098
            fd = self.emcore.file_open(remotename, 0x15)
1098
            fd = self.emcore.file_open(remotename, 0x15)
1099
            while True:
1099
            while True:
1100
                data = f.read(buffsize)
1100
                data = f.read(buffsize)
1101
                if len(data) == 0: break
1101
                if len(data) == 0: break
1102
                self.emcore.write(buffer, data)
1102
                self.emcore.write(buffer, data)
Line 1192... Line 1192...
1192
    @command
1192
    @command
1193
    def reownalloc(self, ptr, owner):
1193
    def reownalloc(self, ptr, owner):
1194
        """ Changes the owner of the memory allocation <ptr> to the thread struct at addr <owner> """
1194
        """ Changes the owner of the memory allocation <ptr> to the thread struct at addr <owner> """
1195
        ptr = self._hexint(ptr)
1195
        ptr = self._hexint(ptr)
1196
        owner = self._hexint(owner)
1196
        owner = self._hexint(owner)
1197
        self.logger.info("Changing owner of the memory region 0x%x to 0x%x" % (ptr, owner))
1197
        self.logger.info("Changing owner of the memory region 0x%x to 0x%x\n" % (ptr, owner))
1198
        self.emcore.reownalloc(ptr, owner)
1198
        self.emcore.reownalloc(ptr, owner)
1199
        self.logger.info("Successfully changed owner of 0x%x to 0x%x" % (ptr, owner))
1199
        self.logger.info("Successfully changed owner of 0x%x to 0x%x\n" % (ptr, owner))
1200
    
1200
    
1201
    @command
1201
    @command
1202
    def free(self, ptr):
1202
    def free(self, ptr):
1203
        """ Frees the memory space pointed to by 'ptr' """
1203
        """ Frees the memory space pointed to by 'ptr' """
1204
        ptr = self._hexint(ptr)
1204
        ptr = self._hexint(ptr)