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