summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2011-06-17 11:04:11 -0700
committerJosh Blum <josh@joshknows.com>2011-06-17 11:04:11 -0700
commita852b6011c11e32e000ccd18c2009edfe81500ee (patch)
tree17f7647a5ed5cb4dc610b50116bd920c3958356d
parenta984d9059a9cd405b18815f5e7669fbd0b0fa555 (diff)
parentbc87971891df7f47c8240a24d2a602c6ae63bbc2 (diff)
downloaduhd-a852b6011c11e32e000ccd18c2009edfe81500ee.tar.gz
uhd-a852b6011c11e32e000ccd18c2009edfe81500ee.tar.bz2
uhd-a852b6011c11e32e000ccd18c2009edfe81500ee.zip
Merge branch 'master' into frontend_work
Conflicts: host/lib/usrp/usrp_e100/io_impl.cpp
-rw-r--r--firmware/zpu/lib/udp_fw_update.h6
-rw-r--r--firmware/zpu/usrp2p/udp_fw_update.c19
-rw-r--r--host/docs/general.rst8
-rw-r--r--host/lib/transport/libusb1_zero_copy.cpp5
-rw-r--r--host/lib/usrp/b100/b100_ctrl.cpp5
-rw-r--r--host/lib/usrp/usrp2/codec_ctrl.cpp2
-rw-r--r--host/lib/usrp/usrp2/io_impl.cpp5
-rw-r--r--host/tests/sph_recv_test.cpp18
-rwxr-xr-xhost/utils/usrp2_card_burner.py28
-rwxr-xr-xhost/utils/usrp_n2xx_net_burner.py143
-rwxr-xr-xhost/utils/usrp_n2xx_net_burner_gui.py51
11 files changed, 242 insertions, 48 deletions
diff --git a/firmware/zpu/lib/udp_fw_update.h b/firmware/zpu/lib/udp_fw_update.h
index d25525bd2..d98447aef 100644
--- a/firmware/zpu/lib/udp_fw_update.h
+++ b/firmware/zpu/lib/udp_fw_update.h
@@ -45,6 +45,9 @@ typedef enum {
USRP2_FW_UPDATE_ID_RESET_MAH_COMPUTORZ_LOL = 's',
USRP2_FW_UPDATE_ID_RESETTIN_TEH_COMPUTORZ_OMG = 'S',
+ USRP2_FW_UPDATE_ID_I_CAN_HAS_HW_REV_LOL = 'v',
+ USRP2_FW_UPDATE_ID_HERES_TEH_HW_REV_OMG = 'V',
+
USRP2_FW_UPDATE_ID_KTHXBAI = '~'
} usrp2_fw_update_id_t;
@@ -54,7 +57,8 @@ typedef struct {
uint32_t id;
uint32_t seq;
union {
- uint32_t ip_addr;
+ uint32_t ip_addr;
+ uint32_t hw_rev;
struct {
uint32_t flash_addr;
uint32_t length;
diff --git a/firmware/zpu/usrp2p/udp_fw_update.c b/firmware/zpu/usrp2p/udp_fw_update.c
index ead08ad2c..f64e7653c 100644
--- a/firmware/zpu/usrp2p/udp_fw_update.c
+++ b/firmware/zpu/usrp2p/udp_fw_update.c
@@ -27,6 +27,13 @@
#include "ethernet.h"
#include "udp_fw_update.h"
#include "xilinx_s3_icap.h"
+#include "i2c.h"
+
+uint16_t get_hw_rev(void) {
+ uint16_t tmp;
+ eeprom_read(USRP2_I2C_ADDR_MBOARD, USRP2_EE_MBOARD_REV, &tmp, sizeof(tmp));
+ return tmp;
+}
//Firmware update packet handler
void handle_udp_fw_update_packet(struct socket_address src, struct socket_address dst,
@@ -59,6 +66,13 @@ void handle_udp_fw_update_packet(struct socket_address src, struct socket_addres
case USRP2_FW_UPDATE_ID_OHAI_LOL: //why hello there you handsome devil
update_data_out.id = USRP2_FW_UPDATE_ID_OHAI_OMG;
memcpy(&update_data_out.data.ip_addr, (void *)get_ip_addr(), sizeof(struct ip_addr));
+ //this is to stop streaming for the folks who think updating while streaming is a good idea
+ sr_rx_ctrl0->cmd = 1 << 31; //no samples now
+ sr_rx_ctrl0->time_secs = 0;
+ sr_rx_ctrl0->time_ticks = 0; //latch the command
+ sr_rx_ctrl1->cmd = 1 << 31; //no samples now
+ sr_rx_ctrl1->time_secs = 0;
+ sr_rx_ctrl1->time_ticks = 0; //latch the command
break;
case USRP2_FW_UPDATE_ID_WATS_TEH_FLASH_INFO_LOL: //query sector size, memory size so the host can mind the boundaries
@@ -67,6 +81,11 @@ void handle_udp_fw_update_packet(struct socket_address src, struct socket_addres
update_data_out.id = USRP2_FW_UPDATE_ID_HERES_TEH_FLASH_INFO_OMG;
break;
+ case USRP2_FW_UPDATE_ID_I_CAN_HAS_HW_REV_LOL: //get the hardware revision of the platform for validation checking
+ update_data_out.data.hw_rev = (uint32_t) get_hw_rev();
+ update_data_out.id = USRP2_FW_UPDATE_ID_HERES_TEH_HW_REV_OMG;
+ break;
+
case USRP2_FW_UPDATE_ID_ERASE_TEH_FLASHES_LOL: //out with the old
spi_flash_async_erase_start(&spi_flash_async_state, update_data_in->data.flash_args.flash_addr, update_data_in->data.flash_args.length);
update_data_out.id = USRP2_FW_UPDATE_ID_ERASING_TEH_FLASHES_OMG;
diff --git a/host/docs/general.rst b/host/docs/general.rst
index cc00fc0f9..7952abb8b 100644
--- a/host/docs/general.rst
+++ b/host/docs/general.rst
@@ -107,10 +107,10 @@ For the most part, UHD is thread-safe.
Please observe the following limitations:
**Fast-path thread requirements:**
-It is safe to call send() and recv() simultaneously. However,
-it is not safe to call recv() simultaneously from different thread contexts.
-The same rule applies for recv(), send(), and recv_async_msg().
-One thread context per fast-path device method at a time.
+There are three fast-path methods for a device: send(), recv(), and recv_async_msg().
+All three methods are thread-safe and can be called from different thread contexts.
+For performance, the user should call each method from a separate thread context.
+These methods can also be used in a non-blocking fashion by using a timeout of zero.
**Slow-path thread requirements:**
It is safe to change multiple settings simultaneously. However,
diff --git a/host/lib/transport/libusb1_zero_copy.cpp b/host/lib/transport/libusb1_zero_copy.cpp
index 19a7a3742..f781f890d 100644
--- a/host/lib/transport/libusb1_zero_copy.cpp
+++ b/host/lib/transport/libusb1_zero_copy.cpp
@@ -222,7 +222,6 @@ public:
}
}
//shutdown the threads
- _threads_running = false;
_thread_group.interrupt_all();
_thread_group.join_all();
}
@@ -277,15 +276,13 @@ private:
//! event handler threads
boost::thread_group _thread_group;
- bool _threads_running;
void run_event_loop(boost::barrier &spawn_barrier){
- _threads_running = true;
spawn_barrier.wait();
set_thread_priority_safe();
libusb_context *context = libusb::session::get_global_session()->get_context();
try{
- while(_threads_running){
+ while (not boost::this_thread::interruption_requested()){
timeval tv;
tv.tv_sec = 0;
tv.tv_usec = 100000; //100ms
diff --git a/host/lib/usrp/b100/b100_ctrl.cpp b/host/lib/usrp/b100/b100_ctrl.cpp
index 70decd4c1..2a87703f7 100644
--- a/host/lib/usrp/b100/b100_ctrl.cpp
+++ b/host/lib/usrp/b100/b100_ctrl.cpp
@@ -51,7 +51,6 @@ public:
ctrl_data_t read(boost::uint32_t addr, size_t len);
~b100_ctrl_impl(void) {
- bbl_out_marauding = false;
viking_marauders.interrupt_all();
viking_marauders.join_all();
}
@@ -67,7 +66,6 @@ private:
bounded_buffer<ctrl_data_t> sync_ctrl_fifo;
bounded_buffer<async_metadata_t> async_msg_fifo;
boost::thread_group viking_marauders;
- bool bbl_out_marauding;
uhd::transport::usb_zero_copy::sptr _ctrl_transport;
boost::uint8_t _seq;
@@ -168,11 +166,10 @@ ctrl_data_t b100_ctrl_impl::read(boost::uint32_t addr, size_t len) {
* wait for a control operation to finish before starting another one.
**********************************************************************/
void b100_ctrl_impl::viking_marauder_loop(boost::barrier &spawn_barrier) {
- bbl_out_marauding = true;
spawn_barrier.wait();
set_thread_priority_safe();
- while(bbl_out_marauding){
+ while (not boost::this_thread::interruption_requested()){
managed_recv_buffer::sptr rbuf = _ctrl_transport->get_recv_buff();
if(!rbuf.get()) continue; //that's ok, there are plenty of villages to pillage!
const boost::uint16_t *pkt_buf = rbuf->cast<const boost::uint16_t *>();
diff --git a/host/lib/usrp/usrp2/codec_ctrl.cpp b/host/lib/usrp/usrp2/codec_ctrl.cpp
index ee0ef9ceb..06bf83b15 100644
--- a/host/lib/usrp/usrp2/codec_ctrl.cpp
+++ b/host/lib/usrp/usrp2/codec_ctrl.cpp
@@ -87,7 +87,9 @@ public:
_ads62p44_regs.power_down = ads62p44_regs_t::POWER_DOWN_NORMAL;
_ads62p44_regs.output_interface = ads62p44_regs_t::OUTPUT_INTERFACE_LVDS;
_ads62p44_regs.lvds_current = ads62p44_regs_t::LVDS_CURRENT_2_5MA;
+ _ads62p44_regs.lvds_data_term = ads62p44_regs_t::LVDS_DATA_TERM_100;
this->send_ads62p44_reg(0x11);
+ this->send_ads62p44_reg(0x12);
this->send_ads62p44_reg(0x14);
this->set_rx_analog_gain(1);
break;
diff --git a/host/lib/usrp/usrp2/io_impl.cpp b/host/lib/usrp/usrp2/io_impl.cpp
index ffe9a88e7..df452942c 100644
--- a/host/lib/usrp/usrp2/io_impl.cpp
+++ b/host/lib/usrp/usrp2/io_impl.cpp
@@ -146,7 +146,6 @@ struct usrp2_impl::io_impl{
}
~io_impl(void){
- recv_pirate_crew_raiding = false;
recv_pirate_crew.interrupt_all();
recv_pirate_crew.join_all();
}
@@ -185,7 +184,6 @@ struct usrp2_impl::io_impl{
//methods and variables for the pirate crew
void recv_pirate_loop(boost::barrier &, usrp2_mboard_impl::sptr, zero_copy_if::sptr, size_t);
boost::thread_group recv_pirate_crew;
- bool recv_pirate_crew_raiding;
bounded_buffer<async_metadata_t> async_msg_fifo;
};
@@ -201,14 +199,13 @@ void usrp2_impl::io_impl::recv_pirate_loop(
zero_copy_if::sptr err_xport,
size_t index
){
- recv_pirate_crew_raiding = true;
spawn_barrier.wait();
set_thread_priority_safe();
//store a reference to the flow control monitor (offset by max dsps)
flow_control_monitor &fc_mon = *(this->fc_mons[index*usrp2_mboard_impl::MAX_NUM_DSPS]);
- while(recv_pirate_crew_raiding){
+ while (not boost::this_thread::interruption_requested()){
managed_recv_buffer::sptr buff = err_xport->get_recv_buff();
if (not buff.get()) continue; //ignore timeout/error buffers
diff --git a/host/tests/sph_recv_test.cpp b/host/tests/sph_recv_test.cpp
index 6bb5d1175..cd33452c6 100644
--- a/host/tests/sph_recv_test.cpp
+++ b/host/tests/sph_recv_test.cpp
@@ -27,6 +27,19 @@
BOOST_CHECK_CLOSE((a).get_real_secs(), (b).get_real_secs(), 0.001)
/***********************************************************************
+ * A dummy overflow handler for testing
+ **********************************************************************/
+struct overflow_handler_type{
+ overflow_handler_type(void){
+ num_overflow = 0;
+ }
+ void handle(void){
+ num_overflow++;
+ }
+ size_t num_overflow;
+};
+
+/***********************************************************************
* A dummy managed receive buffer for testing
**********************************************************************/
class dummy_mrb : public uhd::transport::managed_recv_buffer{
@@ -300,6 +313,10 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_one_channel_inline_message){
handler.set_xport_chan_get_buff(0, boost::bind(&dummy_recv_xport_class::get_recv_buff, &dummy_recv_xport, _1));
handler.set_converter(otw_type);
+ //create an overflow handler
+ overflow_handler_type overflow_handler;
+ handler.set_overflow_handler(0, boost::bind(&overflow_handler_type::handle, &overflow_handler));
+
//check the received packets
size_t num_accum_samps = 0;
std::vector<std::complex<float> > buff(20);
@@ -326,6 +343,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_one_channel_inline_message){
std::cout << "metadata.error_code " << metadata.error_code << std::endl;
BOOST_REQUIRE(metadata.error_code == uhd::rx_metadata_t::ERROR_CODE_OVERFLOW);
BOOST_CHECK_TS_CLOSE(metadata.time_spec, uhd::time_spec_t(0, num_accum_samps, SAMP_RATE));
+ BOOST_CHECK_EQUAL(overflow_handler.num_overflow, size_t(1));
}
}
diff --git a/host/utils/usrp2_card_burner.py b/host/utils/usrp2_card_burner.py
index 26adb91c7..43689dd20 100755
--- a/host/utils/usrp2_card_burner.py
+++ b/host/utils/usrp2_card_burner.py
@@ -50,7 +50,7 @@ def command(*args):
stderr=subprocess.STDOUT,
)
ret = p.wait()
- verbose = p.stdout.read().decode('ascii')
+ verbose = p.stdout.read().decode()
if ret != 0: raise Exception(verbose)
return verbose
@@ -92,12 +92,12 @@ def get_raw_device_hints():
if in_info: info += '\n'+line.strip()
def is_info_valid(info):
try:
- assert 'link to' in info
+ if 'link to' not in info: return False
#handles two spellings of remov(e)able:
- assert 'remov' in info.lower()
- if 'size is' in info: assert int(extract_info_value(info, 'size is')) <= MAX_SD_CARD_SIZE
- return True
+ if 'remov' not in info.lower(): return False
+ if 'size is' in info and int(extract_info_value(info, 'size is')) > MAX_SD_CARD_SIZE: return False
except: return False
+ return True
def extract_info_name(info):
for key in ('Mounted on', 'link to'):
if key in info: return extract_info_value(info, key)
@@ -110,13 +110,11 @@ def get_raw_device_hints():
####################################################################
if platform.system() == 'Linux':
devs = list()
- try: output = open('/proc/partitions', 'r').read().decode('ascii')
- except: return devs
- for line in output.splitlines():
+ for line in command('cat', '/proc/partitions').splitlines():
try:
major, minor, blocks, name = line.split()
- assert not name[-1].isdigit() or int(minor) == 0
- assert int(blocks)*1024 <= MAX_SD_CARD_SIZE
+ if not name[-1].isdigit() and int(minor) == 0: continue
+ if int(blocks)*1024 > MAX_SD_CARD_SIZE: continue
except: continue
devs.append(os.path.join('/dev', name))
@@ -128,17 +126,17 @@ def get_raw_device_hints():
if platform.system() == 'Darwin':
devs = [d.split()[0] for d in [l for l in command('diskutil', 'list').splitlines() if l.startswith('/dev')]]
def output_to_info(output):
- return dict([list(map(str.strip, pair.lower().split(':'))) for pair in [l for l in output.splitlines() if ':' in l]])
+ return dict([list(map(lambda x: x.strip(), pair.lower().split(':'))) for pair in [l for l in output.splitlines() if ':' in l]])
def is_dev_valid(dev):
info = output_to_info(command('diskutil', 'info', dev))
try:
- if 'internal' in info: assert info['internal'] == 'no'
- if 'ejectable' in info: assert info['ejectable'] == 'yes'
+ if 'internal' in info and info['internal'] == 'yes': return False
+ if 'ejectable' in info and info['ejectable'] == 'no': return False
if 'total size' in info:
size_match = re.match('^.*\((\d+)\s*bytes\).*$', info['total size'])
- if size_match: assert int(size_match.groups()[0]) <= MAX_SD_CARD_SIZE
- return True
+ if size_match and int(size_match.groups()[0]) > MAX_SD_CARD_SIZE: return False
except: return False
+ return True
return sorted(set(filter(is_dev_valid, devs)))
diff --git a/host/utils/usrp_n2xx_net_burner.py b/host/utils/usrp_n2xx_net_burner.py
index 06af8c860..1df300c76 100755
--- a/host/utils/usrp_n2xx_net_burner.py
+++ b/host/utils/usrp_n2xx_net_burner.py
@@ -17,8 +17,6 @@
#
# TODO: make it autodetect UHD devices
-# TODO: you should probably watch sequence numbers
-# TODO: validate images in 1) size and 2) header content so you can't write a Justin Bieber MP3 to Flash
import optparse
import math
@@ -28,6 +26,8 @@ import struct
import socket
import sys
import time
+import platform
+import subprocess
########################################################################
# constants
@@ -54,6 +54,14 @@ FLASH_DATA_PACKET_SIZE = 256
FLASH_ARGS_FMT = '!LLLLL256s'
FLASH_INFO_FMT = '!LLLLL256x'
FLASH_IP_FMT = '!LLLL260x'
+FLASH_HW_REV_FMT = '!LLLL260x'
+
+n2xx_revs = {
+ 0x0a00: ["n200_r3", "n200_r2"],
+ 0x0a10: ["n200_r4"],
+ 0x0a01: ["n210_r3", "n210_r2"],
+ 0x0a11: ["n210_r4"]
+ }
class update_id_t:
USRP2_FW_UPDATE_ID_WAT = ord(' ')
@@ -72,6 +80,8 @@ class update_id_t:
USRP2_FW_UPDATE_ID_KK_READ_TEH_FLASHES_OMG = ord('R')
USRP2_FW_UPDATE_ID_RESET_MAH_COMPUTORZ_LOL = ord('s')
USRP2_FW_UPDATE_ID_RESETTIN_TEH_COMPUTORZ_OMG = ord('S')
+ USRP2_FW_UPDATE_ID_I_CAN_HAS_HW_REV_LOL = ord('v')
+ USRP2_FW_UPDATE_ID_HERES_TEH_HW_REV_OMG = ord('V')
USRP2_FW_UPDATE_ID_KTHXBAI = ord('~')
_seq = -1
@@ -92,12 +102,18 @@ def unpack_flash_info_fmt(s):
def unpack_flash_ip_fmt(s):
return struct.unpack(FLASH_IP_FMT, s) #(proto_ver, pktid, seq, ip_addr)
+def unpack_flash_hw_rev_fmt(s):
+ return struct.unpack(FLASH_HW_REV_FMT, s) #proto_ver, pktid, seq, hw_rev
+
def pack_flash_args_fmt(proto_ver, pktid, seq, flash_addr, length, data=bytes()):
return struct.pack(FLASH_ARGS_FMT, proto_ver, pktid, seq, flash_addr, length, data)
def pack_flash_info_fmt(proto_ver, pktid, seq, sector_size_bytes, memory_size_bytes):
return struct.pack(FLASH_INFO_FMT, proto_ver, pktid, seq, sector_size_bytes, memory_size_bytes)
+def pack_flash_hw_rev_fmt(proto_ver, pktid, seq, hw_rev):
+ return struct.pack(FLASH_HW_REV_FMT, proto_ver, pktid, seq, hw_rev)
+
def is_valid_fpga_image(fpga_image):
for i in range(0,63):
if fpga_image[i:i+1] == bytes(b'\xFF'): continue
@@ -107,6 +123,96 @@ def is_valid_fpga_image(fpga_image):
def is_valid_fw_image(fw_image):
return fw_image[:4] == bytes(b'\x0B\x0B\x0B\x0B')
+
+########################################################################
+# interface discovery and device enumeration
+########################################################################
+def get_interfaces():
+ if(platform.system() is "Windows"): return win_get_interfaces()
+ else: return unix_get_interfaces()
+
+def unix_get_interfaces():
+ ifconfig = subprocess.check_output("/sbin/ifconfig")
+ ip_addr_re = "cast\D*(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})"
+ bcasts = re.findall(ip_addr_re, ifconfig)
+ return bcasts
+
+def win_get_interfaces():
+ from ctypes import Structure, windll, sizeof
+ from ctypes import POINTER, byref
+ from ctypes import c_ulong, c_uint, c_ubyte, c_char
+ MAX_ADAPTER_DESCRIPTION_LENGTH = 128
+ MAX_ADAPTER_NAME_LENGTH = 256
+ MAX_ADAPTER_ADDRESS_LENGTH = 8
+ class IP_ADDR_STRING(Structure):
+ pass
+ LP_IP_ADDR_STRING = POINTER(IP_ADDR_STRING)
+ IP_ADDR_STRING._fields_ = [
+ ("next", LP_IP_ADDR_STRING),
+ ("ipAddress", c_char * 16),
+ ("ipMask", c_char * 16),
+ ("context", c_ulong)]
+ class IP_ADAPTER_INFO (Structure):
+ pass
+ LP_IP_ADAPTER_INFO = POINTER(IP_ADAPTER_INFO)
+ IP_ADAPTER_INFO._fields_ = [
+ ("next", LP_IP_ADAPTER_INFO),
+ ("comboIndex", c_ulong),
+ ("adapterName", c_char * (MAX_ADAPTER_NAME_LENGTH + 4)),
+ ("description", c_char * (MAX_ADAPTER_DESCRIPTION_LENGTH + 4)),
+ ("addressLength", c_uint),
+ ("address", c_ubyte * MAX_ADAPTER_ADDRESS_LENGTH),
+ ("index", c_ulong),
+ ("type", c_uint),
+ ("dhcpEnabled", c_uint),
+ ("currentIpAddress", LP_IP_ADDR_STRING),
+ ("ipAddressList", IP_ADDR_STRING),
+ ("gatewayList", IP_ADDR_STRING),
+ ("dhcpServer", IP_ADDR_STRING),
+ ("haveWins", c_uint),
+ ("primaryWinsServer", IP_ADDR_STRING),
+ ("secondaryWinsServer", IP_ADDR_STRING),
+ ("leaseObtained", c_ulong),
+ ("leaseExpires", c_ulong)]
+ GetAdaptersInfo = windll.iphlpapi.GetAdaptersInfo
+ GetAdaptersInfo.restype = c_ulong
+ GetAdaptersInfo.argtypes = [LP_IP_ADAPTER_INFO, POINTER(c_ulong)]
+ adapterList = (IP_ADAPTER_INFO * 10)()
+ buflen = c_ulong(sizeof(adapterList))
+ rc = GetAdaptersInfo(byref(adapterList[0]), byref(buflen))
+ if rc == 0:
+ for a in adapterList:
+ adNode = a.ipAddressList
+ while True:
+ #convert ipAddr and ipMask into hex addrs that can be turned into a bcast addr
+ ipAddr = adNode.ipAddress.decode()
+ ipMask = adNode.ipMask.decode()
+ if ipAddr and ipMask:
+ hexAddr = struct.unpack("<L", socket.inet_aton(ipAddr))[0]
+ hexMask = struct.unpack("<L", socket.inet_aton(ipMask))[0]
+ if(hexAddr and hexMask): #don't broadcast on 255.255.255.255, that's just lame
+ yield socket.inet_ntoa(struct.pack("<L", (hexAddr & hexMask) | (~hexMask) & 0xFFFFFFFF))
+ adNode = adNode.next
+ if not adNode:
+ break
+
+def enumerate_devices():
+ for bcast_addr in get_interfaces():
+ sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+ sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
+ sock.settimeout(0.1)
+ out_pkt = pack_flash_args_fmt(USRP2_FW_PROTO_VERSION, update_id_t.USRP2_FW_UPDATE_ID_OHAI_LOL, 0, 0, 0)
+ sock.sendto(out_pkt, (bcast_addr, UDP_FW_UPDATE_PORT))
+ still_goin = True
+ while(still_goin):
+ try:
+ pkt = sock.recv(UDP_MAX_XFER_BYTES)
+ (proto_ver, pktid, rxseq, ip_addr) = unpack_flash_ip_fmt(pkt)
+ if(pktid == update_id_t.USRP2_FW_UPDATE_ID_OHAI_OMG):
+ yield socket.inet_ntoa(struct.pack("<L", socket.ntohl(ip_addr)))
+ except socket.timeout:
+ still_goin = False
+
########################################################################
# Burner class, holds a socket and send/recv routines
########################################################################
@@ -117,6 +223,7 @@ class burner_socket(object):
self._sock.connect((addr, UDP_FW_UPDATE_PORT))
self.set_callbacks(lambda *a: None, lambda *a: None)
self.init_update() #check that the device is there
+ self.get_hw_rev()
def set_callbacks(self, progress_cb, status_cb):
self._progress_cb = progress_cb
@@ -137,14 +244,19 @@ class burner_socket(object):
else:
raise Exception("Invalid reply received from device.")
- # print "Incoming:\n\tVer: %i\n\tID: %c\n\tSeq: %i\n\tIP: %i\n" % (proto_ver, chr(pktid), rxseq, ip_addr)
+ def get_hw_rev(self):
+ out_pkt = pack_flash_hw_rev_fmt(USRP2_FW_PROTO_VERSION, update_id_t.USRP2_FW_UPDATE_ID_I_CAN_HAS_HW_REV_LOL, seq(), 0)
+ in_pkt = self.send_and_recv(out_pkt)
+ (proto_ver, pktid, rxseq, hw_rev) = unpack_flash_hw_rev_fmt(in_pkt)
+ if(pktid != update_id_t.USRP2_FW_UPDATE_ID_HERES_TEH_HW_REV_OMG): hw_rev = 0
+ return socket.ntohs(hw_rev)
memory_size_bytes = 0
sector_size_bytes = 0
def get_flash_info(self):
if (self.memory_size_bytes != 0) and (self.sector_size_bytes != 0):
return (self.memory_size_bytes, self.sector_size_bytes)
-
+
out_pkt = pack_flash_args_fmt(USRP2_FW_PROTO_VERSION, update_id_t.USRP2_FW_UPDATE_ID_WATS_TEH_FLASH_INFO_LOL, seq(), 0, 0)
in_pkt = self.send_and_recv(out_pkt)
@@ -157,10 +269,16 @@ class burner_socket(object):
def burn_fw(self, fw, fpga, reset, safe):
(flash_size, sector_size) = self.get_flash_info()
+ hw_rev = self.get_hw_rev()
- print("Flash size: %i\nSector size: %i\n\n" % (flash_size, sector_size))
+ if(hw_rev != 0): print("Hardware type: %s" % n2xx_revs[hw_rev][0])
+ print("Flash size: %i\nSector size: %i\n" % (flash_size, sector_size))
if fpga:
+ #validate fpga image name against hardware rev
+ if(hw_rev != 0 and not any(name in fpga for name in n2xx_revs[hw_rev])):
+ raise Exception("Error: incorrect FPGA image version. Please use the correct image for device %s" % n2xx_revs[hw_rev][0])
+
if safe: image_location = SAFE_FPGA_IMAGE_LOCATION_ADDR
else: image_location = PROD_FPGA_IMAGE_LOCATION_ADDR
@@ -172,7 +290,7 @@ class burner_socket(object):
if not is_valid_fpga_image(fpga_image):
raise Exception("Error: Invalid FPGA image file.")
-
+
if (len(fpga_image) + image_location) > flash_size:
raise Exception("Error: Cannot write past end of device")
@@ -196,7 +314,7 @@ class burner_socket(object):
if not is_valid_fw_image(fw_image):
raise Exception("Error: Invalid firmware image file.")
-
+
if (len(fw_image) + image_location) > flash_size:
raise Exception("Error: Cannot write past end of device")
@@ -218,7 +336,7 @@ class burner_socket(object):
(mem_size, sector_size) = self.get_flash_info()
if (addr + len(writedata)) > mem_size:
raise Exception("Error: Cannot write past end of device")
-
+
while writedata:
out_pkt = pack_flash_args_fmt(USRP2_FW_PROTO_VERSION, update_id_t.USRP2_FW_UPDATE_ID_WRITE_TEH_FLASHES_LOL, seq(), addr, FLASH_DATA_PACKET_SIZE, writedata[:FLASH_DATA_PACKET_SIZE])
in_pkt = self.send_and_recv(out_pkt)
@@ -305,7 +423,7 @@ class burner_socket(object):
(flash_size, sector_size) = self.get_flash_info()
if (addr + length) > flash_size:
raise Exception("Cannot erase past end of device")
-
+
out_pkt = pack_flash_args_fmt(USRP2_FW_PROTO_VERSION, update_id_t.USRP2_FW_UPDATE_ID_ERASE_TEH_FLASHES_LOL, seq(), addr, length)
in_pkt = self.send_and_recv(out_pkt)
@@ -342,6 +460,7 @@ def get_options():
parser.add_option("--reset", action="store_true", help="reset the device after writing", default=False)
parser.add_option("--read", action="store_true", help="read to file instead of write from file", default=False)
parser.add_option("--overwrite-safe", action="store_true", help="never ever use this option", default=False)
+ parser.add_option("--list", action="store_true", help="list possible network devices", default=False)
(options, args) = parser.parse_args()
return options
@@ -351,6 +470,12 @@ def get_options():
########################################################################
if __name__=='__main__':
options = get_options()
+
+ if options.list:
+ print('Possible network devices:')
+ print(' ' + '\n '.join(enumerate_devices()))
+ exit()
+
if not options.addr: raise Exception('no address specified')
if not options.fpga and not options.fw and not options.reset: raise Exception('Must specify either a firmware image or FPGA image, and/or reset.')
diff --git a/host/utils/usrp_n2xx_net_burner_gui.py b/host/utils/usrp_n2xx_net_burner_gui.py
index 3b414a918..e2b79e72c 100755
--- a/host/utils/usrp_n2xx_net_burner_gui.py
+++ b/host/utils/usrp_n2xx_net_burner_gui.py
@@ -84,6 +84,45 @@ class ProgressBar(tkinter.Canvas):
if frac: self.create_rectangle(0, 0, fill_pixels, self._height, fill="#357EC7")
else: self.create_rectangle(0, 0, self._width, self._height, fill="#E8E8E8")
+class DeviceEntryWidget(tkinter.Frame):
+ """
+ Simple entry widget for getting the network device name.
+ Combines a label, entry, and helpful text box with hints.
+ """
+
+ def __init__(self, root, text=''):
+ tkinter.Frame.__init__(self, root)
+
+ tkinter.Button(self, text="Rescan for Devices", command=self._reload_cb).pack()
+
+ self._hints = tkinter.Listbox(self)
+ self._hints.bind("<<ListboxSelect>>", self._listbox_cb)
+ self._reload_cb()
+ self._hints.pack(expand=tkinter.YES, fill=tkinter.X)
+
+ frame = tkinter.Frame(self)
+ frame.pack()
+
+ tkinter.Label(frame, text="Network Address:").pack(side=tkinter.LEFT)
+ self._entry = tkinter.Entry(frame, width=50)
+ self._entry.insert(tkinter.END, text)
+ self._entry.pack(side=tkinter.LEFT)
+
+ def _reload_cb(self):
+ self._hints.delete(0, tkinter.END)
+ for hint in usrp_n2xx_net_burner.enumerate_devices():
+ self._hints.insert(tkinter.END, hint)
+
+ def _listbox_cb(self, event):
+ try:
+ sel = self._hints.get(self._hints.curselection()[0])
+ self._entry.delete(0, tkinter.END)
+ self._entry.insert(0, sel)
+ except Exception as e: print(e)
+
+ def get_devname(self):
+ return self._entry.get()
+
class SectionLabel(tkinter.Label):
"""
Make a text label with bold font.
@@ -115,10 +154,9 @@ class USRPN2XXNetBurnerApp(tkinter.Frame):
self._fpga_img_entry.pack()
#pack the destination entry widget
- SectionLabel(self, text="Select Address").pack(pady=5)
- self._addr_entry = tkinter.Entry(self, width=30)
- self._addr_entry.insert(tkinter.END, addr)
- self._addr_entry.pack()
+ SectionLabel(self, text="Select Device").pack(pady=5)
+ self._net_dev_entry = DeviceEntryWidget(self, text=addr)
+ self._net_dev_entry.pack()
#the do it button
SectionLabel(self, text="").pack(pady=5)
@@ -136,12 +174,10 @@ class USRPN2XXNetBurnerApp(tkinter.Frame):
self._pbar.pack(side=tkinter.RIGHT, expand=True)
def _burn(self):
- self._disable_input()
-
#grab strings from the gui
fw = self._fw_img_entry.get_filename()
fpga = self._fpga_img_entry.get_filename()
- addr = self._addr_entry.get()
+ addr = self._net_dev_entry.get_devname()
#check input
if not addr:
@@ -157,6 +193,7 @@ class USRPN2XXNetBurnerApp(tkinter.Frame):
tkinter.messagebox.showerror('Error:', 'FPGA image not found!')
return
+ self._disable_input()
try:
#make a new burner object and attempt the burner operation
burner = usrp_n2xx_net_burner.burner_socket(addr=addr)