blob: 37c8cad25001780322bcd748c7128cf2ead80d3a [file] [log] [blame]
Christopher Meis7e446a42024-10-22 09:36:41 +02001#include "i2cvr_device.hpp"
2
3#include <phosphor-logging/lg2.hpp>
4#include <sdbusplus/async.hpp>
5#include <sdbusplus/async/context.hpp>
6
7namespace phosphor::software::i2c_vr::device
8{
9
Christopher Meis7e446a42024-10-22 09:36:41 +020010sdbusplus::async::task<bool> I2CVRDevice::updateDevice(const uint8_t* image,
11 size_t imageSize)
Christopher Meis7e446a42024-10-22 09:36:41 +020012{
Christopher Meis7e446a42024-10-22 09:36:41 +020013 setUpdateProgress(20);
14
15 // NOLINTBEGIN(clang-analyzer-core.uninitialized.Branch)
Christopher Meisfd341442025-06-16 14:34:51 +020016 if (!(co_await vrInterface->verifyImage(image, imageSize)))
Christopher Meis7e446a42024-10-22 09:36:41 +020017 // NOLINTEND(clang-analyzer-core.uninitialized.Branch)
Christopher Meis7e446a42024-10-22 09:36:41 +020018 {
19 co_return false;
20 }
21
22 setUpdateProgress(50);
23
24 // NOLINTBEGIN(clang-analyzer-core.uninitialized.Branch)
Christopher Meisfd341442025-06-16 14:34:51 +020025 if (!(co_await vrInterface->updateFirmware(false)))
Christopher Meis7e446a42024-10-22 09:36:41 +020026 // NOLINTEND(clang-analyzer-core.uninitialized.Branch)
Christopher Meis7e446a42024-10-22 09:36:41 +020027 {
28 co_return false;
29 }
30
31 setUpdateProgress(80);
32
33 // NOLINTBEGIN(clang-analyzer-core.uninitialized.Branch)
Christopher Meisfd341442025-06-16 14:34:51 +020034 if (!(co_await vrInterface->reset()))
Christopher Meis7e446a42024-10-22 09:36:41 +020035 // NOLINTEND(clang-analyzer-core.uninitialized.Branch)
Christopher Meis7e446a42024-10-22 09:36:41 +020036 {
37 co_return false;
38 }
39
40 setUpdateProgress(100);
41
42 lg2::info("Successfully updated VR {NAME}", "NAME", config.configName);
43
44 co_return true;
45}
46
Christopher Meis7e446a42024-10-22 09:36:41 +020047sdbusplus::async::task<bool> I2CVRDevice::getVersion(uint32_t* sum) const
Christopher Meis7e446a42024-10-22 09:36:41 +020048{
49 // NOLINTBEGIN(clang-analyzer-core.uninitialized.Branch)
50 if (!(co_await this->vrInterface->getCRC(sum)))
51 // NOLINTEND(clang-analyzer-core.uninitialized.Branch)
52 {
53 co_return false;
54 }
55 co_return true;
56}
57
58} // namespace phosphor::software::i2c_vr::device