summaryrefslogtreecommitdiffstats
path: root/firmware/fx2
diff options
context:
space:
mode:
authorNick Foster <nick@nerdnetworks.org>2010-08-31 16:44:30 -0700
committerNick Foster <nick@nerdnetworks.org>2010-08-31 16:44:30 -0700
commitb96088b692a5c44974919ee36e253b6ea8c51972 (patch)
tree5200ca3a1b589a83aca06e91c559154ddea82249 /firmware/fx2
parentad55e25aeb273fb7278c6d5175cd0df01fc90924 (diff)
downloaduhd-b96088b692a5c44974919ee36e253b6ea8c51972.tar.gz
uhd-b96088b692a5c44974919ee36e253b6ea8c51972.tar.bz2
uhd-b96088b692a5c44974919ee36e253b6ea8c51972.zip
EEPROM burning in UHD. Changed some USB device handle stuff. Added usrp_init_eeprom.cpp. Hacked up the firmware makefile to behave and to generate .bin EEPROM images instead of IHX.
Diffstat (limited to 'firmware/fx2')
-rwxr-xr-xfirmware/fx2/src/common/build_eeprom.py103
-rw-r--r--firmware/fx2/src/usrp1/Makefile.am58
2 files changed, 28 insertions, 133 deletions
diff --git a/firmware/fx2/src/common/build_eeprom.py b/firmware/fx2/src/common/build_eeprom.py
index 023c4b3f5..ae62587db 100755
--- a/firmware/fx2/src/common/build_eeprom.py
+++ b/firmware/fx2/src/common/build_eeprom.py
@@ -29,15 +29,6 @@ from optparse import OptionParser
VID = 0xfffe # Free Software Folks
PID = 0x0002 # Universal Software Radio Peripheral
-
-
-def hex_to_bytes (s):
- if len (s) & 0x1:
- raise ValueError, "Length must be even"
- r = []
- for i in range (0, len(s), 2):
- r.append (int (s[i:i+2], 16))
- return r
def msb (x):
return (x >> 8) & 0xff
@@ -45,56 +36,6 @@ def msb (x):
def lsb (x):
return x & 0xff
-class ihx_rec (object):
- def __init__ (self, addr, type, data):
- self.addr = addr
- self.type = type
- self.data = data
-
-class ihx_file (object):
- def __init__ (self):
- self.pat = re.compile (r':[0-9A-F]{10,}')
- def read (self, file):
- r = []
- for line in file:
- line = line.strip().upper ()
- if not self.pat.match (line):
- raise ValueError, "Invalid hex record format"
- bytes = hex_to_bytes (line[1:])
- sum = reduce (lambda x, y: x + y, bytes, 0) % 256
- if sum != 0:
- raise ValueError, "Bad hex checksum"
- lenx = bytes[0]
- addr = (bytes[1] << 8) + bytes[2]
- type = bytes[3]
- data = bytes[4:-1]
- if lenx != len (data):
- raise ValueError, "Invalid hex record (bad length)"
- if type != 0:
- break;
- r.append (ihx_rec (addr, type, data))
-
- return r
-
-def get_code (filename):
- """Read the intel hex format file FILENAME and return a tuple
- of the code starting address and a list of bytes to load there.
- """
- f = open (filename, 'r')
- ifx = ihx_file ()
- r = ifx.read (f)
- r.sort (lambda a,b: a.addr - b.addr)
- code_start = r[0].addr
- code_end = r[-1].addr + len (r[-1].data)
- code_len = code_end - code_start
- code = [0] * code_len
- for x in r:
- a = x.addr
- l = len (x.data)
- code[a-code_start:a-code_start+l] = x.data
- return (code_start, code)
-
-
def build_eeprom_image (filename, rev):
"""Build a ``C2 Load'' EEPROM image.
@@ -102,9 +43,11 @@ def build_eeprom_image (filename, rev):
the EZ-USB FX2 Technical Reference Manual
"""
# get the code we want to run
- (start_addr, bytes) = get_code (filename)
+ f = open(filename, 'rb')
+ bytes = f.read()
devid = rev
+ start_addr = 0 #prove me wrong
rom_header = [
0xC2, # boot from EEPROM
@@ -135,41 +78,18 @@ def build_eeprom_image (filename, rev):
0x00
]
- image = rom_header + code_header + bytes + trailer
+ image = rom_header + code_header + [ord(c) for c in bytes] + trailer
assert (len (image) <= 256)
- return image
-
-def build_shell_script (out, ihx_filename, rev):
-
- image = build_eeprom_image (ihx_filename, rev)
-
- out.write ('#!/bin/sh\n')
- out.write ('usrper -x load_firmware /usr/local/share/usrp/rev%d/std.ihx\n' % rev)
- out.write ('sleep 1\n')
-
- # print "len(image) =", len(image)
-
- i2c_addr = 0x50
- rom_addr = 0x00
-
- hex_image = map (lambda x : "%02x" % (x,), image)
-
- while (len (hex_image) > 0):
- l = min (len (hex_image), 16)
- out.write ('usrper i2c_write 0x%02x %02x%s\n' %
- (i2c_addr, rom_addr, ''.join (hex_image[0:l])))
- hex_image = hex_image[l:]
- rom_addr = rom_addr + l
- out.write ('sleep 1\n')
+ return image
if __name__ == '__main__':
- usage = "usage: %prog -r REV [options] bootfile.ihx"
+ 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 number REV (2 or 4)")
(options, args) = parser.parse_args ()
- if len (args) != 1:
+ if len (args) != 2:
parser.print_help ()
sys.exit (1)
if options.rev < 0:
@@ -177,6 +97,11 @@ if __name__ == '__main__':
"You must specify the USRP revision number (2 or 4) with -r REV\n")
sys.exit (1)
- ihx_filename = args[0]
+ infile = args[0]
+ outfile = args[1]
+
+ image = "".join(chr(c) for c in build_eeprom_image(infile, options.rev))
- build_shell_script (sys.stdout, ihx_filename, options.rev)
+ f = open(outfile, 'wb')
+ f.write(str(image))
+ f.close()
diff --git a/firmware/fx2/src/usrp1/Makefile.am b/firmware/fx2/src/usrp1/Makefile.am
index 5586e83a3..a964f9198 100644
--- a/firmware/fx2/src/usrp1/Makefile.am
+++ b/firmware/fx2/src/usrp1/Makefile.am
@@ -19,12 +19,12 @@
# Boston, MA 02110-1301, USA.
#
-firmware2dir = $(prefix)/share/usrp/rev2
-firmware2_DATA = std.ihx
+#firmwaredir = $(prefix)/share/uhd/images
+#firmware_DATA = usrp1_fw.ihx
-# we put the same stuff in the rev4 directory
-firmware4dir = $(prefix)/share/usrp/rev4
-firmware4_DATA = std.ihx
+#eepromdir = $(firmwaredir)
+#eepromfile = eeprom_boot.ihx
+#eeprom_DATA = usrp1_eeprom.bin
EXTRA_DIST = \
edit-gpif \
@@ -85,11 +85,6 @@ EXECUTABLES = \
STARTUP = _startup.rel
-noinst_SCRIPTS = \
- burn-usrp2-eeprom \
- burn-usrp4-eeprom
-
-
.c.rel:
$(XCC) $(FW_INCLUDES) $(DEFINES) \
-c -o $@ `test -f '$<' || echo '$(srcdir)/'`$<
@@ -107,34 +102,11 @@ EEPROM_BOOT_OBJS = eeprom_boot.rel eeprom_init.rel $(STARTUP)
eeprom_boot.ihx: $(EEPROM_BOOT_OBJS) $(LIBDEP)
$(XCC) $(LINKOPTS) -o $@ $(EEPROM_BOOT_OBJS)
-burn-usrp2-eeprom: eeprom_boot.ihx
- $(PYTHON) $(srcdir)/../common/build_eeprom.py -r2 eeprom_boot.ihx > $@
- chmod +x $@
-
-burn-usrp4-eeprom: eeprom_boot.ihx
- $(PYTHON) $(srcdir)/../common/build_eeprom.py -r4 eeprom_boot.ihx > $@
- chmod +x $@
-
-
-BLINK_LEDS_OBJS = blink_leds.rel usrp_common.rel board_specific.rel spi.rel $(STARTUP)
-
-blink_leds.ihx: $(BLINK_LEDS_OBJS) $(LIBDEP)
- $(XCC) $(LINKOPTS) -o $@ $(BLINK_LEDS_OBJS)
-
-
-CHECK_MDELAY_OBJS = check_mdelay.rel usrp_common.rel board_specific.rel spi.rel $(STARTUP)
-
-check_mdelay.ihx: $(CHECK_MDELAY_OBJS) $(LIBDEP)
- $(XCC) $(LINKOPTS) -o $@ $(CHECK_MDELAY_OBJS)
-
-
-
-CHECK_UDELAY_OBJS = check_udelay.rel usrp_common.rel board_specific.rel spi.rel $(STARTUP)
-
-check_udelay.ihx: $(CHECK_UDELAY_OBJS) $(LIBDEP)
- $(XCC) $(LINKOPTS) -o $@ $(CHECK_UDELAY_OBJS)
-
+usrp1_eeprom.bin: eeprom_boot.bin
+ $(PYTHON) ../common/build_eeprom.py -r4 $< $@
+eeprom_boot.bin: eeprom_boot.ihx
+ objcopy -I ihex -O binary $< $@
USRP_OBJS = \
vectors.rel \
@@ -146,25 +118,23 @@ std.ihx: $(USRP_OBJS) $(LIBDEP)
$(XCC) $(LINKOPTS) -o $@ $(USRP_OBJS)
CLEANFILES = \
- *.ihx *.lnk *.lst *.map *.mem *.rel *.rst *.sym *.asm *.lib \
- usrp_gpif.c usrp_gpif_inline.h \
- burn-usrp2-eeprom \
- burn-usrp4-eeprom
+ *.ihx *.lnk *.lst *.map *.mem *.rel *.rst *.sym *.asm *.lib *.bin \
+ usrp_gpif.c usrp_gpif_inline.h
DISTCLEANFILES = \
- *.ihx *.lnk *.lst *.map *.mem *.rel *.rst *.sym *.asm *.lib
+ *.ihx *.lnk *.lst *.map *.mem *.rel *.rst *.sym *.asm *.lib *.bin
# build gpif stuff
-all: usrp_gpif.c
+all: usrp_gpif.c std.ihx usrp1_eeprom.bin
usrp_gpif.c usrp_gpif_inline.h : gpif.c
srcdir=$(srcdir) $(PYTHON) $(srcdir)/edit-gpif $(srcdir)/gpif.c usrp_gpif.c usrp_gpif_inline.h
-
# dependencies
usrp_main.rel: usrp_gpif_inline.h
+
#usrp_main.rel: fpga.h usrp_common.h ../../include/usrp_commands.h usrp_gpif_inline.h ../../include/usrp_config.h usrp_rev2_regs.h ../../include/fx2regs.h
#usrp_common.rel: usrp_common.h ../../include/usrp_commands.h ../../include/usrp_config.h usrp_rev2_regs.h ../../include/fx2regs.h
#fpga.rel: usrp_common.h ../../include/usrp_commands.h fpga.h ../../include/usrp_config.h usrp_rev2_regs.h ../../include/fx2regs.h