blob: 5cdf5354f4b11bfe2d25527d0c281c9556e40494 [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#include "types.hpp"
6
Patrick Venture46470a32018-09-07 19:26:25 -07007#include <host-ipmid/ipmid-api.h>
Patrick Venture0b02be92018-08-31 11:55:55 -07008#include <mapper.h>
Patrick Venture0b02be92018-08-31 11:55:55 -07009#include <systemd/sd-bus.h>
10
11#include <algorithm>
Chris Austen41a4b312015-10-25 03:45:42 -050012#include <cstdlib>
13#include <cstring>
14#include <fstream>
15#include <iostream>
Chris Austen41a4b312015-10-25 03:45:42 -050016#include <memory>
Saqib Khand33a4af2017-02-20 15:23:27 -060017#include <phosphor-logging/elog.hpp>
Patrick Venture0b02be92018-08-31 11:55:55 -070018#include <vector>
19#include <xyz/openbmc_project/Logging/Entry/server.hpp>
20
Chris Austen41a4b312015-10-25 03:45:42 -050021using namespace std;
Adriana Kobylak2efb3e72017-02-06 21:43:59 -060022using namespace phosphor::logging;
Deepak Kodihalli3d230482018-04-03 07:00:45 -050023using namespace sdbusplus::xyz::openbmc_project::Logging::server;
Chris Austen41a4b312015-10-25 03:45:42 -050024
Chris Austen41a4b312015-10-25 03:45:42 -050025//////////////////////////
Patrick Venture0b02be92018-08-31 11:55:55 -070026struct esel_section_headers_t
27{
Nagaraju Goruganti2fa0e702018-04-16 05:25:21 -050028 uint8_t sectionid[2];
29 uint8_t sectionlength[2];
30 uint8_t version;
31 uint8_t subsectiontype;
32 uint8_t compid;
Chris Austen41a4b312015-10-25 03:45:42 -050033};
34
Tom Josephb647d5b2017-10-31 17:25:33 +053035std::string readESEL(const char* fileName)
36{
37 std::string content;
38 std::ifstream handle(fileName);
39
40 if (handle.fail())
41 {
42 log<level::ERR>("Failed to open eSEL", entry("FILENAME=%s", fileName));
43 return content;
44 }
45
46 handle.seekg(0, std::ios::end);
47 content.resize(handle.tellg());
48 handle.seekg(0, std::ios::beg);
49 handle.read(&content[0], content.size());
50 handle.close();
51
52 return content;
53}
54
55void createProcedureLogEntry(uint8_t procedureNum)
56{
57 // Read the eSEL data from the file.
58 static constexpr auto eSELFile = "/tmp/esel";
59 auto eSELData = readESEL(eSELFile);
60
61 // Each byte in eSEL is formatted as %02x with a space between bytes and
62 // insert '/0' at the end of the character array.
63 static constexpr auto byteSeparator = 3;
Patrick Venture0b02be92018-08-31 11:55:55 -070064 std::unique_ptr<char[]> data(
65 new char[(eSELData.size() * byteSeparator) + 1]());
Tom Josephb647d5b2017-10-31 17:25:33 +053066
67 for (size_t i = 0; i < eSELData.size(); i++)
68 {
69 sprintf(&data[i * byteSeparator], "%02x ", eSELData[i]);
70 }
71 data[eSELData.size() * byteSeparator] = '\0';
72
Patrick Venture0b02be92018-08-31 11:55:55 -070073 using error = sdbusplus::org::open_power::Host::Error::MaintenanceProcedure;
Tom Josephb647d5b2017-10-31 17:25:33 +053074 using metadata = org::open_power::Host::MaintenanceProcedure;
75
76 report<error>(metadata::ESEL(data.get()),
77 metadata::PROCEDURE(static_cast<uint32_t>(procedureNum)));
78}