blob: e4fdd69500dffed3a757711d571ab2339594e78a [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
Gunnar Millsec1b41c2017-05-02 12:20:36 -050069 private:
70 /** @brief Callback function for Software.Version match.
71 * @details Creates an Activation dbus object.
72 *
73 * @param[in] msg - Data associated with subscribed signal
Gunnar Millsec1b41c2017-05-02 12:20:36 -050074 */
Patrick Williamse75d10f2017-05-30 16:56:32 -050075 void createActivation(sdbusplus::message::message& msg);
Gunnar Millsec1b41c2017-05-02 12:20:36 -050076
Saqib Khan35e83f32017-05-22 11:37:32 -050077 /**
78 * @brief Validates the presence of SquashFS iamge in the image dir.
79 *
Saqib Khan19177d32017-06-20 08:11:49 -050080 * @param[in] filePath - The path to the image dir.
Saqib Khan35e83f32017-05-22 11:37:32 -050081 * @param[out] result - ActivationStatus Enum.
82 * ready if validation was successful.
83 * invalid if validation fail.
84 * active if image is the current version.
85 *
86 */
Saqib Khan19177d32017-06-20 08:11:49 -050087 ActivationStatus validateSquashFSImage(const std::string& filePath);
Saqib Khan35e83f32017-05-22 11:37:32 -050088
Michael Tritz37a59042017-07-12 13:44:53 -050089 /** @brief BMC factory reset - marks the read-write partition for
90 * recreation upon reboot. */
91 void reset() override;
92
Gunnar Millsec1b41c2017-05-02 12:20:36 -050093 /** @brief Persistent sdbusplus DBus bus connection. */
94 sdbusplus::bus::bus& bus;
95
96 /** @brief Persistent map of Activation dbus objects and their
97 * version id */
98 std::map<std::string, std::unique_ptr<Activation>> activations;
99
Saqib Khan705f1bf2017-06-09 23:58:38 -0500100 /** @brief Persistent map of Version dbus objects and their
101 * version id */
102 std::map<std::string, std::unique_ptr<phosphor::software::
103 manager::Version>> versions;
104
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500105 /** @brief sdbusplus signal match for Software.Version */
Patrick Williamse75d10f2017-05-30 16:56:32 -0500106 sdbusplus::bus::match_t versionMatch;
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500107
108};
109
110
111
112} // namespace updater
113} // namespace software
114} // namespace phosphor