Change primary postcode interface to byte array
Change primary code to std::vector<uint8_t> to meet the changes in
phosphor-dbus-interface.
[1] https://gerrit.openbmc.org/c/openbmc/phosphor-dbus-interfaces/+/74633
Change-Id: Ib5822973a1dbc6aa8c52f4e81b56091dc33b5f08
Signed-off-by: Cosmo Chou <cosmo.chou@quantatw.com>
Signed-off-by: Potin Lai <potin.lai@quantatw.com>
diff --git a/main.cpp b/main.cpp
index e544a11..f4353d7 100644
--- a/main.cpp
+++ b/main.cpp
@@ -44,7 +44,7 @@
static size_t codeSize = 1; /* Size of each POST code in bytes */
static bool verbose = false;
-static std::function<bool(uint64_t&, ssize_t)> procPostCode;
+static std::function<bool(std::vector<uint8_t>&, ssize_t)> procPostCode;
static void usage(const char* name)
{
@@ -134,7 +134,7 @@
* aspeedPCCBuffer contains enough PCC codes, the postcode will be assigned as
* 0xDDCCBBAA.
*/
-bool aspeedPCC(uint64_t& code, ssize_t readb)
+bool aspeedPCC(std::vector<uint8_t>& code, ssize_t readb)
{
// Size of data coming from the PCC hardware
constexpr size_t pccSize = sizeof(uint16_t);
@@ -148,7 +148,7 @@
constexpr uint16_t pccPostCodeMask = 0x00FF;
constexpr uint8_t byteShift = 8;
- uint16_t* codePtr = reinterpret_cast<uint16_t*>(&code);
+ uint16_t* codePtr = reinterpret_cast<uint16_t*>(code.data());
for (size_t i = 0; i < (readb / pccSize); i++)
{
@@ -180,11 +180,10 @@
}
// Remove the prefix bytes and combine the partial postcodes together.
- code = 0;
- for (size_t i = 0; i < fullPostPCCCount; i++)
+ code.clear();
+ for (size_t i = fullPostPCCCount; i > 0; --i)
{
- code |= static_cast<uint64_t>(aspeedPCCBuffer[i] & pccPostCodeMask)
- << (byteShift * i);
+ code.push_back(aspeedPCCBuffer[i - 1] & pccPostCodeMask);
}
aspeedPCCBuffer.erase(aspeedPCCBuffer.begin(),
aspeedPCCBuffer.begin() + fullPostPCCCount);
@@ -199,30 +198,37 @@
void PostCodeEventHandler(PostReporter* reporter, sdeventplus::source::IO& s,
int postFd, uint32_t)
{
- uint64_t code = 0;
+ std::vector<uint8_t> code(codeSize, 0);
ssize_t readb;
- while ((readb = read(postFd, &code, codeSize)) > 0)
+ while ((readb = read(postFd, code.data(), codeSize)) > 0)
{
if (procPostCode && procPostCode(code, readb) == false)
{
return;
}
- code = le64toh(code);
if (verbose)
{
- fprintf(stderr, "Code: 0x%" PRIx64 "\n", code);
+ fprintf(stderr, "Code: 0x");
+ for (const auto& byte : code)
+ {
+ fprintf(stderr, "%02x", byte);
+ }
+ fprintf(stderr, "\n");
}
// HACK: Always send property changed signal even for the same code
// since we are single threaded, external users will never see the
// first value.
- reporter->value(std::make_tuple(~code, secondary_post_code_t{}), true);
+ code[0] = ~code[0];
+ reporter->value(std::make_tuple(code, secondary_post_code_t{}), true);
+ code[0] = ~code[0];
reporter->value(std::make_tuple(code, secondary_post_code_t{}));
// read depends on old data being cleared since it doesn't always read
// the full code size
- code = 0;
+ code.resize(codeSize);
+ std::fill(code.begin(), code.end(), 0);
if (rateLimit(*reporter, s))
{