diff options
author | Michael Hope <michael.hope@linaro.org> | 2010-09-29 20:28:39 +1300 |
---|---|---|
committer | Michael Hope <michael.hope@linaro.org> | 2010-09-29 20:28:39 +1300 |
commit | 0fcccd921ef306f6c7ba87b063ad037d2c0bd1e8 (patch) | |
tree | dba1864c9353dba3f31397cfc8c82d2a10da6ca3 | |
parent | d470dc6daa46f26fc995ec86929e8209c581ea2d (diff) | |
download | librambutan-0fcccd921ef306f6c7ba87b063ad037d2c0bd1e8.tar.gz librambutan-0fcccd921ef306f6c7ba87b063ad037d2c0bd1e8.zip |
Added support for programming ELF files without converting first.
-rwxr-xr-x | support/stm32loader.py | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/support/stm32loader.py b/support/stm32loader.py index b7fb96c..02ca4e8 100755 --- a/support/stm32loader.py +++ b/support/stm32loader.py @@ -27,6 +27,9 @@ import serial import time import glob import time +import tempfile +import os +import subprocess try: from progressbar import * @@ -338,6 +341,34 @@ def usage(): """ % sys.argv[0] +def read(filename): + """Read the file to be programmed and turn it into a binary""" + with open(filename, 'rb') as f: + bytes = f.read() + + if bytes.startswith('\x7FELF'): + # Actually an ELF file. Convert to binary + handle, path = tempfile.mkstemp(suffix='.bin', prefix='stm32loader') + + try: + os.close(handle) + + # Try a couple of options for objcopy + for name in ['arm-none-eabi-objcopy', 'arm-linux-gnueabi-objcopy']: + try: + code = subprocess.call([name, '-Obinary', filename, path]) + + if code == 0: + return read(path) + except OSError: + pass + else: + raise Exception('Error %d while converting to a binary file' % code) + finally: + # Remove the temporary file + os.unlink(path) + else: + return [ord(x) for x in bytes] if __name__ == "__main__": @@ -420,6 +451,9 @@ if __name__ == "__main__": cmd.open(conf['port'], conf['baud']) mdebug(10, "Open port %(port)s, baud %(baud)d" % {'port':conf['port'], 'baud':conf['baud']}) try: + if (conf['write'] or conf['verify']): + data = read(args[0]) + try: cmd.initChip() except CmdException: @@ -444,9 +478,6 @@ if __name__ == "__main__": # cmd.cmdWriteUnprotect() # cmd.cmdWriteProtect([0, 1]) - if (conf['write'] or conf['verify']): - data = map(lambda c: ord(c), file(args[0]).read()) - if conf['erase']: cmd.cmdEraseMemory() |