1 #include "config.h"
2 
3 #include "item_updater_mmc.hpp"
4 
5 #include "activation_mmc.hpp"
6 #include "version.hpp"
7 
8 #include <filesystem>
9 #include <iostream>
10 
11 namespace openpower
12 {
13 namespace software
14 {
15 namespace 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 
23 std::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 
34 std::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 
48 bool ItemUpdaterMMC::validateImage(const std::string&)
49 {
50     return true;
51 }
52 
53 void ItemUpdaterMMC::processPNORImage()
54 {}
55 
56 void ItemUpdaterMMC::reset()
57 {
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 
72     // 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 
85     // Recreate default files.
86     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 
93     auto bus = sdbusplus::bus::new_default();
94     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     }
108 }
109 
110 bool ItemUpdaterMMC::isVersionFunctional(const std::string& versionId)
111 {
112     return versionId == functionalVersionId;
113 }
114 
115 void ItemUpdaterMMC::freePriority(uint8_t, const std::string&)
116 {}
117 
118 void ItemUpdaterMMC::deleteAll()
119 {}
120 
121 bool ItemUpdaterMMC::freeSpace()
122 {
123     return true;
124 }
125 
126 void ItemUpdaterMMC::updateFunctionalAssociation(const std::string&)
127 {}
128 
129 void GardResetMMC::reset()
130 {}
131 
132 } // namespace updater
133 } // namespace software
134 } // namespace openpower
135