blob: 3872b963389c25c35dc63ab1fca1b64b6948b801 [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
61void ItemUpdaterMMC::processPNORImage()
Brad Bishop8facccf2020-11-04 09:44:58 -050062{}
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -050063
64void ItemUpdaterMMC::reset()
Isaac Kurth0ddd4fa2021-07-14 17:35:37 -050065{
66 // Do not reset read-only files needed for reset or ext4 default files
Adriana Kobylakf9a72a72022-05-20 14:52:29 +000067 const std::vector<std::string> exclusionList = {"alternate", "hostfw-a",
68 "hostfw-b", "lost+found",
69 "nvram", "running-ro"};
Isaac Kurth0ddd4fa2021-07-14 17:35:37 -050070 std::filesystem::path dirPath(std::string(MEDIA_DIR "hostfw/"));
71 // Delete all files in /media/hostfw/ except for those on exclusionList
72 for (const auto& p : std::filesystem::directory_iterator(dirPath))
73 {
74 if (std::find(exclusionList.begin(), exclusionList.end(),
75 p.path().stem().string()) == exclusionList.end())
76 {
77 std::filesystem::remove_all(p);
78 }
79 }
80
Adriana Kobylak267c4132022-02-25 20:00:07 +000081 // Delete all BMC error logs to avoid discrepancies with the host error logs
82 utils::deleteAllErrorLogs(bus);
83
Adriana Kobylakf9a72a72022-05-20 14:52:29 +000084 // Set attribute to clear hypervisor NVRAM
85 utils::setClearNvram(bus);
86
Marri Devender Rao2b314972022-07-01 05:37:30 -050087 // reset the enabled property of dimms/cpu after factory reset
88 gardReset->reset();
89
Isaac Kurthbde5d7d2021-09-14 18:40:25 +000090 // Remove files related to the Hardware Management Console / BMC web app
Adriana Kobylak56a46772022-02-25 16:37:37 +000091 utils::clearHMCManaged(bus);
Isaac Kurthbde5d7d2021-09-14 18:40:25 +000092 std::filesystem::path consolePath("/var/lib/bmcweb/ibm-management-console");
93 if (std::filesystem::exists(consolePath))
94 {
95 std::filesystem::remove_all(consolePath);
96 }
Isaac Kurthbde5d7d2021-09-14 18:40:25 +000097 std::filesystem::path bmcdataPath("/home/root/bmcweb_persistent_data.json");
98 if (std::filesystem::exists(bmcdataPath))
99 {
100 std::filesystem::remove(bmcdataPath);
101 }
102
Isaac Kurth0ddd4fa2021-07-14 17:35:37 -0500103 // Recreate default files.
Ramesh Iyyar6b56bd42022-04-20 08:43:24 -0500104 // std::tuple<method, service_name>
105 const std::tuple<std::string, std::string> services[] = {
106 {"StartUnit", "obmc-flash-bios-init.service"},
107 {"StartUnit", "obmc-flash-bios-patch.service"},
108 {"StartUnit", "openpower-process-host-firmware.service"},
109 {"StartUnit", "openpower-update-bios-attr-table.service"},
Ramesh Iyyar6b56bd42022-04-20 08:43:24 -0500110 {"RestartUnit", "org.open_power.HardwareIsolation.service"}};
Isaac Kurthbde5d7d2021-09-14 18:40:25 +0000111
Isaac Kurthbde5d7d2021-09-14 18:40:25 +0000112 for (const auto& service : services)
113 {
114 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
Ramesh Iyyar6b56bd42022-04-20 08:43:24 -0500115 SYSTEMD_INTERFACE,
116 std::get<0>(service).c_str());
117 method.append(std::get<1>(service), "replace");
Isaac Kurthbde5d7d2021-09-14 18:40:25 +0000118 // Ignore errors if the service is not found - not all systems
119 // may have these services
120 try
121 {
122 bus.call_noreply(method);
123 }
124 catch (const std::exception& e)
125 {}
126 }
Adriana Kobylak295fce02022-06-13 15:11:49 +0000127
128 // Wait a few seconds for the service files and reset operations to finish,
129 // otherwise the BMC may be rebooted and cause corruption.
130 constexpr auto resetWait = std::chrono::seconds(5);
131 std::this_thread::sleep_for(resetWait);
Isaac Kurth0ddd4fa2021-07-14 17:35:37 -0500132}
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -0500133
134bool ItemUpdaterMMC::isVersionFunctional(const std::string& versionId)
135{
136 return versionId == functionalVersionId;
137}
138
Brad Bishopc8f22502020-11-06 14:42:09 -0500139void ItemUpdaterMMC::freePriority(uint8_t, const std::string&)
Brad Bishop8facccf2020-11-04 09:44:58 -0500140{}
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -0500141
142void ItemUpdaterMMC::deleteAll()
Brad Bishop8facccf2020-11-04 09:44:58 -0500143{}
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -0500144
145bool ItemUpdaterMMC::freeSpace()
146{
147 return true;
148}
149
Brad Bishopc8f22502020-11-06 14:42:09 -0500150void ItemUpdaterMMC::updateFunctionalAssociation(const std::string&)
Brad Bishop8facccf2020-11-04 09:44:58 -0500151{}
Marri Devender Rao2b314972022-07-01 05:37:30 -0500152void GardResetMMC::enableInventoryItems()
153{
154 (void)enableInventoryItemsHelper(
155 "xyz.openbmc_project.PLDM",
156 "xyz.openbmc_project.Inventory.Item.CpuCore",
157 "/xyz/openbmc_project/inventory/system/chassis/motherboard");
158
159 (void)enableInventoryItemsHelper("xyz.openbmc_project.Inventory.Manager",
160 "xyz.openbmc_project.Inventory.Item.Dimm",
161 "/xyz/openbmc_project/inventory");
162}
163
164void GardResetMMC::enableInventoryItemsHelper(const std::string& service,
165 const std::string& intf,
166 const std::string& objPath)
167{
168 const std::vector<std::string> intflist{intf};
169
170 std::vector<std::string> objs;
171 try
172 {
173 auto mapperCall = bus.new_method_call(
174 "xyz.openbmc_project.ObjectMapper",
175 "/xyz/openbmc_project/object_mapper",
176 "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths");
177 mapperCall.append(objPath);
178 mapperCall.append(0);
179 mapperCall.append(intflist);
180
181 auto response = bus.call(mapperCall);
182 response.read(objs);
183 for (auto& obj : objs)
184 {
185 auto method =
186 bus.new_method_call(service.c_str(), obj.c_str(),
187 "org.freedesktop.DBus.Properties", "Set");
188 std::variant<bool> propertyVal{true};
189 method.append("xyz.openbmc_project.Object.Enable", "Enabled",
190 propertyVal);
191 bus.call_noreply(method);
192 }
193 }
194 catch (const sdbusplus::exception_t& e)
195 {
196 log<level::ERR>(
197 fmt::format("Failed to enable specified inventory items ex({}) "
198 "intf({}) objpath({})",
199 e.what(), intf, objPath)
200 .c_str());
201 }
202}
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -0500203
204void GardResetMMC::reset()
Marri Devender Rao2b314972022-07-01 05:37:30 -0500205{
206 log<level::INFO>("GardResetMMC::reset");
207 (void)enableInventoryItems();
208}
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -0500209
210} // namespace updater
211} // namespace software
212} // namespace openpower