Skip to content

Instantly share code, notes, and snippets.

@edy555
Created February 13, 2014 14:53
Show Gist options
  • Select an option

  • Save edy555/8976352 to your computer and use it in GitHub Desktop.

Select an option

Save edy555/8976352 to your computer and use it in GitHub Desktop.
append header onto binary file for writing dfu-util
#!/usr/bin/env python
import struct
import sys
fin = open(sys.argv[1], 'rb')
fout = open(sys.argv[2], 'wb')
bin = fin.read()
fin.close()
n = (len(bin) + 511) / 512
fout.write('\32\77%s\0\0\0\0\0\0\0\0\377\377\377\377' % struct.pack('<H', n))
fout.write(bin)
fout.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment