Skip to content

Commit

Permalink
mmc: Set clear NVRAM bios attribute during factory reset
Browse files Browse the repository at this point in the history
During factory reset, instead of calling the PLDM services to delete the
PHYP NVRAM files, set the pvm_clear_nvram bios attribute to Enabled to
signal the hypervisor to clear NVRAM when it starts up.

Add the nvram hostfw directory to the list of directories to preserve
during a factory reset because the NVRAM files would now be cleared by
the hypervisor after reading the bios attribute.

Tested: Verified the pvm_clar_nvram bios attribute was set to Enabled as
part of factory reset. Verified a journal error message was logged if
the attribute did not exist and the rest of the factory reset actions
were executed.

Change-Id: Ia3c0f707e8fb8208b5e2bc1edb9a8aef3bb36a89
Signed-off-by: Adriana Kobylak <[email protected]>
  • Loading branch information
anoo1 committed May 23, 2022
1 parent 8652eb9 commit f9a72a7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
13 changes: 6 additions & 7 deletions mmc/item_updater_mmc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ void ItemUpdaterMMC::processPNORImage()
void ItemUpdaterMMC::reset()
{
// Do not reset read-only files needed for reset or ext4 default files
const std::vector<std::string> exclusionList = {
"alternate", "hostfw-a", "hostfw-b", "lost+found", "running-ro"};
const std::vector<std::string> exclusionList = {"alternate", "hostfw-a",
"hostfw-b", "lost+found",
"nvram", "running-ro"};
std::filesystem::path dirPath(std::string(MEDIA_DIR "hostfw/"));
// Delete all files in /media/hostfw/ except for those on exclusionList
for (const auto& p : std::filesystem::directory_iterator(dirPath))
Expand All @@ -73,16 +74,16 @@ void ItemUpdaterMMC::reset()
// Delete all BMC error logs to avoid discrepancies with the host error logs
utils::deleteAllErrorLogs(bus);

// Remove files related to the Hardware Management Console / BMC web app
// Set attribute to clear hypervisor NVRAM
utils::setClearNvram(bus);

// Remove files related to the Hardware Management Console / BMC web app
utils::clearHMCManaged(bus);

std::filesystem::path consolePath("/var/lib/bmcweb/ibm-management-console");
if (std::filesystem::exists(consolePath))
{
std::filesystem::remove_all(consolePath);
}

std::filesystem::path bmcdataPath("/home/root/bmcweb_persistent_data.json");
if (std::filesystem::exists(bmcdataPath))
{
Expand All @@ -96,8 +97,6 @@ void ItemUpdaterMMC::reset()
{"StartUnit", "obmc-flash-bios-patch.service"},
{"StartUnit", "openpower-process-host-firmware.service"},
{"StartUnit", "openpower-update-bios-attr-table.service"},
{"StartUnit", "pldm-reset-phyp-nvram.service"},
{"StartUnit", "pldm-reset-phyp-nvram-cksum.service"},
{"RestartUnit", "org.open_power.HardwareIsolation.service"}};

for (const auto& service : services)
Expand Down
21 changes: 16 additions & 5 deletions utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,19 @@ void hiomapdResume(sdbusplus::bus::bus& bus)
}
}

void clearHMCManaged(sdbusplus::bus::bus& bus)
void setPendingAttributes(sdbusplus::bus::bus& bus, const std::string& attrName,
const std::string& attrValue)
{
constexpr auto biosConfigPath = "/xyz/openbmc_project/bios_config/manager";
constexpr auto biosConfigIntf = "xyz.openbmc_project.BIOSConfig.Manager";
constexpr auto dbusAttrType =
"xyz.openbmc_project.BIOSConfig.Manager.AttributeType.Enumeration";
constexpr auto dbusAttrName = "pvm_hmc_managed";

using PendingAttributesType = std::vector<std::pair<
std::string, std::tuple<std::string, std::variant<std::string>>>>;
PendingAttributesType pendingAttributes;
pendingAttributes.emplace_back(std::make_pair(
dbusAttrName, std::make_tuple(dbusAttrType, "Disabled")));
pendingAttributes.emplace_back(
std::make_pair(attrName, std::make_tuple(dbusAttrType, attrValue)));

try
{
Expand All @@ -139,11 +139,22 @@ void clearHMCManaged(sdbusplus::bus::bus& bus)
{
log<level::ERR>("Error setting the bios attribute",
entry("ERROR=%s", e.what()),
entry("ATTRIBUTE=%s", dbusAttrName));
entry("ATTRIBUTE=%s", attrName.c_str()),
entry("ATTRIBUTE_VALUE=%s", attrValue.c_str()));
return;
}
}

void clearHMCManaged(sdbusplus::bus::bus& bus)
{
setPendingAttributes(bus, "pvm_hmc_managed", "Disabled");
}

void setClearNvram(sdbusplus::bus::bus& bus)
{
setPendingAttributes(bus, "pvm_clear_nvram", "Enabled");
}

void deleteAllErrorLogs(sdbusplus::bus::bus& bus)
{
constexpr auto loggingPath = "/xyz/openbmc_project/logging";
Expand Down
7 changes: 7 additions & 0 deletions utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ void hiomapdResume(sdbusplus::bus::bus& bus);
*/
void clearHMCManaged(sdbusplus::bus::bus& bus);

/** @brief Set the Clear hypervisor NVRAM bios attribute to Enabled to indicate
* to the hypervisor to clear its NVRAM.
*
* @param[in] bus - The D-Bus bus object.
*/
void setClearNvram(sdbusplus::bus::bus& bus);

/** @brief DeleteAll error logs
*
* @param[in] bus - The D-Bus bus object.
Expand Down

0 comments on commit f9a72a7

Please sign in to comment.