aboutsummaryrefslogtreecommitdiff
path: root/libnxt/make_flash_header.py
diff options
context:
space:
mode:
authordave2006-03-17 03:30:09 +0000
committerdave2006-03-17 03:30:09 +0000
commit68066815511b3b54a539b618d24234b0d743e2fb (patch)
treef9671aeb9064d79f3295c73958407fa2b8d371a7 /libnxt/make_flash_header.py
Update the README file for release 0.2.
Diffstat (limited to 'libnxt/make_flash_header.py')
-rwxr-xr-xlibnxt/make_flash_header.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/libnxt/make_flash_header.py b/libnxt/make_flash_header.py
new file mode 100755
index 0000000..7901891
--- /dev/null
+++ b/libnxt/make_flash_header.py
@@ -0,0 +1,51 @@
+#!/usr/bin/env python
+#
+# Take the flash_routine.bin file, and embed it as an array of bytes
+# in a flash_routine.h, ready for packaging with the C firmware
+# flasher.
+#
+# If a file name is provided on the commandline, load that file as the
+# firmware flashing routine instead.
+#
+
+from sys import argv
+
+if len(argv) == 2:
+ fname = argv[1]
+else:
+ fname = 'flash_write/flash_write.bin'
+
+fwbin = file(fname)
+
+# Build the char representation in memory
+
+def char_by_char(f):
+ while True:
+ d = f.read(1)
+ if d == '':
+ raise StopIteration
+ yield d
+
+data = []
+for c in char_by_char(fwbin):
+ data.append("0x%s" % c.encode('hex'))
+
+for i in range(0, len(data), 12):
+ data[i] = "\n" + data[i]
+
+data_str = ', '.join(data)
+len_data = "0x%X" % len(data)
+
+# Read in the template
+tplfile = file('flash_routine.h.base')
+template = tplfile.read()
+tplfile.close()
+
+# Replace the values in the template
+template = template.replace('___FLASH_BIN___', data_str)
+template = template.replace('___FLASH_LEN___', len_data)
+
+# Output the done header
+out = file('flash_routine.h', 'w')
+out.write(template)
+out.close()