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