blob: 3ea954c244053d79c97cb5a80a85ff39adec9a2a [file] [log] [blame]
Gunnar Millsb0ce9962018-09-07 13:39:10 -05001#include "config.h"
2
3#include "item_updater.hpp"
4
5#include "images.hpp"
6#include "serialize.hpp"
7#include "version.hpp"
Chanh Nguyen1fd6ddd2021-01-06 11:09:09 +07008#include "xyz/openbmc_project/Software/ExtendedVersion/server.hpp"
Gunnar Millsb0ce9962018-09-07 13:39:10 -05009#include "xyz/openbmc_project/Software/Version/server.hpp"
10
Adriana Kobylakd5b8f752019-05-01 11:52:35 -050011#include <phosphor-logging/elog-errors.hpp>
Gunnar Millsb0ce9962018-09-07 13:39:10 -050012#include <phosphor-logging/elog.hpp>
Patrick Williamsc9bb6422021-08-27 06:18:35 -050013#include <phosphor-logging/lg2.hpp>
Adriana Kobylak58aa7502020-06-08 11:12:11 -050014#include <xyz/openbmc_project/Common/error.hpp>
15#include <xyz/openbmc_project/Software/Image/error.hpp>
16
17#include <filesystem>
18#include <fstream>
Adriana Kobylak204e1e72018-01-24 16:00:05 -060019#include <queue>
Adriana Kobylakb77551c2017-10-27 12:46:23 -050020#include <set>
Gunnar Millsec1b41c2017-05-02 12:20:36 -050021#include <string>
George Liu44b9fef2023-02-07 14:31:32 +080022#include <system_error>
Gunnar Millsec1b41c2017-05-02 12:20:36 -050023
24namespace phosphor
25{
26namespace software
27{
28namespace updater
29{
30
Gunnar Mills2ce7da22017-05-04 15:37:56 -050031// When you see server:: you know we're referencing our base class
32namespace server = sdbusplus::xyz::openbmc_project::Software::server;
Michael Tritz0129d922017-08-10 19:33:46 -050033namespace control = sdbusplus::xyz::openbmc_project::Control::server;
Gunnar Mills2ce7da22017-05-04 15:37:56 -050034
Patrick Williamsc9bb6422021-08-27 06:18:35 -050035PHOSPHOR_LOG2_USING;
Gunnar Mills2ce7da22017-05-04 15:37:56 -050036using namespace phosphor::logging;
Adriana Kobylak43699ca2018-10-17 14:56:29 -050037using namespace sdbusplus::xyz::openbmc_project::Software::Image::Error;
Jayanth Othayoth2ab9b102018-02-21 05:27:47 -060038using namespace phosphor::software::image;
Adriana Kobylakc98d9122020-05-05 10:36:01 -050039namespace fs = std::filesystem;
Adriana Kobylakd5b8f752019-05-01 11:52:35 -050040using NotAllowed = sdbusplus::xyz::openbmc_project::Common::Error::NotAllowed;
Saqib Khan35e83f32017-05-22 11:37:32 -050041
Patrick Williamsbf2bb2b2022-07-22 19:26:52 -050042void ItemUpdater::createActivation(sdbusplus::message_t& msg)
Gunnar Millsec1b41c2017-05-02 12:20:36 -050043{
Saqib Khan84a0e692017-06-28 17:27:01 -050044
45 using SVersion = server::Version;
46 using VersionPurpose = SVersion::VersionPurpose;
Gunnar Mills9a782242017-08-22 16:23:15 -050047 using VersionClass = phosphor::software::manager::Version;
Saqib Khan84a0e692017-06-28 17:27:01 -050048
Patrick Williamsbc1facd2020-06-03 05:58:27 -050049 sdbusplus::message::object_path objPath;
Saqib Khan84a0e692017-06-28 17:27:01 -050050 auto purpose = VersionPurpose::Unknown;
Chanh Nguyen1fd6ddd2021-01-06 11:09:09 +070051 std::string extendedVersion;
Saqib Khan705f1bf2017-06-09 23:58:38 -050052 std::string version;
Justin Ledford054bb0b2022-03-15 15:46:58 -070053 std::map<std::string,
54 std::map<std::string,
55 std::variant<std::string, std::vector<std::string>>>>
Adriana Kobylak2285fe02018-02-27 15:36:59 -060056 interfaces;
Patrick Williamse75d10f2017-05-30 16:56:32 -050057 msg.read(objPath, interfaces);
Gunnar Mills2ce7da22017-05-04 15:37:56 -050058 std::string path(std::move(objPath));
Saqib Khan19177d32017-06-20 08:11:49 -050059 std::string filePath;
Justin Ledford054bb0b2022-03-15 15:46:58 -070060 std::vector<std::string> compatibleNames;
Gunnar Mills2ce7da22017-05-04 15:37:56 -050061
62 for (const auto& intf : interfaces)
63 {
Saqib Khan705f1bf2017-06-09 23:58:38 -050064 if (intf.first == VERSION_IFACE)
Gunnar Mills2ce7da22017-05-04 15:37:56 -050065 {
Saqib Khan705f1bf2017-06-09 23:58:38 -050066 for (const auto& property : intf.second)
Gunnar Mills2ce7da22017-05-04 15:37:56 -050067 {
Saqib Khan705f1bf2017-06-09 23:58:38 -050068 if (property.first == "Purpose")
Gunnar Mills2ce7da22017-05-04 15:37:56 -050069 {
Saqib Khan84a0e692017-06-28 17:27:01 -050070 auto value = SVersion::convertVersionPurposeFromString(
Patrick Williamse883fb82020-05-13 11:38:55 -050071 std::get<std::string>(property.second));
Saqib Khan84a0e692017-06-28 17:27:01 -050072 if (value == VersionPurpose::BMC ||
Vijay Khemkae9f6c842020-01-14 14:32:39 -080073#ifdef HOST_BIOS_UPGRADE
74 value == VersionPurpose::Host ||
75#endif
Saqib Khan84a0e692017-06-28 17:27:01 -050076 value == VersionPurpose::System)
77 {
78 purpose = value;
79 }
Saqib Khan705f1bf2017-06-09 23:58:38 -050080 }
81 else if (property.first == "Version")
82 {
Patrick Williamse883fb82020-05-13 11:38:55 -050083 version = std::get<std::string>(property.second);
Gunnar Mills2ce7da22017-05-04 15:37:56 -050084 }
85 }
86 }
Saqib Khan19177d32017-06-20 08:11:49 -050087 else if (intf.first == FILEPATH_IFACE)
88 {
89 for (const auto& property : intf.second)
90 {
91 if (property.first == "Path")
92 {
Patrick Williamse883fb82020-05-13 11:38:55 -050093 filePath = std::get<std::string>(property.second);
Saqib Khan19177d32017-06-20 08:11:49 -050094 }
95 }
96 }
Chanh Nguyen1fd6ddd2021-01-06 11:09:09 +070097 else if (intf.first == EXTENDED_VERSION_IFACE)
98 {
99 for (const auto& property : intf.second)
100 {
101 if (property.first == "ExtendedVersion")
102 {
103 extendedVersion = std::get<std::string>(property.second);
104 }
105 }
106 }
Justin Ledford054bb0b2022-03-15 15:46:58 -0700107 else if (intf.first == COMPATIBLE_IFACE)
108 {
109 for (const auto& property : intf.second)
110 {
111 if (property.first == "Names")
112 {
113 compatibleNames =
114 std::get<std::vector<std::string>>(property.second);
115 }
116 }
117 }
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500118 }
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600119 if (version.empty() || filePath.empty() ||
Saqib Khan84a0e692017-06-28 17:27:01 -0500120 purpose == VersionPurpose::Unknown)
Saqib Khan705f1bf2017-06-09 23:58:38 -0500121 {
122 return;
123 }
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500124
125 // Version id is the last item in the path
126 auto pos = path.rfind("/");
127 if (pos == std::string::npos)
128 {
Patrick Williamsc9bb6422021-08-27 06:18:35 -0500129 error("No version id found in object path: {PATH}", "PATH", path);
Patrick Williamse75d10f2017-05-30 16:56:32 -0500130 return;
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500131 }
132
133 auto versionId = path.substr(pos + 1);
134
Patrick Williamse75d10f2017-05-30 16:56:32 -0500135 if (activations.find(versionId) == activations.end())
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500136 {
Saqib Khan35e83f32017-05-22 11:37:32 -0500137 // Determine the Activation state by processing the given image dir.
138 auto activationState = server::Activation::Activations::Invalid;
Vijay Khemkae9f6c842020-01-14 14:32:39 -0800139 ItemUpdater::ActivationStatus result;
140 if (purpose == VersionPurpose::BMC || purpose == VersionPurpose::System)
141 result = ItemUpdater::validateSquashFSImage(filePath);
142 else
143 result = ItemUpdater::ActivationStatus::ready;
144
Gunnar Mills43b25cd2017-09-07 13:19:34 -0500145 AssociationList associations = {};
146
Saqib Khan35e83f32017-05-22 11:37:32 -0500147 if (result == ItemUpdater::ActivationStatus::ready)
148 {
149 activationState = server::Activation::Activations::Ready;
Gunnar Mills43b25cd2017-09-07 13:19:34 -0500150 // Create an association to the BMC inventory item
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600151 associations.emplace_back(
152 std::make_tuple(ACTIVATION_FWD_ASSOCIATION,
153 ACTIVATION_REV_ASSOCIATION, bmcInventoryPath));
Saqib Khan35e83f32017-05-22 11:37:32 -0500154 }
Gunnar Millsb60add12017-08-24 16:41:42 -0500155
Saqib Khanee13e832017-10-23 12:53:11 -0500156 auto versionPtr = std::make_unique<VersionClass>(
Chanh Nguyen1fd6ddd2021-01-06 11:09:09 +0700157 bus, path, version, purpose, extendedVersion, filePath,
Justin Ledford054bb0b2022-03-15 15:46:58 -0700158 compatibleNames,
Adriana Kobylak59b640b2022-01-21 19:45:22 +0000159 std::bind(&ItemUpdater::erase, this, std::placeholders::_1),
160 versionId);
Saqib Khanee13e832017-10-23 12:53:11 -0500161 versionPtr->deleteObject =
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600162 std::make_unique<phosphor::software::manager::Delete>(bus, path,
163 *versionPtr);
Saqib Khanee13e832017-10-23 12:53:11 -0500164 versions.insert(std::make_pair(versionId, std::move(versionPtr)));
Adriana Kobylak88ba1f92022-03-09 21:14:15 +0000165
166 activations.insert(std::make_pair(
167 versionId,
168 std::make_unique<Activation>(bus, path, *this, versionId,
169 activationState, associations)));
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500170 }
Patrick Williamse75d10f2017-05-30 16:56:32 -0500171 return;
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500172}
173
Saqib Khanba239882017-05-26 08:41:54 -0500174void ItemUpdater::processBMCImage()
175{
Gunnar Mills88e8a322017-09-13 11:09:28 -0500176 using VersionClass = phosphor::software::manager::Version;
Lei YU269bff32018-08-21 15:21:40 +0800177
178 // Check MEDIA_DIR and create if it does not exist
179 try
180 {
181 if (!fs::is_directory(MEDIA_DIR))
182 {
183 fs::create_directory(MEDIA_DIR);
184 }
185 }
186 catch (const fs::filesystem_error& e)
187 {
Patrick Williamsc9bb6422021-08-27 06:18:35 -0500188 error("Failed to prepare dir: {ERROR}", "ERROR", e);
Lei YU269bff32018-08-21 15:21:40 +0800189 return;
190 }
191
Adriana Kobylak1e81f232022-01-18 22:28:47 +0000192 // Functional images are mounted as rofs-<location>-functional
193 constexpr auto functionalSuffix = "-functional";
Lei YUd474d9c2021-12-10 16:21:21 +0800194 bool functionalFound = false;
Gunnar Mills88e8a322017-09-13 11:09:28 -0500195
Saqib Khan1eef62d2017-08-10 15:29:34 -0500196 // Read os-release from folders under /media/ to get
197 // BMC Software Versions.
George Liu44b9fef2023-02-07 14:31:32 +0800198 std::error_code ec;
199 for (const auto& iter : fs::directory_iterator(MEDIA_DIR, ec))
Saqib Khan1eef62d2017-08-10 15:29:34 -0500200 {
201 auto activationState = server::Activation::Activations::Active;
Saqib Khan6fab70d2017-09-07 00:13:50 -0500202 static const auto BMC_RO_PREFIX_LEN = strlen(BMC_ROFS_PREFIX);
Saqib Khan1eef62d2017-08-10 15:29:34 -0500203
204 // Check if the BMC_RO_PREFIXis the prefix of the iter.path
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600205 if (0 ==
206 iter.path().native().compare(0, BMC_RO_PREFIX_LEN, BMC_ROFS_PREFIX))
Saqib Khan1eef62d2017-08-10 15:29:34 -0500207 {
Adriana Kobylak716cd782020-06-08 13:27:43 -0500208 // Get the version to calculate the id
Adriana Kobylak24a8d832020-06-10 08:29:36 -0500209 fs::path releaseFile(OS_RELEASE_FILE);
210 auto osRelease = iter.path() / releaseFile.relative_path();
George Liu44b9fef2023-02-07 14:31:32 +0800211 if (!fs::is_regular_file(osRelease, ec))
Saqib Khan1eef62d2017-08-10 15:29:34 -0500212 {
Lei YUe56bf872022-02-22 18:40:37 +0800213#ifdef BMC_STATIC_DUAL_IMAGE
214 // For dual image, it is possible that the secondary image is
215 // empty or contains invalid data, ignore such case.
George Liu44b9fef2023-02-07 14:31:32 +0800216 info("Unable to find osRelease: {PATH}: {ERROR_MSG}", "PATH",
217 osRelease, "ERROR_MSG", ec.message());
Lei YUe56bf872022-02-22 18:40:37 +0800218#else
George Liu44b9fef2023-02-07 14:31:32 +0800219 error("Failed to read osRelease: {PATH}: {ERROR_MSG}", "PATH",
220 osRelease, "ERROR_MSG", ec.message());
Adriana Kobylak716cd782020-06-08 13:27:43 -0500221
222 // Try to get the version id from the mount directory name and
223 // call to delete it as this version may be corrupted. Dynamic
224 // volumes created by the UBI layout for example have the id in
225 // the mount directory name. The worst that can happen is that
226 // erase() is called with an non-existent id and returns.
227 auto id = iter.path().native().substr(BMC_RO_PREFIX_LEN);
Saqib Khan021c3652017-09-26 12:11:02 -0500228 ItemUpdater::erase(id);
Lei YUe56bf872022-02-22 18:40:37 +0800229#endif
Adriana Kobylak716cd782020-06-08 13:27:43 -0500230
Saqib Khan021c3652017-09-26 12:11:02 -0500231 continue;
Saqib Khan1eef62d2017-08-10 15:29:34 -0500232 }
Gunnar Mills88e8a322017-09-13 11:09:28 -0500233 auto version = VersionClass::getBMCVersion(osRelease);
Saqib Khan1eef62d2017-08-10 15:29:34 -0500234 if (version.empty())
235 {
Patrick Williamsc9bb6422021-08-27 06:18:35 -0500236 error("Failed to read version from osRelease: {PATH}", "PATH",
237 osRelease);
Adriana Kobylak716cd782020-06-08 13:27:43 -0500238
239 // Try to delete the version, same as above if the
240 // OS_RELEASE_FILE does not exist.
241 auto id = iter.path().native().substr(BMC_RO_PREFIX_LEN);
242 ItemUpdater::erase(id);
243
244 continue;
Saqib Khan1eef62d2017-08-10 15:29:34 -0500245 }
Saqib Khan021c3652017-09-26 12:11:02 -0500246
Adriana Kobylak59b640b2022-01-21 19:45:22 +0000247 // The flash location is part of the mount name: rofs-<location>
248 auto flashId = iter.path().native().substr(BMC_RO_PREFIX_LEN);
249
250 auto id = VersionClass::getId(version + flashId);
Adriana Kobylak716cd782020-06-08 13:27:43 -0500251
Adriana Kobylakf383d272020-06-16 15:17:22 -0500252 // Check if the id has already been added. This can happen if the
253 // BMC partitions / devices were manually flashed with the same
254 // image.
255 if (versions.find(id) != versions.end())
256 {
257 continue;
258 }
259
Adriana Kobylak1e81f232022-01-18 22:28:47 +0000260 auto functional = false;
261 if (iter.path().native().find(functionalSuffix) !=
262 std::string::npos)
263 {
264 // Set functional to true and remove the functional suffix
265 functional = true;
266 flashId.erase(flashId.length() - strlen(functionalSuffix));
Lei YUd474d9c2021-12-10 16:21:21 +0800267 functionalFound = true;
Adriana Kobylak1e81f232022-01-18 22:28:47 +0000268 }
Adriana Kobylak780220f2022-01-18 20:01:53 +0000269
Saqib Khan1eef62d2017-08-10 15:29:34 -0500270 auto purpose = server::Version::VersionPurpose::BMC;
Adriana Kobylak780220f2022-01-18 20:01:53 +0000271 restorePurpose(flashId, purpose);
Adriana Kobylakec4eec32019-11-13 14:28:35 -0600272
Chanh Nguyen1fd6ddd2021-01-06 11:09:09 +0700273 // Read os-release from /etc/ to get the BMC extended version
274 std::string extendedVersion =
275 VersionClass::getBMCExtendedVersion(osRelease);
276
Saqib Khan1eef62d2017-08-10 15:29:34 -0500277 auto path = fs::path(SOFTWARE_OBJPATH) / id;
278
Lei YU269bff32018-08-21 15:21:40 +0800279 // Create functional association if this is the functional
280 // version
Adriana Kobylak1e81f232022-01-18 22:28:47 +0000281 if (functional)
Gunnar Mills88e8a322017-09-13 11:09:28 -0500282 {
283 createFunctionalAssociation(path);
284 }
285
Gunnar Mills43b25cd2017-09-07 13:19:34 -0500286 AssociationList associations = {};
287
288 if (activationState == server::Activation::Activations::Active)
289 {
290 // Create an association to the BMC inventory item
291 associations.emplace_back(std::make_tuple(
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600292 ACTIVATION_FWD_ASSOCIATION, ACTIVATION_REV_ASSOCIATION,
293 bmcInventoryPath));
Gunnar Mills43b25cd2017-09-07 13:19:34 -0500294
295 // Create an active association since this image is active
296 createActiveAssociation(path);
297 }
298
AppaRao Pulibbebec72020-01-28 23:57:41 +0530299 // All updateable firmware components must expose the updateable
300 // association.
301 createUpdateableAssociation(path);
302
Adriana Kobylakee590c72017-09-26 15:16:06 -0500303 // Create Version instance for this version.
304 auto versionPtr = std::make_unique<VersionClass>(
Adriana Kobylaka84f06d2022-01-18 15:41:57 +0000305 bus, path, version, purpose, extendedVersion, flashId,
Justin Ledford054bb0b2022-03-15 15:46:58 -0700306 std::vector<std::string>(),
Adriana Kobylak59b640b2022-01-21 19:45:22 +0000307 std::bind(&ItemUpdater::erase, this, std::placeholders::_1),
308 id);
Adriana Kobylak1e81f232022-01-18 22:28:47 +0000309 if (functional)
310 {
311 versionPtr->setFunctional(true);
312 }
313 else
Michael Tritz4254bec2017-10-03 17:18:22 -0500314 {
Saqib Khanee13e832017-10-23 12:53:11 -0500315 versionPtr->deleteObject =
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600316 std::make_unique<phosphor::software::manager::Delete>(
317 bus, path, *versionPtr);
Michael Tritz4254bec2017-10-03 17:18:22 -0500318 }
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600319 versions.insert(std::make_pair(id, std::move(versionPtr)));
Michael Tritz4254bec2017-10-03 17:18:22 -0500320
Saqib Khanee13e832017-10-23 12:53:11 -0500321 // Create Activation instance for this version.
322 activations.insert(std::make_pair(
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600323 id, std::make_unique<Activation>(
324 bus, path, *this, id, activationState, associations)));
Saqib Khan1eef62d2017-08-10 15:29:34 -0500325
Lei YUbdf2d6c2021-12-15 14:05:01 +0800326#ifdef BMC_STATIC_DUAL_IMAGE
327 uint8_t priority;
328 if ((functional && (runningImageSlot == 0)) ||
329 (!functional && (runningImageSlot == 1)))
330 {
331 priority = 0;
332 }
333 else
334 {
335 priority = 1;
336 }
337 activations.find(id)->second->redundancyPriority =
338 std::make_unique<RedundancyPriority>(
339 bus, path, *(activations.find(id)->second), priority,
340 false);
341#else
Lei YU269bff32018-08-21 15:21:40 +0800342 // If Active, create RedundancyPriority instance for this
343 // version.
Saqib Khan1eef62d2017-08-10 15:29:34 -0500344 if (activationState == server::Activation::Activations::Active)
345 {
346 uint8_t priority = std::numeric_limits<uint8_t>::max();
Adriana Kobylak780220f2022-01-18 20:01:53 +0000347 if (!restorePriority(flashId, priority))
Saqib Khan1eef62d2017-08-10 15:29:34 -0500348 {
Adriana Kobylak1e81f232022-01-18 22:28:47 +0000349 if (functional)
Adriana Kobylakee590c72017-09-26 15:16:06 -0500350 {
351 priority = 0;
352 }
353 else
354 {
Patrick Williamsc9bb6422021-08-27 06:18:35 -0500355 error(
356 "Unable to restore priority from file for {VERSIONID}",
357 "VERSIONID", id);
Adriana Kobylakee590c72017-09-26 15:16:06 -0500358 }
Saqib Khan1eef62d2017-08-10 15:29:34 -0500359 }
360 activations.find(id)->second->redundancyPriority =
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600361 std::make_unique<RedundancyPriority>(
362 bus, path, *(activations.find(id)->second), priority,
363 false);
Saqib Khan1eef62d2017-08-10 15:29:34 -0500364 }
Lei YUbdf2d6c2021-12-15 14:05:01 +0800365#endif
Saqib Khan1eef62d2017-08-10 15:29:34 -0500366 }
367 }
Saqib Khandcbfa042017-09-18 13:08:39 -0500368
Lei YUd474d9c2021-12-10 16:21:21 +0800369 if (!functionalFound)
Saqib Khandcbfa042017-09-18 13:08:39 -0500370 {
Lei YUd474d9c2021-12-10 16:21:21 +0800371 // If there is no functional version found, read the /etc/os-release and
372 // create rofs-<versionId>-functional under MEDIA_DIR, then call again
373 // processBMCImage() to create the D-Bus interface for it.
Gunnar Millsd16bcbd2017-10-08 16:50:42 -0500374 auto version = VersionClass::getBMCVersion(OS_RELEASE_FILE);
Adriana Kobylak59b640b2022-01-21 19:45:22 +0000375 auto id = phosphor::software::manager::Version::getId(version +
376 functionalSuffix);
Adriana Kobylak1e81f232022-01-18 22:28:47 +0000377 auto versionFileDir = BMC_ROFS_PREFIX + id + functionalSuffix + "/etc/";
Saqib Khandcbfa042017-09-18 13:08:39 -0500378 try
379 {
Gunnar Millsd16bcbd2017-10-08 16:50:42 -0500380 if (!fs::is_directory(versionFileDir))
Saqib Khandcbfa042017-09-18 13:08:39 -0500381 {
382 fs::create_directories(versionFileDir);
383 }
Adriana Kobylak1e81f232022-01-18 22:28:47 +0000384 auto versionFilePath =
385 BMC_ROFS_PREFIX + id + functionalSuffix + OS_RELEASE_FILE;
Saqib Khandcbfa042017-09-18 13:08:39 -0500386 fs::create_directory_symlink(OS_RELEASE_FILE, versionFilePath);
387 ItemUpdater::processBMCImage();
388 }
389 catch (const std::exception& e)
390 {
Patrick Williamsc9bb6422021-08-27 06:18:35 -0500391 error("Exception during processing: {ERROR}", "ERROR", e);
Saqib Khandcbfa042017-09-18 13:08:39 -0500392 }
393 }
Eddie Jameseaa1ee02018-03-01 10:09:10 -0600394
395 mirrorUbootToAlt();
Saqib Khanba239882017-05-26 08:41:54 -0500396 return;
397}
398
Leonel Gonzalez3526ef72017-07-07 14:38:25 -0500399void ItemUpdater::erase(std::string entryId)
400{
Eddie James6d873712017-09-01 11:29:07 -0500401 // Find entry in versions map
402 auto it = versions.find(entryId);
403 if (it != versions.end())
404 {
Lei YU0f88b5a2018-08-21 15:28:53 +0800405 if (it->second->isFunctional() && ACTIVE_BMC_MAX_ALLOWED > 1)
Eddie James6d873712017-09-01 11:29:07 -0500406 {
Patrick Williamsc9bb6422021-08-27 06:18:35 -0500407 error(
408 "Version ({VERSIONID}) is currently running on the BMC; unable to remove.",
409 "VERSIONID", entryId);
Gunnar Millsd16bcbd2017-10-08 16:50:42 -0500410 return;
Eddie James6d873712017-09-01 11:29:07 -0500411 }
Adriana Kobylakd1a55ad2020-06-11 14:01:28 -0500412 }
Eddie James6d873712017-09-01 11:29:07 -0500413
Adriana Kobylakd1a55ad2020-06-11 14:01:28 -0500414 // First call resetUbootEnvVars() so that the BMC points to a valid image to
415 // boot from. If resetUbootEnvVars() is called after the image is actually
416 // deleted from the BMC flash, there'd be a time window where the BMC would
417 // be pointing to a non-existent image to boot from.
418 // Need to remove the entries from the activations map before that call so
419 // that resetUbootEnvVars() doesn't use the version to be deleted.
420 auto iteratorActivations = activations.find(entryId);
421 if (iteratorActivations == activations.end())
422 {
Patrick Williamsc9bb6422021-08-27 06:18:35 -0500423 error(
424 "Failed to find version ({VERSIONID}) in item updater activations map; unable to remove.",
425 "VERSIONID", entryId);
Adriana Kobylakd1a55ad2020-06-11 14:01:28 -0500426 }
427 else
428 {
429 removeAssociations(iteratorActivations->second->path);
Zami Seckae06d762021-08-13 20:11:15 -0500430 iteratorActivations->second->deleteImageManagerObject();
Adriana Kobylakd1a55ad2020-06-11 14:01:28 -0500431 this->activations.erase(entryId);
432 }
433 ItemUpdater::resetUbootEnvVars();
434
435 if (it != versions.end())
436 {
Adriana Kobylak780220f2022-01-18 20:01:53 +0000437 auto flashId = it->second->path();
438
Adriana Kobylak25773a72022-01-21 15:24:48 +0000439 // Delete version data if it has been installed on flash (path is not
440 // the upload directory)
441 if (flashId.find(IMG_UPLOAD_DIR) == std::string::npos)
442 {
443 removeReadOnlyPartition(entryId);
444 removePersistDataDirectory(flashId);
445 helper.clearEntry(flashId);
446 }
Saqib Khanee13e832017-10-23 12:53:11 -0500447
448 // Removing entry in versions map
449 this->versions.erase(entryId);
Eddie James6d873712017-09-01 11:29:07 -0500450 }
Leonel Gonzalez3526ef72017-07-07 14:38:25 -0500451
Saqib Khanee13e832017-10-23 12:53:11 -0500452 return;
Leonel Gonzalez3526ef72017-07-07 14:38:25 -0500453}
454
Michael Tritzbc1bf3a2017-09-18 16:38:23 -0500455void ItemUpdater::deleteAll()
456{
Adriana Kobylak83cd21f2018-02-28 15:48:48 -0600457 std::vector<std::string> deletableVersions;
458
Michael Tritzbc1bf3a2017-09-18 16:38:23 -0500459 for (const auto& versionIt : versions)
460 {
461 if (!versionIt.second->isFunctional())
462 {
Adriana Kobylak83cd21f2018-02-28 15:48:48 -0600463 deletableVersions.push_back(versionIt.first);
Michael Tritzbc1bf3a2017-09-18 16:38:23 -0500464 }
465 }
466
Adriana Kobylak83cd21f2018-02-28 15:48:48 -0600467 for (const auto& deletableIt : deletableVersions)
468 {
469 ItemUpdater::erase(deletableIt);
470 }
471
Lei YU56aaf452018-06-21 16:09:44 +0800472 helper.cleanup();
Michael Tritzbc1bf3a2017-09-18 16:38:23 -0500473}
474
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600475ItemUpdater::ActivationStatus
476 ItemUpdater::validateSquashFSImage(const std::string& filePath)
Saqib Khan35e83f32017-05-22 11:37:32 -0500477{
Bright Cheng8e9ccfe2019-11-18 16:18:44 +0800478 bool valid = true;
Saqib Khan35e83f32017-05-22 11:37:32 -0500479
Bright Cheng8e9ccfe2019-11-18 16:18:44 +0800480 // Record the images which are being updated
481 // First check for the fullimage, then check for images with partitions
482 imageUpdateList.push_back(bmcFullImages);
483 valid = checkImage(filePath, imageUpdateList);
484 if (!valid)
Saqib Khan35e83f32017-05-22 11:37:32 -0500485 {
Bright Cheng8e9ccfe2019-11-18 16:18:44 +0800486 imageUpdateList.clear();
487 imageUpdateList.assign(bmcImages.begin(), bmcImages.end());
488 valid = checkImage(filePath, imageUpdateList);
489 if (!valid)
Michael Tritzb1cfdf92017-08-14 14:33:30 -0500490 {
Patrick Williamsc9bb6422021-08-27 06:18:35 -0500491 error("Failed to find the needed BMC images.");
Bright Cheng8e9ccfe2019-11-18 16:18:44 +0800492 return ItemUpdater::ActivationStatus::invalid;
Michael Tritzb1cfdf92017-08-14 14:33:30 -0500493 }
Saqib Khan35e83f32017-05-22 11:37:32 -0500494 }
Michael Tritzb1cfdf92017-08-14 14:33:30 -0500495
Michael Tritzb1cfdf92017-08-14 14:33:30 -0500496 return ItemUpdater::ActivationStatus::ready;
Saqib Khan35e83f32017-05-22 11:37:32 -0500497}
498
Adriana Kobylakbbcb7be2018-07-17 15:47:34 -0500499void ItemUpdater::savePriority(const std::string& versionId, uint8_t value)
500{
Adriana Kobylak780220f2022-01-18 20:01:53 +0000501 auto flashId = versions.find(versionId)->second->path();
502 storePriority(flashId, value);
Adriana Kobylak25773a72022-01-21 15:24:48 +0000503 helper.setEntry(flashId, value);
Adriana Kobylakbbcb7be2018-07-17 15:47:34 -0500504}
505
Saqib Khanb9da6632017-09-13 09:48:37 -0500506void ItemUpdater::freePriority(uint8_t value, const std::string& versionId)
Saqib Khan4c1aec02017-07-06 11:46:13 -0500507{
Adriana Kobylakb77551c2017-10-27 12:46:23 -0500508 std::map<std::string, uint8_t> priorityMap;
509
510 // Insert the requested version and priority, it may not exist yet.
511 priorityMap.insert(std::make_pair(versionId, value));
512
Saqib Khan4c1aec02017-07-06 11:46:13 -0500513 for (const auto& intf : activations)
514 {
Gunnar Mills9a782242017-08-22 16:23:15 -0500515 if (intf.second->redundancyPriority)
Saqib Khan4c1aec02017-07-06 11:46:13 -0500516 {
Adriana Kobylakb77551c2017-10-27 12:46:23 -0500517 priorityMap.insert(std::make_pair(
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600518 intf.first, intf.second->redundancyPriority.get()->priority()));
Saqib Khan4c1aec02017-07-06 11:46:13 -0500519 }
520 }
Adriana Kobylakb77551c2017-10-27 12:46:23 -0500521
522 // Lambda function to compare 2 priority values, use <= to allow duplicates
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600523 typedef std::function<bool(std::pair<std::string, uint8_t>,
524 std::pair<std::string, uint8_t>)>
525 cmpPriority;
526 cmpPriority cmpPriorityFunc =
527 [](std::pair<std::string, uint8_t> priority1,
528 std::pair<std::string, uint8_t> priority2) {
529 return priority1.second <= priority2.second;
530 };
Adriana Kobylakb77551c2017-10-27 12:46:23 -0500531
532 // Sort versions by ascending priority
533 std::set<std::pair<std::string, uint8_t>, cmpPriority> prioritySet(
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600534 priorityMap.begin(), priorityMap.end(), cmpPriorityFunc);
Adriana Kobylakb77551c2017-10-27 12:46:23 -0500535
536 auto freePriorityValue = value;
537 for (auto& element : prioritySet)
538 {
539 if (element.first == versionId)
540 {
541 continue;
542 }
543 if (element.second == freePriorityValue)
544 {
545 ++freePriorityValue;
546 auto it = activations.find(element.first);
547 it->second->redundancyPriority.get()->sdbusPriority(
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600548 freePriorityValue);
Adriana Kobylakb77551c2017-10-27 12:46:23 -0500549 }
550 }
551
552 auto lowestVersion = prioritySet.begin()->first;
553 if (value == prioritySet.begin()->second)
554 {
555 lowestVersion = versionId;
556 }
557 updateUbootEnvVars(lowestVersion);
Saqib Khan4c1aec02017-07-06 11:46:13 -0500558}
559
Michael Tritz37a59042017-07-12 13:44:53 -0500560void ItemUpdater::reset()
561{
Lei YU56aaf452018-06-21 16:09:44 +0800562 helper.factoryReset();
Michael Tritz37a59042017-07-12 13:44:53 -0500563
Patrick Williamsc9bb6422021-08-27 06:18:35 -0500564 info("BMC factory reset will take effect upon reboot.");
Michael Tritz37a59042017-07-12 13:44:53 -0500565}
566
Leonel Gonzalez3526ef72017-07-07 14:38:25 -0500567void ItemUpdater::removeReadOnlyPartition(std::string versionId)
568{
Adriana Kobylak25773a72022-01-21 15:24:48 +0000569 auto flashId = versions.find(versionId)->second->path();
570 helper.removeVersion(flashId);
Leonel Gonzalez3526ef72017-07-07 14:38:25 -0500571}
572
Michael Tritz0129d922017-08-10 19:33:46 -0500573bool ItemUpdater::fieldModeEnabled(bool value)
574{
575 // enabling field mode is intended to be one way: false -> true
576 if (value && !control::FieldMode::fieldModeEnabled())
577 {
578 control::FieldMode::fieldModeEnabled(value);
579
Adriana Kobylak22848ec2019-10-28 10:08:39 -0500580 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
581 SYSTEMD_INTERFACE, "StartUnit");
582 method.append("obmc-flash-bmc-setenv@fieldmode\\x3dtrue.service",
583 "replace");
584 bus.call_noreply(method);
585
586 method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
587 SYSTEMD_INTERFACE, "StopUnit");
588 method.append("usr-local.mount", "replace");
589 bus.call_noreply(method);
590
591 std::vector<std::string> usrLocal = {"usr-local.mount"};
592
593 method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
594 SYSTEMD_INTERFACE, "MaskUnitFiles");
595 method.append(usrLocal, false, true);
596 bus.call_noreply(method);
Michael Tritz0129d922017-08-10 19:33:46 -0500597 }
Adriana Kobylakd5b8f752019-05-01 11:52:35 -0500598 else if (!value && control::FieldMode::fieldModeEnabled())
599 {
600 elog<NotAllowed>(xyz::openbmc_project::Common::NotAllowed::REASON(
601 "FieldMode is not allowed to be cleared"));
602 }
Michael Tritz0129d922017-08-10 19:33:46 -0500603
604 return control::FieldMode::fieldModeEnabled();
605}
606
607void ItemUpdater::restoreFieldModeStatus()
608{
Isaac Kurthdeb86b42022-03-08 19:47:53 -0600609 // The fieldmode u-boot environment variable may not exist since it is not
610 // part of the default environment, run fw_printenv with 2>&1 to ignore the
611 // error message in the journal "Error: "fieldmode" not defined"
612 std::pair<int, std::string> ret =
613 utils::execute("/sbin/fw_printenv", "-n", "fieldmode", "2>&1");
Michael Tritz0129d922017-08-10 19:33:46 -0500614
Isaac Kurthdeb86b42022-03-08 19:47:53 -0600615 if (ret.first != 0)
616 {
617 return;
618 }
619
620 // truncate any extra characters off the end to compare against a "true" str
621 std::string result = ret.second.substr(0, 4);
622 if (result == "true")
Michael Tritz0129d922017-08-10 19:33:46 -0500623 {
624 ItemUpdater::fieldModeEnabled(true);
625 }
626}
627
Gunnar Millsb60add12017-08-24 16:41:42 -0500628void ItemUpdater::setBMCInventoryPath()
629{
Gunnar Millsb60add12017-08-24 16:41:42 -0500630 auto depth = 0;
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600631 auto mapperCall = bus.new_method_call(MAPPER_BUSNAME, MAPPER_PATH,
632 MAPPER_INTERFACE, "GetSubTreePaths");
Gunnar Millsb60add12017-08-24 16:41:42 -0500633
Adriana Kobylak1254c622017-12-07 12:24:56 -0600634 mapperCall.append(INVENTORY_PATH);
Gunnar Millsb60add12017-08-24 16:41:42 -0500635 mapperCall.append(depth);
Adriana Kobylak1254c622017-12-07 12:24:56 -0600636 std::vector<std::string> filter = {BMC_INVENTORY_INTERFACE};
Gunnar Millsb60add12017-08-24 16:41:42 -0500637 mapperCall.append(filter);
638
Ed Tanous87c78172018-08-10 12:51:53 -0700639 try
640 {
641 auto response = bus.call(mapperCall);
642
643 using ObjectPaths = std::vector<std::string>;
644 ObjectPaths result;
645 response.read(result);
646
647 if (!result.empty())
648 {
649 bmcInventoryPath = result.front();
650 }
651 }
Patrick Williamsbf2bb2b2022-07-22 19:26:52 -0500652 catch (const sdbusplus::exception_t& e)
Gunnar Millsb60add12017-08-24 16:41:42 -0500653 {
Patrick Williamsc9bb6422021-08-27 06:18:35 -0500654 error("Error in mapper GetSubTreePath: {ERROR}", "ERROR", e);
Gunnar Millsb60add12017-08-24 16:41:42 -0500655 return;
656 }
657
Adriana Kobylak1254c622017-12-07 12:24:56 -0600658 return;
Gunnar Millsb60add12017-08-24 16:41:42 -0500659}
660
Gunnar Millsf10b2322017-09-21 15:31:55 -0500661void ItemUpdater::createActiveAssociation(const std::string& path)
Gunnar Millsded875d2017-08-28 16:44:52 -0500662{
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600663 assocs.emplace_back(
664 std::make_tuple(ACTIVE_FWD_ASSOCIATION, ACTIVE_REV_ASSOCIATION, path));
Gunnar Millsded875d2017-08-28 16:44:52 -0500665 associations(assocs);
666}
667
Gunnar Mills88e8a322017-09-13 11:09:28 -0500668void ItemUpdater::createFunctionalAssociation(const std::string& path)
669{
670 assocs.emplace_back(std::make_tuple(FUNCTIONAL_FWD_ASSOCIATION,
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600671 FUNCTIONAL_REV_ASSOCIATION, path));
Gunnar Mills88e8a322017-09-13 11:09:28 -0500672 associations(assocs);
673}
674
AppaRao Pulibbebec72020-01-28 23:57:41 +0530675void ItemUpdater::createUpdateableAssociation(const std::string& path)
676{
677 assocs.emplace_back(std::make_tuple(UPDATEABLE_FWD_ASSOCIATION,
678 UPDATEABLE_REV_ASSOCIATION, path));
679 associations(assocs);
680}
681
Adriana Kobylak991af7e2018-12-10 13:08:38 -0600682void ItemUpdater::removeAssociations(const std::string& path)
Gunnar Millsded875d2017-08-28 16:44:52 -0500683{
684 for (auto iter = assocs.begin(); iter != assocs.end();)
685 {
Adriana Kobylak991af7e2018-12-10 13:08:38 -0600686 if ((std::get<2>(*iter)).compare(path) == 0)
Gunnar Millsded875d2017-08-28 16:44:52 -0500687 {
688 iter = assocs.erase(iter);
689 associations(assocs);
690 }
691 else
692 {
693 ++iter;
694 }
695 }
696}
697
Saqib Khanb9da6632017-09-13 09:48:37 -0500698bool ItemUpdater::isLowestPriority(uint8_t value)
699{
700 for (const auto& intf : activations)
701 {
Gunnar Millsd16bcbd2017-10-08 16:50:42 -0500702 if (intf.second->redundancyPriority)
Saqib Khanb9da6632017-09-13 09:48:37 -0500703 {
704 if (intf.second->redundancyPriority.get()->priority() < value)
705 {
706 return false;
707 }
708 }
709 }
710 return true;
711}
712
Adriana Kobylakb77551c2017-10-27 12:46:23 -0500713void ItemUpdater::updateUbootEnvVars(const std::string& versionId)
714{
Lei YU9c76a0a2022-03-14 11:37:15 +0800715 auto it = versions.find(versionId);
716 if (it == versions.end())
717 {
718 return;
719 }
720 auto flashId = it->second->path();
Adriana Kobylak25773a72022-01-21 15:24:48 +0000721 helper.updateUbootVersionId(flashId);
Adriana Kobylakb77551c2017-10-27 12:46:23 -0500722}
723
Saqib Khan49446ae2017-10-02 10:54:20 -0500724void ItemUpdater::resetUbootEnvVars()
725{
726 decltype(activations.begin()->second->redundancyPriority.get()->priority())
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600727 lowestPriority = std::numeric_limits<uint8_t>::max();
Saqib Khan49446ae2017-10-02 10:54:20 -0500728 decltype(activations.begin()->second->versionId) lowestPriorityVersion;
729 for (const auto& intf : activations)
730 {
731 if (!intf.second->redundancyPriority.get())
732 {
733 // Skip this version if the redundancyPriority is not initialized.
734 continue;
735 }
736
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600737 if (intf.second->redundancyPriority.get()->priority() <= lowestPriority)
Saqib Khan49446ae2017-10-02 10:54:20 -0500738 {
739 lowestPriority = intf.second->redundancyPriority.get()->priority();
740 lowestPriorityVersion = intf.second->versionId;
741 }
742 }
743
Saqib Khanf0382c32017-10-24 13:36:22 -0500744 // Update the U-boot environment variable to point to the lowest priority
Adriana Kobylakb77551c2017-10-27 12:46:23 -0500745 updateUbootEnvVars(lowestPriorityVersion);
Saqib Khan49446ae2017-10-02 10:54:20 -0500746}
747
Lei YUd8c9eea2021-12-16 16:08:30 +0800748void ItemUpdater::freeSpace([[maybe_unused]] const Activation& caller)
Adriana Kobylak204e1e72018-01-24 16:00:05 -0600749{
Lei YUd8c9eea2021-12-16 16:08:30 +0800750#ifdef BMC_STATIC_DUAL_IMAGE
751 // For the golden image case, always remove the version on the primary side
752 std::string versionIDtoErase;
753 for (const auto& iter : activations)
754 {
755 if (iter.second->redundancyPriority &&
756 iter.second->redundancyPriority.get()->priority() == 0)
757 {
758 versionIDtoErase = iter.second->versionId;
759 break;
760 }
761 }
762 if (!versionIDtoErase.empty())
763 {
764 erase(versionIDtoErase);
765 }
766 else
767 {
768 warning("Failed to find version to erase");
769 }
770#else
Adriana Kobylak204e1e72018-01-24 16:00:05 -0600771 // Versions with the highest priority in front
772 std::priority_queue<std::pair<int, std::string>,
773 std::vector<std::pair<int, std::string>>,
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600774 std::less<std::pair<int, std::string>>>
775 versionsPQ;
Adriana Kobylak204e1e72018-01-24 16:00:05 -0600776
777 std::size_t count = 0;
778 for (const auto& iter : activations)
779 {
780 if ((iter.second.get()->activation() ==
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600781 server::Activation::Activations::Active) ||
Adriana Kobylak204e1e72018-01-24 16:00:05 -0600782 (iter.second.get()->activation() ==
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600783 server::Activation::Activations::Failed))
Adriana Kobylak204e1e72018-01-24 16:00:05 -0600784 {
785 count++;
786 // Don't put the functional version on the queue since we can't
787 // remove the "running" BMC version.
Lei YU0f88b5a2018-08-21 15:28:53 +0800788 // If ACTIVE_BMC_MAX_ALLOWED <= 1, there is only one active BMC,
789 // so remove functional version as well.
Adriana Kobylaka6963592018-09-07 14:13:29 -0500790 // Don't delete the the Activation object that called this function.
791 if ((versions.find(iter.second->versionId)
792 ->second->isFunctional() &&
793 ACTIVE_BMC_MAX_ALLOWED > 1) ||
794 (iter.second->versionId == caller.versionId))
Adriana Kobylak204e1e72018-01-24 16:00:05 -0600795 {
796 continue;
797 }
Adriana Kobylaka6963592018-09-07 14:13:29 -0500798
799 // Failed activations don't have priority, assign them a large value
800 // for sorting purposes.
801 auto priority = 999;
802 if (iter.second.get()->activation() ==
Lei YUcfb4b202021-05-06 17:47:28 +0800803 server::Activation::Activations::Active &&
804 iter.second->redundancyPriority)
Adriana Kobylaka6963592018-09-07 14:13:29 -0500805 {
806 priority = iter.second->redundancyPriority.get()->priority();
807 }
808
809 versionsPQ.push(std::make_pair(priority, iter.second->versionId));
Adriana Kobylak204e1e72018-01-24 16:00:05 -0600810 }
811 }
812
813 // If the number of BMC versions is over ACTIVE_BMC_MAX_ALLOWED -1,
814 // remove the highest priority one(s).
815 while ((count >= ACTIVE_BMC_MAX_ALLOWED) && (!versionsPQ.empty()))
816 {
817 erase(versionsPQ.top().second);
818 versionsPQ.pop();
819 count--;
820 }
Lei YUd8c9eea2021-12-16 16:08:30 +0800821#endif
Adriana Kobylak204e1e72018-01-24 16:00:05 -0600822}
823
Eddie Jameseaa1ee02018-03-01 10:09:10 -0600824void ItemUpdater::mirrorUbootToAlt()
825{
Lei YU56aaf452018-06-21 16:09:44 +0800826 helper.mirrorAlt();
Eddie Jameseaa1ee02018-03-01 10:09:10 -0600827}
828
Bright Cheng8e9ccfe2019-11-18 16:18:44 +0800829bool ItemUpdater::checkImage(const std::string& filePath,
830 const std::vector<std::string>& imageList)
831{
832 bool valid = true;
833
834 for (auto& bmcImage : imageList)
835 {
836 fs::path file(filePath);
837 file /= bmcImage;
838 std::ifstream efile(file.c_str());
839 if (efile.good() != 1)
840 {
841 valid = false;
842 break;
843 }
844 }
845
846 return valid;
847}
848
Lei YU6e9fb1d2021-02-19 18:01:40 +0800849#ifdef HOST_BIOS_UPGRADE
850void ItemUpdater::createBIOSObject()
851{
852 std::string path = BIOS_OBJPATH;
853 // Get version id from last item in the path
854 auto pos = path.rfind("/");
855 if (pos == std::string::npos)
856 {
Patrick Williamsc9bb6422021-08-27 06:18:35 -0500857 error("No version id found in object path {PATH}", "PATH", path);
Lei YU6e9fb1d2021-02-19 18:01:40 +0800858 return;
859 }
860
861 createActiveAssociation(path);
862 createFunctionalAssociation(path);
863
864 auto versionId = path.substr(pos + 1);
865 auto version = "null";
866 AssociationList assocs = {};
867 biosActivation = std::make_unique<Activation>(
868 bus, path, *this, versionId, server::Activation::Activations::Active,
869 assocs);
870 auto dummyErase = [](std::string /*entryId*/) {
871 // Do nothing;
872 };
873 biosVersion = std::make_unique<VersionClass>(
874 bus, path, version, VersionPurpose::Host, "", "",
Justin Ledford054bb0b2022-03-15 15:46:58 -0700875 std::vector<std::string>(),
Adriana Kobylak59b640b2022-01-21 19:45:22 +0000876 std::bind(dummyErase, std::placeholders::_1), "");
Lei YU6e9fb1d2021-02-19 18:01:40 +0800877 biosVersion->deleteObject =
878 std::make_unique<phosphor::software::manager::Delete>(bus, path,
879 *biosVersion);
880}
881#endif
882
Lei YU531fbc22021-12-10 20:03:18 +0800883void ItemUpdater::getRunningSlot()
884{
885 // Check /run/media/slot to get the slot number
886 constexpr auto slotFile = "/run/media/slot";
887 std::fstream f(slotFile, std::ios_base::in);
888 f >> runningImageSlot;
889}
890
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500891} // namespace updater
892} // namespace software
893} // namespace phosphor