aboutsummaryrefslogtreecommitdiffstats
path: root/firmware/fx2/src/common
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/src/common
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/src/common')
-rwxr-xr-xfirmware/fx2/src/common/build_eeprom.py103
1 files changed, 14 insertions, 89 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()