freemyipod r394 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r393‎ | r394 | r395 >
Date:02:54, 29 December 2010
Author:farthen
Status:new
Tags:
Comment:
libembios: Implement basic timeout handling that lasts for the duration of one function and that can easily be overridden from external programs like embios.py.
Modified paths:
  • /embios/trunk/tools/libembios.py (modified) (history)

Diff [purge]

Index: embios/trunk/tools/libembios.py
@@ -26,6 +26,8 @@
2727 import usb.core
2828 import libembiosdata
2929
 30+from functools import wraps
 31+
3032 class Error(Exception):
3133 def __init__(self, value=None):
3234 self.value = value
@@ -66,9 +68,47 @@
6769 self.__dict__ = self
6870
6971
 72+def command(timeout = None):
 73+ """
 74+ Decorator for all commands.
 75+ It adds the "timeout" variable to all commands.
 76+ It also provides the possibility to set the timeout directly in the decorator.
 77+ It also includes some dirty hacks to not learn from.
 78+ """
 79+ time = timeout # dirty hack because otherwise it would raise a scoping problem.
 80+ # The reason is probably because I suck but I can't find any good explanation of this.
 81+ def decorator(func):
 82+ @wraps(func)
 83+ def wrapper(*args, **kwargs):
 84+ # precommand stuff
 85+ self = args[0] # little cheat as it expects self being always the first argument
 86+ timeout = None
 87+ if "timeout" in kwargs.keys():
 88+ timeout = kwargs['timeout']
 89+ elif time is not None:
 90+ timeout = time
 91+ if timeout is not None:
 92+ oldtimeout = self.lib.dev.timeout
 93+ self.lib.dev.timeout = timeout
 94+ # function call
 95+ ret = func(*args)
 96+ # postcommand stuff
 97+ if timeout is not None:
 98+ self.lib.dev.timeout = oldtimeout
 99+ return ret
 100+ return wrapper
 101+ return decorator
 102+
 103+
70104 class Embios(object):
71105 """
72106 Class for all embios functions.
 107+ They all get the "@command()" decorator.
 108+ This decorator has a timeout variable that can be set to change the
 109+ device timeout for the duration of the function.
 110+ It also adds a "timeout" argument to every function to access this
 111+ feature from external. So DON'T EVER use a parameter called 'timeout'
 112+ in your commands. Variables are ok.
73113 """
74114 def __init__(self):
75115 self.lib = Lib()
@@ -91,6 +131,7 @@
92132 tailsize = end - tailaddr
93133 return (headsize, tailaddr - bodyaddr, tailsize)
94134
 135+ @command()
95136 def _readmem(self, addr, size):
96137 """ Reads the memory from location 'addr' with size 'size'
97138 from the device.
@@ -97,7 +138,8 @@
98139 """
99140 resp = self.lib.monitorcommand(struct.pack("IIII", 4, addr, size, 0), "III%ds" % size, (None, None, None, "data"))
100141 return resp.data
101 -
 142+
 143+ @command()
102144 def _writemem(self, addr, data):
103145 """ Writes the data in 'data' to the location 'addr'
104146 in the memory of the device.
@@ -104,6 +146,7 @@
105147 """
106148 return self.lib.monitorcommand(struct.pack("IIII%ds" % len(data), 5, addr, len(data), 0, data), "III", (None, None, None))
107149
 150+ @command()
108151 def _readdma(self, addr, size):
109152 """ Reads the memory from location 'addr' with size 'size'
110153 from the device. This uses DMA and the data in endpoint.
@@ -111,6 +154,7 @@
112155 self.lib.monitorcommand(struct.pack("IIII", 6, addr, size, 0), "III", (None, None, None))
113156 return struct.unpack("%ds" % size, self.lib.dev.din(size))[0]
114157
 158+ @command()
115159 def _writedma(self, addr, data):
116160 """ Writes the data in 'data' to the location 'addr'
117161 in the memory of the device. This uses DMA and the data out endpoint.
@@ -118,6 +162,7 @@
119163 self.lib.monitorcommand(struct.pack("IIII", 7, addr, len(data), 0), "III", (None, None, None))
120164 return self.lib.dev.dout(data)
121165
 166+ @command()
122167 def getversioninfo(self):
123168 """ This returns the emBIOS version and device information. """
124169 resp = self.lib.monitorcommand(struct.pack("IIII", 1, 0, 0, 0), "IBBBBI", ("revision", "majorv", "minorv", "patchv", "swtypeid", "hwtypeid"))
@@ -129,6 +174,7 @@
130175 self.lib.dev.hwtypeid = resp.hwtypeid
131176 return resp
132177
 178+ @command()
133179 def getpacketsizeinfo(self):
134180 """ This returns the emBIOS max packet size information.
135181 It also sets the properties of the device object accordingly.
@@ -140,6 +186,7 @@
141187 self.lib.dev.packetsizelimit.dout = resp.doutmax
142188 return resp
143189
 190+ @command()
144191 def getusermemrange(self):
145192 """ This returns the memory range the user has access to. """
146193 resp = self.lib.monitorcommand(struct.pack("IIII", 1, 2, 0, 0), "III", ("lower", "upper", None))
@@ -147,6 +194,7 @@
148195 self.lib.dev.usermem.upper = resp.upper
149196 return resp
150197
 198+ @command()
151199 def reset(self, force=False):
152200 """ Reboot the device """
153201 if force:
@@ -154,6 +202,7 @@
155203 else:
156204 return self.lib.monitorcommand(struct.pack("IIII", 2, 1, 0, 0), "III", (None, None, None))
157205
 206+ @command()
158207 def poweroff(self, force=False):
159208 """ Powers the device off. """
160209 if force:
@@ -161,6 +210,7 @@
162211 else:
163212 return self.lib.monitorcommand(struct.pack("IIII", 3, 1, 0, 0), "III", (None, None, None))
164213
 214+ @command()
165215 def read(self, addr, size):
166216 """ Reads the memory from location 'addr' with size 'size'
167217 from the device. This cares about too long packages
@@ -186,6 +236,7 @@
187237 data += self._readmem(addr, tailsize)
188238 return data
189239
 240+ @command()
190241 def write(self, addr, data):
191242 """ Writes the data in 'data' to the location 'addr'
192243 in the memory of the device. This cares about too long packages
@@ -213,6 +264,7 @@
214265 self._writemem(addr, data[offset:offset+tailsize])
215266 return data
216267
 268+ @command()
217269 def readstring(self, addr, maxlength = 256):
218270 """ Reads a zero terminated string from memory
219271 Reads only a maximum of 'maxlength' chars.
@@ -230,6 +282,7 @@
231283 addr += cin_maxsize
232284 return string
233285
 286+ @command()
234287 def i2cread(self, index, slaveaddr, startaddr, size):
235288 """ Reads data from an i2c slave """
236289 data = ""
@@ -238,6 +291,7 @@
239292 data += resp.data
240293 return data
241294
 295+ @command()
242296 def i2cwrite(self, index, slaveaddr, startaddr, data):
243297 """ Writes data to an i2c slave """
244298 size = len(data)
@@ -247,6 +301,7 @@
248302 size = 0
249303 return self.lib.monitorcommand(struct.pack("IBBBBII%ds" % size, 9, index, slaveaddr, startaddr, size, 0, 0, data), "III", (None, None, None))
250304
 305+ @command()
251306 def usbcread(self):
252307 """ Reads one packet with the maximal cin size """
253308 cin_maxsize = self.lib.dev.packetsizelimit.cin - self.lib.headersize
@@ -255,6 +310,7 @@
256311 resp.maxsize = cin_maxsize
257312 return resp
258313
 314+ @command()
259315 def usbcwrite(self, data):
260316 """ Writes data to the USB console """
261317 cin_maxsize = self.lib.dev.packetsizelimit.cin - self.lib.headersize
@@ -265,6 +321,7 @@
266322 data = data[resp.validsize:]
267323 return size
268324
 325+ @command()
269326 def cread(self, bitmask=0x1):
270327 """ Reads one packet with the maximal cin size from the device consoles
271328 identified with the specified bitmask
@@ -274,7 +331,8 @@
275332 resp.data = resp.data[size:]
276333 resp.maxsize = cin_maxsize
277334 return resp
278 -
 335+
 336+ @command()
279337 def cwrite(self, data, bitmask=0x1):
280338 """ Writes data to the device consoles
281339 identified with the specified bitmask.
@@ -287,10 +345,12 @@
288346 data = data[writesize:]
289347 return size
290348
 349+ @command()
291350 def cflush(self, bitmask):
292351 """ Flushes the consoles specified with 'bitmask' """
293352 return self.lib.monitorcommand(struct.pack("IIII", 14, bitmask, 0, 0), "III", (None, None, None))
294353
 354+ @command()
295355 def getprocinfo(self):
296356 """ Gets current state of the scheduler """
297357 cin_maxsize = self.lib.dev.packetsizelimit.cin - self.lib.headersize
@@ -355,28 +415,34 @@
356416 id += 1
357417 return threads
358418
 419+ @command()
359420 def lockscheduler(self, freeze=True):
360421 """ Freezes/Unfreezes the scheduler """
361422 resp = self.lib.monitorcommand(struct.pack("IIII", 16, 1 if freeze else 0, 0, 0), "III", ("before", None, None))
362423 return True if resp.before == 1 else False
363424
 425+ @command()
364426 def unlockscheduler(self):
365427 """ Unfreezes the scheduler """
366428 return self.lib.monitorcommand(struct.pack("IIII", 16, 0, 0, 0), "III", ("before", None, None))
367429
 430+ @command()
368431 def suspendthread(self, id, suspend=True):
369432 """ Suspends the thread with the specified id """
370433 resp = self.lib.monitorcommand(struct.pack("IIII", 17, 1 if suspend else 0, id, 0), "III", ("before", None, None))
371434 return True if resp.before == 1 else False
372435
 436+ @command()
373437 def resumethread(self, id):
374438 """ Resumes the thread with the specified id """
375439 return self.lib.monitorcommand(struct.pack("IIII", 17, 0, id, 0), "III", ("before", None, None))
376440
 441+ @command()
377442 def killthread(self, id):
378443 """ Kills the thread with the specified id """
379444 return self.lib.monitorcommand(struct.pack("IIII", 18, id, 0, 0), "III", ("before", None, None))
380445
 446+ @command()
381447 def createthread(self, nameptr, entrypoint, stackptr, stacksize, threadtype, priority, state):
382448 """ Creates a thread with the specified attributes """
383449 if threadtype == "user":
@@ -398,14 +464,17 @@
399465 raise DeviceError("The device returned the error code "+str(resp.id))
400466 return resp
401467
 468+ @command()
402469 def flushcaches(self):
403470 """ Flushes the CPU instruction and data cache """
404471 return self.lib.monitorcommand(struct.pack("IIII", 20, 0, 0, 0), "III", (None, None, None))
405472
 473+ @command()
406474 def execimage(self, addr):
407475 """ Runs the emBIOS app at 'addr' """
408476 return self.lib.monitorcommand(struct.pack("IIII", 21, addr, 0, 0), "III", ("rc", None, None))
409477
 478+ @command()
410479 def run(self, app):
411480 """ Uploads and runs the emBIOS app in the string 'app' """
412481 try:
@@ -435,6 +504,7 @@
436505 self.execimage(baseaddr)
437506 return Bunch(baseaddr=baseaddr, name=name)
438507
 508+ @command()
439509 def bootflashread(self, memaddr, flashaddr, size):
440510 """ Copies the data in the bootflash at 'flashaddr' of the specified size
441511 to the memory at addr 'memaddr'
@@ -441,6 +511,7 @@
442512 """
443513 return self.lib.monitorcommand(struct.pack("IIII", 22, memaddr, flashaddr, size), "III", (None, None, None))
444514
 515+ @command()
445516 def bootflashwrite(self, memaddr, flashaddr, size):
446517 """ Copies the data in the memory at 'memaddr' of the specified size
447518 to the boot flash at addr 'flashaddr'
@@ -447,10 +518,12 @@
448519 """
449520 return self.lib.monitorcommand(struct.pack("IIII", 23, memaddr, flashaddr, size), "III", (None, None, None))
450521
 522+ @command()
451523 def execfirmware(self, addr):
452524 """ Executes the firmware at 'addr' and passes all control to it. """
453525 return self.lib.monitorcommand(struct.pack("IIII", 24, addr, 0, 0))
454526
 527+ @command()
455528 def aesencrypt(self, addr, size, keyindex):
456529 """ Encrypts the buffer at 'addr' with the specified size
457530 with the hardware AES key index 'keyindex'
@@ -457,6 +530,7 @@
458531 """
459532 return self.lib.monitorcommand(struct.pack("IBBHII", 25, 1, 0, keyindex, addr, size), "III", (None, None, None))
460533
 534+ @command()
461535 def aesdecrypt(self, addr, size, keyindex):
462536 """ Decrypts the buffer at 'addr' with the specified size
463537 with the hardware AES key index 'keyindex'
@@ -463,10 +537,12 @@
464538 """
465539 return self.lib.monitorcommand(struct.pack("IBBHII", 25, 0, 0, keyindex, addr, size), "III", (None, None, None))
466540
 541+ @command()
467542 def hmac_sha1(self, addr, size, destination):
468543 """ Generates a HMAC-SHA1 hash of the buffer and saves it to 'destination' """
469544 return self.lib.monitorcommand(struct.pack("IIII", 26, addr, size, destination), "III", (None, None, None))
470545
 546+ @command()
471547 def ipodnano2g_getnandinfo(self):
472548 """ Target-specific function: ipodnano2g
473549 Gathers some information about the NAND chip used
@@ -474,6 +550,7 @@
475551 if self.lib.dev.hwtypeid != 0x47324e49: raise DeviceError("Wrong device for target-specific command.")
476552 return self.lib.monitorcommand(struct.pack("IIII", 0xffff0001, 0, 0, 0), "IHHHH", ("type", "pagesperblock", "banks", "userblocks", "blocks"))
477553
 554+ @command()
478555 def ipodnano2g_nandread(self, addr, start, count, doecc, checkempty):
479556 """ Target-specific function: ipodnano2g
480557 Reads data from the NAND chip into memory
@@ -481,6 +558,7 @@
482559 if self.lib.dev.hwtypeid != 0x47324e49: raise DeviceError("Wrong device for target-specific command.")
483560 return self.lib.monitorcommand(struct.pack("IIII", 0xffff0002, addr | (0x80000000 if doecc != 0 else 0) | (0x40000000 if checkempty != 0 else 0), start, count), "III", (None, None, None))
484561
 562+ @command()
485563 def ipodnano2g_nandwrite(self, addr, start, count, doecc):
486564 """ Target-specific function: ipodnano2g
487565 Writes data to the NAND chip
@@ -488,6 +566,7 @@
489567 if self.lib.dev.hwtypeid != 0x47324e49: raise DeviceError("Wrong device for target-specific command.")
490568 return self.lib.monitorcommand(struct.pack("IIII", 0xffff0003, addr | (0x80000000 if doecc != 0 else 0), start, count), "III", (None, None, None))
491569
 570+ @command()
492571 def ipodnano2g_nanderase(self, addr, start, count):
493572 """ Target-specific function: ipodnano2g
494573 Erases blocks on the NAND chip and stores the results to memory
@@ -495,6 +574,7 @@
496575 if self.lib.dev.hwtypeid != 0x47324e49: raise DeviceError("Wrong device for target-specific command.")
497576 return self.lib.monitorcommand(struct.pack("IIII", 0xffff0004, addr, start, count), "III", (None, None, None))
498577
 578+ @command()
499579 def ipodclassic_gethddinfo(self):
500580 """ Target-specific function: ipodclassic
501581 Gather information about the hard disk drive
@@ -502,6 +582,7 @@
503583 if self.lib.dev.hwtypeid != 0x4c435049: raise DeviceError("Wrong device for target-specific command.")
504584 return self.lib.monitorcommand(struct.pack("IIII", 0xffff0001, 0, 0, 0), "IQQII", ("identifyptr", "totalsectors", "virtualsectors", "bbtptr", "bbtsize"))
505585
 586+ @command()
506587 def ipodclassic_hddaccess(self, type, sector, count, addr):
507588 """ Target-specific function: ipodclassic
508589 Access the hard disk, type = 0 (read) / 1 (write)
@@ -511,6 +592,7 @@
512593 if (rc > 0x80000000):
513594 raise DeviceError("HDD access (type=%d, sector=%d, count=%d, addr=0x%08X) failed with RC 0x%08X" % (type, sector, count, addr, rc))
514595
 596+ @command()
515597 def ipodclassic_writebbt(self, bbt, tempaddr):
516598 """ Target-specific function: ipodclassic
517599 Write hard drive bad block table
@@ -538,6 +620,7 @@
539621 count = 1
540622 self.ipodclassic_hddaccess(1, sector, count, tempaddr + offset)
541623
 624+ @command()
542625 def storage_get_info(self, volume):
543626 """ Get information about a storage device """
544627 result = self.lib.monitorcommand(struct.pack("IIII", 27, volume, 0, 0), "IIIIIIII", ("version", None, None, "sectorsize", "numsectors", "vendorptr", "productptr", "revisionptr"))
@@ -548,18 +631,21 @@
549632 result.revision = self.readstring(result.revisionptr)
550633 return result
551634
 635+ @command()
552636 def storage_read_sectors_md(self, volume, sector, count, addr):
553637 """ Read sectors from as storage device """
554638 result = self.lib.monitorcommand(struct.pack("IIQIIII", 28, volume, sector, count, addr, 0, 0), "III", ("rc", None, None, None))
555639 if result.rc > 0x80000000:
556640 raise DeviceError("storage_read_sectors_md(volume=%d, sector=%d, count=%d, addr=0x%08X) failed with RC 0x%08X" % (volume, sector, count, addr, rc))
557 -
 641+
 642+ @command()
558643 def storage_write_sectors_md(self, volume, sector, count, addr):
559644 """ Read sectors from as storage device """
560645 result = self.lib.monitorcommand(struct.pack("IIQIIII", 29, volume, sector, count, addr, 0, 0), "III", ("rc", None, None, None))
561646 if result.rc > 0x80000000:
562647 raise DeviceError("storage_read_sectors_md(volume=%d, sector=%d, count=%d, addr=0x%08X) failed with RC 0x%08X" % (volume, sector, count, addr, rc))
563 -
 648+
 649+ @command()
564650 def file_open(self, filename, mode):
565651 """ Opens a file and returns the handle """
566652 result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(filename), 30, mode, 0, 0, filename, 0), "III", ("fd", None, None))
@@ -567,6 +653,7 @@
568654 raise DeviceError("file_open(filename=\"%s\", mode=0x%X) failed with RC=0x%08X, errno=%d" % (filename, mode, result.fd, self.errno()))
569655 return result.fd
570656
 657+ @command()
571658 def file_size(self, fd):
572659 """ Gets the size of a file referenced by a handle """
573660 result = self.lib.monitorcommand(struct.pack("IIII", 31, fd, 0, 0), "III", ("size", None, None))
@@ -573,7 +660,8 @@
574661 if result.size > 0x80000000:
575662 raise DeviceError("file_size(fd=%d) failed with RC=0x%08X, errno=%d" % (fd, result.size, self.errno()))
576663 return result.size
577 -
 664+
 665+ @command()
578666 def file_read(self, fd, addr, size):
579667 """ Reads data from a file referenced by a handle """
580668 result = self.lib.monitorcommand(struct.pack("IIII", 32, fd, addr, size), "III", ("rc", None, None))
@@ -580,7 +668,8 @@
581669 if result.rc > 0x80000000:
582670 raise DeviceError("file_read(fd=%d, addr=0x%08X, size=0x%08X) failed with RC=0x%08X, errno=%d" % (fd, addr, size, result.rc, self.errno()))
583671 return result.rc
584 -
 672+
 673+ @command()
585674 def file_write(self, fd, addr, size):
586675 """ Writes data from a file referenced by a handle """
587676 result = self.lib.monitorcommand(struct.pack("IIII", 33, fd, addr, size), "III", ("rc", None, None))
@@ -588,6 +677,7 @@
589678 raise DeviceError("file_write(fd=%d, addr=0x%08X, size=0x%08X) failed with RC=0x%08X, errno=%d" % (fd, addr, size, result.rc, self.errno()))
590679 return result.rc
591680
 681+ @command()
592682 def file_seek(self, fd, offset, whence):
593683 """ Seeks the file handle to the specified position in the file """
594684 result = self.lib.monitorcommand(struct.pack("IIII", 34, fd, offset, whence), "III", ("rc", None, None))
@@ -595,6 +685,7 @@
596686 raise DeviceError("file_seek(fd=%d, offset=0x%08X, whence=%d) failed with RC=0x%08X, errno=%d" % (fd, offset, whence, result.rc, self.errno()))
597687 return result.rc
598688
 689+ @command()
599690 def file_truncate(self, fd, length):
600691 """ Truncates a file referenced by a handle to a specified length """
601692 result = self.lib.monitorcommand(struct.pack("IIII", 35, fd, offset, 0), "III", ("rc", None, None))
@@ -602,6 +693,7 @@
603694 raise DeviceError("file_truncate(fd=%d, length=0x%08X) failed with RC=0x%08X, errno=%d" % (fd, length, result.rc, self.errno()))
604695 return result.rc
605696
 697+ @command()
606698 def file_sync(self, fd):
607699 """ Flushes a file handles' buffers """
608700 result = self.lib.monitorcommand(struct.pack("IIII", 36, fd, 0, 0), "III", ("rc", None, None))
@@ -609,6 +701,7 @@
610702 raise DeviceError("file_sync(fd=%d) failed with RC=0x%08X, errno=%d" % (fd, result.rc, self.errno()))
611703 return result.rc
612704
 705+ @command()
613706 def file_close(self, fd):
614707 """ Closes a file handle """
615708 result = self.lib.monitorcommand(struct.pack("IIII", 37, fd, 0, 0), "III", ("rc", None, None))
@@ -616,6 +709,7 @@
617710 raise DeviceError("file_close(fd=%d) failed with RC=0x%08X, errno=%d" % (fd, result.rc, self.errno()))
618711 return result.rc
619712
 713+ @command()
620714 def file_close_all(self):
621715 """ Closes all file handles opened through the debugger """
622716 result = self.lib.monitorcommand(struct.pack("IIII", 38, 0, 0, 0), "III", ("rc", None, None))
@@ -623,6 +717,7 @@
624718 raise DeviceError("file_close_all() failed with RC=0x%08X, errno=%d" % (result.rc, self.errno()))
625719 return result.rc
626720
 721+ @command()
627722 def file_kill_all(self):
628723 """ Kills all file handles (in the whole system) """
629724 result = self.lib.monitorcommand(struct.pack("IIII", 39, 0, 0, 0), "III", ("rc", None, None))
@@ -630,6 +725,7 @@
631726 raise DeviceError("file_kill_all() failed with RC=0x%08X, errno=%d" % (result.rc, self.errno()))
632727 return result.rc
633728
 729+ @command()
634730 def file_unlink(self, filename):
635731 """ Removes a file """
636732 result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(filename), 40, 0, 0, 0, filename, 0), "III", ("rc", None, None))
@@ -637,6 +733,7 @@
638734 raise DeviceError("file_unlink(filename=\"%s\") failed with RC=0x%08X, errno=%d" % (filename, result.rc, self.errno()))
639735 return result.rc
640736
 737+ @command()
641738 def file_rename(self, oldname, newname):
642739 """ Renames a file """
643740 result = self.lib.monitorcommand(struct.pack("IIII248s%dsB" % min(247, len(newname)), 41, 0, 0, 0, oldname, newname, 0), "III", ("rc", None, None))
@@ -644,6 +741,7 @@
645742 raise DeviceError("file_rename(oldname=\"%s\", newname=\"%s\") failed with RC=0x%08X, errno=%d" % (oldname, newname, result.rc, self.errno()))
646743 return result.rc
647744
 745+ @command()
648746 def dir_open(self, dirname):
649747 """ Opens a directory and returns the handle """
650748 result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(dirname), 42, 0, 0, 0, dirname, 0), "III", ("handle", None, None))
@@ -651,6 +749,7 @@
652750 raise DeviceError("dir_open(dirname=\"%s\") failed with RC=0x%08X, errno=%d" % (dirname, result.handle, self.errno()))
653751 return result.handle
654752
 753+ @command()
655754 def dir_read(self, handle):
656755 """ Reads the next entry from a directory """
657756 result = self.lib.monitorcommand(struct.pack("IIII", 43, handle, 0, 0), "III", ("version", "maxpath", "ptr"))
@@ -664,6 +763,7 @@
665764 ret.name = ret.name[:ret.name.index('\x00')]
666765 return ret
667766
 767+ @command()
668768 def dir_close(self, handle):
669769 """ Closes a directory handle """
670770 result = self.lib.monitorcommand(struct.pack("IIII", 44, handle, 0, 0), "III", ("rc", None, None))
@@ -671,6 +771,7 @@
672772 raise DeviceError("dir_close(handle=0x%08X) failed with RC=0x%08X, errno=%d" % (handle, result.rc, self.errno()))
673773 return result.rc
674774
 775+ @command()
675776 def dir_close_all(self):
676777 """ Closes all directory handles opened through the debugger """
677778 result = self.lib.monitorcommand(struct.pack("IIII", 45, 0, 0, 0), "III", ("rc", None, None))
@@ -678,6 +779,7 @@
679780 raise DeviceError("dir_close_all() failed with RC=0x%08X, errno=%d" % (result.rc, self.errno()))
680781 return result.rc
681782
 783+ @command()
682784 def dir_kill_all(self):
683785 """ Kills all directory handles (in the whole system) """
684786 result = self.lib.monitorcommand(struct.pack("IIII", 46, 0, 0, 0), "III", ("rc", None, None))
@@ -685,6 +787,7 @@
686788 raise DeviceError("dir_kill_all() failed with RC=0x%08X, errno=%d" % (result.rc, self.errno()))
687789 return result.rc
688790
 791+ @command()
689792 def dir_create(self, dirname):
690793 """ Creates a directory """
691794 result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(dirname), 47, 0, 0, 0, dirname, 0), "III", ("rc", None, None))
@@ -692,6 +795,7 @@
693796 raise DeviceError("dir_create(dirname=\"%s\") failed with RC=0x%08X, errno=%d" % (dirname, result.rc, self.errno()))
694797 return result.rc
695798
 799+ @command()
696800 def dir_remove(self, dirname):
697801 """ Removes an (empty) directory """
698802 result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(dirname), 48, 0, 0, 0, dirname, 0), "III", ("rc", None, None))
@@ -699,11 +803,13 @@
700804 raise DeviceError("dir_remove(dirname=\"%s\") failed with RC=0x%08X, errno=%d" % (dirname, result.rc, self.errno()))
701805 return result.rc
702806
 807+ @command()
703808 def errno(self):
704809 """ Returns the number of the last error that happened """
705810 result = self.lib.monitorcommand(struct.pack("IIII", 49, 0, 0, 0), "III", ("errno", None, None))
706811 return result.errno
707812
 813+ @command()
708814 def disk_mount(self, volume):
709815 """ Mounts a volume """
710816 result = self.lib.monitorcommand(struct.pack("IIII", 50, volume, 0, 0), "III", ("rc", None, None))
@@ -711,6 +817,7 @@
712818 raise DeviceError("disk_mount(volume=%d) failed with RC=0x%08X, errno=%d" % (volume, result.rc, self.errno()))
713819 return result.rc
714820
 821+ @command()
715822 def disk_unmount(self, volume):
716823 """ Unmounts a volume """
717824 result = self.lib.monitorcommand(struct.pack("IIII", 51, volume, 0, 0), "III", ("rc", None, None))