Index: embios/trunk/tools/embios.py |
— | — | @@ -144,7 +144,7 @@ |
145 | 145 | Decorator for all commands.
|
146 | 146 | The decorated function is called with (self, all, other, arguments, ...)
|
147 | 147 | """
|
148 | | - def decorator(args):
|
| 148 | + def decorator(*args):
|
149 | 149 | return func(args[0], *args[1:])
|
150 | 150 | func._command = True
|
151 | 151 | decorator.func = func
|
— | — | @@ -180,6 +180,7 @@ |
181 | 181 | except libembios.DeviceNotFoundError:
|
182 | 182 | self.logger.error("No emBIOS device found!")
|
183 | 183 | end(1)
|
| 184 | + self.getinfo("version")
|
184 | 185 |
|
185 | 186 | def _parsecommand(self, func, args):
|
186 | 187 | # adds self to the commandline args.
|
— | — | @@ -187,7 +188,7 @@ |
188 | 189 | args.insert(0, self)
|
189 | 190 | if func in self.cmddict:
|
190 | 191 | try:
|
191 | | - self.cmddict[func](args)
|
| 192 | + self.cmddict[func](*args)
|
192 | 193 | except ArgumentError, e:
|
193 | 194 | usage(e)
|
194 | 195 | except ArgumentError:
|
— | — | @@ -196,6 +197,8 @@ |
197 | 198 | usage(e)
|
198 | 199 | except NotImplementedError:
|
199 | 200 | self.logger.error("This function is not implemented yet!")
|
| 201 | + except libembios.DeviceNotFoundError:
|
| 202 | + self.logger.error("Device not found!")
|
200 | 203 | except libembios.DeviceError, e:
|
201 | 204 | self.logger.error(str(e))
|
202 | 205 | except TypeError, e:
|
— | — | @@ -263,7 +266,7 @@ |
264 | 267 | """
|
265 | 268 | if infotype == "version":
|
266 | 269 | resp = self.embios.getversioninfo()
|
267 | | - self.logger.info(libembiosdata.swtypes[resp.swtypeid] + " v" + str(resp.majorv) + "." + str(resp.minorv) +
|
| 270 | + self.logger.info("Connected to "+libembiosdata.swtypes[resp.swtypeid] + " v" + str(resp.majorv) + "." + str(resp.minorv) +
|
268 | 271 | "." + str(resp.patchv) + " r" + str(resp.revision) + " running on " + libembiosdata.hwtypes[resp.hwtypeid] + "\n")
|
269 | 272 | elif infotype == "packetsize":
|
270 | 273 | resp = self.embios.getpacketsizeinfo()
|
— | — | @@ -546,14 +549,35 @@ |
547 | 550 | stacksize = self._hexint(stacksize)
|
548 | 551 | priority = self._hexint(priority)
|
549 | 552 | self.embios.createthread(nameptr, entrypoint, stackptr, stacksize, type, priority, state)
|
| 553 | +
|
| 554 | + @command
|
| 555 | + def run(self, filename):
|
| 556 | + """
|
| 557 | + Uploads the emBIOS application to an address in the user memory
|
| 558 | + and executes it
|
| 559 | + """
|
| 560 | + try:
|
| 561 | + f = open(filename, "rb")
|
| 562 | + except IOError:
|
| 563 | + raise ArgumentError("File not readable. Does it exist?")
|
| 564 | + data = self.embios.getusermemrange()
|
| 565 | + addr = data.lower
|
| 566 | + maxsize = data.upper - data.lower
|
| 567 | + filesize = os.path.getsize(filename)
|
| 568 | + if filesize > maxsize:
|
| 569 | + raise ArgumentError("The file is too big, it doesn't fit into the user memory.")
|
| 570 | + self.logger.info("Uploading application to "+hex(addr)+" - "+hex(addr+filesize)+"\n")
|
| 571 | + self.embios.write(addr, f.read())
|
| 572 | + self.execute(addr)
|
550 | 573 |
|
551 | 574 | @command
|
552 | | - def run(self, address):
|
| 575 | + def execute(self, addr):
|
553 | 576 | """
|
554 | 577 | Executes the emBIOS application at <address>.
|
555 | 578 | """
|
556 | | - address = self._hexint(address)
|
557 | | - raise NotImplementedError
|
| 579 | + addr = self._hexint(addr)
|
| 580 | + self.logger.info("Starting emBIOS app at "+hex(addr)+"\n")
|
| 581 | + self.embios.execimage(addr)
|
558 | 582 |
|
559 | 583 | @command
|
560 | 584 | def readrawbootflash(self, addr_flash, addr_mem, size):
|
— | — | @@ -586,12 +610,14 @@ |
587 | 611 | """
|
588 | 612 | Flushes the CPUs data and instruction caches.
|
589 | 613 | """
|
590 | | - raise NotImplementedError
|
| 614 | + self.logger.info("Flushing CPU data and instruction caches...")
|
| 615 | + self.embios.flushcaches()
|
| 616 | + self.logger.info("done\n")
|
591 | 617 |
|
592 | 618 | @command
|
593 | 619 | def aesencrypt(self, addr, size, keyindex):
|
594 | 620 | """
|
595 | | - Encrypt a buffer using a hardware key
|
| 621 | + Encrypts a buffer using a hardware key
|
596 | 622 | """
|
597 | 623 | addr = self._hexint(addr)
|
598 | 624 | size = self._hexint(size)
|
— | — | @@ -601,12 +627,29 @@ |
602 | 628 | @command
|
603 | 629 | def aesdecrypt(self, addr, size, keyindex):
|
604 | 630 | """
|
605 | | - Decrypt a buffer using a hardware key
|
| 631 | + Decrypts a buffer using a hardware key
|
606 | 632 | """
|
607 | 633 | addr = self._hexint(addr)
|
608 | 634 | size = self._hexint(size)
|
609 | 635 | keyindex = self._hexint(keyindex)
|
610 | 636 | self.embios.aesdecrypt(addr, size, keyindex)
|
| 637 | +
|
| 638 | + @command
|
| 639 | + def hmac_sha1(self, addr, size, destination):
|
| 640 | + """
|
| 641 | + Generates a HMAC-SHA1 hash of the buffer and saves it to 'destination'
|
| 642 | + """
|
| 643 | + addr = self._hexint(addr)
|
| 644 | + size = self._hexint(size)
|
| 645 | + destination = self._hexint(destination)
|
| 646 | + sha1size = 0x14
|
| 647 | + self.logger.info("Generating hmac-sha1 hash from the buffer at "+hex(addr)+" with the size "+hex(size)+
|
| 648 | + " and saving it to "+hex(destination)+" - "+hex(destination+sha1size)+"...")
|
| 649 | + self.embios.hmac_sha1(addr, size, destination)
|
| 650 | + self.logger.info("done\n")
|
| 651 | + data = self.embios.readmem(destination, sha1size)
|
| 652 | + hash = ord(data)
|
| 653 | + self.logger.info("The generated hash is "+hex(hash))
|
611 | 654 |
|
612 | 655 | if __name__ == "__main__":
|
613 | 656 | if len(sys.argv) < 2:
|
Index: embios/trunk/tools/libembios.py |
— | — | @@ -269,11 +269,11 @@ |
270 | 270 | raise DeviceError("The device returned the error code "+str(resp.id))
|
271 | 271 | return resp
|
272 | 272 |
|
273 | | - def flushcpucache(self):
|
| 273 | + def flushcaches(self):
|
274 | 274 | """ Flushes the CPU instruction and data cache """
|
275 | 275 | return self.lib.monitorcommand(struct.pack("IIII", 20, 0, 0, 0), "III", (None, None, None))
|
276 | 276 |
|
277 | | - def run(self, addr):
|
| 277 | + def execimage(self, addr):
|
278 | 278 | """ Runs the emBIOS app at 'addr' """
|
279 | 279 | return self.lib.monitorcommand(struct.pack("IIII", 21, addr, 0, 0), "III", ("excecimage", None, None))
|
280 | 280 |
|