blob: 34e839e3fdeea54612923a0a378a1f6ead637eb9 [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
Patrick Venture0b02be92018-08-31 11:55:55 -07005#include <systemd/sd-bus.h>
6
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05007#include <ipmid/api.hpp>
8#include <ipmid/types.hpp>
Patrick Williams6856f1b2023-09-01 16:10:07 -05009#include <phosphor-logging/elog-errors.hpp>
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -050010#include <phosphor-logging/elog.hpp>
11#include <xyz/openbmc_project/Logging/Entry/server.hpp>
12
Patrick Venture0b02be92018-08-31 11:55:55 -070013#include <algorithm>
Chris Austen41a4b312015-10-25 03:45:42 -050014#include <cstdlib>
15#include <cstring>
16#include <fstream>
17#include <iostream>
Chris Austen41a4b312015-10-25 03:45:42 -050018#include <memory>
Patrick Venture0b02be92018-08-31 11:55:55 -070019#include <vector>
Patrick Venture0b02be92018-08-31 11:55:55 -070020
Chris Austen41a4b312015-10-25 03:45:42 -050021using namespace std;
Adriana Kobylak2efb3e72017-02-06 21:43:59 -060022using namespace phosphor::logging;
Willy Tu523e2d12023-09-05 11:36:48 -070023using namespace sdbusplus::server::xyz::openbmc_project::logging;
Tom Josephe19540e2019-02-04 14:06:58 +053024
Tom Josephb647d5b2017-10-31 17:25:33 +053025std::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
45void 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 Venture0b02be92018-08-31 11:55:55 -070054 std::unique_ptr<char[]> data(
55 new char[(eSELData.size() * byteSeparator) + 1]());
Tom Josephb647d5b2017-10-31 17:25:33 +053056
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
Willy Tu523e2d12023-09-05 11:36:48 -070063 using error = sdbusplus::error::org::open_power::host::MaintenanceProcedure;
64 using metadata = org::open_power::host::MaintenanceProcedure;
Tom Josephb647d5b2017-10-31 17:25:33 +053065
66 report<error>(metadata::ESEL(data.get()),
67 metadata::PROCEDURE(static_cast<uint32_t>(procedureNum)));
68}