aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicholas Corgan <nick.corgan@ettus.com>2012-06-07 12:30:21 -0700
committerJosh Blum <josh@joshknows.com>2012-06-07 15:05:41 -0700
commite7df63844f0920d35bc76a9fe70f9bbb59443c2f (patch)
tree63cff49610a8f03c2168f7144e662662bb843392
parent49d4f8e479534d856a242c2271d1b930487aea6c (diff)
downloaduhd-e7df63844f0920d35bc76a9fe70f9bbb59443c2f.tar.gz
uhd-e7df63844f0920d35bc76a9fe70f9bbb59443c2f.tar.bz2
uhd-e7df63844f0920d35bc76a9fe70f9bbb59443c2f.zip
utils: UHD Image Downloader - downloads firmware/FPGA images compatible with the current host code and places them in the images directory
-rw-r--r--host/CMakeLists.txt7
-rw-r--r--host/include/uhd/utils/images.hpp17
-rw-r--r--host/lib/usrp/b100/b100_impl.cpp16
-rw-r--r--host/lib/usrp/usrp1/usrp1_impl.cpp6
-rw-r--r--host/lib/usrp/usrp2/usrp2_iface.cpp24
-rw-r--r--host/lib/utils/images.cpp18
-rw-r--r--host/utils/CMakeLists.txt13
-rw-r--r--host/utils/uhd_images_downloader.py95
-rw-r--r--images/CMakeLists.txt2
9 files changed, 170 insertions, 28 deletions
diff --git a/host/CMakeLists.txt b/host/CMakeLists.txt
index f14c0bd7c..8b55fa170 100644
--- a/host/CMakeLists.txt
+++ b/host/CMakeLists.txt
@@ -192,6 +192,12 @@ INSTALL(FILES
)
########################################################################
+# Images download directory for utils/uhd_images_downloader.py
+########################################################################
+
+SET(UHD_IMAGES_DOWNLOAD_SRC "http://files.ettus.com/binaries/master_images/archive/uhd-images_003.004.001-109-g6ca39ad9.zip")
+
+########################################################################
# Register top level components
########################################################################
LIBUHD_REGISTER_COMPONENT("LibUHD" ENABLE_LIBUHD ON "Boost_FOUND;HAVE_PYTHON_PLAT_MIN_VERSION;HAVE_PYTHON_MODULE_CHEETAH" OFF)
@@ -275,3 +281,4 @@ ENDIF(DEFINED UHD_IMAGES_DIR AND EXISTS "${UHD_IMAGES_DIR}")
UHD_PRINT_COMPONENT_SUMMARY()
MESSAGE(STATUS "Building version: ${UHD_VERSION}")
MESSAGE(STATUS "Using install prefix: ${CMAKE_INSTALL_PREFIX}")
+MESSAGE(STATUS "Compatible images can be downloaded from: ${UHD_IMAGES_DOWNLOAD_SRC}")
diff --git a/host/include/uhd/utils/images.hpp b/host/include/uhd/utils/images.hpp
index 8b5a1eedd..a0934fb08 100644
--- a/host/include/uhd/utils/images.hpp
+++ b/host/include/uhd/utils/images.hpp
@@ -1,5 +1,5 @@
//
-// Copyright 2010 Ettus Research LLC
+// Copyright 2010,2012 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
@@ -33,6 +33,21 @@ namespace uhd{
*/
UHD_API std::string find_image_path(const std::string &image_name);
+ /*!
+ * Search for the location of the UHD Images Downloader script.
+ * \return the full system path to uhd_images_downloader.py
+ */
+
+ UHD_API std::string find_images_downloader(void);
+
+ /*!
+ * Return the error string for recommending using the UHD Images Downloader.
+ * String depends on OS.
+ * \return the message suggesting the use of uhd_images_downloader.py
+ */
+
+ UHD_API std::string print_images_error(void);
+
} //namespace uhd
#endif /* INCLUDED_UHD_UTILS_IMAGES_HPP */
diff --git a/host/lib/usrp/b100/b100_impl.cpp b/host/lib/usrp/b100/b100_impl.cpp
index b1d828cf1..eec777842 100644
--- a/host/lib/usrp/b100/b100_impl.cpp
+++ b/host/lib/usrp/b100/b100_impl.cpp
@@ -35,6 +35,7 @@
#include <boost/lexical_cast.hpp>
#include "b100_regs.hpp"
#include <cstdio>
+#include <iostream>
using namespace uhd;
using namespace uhd::usrp;
@@ -85,13 +86,10 @@ static device_addrs_t b100_find(const device_addr_t &hint)
b100_fw_image = find_image_path(hint.get("fw", B100_FW_FILE_NAME));
}
catch(...){
- UHD_MSG(warning) << boost::format(
- "Could not locate B100 firmware.\n"
- "Please install the images package.\n"
- );
+ UHD_MSG(warning) << boost::format("Could not locate B100 firmware. %s\n") % print_images_error();
return b100_addrs;
}
- UHD_LOG << "the firmware image: " << b100_fw_image << std::endl;
+ UHD_LOG << "the firmware image: " << b100_fw_image << std::endl;
usb_control::sptr control;
try{control = usb_control::make(handle, 0);}
@@ -497,8 +495,9 @@ void b100_impl::check_fw_compat(void){
if (fw_compat_num != B100_FW_COMPAT_NUM){
throw uhd::runtime_error(str(boost::format(
"Expected firmware compatibility number 0x%x, but got 0x%x:\n"
- "The firmware build is not compatible with the host code build."
- ) % B100_FW_COMPAT_NUM % fw_compat_num));
+ "The firmware build is not compatible with the host code build.\n"
+ "%s"
+ ) % B100_FW_COMPAT_NUM % fw_compat_num % print_images_error()));
}
}
@@ -513,7 +512,8 @@ void b100_impl::check_fpga_compat(void){
throw uhd::runtime_error(str(boost::format(
"Expected FPGA compatibility number %d, but got %d:\n"
"The FPGA build is not compatible with the host code build."
- ) % int(B100_FPGA_COMPAT_NUM) % fpga_major));
+ "%s"
+ ) % int(B100_FPGA_COMPAT_NUM) % fpga_major % print_images_error()));
}
_tree->create<std::string>("/mboards/0/fpga_version").set(str(boost::format("%u.%u") % fpga_major % fpga_minor));
}
diff --git a/host/lib/usrp/usrp1/usrp1_impl.cpp b/host/lib/usrp/usrp1/usrp1_impl.cpp
index f1c11a492..ffe25b81e 100644
--- a/host/lib/usrp/usrp1/usrp1_impl.cpp
+++ b/host/lib/usrp/usrp1/usrp1_impl.cpp
@@ -89,11 +89,7 @@ static device_addrs_t usrp1_find(const device_addr_t &hint)
usrp1_fw_image = find_image_path(hint.get("fw", "usrp1_fw.ihx"));
}
catch(...){
- UHD_MSG(warning) << boost::format(
- "Could not locate USRP1 firmware.\n"
- "Please install the images package.\n"
- );
- return usrp1_addrs;
+ UHD_MSG(warning) << boost::format("Could not locate USRP1 firmware. %s") % print_images_error();
}
UHD_LOG << "USRP1 firmware image: " << usrp1_fw_image << std::endl;
diff --git a/host/lib/usrp/usrp2/usrp2_iface.cpp b/host/lib/usrp/usrp2/usrp2_iface.cpp
index a05710891..7c26e2e71 100644
--- a/host/lib/usrp/usrp2/usrp2_iface.cpp
+++ b/host/lib/usrp/usrp2/usrp2_iface.cpp
@@ -376,6 +376,13 @@ public:
}
if (fw_image.empty() or fpga_image.empty()) return "";
+ //does your platform use sudo?
+ std::string sudo;
+ #if defined(UHD_PLATFORM_LINUX) || defined(UHD_PLATFORM_MACOS)
+ sudo = "sudo ";
+ #endif
+
+
//look up the real FS path to the images
std::string fw_image_path, fpga_image_path;
try{
@@ -383,15 +390,9 @@ public:
fpga_image_path = uhd::find_image_path(fpga_image);
}
catch(const std::exception &){
- return str(boost::format("Could not find %s and %s in your images path!") % fw_image % fpga_image);
+ return str(boost::format("Could not find %s and %s in your images path!\n%s") % fw_image % fpga_image % print_images_error());
}
- //does your platform use sudo?
- std::string sudo;
- #if defined(UHD_PLATFORM_LINUX) || defined(UHD_PLATFORM_MACOS)
- sudo = "sudo";
- #endif
-
//escape char for multi-line cmd + newline + indent?
#ifdef UHD_PLATFORM_WIN32
const std::string ml = "^\n ";
@@ -399,15 +400,18 @@ public:
const std::string ml = "\\\n ";
#endif
- //create the burner command
+ //create the images downloader and burner commands
+ const std::string images_downloader_cmd = str(boost::format("%s\"%s\"") % sudo % find_images_downloader());
if (this->get_rev() == USRP2_REV3 or this->get_rev() == USRP2_REV4){
const std::string card_burner = (fs::path(fw_image_path).branch_path().branch_path() / "utils" / "usrp2_card_burner_gui.py").string();
- return str(boost::format("Please run:\n%s \"%s\" %s--fpga=\"%s\" %s--fw=\"%s\"") % sudo % card_burner % ml % fpga_image_path % ml % fw_image_path);
+ const std::string card_burner_cmd = str(boost::format("\"%s%s\" %s--fpga=\"%s\" %s--fw=\"%s\"") % sudo % card_burner % ml % fpga_image_path % ml % fw_image_path);
+ return str(boost::format("%s\n%s") % print_images_error() % card_burner_cmd);
}
else{
const std::string addr = _ctrl_transport->get_recv_addr();
const std::string net_burner = (fs::path(fw_image_path).branch_path().branch_path() / "utils" / "usrp_n2xx_net_burner_gui.py").string();
- return str(boost::format("Please run:\n\"%s\" %s--fpga=\"%s\" %s--fw=\"%s\" %s--addr=\"%s\"") % net_burner % ml % fpga_image_path % ml % fw_image_path % ml % addr);
+ const std::string net_burner_cmd = str(boost::format("\"%s\" %s--fpga=\"%s\" %s--fw=\"%s\" %s--addr=\"%s\"") % net_burner % ml % fpga_image_path % ml % fw_image_path % ml % addr);
+ return str(boost::format("%s\n%s") % print_images_error() % net_burner_cmd);
}
}
diff --git a/host/lib/utils/images.cpp b/host/lib/utils/images.cpp
index a124cc208..654e31179 100644
--- a/host/lib/utils/images.cpp
+++ b/host/lib/utils/images.cpp
@@ -1,5 +1,5 @@
//
-// Copyright 2010-2011 Ettus Research LLC
+// Copyright 2010-2012 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
@@ -17,16 +17,18 @@
#include <uhd/utils/images.hpp>
#include <uhd/exception.hpp>
+#include <uhd/utils/paths.hpp>
#include <boost/foreach.hpp>
#include <boost/filesystem.hpp>
#include <vector>
+#include <iostream>
namespace fs = boost::filesystem;
std::vector<fs::path> get_image_paths(void); //defined in paths.cpp
/***********************************************************************
- * Find a image in the image paths
+ * Find an image in the image paths
**********************************************************************/
std::string uhd::find_image_path(const std::string &image_name){
if (fs::exists(image_name)){
@@ -38,3 +40,15 @@ std::string uhd::find_image_path(const std::string &image_name){
}
throw uhd::io_error("Could not find path for image: " + image_name);
}
+
+std::string uhd::find_images_downloader(void){
+ return fs::path((fs::path(get_pkg_data_path()) / "utils" / "uhd_images_downloader.py")).string();
+}
+
+std::string uhd::print_images_error(void){
+ #ifdef UHD_PLATFORM_WIN32
+ return "As an Administrator, please run:\n\n\"" + find_images_downloader() + "\"";
+ #else
+ return "Please run:\n\nsudo \"" + find_images_downloader() + "\"";
+ #endif
+}
diff --git a/host/utils/CMakeLists.txt b/host/utils/CMakeLists.txt
index 0ecd6b4e7..8ddab035b 100644
--- a/host/utils/CMakeLists.txt
+++ b/host/utils/CMakeLists.txt
@@ -1,5 +1,5 @@
#
-# Copyright 2010-2011 Ettus Research LLC
+# Copyright 2010-2012 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
@@ -64,6 +64,17 @@ FOREACH(util_source ${util_share_sources})
INSTALL(TARGETS ${util_name} RUNTIME DESTINATION ${PKG_LIB_DIR}/utils COMPONENT utilities)
ENDFOREACH(util_source)
+#UHD images downloader configuration
+CONFIGURE_FILE(
+ ${CMAKE_CURRENT_SOURCE_DIR}/uhd_images_downloader.py
+ ${CMAKE_CURRENT_BINARY_DIR}/uhd_images_downloader.py
+@ONLY)
+INSTALL(PROGRAMS
+ ${CMAKE_CURRENT_BINARY_DIR}/uhd_images_downloader.py
+ DESTINATION ${PKG_LIB_DIR}/utils
+ COMPONENT utilities
+)
+
IF(ENABLE_USRP2)
IF(WIN32 AND UHD_RELEASE_MODE) #include dd.exe
FILE(DOWNLOAD
diff --git a/host/utils/uhd_images_downloader.py b/host/utils/uhd_images_downloader.py
new file mode 100644
index 000000000..be76f5b2d
--- /dev/null
+++ b/host/utils/uhd_images_downloader.py
@@ -0,0 +1,95 @@
+#!/usr/bin/env python
+#
+# Copyright 2012 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/>.
+#
+
+from optparse import OptionParser
+import os
+import os.path
+import shutil
+import sys
+import urllib2
+import zipfile
+
+if __name__ == "__main__":
+
+ #Command line options
+ parser = OptionParser()
+ parser.add_option("--download-location", type="string", default="@CMAKE_INSTALL_PREFIX@/share/uhd/images", help="Set custom download location for images, [default=%default]")
+ parser.add_option("--buffer-size", type="int", default=8192, help="Set download buffer size, [default=%default]",)
+ (options, args) = parser.parse_args()
+
+ #Configuring image download info
+ images_src = "@UHD_IMAGES_DOWNLOAD_SRC@"
+ filename = images_src.split("/")[-1]
+
+ #Configuring image destination
+ cmake_install_prefix = "@CMAKE_INSTALL_PREFIX@"
+ if options.download_location != "":
+ images_dir = options.download_location
+ else:
+ images_dir = "@CMAKE_INSTALL_PREFIX@/share/uhd/images"
+
+ u = urllib2.urlopen(images_src)
+ f = open(filename, "wb")
+ meta = u.info()
+ #filesize = int(meta.getheaders("Content-Length")[0])
+ filesize = float(int(meta.getheaders("Content-Length")[0]))
+
+ print "Downloading images from: %s" % images_src
+
+ filesize_dl = 0.0
+
+ #Downloading file
+ while True:
+ buffer = u.read(options.buffer_size)
+ if not buffer:
+ break
+
+ filesize_dl -= len(buffer)
+ f.write(buffer)
+
+ status = r"%2.2f MB/%2.2f MB (%3.2f" % (-filesize_dl/1e6, filesize/1e6, (-filesize_dl*100.)/filesize) + r"%)"
+ status += chr(8)*(len(status)+1)
+ print status,
+
+ f.close()
+
+ #Extracting contents of zip file
+ if os.path.exists("tempdir"):
+ shutil.rmtree("tempdir")
+ os.mkdir("tempdir")
+
+ images_zip = zipfile.ZipFile(filename)
+ images_zip.extractall("tempdir")
+
+ #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)
+
+ #Copying downloaded images into images_dir
+ shutil.copytree("tempdir/%s/share/uhd/images" % filename[:-4],images_dir)
+
+ #Removing tempdir and zip file
+ shutil.rmtree("tempdir")
+ images_zip.close()
+ os.remove(filename)
+
+ print "\nImages successfully installed to: %s" % images_dir
diff --git a/images/CMakeLists.txt b/images/CMakeLists.txt
index a59568ef4..9a05f11f5 100644
--- a/images/CMakeLists.txt
+++ b/images/CMakeLists.txt
@@ -1,5 +1,5 @@
#
-# Copyright 2010-2011 Ettus Research LLC
+# Copyright 2010-2012 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