blob: 7f9a88b6f319cbb7f0bffff4b780b48dfdabcf08 [file] [log] [blame]
Adriana Kobylak2d8fa222017-03-15 12:34:32 -05001#pragma once
2
3#include <sdbusplus/server.hpp>
4#include "activation.hpp"
Michael Tritzdd961b62017-05-17 14:07:03 -05005#include <xyz/openbmc_project/Common/FactoryReset/server.hpp>
Saqib Khance148702017-06-11 12:01:58 -05006#include "version.hpp"
Gunnar Mills9741cd12017-08-28 15:09:00 -05007#include "org/openbmc/Associations/server.hpp"
Michael Tritz234a07e2017-09-21 00:53:06 -05008#include "xyz/openbmc_project/Collection/DeleteAll/server.hpp"
Adriana Kobylak2d8fa222017-03-15 12:34:32 -05009
10namespace openpower
11{
12namespace software
13{
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -050014namespace updater
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050015{
16
Michael Tritzdd961b62017-05-17 14:07:03 -050017using ItemUpdaterInherit = sdbusplus::server::object::object<
Gunnar Mills139cf1a2017-09-21 16:25:37 -050018 sdbusplus::xyz::openbmc_project::Common::server::FactoryReset,
19 sdbusplus::org::openbmc::server::Associations,
20 sdbusplus::xyz::openbmc_project::Collection::server::DeleteAll>;
Patrick Williams3accb322017-05-30 16:29:52 -050021namespace MatchRules = sdbusplus::bus::match::rules;
Michael Tritzdd961b62017-05-17 14:07:03 -050022
Gunnar Mills9741cd12017-08-28 15:09:00 -050023using AssociationList =
24 std::vector<std::tuple<std::string, std::string, std::string>>;
25
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050026/** @class ItemUpdater
Gunnar Mills139cf1a2017-09-21 16:25:37 -050027 * @brief Manages the activation of the host version items.
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050028 */
Michael Tritzdd961b62017-05-17 14:07:03 -050029class ItemUpdater : public ItemUpdaterInherit
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050030{
31 public:
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050032 /** @brief Constructs ItemUpdater
33 *
Gunnar Mills139cf1a2017-09-21 16:25:37 -050034 * @param[in] bus - The D-Bus bus object
35 * @param[in] path - The D-Bus path
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050036 */
Michael Tritzdd961b62017-05-17 14:07:03 -050037 ItemUpdater(sdbusplus::bus::bus& bus, const std::string& path) :
38 ItemUpdaterInherit(bus, path.c_str()),
Adriana Kobylakd6a549e2017-05-10 16:23:01 -050039 bus(bus),
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050040 versionMatch(
41 bus,
Patrick Williams3accb322017-05-30 16:29:52 -050042 MatchRules::interfacesAdded() +
43 MatchRules::path("/xyz/openbmc_project/software"),
44 std::bind(
45 std::mem_fn(&ItemUpdater::createActivation),
46 this,
47 std::placeholders::_1))
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050048 {
Saqib Khan167601b2017-06-18 23:33:46 -050049 processPNORImage();
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050050 }
51
Saqib Khan81bac882017-06-08 12:17:01 -050052 /** @brief Sets the given priority free by incrementing
53 * any existing priority with the same value by 1
54 *
55 * @param[in] value - The priority that needs to be set free.
Saqib Khanb8e7f312017-08-12 10:24:10 -050056 * @param[in] versionId - The Id of the version for which we
57 * are trying to free up the priority.
Saqib Khan81bac882017-06-08 12:17:01 -050058 * @return None
59 */
Saqib Khanb8e7f312017-08-12 10:24:10 -050060 void freePriority(uint8_t value, const std::string& versionId);
Saqib Khan81bac882017-06-08 12:17:01 -050061
Saqib Khan2af5c492017-07-17 16:15:13 -050062 /** @brief Determine is the given priority is the lowest
63 *
64 * @param[in] value - The priority that needs to be checked.
65 *
66 * @return boolean corresponding to whether the given
67 * priority is lowest.
68 */
69 bool isLowestPriority(uint8_t value);
70
Saqib Khan167601b2017-06-18 23:33:46 -050071 /**
72 * @brief Create and populate the active PNOR Version.
73 */
74 void processPNORImage();
75
Leonel Gonzalez9c8adfa2017-07-12 11:08:40 -050076 /** @brief Deletes version
77 *
78 * @param[in] entryId - Id of the version to delete
79 *
80 * @return None
81 */
82 void erase(std::string entryId);
83
Michael Tritz234a07e2017-09-21 00:53:06 -050084 /**
85 * @brief Erases any non-active pnor versions.
86 */
87 void deleteAll();
88
Gunnar Mills139cf1a2017-09-21 16:25:37 -050089 /** @brief Deletes the active PNOR version with highest priority
90 if the total number of volumes exceeds the threshold.
Saqib Khan2cbfa032017-08-17 14:52:37 -050091 */
92 void freeSpace();
93
Gunnar Mills9741cd12017-08-28 15:09:00 -050094 /** @brief Creates an active association to the
95 * newly active software image
96 *
97 * @param[in] path - The path to create the association to.
98 */
99 void createActiveAssociation(std::string path);
100
Gunnar Mills833e4f32017-09-14 12:30:27 -0500101 /** @brief Updates the functional association to the
102 * new "running" PNOR image
103 *
104 * @param[in] path - The path to update the association to.
105 */
106 void updateFunctionalAssociation(const std::string& path);
107
Gunnar Mills9741cd12017-08-28 15:09:00 -0500108 /** @brief Removes an active association to the software image
109 *
110 * @param[in] path - The path to remove the association from.
111 */
112 void removeActiveAssociation(std::string path);
113
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500114 private:
115 /** @brief Callback function for Software.Version match.
Gunnar Mills139cf1a2017-09-21 16:25:37 -0500116 * @details Creates an Activation D-Bus object.
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500117 *
118 * @param[in] msg - Data associated with subscribed signal
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500119 */
Patrick Williams3accb322017-05-30 16:29:52 -0500120 void createActivation(sdbusplus::message::message& msg);
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500121
Saqib Khan7254f0e2017-04-10 21:45:37 -0500122 /**
Gunnar Mills139cf1a2017-09-21 16:25:37 -0500123 * @brief Validates the presence of SquashFS image in the image dir.
Saqib Khana8ade7e2017-04-12 10:27:56 -0500124 *
Gunnar Mills139cf1a2017-09-21 16:25:37 -0500125 * @param[in] filePath - The path to the SquashFS image.
Saqib Khana8ade7e2017-04-12 10:27:56 -0500126 * @param[out] result - 0 --> if validation was successful
127 * - -1--> Otherwise
128 */
Adriana Kobylak5ba6b102017-05-19 09:41:27 -0500129 static int validateSquashFSImage(const std::string& filePath);
Saqib Khan7254f0e2017-04-10 21:45:37 -0500130
Gunnar Mills139cf1a2017-09-21 16:25:37 -0500131 /** @brief Persistent sdbusplus D-Bus bus connection. */
Adriana Kobylakd6a549e2017-05-10 16:23:01 -0500132 sdbusplus::bus::bus& bus;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500133
Gunnar Mills139cf1a2017-09-21 16:25:37 -0500134 /** @brief Persistent map of Activation D-Bus objects and their
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500135 * version id */
Adriana Kobylak268616b2017-04-05 15:23:30 -0500136 std::map<std::string, std::unique_ptr<Activation>> activations;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500137
Gunnar Mills139cf1a2017-09-21 16:25:37 -0500138 /** @brief Persistent map of Version D-Bus objects and their
Saqib Khance148702017-06-11 12:01:58 -0500139 * version id */
140 std::map<std::string, std::unique_ptr<Version>> versions;
141
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500142 /** @brief sdbusplus signal match for Software.Version */
Patrick Williams3accb322017-05-30 16:29:52 -0500143 sdbusplus::bus::match_t versionMatch;
Michael Tritzdd961b62017-05-17 14:07:03 -0500144
Gunnar Mills9741cd12017-08-28 15:09:00 -0500145 /** @brief This entry's associations */
146 AssociationList assocs = {};
147
Leonel Gonzalez9c8adfa2017-07-12 11:08:40 -0500148 /** @brief Clears read only PNOR partition for
Gunnar Mills139cf1a2017-09-21 16:25:37 -0500149 * given Activation D-Bus object
Leonel Gonzalez9c8adfa2017-07-12 11:08:40 -0500150 *
151 * @param[in] versionId - The id of the ro partition to remove.
152 */
153 void removeReadOnlyPartition(std::string versionId);
154
155 /** @brief Clears read write PNOR partition for
Gunnar Mills139cf1a2017-09-21 16:25:37 -0500156 * given Activation D-Bus object
Leonel Gonzalez9c8adfa2017-07-12 11:08:40 -0500157 *
Saqib Khan1e0aa5c2017-08-31 11:04:17 -0500158 * @param[in] versionId - The id of the rw partition to remove.
Leonel Gonzalez9c8adfa2017-07-12 11:08:40 -0500159 */
160 void removeReadWritePartition(std::string versionId);
161
162 /** @brief Clears preserved PNOR partition */
163 void removePreservedPartition();
164
Michael Tritzdd961b62017-05-17 14:07:03 -0500165 /** @brief Host factory reset - clears PNOR partitions for each
Gunnar Mills139cf1a2017-09-21 16:25:37 -0500166 * Activation D-Bus object */
Michael Tritzdd961b62017-05-17 14:07:03 -0500167 void reset() override;
Eddie James13fc66a2017-08-31 15:36:44 -0500168
169 /** @brief Check whether the provided image id is the functional one
170 *
171 * @param[in] - versionId - The id of the image to check.
172 *
173 * @return - Returns true if this version is currently functional.
174 */
175 static bool isVersionFunctional(std::string versionId);
176
177 /** @brief Check whether the host is running
178 *
179 * @return - Returns true if the Chassis is powered on.
180 */
181 bool isChassisOn();
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500182};
183
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500184} // namespace updater
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500185} // namespace software
186} // namespace openpower