1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
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 */
|