diff options
author | Nick Foster <nick@nerdnetworks.org> | 2010-11-10 12:15:35 -0800 |
---|---|---|
committer | Nick Foster <nick@nerdnetworks.org> | 2010-11-10 12:15:35 -0800 |
commit | fb0cdbc553d288402ee7939dc72f4368eb9e8e1b (patch) | |
tree | e20003155af08428448a7834a82d259f3b68717d /firmware/fx2/utils/build_eeprom.py | |
parent | 8fe1e7b29aacce7f75ae36e81706bbde02749b97 (diff) | |
parent | 8c434f7d63aca25b55d6d13dffcc1d7037261d4f (diff) | |
download | uhd-fb0cdbc553d288402ee7939dc72f4368eb9e8e1b.tar.gz uhd-fb0cdbc553d288402ee7939dc72f4368eb9e8e1b.tar.bz2 uhd-fb0cdbc553d288402ee7939dc72f4368eb9e8e1b.zip |
Merge branch 'master' of ettus.sourcerepo.com:ettus/uhdpriv into usrp2p-next
Conflicts:
firmware/microblaze/lib/u2_init.c
host/lib/usrp/usrp2/clock_ctrl.cpp
host/lib/usrp/usrp2/fw_common.h
host/lib/usrp/usrp2/mboard_impl.cpp
host/lib/usrp/usrp2/usrp2_iface.cpp
host/lib/usrp/usrp2/usrp2_iface.hpp
Diffstat (limited to 'firmware/fx2/utils/build_eeprom.py')
-rwxr-xr-x | firmware/fx2/utils/build_eeprom.py | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/firmware/fx2/utils/build_eeprom.py b/firmware/fx2/utils/build_eeprom.py new file mode 100755 index 000000000..298ccc00c --- /dev/null +++ b/firmware/fx2/utils/build_eeprom.py @@ -0,0 +1,112 @@ +#!/usr/bin/env python +# +# Copyright 2004,2006 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +import re +import sys +import os, os.path +from optparse import OptionParser + +# USB Vendor and Product ID's + +VID = 0xfffe # Free Software Folks + + +def msb (x): + return (x >> 8) & 0xff + +def lsb (x): + return x & 0xff + +def build_eeprom_image (filename, rev): + """Build a ``C2 Load'' EEPROM image. + + For details on this format, see section 3.4.3 of + the EZ-USB FX2 Technical Reference Manual + """ + # get the code we want to run + f = open(filename, 'rb') + bytes = f.read() + + devid = 4 #for compatibility + start_addr = 0 #prove me wrong + + if(rev == 1): + PID = 0x0002 #USRP1 + else: + PID = 0x0003 #USRP1P + + rom_header = [ + 0xC2, # boot from EEPROM + lsb (VID), + msb (VID), + lsb (PID), + msb (PID), + lsb (devid), + msb (devid), + 0 # configuration byte + ] + + # 4 byte header that indicates where to load + # the immediately follow code bytes. + code_header = [ + msb (len (bytes)), + lsb (len (bytes)), + msb (start_addr), + lsb (start_addr) + ] + + # writes 0 to CPUCS reg (brings FX2 out of reset) + trailer = [ + 0x80, + 0x01, + 0xe6, + 0x00, + 0x00 + ] + + image = rom_header + code_header + [ord(c) for c in bytes] + trailer + + assert (len (image) <= 256) + return image + +if __name__ == '__main__': + usage = "usage: %prog -r REV [options] bootfile.bin outfile.bin" + parser = OptionParser (usage=usage) + parser.add_option ("-r", "--rev", type="int", default=-1, + help="Specify USRP revision, 1 for USRP1, 2 for USRP1P") + (options, args) = parser.parse_args () + if len (args) != 2: + parser.print_help () + sys.exit (1) + if options.rev < 0: + sys.stderr.write ( + "You must specify the USRP revision number (2 or 4) with -r REV\n") + sys.exit (1) + + infile = args[0] + outfile = args[1] + + image = "".join(chr(c) for c in build_eeprom_image(infile, options.rev)) + + f = open(outfile, 'wb') + f.write(str(image)) + f.close() |