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 
10 namespace openpower
11 {
12 namespace software
13 {
14 namespace updater
15 {
16 
17 // These functions are just a stub (empty) because the current eMMC
18 // implementation uses the BMC updater (repo phosphor-bmc-code-mgmt) to write
19 // the new host FW to flash since it's delivered as a "System" image in the
20 // same BMC tarball as the BMC image.
21 
22 std::unique_ptr<Activation> ItemUpdaterMMC::createActivationObject(
23     const std::string& path, const std::string& versionId,
24     const std::string& extVersion,
25     sdbusplus::xyz::openbmc_project::Software::server::Activation::Activations
26         activationStatus,
27     AssociationList& assocs)
28 {
29     return std::make_unique<ActivationMMC>(
30         bus, path, *this, versionId, extVersion, activationStatus, assocs);
31 }
32 
33 std::unique_ptr<Version> ItemUpdaterMMC::createVersionObject(
34     const std::string& objPath, const std::string& versionId,
35     const std::string& versionString,
36     sdbusplus::xyz::openbmc_project::Software::server::Version::VersionPurpose
37         versionPurpose,
38     const std::string& filePath)
39 {
40     auto version = std::make_unique<Version>(
41         bus, objPath, *this, versionId, versionString, versionPurpose, filePath,
42         std::bind(&ItemUpdaterMMC::erase, this, std::placeholders::_1));
43     version->deleteObject = std::make_unique<Delete>(bus, objPath, *version);
44     return version;
45 }
46 
47 bool ItemUpdaterMMC::validateImage(const std::string&)
48 {
49     return true;
50 }
51 
52 void ItemUpdaterMMC::processPNORImage()
53 {}
54 
55 void ItemUpdaterMMC::reset()
56 {
57     // Do not reset read-only files needed for reset or ext4 default files
58     const std::vector<std::string> exclusionList = {
59         "alternate", "hostfw-a", "hostfw-b", "lost+found", "running-ro"};
60     std::filesystem::path dirPath(std::string(MEDIA_DIR "hostfw/"));
61     // Delete all files in /media/hostfw/ except for those on exclusionList
62     for (const auto& p : std::filesystem::directory_iterator(dirPath))
63     {
64         if (std::find(exclusionList.begin(), exclusionList.end(),
65                       p.path().stem().string()) == exclusionList.end())
66         {
67             std::filesystem::remove_all(p);
68         }
69     }
70 
71     // Recreate default files.
72     auto bus = sdbusplus::bus::new_default();
73     constexpr auto initService = "obmc-flash-bios-init.service";
74     auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
75                                       SYSTEMD_INTERFACE, "StartUnit");
76     method.append(initService, "replace");
77     bus.call_noreply(method);
78 
79     constexpr auto patchService = "obmc-flash-bios-patch.service";
80     method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
81                                  SYSTEMD_INTERFACE, "StartUnit");
82     method.append(patchService, "replace");
83     bus.call_noreply(method);
84 
85     constexpr auto processService = "openpower-process-host-firmware.service";
86     method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
87                                  SYSTEMD_INTERFACE, "StartUnit");
88     method.append(processService, "replace");
89     bus.call_noreply(method);
90 
91     constexpr auto updateService = "openpower-update-bios-attr-table.service";
92     method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
93                                  SYSTEMD_INTERFACE, "StartUnit");
94     method.append(updateService, "replace");
95     bus.call_noreply(method);
96 }
97 
98 bool ItemUpdaterMMC::isVersionFunctional(const std::string& versionId)
99 {
100     return versionId == functionalVersionId;
101 }
102 
103 void ItemUpdaterMMC::freePriority(uint8_t, const std::string&)
104 {}
105 
106 void ItemUpdaterMMC::deleteAll()
107 {}
108 
109 bool ItemUpdaterMMC::freeSpace()
110 {
111     return true;
112 }
113 
114 void ItemUpdaterMMC::updateFunctionalAssociation(const std::string&)
115 {}
116 
117 void GardResetMMC::reset()
118 {}
119 
120 } // namespace updater
121 } // namespace software
122 } // namespace openpower
123