Index: embios/trunk/tools/embios.py |
— | — | @@ -562,34 +562,9 @@ |
563 | 563 | f = open(filename, 'rb')
|
564 | 564 | except IOError:
|
565 | 565 | raise ArgumentError("File not readable. Does it exist?")
|
566 | | - try:
|
567 | | - appheader = struct.unpack("<8sIIIIIIIIII", f.read(48))
|
568 | | - header = appheader[0]
|
569 | | - if header != "emBIexec":
|
570 | | - raise ArgumentError("The specified file is not an emBIOS application (header)")
|
571 | | - baseaddr = appheader[2]
|
572 | | - threadnameptr = appheader[8]
|
573 | | - f.seek(threadnameptr - baseaddr)
|
574 | | - name = ""
|
575 | | - while True:
|
576 | | - char = f.read(1)
|
577 | | - if ord(char) == 0:
|
578 | | - break
|
579 | | - name += char
|
580 | | - usermem = self.embios.getusermemrange()
|
581 | | - if usermem.lower > baseaddr or usermem.upper < baseaddr + os.stat(filename).st_size:
|
582 | | - 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?")
|
583 | | - self.logger.info("Writing emBIOS application \"" + name + "\" to the memory at " + self._hex(baseaddr) + "...")
|
584 | | - f.seek(0)
|
585 | | - self.embios.write(baseaddr, f.read())
|
586 | | - except IOError:
|
587 | | - raise ArgumentError("The specified file is not an emBIOS application (IOError)")
|
588 | | - except struct.error:
|
589 | | - raise ArgumentError("The specified file is not an emBIOS application (struct.error)")
|
590 | | - finally:
|
591 | | - f.close()
|
592 | | - self.logger.info("done\n")
|
593 | | - self.execimage(baseaddr)
|
| 566 | + with f:
|
| 567 | + data = self.embios.run(f.read())
|
| 568 | + self.logger.info("Executed emBIOS application \"" + data.name + "\" at address " + self._hex(data.baseaddr))
|
594 | 569 |
|
595 | 570 | @command
|
596 | 571 | def execimage(self, addr):
|
Index: embios/trunk/tools/libembios.py |
— | — | @@ -393,6 +393,36 @@ |
394 | 394 | """ Runs the emBIOS app at 'addr' """
|
395 | 395 | return self.lib.monitorcommand(struct.pack("IIII", 21, addr, 0, 0), "III", ("excecimage", None, None))
|
396 | 396 |
|
| 397 | + def run(self, app):
|
| 398 | + """ Uploads and runs the emBIOS app in the string 'app' """
|
| 399 | + try:
|
| 400 | + appheader = struct.unpack("<8sIIIIIIIIII", app[:48])
|
| 401 | + except struct.error:
|
| 402 | + raise ArgumentError("The specified file is not an emBIOS application")
|
| 403 | + header = appheader[0]
|
| 404 | + if header != "emBIexec":
|
| 405 | + raise ArgumentError("The specified file is not an emBIOS application")
|
| 406 | + baseaddr = appheader[2]
|
| 407 | + threadnameptr = appheader[8]
|
| 408 | + nameptr = threadnameptr - baseaddr
|
| 409 | + name = ""
|
| 410 | + while True:
|
| 411 | + char = app[nameptr:nameptr+1]
|
| 412 | + try:
|
| 413 | + if ord(char) == 0:
|
| 414 | + break
|
| 415 | + except TypeError:
|
| 416 | + raise ArgumentError("The specified file is not an emBIOS application")
|
| 417 | + name += char
|
| 418 | + nameptr += 1
|
| 419 | + usermem = self.getusermemrange()
|
| 420 | + if usermem.lower > baseaddr or usermem.upper < baseaddr + len(app):
|
| 421 | + 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?")
|
| 422 | + self.write(baseaddr, app)
|
| 423 | + self.execimage(baseaddr)
|
| 424 | + return Bunch(baseaddr=baseaddr, name=name)
|
| 425 | +
|
| 426 | +
|
397 | 427 | def bootflashread(self, memaddr, flashaddr, size):
|
398 | 428 | """ Copies the data in the bootflash at 'flashaddr' of the specified size
|
399 | 429 | to the memory at addr 'memaddr'
|