Adriana Kobylak | 8bc2ab4 | 2020-07-15 09:16:27 -0500 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
| 3 | #include "item_updater_mmc.hpp" |
| 4 | |
| 5 | #include "activation_mmc.hpp" |
Adriana Kobylak | 56a4677 | 2022-02-25 16:37:37 +0000 | [diff] [blame] | 6 | #include "utils.hpp" |
Adriana Kobylak | 8bc2ab4 | 2020-07-15 09:16:27 -0500 | [diff] [blame] | 7 | #include "version.hpp" |
| 8 | |
Marri Devender Rao | 2b31497 | 2022-07-01 05:37:30 -0500 | [diff] [blame] | 9 | #include <phosphor-logging/log.hpp> |
| 10 | |
Isaac Kurth | 0ddd4fa | 2021-07-14 17:35:37 -0500 | [diff] [blame] | 11 | #include <filesystem> |
Patrick Williams | 4cf521e | 2024-02-13 21:45:04 -0600 | [diff] [blame] | 12 | #include <format> |
Isaac Kurth | bde5d7d | 2021-09-14 18:40:25 +0000 | [diff] [blame] | 13 | #include <iostream> |
Adriana Kobylak | 295fce0 | 2022-06-13 15:11:49 +0000 | [diff] [blame] | 14 | #include <thread> |
Isaac Kurth | 0ddd4fa | 2021-07-14 17:35:37 -0500 | [diff] [blame] | 15 | |
Adriana Kobylak | 8bc2ab4 | 2020-07-15 09:16:27 -0500 | [diff] [blame] | 16 | namespace openpower |
| 17 | { |
| 18 | namespace software |
| 19 | { |
| 20 | namespace updater |
| 21 | { |
| 22 | |
Marri Devender Rao | 2b31497 | 2022-07-01 05:37:30 -0500 | [diff] [blame] | 23 | using ::phosphor::logging::level; |
| 24 | using ::phosphor::logging::log; |
Adriana Kobylak | 8bc2ab4 | 2020-07-15 09:16:27 -0500 | [diff] [blame] | 25 | // These functions are just a stub (empty) because the current eMMC |
| 26 | // implementation uses the BMC updater (repo phosphor-bmc-code-mgmt) to write |
| 27 | // the new host FW to flash since it's delivered as a "System" image in the |
| 28 | // same BMC tarball as the BMC image. |
| 29 | |
| 30 | std::unique_ptr<Activation> ItemUpdaterMMC::createActivationObject( |
| 31 | const std::string& path, const std::string& versionId, |
| 32 | const std::string& extVersion, |
| 33 | sdbusplus::xyz::openbmc_project::Software::server::Activation::Activations |
| 34 | activationStatus, |
| 35 | AssociationList& assocs) |
| 36 | { |
| 37 | return std::make_unique<ActivationMMC>( |
| 38 | bus, path, *this, versionId, extVersion, activationStatus, assocs); |
| 39 | } |
| 40 | |
| 41 | std::unique_ptr<Version> ItemUpdaterMMC::createVersionObject( |
| 42 | const std::string& objPath, const std::string& versionId, |
| 43 | const std::string& versionString, |
| 44 | sdbusplus::xyz::openbmc_project::Software::server::Version::VersionPurpose |
| 45 | versionPurpose, |
| 46 | const std::string& filePath) |
| 47 | { |
| 48 | auto version = std::make_unique<Version>( |
| 49 | bus, objPath, *this, versionId, versionString, versionPurpose, filePath, |
| 50 | std::bind(&ItemUpdaterMMC::erase, this, std::placeholders::_1)); |
| 51 | version->deleteObject = std::make_unique<Delete>(bus, objPath, *version); |
| 52 | return version; |
| 53 | } |
| 54 | |
Brad Bishop | c8f2250 | 2020-11-06 14:42:09 -0500 | [diff] [blame] | 55 | bool ItemUpdaterMMC::validateImage(const std::string&) |
Adriana Kobylak | 8bc2ab4 | 2020-07-15 09:16:27 -0500 | [diff] [blame] | 56 | { |
| 57 | return true; |
| 58 | } |
| 59 | |
Patrick Williams | 7fb6c34 | 2023-05-10 07:50:18 -0500 | [diff] [blame] | 60 | void ItemUpdaterMMC::processPNORImage() {} |
Adriana Kobylak | 8bc2ab4 | 2020-07-15 09:16:27 -0500 | [diff] [blame] | 61 | |
| 62 | void ItemUpdaterMMC::reset() |
Isaac Kurth | 0ddd4fa | 2021-07-14 17:35:37 -0500 | [diff] [blame] | 63 | { |
| 64 | // Do not reset read-only files needed for reset or ext4 default files |
Adriana Kobylak | f9a72a7 | 2022-05-20 14:52:29 +0000 | [diff] [blame] | 65 | const std::vector<std::string> exclusionList = {"alternate", "hostfw-a", |
| 66 | "hostfw-b", "lost+found", |
| 67 | "nvram", "running-ro"}; |
Isaac Kurth | 0ddd4fa | 2021-07-14 17:35:37 -0500 | [diff] [blame] | 68 | std::filesystem::path dirPath(std::string(MEDIA_DIR "hostfw/")); |
| 69 | // Delete all files in /media/hostfw/ except for those on exclusionList |
| 70 | for (const auto& p : std::filesystem::directory_iterator(dirPath)) |
| 71 | { |
| 72 | if (std::find(exclusionList.begin(), exclusionList.end(), |
| 73 | p.path().stem().string()) == exclusionList.end()) |
| 74 | { |
| 75 | std::filesystem::remove_all(p); |
| 76 | } |
| 77 | } |
| 78 | |
Adriana Kobylak | 267c413 | 2022-02-25 20:00:07 +0000 | [diff] [blame] | 79 | // Delete all BMC error logs to avoid discrepancies with the host error logs |
| 80 | utils::deleteAllErrorLogs(bus); |
| 81 | |
Adriana Kobylak | f9a72a7 | 2022-05-20 14:52:29 +0000 | [diff] [blame] | 82 | // Set attribute to clear hypervisor NVRAM |
| 83 | utils::setClearNvram(bus); |
| 84 | |
Marri Devender Rao | 2b31497 | 2022-07-01 05:37:30 -0500 | [diff] [blame] | 85 | // reset the enabled property of dimms/cpu after factory reset |
| 86 | gardReset->reset(); |
| 87 | |
Isaac Kurth | bde5d7d | 2021-09-14 18:40:25 +0000 | [diff] [blame] | 88 | // Remove files related to the Hardware Management Console / BMC web app |
Adriana Kobylak | 56a4677 | 2022-02-25 16:37:37 +0000 | [diff] [blame] | 89 | utils::clearHMCManaged(bus); |
Isaac Kurth | bde5d7d | 2021-09-14 18:40:25 +0000 | [diff] [blame] | 90 | std::filesystem::path consolePath("/var/lib/bmcweb/ibm-management-console"); |
| 91 | if (std::filesystem::exists(consolePath)) |
| 92 | { |
| 93 | std::filesystem::remove_all(consolePath); |
| 94 | } |
Isaac Kurth | bde5d7d | 2021-09-14 18:40:25 +0000 | [diff] [blame] | 95 | std::filesystem::path bmcdataPath("/home/root/bmcweb_persistent_data.json"); |
| 96 | if (std::filesystem::exists(bmcdataPath)) |
| 97 | { |
| 98 | std::filesystem::remove(bmcdataPath); |
| 99 | } |
| 100 | |
Isaac Kurth | 0ddd4fa | 2021-07-14 17:35:37 -0500 | [diff] [blame] | 101 | // Recreate default files. |
Ramesh Iyyar | 6b56bd4 | 2022-04-20 08:43:24 -0500 | [diff] [blame] | 102 | // std::tuple<method, service_name> |
| 103 | const std::tuple<std::string, std::string> services[] = { |
| 104 | {"StartUnit", "obmc-flash-bios-init.service"}, |
| 105 | {"StartUnit", "obmc-flash-bios-patch.service"}, |
| 106 | {"StartUnit", "openpower-process-host-firmware.service"}, |
| 107 | {"StartUnit", "openpower-update-bios-attr-table.service"}, |
Ramesh Iyyar | 6b56bd4 | 2022-04-20 08:43:24 -0500 | [diff] [blame] | 108 | {"RestartUnit", "org.open_power.HardwareIsolation.service"}}; |
Isaac Kurth | bde5d7d | 2021-09-14 18:40:25 +0000 | [diff] [blame] | 109 | |
Isaac Kurth | bde5d7d | 2021-09-14 18:40:25 +0000 | [diff] [blame] | 110 | for (const auto& service : services) |
| 111 | { |
| 112 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
Ramesh Iyyar | 6b56bd4 | 2022-04-20 08:43:24 -0500 | [diff] [blame] | 113 | SYSTEMD_INTERFACE, |
| 114 | std::get<0>(service).c_str()); |
| 115 | method.append(std::get<1>(service), "replace"); |
Isaac Kurth | bde5d7d | 2021-09-14 18:40:25 +0000 | [diff] [blame] | 116 | // Ignore errors if the service is not found - not all systems |
| 117 | // may have these services |
| 118 | try |
| 119 | { |
| 120 | bus.call_noreply(method); |
| 121 | } |
| 122 | catch (const std::exception& e) |
| 123 | {} |
| 124 | } |
Adriana Kobylak | 295fce0 | 2022-06-13 15:11:49 +0000 | [diff] [blame] | 125 | |
| 126 | // Wait a few seconds for the service files and reset operations to finish, |
| 127 | // otherwise the BMC may be rebooted and cause corruption. |
| 128 | constexpr auto resetWait = std::chrono::seconds(5); |
| 129 | std::this_thread::sleep_for(resetWait); |
Isaac Kurth | 0ddd4fa | 2021-07-14 17:35:37 -0500 | [diff] [blame] | 130 | } |
Adriana Kobylak | 8bc2ab4 | 2020-07-15 09:16:27 -0500 | [diff] [blame] | 131 | |
| 132 | bool ItemUpdaterMMC::isVersionFunctional(const std::string& versionId) |
| 133 | { |
| 134 | return versionId == functionalVersionId; |
| 135 | } |
| 136 | |
Patrick Williams | 7fb6c34 | 2023-05-10 07:50:18 -0500 | [diff] [blame] | 137 | void ItemUpdaterMMC::freePriority(uint8_t, const std::string&) {} |
Adriana Kobylak | 8bc2ab4 | 2020-07-15 09:16:27 -0500 | [diff] [blame] | 138 | |
Patrick Williams | 7fb6c34 | 2023-05-10 07:50:18 -0500 | [diff] [blame] | 139 | void ItemUpdaterMMC::deleteAll() {} |
Adriana Kobylak | 8bc2ab4 | 2020-07-15 09:16:27 -0500 | [diff] [blame] | 140 | |
| 141 | bool ItemUpdaterMMC::freeSpace() |
| 142 | { |
| 143 | return true; |
| 144 | } |
| 145 | |
Patrick Williams | 7fb6c34 | 2023-05-10 07:50:18 -0500 | [diff] [blame] | 146 | void ItemUpdaterMMC::updateFunctionalAssociation(const std::string&) {} |
Marri Devender Rao | 2b31497 | 2022-07-01 05:37:30 -0500 | [diff] [blame] | 147 | void GardResetMMC::enableInventoryItems() |
| 148 | { |
| 149 | (void)enableInventoryItemsHelper( |
| 150 | "xyz.openbmc_project.PLDM", |
| 151 | "xyz.openbmc_project.Inventory.Item.CpuCore", |
| 152 | "/xyz/openbmc_project/inventory/system/chassis/motherboard"); |
| 153 | |
| 154 | (void)enableInventoryItemsHelper("xyz.openbmc_project.Inventory.Manager", |
| 155 | "xyz.openbmc_project.Inventory.Item.Dimm", |
| 156 | "/xyz/openbmc_project/inventory"); |
| 157 | } |
| 158 | |
| 159 | void GardResetMMC::enableInventoryItemsHelper(const std::string& service, |
| 160 | const std::string& intf, |
| 161 | const std::string& objPath) |
| 162 | { |
| 163 | const std::vector<std::string> intflist{intf}; |
| 164 | |
| 165 | std::vector<std::string> objs; |
| 166 | try |
| 167 | { |
| 168 | auto mapperCall = bus.new_method_call( |
| 169 | "xyz.openbmc_project.ObjectMapper", |
| 170 | "/xyz/openbmc_project/object_mapper", |
| 171 | "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths"); |
| 172 | mapperCall.append(objPath); |
| 173 | mapperCall.append(0); |
| 174 | mapperCall.append(intflist); |
| 175 | |
| 176 | auto response = bus.call(mapperCall); |
| 177 | response.read(objs); |
| 178 | for (auto& obj : objs) |
| 179 | { |
Patrick Williams | 7fb6c34 | 2023-05-10 07:50:18 -0500 | [diff] [blame] | 180 | auto method = bus.new_method_call(service.c_str(), obj.c_str(), |
| 181 | "org.freedesktop.DBus.Properties", |
| 182 | "Set"); |
Marri Devender Rao | 2b31497 | 2022-07-01 05:37:30 -0500 | [diff] [blame] | 183 | std::variant<bool> propertyVal{true}; |
| 184 | method.append("xyz.openbmc_project.Object.Enable", "Enabled", |
| 185 | propertyVal); |
| 186 | bus.call_noreply(method); |
| 187 | } |
| 188 | } |
| 189 | catch (const sdbusplus::exception_t& e) |
| 190 | { |
| 191 | log<level::ERR>( |
Patrick Williams | 4cf521e | 2024-02-13 21:45:04 -0600 | [diff] [blame] | 192 | std::format("Failed to enable specified inventory items ex({}) " |
Marri Devender Rao | 2b31497 | 2022-07-01 05:37:30 -0500 | [diff] [blame] | 193 | "intf({}) objpath({})", |
| 194 | e.what(), intf, objPath) |
| 195 | .c_str()); |
| 196 | } |
| 197 | } |
Adriana Kobylak | 8bc2ab4 | 2020-07-15 09:16:27 -0500 | [diff] [blame] | 198 | |
| 199 | void GardResetMMC::reset() |
Marri Devender Rao | 2b31497 | 2022-07-01 05:37:30 -0500 | [diff] [blame] | 200 | { |
| 201 | log<level::INFO>("GardResetMMC::reset"); |
| 202 | (void)enableInventoryItems(); |
| 203 | } |
Adriana Kobylak | 8bc2ab4 | 2020-07-15 09:16:27 -0500 | [diff] [blame] | 204 | |
| 205 | } // namespace updater |
| 206 | } // namespace software |
| 207 | } // namespace openpower |