From 700e41150f19b92283137302b1dc6443c7811fb8 Mon Sep 17 00:00:00 2001 From: Aaron Nyholm Date: Mon, 15 Jul 2024 10:23:28 +1000 Subject: [PATCH] P16-1166 : Optionally disable default fw path * Users can now disable the default firmware search path by setting the environment variable PIXIE_DISABLE_SYSTEM_FIRMWARE to a true value. --- sdk/include/pixie/utils/string.hpp | 7 +++++++ sdk/src/pixie/fw.cpp | 14 ++++++++++++-- sdk/src/pixie/utils/string.cpp | 6 ++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/sdk/include/pixie/utils/string.hpp b/sdk/include/pixie/utils/string.hpp index 69fa79fc..84adf4ba 100644 --- a/sdk/include/pixie/utils/string.hpp +++ b/sdk/include/pixie/utils/string.hpp @@ -140,6 +140,13 @@ bool check_number(const std::string& s); */ bool check_number_range(const std::string& s); +/** + * @brief Check if a string is an affirmative value. + * @param[in] s the string that we'll check. + * @return @true if the string is affirmative else @false + */ +bool check_affirmative(const std::string& s); + /** * @brief Token editor splits a string by a token separator allowing * you to add, edit or remove tokens. You can export the list as a diff --git a/sdk/src/pixie/fw.cpp b/sdk/src/pixie/fw.cpp index effa8ec5..4fbb62d0 100644 --- a/sdk/src/pixie/fw.cpp +++ b/sdk/src/pixie/fw.cpp @@ -1340,8 +1340,18 @@ void load_system_firmwares(system& firmwares) { if (sys_fw_path_env != nullptr) { system_firmware_path = sys_fw_path_env; } - xia_log(log::info) << "firmware: system: loading from " << system_firmware_path; - load_firmwares(firmwares, system_firmware_path, true); + auto disable_sys_fw_env = std::getenv("PIXIE_DISABLE_SYSTEM_FIRMWARE"); + bool disable_sys_fw = false; + if (disable_sys_fw_env != NULL) { + std::string s(disable_sys_fw_env); + disable_sys_fw = util::string::check_affirmative(s); + } + if (!disable_sys_fw) { + xia_log(log::info) << "firmware: system: loading from " << system_firmware_path; + load_firmwares(firmwares, system_firmware_path, true); + } else { + xia_log(log::info) << "firmware: system: disabled"; + } } void load_firmwares(system& firmwares, const std::string path, bool ignore_error) { diff --git a/sdk/src/pixie/utils/string.cpp b/sdk/src/pixie/utils/string.cpp index 76e05d34..9483ff85 100644 --- a/sdk/src/pixie/utils/string.cpp +++ b/sdk/src/pixie/utils/string.cpp @@ -123,6 +123,12 @@ bool check_number_range(const std::string& s) { throw std::runtime_error("invalid range: " + s); } +bool check_affirmative(const std::string& s) { + std::string e(s); + util::string::tolower(e); + return (e == "true" || e == "t" || e == "yes" || e == "y" || e == "1"); +} + token_editor::token_editor(const std::string& str, char separator_, bool sort_) : separator(separator_), sorted(sort_) { set(str);