| Index: embios/trunk/tools/embios.py |
| — | — | @@ -34,6 +34,7 @@ |
| 35 | 35 | from libembios import Error
|
| 36 | 36 | import libembiosdata
|
| 37 | 37 |
|
| | 38 | +
|
| 38 | 39 | class NotImplementedError(Error):
|
| 39 | 40 | pass
|
| 40 | 41 |
|
| — | — | @@ -252,17 +253,6 @@ |
| 253 | 254 | return None
|
| 254 | 255 | else:
|
| 255 | 256 | raise ArgumentTypeError("hexadecimal coded integer", "'"+str(something)+"'")
|
| 256 | | -
|
| 257 | | - @staticmethod
|
| 258 | | - def _strcheck(string, values):
|
| 259 | | - if string in values:
|
| 260 | | - return string
|
| 261 | | - else:
|
| 262 | | - expected = ""
|
| 263 | | - for item in values:
|
| 264 | | - expected += "'" + item + "', "
|
| 265 | | - expected = expected[:-2]
|
| 266 | | - raise ArgumentTypeError("one out of " + expected, "'" + string + "'")
|
| 267 | 257 |
|
| 268 | 258 | @staticmethod
|
| 269 | 259 | def _hex(integer):
|
| — | — | @@ -362,18 +352,18 @@ |
| 363 | 353 | raise ArgumentError("Specified integer too long")
|
| 364 | 354 | data = chr(integer)
|
| 365 | 355 | self.embios.write(addr, data)
|
| 366 | | - self.logger.info("Integer '"+self._hex(integer)+"' written successfully to "+self._hex(addr))
|
| | 356 | + self.logger.info("Integer '"+self._hex(integer)+"' written successfully to "+self._hex(addr)+"\n")
|
| 367 | 357 |
|
| 368 | 358 | @command
|
| 369 | 359 | def downloadint(self, addr):
|
| 370 | 360 | """
|
| 371 | 361 | Downloads a single integer from the device and prints it to the console window
|
| 372 | | - <offset>: the address to download the integer from
|
| | 362 | + <addr>: the address to download the integer from
|
| 373 | 363 | """
|
| 374 | 364 | addr = self._hexint(addr)
|
| 375 | 365 | data = self.embios.read(addr, 1)
|
| 376 | 366 | integer = ord(data)
|
| 377 | | - self.logger.info("Integer '"+self._hex(integer)+"' read from address "+self._hex(addr))
|
| | 367 | + self.logger.info("Integer '"+self._hex(integer)+"' read from address "+self._hex(addr)+"\n")
|
| 378 | 368 |
|
| 379 | 369 | @command
|
| 380 | 370 | def i2cread(self, bus, slave, addr, size):
|
| — | — | @@ -388,8 +378,11 @@ |
| 389 | 379 | slave = self._hexint(slave)
|
| 390 | 380 | addr = self._hexint(addr)
|
| 391 | 381 | size = self._hexint(size)
|
| 392 | | - for i in range(size):
|
| 393 | | - print("%02X: %02X" % (addr + i, struct.unpack("B", self.embios.i2cread(bus, slave, addr + i, 1))[0]))
|
| | 382 | + data = self.embios.i2cread(bus, slave, addr, size)
|
| | 383 | + bytes = struct.unpack("%dB" % len(data), data)
|
| | 384 | + self.logger.info("Data read from I2C:\n")
|
| | 385 | + for index, byte in enumerate(bytes):
|
| | 386 | + self.logger.info("%02X: %02X\n" % (index, byte))
|
| 394 | 387 |
|
| 395 | 388 | @command
|
| 396 | 389 | def i2cwrite(self, bus, slave, addr, *args):
|
| — | — | @@ -399,7 +392,7 @@ |
| 400 | 393 | <slave> the slave address
|
| 401 | 394 | <addr> the start address on the I2C device
|
| 402 | 395 | <db1> ... <dbN> the data in single bytes, encoded in hex,
|
| 403 | | - seperated by whitespaces, eg. 37 56 45 12
|
| | 396 | + seperated by whitespaces, eg. 37 5A 4F EB
|
| 404 | 397 | """
|
| 405 | 398 | bus = self._hexint(bus)
|
| 406 | 399 | slave = self._hexint(slave)
|
| — | — | @@ -407,7 +400,9 @@ |
| 408 | 401 | data = ""
|
| 409 | 402 | for arg in args:
|
| 410 | 403 | data += chr(self._hexint(arg))
|
| | 404 | + self.logger.info("Writing data to I2C...\n")
|
| 411 | 405 | self.embios.i2cwrite(bus, slave, addr, data)
|
| | 406 | + self.logger.info("done\n")
|
| 412 | 407 |
|
| 413 | 408 | @command
|
| 414 | 409 | def console(self):
|
| — | — | @@ -428,7 +423,7 @@ |
| 429 | 424 | for word in args:
|
| 430 | 425 | text += word + " "
|
| 431 | 426 | text = text[:-1]
|
| 432 | | - self.logger.info("Writing '"+text+"' to the usb console\n")
|
| | 427 | + self.logger.info("Writing '"+ text +"' to the usb console\n")
|
| 433 | 428 | self.embios.usbcwrite(text)
|
| 434 | 429 |
|
| 435 | 430 | @command
|
| — | — | @@ -464,7 +459,8 @@ |
| 465 | 460 | <bitmask>: the bitmask of the consoles to be flushed
|
| 466 | 461 | """
|
| 467 | 462 | bitmask = self._hexint(bitmask)
|
| 468 | | - raise NotImplementedError
|
| | 463 | + self.logger.info("Flushing consoles identified with the bitmask "+self._hex(bitmask)+"\n")
|
| | 464 | + self.embios.cflush(bitmask)
|
| 469 | 465 |
|
| 470 | 466 | @command
|
| 471 | 467 | def getprocinfo(self):
|
| — | — | @@ -514,7 +510,8 @@ |
| 515 | 511 | Suspends/resumes the thread with thread ID <threadid>
|
| 516 | 512 | """
|
| 517 | 513 | threadid = self._hexint(threadid)
|
| 518 | | - self.embios.resumethread(threadid)
|
| | 514 | + self.logger.info("Suspending the thread with the threadid "+self._hex(threadid)+"\n")
|
| | 515 | + self.embios.suspendthread(threadid)
|
| 519 | 516 |
|
| 520 | 517 | @command
|
| 521 | 518 | def resumethread(self, threadid):
|
| — | — | @@ -522,6 +519,7 @@ |
| 523 | 520 | Resumes the thread with thread ID <threadid>
|
| 524 | 521 | """
|
| 525 | 522 | threadid = self._hexint(threadid)
|
| | 523 | + self.logger.info("Resuming the thread with the threadid "+self._hex(threadid)+"\n")
|
| 526 | 524 | self.embios.resumethread(threadid)
|
| 527 | 525 |
|
| 528 | 526 | @command
|
| — | — | @@ -530,6 +528,7 @@ |
| 531 | 529 | Kills the thread with thread ID <threadid>
|
| 532 | 530 | """
|
| 533 | 531 | threadid = self._hexint(threadid)
|
| | 532 | + self.logger.info("Killing the thread with the threadid " + self._hex(threadid) + "\n")
|
| 534 | 533 | self.embios.killthread(threadid)
|
| 535 | 534 |
|
| 536 | 535 | @command
|
| — | — | @@ -549,16 +548,45 @@ |
| 550 | 549 | stackpointer = self._hexint(stackpointer)
|
| 551 | 550 | stacksize = self._hexint(stacksize)
|
| 552 | 551 | priority = self._hexint(priority)
|
| 553 | | - self.embios.createthread(nameptr, entrypoint, stackptr, stacksize, type, priority, state)
|
| | 552 | + data = self.embios.createthread(nameptr, entrypoint, stackptr, stacksize, type, priority, state)
|
| | 553 | + name = self.embios.readstring(nameptr)
|
| | 554 | + self.logger.info("Created a thread with the threadid " + data.id + ", the name \"" + name + "\", the entrypoint at " + self._hex(entrypoint) + ", the stack at " + self._hex(stackpointer) + " with a size of " + self._hex(stacksize) + " and a priority of " + self._hex(priority) + "\n")
|
| 554 | 555 |
|
| 555 | 556 | @command
|
| 556 | 557 | def run(self, filename):
|
| 557 | 558 | """
|
| 558 | 559 | Uploads the emBIOS application <filename> to
|
| 559 | | - the beginning of the user memory and executes it
|
| | 560 | + the memory and executes it
|
| 560 | 561 | """
|
| 561 | | - #self.execimage(addr)
|
| 562 | | - raise NotImplementedError
|
| | 562 | + try:
|
| | 563 | + f = open(filename, 'rb')
|
| | 564 | + except IOError:
|
| | 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")
|
| | 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 | + self.logger.info("Writing emBIOS application \"" + name + "\" to the memory at " + self._hex(baseaddr) + "...")
|
| | 581 | + f.seek(0)
|
| | 582 | + self.embios.write(baseaddr, f.read())
|
| | 583 | + except IOError:
|
| | 584 | + raise ArgumentError("The specified file is not an emBIOS application")
|
| | 585 | + except struct.error:
|
| | 586 | + raise ArgumentError("The specified file is not an emBIOS application")
|
| | 587 | + finally:
|
| | 588 | + f.close()
|
| | 589 | + self.logger.info("done\n")
|
| | 590 | + self.execimage(baseaddr)
|
| 563 | 591 |
|
| 564 | 592 | @command
|
| 565 | 593 | def execimage(self, addr):
|
| Index: embios/trunk/tools/libembios.py |
| — | — | @@ -219,12 +219,11 @@ |
| 220 | 220 |
|
| 221 | 221 | def i2cread(self, index, slaveaddr, startaddr, size):
|
| 222 | 222 | """ Reads data from an i2c slave """
|
| 223 | | - if size > 256 or size < 1:
|
| 224 | | - raise ValueError("Size must be a number between 1 and 256")
|
| 225 | | - if size == 256:
|
| 226 | | - size = 0
|
| 227 | | - resp = self.lib.monitorcommand(struct.pack("IBBBBII", 8, index, slaveaddr, startaddr, size, 0, 0), "III%ds" % size, (None, None, None, "data"))
|
| 228 | | - return resp.data
|
| | 223 | + data = ""
|
| | 224 | + for i in range(size):
|
| | 225 | + resp = self.lib.monitorcommand(struct.pack("IBBBBII", 8, index, slaveaddr, startaddr + i, 1, 0, 0), "III1s", (None, None, None, "data"))
|
| | 226 | + data += resp.data
|
| | 227 | + return data
|
| 229 | 228 |
|
| 230 | 229 | def i2cwrite(self, index, slaveaddr, startaddr, data):
|
| 231 | 230 | """ Writes data to an i2c slave """
|