Created
November 18, 2019 07:47
-
-
Save geekman/d63139312a36f1478b1cbfc53279ec61 to your computer and use it in GitHub Desktop.
minicom script generator for dumping firmware
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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