summaryrefslogtreecommitdiff
path: root/services
diff options
context:
space:
mode:
authorcyang29 <cheng.c.yang@intel.com>2018-10-17 11:44:08 +0300
committercyang29 <cheng.c.yang@intel.com>2018-10-17 11:44:08 +0300
commit5503c09b879b4baf5cd94c70dbf0856766bade20 (patch)
tree595437fe0161af19bfa437f5c3f8072c06fd3836 /services
parenta1c921909056c5df7ca523ffcf96ab4b2470dd7b (diff)
downloadprovingground-5503c09b879b4baf5cd94c70dbf0856766bade20.tar.xz
Add synchronization function for MDR V2
Add synchronization function to sync smbios dir data with BMC through dbus interface. Also add function to read smbios table from flash file to memory. Change-Id: I9e430df504acb0197d6d3288a6d7799ac428b579 Signed-off-by: cyang29 <cheng.c.yang@intel.com>
Diffstat (limited to 'services')
-rw-r--r--services/smbios-mdrv2/include/mdrv2.hpp14
-rw-r--r--services/smbios-mdrv2/include/smbios-mdrv2.hpp6
-rw-r--r--services/smbios-mdrv2/src/mdrv2.cpp81
-rw-r--r--services/smbios-mdrv2/src/smbios-mdrv2-main.cpp3
4 files changed, 98 insertions, 6 deletions
diff --git a/services/smbios-mdrv2/include/mdrv2.hpp b/services/smbios-mdrv2/include/mdrv2.hpp
index 6377277..3a4bb23 100644
--- a/services/smbios-mdrv2/include/mdrv2.hpp
+++ b/services/smbios-mdrv2/include/mdrv2.hpp
@@ -24,6 +24,7 @@
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/log.hpp>
#include <sdbusplus/server.hpp>
+#include <sdbusplus/timer.hpp>
#include <xyz/openbmc_project/Smbios/MDR_V2/server.hpp>
namespace phosphor
@@ -43,9 +44,9 @@ class MDR_V2 : sdbusplus::xyz::openbmc_project::Smbios::server::MDR_V2
MDR_V2 &operator=(MDR_V2 &&) = delete;
~MDR_V2() = default;
- MDR_V2(sdbusplus::bus::bus &bus, const char *path) :
+ MDR_V2(sdbusplus::bus::bus &bus, const char *path, sd_event *event) :
sdbusplus::xyz::openbmc_project::Smbios::server::MDR_V2(bus, path),
- bus(bus)
+ bus(bus), timer(event, [&](void) { agentSynchronizeData(); })
{
smbiosDir.agentVersion = smbiosAgentVersion;
@@ -57,6 +58,10 @@ class MDR_V2 : sdbusplus::xyz::openbmc_project::Smbios::server::MDR_V2
std::copy(smbiosTableId.begin(), smbiosTableId.end(),
smbiosDir.dir[smbiosDirIndex].common.id.dataInfo);
+
+ smbiosDir.dir[smbiosDirIndex].dataStorage = smbiosTableStorage;
+
+ agentSynchronizeData();
}
std::vector<uint8_t> getDirectoryInformation(uint8_t dirIndex) override;
@@ -83,14 +88,19 @@ class MDR_V2 : sdbusplus::xyz::openbmc_project::Smbios::server::MDR_V2
uint8_t directoryEntries(uint8_t value) override;
private:
+ Timer timer;
+
sdbusplus::bus::bus &bus;
Mdr2DirStruct smbiosDir;
+ bool readDataFromFlash(MDRSMBIOSHeader *mdrHdr, uint8_t *data);
+
const std::array<uint8_t, 16> smbiosTableId{
40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 0x42};
uint8_t smbiosTableStorage[smbiosTableStorageSize];
+ bool smbiosIsUpdating(uint8_t index);
bool smbiosIsAvailForUpdate(uint8_t index);
inline uint8_t smbiosValidFlag(uint8_t index);
};
diff --git a/services/smbios-mdrv2/include/smbios-mdrv2.hpp b/services/smbios-mdrv2/include/smbios-mdrv2.hpp
index 50482cb..9591e78 100644
--- a/services/smbios-mdrv2/include/smbios-mdrv2.hpp
+++ b/services/smbios-mdrv2/include/smbios-mdrv2.hpp
@@ -21,7 +21,7 @@
static constexpr const char *mdrType2File = "/etc/smbios/smbios2";
static constexpr const char *smbiosPath = "/etc/smbios";
-static constexpr uint16_t mdrSmbiosSize = 32 * 1024;
+static constexpr uint16_t mdrSMBIOSSize = 32 * 1024;
constexpr uint16_t smbiosAgentId = 0x0101;
constexpr int firstAgentIndex = 1;
@@ -43,7 +43,7 @@ constexpr uint32_t smbiosTableTimestamp = 0x45464748;
constexpr uint32_t smbiosSMMemoryOffset = 0;
constexpr uint32_t smbiosSMMemorySize = 1024 * 1024;
constexpr uint32_t smbiosTableStorageSize = 64 * 1024;
-constexpr uint32_t defaultTimeout = 200;
+constexpr uint32_t defaultTimeout = 2000;
enum class MDR2SMBIOSStatusEnum
{
@@ -109,7 +109,7 @@ typedef struct
Mdr2DirLocalStruct dir[maxDirEntries];
} Mdr2DirStruct;
-struct MDRSmbiosHeader
+struct MDRSMBIOSHeader
{
uint8_t dirVer;
uint8_t mdrType;
diff --git a/services/smbios-mdrv2/src/mdrv2.cpp b/services/smbios-mdrv2/src/mdrv2.cpp
index dd3bad2..3b8858e 100644
--- a/services/smbios-mdrv2/src/mdrv2.cpp
+++ b/services/smbios-mdrv2/src/mdrv2.cpp
@@ -178,6 +178,58 @@ std::vector<uint8_t> MDR_V2::getDataInformation(uint8_t idIndex)
return responseInfo;
}
+bool MDR_V2::readDataFromFlash(MDRSMBIOSHeader *mdrHdr, uint8_t *data)
+{
+ if (mdrHdr == nullptr)
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "Read data from flash error - Invalid mdr header");
+ return false;
+ }
+ if (data == nullptr)
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "Read data from flash error - Invalid data point");
+ return false;
+ }
+ std::ifstream smbiosFile(mdrType2File, std::ios_base::binary);
+ if (!smbiosFile.good())
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "Read data from flash error - Open MDRV2 table file failure");
+ return false;
+ }
+ smbiosFile.clear();
+ smbiosFile.seekg(0, std::ios_base::end);
+ int fileLength = smbiosFile.tellg();
+ smbiosFile.seekg(0, std::ios_base::beg);
+ if (fileLength < sizeof(MDRSMBIOSHeader))
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "MDR V2 file size is smaller than mdr header");
+ return false;
+ }
+ smbiosFile.read(reinterpret_cast<char *>(mdrHdr), sizeof(MDRSMBIOSHeader));
+ if (mdrHdr->dataSize > smbiosTableStorageSize)
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "Data size out of limitation");
+ smbiosFile.close();
+ return false;
+ }
+ fileLength -= sizeof(MDRSMBIOSHeader);
+ if (fileLength < mdrHdr->dataSize)
+ {
+ smbiosFile.read(reinterpret_cast<char *>(data), fileLength);
+ }
+ else
+ {
+ smbiosFile.read(reinterpret_cast<char *>(data), mdrHdr->dataSize);
+ }
+ smbiosFile.close();
+ return true;
+}
+
bool MDR_V2::sendDirectoryInformation(uint8_t dirVersion, uint8_t dirIndex,
uint8_t returnedEntries,
uint8_t remainingEntries,
@@ -307,11 +359,40 @@ uint8_t MDR_V2::directoryEntries(uint8_t value)
bool MDR_V2::agentSynchronizeData()
{
+ struct MDRSMBIOSHeader mdr2SMBIOS;
+ bool status = readDataFromFlash(&mdr2SMBIOS,
+ smbiosDir.dir[smbiosDirIndex].dataStorage);
+ if (!status)
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "agent data sync failed - read data from flash failed");
+ return false;
+ }
+ else
+ {
+ smbiosDir.dir[smbiosDirIndex].common.dataVersion = mdr2SMBIOS.dirVer;
+ smbiosDir.dir[smbiosDirIndex].common.timestamp = mdr2SMBIOS.timestamp;
+ smbiosDir.dir[smbiosDirIndex].common.size = mdr2SMBIOS.dataSize;
+ smbiosDir.dir[smbiosDirIndex].stage = MDR2SMBIOSStatusEnum::mdr2Loaded;
+ smbiosDir.dir[smbiosDirIndex].lock = MDR2DirLockEnum::mdr2DirUnlock;
+ }
+ timer.stop();
+ return true;
}
std::vector<uint32_t> MDR_V2::synchronizeDirectoryCommonData(uint8_t idIndex,
uint32_t size)
{
+ std::chrono::microseconds usec(
+ defaultTimeout); // default lock time out is 2s
+ std::vector<uint32_t> result;
+ smbiosDir.dir[idIndex].common.size = size;
+ result.push_back(smbiosDir.dir[idIndex].common.dataSetSize);
+ result.push_back(smbiosDir.dir[idIndex].common.dataVersion);
+ result.push_back(smbiosDir.dir[idIndex].common.timestamp);
+
+ timer.start(usec);
+ return result;
}
} // namespace smbios
diff --git a/services/smbios-mdrv2/src/smbios-mdrv2-main.cpp b/services/smbios-mdrv2/src/smbios-mdrv2-main.cpp
index e96da8e..bb26ff6 100644
--- a/services/smbios-mdrv2/src/smbios-mdrv2-main.cpp
+++ b/services/smbios-mdrv2/src/smbios-mdrv2-main.cpp
@@ -29,7 +29,7 @@ int main(void)
bus.attach_event(events, SD_EVENT_PRIORITY_NORMAL);
bus.request_name("xyz.openbmc_project.Smbios.MDR_V2");
- phosphor::smbios::MDR_V2 mdrV2(bus, phosphor::smbios::mdrV2Path);
+ phosphor::smbios::MDR_V2 mdrV2(bus, phosphor::smbios::mdrV2Path, events);
while (true)
{
@@ -42,5 +42,6 @@ int main(void)
return -1;
}
}
+
return 0;
}