Jayanth Othayoth | d31be2c | 2020-02-04 02:56:45 -0600 | [diff] [blame] | 1 | #include "dump_utils.hpp" |
| 2 | |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame^] | 3 | #include <phosphor-logging/lg2.hpp> |
Jayanth Othayoth | d31be2c | 2020-02-04 02:56:45 -0600 | [diff] [blame] | 4 | #include <phosphor-logging/log.hpp> |
| 5 | |
| 6 | namespace phosphor |
| 7 | { |
| 8 | namespace dump |
| 9 | { |
| 10 | |
Ramesh Iyyar | 2279386 | 2020-12-04 04:03:03 -0600 | [diff] [blame] | 11 | using namespace phosphor::logging; |
| 12 | |
Patrick Williams | 9b18bf2 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 13 | std::string getService(sdbusplus::bus_t& bus, const std::string& path, |
Jayanth Othayoth | d31be2c | 2020-02-04 02:56:45 -0600 | [diff] [blame] | 14 | const std::string& interface) |
| 15 | { |
| 16 | constexpr auto objectMapperName = "xyz.openbmc_project.ObjectMapper"; |
| 17 | constexpr auto objectMapperPath = "/xyz/openbmc_project/object_mapper"; |
Jayanth Othayoth | d31be2c | 2020-02-04 02:56:45 -0600 | [diff] [blame] | 18 | |
| 19 | auto method = bus.new_method_call(objectMapperName, objectMapperPath, |
| 20 | objectMapperName, "GetObject"); |
| 21 | |
| 22 | method.append(path); |
| 23 | method.append(std::vector<std::string>({interface})); |
| 24 | |
| 25 | std::vector<std::pair<std::string, std::vector<std::string>>> response; |
| 26 | |
| 27 | try |
| 28 | { |
| 29 | auto reply = bus.call(method); |
| 30 | reply.read(response); |
| 31 | if (response.empty()) |
| 32 | { |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame^] | 33 | lg2::error( |
| 34 | "Error in mapper response for getting service name, PATH: " |
| 35 | "{PATH}, INTERFACE: {INTERFACE}", |
| 36 | "PATH", path, "INTERFACE", interface); |
Jayanth Othayoth | d31be2c | 2020-02-04 02:56:45 -0600 | [diff] [blame] | 37 | return std::string{}; |
| 38 | } |
| 39 | } |
Patrick Williams | 9b18bf2 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 40 | catch (const sdbusplus::exception_t& e) |
Jayanth Othayoth | d31be2c | 2020-02-04 02:56:45 -0600 | [diff] [blame] | 41 | { |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame^] | 42 | lg2::error("Error in mapper method call, errormsg: {ERROR}, " |
| 43 | "PATH: {PATH}, INTERFACE: {INTERFACE}", |
| 44 | "ERROR", e, "PATH", path, "INTERFACE", interface); |
Jayanth Othayoth | d31be2c | 2020-02-04 02:56:45 -0600 | [diff] [blame] | 45 | return std::string{}; |
| 46 | } |
| 47 | return response[0].first; |
| 48 | } |
| 49 | |
Ramesh Iyyar | 2279386 | 2020-12-04 04:03:03 -0600 | [diff] [blame] | 50 | BootProgress getBootProgress() |
| 51 | { |
| 52 | constexpr auto bootProgressInterface = |
| 53 | "xyz.openbmc_project.State.Boot.Progress"; |
| 54 | // TODO Need to change host instance if multiple instead "0" |
| 55 | constexpr auto hostStateObjPath = "/xyz/openbmc_project/state/host0"; |
| 56 | |
| 57 | BootProgress bootProgessStage; |
| 58 | |
| 59 | try |
| 60 | { |
| 61 | auto bus = sdbusplus::bus::new_default(); |
| 62 | auto service = getService(bus, hostStateObjPath, bootProgressInterface); |
| 63 | |
Patrick Williams | 78e8840 | 2023-05-10 07:50:48 -0500 | [diff] [blame] | 64 | auto method = bus.new_method_call(service.c_str(), hostStateObjPath, |
| 65 | "org.freedesktop.DBus.Properties", |
| 66 | "Get"); |
Ramesh Iyyar | 2279386 | 2020-12-04 04:03:03 -0600 | [diff] [blame] | 67 | |
| 68 | method.append(bootProgressInterface, "BootProgress"); |
| 69 | |
| 70 | auto reply = bus.call(method); |
| 71 | |
| 72 | using DBusValue_t = |
| 73 | std::variant<std::string, bool, std::vector<uint8_t>, |
| 74 | std::vector<std::string>>; |
| 75 | DBusValue_t propertyVal; |
| 76 | |
| 77 | reply.read(propertyVal); |
| 78 | |
| 79 | // BootProgress property type is string |
| 80 | std::string bootPgs(std::get<std::string>(propertyVal)); |
| 81 | |
| 82 | bootProgessStage = sdbusplus::xyz::openbmc_project::State::Boot:: |
| 83 | server::Progress::convertProgressStagesFromString(bootPgs); |
| 84 | } |
Patrick Williams | 9b18bf2 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 85 | catch (const sdbusplus::exception_t& e) |
Ramesh Iyyar | 2279386 | 2020-12-04 04:03:03 -0600 | [diff] [blame] | 86 | { |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame^] | 87 | lg2::error("D-Bus call exception, OBJPATH: {OBJ_PATH}, " |
| 88 | "INTERFACE: {INTERFACE}, EXCEPTION: {ERROR}", |
| 89 | "OBJ_PATH", hostStateObjPath, "INTERFACE", |
| 90 | bootProgressInterface, "ERROR", e); |
Ramesh Iyyar | 2279386 | 2020-12-04 04:03:03 -0600 | [diff] [blame] | 91 | throw std::runtime_error("Failed to get BootProgress stage"); |
| 92 | } |
| 93 | catch (const std::bad_variant_access& e) |
| 94 | { |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame^] | 95 | lg2::error("Exception raised while read BootProgress property value, " |
| 96 | "OBJPATH: {OBJ_PATH}, INTERFACE: {INTERFACE}, " |
| 97 | "EXCEPTION: {ERROR}", |
| 98 | "OBJ_PATH", hostStateObjPath, "INTERFACE", |
| 99 | bootProgressInterface, "ERROR", e); |
Ramesh Iyyar | 2279386 | 2020-12-04 04:03:03 -0600 | [diff] [blame] | 100 | throw std::runtime_error("Failed to get BootProgress stage"); |
| 101 | } |
| 102 | |
| 103 | return bootProgessStage; |
| 104 | } |
Dhruvaraj Subhashchandran | 6a54d9a | 2020-12-17 22:24:37 -0600 | [diff] [blame] | 105 | |
| 106 | bool isHostRunning() |
| 107 | { |
| 108 | // TODO #ibm-openbmc/dev/2858 Revisit the method for finding whether host |
| 109 | // is running. |
| 110 | BootProgress bootProgressStatus = phosphor::dump::getBootProgress(); |
| 111 | if ((bootProgressStatus == BootProgress::SystemInitComplete) || |
Ravi Teja | 8a9736b | 2022-04-02 01:42:22 -0500 | [diff] [blame] | 112 | (bootProgressStatus == BootProgress::SystemSetup) || |
Dhruvaraj Subhashchandran | 6a54d9a | 2020-12-17 22:24:37 -0600 | [diff] [blame] | 113 | (bootProgressStatus == BootProgress::OSStart) || |
Dhruvaraj Subhashchandran | 706ae1b | 2022-09-21 01:05:01 -0500 | [diff] [blame] | 114 | (bootProgressStatus == BootProgress::OSRunning) || |
| 115 | (bootProgressStatus == BootProgress::PCIInit)) |
Dhruvaraj Subhashchandran | 6a54d9a | 2020-12-17 22:24:37 -0600 | [diff] [blame] | 116 | { |
| 117 | return true; |
| 118 | } |
| 119 | return false; |
| 120 | } |
Jayanth Othayoth | d31be2c | 2020-02-04 02:56:45 -0600 | [diff] [blame] | 121 | } // namespace dump |
| 122 | } // namespace phosphor |