#include "cpld_software_manager.hpp" #include "common/include/dbus_helper.hpp" #include "cpld.hpp" #include #include PHOSPHOR_LOG2_USING; using namespace phosphor::software::cpld; sdbusplus::async::task CPLDSoftwareManager::initDevice( const std::string& service, const std::string& path, SoftwareConfig& config) { std::string configIface = "xyz.openbmc_project.Configuration." + config.configType; auto busNo = co_await dbusGetRequiredProperty( ctx, service, path, configIface, "Bus"); auto address = co_await dbusGetRequiredProperty( ctx, service, path, configIface, "Address"); auto chipType = co_await dbusGetRequiredProperty( ctx, service, path, configIface, "Type"); auto chipName = co_await dbusGetRequiredProperty( ctx, service, path, configIface, "Name"); if (!busNo.has_value() || !address.has_value() || !chipType.has_value() || !chipName.has_value()) { error("missing config property"); co_return false; } lg2::debug( "CPLD device type: {TYPE} - {NAME} on Bus: {BUS} at Address: {ADDR}", "TYPE", chipType.value(), "NAME", chipName.value(), "BUS", busNo.value(), "ADDR", address.value()); auto cpld = std::make_unique( ctx, chipType.value(), chipName.value(), busNo.value(), address.value(), config, this); std::string version = "unknown"; if (!(co_await cpld->getVersion(version))) { lg2::error("Failed to get CPLD version for {NAME}", "NAME", chipName.value()); } std::unique_ptr software = std::make_unique(ctx, *cpld); software->setVersion(version, SoftwareVersion::VersionPurpose::Other); std::set allowedApplyTimes = { RequestedApplyTimes::Immediate, RequestedApplyTimes::OnReset}; software->enableUpdate(allowedApplyTimes); cpld->softwareCurrent = std::move(software); devices.insert({config.objectPath, std::move(cpld)}); co_return true; } void CPLDSoftwareManager::start() { std::vector configIntfs; auto configs = CPLDFactory::instance().getConfigs(); configIntfs.reserve(configs.size()); for (const auto& config : configs) { configIntfs.push_back("xyz.openbmc_project.Configuration." + config); } ctx.spawn(initDevices(configIntfs)); ctx.run(); } int main() { sdbusplus::async::context ctx; CPLDSoftwareManager cpldSoftwareManager(ctx); cpldSoftwareManager.start(); return 0; }