Saqib Khan | 7254f0e | 2017-04-10 21:45:37 -0500 | [diff] [blame] | 1 | #include <string> |
Adriana Kobylak | 5ba6b10 | 2017-05-19 09:41:27 -0500 | [diff] [blame] | 2 | #include <experimental/filesystem> |
Saqib Khan | 7254f0e | 2017-04-10 21:45:37 -0500 | [diff] [blame] | 3 | #include <fstream> |
Gunnar Mills | fedbf3d | 2018-01-17 11:17:31 -0600 | [diff] [blame] | 4 | #include <queue> |
Eddie James | 13fc66a | 2017-08-31 15:36:44 -0500 | [diff] [blame] | 5 | #include <phosphor-logging/elog-errors.hpp> |
Adriana Kobylak | b66ac3a | 2017-03-28 13:33:20 -0500 | [diff] [blame] | 6 | #include <phosphor-logging/log.hpp> |
Eddie James | 13fc66a | 2017-08-31 15:36:44 -0500 | [diff] [blame] | 7 | #include "xyz/openbmc_project/Common/error.hpp" |
Adriana Kobylak | d6a549e | 2017-05-10 16:23:01 -0500 | [diff] [blame] | 8 | #include <xyz/openbmc_project/Software/Version/server.hpp> |
Saqib Khan | 167601b | 2017-06-18 23:33:46 -0500 | [diff] [blame] | 9 | #include "version.hpp" |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 10 | #include "config.h" |
| 11 | #include "item_updater.hpp" |
Saqib Khan | a8ade7e | 2017-04-12 10:27:56 -0500 | [diff] [blame] | 12 | #include "activation.hpp" |
Michael Tritz | 60bc20f | 2017-07-29 23:32:21 -0500 | [diff] [blame] | 13 | #include "serialize.hpp" |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 14 | |
| 15 | namespace openpower |
| 16 | { |
| 17 | namespace software |
| 18 | { |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 19 | namespace updater |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 20 | { |
| 21 | |
Saqib Khan | a8ade7e | 2017-04-12 10:27:56 -0500 | [diff] [blame] | 22 | // When you see server:: you know we're referencing our base class |
| 23 | namespace server = sdbusplus::xyz::openbmc_project::Software::server; |
Adriana Kobylak | 5ba6b10 | 2017-05-19 09:41:27 -0500 | [diff] [blame] | 24 | namespace fs = std::experimental::filesystem; |
Saqib Khan | a8ade7e | 2017-04-12 10:27:56 -0500 | [diff] [blame] | 25 | |
Eddie James | 13fc66a | 2017-08-31 15:36:44 -0500 | [diff] [blame] | 26 | using namespace sdbusplus::xyz::openbmc_project::Common::Error; |
Adriana Kobylak | b66ac3a | 2017-03-28 13:33:20 -0500 | [diff] [blame] | 27 | using namespace phosphor::logging; |
| 28 | |
Saqib Khan | a8ade7e | 2017-04-12 10:27:56 -0500 | [diff] [blame] | 29 | constexpr auto squashFSImage = "pnor.xz.squashfs"; |
| 30 | |
Michael Tritz | b541f1b | 2017-10-15 15:10:21 -0500 | [diff] [blame] | 31 | // TODO: Change paths once openbmc/openbmc#1663 is completed. |
| 32 | constexpr auto MBOXD_INTERFACE = "org.openbmc.mboxd"; |
| 33 | constexpr auto MBOXD_PATH = "/org/openbmc/mboxd"; |
| 34 | |
Adriana Kobylak | d6a549e | 2017-05-10 16:23:01 -0500 | [diff] [blame] | 35 | void ItemUpdater::createActivation(sdbusplus::message::message& m) |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 36 | { |
Patrick Williams | e429094 | 2017-06-16 05:43:08 -0500 | [diff] [blame] | 37 | using SVersion = server::Version; |
| 38 | using VersionPurpose = SVersion::VersionPurpose; |
| 39 | namespace msg = sdbusplus::message; |
| 40 | namespace variant_ns = msg::variant_ns; |
| 41 | |
Adriana Kobylak | d6a549e | 2017-05-10 16:23:01 -0500 | [diff] [blame] | 42 | sdbusplus::message::object_path objPath; |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 43 | std::map<std::string, std::map<std::string, msg::variant<std::string>>> |
| 44 | interfaces; |
Adriana Kobylak | d6a549e | 2017-05-10 16:23:01 -0500 | [diff] [blame] | 45 | m.read(objPath, interfaces); |
Patrick Williams | e429094 | 2017-06-16 05:43:08 -0500 | [diff] [blame] | 46 | |
Adriana Kobylak | d6a549e | 2017-05-10 16:23:01 -0500 | [diff] [blame] | 47 | std::string path(std::move(objPath)); |
Adriana Kobylak | 5ba6b10 | 2017-05-19 09:41:27 -0500 | [diff] [blame] | 48 | std::string filePath; |
Patrick Williams | e429094 | 2017-06-16 05:43:08 -0500 | [diff] [blame] | 49 | auto purpose = VersionPurpose::Unknown; |
Saqib Khan | ce14870 | 2017-06-11 12:01:58 -0500 | [diff] [blame] | 50 | std::string version; |
Adriana Kobylak | 5ba6b10 | 2017-05-19 09:41:27 -0500 | [diff] [blame] | 51 | |
Adriana Kobylak | d6a549e | 2017-05-10 16:23:01 -0500 | [diff] [blame] | 52 | for (const auto& intf : interfaces) |
Adriana Kobylak | b66ac3a | 2017-03-28 13:33:20 -0500 | [diff] [blame] | 53 | { |
Adriana Kobylak | d6a549e | 2017-05-10 16:23:01 -0500 | [diff] [blame] | 54 | if (intf.first == VERSION_IFACE) |
| 55 | { |
| 56 | for (const auto& property : intf.second) |
| 57 | { |
| 58 | if (property.first == "Purpose") |
| 59 | { |
| 60 | // Only process the Host and System images |
Patrick Williams | e429094 | 2017-06-16 05:43:08 -0500 | [diff] [blame] | 61 | auto value = SVersion::convertVersionPurposeFromString( |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 62 | variant_ns::get<std::string>(property.second)); |
Patrick Williams | e429094 | 2017-06-16 05:43:08 -0500 | [diff] [blame] | 63 | |
| 64 | if (value == VersionPurpose::Host || |
| 65 | value == VersionPurpose::System) |
Adriana Kobylak | d6a549e | 2017-05-10 16:23:01 -0500 | [diff] [blame] | 66 | { |
Saqib Khan | ce14870 | 2017-06-11 12:01:58 -0500 | [diff] [blame] | 67 | purpose = value; |
Adriana Kobylak | d6a549e | 2017-05-10 16:23:01 -0500 | [diff] [blame] | 68 | } |
| 69 | } |
Saqib Khan | ce14870 | 2017-06-11 12:01:58 -0500 | [diff] [blame] | 70 | else if (property.first == "Version") |
| 71 | { |
Patrick Williams | e429094 | 2017-06-16 05:43:08 -0500 | [diff] [blame] | 72 | version = variant_ns::get<std::string>(property.second); |
Saqib Khan | ce14870 | 2017-06-11 12:01:58 -0500 | [diff] [blame] | 73 | } |
Adriana Kobylak | d6a549e | 2017-05-10 16:23:01 -0500 | [diff] [blame] | 74 | } |
| 75 | } |
Adriana Kobylak | 5ba6b10 | 2017-05-19 09:41:27 -0500 | [diff] [blame] | 76 | else if (intf.first == FILEPATH_IFACE) |
| 77 | { |
| 78 | for (const auto& property : intf.second) |
| 79 | { |
| 80 | if (property.first == "Path") |
| 81 | { |
Patrick Williams | e429094 | 2017-06-16 05:43:08 -0500 | [diff] [blame] | 82 | filePath = variant_ns::get<std::string>(property.second); |
Adriana Kobylak | 5ba6b10 | 2017-05-19 09:41:27 -0500 | [diff] [blame] | 83 | } |
| 84 | } |
| 85 | } |
| 86 | } |
Patrick Williams | e429094 | 2017-06-16 05:43:08 -0500 | [diff] [blame] | 87 | if ((filePath.empty()) || (purpose == VersionPurpose::Unknown)) |
Adriana Kobylak | 5ba6b10 | 2017-05-19 09:41:27 -0500 | [diff] [blame] | 88 | { |
| 89 | return; |
Adriana Kobylak | b66ac3a | 2017-03-28 13:33:20 -0500 | [diff] [blame] | 90 | } |
| 91 | |
Adriana Kobylak | d6a549e | 2017-05-10 16:23:01 -0500 | [diff] [blame] | 92 | // Version id is the last item in the path |
| 93 | auto pos = path.rfind("/"); |
| 94 | if (pos == std::string::npos) |
Adriana Kobylak | b66ac3a | 2017-03-28 13:33:20 -0500 | [diff] [blame] | 95 | { |
Adriana Kobylak | d6a549e | 2017-05-10 16:23:01 -0500 | [diff] [blame] | 96 | log<level::ERR>("No version id found in object path", |
Joseph Reynolds | afd0a45 | 2018-05-30 11:16:03 -0500 | [diff] [blame] | 97 | entry("OBJPATH=%s", path.c_str())); |
Adriana Kobylak | d6a549e | 2017-05-10 16:23:01 -0500 | [diff] [blame] | 98 | return; |
| 99 | } |
| 100 | |
| 101 | auto versionId = path.substr(pos + 1); |
| 102 | |
| 103 | if (activations.find(versionId) == activations.end()) |
| 104 | { |
| 105 | // Determine the Activation state by processing the given image dir. |
| 106 | auto activationState = server::Activation::Activations::Invalid; |
Gunnar Mills | 3588acc | 2017-09-07 13:13:22 -0500 | [diff] [blame] | 107 | AssociationList associations = {}; |
Adriana Kobylak | 5ba6b10 | 2017-05-19 09:41:27 -0500 | [diff] [blame] | 108 | if (ItemUpdater::validateSquashFSImage(filePath) == 0) |
Adriana Kobylak | b66ac3a | 2017-03-28 13:33:20 -0500 | [diff] [blame] | 109 | { |
Adriana Kobylak | d6a549e | 2017-05-10 16:23:01 -0500 | [diff] [blame] | 110 | activationState = server::Activation::Activations::Ready; |
Gunnar Mills | 3588acc | 2017-09-07 13:13:22 -0500 | [diff] [blame] | 111 | // Create an association to the host inventory item |
| 112 | associations.emplace_back(std::make_tuple( |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 113 | ACTIVATION_FWD_ASSOCIATION, ACTIVATION_REV_ASSOCIATION, |
| 114 | HOST_INVENTORY_PATH)); |
Adriana Kobylak | b66ac3a | 2017-03-28 13:33:20 -0500 | [diff] [blame] | 115 | } |
| 116 | |
Adriana Kobylak | 5ba6b10 | 2017-05-19 09:41:27 -0500 | [diff] [blame] | 117 | fs::path manifestPath(filePath); |
| 118 | manifestPath /= MANIFEST_FILE; |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 119 | std::string extendedVersion = |
| 120 | (Version::getValue( |
| 121 | manifestPath.string(), |
| 122 | std::map<std::string, std::string>{{"extended_version", ""}})) |
| 123 | .begin() |
| 124 | ->second; |
Gunnar Mills | 3edb84b | 2017-08-18 15:13:15 -0500 | [diff] [blame] | 125 | |
Adriana Kobylak | d6a549e | 2017-05-10 16:23:01 -0500 | [diff] [blame] | 126 | activations.insert(std::make_pair( |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 127 | versionId, std::make_unique<Activation>( |
| 128 | bus, path, *this, versionId, extendedVersion, |
| 129 | activationState, associations))); |
Michael Tritz | 5b75651 | 2017-10-06 16:52:01 -0500 | [diff] [blame] | 130 | |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 131 | auto versionPtr = std::make_unique<Version>( |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 132 | bus, path, *this, versionId, version, purpose, filePath, |
| 133 | std::bind(&ItemUpdater::erase, this, std::placeholders::_1)); |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 134 | versionPtr->deleteObject = |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 135 | std::make_unique<Delete>(bus, path, *versionPtr); |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 136 | versions.insert(std::make_pair(versionId, std::move(versionPtr))); |
Saqib Khan | 00044f4 | 2017-07-10 17:24:43 -0500 | [diff] [blame] | 137 | } |
Patrick Williams | 3accb32 | 2017-05-30 16:29:52 -0500 | [diff] [blame] | 138 | return; |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 139 | } |
| 140 | |
Saqib Khan | 167601b | 2017-06-18 23:33:46 -0500 | [diff] [blame] | 141 | void ItemUpdater::processPNORImage() |
Saqib Khan | 7254f0e | 2017-04-10 21:45:37 -0500 | [diff] [blame] | 142 | { |
Saqib Khan | 4c5d744 | 2017-07-18 00:43:52 -0500 | [diff] [blame] | 143 | // Read pnor.toc from folders under /media/ |
| 144 | // to get Active Software Versions. |
Gunnar Mills | 3fa7028 | 2017-08-18 15:30:42 -0500 | [diff] [blame] | 145 | for (const auto& iter : fs::directory_iterator(MEDIA_DIR)) |
Saqib Khan | 4c5d744 | 2017-07-18 00:43:52 -0500 | [diff] [blame] | 146 | { |
| 147 | auto activationState = server::Activation::Activations::Active; |
| 148 | |
| 149 | static const auto PNOR_RO_PREFIX_LEN = strlen(PNOR_RO_PREFIX); |
Saqib Khan | 2be9ba9 | 2017-09-26 22:44:10 -0500 | [diff] [blame] | 150 | static const auto PNOR_RW_PREFIX_LEN = strlen(PNOR_RW_PREFIX); |
Saqib Khan | 4c5d744 | 2017-07-18 00:43:52 -0500 | [diff] [blame] | 151 | |
| 152 | // Check if the PNOR_RO_PREFIX is the prefix of the iter.path |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 153 | if (0 == |
| 154 | iter.path().native().compare(0, PNOR_RO_PREFIX_LEN, PNOR_RO_PREFIX)) |
Saqib Khan | 4c5d744 | 2017-07-18 00:43:52 -0500 | [diff] [blame] | 155 | { |
Saqib Khan | 6a52226 | 2017-09-26 12:02:50 -0500 | [diff] [blame] | 156 | // The versionId is extracted from the path |
| 157 | // for example /media/pnor-ro-2a1022fe. |
| 158 | auto id = iter.path().native().substr(PNOR_RO_PREFIX_LEN); |
Saqib Khan | 4c5d744 | 2017-07-18 00:43:52 -0500 | [diff] [blame] | 159 | auto pnorTOC = iter.path() / PNOR_TOC_FILE; |
| 160 | if (!fs::is_regular_file(pnorTOC)) |
| 161 | { |
Gunnar Mills | 850d5f6 | 2017-10-19 17:04:38 -0500 | [diff] [blame] | 162 | log<level::ERR>("Failed to read pnorTOC.", |
Joseph Reynolds | afd0a45 | 2018-05-30 11:16:03 -0500 | [diff] [blame] | 163 | entry("FILENAME=%s", pnorTOC.c_str())); |
Saqib Khan | 6a52226 | 2017-09-26 12:02:50 -0500 | [diff] [blame] | 164 | ItemUpdater::erase(id); |
| 165 | continue; |
Saqib Khan | 4c5d744 | 2017-07-18 00:43:52 -0500 | [diff] [blame] | 166 | } |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 167 | auto keyValues = Version::getValue( |
| 168 | pnorTOC, {{"version", ""}, {"extended_version", ""}}); |
Saqib Khan | 4c5d744 | 2017-07-18 00:43:52 -0500 | [diff] [blame] | 169 | auto& version = keyValues.at("version"); |
| 170 | if (version.empty()) |
| 171 | { |
| 172 | log<level::ERR>("Failed to read version from pnorTOC", |
Joseph Reynolds | afd0a45 | 2018-05-30 11:16:03 -0500 | [diff] [blame] | 173 | entry("FILENAME=%s", pnorTOC.c_str())); |
Saqib Khan | 4c5d744 | 2017-07-18 00:43:52 -0500 | [diff] [blame] | 174 | activationState = server::Activation::Activations::Invalid; |
| 175 | } |
| 176 | |
| 177 | auto& extendedVersion = keyValues.at("extended_version"); |
| 178 | if (extendedVersion.empty()) |
| 179 | { |
| 180 | log<level::ERR>("Failed to read extendedVersion from pnorTOC", |
Joseph Reynolds | afd0a45 | 2018-05-30 11:16:03 -0500 | [diff] [blame] | 181 | entry("FILENAME=%s", pnorTOC.c_str())); |
Saqib Khan | 4c5d744 | 2017-07-18 00:43:52 -0500 | [diff] [blame] | 182 | activationState = server::Activation::Activations::Invalid; |
| 183 | } |
| 184 | |
Saqib Khan | 4c5d744 | 2017-07-18 00:43:52 -0500 | [diff] [blame] | 185 | auto purpose = server::Version::VersionPurpose::Host; |
| 186 | auto path = fs::path(SOFTWARE_OBJPATH) / id; |
Gunnar Mills | 3588acc | 2017-09-07 13:13:22 -0500 | [diff] [blame] | 187 | AssociationList associations = {}; |
Saqib Khan | 4c5d744 | 2017-07-18 00:43:52 -0500 | [diff] [blame] | 188 | |
Gunnar Mills | 3588acc | 2017-09-07 13:13:22 -0500 | [diff] [blame] | 189 | if (activationState == server::Activation::Activations::Active) |
| 190 | { |
| 191 | // Create an association to the host inventory item |
| 192 | associations.emplace_back(std::make_tuple( |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 193 | ACTIVATION_FWD_ASSOCIATION, ACTIVATION_REV_ASSOCIATION, |
| 194 | HOST_INVENTORY_PATH)); |
Gunnar Mills | 3edb84b | 2017-08-18 15:13:15 -0500 | [diff] [blame] | 195 | |
Gunnar Mills | 3588acc | 2017-09-07 13:13:22 -0500 | [diff] [blame] | 196 | // Create an active association since this image is active |
| 197 | createActiveAssociation(path); |
| 198 | } |
Gunnar Mills | 3edb84b | 2017-08-18 15:13:15 -0500 | [diff] [blame] | 199 | |
Saqib Khan | 4c5d744 | 2017-07-18 00:43:52 -0500 | [diff] [blame] | 200 | // Create Activation instance for this version. |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 201 | activations.insert( |
| 202 | std::make_pair(id, std::make_unique<Activation>( |
| 203 | bus, path, *this, id, extendedVersion, |
| 204 | activationState, associations))); |
Saqib Khan | 4c5d744 | 2017-07-18 00:43:52 -0500 | [diff] [blame] | 205 | |
| 206 | // If Active, create RedundancyPriority instance for this version. |
| 207 | if (activationState == server::Activation::Activations::Active) |
| 208 | { |
Michael Tritz | 3641792 | 2017-08-04 14:00:29 -0500 | [diff] [blame] | 209 | uint8_t priority = std::numeric_limits<uint8_t>::max(); |
| 210 | if (!restoreFromFile(id, priority)) |
Saqib Khan | 4c5d744 | 2017-07-18 00:43:52 -0500 | [diff] [blame] | 211 | { |
Michael Tritz | 3641792 | 2017-08-04 14:00:29 -0500 | [diff] [blame] | 212 | log<level::ERR>("Unable to restore priority from file.", |
Joseph Reynolds | afd0a45 | 2018-05-30 11:16:03 -0500 | [diff] [blame] | 213 | entry("VERSIONID=%s", id.c_str())); |
Saqib Khan | 4c5d744 | 2017-07-18 00:43:52 -0500 | [diff] [blame] | 214 | } |
Michael Tritz | 3641792 | 2017-08-04 14:00:29 -0500 | [diff] [blame] | 215 | activations.find(id)->second->redundancyPriority = |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 216 | std::make_unique<RedundancyPriority>( |
| 217 | bus, path, *(activations.find(id)->second), priority); |
Saqib Khan | 4c5d744 | 2017-07-18 00:43:52 -0500 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | // Create Version instance for this version. |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 221 | auto versionPtr = std::make_unique<Version>( |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 222 | bus, path, *this, id, version, purpose, "", |
| 223 | std::bind(&ItemUpdater::erase, this, std::placeholders::_1)); |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 224 | versionPtr->deleteObject = |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 225 | std::make_unique<Delete>(bus, path, *versionPtr); |
| 226 | versions.insert(std::make_pair(id, std::move(versionPtr))); |
Saqib Khan | 4c5d744 | 2017-07-18 00:43:52 -0500 | [diff] [blame] | 227 | } |
Saqib Khan | 2be9ba9 | 2017-09-26 22:44:10 -0500 | [diff] [blame] | 228 | else if (0 == iter.path().native().compare(0, PNOR_RW_PREFIX_LEN, |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 229 | PNOR_RW_PREFIX)) |
Saqib Khan | 2be9ba9 | 2017-09-26 22:44:10 -0500 | [diff] [blame] | 230 | { |
| 231 | auto id = iter.path().native().substr(PNOR_RW_PREFIX_LEN); |
| 232 | auto roDir = PNOR_RO_PREFIX + id; |
| 233 | if (!fs::is_directory(roDir)) |
| 234 | { |
| 235 | log<level::ERR>("No corresponding read-only volume found.", |
Joseph Reynolds | afd0a45 | 2018-05-30 11:16:03 -0500 | [diff] [blame] | 236 | entry("DIRNAME=%s", roDir.c_str())); |
Saqib Khan | 2be9ba9 | 2017-09-26 22:44:10 -0500 | [diff] [blame] | 237 | ItemUpdater::erase(id); |
| 238 | } |
| 239 | } |
Saqib Khan | 4c5d744 | 2017-07-18 00:43:52 -0500 | [diff] [blame] | 240 | } |
Gunnar Mills | 2badd7a | 2017-09-20 12:51:28 -0500 | [diff] [blame] | 241 | |
| 242 | // Look at the RO symlink to determine if there is a functional image |
| 243 | auto id = determineId(PNOR_RO_ACTIVE_PATH); |
| 244 | if (!id.empty()) |
| 245 | { |
| 246 | updateFunctionalAssociation(std::string{SOFTWARE_OBJPATH} + '/' + id); |
| 247 | } |
Saqib Khan | 167601b | 2017-06-18 23:33:46 -0500 | [diff] [blame] | 248 | return; |
Saqib Khan | 7254f0e | 2017-04-10 21:45:37 -0500 | [diff] [blame] | 249 | } |
| 250 | |
Adriana Kobylak | 5ba6b10 | 2017-05-19 09:41:27 -0500 | [diff] [blame] | 251 | int ItemUpdater::validateSquashFSImage(const std::string& filePath) |
Saqib Khan | a8ade7e | 2017-04-12 10:27:56 -0500 | [diff] [blame] | 252 | { |
Saqib Khan | 4c5d744 | 2017-07-18 00:43:52 -0500 | [diff] [blame] | 253 | auto file = fs::path(filePath) / squashFSImage; |
| 254 | if (fs::is_regular_file(file)) |
Saqib Khan | a8ade7e | 2017-04-12 10:27:56 -0500 | [diff] [blame] | 255 | { |
| 256 | return 0; |
| 257 | } |
| 258 | else |
| 259 | { |
| 260 | log<level::ERR>("Failed to find the SquashFS image."); |
| 261 | return -1; |
| 262 | } |
| 263 | } |
| 264 | |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 265 | void ItemUpdater::removeReadOnlyPartition(std::string versionId) |
Michael Tritz | dd961b6 | 2017-05-17 14:07:03 -0500 | [diff] [blame] | 266 | { |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 267 | auto serviceFile = "obmc-flash-bios-ubiumount-ro@" + versionId + ".service"; |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 268 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 269 | // Remove the read-only partitions. |
| 270 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 271 | SYSTEMD_INTERFACE, "StartUnit"); |
| 272 | method.append(serviceFile, "replace"); |
| 273 | bus.call_noreply(method); |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | void ItemUpdater::removeReadWritePartition(std::string versionId) |
| 277 | { |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 278 | auto serviceFile = "obmc-flash-bios-ubiumount-rw@" + versionId + ".service"; |
Michael Tritz | dd961b6 | 2017-05-17 14:07:03 -0500 | [diff] [blame] | 279 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 280 | // Remove the read-write partitions. |
| 281 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 282 | SYSTEMD_INTERFACE, "StartUnit"); |
| 283 | method.append(serviceFile, "replace"); |
| 284 | bus.call_noreply(method); |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 285 | } |
Michael Tritz | dd961b6 | 2017-05-17 14:07:03 -0500 | [diff] [blame] | 286 | |
Michael Tritz | fa7aa12 | 2017-09-22 15:16:11 -0500 | [diff] [blame] | 287 | void ItemUpdater::reset() |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 288 | { |
Michael Tritz | bb31f02 | 2017-11-22 11:51:29 -0600 | [diff] [blame] | 289 | constexpr static auto patchDir = "/usr/local/share/pnor"; |
| 290 | if (fs::is_directory(patchDir)) |
| 291 | { |
| 292 | for (const auto& iter : fs::directory_iterator(patchDir)) |
| 293 | { |
| 294 | fs::remove_all(iter); |
| 295 | } |
| 296 | } |
| 297 | |
Michael Tritz | fa7aa12 | 2017-09-22 15:16:11 -0500 | [diff] [blame] | 298 | for (const auto& it : activations) |
| 299 | { |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 300 | auto serviceFile = |
| 301 | "obmc-flash-bios-ubiclear@pnor-rw-" + it.first + ".service"; |
Michael Tritz | fa7aa12 | 2017-09-22 15:16:11 -0500 | [diff] [blame] | 302 | |
| 303 | // Clear the read-write partitions. |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 304 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 305 | SYSTEMD_INTERFACE, "StartUnit"); |
Michael Tritz | fa7aa12 | 2017-09-22 15:16:11 -0500 | [diff] [blame] | 306 | method.append(serviceFile, "replace"); |
| 307 | auto reply = bus.call(method); |
| 308 | |
| 309 | if (reply.is_method_error()) |
| 310 | { |
Marri Devender Rao | 795d984 | 2017-11-07 22:52:07 -0600 | [diff] [blame] | 311 | log<level::ERR>("Failed to clear read-write partitions", |
Joseph Reynolds | afd0a45 | 2018-05-30 11:16:03 -0500 | [diff] [blame] | 312 | entry("SERVICE_FILE=%s", serviceFile.c_str())); |
Michael Tritz | fa7aa12 | 2017-09-22 15:16:11 -0500 | [diff] [blame] | 313 | elog<InternalFailure>(); |
| 314 | } |
Michael Tritz | fa7aa12 | 2017-09-22 15:16:11 -0500 | [diff] [blame] | 315 | } |
Marri Devender Rao | 795d984 | 2017-11-07 22:52:07 -0600 | [diff] [blame] | 316 | static constexpr auto serviceFile = |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 317 | "obmc-flash-bios-ubiclear@pnor-prsv.service"; |
Michael Tritz | fa7aa12 | 2017-09-22 15:16:11 -0500 | [diff] [blame] | 318 | // Clear the preserved partition. |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 319 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 320 | SYSTEMD_INTERFACE, "StartUnit"); |
Marri Devender Rao | 795d984 | 2017-11-07 22:52:07 -0600 | [diff] [blame] | 321 | method.append(serviceFile, "replace"); |
Michael Tritz | fa7aa12 | 2017-09-22 15:16:11 -0500 | [diff] [blame] | 322 | auto reply = bus.call(method); |
Michael Tritz | dd961b6 | 2017-05-17 14:07:03 -0500 | [diff] [blame] | 323 | |
Michael Tritz | fa7aa12 | 2017-09-22 15:16:11 -0500 | [diff] [blame] | 324 | if (reply.is_method_error()) |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 325 | { |
Marri Devender Rao | 795d984 | 2017-11-07 22:52:07 -0600 | [diff] [blame] | 326 | log<level::ERR>("Failed to clear preserved partition", |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 327 | entry("SERVICE_FILE=%s", serviceFile)); |
Michael Tritz | fa7aa12 | 2017-09-22 15:16:11 -0500 | [diff] [blame] | 328 | elog<InternalFailure>(); |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 329 | } |
Michael Tritz | fa7aa12 | 2017-09-22 15:16:11 -0500 | [diff] [blame] | 330 | |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 331 | return; |
| 332 | } |
| 333 | |
Michael Tritz | 5b75651 | 2017-10-06 16:52:01 -0500 | [diff] [blame] | 334 | bool ItemUpdater::isVersionFunctional(const std::string& versionId) |
Eddie James | 13fc66a | 2017-08-31 15:36:44 -0500 | [diff] [blame] | 335 | { |
| 336 | if (!fs::exists(PNOR_RO_ACTIVE_PATH)) |
| 337 | { |
| 338 | return false; |
| 339 | } |
| 340 | |
| 341 | fs::path activeRO = fs::read_symlink(PNOR_RO_ACTIVE_PATH); |
| 342 | |
| 343 | if (!fs::is_directory(activeRO)) |
| 344 | { |
| 345 | return false; |
| 346 | } |
| 347 | |
| 348 | if (activeRO.string().find(versionId) == std::string::npos) |
| 349 | { |
| 350 | return false; |
| 351 | } |
| 352 | |
| 353 | // active PNOR is the version we're checking |
| 354 | return true; |
| 355 | } |
| 356 | |
| 357 | bool ItemUpdater::isChassisOn() |
| 358 | { |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 359 | auto mapperCall = bus.new_method_call(MAPPER_BUSNAME, MAPPER_PATH, |
| 360 | MAPPER_INTERFACE, "GetObject"); |
Eddie James | 13fc66a | 2017-08-31 15:36:44 -0500 | [diff] [blame] | 361 | |
| 362 | mapperCall.append(CHASSIS_STATE_PATH, |
| 363 | std::vector<std::string>({CHASSIS_STATE_OBJ})); |
| 364 | auto mapperResponseMsg = bus.call(mapperCall); |
| 365 | if (mapperResponseMsg.is_method_error()) |
| 366 | { |
| 367 | log<level::ERR>("Error in Mapper call"); |
| 368 | elog<InternalFailure>(); |
| 369 | } |
| 370 | using MapperResponseType = std::map<std::string, std::vector<std::string>>; |
| 371 | MapperResponseType mapperResponse; |
| 372 | mapperResponseMsg.read(mapperResponse); |
| 373 | if (mapperResponse.empty()) |
| 374 | { |
| 375 | log<level::ERR>("Invalid Response from mapper"); |
| 376 | elog<InternalFailure>(); |
| 377 | } |
| 378 | |
| 379 | auto method = bus.new_method_call((mapperResponse.begin()->first).c_str(), |
| 380 | CHASSIS_STATE_PATH, |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 381 | SYSTEMD_PROPERTY_INTERFACE, "Get"); |
Eddie James | 13fc66a | 2017-08-31 15:36:44 -0500 | [diff] [blame] | 382 | method.append(CHASSIS_STATE_OBJ, "CurrentPowerState"); |
| 383 | auto response = bus.call(method); |
| 384 | if (response.is_method_error()) |
| 385 | { |
| 386 | log<level::ERR>("Error in fetching current Chassis State", |
Gunnar Mills | 850d5f6 | 2017-10-19 17:04:38 -0500 | [diff] [blame] | 387 | entry("MAPPERRESPONSE=%s", |
Eddie James | 13fc66a | 2017-08-31 15:36:44 -0500 | [diff] [blame] | 388 | (mapperResponse.begin()->first).c_str())); |
| 389 | elog<InternalFailure>(); |
| 390 | } |
| 391 | sdbusplus::message::variant<std::string> currentChassisState; |
| 392 | response.read(currentChassisState); |
| 393 | auto strParam = |
| 394 | sdbusplus::message::variant_ns::get<std::string>(currentChassisState); |
| 395 | return (strParam != CHASSIS_STATE_OFF); |
| 396 | } |
| 397 | |
Saqib Khan | b8e7f31 | 2017-08-12 10:24:10 -0500 | [diff] [blame] | 398 | void ItemUpdater::freePriority(uint8_t value, const std::string& versionId) |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 399 | { |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 400 | // TODO openbmc/openbmc#1896 Improve the performance of this function |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 401 | for (const auto& intf : activations) |
| 402 | { |
Gunnar Mills | 3fa7028 | 2017-08-18 15:30:42 -0500 | [diff] [blame] | 403 | if (intf.second->redundancyPriority) |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 404 | { |
Saqib Khan | b8e7f31 | 2017-08-12 10:24:10 -0500 | [diff] [blame] | 405 | if (intf.second->redundancyPriority.get()->priority() == value && |
| 406 | intf.second->versionId != versionId) |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 407 | { |
Gunnar Mills | 3fa7028 | 2017-08-18 15:30:42 -0500 | [diff] [blame] | 408 | intf.second->redundancyPriority.get()->priority(value + 1); |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 409 | } |
| 410 | } |
| 411 | } |
| 412 | } |
| 413 | |
Saqib Khan | 2af5c49 | 2017-07-17 16:15:13 -0500 | [diff] [blame] | 414 | bool ItemUpdater::isLowestPriority(uint8_t value) |
| 415 | { |
| 416 | for (const auto& intf : activations) |
| 417 | { |
Gunnar Mills | 3fa7028 | 2017-08-18 15:30:42 -0500 | [diff] [blame] | 418 | if (intf.second->redundancyPriority) |
Saqib Khan | 2af5c49 | 2017-07-17 16:15:13 -0500 | [diff] [blame] | 419 | { |
| 420 | if (intf.second->redundancyPriority.get()->priority() < value) |
| 421 | { |
| 422 | return false; |
| 423 | } |
| 424 | } |
| 425 | } |
| 426 | return true; |
| 427 | } |
| 428 | |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 429 | void ItemUpdater::erase(std::string entryId) |
| 430 | { |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 431 | if (isVersionFunctional(entryId) && isChassisOn()) |
| 432 | { |
| 433 | log<level::ERR>(("Error: Version " + entryId + |
| 434 | " is currently active and running on the host." |
| 435 | " Unable to remove.") |
| 436 | .c_str()); |
Eddie James | 13fc66a | 2017-08-31 15:36:44 -0500 | [diff] [blame] | 437 | return; |
| 438 | } |
Saqib Khan | ef8cd9f | 2017-08-16 14:20:30 -0500 | [diff] [blame] | 439 | // Remove priority persistence file |
| 440 | removeFile(entryId); |
| 441 | |
Saqib Khan | 1e0aa5c | 2017-08-31 11:04:17 -0500 | [diff] [blame] | 442 | // Removing read-only and read-write partitions |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 443 | removeReadWritePartition(entryId); |
| 444 | removeReadOnlyPartition(entryId); |
| 445 | |
| 446 | // Removing entry in versions map |
| 447 | auto it = versions.find(entryId); |
| 448 | if (it == versions.end()) |
| 449 | { |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 450 | log<level::ERR>(("Error: Failed to find version " + entryId + |
| 451 | " in item updater versions map." |
| 452 | " Unable to remove.") |
| 453 | .c_str()); |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 454 | } |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 455 | else |
| 456 | { |
| 457 | versions.erase(entryId); |
| 458 | } |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 459 | |
| 460 | // Removing entry in activations map |
| 461 | auto ita = activations.find(entryId); |
| 462 | if (ita == activations.end()) |
| 463 | { |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 464 | log<level::ERR>(("Error: Failed to find version " + entryId + |
| 465 | " in item updater activations map." |
| 466 | " Unable to remove.") |
| 467 | .c_str()); |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 468 | } |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 469 | else |
| 470 | { |
| 471 | activations.erase(entryId); |
| 472 | } |
| 473 | return; |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 474 | } |
| 475 | |
Michael Tritz | 234a07e | 2017-09-21 00:53:06 -0500 | [diff] [blame] | 476 | void ItemUpdater::deleteAll() |
| 477 | { |
Michael Tritz | 234a07e | 2017-09-21 00:53:06 -0500 | [diff] [blame] | 478 | for (const auto& activationIt : activations) |
| 479 | { |
| 480 | if (!isVersionFunctional(activationIt.first)) |
| 481 | { |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 482 | ItemUpdater::erase(activationIt.first); |
Michael Tritz | 234a07e | 2017-09-21 00:53:06 -0500 | [diff] [blame] | 483 | } |
| 484 | } |
| 485 | |
Michael Tritz | 234a07e | 2017-09-21 00:53:06 -0500 | [diff] [blame] | 486 | // Remove any remaining pnor-ro- or pnor-rw- volumes that do not match |
| 487 | // the current version. |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 488 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 489 | SYSTEMD_INTERFACE, "StartUnit"); |
Michael Tritz | 234a07e | 2017-09-21 00:53:06 -0500 | [diff] [blame] | 490 | method.append("obmc-flash-bios-cleanup.service", "replace"); |
| 491 | bus.call_noreply(method); |
| 492 | } |
| 493 | |
Saqib Khan | 2cbfa03 | 2017-08-17 14:52:37 -0500 | [diff] [blame] | 494 | // TODO: openbmc/openbmc#1402 Monitor flash usage |
| 495 | void ItemUpdater::freeSpace() |
| 496 | { |
Gunnar Mills | fedbf3d | 2018-01-17 11:17:31 -0600 | [diff] [blame] | 497 | // Versions with the highest priority in front |
| 498 | std::priority_queue<std::pair<int, std::string>, |
| 499 | std::vector<std::pair<int, std::string>>, |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 500 | std::less<std::pair<int, std::string>>> |
| 501 | versionsPQ; |
Gunnar Mills | fedbf3d | 2018-01-17 11:17:31 -0600 | [diff] [blame] | 502 | |
Saqib Khan | 2cbfa03 | 2017-08-17 14:52:37 -0500 | [diff] [blame] | 503 | std::size_t count = 0; |
Saqib Khan | 2cbfa03 | 2017-08-17 14:52:37 -0500 | [diff] [blame] | 504 | for (const auto& iter : activations) |
| 505 | { |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 506 | if (iter.second.get()->activation() == |
| 507 | server::Activation::Activations::Active) |
Saqib Khan | 2cbfa03 | 2017-08-17 14:52:37 -0500 | [diff] [blame] | 508 | { |
| 509 | count++; |
Gunnar Mills | fedbf3d | 2018-01-17 11:17:31 -0600 | [diff] [blame] | 510 | // Don't put the functional version on the queue since we can't |
| 511 | // remove the "running" PNOR version. |
Adriana Kobylak | ee201a5 | 2017-11-09 15:05:04 -0600 | [diff] [blame] | 512 | if (isVersionFunctional(iter.second->versionId)) |
| 513 | { |
| 514 | continue; |
| 515 | } |
Gunnar Mills | fedbf3d | 2018-01-17 11:17:31 -0600 | [diff] [blame] | 516 | versionsPQ.push(std::make_pair( |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 517 | iter.second->redundancyPriority.get()->priority(), |
| 518 | iter.second->versionId)); |
Saqib Khan | 2cbfa03 | 2017-08-17 14:52:37 -0500 | [diff] [blame] | 519 | } |
| 520 | } |
Gunnar Mills | fedbf3d | 2018-01-17 11:17:31 -0600 | [diff] [blame] | 521 | |
| 522 | // If the number of PNOR versions is over ACTIVE_PNOR_MAX_ALLOWED -1, |
| 523 | // remove the highest priority one(s). |
| 524 | while ((count >= ACTIVE_PNOR_MAX_ALLOWED) && (!versionsPQ.empty())) |
Saqib Khan | 2cbfa03 | 2017-08-17 14:52:37 -0500 | [diff] [blame] | 525 | { |
Gunnar Mills | fedbf3d | 2018-01-17 11:17:31 -0600 | [diff] [blame] | 526 | erase(versionsPQ.top().second); |
| 527 | versionsPQ.pop(); |
| 528 | count--; |
Saqib Khan | 2cbfa03 | 2017-08-17 14:52:37 -0500 | [diff] [blame] | 529 | } |
| 530 | } |
| 531 | |
Gunnar Mills | 61010b2 | 2017-09-20 15:25:26 -0500 | [diff] [blame] | 532 | void ItemUpdater::createActiveAssociation(const std::string& path) |
Gunnar Mills | 9741cd1 | 2017-08-28 15:09:00 -0500 | [diff] [blame] | 533 | { |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 534 | assocs.emplace_back( |
| 535 | std::make_tuple(ACTIVE_FWD_ASSOCIATION, ACTIVE_REV_ASSOCIATION, path)); |
Gunnar Mills | 9741cd1 | 2017-08-28 15:09:00 -0500 | [diff] [blame] | 536 | associations(assocs); |
| 537 | } |
| 538 | |
Gunnar Mills | 833e4f3 | 2017-09-14 12:30:27 -0500 | [diff] [blame] | 539 | void ItemUpdater::updateFunctionalAssociation(const std::string& path) |
| 540 | { |
| 541 | // remove all functional associations |
| 542 | for (auto iter = assocs.begin(); iter != assocs.end();) |
| 543 | { |
| 544 | if ((std::get<0>(*iter)).compare(FUNCTIONAL_FWD_ASSOCIATION) == 0) |
| 545 | { |
| 546 | iter = assocs.erase(iter); |
| 547 | } |
| 548 | else |
| 549 | { |
| 550 | ++iter; |
| 551 | } |
| 552 | } |
| 553 | assocs.emplace_back(std::make_tuple(FUNCTIONAL_FWD_ASSOCIATION, |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 554 | FUNCTIONAL_REV_ASSOCIATION, path)); |
Gunnar Mills | 833e4f3 | 2017-09-14 12:30:27 -0500 | [diff] [blame] | 555 | associations(assocs); |
| 556 | } |
| 557 | |
Gunnar Mills | 61010b2 | 2017-09-20 15:25:26 -0500 | [diff] [blame] | 558 | void ItemUpdater::removeActiveAssociation(const std::string& path) |
Gunnar Mills | 9741cd1 | 2017-08-28 15:09:00 -0500 | [diff] [blame] | 559 | { |
| 560 | for (auto iter = assocs.begin(); iter != assocs.end();) |
| 561 | { |
Gunnar Mills | 833e4f3 | 2017-09-14 12:30:27 -0500 | [diff] [blame] | 562 | if ((std::get<0>(*iter)).compare(ACTIVE_FWD_ASSOCIATION) == 0 && |
| 563 | (std::get<2>(*iter)).compare(path) == 0) |
Gunnar Mills | 9741cd1 | 2017-08-28 15:09:00 -0500 | [diff] [blame] | 564 | { |
| 565 | iter = assocs.erase(iter); |
| 566 | associations(assocs); |
| 567 | } |
| 568 | else |
| 569 | { |
| 570 | ++iter; |
| 571 | } |
| 572 | } |
| 573 | } |
| 574 | |
Gunnar Mills | 2badd7a | 2017-09-20 12:51:28 -0500 | [diff] [blame] | 575 | std::string ItemUpdater::determineId(const std::string& symlinkPath) |
| 576 | { |
| 577 | if (!fs::exists(symlinkPath)) |
| 578 | { |
| 579 | return {}; |
| 580 | } |
| 581 | |
| 582 | auto target = fs::canonical(symlinkPath).string(); |
| 583 | |
| 584 | // check to make sure the target really exists |
| 585 | if (!fs::is_regular_file(target + "/" + PNOR_TOC_FILE)) |
| 586 | { |
| 587 | return {}; |
| 588 | } |
| 589 | // Get the image <id> from the symlink target |
| 590 | // for example /media/ro-2a1022fe |
| 591 | static const auto PNOR_RO_PREFIX_LEN = strlen(PNOR_RO_PREFIX); |
| 592 | return target.substr(PNOR_RO_PREFIX_LEN); |
| 593 | } |
| 594 | |
Michael Tritz | b541f1b | 2017-10-15 15:10:21 -0500 | [diff] [blame] | 595 | void GardReset::reset() |
| 596 | { |
| 597 | // The GARD partition is currently misspelled "GUARD." This file path will |
| 598 | // need to be updated in the future. |
| 599 | auto path = fs::path(PNOR_PRSV_ACTIVE_PATH); |
| 600 | path /= "GUARD"; |
| 601 | std::vector<uint8_t> mboxdArgs; |
| 602 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 603 | auto dbusCall = bus.new_method_call(MBOXD_INTERFACE, MBOXD_PATH, |
| 604 | MBOXD_INTERFACE, "cmd"); |
Michael Tritz | b541f1b | 2017-10-15 15:10:21 -0500 | [diff] [blame] | 605 | |
| 606 | // Suspend mboxd - no args required. |
| 607 | dbusCall.append(static_cast<uint8_t>(3), mboxdArgs); |
| 608 | |
| 609 | auto responseMsg = bus.call(dbusCall); |
| 610 | if (responseMsg.is_method_error()) |
| 611 | { |
| 612 | log<level::ERR>("Error in mboxd suspend call"); |
| 613 | elog<InternalFailure>(); |
| 614 | } |
| 615 | |
| 616 | if (fs::is_regular_file(path)) |
| 617 | { |
| 618 | fs::remove(path); |
| 619 | } |
| 620 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 621 | dbusCall = bus.new_method_call(MBOXD_INTERFACE, MBOXD_PATH, MBOXD_INTERFACE, |
| 622 | "cmd"); |
Michael Tritz | b541f1b | 2017-10-15 15:10:21 -0500 | [diff] [blame] | 623 | |
| 624 | // Resume mboxd with arg 1, indicating that the flash is modified. |
| 625 | mboxdArgs.push_back(1); |
| 626 | dbusCall.append(static_cast<uint8_t>(4), mboxdArgs); |
| 627 | |
| 628 | responseMsg = bus.call(dbusCall); |
| 629 | if (responseMsg.is_method_error()) |
| 630 | { |
| 631 | log<level::ERR>("Error in mboxd resume call"); |
| 632 | elog<InternalFailure>(); |
| 633 | } |
| 634 | } |
| 635 | |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 636 | } // namespace updater |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 637 | } // namespace software |
| 638 | } // namespace openpower |