Skip to content

Commit

Permalink
P16-1166 : Optionally disable default fw path
Browse files Browse the repository at this point in the history
* Users can now disable the default firmware search path
  by setting the environment variable PIXIE_DISABLE_SYSTEM_FIRMWARE
  to a true value.
  • Loading branch information
eagleirony authored and xia-ethan committed Jul 16, 2024
1 parent 6ce9ab4 commit 700e411
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
7 changes: 7 additions & 0 deletions sdk/include/pixie/utils/string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions sdk/src/pixie/fw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions sdk/src/pixie/utils/string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 700e411

Please sign in to comment.