blob: de7b614cd1e4f4fc304270fc1c511eca1066aace [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 Millsec1b41c2017-05-02 12:20:36 -05008
9namespace phosphor
10{
11namespace software
12{
13namespace updater
14{
15
Michael Tritz37a59042017-07-12 13:44:53 -050016using ItemUpdaterInherit = sdbusplus::server::object::object<
Michael Tritz0129d922017-08-10 19:33:46 -050017 sdbusplus::xyz::openbmc_project::Common::server::FactoryReset,
18 sdbusplus::xyz::openbmc_project::Control::server::FieldMode>;
Michael Tritz37a59042017-07-12 13:44:53 -050019
Patrick Williamse75d10f2017-05-30 16:56:32 -050020namespace MatchRules = sdbusplus::bus::match::rules;
21
Gunnar Millsec1b41c2017-05-02 12:20:36 -050022/** @class ItemUpdater
23 * @brief Manages the activation of the BMC version items.
24 */
Michael Tritz37a59042017-07-12 13:44:53 -050025class ItemUpdater : public ItemUpdaterInherit
Gunnar Millsec1b41c2017-05-02 12:20:36 -050026{
27 public:
Saqib Khan35e83f32017-05-22 11:37:32 -050028 /*
29 * @brief Types of Activation status for image validation.
30 */
31 enum class ActivationStatus
32 {
33 ready,
34 invalid,
35 active
36 };
37
Gunnar Millsec1b41c2017-05-02 12:20:36 -050038 /** @brief Constructs ItemUpdater
39 *
40 * @param[in] bus - The Dbus bus object
41 */
Michael Tritz37a59042017-07-12 13:44:53 -050042 ItemUpdater(sdbusplus::bus::bus& bus, const std::string& path) :
Michael Tritz0129d922017-08-10 19:33:46 -050043 ItemUpdaterInherit(bus, path.c_str(), false),
Gunnar Millsec1b41c2017-05-02 12:20:36 -050044 bus(bus),
45 versionMatch(
46 bus,
Patrick Williamse75d10f2017-05-30 16:56:32 -050047 MatchRules::interfacesAdded() +
48 MatchRules::path("/xyz/openbmc_project/software"),
49 std::bind(
50 std::mem_fn(&ItemUpdater::createActivation),
51 this,
52 std::placeholders::_1))
53 {
Saqib Khanba239882017-05-26 08:41:54 -050054 processBMCImage();
Michael Tritz0129d922017-08-10 19:33:46 -050055 restoreFieldModeStatus();
56 emit_object_added();
Patrick Williamse75d10f2017-05-30 16:56:32 -050057 };
Gunnar Millsec1b41c2017-05-02 12:20:36 -050058
Saqib Khan4c1aec02017-07-06 11:46:13 -050059 /** @brief Sets the given priority free by incrementing
60 * any existing priority with the same value by 1
61 *
62 * @param[in] value - The priority that needs to be set free.
63 *
64 * @return None
65 */
66 void freePriority(uint8_t value);
67
Saqib Khanba239882017-05-26 08:41:54 -050068 /**
69 * @brief Create and populate the active BMC Version.
70 */
71 void processBMCImage();
72
Leonel Gonzalez3526ef72017-07-07 14:38:25 -050073 /**
74 * @brief Erase specified entry d-bus object
75 * if Action property is not set to Active
76 *
77 * @param[in] entryId - unique identifier of the entry
78 */
79 void erase(std::string entryId);
80
Gunnar Millsec1b41c2017-05-02 12:20:36 -050081 private:
82 /** @brief Callback function for Software.Version match.
83 * @details Creates an Activation dbus object.
84 *
85 * @param[in] msg - Data associated with subscribed signal
Gunnar Millsec1b41c2017-05-02 12:20:36 -050086 */
Patrick Williamse75d10f2017-05-30 16:56:32 -050087 void createActivation(sdbusplus::message::message& msg);
Gunnar Millsec1b41c2017-05-02 12:20:36 -050088
Saqib Khan35e83f32017-05-22 11:37:32 -050089 /**
90 * @brief Validates the presence of SquashFS iamge in the image dir.
91 *
Saqib Khan19177d32017-06-20 08:11:49 -050092 * @param[in] filePath - The path to the image dir.
Saqib Khan35e83f32017-05-22 11:37:32 -050093 * @param[out] result - ActivationStatus Enum.
94 * ready if validation was successful.
95 * invalid if validation fail.
96 * active if image is the current version.
97 *
98 */
Saqib Khan19177d32017-06-20 08:11:49 -050099 ActivationStatus validateSquashFSImage(const std::string& filePath);
Saqib Khan35e83f32017-05-22 11:37:32 -0500100
Michael Tritz37a59042017-07-12 13:44:53 -0500101 /** @brief BMC factory reset - marks the read-write partition for
102 * recreation upon reboot. */
103 void reset() override;
104
Michael Tritz0129d922017-08-10 19:33:46 -0500105 /**
106 * @brief Enables field mode, if value=true.
107 *
108 * @param[in] value - If true, enables field mode.
109 * @param[out] result - Returns the current state of field mode.
110 *
111 */
112 bool fieldModeEnabled(bool value) override;
113
114 /** @brief Restores field mode status on reboot. */
115 void restoreFieldModeStatus();
116
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500117 /** @brief Persistent sdbusplus DBus bus connection. */
118 sdbusplus::bus::bus& bus;
119
120 /** @brief Persistent map of Activation dbus objects and their
121 * version id */
122 std::map<std::string, std::unique_ptr<Activation>> activations;
123
Saqib Khan705f1bf2017-06-09 23:58:38 -0500124 /** @brief Persistent map of Version dbus objects and their
125 * version id */
126 std::map<std::string, std::unique_ptr<phosphor::software::
127 manager::Version>> versions;
128
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500129 /** @brief sdbusplus signal match for Software.Version */
Patrick Williamse75d10f2017-05-30 16:56:32 -0500130 sdbusplus::bus::match_t versionMatch;
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500131
Leonel Gonzalez3526ef72017-07-07 14:38:25 -0500132 /** @brief Clears read only partition for
133 * given Activation dbus object.
134 *
135 * @param[in] versionId - The version id.
136 */
137 void removeReadOnlyPartition(std::string versionId);
138
139 /** @brief Clears read write partition for
140 * given Activation dbus object.
141 *
142 * @param[in] versionId - The version id.
143 */
144 void removeReadWritePartition(std::string versionId);
145
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500146};
147
148
149
150} // namespace updater
151} // namespace software
152} // namespace phosphor