Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 1 | #include "private_header.hpp" |
| 2 | |
Matt Spinler | 289aa47 | 2019-09-20 12:33:29 -0500 | [diff] [blame] | 3 | #include "log_id.hpp" |
Matt Spinler | 1a94cc3 | 2019-09-11 13:32:12 -0500 | [diff] [blame] | 4 | #include "pel_types.hpp" |
| 5 | |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 6 | #include <phosphor-logging/log.hpp> |
| 7 | |
| 8 | namespace openpower |
| 9 | { |
| 10 | namespace pels |
| 11 | { |
| 12 | |
| 13 | using namespace phosphor::logging; |
| 14 | |
Matt Spinler | 289aa47 | 2019-09-20 12:33:29 -0500 | [diff] [blame] | 15 | PrivateHeader::PrivateHeader(uint16_t componentID, uint32_t obmcLogID, |
| 16 | uint64_t timestamp) |
| 17 | { |
| 18 | _header.id = static_cast<uint16_t>(SectionID::privateHeader); |
| 19 | _header.size = PrivateHeader::flattenedSize(); |
| 20 | _header.version = privateHeaderVersion; |
| 21 | _header.subType = 0; |
| 22 | _header.componentID = componentID; |
| 23 | |
| 24 | _createTimestamp = getBCDTime(timestamp); |
| 25 | |
| 26 | auto now = std::chrono::system_clock::now(); |
| 27 | _commitTimestamp = getBCDTime(now); |
| 28 | |
| 29 | _creatorID = static_cast<uint8_t>(CreatorID::openBMC); |
| 30 | |
| 31 | // Add support for reminder and telemetry log types here if |
| 32 | // ever necessary. |
| 33 | _logType = 0; |
| 34 | |
| 35 | _reservedByte = 0; |
| 36 | |
| 37 | // the final section count will be updated later |
| 38 | _sectionCount = 1; |
| 39 | |
| 40 | _obmcLogID = obmcLogID; |
| 41 | |
| 42 | _id = generatePELID(); |
| 43 | |
| 44 | _plid = _id; |
| 45 | |
| 46 | // Leave _creatorVersion at 0 |
| 47 | |
| 48 | _valid = true; |
| 49 | } |
| 50 | |
Matt Spinler | 31eed99 | 2019-10-09 14:07:52 -0500 | [diff] [blame] | 51 | PrivateHeader::PrivateHeader(Stream& pel) : |
| 52 | _creatorID(0), _logType(0), _reservedByte(0), _sectionCount(0), |
| 53 | _obmcLogID(0), _plid(0), _id(0) |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 54 | { |
| 55 | try |
| 56 | { |
Matt Spinler | cf5a8d0 | 2019-09-05 12:58:53 -0500 | [diff] [blame] | 57 | unflatten(pel); |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 58 | validate(); |
| 59 | } |
| 60 | catch (const std::exception& e) |
| 61 | { |
| 62 | log<level::ERR>("Cannot unflatten private header", |
| 63 | entry("ERROR=%s", e.what())); |
| 64 | _valid = false; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | void PrivateHeader::validate() |
| 69 | { |
| 70 | bool failed = false; |
| 71 | |
Matt Spinler | 1a94cc3 | 2019-09-11 13:32:12 -0500 | [diff] [blame] | 72 | if (header().id != static_cast<uint16_t>(SectionID::privateHeader)) |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 73 | { |
| 74 | log<level::ERR>("Invalid private header section ID", |
| 75 | entry("ID=0x%X", header().id)); |
| 76 | failed = true; |
| 77 | } |
| 78 | |
| 79 | if (header().version != privateHeaderVersion) |
| 80 | { |
| 81 | log<level::ERR>("Invalid private header version", |
| 82 | entry("VERSION=0x%X", header().version)); |
| 83 | failed = true; |
| 84 | } |
| 85 | |
| 86 | if (_sectionCount < minSectionCount) |
| 87 | { |
| 88 | log<level::ERR>("Invalid section count in private header", |
| 89 | entry("SECTION_COUNT=0x%X", _sectionCount)); |
| 90 | failed = true; |
| 91 | } |
| 92 | |
| 93 | _valid = (failed) ? false : true; |
| 94 | } |
| 95 | |
Matt Spinler | cf5a8d0 | 2019-09-05 12:58:53 -0500 | [diff] [blame] | 96 | void PrivateHeader::unflatten(Stream& stream) |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 97 | { |
Matt Spinler | cf5a8d0 | 2019-09-05 12:58:53 -0500 | [diff] [blame] | 98 | stream >> _header >> _createTimestamp >> _commitTimestamp >> _creatorID >> |
| 99 | _logType >> _reservedByte >> _sectionCount >> _obmcLogID >> |
| 100 | _creatorVersion >> _plid >> _id; |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 101 | } |
| 102 | |
Matt Spinler | cf5a8d0 | 2019-09-05 12:58:53 -0500 | [diff] [blame] | 103 | void PrivateHeader::flatten(Stream& stream) |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 104 | { |
Matt Spinler | cf5a8d0 | 2019-09-05 12:58:53 -0500 | [diff] [blame] | 105 | stream << _header << _createTimestamp << _commitTimestamp << _creatorID |
| 106 | << _logType << _reservedByte << _sectionCount << _obmcLogID |
| 107 | << _creatorVersion << _plid << _id; |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | Stream& operator>>(Stream& s, CreatorVersion& cv) |
| 111 | { |
| 112 | for (size_t i = 0; i < sizeof(CreatorVersion); i++) |
| 113 | { |
| 114 | s >> cv.version[i]; |
| 115 | } |
| 116 | return s; |
| 117 | } |
| 118 | |
| 119 | Stream& operator<<(Stream& s, CreatorVersion& cv) |
| 120 | { |
| 121 | for (size_t i = 0; i < sizeof(CreatorVersion); i++) |
| 122 | { |
| 123 | s << cv.version[i]; |
| 124 | } |
| 125 | return s; |
| 126 | } |
| 127 | |
| 128 | } // namespace pels |
| 129 | } // namespace openpower |