Index: embios/trunk/tools/libembios.py |
— | — | @@ -26,6 +26,8 @@ |
27 | 27 | import usb.core
|
28 | 28 | import libembiosdata
|
29 | 29 |
|
| 30 | +from functools import wraps
|
| 31 | +
|
30 | 32 | class Error(Exception):
|
31 | 33 | def __init__(self, value=None):
|
32 | 34 | self.value = value
|
— | — | @@ -66,9 +68,47 @@ |
67 | 69 | self.__dict__ = self
|
68 | 70 |
|
69 | 71 |
|
| 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 | +
|
70 | 104 | class Embios(object):
|
71 | 105 | """
|
72 | 106 | 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.
|
73 | 113 | """
|
74 | 114 | def __init__(self):
|
75 | 115 | self.lib = Lib()
|
— | — | @@ -91,6 +131,7 @@ |
92 | 132 | tailsize = end - tailaddr
|
93 | 133 | return (headsize, tailaddr - bodyaddr, tailsize)
|
94 | 134 |
|
| 135 | + @command()
|
95 | 136 | def _readmem(self, addr, size):
|
96 | 137 | """ Reads the memory from location 'addr' with size 'size'
|
97 | 138 | from the device.
|
— | — | @@ -97,7 +138,8 @@ |
98 | 139 | """
|
99 | 140 | resp = self.lib.monitorcommand(struct.pack("IIII", 4, addr, size, 0), "III%ds" % size, (None, None, None, "data"))
|
100 | 141 | return resp.data
|
101 | | -
|
| 142 | +
|
| 143 | + @command()
|
102 | 144 | def _writemem(self, addr, data):
|
103 | 145 | """ Writes the data in 'data' to the location 'addr'
|
104 | 146 | in the memory of the device.
|
— | — | @@ -104,6 +146,7 @@ |
105 | 147 | """
|
106 | 148 | return self.lib.monitorcommand(struct.pack("IIII%ds" % len(data), 5, addr, len(data), 0, data), "III", (None, None, None))
|
107 | 149 |
|
| 150 | + @command()
|
108 | 151 | def _readdma(self, addr, size):
|
109 | 152 | """ Reads the memory from location 'addr' with size 'size'
|
110 | 153 | from the device. This uses DMA and the data in endpoint.
|
— | — | @@ -111,6 +154,7 @@ |
112 | 155 | self.lib.monitorcommand(struct.pack("IIII", 6, addr, size, 0), "III", (None, None, None))
|
113 | 156 | return struct.unpack("%ds" % size, self.lib.dev.din(size))[0]
|
114 | 157 |
|
| 158 | + @command()
|
115 | 159 | def _writedma(self, addr, data):
|
116 | 160 | """ Writes the data in 'data' to the location 'addr'
|
117 | 161 | in the memory of the device. This uses DMA and the data out endpoint.
|
— | — | @@ -118,6 +162,7 @@ |
119 | 163 | self.lib.monitorcommand(struct.pack("IIII", 7, addr, len(data), 0), "III", (None, None, None))
|
120 | 164 | return self.lib.dev.dout(data)
|
121 | 165 |
|
| 166 | + @command()
|
122 | 167 | def getversioninfo(self):
|
123 | 168 | """ This returns the emBIOS version and device information. """
|
124 | 169 | resp = self.lib.monitorcommand(struct.pack("IIII", 1, 0, 0, 0), "IBBBBI", ("revision", "majorv", "minorv", "patchv", "swtypeid", "hwtypeid"))
|
— | — | @@ -129,6 +174,7 @@ |
130 | 175 | self.lib.dev.hwtypeid = resp.hwtypeid
|
131 | 176 | return resp
|
132 | 177 |
|
| 178 | + @command()
|
133 | 179 | def getpacketsizeinfo(self):
|
134 | 180 | """ This returns the emBIOS max packet size information.
|
135 | 181 | It also sets the properties of the device object accordingly.
|
— | — | @@ -140,6 +186,7 @@ |
141 | 187 | self.lib.dev.packetsizelimit.dout = resp.doutmax
|
142 | 188 | return resp
|
143 | 189 |
|
| 190 | + @command()
|
144 | 191 | def getusermemrange(self):
|
145 | 192 | """ This returns the memory range the user has access to. """
|
146 | 193 | resp = self.lib.monitorcommand(struct.pack("IIII", 1, 2, 0, 0), "III", ("lower", "upper", None))
|
— | — | @@ -147,6 +194,7 @@ |
148 | 195 | self.lib.dev.usermem.upper = resp.upper
|
149 | 196 | return resp
|
150 | 197 |
|
| 198 | + @command()
|
151 | 199 | def reset(self, force=False):
|
152 | 200 | """ Reboot the device """
|
153 | 201 | if force:
|
— | — | @@ -154,6 +202,7 @@ |
155 | 203 | else:
|
156 | 204 | return self.lib.monitorcommand(struct.pack("IIII", 2, 1, 0, 0), "III", (None, None, None))
|
157 | 205 |
|
| 206 | + @command()
|
158 | 207 | def poweroff(self, force=False):
|
159 | 208 | """ Powers the device off. """
|
160 | 209 | if force:
|
— | — | @@ -161,6 +210,7 @@ |
162 | 211 | else:
|
163 | 212 | return self.lib.monitorcommand(struct.pack("IIII", 3, 1, 0, 0), "III", (None, None, None))
|
164 | 213 |
|
| 214 | + @command()
|
165 | 215 | def read(self, addr, size):
|
166 | 216 | """ Reads the memory from location 'addr' with size 'size'
|
167 | 217 | from the device. This cares about too long packages
|
— | — | @@ -186,6 +236,7 @@ |
187 | 237 | data += self._readmem(addr, tailsize)
|
188 | 238 | return data
|
189 | 239 |
|
| 240 | + @command()
|
190 | 241 | def write(self, addr, data):
|
191 | 242 | """ Writes the data in 'data' to the location 'addr'
|
192 | 243 | in the memory of the device. This cares about too long packages
|
— | — | @@ -213,6 +264,7 @@ |
214 | 265 | self._writemem(addr, data[offset:offset+tailsize])
|
215 | 266 | return data
|
216 | 267 |
|
| 268 | + @command()
|
217 | 269 | def readstring(self, addr, maxlength = 256):
|
218 | 270 | """ Reads a zero terminated string from memory
|
219 | 271 | Reads only a maximum of 'maxlength' chars.
|
— | — | @@ -230,6 +282,7 @@ |
231 | 283 | addr += cin_maxsize
|
232 | 284 | return string
|
233 | 285 |
|
| 286 | + @command()
|
234 | 287 | def i2cread(self, index, slaveaddr, startaddr, size):
|
235 | 288 | """ Reads data from an i2c slave """
|
236 | 289 | data = ""
|
— | — | @@ -238,6 +291,7 @@ |
239 | 292 | data += resp.data
|
240 | 293 | return data
|
241 | 294 |
|
| 295 | + @command()
|
242 | 296 | def i2cwrite(self, index, slaveaddr, startaddr, data):
|
243 | 297 | """ Writes data to an i2c slave """
|
244 | 298 | size = len(data)
|
— | — | @@ -247,6 +301,7 @@ |
248 | 302 | size = 0
|
249 | 303 | return self.lib.monitorcommand(struct.pack("IBBBBII%ds" % size, 9, index, slaveaddr, startaddr, size, 0, 0, data), "III", (None, None, None))
|
250 | 304 |
|
| 305 | + @command()
|
251 | 306 | def usbcread(self):
|
252 | 307 | """ Reads one packet with the maximal cin size """
|
253 | 308 | cin_maxsize = self.lib.dev.packetsizelimit.cin - self.lib.headersize
|
— | — | @@ -255,6 +310,7 @@ |
256 | 311 | resp.maxsize = cin_maxsize
|
257 | 312 | return resp
|
258 | 313 |
|
| 314 | + @command()
|
259 | 315 | def usbcwrite(self, data):
|
260 | 316 | """ Writes data to the USB console """
|
261 | 317 | cin_maxsize = self.lib.dev.packetsizelimit.cin - self.lib.headersize
|
— | — | @@ -265,6 +321,7 @@ |
266 | 322 | data = data[resp.validsize:]
|
267 | 323 | return size
|
268 | 324 |
|
| 325 | + @command()
|
269 | 326 | def cread(self, bitmask=0x1):
|
270 | 327 | """ Reads one packet with the maximal cin size from the device consoles
|
271 | 328 | identified with the specified bitmask
|
— | — | @@ -274,7 +331,8 @@ |
275 | 332 | resp.data = resp.data[size:]
|
276 | 333 | resp.maxsize = cin_maxsize
|
277 | 334 | return resp
|
278 | | -
|
| 335 | +
|
| 336 | + @command()
|
279 | 337 | def cwrite(self, data, bitmask=0x1):
|
280 | 338 | """ Writes data to the device consoles
|
281 | 339 | identified with the specified bitmask.
|
— | — | @@ -287,10 +345,12 @@ |
288 | 346 | data = data[writesize:]
|
289 | 347 | return size
|
290 | 348 |
|
| 349 | + @command()
|
291 | 350 | def cflush(self, bitmask):
|
292 | 351 | """ Flushes the consoles specified with 'bitmask' """
|
293 | 352 | return self.lib.monitorcommand(struct.pack("IIII", 14, bitmask, 0, 0), "III", (None, None, None))
|
294 | 353 |
|
| 354 | + @command()
|
295 | 355 | def getprocinfo(self):
|
296 | 356 | """ Gets current state of the scheduler """
|
297 | 357 | cin_maxsize = self.lib.dev.packetsizelimit.cin - self.lib.headersize
|
— | — | @@ -355,28 +415,34 @@ |
356 | 416 | id += 1
|
357 | 417 | return threads
|
358 | 418 |
|
| 419 | + @command()
|
359 | 420 | def lockscheduler(self, freeze=True):
|
360 | 421 | """ Freezes/Unfreezes the scheduler """
|
361 | 422 | resp = self.lib.monitorcommand(struct.pack("IIII", 16, 1 if freeze else 0, 0, 0), "III", ("before", None, None))
|
362 | 423 | return True if resp.before == 1 else False
|
363 | 424 |
|
| 425 | + @command()
|
364 | 426 | def unlockscheduler(self):
|
365 | 427 | """ Unfreezes the scheduler """
|
366 | 428 | return self.lib.monitorcommand(struct.pack("IIII", 16, 0, 0, 0), "III", ("before", None, None))
|
367 | 429 |
|
| 430 | + @command()
|
368 | 431 | def suspendthread(self, id, suspend=True):
|
369 | 432 | """ Suspends the thread with the specified id """
|
370 | 433 | resp = self.lib.monitorcommand(struct.pack("IIII", 17, 1 if suspend else 0, id, 0), "III", ("before", None, None))
|
371 | 434 | return True if resp.before == 1 else False
|
372 | 435 |
|
| 436 | + @command()
|
373 | 437 | def resumethread(self, id):
|
374 | 438 | """ Resumes the thread with the specified id """
|
375 | 439 | return self.lib.monitorcommand(struct.pack("IIII", 17, 0, id, 0), "III", ("before", None, None))
|
376 | 440 |
|
| 441 | + @command()
|
377 | 442 | def killthread(self, id):
|
378 | 443 | """ Kills the thread with the specified id """
|
379 | 444 | return self.lib.monitorcommand(struct.pack("IIII", 18, id, 0, 0), "III", ("before", None, None))
|
380 | 445 |
|
| 446 | + @command()
|
381 | 447 | def createthread(self, nameptr, entrypoint, stackptr, stacksize, threadtype, priority, state):
|
382 | 448 | """ Creates a thread with the specified attributes """
|
383 | 449 | if threadtype == "user":
|
— | — | @@ -398,14 +464,17 @@ |
399 | 465 | raise DeviceError("The device returned the error code "+str(resp.id))
|
400 | 466 | return resp
|
401 | 467 |
|
| 468 | + @command()
|
402 | 469 | def flushcaches(self):
|
403 | 470 | """ Flushes the CPU instruction and data cache """
|
404 | 471 | return self.lib.monitorcommand(struct.pack("IIII", 20, 0, 0, 0), "III", (None, None, None))
|
405 | 472 |
|
| 473 | + @command()
|
406 | 474 | def execimage(self, addr):
|
407 | 475 | """ Runs the emBIOS app at 'addr' """
|
408 | 476 | return self.lib.monitorcommand(struct.pack("IIII", 21, addr, 0, 0), "III", ("rc", None, None))
|
409 | 477 |
|
| 478 | + @command()
|
410 | 479 | def run(self, app):
|
411 | 480 | """ Uploads and runs the emBIOS app in the string 'app' """
|
412 | 481 | try:
|
— | — | @@ -435,6 +504,7 @@ |
436 | 505 | self.execimage(baseaddr)
|
437 | 506 | return Bunch(baseaddr=baseaddr, name=name)
|
438 | 507 |
|
| 508 | + @command()
|
439 | 509 | def bootflashread(self, memaddr, flashaddr, size):
|
440 | 510 | """ Copies the data in the bootflash at 'flashaddr' of the specified size
|
441 | 511 | to the memory at addr 'memaddr'
|
— | — | @@ -441,6 +511,7 @@ |
442 | 512 | """
|
443 | 513 | return self.lib.monitorcommand(struct.pack("IIII", 22, memaddr, flashaddr, size), "III", (None, None, None))
|
444 | 514 |
|
| 515 | + @command()
|
445 | 516 | def bootflashwrite(self, memaddr, flashaddr, size):
|
446 | 517 | """ Copies the data in the memory at 'memaddr' of the specified size
|
447 | 518 | to the boot flash at addr 'flashaddr'
|
— | — | @@ -447,10 +518,12 @@ |
448 | 519 | """
|
449 | 520 | return self.lib.monitorcommand(struct.pack("IIII", 23, memaddr, flashaddr, size), "III", (None, None, None))
|
450 | 521 |
|
| 522 | + @command()
|
451 | 523 | def execfirmware(self, addr):
|
452 | 524 | """ Executes the firmware at 'addr' and passes all control to it. """
|
453 | 525 | return self.lib.monitorcommand(struct.pack("IIII", 24, addr, 0, 0))
|
454 | 526 |
|
| 527 | + @command()
|
455 | 528 | def aesencrypt(self, addr, size, keyindex):
|
456 | 529 | """ Encrypts the buffer at 'addr' with the specified size
|
457 | 530 | with the hardware AES key index 'keyindex'
|
— | — | @@ -457,6 +530,7 @@ |
458 | 531 | """
|
459 | 532 | return self.lib.monitorcommand(struct.pack("IBBHII", 25, 1, 0, keyindex, addr, size), "III", (None, None, None))
|
460 | 533 |
|
| 534 | + @command()
|
461 | 535 | def aesdecrypt(self, addr, size, keyindex):
|
462 | 536 | """ Decrypts the buffer at 'addr' with the specified size
|
463 | 537 | with the hardware AES key index 'keyindex'
|
— | — | @@ -463,10 +537,12 @@ |
464 | 538 | """
|
465 | 539 | return self.lib.monitorcommand(struct.pack("IBBHII", 25, 0, 0, keyindex, addr, size), "III", (None, None, None))
|
466 | 540 |
|
| 541 | + @command()
|
467 | 542 | def hmac_sha1(self, addr, size, destination):
|
468 | 543 | """ Generates a HMAC-SHA1 hash of the buffer and saves it to 'destination' """
|
469 | 544 | return self.lib.monitorcommand(struct.pack("IIII", 26, addr, size, destination), "III", (None, None, None))
|
470 | 545 |
|
| 546 | + @command()
|
471 | 547 | def ipodnano2g_getnandinfo(self):
|
472 | 548 | """ Target-specific function: ipodnano2g
|
473 | 549 | Gathers some information about the NAND chip used
|
— | — | @@ -474,6 +550,7 @@ |
475 | 551 | if self.lib.dev.hwtypeid != 0x47324e49: raise DeviceError("Wrong device for target-specific command.")
|
476 | 552 | return self.lib.monitorcommand(struct.pack("IIII", 0xffff0001, 0, 0, 0), "IHHHH", ("type", "pagesperblock", "banks", "userblocks", "blocks"))
|
477 | 553 |
|
| 554 | + @command()
|
478 | 555 | def ipodnano2g_nandread(self, addr, start, count, doecc, checkempty):
|
479 | 556 | """ Target-specific function: ipodnano2g
|
480 | 557 | Reads data from the NAND chip into memory
|
— | — | @@ -481,6 +558,7 @@ |
482 | 559 | if self.lib.dev.hwtypeid != 0x47324e49: raise DeviceError("Wrong device for target-specific command.")
|
483 | 560 | 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))
|
484 | 561 |
|
| 562 | + @command()
|
485 | 563 | def ipodnano2g_nandwrite(self, addr, start, count, doecc):
|
486 | 564 | """ Target-specific function: ipodnano2g
|
487 | 565 | Writes data to the NAND chip
|
— | — | @@ -488,6 +566,7 @@ |
489 | 567 | if self.lib.dev.hwtypeid != 0x47324e49: raise DeviceError("Wrong device for target-specific command.")
|
490 | 568 | return self.lib.monitorcommand(struct.pack("IIII", 0xffff0003, addr | (0x80000000 if doecc != 0 else 0), start, count), "III", (None, None, None))
|
491 | 569 |
|
| 570 | + @command()
|
492 | 571 | def ipodnano2g_nanderase(self, addr, start, count):
|
493 | 572 | """ Target-specific function: ipodnano2g
|
494 | 573 | Erases blocks on the NAND chip and stores the results to memory
|
— | — | @@ -495,6 +574,7 @@ |
496 | 575 | if self.lib.dev.hwtypeid != 0x47324e49: raise DeviceError("Wrong device for target-specific command.")
|
497 | 576 | return self.lib.monitorcommand(struct.pack("IIII", 0xffff0004, addr, start, count), "III", (None, None, None))
|
498 | 577 |
|
| 578 | + @command()
|
499 | 579 | def ipodclassic_gethddinfo(self):
|
500 | 580 | """ Target-specific function: ipodclassic
|
501 | 581 | Gather information about the hard disk drive
|
— | — | @@ -502,6 +582,7 @@ |
503 | 583 | if self.lib.dev.hwtypeid != 0x4c435049: raise DeviceError("Wrong device for target-specific command.")
|
504 | 584 | return self.lib.monitorcommand(struct.pack("IIII", 0xffff0001, 0, 0, 0), "IQQII", ("identifyptr", "totalsectors", "virtualsectors", "bbtptr", "bbtsize"))
|
505 | 585 |
|
| 586 | + @command()
|
506 | 587 | def ipodclassic_hddaccess(self, type, sector, count, addr):
|
507 | 588 | """ Target-specific function: ipodclassic
|
508 | 589 | Access the hard disk, type = 0 (read) / 1 (write)
|
— | — | @@ -511,6 +592,7 @@ |
512 | 593 | if (rc > 0x80000000):
|
513 | 594 | raise DeviceError("HDD access (type=%d, sector=%d, count=%d, addr=0x%08X) failed with RC 0x%08X" % (type, sector, count, addr, rc))
|
514 | 595 |
|
| 596 | + @command()
|
515 | 597 | def ipodclassic_writebbt(self, bbt, tempaddr):
|
516 | 598 | """ Target-specific function: ipodclassic
|
517 | 599 | Write hard drive bad block table
|
— | — | @@ -538,6 +620,7 @@ |
539 | 621 | count = 1
|
540 | 622 | self.ipodclassic_hddaccess(1, sector, count, tempaddr + offset)
|
541 | 623 |
|
| 624 | + @command()
|
542 | 625 | def storage_get_info(self, volume):
|
543 | 626 | """ Get information about a storage device """
|
544 | 627 | result = self.lib.monitorcommand(struct.pack("IIII", 27, volume, 0, 0), "IIIIIIII", ("version", None, None, "sectorsize", "numsectors", "vendorptr", "productptr", "revisionptr"))
|
— | — | @@ -548,18 +631,21 @@ |
549 | 632 | result.revision = self.readstring(result.revisionptr)
|
550 | 633 | return result
|
551 | 634 |
|
| 635 | + @command()
|
552 | 636 | def storage_read_sectors_md(self, volume, sector, count, addr):
|
553 | 637 | """ Read sectors from as storage device """
|
554 | 638 | result = self.lib.monitorcommand(struct.pack("IIQIIII", 28, volume, sector, count, addr, 0, 0), "III", ("rc", None, None, None))
|
555 | 639 | if result.rc > 0x80000000:
|
556 | 640 | 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()
|
558 | 643 | def storage_write_sectors_md(self, volume, sector, count, addr):
|
559 | 644 | """ Read sectors from as storage device """
|
560 | 645 | result = self.lib.monitorcommand(struct.pack("IIQIIII", 29, volume, sector, count, addr, 0, 0), "III", ("rc", None, None, None))
|
561 | 646 | if result.rc > 0x80000000:
|
562 | 647 | 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()
|
564 | 650 | def file_open(self, filename, mode):
|
565 | 651 | """ Opens a file and returns the handle """
|
566 | 652 | result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(filename), 30, mode, 0, 0, filename, 0), "III", ("fd", None, None))
|
— | — | @@ -567,6 +653,7 @@ |
568 | 654 | raise DeviceError("file_open(filename=\"%s\", mode=0x%X) failed with RC=0x%08X, errno=%d" % (filename, mode, result.fd, self.errno()))
|
569 | 655 | return result.fd
|
570 | 656 |
|
| 657 | + @command()
|
571 | 658 | def file_size(self, fd):
|
572 | 659 | """ Gets the size of a file referenced by a handle """
|
573 | 660 | result = self.lib.monitorcommand(struct.pack("IIII", 31, fd, 0, 0), "III", ("size", None, None))
|
— | — | @@ -573,7 +660,8 @@ |
574 | 661 | if result.size > 0x80000000:
|
575 | 662 | raise DeviceError("file_size(fd=%d) failed with RC=0x%08X, errno=%d" % (fd, result.size, self.errno()))
|
576 | 663 | return result.size
|
577 | | -
|
| 664 | +
|
| 665 | + @command()
|
578 | 666 | def file_read(self, fd, addr, size):
|
579 | 667 | """ Reads data from a file referenced by a handle """
|
580 | 668 | result = self.lib.monitorcommand(struct.pack("IIII", 32, fd, addr, size), "III", ("rc", None, None))
|
— | — | @@ -580,7 +668,8 @@ |
581 | 669 | if result.rc > 0x80000000:
|
582 | 670 | 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()))
|
583 | 671 | return result.rc
|
584 | | -
|
| 672 | +
|
| 673 | + @command()
|
585 | 674 | def file_write(self, fd, addr, size):
|
586 | 675 | """ Writes data from a file referenced by a handle """
|
587 | 676 | result = self.lib.monitorcommand(struct.pack("IIII", 33, fd, addr, size), "III", ("rc", None, None))
|
— | — | @@ -588,6 +677,7 @@ |
589 | 678 | 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()))
|
590 | 679 | return result.rc
|
591 | 680 |
|
| 681 | + @command()
|
592 | 682 | def file_seek(self, fd, offset, whence):
|
593 | 683 | """ Seeks the file handle to the specified position in the file """
|
594 | 684 | result = self.lib.monitorcommand(struct.pack("IIII", 34, fd, offset, whence), "III", ("rc", None, None))
|
— | — | @@ -595,6 +685,7 @@ |
596 | 686 | 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()))
|
597 | 687 | return result.rc
|
598 | 688 |
|
| 689 | + @command()
|
599 | 690 | def file_truncate(self, fd, length):
|
600 | 691 | """ Truncates a file referenced by a handle to a specified length """
|
601 | 692 | result = self.lib.monitorcommand(struct.pack("IIII", 35, fd, offset, 0), "III", ("rc", None, None))
|
— | — | @@ -602,6 +693,7 @@ |
603 | 694 | raise DeviceError("file_truncate(fd=%d, length=0x%08X) failed with RC=0x%08X, errno=%d" % (fd, length, result.rc, self.errno()))
|
604 | 695 | return result.rc
|
605 | 696 |
|
| 697 | + @command()
|
606 | 698 | def file_sync(self, fd):
|
607 | 699 | """ Flushes a file handles' buffers """
|
608 | 700 | result = self.lib.monitorcommand(struct.pack("IIII", 36, fd, 0, 0), "III", ("rc", None, None))
|
— | — | @@ -609,6 +701,7 @@ |
610 | 702 | raise DeviceError("file_sync(fd=%d) failed with RC=0x%08X, errno=%d" % (fd, result.rc, self.errno()))
|
611 | 703 | return result.rc
|
612 | 704 |
|
| 705 | + @command()
|
613 | 706 | def file_close(self, fd):
|
614 | 707 | """ Closes a file handle """
|
615 | 708 | result = self.lib.monitorcommand(struct.pack("IIII", 37, fd, 0, 0), "III", ("rc", None, None))
|
— | — | @@ -616,6 +709,7 @@ |
617 | 710 | raise DeviceError("file_close(fd=%d) failed with RC=0x%08X, errno=%d" % (fd, result.rc, self.errno()))
|
618 | 711 | return result.rc
|
619 | 712 |
|
| 713 | + @command()
|
620 | 714 | def file_close_all(self):
|
621 | 715 | """ Closes all file handles opened through the debugger """
|
622 | 716 | result = self.lib.monitorcommand(struct.pack("IIII", 38, 0, 0, 0), "III", ("rc", None, None))
|
— | — | @@ -623,6 +717,7 @@ |
624 | 718 | raise DeviceError("file_close_all() failed with RC=0x%08X, errno=%d" % (result.rc, self.errno()))
|
625 | 719 | return result.rc
|
626 | 720 |
|
| 721 | + @command()
|
627 | 722 | def file_kill_all(self):
|
628 | 723 | """ Kills all file handles (in the whole system) """
|
629 | 724 | result = self.lib.monitorcommand(struct.pack("IIII", 39, 0, 0, 0), "III", ("rc", None, None))
|
— | — | @@ -630,6 +725,7 @@ |
631 | 726 | raise DeviceError("file_kill_all() failed with RC=0x%08X, errno=%d" % (result.rc, self.errno()))
|
632 | 727 | return result.rc
|
633 | 728 |
|
| 729 | + @command()
|
634 | 730 | def file_unlink(self, filename):
|
635 | 731 | """ Removes a file """
|
636 | 732 | result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(filename), 40, 0, 0, 0, filename, 0), "III", ("rc", None, None))
|
— | — | @@ -637,6 +733,7 @@ |
638 | 734 | raise DeviceError("file_unlink(filename=\"%s\") failed with RC=0x%08X, errno=%d" % (filename, result.rc, self.errno()))
|
639 | 735 | return result.rc
|
640 | 736 |
|
| 737 | + @command()
|
641 | 738 | def file_rename(self, oldname, newname):
|
642 | 739 | """ Renames a file """
|
643 | 740 | 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 @@ |
645 | 742 | raise DeviceError("file_rename(oldname=\"%s\", newname=\"%s\") failed with RC=0x%08X, errno=%d" % (oldname, newname, result.rc, self.errno()))
|
646 | 743 | return result.rc
|
647 | 744 |
|
| 745 | + @command()
|
648 | 746 | def dir_open(self, dirname):
|
649 | 747 | """ Opens a directory and returns the handle """
|
650 | 748 | result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(dirname), 42, 0, 0, 0, dirname, 0), "III", ("handle", None, None))
|
— | — | @@ -651,6 +749,7 @@ |
652 | 750 | raise DeviceError("dir_open(dirname=\"%s\") failed with RC=0x%08X, errno=%d" % (dirname, result.handle, self.errno()))
|
653 | 751 | return result.handle
|
654 | 752 |
|
| 753 | + @command()
|
655 | 754 | def dir_read(self, handle):
|
656 | 755 | """ Reads the next entry from a directory """
|
657 | 756 | result = self.lib.monitorcommand(struct.pack("IIII", 43, handle, 0, 0), "III", ("version", "maxpath", "ptr"))
|
— | — | @@ -664,6 +763,7 @@ |
665 | 764 | ret.name = ret.name[:ret.name.index('\x00')]
|
666 | 765 | return ret
|
667 | 766 |
|
| 767 | + @command()
|
668 | 768 | def dir_close(self, handle):
|
669 | 769 | """ Closes a directory handle """
|
670 | 770 | result = self.lib.monitorcommand(struct.pack("IIII", 44, handle, 0, 0), "III", ("rc", None, None))
|
— | — | @@ -671,6 +771,7 @@ |
672 | 772 | raise DeviceError("dir_close(handle=0x%08X) failed with RC=0x%08X, errno=%d" % (handle, result.rc, self.errno()))
|
673 | 773 | return result.rc
|
674 | 774 |
|
| 775 | + @command()
|
675 | 776 | def dir_close_all(self):
|
676 | 777 | """ Closes all directory handles opened through the debugger """
|
677 | 778 | result = self.lib.monitorcommand(struct.pack("IIII", 45, 0, 0, 0), "III", ("rc", None, None))
|
— | — | @@ -678,6 +779,7 @@ |
679 | 780 | raise DeviceError("dir_close_all() failed with RC=0x%08X, errno=%d" % (result.rc, self.errno()))
|
680 | 781 | return result.rc
|
681 | 782 |
|
| 783 | + @command()
|
682 | 784 | def dir_kill_all(self):
|
683 | 785 | """ Kills all directory handles (in the whole system) """
|
684 | 786 | result = self.lib.monitorcommand(struct.pack("IIII", 46, 0, 0, 0), "III", ("rc", None, None))
|
— | — | @@ -685,6 +787,7 @@ |
686 | 788 | raise DeviceError("dir_kill_all() failed with RC=0x%08X, errno=%d" % (result.rc, self.errno()))
|
687 | 789 | return result.rc
|
688 | 790 |
|
| 791 | + @command()
|
689 | 792 | def dir_create(self, dirname):
|
690 | 793 | """ Creates a directory """
|
691 | 794 | result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(dirname), 47, 0, 0, 0, dirname, 0), "III", ("rc", None, None))
|
— | — | @@ -692,6 +795,7 @@ |
693 | 796 | raise DeviceError("dir_create(dirname=\"%s\") failed with RC=0x%08X, errno=%d" % (dirname, result.rc, self.errno()))
|
694 | 797 | return result.rc
|
695 | 798 |
|
| 799 | + @command()
|
696 | 800 | def dir_remove(self, dirname):
|
697 | 801 | """ Removes an (empty) directory """
|
698 | 802 | result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(dirname), 48, 0, 0, 0, dirname, 0), "III", ("rc", None, None))
|
— | — | @@ -699,11 +803,13 @@ |
700 | 804 | raise DeviceError("dir_remove(dirname=\"%s\") failed with RC=0x%08X, errno=%d" % (dirname, result.rc, self.errno()))
|
701 | 805 | return result.rc
|
702 | 806 |
|
| 807 | + @command()
|
703 | 808 | def errno(self):
|
704 | 809 | """ Returns the number of the last error that happened """
|
705 | 810 | result = self.lib.monitorcommand(struct.pack("IIII", 49, 0, 0, 0), "III", ("errno", None, None))
|
706 | 811 | return result.errno
|
707 | 812 |
|
| 813 | + @command()
|
708 | 814 | def disk_mount(self, volume):
|
709 | 815 | """ Mounts a volume """
|
710 | 816 | result = self.lib.monitorcommand(struct.pack("IIII", 50, volume, 0, 0), "III", ("rc", None, None))
|
— | — | @@ -711,6 +817,7 @@ |
712 | 818 | raise DeviceError("disk_mount(volume=%d) failed with RC=0x%08X, errno=%d" % (volume, result.rc, self.errno()))
|
713 | 819 | return result.rc
|
714 | 820 |
|
| 821 | + @command()
|
715 | 822 | def disk_unmount(self, volume):
|
716 | 823 | """ Unmounts a volume """
|
717 | 824 | result = self.lib.monitorcommand(struct.pack("IIII", 51, volume, 0, 0), "III", ("rc", None, None))
|