summaryrefslogtreecommitdiff
path: root/services
diff options
context:
space:
mode:
authorcyang29 <cheng.c.yang@intel.com>2018-07-30 11:22:38 +0300
committercyang29 <cheng.c.yang@intel.com>2018-07-30 11:22:38 +0300
commitaa9b3d178f6d0fa61d883d1096f74be2692709aa (patch)
tree32c9dae6cf01cdd879eae38f8817ce3a5916f8df /services
parenta525417502ed45717ae16c20f09a0303b09c3d38 (diff)
downloadprovingground-aa9b3d178f6d0fa61d883d1096f74be2692709aa.tar.xz
Fix some SMBIOS issues base on joint test
Fix some SMBIOS service issues base on joint test with MDRV1 command. Verify method: After power on Intel server system, all the CPU and DIMMs' dbus interface in this code can show correct informaton. And the information should match the real CPU and DIMM installed on MotherBoard. Change-Id: I0bc174df48ae0b06de58d814e14a651f56b7f761 Signed-off-by: cyang29 <cheng.c.yang@intel.com>
Diffstat (limited to 'services')
-rw-r--r--services/smbios/include/manager.hpp38
-rw-r--r--services/smbios/include/smbios.hpp10
-rw-r--r--services/smbios/src/manager.cpp29
3 files changed, 63 insertions, 14 deletions
diff --git a/services/smbios/include/manager.hpp b/services/smbios/include/manager.hpp
index e435ddc..7f2a591 100644
--- a/services/smbios/include/manager.hpp
+++ b/services/smbios/include/manager.hpp
@@ -19,9 +19,14 @@
#include "smbios.hpp"
#include "timer.hpp"
#include "xyz/openbmc_project/Smbios/MDR_V1/server.hpp"
+#include <phosphor-logging/elog-errors.hpp>
#include "cpu.hpp"
#include "dimm.hpp"
#include "system.hpp"
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/io.h>
namespace phosphor
{
@@ -55,12 +60,33 @@ class MDR_V1 : sdbusplus::xyz::openbmc_project::Smbios::server::MDR_V1
}
std::copy(&region[0], &region[3], regionS);
+ if (access(smbiosPath, F_OK) == -1)
+ {
+ int flag = mkdir(smbiosPath, S_IRWXU);
+ if (flag != 0)
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "create folder failed for reading smbios file");
+ return;
+ }
+ }
for (int index = 0; index < maxMdrIndex - 1; index++)
{
- readDataFromFlash(reinterpret_cast<uint8_t *>(&regionS[index]));
+ bool status =
+ readDataFromFlash(reinterpret_cast<uint8_t *>(&regionS[index]),
+ regionS[index].flashName);
+ if (status)
+ {
+ restoreRegion = true;
+ regionComplete(index);
+ }
+ else
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "read data from flash failed",
+ phosphor::logging::entry("REGION ID %d", index));
+ }
}
-
- system = std::make_unique<System>(bus, systemPath, &regionS[0]);
}
std::vector<uint8_t> regionStatus(uint8_t regionId) override;
@@ -95,8 +121,10 @@ class MDR_V1 : sdbusplus::xyz::openbmc_project::Smbios::server::MDR_V1
private:
sdbusplus::bus::bus &bus;
- bool storeDataToFlash(uint8_t *data);
- bool readDataFromFlash(uint8_t *data);
+ bool restoreRegion = false;
+
+ bool storeDataToFlash(uint8_t *data, const char *file);
+ bool readDataFromFlash(uint8_t *data, const char *file);
uint8_t globalRegionId;
diff --git a/services/smbios/include/smbios.hpp b/services/smbios/include/smbios.hpp
index 77a6374..8a1550f 100644
--- a/services/smbios/include/smbios.hpp
+++ b/services/smbios/include/smbios.hpp
@@ -25,6 +25,7 @@ static constexpr uint16_t smbiosTableStorageSize = 0xffff;
static constexpr uint8_t mdrVersion = 0x11; // MDR version 1.1
+static constexpr const char *smbiosPath = "/etc/smbios";
static constexpr const char *mdrType1File = "/etc/smbios/smbios1";
static constexpr const char *mdrType2File = "/etc/smbios/smbios2";
static constexpr const char *mdrAcpiFile = "/etc/smbios/acpi";
@@ -132,14 +133,14 @@ static inline uint8_t *smbiosTypePtr(uint8_t *smbiosDataIn, uint8_t typeId)
{
return nullptr;
}
- uint8_t *smbiosData = smbiosDataIn;
- while ((*smbiosData | *(smbiosData + 1)) != 0)
+ char *smbiosData = reinterpret_cast<char *>(smbiosDataIn);
+ while ((*smbiosData != '\0') || (*(smbiosData + 1) != '\0'))
{
if (*smbiosData != typeId)
{
uint32_t len = *(smbiosData + 1);
smbiosData += len;
- while (*smbiosData | (*smbiosData - 1) != 0)
+ while ((*smbiosData != '\0') || (*(smbiosData + 1) != '\0'))
{
smbiosData++;
len++;
@@ -148,9 +149,10 @@ static inline uint8_t *smbiosTypePtr(uint8_t *smbiosDataIn, uint8_t typeId)
return nullptr;
}
}
+ smbiosData += separateLen;
continue;
}
- return smbiosData;
+ return reinterpret_cast<uint8_t *>(smbiosData);
}
return nullptr;
}
diff --git a/services/smbios/src/manager.cpp b/services/smbios/src/manager.cpp
index 8f80824..1efe87a 100644
--- a/services/smbios/src/manager.cpp
+++ b/services/smbios/src/manager.cpp
@@ -173,6 +173,7 @@ void MDR_V1::systemInfoUpdate()
std::vector<std::unique_ptr<Dimm>>().swap(dimms);
std::vector<std::unique_ptr<Cpu>>().swap(cpus);
+ system = std::make_unique<System>(bus, systemPath, &regionS[0]);
for (int index = 0; index < num; index++)
{
path = dimmPath + std::to_string(index);
@@ -191,9 +192,9 @@ void MDR_V1::systemInfoUpdate()
}
}
-bool MDR_V1::readDataFromFlash(uint8_t *data)
+bool MDR_V1::readDataFromFlash(uint8_t *data, const char *file)
{
- std::ifstream filePtr(mdrType1File, std::ios_base::binary);
+ std::ifstream filePtr(file, std::ios_base::binary);
if (!filePtr.good())
{
phosphor::logging::log<phosphor::logging::level::ERR>(
@@ -212,9 +213,9 @@ bool MDR_V1::readDataFromFlash(uint8_t *data)
return true;
}
-bool MDR_V1::storeDataToFlash(uint8_t *data)
+bool MDR_V1::storeDataToFlash(uint8_t *data, const char *file)
{
- std::ofstream filePtr(mdrType1File, std::ios_base::binary);
+ std::ofstream filePtr(file, std::ios_base::binary);
if (!filePtr.good())
{
phosphor::logging::log<phosphor::logging::level::ERR>(
@@ -263,7 +264,25 @@ void MDR_V1::regionComplete(uint8_t regionId)
// TODO: Create a SEL Log
systemInfoUpdate(); // Update CPU and DIMM information
- if (!storeDataToFlash(reinterpret_cast<uint8_t *>(&regionS[regionId])))
+ // If BMC try to restore region data from BMC flash
+ // no need to store the data to flash again.
+ if (restoreRegion)
+ {
+ restoreRegion = false;
+ return;
+ }
+
+ if (access(smbiosPath, F_OK) == -1)
+ {
+ if (0 != mkdir(smbiosPath, S_IRWXU))
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "create folder failed for writting smbios file");
+ return;
+ }
+ }
+ if (!storeDataToFlash(reinterpret_cast<uint8_t *>(&regionS[regionId]),
+ regionS[regionId].flashName))
{
phosphor::logging::log<phosphor::logging::level::ERR>(
"Store data to flash failed");