Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <sdbusplus/server.hpp> |
| 4 | #include "activation.hpp" |
Michael Tritz | dd961b6 | 2017-05-17 14:07:03 -0500 | [diff] [blame] | 5 | #include <xyz/openbmc_project/Common/FactoryReset/server.hpp> |
Saqib Khan | ce14870 | 2017-06-11 12:01:58 -0500 | [diff] [blame] | 6 | #include "version.hpp" |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 7 | |
| 8 | namespace openpower |
| 9 | { |
| 10 | namespace software |
| 11 | { |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 12 | namespace updater |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 13 | { |
| 14 | |
Michael Tritz | dd961b6 | 2017-05-17 14:07:03 -0500 | [diff] [blame] | 15 | using ItemUpdaterInherit = sdbusplus::server::object::object< |
| 16 | sdbusplus::xyz::openbmc_project::Common::server::FactoryReset>; |
Patrick Williams | 3accb32 | 2017-05-30 16:29:52 -0500 | [diff] [blame] | 17 | namespace MatchRules = sdbusplus::bus::match::rules; |
Michael Tritz | dd961b6 | 2017-05-17 14:07:03 -0500 | [diff] [blame] | 18 | |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 19 | /** @class ItemUpdater |
| 20 | * @brief Manages the activation of the version items. |
| 21 | */ |
Michael Tritz | dd961b6 | 2017-05-17 14:07:03 -0500 | [diff] [blame] | 22 | class ItemUpdater : public ItemUpdaterInherit |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 23 | { |
| 24 | public: |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 25 | /** @brief Constructs ItemUpdater |
| 26 | * |
| 27 | * @param[in] bus - The Dbus bus object |
Michael Tritz | dd961b6 | 2017-05-17 14:07:03 -0500 | [diff] [blame] | 28 | * @param[in] path - The Dbus path |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 29 | */ |
Michael Tritz | dd961b6 | 2017-05-17 14:07:03 -0500 | [diff] [blame] | 30 | ItemUpdater(sdbusplus::bus::bus& bus, const std::string& path) : |
| 31 | ItemUpdaterInherit(bus, path.c_str()), |
Adriana Kobylak | d6a549e | 2017-05-10 16:23:01 -0500 | [diff] [blame] | 32 | bus(bus), |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 33 | versionMatch( |
| 34 | bus, |
Patrick Williams | 3accb32 | 2017-05-30 16:29:52 -0500 | [diff] [blame] | 35 | MatchRules::interfacesAdded() + |
| 36 | MatchRules::path("/xyz/openbmc_project/software"), |
| 37 | std::bind( |
| 38 | std::mem_fn(&ItemUpdater::createActivation), |
| 39 | this, |
| 40 | std::placeholders::_1)) |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 41 | { |
Saqib Khan | 167601b | 2017-06-18 23:33:46 -0500 | [diff] [blame] | 42 | processPNORImage(); |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 43 | } |
| 44 | |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 45 | /** @brief Sets the given priority free by incrementing |
| 46 | * any existing priority with the same value by 1 |
| 47 | * |
| 48 | * @param[in] value - The priority that needs to be set free. |
Saqib Khan | b8e7f31 | 2017-08-12 10:24:10 -0500 | [diff] [blame] | 49 | * @param[in] versionId - The Id of the version for which we |
| 50 | * are trying to free up the priority. |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 51 | * @return None |
| 52 | */ |
Saqib Khan | b8e7f31 | 2017-08-12 10:24:10 -0500 | [diff] [blame] | 53 | void freePriority(uint8_t value, const std::string& versionId); |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 54 | |
Saqib Khan | 2af5c49 | 2017-07-17 16:15:13 -0500 | [diff] [blame] | 55 | /** @brief Determine is the given priority is the lowest |
| 56 | * |
| 57 | * @param[in] value - The priority that needs to be checked. |
| 58 | * |
| 59 | * @return boolean corresponding to whether the given |
| 60 | * priority is lowest. |
| 61 | */ |
| 62 | bool isLowestPriority(uint8_t value); |
| 63 | |
Saqib Khan | 167601b | 2017-06-18 23:33:46 -0500 | [diff] [blame] | 64 | /** |
| 65 | * @brief Create and populate the active PNOR Version. |
| 66 | */ |
| 67 | void processPNORImage(); |
| 68 | |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 69 | /** @brief Deletes version |
| 70 | * |
| 71 | * @param[in] entryId - Id of the version to delete |
| 72 | * |
| 73 | * @return None |
| 74 | */ |
| 75 | void erase(std::string entryId); |
| 76 | |
Saqib Khan | 2cbfa03 | 2017-08-17 14:52:37 -0500 | [diff] [blame] | 77 | /** @brief Deletes the active pnor version with highest priority |
| 78 | if the total number of volume exceeds the threshold. |
| 79 | */ |
| 80 | void freeSpace(); |
| 81 | |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 82 | 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 |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 87 | */ |
Patrick Williams | 3accb32 | 2017-05-30 16:29:52 -0500 | [diff] [blame] | 88 | void createActivation(sdbusplus::message::message& msg); |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 89 | |
Saqib Khan | 7254f0e | 2017-04-10 21:45:37 -0500 | [diff] [blame] | 90 | /** |
Saqib Khan | a8ade7e | 2017-04-12 10:27:56 -0500 | [diff] [blame] | 91 | * @brief Validates the presence of SquashFS iamge in the image dir. |
| 92 | * |
Adriana Kobylak | 5ba6b10 | 2017-05-19 09:41:27 -0500 | [diff] [blame] | 93 | * @param[in] filePath - The path to the SquashfFS image. |
Saqib Khan | a8ade7e | 2017-04-12 10:27:56 -0500 | [diff] [blame] | 94 | * @param[out] result - 0 --> if validation was successful |
| 95 | * - -1--> Otherwise |
| 96 | */ |
Adriana Kobylak | 5ba6b10 | 2017-05-19 09:41:27 -0500 | [diff] [blame] | 97 | static int validateSquashFSImage(const std::string& filePath); |
Saqib Khan | 7254f0e | 2017-04-10 21:45:37 -0500 | [diff] [blame] | 98 | |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 99 | /** @brief Persistent sdbusplus DBus bus connection. */ |
Adriana Kobylak | d6a549e | 2017-05-10 16:23:01 -0500 | [diff] [blame] | 100 | sdbusplus::bus::bus& bus; |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 101 | |
| 102 | /** @brief Persistent map of Activation dbus objects and their |
| 103 | * version id */ |
Adriana Kobylak | 268616b | 2017-04-05 15:23:30 -0500 | [diff] [blame] | 104 | std::map<std::string, std::unique_ptr<Activation>> activations; |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 105 | |
Saqib Khan | ce14870 | 2017-06-11 12:01:58 -0500 | [diff] [blame] | 106 | /** @brief Persistent map of Version dbus objects and their |
| 107 | * version id */ |
| 108 | std::map<std::string, std::unique_ptr<Version>> versions; |
| 109 | |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 110 | /** @brief sdbusplus signal match for Software.Version */ |
Patrick Williams | 3accb32 | 2017-05-30 16:29:52 -0500 | [diff] [blame] | 111 | sdbusplus::bus::match_t versionMatch; |
Michael Tritz | dd961b6 | 2017-05-17 14:07:03 -0500 | [diff] [blame] | 112 | |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 113 | /** @brief Clears read only PNOR partition for |
| 114 | * given Activation dbus object |
| 115 | * |
| 116 | * @param[in] versionId - The id of the ro partition to remove. |
| 117 | */ |
| 118 | void removeReadOnlyPartition(std::string versionId); |
| 119 | |
| 120 | /** @brief Clears read write PNOR partition for |
| 121 | * given Activation dbus object |
| 122 | * |
| 123 | * @param[in] versionId - The id of the rw partition to remove. |
| 124 | */ |
| 125 | void removeReadWritePartition(std::string versionId); |
| 126 | |
| 127 | /** @brief Clears preserved PNOR partition */ |
| 128 | void removePreservedPartition(); |
| 129 | |
Michael Tritz | dd961b6 | 2017-05-17 14:07:03 -0500 | [diff] [blame] | 130 | /** @brief Host factory reset - clears PNOR partitions for each |
| 131 | * Activation dbus object */ |
| 132 | void reset() override; |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 133 | }; |
| 134 | |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 135 | } // namespace updater |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 136 | } // namespace software |
| 137 | } // namespace openpower |