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