1 #include "cpld_software_manager.hpp"
2
3 #include "common/include/dbus_helper.hpp"
4 #include "cpld.hpp"
5
6 #include <phosphor-logging/lg2.hpp>
7 #include <sdbusplus/async.hpp>
8
9 PHOSPHOR_LOG2_USING;
10
11 using namespace phosphor::software::cpld;
12
initDevice(const std::string & service,const std::string & path,SoftwareConfig & config)13 sdbusplus::async::task<bool> CPLDSoftwareManager::initDevice(
14 const std::string& service, const std::string& path, SoftwareConfig& config)
15 {
16 std::string configIface =
17 "xyz.openbmc_project.Configuration." + config.configType;
18
19 auto busNo = co_await dbusGetRequiredProperty<uint64_t>(
20 ctx, service, path, configIface, "Bus");
21 auto address = co_await dbusGetRequiredProperty<uint64_t>(
22 ctx, service, path, configIface, "Address");
23 auto chipType = co_await dbusGetRequiredProperty<std::string>(
24 ctx, service, path, configIface, "Type");
25 auto chipName = co_await dbusGetRequiredProperty<std::string>(
26 ctx, service, path, configIface, "Name");
27
28 if (!busNo.has_value() || !address.has_value() || !chipType.has_value() ||
29 !chipName.has_value())
30 {
31 error("missing config property");
32 co_return false;
33 }
34
35 lg2::debug(
36 "CPLD device type: {TYPE} - {NAME} on Bus: {BUS} at Address: {ADDR}",
37 "TYPE", chipType.value(), "NAME", chipName.value(), "BUS",
38 busNo.value(), "ADDR", address.value());
39
40 auto cpld = std::make_unique<CPLDDevice>(
41 ctx, chipType.value(), chipName.value(), busNo.value(), address.value(),
42 config, this);
43
44 std::string version = "unknown";
45 if (!(co_await cpld->getVersion(version)))
46 {
47 lg2::error("Failed to get CPLD version for {NAME}", "NAME",
48 chipName.value());
49 }
50
51 std::unique_ptr<Software> software = std::make_unique<Software>(ctx, *cpld);
52
53 software->setVersion(version, SoftwareVersion::VersionPurpose::Other);
54
55 std::set<RequestedApplyTimes> allowedApplyTimes = {
56 RequestedApplyTimes::Immediate, RequestedApplyTimes::OnReset};
57
58 software->enableUpdate(allowedApplyTimes);
59
60 cpld->softwareCurrent = std::move(software);
61
62 devices.insert({config.objectPath, std::move(cpld)});
63
64 co_return true;
65 }
66
start()67 void CPLDSoftwareManager::start()
68 {
69 std::vector<std::string> configIntfs;
70 auto configs = CPLDFactory::instance().getConfigs();
71 configIntfs.reserve(configs.size());
72 for (const auto& config : configs)
73 {
74 configIntfs.push_back("xyz.openbmc_project.Configuration." + config);
75 }
76
77 ctx.spawn(initDevices(configIntfs));
78 ctx.run();
79 }
80
main()81 int main()
82 {
83 sdbusplus::async::context ctx;
84
85 CPLDSoftwareManager cpldSoftwareManager(ctx);
86
87 cpldSoftwareManager.start();
88
89 return 0;
90 }
91