Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 1 | #include "device_updater.hpp" |
| 2 | |
Tom Joseph | 4d8d577 | 2021-08-17 07:35:05 -0700 | [diff] [blame] | 3 | #include "activation.hpp" |
| 4 | #include "update_manager.hpp" |
| 5 | |
George Liu | c453e16 | 2022-12-21 17:16:23 +0800 | [diff] [blame] | 6 | #include <libpldm/firmware_update.h> |
| 7 | |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 8 | #include <phosphor-logging/lg2.hpp> |
| 9 | |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 10 | #include <functional> |
| 11 | |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 12 | PHOSPHOR_LOG2_USING; |
| 13 | |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 14 | namespace pldm |
| 15 | { |
| 16 | |
| 17 | namespace fw_update |
| 18 | { |
| 19 | |
| 20 | void DeviceUpdater::startFwUpdateFlow() |
| 21 | { |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 22 | auto instanceId = updateManager->instanceIdDb.next(eid); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 23 | // NumberOfComponents |
| 24 | const auto& applicableComponents = |
| 25 | std::get<ApplicableComponents>(fwDeviceIDRecord); |
| 26 | // PackageDataLength |
| 27 | const auto& fwDevicePkgData = |
| 28 | std::get<FirmwareDevicePackageData>(fwDeviceIDRecord); |
| 29 | // ComponentImageSetVersionString |
| 30 | const auto& compImageSetVersion = |
| 31 | std::get<ComponentImageSetVersion>(fwDeviceIDRecord); |
| 32 | variable_field compImgSetVerStrInfo{}; |
| 33 | compImgSetVerStrInfo.ptr = |
| 34 | reinterpret_cast<const uint8_t*>(compImageSetVersion.data()); |
| 35 | compImgSetVerStrInfo.length = |
| 36 | static_cast<uint8_t>(compImageSetVersion.size()); |
| 37 | |
Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 38 | Request request( |
| 39 | sizeof(pldm_msg_hdr) + sizeof(struct pldm_request_update_req) + |
| 40 | compImgSetVerStrInfo.length); |
Pavithra Barithaya | 1039a8a | 2025-01-31 11:30:14 +0530 | [diff] [blame] | 41 | auto requestMsg = new (request.data()) pldm_msg; |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 42 | |
| 43 | auto rc = encode_request_update_req( |
| 44 | instanceId, maxTransferSize, applicableComponents.size(), |
| 45 | PLDM_FWUP_MIN_OUTSTANDING_REQ, fwDevicePkgData.size(), |
| 46 | PLDM_STR_TYPE_ASCII, compImgSetVerStrInfo.length, &compImgSetVerStrInfo, |
| 47 | requestMsg, |
| 48 | sizeof(struct pldm_request_update_req) + compImgSetVerStrInfo.length); |
| 49 | if (rc) |
| 50 | { |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 51 | // Handle error scenario |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 52 | updateManager->instanceIdDb.free(eid, instanceId); |
| 53 | error( |
| 54 | "Failed to encode request update request for endpoint ID '{EID}', response code '{RC}'", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 55 | "EID", eid, "RC", rc); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 56 | } |
| 57 | |
Tom Joseph | b7e083e | 2021-10-26 15:10:03 +0530 | [diff] [blame] | 58 | rc = updateManager->handler.registerRequest( |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 59 | eid, instanceId, PLDM_FWUP, PLDM_REQUEST_UPDATE, std::move(request), |
Eric Yang | 70eca96 | 2025-05-11 01:48:15 +0800 | [diff] [blame] | 60 | [this](mctp_eid_t eid, const pldm_msg* response, size_t respMsgLen) { |
| 61 | this->requestUpdate(eid, response, respMsgLen); |
| 62 | }); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 63 | if (rc) |
| 64 | { |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 65 | // Handle error scenario |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 66 | error( |
| 67 | "Failed to send request update for endpoint ID '{EID}', response code '{RC}'", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 68 | "EID", eid, "RC", rc); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 69 | } |
| 70 | } |
| 71 | |
| 72 | void DeviceUpdater::requestUpdate(mctp_eid_t eid, const pldm_msg* response, |
| 73 | size_t respMsgLen) |
| 74 | { |
| 75 | if (response == nullptr || !respMsgLen) |
| 76 | { |
| 77 | // Handle error scenario |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 78 | error("No response received for request update for endpoint ID '{EID}'", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 79 | "EID", eid); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 80 | return; |
| 81 | } |
| 82 | |
| 83 | uint8_t completionCode = 0; |
| 84 | uint16_t fdMetaDataLen = 0; |
| 85 | uint8_t fdWillSendPkgData = 0; |
| 86 | |
| 87 | auto rc = decode_request_update_resp(response, respMsgLen, &completionCode, |
| 88 | &fdMetaDataLen, &fdWillSendPkgData); |
| 89 | if (rc) |
| 90 | { |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 91 | error( |
| 92 | "Failed to decode request update response for endpoint ID '{EID}', response code '{RC}'", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 93 | "EID", eid, "RC", rc); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 94 | return; |
| 95 | } |
| 96 | if (completionCode) |
| 97 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 98 | error( |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 99 | "Failure in request update response for endpoint ID '{EID}', completion code '{CC}'", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 100 | "EID", eid, "CC", completionCode); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 101 | return; |
| 102 | } |
| 103 | |
| 104 | // Optional fields DeviceMetaData and GetPackageData not handled |
| 105 | pldmRequest = std::make_unique<sdeventplus::source::Defer>( |
Tom Joseph | b7e083e | 2021-10-26 15:10:03 +0530 | [diff] [blame] | 106 | updateManager->event, |
| 107 | std::bind(&DeviceUpdater::sendPassCompTableRequest, this, |
| 108 | componentIndex)); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | void DeviceUpdater::sendPassCompTableRequest(size_t offset) |
| 112 | { |
| 113 | pldmRequest.reset(); |
| 114 | |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 115 | auto instanceId = updateManager->instanceIdDb.next(eid); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 116 | // TransferFlag |
| 117 | const auto& applicableComponents = |
| 118 | std::get<ApplicableComponents>(fwDeviceIDRecord); |
| 119 | uint8_t transferFlag = 0; |
| 120 | if (applicableComponents.size() == 1) |
| 121 | { |
| 122 | transferFlag = PLDM_START_AND_END; |
| 123 | } |
| 124 | else if (offset == 0) |
| 125 | { |
| 126 | transferFlag = PLDM_START; |
| 127 | } |
| 128 | else if (offset == applicableComponents.size() - 1) |
| 129 | { |
| 130 | transferFlag = PLDM_END; |
| 131 | } |
| 132 | else |
| 133 | { |
| 134 | transferFlag = PLDM_MIDDLE; |
| 135 | } |
| 136 | const auto& comp = compImageInfos[applicableComponents[offset]]; |
| 137 | // ComponentClassification |
| 138 | CompClassification compClassification = std::get<static_cast<size_t>( |
| 139 | ComponentImageInfoPos::CompClassificationPos)>(comp); |
| 140 | // ComponentIdentifier |
| 141 | CompIdentifier compIdentifier = |
| 142 | std::get<static_cast<size_t>(ComponentImageInfoPos::CompIdentifierPos)>( |
| 143 | comp); |
| 144 | // ComponentClassificationIndex |
| 145 | CompClassificationIndex compClassificationIndex{}; |
| 146 | auto compKey = std::make_pair(compClassification, compIdentifier); |
| 147 | if (compInfo.contains(compKey)) |
| 148 | { |
| 149 | auto search = compInfo.find(compKey); |
| 150 | compClassificationIndex = search->second; |
| 151 | } |
| 152 | else |
| 153 | { |
| 154 | // Handle error scenario |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 155 | error( |
| 156 | "Failed to find component classification '{CLASSIFICATION}' and identifier '{IDENTIFIER}'", |
| 157 | "CLASSIFICATION", compClassification, "IDENTIFIER", compIdentifier); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 158 | } |
| 159 | // ComponentComparisonStamp |
| 160 | CompComparisonStamp compComparisonStamp = std::get<static_cast<size_t>( |
| 161 | ComponentImageInfoPos::CompComparisonStampPos)>(comp); |
| 162 | // ComponentVersionString |
| 163 | const auto& compVersion = |
| 164 | std::get<static_cast<size_t>(ComponentImageInfoPos::CompVersionPos)>( |
| 165 | comp); |
| 166 | variable_field compVerStrInfo{}; |
| 167 | compVerStrInfo.ptr = reinterpret_cast<const uint8_t*>(compVersion.data()); |
| 168 | compVerStrInfo.length = static_cast<uint8_t>(compVersion.size()); |
| 169 | |
Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 170 | Request request( |
| 171 | sizeof(pldm_msg_hdr) + sizeof(struct pldm_pass_component_table_req) + |
| 172 | compVerStrInfo.length); |
Pavithra Barithaya | 1039a8a | 2025-01-31 11:30:14 +0530 | [diff] [blame] | 173 | auto requestMsg = new (request.data()) pldm_msg; |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 174 | auto rc = encode_pass_component_table_req( |
| 175 | instanceId, transferFlag, compClassification, compIdentifier, |
| 176 | compClassificationIndex, compComparisonStamp, PLDM_STR_TYPE_ASCII, |
| 177 | compVerStrInfo.length, &compVerStrInfo, requestMsg, |
| 178 | sizeof(pldm_pass_component_table_req) + compVerStrInfo.length); |
| 179 | if (rc) |
| 180 | { |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 181 | // Handle error scenario |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 182 | updateManager->instanceIdDb.free(eid, instanceId); |
| 183 | error( |
| 184 | "Failed to encode pass component table req for endpoint ID '{EID}', response code '{RC}'", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 185 | "EID", eid, "RC", rc); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 186 | } |
| 187 | |
Tom Joseph | b7e083e | 2021-10-26 15:10:03 +0530 | [diff] [blame] | 188 | rc = updateManager->handler.registerRequest( |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 189 | eid, instanceId, PLDM_FWUP, PLDM_PASS_COMPONENT_TABLE, |
| 190 | std::move(request), |
Eric Yang | 70eca96 | 2025-05-11 01:48:15 +0800 | [diff] [blame] | 191 | [this](mctp_eid_t eid, const pldm_msg* response, size_t respMsgLen) { |
| 192 | this->passCompTable(eid, response, respMsgLen); |
| 193 | }); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 194 | if (rc) |
| 195 | { |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 196 | // Handle error scenario |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 197 | error( |
| 198 | "Failed to send pass component table request for endpoint ID '{EID}', response code '{RC}'", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 199 | "EID", eid, "RC", rc); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 200 | } |
| 201 | } |
| 202 | |
| 203 | void DeviceUpdater::passCompTable(mctp_eid_t eid, const pldm_msg* response, |
| 204 | size_t respMsgLen) |
| 205 | { |
| 206 | if (response == nullptr || !respMsgLen) |
| 207 | { |
| 208 | // Handle error scenario |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 209 | error( |
| 210 | "No response received for pass component table for endpoint ID '{EID}'", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 211 | "EID", eid); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 212 | return; |
| 213 | } |
| 214 | |
| 215 | uint8_t completionCode = 0; |
| 216 | uint8_t compResponse = 0; |
| 217 | uint8_t compResponseCode = 0; |
| 218 | |
Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 219 | auto rc = |
| 220 | decode_pass_component_table_resp(response, respMsgLen, &completionCode, |
| 221 | &compResponse, &compResponseCode); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 222 | if (rc) |
| 223 | { |
| 224 | // Handle error scenario |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 225 | error( |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 226 | "Failed to decode pass component table response for endpoint ID '{EID}', response code '{RC}'", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 227 | "EID", eid, "RC", rc); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 228 | return; |
| 229 | } |
| 230 | if (completionCode) |
| 231 | { |
| 232 | // Handle error scenario |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 233 | error( |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 234 | "Failed to pass component table response for endpoint ID '{EID}', completion code '{CC}'", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 235 | "EID", eid, "CC", completionCode); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 236 | return; |
| 237 | } |
| 238 | // Handle ComponentResponseCode |
| 239 | |
| 240 | const auto& applicableComponents = |
| 241 | std::get<ApplicableComponents>(fwDeviceIDRecord); |
| 242 | if (componentIndex == applicableComponents.size() - 1) |
| 243 | { |
| 244 | componentIndex = 0; |
| 245 | pldmRequest = std::make_unique<sdeventplus::source::Defer>( |
Tom Joseph | b7e083e | 2021-10-26 15:10:03 +0530 | [diff] [blame] | 246 | updateManager->event, |
| 247 | std::bind(&DeviceUpdater::sendUpdateComponentRequest, this, |
| 248 | componentIndex)); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 249 | } |
| 250 | else |
| 251 | { |
| 252 | componentIndex++; |
| 253 | pldmRequest = std::make_unique<sdeventplus::source::Defer>( |
Tom Joseph | b7e083e | 2021-10-26 15:10:03 +0530 | [diff] [blame] | 254 | updateManager->event, |
| 255 | std::bind(&DeviceUpdater::sendPassCompTableRequest, this, |
| 256 | componentIndex)); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 257 | } |
| 258 | } |
| 259 | |
| 260 | void DeviceUpdater::sendUpdateComponentRequest(size_t offset) |
| 261 | { |
| 262 | pldmRequest.reset(); |
| 263 | |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 264 | auto instanceId = updateManager->instanceIdDb.next(eid); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 265 | const auto& applicableComponents = |
| 266 | std::get<ApplicableComponents>(fwDeviceIDRecord); |
| 267 | const auto& comp = compImageInfos[applicableComponents[offset]]; |
| 268 | // ComponentClassification |
| 269 | CompClassification compClassification = std::get<static_cast<size_t>( |
| 270 | ComponentImageInfoPos::CompClassificationPos)>(comp); |
| 271 | // ComponentIdentifier |
| 272 | CompIdentifier compIdentifier = |
| 273 | std::get<static_cast<size_t>(ComponentImageInfoPos::CompIdentifierPos)>( |
| 274 | comp); |
| 275 | // ComponentClassificationIndex |
| 276 | CompClassificationIndex compClassificationIndex{}; |
| 277 | auto compKey = std::make_pair(compClassification, compIdentifier); |
| 278 | if (compInfo.contains(compKey)) |
| 279 | { |
| 280 | auto search = compInfo.find(compKey); |
| 281 | compClassificationIndex = search->second; |
| 282 | } |
| 283 | else |
| 284 | { |
| 285 | // Handle error scenario |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 286 | error( |
| 287 | "Failed to find component classification '{CLASSIFICATION}' and identifier '{IDENTIFIER}'", |
| 288 | "CLASSIFICATION", compClassification, "IDENTIFIER", compIdentifier); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | // UpdateOptionFlags |
| 292 | bitfield32_t updateOptionFlags; |
| 293 | updateOptionFlags.bits.bit0 = std::get<3>(comp)[0]; |
| 294 | // ComponentVersion |
| 295 | const auto& compVersion = std::get<7>(comp); |
| 296 | variable_field compVerStrInfo{}; |
| 297 | compVerStrInfo.ptr = reinterpret_cast<const uint8_t*>(compVersion.data()); |
| 298 | compVerStrInfo.length = static_cast<uint8_t>(compVersion.size()); |
| 299 | |
Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 300 | Request request( |
| 301 | sizeof(pldm_msg_hdr) + sizeof(struct pldm_update_component_req) + |
| 302 | compVerStrInfo.length); |
Pavithra Barithaya | 1039a8a | 2025-01-31 11:30:14 +0530 | [diff] [blame] | 303 | auto requestMsg = new (request.data()) pldm_msg; |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 304 | |
| 305 | auto rc = encode_update_component_req( |
| 306 | instanceId, compClassification, compIdentifier, compClassificationIndex, |
| 307 | std::get<static_cast<size_t>( |
| 308 | ComponentImageInfoPos::CompComparisonStampPos)>(comp), |
| 309 | std::get<static_cast<size_t>(ComponentImageInfoPos::CompSizePos)>(comp), |
| 310 | updateOptionFlags, PLDM_STR_TYPE_ASCII, compVerStrInfo.length, |
| 311 | &compVerStrInfo, requestMsg, |
| 312 | sizeof(pldm_update_component_req) + compVerStrInfo.length); |
| 313 | if (rc) |
| 314 | { |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 315 | // Handle error scenario |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 316 | updateManager->instanceIdDb.free(eid, instanceId); |
| 317 | error( |
| 318 | "Failed to encode update component req for endpoint ID '{EID}', response code '{RC}'", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 319 | "EID", eid, "RC", rc); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 320 | } |
| 321 | |
Tom Joseph | b7e083e | 2021-10-26 15:10:03 +0530 | [diff] [blame] | 322 | rc = updateManager->handler.registerRequest( |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 323 | eid, instanceId, PLDM_FWUP, PLDM_UPDATE_COMPONENT, std::move(request), |
Eric Yang | 70eca96 | 2025-05-11 01:48:15 +0800 | [diff] [blame] | 324 | [this](mctp_eid_t eid, const pldm_msg* response, size_t respMsgLen) { |
| 325 | this->updateComponent(eid, response, respMsgLen); |
| 326 | }); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 327 | if (rc) |
| 328 | { |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 329 | // Handle error scenario |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 330 | error( |
| 331 | "Failed to send update request for endpoint ID '{EID}', response code '{RC}'", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 332 | "EID", eid, "RC", rc); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 333 | } |
| 334 | } |
| 335 | |
| 336 | void DeviceUpdater::updateComponent(mctp_eid_t eid, const pldm_msg* response, |
| 337 | size_t respMsgLen) |
| 338 | { |
| 339 | if (response == nullptr || !respMsgLen) |
| 340 | { |
| 341 | // Handle error scenario |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 342 | error( |
| 343 | "No response received for update component with endpoint ID {EID}", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 344 | "EID", eid); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 345 | return; |
| 346 | } |
| 347 | |
| 348 | uint8_t completionCode = 0; |
| 349 | uint8_t compCompatibilityResp = 0; |
| 350 | uint8_t compCompatibilityRespCode = 0; |
| 351 | bitfield32_t updateOptionFlagsEnabled{}; |
| 352 | uint16_t timeBeforeReqFWData = 0; |
| 353 | |
| 354 | auto rc = decode_update_component_resp( |
| 355 | response, respMsgLen, &completionCode, &compCompatibilityResp, |
| 356 | &compCompatibilityRespCode, &updateOptionFlagsEnabled, |
| 357 | &timeBeforeReqFWData); |
| 358 | if (rc) |
| 359 | { |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 360 | error( |
| 361 | "Failed to decode update request response for endpoint ID '{EID}', response code '{RC}'", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 362 | "EID", eid, "RC", rc); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 363 | return; |
| 364 | } |
| 365 | if (completionCode) |
| 366 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 367 | error( |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 368 | "Failed to update request response for endpoint ID '{EID}', completion code '{CC}'", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 369 | "EID", eid, "CC", completionCode); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 370 | return; |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | Response DeviceUpdater::requestFwData(const pldm_msg* request, |
| 375 | size_t payloadLength) |
| 376 | { |
| 377 | uint8_t completionCode = PLDM_SUCCESS; |
| 378 | uint32_t offset = 0; |
| 379 | uint32_t length = 0; |
| 380 | Response response(sizeof(pldm_msg_hdr) + sizeof(completionCode), 0); |
Pavithra Barithaya | 1039a8a | 2025-01-31 11:30:14 +0530 | [diff] [blame] | 381 | auto responseMsg = new (response.data()) pldm_msg; |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 382 | auto rc = decode_request_firmware_data_req(request, payloadLength, &offset, |
| 383 | &length); |
| 384 | if (rc) |
| 385 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 386 | error( |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 387 | "Failed to decode request firmware date request for endpoint ID '{EID}', response code '{RC}'", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 388 | "EID", eid, "RC", rc); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 389 | rc = encode_request_firmware_data_resp( |
| 390 | request->hdr.instance_id, PLDM_ERROR_INVALID_DATA, responseMsg, |
| 391 | sizeof(completionCode)); |
| 392 | if (rc) |
| 393 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 394 | error( |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 395 | "Failed to encode request firmware date response for endpoint ID '{EID}', response code '{RC}'", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 396 | "EID", eid, "RC", rc); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 397 | } |
| 398 | return response; |
| 399 | } |
| 400 | |
| 401 | const auto& applicableComponents = |
| 402 | std::get<ApplicableComponents>(fwDeviceIDRecord); |
| 403 | const auto& comp = compImageInfos[applicableComponents[componentIndex]]; |
| 404 | auto compOffset = std::get<5>(comp); |
| 405 | auto compSize = std::get<6>(comp); |
Eric Yang | 9119752 | 2024-12-06 15:44:54 +0800 | [diff] [blame] | 406 | debug("Decoded fw request data at offset '{OFFSET}' and length '{LENGTH}' ", |
| 407 | "OFFSET", offset, "LENGTH", length); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 408 | if (length < PLDM_FWUP_BASELINE_TRANSFER_SIZE || length > maxTransferSize) |
| 409 | { |
| 410 | rc = encode_request_firmware_data_resp( |
| 411 | request->hdr.instance_id, PLDM_FWUP_INVALID_TRANSFER_LENGTH, |
| 412 | responseMsg, sizeof(completionCode)); |
| 413 | if (rc) |
| 414 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 415 | error( |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 416 | "Failed to encode request firmware date response for endpoint ID '{EID}', response code '{RC}'", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 417 | "EID", eid, "RC", rc); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 418 | } |
| 419 | return response; |
| 420 | } |
| 421 | |
| 422 | if (offset + length > compSize + PLDM_FWUP_BASELINE_TRANSFER_SIZE) |
| 423 | { |
| 424 | rc = encode_request_firmware_data_resp( |
| 425 | request->hdr.instance_id, PLDM_FWUP_DATA_OUT_OF_RANGE, responseMsg, |
| 426 | sizeof(completionCode)); |
| 427 | if (rc) |
| 428 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 429 | error( |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 430 | "Failed to encode request firmware date response for endpoint ID '{EID}', response code '{RC}'", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 431 | "EID", eid, "RC", rc); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 432 | } |
| 433 | return response; |
| 434 | } |
| 435 | |
| 436 | size_t padBytes = 0; |
| 437 | if (offset + length > compSize) |
| 438 | { |
| 439 | padBytes = offset + length - compSize; |
| 440 | } |
| 441 | |
| 442 | response.resize(sizeof(pldm_msg_hdr) + sizeof(completionCode) + length); |
Pavithra Barithaya | 1039a8a | 2025-01-31 11:30:14 +0530 | [diff] [blame] | 443 | responseMsg = new (response.data()) pldm_msg; |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 444 | package.seekg(compOffset + offset); |
Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 445 | package.read( |
| 446 | reinterpret_cast<char*>( |
| 447 | response.data() + sizeof(pldm_msg_hdr) + sizeof(completionCode)), |
| 448 | length - padBytes); |
| 449 | rc = encode_request_firmware_data_resp( |
| 450 | request->hdr.instance_id, completionCode, responseMsg, |
| 451 | sizeof(completionCode)); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 452 | if (rc) |
| 453 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 454 | error( |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 455 | "Failed to encode request firmware date response for endpoint ID '{EID}', response code '{RC}'", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 456 | "EID", eid, "RC", rc); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 457 | return response; |
| 458 | } |
| 459 | |
| 460 | return response; |
| 461 | } |
| 462 | |
| 463 | Response DeviceUpdater::transferComplete(const pldm_msg* request, |
| 464 | size_t payloadLength) |
| 465 | { |
| 466 | uint8_t completionCode = PLDM_SUCCESS; |
| 467 | Response response(sizeof(pldm_msg_hdr) + sizeof(completionCode), 0); |
Pavithra Barithaya | 1039a8a | 2025-01-31 11:30:14 +0530 | [diff] [blame] | 468 | auto responseMsg = new (response.data()) pldm_msg; |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 469 | |
| 470 | uint8_t transferResult = 0; |
Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 471 | auto rc = |
| 472 | decode_transfer_complete_req(request, payloadLength, &transferResult); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 473 | if (rc) |
| 474 | { |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 475 | error( |
| 476 | "Failed to decode TransferComplete request for endpoint ID '{EID}', response code '{RC}'", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 477 | "EID", eid, "RC", rc); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 478 | rc = encode_transfer_complete_resp(request->hdr.instance_id, |
| 479 | PLDM_ERROR_INVALID_DATA, responseMsg, |
| 480 | sizeof(completionCode)); |
| 481 | if (rc) |
| 482 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 483 | error( |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 484 | "Failed to encode TransferComplete response for endpoint ID '{EID}', response code '{RC}'", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 485 | "EID", eid, "RC", rc); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 486 | } |
| 487 | return response; |
| 488 | } |
| 489 | |
| 490 | const auto& applicableComponents = |
| 491 | std::get<ApplicableComponents>(fwDeviceIDRecord); |
| 492 | const auto& comp = compImageInfos[applicableComponents[componentIndex]]; |
| 493 | const auto& compVersion = std::get<7>(comp); |
| 494 | |
| 495 | if (transferResult == PLDM_FWUP_TRANSFER_SUCCESS) |
| 496 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 497 | info( |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 498 | "Component endpoint ID '{EID}' and version '{COMPONENT_VERSION}' transfer complete.", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 499 | "EID", eid, "COMPONENT_VERSION", compVersion); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 500 | } |
| 501 | else |
| 502 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 503 | error( |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 504 | "Failure in transfer of the component endpoint ID '{EID}' and version '{COMPONENT_VERSION}' with transfer result - {RESULT}", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 505 | "EID", eid, "COMPONENT_VERSION", compVersion, "RESULT", |
| 506 | transferResult); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | rc = encode_transfer_complete_resp(request->hdr.instance_id, completionCode, |
| 510 | responseMsg, sizeof(completionCode)); |
| 511 | if (rc) |
| 512 | { |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 513 | error( |
| 514 | "Failed to encode transfer complete response of endpoint ID '{EID}', response code '{RC}'", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 515 | "EID", eid, "RC", rc); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 516 | return response; |
| 517 | } |
| 518 | |
| 519 | return response; |
| 520 | } |
| 521 | |
| 522 | Response DeviceUpdater::verifyComplete(const pldm_msg* request, |
| 523 | size_t payloadLength) |
| 524 | { |
| 525 | uint8_t completionCode = PLDM_SUCCESS; |
| 526 | Response response(sizeof(pldm_msg_hdr) + sizeof(completionCode), 0); |
Pavithra Barithaya | 1039a8a | 2025-01-31 11:30:14 +0530 | [diff] [blame] | 527 | auto responseMsg = new (response.data()) pldm_msg; |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 528 | |
| 529 | uint8_t verifyResult = 0; |
| 530 | auto rc = decode_verify_complete_req(request, payloadLength, &verifyResult); |
| 531 | if (rc) |
| 532 | { |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 533 | error( |
| 534 | "Failed to decode verify complete request of endpoint ID '{EID}', response code '{RC}'", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 535 | "EID", eid, "RC", rc); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 536 | rc = encode_verify_complete_resp(request->hdr.instance_id, |
| 537 | PLDM_ERROR_INVALID_DATA, responseMsg, |
| 538 | sizeof(completionCode)); |
| 539 | if (rc) |
| 540 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 541 | error( |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 542 | "Failed to encode verify complete response of endpoint ID '{EID}', response code '{RC}'.", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 543 | "EID", eid, "RC", rc); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 544 | } |
| 545 | return response; |
| 546 | } |
| 547 | |
| 548 | const auto& applicableComponents = |
| 549 | std::get<ApplicableComponents>(fwDeviceIDRecord); |
| 550 | const auto& comp = compImageInfos[applicableComponents[componentIndex]]; |
| 551 | const auto& compVersion = std::get<7>(comp); |
| 552 | |
| 553 | if (verifyResult == PLDM_FWUP_VERIFY_SUCCESS) |
| 554 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 555 | info( |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 556 | "Component endpoint ID '{EID}' and version '{COMPONENT_VERSION}' verification complete.", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 557 | "EID", eid, "COMPONENT_VERSION", compVersion); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 558 | } |
| 559 | else |
| 560 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 561 | error( |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 562 | "Failed to verify component endpoint ID '{EID}' and version '{COMPONENT_VERSION}' with transfer result - '{RESULT}'", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 563 | "EID", eid, "COMPONENT_VERSION", compVersion, "RESULT", |
| 564 | verifyResult); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | rc = encode_verify_complete_resp(request->hdr.instance_id, completionCode, |
| 568 | responseMsg, sizeof(completionCode)); |
| 569 | if (rc) |
| 570 | { |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 571 | error( |
| 572 | "Failed to encode verify complete response for endpoint ID '{EID}', response code - {RC}", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 573 | "EID", eid, "RC", rc); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 574 | return response; |
| 575 | } |
| 576 | |
| 577 | return response; |
| 578 | } |
| 579 | |
| 580 | Response DeviceUpdater::applyComplete(const pldm_msg* request, |
| 581 | size_t payloadLength) |
| 582 | { |
| 583 | uint8_t completionCode = PLDM_SUCCESS; |
| 584 | Response response(sizeof(pldm_msg_hdr) + sizeof(completionCode), 0); |
Pavithra Barithaya | 1039a8a | 2025-01-31 11:30:14 +0530 | [diff] [blame] | 585 | auto responseMsg = new (response.data()) pldm_msg; |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 586 | |
| 587 | uint8_t applyResult = 0; |
| 588 | bitfield16_t compActivationModification{}; |
| 589 | auto rc = decode_apply_complete_req(request, payloadLength, &applyResult, |
| 590 | &compActivationModification); |
| 591 | if (rc) |
| 592 | { |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 593 | error( |
| 594 | "Failed to decode apply complete request for endpoint ID '{EID}', response code '{RC}'", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 595 | "EID", eid, "RC", rc); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 596 | rc = encode_apply_complete_resp(request->hdr.instance_id, |
| 597 | PLDM_ERROR_INVALID_DATA, responseMsg, |
| 598 | sizeof(completionCode)); |
| 599 | if (rc) |
| 600 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 601 | error( |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 602 | "Failed to encode apply complete response for endpoint ID '{EID}', response code '{RC}'", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 603 | "EID", eid, "RC", rc); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 604 | } |
| 605 | return response; |
| 606 | } |
| 607 | |
| 608 | const auto& applicableComponents = |
| 609 | std::get<ApplicableComponents>(fwDeviceIDRecord); |
| 610 | const auto& comp = compImageInfos[applicableComponents[componentIndex]]; |
| 611 | const auto& compVersion = std::get<7>(comp); |
| 612 | |
| 613 | if (applyResult == PLDM_FWUP_APPLY_SUCCESS || |
| 614 | applyResult == PLDM_FWUP_APPLY_SUCCESS_WITH_ACTIVATION_METHOD) |
| 615 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 616 | info( |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 617 | "Component endpoint ID '{EID}' with '{COMPONENT_VERSION}' apply complete.", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 618 | "EID", eid, "COMPONENT_VERSION", compVersion); |
Tom Joseph | 4d8d577 | 2021-08-17 07:35:05 -0700 | [diff] [blame] | 619 | updateManager->updateActivationProgress(); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 620 | } |
| 621 | else |
| 622 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 623 | error( |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 624 | "Failed to apply component endpoint ID '{EID}' and version '{COMPONENT_VERSION}', error - {ERROR}", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 625 | "EID", eid, "COMPONENT_VERSION", compVersion, "ERROR", applyResult); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | rc = encode_apply_complete_resp(request->hdr.instance_id, completionCode, |
| 629 | responseMsg, sizeof(completionCode)); |
| 630 | if (rc) |
| 631 | { |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 632 | error( |
| 633 | "Failed to encode apply complete response for endpoint ID '{EID}', response code '{RC}'", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 634 | "EID", eid, "RC", rc); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 635 | return response; |
| 636 | } |
| 637 | |
| 638 | if (componentIndex == applicableComponents.size() - 1) |
| 639 | { |
| 640 | componentIndex = 0; |
| 641 | pldmRequest = std::make_unique<sdeventplus::source::Defer>( |
Tom Joseph | b7e083e | 2021-10-26 15:10:03 +0530 | [diff] [blame] | 642 | updateManager->event, |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 643 | std::bind(&DeviceUpdater::sendActivateFirmwareRequest, this)); |
| 644 | } |
| 645 | else |
| 646 | { |
| 647 | componentIndex++; |
| 648 | pldmRequest = std::make_unique<sdeventplus::source::Defer>( |
Tom Joseph | b7e083e | 2021-10-26 15:10:03 +0530 | [diff] [blame] | 649 | updateManager->event, |
| 650 | std::bind(&DeviceUpdater::sendUpdateComponentRequest, this, |
| 651 | componentIndex)); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | return response; |
| 655 | } |
| 656 | |
| 657 | void DeviceUpdater::sendActivateFirmwareRequest() |
| 658 | { |
| 659 | pldmRequest.reset(); |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 660 | auto instanceId = updateManager->instanceIdDb.next(eid); |
Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 661 | Request request( |
| 662 | sizeof(pldm_msg_hdr) + sizeof(struct pldm_activate_firmware_req)); |
Pavithra Barithaya | 1039a8a | 2025-01-31 11:30:14 +0530 | [diff] [blame] | 663 | auto requestMsg = new (request.data()) pldm_msg; |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 664 | |
| 665 | auto rc = encode_activate_firmware_req( |
| 666 | instanceId, PLDM_NOT_ACTIVATE_SELF_CONTAINED_COMPONENTS, requestMsg, |
| 667 | sizeof(pldm_activate_firmware_req)); |
| 668 | if (rc) |
| 669 | { |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 670 | updateManager->instanceIdDb.free(eid, instanceId); |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 671 | error( |
| 672 | "Failed to encode activate firmware req for endpoint ID '{EID}', response code '{RC}'", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 673 | "EID", eid, "RC", rc); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 674 | } |
| 675 | |
Tom Joseph | b7e083e | 2021-10-26 15:10:03 +0530 | [diff] [blame] | 676 | rc = updateManager->handler.registerRequest( |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 677 | eid, instanceId, PLDM_FWUP, PLDM_ACTIVATE_FIRMWARE, std::move(request), |
Eric Yang | 70eca96 | 2025-05-11 01:48:15 +0800 | [diff] [blame] | 678 | [this](mctp_eid_t eid, const pldm_msg* response, size_t respMsgLen) { |
| 679 | this->activateFirmware(eid, response, respMsgLen); |
| 680 | }); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 681 | if (rc) |
| 682 | { |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 683 | error( |
| 684 | "Failed to send activate firmware request for endpoint ID '{EID}', response code '{RC}'", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 685 | "EID", eid, "RC", rc); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 686 | } |
| 687 | } |
| 688 | |
| 689 | void DeviceUpdater::activateFirmware(mctp_eid_t eid, const pldm_msg* response, |
| 690 | size_t respMsgLen) |
| 691 | { |
| 692 | if (response == nullptr || !respMsgLen) |
| 693 | { |
| 694 | // Handle error scenario |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 695 | error( |
| 696 | "No response received for activate firmware for endpoint ID '{EID}'", |
| 697 | "EID", eid); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 698 | return; |
| 699 | } |
| 700 | |
| 701 | uint8_t completionCode = 0; |
| 702 | uint16_t estimatedTimeForActivation = 0; |
| 703 | |
| 704 | auto rc = decode_activate_firmware_resp( |
| 705 | response, respMsgLen, &completionCode, &estimatedTimeForActivation); |
| 706 | if (rc) |
| 707 | { |
| 708 | // Handle error scenario |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 709 | error( |
| 710 | "Failed to decode activate firmware response for endpoint ID '{EID}', response code '{RC}'", |
| 711 | "EID", eid, "RC", rc); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 712 | return; |
| 713 | } |
| 714 | if (completionCode) |
| 715 | { |
| 716 | // Handle error scenario |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 717 | error( |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 718 | "Failed to activate firmware response for endpoint ID '{EID}', completion code '{CC}'", |
| 719 | "EID", eid, "CC", completionCode); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 720 | return; |
| 721 | } |
Tom Joseph | 4d8d577 | 2021-08-17 07:35:05 -0700 | [diff] [blame] | 722 | |
| 723 | updateManager->updateDeviceCompletion(eid, true); |
Tom Joseph | ef90b0d | 2021-08-17 07:12:49 -0700 | [diff] [blame] | 724 | } |
| 725 | |
| 726 | } // namespace fw_update |
| 727 | |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 728 | } // namespace pldm |