aboutsummaryrefslogtreecommitdiffstats
path: root/host/utils
diff options
context:
space:
mode:
authorMarcus Müller <marcus.mueller@ettus.com>2017-01-17 16:10:19 +0100
committerMartin Braun <martin.braun@ettus.com>2017-01-26 16:22:49 +0100
commit207903d343f6cb520d86e62c2ebee2e847546f7b (patch)
tree93829595a7d16f9ab1418e8ae7431002aa849e84 /host/utils
parent4eb9ab0be83f9cf1c677120eeb7165152201848a (diff)
downloaduhd-207903d343f6cb520d86e62c2ebee2e847546f7b.tar.gz
uhd-207903d343f6cb520d86e62c2ebee2e847546f7b.tar.bz2
uhd-207903d343f6cb520d86e62c2ebee2e847546f7b.zip
made fx2_init_eeprom capable of using built-in images
Diffstat (limited to 'host/utils')
-rw-r--r--host/utils/fx2_init_eeprom.cpp53
1 files changed, 46 insertions, 7 deletions
diff --git a/host/utils/fx2_init_eeprom.cpp b/host/utils/fx2_init_eeprom.cpp
index cf7fb2de2..e0915d9f2 100644
--- a/host/utils/fx2_init_eeprom.cpp
+++ b/host/utils/fx2_init_eeprom.cpp
@@ -20,11 +20,13 @@
#include <uhd/property_tree.hpp>
#include <boost/program_options.hpp>
#include <boost/format.hpp>
+#include <boost/filesystem.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <iostream>
-//#include <cstdlib>
-#ifdef UHD_PLATFORM_LINUX
#include <fstream>
+#include "usrp1_eeprom.h"
+#include "b100_eeprom.h"
+#ifdef UHD_PLATFORM_LINUX
#include <unistd.h> // syscall constants
#include <fcntl.h> // O_NONBLOCK
#include <sys/syscall.h>
@@ -39,13 +41,14 @@ namespace po = boost::program_options;
int UHD_SAFE_MAIN(int argc, char *argv[]){
std::string type;
+ std::string image;
po::options_description desc("Allowed options");
desc.add_options()
("help", "help message")
- ("image", po::value<std::string>(), "BIN image file")
+ ("image", po::value<std::string>(), "BIN image file; if not specified, use built-in image")
("vid", po::value<std::string>(), "VID of device to program")
("pid", po::value<std::string>(), "PID of device to program")
- ("type", po::value<std::string>(), "device type (usrp1 or b100)")
+ ("type", po::value<std::string>(&type), "device type (usrp1 or b100, required if using built-in image)")
;
po::variables_map vm;
@@ -78,9 +81,9 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
//load the options into the address
uhd::device_addr_t device_addr;
device_addr["type"] = type;
- if(vm.count("vid") or vm.count("pid") or vm.count("type")) {
+ if(vm.count("vid") or vm.count("pid")) {
if(not (vm.count("vid") and vm.count("pid") and vm.count("type"))) {
- std::cerr << "ERROR: Must specify vid, pid, and type if specifying any of the three args" << std::endl;
+ std::cerr << "ERROR: Must specify vid, pid, and type if specifying any of the two former args" << std::endl;
} else {
device_addr["vid"] = vm["vid"].as<std::string>();
device_addr["pid"] = vm["pid"].as<std::string>();
@@ -90,6 +93,38 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
device_addr["vid"] = FX2_VENDOR_ID;
device_addr["pid"] = FX2_PRODUCT_ID;
}
+ if(vm.count("image")) {
+ //if specified, use external image file
+ image = vm["image"].as<std::string>();
+ } else {
+ //if not specified, use built-ins; requires user to define type
+ size_t image_len;
+ unsigned const char* image_data;
+
+ if(!vm.count("type")) {
+ std::cerr << boost::format("ERROR: Image file not specified and type of device not given. Cannot use built-in images.\n");
+ return EXIT_FAILURE;
+ }
+
+ std::cout << boost::format("Using built-in image for \"%s\".\n") % type;
+
+ if(vm["type"].as<std::string>() == "usrp1") {
+ image_len = usrp1_eeprom_bin_len;
+ image_data = usrp1_eeprom_bin;
+ } else if(vm["type"].as<std::string>() == "b100") {
+ image_len = b100_eeprom_bin_len;
+ image_data = b100_eeprom_bin;
+ } else {
+ std::cerr << boost::format("ERROR: Unsupported device type \"%s\" specified and no EEPROM image file given.\n") % type;
+ return EXIT_FAILURE;
+ }
+
+ //get temporary file name, and write image to that.
+ image = boost::filesystem::unique_path().string();
+ std::ofstream tmp_image(image, std::ofstream::binary);
+ tmp_image.write((const char*)image_data, image_len);
+ tmp_image.close();
+ }
//find and create a control transport to do the writing.
@@ -105,9 +140,13 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
//uhd::device_addrs_t devs = uhd::device::find(found_addrs[i]);
uhd::device::sptr dev = uhd::device::make(found_addrs[i], uhd::device::USRP);
uhd::property_tree::sptr tree = dev->get_tree();
- tree->access<std::string>("/mboards/0/load_eeprom").set(vm["image"].as<std::string>());
+ tree->access<std::string>("/mboards/0/load_eeprom").set(image);
}
+ //delete temporary image file if we created one
+ if(!vm.count("image")) {
+ boost::filesystem::remove(image);
+ }
std::cout << "Power-cycle the usrp for the changes to take effect." << std::endl;
return EXIT_SUCCESS;