aboutsummaryrefslogtreecommitdiffstats
path: root/host/utils
diff options
context:
space:
mode:
Diffstat (limited to 'host/utils')
-rw-r--r--host/utils/uhd_images_downloader.py.in63
-rw-r--r--host/utils/usrp_burn_mb_eeprom.cpp43
2 files changed, 75 insertions, 31 deletions
diff --git a/host/utils/uhd_images_downloader.py.in b/host/utils/uhd_images_downloader.py.in
index e7fc9e8a5..bb082190c 100644
--- a/host/utils/uhd_images_downloader.py.in
+++ b/host/utils/uhd_images_downloader.py.in
@@ -44,13 +44,25 @@ class temp_dir():
self.name = tempfile.mkdtemp()
return self.name
def __exit__(self, type, value, traceback):
- os.removedirs(self.name)
+ try:
+ shutil.rmtree(self.name)
+ except OSError,e:
+ #Utility should have already detected this, but this is for safety
+ print str(e)
+ raise Exception("Could not install images! Make sure you have write permissions.")
if __name__ == "__main__":
+ print
+ if os.environ.get("UHD_IMAGES_DIR") != None and os.environ.get("UHD_IMAGES_DIR") != "":
+ default_images_dir = os.environ.get("UHD_IMAGES_DIR")
+ print "UHD_IMAGES_DIR environment variable is set. Default install location: %s" % default_images_dir
+ else:
+ default_images_dir = "@CMAKE_INSTALL_PREFIX@/share/uhd/images"
+
#Command line options
parser = OptionParser()
- parser.add_option("--install-location", type="string", default="", help="Set custom install location for images")
+ parser.add_option("--install-location", type="string", default=default_images_dir, help="Set custom install location for images")
parser.add_option("--buffer-size", type="int", default=8192, help="Set download buffer size, [default=%default]",)
(options, args) = parser.parse_args()
@@ -59,17 +71,27 @@ if __name__ == "__main__":
images_zip_md5sum = "@UHD_IMAGES_MD5SUM@"
filename = images_src.split("/")[-1]
+ #Use this directory with relative paths
+ current_directory = os.getcwd()
+
with temp_dir() as dirname:
os.chdir(dirname)
- #Configuring image destination
- if options.install_location != "":
+ if os.path.isabs(options.install_location):
+ #Custom absolute path given
images_dir = options.install_location
- elif os.environ.get("UHD_IMAGES_DIR") != "" and os.environ.get("UHD_IMAGES_DIR") != None:
- images_dir = os.environ.get("UHD_IMAGES_DIR")
else:
- images_dir = "@CMAKE_INSTALL_PREFIX@/share/uhd/images"
-
+ #Custom relative path given, so construct absolute path
+ images_dir = os.path.abspath(os.path.join(current_directory, options.install_location))
+
+ #Before doing anything, check for write permissions in parent directory
+ parent_directory = os.path.dirname(images_dir)
+ if os.access(parent_directory, os.W_OK):
+ print "Downloading images to: %s" % images_dir
+ else:
+ print "You do not have write permissions at the install location!"
+ sys.exit(1)
+
opener = urllib2.build_opener()
opener.add_headers = [('User-Agent', 'UHD Images Downloader')]
u = opener.open(images_src)
@@ -101,32 +123,37 @@ if __name__ == "__main__":
if images_zip_md5sum != downloaded_zip_md5sum:
print "\nMD5 checksum does not match!"
print "Expected %s, got %s" % (images_zip_md5sum, downloaded_zip_md5sum)
+ print "Images did not install. If problem persists, please contact support@ettus.com."
os.remove(filename)
os.chdir("/".join(images_dir.split("/")[:-1]))
+ sys.exit(1)
else:
+ temp_path = "tempdir"
+
#Extracting contents of zip file
- if os.path.exists("tempdir"):
- shutil.rmtree("tempdir")
- os.mkdir("tempdir")
+ if os.path.exists(temp_path):
+ shutil.rmtree(temp_path)
+ os.mkdir(temp_path)
images_zip = zipfile.ZipFile(filename)
- images_zip.extractall("tempdir")
+ images_zip.extractall(temp_path)
#Removing images currently in images_dir
if os.path.exists(images_dir):
try:
shutil.rmtree(images_dir)
- except:
- sys.stderr.write("\nMake sure you have write permissions in the images directory.\n")
- sys.exit(0)
+ except OSError,e:
+ print str(e)
+ print "Make sure you have write permissions in the images directory."
+ sys.exit(1)
#Copying downloaded images into images_dir
- shutil.copytree("tempdir/%s/share/uhd/images" % filename[:-4],images_dir)
+ shutil.copytree(os.path.join(temp_path, os.path.splitext(filename)[0], 'share', 'uhd', 'images'), images_dir)
#Removing tempdir and zip file
- shutil.rmtree("tempdir")
+ shutil.rmtree(temp_path)
images_zip.close()
os.remove(filename)
os.chdir(images_dir)
- print "\nImages successfully installed to: %s" % images_dir
+ print "\n\nImages successfully installed!"
diff --git a/host/utils/usrp_burn_mb_eeprom.cpp b/host/utils/usrp_burn_mb_eeprom.cpp
index 1b13fb615..ce0879c8e 100644
--- a/host/utils/usrp_burn_mb_eeprom.cpp
+++ b/host/utils/usrp_burn_mb_eeprom.cpp
@@ -1,5 +1,5 @@
//
-// Copyright 2010 Ettus Research LLC
+// Copyright 2010,2013 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
@@ -19,9 +19,11 @@
#include <uhd/device.hpp>
#include <uhd/property_tree.hpp>
#include <uhd/usrp/mboard_eeprom.hpp>
+#include <boost/algorithm/string.hpp>
#include <boost/program_options.hpp>
#include <boost/format.hpp>
#include <iostream>
+#include <vector>
namespace po = boost::program_options;
@@ -32,8 +34,8 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
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")
+ ("key", po::value<std::string>(&key), "identifiers for new values in EEPROM, separate multiple by \",\"")
+ ("val", po::value<std::string>(&val), "the new values to set, omit for readback, separate multiple by \",\"")
;
po::variables_map vm;
@@ -55,20 +57,35 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
uhd::property_tree::sptr tree = dev->get_tree();
std::cout << std::endl;
- if (true /*always readback*/){
- std::cout << "Fetching current settings from EEPROM..." << std::endl;
- uhd::usrp::mboard_eeprom_t mb_eeprom = tree->access<uhd::usrp::mboard_eeprom_t>("/mboards/0/eeprom").get();
- if (not mb_eeprom.has_key(key)){
- std::cerr << boost::format("Cannot find value for EEPROM[%s]") % key << std::endl;
+ //remove whitespace, split arguments and values
+ boost::algorithm::erase_all(key, " ");
+ boost::algorithm::erase_all(val, " ");
+
+ std::vector<std::string> keys_vec, vals_vec;
+ boost::split(keys_vec, key, boost::is_any_of("\"',"));
+ boost::split(vals_vec, val, boost::is_any_of("\"',"));
+
+ if((keys_vec.size() != vals_vec.size()) and val != "") {
+ //If zero values are given, then user just wants values read to them
+ throw std::runtime_error("Number of keys must match number of values!");
+ }
+
+ std::cout << "Fetching current settings from EEPROM..." << std::endl;
+ uhd::usrp::mboard_eeprom_t mb_eeprom = tree->access<uhd::usrp::mboard_eeprom_t>("/mboards/0/eeprom").get();
+ for(size_t i = 0; i < keys_vec.size(); i++){
+ if (not mb_eeprom.has_key(keys_vec[i])){
+ std::cerr << boost::format("Cannot find value for EEPROM[%s]") % keys_vec[i] << std::endl;
return EXIT_FAILURE;
}
- std::cout << boost::format(" EEPROM [\"%s\"] is \"%s\"") % key % mb_eeprom[key] << std::endl;
- std::cout << std::endl;
+ std::cout << boost::format(" EEPROM [\"%s\"] is \"%s\"") % keys_vec[i] % mb_eeprom[keys_vec[i]] << std::endl;
}
+ std::cout << std::endl;
if (vm.count("val")){
- uhd::usrp::mboard_eeprom_t mb_eeprom; mb_eeprom[key] = val;
- std::cout << boost::format("Setting EEPROM [\"%s\"] to \"%s\"...") % key % val << std::endl;
- tree->access<uhd::usrp::mboard_eeprom_t>("/mboards/0/eeprom").set(mb_eeprom);
+ for(size_t i = 0; i < vals_vec.size(); i++){
+ uhd::usrp::mboard_eeprom_t mb_eeprom; mb_eeprom[keys_vec[i]] = vals_vec[i];
+ std::cout << boost::format("Setting EEPROM [\"%s\"] to \"%s\"...") % keys_vec[i] % vals_vec[i] << std::endl;
+ tree->access<uhd::usrp::mboard_eeprom_t>("/mboards/0/eeprom").set(mb_eeprom);
+ }
std::cout << "Power-cycle the USRP device for the changes to take effect." << std::endl;
std::cout << std::endl;
}