Subversion Repositories freemyipod

Rev

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

Rev 237 Rev 238
Line 560... Line 560...
560
        """
560
        """
561
        try:
561
        try:
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
        try:
565
        with f:
566
            appheader = struct.unpack("<8sIIIIIIIIII", f.read(48))
-
 
567
            header = appheader[0]
-
 
568
            if header != "emBIexec":
-
 
569
                raise ArgumentError("The specified file is not an emBIOS application (header)")
-
 
570
            baseaddr = appheader[2]
-
 
571
            threadnameptr = appheader[8]
-
 
572
            f.seek(threadnameptr - baseaddr)
-
 
573
            name = ""
-
 
574
            while True:
-
 
575
                char = f.read(1)
-
 
576
                if ord(char) == 0:
-
 
577
                    break
-
 
578
                name += char
-
 
579
            usermem = self.embios.getusermemrange()
566
            data = self.embios.run(f.read())
580
            if usermem.lower > baseaddr or usermem.upper < baseaddr + os.stat(filename).st_size:
-
 
581
                raise ArgumentError("The baseaddress of the specified emBIOS application is out of range of the user memory range on the device. Are you sure that this application is compatible with your device?")
-
 
582
            self.logger.info("Writing emBIOS application \"" + name + "\" to the memory at " + self._hex(baseaddr) + "...")
567
        self.logger.info("Executed emBIOS application \"" + data.name + "\" at address " + self._hex(data.baseaddr))
583
            f.seek(0)
-
 
584
            self.embios.write(baseaddr, f.read())
-
 
585
        except IOError:
-
 
586
            raise ArgumentError("The specified file is not an emBIOS application (IOError)")
-
 
587
        except struct.error:
-
 
588
            raise ArgumentError("The specified file is not an emBIOS application (struct.error)")
-
 
589
        finally:
-
 
590
            f.close()
-
 
591
        self.logger.info("done\n")
-
 
592
        self.execimage(baseaddr)
-
 
593
 
568
 
594
    @command
569
    @command
595
    def execimage(self, addr):
570
    def execimage(self, addr):
596
        """
571
        """
597
            Executes the emBIOS application at <addr>.
572
            Executes the emBIOS application at <addr>.