Last active
August 29, 2015 14:24
-
-
Save pamaury/b59f4abaf5e6bbbdcb5e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
diff --git a/dfu/adfu.py b/dfu/adfu.py | |
index 6ea80a0..e454c8b 100644 | |
--- a/dfu/adfu.py | |
+++ b/dfu/adfu.py | |
@@ -181,6 +181,20 @@ def adfu_read_result_block(size): | |
0, # unused | |
0, 0, 0) | |
+def adfu_read_from_memory(length, start_address): | |
+ return struct.pack('<IIIBBBBIIIBBB', | |
+ 0x43425355, # 'USBC' | |
+ 0x00000000, # tag | |
+ length, | |
+ 0x80, # flags | |
+ 0, # LUN | |
+ 0x10, # CDB length | |
+ 0xcd, | |
+ 0x00000093, # command | |
+ length, | |
+ start_address, | |
+ 0, 0, 0) | |
+ | |
def run_code(filename): | |
# Prepare to read data | |
with open('ADFUS.BIN', 'rb') as h: | |
@@ -216,18 +230,48 @@ def run_code(filename): | |
print(dev.read(EP_FROM_DEVICE, 512)) | |
print(dev.read(EP_FROM_DEVICE, 512)) | |
+def upload_afdu(): | |
+ # Prepare to read data | |
+ with open('ADFUS.BIN', 'rb') as h: | |
+ adfus = h.read() | |
+ | |
+ dev = _find_device(ADFU_DEVICES) | |
+ | |
+ dev.write(EP_TO_DEVICE, adfu_write_to_ram(len(adfus), 0xbfc18000)) | |
+ dev.write(EP_TO_DEVICE, adfus) | |
+ print(dev.read(EP_FROM_DEVICE, 512)) | |
+ | |
+ dev.write(EP_TO_DEVICE, adfu_prepare_exec(0xbfc18000)) | |
+ print(dev.read(EP_FROM_DEVICE, 512)) | |
+ | |
+ print("start exec") | |
+ | |
+def dump_rom(filename): | |
+ dev = _find_device(ADFU_DEVICES) | |
+ with open(filename, 'wb') as h: | |
+ for x in range(0, 64): | |
+ dev.write(EP_TO_DEVICE, adfu_read_from_memory(512, 0xbfc00000 + x * 512)) | |
+ # print(dev.read(EP_FROM_DEVICE, 512)) | |
+ h.write(dev.read(EP_FROM_DEVICE, 512)) | |
+ print(dev.read(EP_FROM_DEVICE, 512)) | |
+ | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser() | |
- parser.add_argument('command', choices=('adfu', 'udisk', 'run_code')) | |
+ parser.add_argument('command', choices=('adfu', 'udisk', 'run_code', 'upload_afdu', 'dump_rom')) | |
parser.add_argument('args', nargs='*') | |
args = parser.parse_args() | |
+ | |
if args.command == 'adfu': | |
switch_to_dfu(*args.args) | |
elif args.command == 'udisk': | |
switch_to_udisk(*args.args) | |
elif args.command == 'run_code': | |
run_code(*args.args) | |
+ elif args.command == "upload_afdu": | |
+ upload_afdu(*args.args) | |
+ elif args.command == "dump_rom": | |
+ dump_rom(*args.args) | |
else: | |
raise NotImplementedError() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment