blob: 7b65b80f6dc01a958eb8a402021771ba51ef0307 [file] [log] [blame]
Gunnar Millsec1b41c2017-05-02 12:20:36 -05001#pragma once
2
3#include <sdbusplus/server.hpp>
4#include "activation.hpp"
Saqib Khan705f1bf2017-06-09 23:58:38 -05005#include "version.hpp"
Michael Tritz37a59042017-07-12 13:44:53 -05006#include <xyz/openbmc_project/Common/FactoryReset/server.hpp>
Michael Tritz0129d922017-08-10 19:33:46 -05007#include <xyz/openbmc_project/Control/FieldMode/server.hpp>
Gunnar Millsded875d2017-08-28 16:44:52 -05008#include "org/openbmc/Associations/server.hpp"
Michael Tritzbc1bf3a2017-09-18 16:38:23 -05009#include "xyz/openbmc_project/Collection/DeleteAll/server.hpp"
Gunnar Millsec1b41c2017-05-02 12:20:36 -050010
11namespace phosphor
12{
13namespace software
14{
15namespace updater
16{
17
Michael Tritz37a59042017-07-12 13:44:53 -050018using ItemUpdaterInherit = sdbusplus::server::object::object<
Gunnar Mills48442912017-10-06 13:34:07 -050019 sdbusplus::xyz::openbmc_project::Common::server::FactoryReset,
20 sdbusplus::xyz::openbmc_project::Control::server::FieldMode,
21 sdbusplus::org::openbmc::server::Associations,
22 sdbusplus::xyz::openbmc_project::Collection::server::DeleteAll>;
Michael Tritz37a59042017-07-12 13:44:53 -050023
Patrick Williamse75d10f2017-05-30 16:56:32 -050024namespace MatchRules = sdbusplus::bus::match::rules;
Gunnar Mills48442912017-10-06 13:34:07 -050025using VersionClass = phosphor::software::manager::Version;
Gunnar Millsded875d2017-08-28 16:44:52 -050026using AssociationList =
27 std::vector<std::tuple<std::string, std::string, std::string>>;
28
Gunnar Millsec1b41c2017-05-02 12:20:36 -050029/** @class ItemUpdater
30 * @brief Manages the activation of the BMC version items.
31 */
Michael Tritz37a59042017-07-12 13:44:53 -050032class ItemUpdater : public ItemUpdaterInherit
Gunnar Millsec1b41c2017-05-02 12:20:36 -050033{
34 public:
Saqib Khan35e83f32017-05-22 11:37:32 -050035 /*
36 * @brief Types of Activation status for image validation.
37 */
38 enum class ActivationStatus
39 {
40 ready,
41 invalid,
42 active
43 };
44
Gunnar Millsec1b41c2017-05-02 12:20:36 -050045 /** @brief Constructs ItemUpdater
46 *
Gunnar Mills48442912017-10-06 13:34:07 -050047 * @param[in] bus - The D-Bus bus object
Gunnar Millsec1b41c2017-05-02 12:20:36 -050048 */
Michael Tritz37a59042017-07-12 13:44:53 -050049 ItemUpdater(sdbusplus::bus::bus& bus, const std::string& path) :
Michael Tritz0129d922017-08-10 19:33:46 -050050 ItemUpdaterInherit(bus, path.c_str(), false),
Gunnar Millsec1b41c2017-05-02 12:20:36 -050051 bus(bus),
52 versionMatch(
53 bus,
Patrick Williamse75d10f2017-05-30 16:56:32 -050054 MatchRules::interfacesAdded() +
55 MatchRules::path("/xyz/openbmc_project/software"),
56 std::bind(
57 std::mem_fn(&ItemUpdater::createActivation),
58 this,
59 std::placeholders::_1))
60 {
Gunnar Millsb60add12017-08-24 16:41:42 -050061 setBMCInventoryPath();
Saqib Khanba239882017-05-26 08:41:54 -050062 processBMCImage();
Michael Tritz0129d922017-08-10 19:33:46 -050063 restoreFieldModeStatus();
64 emit_object_added();
Patrick Williamse75d10f2017-05-30 16:56:32 -050065 };
Gunnar Millsec1b41c2017-05-02 12:20:36 -050066
Gunnar Mills48442912017-10-06 13:34:07 -050067 /** @brief Sets the given priority free by incrementing
68 * any existing priority with the same value by 1
69 *
70 * @param[in] value - The priority that needs to be set free.
71 * @param[in] versionId - The Id of the version for which we
72 * are trying to free up the priority.
73 * @return None
74 */
75 void freePriority(uint8_t value, const std::string& versionId);
Saqib Khan4c1aec02017-07-06 11:46:13 -050076
Gunnar Mills48442912017-10-06 13:34:07 -050077 /**
78 * @brief Create and populate the active BMC Version.
79 */
80 void processBMCImage();
Saqib Khanba239882017-05-26 08:41:54 -050081
Gunnar Mills48442912017-10-06 13:34:07 -050082 /**
83 * @brief Erase specified entry D-Bus object
84 * if Action property is not set to Active
85 *
86 * @param[in] entryId - unique identifier of the entry
87 */
88 void erase(std::string entryId);
Leonel Gonzalez3526ef72017-07-07 14:38:25 -050089
Gunnar Mills48442912017-10-06 13:34:07 -050090 /**
91 * @brief Deletes all versions except for the current one
92 */
93 void deleteAll();
Gunnar Millsded875d2017-08-28 16:44:52 -050094
Gunnar Mills48442912017-10-06 13:34:07 -050095 /** @brief Creates an active association to the
96 * newly active software image
97 *
98 * @param[in] path - The path to create the association to.
99 */
100 void createActiveAssociation(const std::string& path);
Gunnar Millsded875d2017-08-28 16:44:52 -0500101
Gunnar Mills48442912017-10-06 13:34:07 -0500102 /** @brief Removes an active association to the software image
103 *
104 * @param[in] path - The path to remove the association from.
105 */
106 void removeActiveAssociation(const std::string& path);
Gunnar Millsded875d2017-08-28 16:44:52 -0500107
Gunnar Mills48442912017-10-06 13:34:07 -0500108 /** @brief Determine if the given priority is the lowest
109 *
110 * @param[in] value - The priority that needs to be checked.
111 *
112 * @return boolean corresponding to whether the given
113 * priority is lowest.
114 */
115 bool isLowestPriority(uint8_t value);
Saqib Khanb9da6632017-09-13 09:48:37 -0500116
Saqib Khan49446ae2017-10-02 10:54:20 -0500117 /**
118 * @brief Updates the uboot variables to point to BMC version with lowest
119 * priority, so that the system boots from this version on the
120 * next boot.
121 */
122 void resetUbootEnvVars();
123
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500124 private:
125 /** @brief Callback function for Software.Version match.
Gunnar Mills48442912017-10-06 13:34:07 -0500126 * @details Creates an Activation D-Bus object.
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500127 *
128 * @param[in] msg - Data associated with subscribed signal
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500129 */
Patrick Williamse75d10f2017-05-30 16:56:32 -0500130 void createActivation(sdbusplus::message::message& msg);
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500131
Saqib Khan35e83f32017-05-22 11:37:32 -0500132 /**
Gunnar Mills48442912017-10-06 13:34:07 -0500133 * @brief Validates the presence of SquashFS image in the image dir.
Saqib Khan35e83f32017-05-22 11:37:32 -0500134 *
Saqib Khan19177d32017-06-20 08:11:49 -0500135 * @param[in] filePath - The path to the image dir.
Saqib Khan35e83f32017-05-22 11:37:32 -0500136 * @param[out] result - ActivationStatus Enum.
137 * ready if validation was successful.
138 * invalid if validation fail.
139 * active if image is the current version.
140 *
141 */
Saqib Khan19177d32017-06-20 08:11:49 -0500142 ActivationStatus validateSquashFSImage(const std::string& filePath);
Saqib Khan35e83f32017-05-22 11:37:32 -0500143
Michael Tritz37a59042017-07-12 13:44:53 -0500144 /** @brief BMC factory reset - marks the read-write partition for
145 * recreation upon reboot. */
146 void reset() override;
147
Michael Tritz0129d922017-08-10 19:33:46 -0500148 /**
149 * @brief Enables field mode, if value=true.
150 *
151 * @param[in] value - If true, enables field mode.
152 * @param[out] result - Returns the current state of field mode.
153 *
154 */
155 bool fieldModeEnabled(bool value) override;
156
Gunnar Millsb60add12017-08-24 16:41:42 -0500157 /** @brief Sets the BMC inventory item path under
158 * /xyz/openbmc_project/inventory/system/chassis/. */
159 void setBMCInventoryPath();
160
161 /** @brief The path to the BMC inventory item. */
162 std::string bmcInventoryPath;
163
Michael Tritz0129d922017-08-10 19:33:46 -0500164 /** @brief Restores field mode status on reboot. */
165 void restoreFieldModeStatus();
166
Gunnar Mills88e8a322017-09-13 11:09:28 -0500167 /** @brief Creates a functional association to the
168 * "running" BMC software image
169 *
170 * @param[in] path - The path to create the association to.
171 */
172 void createFunctionalAssociation(const std::string& path);
173
Gunnar Mills48442912017-10-06 13:34:07 -0500174 /** @brief Persistent sdbusplus D-Bus bus connection. */
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500175 sdbusplus::bus::bus& bus;
176
Gunnar Mills48442912017-10-06 13:34:07 -0500177 /** @brief Persistent map of Activation D-Bus objects and their
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500178 * version id */
179 std::map<std::string, std::unique_ptr<Activation>> activations;
180
Gunnar Mills48442912017-10-06 13:34:07 -0500181 /** @brief Persistent map of Version D-Bus objects and their
Saqib Khan705f1bf2017-06-09 23:58:38 -0500182 * version id */
Gunnar Mills48442912017-10-06 13:34:07 -0500183 std::map<std::string, std::unique_ptr<VersionClass>> versions;
Saqib Khan705f1bf2017-06-09 23:58:38 -0500184
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500185 /** @brief sdbusplus signal match for Software.Version */
Patrick Williamse75d10f2017-05-30 16:56:32 -0500186 sdbusplus::bus::match_t versionMatch;
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500187
Gunnar Millsded875d2017-08-28 16:44:52 -0500188 /** @brief This entry's associations */
189 AssociationList assocs = {};
190
Leonel Gonzalez3526ef72017-07-07 14:38:25 -0500191 /** @brief Clears read only partition for
Gunnar Mills48442912017-10-06 13:34:07 -0500192 * given Activation D-Bus object.
193 *
194 * @param[in] versionId - The version id.
195 */
Leonel Gonzalez3526ef72017-07-07 14:38:25 -0500196 void removeReadOnlyPartition(std::string versionId);
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500197};
198
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500199} // namespace updater
200} // namespace software
201} // namespace phosphor