diff options
-rw-r--r-- | host/lib/usrp_clock/octoclock/octoclock_image_loader.cpp | 17 | ||||
-rw-r--r-- | host/lib/utils/ihex.cpp | 4 | ||||
-rw-r--r-- | host/utils/CMakeLists.txt | 1 |
3 files changed, 10 insertions, 12 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; } diff --git a/host/utils/CMakeLists.txt b/host/utils/CMakeLists.txt index 8367c0184..28fecc895 100644 --- a/host/utils/CMakeLists.txt +++ b/host/utils/CMakeLists.txt @@ -87,7 +87,6 @@ IF(ENABLE_OCTOCLOCK) ${CMAKE_SOURCE_DIR}/lib/utils/ihex.cpp ) - ADD_DEFINITIONS(-DIHEX_USE_STDBOOL) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/lib/usrp_clock/octoclock) ADD_EXECUTABLE(octoclock_firmware_burner ${octoclock_burner_sources}) TARGET_LINK_LIBRARIES(octoclock_firmware_burner uhd ${Boost_LIBRARIES}) |