diff --git a/fpga/include/villas/fpga/pcie_card.hpp b/fpga/include/villas/fpga/pcie_card.hpp index e29ddee70..6e7153d56 100644 --- a/fpga/include/villas/fpga/pcie_card.hpp +++ b/fpga/include/villas/fpga/pcie_card.hpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -78,8 +79,10 @@ protected: class PCIeCardFactory : public plugin::Plugin { public: - static - std::list> make(json_t *json, std::shared_ptr pci, std::shared_ptr vc); + static std::list> make(json_t *json, + std::shared_ptr pci, + std::shared_ptr vc, + const std::filesystem::path& searchPath = std::filesystem::path()); static PCIeCard* make() diff --git a/fpga/lib/pcie_card.cpp b/fpga/lib/pcie_card.cpp index 31fb1ca8d..2df19dd0d 100644 --- a/fpga/lib/pcie_card.cpp +++ b/fpga/lib/pcie_card.cpp @@ -27,7 +27,10 @@ static PCIeCardFactory PCIeCardFactoryInstance; static const kernel::pci::Device defaultFilter((kernel::pci::Id(FPGA_PCI_VID_XILINX, FPGA_PCI_PID_VFPGA))); -std::list> PCIeCardFactory::make(json_t *json, std::shared_ptr pci, std::shared_ptr vc) +std::list> PCIeCardFactory::make(json_t *json, + std::shared_ptr pci, + std::shared_ptr vc, + const std::filesystem::path& searchPath) { std::list> cards; auto logger = getStaticLogger(); @@ -87,11 +90,19 @@ std::list> PCIeCardFactory::make(json_t *json, std::sh } // Load IPs from a separate json file - if (json_is_string(json_ips)) { - auto json_ips_fn = json_string_value(json_ips); - json_ips = json_load_file(json_ips_fn, 0, nullptr); - if (json_ips == nullptr) - throw ConfigError(json_ips, "node-config-fpga-ips", "Failed to load FPGA IP cores from {}", json_ips_fn); + if (json_is_string(json_ips) && !searchPath.empty()) { + std::filesystem::path json_ips_path = searchPath / json_string_value(json_ips); + json_ips = json_load_file(json_ips_path.c_str(), 0, nullptr); + if (json_ips == nullptr) { + logger->debug("FPGA IP cores config not found in {} looking elsewhere...", json_ips_path); + } + } + if (json_is_string(json_ips) && json_ips == nullptr) { + json_ips = json_load_file(json_string_value(json_ips), 0, nullptr); + if (json_ips == nullptr) { + logger->debug("FPGA IP cores config not found in {}", json_string_value(json_ips)); + throw ConfigError(json_ips, "node-config-fpga-ips", "Failed to find FPGA IP cores config"); + } } if (not json_is_object(json_ips)) diff --git a/fpga/lib/utils.cpp b/fpga/lib/utils.cpp index 763a68739..11e786797 100644 --- a/fpga/lib/utils.cpp +++ b/fpga/lib/utils.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -168,6 +169,7 @@ fpga::setupFpgaCard(const std::string &configFile, const std::string &fpgaName) pciDevices = std::make_shared(); auto vfioContainer = std::make_shared(); + auto configDir = std::filesystem::path(configFile).parent_path(); // Parse FPGA configuration FILE* f = fopen(configFile.c_str(), "r");