freemyipod r548 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r547‎ | r548 | r549 >
Date:01:26, 7 February 2011
Author:farthen
Status:new
Tags:
Comment:
emcore tools: force little endian on all struct.pack/struct.unpack calls.
Modified paths:
  • /emcore/trunk/tools/emcore.py (modified) (history)
  • /emcore/trunk/tools/libemcore.py (modified) (history)

Diff [purge]

Index: emcore/trunk/tools/emcore.py
@@ -266,7 +266,7 @@
267267 integer = to_int(integer)
268268 if integer > 0xFFFFFFFF:
269269 raise ArgumentError("Specified integer too long")
270 - data = struct.pack("I", integer)
 270+ data = struct.pack("<I", integer)
271271 self.emcore.write(addr, data)
272272 self.logger.info("Integer '0x%X' written successfully to 0x%X\n" % (integer, addr))
273273
@@ -278,7 +278,7 @@
279279 """
280280 addr = to_int(addr)
281281 data = self.emcore.read(addr, 4)
282 - integer = struct.unpack("I", data)[0]
 282+ integer = struct.unpack("<I", data)[0]
283283 self.logger.info("Read '0x%X' from address 0x%X\n" % (integer, addr))
284284
285285 @command
@@ -295,7 +295,7 @@
296296 addr = to_int(addr)
297297 size = to_int(size)
298298 data = self.emcore.i2cread(bus, slave, addr, size)
299 - bytes = struct.unpack("%dB" % len(data), data)
 299+ bytes = struct.unpack("<%dB" % len(data), data)
300300 self.logger.info("Data read from I2C:\n")
301301 for index, byte in enumerate(bytes):
302302 self.logger.info("%02X: %02X\n" % (addr + index, byte))
Index: emcore/trunk/tools/libemcore.py
@@ -133,7 +133,7 @@
134134 """ Reads the memory from location 'addr' with size 'size'
135135 from the device.
136136 """
137 - resp = self.lib.monitorcommand(struct.pack("IIII", 4, addr, size, 0), "III%ds" % size, (None, None, None, "data"))
 137+ resp = self.lib.monitorcommand(struct.pack("<IIII", 4, addr, size, 0), "III%ds" % size, (None, None, None, "data"))
138138 return resp.data
139139
140140 @command()
@@ -141,7 +141,7 @@
142142 """ Writes the data in 'data' to the location 'addr'
143143 in the memory of the device.
144144 """
145 - return self.lib.monitorcommand(struct.pack("IIII%ds" % len(data), 5, addr, len(data), 0, data), "III", (None, None, None))
 145+ return self.lib.monitorcommand(struct.pack("<IIII%ds" % len(data), 5, addr, len(data), 0, data), "III", (None, None, None))
146146
147147 @command()
148148 def _readdma(self, addr, size):
@@ -148,8 +148,8 @@
149149 """ Reads the memory from location 'addr' with size 'size'
150150 from the device. This uses DMA and the data in endpoint.
151151 """
152 - self.lib.monitorcommand(struct.pack("IIII", 6, addr, size, 0), "III", (None, None, None))
153 - return struct.unpack("%ds" % size, self.lib.dev.din(size))[0]
 152+ self.lib.monitorcommand(struct.pack("<IIII", 6, addr, size, 0), "III", (None, None, None))
 153+ return struct.unpack("<%ds" % size, self.lib.dev.din(size))[0]
154154
155155 @command()
156156 def _writedma(self, addr, data):
@@ -156,13 +156,13 @@
157157 """ Writes the data in 'data' to the location 'addr'
158158 in the memory of the device. This uses DMA and the data out endpoint.
159159 """
160 - self.lib.monitorcommand(struct.pack("IIII", 7, addr, len(data), 0), "III", (None, None, None))
 160+ self.lib.monitorcommand(struct.pack("<IIII", 7, addr, len(data), 0), "III", (None, None, None))
161161 return self.lib.dev.dout(data)
162162
163163 @command()
164164 def getversioninfo(self):
165165 """ This returns the emCORE version and device information. """
166 - resp = self.lib.monitorcommand(struct.pack("IIII", 1, 0, 0, 0), "IBBBBI", ("revision", "majorv", "minorv", "patchv", "swtypeid", "hwtypeid"))
 166+ resp = self.lib.monitorcommand(struct.pack("<IIII", 1, 0, 0, 0), "IBBBBI", ("revision", "majorv", "minorv", "patchv", "swtypeid", "hwtypeid"))
167167 self.lib.dev.version.revision = resp.revision
168168 self.lib.dev.version.majorv = resp.majorv
169169 self.lib.dev.version.minorv = resp.minorv
@@ -178,7 +178,7 @@
179179 """ This returns the emCORE max packet size information.
180180 It also sets the properties of the device object accordingly.
181181 """
182 - resp = self.lib.monitorcommand(struct.pack("IIII", 1, 1, 0, 0), "HHII", ("coutmax", "cinmax", "doutmax", "dinmax"))
 182+ resp = self.lib.monitorcommand(struct.pack("<IIII", 1, 1, 0, 0), "HHII", ("coutmax", "cinmax", "doutmax", "dinmax"))
183183 self.logger.debug("Device cout packet size limit = %d\n" % resp.coutmax)
184184 self.lib.dev.packetsizelimit.cout = resp.coutmax
185185 self.logger.debug("Device cin packet size limit = %d\n" % resp.cinmax)
@@ -192,7 +192,7 @@
193193 @command()
194194 def getusermemrange(self):
195195 """ This returns the memory range the user has access to. """
196 - resp = self.lib.monitorcommand(struct.pack("IIII", 1, 2, 0, 0), "III", ("lower", "upper", None))
 196+ resp = self.lib.monitorcommand(struct.pack("<IIII", 1, 2, 0, 0), "III", ("lower", "upper", None))
197197 self.logger.debug("Device user memory = 0x%X - 0x%X\n" % (resp.lower, resp.upper))
198198 self.lib.dev.usermem.lower = resp.lower
199199 self.lib.dev.usermem.upper = resp.upper
@@ -202,17 +202,17 @@
203203 def reset(self, force=False):
204204 """ Reboot the device """
205205 if force:
206 - return self.lib.monitorcommand(struct.pack("IIII", 2, 0, 0, 0))
 206+ return self.lib.monitorcommand(struct.pack("<IIII", 2, 0, 0, 0))
207207 else:
208 - return self.lib.monitorcommand(struct.pack("IIII", 2, 1, 0, 0), "III", (None, None, None))
 208+ return self.lib.monitorcommand(struct.pack("<IIII", 2, 1, 0, 0), "III", (None, None, None))
209209
210210 @command()
211211 def poweroff(self, force=False):
212212 """ Powers the device off. """
213213 if force:
214 - return self.lib.monitorcommand(struct.pack("IIII", 3, 0, 0, 0))
 214+ return self.lib.monitorcommand(struct.pack("<IIII", 3, 0, 0, 0))
215215 else:
216 - return self.lib.monitorcommand(struct.pack("IIII", 3, 1, 0, 0), "III", (None, None, None))
 216+ return self.lib.monitorcommand(struct.pack("<IIII", 3, 1, 0, 0), "III", (None, None, None))
217217
218218 @command()
219219 def read(self, addr, size):
@@ -302,7 +302,7 @@
303303 """ Reads data from an i2c slave """
304304 data = ""
305305 for i in range(size):
306 - resp = self.lib.monitorcommand(struct.pack("IBBBBII", 8, index, slaveaddr, startaddr + i, 1, 0, 0), "III1s", (None, None, None, "data"))
 306+ resp = self.lib.monitorcommand(struct.pack("<IBBBBII", 8, index, slaveaddr, startaddr + i, 1, 0, 0), "III1s", (None, None, None, "data"))
307307 data += resp.data
308308 return data
309309
@@ -314,13 +314,13 @@
315315 raise ArgumentError("Size must be a number between 1 and 256")
316316 if size == 256:
317317 size = 0
318 - return self.lib.monitorcommand(struct.pack("IBBBBII%ds" % size, 9, index, slaveaddr, startaddr, size, 0, 0, data), "III", (None, None, None))
 318+ return self.lib.monitorcommand(struct.pack("<IBBBBII%ds" % size, 9, index, slaveaddr, startaddr, size, 0, 0, data), "III", (None, None, None))
319319
320320 @command()
321321 def usbcread(self):
322322 """ Reads one packet with the maximal cin size """
323323 cin_maxsize = self.lib.dev.packetsizelimit.cin - self.lib.headersize
324 - resp = self.lib.monitorcommand(struct.pack("IIII", 10, cin_maxsize, 0, 0), "III%ds" % cin_maxsize, ("validsize", "buffersize", "queuesize", "data"))
 324+ resp = self.lib.monitorcommand(struct.pack("<IIII", 10, cin_maxsize, 0, 0), "III%ds" % cin_maxsize, ("validsize", "buffersize", "queuesize", "data"))
325325 resp.data = resp.data[:resp.validsize]
326326 resp.maxsize = cin_maxsize
327327 return resp
@@ -332,7 +332,7 @@
333333 size = len(data)
334334 while len(data) > 0:
335335 writesize = min(cin_maxsize, len(data))
336 - resp = self.lib.monitorcommand(struct.pack("IIII%ds" % writesize, 11, writesize, 0, 0, data[:writesize]), "III", ("validsize", "buffersize", "freesize"))
 336+ resp = self.lib.monitorcommand(struct.pack("<IIII%ds" % writesize, 11, writesize, 0, 0, data[:writesize]), "III", ("validsize", "buffersize", "freesize"))
337337 data = data[resp.validsize:]
338338 return size
339339
@@ -342,7 +342,7 @@
343343 identified with the specified bitmask
344344 """
345345 cin_maxsize = self.lib.dev.packetsizelimit.cin - self.lib.headersize
346 - resp = self.lib.monitorcommand(struct.pack("IIII", 13, bitmask, cin_maxsize, 0), "III%ds" % cin_maxsize, ("size", None, None))
 346+ resp = self.lib.monitorcommand(struct.pack("<IIII", 13, bitmask, cin_maxsize, 0), "III%ds" % cin_maxsize, ("size", None, None))
347347 resp.data = resp.data[size:]
348348 resp.maxsize = cin_maxsize
349349 return resp
@@ -356,7 +356,7 @@
357357 size = len(data)
358358 while len(data) > 0:
359359 writesize = min(cin_maxsize, len(data))
360 - resp = self.lib.monitorcommand(struct.pack("IIII%ds" % writesize, 12, bitmask, writesize, 0, data[:writesize]), "III", (None, None, None))
 360+ resp = self.lib.monitorcommand(struct.pack("<IIII%ds" % writesize, 12, bitmask, writesize, 0, data[:writesize]), "III", (None, None, None))
361361 data = data[writesize:]
362362 return size
363363
@@ -363,13 +363,13 @@
364364 @command()
365365 def cflush(self, bitmask):
366366 """ Flushes the consoles specified with 'bitmask' """
367 - return self.lib.monitorcommand(struct.pack("IIII", 14, bitmask, 0, 0), "III", (None, None, None))
 367+ return self.lib.monitorcommand(struct.pack("<IIII", 14, bitmask, 0, 0), "III", (None, None, None))
368368
369369 @command()
370370 def getprocinfo(self):
371371 """ Gets current state of the scheduler """
372372 schedulerstate = self.lockscheduler()
373 - resp = self.lib.monitorcommand(struct.pack("IIII", 15, 0, 0, 0), "III", ("structver", "structptr", None))
 373+ resp = self.lib.monitorcommand(struct.pack("<IIII", 15, 0, 0, 0), "III", ("structver", "structptr", None))
374374 if resp.structver != 2:
375375 raise DeviceError("Unsupported thread struct version!")
376376
@@ -395,29 +395,29 @@
396396 @command()
397397 def lockscheduler(self, freeze=True):
398398 """ Freezes/Unfreezes the scheduler """
399 - resp = self.lib.monitorcommand(struct.pack("IIII", 16, 1 if freeze else 0, 0, 0), "III", ("before", None, None))
 399+ resp = self.lib.monitorcommand(struct.pack("<IIII", 16, 1 if freeze else 0, 0, 0), "III", ("before", None, None))
400400 return True if resp.before == 1 else False
401401
402402 @command()
403403 def unlockscheduler(self):
404404 """ Unfreezes the scheduler """
405 - return self.lib.monitorcommand(struct.pack("IIII", 16, 0, 0, 0), "III", ("before", None, None))
 405+ return self.lib.monitorcommand(struct.pack("<IIII", 16, 0, 0, 0), "III", ("before", None, None))
406406
407407 @command()
408408 def suspendthread(self, id, suspend=True):
409409 """ Suspends the thread with the specified id """
410 - resp = self.lib.monitorcommand(struct.pack("IIII", 17, 1 if suspend else 0, id, 0), "III", ("before", None, None))
 410+ resp = self.lib.monitorcommand(struct.pack("<IIII", 17, 1 if suspend else 0, id, 0), "III", ("before", None, None))
411411 return True if resp.before == 1 else False
412412
413413 @command()
414414 def resumethread(self, id):
415415 """ Resumes the thread with the specified id """
416 - return self.lib.monitorcommand(struct.pack("IIII", 17, 0, id, 0), "III", ("before", None, None))
 416+ return self.lib.monitorcommand(struct.pack("<IIII", 17, 0, id, 0), "III", ("before", None, None))
417417
418418 @command()
419419 def killthread(self, id):
420420 """ Kills the thread with the specified id """
421 - return self.lib.monitorcommand(struct.pack("IIII", 18, id, 0, 0), "III", ("before", None, None))
 421+ return self.lib.monitorcommand(struct.pack("<IIII", 18, id, 0, 0), "III", ("before", None, None))
422422
423423 @command()
424424 def createthread(self, nameptr, entrypoint, stackptr, stacksize, threadtype, priority, state):
@@ -436,7 +436,7 @@
437437 state = 1
438438 else:
439439 raise ArgumentError("State must be either 'ready' or 'suspended'")
440 - resp = self.lib.monitorcommand(struct.pack("IIIIIIII", 19, nameptr, entrypoint, stackptr, stacksize, threadtype, priority, state), "III", ("threadptr", None, None))
 440+ resp = self.lib.monitorcommand(struct.pack("<IIIIIIII", 19, nameptr, entrypoint, stackptr, stacksize, threadtype, priority, state), "III", ("threadptr", None, None))
441441 if resp.threadptr < 0:
442442 raise DeviceError("The device returned the error code %d" % resp.threadptr)
443443 return resp
@@ -444,12 +444,12 @@
445445 @command()
446446 def flushcaches(self):
447447 """ Flushes the CPU instruction and data cache """
448 - return self.lib.monitorcommand(struct.pack("IIII", 20, 0, 0, 0), "III", (None, None, None))
 448+ return self.lib.monitorcommand(struct.pack("<IIII", 20, 0, 0, 0), "III", (None, None, None))
449449
450450 @command()
451451 def execimage(self, addr):
452452 """ Runs the emCORE app at 'addr' """
453 - return self.lib.monitorcommand(struct.pack("IIII", 21, addr, 0, 0), "III", ("thread", None, None))
 453+ return self.lib.monitorcommand(struct.pack("<IIII", 21, addr, 0, 0), "III", ("thread", None, None))
454454
455455 @command()
456456 def run(self, app):
@@ -466,7 +466,7 @@
467467 """ Copies the data in the bootflash at 'flashaddr' of the specified size
468468 to the memory at addr 'memaddr'
469469 """
470 - return self.lib.monitorcommand(struct.pack("IIII", 22, memaddr, flashaddr, size), "III", (None, None, None))
 470+ return self.lib.monitorcommand(struct.pack("<IIII", 22, memaddr, flashaddr, size), "III", (None, None, None))
471471
472472 @command(timeout = 30000)
473473 def bootflashwrite(self, memaddr, flashaddr, size):
@@ -473,13 +473,13 @@
474474 """ Copies the data in the memory at 'memaddr' of the specified size
475475 to the boot flash at addr 'flashaddr'
476476 """
477 - return self.lib.monitorcommand(struct.pack("IIII", 23, memaddr, flashaddr, size), "III", (None, None, None))
 477+ return self.lib.monitorcommand(struct.pack("<IIII", 23, memaddr, flashaddr, size), "III", (None, None, None))
478478
479479 @command()
480480 def execfirmware(self, targetaddr, addr, size):
481481 """ Moves the firmware at 'addr' with size 'size' to 'targetaddr' and passes all control to it. """
482482 self.logger.debug("Moving firmware at 0x%X with the size %d to 0x%X and executing it\n" % (addr, size, targetaddr))
483 - return self.lib.monitorcommand(struct.pack("IIII", 24, targetaddr, addr, size))
 483+ return self.lib.monitorcommand(struct.pack("<IIII", 24, targetaddr, addr, size))
484484
485485 @command(timeout = 30000)
486486 def aesencrypt(self, addr, size, keyindex):
@@ -486,7 +486,7 @@
487487 """ Encrypts the buffer at 'addr' with the specified size
488488 with the hardware AES key index 'keyindex'
489489 """
490 - return self.lib.monitorcommand(struct.pack("IBBHII", 25, 1, 0, keyindex, addr, size), "III", (None, None, None))
 490+ return self.lib.monitorcommand(struct.pack("<IBBHII", 25, 1, 0, keyindex, addr, size), "III", (None, None, None))
491491
492492 @command(timeout = 30000)
493493 def aesdecrypt(self, addr, size, keyindex):
@@ -493,12 +493,12 @@
494494 """ Decrypts the buffer at 'addr' with the specified size
495495 with the hardware AES key index 'keyindex'
496496 """
497 - return self.lib.monitorcommand(struct.pack("IBBHII", 25, 0, 0, keyindex, addr, size), "III", (None, None, None))
 497+ return self.lib.monitorcommand(struct.pack("<IBBHII", 25, 0, 0, keyindex, addr, size), "III", (None, None, None))
498498
499499 @command(timeout = 30000)
500500 def hmac_sha1(self, addr, size, destination):
501501 """ Generates a HMAC-SHA1 hash of the buffer and saves it to 'destination' """
502 - return self.lib.monitorcommand(struct.pack("IIII", 26, addr, size, destination), "III", (None, None, None))
 502+ return self.lib.monitorcommand(struct.pack("<IIII", 26, addr, size, destination), "III", (None, None, None))
503503
504504 @command(target = 0x47324e49)
505505 def ipodnano2g_getnandinfo(self):
@@ -505,7 +505,7 @@
506506 """ Target-specific function: ipodnano2g
507507 Gathers some information about the NAND chip used
508508 """
509 - return self.lib.monitorcommand(struct.pack("IIII", 0xffff0001, 0, 0, 0), "IHHHH", ("type", "pagesperblock", "banks", "userblocks", "blocks"))
 509+ return self.lib.monitorcommand(struct.pack("<IIII", 0xffff0001, 0, 0, 0), "IHHHH", ("type", "pagesperblock", "banks", "userblocks", "blocks"))
510510
511511 @command(timeout = 30000, target = 0x47324e49)
512512 def ipodnano2g_nandread(self, addr, start, count, doecc, checkempty):
@@ -512,7 +512,7 @@
513513 """ Target-specific function: ipodnano2g
514514 Reads data from the NAND chip into memory
515515 """
516 - return self.lib.monitorcommand(struct.pack("IIII", 0xffff0002, addr | (0x80000000 if doecc else 0) | (0x40000000 if checkempty else 0), start, count), "III", (None, None, None))
 516+ return self.lib.monitorcommand(struct.pack("<IIII", 0xffff0002, addr | (0x80000000 if doecc else 0) | (0x40000000 if checkempty else 0), start, count), "III", (None, None, None))
517517
518518 @command(timeout = 30000, target = 0x47324e49)
519519 def ipodnano2g_nandwrite(self, addr, start, count, doecc):
@@ -519,7 +519,7 @@
520520 """ Target-specific function: ipodnano2g
521521 Writes data to the NAND chip
522522 """
523 - return self.lib.monitorcommand(struct.pack("IIII", 0xffff0003, addr | (0x80000000 if doecc else 0), start, count), "III", (None, None, None))
 523+ return self.lib.monitorcommand(struct.pack("<IIII", 0xffff0003, addr | (0x80000000 if doecc else 0), start, count), "III", (None, None, None))
524524
525525 @command(timeout = 30000, target = 0x47324e49)
526526 def ipodnano2g_nanderase(self, addr, start, count):
@@ -526,7 +526,7 @@
527527 """ Target-specific function: ipodnano2g
528528 Erases blocks on the NAND chip and stores the results to memory
529529 """
530 - return self.lib.monitorcommand(struct.pack("IIII", 0xffff0004, addr, start, count), "III", (None, None, None))
 530+ return self.lib.monitorcommand(struct.pack("<IIII", 0xffff0004, addr, start, count), "III", (None, None, None))
531531
532532 @command(target = 0x4c435049)
533533 def ipodclassic_gethddinfo(self):
@@ -533,7 +533,7 @@
534534 """ Target-specific function: ipodclassic
535535 Gather information about the hard disk drive
536536 """
537 - return self.lib.monitorcommand(struct.pack("IIII", 0xffff0001, 0, 0, 0), "IQQII", ("identifyptr", "totalsectors", "virtualsectors", "bbtptr", "bbtsize"))
 537+ return self.lib.monitorcommand(struct.pack("<IIII", 0xffff0001, 0, 0, 0), "IQQII", ("identifyptr", "totalsectors", "virtualsectors", "bbtptr", "bbtsize"))
538538
539539 @command(timeout = 30000, target = 0x4c435049)
540540 def ipodclassic_hddaccess(self, type, sector, count, addr):
@@ -540,7 +540,7 @@
541541 """ Target-specific function: ipodclassic
542542 Access the hard disk, type = 0 (read) / 1 (write)
543543 """
544 - rc = self.lib.monitorcommand(struct.pack("IIQIIII", 0xffff0002, type, sector, count, addr, 0, 0), "III", ("rc", None, None))
 544+ rc = self.lib.monitorcommand(struct.pack("<IIQIIII", 0xffff0002, type, sector, count, addr, 0, 0), "III", ("rc", None, None))
545545 if (rc > 0x80000000):
546546 raise DeviceError("HDD access (type=%d, sector=%d, count=%d, addr=0x%08X) failed with RC 0x%08X" % (type, sector, count, addr, rc))
547547
@@ -575,7 +575,7 @@
576576 def storage_get_info(self, volume):
577577 """ Get information about a storage device """
578578 self.logger.debug("Getting storage information\n")
579 - result = self.lib.monitorcommand(struct.pack("IIII", 27, volume, 0, 0), "IIIIIIII", ("version", None, None, "sectorsize", "numsectors", "vendorptr", "productptr", "revisionptr"))
 579+ result = self.lib.monitorcommand(struct.pack("<IIII", 27, volume, 0, 0), "IIIIIIII", ("version", None, None, "sectorsize", "numsectors", "vendorptr", "productptr", "revisionptr"))
580580 if result.version != 1:
581581 raise ValueError("Unknown version of storage_info struct: %d" % result.version)
582582 result.vendor = self.readstring(result.vendorptr)
@@ -593,7 +593,7 @@
594594 def storage_read_sectors_md(self, volume, sector, count, addr):
595595 """ Read sectors from as storage device """
596596 self.logger.debug("Reading %d sectors from disk at volume %d, sector %d to memory at 0x%X\n" % (count, volume, sector, addr))
597 - result = self.lib.monitorcommand(struct.pack("IIQIIII", 28, volume, sector, count, addr, 0, 0), "III", ("rc", None, None))
 597+ result = self.lib.monitorcommand(struct.pack("<IIQIIII", 28, volume, sector, count, addr, 0, 0), "III", ("rc", None, None))
598598 self.logger.debug("Read sectors, result: 0x%X\n" % result.rc)
599599 if result.rc > 0x80000000:
600600 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))
@@ -602,7 +602,7 @@
603603 def storage_write_sectors_md(self, volume, sector, count, addr):
604604 """ Read sectors from as storage device """
605605 self.logger.debug("Writing %d sectors from memory at 0x%X to disk at volume %d, sector %d\n" % (count, addr, volume, sector))
606 - result = self.lib.monitorcommand(struct.pack("IIQIIII", 29, volume, sector, count, addr, 0, 0), "III", ("rc", None, None))
 606+ result = self.lib.monitorcommand(struct.pack("<IIQIIII", 29, volume, sector, count, addr, 0, 0), "III", ("rc", None, None))
607607 self.logger.debug("Wrote sectors, result: 0x%X\n" % result.rc)
608608 if result.rc > 0x80000000:
609609 raise DeviceError("storage_write_sectors_md(volume=%d, sector=%d, count=%d, addr=0x%08X) failed with RC 0x%08X" % (volume, sector, count, addr, rc))
@@ -612,7 +612,7 @@
613613 """ Enables/disables flushing the FAT cache after every transaction """
614614 if state != 0: self.logger.debug("Enabling FAT flushing\n")
615615 else: self.logger.debug("Disabling FAT flushing\n")
616 - self.lib.monitorcommand(struct.pack("IIII", 58, state, 0, 0), "III", (None, None, None))
 616+ self.lib.monitorcommand(struct.pack("<IIII", 58, state, 0, 0), "III", (None, None, None))
617617 if state != 0: self.logger.debug("Enabled FAT flushing\n")
618618 else: self.logger.debug("Disabled FAT flushing\n")
619619
@@ -620,7 +620,7 @@
621621 def file_open(self, filename, mode):
622622 """ Opens a file and returns the handle """
623623 self.logger.debug("Opening remote file %s with mode %d\n" % (filename, mode))
624 - result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(filename), 30, mode, 0, 0, filename, 0), "III", ("fd", None, None))
 624+ result = self.lib.monitorcommand(struct.pack("<IIII%dsB" % len(filename), 30, mode, 0, 0, filename, 0), "III", ("fd", None, None))
625625 if result.fd > 0x80000000:
626626 raise DeviceError("file_open(filename=\"%s\", mode=0x%X) failed with RC=0x%08X, errno=%d" % (filename, mode, result.fd, self.errno()))
627627 self.logger.debug("Opened file as handle 0x%X\n" % result.fd)
@@ -630,7 +630,7 @@
631631 def file_size(self, fd):
632632 """ Gets the size of a file referenced by a handle """
633633 self.logger.debug("Getting file size of handle 0x%X\n" % fd)
634 - result = self.lib.monitorcommand(struct.pack("IIII", 31, fd, 0, 0), "III", ("size", None, None))
 634+ result = self.lib.monitorcommand(struct.pack("<IIII", 31, fd, 0, 0), "III", ("size", None, None))
635635 if result.size > 0x80000000:
636636 raise DeviceError("file_size(fd=%d) failed with RC=0x%08X, errno=%d" % (fd, result.size, self.errno()))
637637 self.logger.debug("Got file size: %d bytes\n" % result.size)
@@ -646,7 +646,7 @@
647647 malloc = False
648648 self.logger.debug("Reading %d bytes from file handle 0x%X to 0x%X\n" % (size, fd, addr))
649649 try:
650 - result = self.lib.monitorcommand(struct.pack("IIII", 32, fd, addr, size), "III", ("rc", None, None))
 650+ result = self.lib.monitorcommand(struct.pack("<IIII", 32, fd, addr, size), "III", ("rc", None, None))
651651 if result.rc > 0x80000000:
652652 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()))
653653 except:
@@ -660,7 +660,7 @@
661661 def file_write(self, fd, size, addr):
662662 """ Writes data from a file referenced by a handle. """
663663 self.logger.debug("Writing %d bytes from 0x%X to file handle 0x%X\n" % (size, addr, fd))
664 - result = self.lib.monitorcommand(struct.pack("IIII", 33, fd, addr, size), "III", ("rc", None, None))
 664+ result = self.lib.monitorcommand(struct.pack("<IIII", 33, fd, addr, size), "III", ("rc", None, None))
665665 if result.rc > 0x80000000:
666666 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()))
667667 self.logger.debug("File write result: 0x%X\n" % result.rc)
@@ -670,7 +670,7 @@
671671 def file_seek(self, fd, offset, whence):
672672 """ Seeks the file handle to the specified position in the file """
673673 self.logger.debug("Seeking file handle 0x%X to whence=%d, offset=0x%X\n" % (fd, whence, offset))
674 - result = self.lib.monitorcommand(struct.pack("IIII", 34, fd, offset, whence), "III", ("rc", None, None))
 674+ result = self.lib.monitorcommand(struct.pack("<IIII", 34, fd, offset, whence), "III", ("rc", None, None))
675675 if result.rc > 0x80000000:
676676 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()))
677677 self.logger.debug("File seek result: 0x%X\n" % (result.rc))
@@ -680,7 +680,7 @@
681681 def file_truncate(self, fd, length):
682682 """ Truncates a file referenced by a handle to a specified length """
683683 self.logger.debug("Truncating file with handle 0x%X to 0x%X bytes\n" % (fd, length))
684 - result = self.lib.monitorcommand(struct.pack("IIII", 35, fd, offset, 0), "III", ("rc", None, None))
 684+ result = self.lib.monitorcommand(struct.pack("<IIII", 35, fd, offset, 0), "III", ("rc", None, None))
685685 if result.rc > 0x80000000:
686686 raise DeviceError("file_truncate(fd=%d, length=0x%08X) failed with RC=0x%08X, errno=%d" % (fd, length, result.rc, self.errno()))
687687 self.logger.debug("File truncate result: 0x%X\n" % (result.rc))
@@ -690,7 +690,7 @@
691691 def file_sync(self, fd):
692692 """ Flushes a file handles' buffers """
693693 self.logger.debug("Flushing buffers of file with handle 0x%X\n" % (fd))
694 - result = self.lib.monitorcommand(struct.pack("IIII", 36, fd, 0, 0), "III", ("rc", None, None))
 694+ result = self.lib.monitorcommand(struct.pack("<IIII", 36, fd, 0, 0), "III", ("rc", None, None))
695695 if result.rc > 0x80000000:
696696 raise DeviceError("file_sync(fd=%d) failed with RC=0x%08X, errno=%d" % (fd, result.rc, self.errno()))
697697 self.logger.debug("File flush result: 0x%X\n" % (result.rc))
@@ -700,7 +700,7 @@
701701 def file_close(self, fd):
702702 """ Closes a file handle """
703703 self.logger.debug("Closing file handle 0x%X\n" % (fd))
704 - result = self.lib.monitorcommand(struct.pack("IIII", 37, fd, 0, 0), "III", ("rc", None, None))
 704+ result = self.lib.monitorcommand(struct.pack("<IIII", 37, fd, 0, 0), "III", ("rc", None, None))
705705 if result.rc > 0x80000000:
706706 raise DeviceError("file_close(fd=%d) failed with RC=0x%08X, errno=%d" % (fd, result.rc, self.errno()))
707707 self.logger.debug("File close result: 0x%X\n" % (result.rc))
@@ -710,7 +710,7 @@
711711 def file_close_all(self):
712712 """ Closes all file handles opened through the debugger """
713713 self.logger.debug("Closing all files that were opened via USB\n")
714 - result = self.lib.monitorcommand(struct.pack("IIII", 38, 0, 0, 0), "III", ("rc", None, None))
 714+ result = self.lib.monitorcommand(struct.pack("<IIII", 38, 0, 0, 0), "III", ("rc", None, None))
715715 if result.rc > 0x80000000:
716716 raise DeviceError("file_close_all() failed with RC=0x%08X, errno=%d" % (result.rc, self.errno()))
717717 self.logger.debug("Closed %d files\n" % (result.rc))
@@ -720,7 +720,7 @@
721721 def file_kill_all(self, volume):
722722 """ Kills all file handles of a volume (in the whole system) """
723723 self.logger.debug("Killing all file handles of volume %d\n" % (volume))
724 - result = self.lib.monitorcommand(struct.pack("IIII", 39, volume, 0, 0), "III", ("rc", None, None))
 724+ result = self.lib.monitorcommand(struct.pack("<IIII", 39, volume, 0, 0), "III", ("rc", None, None))
725725 if result.rc > 0x80000000:
726726 raise DeviceError("file_kill_all() failed with RC=0x%08X, errno=%d" % (result.rc, self.errno()))
727727 self.logger.debug("Closed %d files\n" % (result.rc))
@@ -730,7 +730,7 @@
731731 def file_unlink(self, filename):
732732 """ Removes a file """
733733 self.logger.debug("Deleting file %s\n" % (filename))
734 - result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(filename), 40, 0, 0, 0, filename, 0), "III", ("rc", None, None))
 734+ result = self.lib.monitorcommand(struct.pack("<IIII%dsB" % len(filename), 40, 0, 0, 0, filename, 0), "III", ("rc", None, None))
735735 if result.rc > 0x80000000:
736736 raise DeviceError("file_unlink(filename=\"%s\") failed with RC=0x%08X, errno=%d" % (filename, result.rc, self.errno()))
737737 self.logger.debug("Delete file result: 0x%X\n" % (result.rc))
@@ -740,7 +740,7 @@
741741 def file_rename(self, oldname, newname):
742742 """ Renames a file """
743743 self.logger.debug("Renaming file %s to %s\n" % (oldname, newname))
744 - result = self.lib.monitorcommand(struct.pack("IIII248s%dsB" % min(247, len(newname)), 41, 0, 0, 0, oldname, newname, 0), "III", ("rc", None, None))
 744+ result = self.lib.monitorcommand(struct.pack("<IIII248s%dsB" % min(247, len(newname)), 41, 0, 0, 0, oldname, newname, 0), "III", ("rc", None, None))
745745 if result.rc > 0x80000000:
746746 raise DeviceError("file_rename(oldname=\"%s\", newname=\"%s\") failed with RC=0x%08X, errno=%d" % (oldname, newname, result.rc, self.errno()))
747747 self.logger.debug("Rename file result: 0x%X\n" % (result.rc))
@@ -750,7 +750,7 @@
751751 def dir_open(self, dirname):
752752 """ Opens a directory and returns the handle """
753753 self.logger.debug("Opening directory %s\n" % (dirname))
754 - result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(dirname), 42, 0, 0, 0, dirname, 0), "III", ("handle", None, None))
 754+ result = self.lib.monitorcommand(struct.pack("<IIII%dsB" % len(dirname), 42, 0, 0, 0, dirname, 0), "III", ("handle", None, None))
755755 if result.handle == 0:
756756 raise DeviceError("dir_open(dirname=\"%s\") failed with RC=0x%08X, errno=%d" % (dirname, result.handle, self.errno()))
757757 self.logger.debug("Opened directory as handle 0x%X\n" % (result.handle))
@@ -760,7 +760,7 @@
761761 def dir_read(self, handle):
762762 """ Reads the next entry from a directory """
763763 self.logger.debug("Reading next entry of directory handle 0x%X\n" % (handle))
764 - result = self.lib.monitorcommand(struct.pack("IIII", 43, handle, 0, 0), "III", ("version", "maxpath", "ptr"))
 764+ result = self.lib.monitorcommand(struct.pack("<IIII", 43, handle, 0, 0), "III", ("version", "maxpath", "ptr"))
765765 if result.ptr == 0:
766766 raise DeviceError("dir_read(handle=0x%08X) failed with RC=0x%08X, errno=%d" % (handle, result.ptr, self.errno()))
767767 if result.version != 1:
@@ -767,7 +767,7 @@
768768 raise ValueError("Unknown version of dirent struct: %d" % result.version)
769769 dirent = self.read(result.ptr, result.maxpath + 16)
770770 ret = Bunch()
771 - (ret.name, ret.attributes, ret.size, ret.startcluster, ret.wrtdate, ret.wrttime) = struct.unpack("%dsIIIHH" % result.maxpath, dirent)
 771+ (ret.name, ret.attributes, ret.size, ret.startcluster, ret.wrtdate, ret.wrttime) = struct.unpack("<%dsIIIHH" % result.maxpath, dirent)
772772 ret.name = ret.name[:ret.name.index('\x00')]
773773 self.logger.debug("Read directory entry:\n")
774774 self.logger.debug("Name: %s\n" % ret.name)
@@ -782,7 +782,7 @@
783783 def dir_close(self, handle):
784784 """ Closes a directory handle """
785785 self.logger.debug("Closing directory handle 0x%X\n" % (handle))
786 - result = self.lib.monitorcommand(struct.pack("IIII", 44, handle, 0, 0), "III", ("rc", None, None))
 786+ result = self.lib.monitorcommand(struct.pack("<IIII", 44, handle, 0, 0), "III", ("rc", None, None))
787787 if result.rc > 0x80000000:
788788 raise DeviceError("dir_close(handle=0x%08X) failed with RC=0x%08X, errno=%d" % (handle, result.rc, self.errno()))
789789 self.logger.debug("Close directory result: 0x%X\n" % (result.rc))
@@ -792,7 +792,7 @@
793793 def dir_close_all(self):
794794 """ Closes all directory handles opened through the debugger """
795795 self.logger.debug("Closing all directories that were opened via USB\n")
796 - result = self.lib.monitorcommand(struct.pack("IIII", 45, 0, 0, 0), "III", ("rc", None, None))
 796+ result = self.lib.monitorcommand(struct.pack("<IIII", 45, 0, 0, 0), "III", ("rc", None, None))
797797 if result.rc > 0x80000000:
798798 raise DeviceError("dir_close_all() failed with RC=0x%08X, errno=%d" % (result.rc, self.errno()))
799799 self.logger.debug("Closed %d directories\n" % (result.rc))
@@ -802,7 +802,7 @@
803803 def dir_kill_all(self, volume):
804804 """ Kills all directory handles of a volume (in the whole system) """
805805 self.logger.debug("Closing all directories of volume %d\n" % (volume))
806 - result = self.lib.monitorcommand(struct.pack("IIII", 46, volume, 0, 0), "III", ("rc", None, None))
 806+ result = self.lib.monitorcommand(struct.pack("<IIII", 46, volume, 0, 0), "III", ("rc", None, None))
807807 if result.rc > 0x80000000:
808808 raise DeviceError("dir_kill_all() failed with RC=0x%08X, errno=%d" % (result.rc, self.errno()))
809809 self.logger.debug("Closed %d directories\n" % (result.rc))
@@ -812,7 +812,7 @@
813813 def dir_create(self, dirname):
814814 """ Creates a directory """
815815 self.logger.debug("Creating directory %s\n" % (dirname))
816 - result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(dirname), 47, 0, 0, 0, dirname, 0), "III", ("rc", None, None))
 816+ result = self.lib.monitorcommand(struct.pack("<IIII%dsB" % len(dirname), 47, 0, 0, 0, dirname, 0), "III", ("rc", None, None))
817817 if result.rc > 0x80000000:
818818 raise DeviceError("dir_create(dirname=\"%s\") failed with RC=0x%08X, errno=%d" % (dirname, result.rc, self.errno()))
819819 self.logger.debug("Create directory result: 0x%X\n" % (result.rc))
@@ -822,7 +822,7 @@
823823 def dir_remove(self, dirname):
824824 """ Removes an (empty) directory """
825825 self.logger.debug("Removing directory %s\n" % (dirname))
826 - result = self.lib.monitorcommand(struct.pack("IIII%dsB" % len(dirname), 48, 0, 0, 0, dirname, 0), "III", ("rc", None, None))
 826+ result = self.lib.monitorcommand(struct.pack("<IIII%dsB" % len(dirname), 48, 0, 0, 0, dirname, 0), "III", ("rc", None, None))
827827 if result.rc > 0x80000000:
828828 raise DeviceError("dir_remove(dirname=\"%s\") failed with RC=0x%08X, errno=%d" % (dirname, result.rc, self.errno()))
829829 self.logger.debug("Remove directory result: 0x%X\n" % (result.rc))
@@ -832,7 +832,7 @@
833833 def errno(self):
834834 """ Returns the number of the last error that happened """
835835 self.logger.debug("Getting last error number\n")
836 - result = self.lib.monitorcommand(struct.pack("IIII", 49, 0, 0, 0), "III", ("errno", None, None))
 836+ result = self.lib.monitorcommand(struct.pack("<IIII", 49, 0, 0, 0), "III", ("errno", None, None))
837837 self.logger.debug("Last error: 0x%X\n" % (result.errno))
838838 return result.errno
839839
@@ -840,7 +840,7 @@
841841 def disk_mount(self, volume):
842842 """ Mounts a volume """
843843 self.logger.debug("Mounting volume %d\n" % (volume))
844 - result = self.lib.monitorcommand(struct.pack("IIII", 50, volume, 0, 0), "III", ("rc", None, None))
 844+ result = self.lib.monitorcommand(struct.pack("<IIII", 50, volume, 0, 0), "III", ("rc", None, None))
845845 if result.rc > 0x80000000:
846846 raise DeviceError("disk_mount(volume=%d) failed with RC=0x%08X, errno=%d" % (volume, result.rc, self.errno()))
847847 self.logger.debug("Mount volume result: 0x%X\n" % (result.rc))
@@ -850,7 +850,7 @@
851851 def disk_unmount(self, volume):
852852 """ Unmounts a volume """
853853 self.logger.debug("Unmounting volume %d\n" % (volume))
854 - result = self.lib.monitorcommand(struct.pack("IIII", 51, volume, 0, 0), "III", ("rc", None, None))
 854+ result = self.lib.monitorcommand(struct.pack("<IIII", 51, volume, 0, 0), "III", ("rc", None, None))
855855 if result.rc > 0x80000000:
856856 raise DeviceError("disk_unmount(volume=%d) failed with RC=0x%08X, errno=%d" % (volume, result.rc, self.errno()))
857857 self.logger.debug("Unmount volume result: 0x%X\n" % (result.rc))
@@ -860,7 +860,7 @@
861861 def malloc(self, size):
862862 """ Allocates 'size' bytes and returns a pointer to the allocated memory """
863863 self.logger.debug("Allocating %d bytes of memory\n" % size)
864 - result = self.lib.monitorcommand(struct.pack("IIII", 52, size, 0, 0), "III", ("ptr", None, None))
 864+ result = self.lib.monitorcommand(struct.pack("<IIII", 52, size, 0, 0), "III", ("ptr", None, None))
865865 self.logger.debug("Allocated %d bytes of memory at 0x%X\n" % (size, result.ptr))
866866 return result.ptr
867867
@@ -868,7 +868,7 @@
869869 def memalign(self, align, size):
870870 """ Allocates 'size' bytes aligned to 'align' and returns a pointer to the allocated memory """
871871 self.logger.debug("Allocating %d bytes of memory aligned to 0x%X\n" % (size, align))
872 - result = self.lib.monitorcommand(struct.pack("IIII", 53, align, size, 0), "III", ("ptr", None, None))
 872+ result = self.lib.monitorcommand(struct.pack("<IIII", 53, align, size, 0), "III", ("ptr", None, None))
873873 self.logger.debug("Allocated %d bytes of memory at 0x%X\n" % (size, result.ptr))
874874 return result.ptr
875875
@@ -879,7 +879,7 @@
880880 Returns a pointer to the reallocated memory.
881881 """
882882 self.logger.debug("Reallocating 0x%X to have the new size %d\n" % (ptr, size))
883 - result = self.lib.monitorcommand(struct.pack("IIII", 54, ptr, size, 0), "III", ("ptr", None, None))
 883+ result = self.lib.monitorcommand(struct.pack("<IIII", 54, ptr, size, 0), "III", ("ptr", None, None))
884884 self.logger.debug("Reallocated memory at 0x%X to 0x%X with the new size %d\n" % (ptr, result.ptr, size))
885885 return result.ptr
886886
@@ -887,19 +887,19 @@
888888 def reownalloc(self, ptr, owner):
889889 """ Changes the owner of the memory allocation 'ptr' to the thread struct at addr 'owner' """
890890 self.logger.debug("Changing owner of the memory region 0x%X to 0x%X\n" % (ptr, owner))
891 - return self.lib.monitorcommand(struct.pack("IIII", 55, ptr, owner, 0), "III", (None, None, None))
 891+ return self.lib.monitorcommand(struct.pack("<IIII", 55, ptr, owner, 0), "III", (None, None, None))
892892
893893 @command()
894894 def free(self, ptr):
895895 """ Frees the memory space pointed to by 'ptr' """
896896 self.logger.debug("Freeing the memory region at 0x%X\n" % ptr)
897 - return self.lib.monitorcommand(struct.pack("IIII", 56, ptr, 0, 0), "III", (None, None, None))
 897+ return self.lib.monitorcommand(struct.pack("<IIII", 56, ptr, 0, 0), "III", (None, None, None))
898898
899899 @command()
900900 def free_all(self):
901901 """ Frees all memory allocations created by the monitor thread """
902902 self.logger.debug("Freeing all memory allocations created by the monitor thread\n")
903 - return self.lib.monitorcommand(struct.pack("IIII", 57, 0, 0, 0), "III", (None, None, None))
 903+ return self.lib.monitorcommand(struct.pack("<IIII", 57, 0, 0, 0), "III", (None, None, None))
904904
905905
906906 class Lib(object):