Skip to content

Instantly share code, notes, and snippets.

@geekman
Created November 18, 2019 07:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save geekman/d63139312a36f1478b1cbfc53279ec61 to your computer and use it in GitHub Desktop.
Save geekman/d63139312a36f1478b1cbfc53279ec61 to your computer and use it in GitHub Desktop.
minicom script generator for dumping firmware
#!/usr/bin/python2
#
# script to generate a minicom script that dumps entire flash
# problem is the stub seems to read all data into RAM first,
# so you can only do in batches
#
# 2019.10.24
# inc needs to be low enough to complete within `expect` timeout
inc = 0x20000
end = 0x1000000
addr = 0
prompt = 'flash> '
dump_cmd = r'dump -p /dev/mtdblock0 -r 0x{addr:08x} -l 0x{len:08x} -4\n'
print r"""#
# dump firmware answer file, generated by dumpscript-gen.py
#
timeout 86400 # one day ought to be enough
# test it works
sleep 2
send "\n\n"
expect {{
"{prompt}" break
timeout 5 goto end
}}
""".format(prompt=prompt)
while addr < end:
l = min(end - addr, inc)
cmd = dump_cmd.format(addr=addr, len=l)
print 'send "{cmd}"\nexpect "{prompt}"'.format(cmd=cmd, prompt=prompt)
addr += inc
print """
end:
print "dumpscript done."
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment