blob: 75ef2849e6bdd680994793bb52f12838e5904c76 [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
Marri Devender Rao2b314972022-07-01 05:37:30 -05009#include <fmt/core.h>
10
11#include <phosphor-logging/log.hpp>
12
Isaac Kurth0ddd4fa2021-07-14 17:35:37 -050013#include <filesystem>
Isaac Kurthbde5d7d2021-09-14 18:40:25 +000014#include <iostream>
Adriana Kobylak295fce02022-06-13 15:11:49 +000015#include <thread>
Isaac Kurth0ddd4fa2021-07-14 17:35:37 -050016
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -050017namespace openpower
18{
19namespace software
20{
21namespace updater
22{
23
Marri Devender Rao2b314972022-07-01 05:37:30 -050024using ::phosphor::logging::level;
25using ::phosphor::logging::log;
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -050026// These functions are just a stub (empty) because the current eMMC
27// implementation uses the BMC updater (repo phosphor-bmc-code-mgmt) to write
28// the new host FW to flash since it's delivered as a "System" image in the
29// same BMC tarball as the BMC image.
30
31std::unique_ptr<Activation> ItemUpdaterMMC::createActivationObject(
32 const std::string& path, const std::string& versionId,
33 const std::string& extVersion,
34 sdbusplus::xyz::openbmc_project::Software::server::Activation::Activations
35 activationStatus,
36 AssociationList& assocs)
37{
38 return std::make_unique<ActivationMMC>(
39 bus, path, *this, versionId, extVersion, activationStatus, assocs);
40}
41
42std::unique_ptr<Version> ItemUpdaterMMC::createVersionObject(
43 const std::string& objPath, const std::string& versionId,
44 const std::string& versionString,
45 sdbusplus::xyz::openbmc_project::Software::server::Version::VersionPurpose
46 versionPurpose,
47 const std::string& filePath)
48{
49 auto version = std::make_unique<Version>(
50 bus, objPath, *this, versionId, versionString, versionPurpose, filePath,
51 std::bind(&ItemUpdaterMMC::erase, this, std::placeholders::_1));
52 version->deleteObject = std::make_unique<Delete>(bus, objPath, *version);
53 return version;
54}
55
Brad Bishopc8f22502020-11-06 14:42:09 -050056bool ItemUpdaterMMC::validateImage(const std::string&)
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -050057{
58 return true;
59}
60
Patrick Williams7fb6c342023-05-10 07:50:18 -050061void ItemUpdaterMMC::processPNORImage() {}
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -050062
63void ItemUpdaterMMC::reset()
Isaac Kurth0ddd4fa2021-07-14 17:35:37 -050064{
65 // Do not reset read-only files needed for reset or ext4 default files
Adriana Kobylakf9a72a72022-05-20 14:52:29 +000066 const std::vector<std::string> exclusionList = {"alternate", "hostfw-a",
67 "hostfw-b", "lost+found",
68 "nvram", "running-ro"};
Isaac Kurth0ddd4fa2021-07-14 17:35:37 -050069 std::filesystem::path dirPath(std::string(MEDIA_DIR "hostfw/"));
70 // Delete all files in /media/hostfw/ except for those on exclusionList
71 for (const auto& p : std::filesystem::directory_iterator(dirPath))
72 {
73 if (std::find(exclusionList.begin(), exclusionList.end(),
74 p.path().stem().string()) == exclusionList.end())
75 {
76 std::filesystem::remove_all(p);
77 }
78 }
79
Adriana Kobylak267c4132022-02-25 20:00:07 +000080 // Delete all BMC error logs to avoid discrepancies with the host error logs
81 utils::deleteAllErrorLogs(bus);
82
Adriana Kobylakf9a72a72022-05-20 14:52:29 +000083 // Set attribute to clear hypervisor NVRAM
84 utils::setClearNvram(bus);
85
Marri Devender Rao2b314972022-07-01 05:37:30 -050086 // reset the enabled property of dimms/cpu after factory reset
87 gardReset->reset();
88
Isaac Kurthbde5d7d2021-09-14 18:40:25 +000089 // Remove files related to the Hardware Management Console / BMC web app
Adriana Kobylak56a46772022-02-25 16:37:37 +000090 utils::clearHMCManaged(bus);
Isaac Kurthbde5d7d2021-09-14 18:40:25 +000091 std::filesystem::path consolePath("/var/lib/bmcweb/ibm-management-console");
92 if (std::filesystem::exists(consolePath))
93 {
94 std::filesystem::remove_all(consolePath);
95 }
Isaac Kurthbde5d7d2021-09-14 18:40:25 +000096 std::filesystem::path bmcdataPath("/home/root/bmcweb_persistent_data.json");
97 if (std::filesystem::exists(bmcdataPath))
98 {
99 std::filesystem::remove(bmcdataPath);
100 }
101
Isaac Kurth0ddd4fa2021-07-14 17:35:37 -0500102 // Recreate default files.
Ramesh Iyyar6b56bd42022-04-20 08:43:24 -0500103 // std::tuple<method, service_name>
104 const std::tuple<std::string, std::string> services[] = {
105 {"StartUnit", "obmc-flash-bios-init.service"},
106 {"StartUnit", "obmc-flash-bios-patch.service"},
107 {"StartUnit", "openpower-process-host-firmware.service"},
108 {"StartUnit", "openpower-update-bios-attr-table.service"},
Ramesh Iyyar6b56bd42022-04-20 08:43:24 -0500109 {"RestartUnit", "org.open_power.HardwareIsolation.service"}};
Isaac Kurthbde5d7d2021-09-14 18:40:25 +0000110
Isaac Kurthbde5d7d2021-09-14 18:40:25 +0000111 for (const auto& service : services)
112 {
113 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
Ramesh Iyyar6b56bd42022-04-20 08:43:24 -0500114 SYSTEMD_INTERFACE,
115 std::get<0>(service).c_str());
116 method.append(std::get<1>(service), "replace");
Isaac Kurthbde5d7d2021-09-14 18:40:25 +0000117 // Ignore errors if the service is not found - not all systems
118 // may have these services
119 try
120 {
121 bus.call_noreply(method);
122 }
123 catch (const std::exception& e)
124 {}
125 }
Adriana Kobylak295fce02022-06-13 15:11:49 +0000126
127 // Wait a few seconds for the service files and reset operations to finish,
128 // otherwise the BMC may be rebooted and cause corruption.
129 constexpr auto resetWait = std::chrono::seconds(5);
130 std::this_thread::sleep_for(resetWait);
Isaac Kurth0ddd4fa2021-07-14 17:35:37 -0500131}
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -0500132
133bool ItemUpdaterMMC::isVersionFunctional(const std::string& versionId)
134{
135 return versionId == functionalVersionId;
136}
137
Patrick Williams7fb6c342023-05-10 07:50:18 -0500138void ItemUpdaterMMC::freePriority(uint8_t, const std::string&) {}
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -0500139
Patrick Williams7fb6c342023-05-10 07:50:18 -0500140void ItemUpdaterMMC::deleteAll() {}
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -0500141
142bool ItemUpdaterMMC::freeSpace()
143{
144 return true;
145}
146
Patrick Williams7fb6c342023-05-10 07:50:18 -0500147void ItemUpdaterMMC::updateFunctionalAssociation(const std::string&) {}
Marri Devender Rao2b314972022-07-01 05:37:30 -0500148void GardResetMMC::enableInventoryItems()
149{
150 (void)enableInventoryItemsHelper(
151 "xyz.openbmc_project.PLDM",
152 "xyz.openbmc_project.Inventory.Item.CpuCore",
153 "/xyz/openbmc_project/inventory/system/chassis/motherboard");
154
155 (void)enableInventoryItemsHelper("xyz.openbmc_project.Inventory.Manager",
156 "xyz.openbmc_project.Inventory.Item.Dimm",
157 "/xyz/openbmc_project/inventory");
158}
159
160void GardResetMMC::enableInventoryItemsHelper(const std::string& service,
161 const std::string& intf,
162 const std::string& objPath)
163{
164 const std::vector<std::string> intflist{intf};
165
166 std::vector<std::string> objs;
167 try
168 {
169 auto mapperCall = bus.new_method_call(
170 "xyz.openbmc_project.ObjectMapper",
171 "/xyz/openbmc_project/object_mapper",
172 "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths");
173 mapperCall.append(objPath);
174 mapperCall.append(0);
175 mapperCall.append(intflist);
176
177 auto response = bus.call(mapperCall);
178 response.read(objs);
179 for (auto& obj : objs)
180 {
Patrick Williams7fb6c342023-05-10 07:50:18 -0500181 auto method = bus.new_method_call(service.c_str(), obj.c_str(),
182 "org.freedesktop.DBus.Properties",
183 "Set");
Marri Devender Rao2b314972022-07-01 05:37:30 -0500184 std::variant<bool> propertyVal{true};
185 method.append("xyz.openbmc_project.Object.Enable", "Enabled",
186 propertyVal);
187 bus.call_noreply(method);
188 }
189 }
190 catch (const sdbusplus::exception_t& e)
191 {
192 log<level::ERR>(
193 fmt::format("Failed to enable specified inventory items ex({}) "
194 "intf({}) objpath({})",
195 e.what(), intf, objPath)
196 .c_str());
197 }
198}
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -0500199
200void GardResetMMC::reset()
Marri Devender Rao2b314972022-07-01 05:37:30 -0500201{
202 log<level::INFO>("GardResetMMC::reset");
203 (void)enableInventoryItems();
204}
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -0500205
206} // namespace updater
207} // namespace software
208} // namespace openpower