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