blob: 3489a479b3195e31fc3de5b95b3654316a8e5eda [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"
Gunnar Millsec1b41c2017-05-02 12:20:36 -05009
10namespace phosphor
11{
12namespace software
13{
14namespace updater
15{
16
Michael Tritz37a59042017-07-12 13:44:53 -050017using ItemUpdaterInherit = sdbusplus::server::object::object<
Michael Tritz0129d922017-08-10 19:33:46 -050018 sdbusplus::xyz::openbmc_project::Common::server::FactoryReset,
Gunnar Millsded875d2017-08-28 16:44:52 -050019 sdbusplus::xyz::openbmc_project::Control::server::FieldMode,
20 sdbusplus::org::openbmc::server::Associations>;
Michael Tritz37a59042017-07-12 13:44:53 -050021
Patrick Williamse75d10f2017-05-30 16:56:32 -050022namespace MatchRules = sdbusplus::bus::match::rules;
23
Gunnar Millsded875d2017-08-28 16:44:52 -050024using AssociationList =
25 std::vector<std::tuple<std::string, std::string, std::string>>;
26
Gunnar Millsec1b41c2017-05-02 12:20:36 -050027/** @class ItemUpdater
28 * @brief Manages the activation of the BMC version items.
29 */
Michael Tritz37a59042017-07-12 13:44:53 -050030class ItemUpdater : public ItemUpdaterInherit
Gunnar Millsec1b41c2017-05-02 12:20:36 -050031{
32 public:
Saqib Khan35e83f32017-05-22 11:37:32 -050033 /*
34 * @brief Types of Activation status for image validation.
35 */
36 enum class ActivationStatus
37 {
38 ready,
39 invalid,
40 active
41 };
42
Gunnar Millsec1b41c2017-05-02 12:20:36 -050043 /** @brief Constructs ItemUpdater
44 *
45 * @param[in] bus - The Dbus bus object
46 */
Michael Tritz37a59042017-07-12 13:44:53 -050047 ItemUpdater(sdbusplus::bus::bus& bus, const std::string& path) :
Michael Tritz0129d922017-08-10 19:33:46 -050048 ItemUpdaterInherit(bus, path.c_str(), false),
Gunnar Millsec1b41c2017-05-02 12:20:36 -050049 bus(bus),
50 versionMatch(
51 bus,
Patrick Williamse75d10f2017-05-30 16:56:32 -050052 MatchRules::interfacesAdded() +
53 MatchRules::path("/xyz/openbmc_project/software"),
54 std::bind(
55 std::mem_fn(&ItemUpdater::createActivation),
56 this,
57 std::placeholders::_1))
58 {
Gunnar Millsb60add12017-08-24 16:41:42 -050059 setBMCInventoryPath();
Saqib Khanba239882017-05-26 08:41:54 -050060 processBMCImage();
Michael Tritz0129d922017-08-10 19:33:46 -050061 restoreFieldModeStatus();
62 emit_object_added();
Patrick Williamse75d10f2017-05-30 16:56:32 -050063 };
Gunnar Millsec1b41c2017-05-02 12:20:36 -050064
Saqib Khan4c1aec02017-07-06 11:46:13 -050065 /** @brief Sets the given priority free by incrementing
66 * any existing priority with the same value by 1
67 *
68 * @param[in] value - The priority that needs to be set free.
69 *
70 * @return None
71 */
72 void freePriority(uint8_t value);
73
Saqib Khanba239882017-05-26 08:41:54 -050074 /**
75 * @brief Create and populate the active BMC Version.
76 */
77 void processBMCImage();
78
Leonel Gonzalez3526ef72017-07-07 14:38:25 -050079 /**
80 * @brief Erase specified entry d-bus object
81 * if Action property is not set to Active
82 *
83 * @param[in] entryId - unique identifier of the entry
84 */
85 void erase(std::string entryId);
86
Gunnar Millsded875d2017-08-28 16:44:52 -050087
88 /** @brief Creates an active association to the
89 * newly active software image
90 *
91 * @param[in] path - The path to create the association to.
92 */
93 void createActiveAssociation(std::string path);
94
95 /** @brief Removes an active association to the software image
96 *
97 * @param[in] path - The path to remove the association from.
98 */
99 void removeActiveAssociation(std::string path);
100
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500101 private:
102 /** @brief Callback function for Software.Version match.
103 * @details Creates an Activation dbus object.
104 *
105 * @param[in] msg - Data associated with subscribed signal
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500106 */
Patrick Williamse75d10f2017-05-30 16:56:32 -0500107 void createActivation(sdbusplus::message::message& msg);
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500108
Saqib Khan35e83f32017-05-22 11:37:32 -0500109 /**
110 * @brief Validates the presence of SquashFS iamge in the image dir.
111 *
Saqib Khan19177d32017-06-20 08:11:49 -0500112 * @param[in] filePath - The path to the image dir.
Saqib Khan35e83f32017-05-22 11:37:32 -0500113 * @param[out] result - ActivationStatus Enum.
114 * ready if validation was successful.
115 * invalid if validation fail.
116 * active if image is the current version.
117 *
118 */
Saqib Khan19177d32017-06-20 08:11:49 -0500119 ActivationStatus validateSquashFSImage(const std::string& filePath);
Saqib Khan35e83f32017-05-22 11:37:32 -0500120
Michael Tritz37a59042017-07-12 13:44:53 -0500121 /** @brief BMC factory reset - marks the read-write partition for
122 * recreation upon reboot. */
123 void reset() override;
124
Michael Tritz0129d922017-08-10 19:33:46 -0500125 /**
126 * @brief Enables field mode, if value=true.
127 *
128 * @param[in] value - If true, enables field mode.
129 * @param[out] result - Returns the current state of field mode.
130 *
131 */
132 bool fieldModeEnabled(bool value) override;
133
Gunnar Millsb60add12017-08-24 16:41:42 -0500134 /** @brief Sets the BMC inventory item path under
135 * /xyz/openbmc_project/inventory/system/chassis/. */
136 void setBMCInventoryPath();
137
138 /** @brief The path to the BMC inventory item. */
139 std::string bmcInventoryPath;
140
Michael Tritz0129d922017-08-10 19:33:46 -0500141 /** @brief Restores field mode status on reboot. */
142 void restoreFieldModeStatus();
143
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500144 /** @brief Persistent sdbusplus DBus bus connection. */
145 sdbusplus::bus::bus& bus;
146
147 /** @brief Persistent map of Activation dbus objects and their
148 * version id */
149 std::map<std::string, std::unique_ptr<Activation>> activations;
150
Saqib Khan705f1bf2017-06-09 23:58:38 -0500151 /** @brief Persistent map of Version dbus objects and their
152 * version id */
153 std::map<std::string, std::unique_ptr<phosphor::software::
154 manager::Version>> versions;
155
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500156 /** @brief sdbusplus signal match for Software.Version */
Patrick Williamse75d10f2017-05-30 16:56:32 -0500157 sdbusplus::bus::match_t versionMatch;
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500158
Gunnar Millsded875d2017-08-28 16:44:52 -0500159 /** @brief This entry's associations */
160 AssociationList assocs = {};
161
Leonel Gonzalez3526ef72017-07-07 14:38:25 -0500162 /** @brief Clears read only partition for
163 * given Activation dbus object.
164 *
165 * @param[in] versionId - The version id.
166 */
167 void removeReadOnlyPartition(std::string versionId);
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500168};
169
170
171
172} // namespace updater
173} // namespace software
174} // namespace phosphor