Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "common/utils.hpp" |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 4 | #include "libpldmresponder/pdr_utils.hpp" |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 5 | #include "libpldmresponder/platform.hpp" |
| 6 | |
| 7 | #include <string> |
| 8 | |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 9 | namespace pldm |
| 10 | { |
| 11 | namespace responder |
| 12 | { |
| 13 | |
| 14 | static constexpr uint8_t pSideNum = 1; |
| 15 | static constexpr uint8_t tSideNum = 2; |
| 16 | static constexpr auto Pside = "P"; |
| 17 | static constexpr auto Tside = "T"; |
| 18 | |
| 19 | static constexpr auto redundancyIntf = |
| 20 | "xyz.openbmc_project.Software.RedundancyPriority"; |
| 21 | |
Archana Kakani | e26d13f | 2025-03-09 23:17:46 -0500 | [diff] [blame^] | 22 | /** |
| 23 | * @struct pldm_boot_side_data |
| 24 | * @brief Holds PLDM current/next boot side and the boot side which has the |
| 25 | * active image. |
| 26 | * |
| 27 | * This structure stores the current and next boot side identifiers, |
| 28 | * as well as the running version information. |
| 29 | * The running version value is an alias to the currently active boot side. |
| 30 | * It contains either 'a' or 'b', mapping to the two available boot sides |
| 31 | * based on which side is active. |
| 32 | */ |
| 33 | struct pldm_boot_side_data |
| 34 | { |
| 35 | std::string current_boot_side; |
| 36 | std::string next_boot_side; |
| 37 | std::string running_version_object; |
| 38 | }; |
| 39 | |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 40 | /** @class CodeUpdate |
| 41 | * |
| 42 | * @brief This class performs the necessary operation in pldm for |
| 43 | * inband code update. That includes taking actions on the |
| 44 | * setStateEffecterStates calls from Host and also sending |
| 45 | * notification to phosphor-software-manager app |
| 46 | */ |
| 47 | class CodeUpdate |
| 48 | { |
| 49 | public: |
| 50 | /** @brief Constructor to create an inband codeupdate object |
| 51 | * @param[in] dBusIntf - D-Bus handler pointer |
| 52 | */ |
| 53 | CodeUpdate(const pldm::utils::DBusHandler* dBusIntf) : dBusIntf(dBusIntf) |
| 54 | { |
| 55 | currBootSide = Tside; |
| 56 | nextBootSide = Tside; |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 57 | markerLidSensorId = PLDM_INVALID_EFFECTER_ID; |
| 58 | firmwareUpdateSensorId = PLDM_INVALID_EFFECTER_ID; |
Sagar Srinivas | 9a64b4a | 2021-02-09 07:55:38 -0600 | [diff] [blame] | 59 | imageActivationMatch = nullptr; |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | /* @brief Method to return the current boot side |
| 63 | */ |
| 64 | std::string fetchCurrentBootSide(); |
| 65 | |
| 66 | /* @brief Method to return the next boot side |
| 67 | */ |
| 68 | std::string fetchNextBootSide(); |
| 69 | |
| 70 | /* @brief Method to set the current boot side or |
| 71 | * perform a rename operation on current boot side |
| 72 | * @param[in] currSide - current side to be set to |
| 73 | * @return PLDM_SUCCESS codes |
| 74 | */ |
| 75 | int setCurrentBootSide(const std::string& currSide); |
| 76 | |
| 77 | /* @brief Method to set the next boot side |
| 78 | * @param[in] nextSide - next boot side to be set to |
| 79 | * @return PLDM_SUCCESS codes |
| 80 | */ |
| 81 | int setNextBootSide(const std::string& nextSide); |
| 82 | |
| 83 | /* @brief Method to set the running and non-running |
| 84 | * images |
| 85 | */ |
| 86 | virtual void setVersions(); |
| 87 | |
| 88 | /* @brief Method to return the newly upoaded image id in |
| 89 | * /tmp |
| 90 | */ |
| 91 | std::string fetchnewImageId() |
| 92 | { |
| 93 | return newImageId; |
| 94 | } |
| 95 | |
| 96 | /* @brief Method to set the oem platform handler in CodeUpdate class */ |
| 97 | void setOemPlatformHandler(pldm::responder::oem_platform::Handler* handler); |
| 98 | |
Sampa Misra | 6950850 | 2020-09-08 00:08:21 -0500 | [diff] [blame] | 99 | /* @brief Method to check whether code update is |
| 100 | * going on |
| 101 | * @return - bool |
| 102 | */ |
| 103 | bool isCodeUpdateInProgress() |
| 104 | { |
| 105 | return codeUpdateInProgress; |
| 106 | } |
| 107 | |
| 108 | /* @brief Method to indicate whether code update |
| 109 | * is going on |
| 110 | * @param[in] progress - yes/no |
| 111 | */ |
| 112 | void setCodeUpdateProgress(bool progress) |
| 113 | { |
| 114 | codeUpdateInProgress = progress; |
| 115 | } |
| 116 | |
Varsha Kaverappa | 3ca29df | 2020-09-27 12:39:22 -0500 | [diff] [blame] | 117 | /** @brief Method to clear contents the LID staging directory that contains |
| 118 | * images such as host firmware and BMC. |
| 119 | * @param[in] dirPath - directory system path that has to be cleared |
| 120 | * @return none |
| 121 | */ |
| 122 | void clearDirPath(const std::string& dirPath); |
| 123 | |
Sagar Srinivas | cfdbca7 | 2020-09-22 10:03:35 -0500 | [diff] [blame] | 124 | /* @brief Method to set the RequestApplyTime D-Bus property |
| 125 | * on start update to OnReset |
| 126 | * @return - Completion codes |
| 127 | */ |
| 128 | int setRequestedApplyTime(); |
| 129 | |
| 130 | /* @brief Method to set the RequestedActivation D-Bus property |
| 131 | * on end update to Active by fetching the newImageID and |
| 132 | * clearning it once RequestedActivation is set or on error |
| 133 | * @param[in] codeUpdate - codeUpdate pointer |
| 134 | * @return - Completion codes |
| 135 | */ |
| 136 | int setRequestedActivation(); |
| 137 | |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 138 | /* @brief Method to fetch the sensor id for marker lid |
| 139 | * validation PDR |
| 140 | * @return - sensor id |
| 141 | */ |
| 142 | uint16_t getMarkerLidSensor() |
| 143 | { |
| 144 | return markerLidSensorId; |
| 145 | } |
| 146 | |
| 147 | /* @brief Method to set the sensor id for marker lid |
| 148 | * validation |
| 149 | * @param[in] sensorId - sensor id for marker lid validation |
| 150 | */ |
| 151 | void setMarkerLidSensor(uint16_t sensorId) |
| 152 | { |
| 153 | markerLidSensorId = sensorId; |
| 154 | } |
| 155 | |
| 156 | /* @brief Method to set the sensor id for firmware update state |
| 157 | * @param[in] sensorId - sensor id for firmware update state |
| 158 | */ |
| 159 | void setFirmwareUpdateSensor(uint16_t sensorId) |
| 160 | { |
| 161 | firmwareUpdateSensorId = sensorId; |
| 162 | } |
| 163 | |
| 164 | /* @brief Method to fetch the sensor id for firmware update state |
| 165 | * @return - sensor id |
| 166 | */ |
| 167 | uint16_t getFirmwareUpdateSensor() |
| 168 | { |
| 169 | return firmwareUpdateSensorId; |
| 170 | } |
| 171 | |
Archana Kakani | c23b614 | 2025-02-19 04:04:20 -0600 | [diff] [blame] | 172 | /* @brief Method to set the sensor id for boot side rename state |
| 173 | * @param[in] sensorId - sensor id for boot side rename update |
| 174 | * state |
| 175 | */ |
| 176 | void setBootSideRenameStateSensor(uint16_t sensorId) |
| 177 | { |
| 178 | bootSideRenameStateSensorId = sensorId; |
| 179 | } |
| 180 | |
| 181 | /* @brief Method to fetch the sensor id for boot side rename state |
| 182 | * @return - sensor id |
| 183 | */ |
| 184 | uint16_t getBootSideRenameStateSensor() |
| 185 | { |
| 186 | return bootSideRenameStateSensorId; |
| 187 | } |
| 188 | |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 189 | /* @brief Method to send a state sensor event to Host from CodeUpdate class |
| 190 | * @param[in] sensorId - sensor id for the event |
| 191 | * @param[in] sensorEventClass - sensor event class wrt DSP0248 |
| 192 | * @param[in] sensorOffset - sensor offset |
| 193 | * @param[in] eventState - new event state |
| 194 | * @param[in] prevEventState - previous state |
| 195 | */ |
| 196 | void sendStateSensorEvent(uint16_t sensorId, |
| 197 | enum sensor_event_class_states sensorEventClass, |
| 198 | uint8_t sensorOffset, uint8_t eventState, |
| 199 | uint8_t prevEventState); |
| 200 | |
| 201 | /* @brief Method to delete the image from non running side prior to |
| 202 | * an inband code update |
| 203 | */ |
| 204 | void deleteImage(); |
| 205 | |
Adriana Kobylak | 9296f24 | 2021-09-22 15:52:00 +0000 | [diff] [blame] | 206 | /** @brief Method to assemble the code update tarball and trigger the |
| 207 | * phosphor software manager to create a version interface |
| 208 | * @return - PLDM_SUCCESS codes |
| 209 | */ |
| 210 | int assembleCodeUpdateImage(); |
| 211 | |
Archana Kakani | c23b614 | 2025-02-19 04:04:20 -0600 | [diff] [blame] | 212 | /* @brief Method to process the bootside rename event, sends a boot side |
| 213 | * rename event notification to host when code update is initiated*/ |
| 214 | void processRenameEvent(); |
| 215 | |
Archana Kakani | e26d13f | 2025-03-09 23:17:46 -0500 | [diff] [blame^] | 216 | /* @brief Method to write the bootside information into mapping |
| 217 | * file which would be stored on bmc |
| 218 | * @param[in] pldmBootSideData - bootside information such as |
| 219 | * current boot side and running version |
| 220 | */ |
| 221 | void writeBootSideFile(const pldm_boot_side_data& pldmBootSideData); |
| 222 | |
| 223 | /* @brief Method to read the mapping file containing bootside |
| 224 | * which is stored on bmc and stores that information |
| 225 | * in a structure |
| 226 | * @return pldm_boot_side_data - the structure which holds information |
| 227 | * regarding bootside information */ |
| 228 | pldm_boot_side_data readBootSideFile(); |
| 229 | |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 230 | virtual ~CodeUpdate() {} |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 231 | |
| 232 | private: |
| 233 | std::string currBootSide; //!< current boot side |
| 234 | std::string nextBootSide; //!< next boot side |
| 235 | std::string runningVersion; //!< currently running image |
| 236 | std::string nonRunningVersion; //!< alternate image |
| 237 | std::string newImageId; //!< new image id |
| 238 | bool codeUpdateInProgress = |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 239 | false; //!< indicates whether codeupdate is going on |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 240 | const pldm::utils::DBusHandler* dBusIntf; //!< D-Bus handler |
Patrick Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 241 | std::vector<std::unique_ptr<sdbusplus::bus::match_t>> |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 242 | captureNextBootSideChange; //!< vector to catch the D-Bus property |
| 243 | //!< change for next boot side |
Patrick Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 244 | std::vector<std::unique_ptr<sdbusplus::bus::match_t>> |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 245 | fwUpdateMatcher; //!< pointer to capture the interface added signal for |
| 246 | //!< new image |
| 247 | pldm::responder::oem_platform::Handler* |
| 248 | oemPlatformHandler; //!< oem platform handler |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 249 | uint16_t markerLidSensorId; |
| 250 | uint16_t firmwareUpdateSensorId; |
Archana Kakani | c23b614 | 2025-02-19 04:04:20 -0600 | [diff] [blame] | 251 | uint16_t bootSideRenameStateSensorId; |
Sagar Srinivas | 9a64b4a | 2021-02-09 07:55:38 -0600 | [diff] [blame] | 252 | /** @brief D-Bus property changed signal match for image activation */ |
Patrick Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 253 | std::unique_ptr<sdbusplus::bus::match_t> imageActivationMatch; |
Sagar Srinivas | 9a64b4a | 2021-02-09 07:55:38 -0600 | [diff] [blame] | 254 | |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 255 | /* @brief Method to take action when the subscribed D-Bus property is |
| 256 | * changed |
| 257 | * @param[in] chProperties - list of properties which have changed |
| 258 | * @return - none |
| 259 | */ |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 260 | void processPriorityChangeNotification( |
| 261 | const pldm::utils::DbusChangedProps& chProperties); |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 262 | }; |
| 263 | |
| 264 | /* @brief Method to fetch current or next boot side |
| 265 | * @param[in] entityInstance - entity instance for the sensor |
| 266 | * @param[in] codeUpdate - pointer to the CodeUpdate object |
| 267 | * |
| 268 | * @return - boot side |
| 269 | */ |
| 270 | uint8_t fetchBootSide(uint16_t entityInstance, CodeUpdate* codeUpdate); |
| 271 | |
| 272 | /* @brief Method to set current or next boot side |
| 273 | * @param[in] entityInstance - entity instance for the effecter |
| 274 | * @param[in] currState - state to be set |
| 275 | * @param[in] stateField - state field set as sent by Host |
| 276 | * @return - PLDM_SUCCESS codes |
| 277 | */ |
| 278 | int setBootSide(uint16_t entityInstance, uint8_t currState, |
| 279 | const std::vector<set_effecter_state_field>& stateField, |
| 280 | CodeUpdate* codeUpdate); |
| 281 | |
Adriana Kobylak | 727f738 | 2020-09-01 14:38:25 -0500 | [diff] [blame] | 282 | /* @brief Method to process LIDs during inband update, such as verifying and |
| 283 | * removing the header to get them ready to be written to flash |
| 284 | * @param[in] filePath - Path to the LID file |
| 285 | * @return - PLDM_SUCCESS codes |
| 286 | */ |
| 287 | int processCodeUpdateLid(const std::string& filePath); |
Adriana Kobylak | 837fb47 | 2020-10-16 16:53:42 -0500 | [diff] [blame] | 288 | |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 289 | } // namespace responder |
| 290 | } // namespace pldm |