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