blob: 61c1a55843d4746f4d76ba64f1e3411b66db18a5 [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{
13 bool ret = false;
14 setUpdateProgress(20);
15
16 // NOLINTBEGIN(clang-analyzer-core.uninitialized.Branch)
17 ret = co_await vrInterface->verifyImage(image, imageSize);
18 // NOLINTEND(clang-analyzer-core.uninitialized.Branch)
19 if (!ret)
20 {
21 co_return false;
22 }
23
24 setUpdateProgress(50);
25
26 // NOLINTBEGIN(clang-analyzer-core.uninitialized.Branch)
27 ret = co_await vrInterface->updateFirmware(false);
28 // NOLINTEND(clang-analyzer-core.uninitialized.Branch)
29 if (!ret)
30 {
31 co_return false;
32 }
33
34 setUpdateProgress(80);
35
36 // NOLINTBEGIN(clang-analyzer-core.uninitialized.Branch)
37 ret = co_await vrInterface->reset();
38 // NOLINTEND(clang-analyzer-core.uninitialized.Branch)
39 if (!ret)
40 {
41 co_return false;
42 }
43
44 setUpdateProgress(100);
45
46 lg2::info("Successfully updated VR {NAME}", "NAME", config.configName);
47
48 co_return true;
49}
50
Christopher Meis7e446a42024-10-22 09:36:41 +020051sdbusplus::async::task<bool> I2CVRDevice::getVersion(uint32_t* sum) const
Christopher Meis7e446a42024-10-22 09:36:41 +020052{
53 // NOLINTBEGIN(clang-analyzer-core.uninitialized.Branch)
54 if (!(co_await this->vrInterface->getCRC(sum)))
55 // NOLINTEND(clang-analyzer-core.uninitialized.Branch)
56 {
57 co_return false;
58 }
59 co_return true;
60}
61
62} // namespace phosphor::software::i2c_vr::device