blob: 79064dd7a2f7b64215a31343130092f70dba7f22 [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>
George Liu9ceeafb2024-07-19 09:22:15 +080011#include <phosphor-logging/lg2.hpp>
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -050012#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 {
George Liu9ceeafb2024-07-19 09:22:15 +080033 lg2::error("Failed to open eSEL, file name: {FILENAME}", "FILENAME",
34 fileName);
Tom Josephb647d5b2017-10-31 17:25:33 +053035 return content;
36 }
37
38 handle.seekg(0, std::ios::end);
39 content.resize(handle.tellg());
40 handle.seekg(0, std::ios::beg);
41 handle.read(&content[0], content.size());
42 handle.close();
43
44 return content;
45}
46
47void createProcedureLogEntry(uint8_t procedureNum)
48{
49 // Read the eSEL data from the file.
50 static constexpr auto eSELFile = "/tmp/esel";
51 auto eSELData = readESEL(eSELFile);
52
53 // Each byte in eSEL is formatted as %02x with a space between bytes and
54 // insert '/0' at the end of the character array.
55 static constexpr auto byteSeparator = 3;
Patrick Venture0b02be92018-08-31 11:55:55 -070056 std::unique_ptr<char[]> data(
57 new char[(eSELData.size() * byteSeparator) + 1]());
Tom Josephb647d5b2017-10-31 17:25:33 +053058
59 for (size_t i = 0; i < eSELData.size(); i++)
60 {
61 sprintf(&data[i * byteSeparator], "%02x ", eSELData[i]);
62 }
63 data[eSELData.size() * byteSeparator] = '\0';
64
Willy Tu523e2d12023-09-05 11:36:48 -070065 using error = sdbusplus::error::org::open_power::host::MaintenanceProcedure;
66 using metadata = org::open_power::host::MaintenanceProcedure;
Tom Josephb647d5b2017-10-31 17:25:33 +053067
68 report<error>(metadata::ESEL(data.get()),
69 metadata::PROCEDURE(static_cast<uint32_t>(procedureNum)));
70}