[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r6753 - gnuradio/branches/developers/matt/u2f/firmware
From: |
eb |
Subject: |
[Commit-gnuradio] r6753 - gnuradio/branches/developers/matt/u2f/firmware |
Date: |
Tue, 30 Oct 2007 22:50:54 -0600 (MDT) |
Author: eb
Date: 2007-10-30 22:50:54 -0600 (Tue, 30 Oct 2007)
New Revision: 6753
Added:
gnuradio/branches/developers/matt/u2f/firmware/u2_flash_tool
Log:
new tool
Added: gnuradio/branches/developers/matt/u2f/firmware/u2_flash_tool
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/u2_flash_tool
(rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/u2_flash_tool
2007-10-31 04:50:54 UTC (rev 6753)
@@ -0,0 +1,101 @@
+#!/usr/bin/env python
+
+import sys
+from optparse import OptionParser
+
+SECTOR_SIZE = 512 # bytes
+MAX_FILE_SIZE = 1 * (2**20) # maximum number of bytes we'll burn to a
slot
+
+FPGA_OFFSET = 0 # offset in flash to fpga image
+FIRMWARE_OFFSET = 1 * (2**20) # offset in flash to firmware image
+
+def read_file_data(filename):
+ f = open(filename, "rb")
+ file_data = f.read(MAX_FILE_SIZE)
+ t = len(file_data) % SECTOR_SIZE
+ if t != 0:
+ file_data += (SECTOR_SIZE - t)*chr(0) # pad to an even sector size w/
zeros
+ return file_data
+
+
+def write_flash(offset, filename, devname):
+ file_data = read_file_data(filename)
+ dev = open(devname, "wb")
+ dev.seek(offset, 0) # seek to absolute byte offset
+ dev.write(file_data)
+ dev.flush()
+ dev.close()
+
+
+def verify_flash(offset, filename, devname):
+ file_data = read_file_data(filename)
+ dev = open(devname, "rb")
+ dev.seek(offset, 0) # seek to absolute byte offset
+ dev_data = dev.read(len(file_data))
+ if len(dev_data) != len(file_data):
+ sys.stderr.write("short read on device %s\n" % (devname,))
+ return False
+
+ if file_data == dev_data:
+ return True
+
+ # doesn't match
+ nwrong = 0
+ for i in range(len(file_data)):
+ if dev_data[i] != file_data[i]:
+ sys.stderr.write("mismatch at offset %7d. Expected 0x%02x, got
0x%02x\n" % (
+ i, ord(file_data[i]), ord(dev_data[i])))
+ nwrong += 1
+ if nwrong > 16:
+ sys.stderr.write("> 16 errors, stopping comparison\n")
+ break
+ return False
+
+
+def main():
+ parser = OptionParser(usage="%prog: [options] filename")
+ parser.add_option("-w", "--write", action="store_const", const="write",
dest="mode",
+ help="write FILE to TARGET slot")
+ parser.add_option("-v", "--verify", action="store_const", const="verify",
dest="mode",
+ help="verify FILE against TARGET slot")
+ parser.add_option("-t", "--target", type="choice", choices=("fpga",
"s/w"), default="s/w",
+ help="select TARGET slot from: fpga, s/w
[default=%default]")
+ parser.add_option("", "--dev", default=None,
+ help="specify flash device file, e.g., /dev/sdb. Be
careful!")
+ parser.set_defaults(target="s/w", mode=None)
+
+ (options, args) = parser.parse_args()
+ if len(args) != 1:
+ parser.print_help()
+ raise SystemExit
+
+ filename = args[0]
+
+ if options.mode is None:
+ sys.stderr.write("specify mode with -w or -v\n")
+ parser.print_help()
+ raise SystemExit
+
+ if options.dev is None:
+ sys.stderr.write("specify the device file with --dev\n")
+ parser.print_help()
+ raise SystemExit
+
+ offset = { "fpga" : FPGA_OFFSET, "s/w" : FIRMWARE_OFFSET }[options.target]
+
+ if options.mode == "write":
+ r = write_flash(offset, filename, options.dev)
+ else:
+ r = verify_flash(offset, filename, options.dev)
+
+ if not r:
+ raise SystemExit, 1
+
+
+if __name__ == "__main__":
+ main()
+
+
+
+
+
Property changes on:
gnuradio/branches/developers/matt/u2f/firmware/u2_flash_tool
___________________________________________________________________
Name: svn:executable
+ *
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r6753 - gnuradio/branches/developers/matt/u2f/firmware,
eb <=