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> |
Isaac Kurth | 0ddd4fa | 2021-07-14 17:35:37 -0500 | [diff] [blame] | 11 | |
Adriana Kobylak | 8bc2ab4 | 2020-07-15 09:16:27 -0500 | [diff] [blame] | 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 | |
Brad Bishop | c8f2250 | 2020-11-06 14:42:09 -0500 | [diff] [blame] | 49 | bool ItemUpdaterMMC::validateImage(const std::string&) |
Adriana Kobylak | 8bc2ab4 | 2020-07-15 09:16:27 -0500 | [diff] [blame] | 50 | { |
| 51 | return true; |
| 52 | } |
| 53 | |
| 54 | void ItemUpdaterMMC::processPNORImage() |
Brad Bishop | 8facccf | 2020-11-04 09:44:58 -0500 | [diff] [blame] | 55 | {} |
Adriana Kobylak | 8bc2ab4 | 2020-07-15 09:16:27 -0500 | [diff] [blame] | 56 | |
| 57 | void ItemUpdaterMMC::reset() |
Isaac Kurth | 0ddd4fa | 2021-07-14 17:35:37 -0500 | [diff] [blame] | 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 | |
Isaac Kurth | bde5d7d | 2021-09-14 18:40:25 +0000 | [diff] [blame] | 73 | // Remove files related to the Hardware Management Console / BMC web app |
Adriana Kobylak | 56a4677 | 2022-02-25 16:37:37 +0000 | [diff] [blame^] | 74 | |
| 75 | utils::clearHMCManaged(bus); |
| 76 | |
Isaac Kurth | bde5d7d | 2021-09-14 18:40:25 +0000 | [diff] [blame] | 77 | std::filesystem::path consolePath("/var/lib/bmcweb/ibm-management-console"); |
| 78 | if (std::filesystem::exists(consolePath)) |
| 79 | { |
| 80 | std::filesystem::remove_all(consolePath); |
| 81 | } |
| 82 | |
| 83 | std::filesystem::path bmcdataPath("/home/root/bmcweb_persistent_data.json"); |
| 84 | if (std::filesystem::exists(bmcdataPath)) |
| 85 | { |
| 86 | std::filesystem::remove(bmcdataPath); |
| 87 | } |
| 88 | |
Isaac Kurth | 0ddd4fa | 2021-07-14 17:35:37 -0500 | [diff] [blame] | 89 | // Recreate default files. |
Isaac Kurth | bde5d7d | 2021-09-14 18:40:25 +0000 | [diff] [blame] | 90 | const std::string services[] = {"obmc-flash-bios-init.service", |
| 91 | "obmc-flash-bios-patch.service", |
| 92 | "openpower-process-host-firmware.service", |
| 93 | "openpower-update-bios-attr-table.service", |
| 94 | "pldm-reset-phyp-nvram.service", |
| 95 | "pldm-reset-phyp-nvram-cksum.service"}; |
| 96 | |
Isaac Kurth | bde5d7d | 2021-09-14 18:40:25 +0000 | [diff] [blame] | 97 | for (const auto& service : services) |
| 98 | { |
| 99 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 100 | SYSTEMD_INTERFACE, "StartUnit"); |
| 101 | method.append(service, "replace"); |
| 102 | // Ignore errors if the service is not found - not all systems |
| 103 | // may have these services |
| 104 | try |
| 105 | { |
| 106 | bus.call_noreply(method); |
| 107 | } |
| 108 | catch (const std::exception& e) |
| 109 | {} |
| 110 | } |
Isaac Kurth | 0ddd4fa | 2021-07-14 17:35:37 -0500 | [diff] [blame] | 111 | } |
Adriana Kobylak | 8bc2ab4 | 2020-07-15 09:16:27 -0500 | [diff] [blame] | 112 | |
| 113 | bool ItemUpdaterMMC::isVersionFunctional(const std::string& versionId) |
| 114 | { |
| 115 | return versionId == functionalVersionId; |
| 116 | } |
| 117 | |
Brad Bishop | c8f2250 | 2020-11-06 14:42:09 -0500 | [diff] [blame] | 118 | void ItemUpdaterMMC::freePriority(uint8_t, const std::string&) |
Brad Bishop | 8facccf | 2020-11-04 09:44:58 -0500 | [diff] [blame] | 119 | {} |
Adriana Kobylak | 8bc2ab4 | 2020-07-15 09:16:27 -0500 | [diff] [blame] | 120 | |
| 121 | void ItemUpdaterMMC::deleteAll() |
Brad Bishop | 8facccf | 2020-11-04 09:44:58 -0500 | [diff] [blame] | 122 | {} |
Adriana Kobylak | 8bc2ab4 | 2020-07-15 09:16:27 -0500 | [diff] [blame] | 123 | |
| 124 | bool ItemUpdaterMMC::freeSpace() |
| 125 | { |
| 126 | return true; |
| 127 | } |
| 128 | |
Brad Bishop | c8f2250 | 2020-11-06 14:42:09 -0500 | [diff] [blame] | 129 | void ItemUpdaterMMC::updateFunctionalAssociation(const std::string&) |
Brad Bishop | 8facccf | 2020-11-04 09:44:58 -0500 | [diff] [blame] | 130 | {} |
Adriana Kobylak | 8bc2ab4 | 2020-07-15 09:16:27 -0500 | [diff] [blame] | 131 | |
| 132 | void GardResetMMC::reset() |
Brad Bishop | 8facccf | 2020-11-04 09:44:58 -0500 | [diff] [blame] | 133 | {} |
Adriana Kobylak | 8bc2ab4 | 2020-07-15 09:16:27 -0500 | [diff] [blame] | 134 | |
| 135 | } // namespace updater |
| 136 | } // namespace software |
| 137 | } // namespace openpower |