srikanta mondal | 52a292b | 2020-07-27 23:49:14 +0000 | [diff] [blame] | 1 | #include <byteswap.h> |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 2 | #include <ipmid/api.h> |
| 3 | #include <openssl/evp.h> |
| 4 | #include <openssl/sha.h> |
| 5 | #include <sys/mman.h> |
| 6 | #include <sys/stat.h> |
| 7 | #include <sys/types.h> |
| 8 | #include <unistd.h> |
| 9 | |
srikanta mondal | 52a292b | 2020-07-27 23:49:14 +0000 | [diff] [blame] | 10 | #include <appcommands.hpp> |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 11 | #include <boost/algorithm/string.hpp> |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 12 | #include <boost/container/flat_map.hpp> |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 13 | #include <boost/process/child.hpp> |
| 14 | #include <boost/uuid/random_generator.hpp> |
| 15 | #include <boost/uuid/uuid_io.hpp> |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 16 | #include <commandutils.hpp> |
anil kumar appana | 6c7d938 | 2019-05-31 14:33:13 +0000 | [diff] [blame] | 17 | #include <ipmid/api.hpp> |
AppaRao Puli | 37fde6b | 2019-10-25 16:37:50 +0530 | [diff] [blame] | 18 | #include <ipmid/utils.hpp> |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 19 | #include <phosphor-logging/log.hpp> |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 20 | #include <sdbusplus/bus.hpp> |
| 21 | #include <sdbusplus/bus/match.hpp> |
| 22 | #include <sdbusplus/server/object.hpp> |
| 23 | #include <sdbusplus/timer.hpp> |
Patrick Venture | c2a07d4 | 2020-05-30 16:35:03 -0700 | [diff] [blame] | 24 | #include <types.hpp> |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 25 | |
| 26 | #include <chrono> |
| 27 | #include <cstdint> |
| 28 | #include <filesystem> |
| 29 | #include <fstream> |
| 30 | #include <iostream> |
| 31 | #include <map> |
| 32 | #include <random> |
Rajashekar Gade Reddy | c886406 | 2019-10-15 16:52:30 +0530 | [diff] [blame] | 33 | #ifdef INTEL_PFR_ENABLED |
| 34 | #include <spiDev.hpp> |
| 35 | #endif |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 36 | |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 37 | static constexpr bool DEBUG = true; |
| 38 | static void registerFirmwareFunctions() __attribute__((constructor)); |
| 39 | |
AppaRao Puli | 37fde6b | 2019-10-25 16:37:50 +0530 | [diff] [blame] | 40 | namespace ipmi |
| 41 | { |
| 42 | namespace firmware |
| 43 | { |
| 44 | constexpr Cmd cmdGetFwVersionInfo = 0x20; |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 45 | constexpr Cmd cmdGetFwSecurityVersionInfo = 0x21; |
| 46 | constexpr Cmd cmdGetFwUpdateChannelInfo = 0x22; |
| 47 | constexpr Cmd cmdGetBmcExecutionContext = 0x23; |
Rajashekar Gade Reddy | 3ec2620 | 2019-10-29 14:10:00 +0530 | [diff] [blame] | 48 | constexpr Cmd cmdFwGetRootCertData = 0x25; |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 49 | constexpr Cmd cmdGetFwUpdateRandomNumber = 0x26; |
| 50 | constexpr Cmd cmdSetFirmwareUpdateMode = 0x27; |
| 51 | constexpr Cmd cmdExitFirmwareUpdateMode = 0x28; |
| 52 | constexpr Cmd cmdGetSetFwUpdateControl = 0x29; |
| 53 | constexpr Cmd cmdGetFirmwareUpdateStatus = 0x2A; |
| 54 | constexpr Cmd cmdSetFirmwareUpdateOptions = 0x2B; |
Rajashekar Gade Reddy | 3ec2620 | 2019-10-29 14:10:00 +0530 | [diff] [blame] | 55 | constexpr Cmd cmdFwImageWriteData = 0x2c; |
AppaRao Puli | 37fde6b | 2019-10-25 16:37:50 +0530 | [diff] [blame] | 56 | } // namespace firmware |
| 57 | } // namespace ipmi |
| 58 | |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 59 | namespace ipmi |
| 60 | { |
| 61 | // Custom completion codes |
| 62 | constexpr Cc ccUsbAttachOrDetachFailed = 0x80; |
| 63 | constexpr Cc ccNotSupportedInPresentState = 0xD5; |
| 64 | |
| 65 | static inline auto responseUsbAttachOrDetachFailed() |
| 66 | { |
| 67 | return response(ccUsbAttachOrDetachFailed); |
| 68 | } |
| 69 | static inline auto responseNotSupportedInPresentState() |
| 70 | { |
| 71 | return response(ccNotSupportedInPresentState); |
| 72 | } |
| 73 | } // namespace ipmi |
| 74 | |
Punith Nadur Basavarajaiah | a8dd197 | 2020-08-19 18:05:44 +0000 | [diff] [blame] | 75 | static constexpr size_t imageCount = 2; |
| 76 | std::array<std::array<uint8_t, imageCount>, imageCount> imgFwSecurityVersion = { |
| 77 | (0, 0), (0, 0)}; |
| 78 | static constexpr size_t svnActiveVerOffsetInPfm = 0x404; |
| 79 | static constexpr size_t bkcActiveVerOffsetInPfm = 0x405; |
| 80 | static constexpr size_t svnRecoveryVerOffsetInPfm = 0x804; |
| 81 | static constexpr size_t bkcRecoveryVerOffsetInPfm = 0x805; |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 82 | static constexpr const char* bmcStateIntf = "xyz.openbmc_project.State.BMC"; |
| 83 | static constexpr const char* bmcStatePath = "/xyz/openbmc_project/state/bmc0"; |
| 84 | static constexpr const char* bmcStateReady = |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 85 | "xyz.openbmc_project.State.BMC.BMCState.Ready"; |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 86 | static constexpr const char* bmcStateUpdateInProgress = |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 87 | "xyz.openbmc_project.State.BMC.BMCState.UpdateInProgress"; |
| 88 | |
| 89 | static constexpr char firmwareBufferFile[] = "/tmp/fw-download.bin"; |
| 90 | static std::chrono::steady_clock::time_point fwRandomNumGenTs; |
| 91 | static constexpr auto fwRandomNumExpirySeconds = std::chrono::seconds(30); |
| 92 | static constexpr size_t fwRandomNumLength = 8; |
| 93 | static std::array<uint8_t, fwRandomNumLength> fwRandomNum; |
| 94 | constexpr char usbCtrlPath[] = "/usr/bin/usb-ctrl"; |
| 95 | constexpr char fwUpdateMountPoint[] = "/tmp/usb-fwupd.mnt"; |
| 96 | constexpr char fwUpdateUsbVolImage[] = "/tmp/usb-fwupd.img"; |
| 97 | constexpr char fwUpdateUSBDevName[] = "fw-usb-mass-storage-dev"; |
| 98 | constexpr size_t fwPathMaxLength = 255; |
| 99 | |
Rajashekar Gade Reddy | df5e327 | 2019-09-05 18:10:53 +0530 | [diff] [blame] | 100 | #ifdef INTEL_PFR_ENABLED |
| 101 | uint32_t imgLength = 0; |
| 102 | uint32_t imgType = 0; |
| 103 | bool block0Mapped = false; |
| 104 | static constexpr uint32_t perBlock0MagicNum = 0xB6EAFD19; |
AppaRao Puli | 37fde6b | 2019-10-25 16:37:50 +0530 | [diff] [blame] | 105 | |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 106 | static constexpr const char* bmcActivePfmMTDDev = "/dev/mtd/pfm"; |
| 107 | static constexpr const char* bmcRecoveryImgMTDDev = "/dev/mtd/rc-image"; |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 108 | static constexpr size_t pfmBaseOffsetInImage = 0x400; |
| 109 | static constexpr size_t rootkeyOffsetInPfm = 0xA0; |
| 110 | static constexpr size_t cskKeyOffsetInPfm = 0x124; |
| 111 | static constexpr size_t cskSignatureOffsetInPfm = 0x19c; |
| 112 | static constexpr size_t certKeyLen = 96; |
| 113 | static constexpr size_t cskSignatureLen = 96; |
| 114 | |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 115 | static constexpr const char* versionIntf = |
AppaRao Puli | 37fde6b | 2019-10-25 16:37:50 +0530 | [diff] [blame] | 116 | "xyz.openbmc_project.Software.Version"; |
| 117 | |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 118 | enum class FwGetRootCertDataTag : uint8_t |
| 119 | { |
| 120 | activeRootKey = 1, |
| 121 | recoveryRootKey, |
| 122 | activeCSK, |
| 123 | recoveryCSK, |
| 124 | }; |
| 125 | |
AppaRao Puli | 37fde6b | 2019-10-25 16:37:50 +0530 | [diff] [blame] | 126 | enum class FWDeviceIDTag : uint8_t |
| 127 | { |
| 128 | bmcActiveImage = 1, |
| 129 | bmcRecoveryImage, |
| 130 | }; |
| 131 | |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 132 | const static boost::container::flat_map<FWDeviceIDTag, const char*> |
AppaRao Puli | 37fde6b | 2019-10-25 16:37:50 +0530 | [diff] [blame] | 133 | fwVersionIdMap{{FWDeviceIDTag::bmcActiveImage, |
| 134 | "/xyz/openbmc_project/software/bmc_active"}, |
| 135 | {FWDeviceIDTag::bmcRecoveryImage, |
| 136 | "/xyz/openbmc_project/software/bmc_recovery"}}; |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 137 | #endif // INTEL_PFR_ENABLED |
AppaRao Puli | 37fde6b | 2019-10-25 16:37:50 +0530 | [diff] [blame] | 138 | |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 139 | enum class ChannelIdTag : uint8_t |
| 140 | { |
| 141 | reserved = 0, |
| 142 | kcs = 1, |
| 143 | ipmb = 2, |
| 144 | rmcpPlus = 3 |
| 145 | }; |
Rajashekar Gade Reddy | df5e327 | 2019-09-05 18:10:53 +0530 | [diff] [blame] | 146 | |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 147 | enum class BmcExecutionContext : uint8_t |
| 148 | { |
| 149 | reserved = 0, |
| 150 | linuxOs = 0x10, |
| 151 | bootLoader = 0x11, |
| 152 | }; |
AppaRao Puli | 09a8314 | 2019-11-23 02:46:06 +0530 | [diff] [blame] | 153 | |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 154 | enum class FwUpdateCtrlReq : uint8_t |
| 155 | { |
| 156 | getCurrentControlStatus = 0x00, |
| 157 | imageTransferStart = 0x01, |
| 158 | imageTransferComplete = 0x02, |
| 159 | imageTransferAbort = 0x03, |
| 160 | setFirmwareFilename = 0x04, |
| 161 | attachUsbDevice = 0x05, |
| 162 | detachUsbDevice = 0x06 |
| 163 | }; |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 164 | |
| 165 | constexpr std::size_t operator""_MB(unsigned long long v) |
| 166 | { |
| 167 | return 1024u * 1024u * v; |
| 168 | } |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 169 | static constexpr size_t maxFirmwareImageSize = 32_MB; |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 170 | |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 171 | static bool localDownloadInProgress(void) |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 172 | { |
| 173 | struct stat sb; |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 174 | if (stat(firmwareBufferFile, &sb) < 0) |
| 175 | { |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 176 | return false; |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 177 | } |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 178 | return true; |
| 179 | } |
| 180 | |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 181 | class TransferHashCheck |
| 182 | { |
| 183 | public: |
| 184 | enum class HashCheck : uint8_t |
| 185 | { |
| 186 | notRequested = 0, |
| 187 | requested, |
| 188 | sha2Success, |
| 189 | sha2Failed = 0xe2, |
| 190 | }; |
| 191 | |
| 192 | protected: |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 193 | EVP_MD_CTX* ctx; |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 194 | std::vector<uint8_t> expectedHash; |
| 195 | enum HashCheck check; |
| 196 | bool started; |
| 197 | |
| 198 | public: |
| 199 | TransferHashCheck() : check(HashCheck::notRequested), started(false) |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 200 | {} |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 201 | ~TransferHashCheck() |
| 202 | { |
| 203 | if (ctx) |
| 204 | { |
| 205 | EVP_MD_CTX_destroy(ctx); |
| 206 | ctx = NULL; |
| 207 | } |
| 208 | } |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 209 | void init(const std::vector<uint8_t>& expected) |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 210 | { |
| 211 | expectedHash = expected; |
| 212 | check = HashCheck::requested; |
| 213 | ctx = EVP_MD_CTX_create(); |
| 214 | EVP_DigestInit(ctx, EVP_sha256()); |
| 215 | } |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 216 | void hash(const std::vector<uint8_t>& data) |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 217 | { |
| 218 | if (!started) |
| 219 | { |
| 220 | started = true; |
| 221 | } |
| 222 | EVP_DigestUpdate(ctx, data.data(), data.size()); |
| 223 | } |
| 224 | void clear() |
| 225 | { |
| 226 | // if not started, nothing to clear |
| 227 | if (started) |
| 228 | { |
| 229 | if (ctx) |
| 230 | { |
| 231 | EVP_MD_CTX_destroy(ctx); |
| 232 | } |
| 233 | if (check != HashCheck::notRequested) |
| 234 | { |
| 235 | check = HashCheck::requested; |
| 236 | } |
| 237 | ctx = EVP_MD_CTX_create(); |
| 238 | EVP_DigestInit(ctx, EVP_sha256()); |
| 239 | } |
| 240 | } |
| 241 | enum HashCheck verify() |
| 242 | { |
| 243 | if (check == HashCheck::requested) |
| 244 | { |
| 245 | unsigned int len = 0; |
| 246 | std::vector<uint8_t> digest(EVP_MD_size(EVP_sha256())); |
| 247 | EVP_DigestFinal(ctx, digest.data(), &len); |
| 248 | if (digest == expectedHash) |
| 249 | { |
| 250 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 251 | "Transfer sha2 verify passed."); |
| 252 | check = HashCheck::sha2Success; |
| 253 | } |
| 254 | else |
| 255 | { |
| 256 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 257 | "Transfer sha2 verify failed."); |
| 258 | check = HashCheck::sha2Failed; |
| 259 | } |
| 260 | } |
| 261 | return check; |
| 262 | } |
| 263 | uint8_t status() const |
| 264 | { |
| 265 | return static_cast<uint8_t>(check); |
| 266 | } |
| 267 | }; |
| 268 | |
| 269 | class MappedFile |
| 270 | { |
| 271 | public: |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 272 | MappedFile(const std::string& fname) : addr(nullptr), fsize(0) |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 273 | { |
| 274 | std::error_code ec; |
| 275 | size_t sz = std::filesystem::file_size(fname, ec); |
P Dheeraj Srujan Kumar | c08e975 | 2021-07-14 19:38:32 +0530 | [diff] [blame] | 276 | if (!ec) |
| 277 | { |
| 278 | return; |
| 279 | } |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 280 | int fd = open(fname.c_str(), O_RDONLY); |
P Dheeraj Srujan Kumar | c08e975 | 2021-07-14 19:38:32 +0530 | [diff] [blame] | 281 | if (fd < 0) |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 282 | { |
| 283 | return; |
| 284 | } |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 285 | void* tmp = mmap(NULL, sz, PROT_READ, MAP_SHARED, fd, 0); |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 286 | close(fd); |
| 287 | if (tmp == MAP_FAILED) |
| 288 | { |
| 289 | return; |
| 290 | } |
| 291 | addr = tmp; |
| 292 | fsize = sz; |
| 293 | } |
| 294 | |
| 295 | ~MappedFile() |
| 296 | { |
| 297 | if (addr) |
| 298 | { |
| 299 | munmap(addr, fsize); |
| 300 | } |
| 301 | } |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 302 | const uint8_t* data() const |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 303 | { |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 304 | return static_cast<const uint8_t*>(addr); |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 305 | } |
| 306 | size_t size() const |
| 307 | { |
| 308 | return fsize; |
| 309 | } |
| 310 | |
| 311 | private: |
| 312 | size_t fsize; |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 313 | void* addr; |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 314 | }; |
| 315 | |
| 316 | class FwUpdateStatusCache |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 317 | { |
| 318 | public: |
| 319 | enum |
| 320 | { |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 321 | fwStateInit = 0, |
| 322 | fwStateIdle, |
| 323 | fwStateDownload, |
| 324 | fwStateVerify, |
| 325 | fwStateProgram, |
| 326 | fwStateUpdateSuccess, |
| 327 | fwStateError = 0x0f, |
| 328 | fwStateAcCycleRequired = 0x83, |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 329 | }; |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 330 | uint8_t getState() |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 331 | { |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 332 | if ((fwUpdateState == fwStateIdle || fwUpdateState == fwStateInit) && |
| 333 | localDownloadInProgress()) |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 334 | { |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 335 | fwUpdateState = fwStateDownload; |
| 336 | progressPercent = 0; |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 337 | } |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 338 | return fwUpdateState; |
| 339 | } |
| 340 | void resetStatusCache() |
| 341 | { |
| 342 | unlink(firmwareBufferFile); |
| 343 | } |
| 344 | void setState(const uint8_t state) |
| 345 | { |
| 346 | switch (state) |
| 347 | { |
| 348 | case fwStateInit: |
| 349 | case fwStateIdle: |
| 350 | case fwStateError: |
| 351 | resetStatusCache(); |
| 352 | break; |
| 353 | case fwStateDownload: |
| 354 | case fwStateVerify: |
| 355 | case fwStateProgram: |
| 356 | case fwStateUpdateSuccess: |
| 357 | break; |
| 358 | default: |
| 359 | // Error |
| 360 | break; |
| 361 | } |
| 362 | fwUpdateState = state; |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 363 | } |
| 364 | uint8_t percent() |
| 365 | { |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 366 | return progressPercent; |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 367 | } |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 368 | void updateActivationPercent(const std::string& objPath) |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 369 | { |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 370 | std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus(); |
| 371 | fwUpdateState = fwStateProgram; |
| 372 | progressPercent = 0; |
| 373 | match = std::make_shared<sdbusplus::bus::match::match>( |
| 374 | *busp, |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 375 | sdbusplus::bus::match::rules::propertiesChanged( |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 376 | objPath, "xyz.openbmc_project.Software.ActivationProgress"), |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 377 | [&](sdbusplus::message::message& msg) { |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 378 | std::map<std::string, ipmi::DbusVariant> props; |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 379 | std::vector<std::string> inVal; |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 380 | std::string iface; |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 381 | try |
| 382 | { |
| 383 | msg.read(iface, props, inVal); |
| 384 | } |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 385 | catch (const std::exception& e) |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 386 | { |
| 387 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 388 | "Exception caught in get ActivationProgress"); |
| 389 | return; |
| 390 | } |
| 391 | |
| 392 | auto it = props.find("Progress"); |
| 393 | if (it != props.end()) |
| 394 | { |
| 395 | progressPercent = std::get<uint8_t>(it->second); |
| 396 | if (progressPercent == 100) |
| 397 | { |
| 398 | fwUpdateState = fwStateUpdateSuccess; |
| 399 | } |
| 400 | } |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 401 | }); |
| 402 | } |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 403 | uint8_t activationTimerTimeout() |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 404 | { |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 405 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 406 | "activationTimerTimeout: Increase percentage...", |
| 407 | phosphor::logging::entry("PERCENT:%d", progressPercent)); |
| 408 | progressPercent = progressPercent + 5; |
jayaprakash Mutyala | b8f2bf9 | 2020-01-27 23:17:39 +0000 | [diff] [blame] | 409 | if (progressPercent > 95) |
anil kumar appana | 31f8887 | 2019-08-02 15:16:27 +0000 | [diff] [blame] | 410 | { |
| 411 | /*changing the state to ready to update firmware utility */ |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 412 | fwUpdateState = fwStateUpdateSuccess; |
anil kumar appana | 31f8887 | 2019-08-02 15:16:27 +0000 | [diff] [blame] | 413 | } |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 414 | return progressPercent; |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 415 | } |
anil kumar appana | 31f8887 | 2019-08-02 15:16:27 +0000 | [diff] [blame] | 416 | /* API for changing state to ERROR */ |
| 417 | void firmwareUpdateAbortState() |
| 418 | { |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 419 | unlink(firmwareBufferFile); |
anil kumar appana | 31f8887 | 2019-08-02 15:16:27 +0000 | [diff] [blame] | 420 | // changing the state to error |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 421 | fwUpdateState = fwStateError; |
anil kumar appana | 31f8887 | 2019-08-02 15:16:27 +0000 | [diff] [blame] | 422 | } |
| 423 | void setDeferRestart(bool deferRestart) |
| 424 | { |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 425 | deferRestartState = deferRestart; |
anil kumar appana | 31f8887 | 2019-08-02 15:16:27 +0000 | [diff] [blame] | 426 | } |
| 427 | void setInhibitDowngrade(bool inhibitDowngrade) |
| 428 | { |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 429 | inhibitDowngradeState = inhibitDowngrade; |
anil kumar appana | 31f8887 | 2019-08-02 15:16:27 +0000 | [diff] [blame] | 430 | } |
| 431 | bool getDeferRestart() |
| 432 | { |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 433 | return deferRestartState; |
anil kumar appana | 31f8887 | 2019-08-02 15:16:27 +0000 | [diff] [blame] | 434 | } |
| 435 | bool getInhibitDowngrade() |
| 436 | { |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 437 | return inhibitDowngradeState; |
anil kumar appana | 31f8887 | 2019-08-02 15:16:27 +0000 | [diff] [blame] | 438 | } |
| 439 | |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 440 | protected: |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 441 | std::shared_ptr<sdbusplus::asio::connection> busp; |
| 442 | std::shared_ptr<sdbusplus::bus::match::match> match; |
| 443 | uint8_t fwUpdateState = 0; |
| 444 | uint8_t progressPercent = 0; |
| 445 | bool deferRestartState = false; |
| 446 | bool inhibitDowngradeState = false; |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 447 | }; |
| 448 | |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 449 | static FwUpdateStatusCache fwUpdateStatus; |
| 450 | std::shared_ptr<TransferHashCheck> xferHashCheck; |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 451 | |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 452 | static void activateImage(const std::string& objPath) |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 453 | { |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 454 | // If flag is false means to reboot |
| 455 | if (fwUpdateStatus.getDeferRestart() == false) |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 456 | { |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 457 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 458 | "activating Image: ", |
| 459 | phosphor::logging::entry("OBJPATH =%s", objPath.c_str())); |
| 460 | std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus(); |
| 461 | bus->async_method_call( |
| 462 | [](const boost::system::error_code ec) { |
| 463 | if (ec) |
| 464 | { |
| 465 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 466 | "async_method_call error: activateImage failed"); |
| 467 | return; |
| 468 | } |
| 469 | }, |
| 470 | "xyz.openbmc_project.Software.BMC.Updater", objPath, |
| 471 | "org.freedesktop.DBus.Properties", "Set", |
| 472 | "xyz.openbmc_project.Software.Activation", "RequestedActivation", |
| 473 | std::variant<std::string>("xyz.openbmc_project.Software.Activation." |
| 474 | "RequestedActivations.Active")); |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 475 | } |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 476 | else |
| 477 | { |
| 478 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 479 | "Firmware image activation is deferred."); |
| 480 | } |
| 481 | fwUpdateStatus.setState( |
| 482 | static_cast<uint8_t>(FwUpdateStatusCache::fwStateUpdateSuccess)); |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 483 | } |
| 484 | |
AppaRao Puli | 09a8314 | 2019-11-23 02:46:06 +0530 | [diff] [blame] | 485 | static bool getFirmwareUpdateMode() |
| 486 | { |
| 487 | std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus(); |
| 488 | try |
| 489 | { |
| 490 | auto service = ipmi::getService(*busp, bmcStateIntf, bmcStatePath); |
| 491 | ipmi::Value state = ipmi::getDbusProperty( |
| 492 | *busp, service, bmcStatePath, bmcStateIntf, "CurrentBMCState"); |
| 493 | std::string bmcState = std::get<std::string>(state); |
| 494 | return (bmcState == bmcStateUpdateInProgress); |
| 495 | } |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 496 | catch (const std::exception& e) |
AppaRao Puli | 09a8314 | 2019-11-23 02:46:06 +0530 | [diff] [blame] | 497 | { |
| 498 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 499 | "Exception caught while getting BMC state.", |
| 500 | phosphor::logging::entry("EXCEPTION=%s", e.what())); |
| 501 | throw; |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | static void setFirmwareUpdateMode(const bool mode) |
| 506 | { |
| 507 | |
| 508 | std::string bmcState(bmcStateReady); |
| 509 | if (mode) |
| 510 | { |
| 511 | bmcState = bmcStateUpdateInProgress; |
| 512 | } |
| 513 | |
| 514 | std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus(); |
| 515 | try |
| 516 | { |
| 517 | auto service = ipmi::getService(*busp, bmcStateIntf, bmcStatePath); |
| 518 | ipmi::setDbusProperty(*busp, service, bmcStatePath, bmcStateIntf, |
| 519 | "CurrentBMCState", bmcState); |
| 520 | } |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 521 | catch (const std::exception& e) |
AppaRao Puli | 09a8314 | 2019-11-23 02:46:06 +0530 | [diff] [blame] | 522 | { |
| 523 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 524 | "Exception caught while setting BMC state.", |
| 525 | phosphor::logging::entry("EXCEPTION=%s", e.what())); |
| 526 | throw; |
| 527 | } |
| 528 | } |
| 529 | |
AppaRao Puli | e2cddf6 | 2020-01-31 00:30:08 +0530 | [diff] [blame] | 530 | /** @brief check if channel IPMB |
| 531 | * |
| 532 | * This function checks if the command is from IPMB |
| 533 | * |
| 534 | * @param[in] ctx - context of current session. |
| 535 | * @returns true if the medium is IPMB else return true. |
| 536 | **/ |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 537 | ipmi::Cc checkIPMBChannel(const ipmi::Context::ptr& ctx, bool& isIPMBChannel) |
AppaRao Puli | e2cddf6 | 2020-01-31 00:30:08 +0530 | [diff] [blame] | 538 | { |
| 539 | ipmi::ChannelInfo chInfo; |
| 540 | |
| 541 | if (ipmi::getChannelInfo(ctx->channel, chInfo) != ipmi::ccSuccess) |
| 542 | { |
| 543 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 544 | "Failed to get Channel Info", |
| 545 | phosphor::logging::entry("CHANNEL=%d", ctx->channel)); |
| 546 | return ipmi::ccUnspecifiedError; |
| 547 | } |
| 548 | |
| 549 | if (static_cast<ipmi::EChannelMediumType>(chInfo.mediumType) == |
| 550 | ipmi::EChannelMediumType::ipmb) |
| 551 | { |
| 552 | isIPMBChannel = true; |
| 553 | } |
| 554 | return ipmi::ccSuccess; |
| 555 | } |
| 556 | |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 557 | static void postTransferCompleteHandler( |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 558 | std::unique_ptr<sdbusplus::bus::match::match>& fwUpdateMatchSignal) |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 559 | { |
| 560 | // Setup timer for watching signal |
| 561 | static phosphor::Timer timer( |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 562 | [&fwUpdateMatchSignal]() { fwUpdateMatchSignal = nullptr; }); |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 563 | |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 564 | static phosphor::Timer activationStatusTimer([]() { |
jayaprakash Mutyala | b8f2bf9 | 2020-01-27 23:17:39 +0000 | [diff] [blame] | 565 | if (fwUpdateStatus.activationTimerTimeout() > 95) |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 566 | { |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 567 | activationStatusTimer.stop(); |
| 568 | fwUpdateStatus.setState( |
| 569 | static_cast<uint8_t>(FwUpdateStatusCache::fwStateVerify)); |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 570 | } |
| 571 | }); |
| 572 | |
| 573 | timer.start(std::chrono::microseconds(5000000), false); |
| 574 | |
| 575 | // callback function for capturing signal |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 576 | auto callback = [&](sdbusplus::message::message& m) { |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 577 | bool flag = false; |
| 578 | |
| 579 | std::vector<std::pair< |
| 580 | std::string, |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 581 | std::vector<std::pair<std::string, std::variant<std::string>>>>> |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 582 | intfPropsPair; |
| 583 | sdbusplus::message::object_path objPath; |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 584 | |
| 585 | try |
| 586 | { |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 587 | m.read(objPath, intfPropsPair); // Read in the object path |
| 588 | // that was just created |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 589 | } |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 590 | catch (const std::exception& e) |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 591 | { |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 592 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 593 | "Exception caught in reading created object path."); |
| 594 | return; |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 595 | } |
| 596 | // constructing response message |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 597 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 598 | "New Interface Added.", |
| 599 | phosphor::logging::entry("OBJPATH=%s", objPath.str.c_str())); |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 600 | for (auto& interface : intfPropsPair) |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 601 | { |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 602 | if (interface.first == "xyz.openbmc_project.Software.Activation") |
| 603 | { |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 604 | // There are chances of getting two signals for |
| 605 | // InterfacesAdded. So cross check and discrad second instance. |
| 606 | if (fwUpdateMatchSignal == nullptr) |
| 607 | { |
| 608 | return; |
| 609 | } |
| 610 | // Found our interface, disable callbacks |
| 611 | fwUpdateMatchSignal = nullptr; |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 612 | |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 613 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 614 | "Start activationStatusTimer for status."); |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 615 | try |
| 616 | { |
| 617 | timer.stop(); |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 618 | activationStatusTimer.start( |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 619 | std::chrono::microseconds(3000000), true); |
| 620 | } |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 621 | catch (const std::exception& e) |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 622 | { |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 623 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 624 | "Exception caught in start activationStatusTimer.", |
| 625 | phosphor::logging::entry("ERROR=%s", e.what())); |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 626 | } |
| 627 | |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 628 | fwUpdateStatus.updateActivationPercent(objPath.str); |
| 629 | activateImage(objPath.str); |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 630 | } |
| 631 | } |
| 632 | }; |
| 633 | |
| 634 | // Adding matcher |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 635 | fwUpdateMatchSignal = std::make_unique<sdbusplus::bus::match::match>( |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 636 | *getSdBus(), |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 637 | "interface='org.freedesktop.DBus.ObjectManager',type='signal'," |
| 638 | "member='InterfacesAdded',path='/xyz/openbmc_project/software'", |
| 639 | callback); |
| 640 | } |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 641 | static bool startFirmwareUpdate(const std::string& uri) |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 642 | { |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 643 | // fwupdate URIs start with file:// or usb:// or tftp:// etc. By the time |
| 644 | // the code gets to this point, the file should be transferred start the |
| 645 | // request (creating a new file in /tmp/images causes the update manager to |
| 646 | // check if it is ready for activation) |
| 647 | static std::unique_ptr<sdbusplus::bus::match::match> fwUpdateMatchSignal; |
| 648 | postTransferCompleteHandler(fwUpdateMatchSignal); |
| 649 | std::filesystem::rename( |
| 650 | uri, "/tmp/images/" + |
| 651 | boost::uuids::to_string(boost::uuids::random_generator()())); |
| 652 | return true; |
| 653 | } |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 654 | |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 655 | static int transferImageFromFile(const std::string& uri, bool move = true) |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 656 | { |
| 657 | std::error_code ec; |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 658 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 659 | "Transfer Image From File.", |
| 660 | phosphor::logging::entry("URI=%s", uri.c_str())); |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 661 | if (move) |
| 662 | { |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 663 | std::filesystem::rename(uri, firmwareBufferFile, ec); |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 664 | } |
| 665 | else |
| 666 | { |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 667 | std::filesystem::copy(uri, firmwareBufferFile, |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 668 | std::filesystem::copy_options::overwrite_existing, |
| 669 | ec); |
| 670 | } |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 671 | if (xferHashCheck) |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 672 | { |
| 673 | MappedFile mappedfw(uri); |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 674 | xferHashCheck->hash( |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 675 | {mappedfw.data(), mappedfw.data() + mappedfw.size()}); |
| 676 | } |
| 677 | if (ec.value()) |
| 678 | { |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 679 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 680 | "Image copy failed."); |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 681 | } |
| 682 | return ec.value(); |
| 683 | } |
| 684 | |
| 685 | template <typename... ArgTypes> |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 686 | static int executeCmd(const char* path, ArgTypes&&... tArgs) |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 687 | { |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 688 | boost::process::child execProg(path, const_cast<char*>(tArgs)...); |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 689 | execProg.wait(); |
| 690 | return execProg.exit_code(); |
| 691 | } |
| 692 | |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 693 | static int transferImageFromUsb(const std::string& uri) |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 694 | { |
| 695 | int ret, sysret; |
| 696 | char fwpath[fwPathMaxLength]; |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 697 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 698 | "Transfer Image From USB.", |
| 699 | phosphor::logging::entry("URI=%s", uri.c_str())); |
| 700 | ret = executeCmd(usbCtrlPath, "mount", fwUpdateUsbVolImage, |
| 701 | fwUpdateMountPoint); |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 702 | if (ret) |
| 703 | { |
| 704 | return ret; |
| 705 | } |
| 706 | |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 707 | std::string usb_path = std::string(fwUpdateMountPoint) + "/" + uri; |
| 708 | ret = transferImageFromFile(usb_path, false); |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 709 | |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 710 | executeCmd(usbCtrlPath, "cleanup", fwUpdateUsbVolImage, fwUpdateMountPoint); |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 711 | return ret; |
| 712 | } |
| 713 | |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 714 | static bool transferFirmwareFromUri(const std::string& uri) |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 715 | { |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 716 | static constexpr char fwUriFile[] = "file://"; |
| 717 | static constexpr char fwUriUsb[] = "usb://"; |
| 718 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 719 | "Transfer Image From URI.", |
| 720 | phosphor::logging::entry("URI=%s", uri.c_str())); |
| 721 | if (boost::algorithm::starts_with(uri, fwUriFile)) |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 722 | { |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 723 | std::string fname = uri.substr(sizeof(fwUriFile) - 1); |
| 724 | if (fname != firmwareBufferFile) |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 725 | { |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 726 | return 0 == transferImageFromFile(fname); |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 727 | } |
| 728 | return true; |
| 729 | } |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 730 | if (boost::algorithm::starts_with(uri, fwUriUsb)) |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 731 | { |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 732 | std::string fname = uri.substr(sizeof(fwUriUsb) - 1); |
| 733 | return 0 == transferImageFromUsb(fname); |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 734 | } |
| 735 | return false; |
| 736 | } |
| 737 | |
| 738 | /* Get USB-mass-storage device status: inserted => true, ejected => false */ |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 739 | static bool getUsbStatus() |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 740 | { |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 741 | std::filesystem::path usbDevPath = |
| 742 | std::filesystem::path("/sys/kernel/config/usb_gadget") / |
| 743 | fwUpdateUSBDevName; |
| 744 | return (std::filesystem::exists(usbDevPath) ? true : false); |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | /* Insert the USB-mass-storage device status: success => 0, failure => non-0 */ |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 748 | static int attachUsbDevice() |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 749 | { |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 750 | if (getUsbStatus()) |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 751 | { |
| 752 | return 1; |
| 753 | } |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 754 | int ret = executeCmd(usbCtrlPath, "setup", fwUpdateUsbVolImage, |
| 755 | std::to_string(maxFirmwareImageSize / 1_MB).c_str()); |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 756 | if (!ret) |
| 757 | { |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 758 | ret = executeCmd(usbCtrlPath, "insert", fwUpdateUSBDevName, |
| 759 | fwUpdateUsbVolImage); |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 760 | } |
| 761 | return ret; |
| 762 | } |
| 763 | |
| 764 | /* Eject the USB-mass-storage device status: success => 0, failure => non-0 */ |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 765 | static int detachUsbDevice() |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 766 | { |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 767 | if (!getUsbStatus()) |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 768 | { |
| 769 | return 1; |
| 770 | } |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 771 | return executeCmd(usbCtrlPath, "eject", fwUpdateUSBDevName); |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 772 | } |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 773 | static uint8_t getActiveBootImage(ipmi::Context::ptr ctx) |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 774 | { |
Terry S. Duncan | e319ecf | 2020-02-10 15:59:55 -0800 | [diff] [blame] | 775 | constexpr uint8_t undefinedImage = 0x00; |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 776 | constexpr uint8_t primaryImage = 0x01; |
| 777 | constexpr uint8_t secondaryImage = 0x02; |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 778 | constexpr const char* secondaryFitImageStartAddr = "22480000"; |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 779 | |
| 780 | uint8_t bootImage = primaryImage; |
| 781 | boost::system::error_code ec; |
| 782 | std::string value = ctx->bus->yield_method_call<std::string>( |
| 783 | ctx->yield, ec, "xyz.openbmc_project.U_Boot.Environment.Manager", |
| 784 | "/xyz/openbmc_project/u_boot/environment/mgr", |
| 785 | "xyz.openbmc_project.U_Boot.Environment.Manager", "Read", "bootcmd"); |
| 786 | if (ec) |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 787 | { |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 788 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 789 | "Failed to read the bootcmd value"); |
Terry S. Duncan | e319ecf | 2020-02-10 15:59:55 -0800 | [diff] [blame] | 790 | /* don't fail, just give back undefined until it is ready */ |
| 791 | bootImage = undefinedImage; |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 792 | } |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 793 | |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 794 | /* cheking for secondary FitImage Address 22480000 */ |
Terry S. Duncan | e319ecf | 2020-02-10 15:59:55 -0800 | [diff] [blame] | 795 | else if (value.find(secondaryFitImageStartAddr) != std::string::npos) |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 796 | { |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 797 | bootImage = secondaryImage; |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 798 | } |
| 799 | else |
| 800 | { |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 801 | bootImage = primaryImage; |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 802 | } |
| 803 | |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 804 | return bootImage; |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 805 | } |
| 806 | |
AppaRao Puli | 37fde6b | 2019-10-25 16:37:50 +0530 | [diff] [blame] | 807 | #ifdef INTEL_PFR_ENABLED |
| 808 | using fwVersionInfoType = std::tuple<uint8_t, // ID Tag |
| 809 | uint8_t, // Major Version Number |
| 810 | uint8_t, // Minor Version Number |
| 811 | uint32_t, // Build Number |
| 812 | uint32_t, // Build Timestamp |
| 813 | uint32_t>; // Update Timestamp |
| 814 | ipmi::RspType<uint8_t, std::vector<fwVersionInfoType>> ipmiGetFwVersionInfo() |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 815 | { |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 816 | // Byte 1 - Count (N) Number of devices data is being returned for. |
AppaRao Puli | 37fde6b | 2019-10-25 16:37:50 +0530 | [diff] [blame] | 817 | // Bytes 2:16 - Device firmare information(fwVersionInfoType) |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 818 | // Bytes - 17:(15xN) - Repeat of 2 through 16 |
| 819 | |
AppaRao Puli | 37fde6b | 2019-10-25 16:37:50 +0530 | [diff] [blame] | 820 | std::vector<fwVersionInfoType> fwVerInfoList; |
| 821 | std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus(); |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 822 | for (const auto& fwDev : fwVersionIdMap) |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 823 | { |
AppaRao Puli | 37fde6b | 2019-10-25 16:37:50 +0530 | [diff] [blame] | 824 | std::string verStr; |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 825 | try |
| 826 | { |
AppaRao Puli | 37fde6b | 2019-10-25 16:37:50 +0530 | [diff] [blame] | 827 | auto service = ipmi::getService(*busp, versionIntf, fwDev.second); |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 828 | |
AppaRao Puli | 37fde6b | 2019-10-25 16:37:50 +0530 | [diff] [blame] | 829 | ipmi::Value result = ipmi::getDbusProperty( |
| 830 | *busp, service, fwDev.second, versionIntf, "Version"); |
| 831 | verStr = std::get<std::string>(result); |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 832 | } |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 833 | catch (const std::exception& e) |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 834 | { |
AppaRao Puli | 37fde6b | 2019-10-25 16:37:50 +0530 | [diff] [blame] | 835 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 836 | "Failed to fetch Version property", |
| 837 | phosphor::logging::entry("ERROR=%s", e.what()), |
| 838 | phosphor::logging::entry("PATH=%s", fwDev.second), |
| 839 | phosphor::logging::entry("INTERFACE=%s", versionIntf)); |
| 840 | continue; |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 841 | } |
| 842 | |
AppaRao Puli | 37fde6b | 2019-10-25 16:37:50 +0530 | [diff] [blame] | 843 | if (verStr.empty()) |
| 844 | { |
| 845 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 846 | "Version is empty.", |
| 847 | phosphor::logging::entry("PATH=%s", fwDev.second), |
| 848 | phosphor::logging::entry("INTERFACE=%s", versionIntf)); |
| 849 | continue; |
| 850 | } |
| 851 | |
AppaRao Puli | 37fde6b | 2019-10-25 16:37:50 +0530 | [diff] [blame] | 852 | uint8_t majorNum = 0; |
| 853 | uint8_t minorNum = 0; |
| 854 | uint32_t buildNum = 0; |
| 855 | try |
| 856 | { |
srikanta mondal | 52a292b | 2020-07-27 23:49:14 +0000 | [diff] [blame] | 857 | std::optional<ipmi::MetaRevision> rev = |
| 858 | ipmi::convertIntelVersion(verStr); |
| 859 | if (rev.has_value()) |
| 860 | { |
| 861 | ipmi::MetaRevision revision = rev.value(); |
| 862 | majorNum = revision.major % 10 + (revision.major / 10) * 16; |
| 863 | minorNum = (revision.minor > 99 ? 99 : revision.minor); |
| 864 | minorNum = minorNum % 10 + (minorNum / 10) * 16; |
| 865 | uint32_t hash = std::stoul(revision.metaHash, 0, 16); |
| 866 | hash = bswap_32(hash); |
| 867 | buildNum = (revision.buildNo & 0xFF) + (hash & 0xFFFFFF00); |
| 868 | } |
| 869 | else |
| 870 | { |
| 871 | std::vector<std::string> splitVer; |
| 872 | boost::split(splitVer, verStr, boost::is_any_of(".-")); |
| 873 | if (splitVer.size() < 3) |
| 874 | { |
| 875 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 876 | "Invalid Version format.", |
| 877 | phosphor::logging::entry("Version=%s", verStr.c_str()), |
| 878 | phosphor::logging::entry("PATH=%s", fwDev.second)); |
| 879 | continue; |
| 880 | } |
| 881 | majorNum = std::stoul(splitVer[0], nullptr, 16); |
| 882 | minorNum = std::stoul(splitVer[1], nullptr, 16); |
| 883 | buildNum = std::stoul(splitVer[2], nullptr, 16); |
| 884 | } |
| 885 | // Build Timestamp - Not supported. |
| 886 | // Update Timestamp - TODO: Need to check with CPLD team. |
| 887 | fwVerInfoList.emplace_back( |
| 888 | fwVersionInfoType(static_cast<uint8_t>(fwDev.first), majorNum, |
| 889 | minorNum, buildNum, 0, 0)); |
AppaRao Puli | 37fde6b | 2019-10-25 16:37:50 +0530 | [diff] [blame] | 890 | } |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 891 | catch (const std::exception& e) |
AppaRao Puli | 37fde6b | 2019-10-25 16:37:50 +0530 | [diff] [blame] | 892 | { |
| 893 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 894 | "Failed to convert stoul.", |
| 895 | phosphor::logging::entry("ERROR=%s", e.what())); |
| 896 | continue; |
| 897 | } |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 898 | } |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 899 | |
AppaRao Puli | 37fde6b | 2019-10-25 16:37:50 +0530 | [diff] [blame] | 900 | return ipmi::responseSuccess(fwVerInfoList.size(), fwVerInfoList); |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 901 | } |
Punith Nadur Basavarajaiah | a8dd197 | 2020-08-19 18:05:44 +0000 | [diff] [blame] | 902 | |
| 903 | std::array<uint8_t, imageCount> getSecurityVersionInfo(const char* mtdDevBuf, |
| 904 | size_t svnVerOffsetInPfm, |
| 905 | size_t bkcVerOffsetInPfm) |
| 906 | { |
| 907 | constexpr size_t bufLength = 1; |
| 908 | std::array<uint8_t, imageCount> fwSecurityVersionBuf = {0}, temp; |
| 909 | constexpr uint8_t svnIndexValue = 0x00; |
| 910 | constexpr uint8_t bkcIndexValue = 0x01; |
| 911 | constexpr uint8_t tempIndexValue = 0x00; |
| 912 | try |
| 913 | { |
| 914 | SPIDev spiDev(mtdDevBuf); |
| 915 | spiDev.spiReadData(svnVerOffsetInPfm, bufLength, temp.data()); |
| 916 | fwSecurityVersionBuf.at(svnIndexValue) = temp.at(tempIndexValue); |
| 917 | spiDev.spiReadData(bkcVerOffsetInPfm, bufLength, temp.data()); |
| 918 | fwSecurityVersionBuf.at(bkcIndexValue) = temp.at(tempIndexValue); |
| 919 | } |
| 920 | catch (const std::exception& e) |
| 921 | { |
| 922 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 923 | "Exception caught in getSecurityVersionInfo", |
| 924 | phosphor::logging::entry("MSG=%s", e.what())); |
| 925 | fwSecurityVersionBuf = {0, 0}; |
| 926 | } |
| 927 | |
| 928 | return fwSecurityVersionBuf; |
| 929 | } |
| 930 | |
| 931 | ipmi::RspType< |
| 932 | uint8_t, // device ID |
| 933 | uint8_t, // Active Image Value |
| 934 | std::array<uint8_t, imageCount>, // Security version for Active Image |
| 935 | uint8_t, // recovery Image Value |
| 936 | std::array<uint8_t, imageCount>> // Security version for Recovery Image |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 937 | ipmiGetFwSecurityVersionInfo() |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 938 | { |
Punith Nadur Basavarajaiah | a8dd197 | 2020-08-19 18:05:44 +0000 | [diff] [blame] | 939 | static bool cacheFlag = false; |
| 940 | constexpr std::array<const char*, imageCount> mtdDevBuf = { |
| 941 | bmcActivePfmMTDDev, bmcRecoveryImgMTDDev}; |
| 942 | |
| 943 | // To avoid multiple reading from SPI device |
| 944 | if (!cacheFlag) |
| 945 | { |
| 946 | imgFwSecurityVersion[0] = getSecurityVersionInfo( |
| 947 | mtdDevBuf[0], svnActiveVerOffsetInPfm, bkcActiveVerOffsetInPfm); |
| 948 | imgFwSecurityVersion[1] = getSecurityVersionInfo( |
| 949 | mtdDevBuf[1], svnRecoveryVerOffsetInPfm, bkcRecoveryVerOffsetInPfm); |
| 950 | cacheFlag = true; |
| 951 | } |
| 952 | |
| 953 | constexpr uint8_t ActivePfmMTDDev = 0x00; |
| 954 | constexpr uint8_t RecoveryImgMTDDev = 0x01; |
| 955 | |
| 956 | return ipmi::responseSuccess( |
| 957 | imageCount, static_cast<uint8_t>(FWDeviceIDTag::bmcActiveImage), |
| 958 | imgFwSecurityVersion[ActivePfmMTDDev], |
| 959 | static_cast<uint8_t>(FWDeviceIDTag::bmcRecoveryImage), |
| 960 | imgFwSecurityVersion[RecoveryImgMTDDev]); |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 961 | } |
| 962 | |
Rajashekar Gade Reddy | c886406 | 2019-10-15 16:52:30 +0530 | [diff] [blame] | 963 | ipmi::RspType<std::array<uint8_t, certKeyLen>, |
| 964 | std::optional<std::array<uint8_t, cskSignatureLen>>> |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 965 | ipmiGetFwRootCertData(const ipmi::Context::ptr& ctx, uint8_t certId) |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 966 | { |
Rajashekar Gade Reddy | 5b1988b | 2019-12-18 19:17:26 +0530 | [diff] [blame] | 967 | bool isIPMBChannel = false; |
| 968 | |
| 969 | if (checkIPMBChannel(ctx, isIPMBChannel) != ipmi::ccSuccess) |
| 970 | { |
| 971 | return ipmi::responseUnspecifiedError(); |
| 972 | } |
| 973 | if (isIPMBChannel) |
| 974 | { |
| 975 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 976 | "Command not supported. Failed to get root certificate data."); |
| 977 | return ipmi::responseCommandNotAvailable(); |
| 978 | } |
| 979 | |
Rajashekar Gade Reddy | c886406 | 2019-10-15 16:52:30 +0530 | [diff] [blame] | 980 | size_t certKeyOffset = 0; |
| 981 | size_t cskSigOffset = 0; |
| 982 | std::string mtdDev; |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 983 | |
Rajashekar Gade Reddy | c886406 | 2019-10-15 16:52:30 +0530 | [diff] [blame] | 984 | switch (static_cast<FwGetRootCertDataTag>(certId)) |
| 985 | { |
| 986 | case FwGetRootCertDataTag::activeRootKey: |
| 987 | { |
| 988 | mtdDev = bmcActivePfmMTDDev; |
| 989 | certKeyOffset = rootkeyOffsetInPfm; |
| 990 | break; |
| 991 | } |
| 992 | case FwGetRootCertDataTag::recoveryRootKey: |
| 993 | { |
| 994 | mtdDev = bmcRecoveryImgMTDDev; |
| 995 | certKeyOffset = pfmBaseOffsetInImage + rootkeyOffsetInPfm; |
| 996 | break; |
| 997 | } |
| 998 | case FwGetRootCertDataTag::activeCSK: |
| 999 | { |
| 1000 | mtdDev = bmcActivePfmMTDDev; |
| 1001 | certKeyOffset = cskKeyOffsetInPfm; |
| 1002 | cskSigOffset = cskSignatureOffsetInPfm; |
| 1003 | break; |
| 1004 | } |
| 1005 | case FwGetRootCertDataTag::recoveryCSK: |
| 1006 | { |
| 1007 | mtdDev = bmcRecoveryImgMTDDev; |
| 1008 | certKeyOffset = pfmBaseOffsetInImage + cskKeyOffsetInPfm; |
| 1009 | cskSigOffset = pfmBaseOffsetInImage + cskSignatureOffsetInPfm; |
| 1010 | break; |
| 1011 | } |
| 1012 | default: |
| 1013 | { |
| 1014 | return ipmi::responseInvalidFieldRequest(); |
| 1015 | } |
| 1016 | } |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 1017 | |
Rajashekar Gade Reddy | c886406 | 2019-10-15 16:52:30 +0530 | [diff] [blame] | 1018 | std::array<uint8_t, certKeyLen> certKey = {0}; |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 1019 | |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 1020 | try |
| 1021 | { |
Rajashekar Gade Reddy | c886406 | 2019-10-15 16:52:30 +0530 | [diff] [blame] | 1022 | SPIDev spiDev(mtdDev); |
| 1023 | spiDev.spiReadData(certKeyOffset, certKeyLen, certKey.data()); |
| 1024 | |
| 1025 | if (cskSigOffset) |
| 1026 | { |
| 1027 | std::array<uint8_t, cskSignatureLen> cskSignature = {0}; |
| 1028 | spiDev.spiReadData(cskSigOffset, cskSignatureLen, |
| 1029 | cskSignature.data()); |
| 1030 | return ipmi::responseSuccess(certKey, cskSignature); |
| 1031 | } |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 1032 | } |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 1033 | catch (const std::exception& e) |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 1034 | { |
Rajashekar Gade Reddy | c886406 | 2019-10-15 16:52:30 +0530 | [diff] [blame] | 1035 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1036 | "Exception caught in ipmiGetFwRootCertData", |
| 1037 | phosphor::logging::entry("MSG=%s", e.what())); |
| 1038 | return ipmi::responseUnspecifiedError(); |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 1039 | } |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 1040 | |
Rajashekar Gade Reddy | c886406 | 2019-10-15 16:52:30 +0530 | [diff] [blame] | 1041 | return ipmi::responseSuccess(certKey, std::nullopt); |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 1042 | } |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 1043 | #endif // INTEL_PFR_ENABLED |
| 1044 | |
| 1045 | static constexpr uint8_t channelListSize = 3; |
| 1046 | /** @brief implements Maximum Firmware Transfer size command |
| 1047 | * @parameter |
| 1048 | * - none |
| 1049 | * @returns IPMI completion code plus response data |
| 1050 | * - count - channel count |
| 1051 | * - channelList - channel list information |
| 1052 | */ |
| 1053 | ipmi::RspType<uint8_t, // channel count |
| 1054 | std::array<std::tuple<uint8_t, uint32_t>, |
| 1055 | channelListSize> // Channel List |
| 1056 | > |
| 1057 | ipmiFirmwareMaxTransferSize() |
| 1058 | { |
| 1059 | constexpr size_t kcsMaxBufSize = 128; |
| 1060 | constexpr size_t rmcpPlusMaxBufSize = 50 * 1024; |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 1061 | // Byte 1 - Count (N) Number of devices data is being returned for. |
| 1062 | // Byte 2 - ID Tag 00 – reserved 01 – kcs 02 – rmcp+, 03 - ipmb |
| 1063 | // Byte 3-6 - transfer size (little endian) |
| 1064 | // Bytes - 7:(5xN) - Repeat of 2 through 6 |
| 1065 | constexpr std::array<std::tuple<uint8_t, uint32_t>, channelListSize> |
| 1066 | channelList = { |
| 1067 | {{static_cast<uint8_t>(ChannelIdTag::kcs), kcsMaxBufSize}, |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 1068 | {static_cast<uint8_t>(ChannelIdTag::rmcpPlus), |
| 1069 | rmcpPlusMaxBufSize}}}; |
| 1070 | |
| 1071 | return ipmi::responseSuccess(channelListSize, channelList); |
| 1072 | } |
| 1073 | |
| 1074 | ipmi::RspType<uint8_t, uint8_t> |
| 1075 | ipmiGetBmcExecutionContext(ipmi::Context::ptr ctx) |
| 1076 | { |
| 1077 | // Byte 1 - Current execution context |
| 1078 | // 0x10 - Linux OS, 0x11 - Bootloader, Forced-firmware updat mode |
| 1079 | // Byte 2 - Partition pointer |
| 1080 | // 0x01 - primary, 0x02 - secondary |
| 1081 | uint8_t partitionPtr = getActiveBootImage(ctx); |
| 1082 | |
| 1083 | return ipmi::responseSuccess( |
| 1084 | static_cast<uint8_t>(BmcExecutionContext::linuxOs), partitionPtr); |
| 1085 | } |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 1086 | /** @brief Get Firmware Update Random Number |
| 1087 | * |
| 1088 | * This function generate the random number used for |
| 1089 | * setting the firmware update mode as authentication key. |
| 1090 | * |
Rajashekar Gade Reddy | 5b1988b | 2019-12-18 19:17:26 +0530 | [diff] [blame] | 1091 | * @param[in] ctx - context of current session |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 1092 | * @returns IPMI completion code along with |
| 1093 | * - random number |
| 1094 | **/ |
| 1095 | ipmi::RspType<std::array<uint8_t, fwRandomNumLength>> |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 1096 | ipmiGetFwUpdateRandomNumber(const ipmi::Context::ptr& ctx) |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 1097 | { |
| 1098 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 1099 | "Generate FW update random number"); |
Rajashekar Gade Reddy | 5b1988b | 2019-12-18 19:17:26 +0530 | [diff] [blame] | 1100 | bool isIPMBChannel = false; |
| 1101 | |
| 1102 | if (checkIPMBChannel(ctx, isIPMBChannel) != ipmi::ccSuccess) |
| 1103 | { |
| 1104 | return ipmi::responseUnspecifiedError(); |
| 1105 | } |
| 1106 | if (isIPMBChannel) |
| 1107 | { |
| 1108 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 1109 | "Channel not supported. Failed to fetch FW update random number"); |
| 1110 | return ipmi::responseCommandNotAvailable(); |
| 1111 | } |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 1112 | std::random_device rd; |
| 1113 | std::default_random_engine gen(rd()); |
| 1114 | std::uniform_int_distribution<> dist{0, 255}; |
| 1115 | |
| 1116 | fwRandomNumGenTs = std::chrono::steady_clock::now(); |
| 1117 | |
| 1118 | for (int i = 0; i < fwRandomNumLength; i++) |
| 1119 | { |
| 1120 | fwRandomNum[i] = dist(gen); |
| 1121 | } |
| 1122 | |
| 1123 | return ipmi::responseSuccess(fwRandomNum); |
| 1124 | } |
| 1125 | |
| 1126 | /** @brief Set Firmware Update Mode |
| 1127 | * |
| 1128 | * This function sets BMC into firmware update mode |
| 1129 | * after validating Random number obtained from the Get |
| 1130 | * Firmware Update Random Number command |
| 1131 | * |
Rajashekar Gade Reddy | 5b1988b | 2019-12-18 19:17:26 +0530 | [diff] [blame] | 1132 | * @param[in] ctx - context of current session |
| 1133 | * @parameter randNum - Random number(token) |
| 1134 | * @returns IPMI completion code |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 1135 | **/ |
| 1136 | ipmi::RspType<> |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 1137 | ipmiSetFirmwareUpdateMode(const ipmi::Context::ptr& ctx, |
| 1138 | std::array<uint8_t, fwRandomNumLength>& randNum) |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 1139 | { |
| 1140 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 1141 | "Start FW update mode"); |
Rajashekar Gade Reddy | 5b1988b | 2019-12-18 19:17:26 +0530 | [diff] [blame] | 1142 | |
| 1143 | bool isIPMBChannel = false; |
| 1144 | |
| 1145 | if (checkIPMBChannel(ctx, isIPMBChannel) != ipmi::ccSuccess) |
| 1146 | { |
| 1147 | return ipmi::responseUnspecifiedError(); |
| 1148 | } |
| 1149 | if (isIPMBChannel) |
| 1150 | { |
| 1151 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 1152 | "Channel not supported. Failed to set FW update mode"); |
| 1153 | return ipmi::responseCommandNotAvailable(); |
| 1154 | } |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 1155 | /* Firmware Update Random number is valid for 30 seconds only */ |
| 1156 | auto timeElapsed = (std::chrono::steady_clock::now() - fwRandomNumGenTs); |
| 1157 | if (std::chrono::duration_cast<std::chrono::microseconds>(timeElapsed) |
| 1158 | .count() > std::chrono::duration_cast<std::chrono::microseconds>( |
| 1159 | fwRandomNumExpirySeconds) |
| 1160 | .count()) |
| 1161 | { |
| 1162 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 1163 | "Firmware update random number expired."); |
| 1164 | return ipmi::responseInvalidFieldRequest(); |
| 1165 | } |
| 1166 | |
| 1167 | /* Validate random number */ |
| 1168 | for (int i = 0; i < fwRandomNumLength; i++) |
| 1169 | { |
| 1170 | if (fwRandomNum[i] != randNum[i]) |
| 1171 | { |
| 1172 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 1173 | "Invalid random number specified."); |
| 1174 | return ipmi::responseInvalidFieldRequest(); |
| 1175 | } |
| 1176 | } |
| 1177 | |
| 1178 | try |
| 1179 | { |
| 1180 | if (getFirmwareUpdateMode()) |
| 1181 | { |
| 1182 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 1183 | "Already firmware update is in progress."); |
| 1184 | return ipmi::responseBusy(); |
| 1185 | } |
| 1186 | } |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 1187 | catch (const std::exception& e) |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 1188 | { |
| 1189 | return ipmi::responseUnspecifiedError(); |
| 1190 | } |
| 1191 | |
| 1192 | // FIXME? c++ doesn't off an option for exclusive file creation |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 1193 | FILE* fp = fopen(firmwareBufferFile, "wx"); |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 1194 | if (!fp) |
| 1195 | { |
| 1196 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 1197 | "Unable to open file."); |
| 1198 | return ipmi::responseUnspecifiedError(); |
| 1199 | } |
| 1200 | fclose(fp); |
| 1201 | |
| 1202 | try |
| 1203 | { |
| 1204 | setFirmwareUpdateMode(true); |
| 1205 | } |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 1206 | catch (const std::exception& e) |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 1207 | { |
| 1208 | unlink(firmwareBufferFile); |
| 1209 | return ipmi::responseUnspecifiedError(); |
| 1210 | } |
| 1211 | |
| 1212 | return ipmi::responseSuccess(); |
| 1213 | } |
| 1214 | |
| 1215 | /** @brief implements exit firmware update mode command |
| 1216 | * @param None |
| 1217 | * |
| 1218 | * @returns IPMI completion code |
| 1219 | */ |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 1220 | ipmi::RspType<> ipmiExitFirmwareUpdateMode(const ipmi::Context::ptr& ctx) |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 1221 | { |
| 1222 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 1223 | "Exit FW update mode"); |
Rajashekar Gade Reddy | 5b1988b | 2019-12-18 19:17:26 +0530 | [diff] [blame] | 1224 | bool isIPMBChannel = false; |
| 1225 | |
| 1226 | if (checkIPMBChannel(ctx, isIPMBChannel) != ipmi::ccSuccess) |
| 1227 | { |
| 1228 | return ipmi::responseUnspecifiedError(); |
| 1229 | } |
| 1230 | if (isIPMBChannel) |
| 1231 | { |
| 1232 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 1233 | "Command not supported. Failed to exit firmware update mode"); |
| 1234 | return ipmi::responseCommandNotAvailable(); |
| 1235 | } |
| 1236 | |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 1237 | switch (fwUpdateStatus.getState()) |
| 1238 | { |
| 1239 | case FwUpdateStatusCache::fwStateInit: |
| 1240 | case FwUpdateStatusCache::fwStateIdle: |
| 1241 | return ipmi::responseInvalidFieldRequest(); |
| 1242 | break; |
| 1243 | case FwUpdateStatusCache::fwStateDownload: |
| 1244 | case FwUpdateStatusCache::fwStateVerify: |
| 1245 | break; |
| 1246 | case FwUpdateStatusCache::fwStateProgram: |
| 1247 | break; |
| 1248 | case FwUpdateStatusCache::fwStateUpdateSuccess: |
| 1249 | case FwUpdateStatusCache::fwStateError: |
| 1250 | break; |
| 1251 | case FwUpdateStatusCache::fwStateAcCycleRequired: |
| 1252 | return ipmi::responseInvalidFieldRequest(); |
| 1253 | break; |
| 1254 | } |
| 1255 | fwUpdateStatus.firmwareUpdateAbortState(); |
| 1256 | |
| 1257 | try |
| 1258 | { |
| 1259 | setFirmwareUpdateMode(false); |
| 1260 | } |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 1261 | catch (const std::exception& e) |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 1262 | { |
| 1263 | return ipmi::responseUnspecifiedError(); |
| 1264 | } |
| 1265 | |
| 1266 | return ipmi::responseSuccess(); |
| 1267 | } |
| 1268 | |
| 1269 | /** @brief implements Get/Set Firmware Update Control |
Rajashekar Gade Reddy | 5b1988b | 2019-12-18 19:17:26 +0530 | [diff] [blame] | 1270 | * @param[in] ctx - context of current session |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 1271 | * @parameter |
| 1272 | * - Byte 1: Control Byte |
| 1273 | * - Byte 2: Firmware filename length (Optional) |
| 1274 | * - Byte 3:N: Firmware filename data (Optional) |
| 1275 | * @returns IPMI completion code plus response data |
| 1276 | * - Byte 2: Current control status |
| 1277 | **/ |
| 1278 | ipmi::RspType<bool, bool, bool, bool, uint4_t> |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 1279 | ipmiGetSetFirmwareUpdateControl(const ipmi::Context::ptr& ctx, |
Rajashekar Gade Reddy | 5b1988b | 2019-12-18 19:17:26 +0530 | [diff] [blame] | 1280 | const uint8_t controlReq, |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 1281 | const std::optional<std::string>& fileName) |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 1282 | { |
Rajashekar Gade Reddy | 5b1988b | 2019-12-18 19:17:26 +0530 | [diff] [blame] | 1283 | bool isIPMBChannel = false; |
| 1284 | |
| 1285 | if (checkIPMBChannel(ctx, isIPMBChannel) != ipmi::ccSuccess) |
| 1286 | { |
| 1287 | return ipmi::responseUnspecifiedError(); |
| 1288 | } |
| 1289 | if (isIPMBChannel) |
| 1290 | { |
| 1291 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 1292 | "Channel not supported. Failed to get or set FW update control"); |
| 1293 | return ipmi::responseCommandNotAvailable(); |
| 1294 | } |
| 1295 | |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 1296 | static std::string fwXferUriPath; |
| 1297 | static bool imageTransferStarted = false; |
| 1298 | static bool imageTransferCompleted = false; |
| 1299 | static bool imageTransferAborted = false; |
| 1300 | |
| 1301 | if ((controlReq != |
| 1302 | static_cast<uint8_t>(FwUpdateCtrlReq::setFirmwareFilename)) && |
| 1303 | (fileName)) |
| 1304 | { |
| 1305 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1306 | "Invalid request field (Filename)."); |
| 1307 | return ipmi::responseInvalidFieldRequest(); |
| 1308 | } |
| 1309 | |
| 1310 | static bool usbAttached = getUsbStatus(); |
| 1311 | |
| 1312 | switch (static_cast<FwUpdateCtrlReq>(controlReq)) |
| 1313 | { |
| 1314 | case FwUpdateCtrlReq::getCurrentControlStatus: |
| 1315 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 1316 | "ipmiGetSetFirmwareUpdateControl: Get status"); |
| 1317 | break; |
| 1318 | case FwUpdateCtrlReq::imageTransferStart: |
| 1319 | { |
| 1320 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 1321 | "ipmiGetSetFirmwareUpdateControl: Set transfer start"); |
| 1322 | imageTransferStarted = true; |
| 1323 | // reset buffer to empty (truncate file) |
| 1324 | std::ofstream out(firmwareBufferFile, |
| 1325 | std::ofstream::binary | std::ofstream::trunc); |
| 1326 | fwXferUriPath = std::string("file://") + firmwareBufferFile; |
| 1327 | if (xferHashCheck) |
| 1328 | { |
| 1329 | xferHashCheck->clear(); |
| 1330 | } |
| 1331 | // Setting state to download |
| 1332 | fwUpdateStatus.setState( |
| 1333 | static_cast<uint8_t>(FwUpdateStatusCache::fwStateDownload)); |
| 1334 | #ifdef INTEL_PFR_ENABLED |
| 1335 | imgLength = 0; |
| 1336 | imgType = 0; |
| 1337 | block0Mapped = false; |
Rajashekar Gade Reddy | c886406 | 2019-10-15 16:52:30 +0530 | [diff] [blame] | 1338 | #endif |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 1339 | } |
| 1340 | break; |
| 1341 | case FwUpdateCtrlReq::imageTransferComplete: |
| 1342 | { |
| 1343 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 1344 | "ipmiGetSetFirmwareUpdateControl: Set transfer complete."); |
| 1345 | if (usbAttached) |
| 1346 | { |
| 1347 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1348 | "USB should be detached to perform this operation."); |
| 1349 | return ipmi::responseNotSupportedInPresentState(); |
| 1350 | } |
| 1351 | // finish transfer based on URI |
| 1352 | if (!transferFirmwareFromUri(fwXferUriPath)) |
| 1353 | { |
| 1354 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1355 | "transferFirmwareFromUri failed."); |
| 1356 | return ipmi::responseUnspecifiedError(); |
| 1357 | } |
| 1358 | // transfer complete |
| 1359 | if (xferHashCheck) |
| 1360 | { |
| 1361 | if (TransferHashCheck::HashCheck::sha2Success != |
| 1362 | xferHashCheck->verify()) |
| 1363 | { |
| 1364 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1365 | "xferHashCheck failed."); |
| 1366 | return ipmi::responseUnspecifiedError(); |
| 1367 | } |
| 1368 | } |
| 1369 | // Set state to verify and start the update |
| 1370 | fwUpdateStatus.setState( |
| 1371 | static_cast<uint8_t>(FwUpdateStatusCache::fwStateVerify)); |
| 1372 | // start the request |
| 1373 | if (!startFirmwareUpdate(firmwareBufferFile)) |
| 1374 | { |
| 1375 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1376 | "startFirmwareUpdate failed."); |
| 1377 | return ipmi::responseUnspecifiedError(); |
| 1378 | } |
| 1379 | imageTransferCompleted = true; |
| 1380 | } |
| 1381 | break; |
| 1382 | case FwUpdateCtrlReq::imageTransferAbort: |
| 1383 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 1384 | "ipmiGetSetFirmwareUpdateControl: Set transfer abort."); |
| 1385 | if (usbAttached) |
| 1386 | { |
| 1387 | if (detachUsbDevice()) |
| 1388 | { |
| 1389 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1390 | "Detach USB device failed."); |
| 1391 | return ipmi::responseUsbAttachOrDetachFailed(); |
| 1392 | } |
| 1393 | usbAttached = false; |
| 1394 | } |
| 1395 | // During abort request reset the state to Init by cleaning update |
| 1396 | // file. |
| 1397 | fwUpdateStatus.firmwareUpdateAbortState(); |
| 1398 | imageTransferAborted = true; |
| 1399 | break; |
| 1400 | case FwUpdateCtrlReq::setFirmwareFilename: |
| 1401 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 1402 | "ipmiGetSetFirmwareUpdateControl: Set filename."); |
| 1403 | if (!fileName || ((*fileName).length() == 0)) |
| 1404 | { |
| 1405 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1406 | "Invalid Filename specified."); |
| 1407 | return ipmi::responseInvalidFieldRequest(); |
| 1408 | } |
| 1409 | |
| 1410 | fwXferUriPath = *fileName; |
| 1411 | break; |
| 1412 | case FwUpdateCtrlReq::attachUsbDevice: |
| 1413 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 1414 | "ipmiGetSetFirmwareUpdateControl: Attach USB device."); |
| 1415 | if (usbAttached) |
| 1416 | { |
| 1417 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1418 | "USB device is already attached."); |
| 1419 | return ipmi::responseInvalidFieldRequest(); |
| 1420 | } |
| 1421 | if (attachUsbDevice()) |
| 1422 | { |
| 1423 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1424 | "Attach USB device failed."); |
| 1425 | return ipmi::responseUsbAttachOrDetachFailed(); |
| 1426 | } |
| 1427 | usbAttached = true; |
| 1428 | break; |
| 1429 | case FwUpdateCtrlReq::detachUsbDevice: |
| 1430 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 1431 | "ipmiGetSetFirmwareUpdateControl: Detach USB device."); |
| 1432 | if (!usbAttached) |
| 1433 | { |
| 1434 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1435 | "USB device is not attached."); |
| 1436 | return ipmi::responseInvalidFieldRequest(); |
| 1437 | } |
| 1438 | if (detachUsbDevice()) |
| 1439 | { |
| 1440 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1441 | "Detach USB device failed."); |
| 1442 | return ipmi::responseUsbAttachOrDetachFailed(); |
| 1443 | } |
| 1444 | usbAttached = false; |
| 1445 | break; |
| 1446 | default: |
| 1447 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1448 | "Invalid control option specified."); |
| 1449 | return ipmi::responseInvalidFieldRequest(); |
| 1450 | } |
| 1451 | |
| 1452 | return ipmi::responseSuccess(imageTransferStarted, imageTransferCompleted, |
| 1453 | imageTransferAborted, usbAttached, uint4_t(0)); |
| 1454 | } |
| 1455 | |
| 1456 | /** @brief implements firmware get status command |
| 1457 | * @parameter |
| 1458 | * - none |
| 1459 | * @returns IPMI completion code plus response data |
| 1460 | * - status - processing status |
| 1461 | * - percentage - percentage completion |
| 1462 | * - check - channel integrity check status |
| 1463 | **/ |
| 1464 | ipmi::RspType<uint8_t, // status |
| 1465 | uint8_t, // percentage |
| 1466 | uint8_t // check |
| 1467 | > |
| 1468 | ipmiGetFirmwareUpdateStatus() |
| 1469 | |
| 1470 | { |
| 1471 | // Byte 1 - status (0=init, 1=idle, 2=download, 3=validate, 4=write, |
| 1472 | // 5=ready, f=error, 83=ac cycle required) |
| 1473 | // Byte 2 - percent |
| 1474 | // Byte 3 - integrity check status (0=none, 1=req, 2=sha2ok, e2=sha2fail) |
| 1475 | uint8_t status = fwUpdateStatus.getState(); |
| 1476 | uint8_t percent = fwUpdateStatus.percent(); |
| 1477 | uint8_t check = xferHashCheck ? xferHashCheck->status() : 0; |
| 1478 | |
| 1479 | // Status code. |
| 1480 | return ipmi::responseSuccess(status, percent, check); |
| 1481 | } |
| 1482 | |
| 1483 | ipmi::RspType<bool, bool, bool, uint5_t> ipmiSetFirmwareUpdateOptions( |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 1484 | const ipmi::Context::ptr& ctx, bool noDowngradeMask, bool deferRestartMask, |
Rajashekar Gade Reddy | 5b1988b | 2019-12-18 19:17:26 +0530 | [diff] [blame] | 1485 | bool sha2CheckMask, uint5_t reserved1, bool noDowngrade, bool deferRestart, |
| 1486 | bool sha2Check, uint5_t reserved2, |
| 1487 | std::optional<std::vector<uint8_t>> integrityCheckVal) |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 1488 | { |
| 1489 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 1490 | "Set firmware update options."); |
Rajashekar Gade Reddy | 5b1988b | 2019-12-18 19:17:26 +0530 | [diff] [blame] | 1491 | bool isIPMBChannel = false; |
| 1492 | |
| 1493 | if (checkIPMBChannel(ctx, isIPMBChannel) != ipmi::ccSuccess) |
| 1494 | { |
| 1495 | return ipmi::responseUnspecifiedError(); |
| 1496 | } |
| 1497 | if (isIPMBChannel) |
| 1498 | { |
| 1499 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 1500 | "Channel not supported. Failed to set firmware update options"); |
| 1501 | return ipmi::responseCommandNotAvailable(); |
| 1502 | } |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 1503 | bool noDowngradeState = fwUpdateStatus.getInhibitDowngrade(); |
| 1504 | bool deferRestartState = fwUpdateStatus.getDeferRestart(); |
| 1505 | bool sha2CheckState = xferHashCheck ? true : false; |
| 1506 | |
| 1507 | if (noDowngradeMask && (noDowngradeState != noDowngrade)) |
| 1508 | { |
| 1509 | fwUpdateStatus.setInhibitDowngrade(noDowngrade); |
| 1510 | noDowngradeState = noDowngrade; |
| 1511 | } |
| 1512 | if (deferRestartMask && (deferRestartState != deferRestart)) |
| 1513 | { |
| 1514 | fwUpdateStatus.setDeferRestart(deferRestart); |
| 1515 | deferRestartState = deferRestart; |
| 1516 | } |
| 1517 | if (sha2CheckMask) |
| 1518 | { |
| 1519 | if (sha2Check) |
| 1520 | { |
| 1521 | auto hashSize = EVP_MD_size(EVP_sha256()); |
| 1522 | if ((*integrityCheckVal).size() != hashSize) |
| 1523 | { |
| 1524 | phosphor::logging::log<phosphor::logging::level::DEBUG>( |
| 1525 | "Invalid size of Hash specified."); |
| 1526 | return ipmi::responseInvalidFieldRequest(); |
| 1527 | } |
| 1528 | xferHashCheck = std::make_shared<TransferHashCheck>(); |
| 1529 | xferHashCheck->init(*integrityCheckVal); |
| 1530 | } |
| 1531 | else |
| 1532 | { |
| 1533 | // delete the xferHashCheck object |
| 1534 | xferHashCheck.reset(); |
| 1535 | } |
| 1536 | sha2CheckState = sha2CheckMask; |
| 1537 | } |
| 1538 | return ipmi::responseSuccess(noDowngradeState, deferRestartState, |
| 1539 | sha2CheckState, reserved1); |
| 1540 | } |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 1541 | |
Rajashekar Gade Reddy | 3ec2620 | 2019-10-29 14:10:00 +0530 | [diff] [blame] | 1542 | ipmi::RspType<uint32_t> |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 1543 | ipmiFwImageWriteData(const std::vector<uint8_t>& writeData) |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 1544 | { |
Rajashekar Gade Reddy | 3ec2620 | 2019-10-29 14:10:00 +0530 | [diff] [blame] | 1545 | const uint8_t ccCmdNotSupportedInPresentState = 0xD5; |
| 1546 | size_t writeDataLen = writeData.size(); |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 1547 | |
Rajashekar Gade Reddy | 3ec2620 | 2019-10-29 14:10:00 +0530 | [diff] [blame] | 1548 | if (!writeDataLen) |
| 1549 | { |
| 1550 | return ipmi::responseReqDataLenInvalid(); |
| 1551 | } |
| 1552 | |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 1553 | if (fwUpdateStatus.getState() != FwUpdateStatusCache::fwStateDownload) |
Rajashekar Gade Reddy | 3ec2620 | 2019-10-29 14:10:00 +0530 | [diff] [blame] | 1554 | { |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 1555 | phosphor::logging::log<phosphor::logging::level::ERR>( |
Rajashekar Gade Reddy | 3ec2620 | 2019-10-29 14:10:00 +0530 | [diff] [blame] | 1556 | "Invalid firmware update state."); |
| 1557 | return ipmi::response(ccCmdNotSupportedInPresentState); |
| 1558 | } |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 1559 | |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 1560 | std::ofstream out(firmwareBufferFile, |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 1561 | std::ofstream::binary | std::ofstream::app); |
| 1562 | if (!out) |
| 1563 | { |
Rajashekar Gade Reddy | 3ec2620 | 2019-10-29 14:10:00 +0530 | [diff] [blame] | 1564 | phosphor::logging::log<phosphor::logging::level::DEBUG>( |
| 1565 | "Error while opening file."); |
| 1566 | return ipmi::responseUnspecifiedError(); |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 1567 | } |
Rajashekar Gade Reddy | df5e327 | 2019-09-05 18:10:53 +0530 | [diff] [blame] | 1568 | |
| 1569 | uint64_t fileDataLen = out.tellp(); |
Rajashekar Gade Reddy | 3ec2620 | 2019-10-29 14:10:00 +0530 | [diff] [blame] | 1570 | |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 1571 | if ((fileDataLen + writeDataLen) > maxFirmwareImageSize) |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 1572 | { |
Rajashekar Gade Reddy | 3ec2620 | 2019-10-29 14:10:00 +0530 | [diff] [blame] | 1573 | phosphor::logging::log<phosphor::logging::level::DEBUG>( |
| 1574 | "Firmware image size exceeds the limit"); |
| 1575 | return ipmi::responseInvalidFieldRequest(); |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 1576 | } |
Rajashekar Gade Reddy | 3ec2620 | 2019-10-29 14:10:00 +0530 | [diff] [blame] | 1577 | |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 1578 | const char* data = reinterpret_cast<const char*>(writeData.data()); |
Rajashekar Gade Reddy | 3ec2620 | 2019-10-29 14:10:00 +0530 | [diff] [blame] | 1579 | out.write(data, writeDataLen); |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 1580 | out.close(); |
Rajashekar Gade Reddy | 3ec2620 | 2019-10-29 14:10:00 +0530 | [diff] [blame] | 1581 | |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 1582 | if (xferHashCheck) |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 1583 | { |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 1584 | xferHashCheck->hash(writeData); |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 1585 | } |
| 1586 | |
Rajashekar Gade Reddy | df5e327 | 2019-09-05 18:10:53 +0530 | [diff] [blame] | 1587 | #ifdef INTEL_PFR_ENABLED |
| 1588 | /* PFR image block 0 - As defined in HAS */ |
| 1589 | struct PFRImageBlock0 |
| 1590 | { |
| 1591 | uint32_t tag; |
| 1592 | uint32_t pcLength; |
| 1593 | uint32_t pcType; |
| 1594 | uint32_t reserved1; |
| 1595 | uint8_t hash256[32]; |
| 1596 | uint8_t hash384[48]; |
| 1597 | uint8_t reserved2[32]; |
| 1598 | } __attribute__((packed)); |
| 1599 | |
| 1600 | /* Get the PFR block 0 data and read the uploaded image |
| 1601 | * information( Image type, length etc) */ |
Rajashekar Gade Reddy | 3ec2620 | 2019-10-29 14:10:00 +0530 | [diff] [blame] | 1602 | if (((fileDataLen + writeDataLen) >= sizeof(PFRImageBlock0)) && |
| 1603 | (!block0Mapped)) |
Rajashekar Gade Reddy | df5e327 | 2019-09-05 18:10:53 +0530 | [diff] [blame] | 1604 | { |
| 1605 | struct PFRImageBlock0 block0Data = {0}; |
| 1606 | |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 1607 | std::ifstream inFile(firmwareBufferFile, |
Rajashekar Gade Reddy | df5e327 | 2019-09-05 18:10:53 +0530 | [diff] [blame] | 1608 | std::ios::binary | std::ios::in); |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 1609 | inFile.read(reinterpret_cast<char*>(&block0Data), sizeof(block0Data)); |
Rajashekar Gade Reddy | df5e327 | 2019-09-05 18:10:53 +0530 | [diff] [blame] | 1610 | inFile.close(); |
| 1611 | |
| 1612 | uint32_t magicNum = block0Data.tag; |
| 1613 | |
| 1614 | /* Validate the magic number */ |
| 1615 | if (magicNum != perBlock0MagicNum) |
| 1616 | { |
Rajashekar Gade Reddy | 3ec2620 | 2019-10-29 14:10:00 +0530 | [diff] [blame] | 1617 | phosphor::logging::log<phosphor::logging::level::DEBUG>( |
| 1618 | "PFR image magic number not matched"); |
| 1619 | return ipmi::responseInvalidFieldRequest(); |
Rajashekar Gade Reddy | df5e327 | 2019-09-05 18:10:53 +0530 | [diff] [blame] | 1620 | } |
| 1621 | // Note:imgLength, imgType and block0Mapped are in global scope, as |
| 1622 | // these are used in cascaded updates. |
| 1623 | imgLength = block0Data.pcLength; |
| 1624 | imgType = block0Data.pcType; |
| 1625 | block0Mapped = true; |
| 1626 | } |
| 1627 | #endif // end of INTEL_PFR_ENABLED |
Rajashekar Gade Reddy | 3ec2620 | 2019-10-29 14:10:00 +0530 | [diff] [blame] | 1628 | return ipmi::responseSuccess(writeDataLen); |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 1629 | } |
| 1630 | |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 1631 | static void registerFirmwareFunctions() |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 1632 | { |
| 1633 | // guarantee that we start with an already timed out timestamp |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 1634 | fwRandomNumGenTs = |
| 1635 | std::chrono::steady_clock::now() - fwRandomNumExpirySeconds; |
| 1636 | fwUpdateStatus.setState( |
| 1637 | static_cast<uint8_t>(FwUpdateStatusCache::fwStateInit)); |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 1638 | |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 1639 | unlink(firmwareBufferFile); |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 1640 | |
AppaRao Puli | 37fde6b | 2019-10-25 16:37:50 +0530 | [diff] [blame] | 1641 | #ifdef INTEL_PFR_ENABLED |
| 1642 | // Following commands are supported only for PFR enabled platforms |
| 1643 | // CMD:0x20 - Get Firmware Version Information |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 1644 | // CMD:0x21 - Get Firmware Security Version Information |
| 1645 | // CMD:0x25 - Get Root Certificate Data |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 1646 | |
AppaRao Puli | 37fde6b | 2019-10-25 16:37:50 +0530 | [diff] [blame] | 1647 | // get firmware version information |
| 1648 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnFirmware, |
| 1649 | ipmi::firmware::cmdGetFwVersionInfo, |
| 1650 | ipmi::Privilege::Admin, ipmiGetFwVersionInfo); |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 1651 | |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 1652 | // get firmware security version information |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 1653 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnFirmware, |
| 1654 | ipmi::firmware::cmdGetFwSecurityVersionInfo, |
| 1655 | ipmi::Privilege::Admin, ipmiGetFwSecurityVersionInfo); |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 1656 | |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 1657 | // get root certificate data |
Rajashekar Gade Reddy | c886406 | 2019-10-15 16:52:30 +0530 | [diff] [blame] | 1658 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnFirmware, |
| 1659 | ipmi::firmware::cmdFwGetRootCertData, |
| 1660 | ipmi::Privilege::Admin, ipmiGetFwRootCertData); |
| 1661 | #endif |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 1662 | |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 1663 | // get firmware update channel information (max transfer sizes) |
| 1664 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnFirmware, |
| 1665 | ipmi::firmware::cmdGetFwUpdateChannelInfo, |
| 1666 | ipmi::Privilege::Admin, ipmiFirmwareMaxTransferSize); |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 1667 | |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 1668 | // get bmc execution context |
| 1669 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnFirmware, |
| 1670 | ipmi::firmware::cmdGetBmcExecutionContext, |
| 1671 | ipmi::Privilege::Admin, ipmiGetBmcExecutionContext); |
| 1672 | |
| 1673 | // Get Firmware Update Random number |
| 1674 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnFirmware, |
| 1675 | ipmi::firmware::cmdGetFwUpdateRandomNumber, |
| 1676 | ipmi::Privilege::Admin, ipmiGetFwUpdateRandomNumber); |
| 1677 | |
| 1678 | // Set Firmware Update Mode |
| 1679 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnFirmware, |
| 1680 | ipmi::firmware::cmdSetFirmwareUpdateMode, |
AppaRao Puli | 4b3e1c7 | 2019-10-16 20:53:09 +0530 | [diff] [blame] | 1681 | ipmi::Privilege::Admin, ipmiSetFirmwareUpdateMode); |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 1682 | |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 1683 | // Exit Firmware Update Mode |
anil kumar appana | b57098a | 2019-05-28 16:22:33 +0000 | [diff] [blame] | 1684 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnFirmware, |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 1685 | ipmi::firmware::cmdExitFirmwareUpdateMode, |
| 1686 | ipmi::Privilege::Admin, ipmiExitFirmwareUpdateMode); |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 1687 | |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 1688 | // Get/Set Firmware Update Control |
| 1689 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnFirmware, |
| 1690 | ipmi::firmware::cmdGetSetFwUpdateControl, |
| 1691 | ipmi::Privilege::Admin, |
| 1692 | ipmiGetSetFirmwareUpdateControl); |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 1693 | |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 1694 | // Get Firmware Update Status |
| 1695 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnFirmware, |
| 1696 | ipmi::firmware::cmdGetFirmwareUpdateStatus, |
| 1697 | ipmi::Privilege::Admin, ipmiGetFirmwareUpdateStatus); |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 1698 | |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 1699 | // Set Firmware Update Options |
| 1700 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnFirmware, |
| 1701 | ipmi::firmware::cmdSetFirmwareUpdateOptions, |
| 1702 | ipmi::Privilege::Admin, ipmiSetFirmwareUpdateOptions); |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 1703 | // write image data |
Rajashekar Gade Reddy | 3ec2620 | 2019-10-29 14:10:00 +0530 | [diff] [blame] | 1704 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnFirmware, |
| 1705 | ipmi::firmware::cmdFwImageWriteData, |
| 1706 | ipmi::Privilege::Admin, ipmiFwImageWriteData); |
Vernon Mauery | 52ce662 | 2019-05-22 09:19:46 -0700 | [diff] [blame] | 1707 | return; |
| 1708 | } |