Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 1 | #include "private_header.hpp" |
| 2 | |
Matt Spinler | 1a94cc3 | 2019-09-11 13:32:12 -0500 | [diff] [blame] | 3 | #include "pel_types.hpp" |
| 4 | |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 5 | #include <phosphor-logging/log.hpp> |
| 6 | |
| 7 | namespace openpower |
| 8 | { |
| 9 | namespace pels |
| 10 | { |
| 11 | |
| 12 | using namespace phosphor::logging; |
| 13 | |
| 14 | PrivateHeader::PrivateHeader(Stream& pel) |
| 15 | { |
| 16 | try |
| 17 | { |
Matt Spinler | cf5a8d0 | 2019-09-05 12:58:53 -0500 | [diff] [blame] | 18 | unflatten(pel); |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 19 | validate(); |
| 20 | } |
| 21 | catch (const std::exception& e) |
| 22 | { |
| 23 | log<level::ERR>("Cannot unflatten private header", |
| 24 | entry("ERROR=%s", e.what())); |
| 25 | _valid = false; |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | void PrivateHeader::validate() |
| 30 | { |
| 31 | bool failed = false; |
| 32 | |
Matt Spinler | 1a94cc3 | 2019-09-11 13:32:12 -0500 | [diff] [blame] | 33 | if (header().id != static_cast<uint16_t>(SectionID::privateHeader)) |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 34 | { |
| 35 | log<level::ERR>("Invalid private header section ID", |
| 36 | entry("ID=0x%X", header().id)); |
| 37 | failed = true; |
| 38 | } |
| 39 | |
| 40 | if (header().version != privateHeaderVersion) |
| 41 | { |
| 42 | log<level::ERR>("Invalid private header version", |
| 43 | entry("VERSION=0x%X", header().version)); |
| 44 | failed = true; |
| 45 | } |
| 46 | |
| 47 | if (_sectionCount < minSectionCount) |
| 48 | { |
| 49 | log<level::ERR>("Invalid section count in private header", |
| 50 | entry("SECTION_COUNT=0x%X", _sectionCount)); |
| 51 | failed = true; |
| 52 | } |
| 53 | |
| 54 | _valid = (failed) ? false : true; |
| 55 | } |
| 56 | |
Matt Spinler | cf5a8d0 | 2019-09-05 12:58:53 -0500 | [diff] [blame] | 57 | void PrivateHeader::unflatten(Stream& stream) |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 58 | { |
Matt Spinler | cf5a8d0 | 2019-09-05 12:58:53 -0500 | [diff] [blame] | 59 | stream >> _header >> _createTimestamp >> _commitTimestamp >> _creatorID >> |
| 60 | _logType >> _reservedByte >> _sectionCount >> _obmcLogID >> |
| 61 | _creatorVersion >> _plid >> _id; |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 62 | } |
| 63 | |
Matt Spinler | cf5a8d0 | 2019-09-05 12:58:53 -0500 | [diff] [blame] | 64 | void PrivateHeader::flatten(Stream& stream) |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 65 | { |
Matt Spinler | cf5a8d0 | 2019-09-05 12:58:53 -0500 | [diff] [blame] | 66 | stream << _header << _createTimestamp << _commitTimestamp << _creatorID |
| 67 | << _logType << _reservedByte << _sectionCount << _obmcLogID |
| 68 | << _creatorVersion << _plid << _id; |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | Stream& operator>>(Stream& s, CreatorVersion& cv) |
| 72 | { |
| 73 | for (size_t i = 0; i < sizeof(CreatorVersion); i++) |
| 74 | { |
| 75 | s >> cv.version[i]; |
| 76 | } |
| 77 | return s; |
| 78 | } |
| 79 | |
| 80 | Stream& operator<<(Stream& s, CreatorVersion& cv) |
| 81 | { |
| 82 | for (size_t i = 0; i < sizeof(CreatorVersion); i++) |
| 83 | { |
| 84 | s << cv.version[i]; |
| 85 | } |
| 86 | return s; |
| 87 | } |
| 88 | |
| 89 | } // namespace pels |
| 90 | } // namespace openpower |