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 | |
Isaac Kurth | 0ddd4fa | 2021-07-14 17:35:37 -0500 | [diff] [blame] | 9 | #include <filesystem> |
Isaac Kurth | bde5d7d | 2021-09-14 18:40:25 +0000 | [diff] [blame] | 10 | #include <iostream> |
Adriana Kobylak | 295fce0 | 2022-06-13 15:11:49 +0000 | [diff] [blame] | 11 | #include <thread> |
Isaac Kurth | 0ddd4fa | 2021-07-14 17:35:37 -0500 | [diff] [blame] | 12 | |
Adriana Kobylak | 8bc2ab4 | 2020-07-15 09:16:27 -0500 | [diff] [blame] | 13 | namespace openpower |
| 14 | { |
| 15 | namespace software |
| 16 | { |
| 17 | namespace updater |
| 18 | { |
| 19 | |
| 20 | // These functions are just a stub (empty) because the current eMMC |
| 21 | // implementation uses the BMC updater (repo phosphor-bmc-code-mgmt) to write |
| 22 | // the new host FW to flash since it's delivered as a "System" image in the |
| 23 | // same BMC tarball as the BMC image. |
| 24 | |
| 25 | std::unique_ptr<Activation> ItemUpdaterMMC::createActivationObject( |
| 26 | const std::string& path, const std::string& versionId, |
| 27 | const std::string& extVersion, |
| 28 | sdbusplus::xyz::openbmc_project::Software::server::Activation::Activations |
| 29 | activationStatus, |
| 30 | AssociationList& assocs) |
| 31 | { |
| 32 | return std::make_unique<ActivationMMC>( |
| 33 | bus, path, *this, versionId, extVersion, activationStatus, assocs); |
| 34 | } |
| 35 | |
| 36 | std::unique_ptr<Version> ItemUpdaterMMC::createVersionObject( |
| 37 | const std::string& objPath, const std::string& versionId, |
| 38 | const std::string& versionString, |
| 39 | sdbusplus::xyz::openbmc_project::Software::server::Version::VersionPurpose |
| 40 | versionPurpose, |
| 41 | const std::string& filePath) |
| 42 | { |
| 43 | auto version = std::make_unique<Version>( |
| 44 | bus, objPath, *this, versionId, versionString, versionPurpose, filePath, |
| 45 | std::bind(&ItemUpdaterMMC::erase, this, std::placeholders::_1)); |
| 46 | version->deleteObject = std::make_unique<Delete>(bus, objPath, *version); |
| 47 | return version; |
| 48 | } |
| 49 | |
Brad Bishop | c8f2250 | 2020-11-06 14:42:09 -0500 | [diff] [blame] | 50 | bool ItemUpdaterMMC::validateImage(const std::string&) |
Adriana Kobylak | 8bc2ab4 | 2020-07-15 09:16:27 -0500 | [diff] [blame] | 51 | { |
| 52 | return true; |
| 53 | } |
| 54 | |
| 55 | void ItemUpdaterMMC::processPNORImage() |
Brad Bishop | 8facccf | 2020-11-04 09:44:58 -0500 | [diff] [blame] | 56 | {} |
Adriana Kobylak | 8bc2ab4 | 2020-07-15 09:16:27 -0500 | [diff] [blame] | 57 | |
| 58 | void ItemUpdaterMMC::reset() |
Isaac Kurth | 0ddd4fa | 2021-07-14 17:35:37 -0500 | [diff] [blame] | 59 | { |
| 60 | // 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] | 61 | const std::vector<std::string> exclusionList = {"alternate", "hostfw-a", |
| 62 | "hostfw-b", "lost+found", |
| 63 | "nvram", "running-ro"}; |
Isaac Kurth | 0ddd4fa | 2021-07-14 17:35:37 -0500 | [diff] [blame] | 64 | std::filesystem::path dirPath(std::string(MEDIA_DIR "hostfw/")); |
| 65 | // Delete all files in /media/hostfw/ except for those on exclusionList |
| 66 | for (const auto& p : std::filesystem::directory_iterator(dirPath)) |
| 67 | { |
| 68 | if (std::find(exclusionList.begin(), exclusionList.end(), |
| 69 | p.path().stem().string()) == exclusionList.end()) |
| 70 | { |
| 71 | std::filesystem::remove_all(p); |
| 72 | } |
| 73 | } |
| 74 | |
Adriana Kobylak | 267c413 | 2022-02-25 20:00:07 +0000 | [diff] [blame] | 75 | // Delete all BMC error logs to avoid discrepancies with the host error logs |
| 76 | utils::deleteAllErrorLogs(bus); |
| 77 | |
Adriana Kobylak | f9a72a7 | 2022-05-20 14:52:29 +0000 | [diff] [blame] | 78 | // Set attribute to clear hypervisor NVRAM |
| 79 | utils::setClearNvram(bus); |
| 80 | |
Isaac Kurth | bde5d7d | 2021-09-14 18:40:25 +0000 | [diff] [blame] | 81 | // Remove files related to the Hardware Management Console / BMC web app |
Adriana Kobylak | 56a4677 | 2022-02-25 16:37:37 +0000 | [diff] [blame] | 82 | utils::clearHMCManaged(bus); |
Isaac Kurth | bde5d7d | 2021-09-14 18:40:25 +0000 | [diff] [blame] | 83 | std::filesystem::path consolePath("/var/lib/bmcweb/ibm-management-console"); |
| 84 | if (std::filesystem::exists(consolePath)) |
| 85 | { |
| 86 | std::filesystem::remove_all(consolePath); |
| 87 | } |
Isaac Kurth | bde5d7d | 2021-09-14 18:40:25 +0000 | [diff] [blame] | 88 | std::filesystem::path bmcdataPath("/home/root/bmcweb_persistent_data.json"); |
| 89 | if (std::filesystem::exists(bmcdataPath)) |
| 90 | { |
| 91 | std::filesystem::remove(bmcdataPath); |
| 92 | } |
| 93 | |
Isaac Kurth | 0ddd4fa | 2021-07-14 17:35:37 -0500 | [diff] [blame] | 94 | // Recreate default files. |
Ramesh Iyyar | 6b56bd4 | 2022-04-20 08:43:24 -0500 | [diff] [blame] | 95 | // std::tuple<method, service_name> |
| 96 | const std::tuple<std::string, std::string> services[] = { |
| 97 | {"StartUnit", "obmc-flash-bios-init.service"}, |
| 98 | {"StartUnit", "obmc-flash-bios-patch.service"}, |
| 99 | {"StartUnit", "openpower-process-host-firmware.service"}, |
| 100 | {"StartUnit", "openpower-update-bios-attr-table.service"}, |
Ramesh Iyyar | 6b56bd4 | 2022-04-20 08:43:24 -0500 | [diff] [blame] | 101 | {"RestartUnit", "org.open_power.HardwareIsolation.service"}}; |
Isaac Kurth | bde5d7d | 2021-09-14 18:40:25 +0000 | [diff] [blame] | 102 | |
Isaac Kurth | bde5d7d | 2021-09-14 18:40:25 +0000 | [diff] [blame] | 103 | for (const auto& service : services) |
| 104 | { |
| 105 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
Ramesh Iyyar | 6b56bd4 | 2022-04-20 08:43:24 -0500 | [diff] [blame] | 106 | SYSTEMD_INTERFACE, |
| 107 | std::get<0>(service).c_str()); |
| 108 | method.append(std::get<1>(service), "replace"); |
Isaac Kurth | bde5d7d | 2021-09-14 18:40:25 +0000 | [diff] [blame] | 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 | } |
Adriana Kobylak | 295fce0 | 2022-06-13 15:11:49 +0000 | [diff] [blame] | 118 | |
| 119 | // Wait a few seconds for the service files and reset operations to finish, |
| 120 | // otherwise the BMC may be rebooted and cause corruption. |
| 121 | constexpr auto resetWait = std::chrono::seconds(5); |
| 122 | std::this_thread::sleep_for(resetWait); |
Isaac Kurth | 0ddd4fa | 2021-07-14 17:35:37 -0500 | [diff] [blame] | 123 | } |
Adriana Kobylak | 8bc2ab4 | 2020-07-15 09:16:27 -0500 | [diff] [blame] | 124 | |
| 125 | bool ItemUpdaterMMC::isVersionFunctional(const std::string& versionId) |
| 126 | { |
| 127 | return versionId == functionalVersionId; |
| 128 | } |
| 129 | |
Brad Bishop | c8f2250 | 2020-11-06 14:42:09 -0500 | [diff] [blame] | 130 | void ItemUpdaterMMC::freePriority(uint8_t, const std::string&) |
Brad Bishop | 8facccf | 2020-11-04 09:44:58 -0500 | [diff] [blame] | 131 | {} |
Adriana Kobylak | 8bc2ab4 | 2020-07-15 09:16:27 -0500 | [diff] [blame] | 132 | |
| 133 | void ItemUpdaterMMC::deleteAll() |
Brad Bishop | 8facccf | 2020-11-04 09:44:58 -0500 | [diff] [blame] | 134 | {} |
Adriana Kobylak | 8bc2ab4 | 2020-07-15 09:16:27 -0500 | [diff] [blame] | 135 | |
| 136 | bool ItemUpdaterMMC::freeSpace() |
| 137 | { |
| 138 | return true; |
| 139 | } |
| 140 | |
Brad Bishop | c8f2250 | 2020-11-06 14:42:09 -0500 | [diff] [blame] | 141 | void ItemUpdaterMMC::updateFunctionalAssociation(const std::string&) |
Brad Bishop | 8facccf | 2020-11-04 09:44:58 -0500 | [diff] [blame] | 142 | {} |
Adriana Kobylak | 8bc2ab4 | 2020-07-15 09:16:27 -0500 | [diff] [blame] | 143 | |
| 144 | void GardResetMMC::reset() |
Brad Bishop | 8facccf | 2020-11-04 09:44:58 -0500 | [diff] [blame] | 145 | {} |
Adriana Kobylak | 8bc2ab4 | 2020-07-15 09:16:27 -0500 | [diff] [blame] | 146 | |
| 147 | } // namespace updater |
| 148 | } // namespace software |
| 149 | } // namespace openpower |