diff options
| author | Nicholas Corgan <nick.corgan@ettus.com> | 2015-07-15 09:32:18 -0700 | 
|---|---|---|
| committer | Nicholas Corgan <nick.corgan@ettus.com> | 2015-07-15 09:32:18 -0700 | 
| commit | 0595900eccfffee9e944dc53466337b44655caac (patch) | |
| tree | 7db7ee8e908b604236b04cf49f3d8d978e386543 /host/lib/usrp/b200 | |
| parent | 012381d999c4a895593412aaf06e73432b458810 (diff) | |
| download | uhd-0595900eccfffee9e944dc53466337b44655caac.tar.gz uhd-0595900eccfffee9e944dc53466337b44655caac.tar.bz2 uhd-0595900eccfffee9e944dc53466337b44655caac.zip | |
Added uhd::image_loader class and uhd_image_loader utility
* Single class for loading firmware/FPGA images onto devices instead of multiple utilities
* Loading functions are registered for each device, corresponding to their --args="type=foo" name
* Deprecation warnings added to all product-specific image loading utilities
Diffstat (limited to 'host/lib/usrp/b200')
| -rw-r--r-- | host/lib/usrp/b200/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | host/lib/usrp/b200/b200_iface.cpp | 4 | ||||
| -rw-r--r-- | host/lib/usrp/b200/b200_iface.hpp | 2 | ||||
| -rw-r--r-- | host/lib/usrp/b200/b200_image_loader.cpp | 125 | ||||
| -rw-r--r-- | host/lib/usrp/b200/b200_impl.cpp | 39 | ||||
| -rw-r--r-- | host/lib/usrp/b200/b200_impl.hpp | 16 | 
6 files changed, 162 insertions, 25 deletions
| diff --git a/host/lib/usrp/b200/CMakeLists.txt b/host/lib/usrp/b200/CMakeLists.txt index ce89b5d80..cd8ebcba7 100644 --- a/host/lib/usrp/b200/CMakeLists.txt +++ b/host/lib/usrp/b200/CMakeLists.txt @@ -26,6 +26,7 @@ LIBUHD_REGISTER_COMPONENT("B200" ENABLE_B200 ON "ENABLE_LIBUHD;ENABLE_USB" OFF)  IF(ENABLE_B200)      LIBUHD_APPEND_SOURCES( +        ${CMAKE_CURRENT_SOURCE_DIR}/b200_image_loader.cpp          ${CMAKE_CURRENT_SOURCE_DIR}/b200_impl.cpp          ${CMAKE_CURRENT_SOURCE_DIR}/b200_iface.cpp          ${CMAKE_CURRENT_SOURCE_DIR}/b200_io_impl.cpp diff --git a/host/lib/usrp/b200/b200_iface.cpp b/host/lib/usrp/b200/b200_iface.cpp index 270d3bb4b..4754a6357 100644 --- a/host/lib/usrp/b200/b200_iface.cpp +++ b/host/lib/usrp/b200/b200_iface.cpp @@ -511,7 +511,7 @@ public:              throw uhd::io_error((boost::format("Short write on set FPGA hash (expecting: %d, returned: %d)") % bytes_to_send % ret).str());      } -    boost::uint32_t load_fpga(const std::string filestring) { +    boost::uint32_t load_fpga(const std::string filestring, bool force) {          boost::uint8_t fx3_state = 0;          boost::uint32_t wait_count; @@ -522,7 +522,7 @@ public:          hash_type hash = generate_hash(filename);          hash_type loaded_hash; usrp_get_fpga_hash(loaded_hash); -        if (hash == loaded_hash) return 0; +        if (hash == loaded_hash and !force) return 0;          // Establish default largest possible control request transfer size based on operating USB speed          int transfer_size = VREQ_DEFAULT_SIZE; diff --git a/host/lib/usrp/b200/b200_iface.hpp b/host/lib/usrp/b200/b200_iface.hpp index 1d123439a..0c7ee6b9e 100644 --- a/host/lib/usrp/b200/b200_iface.hpp +++ b/host/lib/usrp/b200/b200_iface.hpp @@ -97,7 +97,7 @@ public:      virtual void set_fpga_reset_pin(const bool reset) = 0;      //! load an FPGA image -    virtual boost::uint32_t load_fpga(const std::string filestring) = 0; +    virtual boost::uint32_t load_fpga(const std::string filestring, bool force=false) = 0;      virtual void write_eeprom(boost::uint16_t addr, boost::uint16_t offset, const uhd::byte_vector_t &bytes) = 0; diff --git a/host/lib/usrp/b200/b200_image_loader.cpp b/host/lib/usrp/b200/b200_image_loader.cpp new file mode 100644 index 000000000..87010244c --- /dev/null +++ b/host/lib/usrp/b200/b200_image_loader.cpp @@ -0,0 +1,125 @@ +// +// Copyright 2014-2015 Ettus Research LLC +// +// This program 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 of the License, or +// (at your option) any later version. +// +// This program 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 this program.  If not, see <http://www.gnu.org/licenses/>. +// + +#include <boost/assign.hpp> +#include <boost/foreach.hpp> +#include <boost/lexical_cast.hpp> + +#include <uhd/exception.hpp> +#include <uhd/image_loader.hpp> +#include <uhd/types/dict.hpp> +#include <uhd/usrp/mboard_eeprom.hpp> +#include <uhd/utils/paths.hpp> +#include <uhd/utils/static.hpp> + +#include "b200_iface.hpp" +#include "b200_impl.hpp" + +using namespace uhd; +using namespace uhd::usrp; +using namespace uhd::transport; + +namespace uhd{ + +static b200_iface::sptr get_b200_iface(const image_loader::image_loader_args_t &image_loader_args, +                                       mboard_eeprom_t &mb_eeprom, +                                       bool user_specified){ + +    std::vector<usb_device_handle::sptr> dev_handles = get_b200_device_handles(image_loader_args.args); +    b200_iface::sptr iface; + +    if(dev_handles.size() > 0){ +        BOOST_FOREACH(usb_device_handle::sptr dev_handle, dev_handles){ +            if(dev_handle->firmware_loaded()){ +                iface = b200_iface::make(usb_control::make(dev_handle,0)); +                mb_eeprom = mboard_eeprom_t(*iface, "B200"); +                if(user_specified){ +                    if(image_loader_args.args.has_key("serial") and +                       mb_eeprom.get("serial") != image_loader_args.args.get("serial")){ +                           continue; +                    } +                    if(image_loader_args.args.has_key("name") and +                       mb_eeprom.get("name") != image_loader_args.args.get("name")){ +                           continue; +                    } +                    return iface; +                } +                else return iface; // Just return first found +            } +        } +    } + +    // No applicable devices found, return empty sptr so we can exit +    iface.reset(); +    mb_eeprom = mboard_eeprom_t(); +    return iface; +} + +static bool b200_image_loader(const image_loader::image_loader_args_t &image_loader_args){ +    if(!image_loader_args.load_fpga) +        return false; + +    bool user_specified = (image_loader_args.args.has_key("serial") or +                           image_loader_args.args.has_key("name")); + +    // See if a B2x0 with the given args is found +    mboard_eeprom_t mb_eeprom; +    b200_iface::sptr iface = get_b200_iface(image_loader_args, mb_eeprom, user_specified); +    if(!iface) return false; // No initialized B2x0 found + +    std::string fpga_path; +    if(image_loader_args.fpga_path == ""){ +        /* +         * Normally, we can auto-generate the FPGA filename from what's in the EEPROM, +         * but if the applicable value is not in the EEPROM, the user must give a specific +         * filename for us to use. +         */ +        std::string product = mb_eeprom.get("product"); +        if(not B2X0_PRODUCT_ID.has_key(boost::lexical_cast<boost::uint16_t>(product))){ +            if(user_specified){ +                // The user specified a bad device but expects us to know what it is +                throw uhd::runtime_error("Could not determine model. You must manually specify an FPGA image filename."); +            } +            else{ +                return false; +            } +        } +        else{ +            fpga_path = find_image_path(B2X0_FPGA_FILE_NAME.get(get_b200_type(mb_eeprom))); +        } +    } +    else fpga_path = image_loader_args.fpga_path; + +    std::cout << boost::format("Unit: USRP %s (%s)") +                 % B2X0_STR_NAMES.get(get_b200_type(mb_eeprom), "B2XX") +                 % mb_eeprom.get("serial") +              << std::endl; + +    iface->load_fpga(fpga_path, true); + +    return true; +} + +UHD_STATIC_BLOCK(register_b200_image_loader){ +    std::string recovery_instructions = "This device is likely in an unusable state. Power-cycle the\n" +                                        "device, and the firmware/FPGA will be reloaded the next time\n" +                                        "UHD uses the device."; + +    image_loader::register_image_loader("b200", b200_image_loader, recovery_instructions); +} + +} /* namespace uhd */ diff --git a/host/lib/usrp/b200/b200_impl.cpp b/host/lib/usrp/b200/b200_impl.cpp index 7c672fd46..17086de02 100644 --- a/host/lib/usrp/b200/b200_impl.cpp +++ b/host/lib/usrp/b200/b200_impl.cpp @@ -76,7 +76,7 @@ public:  //! Look up the type of B-Series device we're currently running.  //  If the product ID stored in mb_eeprom is invalid, throws a  //  uhd::runtime_error. -static b200_type_t get_b200_type(const mboard_eeprom_t &mb_eeprom) +b200_type_t get_b200_type(const mboard_eeprom_t &mb_eeprom)  {      if (mb_eeprom["product"].empty()) {          throw uhd::runtime_error("B200: Missing product ID on EEPROM."); @@ -91,6 +91,21 @@ static b200_type_t get_b200_type(const mboard_eeprom_t &mb_eeprom)      return B2X0_PRODUCT_ID[product_id];  } +std::vector<usb_device_handle::sptr> get_b200_device_handles(const device_addr_t &hint) +{ +    std::vector<usb_device_handle::vid_pid_pair_t> vid_pid_pair_list; + +    if(hint.has_key("vid") && hint.has_key("pid") && hint.has_key("type") && hint["type"] == "b200") { +        vid_pid_pair_list.push_back(usb_device_handle::vid_pid_pair_t(uhd::cast::hexstr_cast<boost::uint16_t>(hint.get("vid")), +                                                                      uhd::cast::hexstr_cast<boost::uint16_t>(hint.get("pid")))); +    } else { +        vid_pid_pair_list = b200_vid_pid_pairs; +    } + +    //find the usrps and load firmware +    return usb_device_handle::get_device_list(vid_pid_pair_list); +} +  static device_addrs_t b200_find(const device_addr_t &hint)  {      device_addrs_t b200_addrs; @@ -104,28 +119,14 @@ static device_addrs_t b200_find(const device_addr_t &hint)          if (hint_i.has_key("addr") || hint_i.has_key("resource")) return b200_addrs;      } -    size_t found = 0; -    std::vector<usb_device_handle::vid_pid_pair_t> vid_pid_pair_list;//vid pid pair search list for devices. - -    if(hint.has_key("vid") && hint.has_key("pid") && hint.has_key("type") && hint["type"] == "b200") { -        vid_pid_pair_list.push_back(usb_device_handle::vid_pid_pair_t(uhd::cast::hexstr_cast<boost::uint16_t>(hint.get("vid")), -                                                                    uhd::cast::hexstr_cast<boost::uint16_t>(hint.get("pid")))); -    } else { -        vid_pid_pair_list.push_back(usb_device_handle::vid_pid_pair_t(B200_VENDOR_ID, B200_PRODUCT_ID)); -        vid_pid_pair_list.push_back(usb_device_handle::vid_pid_pair_t(B200_VENDOR_NI_ID, B200_PRODUCT_NI_ID)); -        vid_pid_pair_list.push_back(usb_device_handle::vid_pid_pair_t(B200_VENDOR_NI_ID, B210_PRODUCT_NI_ID)); -    } -      // Important note:      // The get device list calls are nested inside the for loop.      // This allows the usb guts to decontruct when not in use,      // so that re-enumeration after fw load can occur successfully.      // This requirement is a courtesy of libusb1.0 on windows. - -    //find the usrps and load firmware -    std::vector<usb_device_handle::sptr> uhd_usb_device_vector = usb_device_handle::get_device_list(vid_pid_pair_list); - -    BOOST_FOREACH(usb_device_handle::sptr handle, uhd_usb_device_vector) { +    size_t found = 0; +    std::vector<usb_device_handle::sptr> b200_device_handles = get_b200_device_handles(hint); +    BOOST_FOREACH(usb_device_handle::sptr handle, b200_device_handles) {          //extract the firmware path for the b200          std::string b200_fw_image;          try{ @@ -156,7 +157,7 @@ static device_addrs_t b200_find(const device_addr_t &hint)      //search for the device until found or timeout      while (boost::get_system_time() < timeout_time and b200_addrs.empty() and found != 0)      { -        BOOST_FOREACH(usb_device_handle::sptr handle, usb_device_handle::get_device_list(vid_pid_pair_list)) +        BOOST_FOREACH(usb_device_handle::sptr handle, b200_device_handles)          {              usb_control::sptr control;              try{control = usb_control::make(handle, 0);} diff --git a/host/lib/usrp/b200/b200_impl.hpp b/host/lib/usrp/b200/b200_impl.hpp index 11c3da0d9..a3c93e22e 100644 --- a/host/lib/usrp/b200/b200_impl.hpp +++ b/host/lib/usrp/b200/b200_impl.hpp @@ -43,6 +43,7 @@  #include <uhd/usrp/gps_ctrl.hpp>  #include <uhd/transport/usb_zero_copy.hpp>  #include <uhd/transport/bounded_buffer.hpp> +#include <boost/assign.hpp>  #include <boost/weak_ptr.hpp>  #include "recv_packet_demuxer_3000.hpp"  static const boost::uint8_t  B200_FW_COMPAT_NUM_MAJOR = 8; @@ -82,9 +83,18 @@ static const boost::uint32_t B200_RX_GPS_UART_SID = FLIP_SID(B200_TX_GPS_UART_SI  static const boost::uint32_t B200_LOCAL_CTRL_SID = 0x00000040;  static const boost::uint32_t B200_LOCAL_RESP_SID = FLIP_SID(B200_LOCAL_CTRL_SID); -/*********************************************************************** - * The B200 Capability Constants - **********************************************************************/ +/* + * VID/PID pairs for all B2xx products + */ +static std::vector<uhd::transport::usb_device_handle::vid_pid_pair_t> b200_vid_pid_pairs = +    boost::assign::list_of +        (uhd::transport::usb_device_handle::vid_pid_pair_t(B200_VENDOR_ID, B200_PRODUCT_ID)) +        (uhd::transport::usb_device_handle::vid_pid_pair_t(B200_VENDOR_NI_ID, B200_PRODUCT_NI_ID)) +        (uhd::transport::usb_device_handle::vid_pid_pair_t(B200_VENDOR_NI_ID, B210_PRODUCT_NI_ID)) +    ; + +b200_type_t get_b200_type(const uhd::usrp::mboard_eeprom_t &mb_eeprom); +std::vector<uhd::transport::usb_device_handle::sptr> get_b200_device_handles(const uhd::device_addr_t &hint);  //! Implementation guts  class b200_impl : public uhd::device | 
