Add overlay logic to Entity Manager
Generate overlays and fixup symbols to map virtual i2c
busses to muxes. Also scan muxes in order as they seem
to get confused if we scan them out of order.
Change-Id: Iec3ed49fca22db8537e4474d9d95cab2da574aef
Signed-off-by: James Feist <james.feist@linux.intel.com>
diff --git a/src/FruDevice.cpp b/src/FruDevice.cpp
index 83b60e2..4eea9a5 100644
--- a/src/FruDevice.cpp
+++ b/src/FruDevice.cpp
@@ -31,7 +31,6 @@
namespace fs = std::experimental::filesystem;
static constexpr bool DEBUG = false;
-static constexpr size_t SLEEP_SECONDS_AFTER_PGOOD = 5;
static size_t UNKNOWN_BUS_OBJECT_COUNT = 0;
const static constexpr char *BASEBOARD_FRU_LOCATION =
@@ -43,6 +42,12 @@
using DeviceMap = boost::container::flat_map<int, std::vector<char>>;
using BusMap = boost::container::flat_map<int, std::shared_ptr<DeviceMap>>;
+static bool isMuxBus(size_t bus)
+{
+ return is_symlink(std::experimental::filesystem::path(
+ "/sys/bus/i2c/devices/i2c-" + std::to_string(bus) + "/mux_device"));
+}
+
int get_bus_frus(int file, int first, int last, int bus,
std::shared_ptr<DeviceMap> devices)
{
@@ -173,16 +178,26 @@
auto &device = busMap[bus];
device = std::make_shared<DeviceMap>();
- // todo: call with boost asio?
- futures.emplace_back(
- std::async(std::launch::async, [file, device, bus] {
- // i2cdetect by default uses the range 0x03 to 0x77, as this is
- // what we
- // have tested with, use this range. Could be changed in
- // future.
- get_bus_frus(file, 0x03, 0x77, bus, device);
- close(file);
- }));
+ // don't scan muxed buses async as don't want to confuse the mux
+ if (isMuxBus(bus))
+ {
+ get_bus_frus(file, 0x03, 0x77, bus, device);
+ close(file);
+ }
+ else
+ {
+ // todo: call with boost asio?
+ futures.emplace_back(
+ std::async(std::launch::async, [file, device, bus] {
+ // i2cdetect by default uses the range 0x03 to 0x77, as
+ // this is
+ // what we
+ // have tested with, use this range. Could be changed in
+ // future.
+ get_bus_frus(file, 0x03, 0x77, bus, device);
+ close(file);
+ }));
+ }
}
for (auto &fut : futures)
{
@@ -329,12 +344,6 @@
return true;
}
-static bool isMuxBus(size_t bus)
-{
- return std::experimental::filesystem::exists(
- "/sys/bus/i2c/devices/i2c-" + std::to_string(bus) + "/mux_device");
-}
-
void AddFruObjectToDbus(
std::shared_ptr<dbus::connection> dbusConn, std::vector<char> &device,
dbus::DbusObjectServer &objServer,
@@ -438,6 +447,9 @@
std::cerr << "unable to find i2c devices\n";
return;
}
+ // scanning muxes in reverse order seems to have adverse effects
+ // sorting this list seems to be a fix for that
+ std::sort(i2cBuses.begin(), i2cBuses.end());
BusMap busMap = FindI2CDevices(i2cBuses);
for (auto &busObj : dbusObjectMap)
@@ -476,7 +488,6 @@
std::cerr << "unable to find i2c devices\n";
return 1;
}
- BusMap busMap = FindI2CDevices(i2cBuses);
boost::asio::io_service io;
auto systemBus = std::make_shared<dbus::connection>(io, dbus::bus::system);
@@ -534,8 +545,6 @@
{
threadRunning = true;
future = std::async(std::launch::async, [&] {
- std::this_thread::sleep_for(
- std::chrono::seconds(SLEEP_SECONDS_AFTER_PGOOD));
rescanBusses(dbusObjectMap, systemBus, objServer);
threadRunning = false;
});