blob: 432f71238945c311f731196dd013594f4f788e9b [file] [log] [blame]
Patrick Venture0b02be92018-08-31 11:55:55 -07001#include "elog-errors.hpp"
2#include "error-HostEvent.hpp"
Patrick Venture46470a32018-09-07 19:26:25 -07003#include "sensorhandler.hpp"
4#include "storagehandler.hpp"
Patrick Venture0b02be92018-08-31 11:55:55 -07005
6#include <mapper.h>
Patrick Venture0b02be92018-08-31 11:55:55 -07007#include <systemd/sd-bus.h>
8
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05009#include <ipmid/api.hpp>
10#include <ipmid/types.hpp>
11#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;
Deepak Kodihalli3d230482018-04-03 07:00:45 -050024using namespace sdbusplus::xyz::openbmc_project::Logging::server;
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
Patrick Venture0b02be92018-08-31 11:55:55 -070064 using error = sdbusplus::org::open_power::Host::Error::MaintenanceProcedure;
Tom Josephb647d5b2017-10-31 17:25:33 +053065 using metadata = org::open_power::Host::MaintenanceProcedure;
66
67 report<error>(metadata::ESEL(data.get()),
68 metadata::PROCEDURE(static_cast<uint32_t>(procedureNum)));
69}