blob: 7fd7b0ee1cc0954a2ed8351f0dee864b6787f259 [file] [log] [blame]
Matt Spinlerf9bae182019-10-09 13:37:38 -05001#include "src.hpp"
2
3#include <phosphor-logging/log.hpp>
4
5namespace openpower
6{
7namespace pels
8{
9
10using namespace phosphor::logging;
11
12void SRC::unflatten(Stream& stream)
13{
14 stream >> _header >> _version >> _flags >> _reserved1B >> _wordCount >>
15 _reserved2B >> _size;
16
17 for (auto& word : _hexData)
18 {
19 stream >> word;
20 }
21
22 _asciiString = std::make_unique<src::AsciiString>(stream);
23
24 if (hasAdditionalSections())
25 {
26 // The callouts section is currently the only extra subsection type
27 _callouts = std::make_unique<src::Callouts>(stream);
28 }
29}
30
31void SRC::flatten(Stream& stream)
32{
33 stream << _header << _version << _flags << _reserved1B << _wordCount
34 << _reserved2B << _size;
35
36 for (auto& word : _hexData)
37 {
38 stream << word;
39 }
40
41 _asciiString->flatten(stream);
42
43 if (_callouts)
44 {
45 _callouts->flatten(stream);
46 }
47}
48
49SRC::SRC(Stream& pel)
50{
51 try
52 {
53 unflatten(pel);
54 validate();
55 }
56 catch (const std::exception& e)
57 {
58 log<level::ERR>("Cannot unflatten SRC", entry("ERROR=%s", e.what()));
59 _valid = false;
60 }
61}
62
63void SRC::validate()
64{
65 bool failed = false;
66
67 if ((header().id != static_cast<uint16_t>(SectionID::primarySRC)) &&
68 (header().id != static_cast<uint16_t>(SectionID::secondarySRC)))
69 {
70 log<level::ERR>("Invalid SRC section ID",
71 entry("ID=0x%X", header().id));
72 failed = true;
73 }
74
75 // Check the version in the SRC, not in the header
76 if (_version != srcSectionVersion)
77 {
78 log<level::ERR>("Invalid SRC section version",
79 entry("VERSION=0x%X", _version));
80 failed = true;
81 }
82
83 _valid = failed ? false : true;
84}
85
86} // namespace pels
87} // namespace openpower