1378fe11dSAndrew Geissler #include "config.h"
2378fe11dSAndrew Geissler
3378fe11dSAndrew Geissler #include "utils.hpp"
4378fe11dSAndrew Geissler
5378fe11dSAndrew Geissler #include <getopt.h>
6378fe11dSAndrew Geissler #include <systemd/sd-bus.h>
7378fe11dSAndrew Geissler
8378fe11dSAndrew Geissler #include <phosphor-logging/elog-errors.hpp>
9378fe11dSAndrew Geissler #include <phosphor-logging/lg2.hpp>
10378fe11dSAndrew Geissler #include <sdbusplus/exception.hpp>
11378fe11dSAndrew Geissler #include <sdbusplus/server.hpp>
127a7c38dbSPatrick Williams #include <xyz/openbmc_project/Common/error.hpp>
13*f566c964SAmithash Prasasd #include <xyz/openbmc_project/State/Chassis/client.hpp>
14378fe11dSAndrew Geissler
15378fe11dSAndrew Geissler #include <iostream>
16378fe11dSAndrew Geissler #include <map>
17378fe11dSAndrew Geissler #include <string>
18378fe11dSAndrew Geissler
19378fe11dSAndrew Geissler PHOSPHOR_LOG2_USING;
20378fe11dSAndrew Geissler
21378fe11dSAndrew Geissler using namespace phosphor::logging;
22378fe11dSAndrew Geissler using namespace sdbusplus::xyz::openbmc_project::Common::Error;
23378fe11dSAndrew Geissler
24*f566c964SAmithash Prasasd using ChassisState = sdbusplus::client::xyz::openbmc_project::state::Chassis<>;
25*f566c964SAmithash Prasasd
main(int argc,char ** argv)26378fe11dSAndrew Geissler int main(int argc, char** argv)
27378fe11dSAndrew Geissler {
28*f566c964SAmithash Prasasd size_t chassisId = 0;
29*f566c964SAmithash Prasasd const auto* objPath = ChassisState::namespace_path::value;
30*f566c964SAmithash Prasasd auto chassisBusName = ChassisState::interface + std::to_string(chassisId);
31378fe11dSAndrew Geissler int arg;
32378fe11dSAndrew Geissler int optIndex = 0;
33378fe11dSAndrew Geissler
34f15b9544SPavithra Barithaya static struct option longOpts[] = {
35f15b9544SPavithra Barithaya {"chassis", required_argument, nullptr, 'c'}, {nullptr, 0, nullptr, 0}};
36378fe11dSAndrew Geissler
37378fe11dSAndrew Geissler while ((arg = getopt_long(argc, argv, "c:", longOpts, &optIndex)) != -1)
38378fe11dSAndrew Geissler {
39378fe11dSAndrew Geissler switch (arg)
40378fe11dSAndrew Geissler {
41378fe11dSAndrew Geissler case 'c':
42*f566c964SAmithash Prasasd chassisId = std::stoul(optarg);
43378fe11dSAndrew Geissler break;
44378fe11dSAndrew Geissler default:
45378fe11dSAndrew Geissler break;
46378fe11dSAndrew Geissler }
47378fe11dSAndrew Geissler }
48378fe11dSAndrew Geissler
49*f566c964SAmithash Prasasd auto chassisName = std::string(ChassisState::namespace_path::chassis) +
50*f566c964SAmithash Prasasd std::to_string(chassisId);
51*f566c964SAmithash Prasasd std::string chassisPath =
52*f566c964SAmithash Prasasd sdbusplus::message::object_path(objPath) / chassisName;
53378fe11dSAndrew Geissler auto bus = sdbusplus::bus::new_default();
54378fe11dSAndrew Geissler
55378fe11dSAndrew Geissler // If the chassis power status is not good, log an error and exit with
56378fe11dSAndrew Geissler // a non-zero rc so the system does not power on
57378fe11dSAndrew Geissler auto currentPowerStatus = phosphor::state::manager::utils::getProperty(
58*f566c964SAmithash Prasasd bus, chassisPath, ChassisState::interface, "CurrentPowerStatus");
59378fe11dSAndrew Geissler if (currentPowerStatus !=
60378fe11dSAndrew Geissler "xyz.openbmc_project.State.Chassis.PowerStatus.Good")
61378fe11dSAndrew Geissler {
62378fe11dSAndrew Geissler error("Chassis power status is not good: {CURRENT_PWR_STATUS}",
63378fe11dSAndrew Geissler "CURRENT_PWR_STATUS", currentPowerStatus);
64378fe11dSAndrew Geissler
65378fe11dSAndrew Geissler // Generate log telling user why system is not powering on
66378fe11dSAndrew Geissler const std::string errorMsg =
67378fe11dSAndrew Geissler "xyz.openbmc_project.State.ChassisPowerBad";
68378fe11dSAndrew Geissler phosphor::state::manager::utils::createError(
69378fe11dSAndrew Geissler bus, errorMsg,
707e969cb9SPatrick Williams sdbusplus::server::xyz::openbmc_project::logging::Entry::Level::
71378fe11dSAndrew Geissler Critical);
72378fe11dSAndrew Geissler return -1;
73378fe11dSAndrew Geissler }
74378fe11dSAndrew Geissler // all good
75378fe11dSAndrew Geissler info("Chassis power status good, start power on");
76378fe11dSAndrew Geissler return 0;
77378fe11dSAndrew Geissler }
78