summaryrefslogtreecommitdiffstats
path: root/host
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-11-04 23:44:58 -0700
committerJosh Blum <josh@joshknows.com>2010-11-04 23:44:58 -0700
commit0066ef2972f35d3d1ba7a9127f197fba9e754d88 (patch)
tree8d6b16b8f8f7e4feef56e0dd21988ef3623ad882 /host
parent9dff7952f618360943470711636db64fe2376b40 (diff)
downloaduhd-0066ef2972f35d3d1ba7a9127f197fba9e754d88.tar.gz
uhd-0066ef2972f35d3d1ba7a9127f197fba9e754d88.tar.bz2
uhd-0066ef2972f35d3d1ba7a9127f197fba9e754d88.zip
usrp: replaced device specific burner apps with one generic one for mboard eeproms
Diffstat (limited to 'host')
-rw-r--r--host/lib/usrp/mboard_eeprom.cpp3
-rw-r--r--host/lib/usrp/usrp1/mboard_impl.cpp35
-rw-r--r--host/lib/usrp/usrp1/usrp1_impl.hpp2
-rw-r--r--host/utils/CMakeLists.txt12
-rw-r--r--host/utils/usrp1_serial_burner.cpp75
-rw-r--r--host/utils/usrp2_addr_burner.cpp91
-rw-r--r--host/utils/usrp_burn_db_eeprom.cpp6
-rw-r--r--host/utils/usrp_burn_mb_eeprom.cpp79
8 files changed, 101 insertions, 202 deletions
diff --git a/host/lib/usrp/mboard_eeprom.cpp b/host/lib/usrp/mboard_eeprom.cpp
index 2f5d41c95..81dc6f194 100644
--- a/host/lib/usrp/mboard_eeprom.cpp
+++ b/host/lib/usrp/mboard_eeprom.cpp
@@ -40,8 +40,7 @@ static const size_t NAME_MAX_LEN = 32 - SERIAL_LEN;
static const std::string bytes_to_string(const byte_vector_t &bytes){
std::string out;
BOOST_FOREACH(boost::uint8_t byte, bytes){
- if (byte == '\0') return out;
- if (byte < 32 or byte > 127) return "";
+ if (byte < 32 or byte > 127) return out;
out += byte;
}
return out;
diff --git a/host/lib/usrp/usrp1/mboard_impl.cpp b/host/lib/usrp/usrp1/mboard_impl.cpp
index 669b20efa..d7ab46eb1 100644
--- a/host/lib/usrp/usrp1/mboard_impl.cpp
+++ b/host/lib/usrp/usrp1/mboard_impl.cpp
@@ -208,6 +208,8 @@ bool usrp1_impl::has_tx_halfband(void){
**********************************************************************/
void usrp1_impl::mboard_init(void)
{
+ _mb_eeprom = mboard_eeprom_t(*_iface, mboard_eeprom_t::MAP_BXXX);
+
_mboard_proxy = wax_obj_proxy::make(
boost::bind(&usrp1_impl::mboard_get, this, _1, _2),
boost::bind(&usrp1_impl::mboard_set, this, _1, _2));
@@ -262,24 +264,10 @@ void usrp1_impl::mboard_get(const wax::obj &key_, wax::obj &val)
{
named_prop_t key = named_prop_t::extract(key_);
- if(key_.type() == typeid(std::string)) {
- if(key.as<std::string>() == "serial") {
- uhd::byte_vector_t buf;
- buf.insert(buf.begin(), 248);
- boost::this_thread::sleep(boost::posix_time::milliseconds(100));
- _iface->write_i2c(I2C_DEV_EEPROM, buf);
- boost::this_thread::sleep(boost::posix_time::milliseconds(100));
- buf = _iface->read_i2c(I2C_DEV_EEPROM, 8);
- val = std::string(buf.begin(), buf.end());
- }
-
- return;
- }
-
//handle the get request conditioned on the key
switch(key.as<mboard_prop_t>()){
case MBOARD_PROP_NAME:
- val = std::string("usrp1 mboard - " + (*_mboard_proxy)[std::string("serial")].as<std::string>());
+ val = std::string("usrp1 mboard - " + _mb_eeprom["serial"]);
return;
case MBOARD_PROP_OTHERS:
@@ -336,6 +324,10 @@ void usrp1_impl::mboard_get(const wax::obj &key_, wax::obj &val)
val = _tx_subdev_spec;
return;
+ case MBOARD_PROP_EEPROM_MAP:
+ val = _mb_eeprom;
+ return;
+
default: UHD_THROW_PROP_GET_ERROR();
}
}
@@ -351,14 +343,6 @@ void usrp1_impl::mboard_set(const wax::obj &key, const wax::obj &val)
std::cout << "USRP1 EEPROM image: " << usrp1_eeprom_image << std::endl;
_ctrl_transport->usrp_load_eeprom(val.as<std::string>());
}
-
- if(key.as<std::string>() == "serial") {
- std::string sernum = val.as<std::string>();
- uhd::byte_vector_t buf(sernum.begin(), sernum.end());
- buf.insert(buf.begin(), 248);
- _iface->write_i2c(I2C_DEV_EEPROM, buf);
- }
-
return;
}
@@ -395,6 +379,11 @@ void usrp1_impl::mboard_set(const wax::obj &key, const wax::obj &val)
_iface->poke32(FR_TX_MUX, calc_tx_mux(_tx_subdev_spec, _mboard_proxy->get_link()));
return;
+ case MBOARD_PROP_EEPROM_MAP:
+ _mb_eeprom = val.as<mboard_eeprom_t>();
+ _mb_eeprom.commit(*_iface, mboard_eeprom_t::MAP_BXXX);
+ return;
+
default: UHD_THROW_PROP_SET_ERROR();
}
}
diff --git a/host/lib/usrp/usrp1/usrp1_impl.hpp b/host/lib/usrp/usrp1/usrp1_impl.hpp
index ff4d40762..3eb221a52 100644
--- a/host/lib/usrp/usrp1/usrp1_impl.hpp
+++ b/host/lib/usrp/usrp1/usrp1_impl.hpp
@@ -26,6 +26,7 @@
#include <uhd/types/clock_config.hpp>
#include <uhd/types/stream_cmd.hpp>
#include <uhd/usrp/dboard_id.hpp>
+#include <uhd/usrp/mboard_eeprom.hpp>
#include <uhd/usrp/subdev_spec.hpp>
#include <uhd/usrp/dboard_eeprom.hpp>
#include <uhd/usrp/dboard_manager.hpp>
@@ -158,6 +159,7 @@ private:
void mboard_get(const wax::obj &, wax::obj &);
void mboard_set(const wax::obj &, const wax::obj &);
wax_obj_proxy::sptr _mboard_proxy;
+ uhd::usrp::mboard_eeprom_t _mb_eeprom;
//xx dboard functions and settings
void dboard_init(void);
diff --git a/host/utils/CMakeLists.txt b/host/utils/CMakeLists.txt
index a95864ca7..f0fa806c5 100644
--- a/host/utils/CMakeLists.txt
+++ b/host/utils/CMakeLists.txt
@@ -33,23 +33,19 @@ INSTALL(TARGETS
########################################################################
# Utilities that get installed into the share path
########################################################################
-ADD_EXECUTABLE(usrp2_addr_burner usrp2_addr_burner.cpp)
-TARGET_LINK_LIBRARIES(usrp2_addr_burner uhd)
-
ADD_EXECUTABLE(usrp_burn_db_eeprom usrp_burn_db_eeprom.cpp)
TARGET_LINK_LIBRARIES(usrp_burn_db_eeprom uhd)
+ADD_EXECUTABLE(usrp_burn_mb_eeprom usrp_burn_mb_eeprom.cpp)
+TARGET_LINK_LIBRARIES(usrp_burn_mb_eeprom uhd)
+
ADD_EXECUTABLE(usrp1_init_eeprom usrp1_init_eeprom.cpp)
TARGET_LINK_LIBRARIES(usrp1_init_eeprom uhd)
-ADD_EXECUTABLE(usrp1_serial_burner usrp1_serial_burner.cpp)
-TARGET_LINK_LIBRARIES(usrp1_serial_burner uhd)
-
INSTALL(TARGETS
- usrp2_addr_burner
usrp_burn_db_eeprom
+ usrp_burn_mb_eeprom
usrp1_init_eeprom
- usrp1_serial_burner
RUNTIME DESTINATION ${PKG_DATA_DIR}/utils
)
diff --git a/host/utils/usrp1_serial_burner.cpp b/host/utils/usrp1_serial_burner.cpp
deleted file mode 100644
index bf7d3d3bb..000000000
--- a/host/utils/usrp1_serial_burner.cpp
+++ /dev/null
@@ -1,75 +0,0 @@
-//
-// Copyright 2010 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 <uhd/utils/safe_main.hpp>
-#include <uhd/device.hpp>
-#include <uhd/usrp/device_props.hpp>
-#include <boost/program_options.hpp>
-#include <boost/format.hpp>
-#include <iostream>
-
-namespace po = boost::program_options;
-
-int UHD_SAFE_MAIN(int argc, char *argv[]){
- po::options_description desc("Allowed options");
- desc.add_options()
- ("help", "help message")
- ("old", po::value<std::string>(), "old USRP serial number (optional)")
- ("new", po::value<std::string>(), "new USRP serial number")
- ;
-
- po::variables_map vm;
- po::store(po::parse_command_line(argc, argv, desc), vm);
- po::notify(vm);
-
- //print the help message
- if (vm.count("help")){
- std::cout << boost::format("USRP serial burner %s") % desc << std::endl;
- return ~0;
- }
-
- if(vm.count("new") == 0) {
- std::cout << "error: must input --new arg" << std::endl;
- return ~0;
- }
-
- //load the options into the address
- uhd::device_addr_t device_addr;
- device_addr["type"] = "usrp1";
- if(vm.count("old")) device_addr["serial"] = vm["old"].as<std::string>();
-
- //find and create a control transport to do the writing.
-
- uhd::device_addrs_t found_addrs = uhd::device::find(device_addr);
-
- if (found_addrs.size() == 0){
- std::cerr << "No USRP devices found" << std::endl;
- return ~0;
- }
-
- for (size_t i = 0; i < found_addrs.size(); i++){
- uhd::device::sptr dev = uhd::device::make(found_addrs[i]);
- wax::obj mb = (*dev)[uhd::usrp::DEVICE_PROP_MBOARD];
- std::cout << "Writing serial number..." << std::endl;
- mb[std::string("serial")] = vm["new"].as<std::string>();
- std::cout << "Reading back serial number: " << mb[std::string("serial")].as<std::string>() << std::endl;
- }
-
-
- std::cout << "Power-cycle the usrp for the changes to take effect." << std::endl;
- return 0;
-}
diff --git a/host/utils/usrp2_addr_burner.cpp b/host/utils/usrp2_addr_burner.cpp
deleted file mode 100644
index f0e3434b7..000000000
--- a/host/utils/usrp2_addr_burner.cpp
+++ /dev/null
@@ -1,91 +0,0 @@
-//
-// Copyright 2010 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 <uhd/utils/safe_main.hpp>
-#include <uhd/device.hpp>
-#include <uhd/usrp/device_props.hpp>
-#include <boost/program_options.hpp>
-#include <boost/format.hpp>
-#include <iostream>
-
-namespace po = boost::program_options;
-
-int UHD_SAFE_MAIN(int argc, char *argv[]){
- po::options_description desc("Allowed options");
- desc.add_options()
- ("help", "help message")
- ("addr", po::value<std::string>(), "resolvable network address")
- ("new-ip", po::value<std::string>(), "new ip address (optional)")
- ("new-mac", po::value<std::string>(), "new mac address (optional)")
- ;
-
- po::variables_map vm;
- po::store(po::parse_command_line(argc, argv, desc), vm);
- po::notify(vm);
-
- //print the help message
- if (vm.count("help")){
- std::cout << boost::format("USRP2 Address Burner %s") % desc << std::endl;
- return ~0;
- }
-
- //load the options into the address
- uhd::device_addr_t device_addr;
- device_addr["type"] = "usrp2";
- if (vm.count("addr")){
- device_addr["addr"] = vm["addr"].as<std::string>();
- }
- else{
- std::cerr << "Error: missing addr option" << std::endl;
- return ~0;
- }
-
- //create a usrp2 device
- uhd::device::sptr u2_dev = uhd::device::make(device_addr);
- //FIXME usees the default mboard for now (until the mimo link is supported)
- wax::obj u2_mb = (*u2_dev)[uhd::usrp::DEVICE_PROP_MBOARD];
- std::cout << std::endl;
-
- //fetch and print current settings
- std::cout << "Fetching current settings from usrp2 eeprom:" << std::endl;
- std::string curr_ip = u2_mb[std::string("ip-addr")].as<std::string>();
- std::cout << boost::format(" Current IP Address: %s") % curr_ip << std::endl;
- std::string curr_mac = u2_mb[std::string("mac-addr")].as<std::string>();
- std::cout << boost::format(" Current MAC Address: %s") % curr_mac << std::endl;
- std::cout << " Done" << std::endl << std::endl;
-
- //try to set the new ip (if provided)
- if (vm.count("new-ip")){
- std::cout << "Burning a new ip address into the usrp2 eeprom:" << std::endl;
- std::string new_ip = vm["new-ip"].as<std::string>();
- std::cout << boost::format(" New IP Address: %s") % new_ip << std::endl;
- u2_mb[std::string("ip-addr")] = new_ip;
- std::cout << " Done" << std::endl << std::endl;
- }
-
- //try to set the new mac (if provided)
- if (vm.count("new-mac")){
- std::cout << "Burning a new mac address into the usrp2 eeprom:" << std::endl;
- std::string new_mac = vm["new-mac"].as<std::string>();
- std::cout << boost::format(" New MAC Address: %s") % new_mac << std::endl;
- u2_mb[std::string("mac-addr")] = new_mac;
- std::cout << " Done" << std::endl << std::endl;
- }
-
- std::cout << "Power-cycle the usrp2 for the changes to take effect." << std::endl;
- return 0;
-}
diff --git a/host/utils/usrp_burn_db_eeprom.cpp b/host/utils/usrp_burn_db_eeprom.cpp
index 64ecf75d6..9afd71a22 100644
--- a/host/utils/usrp_burn_db_eeprom.cpp
+++ b/host/utils/usrp_burn_db_eeprom.cpp
@@ -58,10 +58,10 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
//print the help message
if (vm.count("help")){
- std::cout << boost::format("USRP Burn DB EEPROM %s") % desc << std::endl;
+ std::cout << boost::format("USRP Burn Daughterboard EEPROM %s") % desc << std::endl;
std::cout << boost::format(
- "Omit the id argument to perform readback,\n"
- "Or specify a new id to burn into the eeprom.\n"
+ "Omit the ID argument to perform readback,\n"
+ "Or specify a new ID to burn into the EEPROM.\n"
) << std::endl;
return ~0;
}
diff --git a/host/utils/usrp_burn_mb_eeprom.cpp b/host/utils/usrp_burn_mb_eeprom.cpp
new file mode 100644
index 000000000..8d0835222
--- /dev/null
+++ b/host/utils/usrp_burn_mb_eeprom.cpp
@@ -0,0 +1,79 @@
+//
+// Copyright 2010 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 <uhd/utils/safe_main.hpp>
+#include <uhd/device.hpp>
+#include <uhd/usrp/device_props.hpp>
+#include <uhd/usrp/mboard_props.hpp>
+#include <uhd/usrp/mboard_eeprom.hpp>
+#include <boost/program_options.hpp>
+#include <boost/format.hpp>
+#include <iostream>
+
+namespace po = boost::program_options;
+
+int UHD_SAFE_MAIN(int argc, char *argv[]){
+ std::string args, key, val;
+
+ po::options_description desc("Allowed options");
+ desc.add_options()
+ ("help", "help message")
+ ("args", po::value<std::string>(&args)->default_value(""), "device address args [default = \"\"]")
+ ("key", po::value<std::string>(&key), "the indentifier for a value in EEPROM")
+ ("val", po::value<std::string>(&val), "the new value to set, omit for readback")
+ ;
+
+ po::variables_map vm;
+ po::store(po::parse_command_line(argc, argv, desc), vm);
+ po::notify(vm);
+
+ //print the help message
+ if (vm.count("help") or not vm.count("key")){
+ std::cout << boost::format("USRP Burn Motherboard EEPROM %s") % desc << std::endl;
+ std::cout << boost::format(
+ "Omit the value argument to perform a readback,\n"
+ "Or specify a new value to burn into the EEPROM.\n"
+ ) << std::endl;
+ return ~0;
+ }
+
+ std::cout << "Creating USRP device from address: " + args << std::endl;
+ uhd::device::sptr dev = uhd::device::make(args);
+ std::cout << std::endl;
+
+ std::cout << "Fetching current settings from EEPROM..." << std::endl;
+ //FIXME the default mboard for now (may be others)
+ wax::obj mboard = (*dev)[uhd::usrp::DEVICE_PROP_MBOARD];
+ uhd::usrp::mboard_eeprom_t mb_eeprom = \
+ mboard[uhd::usrp::MBOARD_PROP_EEPROM_MAP].as<uhd::usrp::mboard_eeprom_t>();
+ if (not mb_eeprom.has_key(key)){
+ std::cerr << boost::format("Cannot find value for EEPROM[%s]") % key << std::endl;
+ return ~0;
+ }
+ std::cout << boost::format(" EEPROM [\"%s\"] is \"%s\"") % key % mb_eeprom[key] << std::endl;
+ std::cout << std::endl;
+
+ if (vm.count("val")){
+ std::cout << boost::format("Setting EEPROM [\"%s\"] to \"%s\"...") % key % val << std::endl;
+ mb_eeprom[key] = val;
+ mboard[uhd::usrp::MBOARD_PROP_EEPROM_MAP] = mb_eeprom;
+ std::cout << "Power-cycle the USRP device for the changes to take effect." << std::endl;
+ }
+
+ std::cout << "Done" << std::endl;
+ return 0;
+}