Fix: Get device ID returns wrong firmware version
Get device ID is currently getting the version and device
information(Product ID, Manufacturing ID etc.) and caching
that data. If any failure while getting the versions info
like D-Bus calls, cache data is not getting updated in next
call. This is purely timing issue.
Added separate initialize flag for firmware version. If any
failure to get firmware version, it will update the cache
on next call.
Tested:
- Get device id works fine always after boot complete.
- Also Unit tested negative scenario by stopping D-Bus service
which provides BMC version and restarting IPMI.
Change-Id: I10025c871cf1d23951b9609fcbed277f2b0069e5
Signed-off-by: AppaRao Puli <apparao.puli@linux.intel.com>
diff --git a/src/appcommands.cpp b/src/appcommands.cpp
index 9b75cb8..539d119 100644
--- a/src/appcommands.cpp
+++ b/src/appcommands.cpp
@@ -249,7 +249,8 @@
uint16_t prodId;
uint32_t aux;
} devId;
- static bool dev_id_initialized = false;
+ static bool fwVerInitialized = false;
+ static bool devIdInitialized = false;
static bool defaultActivationSetting = false;
const char* filename = "/usr/share/ipmi-providers/dev_id.json";
const char* prodIdFilename = "/var/cache/private/prodID";
@@ -257,7 +258,7 @@
constexpr auto ipmiDevIdFw1Mask = ~(1 << ipmiDevIdStateShift);
constexpr auto ipmiDevIdBusy = (1 << ipmiDevIdStateShift);
- if (!dev_id_initialized)
+ if (!fwVerInitialized)
{
std::optional<MetaRevision> rev;
try
@@ -291,6 +292,7 @@
((hash & 0x00FF0000) >> 8) | ((hash & 0x0000FF00) << 8) |
((hash & 0xFF) << 24);
devId.aux = (revision.buildNo & 0xFF) + (hash & 0xFFFFFF00);
+ fwVerInitialized = true;
}
catch (const std::exception& e)
{
@@ -298,7 +300,10 @@
Log::entry("ERROR=%s", e.what()));
}
}
+ }
+ if (!devIdInitialized)
+ {
std::ifstream devIdFile(filename);
if (devIdFile.is_open())
{
@@ -333,13 +338,13 @@
char* end;
prodIdFile.getline(&id[0], id.size() + 1);
devId.prodId = std::strtol(&id[0], &end, 0);
- dev_id_initialized = true;
+ devIdInitialized = true;
}
else
{
// For any exception send out platform id as 0,
// and make sure to re-query the device id.
- dev_id_initialized = false;
+ devIdInitialized = false;
devId.prodId = 0;
}
}