freemyipod r402 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r401‎ | r402 | r403 >
Date:03:58, 30 December 2010
Author:farthen
Status:new
Tags:
Comment:
embios.py/libembios.py: update docstrings
Modified paths:
  • /embios/trunk/tools/embios.py (modified) (history)
  • /embios/trunk/tools/libembios.py (modified) (history)

Diff [purge]

Index: embios/trunk/tools/embios.py
@@ -21,6 +21,11 @@
2222 #
2323 #
2424
 25+"""
 26+ Command line interface to communicate with emBIOS devices.
 27+ Run it without arguments to see usage information.
 28+"""
 29+
2530 import sys
2631 import os
2732 import time
@@ -71,8 +76,8 @@
7277 for arg in doc[function]['args']:
7378 logger.log("<" + arg + "> ")
7479 if doc[function]['kwargs']:
75 - for kwarg in doc[function]['kwargs']:
76 - logger.log("[" + kwarg + "] ")
 80+ for kwvalue, kwarg in enumerate(doc[function]['kwargs']):
 81+ logger.log("[" + kwarg + " = " + str(kwvalue) + "] ")
7782 if doc[function]['varargs']:
7883 logger.log("<db1> ... <dbN>")
7984 logger.log("\n")
@@ -235,7 +240,7 @@
236241 def reset(self, force=False):
237242 """
238243 Resets the device"
239 - If <force> is 1, the reset will be forced, otherwise it will be gracefully,
 244+ If [force] is 1, the reset will be forced, otherwise it will be gracefully,
240245 which may take some time.
241246 """
242247 force = self._bool(force)
@@ -247,7 +252,7 @@
248253 def poweroff(self, force=False):
249254 """
250255 Powers the device off
251 - If <force> is 1, the poweroff will be forced, otherwise it will be gracefully,
 256+ If [force] is 1, the poweroff will be forced, otherwise it will be gracefully,
252257 which may take some time.
253258 """
254259 force = self._bool(force)
@@ -328,10 +333,10 @@
329334 def i2cread(self, bus, slave, addr, size):
330335 """
331336 Reads data from an I2C device
332 - <bus> the bus index
333 - <slave> the slave address
334 - <addr> the start address on the I2C device
335 - <size> the number of bytes to read
 337+ <bus>: the bus index
 338+ <slave>: the slave address
 339+ <addr>: the start address on the I2C device
 340+ <size>: the number of bytes to read
336341 """
337342 bus = self._hexint(bus)
338343 slave = self._hexint(slave)
@@ -347,10 +352,10 @@
348353 def i2cwrite(self, bus, slave, addr, *args):
349354 """
350355 Writes data to an I2C device
351 - <bus> the bus index
352 - <slave> the slave address
353 - <addr> the start address on the I2C device
354 - <db1> ... <dbN> the data in single bytes, encoded in hex,
 356+ <bus>: the bus index
 357+ <slave>: the slave address
 358+ <addr>: the start address on the I2C device
 359+ <db1> ... <dbN>: the data in single bytes, encoded in hex,
355360 seperated by whitespaces, eg. 37 5A 4F EB
356361 """
357362 bus = self._hexint(bus)
@@ -510,13 +515,13 @@
511516 def createthread(self, nameptr, entrypoint, stackptr, stacksize, threadtype, priority, state):
512517 """
513518 Creates a new thread and returns its thread ID
514 - <namepointer> a pointer to the thread's name
515 - <entrypoint> a pointer to the entrypoint of the thread
516 - <stackpointer> a pointer to the stack of the thread
517 - <stacksize> the size of the thread's stack
518 - <type> the thread type, vaild are: 0 => user thread, 1 => system thread
519 - <priority> the priority of the thread, from 1 to 255
520 - <state> the thread's initial state, valid are: 1 => ready, 0 => suspended
 519+ <namepointer>: a pointer to the thread's name
 520+ <entrypoint>: a pointer to the entrypoint of the thread
 521+ <stackpointer>: a pointer to the stack of the thread
 522+ <stacksize>: the size of the thread's stack
 523+ <type>: the thread type, vaild are: 0 => user thread, 1 => system thread
 524+ <priority>: the priority of the thread, from 1 to 255
 525+ <state>: the thread's initial state, valid are: 1 => ready, 0 => suspended
521526 """
522527 nameptr = self._hexint(nameptr)
523528 entrypoint = self._hexint(entrypoint)
@@ -586,7 +591,7 @@
587592 This may BRICK your device (unless it has a good recovery option)
588593 <addr_mem>: the address in memory to copy the data from
589594 <addr_bootflsh>: the address in bootflash to write to
590 - <force>: Use this flag to suppress the 5 seconds delay
 595+ [force]: Use this flag to suppress the 5 seconds delay
591596 """
592597 addr_flash = self._hexint(addr_flash)
593598 addr_mem = self._hexint(addr_mem)
@@ -605,8 +610,8 @@
606611 @command
607612 def runfirmware(self, addr, filename):
608613 """
609 - Uploads the firmware in 'filename' to the beginning of the
610 - user memory and executes it
 614+ Uploads the firmware in <filename>
 615+ to the address at <addr> and executes it.
611616 """
612617 addr = self._hexint(addr)
613618 self.uploadfile(addr, filename)
@@ -615,7 +620,7 @@
616621 @command
617622 def execfirmware(self, addr):
618623 """
619 - Executes the firmware at addr
 624+ Executes the firmware at <addr>
620625 """
621626 addr = self._hexint(addr)
622627 self.logger.info("Running firmware at "+self._hex(addr)+". Bye.")
@@ -625,6 +630,9 @@
626631 def aesencrypt(self, addr, size, keyindex):
627632 """
628633 Encrypts a buffer using a hardware key
 634+ <addr>: the starting address of the buffer
 635+ <size>: the size of the buffer
 636+ <keyindex>: the index of the key in the crypto unit
629637 """
630638 addr = self._hexint(addr)
631639 size = self._hexint(size)
@@ -635,6 +643,9 @@
636644 def aesdecrypt(self, addr, size, keyindex):
637645 """
638646 Decrypts a buffer using a hardware key
 647+ <addr>: the starting address of the buffer
 648+ <size>: the size of the buffer
 649+ <keyindex>: the index of the key in the crypto unit
639650 """
640651 addr = self._hexint(addr)
641652 size = self._hexint(size)
@@ -644,7 +655,10 @@
645656 @command
646657 def hmac_sha1(self, addr, size, destination):
647658 """
648 - Generates a HMAC-SHA1 hash of the buffer and saves it to 'destination'
 659+ Generates a HMAC-SHA1 hash of the buffer
 660+ <addr>: the starting address of the buffer
 661+ <size>: the size of the buffer
 662+ <destination>: the location where the key will be stored
649663 """
650664 addr = self._hexint(addr)
651665 size = self._hexint(size)
@@ -677,11 +691,16 @@
678692 """
679693 Target-specific function: ipodnano2g
680694 Reads data from the NAND chip into memory
 695+ <addr>: the memory location where the data is written to
 696+ <start>: start block
 697+ <count>: block count
 698+ <doecc>: FIXME
 699+ <checkempty>: FIXME
681700 """
682701 addr = self._hexint(addr)
683702 start = self._hexint(start)
684703 count = self._hexint(count)
685 - doecc = int(doecc)
 704+ doecc = int(doecc) # FIXME shouldn't this be bool?
686705 checkempty = int(checkempty)
687706 self.logger.info("Reading " + self._hex(count) + " NAND pages starting at " + \
688707 self._hex(start) + " to " + self._hex(addr) + "...")
@@ -693,11 +712,15 @@
694713 """
695714 Target-specific function: ipodnano2g
696715 Writes data to the NAND chip
 716+ <addr>: the memory location where the data is read from
 717+ <start>: start block
 718+ <count>: block count
 719+ <doecc>: FIXME
697720 """
698721 addr = self._hexint(addr)
699722 start = self._hexint(start)
700723 count = self._hexint(count)
701 - doecc = int(doecc)
 724+ doecc = int(doecc) # FIXME shouldn't this be bool?
702725 self.logger.info("Writing " + self._hex(count) + " NAND pages starting at " + \
703726 self._hex(start) + " from " + self._hex(addr) + "...")
704727 self.embios.ipodnano2g_nandwrite(addr, start, count, doecc)
@@ -708,6 +731,9 @@
709732 """
710733 Target-specific function: ipodnano2g
711734 Erases blocks on the NAND chip and stores the results to memory
 735+ <addr>: the memory location where the results are stored
 736+ <start>: start block
 737+ <count>: block count
712738 """
713739 addr = self._hexint(addr)
714740 start = self._hexint(start)
@@ -722,6 +748,7 @@
723749 """
724750 Target-specific function: ipodnano2g
725751 Dumps the whole NAND chip to four files
 752+ <filenameprefix>: prefix of the files that will be created
726753 """
727754 info = self.embios.ipodnano2g_getnandinfo()
728755 self.logger.info("Dumping NAND contents...")
@@ -754,7 +781,8 @@
755782 """
756783 Target-specific function: ipodnano2g
757784 Wipes the whole NAND chip and logs the result to a file
758 - <force>: Use this flag to suppress the 5 seconds delay
 785+ <filename>: location of the log file
 786+ [force]: use this flag to suppress the 5 seconds delay
759787 """
760788 self.logger.warn("Wiping the whole NAND chip!\n")
761789 if force == False:
@@ -797,6 +825,7 @@
798826 def getvolumeinfo(self, volume):
799827 """
800828 Gathers some information about a storage volume used
 829+ <volume>: FIXME
801830 """
802831 volume = self._hexint(volume)
803832 data = self.embios.storage_get_info(volume)
@@ -836,7 +865,7 @@
837866 def readrawstoragefile(self, volume, sector, count, file, buffer = False, buffsize = "100000"):
838867 """
839868 Reads <count> sectors starting at <sector> from storage <volume> to file <file>,
840 - buffering them in memory at <buffer> in chunks of <buffsize> bytes (both optional).
 869+ buffering them in memory at [buffer] in chunks of [buffsize] bytes (both optional).
841870 """
842871 volume = self._hexint(volume)
843872 sector = self._hexint(sector)
@@ -863,7 +892,7 @@
864893 def writerawstoragefile(self, volume, sector, count, file, buffer = False, buffsize = "100000"):
865894 """
866895 Writes contents of <file> to <count> sectors starting at <sector> on storage <volume>,
867 - buffering them in memory at <buffer> in chunks of <buffsize> bytes (both optional).
 896+ buffering them in memory at [buffer] in chunks of [buffsize] bytes (both optional).
868897 """
869898 volume = self._hexint(volume)
870899 sector = self._hexint(sector)
@@ -893,7 +922,7 @@
894923 @command
895924 def mkdir(self, dirname):
896925 """
897 - Creates a directory
 926+ Creates a directory with the name <dirname>
898927 """
899928 self.logger.info("Creating directory " + dirname + "...")
900929 self.embios.dir_create(dirname)
@@ -902,7 +931,7 @@
903932 @command
904933 def rmdir(self, dirname):
905934 """
906 - Removes an empty directory
 935+ Removes an empty directory with the name <dirname>
907936 """
908937 self.logger.info("Removing directory " + dirname + "...")
909938 self.embios.dir_remove(dirname)
@@ -911,7 +940,7 @@
912941 @command
913942 def rm(self, filename):
914943 """
915 - Removes a file
 944+ Removes a file with the name <filename>
916945 """
917946 self.logger.info("Removing file " + filename + "...")
918947 self.embios.file_unlink(filename)
@@ -920,7 +949,7 @@
921950 @command
922951 def mv(self, oldname, newname):
923952 """
924 - Renames or moves a file or directory
 953+ Renames or moves file or directory <oldname> to <newname>
925954 """
926955 self.logger.info("Renaming " + oldname + " to " + newname + "...")
927956 self.embios.file_rename(oldname, newname)
@@ -930,6 +959,10 @@
931960 def get(self, remotename, localname, buffer = False, buffsize = "10000"):
932961 """
933962 Downloads a file
 963+ <remotename>: filename on the device
 964+ <localname>: filename on the computer
 965+ [buffer]: buffer address (optional)
 966+ [buffsize]: buffer size (optional)
934967 """
935968 if buffer == False: buffer = self.embios.lib.dev.usermem.lower
936969 else: buffer = self._hexint(buffer)
@@ -953,6 +986,10 @@
954987 def put(self, localname, remotename, buffer = False, buffsize = "10000"):
955988 """
956989 Uploads a file
 990+ <remotename>: filename on the device
 991+ <localname>: filename on the computer
 992+ [buffer]: buffer address (optional)
 993+ [buffsize]: buffer size (optional)
957994 """
958995 if buffer == False: buffer = self.embios.lib.dev.usermem.lower
959996 else: buffer = self._hexint(buffer)
@@ -978,6 +1015,7 @@
9791016 def ls(self, path = "/"):
9801017 """
9811018 Lists all files in the specified path
 1019+ [path]: the path which is listed
9821020 """
9831021 handle = self.embios.dir_open(path)
9841022 self.logger.info("Directory listing of " + path + ":\n")
Index: embios/trunk/tools/libembios.py
@@ -21,6 +21,11 @@
2222 #
2323 #
2424
 25+"""
 26+ emBIOS client library.
 27+ Provides functions to communicate with emBIOS devices via the USB bus.
 28+"""
 29+
2530 import sys
2631 import struct
2732 import usb.core