Skip to content

Commit

Permalink
item_updater_mmc: Implement bios factory reset
Browse files Browse the repository at this point in the history
Implemented the method ItemUpdaterMMC::reset. It clears files in
/media/hostfw/ related to managing console and virtualization
information, then recreates those files using bus calls to service
files. Added checks to obmc-flash-bios so it doesn't cause problems
when its methods are run multiple times. Modified latest services to
allow them to run more than once. Services which depend on the init
service will run after it.

Tested: Created extra files in the directories that the reset method
removes. Called the reset method using busctl. Verified that the
added files were removed and that the removed files that belong were
recreated. Verified that all services called were run.

Signed-off-by: Isaac Kurth <[email protected]>
Change-Id: I1e04e97a7c5c9e3fa8b5ee7af47b7320ff3e91d3
  • Loading branch information
IsaacPK authored and anoo1 committed Sep 8, 2021
1 parent 7b5685d commit 0ddd4fa
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 8 deletions.
44 changes: 43 additions & 1 deletion mmc/item_updater_mmc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "activation_mmc.hpp"
#include "version.hpp"

#include <filesystem>

namespace openpower
{
namespace software
Expand Down Expand Up @@ -51,7 +53,47 @@ 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"};
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))
{
if (std::find(exclusionList.begin(), exclusionList.end(),
p.path().stem().string()) == exclusionList.end())
{
std::filesystem::remove_all(p);
}
}

// Recreate default files.
auto bus = sdbusplus::bus::new_default();
constexpr auto initService = "obmc-flash-bios-init.service";
auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
SYSTEMD_INTERFACE, "StartUnit");
method.append(initService, "replace");
bus.call_noreply(method);

constexpr auto patchService = "obmc-flash-bios-patch.service";
method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
SYSTEMD_INTERFACE, "StartUnit");
method.append(patchService, "replace");
bus.call_noreply(method);

constexpr auto processService = "openpower-process-host-firmware.service";
method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
SYSTEMD_INTERFACE, "StartUnit");
method.append(processService, "replace");
bus.call_noreply(method);

constexpr auto updateService = "openpower-update-bios-attr-table.service";
method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
SYSTEMD_INTERFACE, "StartUnit");
method.append(updateService, "replace");
bus.call_noreply(method);
}

bool ItemUpdaterMMC::isVersionFunctional(const std::string& versionId)
{
Expand Down
20 changes: 15 additions & 5 deletions mmc/obmc-flash-bios
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ mmc_init() {
# Mount the image that corresponds to the boot label as read-only to be used
# to populate the running directory.
boot_label="$(fw_printenv -n bootside)"
mount ${base_dir}/hostfw-"${boot_label}" ${ro_dir} -o ro
if ! grep -q "${ro_dir}" /proc/mounts; then
mount ${base_dir}/hostfw-"${boot_label}" ${ro_dir} -o ro
fi

# Determine if the running dir contains the running version
running_label=""
Expand Down Expand Up @@ -71,7 +73,9 @@ mmc_init() {
if [ ! -d "${alternate_dir}" ]; then
mkdir -p ${alternate_dir}
fi
mount ${base_dir}/hostfw-${alternate_label} ${alternate_dir} -o ro
if ! grep -q "${alternate_dir}" /proc/mounts; then
mount ${base_dir}/hostfw-${alternate_label} ${alternate_dir} -o ro
fi
}

mmc_patch() {
Expand Down Expand Up @@ -108,9 +112,15 @@ mmc_patch() {
mkdir -p "${hostfw_symlink_base}"
fi

ln -s "${running_patch_dir}" "${symlink_base}/pnor"
ln -s "${running_patch_dir}" "${hostfw_symlink_base}/running"
ln -s "${alternate_patch_dir}" "${hostfw_symlink_base}/alternate"
if [ "$(readlink -f "${symlink_base}/pnor")" != "${running_patch_dir}" ]; then
ln -s "${running_patch_dir}" "${symlink_base}/pnor"
fi
if [ "$(readlink -f "${hostfw_symlink_base}/running")" != "${running_patch_dir}" ]; then
ln -s "${running_patch_dir}" "${hostfw_symlink_base}/running"
fi
if [ "$(readlink -f "${hostfw_symlink_base}/alternate")" != "${alternate_patch_dir}" ]; then
ln -s "${alternate_patch_dir}" "${hostfw_symlink_base}/alternate"
fi
}

case "$1" in
Expand Down
2 changes: 1 addition & 1 deletion mmc/openpower-process-host-firmware.service
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ After=obmc-flash-bios-init.service

[Service]
Type=oneshot
RemainAfterExit=yes
RemainAfterExit=no
ExecStart=/usr/bin/openpower-update-manager process-host-firmware

[Install]
Expand Down
3 changes: 2 additions & 1 deletion mmc/openpower-update-bios-attr-table.service
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[Unit]
Description=Update BIOS attr table with host firmware well-known names
After=org.open_power.Software.Host.Updater.service
After=obmc-flash-bios-init.service

[Service]
Type=oneshot
RemainAfterExit=yes
RemainAfterExit=no
ExecStart=/usr/bin/openpower-update-manager update-bios-attr-table

[Install]
Expand Down

0 comments on commit 0ddd4fa

Please sign in to comment.