blob: fc7e9c0562e4a76cd51006f1a280d4817838acc1 [file] [log] [blame]
Patrick Venture0b02be92018-08-31 11:55:55 -07001#include "error-HostEvent.hpp"
Patrick Venture46470a32018-09-07 19:26:25 -07002#include "sensorhandler.hpp"
3#include "storagehandler.hpp"
Patrick Venture0b02be92018-08-31 11:55:55 -07004
5#include <mapper.h>
Patrick Venture0b02be92018-08-31 11:55:55 -07006#include <systemd/sd-bus.h>
7
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05008#include <ipmid/api.hpp>
9#include <ipmid/types.hpp>
Patrick Williams6856f1b2023-09-01 16:10:07 -050010#include <phosphor-logging/elog-errors.hpp>
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -050011#include <phosphor-logging/elog.hpp>
12#include <xyz/openbmc_project/Logging/Entry/server.hpp>
13
Patrick Venture0b02be92018-08-31 11:55:55 -070014#include <algorithm>
Chris Austen41a4b312015-10-25 03:45:42 -050015#include <cstdlib>
16#include <cstring>
17#include <fstream>
18#include <iostream>
Chris Austen41a4b312015-10-25 03:45:42 -050019#include <memory>
Patrick Venture0b02be92018-08-31 11:55:55 -070020#include <vector>
Patrick Venture0b02be92018-08-31 11:55:55 -070021
Chris Austen41a4b312015-10-25 03:45:42 -050022using namespace std;
Adriana Kobylak2efb3e72017-02-06 21:43:59 -060023using namespace phosphor::logging;
Willy Tu523e2d12023-09-05 11:36:48 -070024using namespace sdbusplus::server::xyz::openbmc_project::logging;
Tom Josephe19540e2019-02-04 14:06:58 +053025
Tom Josephb647d5b2017-10-31 17:25:33 +053026std::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
46void 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 Venture0b02be92018-08-31 11:55:55 -070055 std::unique_ptr<char[]> data(
56 new char[(eSELData.size() * byteSeparator) + 1]());
Tom Josephb647d5b2017-10-31 17:25:33 +053057
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
Willy Tu523e2d12023-09-05 11:36:48 -070064 using error = sdbusplus::error::org::open_power::host::MaintenanceProcedure;
65 using metadata = org::open_power::host::MaintenanceProcedure;
Tom Josephb647d5b2017-10-31 17:25:33 +053066
67 report<error>(metadata::ESEL(data.get()),
68 metadata::PROCEDURE(static_cast<uint32_t>(procedureNum)));
69}