diff options
| author | Lei YU <mine260309@gmail.com> | 2019-02-25 17:49:29 +0800 |
|---|---|---|
| committer | Lei YU <mine260309@gmail.com> | 2019-03-13 11:01:53 +0800 |
| commit | a7b4adee12a944d3d937fdf05c56ed58a1cd3cf9 (patch) | |
| tree | 64dc037907b1f627963fe4a7904a09af40b23121 | |
| parent | 5efca58658279f78bcc73282d3f3134a395ce68d (diff) | |
| download | openpower-pnor-code-mgmt-a7b4adee12a944d3d937fdf05c56ed58a1cd3cf9.tar.gz openpower-pnor-code-mgmt-a7b4adee12a944d3d937fdf05c56ed58a1cd3cf9.zip | |
Static layout: Implement factory reset
Tested: Verify the partitions hard-coded are cleared during factory
reset.
Change-Id: I70febe5f8245a299d4e2a782414662dbf09e84cb
Signed-off-by: Lei YU <mine260309@gmail.com>
| -rw-r--r-- | static/item_updater_static.cpp | 84 |
1 files changed, 74 insertions, 10 deletions
diff --git a/static/item_updater_static.cpp b/static/item_updater_static.cpp index 6ab1f9178..023425507 100644 --- a/static/item_updater_static.cpp +++ b/static/item_updater_static.cpp @@ -5,6 +5,7 @@ #include "activation_static.hpp" #include "version.hpp" +#include <array> #include <cstring> #include <filesystem> #include <fstream> @@ -113,6 +114,24 @@ std::string getPNORVersion() return version; } +inline void pnorClear(const std::string& part, bool shouldEcc = true) +{ + int rc; + std::tie(rc, std::ignore) = + pflash("-P", part, shouldEcc ? "-c" : "-e", "-f >/dev/null"); + if (rc != 0) + { + log<level::ERR>("Failed to clear partition", + entry("PART=%s", part.c_str()), + entry("RETURNCODE=%d", rc)); + } + else + { + log<level::INFO>("Clear partition successfully", + entry("PART=%s", part.c_str())); + } +} + } // namespace utils namespace openpower @@ -223,6 +242,60 @@ void ItemUpdaterStatic::processPNORImage() void ItemUpdaterStatic::reset() { + // The pair contains the partition name and if it should use ECC clear + using PartClear = std::pair<const char*, bool>; + constexpr std::array<PartClear, 11> partitions = {{ + {"HBEL", true}, + {"GUARD", true}, + {"NVRAM", false}, + {"DJVPD", true}, + {"MVPD", true}, + {"CVPD", true}, + {"FIRDATA", true}, + {"BMC_INV", false}, + {"ATTR_TMP", false}, + {"ATTR_PERM", true}, + {"HB_VOLATILE", true}, + }}; + + std::vector<uint8_t> mboxdArgs; + + // Suspend mboxd - no args required. + auto dbusCall = bus.new_method_call(MBOXD_INTERFACE, MBOXD_PATH, + MBOXD_INTERFACE, "cmd"); + dbusCall.append(static_cast<uint8_t>(3), mboxdArgs); + + try + { + bus.call_noreply(dbusCall); + } + catch (const SdBusError& e) + { + log<level::ERR>("Error in mboxd suspend call", + entry("ERROR=%s", e.what())); + elog<InternalFailure>(); + } + for (auto p : partitions) + { + utils::pnorClear(p.first, p.second); + } + + // Resume mboxd with arg 1, indicating that the flash was modified. + dbusCall = bus.new_method_call(MBOXD_INTERFACE, MBOXD_PATH, MBOXD_INTERFACE, + "cmd"); + mboxdArgs.push_back(1); + dbusCall.append(static_cast<uint8_t>(4), mboxdArgs); + + try + { + bus.call_noreply(dbusCall); + } + catch (const SdBusError& e) + { + log<level::ERR>("Error in mboxd resume call", + entry("ERROR=%s", e.what())); + elog<InternalFailure>(); + } } bool ItemUpdaterStatic::isVersionFunctional(const std::string& versionId) @@ -267,7 +340,6 @@ void GardReset::reset() { // Clear gard partition std::vector<uint8_t> mboxdArgs; - int rc; auto dbusCall = bus.new_method_call(MBOXD_INTERFACE, MBOXD_PATH, MBOXD_INTERFACE, "cmd"); @@ -286,15 +358,7 @@ void GardReset::reset() } // Clear guard partition - std::tie(rc, std::ignore) = utils::pflash("-P GUARD -c -f >/dev/null"); - if (rc != 0) - { - log<level::ERR>("Failed to clear GUARD", entry("RETURNCODE=%d", rc)); - } - else - { - log<level::INFO>("Clear GUARD successfully"); - } + utils::pnorClear("GUARD"); dbusCall = bus.new_method_call(MBOXD_INTERFACE, MBOXD_PATH, MBOXD_INTERFACE, "cmd"); |

