Created
September 7, 2010 21:26
-
-
Save phooky/569140 to your computer and use it in GitHub Desktop.
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/env python | |
# Here's a useful skeleton for generating (in this case) an intel hex file | |
# for filling size bytes with 0xff; it can be easily modified to convert | |
# bytes from stdin. | |
size = 0x200 | |
offset = 0 | |
blocksize = 16 | |
while size > 0: | |
codes = [] | |
linesize = min(blocksize,size) | |
codes.append(linesize) | |
codes.append(offset>>8) | |
codes.append(offset&0xff) | |
codes.append(0) # data code | |
codes.extend([0xff] * linesize) | |
# calculate checksum | |
checksum=(0x100-(sum(codes)&0xff))&0xff | |
codes.append(checksum) | |
print reduce(lambda s,v:s+'{0:02X}'.format(v), codes, ":") | |
offset += linesize | |
size -= linesize |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment