| Index: emcore/trunk/tools/emcore.py |
| — | — | @@ -256,6 +256,58 @@ |
| 257 | 257 | self.logger.info("done\n")
|
| 258 | 258 |
|
| 259 | 259 | @command
|
| | 260 | + def hexdump(self, addr, size, width = 16, wordsize = 1, separate = 4, \
|
| | 261 | + align = False, relative = False, ascii = True, asciisep = 8):
|
| | 262 | + """
|
| | 263 | + Downloads a region of memory from the device and hexdumps it
|
| | 264 | + <addr>: the address to download the data from
|
| | 265 | + <size>: the number of bytes to be dumped
|
| | 266 | + [width]: the number of words per output line
|
| | 267 | + [wordsize]: the number of bytes per word (little endian)
|
| | 268 | + [separate]: add an additional space character every [separate] words
|
| | 269 | + [align]: if true, output lines are aligned to the line size
|
| | 270 | + [relative]: if true, the addresses displayed are relative to the <addr>, not zero
|
| | 271 | + [ascii]: add ASCII representations of the bytes to the output
|
| | 272 | + [asciisep]: add an additional space character every [asciisep] ASCII characters
|
| | 273 | + """
|
| | 274 | + addr = to_int(addr)
|
| | 275 | + size = to_int(size)
|
| | 276 | + width = to_int(width)
|
| | 277 | + wordsize = to_int(wordsize)
|
| | 278 | + separate = to_int(separate)
|
| | 279 | + align = to_bool(align)
|
| | 280 | + relative = to_bool(relative)
|
| | 281 | + ascii = to_bool(ascii)
|
| | 282 | + asciisep = to_int(asciisep)
|
| | 283 | + if addr % wordsize != 0: raise ArgumentError("Address is not word aligned!")
|
| | 284 | + if size % wordsize != 0: raise ArgumentError("Size is not word aligned!")
|
| | 285 | + if align: skip = addr % (wordsize * width)
|
| | 286 | + else: skip = 0
|
| | 287 | + if relative: base = 0
|
| | 288 | + else: base = addr
|
| | 289 | + data = self.emcore.read(addr, size)
|
| | 290 | + for r in range(-skip, size, wordsize * width):
|
| | 291 | + sys.stdout.write("%08X:" % (base + r))
|
| | 292 | + for i in range(r, r + wordsize * width, wordsize):
|
| | 293 | + if i - r > 0 and (i - r) % (separate * wordsize) == 0: sys.stdout.write(" ")
|
| | 294 | + if i >= 0 and i < size:
|
| | 295 | + w = 0
|
| | 296 | + for b in range(wordsize):
|
| | 297 | + w = (w << 8) | struct.unpack("B", data[i + b])[0]
|
| | 298 | + sys.stdout.write((" %%%dX" % (wordsize * 2)) % w)
|
| | 299 | + else: sys.stdout.write(" " * (wordsize * 2 + 1))
|
| | 300 | + if ascii:
|
| | 301 | + sys.stdout.write(" |")
|
| | 302 | + for i in range(r, r + wordsize * width):
|
| | 303 | + if i - r > 0 and (i - r) % asciisep == 0: sys.stdout.write(" ")
|
| | 304 | + if i >= 0 and i < size:
|
| | 305 | + if ord(data[i]) > 0x1f: sys.stdout.write(data[i])
|
| | 306 | + else: sys.stdout.write(".")
|
| | 307 | + else: sys.stdout.write(" ")
|
| | 308 | + sys.stdout.write("|")
|
| | 309 | + sys.stdout.write("\n")
|
| | 310 | +
|
| | 311 | + @command
|
| 260 | 312 | def uploadint(self, addr, integer):
|
| 261 | 313 | """
|
| 262 | 314 | Uploads a single integer to the device
|