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" |
| 6 | #include "version.hpp" |
| 7 | |
Isaac Kurth | 0ddd4fa | 2021-07-14 17:35:37 -0500 | [diff] [blame] | 8 | #include <filesystem> |
Isaac Kurth | bde5d7d | 2021-09-14 18:40:25 +0000 | [diff] [blame^] | 9 | #include <iostream> |
Isaac Kurth | 0ddd4fa | 2021-07-14 17:35:37 -0500 | [diff] [blame] | 10 | |
Adriana Kobylak | 8bc2ab4 | 2020-07-15 09:16:27 -0500 | [diff] [blame] | 11 | namespace openpower |
| 12 | { |
| 13 | namespace software |
| 14 | { |
| 15 | namespace updater |
| 16 | { |
| 17 | |
| 18 | // These functions are just a stub (empty) because the current eMMC |
| 19 | // implementation uses the BMC updater (repo phosphor-bmc-code-mgmt) to write |
| 20 | // the new host FW to flash since it's delivered as a "System" image in the |
| 21 | // same BMC tarball as the BMC image. |
| 22 | |
| 23 | std::unique_ptr<Activation> ItemUpdaterMMC::createActivationObject( |
| 24 | const std::string& path, const std::string& versionId, |
| 25 | const std::string& extVersion, |
| 26 | sdbusplus::xyz::openbmc_project::Software::server::Activation::Activations |
| 27 | activationStatus, |
| 28 | AssociationList& assocs) |
| 29 | { |
| 30 | return std::make_unique<ActivationMMC>( |
| 31 | bus, path, *this, versionId, extVersion, activationStatus, assocs); |
| 32 | } |
| 33 | |
| 34 | std::unique_ptr<Version> ItemUpdaterMMC::createVersionObject( |
| 35 | const std::string& objPath, const std::string& versionId, |
| 36 | const std::string& versionString, |
| 37 | sdbusplus::xyz::openbmc_project::Software::server::Version::VersionPurpose |
| 38 | versionPurpose, |
| 39 | const std::string& filePath) |
| 40 | { |
| 41 | auto version = std::make_unique<Version>( |
| 42 | bus, objPath, *this, versionId, versionString, versionPurpose, filePath, |
| 43 | std::bind(&ItemUpdaterMMC::erase, this, std::placeholders::_1)); |
| 44 | version->deleteObject = std::make_unique<Delete>(bus, objPath, *version); |
| 45 | return version; |
| 46 | } |
| 47 | |
Brad Bishop | c8f2250 | 2020-11-06 14:42:09 -0500 | [diff] [blame] | 48 | bool ItemUpdaterMMC::validateImage(const std::string&) |
Adriana Kobylak | 8bc2ab4 | 2020-07-15 09:16:27 -0500 | [diff] [blame] | 49 | { |
| 50 | return true; |
| 51 | } |
| 52 | |
| 53 | void ItemUpdaterMMC::processPNORImage() |
Brad Bishop | 8facccf | 2020-11-04 09:44:58 -0500 | [diff] [blame] | 54 | {} |
Adriana Kobylak | 8bc2ab4 | 2020-07-15 09:16:27 -0500 | [diff] [blame] | 55 | |
| 56 | void ItemUpdaterMMC::reset() |
Isaac Kurth | 0ddd4fa | 2021-07-14 17:35:37 -0500 | [diff] [blame] | 57 | { |
| 58 | // Do not reset read-only files needed for reset or ext4 default files |
| 59 | const std::vector<std::string> exclusionList = { |
| 60 | "alternate", "hostfw-a", "hostfw-b", "lost+found", "running-ro"}; |
| 61 | std::filesystem::path dirPath(std::string(MEDIA_DIR "hostfw/")); |
| 62 | // Delete all files in /media/hostfw/ except for those on exclusionList |
| 63 | for (const auto& p : std::filesystem::directory_iterator(dirPath)) |
| 64 | { |
| 65 | if (std::find(exclusionList.begin(), exclusionList.end(), |
| 66 | p.path().stem().string()) == exclusionList.end()) |
| 67 | { |
| 68 | std::filesystem::remove_all(p); |
| 69 | } |
| 70 | } |
| 71 | |
Isaac Kurth | bde5d7d | 2021-09-14 18:40:25 +0000 | [diff] [blame^] | 72 | // Remove files related to the Hardware Management Console / BMC web app |
| 73 | std::filesystem::path consolePath("/var/lib/bmcweb/ibm-management-console"); |
| 74 | if (std::filesystem::exists(consolePath)) |
| 75 | { |
| 76 | std::filesystem::remove_all(consolePath); |
| 77 | } |
| 78 | |
| 79 | std::filesystem::path bmcdataPath("/home/root/bmcweb_persistent_data.json"); |
| 80 | if (std::filesystem::exists(bmcdataPath)) |
| 81 | { |
| 82 | std::filesystem::remove(bmcdataPath); |
| 83 | } |
| 84 | |
Isaac Kurth | 0ddd4fa | 2021-07-14 17:35:37 -0500 | [diff] [blame] | 85 | // Recreate default files. |
Isaac Kurth | bde5d7d | 2021-09-14 18:40:25 +0000 | [diff] [blame^] | 86 | const std::string services[] = {"obmc-flash-bios-init.service", |
| 87 | "obmc-flash-bios-patch.service", |
| 88 | "openpower-process-host-firmware.service", |
| 89 | "openpower-update-bios-attr-table.service", |
| 90 | "pldm-reset-phyp-nvram.service", |
| 91 | "pldm-reset-phyp-nvram-cksum.service"}; |
| 92 | |
Isaac Kurth | 0ddd4fa | 2021-07-14 17:35:37 -0500 | [diff] [blame] | 93 | auto bus = sdbusplus::bus::new_default(); |
Isaac Kurth | bde5d7d | 2021-09-14 18:40:25 +0000 | [diff] [blame^] | 94 | for (const auto& service : services) |
| 95 | { |
| 96 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 97 | SYSTEMD_INTERFACE, "StartUnit"); |
| 98 | method.append(service, "replace"); |
| 99 | // Ignore errors if the service is not found - not all systems |
| 100 | // may have these services |
| 101 | try |
| 102 | { |
| 103 | bus.call_noreply(method); |
| 104 | } |
| 105 | catch (const std::exception& e) |
| 106 | {} |
| 107 | } |
Isaac Kurth | 0ddd4fa | 2021-07-14 17:35:37 -0500 | [diff] [blame] | 108 | } |
Adriana Kobylak | 8bc2ab4 | 2020-07-15 09:16:27 -0500 | [diff] [blame] | 109 | |
| 110 | bool ItemUpdaterMMC::isVersionFunctional(const std::string& versionId) |
| 111 | { |
| 112 | return versionId == functionalVersionId; |
| 113 | } |
| 114 | |
Brad Bishop | c8f2250 | 2020-11-06 14:42:09 -0500 | [diff] [blame] | 115 | void ItemUpdaterMMC::freePriority(uint8_t, const std::string&) |
Brad Bishop | 8facccf | 2020-11-04 09:44:58 -0500 | [diff] [blame] | 116 | {} |
Adriana Kobylak | 8bc2ab4 | 2020-07-15 09:16:27 -0500 | [diff] [blame] | 117 | |
| 118 | void ItemUpdaterMMC::deleteAll() |
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 | bool ItemUpdaterMMC::freeSpace() |
| 122 | { |
| 123 | return true; |
| 124 | } |
| 125 | |
Brad Bishop | c8f2250 | 2020-11-06 14:42:09 -0500 | [diff] [blame] | 126 | void ItemUpdaterMMC::updateFunctionalAssociation(const std::string&) |
Brad Bishop | 8facccf | 2020-11-04 09:44:58 -0500 | [diff] [blame] | 127 | {} |
Adriana Kobylak | 8bc2ab4 | 2020-07-15 09:16:27 -0500 | [diff] [blame] | 128 | |
| 129 | void GardResetMMC::reset() |
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 | } // namespace updater |
| 133 | } // namespace software |
| 134 | } // namespace openpower |