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