blob: 5b2a71b198ea9b7d225dd9a877e39a7a10c030d1 [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>
Gunnar Millsec1b41c2017-05-02 12:20:36 -05007
8namespace phosphor
9{
10namespace software
11{
12namespace updater
13{
14
Michael Tritz37a59042017-07-12 13:44:53 -050015using ItemUpdaterInherit = sdbusplus::server::object::object<
16 sdbusplus::xyz::openbmc_project::Common::server::FactoryReset>;
17
Patrick Williamse75d10f2017-05-30 16:56:32 -050018namespace MatchRules = sdbusplus::bus::match::rules;
19
Gunnar Millsec1b41c2017-05-02 12:20:36 -050020/** @class ItemUpdater
21 * @brief Manages the activation of the BMC version items.
22 */
Michael Tritz37a59042017-07-12 13:44:53 -050023class ItemUpdater : public ItemUpdaterInherit
Gunnar Millsec1b41c2017-05-02 12:20:36 -050024{
25 public:
Saqib Khan35e83f32017-05-22 11:37:32 -050026 /*
27 * @brief Types of Activation status for image validation.
28 */
29 enum class ActivationStatus
30 {
31 ready,
32 invalid,
33 active
34 };
35
Gunnar Millsec1b41c2017-05-02 12:20:36 -050036 /** @brief Constructs ItemUpdater
37 *
38 * @param[in] bus - The Dbus bus object
39 */
Michael Tritz37a59042017-07-12 13:44:53 -050040 ItemUpdater(sdbusplus::bus::bus& bus, const std::string& path) :
41 ItemUpdaterInherit(bus, path.c_str()),
Gunnar Millsec1b41c2017-05-02 12:20:36 -050042 bus(bus),
43 versionMatch(
44 bus,
Patrick Williamse75d10f2017-05-30 16:56:32 -050045 MatchRules::interfacesAdded() +
46 MatchRules::path("/xyz/openbmc_project/software"),
47 std::bind(
48 std::mem_fn(&ItemUpdater::createActivation),
49 this,
50 std::placeholders::_1))
51 {
Saqib Khanba239882017-05-26 08:41:54 -050052 processBMCImage();
Patrick Williamse75d10f2017-05-30 16:56:32 -050053 };
Gunnar Millsec1b41c2017-05-02 12:20:36 -050054
Saqib Khan4c1aec02017-07-06 11:46:13 -050055 /** @brief Sets the given priority free by incrementing
56 * any existing priority with the same value by 1
57 *
58 * @param[in] value - The priority that needs to be set free.
59 *
60 * @return None
61 */
62 void freePriority(uint8_t value);
63
Saqib Khanba239882017-05-26 08:41:54 -050064 /**
65 * @brief Create and populate the active BMC Version.
66 */
67 void processBMCImage();
68
Leonel Gonzalez3526ef72017-07-07 14:38:25 -050069 /**
70 * @brief Erase specified entry d-bus object
71 * if Action property is not set to Active
72 *
73 * @param[in] entryId - unique identifier of the entry
74 */
75 void erase(std::string entryId);
76
Gunnar Millsec1b41c2017-05-02 12:20:36 -050077 private:
78 /** @brief Callback function for Software.Version match.
79 * @details Creates an Activation dbus object.
80 *
81 * @param[in] msg - Data associated with subscribed signal
Gunnar Millsec1b41c2017-05-02 12:20:36 -050082 */
Patrick Williamse75d10f2017-05-30 16:56:32 -050083 void createActivation(sdbusplus::message::message& msg);
Gunnar Millsec1b41c2017-05-02 12:20:36 -050084
Saqib Khan35e83f32017-05-22 11:37:32 -050085 /**
86 * @brief Validates the presence of SquashFS iamge in the image dir.
87 *
Saqib Khan19177d32017-06-20 08:11:49 -050088 * @param[in] filePath - The path to the image dir.
Saqib Khan35e83f32017-05-22 11:37:32 -050089 * @param[out] result - ActivationStatus Enum.
90 * ready if validation was successful.
91 * invalid if validation fail.
92 * active if image is the current version.
93 *
94 */
Saqib Khan19177d32017-06-20 08:11:49 -050095 ActivationStatus validateSquashFSImage(const std::string& filePath);
Saqib Khan35e83f32017-05-22 11:37:32 -050096
Michael Tritz37a59042017-07-12 13:44:53 -050097 /** @brief BMC factory reset - marks the read-write partition for
98 * recreation upon reboot. */
99 void reset() override;
100
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500101 /** @brief Persistent sdbusplus DBus bus connection. */
102 sdbusplus::bus::bus& bus;
103
104 /** @brief Persistent map of Activation dbus objects and their
105 * version id */
106 std::map<std::string, std::unique_ptr<Activation>> activations;
107
Saqib Khan705f1bf2017-06-09 23:58:38 -0500108 /** @brief Persistent map of Version dbus objects and their
109 * version id */
110 std::map<std::string, std::unique_ptr<phosphor::software::
111 manager::Version>> versions;
112
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500113 /** @brief sdbusplus signal match for Software.Version */
Patrick Williamse75d10f2017-05-30 16:56:32 -0500114 sdbusplus::bus::match_t versionMatch;
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500115
Leonel Gonzalez3526ef72017-07-07 14:38:25 -0500116 /** @brief Clears read only partition for
117 * given Activation dbus object.
118 *
119 * @param[in] versionId - The version id.
120 */
121 void removeReadOnlyPartition(std::string versionId);
122
123 /** @brief Clears read write partition for
124 * given Activation dbus object.
125 *
126 * @param[in] versionId - The version id.
127 */
128 void removeReadWritePartition(std::string versionId);
129
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500130};
131
132
133
134} // namespace updater
135} // namespace software
136} // namespace phosphor