diff options
author | Andrew Lynch <andrew.lynch@ni.com> | 2019-04-22 11:07:42 -0500 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2019-05-02 08:44:40 -0700 |
commit | 27f027c54f10defa1eda9e69e5ba6c1597d7b9e2 (patch) | |
tree | 43e06bc9c8ae7e837c71350bbdac00ba14fef253 /host/lib/usrp/mpmd/mpmd_image_loader.cpp | |
parent | 01fd6d52cefdb2baa7070b91ed483e9456141966 (diff) | |
download | uhd-27f027c54f10defa1eda9e69e5ba6c1597d7b9e2.tar.gz uhd-27f027c54f10defa1eda9e69e5ba6c1597d7b9e2.tar.bz2 uhd-27f027c54f10defa1eda9e69e5ba6c1597d7b9e2.zip |
utils: add support for directly updating components from image_loader
Diffstat (limited to 'host/lib/usrp/mpmd/mpmd_image_loader.cpp')
-rw-r--r-- | host/lib/usrp/mpmd/mpmd_image_loader.cpp | 167 |
1 files changed, 96 insertions, 71 deletions
diff --git a/host/lib/usrp/mpmd/mpmd_image_loader.cpp b/host/lib/usrp/mpmd/mpmd_image_loader.cpp index 7553b1df4..e0145bd4b 100644 --- a/host/lib/usrp/mpmd/mpmd_image_loader.cpp +++ b/host/lib/usrp/mpmd/mpmd_image_loader.cpp @@ -1,5 +1,6 @@ // // Copyright 2017 Ettus Research, a National Instruments Company +// Copyright 2019 Ettus Research, a National Instruments Brand // // SPDX-License-Identifier: GPL-3.0-or-later // @@ -79,6 +80,23 @@ uhd::usrp::component_file_t generate_component( } /* + * Helper function to generate a component_file_t using the input ID and contents. + */ +uhd::usrp::component_file_t generate_component(const std::string& id, + const std::vector<uint8_t>& contents, + const uhd::dict<std::string, std::string>& metadata) +{ + uhd::usrp::component_file_t component_file; + // Add an ID to the metadata + component_file.metadata["id"] = id; + component_file.metadata.update(metadata); + UHD_LOG_TRACE( + "MPMD IMAGE LOADER", "Component ID added to the component dictionary: " << id); + component_file.data = contents; + return component_file; +} + +/* * Function to be registered with uhd_image_loader */ static bool mpmd_image_loader(const image_loader::image_loader_args_t& image_loader_args) @@ -103,82 +121,89 @@ static bool mpmd_image_loader(const image_loader::image_loader_args_t& image_loa // Generate the component files uhd::usrp::component_files_t all_component_files; - // FPGA component struct - const auto fpga_path = [image_loader_args, dev_addr, tree]() -> std::string { - // If the user provided a path to an fpga image, use that - if (not image_loader_args.fpga_path.empty()) { - if (boost::filesystem::exists(image_loader_args.fpga_path)) { - return image_loader_args.fpga_path; - } else { - throw uhd::runtime_error( - str(boost::format("FPGA file provided does not exist: %s") - % image_loader_args.fpga_path)); - } - } - // Otherwise, we need to generate one - else { - /* - * The user can specify an FPGA type (HG, XG, AA), rather than a filename. If - * the user does not specify one, this will default to the type currently on - * the device. If this cannot be determined, then the user is forced to - * specify a filename. - */ - const auto fpga_type = [image_loader_args, tree]() -> std::string { - // If the user didn't provide a type, use the type of currently loaded - // image on the device - if (image_loader_args.args.has_key("fpga")) { - return image_loader_args.args.get("fpga"); - } else if (tree->exists("/mboards/0/components/fpga")) { - // Pull the FPGA info from the property tree - // The getter should return a vector of a single component_file_t, - // so grab the metadata from that - auto fpga_metadata = tree->access<uhd::usrp::component_files_t>( - "/mboards/0/components/fpga") - .get()[0] - .metadata; - return fpga_metadata.get("type", ""); - // TODO: Do we want to pull the type from the filename if its not - // available in the metadata directly? + // check if a component was provided + if (not image_loader_args.id.empty() && not image_loader_args.component.empty()) { + uhd::usrp::component_file_t component = generate_component(image_loader_args.id, + image_loader_args.component, + image_loader_args.metadata); + all_component_files.push_back(component); + } else { + // FPGA component struct + const auto fpga_path = [image_loader_args, dev_addr, tree]() -> std::string { + // If the user provided a path to an fpga image, use that + if (not image_loader_args.fpga_path.empty()) { + if (boost::filesystem::exists(image_loader_args.fpga_path)) { + return image_loader_args.fpga_path; + } else { + throw uhd::runtime_error( + str(boost::format("FPGA file provided does not exist: %s") + % image_loader_args.fpga_path)); } - return ""; - }(); // generate_fpga_type lambda function - UHD_LOG_TRACE("MPMD IMAGE LOADER", "FPGA type: " << fpga_type); + } + // Otherwise, we need to generate one + else { + /* + * The user can specify an FPGA type (HG, XG, AA), rather than a filename. + * If the user does not specify one, this will default to the type + * currently on the device. If this cannot be determined, then the user is + * forced to specify a filename. + */ + const auto fpga_type = [image_loader_args, tree]() -> std::string { + // If the user didn't provide a type, use the type of currently loaded + // image on the device + if (image_loader_args.args.has_key("fpga")) { + return image_loader_args.args.get("fpga"); + } else if (tree->exists("/mboards/0/components/fpga")) { + // Pull the FPGA info from the property tree + // The getter should return a vector of a single component_file_t, + // so grab the metadata from that + auto fpga_metadata = tree->access<uhd::usrp::component_files_t>( + "/mboards/0/components/fpga") + .get()[0] + .metadata; + return fpga_metadata.get("type", ""); + // TODO: Do we want to pull the type from the filename if its not + // available in the metadata directly? + } + return ""; + }(); // generate_fpga_type lambda function + UHD_LOG_TRACE("MPMD IMAGE LOADER", "FPGA type: " << fpga_type); - if (!dev_addr.has_key("product") or fpga_type == "") { - throw uhd::runtime_error( - "Found a device but could not auto-generate an image filename."); - } else { - return find_image_path( - str(boost::format("usrp_%s_fpga_%s.bit") - % (boost::algorithm::to_lower_copy(dev_addr["product"])) - % fpga_type)); + if (!dev_addr.has_key("product") or fpga_type == "") { + throw uhd::runtime_error( + "Found a device but could not auto-generate an image filename."); + } else { + return find_image_path( + str(boost::format("usrp_%s_fpga_%s.bit") + % (boost::algorithm::to_lower_copy(dev_addr["product"])) + % fpga_type)); + } } + }(); // generate_fpga_path lambda function + UHD_LOG_TRACE("MPMD IMAGE LOADER", "FPGA path: " << fpga_path); + uhd::usrp::component_file_t comp_fpga = generate_component("fpga", fpga_path); + all_component_files.push_back(comp_fpga); + // DTS component struct + // First, we need to determine the name + const std::string base_name = + boost::filesystem::change_extension(fpga_path, "").string(); + if (base_name == fpga_path) { + const std::string err_msg( + "Can't cut extension from FPGA filename... " + fpga_path); + throw uhd::runtime_error(err_msg); + } + const std::string dts_path = base_name + ".dts"; + // Then try to generate it + try { + uhd::usrp::component_file_t comp_dts = generate_component("dts", dts_path); + all_component_files.push_back(comp_dts); + UHD_LOG_TRACE("MPMD IMAGE LOADER", "FPGA and DTS images read from file."); + } catch (const uhd::runtime_error& ex) { + // If we can't find the DTS file, that's fine, continue without it + UHD_LOG_WARNING("MPMD IMAGE LOADER", ex.what()); + UHD_LOG_TRACE("MPMD IMAGE LOADER", "FPGA images read from file."); } - }(); // generate_fpga_path lambda function - UHD_LOG_TRACE("MPMD IMAGE LOADER", "FPGA path: " << fpga_path); - uhd::usrp::component_file_t comp_fpga = generate_component("fpga", fpga_path); - all_component_files.push_back(comp_fpga); - // DTS component struct - // First, we need to determine the name - const std::string base_name = - boost::filesystem::change_extension(fpga_path, "").string(); - if (base_name == fpga_path) { - const std::string err_msg( - "Can't cut extension from FPGA filename... " + fpga_path); - throw uhd::runtime_error(err_msg); - } - const std::string dts_path = base_name + ".dts"; - // Then try to generate it - try { - uhd::usrp::component_file_t comp_dts = generate_component("dts", dts_path); - all_component_files.push_back(comp_dts); - UHD_LOG_TRACE("MPMD IMAGE LOADER", "FPGA and DTS images read from file."); - } catch (const uhd::runtime_error& ex) { - // If we can't find the DTS file, that's fine, continue without it - UHD_LOG_WARNING("MPMD IMAGE LOADER", ex.what()); - UHD_LOG_TRACE("MPMD IMAGE LOADER", "FPGA images read from file."); } - // Call RPC to update the component UHD_LOG_INFO("MPMD IMAGE LOADER", "Starting update. This may take a while."); tree->access<uhd::usrp::component_files_t>("/mboards/0/components/fpga") |