Gunnar Mills | b0ce996 | 2018-09-07 13:39:10 -0500 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
| 3 | #include "item_updater.hpp" |
| 4 | |
| 5 | #include "images.hpp" |
| 6 | #include "serialize.hpp" |
| 7 | #include "version.hpp" |
Chanh Nguyen | 1fd6ddd | 2021-01-06 11:09:09 +0700 | [diff] [blame] | 8 | #include "xyz/openbmc_project/Software/ExtendedVersion/server.hpp" |
Gunnar Mills | b0ce996 | 2018-09-07 13:39:10 -0500 | [diff] [blame] | 9 | #include "xyz/openbmc_project/Software/Version/server.hpp" |
| 10 | |
Adriana Kobylak | d5b8f75 | 2019-05-01 11:52:35 -0500 | [diff] [blame] | 11 | #include <phosphor-logging/elog-errors.hpp> |
Gunnar Mills | b0ce996 | 2018-09-07 13:39:10 -0500 | [diff] [blame] | 12 | #include <phosphor-logging/elog.hpp> |
Patrick Williams | c9bb642 | 2021-08-27 06:18:35 -0500 | [diff] [blame] | 13 | #include <phosphor-logging/lg2.hpp> |
Adriana Kobylak | 58aa750 | 2020-06-08 11:12:11 -0500 | [diff] [blame] | 14 | #include <xyz/openbmc_project/Common/error.hpp> |
| 15 | #include <xyz/openbmc_project/Software/Image/error.hpp> |
| 16 | |
| 17 | #include <filesystem> |
| 18 | #include <fstream> |
Adriana Kobylak | 204e1e7 | 2018-01-24 16:00:05 -0600 | [diff] [blame] | 19 | #include <queue> |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 20 | #include <set> |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 21 | #include <string> |
George Liu | 44b9fef | 2023-02-07 14:31:32 +0800 | [diff] [blame] | 22 | #include <system_error> |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 23 | |
| 24 | namespace phosphor |
| 25 | { |
| 26 | namespace software |
| 27 | { |
| 28 | namespace updater |
| 29 | { |
| 30 | |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 31 | // When you see server:: you know we're referencing our base class |
Patrick Williams | 1e9a5f1 | 2023-08-23 16:53:06 -0500 | [diff] [blame] | 32 | namespace server = sdbusplus::server::xyz::openbmc_project::software; |
| 33 | namespace control = sdbusplus::server::xyz::openbmc_project::control; |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 34 | |
Patrick Williams | c9bb642 | 2021-08-27 06:18:35 -0500 | [diff] [blame] | 35 | PHOSPHOR_LOG2_USING; |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 36 | using namespace phosphor::logging; |
Adriana Kobylak | ce82de5 | 2024-01-16 13:56:38 -0600 | [diff] [blame] | 37 | using namespace sdbusplus::error::xyz::openbmc_project::software::image; |
Jayanth Othayoth | 2ab9b10 | 2018-02-21 05:27:47 -0600 | [diff] [blame] | 38 | using namespace phosphor::software::image; |
Adriana Kobylak | c98d912 | 2020-05-05 10:36:01 -0500 | [diff] [blame] | 39 | namespace fs = std::filesystem; |
Adriana Kobylak | ce82de5 | 2024-01-16 13:56:38 -0600 | [diff] [blame] | 40 | using NotAllowed = sdbusplus::error::xyz::openbmc_project::common::NotAllowed; |
Saqib Khan | 35e83f3 | 2017-05-22 11:37:32 -0500 | [diff] [blame] | 41 | |
Patrick Williams | bf2bb2b | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 42 | void ItemUpdater::createActivation(sdbusplus::message_t& msg) |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 43 | { |
Saqib Khan | 84a0e69 | 2017-06-28 17:27:01 -0500 | [diff] [blame] | 44 | using SVersion = server::Version; |
| 45 | using VersionPurpose = SVersion::VersionPurpose; |
Saqib Khan | 84a0e69 | 2017-06-28 17:27:01 -0500 | [diff] [blame] | 46 | |
Patrick Williams | bc1facd | 2020-06-03 05:58:27 -0500 | [diff] [blame] | 47 | sdbusplus::message::object_path objPath; |
Saqib Khan | 84a0e69 | 2017-06-28 17:27:01 -0500 | [diff] [blame] | 48 | auto purpose = VersionPurpose::Unknown; |
Chanh Nguyen | 1fd6ddd | 2021-01-06 11:09:09 +0700 | [diff] [blame] | 49 | std::string extendedVersion; |
Saqib Khan | 705f1bf | 2017-06-09 23:58:38 -0500 | [diff] [blame] | 50 | std::string version; |
Justin Ledford | 054bb0b | 2022-03-15 15:46:58 -0700 | [diff] [blame] | 51 | std::map<std::string, |
| 52 | std::map<std::string, |
| 53 | std::variant<std::string, std::vector<std::string>>>> |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 54 | interfaces; |
Patrick Williams | e75d10f | 2017-05-30 16:56:32 -0500 | [diff] [blame] | 55 | msg.read(objPath, interfaces); |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 56 | std::string path(std::move(objPath)); |
Saqib Khan | 19177d3 | 2017-06-20 08:11:49 -0500 | [diff] [blame] | 57 | std::string filePath; |
Justin Ledford | 054bb0b | 2022-03-15 15:46:58 -0700 | [diff] [blame] | 58 | std::vector<std::string> compatibleNames; |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 59 | |
| 60 | for (const auto& intf : interfaces) |
| 61 | { |
Saqib Khan | 705f1bf | 2017-06-09 23:58:38 -0500 | [diff] [blame] | 62 | if (intf.first == VERSION_IFACE) |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 63 | { |
Saqib Khan | 705f1bf | 2017-06-09 23:58:38 -0500 | [diff] [blame] | 64 | for (const auto& property : intf.second) |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 65 | { |
Saqib Khan | 705f1bf | 2017-06-09 23:58:38 -0500 | [diff] [blame] | 66 | if (property.first == "Purpose") |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 67 | { |
Saqib Khan | 84a0e69 | 2017-06-28 17:27:01 -0500 | [diff] [blame] | 68 | auto value = SVersion::convertVersionPurposeFromString( |
Patrick Williams | e883fb8 | 2020-05-13 11:38:55 -0500 | [diff] [blame] | 69 | std::get<std::string>(property.second)); |
Saqib Khan | 84a0e69 | 2017-06-28 17:27:01 -0500 | [diff] [blame] | 70 | if (value == VersionPurpose::BMC || |
Vijay Khemka | e9f6c84 | 2020-01-14 14:32:39 -0800 | [diff] [blame] | 71 | #ifdef HOST_BIOS_UPGRADE |
| 72 | value == VersionPurpose::Host || |
| 73 | #endif |
Saqib Khan | 84a0e69 | 2017-06-28 17:27:01 -0500 | [diff] [blame] | 74 | value == VersionPurpose::System) |
| 75 | { |
| 76 | purpose = value; |
| 77 | } |
Saqib Khan | 705f1bf | 2017-06-09 23:58:38 -0500 | [diff] [blame] | 78 | } |
| 79 | else if (property.first == "Version") |
| 80 | { |
Patrick Williams | e883fb8 | 2020-05-13 11:38:55 -0500 | [diff] [blame] | 81 | version = std::get<std::string>(property.second); |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 82 | } |
| 83 | } |
| 84 | } |
Saqib Khan | 19177d3 | 2017-06-20 08:11:49 -0500 | [diff] [blame] | 85 | else if (intf.first == FILEPATH_IFACE) |
| 86 | { |
| 87 | for (const auto& property : intf.second) |
| 88 | { |
| 89 | if (property.first == "Path") |
| 90 | { |
Patrick Williams | e883fb8 | 2020-05-13 11:38:55 -0500 | [diff] [blame] | 91 | filePath = std::get<std::string>(property.second); |
Saqib Khan | 19177d3 | 2017-06-20 08:11:49 -0500 | [diff] [blame] | 92 | } |
| 93 | } |
| 94 | } |
Chanh Nguyen | 1fd6ddd | 2021-01-06 11:09:09 +0700 | [diff] [blame] | 95 | else if (intf.first == EXTENDED_VERSION_IFACE) |
| 96 | { |
| 97 | for (const auto& property : intf.second) |
| 98 | { |
| 99 | if (property.first == "ExtendedVersion") |
| 100 | { |
| 101 | extendedVersion = std::get<std::string>(property.second); |
| 102 | } |
| 103 | } |
| 104 | } |
Justin Ledford | 054bb0b | 2022-03-15 15:46:58 -0700 | [diff] [blame] | 105 | else if (intf.first == COMPATIBLE_IFACE) |
| 106 | { |
| 107 | for (const auto& property : intf.second) |
| 108 | { |
| 109 | if (property.first == "Names") |
| 110 | { |
| 111 | compatibleNames = |
| 112 | std::get<std::vector<std::string>>(property.second); |
| 113 | } |
| 114 | } |
| 115 | } |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 116 | } |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 117 | if (version.empty() || filePath.empty() || |
Saqib Khan | 84a0e69 | 2017-06-28 17:27:01 -0500 | [diff] [blame] | 118 | purpose == VersionPurpose::Unknown) |
Saqib Khan | 705f1bf | 2017-06-09 23:58:38 -0500 | [diff] [blame] | 119 | { |
| 120 | return; |
| 121 | } |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 122 | |
| 123 | // Version id is the last item in the path |
Pavithra Barithaya | 27d4938 | 2024-06-24 01:52:42 -0500 | [diff] [blame] | 124 | auto pos = path.rfind('/'); |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 125 | if (pos == std::string::npos) |
| 126 | { |
Patrick Williams | c9bb642 | 2021-08-27 06:18:35 -0500 | [diff] [blame] | 127 | error("No version id found in object path: {PATH}", "PATH", path); |
Patrick Williams | e75d10f | 2017-05-30 16:56:32 -0500 | [diff] [blame] | 128 | return; |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | auto versionId = path.substr(pos + 1); |
| 132 | |
Patrick Williams | e75d10f | 2017-05-30 16:56:32 -0500 | [diff] [blame] | 133 | if (activations.find(versionId) == activations.end()) |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 134 | { |
Jagpal Singh Gill | bb024eb | 2024-04-07 23:34:00 -0700 | [diff] [blame] | 135 | verifyAndCreateObjects(versionId, path, version, purpose, |
| 136 | extendedVersion, filePath, compatibleNames); |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 137 | } |
Patrick Williams | e75d10f | 2017-05-30 16:56:32 -0500 | [diff] [blame] | 138 | return; |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 139 | } |
| 140 | |
Jagpal Singh Gill | bb024eb | 2024-04-07 23:34:00 -0700 | [diff] [blame] | 141 | void ItemUpdater::createActivationWithApplyTime( |
| 142 | std::string& id, std::string& path, |
| 143 | ApplyTimeIntf::RequestedApplyTimes applyTime) |
| 144 | { |
| 145 | info("Creating Activation object for id: {ID}", "ID", id); |
| 146 | AssociationList associations = {}; |
| 147 | // Create an association to the BMC inventory item |
| 148 | associations.emplace_back( |
| 149 | std::make_tuple(ACTIVATION_FWD_ASSOCIATION, ACTIVATION_REV_ASSOCIATION, |
| 150 | bmcInventoryPath)); |
| 151 | activations.insert(std::make_pair( |
| 152 | id, std::make_unique<Activation>( |
| 153 | bus, path, *this, id, server::Activation::Activations::NotReady, |
| 154 | associations))); |
| 155 | activations[id]->applyTime = applyTime; |
| 156 | } |
| 157 | |
| 158 | ActivationIntf::Activations ItemUpdater::verifyAndCreateObjects( |
| 159 | std::string& id, std::string& path, std::string& version, |
| 160 | VersionClass::VersionPurpose purpose, std::string& extendedVersion, |
| 161 | std ::string& filePath, std::vector<std::string>& compatibleNames) |
| 162 | { |
| 163 | // Determine the Activation state by processing the given image dir. |
| 164 | auto activationState = server::Activation::Activations::Invalid; |
| 165 | ItemUpdater::ActivationStatus result; |
| 166 | if (purpose == VersionPurpose::BMC || purpose == VersionPurpose::System) |
| 167 | { |
| 168 | result = ItemUpdater::validateSquashFSImage(filePath); |
| 169 | } |
| 170 | else |
| 171 | { |
| 172 | result = ItemUpdater::ActivationStatus::ready; |
| 173 | } |
| 174 | |
| 175 | AssociationList associations = {}; |
| 176 | |
| 177 | if (result == ItemUpdater::ActivationStatus::ready) |
| 178 | { |
| 179 | activationState = server::Activation::Activations::Ready; |
| 180 | // Create an association to the BMC inventory item |
| 181 | associations.emplace_back( |
| 182 | std::make_tuple(ACTIVATION_FWD_ASSOCIATION, |
| 183 | ACTIVATION_REV_ASSOCIATION, bmcInventoryPath)); |
| 184 | } |
| 185 | |
| 186 | auto versionPtr = std::make_unique<VersionClass>( |
| 187 | bus, path, version, purpose, extendedVersion, filePath, compatibleNames, |
| 188 | std::bind(&ItemUpdater::erase, this, std::placeholders::_1), id); |
| 189 | versionPtr->deleteObject = |
| 190 | std::make_unique<phosphor::software::manager::Delete>( |
| 191 | bus, path, *versionPtr); |
| 192 | versions.insert(std::make_pair(id, std::move(versionPtr))); |
| 193 | |
| 194 | auto activation = activations.find(id); |
| 195 | if (activation == activations.end()) |
| 196 | { |
| 197 | activations.insert(std::make_pair( |
| 198 | id, std::make_unique<Activation>(bus, path, *this, id, |
| 199 | activationState, associations))); |
| 200 | } |
| 201 | else |
| 202 | { |
| 203 | activation->second->activation(activationState); |
| 204 | } |
| 205 | return activationState; |
| 206 | } |
| 207 | |
| 208 | bool ItemUpdater::requestActivation(std::string& id) |
| 209 | { |
| 210 | auto activation = activations.find(id); |
| 211 | if (activation == activations.end()) |
| 212 | { |
| 213 | error("Activation object not found for id: {ID}", "ID", id); |
| 214 | return false; |
| 215 | } |
| 216 | activation->second->requestedActivation( |
| 217 | server::Activation::RequestedActivations::Active); |
| 218 | return true; |
| 219 | } |
| 220 | |
| 221 | bool ItemUpdater::updateActivationStatus(std::string& id, |
| 222 | ActivationIntf::Activations status) |
| 223 | { |
| 224 | auto activation = activations.find(id); |
| 225 | if (activation == activations.end()) |
| 226 | { |
| 227 | error("Activation object not found for id: {ID}", "ID", id); |
| 228 | return false; |
| 229 | } |
| 230 | activation->second->activation(status); |
| 231 | return true; |
| 232 | } |
| 233 | |
Saqib Khan | ba23988 | 2017-05-26 08:41:54 -0500 | [diff] [blame] | 234 | void ItemUpdater::processBMCImage() |
| 235 | { |
Gunnar Mills | 88e8a32 | 2017-09-13 11:09:28 -0500 | [diff] [blame] | 236 | using VersionClass = phosphor::software::manager::Version; |
Lei YU | 269bff3 | 2018-08-21 15:21:40 +0800 | [diff] [blame] | 237 | |
| 238 | // Check MEDIA_DIR and create if it does not exist |
| 239 | try |
| 240 | { |
| 241 | if (!fs::is_directory(MEDIA_DIR)) |
| 242 | { |
| 243 | fs::create_directory(MEDIA_DIR); |
| 244 | } |
| 245 | } |
| 246 | catch (const fs::filesystem_error& e) |
| 247 | { |
Patrick Williams | c9bb642 | 2021-08-27 06:18:35 -0500 | [diff] [blame] | 248 | error("Failed to prepare dir: {ERROR}", "ERROR", e); |
Lei YU | 269bff3 | 2018-08-21 15:21:40 +0800 | [diff] [blame] | 249 | return; |
| 250 | } |
| 251 | |
Adriana Kobylak | 1e81f23 | 2022-01-18 22:28:47 +0000 | [diff] [blame] | 252 | // Functional images are mounted as rofs-<location>-functional |
| 253 | constexpr auto functionalSuffix = "-functional"; |
Lei YU | d474d9c | 2021-12-10 16:21:21 +0800 | [diff] [blame] | 254 | bool functionalFound = false; |
Gunnar Mills | 88e8a32 | 2017-09-13 11:09:28 -0500 | [diff] [blame] | 255 | |
Saqib Khan | 1eef62d | 2017-08-10 15:29:34 -0500 | [diff] [blame] | 256 | // Read os-release from folders under /media/ to get |
| 257 | // BMC Software Versions. |
George Liu | 44b9fef | 2023-02-07 14:31:32 +0800 | [diff] [blame] | 258 | std::error_code ec; |
| 259 | for (const auto& iter : fs::directory_iterator(MEDIA_DIR, ec)) |
Saqib Khan | 1eef62d | 2017-08-10 15:29:34 -0500 | [diff] [blame] | 260 | { |
| 261 | auto activationState = server::Activation::Activations::Active; |
Saqib Khan | 6fab70d | 2017-09-07 00:13:50 -0500 | [diff] [blame] | 262 | static const auto BMC_RO_PREFIX_LEN = strlen(BMC_ROFS_PREFIX); |
Saqib Khan | 1eef62d | 2017-08-10 15:29:34 -0500 | [diff] [blame] | 263 | |
| 264 | // Check if the BMC_RO_PREFIXis the prefix of the iter.path |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 265 | if (0 == |
| 266 | iter.path().native().compare(0, BMC_RO_PREFIX_LEN, BMC_ROFS_PREFIX)) |
Saqib Khan | 1eef62d | 2017-08-10 15:29:34 -0500 | [diff] [blame] | 267 | { |
Adriana Kobylak | 716cd78 | 2020-06-08 13:27:43 -0500 | [diff] [blame] | 268 | // Get the version to calculate the id |
Adriana Kobylak | 24a8d83 | 2020-06-10 08:29:36 -0500 | [diff] [blame] | 269 | fs::path releaseFile(OS_RELEASE_FILE); |
| 270 | auto osRelease = iter.path() / releaseFile.relative_path(); |
George Liu | 44b9fef | 2023-02-07 14:31:32 +0800 | [diff] [blame] | 271 | if (!fs::is_regular_file(osRelease, ec)) |
Saqib Khan | 1eef62d | 2017-08-10 15:29:34 -0500 | [diff] [blame] | 272 | { |
Lei YU | e56bf87 | 2022-02-22 18:40:37 +0800 | [diff] [blame] | 273 | #ifdef BMC_STATIC_DUAL_IMAGE |
| 274 | // For dual image, it is possible that the secondary image is |
| 275 | // empty or contains invalid data, ignore such case. |
George Liu | 44b9fef | 2023-02-07 14:31:32 +0800 | [diff] [blame] | 276 | info("Unable to find osRelease: {PATH}: {ERROR_MSG}", "PATH", |
| 277 | osRelease, "ERROR_MSG", ec.message()); |
Lei YU | e56bf87 | 2022-02-22 18:40:37 +0800 | [diff] [blame] | 278 | #else |
George Liu | 44b9fef | 2023-02-07 14:31:32 +0800 | [diff] [blame] | 279 | error("Failed to read osRelease: {PATH}: {ERROR_MSG}", "PATH", |
| 280 | osRelease, "ERROR_MSG", ec.message()); |
Adriana Kobylak | 716cd78 | 2020-06-08 13:27:43 -0500 | [diff] [blame] | 281 | |
| 282 | // Try to get the version id from the mount directory name and |
| 283 | // call to delete it as this version may be corrupted. Dynamic |
| 284 | // volumes created by the UBI layout for example have the id in |
| 285 | // the mount directory name. The worst that can happen is that |
| 286 | // erase() is called with an non-existent id and returns. |
| 287 | auto id = iter.path().native().substr(BMC_RO_PREFIX_LEN); |
Saqib Khan | 021c365 | 2017-09-26 12:11:02 -0500 | [diff] [blame] | 288 | ItemUpdater::erase(id); |
Lei YU | e56bf87 | 2022-02-22 18:40:37 +0800 | [diff] [blame] | 289 | #endif |
Adriana Kobylak | 716cd78 | 2020-06-08 13:27:43 -0500 | [diff] [blame] | 290 | |
Saqib Khan | 021c365 | 2017-09-26 12:11:02 -0500 | [diff] [blame] | 291 | continue; |
Saqib Khan | 1eef62d | 2017-08-10 15:29:34 -0500 | [diff] [blame] | 292 | } |
Gunnar Mills | 88e8a32 | 2017-09-13 11:09:28 -0500 | [diff] [blame] | 293 | auto version = VersionClass::getBMCVersion(osRelease); |
Saqib Khan | 1eef62d | 2017-08-10 15:29:34 -0500 | [diff] [blame] | 294 | if (version.empty()) |
| 295 | { |
Patrick Williams | c9bb642 | 2021-08-27 06:18:35 -0500 | [diff] [blame] | 296 | error("Failed to read version from osRelease: {PATH}", "PATH", |
| 297 | osRelease); |
Adriana Kobylak | 716cd78 | 2020-06-08 13:27:43 -0500 | [diff] [blame] | 298 | |
| 299 | // Try to delete the version, same as above if the |
| 300 | // OS_RELEASE_FILE does not exist. |
| 301 | auto id = iter.path().native().substr(BMC_RO_PREFIX_LEN); |
| 302 | ItemUpdater::erase(id); |
| 303 | |
| 304 | continue; |
Saqib Khan | 1eef62d | 2017-08-10 15:29:34 -0500 | [diff] [blame] | 305 | } |
Saqib Khan | 021c365 | 2017-09-26 12:11:02 -0500 | [diff] [blame] | 306 | |
Adriana Kobylak | 59b640b | 2022-01-21 19:45:22 +0000 | [diff] [blame] | 307 | // The flash location is part of the mount name: rofs-<location> |
| 308 | auto flashId = iter.path().native().substr(BMC_RO_PREFIX_LEN); |
| 309 | |
| 310 | auto id = VersionClass::getId(version + flashId); |
Adriana Kobylak | 716cd78 | 2020-06-08 13:27:43 -0500 | [diff] [blame] | 311 | |
Adriana Kobylak | f383d27 | 2020-06-16 15:17:22 -0500 | [diff] [blame] | 312 | // Check if the id has already been added. This can happen if the |
| 313 | // BMC partitions / devices were manually flashed with the same |
| 314 | // image. |
| 315 | if (versions.find(id) != versions.end()) |
| 316 | { |
| 317 | continue; |
| 318 | } |
| 319 | |
Adriana Kobylak | 1e81f23 | 2022-01-18 22:28:47 +0000 | [diff] [blame] | 320 | auto functional = false; |
| 321 | if (iter.path().native().find(functionalSuffix) != |
| 322 | std::string::npos) |
| 323 | { |
| 324 | // Set functional to true and remove the functional suffix |
| 325 | functional = true; |
| 326 | flashId.erase(flashId.length() - strlen(functionalSuffix)); |
Lei YU | d474d9c | 2021-12-10 16:21:21 +0800 | [diff] [blame] | 327 | functionalFound = true; |
Adriana Kobylak | 1e81f23 | 2022-01-18 22:28:47 +0000 | [diff] [blame] | 328 | } |
Adriana Kobylak | 780220f | 2022-01-18 20:01:53 +0000 | [diff] [blame] | 329 | |
Saqib Khan | 1eef62d | 2017-08-10 15:29:34 -0500 | [diff] [blame] | 330 | auto purpose = server::Version::VersionPurpose::BMC; |
Adriana Kobylak | 780220f | 2022-01-18 20:01:53 +0000 | [diff] [blame] | 331 | restorePurpose(flashId, purpose); |
Adriana Kobylak | ec4eec3 | 2019-11-13 14:28:35 -0600 | [diff] [blame] | 332 | |
Chanh Nguyen | 1fd6ddd | 2021-01-06 11:09:09 +0700 | [diff] [blame] | 333 | // Read os-release from /etc/ to get the BMC extended version |
| 334 | std::string extendedVersion = |
| 335 | VersionClass::getBMCExtendedVersion(osRelease); |
| 336 | |
Saqib Khan | 1eef62d | 2017-08-10 15:29:34 -0500 | [diff] [blame] | 337 | auto path = fs::path(SOFTWARE_OBJPATH) / id; |
| 338 | |
Adriana Kobylak | 7b11bba | 2024-06-24 10:14:49 -0500 | [diff] [blame] | 339 | // Create functional association and minimum ship level instance if |
| 340 | // this is the functional version |
Adriana Kobylak | 1e81f23 | 2022-01-18 22:28:47 +0000 | [diff] [blame] | 341 | if (functional) |
Gunnar Mills | 88e8a32 | 2017-09-13 11:09:28 -0500 | [diff] [blame] | 342 | { |
| 343 | createFunctionalAssociation(path); |
Adriana Kobylak | 7b11bba | 2024-06-24 10:14:49 -0500 | [diff] [blame] | 344 | |
| 345 | if (minimum_ship_level::enabled()) |
| 346 | { |
| 347 | minimumVersionObject = |
| 348 | std::make_unique<MinimumVersion>(bus, path); |
| 349 | minimumVersionObject->minimumVersion( |
| 350 | minimum_ship_level::getMinimumVersion()); |
| 351 | } |
Gunnar Mills | 88e8a32 | 2017-09-13 11:09:28 -0500 | [diff] [blame] | 352 | } |
| 353 | |
Patrick Williams | fc33ba8 | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 354 | AssociationList associations; |
Gunnar Mills | 43b25cd | 2017-09-07 13:19:34 -0500 | [diff] [blame] | 355 | |
| 356 | if (activationState == server::Activation::Activations::Active) |
| 357 | { |
| 358 | // Create an association to the BMC inventory item |
| 359 | associations.emplace_back(std::make_tuple( |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 360 | ACTIVATION_FWD_ASSOCIATION, ACTIVATION_REV_ASSOCIATION, |
| 361 | bmcInventoryPath)); |
Gunnar Mills | 43b25cd | 2017-09-07 13:19:34 -0500 | [diff] [blame] | 362 | |
| 363 | // Create an active association since this image is active |
| 364 | createActiveAssociation(path); |
| 365 | } |
| 366 | |
AppaRao Puli | bbebec7 | 2020-01-28 23:57:41 +0530 | [diff] [blame] | 367 | // All updateable firmware components must expose the updateable |
| 368 | // association. |
| 369 | createUpdateableAssociation(path); |
| 370 | |
Adriana Kobylak | ee590c7 | 2017-09-26 15:16:06 -0500 | [diff] [blame] | 371 | // Create Version instance for this version. |
| 372 | auto versionPtr = std::make_unique<VersionClass>( |
Adriana Kobylak | a84f06d | 2022-01-18 15:41:57 +0000 | [diff] [blame] | 373 | bus, path, version, purpose, extendedVersion, flashId, |
Justin Ledford | 054bb0b | 2022-03-15 15:46:58 -0700 | [diff] [blame] | 374 | std::vector<std::string>(), |
Adriana Kobylak | 59b640b | 2022-01-21 19:45:22 +0000 | [diff] [blame] | 375 | std::bind(&ItemUpdater::erase, this, std::placeholders::_1), |
| 376 | id); |
Adriana Kobylak | 1e81f23 | 2022-01-18 22:28:47 +0000 | [diff] [blame] | 377 | if (functional) |
| 378 | { |
| 379 | versionPtr->setFunctional(true); |
| 380 | } |
| 381 | else |
Michael Tritz | 4254bec | 2017-10-03 17:18:22 -0500 | [diff] [blame] | 382 | { |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 383 | versionPtr->deleteObject = |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 384 | std::make_unique<phosphor::software::manager::Delete>( |
| 385 | bus, path, *versionPtr); |
Michael Tritz | 4254bec | 2017-10-03 17:18:22 -0500 | [diff] [blame] | 386 | } |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 387 | versions.insert(std::make_pair(id, std::move(versionPtr))); |
Michael Tritz | 4254bec | 2017-10-03 17:18:22 -0500 | [diff] [blame] | 388 | |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 389 | // Create Activation instance for this version. |
| 390 | activations.insert(std::make_pair( |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 391 | id, std::make_unique<Activation>( |
| 392 | bus, path, *this, id, activationState, associations))); |
Saqib Khan | 1eef62d | 2017-08-10 15:29:34 -0500 | [diff] [blame] | 393 | |
Lei YU | bdf2d6c | 2021-12-15 14:05:01 +0800 | [diff] [blame] | 394 | #ifdef BMC_STATIC_DUAL_IMAGE |
| 395 | uint8_t priority; |
| 396 | if ((functional && (runningImageSlot == 0)) || |
| 397 | (!functional && (runningImageSlot == 1))) |
| 398 | { |
| 399 | priority = 0; |
| 400 | } |
| 401 | else |
| 402 | { |
| 403 | priority = 1; |
| 404 | } |
| 405 | activations.find(id)->second->redundancyPriority = |
| 406 | std::make_unique<RedundancyPriority>( |
| 407 | bus, path, *(activations.find(id)->second), priority, |
| 408 | false); |
| 409 | #else |
Lei YU | 269bff3 | 2018-08-21 15:21:40 +0800 | [diff] [blame] | 410 | // If Active, create RedundancyPriority instance for this |
| 411 | // version. |
Saqib Khan | 1eef62d | 2017-08-10 15:29:34 -0500 | [diff] [blame] | 412 | if (activationState == server::Activation::Activations::Active) |
| 413 | { |
| 414 | uint8_t priority = std::numeric_limits<uint8_t>::max(); |
Adriana Kobylak | 780220f | 2022-01-18 20:01:53 +0000 | [diff] [blame] | 415 | if (!restorePriority(flashId, priority)) |
Saqib Khan | 1eef62d | 2017-08-10 15:29:34 -0500 | [diff] [blame] | 416 | { |
Adriana Kobylak | 1e81f23 | 2022-01-18 22:28:47 +0000 | [diff] [blame] | 417 | if (functional) |
Adriana Kobylak | ee590c7 | 2017-09-26 15:16:06 -0500 | [diff] [blame] | 418 | { |
| 419 | priority = 0; |
| 420 | } |
| 421 | else |
| 422 | { |
Patrick Williams | c9bb642 | 2021-08-27 06:18:35 -0500 | [diff] [blame] | 423 | error( |
| 424 | "Unable to restore priority from file for {VERSIONID}", |
| 425 | "VERSIONID", id); |
Adriana Kobylak | ee590c7 | 2017-09-26 15:16:06 -0500 | [diff] [blame] | 426 | } |
Saqib Khan | 1eef62d | 2017-08-10 15:29:34 -0500 | [diff] [blame] | 427 | } |
| 428 | activations.find(id)->second->redundancyPriority = |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 429 | std::make_unique<RedundancyPriority>( |
| 430 | bus, path, *(activations.find(id)->second), priority, |
| 431 | false); |
Saqib Khan | 1eef62d | 2017-08-10 15:29:34 -0500 | [diff] [blame] | 432 | } |
Lei YU | bdf2d6c | 2021-12-15 14:05:01 +0800 | [diff] [blame] | 433 | #endif |
Saqib Khan | 1eef62d | 2017-08-10 15:29:34 -0500 | [diff] [blame] | 434 | } |
| 435 | } |
Saqib Khan | dcbfa04 | 2017-09-18 13:08:39 -0500 | [diff] [blame] | 436 | |
Lei YU | d474d9c | 2021-12-10 16:21:21 +0800 | [diff] [blame] | 437 | if (!functionalFound) |
Saqib Khan | dcbfa04 | 2017-09-18 13:08:39 -0500 | [diff] [blame] | 438 | { |
Lei YU | d474d9c | 2021-12-10 16:21:21 +0800 | [diff] [blame] | 439 | // If there is no functional version found, read the /etc/os-release and |
| 440 | // create rofs-<versionId>-functional under MEDIA_DIR, then call again |
| 441 | // processBMCImage() to create the D-Bus interface for it. |
Gunnar Mills | d16bcbd | 2017-10-08 16:50:42 -0500 | [diff] [blame] | 442 | auto version = VersionClass::getBMCVersion(OS_RELEASE_FILE); |
Patrick Williams | fc33ba8 | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 443 | auto id = phosphor::software::manager::Version::getId( |
| 444 | version + functionalSuffix); |
Adriana Kobylak | 1e81f23 | 2022-01-18 22:28:47 +0000 | [diff] [blame] | 445 | auto versionFileDir = BMC_ROFS_PREFIX + id + functionalSuffix + "/etc/"; |
Saqib Khan | dcbfa04 | 2017-09-18 13:08:39 -0500 | [diff] [blame] | 446 | try |
| 447 | { |
Gunnar Mills | d16bcbd | 2017-10-08 16:50:42 -0500 | [diff] [blame] | 448 | if (!fs::is_directory(versionFileDir)) |
Saqib Khan | dcbfa04 | 2017-09-18 13:08:39 -0500 | [diff] [blame] | 449 | { |
| 450 | fs::create_directories(versionFileDir); |
| 451 | } |
Patrick Williams | fc33ba8 | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 452 | auto versionFilePath = |
| 453 | BMC_ROFS_PREFIX + id + functionalSuffix + OS_RELEASE_FILE; |
Saqib Khan | dcbfa04 | 2017-09-18 13:08:39 -0500 | [diff] [blame] | 454 | fs::create_directory_symlink(OS_RELEASE_FILE, versionFilePath); |
| 455 | ItemUpdater::processBMCImage(); |
| 456 | } |
| 457 | catch (const std::exception& e) |
| 458 | { |
Patrick Williams | c9bb642 | 2021-08-27 06:18:35 -0500 | [diff] [blame] | 459 | error("Exception during processing: {ERROR}", "ERROR", e); |
Saqib Khan | dcbfa04 | 2017-09-18 13:08:39 -0500 | [diff] [blame] | 460 | } |
| 461 | } |
Eddie James | eaa1ee0 | 2018-03-01 10:09:10 -0600 | [diff] [blame] | 462 | |
| 463 | mirrorUbootToAlt(); |
Saqib Khan | ba23988 | 2017-05-26 08:41:54 -0500 | [diff] [blame] | 464 | return; |
| 465 | } |
| 466 | |
Leonel Gonzalez | 3526ef7 | 2017-07-07 14:38:25 -0500 | [diff] [blame] | 467 | void ItemUpdater::erase(std::string entryId) |
| 468 | { |
Eddie James | 6d87371 | 2017-09-01 11:29:07 -0500 | [diff] [blame] | 469 | // Find entry in versions map |
| 470 | auto it = versions.find(entryId); |
| 471 | if (it != versions.end()) |
| 472 | { |
Lei YU | 0f88b5a | 2018-08-21 15:28:53 +0800 | [diff] [blame] | 473 | if (it->second->isFunctional() && ACTIVE_BMC_MAX_ALLOWED > 1) |
Eddie James | 6d87371 | 2017-09-01 11:29:07 -0500 | [diff] [blame] | 474 | { |
Patrick Williams | c9bb642 | 2021-08-27 06:18:35 -0500 | [diff] [blame] | 475 | error( |
| 476 | "Version ({VERSIONID}) is currently running on the BMC; unable to remove.", |
| 477 | "VERSIONID", entryId); |
Gunnar Mills | d16bcbd | 2017-10-08 16:50:42 -0500 | [diff] [blame] | 478 | return; |
Eddie James | 6d87371 | 2017-09-01 11:29:07 -0500 | [diff] [blame] | 479 | } |
Adriana Kobylak | d1a55ad | 2020-06-11 14:01:28 -0500 | [diff] [blame] | 480 | } |
Eddie James | 6d87371 | 2017-09-01 11:29:07 -0500 | [diff] [blame] | 481 | |
Adriana Kobylak | d1a55ad | 2020-06-11 14:01:28 -0500 | [diff] [blame] | 482 | // First call resetUbootEnvVars() so that the BMC points to a valid image to |
| 483 | // boot from. If resetUbootEnvVars() is called after the image is actually |
| 484 | // deleted from the BMC flash, there'd be a time window where the BMC would |
| 485 | // be pointing to a non-existent image to boot from. |
| 486 | // Need to remove the entries from the activations map before that call so |
| 487 | // that resetUbootEnvVars() doesn't use the version to be deleted. |
| 488 | auto iteratorActivations = activations.find(entryId); |
| 489 | if (iteratorActivations == activations.end()) |
| 490 | { |
Patrick Williams | c9bb642 | 2021-08-27 06:18:35 -0500 | [diff] [blame] | 491 | error( |
| 492 | "Failed to find version ({VERSIONID}) in item updater activations map; unable to remove.", |
| 493 | "VERSIONID", entryId); |
Adriana Kobylak | d1a55ad | 2020-06-11 14:01:28 -0500 | [diff] [blame] | 494 | } |
| 495 | else |
| 496 | { |
| 497 | removeAssociations(iteratorActivations->second->path); |
Zami Seck | ae06d76 | 2021-08-13 20:11:15 -0500 | [diff] [blame] | 498 | iteratorActivations->second->deleteImageManagerObject(); |
Adriana Kobylak | d1a55ad | 2020-06-11 14:01:28 -0500 | [diff] [blame] | 499 | this->activations.erase(entryId); |
| 500 | } |
| 501 | ItemUpdater::resetUbootEnvVars(); |
| 502 | |
| 503 | if (it != versions.end()) |
| 504 | { |
Adriana Kobylak | 780220f | 2022-01-18 20:01:53 +0000 | [diff] [blame] | 505 | auto flashId = it->second->path(); |
| 506 | |
Adriana Kobylak | 25773a7 | 2022-01-21 15:24:48 +0000 | [diff] [blame] | 507 | // Delete version data if it has been installed on flash (path is not |
| 508 | // the upload directory) |
| 509 | if (flashId.find(IMG_UPLOAD_DIR) == std::string::npos) |
| 510 | { |
| 511 | removeReadOnlyPartition(entryId); |
| 512 | removePersistDataDirectory(flashId); |
| 513 | helper.clearEntry(flashId); |
| 514 | } |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 515 | |
| 516 | // Removing entry in versions map |
| 517 | this->versions.erase(entryId); |
Eddie James | 6d87371 | 2017-09-01 11:29:07 -0500 | [diff] [blame] | 518 | } |
Leonel Gonzalez | 3526ef7 | 2017-07-07 14:38:25 -0500 | [diff] [blame] | 519 | |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 520 | return; |
Leonel Gonzalez | 3526ef7 | 2017-07-07 14:38:25 -0500 | [diff] [blame] | 521 | } |
| 522 | |
Michael Tritz | bc1bf3a | 2017-09-18 16:38:23 -0500 | [diff] [blame] | 523 | void ItemUpdater::deleteAll() |
| 524 | { |
Adriana Kobylak | 83cd21f | 2018-02-28 15:48:48 -0600 | [diff] [blame] | 525 | std::vector<std::string> deletableVersions; |
| 526 | |
Michael Tritz | bc1bf3a | 2017-09-18 16:38:23 -0500 | [diff] [blame] | 527 | for (const auto& versionIt : versions) |
| 528 | { |
| 529 | if (!versionIt.second->isFunctional()) |
| 530 | { |
Adriana Kobylak | 83cd21f | 2018-02-28 15:48:48 -0600 | [diff] [blame] | 531 | deletableVersions.push_back(versionIt.first); |
Michael Tritz | bc1bf3a | 2017-09-18 16:38:23 -0500 | [diff] [blame] | 532 | } |
| 533 | } |
| 534 | |
Adriana Kobylak | 83cd21f | 2018-02-28 15:48:48 -0600 | [diff] [blame] | 535 | for (const auto& deletableIt : deletableVersions) |
| 536 | { |
| 537 | ItemUpdater::erase(deletableIt); |
| 538 | } |
| 539 | |
Lei YU | 56aaf45 | 2018-06-21 16:09:44 +0800 | [diff] [blame] | 540 | helper.cleanup(); |
Michael Tritz | bc1bf3a | 2017-09-18 16:38:23 -0500 | [diff] [blame] | 541 | } |
| 542 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 543 | ItemUpdater::ActivationStatus |
| 544 | ItemUpdater::validateSquashFSImage(const std::string& filePath) |
Saqib Khan | 35e83f3 | 2017-05-22 11:37:32 -0500 | [diff] [blame] | 545 | { |
Bright Cheng | 8e9ccfe | 2019-11-18 16:18:44 +0800 | [diff] [blame] | 546 | bool valid = true; |
Saqib Khan | 35e83f3 | 2017-05-22 11:37:32 -0500 | [diff] [blame] | 547 | |
Bright Cheng | 8e9ccfe | 2019-11-18 16:18:44 +0800 | [diff] [blame] | 548 | // Record the images which are being updated |
| 549 | // First check for the fullimage, then check for images with partitions |
| 550 | imageUpdateList.push_back(bmcFullImages); |
| 551 | valid = checkImage(filePath, imageUpdateList); |
| 552 | if (!valid) |
Saqib Khan | 35e83f3 | 2017-05-22 11:37:32 -0500 | [diff] [blame] | 553 | { |
Bright Cheng | 8e9ccfe | 2019-11-18 16:18:44 +0800 | [diff] [blame] | 554 | imageUpdateList.clear(); |
| 555 | imageUpdateList.assign(bmcImages.begin(), bmcImages.end()); |
| 556 | valid = checkImage(filePath, imageUpdateList); |
| 557 | if (!valid) |
Michael Tritz | b1cfdf9 | 2017-08-14 14:33:30 -0500 | [diff] [blame] | 558 | { |
Patrick Williams | c9bb642 | 2021-08-27 06:18:35 -0500 | [diff] [blame] | 559 | error("Failed to find the needed BMC images."); |
Bright Cheng | 8e9ccfe | 2019-11-18 16:18:44 +0800 | [diff] [blame] | 560 | return ItemUpdater::ActivationStatus::invalid; |
Michael Tritz | b1cfdf9 | 2017-08-14 14:33:30 -0500 | [diff] [blame] | 561 | } |
Saqib Khan | 35e83f3 | 2017-05-22 11:37:32 -0500 | [diff] [blame] | 562 | } |
Michael Tritz | b1cfdf9 | 2017-08-14 14:33:30 -0500 | [diff] [blame] | 563 | |
Michael Tritz | b1cfdf9 | 2017-08-14 14:33:30 -0500 | [diff] [blame] | 564 | return ItemUpdater::ActivationStatus::ready; |
Saqib Khan | 35e83f3 | 2017-05-22 11:37:32 -0500 | [diff] [blame] | 565 | } |
| 566 | |
Adriana Kobylak | bbcb7be | 2018-07-17 15:47:34 -0500 | [diff] [blame] | 567 | void ItemUpdater::savePriority(const std::string& versionId, uint8_t value) |
| 568 | { |
Adriana Kobylak | 780220f | 2022-01-18 20:01:53 +0000 | [diff] [blame] | 569 | auto flashId = versions.find(versionId)->second->path(); |
| 570 | storePriority(flashId, value); |
Adriana Kobylak | 25773a7 | 2022-01-21 15:24:48 +0000 | [diff] [blame] | 571 | helper.setEntry(flashId, value); |
Adriana Kobylak | bbcb7be | 2018-07-17 15:47:34 -0500 | [diff] [blame] | 572 | } |
| 573 | |
Saqib Khan | b9da663 | 2017-09-13 09:48:37 -0500 | [diff] [blame] | 574 | void ItemUpdater::freePriority(uint8_t value, const std::string& versionId) |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 575 | { |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 576 | std::map<std::string, uint8_t> priorityMap; |
| 577 | |
| 578 | // Insert the requested version and priority, it may not exist yet. |
| 579 | priorityMap.insert(std::make_pair(versionId, value)); |
| 580 | |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 581 | for (const auto& intf : activations) |
| 582 | { |
Gunnar Mills | 9a78224 | 2017-08-22 16:23:15 -0500 | [diff] [blame] | 583 | if (intf.second->redundancyPriority) |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 584 | { |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 585 | priorityMap.insert(std::make_pair( |
Pavithra Barithaya | 9d7b331 | 2024-06-26 01:58:51 -0500 | [diff] [blame] | 586 | intf.first, intf.second->redundancyPriority->priority())); |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 587 | } |
| 588 | } |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 589 | |
| 590 | // Lambda function to compare 2 priority values, use <= to allow duplicates |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 591 | typedef std::function<bool(std::pair<std::string, uint8_t>, |
| 592 | std::pair<std::string, uint8_t>)> |
| 593 | cmpPriority; |
| 594 | cmpPriority cmpPriorityFunc = |
Pavithra Barithaya | 6d17852 | 2024-06-24 04:17:29 -0500 | [diff] [blame] | 595 | [](const std::pair<std::string, uint8_t>& priority1, |
| 596 | const std::pair<std::string, uint8_t>& priority2) { |
Patrick Williams | fc33ba8 | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 597 | return priority1.second <= priority2.second; |
| 598 | }; |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 599 | |
| 600 | // Sort versions by ascending priority |
| 601 | std::set<std::pair<std::string, uint8_t>, cmpPriority> prioritySet( |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 602 | priorityMap.begin(), priorityMap.end(), cmpPriorityFunc); |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 603 | |
| 604 | auto freePriorityValue = value; |
| 605 | for (auto& element : prioritySet) |
| 606 | { |
| 607 | if (element.first == versionId) |
| 608 | { |
| 609 | continue; |
| 610 | } |
| 611 | if (element.second == freePriorityValue) |
| 612 | { |
| 613 | ++freePriorityValue; |
| 614 | auto it = activations.find(element.first); |
Pavithra Barithaya | 9d7b331 | 2024-06-26 01:58:51 -0500 | [diff] [blame] | 615 | it->second->redundancyPriority->sdbusPriority(freePriorityValue); |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 616 | } |
| 617 | } |
| 618 | |
| 619 | auto lowestVersion = prioritySet.begin()->first; |
| 620 | if (value == prioritySet.begin()->second) |
| 621 | { |
| 622 | lowestVersion = versionId; |
| 623 | } |
| 624 | updateUbootEnvVars(lowestVersion); |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 625 | } |
| 626 | |
Michael Tritz | 37a5904 | 2017-07-12 13:44:53 -0500 | [diff] [blame] | 627 | void ItemUpdater::reset() |
| 628 | { |
Pavithra Barithaya | c5f6e7e | 2024-06-24 09:50:21 -0500 | [diff] [blame] | 629 | phosphor::software::updater::Helper::factoryReset(); |
Michael Tritz | 37a5904 | 2017-07-12 13:44:53 -0500 | [diff] [blame] | 630 | |
Patrick Williams | c9bb642 | 2021-08-27 06:18:35 -0500 | [diff] [blame] | 631 | info("BMC factory reset will take effect upon reboot."); |
Michael Tritz | 37a5904 | 2017-07-12 13:44:53 -0500 | [diff] [blame] | 632 | } |
| 633 | |
Pavithra Barithaya | 6d17852 | 2024-06-24 04:17:29 -0500 | [diff] [blame] | 634 | void ItemUpdater::removeReadOnlyPartition(const std::string& versionId) |
Leonel Gonzalez | 3526ef7 | 2017-07-07 14:38:25 -0500 | [diff] [blame] | 635 | { |
Adriana Kobylak | 25773a7 | 2022-01-21 15:24:48 +0000 | [diff] [blame] | 636 | auto flashId = versions.find(versionId)->second->path(); |
| 637 | helper.removeVersion(flashId); |
Leonel Gonzalez | 3526ef7 | 2017-07-07 14:38:25 -0500 | [diff] [blame] | 638 | } |
| 639 | |
Michael Tritz | 0129d92 | 2017-08-10 19:33:46 -0500 | [diff] [blame] | 640 | bool ItemUpdater::fieldModeEnabled(bool value) |
| 641 | { |
| 642 | // enabling field mode is intended to be one way: false -> true |
| 643 | if (value && !control::FieldMode::fieldModeEnabled()) |
| 644 | { |
| 645 | control::FieldMode::fieldModeEnabled(value); |
| 646 | |
Adriana Kobylak | 22848ec | 2019-10-28 10:08:39 -0500 | [diff] [blame] | 647 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 648 | SYSTEMD_INTERFACE, "StartUnit"); |
| 649 | method.append("obmc-flash-bmc-setenv@fieldmode\\x3dtrue.service", |
| 650 | "replace"); |
| 651 | bus.call_noreply(method); |
| 652 | |
| 653 | method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 654 | SYSTEMD_INTERFACE, "StopUnit"); |
| 655 | method.append("usr-local.mount", "replace"); |
| 656 | bus.call_noreply(method); |
| 657 | |
| 658 | std::vector<std::string> usrLocal = {"usr-local.mount"}; |
| 659 | |
| 660 | method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 661 | SYSTEMD_INTERFACE, "MaskUnitFiles"); |
| 662 | method.append(usrLocal, false, true); |
| 663 | bus.call_noreply(method); |
Michael Tritz | 0129d92 | 2017-08-10 19:33:46 -0500 | [diff] [blame] | 664 | } |
Adriana Kobylak | d5b8f75 | 2019-05-01 11:52:35 -0500 | [diff] [blame] | 665 | else if (!value && control::FieldMode::fieldModeEnabled()) |
| 666 | { |
Adriana Kobylak | ce82de5 | 2024-01-16 13:56:38 -0600 | [diff] [blame] | 667 | elog<NotAllowed>(xyz::openbmc_project::common::NotAllowed::REASON( |
Adriana Kobylak | d5b8f75 | 2019-05-01 11:52:35 -0500 | [diff] [blame] | 668 | "FieldMode is not allowed to be cleared")); |
| 669 | } |
Michael Tritz | 0129d92 | 2017-08-10 19:33:46 -0500 | [diff] [blame] | 670 | |
| 671 | return control::FieldMode::fieldModeEnabled(); |
| 672 | } |
| 673 | |
| 674 | void ItemUpdater::restoreFieldModeStatus() |
| 675 | { |
Isaac Kurth | deb86b4 | 2022-03-08 19:47:53 -0600 | [diff] [blame] | 676 | // The fieldmode u-boot environment variable may not exist since it is not |
| 677 | // part of the default environment, run fw_printenv with 2>&1 to ignore the |
| 678 | // error message in the journal "Error: "fieldmode" not defined" |
Patrick Williams | fc33ba8 | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 679 | std::pair<int, std::string> ret = |
| 680 | utils::execute("/sbin/fw_printenv", "-n", "fieldmode", "2>&1"); |
Michael Tritz | 0129d92 | 2017-08-10 19:33:46 -0500 | [diff] [blame] | 681 | |
Isaac Kurth | deb86b4 | 2022-03-08 19:47:53 -0600 | [diff] [blame] | 682 | if (ret.first != 0) |
| 683 | { |
| 684 | return; |
| 685 | } |
| 686 | |
| 687 | // truncate any extra characters off the end to compare against a "true" str |
| 688 | std::string result = ret.second.substr(0, 4); |
| 689 | if (result == "true") |
Michael Tritz | 0129d92 | 2017-08-10 19:33:46 -0500 | [diff] [blame] | 690 | { |
| 691 | ItemUpdater::fieldModeEnabled(true); |
| 692 | } |
| 693 | } |
| 694 | |
Gunnar Mills | b60add1 | 2017-08-24 16:41:42 -0500 | [diff] [blame] | 695 | void ItemUpdater::setBMCInventoryPath() |
| 696 | { |
Gunnar Mills | b60add1 | 2017-08-24 16:41:42 -0500 | [diff] [blame] | 697 | auto depth = 0; |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 698 | auto mapperCall = bus.new_method_call(MAPPER_BUSNAME, MAPPER_PATH, |
| 699 | MAPPER_INTERFACE, "GetSubTreePaths"); |
Gunnar Mills | b60add1 | 2017-08-24 16:41:42 -0500 | [diff] [blame] | 700 | |
Adriana Kobylak | 1254c62 | 2017-12-07 12:24:56 -0600 | [diff] [blame] | 701 | mapperCall.append(INVENTORY_PATH); |
Gunnar Mills | b60add1 | 2017-08-24 16:41:42 -0500 | [diff] [blame] | 702 | mapperCall.append(depth); |
Adriana Kobylak | 1254c62 | 2017-12-07 12:24:56 -0600 | [diff] [blame] | 703 | std::vector<std::string> filter = {BMC_INVENTORY_INTERFACE}; |
Gunnar Mills | b60add1 | 2017-08-24 16:41:42 -0500 | [diff] [blame] | 704 | mapperCall.append(filter); |
| 705 | |
Ed Tanous | 87c7817 | 2018-08-10 12:51:53 -0700 | [diff] [blame] | 706 | try |
| 707 | { |
| 708 | auto response = bus.call(mapperCall); |
| 709 | |
| 710 | using ObjectPaths = std::vector<std::string>; |
| 711 | ObjectPaths result; |
| 712 | response.read(result); |
| 713 | |
| 714 | if (!result.empty()) |
| 715 | { |
| 716 | bmcInventoryPath = result.front(); |
| 717 | } |
| 718 | } |
Patrick Williams | bf2bb2b | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 719 | catch (const sdbusplus::exception_t& e) |
Gunnar Mills | b60add1 | 2017-08-24 16:41:42 -0500 | [diff] [blame] | 720 | { |
Patrick Williams | c9bb642 | 2021-08-27 06:18:35 -0500 | [diff] [blame] | 721 | error("Error in mapper GetSubTreePath: {ERROR}", "ERROR", e); |
Gunnar Mills | b60add1 | 2017-08-24 16:41:42 -0500 | [diff] [blame] | 722 | return; |
| 723 | } |
| 724 | |
Adriana Kobylak | 1254c62 | 2017-12-07 12:24:56 -0600 | [diff] [blame] | 725 | return; |
Gunnar Mills | b60add1 | 2017-08-24 16:41:42 -0500 | [diff] [blame] | 726 | } |
| 727 | |
Gunnar Mills | f10b232 | 2017-09-21 15:31:55 -0500 | [diff] [blame] | 728 | void ItemUpdater::createActiveAssociation(const std::string& path) |
Gunnar Mills | ded875d | 2017-08-28 16:44:52 -0500 | [diff] [blame] | 729 | { |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 730 | assocs.emplace_back( |
| 731 | std::make_tuple(ACTIVE_FWD_ASSOCIATION, ACTIVE_REV_ASSOCIATION, path)); |
Gunnar Mills | ded875d | 2017-08-28 16:44:52 -0500 | [diff] [blame] | 732 | associations(assocs); |
| 733 | } |
| 734 | |
Gunnar Mills | 88e8a32 | 2017-09-13 11:09:28 -0500 | [diff] [blame] | 735 | void ItemUpdater::createFunctionalAssociation(const std::string& path) |
| 736 | { |
| 737 | assocs.emplace_back(std::make_tuple(FUNCTIONAL_FWD_ASSOCIATION, |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 738 | FUNCTIONAL_REV_ASSOCIATION, path)); |
Gunnar Mills | 88e8a32 | 2017-09-13 11:09:28 -0500 | [diff] [blame] | 739 | associations(assocs); |
| 740 | } |
| 741 | |
AppaRao Puli | bbebec7 | 2020-01-28 23:57:41 +0530 | [diff] [blame] | 742 | void ItemUpdater::createUpdateableAssociation(const std::string& path) |
| 743 | { |
| 744 | assocs.emplace_back(std::make_tuple(UPDATEABLE_FWD_ASSOCIATION, |
| 745 | UPDATEABLE_REV_ASSOCIATION, path)); |
| 746 | associations(assocs); |
| 747 | } |
| 748 | |
Adriana Kobylak | 991af7e | 2018-12-10 13:08:38 -0600 | [diff] [blame] | 749 | void ItemUpdater::removeAssociations(const std::string& path) |
Gunnar Mills | ded875d | 2017-08-28 16:44:52 -0500 | [diff] [blame] | 750 | { |
| 751 | for (auto iter = assocs.begin(); iter != assocs.end();) |
| 752 | { |
Pavithra Barithaya | 9e307b7 | 2024-06-26 01:27:38 -0500 | [diff] [blame] | 753 | if (std::get<2>(*iter) == path) |
Gunnar Mills | ded875d | 2017-08-28 16:44:52 -0500 | [diff] [blame] | 754 | { |
| 755 | iter = assocs.erase(iter); |
| 756 | associations(assocs); |
| 757 | } |
| 758 | else |
| 759 | { |
| 760 | ++iter; |
| 761 | } |
| 762 | } |
| 763 | } |
| 764 | |
Saqib Khan | b9da663 | 2017-09-13 09:48:37 -0500 | [diff] [blame] | 765 | bool ItemUpdater::isLowestPriority(uint8_t value) |
| 766 | { |
| 767 | for (const auto& intf : activations) |
| 768 | { |
Gunnar Mills | d16bcbd | 2017-10-08 16:50:42 -0500 | [diff] [blame] | 769 | if (intf.second->redundancyPriority) |
Saqib Khan | b9da663 | 2017-09-13 09:48:37 -0500 | [diff] [blame] | 770 | { |
Pavithra Barithaya | 9d7b331 | 2024-06-26 01:58:51 -0500 | [diff] [blame] | 771 | if (intf.second->redundancyPriority->priority() < value) |
Saqib Khan | b9da663 | 2017-09-13 09:48:37 -0500 | [diff] [blame] | 772 | { |
| 773 | return false; |
| 774 | } |
| 775 | } |
| 776 | } |
| 777 | return true; |
| 778 | } |
| 779 | |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 780 | void ItemUpdater::updateUbootEnvVars(const std::string& versionId) |
| 781 | { |
Lei YU | 9c76a0a | 2022-03-14 11:37:15 +0800 | [diff] [blame] | 782 | auto it = versions.find(versionId); |
| 783 | if (it == versions.end()) |
| 784 | { |
| 785 | return; |
| 786 | } |
| 787 | auto flashId = it->second->path(); |
Adriana Kobylak | 25773a7 | 2022-01-21 15:24:48 +0000 | [diff] [blame] | 788 | helper.updateUbootVersionId(flashId); |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 789 | } |
| 790 | |
Saqib Khan | 49446ae | 2017-10-02 10:54:20 -0500 | [diff] [blame] | 791 | void ItemUpdater::resetUbootEnvVars() |
| 792 | { |
Pavithra Barithaya | 9d7b331 | 2024-06-26 01:58:51 -0500 | [diff] [blame] | 793 | decltype(activations.begin()->second->redundancyPriority->priority()) |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 794 | lowestPriority = std::numeric_limits<uint8_t>::max(); |
Saqib Khan | 49446ae | 2017-10-02 10:54:20 -0500 | [diff] [blame] | 795 | decltype(activations.begin()->second->versionId) lowestPriorityVersion; |
| 796 | for (const auto& intf : activations) |
| 797 | { |
Pavithra Barithaya | 9d7b331 | 2024-06-26 01:58:51 -0500 | [diff] [blame] | 798 | if (!intf.second->redundancyPriority) |
Saqib Khan | 49446ae | 2017-10-02 10:54:20 -0500 | [diff] [blame] | 799 | { |
| 800 | // Skip this version if the redundancyPriority is not initialized. |
| 801 | continue; |
| 802 | } |
| 803 | |
Pavithra Barithaya | 9d7b331 | 2024-06-26 01:58:51 -0500 | [diff] [blame] | 804 | if (intf.second->redundancyPriority->priority() <= lowestPriority) |
Saqib Khan | 49446ae | 2017-10-02 10:54:20 -0500 | [diff] [blame] | 805 | { |
Pavithra Barithaya | 9d7b331 | 2024-06-26 01:58:51 -0500 | [diff] [blame] | 806 | lowestPriority = intf.second->redundancyPriority->priority(); |
Saqib Khan | 49446ae | 2017-10-02 10:54:20 -0500 | [diff] [blame] | 807 | lowestPriorityVersion = intf.second->versionId; |
| 808 | } |
| 809 | } |
| 810 | |
Saqib Khan | f0382c3 | 2017-10-24 13:36:22 -0500 | [diff] [blame] | 811 | // Update the U-boot environment variable to point to the lowest priority |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 812 | updateUbootEnvVars(lowestPriorityVersion); |
Saqib Khan | 49446ae | 2017-10-02 10:54:20 -0500 | [diff] [blame] | 813 | } |
| 814 | |
Lei YU | d8c9eea | 2021-12-16 16:08:30 +0800 | [diff] [blame] | 815 | void ItemUpdater::freeSpace([[maybe_unused]] const Activation& caller) |
Adriana Kobylak | 204e1e7 | 2018-01-24 16:00:05 -0600 | [diff] [blame] | 816 | { |
Lei YU | d8c9eea | 2021-12-16 16:08:30 +0800 | [diff] [blame] | 817 | #ifdef BMC_STATIC_DUAL_IMAGE |
| 818 | // For the golden image case, always remove the version on the primary side |
| 819 | std::string versionIDtoErase; |
| 820 | for (const auto& iter : activations) |
| 821 | { |
| 822 | if (iter.second->redundancyPriority && |
Pavithra Barithaya | 9d7b331 | 2024-06-26 01:58:51 -0500 | [diff] [blame] | 823 | iter.second->redundancyPriority->priority() == 0) |
Lei YU | d8c9eea | 2021-12-16 16:08:30 +0800 | [diff] [blame] | 824 | { |
| 825 | versionIDtoErase = iter.second->versionId; |
| 826 | break; |
| 827 | } |
| 828 | } |
| 829 | if (!versionIDtoErase.empty()) |
| 830 | { |
| 831 | erase(versionIDtoErase); |
| 832 | } |
| 833 | else |
| 834 | { |
| 835 | warning("Failed to find version to erase"); |
| 836 | } |
| 837 | #else |
Adriana Kobylak | 204e1e7 | 2018-01-24 16:00:05 -0600 | [diff] [blame] | 838 | // Versions with the highest priority in front |
| 839 | std::priority_queue<std::pair<int, std::string>, |
| 840 | std::vector<std::pair<int, std::string>>, |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 841 | std::less<std::pair<int, std::string>>> |
| 842 | versionsPQ; |
Adriana Kobylak | 204e1e7 | 2018-01-24 16:00:05 -0600 | [diff] [blame] | 843 | |
| 844 | std::size_t count = 0; |
| 845 | for (const auto& iter : activations) |
| 846 | { |
| 847 | if ((iter.second.get()->activation() == |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 848 | server::Activation::Activations::Active) || |
Adriana Kobylak | 204e1e7 | 2018-01-24 16:00:05 -0600 | [diff] [blame] | 849 | (iter.second.get()->activation() == |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 850 | server::Activation::Activations::Failed)) |
Adriana Kobylak | 204e1e7 | 2018-01-24 16:00:05 -0600 | [diff] [blame] | 851 | { |
| 852 | count++; |
| 853 | // Don't put the functional version on the queue since we can't |
| 854 | // remove the "running" BMC version. |
Lei YU | 0f88b5a | 2018-08-21 15:28:53 +0800 | [diff] [blame] | 855 | // If ACTIVE_BMC_MAX_ALLOWED <= 1, there is only one active BMC, |
| 856 | // so remove functional version as well. |
Adriana Kobylak | a696359 | 2018-09-07 14:13:29 -0500 | [diff] [blame] | 857 | // Don't delete the the Activation object that called this function. |
| 858 | if ((versions.find(iter.second->versionId) |
| 859 | ->second->isFunctional() && |
| 860 | ACTIVE_BMC_MAX_ALLOWED > 1) || |
| 861 | (iter.second->versionId == caller.versionId)) |
Adriana Kobylak | 204e1e7 | 2018-01-24 16:00:05 -0600 | [diff] [blame] | 862 | { |
| 863 | continue; |
| 864 | } |
Adriana Kobylak | a696359 | 2018-09-07 14:13:29 -0500 | [diff] [blame] | 865 | |
| 866 | // Failed activations don't have priority, assign them a large value |
| 867 | // for sorting purposes. |
| 868 | auto priority = 999; |
| 869 | if (iter.second.get()->activation() == |
Lei YU | cfb4b20 | 2021-05-06 17:47:28 +0800 | [diff] [blame] | 870 | server::Activation::Activations::Active && |
| 871 | iter.second->redundancyPriority) |
Adriana Kobylak | a696359 | 2018-09-07 14:13:29 -0500 | [diff] [blame] | 872 | { |
| 873 | priority = iter.second->redundancyPriority.get()->priority(); |
| 874 | } |
| 875 | |
| 876 | versionsPQ.push(std::make_pair(priority, iter.second->versionId)); |
Adriana Kobylak | 204e1e7 | 2018-01-24 16:00:05 -0600 | [diff] [blame] | 877 | } |
| 878 | } |
| 879 | |
| 880 | // If the number of BMC versions is over ACTIVE_BMC_MAX_ALLOWED -1, |
| 881 | // remove the highest priority one(s). |
| 882 | while ((count >= ACTIVE_BMC_MAX_ALLOWED) && (!versionsPQ.empty())) |
| 883 | { |
| 884 | erase(versionsPQ.top().second); |
| 885 | versionsPQ.pop(); |
| 886 | count--; |
| 887 | } |
Lei YU | d8c9eea | 2021-12-16 16:08:30 +0800 | [diff] [blame] | 888 | #endif |
Adriana Kobylak | 204e1e7 | 2018-01-24 16:00:05 -0600 | [diff] [blame] | 889 | } |
| 890 | |
Eddie James | eaa1ee0 | 2018-03-01 10:09:10 -0600 | [diff] [blame] | 891 | void ItemUpdater::mirrorUbootToAlt() |
| 892 | { |
Lei YU | 56aaf45 | 2018-06-21 16:09:44 +0800 | [diff] [blame] | 893 | helper.mirrorAlt(); |
Eddie James | eaa1ee0 | 2018-03-01 10:09:10 -0600 | [diff] [blame] | 894 | } |
| 895 | |
Bright Cheng | 8e9ccfe | 2019-11-18 16:18:44 +0800 | [diff] [blame] | 896 | bool ItemUpdater::checkImage(const std::string& filePath, |
| 897 | const std::vector<std::string>& imageList) |
| 898 | { |
| 899 | bool valid = true; |
| 900 | |
| 901 | for (auto& bmcImage : imageList) |
| 902 | { |
| 903 | fs::path file(filePath); |
| 904 | file /= bmcImage; |
| 905 | std::ifstream efile(file.c_str()); |
| 906 | if (efile.good() != 1) |
| 907 | { |
| 908 | valid = false; |
| 909 | break; |
| 910 | } |
| 911 | } |
| 912 | |
| 913 | return valid; |
| 914 | } |
| 915 | |
Lei YU | 6e9fb1d | 2021-02-19 18:01:40 +0800 | [diff] [blame] | 916 | #ifdef HOST_BIOS_UPGRADE |
| 917 | void ItemUpdater::createBIOSObject() |
| 918 | { |
| 919 | std::string path = BIOS_OBJPATH; |
| 920 | // Get version id from last item in the path |
Pavithra Barithaya | 27d4938 | 2024-06-24 01:52:42 -0500 | [diff] [blame] | 921 | auto pos = path.rfind('/'); |
Lei YU | 6e9fb1d | 2021-02-19 18:01:40 +0800 | [diff] [blame] | 922 | if (pos == std::string::npos) |
| 923 | { |
Patrick Williams | c9bb642 | 2021-08-27 06:18:35 -0500 | [diff] [blame] | 924 | error("No version id found in object path {PATH}", "PATH", path); |
Lei YU | 6e9fb1d | 2021-02-19 18:01:40 +0800 | [diff] [blame] | 925 | return; |
| 926 | } |
| 927 | |
| 928 | createActiveAssociation(path); |
| 929 | createFunctionalAssociation(path); |
Daniel Hsu | 27d734f | 2024-05-21 15:20:23 +0800 | [diff] [blame] | 930 | createUpdateableAssociation(path); |
Lei YU | 6e9fb1d | 2021-02-19 18:01:40 +0800 | [diff] [blame] | 931 | |
| 932 | auto versionId = path.substr(pos + 1); |
| 933 | auto version = "null"; |
Patrick Williams | fc33ba8 | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 934 | AssociationList assocs; |
Lei YU | 6e9fb1d | 2021-02-19 18:01:40 +0800 | [diff] [blame] | 935 | biosActivation = std::make_unique<Activation>( |
| 936 | bus, path, *this, versionId, server::Activation::Activations::Active, |
| 937 | assocs); |
Pavithra Barithaya | 6d17852 | 2024-06-24 04:17:29 -0500 | [diff] [blame] | 938 | auto dummyErase = [](const std::string& /*entryId*/) { |
Lei YU | 6e9fb1d | 2021-02-19 18:01:40 +0800 | [diff] [blame] | 939 | // Do nothing; |
| 940 | }; |
| 941 | biosVersion = std::make_unique<VersionClass>( |
| 942 | bus, path, version, VersionPurpose::Host, "", "", |
Justin Ledford | 054bb0b | 2022-03-15 15:46:58 -0700 | [diff] [blame] | 943 | std::vector<std::string>(), |
Adriana Kobylak | 59b640b | 2022-01-21 19:45:22 +0000 | [diff] [blame] | 944 | std::bind(dummyErase, std::placeholders::_1), ""); |
Lei YU | 6e9fb1d | 2021-02-19 18:01:40 +0800 | [diff] [blame] | 945 | biosVersion->deleteObject = |
Patrick Williams | fc33ba8 | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 946 | std::make_unique<phosphor::software::manager::Delete>( |
| 947 | bus, path, *biosVersion); |
Lei YU | 6e9fb1d | 2021-02-19 18:01:40 +0800 | [diff] [blame] | 948 | } |
| 949 | #endif |
| 950 | |
Lei YU | 531fbc2 | 2021-12-10 20:03:18 +0800 | [diff] [blame] | 951 | void ItemUpdater::getRunningSlot() |
| 952 | { |
| 953 | // Check /run/media/slot to get the slot number |
| 954 | constexpr auto slotFile = "/run/media/slot"; |
| 955 | std::fstream f(slotFile, std::ios_base::in); |
| 956 | f >> runningImageSlot; |
| 957 | } |
| 958 | |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 959 | } // namespace updater |
| 960 | } // namespace software |
| 961 | } // namespace phosphor |