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