Andrew Geissler | 378fe11 | 2022-02-03 16:39:44 -0600 | [diff] [blame] | 1 | #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 Williams | 7a7c38d | 2023-09-06 22:00:15 -0500 | [diff] [blame] | 12 | #include <xyz/openbmc_project/Common/error.hpp> |
Amithash Prasasd | f566c96 | 2024-07-22 20:28:42 -0700 | [diff] [blame^] | 13 | #include <xyz/openbmc_project/State/Chassis/client.hpp> |
Andrew Geissler | 378fe11 | 2022-02-03 16:39:44 -0600 | [diff] [blame] | 14 | |
| 15 | #include <iostream> |
| 16 | #include <map> |
| 17 | #include <string> |
| 18 | |
| 19 | PHOSPHOR_LOG2_USING; |
| 20 | |
| 21 | using namespace phosphor::logging; |
| 22 | using namespace sdbusplus::xyz::openbmc_project::Common::Error; |
| 23 | |
Amithash Prasasd | f566c96 | 2024-07-22 20:28:42 -0700 | [diff] [blame^] | 24 | using ChassisState = sdbusplus::client::xyz::openbmc_project::state::Chassis<>; |
| 25 | |
Andrew Geissler | 378fe11 | 2022-02-03 16:39:44 -0600 | [diff] [blame] | 26 | int main(int argc, char** argv) |
| 27 | { |
Amithash Prasasd | f566c96 | 2024-07-22 20:28:42 -0700 | [diff] [blame^] | 28 | size_t chassisId = 0; |
| 29 | const auto* objPath = ChassisState::namespace_path::value; |
| 30 | auto chassisBusName = ChassisState::interface + std::to_string(chassisId); |
Andrew Geissler | 378fe11 | 2022-02-03 16:39:44 -0600 | [diff] [blame] | 31 | int arg; |
| 32 | int optIndex = 0; |
| 33 | |
Pavithra Barithaya | f15b954 | 2024-06-21 08:18:48 -0500 | [diff] [blame] | 34 | static struct option longOpts[] = { |
| 35 | {"chassis", required_argument, nullptr, 'c'}, {nullptr, 0, nullptr, 0}}; |
Andrew Geissler | 378fe11 | 2022-02-03 16:39:44 -0600 | [diff] [blame] | 36 | |
| 37 | while ((arg = getopt_long(argc, argv, "c:", longOpts, &optIndex)) != -1) |
| 38 | { |
| 39 | switch (arg) |
| 40 | { |
| 41 | case 'c': |
Amithash Prasasd | f566c96 | 2024-07-22 20:28:42 -0700 | [diff] [blame^] | 42 | chassisId = std::stoul(optarg); |
Andrew Geissler | 378fe11 | 2022-02-03 16:39:44 -0600 | [diff] [blame] | 43 | break; |
| 44 | default: |
| 45 | break; |
| 46 | } |
| 47 | } |
| 48 | |
Amithash Prasasd | f566c96 | 2024-07-22 20:28:42 -0700 | [diff] [blame^] | 49 | 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 Geissler | 378fe11 | 2022-02-03 16:39:44 -0600 | [diff] [blame] | 53 | 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 Prasasd | f566c96 | 2024-07-22 20:28:42 -0700 | [diff] [blame^] | 58 | bus, chassisPath, ChassisState::interface, "CurrentPowerStatus"); |
Andrew Geissler | 378fe11 | 2022-02-03 16:39:44 -0600 | [diff] [blame] | 59 | 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 Williams | 7e969cb | 2023-08-23 16:24:23 -0500 | [diff] [blame] | 70 | sdbusplus::server::xyz::openbmc_project::logging::Entry::Level:: |
Andrew Geissler | 378fe11 | 2022-02-03 16:39:44 -0600 | [diff] [blame] | 71 | Critical); |
| 72 | return -1; |
| 73 | } |
| 74 | // all good |
| 75 | info("Chassis power status good, start power on"); |
| 76 | return 0; |
| 77 | } |