From 71d0c483f8c5816206eb9c4eb391562f8588e51b Mon Sep 17 00:00:00 2001 From: mruddy Date: Mon, 20 Feb 2017 08:36:00 -0500 Subject: [PATCH] add tools support for reading bootloader from debug link enabled device (#99) --- tools/mem_read.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/tools/mem_read.py b/tools/mem_read.py index f0e676e2ff..0e30fddb4f 100755 --- a/tools/mem_read.py +++ b/tools/mem_read.py @@ -7,6 +7,14 @@ from trezorlib.transport_hid import HidTransport import binascii import sys +# usage examples +# read entire bootloader: ./mem_read.py 8000000 8000 +# read initial stack pointer: ./mem_read.py 8000000 4 +# an entire bootloader can be later disassembled with: +# arm-none-eabi-objdump -D -b binary -m arm -M force-thumb memory.dat +# note that in order for this to work, your trezor device must +# be running a firmware that was built with debug link enabled + def main(): # List all connected TREZORs on USB devices = HidTransport.enumerate() @@ -24,9 +32,16 @@ def main(): client = TrezorClient(transport) debug = DebugLink(debug_transport) - mem = debug.memory_read(int(sys.argv[1],16), int(sys.argv[2],16)) + arg1 = int(sys.argv[1], 16) + arg2 = int(sys.argv[2], 16) + step = 0x400 if arg2 >= 0x400 else arg2 + f = open('memory.dat', 'w') - f.write(mem) + + for addr in range(arg1, arg1 + arg2, step): + mem = debug.memory_read(addr, step) + f.write(mem) + f.close() client.close()