1 #include "config.h" 2 3 #include "item_updater_mmc.hpp" 4 5 #include "activation_mmc.hpp" 6 #include "utils.hpp" 7 #include "version.hpp" 8 9 #include <filesystem> 10 #include <iostream> 11 12 namespace openpower 13 { 14 namespace software 15 { 16 namespace 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 24 std::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 35 std::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 49 bool ItemUpdaterMMC::validateImage(const std::string&) 50 { 51 return true; 52 } 53 54 void ItemUpdaterMMC::processPNORImage() 55 {} 56 57 void ItemUpdaterMMC::reset() 58 { 59 // Do not reset read-only files needed for reset or ext4 default files 60 const std::vector<std::string> exclusionList = { 61 "alternate", "hostfw-a", "hostfw-b", "lost+found", "running-ro"}; 62 std::filesystem::path dirPath(std::string(MEDIA_DIR "hostfw/")); 63 // Delete all files in /media/hostfw/ except for those on exclusionList 64 for (const auto& p : std::filesystem::directory_iterator(dirPath)) 65 { 66 if (std::find(exclusionList.begin(), exclusionList.end(), 67 p.path().stem().string()) == exclusionList.end()) 68 { 69 std::filesystem::remove_all(p); 70 } 71 } 72 73 // Delete all BMC error logs to avoid discrepancies with the host error logs 74 utils::deleteAllErrorLogs(bus); 75 76 // Remove files related to the Hardware Management Console / BMC web app 77 78 utils::clearHMCManaged(bus); 79 80 std::filesystem::path consolePath("/var/lib/bmcweb/ibm-management-console"); 81 if (std::filesystem::exists(consolePath)) 82 { 83 std::filesystem::remove_all(consolePath); 84 } 85 86 std::filesystem::path bmcdataPath("/home/root/bmcweb_persistent_data.json"); 87 if (std::filesystem::exists(bmcdataPath)) 88 { 89 std::filesystem::remove(bmcdataPath); 90 } 91 92 // Recreate default files. 93 // std::tuple<method, service_name> 94 const std::tuple<std::string, std::string> services[] = { 95 {"StartUnit", "obmc-flash-bios-init.service"}, 96 {"StartUnit", "obmc-flash-bios-patch.service"}, 97 {"StartUnit", "openpower-process-host-firmware.service"}, 98 {"StartUnit", "openpower-update-bios-attr-table.service"}, 99 {"StartUnit", "pldm-reset-phyp-nvram.service"}, 100 {"StartUnit", "pldm-reset-phyp-nvram-cksum.service"}, 101 {"RestartUnit", "org.open_power.HardwareIsolation.service"}}; 102 103 for (const auto& service : services) 104 { 105 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, 106 SYSTEMD_INTERFACE, 107 std::get<0>(service).c_str()); 108 method.append(std::get<1>(service), "replace"); 109 // Ignore errors if the service is not found - not all systems 110 // may have these services 111 try 112 { 113 bus.call_noreply(method); 114 } 115 catch (const std::exception& e) 116 {} 117 } 118 } 119 120 bool ItemUpdaterMMC::isVersionFunctional(const std::string& versionId) 121 { 122 return versionId == functionalVersionId; 123 } 124 125 void ItemUpdaterMMC::freePriority(uint8_t, const std::string&) 126 {} 127 128 void ItemUpdaterMMC::deleteAll() 129 {} 130 131 bool ItemUpdaterMMC::freeSpace() 132 { 133 return true; 134 } 135 136 void ItemUpdaterMMC::updateFunctionalAssociation(const std::string&) 137 {} 138 139 void GardResetMMC::reset() 140 {} 141 142 } // namespace updater 143 } // namespace software 144 } // namespace openpower 145