aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib
diff options
context:
space:
mode:
authorNicholas Corgan <nick.corgan@ettus.com>2015-12-14 07:27:38 -0800
committerMartin Braun <martin.braun@ettus.com>2015-12-14 13:26:45 -0800
commit373fec2fb177c50b40733445633a10b01fe62cc5 (patch)
tree6b5a4fdd025b08a66ad4d673d34137ef330e1125 /host/lib
parent87860fc3226c8915cb45a4fc39d5e64bf667470d (diff)
downloaduhd-373fec2fb177c50b40733445633a10b01fe62cc5.tar.gz
uhd-373fec2fb177c50b40733445633a10b01fe62cc5.tar.bz2
uhd-373fec2fb177c50b40733445633a10b01fe62cc5.zip
ihex: Windows fixes
Diffstat (limited to 'host/lib')
-rw-r--r--host/lib/usrp_clock/octoclock/octoclock_image_loader.cpp17
-rw-r--r--host/lib/utils/ihex.cpp4
2 files changed, 10 insertions, 11 deletions
diff --git a/host/lib/usrp_clock/octoclock/octoclock_image_loader.cpp b/host/lib/usrp_clock/octoclock/octoclock_image_loader.cpp
index 1d4699f54..fdb254024 100644
--- a/host/lib/usrp_clock/octoclock/octoclock_image_loader.cpp
+++ b/host/lib/usrp_clock/octoclock/octoclock_image_loader.cpp
@@ -79,20 +79,18 @@ static void octoclock_calculate_crc(octoclock_session_t &session){
static void octoclock_read_bin(octoclock_session_t &session)
{
- std::ifstream bin_file(session.image_filepath.c_str());
+ std::ifstream bin_file(session.image_filepath.c_str(), std::ios::in | std::ios::binary);
if (not bin_file.is_open()) {
throw uhd::io_error("Could not read image file.");
}
size_t filesize = fs::file_size(session.image_filepath);
session.image.clear();
- session.image.reserve(filesize);
-
- std::copy(
- std::istream_iterator<boost::uint8_t>(bin_file),
- std::istream_iterator<boost::uint8_t>(),
- std::back_inserter(session.image)
- );
+ session.image.resize(filesize);
+ bin_file.read((char*)&session.image[0], filesize);
+ if(size_t(bin_file.gcount()) != filesize) {
+ throw uhd::io_error("Failed to read firmware image.");
+ }
bin_file.close();
}
@@ -111,7 +109,8 @@ static void octoclock_validate_firmware_image(octoclock_session_t &session){
ihex_reader hex_reader(session.image_filepath);
session.image = hex_reader.to_vector(OCTOCLOCK_FIRMWARE_MAX_SIZE_BYTES);
}
- else throw uhd::runtime_error(str(boost::format("Invalid extension \"%s\". Extension must be .hex or .bin.")));
+ else throw uhd::runtime_error(str(boost::format("Invalid extension \"%s\". Extension must be .hex or .bin.")
+ % extension));
if(session.image.size() > OCTOCLOCK_FIRMWARE_MAX_SIZE_BYTES){
throw uhd::runtime_error(str(boost::format("The specified firmware image is too large: %d vs. %d")
diff --git a/host/lib/utils/ihex.cpp b/host/lib/utils/ihex.cpp
index bb9b49b32..a29ac3e72 100644
--- a/host/lib/utils/ihex.cpp
+++ b/host/lib/utils/ihex.cpp
@@ -213,7 +213,7 @@ void ihex_reader::to_bin_file(const std::string &bin_filename)
// We need a functor for the cast, a lambda would be perfect...
int _vector_writer_callback(
- std::vector<boost::uint8_t> vector,
+ std::vector<boost::uint8_t>& vector,
unsigned char *buff,
boost::uint16_t len
) {
@@ -229,7 +229,7 @@ std::vector<boost::uint8_t> ihex_reader::to_vector(const size_t size_estimate)
std::vector<boost::uint8_t> buf;
buf.reserve(size_estimate == 0 ? DEFAULT_SIZE_ESTIMATE : size_estimate);
- this->read(boost::bind(&_vector_writer_callback, buf, _3, _4));
+ this->read(boost::bind(&_vector_writer_callback, boost::ref(buf), _3, _4));
return buf;
}