blob: 2392e488fc489164c820850d8dbe0b6963cc283d [file] [log] [blame]
Daniel Hsuf6470b52025-02-26 15:03:47 +08001#include "cpld.hpp"
2
3namespace phosphor::software::cpld
4{
5
6sdbusplus::async::task<bool> CPLDDevice::updateDevice(const uint8_t* image,
7 size_t image_size)
8{
9 if (cpldInterface == nullptr)
10 {
11 lg2::error("CPLD interface is not initialized");
12 co_return false;
13 }
14 else
15 {
16 setUpdateProgress(1);
17 if (!(co_await cpldInterface->updateFirmware(
18 false, image, image_size, [this](int percent) -> bool {
19 return this->setUpdateProgress(percent);
20 })))
21 {
22 lg2::error("Failed to update CPLD firmware");
23 co_return false;
24 }
25
26 setUpdateProgress(100);
27 lg2::info("Successfully updated CPLD");
28 co_return true;
29 }
30}
31
32sdbusplus::async::task<bool> CPLDDevice::getVersion(std::string& version)
33{
34 if (cpldInterface == nullptr)
35 {
36 lg2::error("CPLD interface is not initialized");
37 co_return false;
38 }
39 else
40 {
41 if (!(co_await cpldInterface->getVersion(version)))
42 {
43 lg2::error("Failed to get CPLD version");
44 co_return false;
45 }
46
47 lg2::info("CPLD version: {VERSION}", "VERSION", version);
48 co_return true;
49 }
50}
51
52} // namespace phosphor::software::cpld