diff --git a/debugger/debugger.cpp b/debugger/debugger.cpp index eee710c..9613783 100644 --- a/debugger/debugger.cpp +++ b/debugger/debugger.cpp @@ -377,7 +377,6 @@ void enter_debugger() { size_t separator_pos; unique_ptr ofnvram = unique_ptr(new OfNvramUtils); - ofnvram->init(); context = 1; /* start with the PowerPC context */ @@ -578,11 +577,15 @@ void enter_debugger() { } #endif } else if (cmd == "printenv") { + if (ofnvram->init()) + continue; ofnvram->printenv(); } else if (cmd == "setenv") { string var_name, value; ss >> var_name; ss >> value; + if (ofnvram->init()) + continue; ofnvram->setenv(var_name, value); } else { cout << "Unknown command: " << cmd << endl; diff --git a/devices/common/ofnvram.cpp b/devices/common/ofnvram.cpp index ffb083d..dcd5e71 100644 --- a/devices/common/ofnvram.cpp +++ b/devices/common/ofnvram.cpp @@ -37,9 +37,10 @@ along with this program. If not, see . using namespace std; -void OfNvramUtils::init() +int OfNvramUtils::init() { this->nvram_obj = dynamic_cast(gMachineObj->get_comp_by_name("NVRAM")); + return this->nvram_obj == nullptr; } bool OfNvramUtils::validate() diff --git a/devices/common/ofnvram.h b/devices/common/ofnvram.h index 47ecd9b..fc47d0b 100644 --- a/devices/common/ofnvram.h +++ b/devices/common/ofnvram.h @@ -49,7 +49,7 @@ public: OfNvramUtils() = default; ~OfNvramUtils() = default; - void init(); + int init(); void printenv(); void setenv(std::string var_name, std::string value);