blob: 2b8330558d545ad2e6ed4798f7669ee844304367 [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>
Isaac Kurth0ddd4fa2021-07-14 17:35:37 -050011
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -050012namespace openpower
13{
14namespace software
15{
16namespace updater
17{
18
19// These functions are just a stub (empty) because the current eMMC
20// implementation uses the BMC updater (repo phosphor-bmc-code-mgmt) to write
21// the new host FW to flash since it's delivered as a "System" image in the
22// same BMC tarball as the BMC image.
23
24std::unique_ptr<Activation> ItemUpdaterMMC::createActivationObject(
25 const std::string& path, const std::string& versionId,
26 const std::string& extVersion,
27 sdbusplus::xyz::openbmc_project::Software::server::Activation::Activations
28 activationStatus,
29 AssociationList& assocs)
30{
31 return std::make_unique<ActivationMMC>(
32 bus, path, *this, versionId, extVersion, activationStatus, assocs);
33}
34
35std::unique_ptr<Version> ItemUpdaterMMC::createVersionObject(
36 const std::string& objPath, const std::string& versionId,
37 const std::string& versionString,
38 sdbusplus::xyz::openbmc_project::Software::server::Version::VersionPurpose
39 versionPurpose,
40 const std::string& filePath)
41{
42 auto version = std::make_unique<Version>(
43 bus, objPath, *this, versionId, versionString, versionPurpose, filePath,
44 std::bind(&ItemUpdaterMMC::erase, this, std::placeholders::_1));
45 version->deleteObject = std::make_unique<Delete>(bus, objPath, *version);
46 return version;
47}
48
Brad Bishopc8f22502020-11-06 14:42:09 -050049bool ItemUpdaterMMC::validateImage(const std::string&)
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -050050{
51 return true;
52}
53
54void ItemUpdaterMMC::processPNORImage()
Brad Bishop8facccf2020-11-04 09:44:58 -050055{}
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -050056
57void ItemUpdaterMMC::reset()
Isaac Kurth0ddd4fa2021-07-14 17:35:37 -050058{
59 // Do not reset read-only files needed for reset or ext4 default files
Adriana Kobylakf9a72a72022-05-20 14:52:29 +000060 const std::vector<std::string> exclusionList = {"alternate", "hostfw-a",
61 "hostfw-b", "lost+found",
62 "nvram", "running-ro"};
Isaac Kurth0ddd4fa2021-07-14 17:35:37 -050063 std::filesystem::path dirPath(std::string(MEDIA_DIR "hostfw/"));
64 // Delete all files in /media/hostfw/ except for those on exclusionList
65 for (const auto& p : std::filesystem::directory_iterator(dirPath))
66 {
67 if (std::find(exclusionList.begin(), exclusionList.end(),
68 p.path().stem().string()) == exclusionList.end())
69 {
70 std::filesystem::remove_all(p);
71 }
72 }
73
Adriana Kobylak267c4132022-02-25 20:00:07 +000074 // Delete all BMC error logs to avoid discrepancies with the host error logs
75 utils::deleteAllErrorLogs(bus);
76
Adriana Kobylakf9a72a72022-05-20 14:52:29 +000077 // Set attribute to clear hypervisor NVRAM
78 utils::setClearNvram(bus);
79
Isaac Kurthbde5d7d2021-09-14 18:40:25 +000080 // Remove files related to the Hardware Management Console / BMC web app
Adriana Kobylak56a46772022-02-25 16:37:37 +000081 utils::clearHMCManaged(bus);
Isaac Kurthbde5d7d2021-09-14 18:40:25 +000082 std::filesystem::path consolePath("/var/lib/bmcweb/ibm-management-console");
83 if (std::filesystem::exists(consolePath))
84 {
85 std::filesystem::remove_all(consolePath);
86 }
Isaac Kurthbde5d7d2021-09-14 18:40:25 +000087 std::filesystem::path bmcdataPath("/home/root/bmcweb_persistent_data.json");
88 if (std::filesystem::exists(bmcdataPath))
89 {
90 std::filesystem::remove(bmcdataPath);
91 }
92
Isaac Kurth0ddd4fa2021-07-14 17:35:37 -050093 // Recreate default files.
Ramesh Iyyar6b56bd42022-04-20 08:43:24 -050094 // std::tuple<method, service_name>
95 const std::tuple<std::string, std::string> services[] = {
96 {"StartUnit", "obmc-flash-bios-init.service"},
97 {"StartUnit", "obmc-flash-bios-patch.service"},
98 {"StartUnit", "openpower-process-host-firmware.service"},
99 {"StartUnit", "openpower-update-bios-attr-table.service"},
Ramesh Iyyar6b56bd42022-04-20 08:43:24 -0500100 {"RestartUnit", "org.open_power.HardwareIsolation.service"}};
Isaac Kurthbde5d7d2021-09-14 18:40:25 +0000101
Isaac Kurthbde5d7d2021-09-14 18:40:25 +0000102 for (const auto& service : services)
103 {
104 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
Ramesh Iyyar6b56bd42022-04-20 08:43:24 -0500105 SYSTEMD_INTERFACE,
106 std::get<0>(service).c_str());
107 method.append(std::get<1>(service), "replace");
Isaac Kurthbde5d7d2021-09-14 18:40:25 +0000108 // Ignore errors if the service is not found - not all systems
109 // may have these services
110 try
111 {
112 bus.call_noreply(method);
113 }
114 catch (const std::exception& e)
115 {}
116 }
Isaac Kurth0ddd4fa2021-07-14 17:35:37 -0500117}
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -0500118
119bool ItemUpdaterMMC::isVersionFunctional(const std::string& versionId)
120{
121 return versionId == functionalVersionId;
122}
123
Brad Bishopc8f22502020-11-06 14:42:09 -0500124void ItemUpdaterMMC::freePriority(uint8_t, const std::string&)
Brad Bishop8facccf2020-11-04 09:44:58 -0500125{}
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -0500126
127void ItemUpdaterMMC::deleteAll()
Brad Bishop8facccf2020-11-04 09:44:58 -0500128{}
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -0500129
130bool ItemUpdaterMMC::freeSpace()
131{
132 return true;
133}
134
Brad Bishopc8f22502020-11-06 14:42:09 -0500135void ItemUpdaterMMC::updateFunctionalAssociation(const std::string&)
Brad Bishop8facccf2020-11-04 09:44:58 -0500136{}
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -0500137
138void GardResetMMC::reset()
Brad Bishop8facccf2020-11-04 09:44:58 -0500139{}
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -0500140
141} // namespace updater
142} // namespace software
143} // namespace openpower