Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1 | #include "error-HostEvent.hpp" |
Patrick Venture | 46470a3 | 2018-09-07 19:26:25 -0700 | [diff] [blame] | 2 | #include "sensorhandler.hpp" |
| 3 | #include "storagehandler.hpp" |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 4 | |
| 5 | #include <mapper.h> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 6 | #include <systemd/sd-bus.h> |
| 7 | |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 8 | #include <ipmid/api.hpp> |
| 9 | #include <ipmid/types.hpp> |
Patrick Williams | 6856f1b | 2023-09-01 16:10:07 -0500 | [diff] [blame] | 10 | #include <phosphor-logging/elog-errors.hpp> |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 11 | #include <phosphor-logging/elog.hpp> |
| 12 | #include <xyz/openbmc_project/Logging/Entry/server.hpp> |
| 13 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 14 | #include <algorithm> |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 15 | #include <cstdlib> |
| 16 | #include <cstring> |
| 17 | #include <fstream> |
| 18 | #include <iostream> |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 19 | #include <memory> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 20 | #include <vector> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 21 | |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 22 | using namespace std; |
Adriana Kobylak | 2efb3e7 | 2017-02-06 21:43:59 -0600 | [diff] [blame] | 23 | using namespace phosphor::logging; |
Deepak Kodihalli | 3d23048 | 2018-04-03 07:00:45 -0500 | [diff] [blame] | 24 | using namespace sdbusplus::xyz::openbmc_project::Logging::server; |
Tom Joseph | e19540e | 2019-02-04 14:06:58 +0530 | [diff] [blame] | 25 | |
Tom Joseph | b647d5b | 2017-10-31 17:25:33 +0530 | [diff] [blame] | 26 | std::string readESEL(const char* fileName) |
| 27 | { |
| 28 | std::string content; |
| 29 | std::ifstream handle(fileName); |
| 30 | |
| 31 | if (handle.fail()) |
| 32 | { |
| 33 | log<level::ERR>("Failed to open eSEL", entry("FILENAME=%s", fileName)); |
| 34 | return content; |
| 35 | } |
| 36 | |
| 37 | handle.seekg(0, std::ios::end); |
| 38 | content.resize(handle.tellg()); |
| 39 | handle.seekg(0, std::ios::beg); |
| 40 | handle.read(&content[0], content.size()); |
| 41 | handle.close(); |
| 42 | |
| 43 | return content; |
| 44 | } |
| 45 | |
| 46 | void createProcedureLogEntry(uint8_t procedureNum) |
| 47 | { |
| 48 | // Read the eSEL data from the file. |
| 49 | static constexpr auto eSELFile = "/tmp/esel"; |
| 50 | auto eSELData = readESEL(eSELFile); |
| 51 | |
| 52 | // Each byte in eSEL is formatted as %02x with a space between bytes and |
| 53 | // insert '/0' at the end of the character array. |
| 54 | static constexpr auto byteSeparator = 3; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 55 | std::unique_ptr<char[]> data( |
| 56 | new char[(eSELData.size() * byteSeparator) + 1]()); |
Tom Joseph | b647d5b | 2017-10-31 17:25:33 +0530 | [diff] [blame] | 57 | |
| 58 | for (size_t i = 0; i < eSELData.size(); i++) |
| 59 | { |
| 60 | sprintf(&data[i * byteSeparator], "%02x ", eSELData[i]); |
| 61 | } |
| 62 | data[eSELData.size() * byteSeparator] = '\0'; |
| 63 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 64 | using error = sdbusplus::org::open_power::Host::Error::MaintenanceProcedure; |
Tom Joseph | b647d5b | 2017-10-31 17:25:33 +0530 | [diff] [blame] | 65 | using metadata = org::open_power::Host::MaintenanceProcedure; |
| 66 | |
| 67 | report<error>(metadata::ESEL(data.get()), |
| 68 | metadata::PROCEDURE(static_cast<uint32_t>(procedureNum))); |
| 69 | } |