Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 3 | #include "activation.hpp" |
Lei YU | 56aaf45 | 2018-06-21 16:09:44 +0800 | [diff] [blame] | 4 | #include "item_updater_helper.hpp" |
Gunnar Mills | b0ce996 | 2018-09-07 13:39:10 -0500 | [diff] [blame^] | 5 | #include "org/openbmc/Associations/server.hpp" |
Saqib Khan | 705f1bf | 2017-06-09 23:58:38 -0500 | [diff] [blame] | 6 | #include "version.hpp" |
Gunnar Mills | b0ce996 | 2018-09-07 13:39:10 -0500 | [diff] [blame^] | 7 | #include "xyz/openbmc_project/Collection/DeleteAll/server.hpp" |
| 8 | |
| 9 | #include <sdbusplus/server.hpp> |
Michael Tritz | 37a5904 | 2017-07-12 13:44:53 -0500 | [diff] [blame] | 10 | #include <xyz/openbmc_project/Common/FactoryReset/server.hpp> |
Michael Tritz | 0129d92 | 2017-08-10 19:33:46 -0500 | [diff] [blame] | 11 | #include <xyz/openbmc_project/Control/FieldMode/server.hpp> |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 12 | |
| 13 | namespace phosphor |
| 14 | { |
| 15 | namespace software |
| 16 | { |
| 17 | namespace updater |
| 18 | { |
| 19 | |
Michael Tritz | 37a5904 | 2017-07-12 13:44:53 -0500 | [diff] [blame] | 20 | using ItemUpdaterInherit = sdbusplus::server::object::object< |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 21 | sdbusplus::xyz::openbmc_project::Common::server::FactoryReset, |
| 22 | sdbusplus::xyz::openbmc_project::Control::server::FieldMode, |
| 23 | sdbusplus::org::openbmc::server::Associations, |
| 24 | sdbusplus::xyz::openbmc_project::Collection::server::DeleteAll>; |
Michael Tritz | 37a5904 | 2017-07-12 13:44:53 -0500 | [diff] [blame] | 25 | |
Patrick Williams | e75d10f | 2017-05-30 16:56:32 -0500 | [diff] [blame] | 26 | namespace MatchRules = sdbusplus::bus::match::rules; |
Gunnar Mills | 4844291 | 2017-10-06 13:34:07 -0500 | [diff] [blame] | 27 | using VersionClass = phosphor::software::manager::Version; |
Gunnar Mills | ded875d | 2017-08-28 16:44:52 -0500 | [diff] [blame] | 28 | using AssociationList = |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 29 | std::vector<std::tuple<std::string, std::string, std::string>>; |
Gunnar Mills | ded875d | 2017-08-28 16:44:52 -0500 | [diff] [blame] | 30 | |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 31 | /** @class ItemUpdater |
| 32 | * @brief Manages the activation of the BMC version items. |
| 33 | */ |
Michael Tritz | 37a5904 | 2017-07-12 13:44:53 -0500 | [diff] [blame] | 34 | class ItemUpdater : public ItemUpdaterInherit |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 35 | { |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 36 | public: |
| 37 | /* |
| 38 | * @brief Types of Activation status for image validation. |
| 39 | */ |
| 40 | enum class ActivationStatus |
| 41 | { |
| 42 | ready, |
| 43 | invalid, |
| 44 | active |
| 45 | }; |
Saqib Khan | 35e83f3 | 2017-05-22 11:37:32 -0500 | [diff] [blame] | 46 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 47 | /** @brief Constructs ItemUpdater |
| 48 | * |
| 49 | * @param[in] bus - The D-Bus bus object |
| 50 | */ |
| 51 | ItemUpdater(sdbusplus::bus::bus& bus, const std::string& path) : |
Lei YU | 56aaf45 | 2018-06-21 16:09:44 +0800 | [diff] [blame] | 52 | ItemUpdaterInherit(bus, path.c_str(), false), bus(bus), helper(bus), |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 53 | versionMatch(bus, |
| 54 | MatchRules::interfacesAdded() + |
| 55 | MatchRules::path("/xyz/openbmc_project/software"), |
| 56 | std::bind(std::mem_fn(&ItemUpdater::createActivation), |
| 57 | this, std::placeholders::_1)) |
| 58 | { |
| 59 | setBMCInventoryPath(); |
| 60 | processBMCImage(); |
| 61 | restoreFieldModeStatus(); |
| 62 | emit_object_added(); |
| 63 | }; |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 64 | |
Adriana Kobylak | bbcb7be | 2018-07-17 15:47:34 -0500 | [diff] [blame] | 65 | /** @brief Save priority value to persistent storage (flash and optionally |
| 66 | * a U-Boot environment variable) |
| 67 | * |
| 68 | * @param[in] versionId - The Id of the version |
| 69 | * @param[in] value - The priority value |
| 70 | * @return None |
| 71 | */ |
| 72 | void savePriority(const std::string& versionId, uint8_t value); |
| 73 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 74 | /** @brief Sets the given priority free by incrementing |
| 75 | * any existing priority with the same value by 1 |
| 76 | * |
| 77 | * @param[in] value - The priority that needs to be set free. |
| 78 | * @param[in] versionId - The Id of the version for which we |
| 79 | * are trying to free up the priority. |
| 80 | * @return None |
| 81 | */ |
| 82 | void freePriority(uint8_t value, const std::string& versionId); |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 83 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 84 | /** |
| 85 | * @brief Create and populate the active BMC Version. |
| 86 | */ |
| 87 | void processBMCImage(); |
Saqib Khan | ba23988 | 2017-05-26 08:41:54 -0500 | [diff] [blame] | 88 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 89 | /** |
| 90 | * @brief Erase specified entry D-Bus object |
| 91 | * if Action property is not set to Active |
| 92 | * |
| 93 | * @param[in] entryId - unique identifier of the entry |
| 94 | */ |
| 95 | void erase(std::string entryId); |
Leonel Gonzalez | 3526ef7 | 2017-07-07 14:38:25 -0500 | [diff] [blame] | 96 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 97 | /** |
| 98 | * @brief Deletes all versions except for the current one |
| 99 | */ |
| 100 | void deleteAll(); |
Gunnar Mills | ded875d | 2017-08-28 16:44:52 -0500 | [diff] [blame] | 101 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 102 | /** @brief Creates an active association to the |
| 103 | * newly active software image |
| 104 | * |
| 105 | * @param[in] path - The path to create the association to. |
| 106 | */ |
| 107 | void createActiveAssociation(const std::string& path); |
Gunnar Mills | ded875d | 2017-08-28 16:44:52 -0500 | [diff] [blame] | 108 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 109 | /** @brief Removes an active association to the software image |
| 110 | * |
| 111 | * @param[in] path - The path to remove the association from. |
| 112 | */ |
| 113 | void removeActiveAssociation(const std::string& path); |
Gunnar Mills | ded875d | 2017-08-28 16:44:52 -0500 | [diff] [blame] | 114 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 115 | /** @brief Determine if the given priority is the lowest |
| 116 | * |
| 117 | * @param[in] value - The priority that needs to be checked. |
| 118 | * |
| 119 | * @return boolean corresponding to whether the given |
| 120 | * priority is lowest. |
| 121 | */ |
| 122 | bool isLowestPriority(uint8_t value); |
Saqib Khan | b9da663 | 2017-09-13 09:48:37 -0500 | [diff] [blame] | 123 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 124 | /** |
| 125 | * @brief Updates the U-Boot variables to point to the requested |
| 126 | * versionId, so that the systems boots from this version on |
| 127 | * the next reboot. |
| 128 | * |
| 129 | * @param[in] versionId - The version to point the system to boot from. |
| 130 | */ |
| 131 | void updateUbootEnvVars(const std::string& versionId); |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 132 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 133 | /** |
| 134 | * @brief Updates the uboot variables to point to BMC version with lowest |
| 135 | * priority, so that the system boots from this version on the |
| 136 | * next boot. |
| 137 | */ |
| 138 | void resetUbootEnvVars(); |
Saqib Khan | 49446ae | 2017-10-02 10:54:20 -0500 | [diff] [blame] | 139 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 140 | /** @brief Brings the total number of active BMC versions to |
| 141 | * ACTIVE_BMC_MAX_ALLOWED -1. This function is intended to be |
| 142 | * run before activating a new BMC version. If this function |
| 143 | * needs to delete any BMC version(s) it will delete the |
| 144 | * version(s) with the highest priority, skipping the |
| 145 | * functional BMC version. |
| 146 | */ |
| 147 | void freeSpace(); |
Adriana Kobylak | 204e1e7 | 2018-01-24 16:00:05 -0600 | [diff] [blame] | 148 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 149 | private: |
| 150 | /** @brief Callback function for Software.Version match. |
| 151 | * @details Creates an Activation D-Bus object. |
| 152 | * |
| 153 | * @param[in] msg - Data associated with subscribed signal |
| 154 | */ |
| 155 | void createActivation(sdbusplus::message::message& msg); |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 156 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 157 | /** |
| 158 | * @brief Validates the presence of SquashFS image in the image dir. |
| 159 | * |
| 160 | * @param[in] filePath - The path to the image dir. |
| 161 | * @param[out] result - ActivationStatus Enum. |
| 162 | * ready if validation was successful. |
| 163 | * invalid if validation fail. |
| 164 | * active if image is the current version. |
| 165 | * |
| 166 | */ |
| 167 | ActivationStatus validateSquashFSImage(const std::string& filePath); |
Saqib Khan | 35e83f3 | 2017-05-22 11:37:32 -0500 | [diff] [blame] | 168 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 169 | /** @brief BMC factory reset - marks the read-write partition for |
| 170 | * recreation upon reboot. */ |
| 171 | void reset() override; |
Michael Tritz | 37a5904 | 2017-07-12 13:44:53 -0500 | [diff] [blame] | 172 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 173 | /** |
| 174 | * @brief Enables field mode, if value=true. |
| 175 | * |
| 176 | * @param[in] value - If true, enables field mode. |
| 177 | * @param[out] result - Returns the current state of field mode. |
| 178 | * |
| 179 | */ |
| 180 | bool fieldModeEnabled(bool value) override; |
Michael Tritz | 0129d92 | 2017-08-10 19:33:46 -0500 | [diff] [blame] | 181 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 182 | /** @brief Sets the BMC inventory item path under |
| 183 | * /xyz/openbmc_project/inventory/system/chassis/. */ |
| 184 | void setBMCInventoryPath(); |
Gunnar Mills | b60add1 | 2017-08-24 16:41:42 -0500 | [diff] [blame] | 185 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 186 | /** @brief The path to the BMC inventory item. */ |
| 187 | std::string bmcInventoryPath; |
Gunnar Mills | b60add1 | 2017-08-24 16:41:42 -0500 | [diff] [blame] | 188 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 189 | /** @brief Restores field mode status on reboot. */ |
| 190 | void restoreFieldModeStatus(); |
Michael Tritz | 0129d92 | 2017-08-10 19:33:46 -0500 | [diff] [blame] | 191 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 192 | /** @brief Creates a functional association to the |
| 193 | * "running" BMC software image |
| 194 | * |
| 195 | * @param[in] path - The path to create the association to. |
| 196 | */ |
| 197 | void createFunctionalAssociation(const std::string& path); |
Gunnar Mills | 88e8a32 | 2017-09-13 11:09:28 -0500 | [diff] [blame] | 198 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 199 | /** @brief Persistent sdbusplus D-Bus bus connection. */ |
| 200 | sdbusplus::bus::bus& bus; |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 201 | |
Lei YU | 56aaf45 | 2018-06-21 16:09:44 +0800 | [diff] [blame] | 202 | /** @brief The helper of image updater. */ |
| 203 | Helper helper; |
| 204 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 205 | /** @brief Persistent map of Activation D-Bus objects and their |
| 206 | * version id */ |
| 207 | std::map<std::string, std::unique_ptr<Activation>> activations; |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 208 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 209 | /** @brief Persistent map of Version D-Bus objects and their |
| 210 | * version id */ |
| 211 | std::map<std::string, std::unique_ptr<VersionClass>> versions; |
Saqib Khan | 705f1bf | 2017-06-09 23:58:38 -0500 | [diff] [blame] | 212 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 213 | /** @brief sdbusplus signal match for Software.Version */ |
| 214 | sdbusplus::bus::match_t versionMatch; |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 215 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 216 | /** @brief This entry's associations */ |
| 217 | AssociationList assocs = {}; |
Gunnar Mills | ded875d | 2017-08-28 16:44:52 -0500 | [diff] [blame] | 218 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 219 | /** @brief Clears read only partition for |
| 220 | * given Activation D-Bus object. |
| 221 | * |
| 222 | * @param[in] versionId - The version id. |
| 223 | */ |
| 224 | void removeReadOnlyPartition(std::string versionId); |
Eddie James | eaa1ee0 | 2018-03-01 10:09:10 -0600 | [diff] [blame] | 225 | |
| 226 | /** @brief Copies U-Boot from the currently booted BMC chip to the |
| 227 | * alternate chip. |
| 228 | */ |
| 229 | void mirrorUbootToAlt(); |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 230 | }; |
| 231 | |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 232 | } // namespace updater |
| 233 | } // namespace software |
| 234 | } // namespace phosphor |