xref: /openbmc/phosphor-bmc-code-mgmt/i2c-vr/i2cvr_device.cpp (revision ee55117464c86f0fe4483cd86f82da0501e896e1)
17e446a40SChristopher Meis #include "i2cvr_device.hpp"
27e446a40SChristopher Meis 
37e446a40SChristopher Meis #include <phosphor-logging/lg2.hpp>
47e446a40SChristopher Meis #include <sdbusplus/async.hpp>
57e446a40SChristopher Meis #include <sdbusplus/async/context.hpp>
67e446a40SChristopher Meis 
77e446a40SChristopher Meis namespace phosphor::software::i2c_vr::device
87e446a40SChristopher Meis {
97e446a40SChristopher Meis 
updateDevice(const uint8_t * image,size_t imageSize)107e446a40SChristopher Meis sdbusplus::async::task<bool> I2CVRDevice::updateDevice(const uint8_t* image,
117e446a40SChristopher Meis                                                        size_t imageSize)
127e446a40SChristopher Meis {
137e446a40SChristopher Meis     setUpdateProgress(20);
147e446a40SChristopher Meis 
157e446a40SChristopher Meis     // NOLINTBEGIN(clang-analyzer-core.uninitialized.Branch)
16*fd34144bSChristopher Meis     if (!(co_await vrInterface->verifyImage(image, imageSize)))
177e446a40SChristopher Meis     //  NOLINTEND(clang-analyzer-core.uninitialized.Branch)
187e446a40SChristopher Meis     {
197e446a40SChristopher Meis         co_return false;
207e446a40SChristopher Meis     }
217e446a40SChristopher Meis 
227e446a40SChristopher Meis     setUpdateProgress(50);
237e446a40SChristopher Meis 
247e446a40SChristopher Meis     // NOLINTBEGIN(clang-analyzer-core.uninitialized.Branch)
25*fd34144bSChristopher Meis     if (!(co_await vrInterface->updateFirmware(false)))
267e446a40SChristopher Meis     //  NOLINTEND(clang-analyzer-core.uninitialized.Branch)
277e446a40SChristopher Meis     {
287e446a40SChristopher Meis         co_return false;
297e446a40SChristopher Meis     }
307e446a40SChristopher Meis 
317e446a40SChristopher Meis     setUpdateProgress(100);
327e446a40SChristopher Meis 
337e446a40SChristopher Meis     lg2::info("Successfully updated VR {NAME}", "NAME", config.configName);
347e446a40SChristopher Meis 
357e446a40SChristopher Meis     co_return true;
367e446a40SChristopher Meis }
377e446a40SChristopher Meis 
getVersion(uint32_t * sum) const387e446a40SChristopher Meis sdbusplus::async::task<bool> I2CVRDevice::getVersion(uint32_t* sum) const
397e446a40SChristopher Meis {
407e446a40SChristopher Meis     // NOLINTBEGIN(clang-analyzer-core.uninitialized.Branch)
417e446a40SChristopher Meis     if (!(co_await this->vrInterface->getCRC(sum)))
427e446a40SChristopher Meis     //  NOLINTEND(clang-analyzer-core.uninitialized.Branch)
437e446a40SChristopher Meis     {
447e446a40SChristopher Meis         co_return false;
457e446a40SChristopher Meis     }
467e446a40SChristopher Meis     co_return true;
477e446a40SChristopher Meis }
487e446a40SChristopher Meis 
497e446a40SChristopher Meis } // namespace phosphor::software::i2c_vr::device
50