blob: 04f237df1570aa0fd0eafb3a37e67fe18a54a6a3 [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"
6#include "version.hpp"
7
Isaac Kurth0ddd4fa2021-07-14 17:35:37 -05008#include <filesystem>
Isaac Kurthbde5d7d2021-09-14 18:40:25 +00009#include <iostream>
Isaac Kurth0ddd4fa2021-07-14 17:35:37 -050010
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -050011namespace openpower
12{
13namespace software
14{
15namespace updater
16{
17
18// These functions are just a stub (empty) because the current eMMC
19// implementation uses the BMC updater (repo phosphor-bmc-code-mgmt) to write
20// the new host FW to flash since it's delivered as a "System" image in the
21// same BMC tarball as the BMC image.
22
23std::unique_ptr<Activation> ItemUpdaterMMC::createActivationObject(
24 const std::string& path, const std::string& versionId,
25 const std::string& extVersion,
26 sdbusplus::xyz::openbmc_project::Software::server::Activation::Activations
27 activationStatus,
28 AssociationList& assocs)
29{
30 return std::make_unique<ActivationMMC>(
31 bus, path, *this, versionId, extVersion, activationStatus, assocs);
32}
33
34std::unique_ptr<Version> ItemUpdaterMMC::createVersionObject(
35 const std::string& objPath, const std::string& versionId,
36 const std::string& versionString,
37 sdbusplus::xyz::openbmc_project::Software::server::Version::VersionPurpose
38 versionPurpose,
39 const std::string& filePath)
40{
41 auto version = std::make_unique<Version>(
42 bus, objPath, *this, versionId, versionString, versionPurpose, filePath,
43 std::bind(&ItemUpdaterMMC::erase, this, std::placeholders::_1));
44 version->deleteObject = std::make_unique<Delete>(bus, objPath, *version);
45 return version;
46}
47
Brad Bishopc8f22502020-11-06 14:42:09 -050048bool ItemUpdaterMMC::validateImage(const std::string&)
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -050049{
50 return true;
51}
52
53void ItemUpdaterMMC::processPNORImage()
Brad Bishop8facccf2020-11-04 09:44:58 -050054{}
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -050055
56void ItemUpdaterMMC::reset()
Isaac Kurth0ddd4fa2021-07-14 17:35:37 -050057{
58 // Do not reset read-only files needed for reset or ext4 default files
59 const std::vector<std::string> exclusionList = {
60 "alternate", "hostfw-a", "hostfw-b", "lost+found", "running-ro"};
61 std::filesystem::path dirPath(std::string(MEDIA_DIR "hostfw/"));
62 // Delete all files in /media/hostfw/ except for those on exclusionList
63 for (const auto& p : std::filesystem::directory_iterator(dirPath))
64 {
65 if (std::find(exclusionList.begin(), exclusionList.end(),
66 p.path().stem().string()) == exclusionList.end())
67 {
68 std::filesystem::remove_all(p);
69 }
70 }
71
Isaac Kurthbde5d7d2021-09-14 18:40:25 +000072 // Remove files related to the Hardware Management Console / BMC web app
73 std::filesystem::path consolePath("/var/lib/bmcweb/ibm-management-console");
74 if (std::filesystem::exists(consolePath))
75 {
76 std::filesystem::remove_all(consolePath);
77 }
78
79 std::filesystem::path bmcdataPath("/home/root/bmcweb_persistent_data.json");
80 if (std::filesystem::exists(bmcdataPath))
81 {
82 std::filesystem::remove(bmcdataPath);
83 }
84
Isaac Kurth0ddd4fa2021-07-14 17:35:37 -050085 // Recreate default files.
Isaac Kurthbde5d7d2021-09-14 18:40:25 +000086 const std::string services[] = {"obmc-flash-bios-init.service",
87 "obmc-flash-bios-patch.service",
88 "openpower-process-host-firmware.service",
89 "openpower-update-bios-attr-table.service",
90 "pldm-reset-phyp-nvram.service",
91 "pldm-reset-phyp-nvram-cksum.service"};
92
Isaac Kurth0ddd4fa2021-07-14 17:35:37 -050093 auto bus = sdbusplus::bus::new_default();
Isaac Kurthbde5d7d2021-09-14 18:40:25 +000094 for (const auto& service : services)
95 {
96 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
97 SYSTEMD_INTERFACE, "StartUnit");
98 method.append(service, "replace");
99 // Ignore errors if the service is not found - not all systems
100 // may have these services
101 try
102 {
103 bus.call_noreply(method);
104 }
105 catch (const std::exception& e)
106 {}
107 }
Isaac Kurth0ddd4fa2021-07-14 17:35:37 -0500108}
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -0500109
110bool ItemUpdaterMMC::isVersionFunctional(const std::string& versionId)
111{
112 return versionId == functionalVersionId;
113}
114
Brad Bishopc8f22502020-11-06 14:42:09 -0500115void ItemUpdaterMMC::freePriority(uint8_t, const std::string&)
Brad Bishop8facccf2020-11-04 09:44:58 -0500116{}
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -0500117
118void ItemUpdaterMMC::deleteAll()
Brad Bishop8facccf2020-11-04 09:44:58 -0500119{}
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -0500120
121bool ItemUpdaterMMC::freeSpace()
122{
123 return true;
124}
125
Brad Bishopc8f22502020-11-06 14:42:09 -0500126void ItemUpdaterMMC::updateFunctionalAssociation(const std::string&)
Brad Bishop8facccf2020-11-04 09:44:58 -0500127{}
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -0500128
129void GardResetMMC::reset()
Brad Bishop8facccf2020-11-04 09:44:58 -0500130{}
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -0500131
132} // namespace updater
133} // namespace software
134} // namespace openpower