blob: c99a3c4cd4dc471bf12469633a3fc7eb7f016d0b [file] [log] [blame]
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -05001#include "config.h"
2
3#include "item_updater_mmc.hpp"
4
5#include "activation_mmc.hpp"
Adriana Kobylak56a46772022-02-25 16:37:37 +00006#include "utils.hpp"
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -05007#include "version.hpp"
8
Isaac Kurth0ddd4fa2021-07-14 17:35:37 -05009#include <filesystem>
Isaac Kurthbde5d7d2021-09-14 18:40:25 +000010#include <iostream>
Adriana Kobylak295fce02022-06-13 15:11:49 +000011#include <thread>
Isaac Kurth0ddd4fa2021-07-14 17:35:37 -050012
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -050013namespace openpower
14{
15namespace software
16{
17namespace updater
18{
19
20// These functions are just a stub (empty) because the current eMMC
21// implementation uses the BMC updater (repo phosphor-bmc-code-mgmt) to write
22// the new host FW to flash since it's delivered as a "System" image in the
23// same BMC tarball as the BMC image.
24
25std::unique_ptr<Activation> ItemUpdaterMMC::createActivationObject(
26 const std::string& path, const std::string& versionId,
27 const std::string& extVersion,
28 sdbusplus::xyz::openbmc_project::Software::server::Activation::Activations
29 activationStatus,
30 AssociationList& assocs)
31{
32 return std::make_unique<ActivationMMC>(
33 bus, path, *this, versionId, extVersion, activationStatus, assocs);
34}
35
36std::unique_ptr<Version> ItemUpdaterMMC::createVersionObject(
37 const std::string& objPath, const std::string& versionId,
38 const std::string& versionString,
39 sdbusplus::xyz::openbmc_project::Software::server::Version::VersionPurpose
40 versionPurpose,
41 const std::string& filePath)
42{
43 auto version = std::make_unique<Version>(
44 bus, objPath, *this, versionId, versionString, versionPurpose, filePath,
45 std::bind(&ItemUpdaterMMC::erase, this, std::placeholders::_1));
46 version->deleteObject = std::make_unique<Delete>(bus, objPath, *version);
47 return version;
48}
49
Brad Bishopc8f22502020-11-06 14:42:09 -050050bool ItemUpdaterMMC::validateImage(const std::string&)
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -050051{
52 return true;
53}
54
55void ItemUpdaterMMC::processPNORImage()
Brad Bishop8facccf2020-11-04 09:44:58 -050056{}
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -050057
58void ItemUpdaterMMC::reset()
Isaac Kurth0ddd4fa2021-07-14 17:35:37 -050059{
60 // Do not reset read-only files needed for reset or ext4 default files
Adriana Kobylakf9a72a72022-05-20 14:52:29 +000061 const std::vector<std::string> exclusionList = {"alternate", "hostfw-a",
62 "hostfw-b", "lost+found",
63 "nvram", "running-ro"};
Isaac Kurth0ddd4fa2021-07-14 17:35:37 -050064 std::filesystem::path dirPath(std::string(MEDIA_DIR "hostfw/"));
65 // Delete all files in /media/hostfw/ except for those on exclusionList
66 for (const auto& p : std::filesystem::directory_iterator(dirPath))
67 {
68 if (std::find(exclusionList.begin(), exclusionList.end(),
69 p.path().stem().string()) == exclusionList.end())
70 {
71 std::filesystem::remove_all(p);
72 }
73 }
74
Adriana Kobylak267c4132022-02-25 20:00:07 +000075 // Delete all BMC error logs to avoid discrepancies with the host error logs
76 utils::deleteAllErrorLogs(bus);
77
Adriana Kobylakf9a72a72022-05-20 14:52:29 +000078 // Set attribute to clear hypervisor NVRAM
79 utils::setClearNvram(bus);
80
Isaac Kurthbde5d7d2021-09-14 18:40:25 +000081 // Remove files related to the Hardware Management Console / BMC web app
Adriana Kobylak56a46772022-02-25 16:37:37 +000082 utils::clearHMCManaged(bus);
Isaac Kurthbde5d7d2021-09-14 18:40:25 +000083 std::filesystem::path consolePath("/var/lib/bmcweb/ibm-management-console");
84 if (std::filesystem::exists(consolePath))
85 {
86 std::filesystem::remove_all(consolePath);
87 }
Isaac Kurthbde5d7d2021-09-14 18:40:25 +000088 std::filesystem::path bmcdataPath("/home/root/bmcweb_persistent_data.json");
89 if (std::filesystem::exists(bmcdataPath))
90 {
91 std::filesystem::remove(bmcdataPath);
92 }
93
Isaac Kurth0ddd4fa2021-07-14 17:35:37 -050094 // Recreate default files.
Ramesh Iyyar6b56bd42022-04-20 08:43:24 -050095 // std::tuple<method, service_name>
96 const std::tuple<std::string, std::string> services[] = {
97 {"StartUnit", "obmc-flash-bios-init.service"},
98 {"StartUnit", "obmc-flash-bios-patch.service"},
99 {"StartUnit", "openpower-process-host-firmware.service"},
100 {"StartUnit", "openpower-update-bios-attr-table.service"},
Ramesh Iyyar6b56bd42022-04-20 08:43:24 -0500101 {"RestartUnit", "org.open_power.HardwareIsolation.service"}};
Isaac Kurthbde5d7d2021-09-14 18:40:25 +0000102
Isaac Kurthbde5d7d2021-09-14 18:40:25 +0000103 for (const auto& service : services)
104 {
105 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
Ramesh Iyyar6b56bd42022-04-20 08:43:24 -0500106 SYSTEMD_INTERFACE,
107 std::get<0>(service).c_str());
108 method.append(std::get<1>(service), "replace");
Isaac Kurthbde5d7d2021-09-14 18:40:25 +0000109 // Ignore errors if the service is not found - not all systems
110 // may have these services
111 try
112 {
113 bus.call_noreply(method);
114 }
115 catch (const std::exception& e)
116 {}
117 }
Adriana Kobylak295fce02022-06-13 15:11:49 +0000118
119 // Wait a few seconds for the service files and reset operations to finish,
120 // otherwise the BMC may be rebooted and cause corruption.
121 constexpr auto resetWait = std::chrono::seconds(5);
122 std::this_thread::sleep_for(resetWait);
Isaac Kurth0ddd4fa2021-07-14 17:35:37 -0500123}
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -0500124
125bool ItemUpdaterMMC::isVersionFunctional(const std::string& versionId)
126{
127 return versionId == functionalVersionId;
128}
129
Brad Bishopc8f22502020-11-06 14:42:09 -0500130void ItemUpdaterMMC::freePriority(uint8_t, const std::string&)
Brad Bishop8facccf2020-11-04 09:44:58 -0500131{}
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -0500132
133void ItemUpdaterMMC::deleteAll()
Brad Bishop8facccf2020-11-04 09:44:58 -0500134{}
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -0500135
136bool ItemUpdaterMMC::freeSpace()
137{
138 return true;
139}
140
Brad Bishopc8f22502020-11-06 14:42:09 -0500141void ItemUpdaterMMC::updateFunctionalAssociation(const std::string&)
Brad Bishop8facccf2020-11-04 09:44:58 -0500142{}
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -0500143
144void GardResetMMC::reset()
Brad Bishop8facccf2020-11-04 09:44:58 -0500145{}
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -0500146
147} // namespace updater
148} // namespace software
149} // namespace openpower