blob: cd9eae864497d4f4d3cc1eafaca43914931c969e [file] [log] [blame]
Andrew Geissler378fe112022-02-03 16:39:44 -06001#include "config.h"
2
3#include "utils.hpp"
4
5#include <getopt.h>
6#include <systemd/sd-bus.h>
7
8#include <phosphor-logging/elog-errors.hpp>
9#include <phosphor-logging/lg2.hpp>
10#include <sdbusplus/exception.hpp>
11#include <sdbusplus/server.hpp>
Patrick Williams7a7c38d2023-09-06 22:00:15 -050012#include <xyz/openbmc_project/Common/error.hpp>
Amithash Prasasdf566c962024-07-22 20:28:42 -070013#include <xyz/openbmc_project/State/Chassis/client.hpp>
Andrew Geissler378fe112022-02-03 16:39:44 -060014
15#include <iostream>
16#include <map>
17#include <string>
18
19PHOSPHOR_LOG2_USING;
20
21using namespace phosphor::logging;
22using namespace sdbusplus::xyz::openbmc_project::Common::Error;
23
Amithash Prasasdf566c962024-07-22 20:28:42 -070024using ChassisState = sdbusplus::client::xyz::openbmc_project::state::Chassis<>;
25
Andrew Geissler378fe112022-02-03 16:39:44 -060026int main(int argc, char** argv)
27{
Amithash Prasasdf566c962024-07-22 20:28:42 -070028 size_t chassisId = 0;
29 const auto* objPath = ChassisState::namespace_path::value;
30 auto chassisBusName = ChassisState::interface + std::to_string(chassisId);
Andrew Geissler378fe112022-02-03 16:39:44 -060031 int arg;
32 int optIndex = 0;
33
Pavithra Barithayaf15b9542024-06-21 08:18:48 -050034 static struct option longOpts[] = {
35 {"chassis", required_argument, nullptr, 'c'}, {nullptr, 0, nullptr, 0}};
Andrew Geissler378fe112022-02-03 16:39:44 -060036
37 while ((arg = getopt_long(argc, argv, "c:", longOpts, &optIndex)) != -1)
38 {
39 switch (arg)
40 {
41 case 'c':
Amithash Prasasdf566c962024-07-22 20:28:42 -070042 chassisId = std::stoul(optarg);
Andrew Geissler378fe112022-02-03 16:39:44 -060043 break;
44 default:
45 break;
46 }
47 }
48
Amithash Prasasdf566c962024-07-22 20:28:42 -070049 auto chassisName = std::string(ChassisState::namespace_path::chassis) +
50 std::to_string(chassisId);
51 std::string chassisPath =
52 sdbusplus::message::object_path(objPath) / chassisName;
Andrew Geissler378fe112022-02-03 16:39:44 -060053 auto bus = sdbusplus::bus::new_default();
54
55 // If the chassis power status is not good, log an error and exit with
56 // a non-zero rc so the system does not power on
57 auto currentPowerStatus = phosphor::state::manager::utils::getProperty(
Amithash Prasasdf566c962024-07-22 20:28:42 -070058 bus, chassisPath, ChassisState::interface, "CurrentPowerStatus");
Andrew Geissler378fe112022-02-03 16:39:44 -060059 if (currentPowerStatus !=
60 "xyz.openbmc_project.State.Chassis.PowerStatus.Good")
61 {
62 error("Chassis power status is not good: {CURRENT_PWR_STATUS}",
63 "CURRENT_PWR_STATUS", currentPowerStatus);
64
65 // Generate log telling user why system is not powering on
66 const std::string errorMsg =
67 "xyz.openbmc_project.State.ChassisPowerBad";
68 phosphor::state::manager::utils::createError(
69 bus, errorMsg,
Patrick Williams7e969cb2023-08-23 16:24:23 -050070 sdbusplus::server::xyz::openbmc_project::logging::Entry::Level::
Andrew Geissler378fe112022-02-03 16:39:44 -060071 Critical);
72 return -1;
73 }
74 // all good
75 info("Chassis power status good, start power on");
76 return 0;
77}