blob: 9cb946703337019bf503a3ca2f7917f78f15b508 [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
Patrick Williams1e9a5f12023-08-23 16:53:06 -050032namespace server = sdbusplus::server::xyz::openbmc_project::software;
33namespace control = sdbusplus::server::xyz::openbmc_project::control;
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 Kobylakce82de52024-01-16 13:56:38 -060037using namespace sdbusplus::error::xyz::openbmc_project::software::image;
Jayanth Othayoth2ab9b102018-02-21 05:27:47 -060038using namespace phosphor::software::image;
Adriana Kobylakc98d9122020-05-05 10:36:01 -050039namespace fs = std::filesystem;
Adriana Kobylakce82de52024-01-16 13:56:38 -060040using NotAllowed = sdbusplus::error::xyz::openbmc_project::common::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 using SVersion = server::Version;
45 using VersionPurpose = SVersion::VersionPurpose;
Gunnar Mills9a782242017-08-22 16:23:15 -050046 using VersionClass = phosphor::software::manager::Version;
Saqib Khan84a0e692017-06-28 17:27:01 -050047
Patrick Williamsbc1facd2020-06-03 05:58:27 -050048 sdbusplus::message::object_path objPath;
Saqib Khan84a0e692017-06-28 17:27:01 -050049 auto purpose = VersionPurpose::Unknown;
Chanh Nguyen1fd6ddd2021-01-06 11:09:09 +070050 std::string extendedVersion;
Saqib Khan705f1bf2017-06-09 23:58:38 -050051 std::string version;
Justin Ledford054bb0b2022-03-15 15:46:58 -070052 std::map<std::string,
53 std::map<std::string,
54 std::variant<std::string, std::vector<std::string>>>>
Adriana Kobylak2285fe02018-02-27 15:36:59 -060055 interfaces;
Patrick Williamse75d10f2017-05-30 16:56:32 -050056 msg.read(objPath, interfaces);
Gunnar Mills2ce7da22017-05-04 15:37:56 -050057 std::string path(std::move(objPath));
Saqib Khan19177d32017-06-20 08:11:49 -050058 std::string filePath;
Justin Ledford054bb0b2022-03-15 15:46:58 -070059 std::vector<std::string> compatibleNames;
Gunnar Mills2ce7da22017-05-04 15:37:56 -050060
61 for (const auto& intf : interfaces)
62 {
Saqib Khan705f1bf2017-06-09 23:58:38 -050063 if (intf.first == VERSION_IFACE)
Gunnar Mills2ce7da22017-05-04 15:37:56 -050064 {
Saqib Khan705f1bf2017-06-09 23:58:38 -050065 for (const auto& property : intf.second)
Gunnar Mills2ce7da22017-05-04 15:37:56 -050066 {
Saqib Khan705f1bf2017-06-09 23:58:38 -050067 if (property.first == "Purpose")
Gunnar Mills2ce7da22017-05-04 15:37:56 -050068 {
Saqib Khan84a0e692017-06-28 17:27:01 -050069 auto value = SVersion::convertVersionPurposeFromString(
Patrick Williamse883fb82020-05-13 11:38:55 -050070 std::get<std::string>(property.second));
Saqib Khan84a0e692017-06-28 17:27:01 -050071 if (value == VersionPurpose::BMC ||
Vijay Khemkae9f6c842020-01-14 14:32:39 -080072#ifdef HOST_BIOS_UPGRADE
73 value == VersionPurpose::Host ||
74#endif
Saqib Khan84a0e692017-06-28 17:27:01 -050075 value == VersionPurpose::System)
76 {
77 purpose = value;
78 }
Saqib Khan705f1bf2017-06-09 23:58:38 -050079 }
80 else if (property.first == "Version")
81 {
Patrick Williamse883fb82020-05-13 11:38:55 -050082 version = std::get<std::string>(property.second);
Gunnar Mills2ce7da22017-05-04 15:37:56 -050083 }
84 }
85 }
Saqib Khan19177d32017-06-20 08:11:49 -050086 else if (intf.first == FILEPATH_IFACE)
87 {
88 for (const auto& property : intf.second)
89 {
90 if (property.first == "Path")
91 {
Patrick Williamse883fb82020-05-13 11:38:55 -050092 filePath = std::get<std::string>(property.second);
Saqib Khan19177d32017-06-20 08:11:49 -050093 }
94 }
95 }
Chanh Nguyen1fd6ddd2021-01-06 11:09:09 +070096 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 Ledford054bb0b2022-03-15 15:46:58 -0700106 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 Mills2ce7da22017-05-04 15:37:56 -0500117 }
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600118 if (version.empty() || filePath.empty() ||
Saqib Khan84a0e692017-06-28 17:27:01 -0500119 purpose == VersionPurpose::Unknown)
Saqib Khan705f1bf2017-06-09 23:58:38 -0500120 {
121 return;
122 }
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500123
124 // Version id is the last item in the path
125 auto pos = path.rfind("/");
126 if (pos == std::string::npos)
127 {
Patrick Williamsc9bb6422021-08-27 06:18:35 -0500128 error("No version id found in object path: {PATH}", "PATH", path);
Patrick Williamse75d10f2017-05-30 16:56:32 -0500129 return;
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500130 }
131
132 auto versionId = path.substr(pos + 1);
133
Patrick Williamse75d10f2017-05-30 16:56:32 -0500134 if (activations.find(versionId) == activations.end())
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500135 {
Saqib Khan35e83f32017-05-22 11:37:32 -0500136 // Determine the Activation state by processing the given image dir.
137 auto activationState = server::Activation::Activations::Invalid;
Vijay Khemkae9f6c842020-01-14 14:32:39 -0800138 ItemUpdater::ActivationStatus result;
139 if (purpose == VersionPurpose::BMC || purpose == VersionPurpose::System)
140 result = ItemUpdater::validateSquashFSImage(filePath);
141 else
142 result = ItemUpdater::ActivationStatus::ready;
143
Gunnar Mills43b25cd2017-09-07 13:19:34 -0500144 AssociationList associations = {};
145
Saqib Khan35e83f32017-05-22 11:37:32 -0500146 if (result == ItemUpdater::ActivationStatus::ready)
147 {
148 activationState = server::Activation::Activations::Ready;
Gunnar Mills43b25cd2017-09-07 13:19:34 -0500149 // Create an association to the BMC inventory item
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600150 associations.emplace_back(
151 std::make_tuple(ACTIVATION_FWD_ASSOCIATION,
152 ACTIVATION_REV_ASSOCIATION, bmcInventoryPath));
Saqib Khan35e83f32017-05-22 11:37:32 -0500153 }
Gunnar Millsb60add12017-08-24 16:41:42 -0500154
Saqib Khanee13e832017-10-23 12:53:11 -0500155 auto versionPtr = std::make_unique<VersionClass>(
Chanh Nguyen1fd6ddd2021-01-06 11:09:09 +0700156 bus, path, version, purpose, extendedVersion, filePath,
Justin Ledford054bb0b2022-03-15 15:46:58 -0700157 compatibleNames,
Adriana Kobylak59b640b2022-01-21 19:45:22 +0000158 std::bind(&ItemUpdater::erase, this, std::placeholders::_1),
159 versionId);
Saqib Khanee13e832017-10-23 12:53:11 -0500160 versionPtr->deleteObject =
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600161 std::make_unique<phosphor::software::manager::Delete>(bus, path,
162 *versionPtr);
Saqib Khanee13e832017-10-23 12:53:11 -0500163 versions.insert(std::make_pair(versionId, std::move(versionPtr)));
Adriana Kobylak88ba1f92022-03-09 21:14:15 +0000164
165 activations.insert(std::make_pair(
166 versionId,
167 std::make_unique<Activation>(bus, path, *this, versionId,
168 activationState, associations)));
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500169 }
Patrick Williamse75d10f2017-05-30 16:56:32 -0500170 return;
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500171}
172
Saqib Khanba239882017-05-26 08:41:54 -0500173void ItemUpdater::processBMCImage()
174{
Gunnar Mills88e8a322017-09-13 11:09:28 -0500175 using VersionClass = phosphor::software::manager::Version;
Lei YU269bff32018-08-21 15:21:40 +0800176
177 // Check MEDIA_DIR and create if it does not exist
178 try
179 {
180 if (!fs::is_directory(MEDIA_DIR))
181 {
182 fs::create_directory(MEDIA_DIR);
183 }
184 }
185 catch (const fs::filesystem_error& e)
186 {
Patrick Williamsc9bb6422021-08-27 06:18:35 -0500187 error("Failed to prepare dir: {ERROR}", "ERROR", e);
Lei YU269bff32018-08-21 15:21:40 +0800188 return;
189 }
190
Adriana Kobylak1e81f232022-01-18 22:28:47 +0000191 // Functional images are mounted as rofs-<location>-functional
192 constexpr auto functionalSuffix = "-functional";
Lei YUd474d9c2021-12-10 16:21:21 +0800193 bool functionalFound = false;
Gunnar Mills88e8a322017-09-13 11:09:28 -0500194
Saqib Khan1eef62d2017-08-10 15:29:34 -0500195 // Read os-release from folders under /media/ to get
196 // BMC Software Versions.
George Liu44b9fef2023-02-07 14:31:32 +0800197 std::error_code ec;
198 for (const auto& iter : fs::directory_iterator(MEDIA_DIR, ec))
Saqib Khan1eef62d2017-08-10 15:29:34 -0500199 {
200 auto activationState = server::Activation::Activations::Active;
Saqib Khan6fab70d2017-09-07 00:13:50 -0500201 static const auto BMC_RO_PREFIX_LEN = strlen(BMC_ROFS_PREFIX);
Saqib Khan1eef62d2017-08-10 15:29:34 -0500202
203 // Check if the BMC_RO_PREFIXis the prefix of the iter.path
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600204 if (0 ==
205 iter.path().native().compare(0, BMC_RO_PREFIX_LEN, BMC_ROFS_PREFIX))
Saqib Khan1eef62d2017-08-10 15:29:34 -0500206 {
Adriana Kobylak716cd782020-06-08 13:27:43 -0500207 // Get the version to calculate the id
Adriana Kobylak24a8d832020-06-10 08:29:36 -0500208 fs::path releaseFile(OS_RELEASE_FILE);
209 auto osRelease = iter.path() / releaseFile.relative_path();
George Liu44b9fef2023-02-07 14:31:32 +0800210 if (!fs::is_regular_file(osRelease, ec))
Saqib Khan1eef62d2017-08-10 15:29:34 -0500211 {
Lei YUe56bf872022-02-22 18:40:37 +0800212#ifdef BMC_STATIC_DUAL_IMAGE
213 // For dual image, it is possible that the secondary image is
214 // empty or contains invalid data, ignore such case.
George Liu44b9fef2023-02-07 14:31:32 +0800215 info("Unable to find osRelease: {PATH}: {ERROR_MSG}", "PATH",
216 osRelease, "ERROR_MSG", ec.message());
Lei YUe56bf872022-02-22 18:40:37 +0800217#else
George Liu44b9fef2023-02-07 14:31:32 +0800218 error("Failed to read osRelease: {PATH}: {ERROR_MSG}", "PATH",
219 osRelease, "ERROR_MSG", ec.message());
Adriana Kobylak716cd782020-06-08 13:27:43 -0500220
221 // Try to get the version id from the mount directory name and
222 // call to delete it as this version may be corrupted. Dynamic
223 // volumes created by the UBI layout for example have the id in
224 // the mount directory name. The worst that can happen is that
225 // erase() is called with an non-existent id and returns.
226 auto id = iter.path().native().substr(BMC_RO_PREFIX_LEN);
Saqib Khan021c3652017-09-26 12:11:02 -0500227 ItemUpdater::erase(id);
Lei YUe56bf872022-02-22 18:40:37 +0800228#endif
Adriana Kobylak716cd782020-06-08 13:27:43 -0500229
Saqib Khan021c3652017-09-26 12:11:02 -0500230 continue;
Saqib Khan1eef62d2017-08-10 15:29:34 -0500231 }
Gunnar Mills88e8a322017-09-13 11:09:28 -0500232 auto version = VersionClass::getBMCVersion(osRelease);
Saqib Khan1eef62d2017-08-10 15:29:34 -0500233 if (version.empty())
234 {
Patrick Williamsc9bb6422021-08-27 06:18:35 -0500235 error("Failed to read version from osRelease: {PATH}", "PATH",
236 osRelease);
Adriana Kobylak716cd782020-06-08 13:27:43 -0500237
238 // Try to delete the version, same as above if the
239 // OS_RELEASE_FILE does not exist.
240 auto id = iter.path().native().substr(BMC_RO_PREFIX_LEN);
241 ItemUpdater::erase(id);
242
243 continue;
Saqib Khan1eef62d2017-08-10 15:29:34 -0500244 }
Saqib Khan021c3652017-09-26 12:11:02 -0500245
Adriana Kobylak59b640b2022-01-21 19:45:22 +0000246 // The flash location is part of the mount name: rofs-<location>
247 auto flashId = iter.path().native().substr(BMC_RO_PREFIX_LEN);
248
249 auto id = VersionClass::getId(version + flashId);
Adriana Kobylak716cd782020-06-08 13:27:43 -0500250
Adriana Kobylakf383d272020-06-16 15:17:22 -0500251 // Check if the id has already been added. This can happen if the
252 // BMC partitions / devices were manually flashed with the same
253 // image.
254 if (versions.find(id) != versions.end())
255 {
256 continue;
257 }
258
Adriana Kobylak1e81f232022-01-18 22:28:47 +0000259 auto functional = false;
260 if (iter.path().native().find(functionalSuffix) !=
261 std::string::npos)
262 {
263 // Set functional to true and remove the functional suffix
264 functional = true;
265 flashId.erase(flashId.length() - strlen(functionalSuffix));
Lei YUd474d9c2021-12-10 16:21:21 +0800266 functionalFound = true;
Adriana Kobylak1e81f232022-01-18 22:28:47 +0000267 }
Adriana Kobylak780220f2022-01-18 20:01:53 +0000268
Saqib Khan1eef62d2017-08-10 15:29:34 -0500269 auto purpose = server::Version::VersionPurpose::BMC;
Adriana Kobylak780220f2022-01-18 20:01:53 +0000270 restorePurpose(flashId, purpose);
Adriana Kobylakec4eec32019-11-13 14:28:35 -0600271
Chanh Nguyen1fd6ddd2021-01-06 11:09:09 +0700272 // Read os-release from /etc/ to get the BMC extended version
273 std::string extendedVersion =
274 VersionClass::getBMCExtendedVersion(osRelease);
275
Saqib Khan1eef62d2017-08-10 15:29:34 -0500276 auto path = fs::path(SOFTWARE_OBJPATH) / id;
277
Lei YU269bff32018-08-21 15:21:40 +0800278 // Create functional association if this is the functional
279 // version
Adriana Kobylak1e81f232022-01-18 22:28:47 +0000280 if (functional)
Gunnar Mills88e8a322017-09-13 11:09:28 -0500281 {
282 createFunctionalAssociation(path);
283 }
284
Gunnar Mills43b25cd2017-09-07 13:19:34 -0500285 AssociationList associations = {};
286
287 if (activationState == server::Activation::Activations::Active)
288 {
289 // Create an association to the BMC inventory item
290 associations.emplace_back(std::make_tuple(
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600291 ACTIVATION_FWD_ASSOCIATION, ACTIVATION_REV_ASSOCIATION,
292 bmcInventoryPath));
Gunnar Mills43b25cd2017-09-07 13:19:34 -0500293
294 // Create an active association since this image is active
295 createActiveAssociation(path);
296 }
297
AppaRao Pulibbebec72020-01-28 23:57:41 +0530298 // All updateable firmware components must expose the updateable
299 // association.
300 createUpdateableAssociation(path);
301
Adriana Kobylakee590c72017-09-26 15:16:06 -0500302 // Create Version instance for this version.
303 auto versionPtr = std::make_unique<VersionClass>(
Adriana Kobylaka84f06d2022-01-18 15:41:57 +0000304 bus, path, version, purpose, extendedVersion, flashId,
Justin Ledford054bb0b2022-03-15 15:46:58 -0700305 std::vector<std::string>(),
Adriana Kobylak59b640b2022-01-21 19:45:22 +0000306 std::bind(&ItemUpdater::erase, this, std::placeholders::_1),
307 id);
Adriana Kobylak1e81f232022-01-18 22:28:47 +0000308 if (functional)
309 {
310 versionPtr->setFunctional(true);
311 }
312 else
Michael Tritz4254bec2017-10-03 17:18:22 -0500313 {
Saqib Khanee13e832017-10-23 12:53:11 -0500314 versionPtr->deleteObject =
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600315 std::make_unique<phosphor::software::manager::Delete>(
316 bus, path, *versionPtr);
Michael Tritz4254bec2017-10-03 17:18:22 -0500317 }
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600318 versions.insert(std::make_pair(id, std::move(versionPtr)));
Michael Tritz4254bec2017-10-03 17:18:22 -0500319
Saqib Khanee13e832017-10-23 12:53:11 -0500320 // Create Activation instance for this version.
321 activations.insert(std::make_pair(
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600322 id, std::make_unique<Activation>(
323 bus, path, *this, id, activationState, associations)));
Saqib Khan1eef62d2017-08-10 15:29:34 -0500324
Lei YUbdf2d6c2021-12-15 14:05:01 +0800325#ifdef BMC_STATIC_DUAL_IMAGE
326 uint8_t priority;
327 if ((functional && (runningImageSlot == 0)) ||
328 (!functional && (runningImageSlot == 1)))
329 {
330 priority = 0;
331 }
332 else
333 {
334 priority = 1;
335 }
336 activations.find(id)->second->redundancyPriority =
337 std::make_unique<RedundancyPriority>(
338 bus, path, *(activations.find(id)->second), priority,
339 false);
340#else
Lei YU269bff32018-08-21 15:21:40 +0800341 // If Active, create RedundancyPriority instance for this
342 // version.
Saqib Khan1eef62d2017-08-10 15:29:34 -0500343 if (activationState == server::Activation::Activations::Active)
344 {
345 uint8_t priority = std::numeric_limits<uint8_t>::max();
Adriana Kobylak780220f2022-01-18 20:01:53 +0000346 if (!restorePriority(flashId, priority))
Saqib Khan1eef62d2017-08-10 15:29:34 -0500347 {
Adriana Kobylak1e81f232022-01-18 22:28:47 +0000348 if (functional)
Adriana Kobylakee590c72017-09-26 15:16:06 -0500349 {
350 priority = 0;
351 }
352 else
353 {
Patrick Williamsc9bb6422021-08-27 06:18:35 -0500354 error(
355 "Unable to restore priority from file for {VERSIONID}",
356 "VERSIONID", id);
Adriana Kobylakee590c72017-09-26 15:16:06 -0500357 }
Saqib Khan1eef62d2017-08-10 15:29:34 -0500358 }
359 activations.find(id)->second->redundancyPriority =
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600360 std::make_unique<RedundancyPriority>(
361 bus, path, *(activations.find(id)->second), priority,
362 false);
Saqib Khan1eef62d2017-08-10 15:29:34 -0500363 }
Lei YUbdf2d6c2021-12-15 14:05:01 +0800364#endif
Saqib Khan1eef62d2017-08-10 15:29:34 -0500365 }
366 }
Saqib Khandcbfa042017-09-18 13:08:39 -0500367
Lei YUd474d9c2021-12-10 16:21:21 +0800368 if (!functionalFound)
Saqib Khandcbfa042017-09-18 13:08:39 -0500369 {
Lei YUd474d9c2021-12-10 16:21:21 +0800370 // If there is no functional version found, read the /etc/os-release and
371 // create rofs-<versionId>-functional under MEDIA_DIR, then call again
372 // processBMCImage() to create the D-Bus interface for it.
Gunnar Millsd16bcbd2017-10-08 16:50:42 -0500373 auto version = VersionClass::getBMCVersion(OS_RELEASE_FILE);
Adriana Kobylak59b640b2022-01-21 19:45:22 +0000374 auto id = phosphor::software::manager::Version::getId(version +
375 functionalSuffix);
Adriana Kobylak1e81f232022-01-18 22:28:47 +0000376 auto versionFileDir = BMC_ROFS_PREFIX + id + functionalSuffix + "/etc/";
Saqib Khandcbfa042017-09-18 13:08:39 -0500377 try
378 {
Gunnar Millsd16bcbd2017-10-08 16:50:42 -0500379 if (!fs::is_directory(versionFileDir))
Saqib Khandcbfa042017-09-18 13:08:39 -0500380 {
381 fs::create_directories(versionFileDir);
382 }
Patrick Williamsd5e8e732023-05-10 07:50:18 -0500383 auto versionFilePath = BMC_ROFS_PREFIX + id + functionalSuffix +
384 OS_RELEASE_FILE;
Saqib Khandcbfa042017-09-18 13:08:39 -0500385 fs::create_directory_symlink(OS_RELEASE_FILE, versionFilePath);
386 ItemUpdater::processBMCImage();
387 }
388 catch (const std::exception& e)
389 {
Patrick Williamsc9bb6422021-08-27 06:18:35 -0500390 error("Exception during processing: {ERROR}", "ERROR", e);
Saqib Khandcbfa042017-09-18 13:08:39 -0500391 }
392 }
Eddie Jameseaa1ee02018-03-01 10:09:10 -0600393
394 mirrorUbootToAlt();
Saqib Khanba239882017-05-26 08:41:54 -0500395 return;
396}
397
Leonel Gonzalez3526ef72017-07-07 14:38:25 -0500398void ItemUpdater::erase(std::string entryId)
399{
Eddie James6d873712017-09-01 11:29:07 -0500400 // Find entry in versions map
401 auto it = versions.find(entryId);
402 if (it != versions.end())
403 {
Lei YU0f88b5a2018-08-21 15:28:53 +0800404 if (it->second->isFunctional() && ACTIVE_BMC_MAX_ALLOWED > 1)
Eddie James6d873712017-09-01 11:29:07 -0500405 {
Patrick Williamsc9bb6422021-08-27 06:18:35 -0500406 error(
407 "Version ({VERSIONID}) is currently running on the BMC; unable to remove.",
408 "VERSIONID", entryId);
Gunnar Millsd16bcbd2017-10-08 16:50:42 -0500409 return;
Eddie James6d873712017-09-01 11:29:07 -0500410 }
Adriana Kobylakd1a55ad2020-06-11 14:01:28 -0500411 }
Eddie James6d873712017-09-01 11:29:07 -0500412
Adriana Kobylakd1a55ad2020-06-11 14:01:28 -0500413 // First call resetUbootEnvVars() so that the BMC points to a valid image to
414 // boot from. If resetUbootEnvVars() is called after the image is actually
415 // deleted from the BMC flash, there'd be a time window where the BMC would
416 // be pointing to a non-existent image to boot from.
417 // Need to remove the entries from the activations map before that call so
418 // that resetUbootEnvVars() doesn't use the version to be deleted.
419 auto iteratorActivations = activations.find(entryId);
420 if (iteratorActivations == activations.end())
421 {
Patrick Williamsc9bb6422021-08-27 06:18:35 -0500422 error(
423 "Failed to find version ({VERSIONID}) in item updater activations map; unable to remove.",
424 "VERSIONID", entryId);
Adriana Kobylakd1a55ad2020-06-11 14:01:28 -0500425 }
426 else
427 {
428 removeAssociations(iteratorActivations->second->path);
Zami Seckae06d762021-08-13 20:11:15 -0500429 iteratorActivations->second->deleteImageManagerObject();
Adriana Kobylakd1a55ad2020-06-11 14:01:28 -0500430 this->activations.erase(entryId);
431 }
432 ItemUpdater::resetUbootEnvVars();
433
434 if (it != versions.end())
435 {
Adriana Kobylak780220f2022-01-18 20:01:53 +0000436 auto flashId = it->second->path();
437
Adriana Kobylak25773a72022-01-21 15:24:48 +0000438 // Delete version data if it has been installed on flash (path is not
439 // the upload directory)
440 if (flashId.find(IMG_UPLOAD_DIR) == std::string::npos)
441 {
442 removeReadOnlyPartition(entryId);
443 removePersistDataDirectory(flashId);
444 helper.clearEntry(flashId);
445 }
Saqib Khanee13e832017-10-23 12:53:11 -0500446
447 // Removing entry in versions map
448 this->versions.erase(entryId);
Eddie James6d873712017-09-01 11:29:07 -0500449 }
Leonel Gonzalez3526ef72017-07-07 14:38:25 -0500450
Saqib Khanee13e832017-10-23 12:53:11 -0500451 return;
Leonel Gonzalez3526ef72017-07-07 14:38:25 -0500452}
453
Michael Tritzbc1bf3a2017-09-18 16:38:23 -0500454void ItemUpdater::deleteAll()
455{
Adriana Kobylak83cd21f2018-02-28 15:48:48 -0600456 std::vector<std::string> deletableVersions;
457
Michael Tritzbc1bf3a2017-09-18 16:38:23 -0500458 for (const auto& versionIt : versions)
459 {
460 if (!versionIt.second->isFunctional())
461 {
Adriana Kobylak83cd21f2018-02-28 15:48:48 -0600462 deletableVersions.push_back(versionIt.first);
Michael Tritzbc1bf3a2017-09-18 16:38:23 -0500463 }
464 }
465
Adriana Kobylak83cd21f2018-02-28 15:48:48 -0600466 for (const auto& deletableIt : deletableVersions)
467 {
468 ItemUpdater::erase(deletableIt);
469 }
470
Lei YU56aaf452018-06-21 16:09:44 +0800471 helper.cleanup();
Michael Tritzbc1bf3a2017-09-18 16:38:23 -0500472}
473
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600474ItemUpdater::ActivationStatus
475 ItemUpdater::validateSquashFSImage(const std::string& filePath)
Saqib Khan35e83f32017-05-22 11:37:32 -0500476{
Bright Cheng8e9ccfe2019-11-18 16:18:44 +0800477 bool valid = true;
Saqib Khan35e83f32017-05-22 11:37:32 -0500478
Bright Cheng8e9ccfe2019-11-18 16:18:44 +0800479 // Record the images which are being updated
480 // First check for the fullimage, then check for images with partitions
481 imageUpdateList.push_back(bmcFullImages);
482 valid = checkImage(filePath, imageUpdateList);
483 if (!valid)
Saqib Khan35e83f32017-05-22 11:37:32 -0500484 {
Bright Cheng8e9ccfe2019-11-18 16:18:44 +0800485 imageUpdateList.clear();
486 imageUpdateList.assign(bmcImages.begin(), bmcImages.end());
487 valid = checkImage(filePath, imageUpdateList);
488 if (!valid)
Michael Tritzb1cfdf92017-08-14 14:33:30 -0500489 {
Patrick Williamsc9bb6422021-08-27 06:18:35 -0500490 error("Failed to find the needed BMC images.");
Bright Cheng8e9ccfe2019-11-18 16:18:44 +0800491 return ItemUpdater::ActivationStatus::invalid;
Michael Tritzb1cfdf92017-08-14 14:33:30 -0500492 }
Saqib Khan35e83f32017-05-22 11:37:32 -0500493 }
Michael Tritzb1cfdf92017-08-14 14:33:30 -0500494
Michael Tritzb1cfdf92017-08-14 14:33:30 -0500495 return ItemUpdater::ActivationStatus::ready;
Saqib Khan35e83f32017-05-22 11:37:32 -0500496}
497
Adriana Kobylakbbcb7be2018-07-17 15:47:34 -0500498void ItemUpdater::savePriority(const std::string& versionId, uint8_t value)
499{
Adriana Kobylak780220f2022-01-18 20:01:53 +0000500 auto flashId = versions.find(versionId)->second->path();
501 storePriority(flashId, value);
Adriana Kobylak25773a72022-01-21 15:24:48 +0000502 helper.setEntry(flashId, value);
Adriana Kobylakbbcb7be2018-07-17 15:47:34 -0500503}
504
Saqib Khanb9da6632017-09-13 09:48:37 -0500505void ItemUpdater::freePriority(uint8_t value, const std::string& versionId)
Saqib Khan4c1aec02017-07-06 11:46:13 -0500506{
Adriana Kobylakb77551c2017-10-27 12:46:23 -0500507 std::map<std::string, uint8_t> priorityMap;
508
509 // Insert the requested version and priority, it may not exist yet.
510 priorityMap.insert(std::make_pair(versionId, value));
511
Saqib Khan4c1aec02017-07-06 11:46:13 -0500512 for (const auto& intf : activations)
513 {
Gunnar Mills9a782242017-08-22 16:23:15 -0500514 if (intf.second->redundancyPriority)
Saqib Khan4c1aec02017-07-06 11:46:13 -0500515 {
Adriana Kobylakb77551c2017-10-27 12:46:23 -0500516 priorityMap.insert(std::make_pair(
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600517 intf.first, intf.second->redundancyPriority.get()->priority()));
Saqib Khan4c1aec02017-07-06 11:46:13 -0500518 }
519 }
Adriana Kobylakb77551c2017-10-27 12:46:23 -0500520
521 // Lambda function to compare 2 priority values, use <= to allow duplicates
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600522 typedef std::function<bool(std::pair<std::string, uint8_t>,
523 std::pair<std::string, uint8_t>)>
524 cmpPriority;
525 cmpPriority cmpPriorityFunc =
526 [](std::pair<std::string, uint8_t> priority1,
527 std::pair<std::string, uint8_t> priority2) {
Patrick Williamsd5e8e732023-05-10 07:50:18 -0500528 return priority1.second <= priority2.second;
529 };
Adriana Kobylakb77551c2017-10-27 12:46:23 -0500530
531 // Sort versions by ascending priority
532 std::set<std::pair<std::string, uint8_t>, cmpPriority> prioritySet(
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600533 priorityMap.begin(), priorityMap.end(), cmpPriorityFunc);
Adriana Kobylakb77551c2017-10-27 12:46:23 -0500534
535 auto freePriorityValue = value;
536 for (auto& element : prioritySet)
537 {
538 if (element.first == versionId)
539 {
540 continue;
541 }
542 if (element.second == freePriorityValue)
543 {
544 ++freePriorityValue;
545 auto it = activations.find(element.first);
546 it->second->redundancyPriority.get()->sdbusPriority(
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600547 freePriorityValue);
Adriana Kobylakb77551c2017-10-27 12:46:23 -0500548 }
549 }
550
551 auto lowestVersion = prioritySet.begin()->first;
552 if (value == prioritySet.begin()->second)
553 {
554 lowestVersion = versionId;
555 }
556 updateUbootEnvVars(lowestVersion);
Saqib Khan4c1aec02017-07-06 11:46:13 -0500557}
558
Michael Tritz37a59042017-07-12 13:44:53 -0500559void ItemUpdater::reset()
560{
Lei YU56aaf452018-06-21 16:09:44 +0800561 helper.factoryReset();
Michael Tritz37a59042017-07-12 13:44:53 -0500562
Patrick Williamsc9bb6422021-08-27 06:18:35 -0500563 info("BMC factory reset will take effect upon reboot.");
Michael Tritz37a59042017-07-12 13:44:53 -0500564}
565
Leonel Gonzalez3526ef72017-07-07 14:38:25 -0500566void ItemUpdater::removeReadOnlyPartition(std::string versionId)
567{
Adriana Kobylak25773a72022-01-21 15:24:48 +0000568 auto flashId = versions.find(versionId)->second->path();
569 helper.removeVersion(flashId);
Leonel Gonzalez3526ef72017-07-07 14:38:25 -0500570}
571
Michael Tritz0129d922017-08-10 19:33:46 -0500572bool ItemUpdater::fieldModeEnabled(bool value)
573{
574 // enabling field mode is intended to be one way: false -> true
575 if (value && !control::FieldMode::fieldModeEnabled())
576 {
577 control::FieldMode::fieldModeEnabled(value);
578
Adriana Kobylak22848ec2019-10-28 10:08:39 -0500579 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
580 SYSTEMD_INTERFACE, "StartUnit");
581 method.append("obmc-flash-bmc-setenv@fieldmode\\x3dtrue.service",
582 "replace");
583 bus.call_noreply(method);
584
585 method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
586 SYSTEMD_INTERFACE, "StopUnit");
587 method.append("usr-local.mount", "replace");
588 bus.call_noreply(method);
589
590 std::vector<std::string> usrLocal = {"usr-local.mount"};
591
592 method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
593 SYSTEMD_INTERFACE, "MaskUnitFiles");
594 method.append(usrLocal, false, true);
595 bus.call_noreply(method);
Michael Tritz0129d922017-08-10 19:33:46 -0500596 }
Adriana Kobylakd5b8f752019-05-01 11:52:35 -0500597 else if (!value && control::FieldMode::fieldModeEnabled())
598 {
Adriana Kobylakce82de52024-01-16 13:56:38 -0600599 elog<NotAllowed>(xyz::openbmc_project::common::NotAllowed::REASON(
Adriana Kobylakd5b8f752019-05-01 11:52:35 -0500600 "FieldMode is not allowed to be cleared"));
601 }
Michael Tritz0129d922017-08-10 19:33:46 -0500602
603 return control::FieldMode::fieldModeEnabled();
604}
605
606void ItemUpdater::restoreFieldModeStatus()
607{
Isaac Kurthdeb86b42022-03-08 19:47:53 -0600608 // The fieldmode u-boot environment variable may not exist since it is not
609 // part of the default environment, run fw_printenv with 2>&1 to ignore the
610 // error message in the journal "Error: "fieldmode" not defined"
Patrick Williamsd5e8e732023-05-10 07:50:18 -0500611 std::pair<int, std::string> ret = utils::execute("/sbin/fw_printenv", "-n",
612 "fieldmode", "2>&1");
Michael Tritz0129d922017-08-10 19:33:46 -0500613
Isaac Kurthdeb86b42022-03-08 19:47:53 -0600614 if (ret.first != 0)
615 {
616 return;
617 }
618
619 // truncate any extra characters off the end to compare against a "true" str
620 std::string result = ret.second.substr(0, 4);
621 if (result == "true")
Michael Tritz0129d922017-08-10 19:33:46 -0500622 {
623 ItemUpdater::fieldModeEnabled(true);
624 }
625}
626
Gunnar Millsb60add12017-08-24 16:41:42 -0500627void ItemUpdater::setBMCInventoryPath()
628{
Gunnar Millsb60add12017-08-24 16:41:42 -0500629 auto depth = 0;
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600630 auto mapperCall = bus.new_method_call(MAPPER_BUSNAME, MAPPER_PATH,
631 MAPPER_INTERFACE, "GetSubTreePaths");
Gunnar Millsb60add12017-08-24 16:41:42 -0500632
Adriana Kobylak1254c622017-12-07 12:24:56 -0600633 mapperCall.append(INVENTORY_PATH);
Gunnar Millsb60add12017-08-24 16:41:42 -0500634 mapperCall.append(depth);
Adriana Kobylak1254c622017-12-07 12:24:56 -0600635 std::vector<std::string> filter = {BMC_INVENTORY_INTERFACE};
Gunnar Millsb60add12017-08-24 16:41:42 -0500636 mapperCall.append(filter);
637
Ed Tanous87c78172018-08-10 12:51:53 -0700638 try
639 {
640 auto response = bus.call(mapperCall);
641
642 using ObjectPaths = std::vector<std::string>;
643 ObjectPaths result;
644 response.read(result);
645
646 if (!result.empty())
647 {
648 bmcInventoryPath = result.front();
649 }
650 }
Patrick Williamsbf2bb2b2022-07-22 19:26:52 -0500651 catch (const sdbusplus::exception_t& e)
Gunnar Millsb60add12017-08-24 16:41:42 -0500652 {
Patrick Williamsc9bb6422021-08-27 06:18:35 -0500653 error("Error in mapper GetSubTreePath: {ERROR}", "ERROR", e);
Gunnar Millsb60add12017-08-24 16:41:42 -0500654 return;
655 }
656
Adriana Kobylak1254c622017-12-07 12:24:56 -0600657 return;
Gunnar Millsb60add12017-08-24 16:41:42 -0500658}
659
Gunnar Millsf10b2322017-09-21 15:31:55 -0500660void ItemUpdater::createActiveAssociation(const std::string& path)
Gunnar Millsded875d2017-08-28 16:44:52 -0500661{
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600662 assocs.emplace_back(
663 std::make_tuple(ACTIVE_FWD_ASSOCIATION, ACTIVE_REV_ASSOCIATION, path));
Gunnar Millsded875d2017-08-28 16:44:52 -0500664 associations(assocs);
665}
666
Gunnar Mills88e8a322017-09-13 11:09:28 -0500667void ItemUpdater::createFunctionalAssociation(const std::string& path)
668{
669 assocs.emplace_back(std::make_tuple(FUNCTIONAL_FWD_ASSOCIATION,
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600670 FUNCTIONAL_REV_ASSOCIATION, path));
Gunnar Mills88e8a322017-09-13 11:09:28 -0500671 associations(assocs);
672}
673
AppaRao Pulibbebec72020-01-28 23:57:41 +0530674void ItemUpdater::createUpdateableAssociation(const std::string& path)
675{
676 assocs.emplace_back(std::make_tuple(UPDATEABLE_FWD_ASSOCIATION,
677 UPDATEABLE_REV_ASSOCIATION, path));
678 associations(assocs);
679}
680
Adriana Kobylak991af7e2018-12-10 13:08:38 -0600681void ItemUpdater::removeAssociations(const std::string& path)
Gunnar Millsded875d2017-08-28 16:44:52 -0500682{
683 for (auto iter = assocs.begin(); iter != assocs.end();)
684 {
Adriana Kobylak991af7e2018-12-10 13:08:38 -0600685 if ((std::get<2>(*iter)).compare(path) == 0)
Gunnar Millsded875d2017-08-28 16:44:52 -0500686 {
687 iter = assocs.erase(iter);
688 associations(assocs);
689 }
690 else
691 {
692 ++iter;
693 }
694 }
695}
696
Saqib Khanb9da6632017-09-13 09:48:37 -0500697bool ItemUpdater::isLowestPriority(uint8_t value)
698{
699 for (const auto& intf : activations)
700 {
Gunnar Millsd16bcbd2017-10-08 16:50:42 -0500701 if (intf.second->redundancyPriority)
Saqib Khanb9da6632017-09-13 09:48:37 -0500702 {
703 if (intf.second->redundancyPriority.get()->priority() < value)
704 {
705 return false;
706 }
707 }
708 }
709 return true;
710}
711
Adriana Kobylakb77551c2017-10-27 12:46:23 -0500712void ItemUpdater::updateUbootEnvVars(const std::string& versionId)
713{
Lei YU9c76a0a2022-03-14 11:37:15 +0800714 auto it = versions.find(versionId);
715 if (it == versions.end())
716 {
717 return;
718 }
719 auto flashId = it->second->path();
Adriana Kobylak25773a72022-01-21 15:24:48 +0000720 helper.updateUbootVersionId(flashId);
Adriana Kobylakb77551c2017-10-27 12:46:23 -0500721}
722
Saqib Khan49446ae2017-10-02 10:54:20 -0500723void ItemUpdater::resetUbootEnvVars()
724{
725 decltype(activations.begin()->second->redundancyPriority.get()->priority())
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600726 lowestPriority = std::numeric_limits<uint8_t>::max();
Saqib Khan49446ae2017-10-02 10:54:20 -0500727 decltype(activations.begin()->second->versionId) lowestPriorityVersion;
728 for (const auto& intf : activations)
729 {
730 if (!intf.second->redundancyPriority.get())
731 {
732 // Skip this version if the redundancyPriority is not initialized.
733 continue;
734 }
735
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600736 if (intf.second->redundancyPriority.get()->priority() <= lowestPriority)
Saqib Khan49446ae2017-10-02 10:54:20 -0500737 {
738 lowestPriority = intf.second->redundancyPriority.get()->priority();
739 lowestPriorityVersion = intf.second->versionId;
740 }
741 }
742
Saqib Khanf0382c32017-10-24 13:36:22 -0500743 // Update the U-boot environment variable to point to the lowest priority
Adriana Kobylakb77551c2017-10-27 12:46:23 -0500744 updateUbootEnvVars(lowestPriorityVersion);
Saqib Khan49446ae2017-10-02 10:54:20 -0500745}
746
Lei YUd8c9eea2021-12-16 16:08:30 +0800747void ItemUpdater::freeSpace([[maybe_unused]] const Activation& caller)
Adriana Kobylak204e1e72018-01-24 16:00:05 -0600748{
Lei YUd8c9eea2021-12-16 16:08:30 +0800749#ifdef BMC_STATIC_DUAL_IMAGE
750 // For the golden image case, always remove the version on the primary side
751 std::string versionIDtoErase;
752 for (const auto& iter : activations)
753 {
754 if (iter.second->redundancyPriority &&
755 iter.second->redundancyPriority.get()->priority() == 0)
756 {
757 versionIDtoErase = iter.second->versionId;
758 break;
759 }
760 }
761 if (!versionIDtoErase.empty())
762 {
763 erase(versionIDtoErase);
764 }
765 else
766 {
767 warning("Failed to find version to erase");
768 }
769#else
Adriana Kobylak204e1e72018-01-24 16:00:05 -0600770 // Versions with the highest priority in front
771 std::priority_queue<std::pair<int, std::string>,
772 std::vector<std::pair<int, std::string>>,
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600773 std::less<std::pair<int, std::string>>>
774 versionsPQ;
Adriana Kobylak204e1e72018-01-24 16:00:05 -0600775
776 std::size_t count = 0;
777 for (const auto& iter : activations)
778 {
779 if ((iter.second.get()->activation() ==
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600780 server::Activation::Activations::Active) ||
Adriana Kobylak204e1e72018-01-24 16:00:05 -0600781 (iter.second.get()->activation() ==
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600782 server::Activation::Activations::Failed))
Adriana Kobylak204e1e72018-01-24 16:00:05 -0600783 {
784 count++;
785 // Don't put the functional version on the queue since we can't
786 // remove the "running" BMC version.
Lei YU0f88b5a2018-08-21 15:28:53 +0800787 // If ACTIVE_BMC_MAX_ALLOWED <= 1, there is only one active BMC,
788 // so remove functional version as well.
Adriana Kobylaka6963592018-09-07 14:13:29 -0500789 // Don't delete the the Activation object that called this function.
790 if ((versions.find(iter.second->versionId)
791 ->second->isFunctional() &&
792 ACTIVE_BMC_MAX_ALLOWED > 1) ||
793 (iter.second->versionId == caller.versionId))
Adriana Kobylak204e1e72018-01-24 16:00:05 -0600794 {
795 continue;
796 }
Adriana Kobylaka6963592018-09-07 14:13:29 -0500797
798 // Failed activations don't have priority, assign them a large value
799 // for sorting purposes.
800 auto priority = 999;
801 if (iter.second.get()->activation() ==
Lei YUcfb4b202021-05-06 17:47:28 +0800802 server::Activation::Activations::Active &&
803 iter.second->redundancyPriority)
Adriana Kobylaka6963592018-09-07 14:13:29 -0500804 {
805 priority = iter.second->redundancyPriority.get()->priority();
806 }
807
808 versionsPQ.push(std::make_pair(priority, iter.second->versionId));
Adriana Kobylak204e1e72018-01-24 16:00:05 -0600809 }
810 }
811
812 // If the number of BMC versions is over ACTIVE_BMC_MAX_ALLOWED -1,
813 // remove the highest priority one(s).
814 while ((count >= ACTIVE_BMC_MAX_ALLOWED) && (!versionsPQ.empty()))
815 {
816 erase(versionsPQ.top().second);
817 versionsPQ.pop();
818 count--;
819 }
Lei YUd8c9eea2021-12-16 16:08:30 +0800820#endif
Adriana Kobylak204e1e72018-01-24 16:00:05 -0600821}
822
Eddie Jameseaa1ee02018-03-01 10:09:10 -0600823void ItemUpdater::mirrorUbootToAlt()
824{
Lei YU56aaf452018-06-21 16:09:44 +0800825 helper.mirrorAlt();
Eddie Jameseaa1ee02018-03-01 10:09:10 -0600826}
827
Bright Cheng8e9ccfe2019-11-18 16:18:44 +0800828bool ItemUpdater::checkImage(const std::string& filePath,
829 const std::vector<std::string>& imageList)
830{
831 bool valid = true;
832
833 for (auto& bmcImage : imageList)
834 {
835 fs::path file(filePath);
836 file /= bmcImage;
837 std::ifstream efile(file.c_str());
838 if (efile.good() != 1)
839 {
840 valid = false;
841 break;
842 }
843 }
844
845 return valid;
846}
847
Lei YU6e9fb1d2021-02-19 18:01:40 +0800848#ifdef HOST_BIOS_UPGRADE
849void ItemUpdater::createBIOSObject()
850{
851 std::string path = BIOS_OBJPATH;
852 // Get version id from last item in the path
853 auto pos = path.rfind("/");
854 if (pos == std::string::npos)
855 {
Patrick Williamsc9bb6422021-08-27 06:18:35 -0500856 error("No version id found in object path {PATH}", "PATH", path);
Lei YU6e9fb1d2021-02-19 18:01:40 +0800857 return;
858 }
859
860 createActiveAssociation(path);
861 createFunctionalAssociation(path);
862
863 auto versionId = path.substr(pos + 1);
864 auto version = "null";
865 AssociationList assocs = {};
866 biosActivation = std::make_unique<Activation>(
867 bus, path, *this, versionId, server::Activation::Activations::Active,
868 assocs);
869 auto dummyErase = [](std::string /*entryId*/) {
870 // Do nothing;
871 };
872 biosVersion = std::make_unique<VersionClass>(
873 bus, path, version, VersionPurpose::Host, "", "",
Justin Ledford054bb0b2022-03-15 15:46:58 -0700874 std::vector<std::string>(),
Adriana Kobylak59b640b2022-01-21 19:45:22 +0000875 std::bind(dummyErase, std::placeholders::_1), "");
Lei YU6e9fb1d2021-02-19 18:01:40 +0800876 biosVersion->deleteObject =
877 std::make_unique<phosphor::software::manager::Delete>(bus, path,
878 *biosVersion);
879}
880#endif
881
Lei YU531fbc22021-12-10 20:03:18 +0800882void ItemUpdater::getRunningSlot()
883{
884 // Check /run/media/slot to get the slot number
885 constexpr auto slotFile = "/run/media/slot";
886 std::fstream f(slotFile, std::ios_base::in);
887 f >> runningImageSlot;
888}
889
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500890} // namespace updater
891} // namespace software
892} // namespace phosphor