aboutsummaryrefslogtreecommitdiffstats
path: root/firmware/microblaze/bin/bin_to_mif.py
diff options
context:
space:
mode:
authorNick Foster <nick@nerdnetworks.org>2010-07-26 15:33:30 -0700
committerNick Foster <nick@nerdnetworks.org>2010-07-26 15:33:30 -0700
commitf72ad02f5ec370f45995ecd2b3e8b322e9a7e4dc (patch)
tree069b728b6e44a5db8607a8c5815e3a2d50a114ac /firmware/microblaze/bin/bin_to_mif.py
parentf86c25317b457b280c697fc47905c79bdbbc0c93 (diff)
downloaduhd-f72ad02f5ec370f45995ecd2b3e8b322e9a7e4dc.tar.gz
uhd-f72ad02f5ec370f45995ecd2b3e8b322e9a7e4dc.tar.bz2
uhd-f72ad02f5ec370f45995ecd2b3e8b322e9a7e4dc.zip
New branch with firmware dir from USRP2P branch.
Diffstat (limited to 'firmware/microblaze/bin/bin_to_mif.py')
-rwxr-xr-xfirmware/microblaze/bin/bin_to_mif.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/firmware/microblaze/bin/bin_to_mif.py b/firmware/microblaze/bin/bin_to_mif.py
new file mode 100755
index 000000000..cefce4e92
--- /dev/null
+++ b/firmware/microblaze/bin/bin_to_mif.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python
+
+import struct
+import sys
+
+hextab = ('0000', '0001', '0010', '0011',
+ '0100', '0101', '0110', '0111',
+ '1000', '1001', '1010', '1011',
+ '1100', '1101', '1110', '1111')
+
+def w_to_binary_ascii(w):
+ return ''.join([hextab[(w >> 4*i) & 0xf] for i in range(7,-1,-1)])
+
+def bin_to_mif(bin_input_file, mif_output_file):
+ ifile = open(bin_input_file, 'rb')
+ ofile = open(mif_output_file, 'w')
+ idata = ifile.read()
+ fmt = ">%dI" % ((len(idata) / 4),)
+ words = struct.unpack(fmt, idata)
+ for w in words:
+ ofile.write(w_to_binary_ascii(w))
+ ofile.write('\n')
+
+if __name__ == '__main__':
+ if len(sys.argv) != 3:
+ sys.stderr.write("usage: bin_to_mif bin_input_file mif_output_file\n")
+ raise SystemExit, 1
+
+ bin_to_mif(sys.argv[1], sys.argv[2])