freemyipod r67 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r66‎ | r67 | r68 >
Date:23:33, 9 August 2010
Author:benedikt93
Status:new
Tags:
Comment:
fix & extend libembios.py and embios.py
Modified paths:
  • /embios/trunk/tools/embios.py (modified) (history)
  • /embios/trunk/tools/libembios.py (modified) (history)

Diff [purge]

Index: embios/trunk/tools/embios.py
@@ -46,6 +46,28 @@
4747 print " If <force> is 1, the poweroff will be forced, otherwise it will be gracefully,"
4848 print " which may take some time."
4949 print ""
 50+ print " i2crecv <bus> <slave> <addr> <size>"
 51+ print " Reads data from an I2C device"
 52+ print " <bus> the bus index"
 53+ print " <slave> the slave address"
 54+ print " <addr> the start address on the I2C device"
 55+ print " <size> the number of bytes to read"
 56+ print ""
 57+ print " i2csend <bus> <slave> <addr> <db1> <db2> ... <dbN>"
 58+ print " Writes data to an I2C device"
 59+ print " <bus> the bus index"
 60+ print " <slave> the slave address"
 61+ print " <addr> the start address on the I2C device"
 62+ print " <db1> ... <dbN> the data in single bytes, seperated by whitespaces, eg. 0x37 0x56 0x45 0x12"
 63+ print ""
 64+ print " getprocessinformation <offset> <size> / getprocinfo <offset> <size>"
 65+ print " Fetches data on the currently running processes"
 66+ print " <offset> the offset in the data field"
 67+ print " <size> the number of bytes to be fetched"
 68+ print " ATTENTION: this function will be print the information to the console window."
 69+ print " If several threads are running this might overflow the window,"
 70+ print " causing not everything to be shown."
 71+ print ""
5072 print " lockscheduler"
5173 print " Locks (freezes) the scheduler"
5274 print ""
@@ -93,10 +115,23 @@
94116 if len(argv) != 3: usage()
95117 dev.poweroff(int(argv[2]))
96118
97 - elif argv[1] == "flushcaches":
98 - if len(argv) != 2: usage()
99 - dev.flushcaches()
 119+ elif argv[1] == "i2cread":
 120+ if len(argv) != 6: usage()
 121+ dev.i2crecv(int(argv[2]), int(argv[3]), int(argv[4]), int(argv[5]))
100122
 123+ elif argv[1] == "i2csend":
 124+ if len(argv) < 6: usage()
 125+ data = ""
 126+ ptr = 5
 127+ while ptr < lean(argv):
 128+ data += struct.pack("<B", int(argv[ptr]))
 129+ ptr += 1
 130+ dev.i2csend(int(argv[2]), int(argv[3]), int(argv[4]), data)
 131+
 132+ elif argv[1] == "getprocessinformation" or argv[1] == "getprocinfo":
 133+ if len(argv) != 4: usage()
 134+ dev.getprocinfo(int(argv[2]), int(argv[3]))
 135+
101136 elif argv[1] == "lockscheduler":
102137 if len(argv) != 2: usage()
103138 dev.freezescheduler(1)
@@ -121,6 +156,10 @@
122157 if len(argv) != 9: usage()
123158 dev.createthread(int(argv[2]), int(argv[3]), int(argv[4]), int(argv[5]), int(argv[6]), int(argv[7]), int(argv[8]))
124159
 160+ elif argv[1] == "flushcaches":
 161+ if len(argv) != 2: usage()
 162+ dev.flushcaches()
 163+
125164 else: usage()
126165
127166
Index: embios/trunk/tools/libembios.py
@@ -434,25 +434,27 @@
435435
436436 self.handle.bulkWrite(self.__coutep, struct.pack("<IBBBBII", 8, bus, slave, addr, size, 0, 0))
437437 data = self.__getbulk(self.handle, self.__cinep, 0x10 + size)
438 - self.__checkstatus(data)
 438+ self.__checkstatus(response)
439439
440 - self.__myprint(" done\n", silent)
 440+ self.__myprint(" done\n data was:\n%s\n" % (self.__gethexviewprintout(data[16:])), silent)
441441
442442 return data[16:]
443443
444444
445445 def i2csend(self, bus, slave, addr, data, silent = 0):
 446+ size = len(data)
446447 if (size > self.cout_maxsize - 0x10) or (size > 0xFF):
447448 raise Exception ("The data exceeds the maximum amount that can be send with this instruction.")
448449
449450 self.__myprint("Writing 0x%2x bytes to 0x%2x at I2C device at bus 0x%2x, slave adress 0x%2x ..." % (size, addr, bus, slave), silent)
450451
451 - self.handle.bulkWrite(self.__coutep, struct.pack("<IBBBBII", 9, bus, slave, addr, len(data), 0, 0) + data)
452 - self.__checkstatus(self.__readstatus())
 452+ self.handle.bulkWrite(self.__coutep, struct.pack("<IBBBBII", 9, bus, slave, addr, size, 0, 0) + data)
 453+ response = self.__getbulk(self.handle, self.__cinep, 0x10)
 454+ self.__checkstatus(response)
453455
454456 self.__myprint(" done\n", silent)
455 -
456457
 458+
457459 #=====================================================================================
458460
459461 def readusbcon(self, size, outtype = "", file = "", silent = 0):
@@ -500,10 +502,12 @@
501503 struct.unpack("<IIII", response[:0x10])[2],
502504 struct.unpack("<IIII", response[:0x10])[3])
503505 , silent)
504 - self.__myprint(self.gethexviewprintout(response[0x10:], "", 1), silent)
 506+ self.__myprint(self.__gethexviewprintout(response[0x10:], "", 1), silent)
505507 self.__myprint("\n\n", silent)
506 -
507 - elif (outtype != ""): # none of the above and also not "" which would be return only
 508+
 509+ elif (outtype == ""):
 510+ pass # return only
 511+ else:
508512 raise Exception ("Invalid argument for <outtype>: '%s'." % (outtype))
509513
510514 self.__myprint(" done\n", silent)
@@ -638,11 +642,12 @@
639643
640644 out = []
641645 out[0] = struct.unpack("<I", response[4:8])[0] # Process information struct version
642 - out[1] = struct.unpack("<I", response[4:8])[0] # Process information table size
 646+ out[1] = struct.unpack("<I", response[8:12])[0] # Process information table size
 647+ out[2] = response # raw received data
643648
644649 if (struct.unpack("<I", response[4:8])[0] == 1): # Process information struct version == 1
645650 p = 0x10
646 - process_n = 2 # actually process 0, but there are alread two other elements in out
 651+ process_n = 3 # actually process 0, but there are alread three other elements in out
647652 while True:
648653 # regs ==================================================
649654 keylen = 16
@@ -829,14 +834,47 @@
830835
831836 process_n += 1
832837
 838+ procinfoprint = ""
833839
 840+ try:
 841+ i = 0
 842+ while (out[0] == 1) and (!silent): # Process information struct version == 1 && !silent
 843+ processinfoprint += "--------------------------------------------------------------------------------"
 844+ processinfoprint += "R0: 0x%08x, R1: 0x%08x, R2: 0x%08x, R3: 0x%08x,\n\
 845+ R4: 0x%08x, R5: 0x%08x, R6: 0x%08x, R7: 0x%08x,\n\
 846+ R8: 0x%08x, R9: 0x%08x, R10: 0x%08x, R11: 0x%08x,\n\
 847+ R12: 0x%08x, R13: 0x%08x, LR: 0x%08x, PC: 0x%08x\n" \
 848+ % (out[i+3]['regs'][0], out[i+3]['regs'][1], out[i+3]['regs'][2], out[i+3]['regs'][3], \
 849+ out[i+3]['regs'][4], out[i+3]['regs'][5], out[i+3]['regs'][6], out[i+3]['regs'][7], \
 850+ out[i+3]['regs'][8], out[i+3]['regs'][9], out[i+3]['regs'][10], out[i+3]['regs'][11], \
 851+ out[i+3]['regs'][12], out[i+3]['regs'][13], out[i+3]['regs'][14], out[i+3]['regs'][15] )
 852+ processinfoprint += "cpsr: 0b%032b " % (out[i+3]['cpsr'])
 853+ states = ["THREAD_FREE", "THREAD_SUSPENDED", "THREAD_READY", "THREAD_RUNNING", "THREAD_BLOCKED", "THREAD_DEFUNCT", "THREAD_DEFUNCT_ACK"]
 854+ processinfoprint += "state: %s " % (states[out[i+3]['state']])
 855+ processinfoprint += "nameptr: 0x%08x\n" % (out[i+3]['namepointer'])
 856+ processinfoprint += "current cpu time: 0x%08x " % (out[i+3]['cputime_current'])
 857+ processinfoprint += "total cpu time: 0x%016x\n" % (out[i+3]['cputime_total'])
 858+ processinfoprint += "startusec: 0x%08x " % (out[i+3]['startusec'])
 859+ processinfoprint += "queue next ptr: 0x%08x\n" % (out[i+3]['queue_next_pointer'])
 860+ processinfoprint += "timeout: 0x%08x\n" % (out[i+3]['timeout'])
 861+ processinfoprint += "blocked since: 0x%08x " % (out[i+3]['blocked_since'])
 862+ processinfoprint += "blocked by ptr: 0x%08x\n" % (out[i+3]['blocked_by_pointer'])
 863+ processinfoprint += "stackptr: 0x%08x " % (out[i+3]['stackpointer'])
 864+ blocktype = ["THREAD_NOT_BLOCKED", "THREAD_BLOCK_SLEEP", "THREAD_BLOCK_MUTEX", "THREAD_BLOCK_WAKEUP", "THREAD_DEFUNCT_STKOV", "THREAD_DEFUNCT_PANIC"]
 865+ processinfoprint += "block type: %s\n" % (blocktype[out[i+3]['block_type']])
 866+ threadtype = ["USER_THREAD", "SYSTEM_THREAD"]
 867+ processinfoprint += "thread type: %s\n" % (threadtype[out[i+3]['thread_type']])
 868+ processinfoprint += "priority: 0x%02x " % (out[i+3]['priority'])
 869+ processinfoprint += "cpu load: 0x%02x\n" % (out[i+3]['cpuload'])
 870+
 871+ except IndexError:
 872+ processinfoprint += "--------------------------------------------------------------------------------"
834873
835 -
836874 self.__myprint(" done\n\
837875 Process information struct version: 0x%8x\n\
838876 Total size of process information table: 0x%8x\n\
839877 %s"
840 - % (struct.unpack("<I", response[4:8]), struct.unpack("<I", response[8:12]), hexprint)
 878+ % (out[0], out[1], procinfoprint)
841879 , silent)
842880
843881 return out