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