blob: 4015760e1bcd7fbd9cd2aff95eb0b0e408bf8ad4 [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 {
Gunnar Millsb60add12017-08-24 16:41:42 -050054 setBMCInventoryPath();
Saqib Khanba239882017-05-26 08:41:54 -050055 processBMCImage();
Michael Tritz0129d922017-08-10 19:33:46 -050056 restoreFieldModeStatus();
57 emit_object_added();
Patrick Williamse75d10f2017-05-30 16:56:32 -050058 };
Gunnar Millsec1b41c2017-05-02 12:20:36 -050059
Saqib Khan4c1aec02017-07-06 11:46:13 -050060 /** @brief Sets the given priority free by incrementing
61 * any existing priority with the same value by 1
62 *
63 * @param[in] value - The priority that needs to be set free.
64 *
65 * @return None
66 */
67 void freePriority(uint8_t value);
68
Saqib Khanba239882017-05-26 08:41:54 -050069 /**
70 * @brief Create and populate the active BMC Version.
71 */
72 void processBMCImage();
73
Leonel Gonzalez3526ef72017-07-07 14:38:25 -050074 /**
75 * @brief Erase specified entry d-bus object
76 * if Action property is not set to Active
77 *
78 * @param[in] entryId - unique identifier of the entry
79 */
80 void erase(std::string entryId);
81
Gunnar Millsec1b41c2017-05-02 12:20:36 -050082 private:
83 /** @brief Callback function for Software.Version match.
84 * @details Creates an Activation dbus object.
85 *
86 * @param[in] msg - Data associated with subscribed signal
Gunnar Millsec1b41c2017-05-02 12:20:36 -050087 */
Patrick Williamse75d10f2017-05-30 16:56:32 -050088 void createActivation(sdbusplus::message::message& msg);
Gunnar Millsec1b41c2017-05-02 12:20:36 -050089
Saqib Khan35e83f32017-05-22 11:37:32 -050090 /**
91 * @brief Validates the presence of SquashFS iamge in the image dir.
92 *
Saqib Khan19177d32017-06-20 08:11:49 -050093 * @param[in] filePath - The path to the image dir.
Saqib Khan35e83f32017-05-22 11:37:32 -050094 * @param[out] result - ActivationStatus Enum.
95 * ready if validation was successful.
96 * invalid if validation fail.
97 * active if image is the current version.
98 *
99 */
Saqib Khan19177d32017-06-20 08:11:49 -0500100 ActivationStatus validateSquashFSImage(const std::string& filePath);
Saqib Khan35e83f32017-05-22 11:37:32 -0500101
Michael Tritz37a59042017-07-12 13:44:53 -0500102 /** @brief BMC factory reset - marks the read-write partition for
103 * recreation upon reboot. */
104 void reset() override;
105
Michael Tritz0129d922017-08-10 19:33:46 -0500106 /**
107 * @brief Enables field mode, if value=true.
108 *
109 * @param[in] value - If true, enables field mode.
110 * @param[out] result - Returns the current state of field mode.
111 *
112 */
113 bool fieldModeEnabled(bool value) override;
114
Gunnar Millsb60add12017-08-24 16:41:42 -0500115 /** @brief Sets the BMC inventory item path under
116 * /xyz/openbmc_project/inventory/system/chassis/. */
117 void setBMCInventoryPath();
118
119 /** @brief The path to the BMC inventory item. */
120 std::string bmcInventoryPath;
121
Michael Tritz0129d922017-08-10 19:33:46 -0500122 /** @brief Restores field mode status on reboot. */
123 void restoreFieldModeStatus();
124
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500125 /** @brief Persistent sdbusplus DBus bus connection. */
126 sdbusplus::bus::bus& bus;
127
128 /** @brief Persistent map of Activation dbus objects and their
129 * version id */
130 std::map<std::string, std::unique_ptr<Activation>> activations;
131
Saqib Khan705f1bf2017-06-09 23:58:38 -0500132 /** @brief Persistent map of Version dbus objects and their
133 * version id */
134 std::map<std::string, std::unique_ptr<phosphor::software::
135 manager::Version>> versions;
136
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500137 /** @brief sdbusplus signal match for Software.Version */
Patrick Williamse75d10f2017-05-30 16:56:32 -0500138 sdbusplus::bus::match_t versionMatch;
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500139
Leonel Gonzalez3526ef72017-07-07 14:38:25 -0500140 /** @brief Clears read only partition for
141 * given Activation dbus object.
142 *
143 * @param[in] versionId - The version id.
144 */
145 void removeReadOnlyPartition(std::string versionId);
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500146};
147
148
149
150} // namespace updater
151} // namespace software
152} // namespace phosphor