aboutsummaryrefslogtreecommitdiffstats
path: root/mpm/python/usrp_mpm
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2017-05-23 15:16:50 -0700
committerMartin Braun <martin.braun@ettus.com>2017-12-22 15:03:53 -0800
commit245b96a777afbeb84990ebb377def658879c2fa1 (patch)
tree7333a32c4bd9381b76aef28db0245e2d30a30ef7 /mpm/python/usrp_mpm
parente9a1af171eecb333326b3d791fd6516788ec7cac (diff)
downloaduhd-245b96a777afbeb84990ebb377def658879c2fa1.tar.gz
uhd-245b96a777afbeb84990ebb377def658879c2fa1.tar.bz2
uhd-245b96a777afbeb84990ebb377def658879c2fa1.zip
mpm: Added auto-loading of dboard-specific overlays
Diffstat (limited to 'mpm/python/usrp_mpm')
-rw-r--r--mpm/python/usrp_mpm/CMakeLists.txt1
-rw-r--r--mpm/python/usrp_mpm/dboard_manager/base.py6
-rw-r--r--mpm/python/usrp_mpm/dboard_manager/eiscat.py1
-rw-r--r--mpm/python/usrp_mpm/dtoverlay.py111
-rw-r--r--mpm/python/usrp_mpm/periph_manager/base.py9
5 files changed, 126 insertions, 2 deletions
diff --git a/mpm/python/usrp_mpm/CMakeLists.txt b/mpm/python/usrp_mpm/CMakeLists.txt
index a470f8e67..a08e3fea1 100644
--- a/mpm/python/usrp_mpm/CMakeLists.txt
+++ b/mpm/python/usrp_mpm/CMakeLists.txt
@@ -22,6 +22,7 @@ SET(USRP_MPM_FILES ${USRP_MPM_FILES})
SET(USRP_MPM_TOP_FILES
${CMAKE_CURRENT_SOURCE_DIR}/__init__.py
${CMAKE_CURRENT_SOURCE_DIR}/discovery.py
+ ${CMAKE_CURRENT_SOURCE_DIR}/dtoverlay.py
${CMAKE_CURRENT_SOURCE_DIR}/mpmlog.py
${CMAKE_CURRENT_SOURCE_DIR}/nijesdcore.py
${CMAKE_CURRENT_SOURCE_DIR}/rpc_server.py
diff --git a/mpm/python/usrp_mpm/dboard_manager/base.py b/mpm/python/usrp_mpm/dboard_manager/base.py
index c7e116fc0..e16906cb4 100644
--- a/mpm/python/usrp_mpm/dboard_manager/base.py
+++ b/mpm/python/usrp_mpm/dboard_manager/base.py
@@ -38,6 +38,12 @@ class DboardManagerBase(object):
# maps these keys to actual spidev paths. Also throws a warning/error if
# the SPI configuration is invalid.
spi_chipselect = {}
+ # Lists device tree overlays that need to be applied before this class can
+ # be used. List of strings. If strings contain the token {sfp}, it will be
+ # expanded to the flavour of SFP configuration is (XG, 1G, ...).
+ # Example: 'magnesium-{sfp}' could get expanded to 'eiscat-XG'.
+ # Are applied in order.
+ dt_overlays = []
def __init__(self, slot_idx, **kwargs):
self.log = get_logger('dboardManager')
diff --git a/mpm/python/usrp_mpm/dboard_manager/eiscat.py b/mpm/python/usrp_mpm/dboard_manager/eiscat.py
index 78d5d0e18..c0a5e2fb1 100644
--- a/mpm/python/usrp_mpm/dboard_manager/eiscat.py
+++ b/mpm/python/usrp_mpm/dboard_manager/eiscat.py
@@ -366,6 +366,7 @@ class EISCAT(DboardManagerBase):
"adc1": create_spidev_iface_sane,
"phase_dac": create_spidev_iface_phasedac,
}
+ dt_overlays = ['eiscat-{sfp}']
def __init__(self, slot_idx, **kwargs):
super(EISCAT, self).__init__(slot_idx, **kwargs)
diff --git a/mpm/python/usrp_mpm/dtoverlay.py b/mpm/python/usrp_mpm/dtoverlay.py
new file mode 100644
index 000000000..65b350a04
--- /dev/null
+++ b/mpm/python/usrp_mpm/dtoverlay.py
@@ -0,0 +1,111 @@
+#
+# Copyright 2017 Ettus Research (National Instruments)
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+"""
+Manipulation of device tree overlays (Linux kernel)
+"""
+
+import os
+from .mpmlog import get_logger
+
+SYSFS_OVERLAY_BASE_DIR = '/sys/kernel/config/device-tree/overlays'
+OVERLAY_DEFAULT_PATH = '/lib/firmware'
+
+def get_overlay_attrs(overlay_name):
+ """
+ List those attributes that are connected to an overlay entry in a sysfs
+ node.
+ """
+ overlay_path = os.path.join(SYSFS_OVERLAY_BASE_DIR, overlay_name)
+ attrs = {}
+ for attr_name in os.listdir(overlay_path):
+ try:
+ attr_val = open(
+ os.path.join(overlay_path, attr_name), 'r'
+ ).read().strip()
+ except OSError:
+ pass
+ if len(attr_val):
+ attrs[attr_name] = attr_val
+ return attrs
+
+def list_overlays(applied_only=False):
+ """
+ List all registered kernel modules. Returns a dict of dicts:
+ {
+ '<overlay_name>': {
+ # attributes
+ },
+ }
+
+ All the attributes come from sysfs. See get_overlay_attrs().
+
+ applied_only -- Only return those overlays that are already applied.
+ """
+ return {
+ overlay_name: get_overlay_attrs(overlay_name)
+ for overlay_name in os.listdir(SYSFS_OVERLAY_BASE_DIR)
+ if not applied_only \
+ or get_overlay_attrs(overlay_name).get('status') == 'applied'
+ }
+
+def list_available_overlays(path):
+ """
+ List available overlay files (dtbo)
+ """
+ path = path or OVERLAY_DEFAULT_PATH
+ return [x.strip()[:-5] for x in os.listdir(path) if x.endswith('.dtbo')]
+
+def apply_overlay(overlay_name):
+ """
+ Applies the given overlay. Does not check if the overlay is loaded.
+ """
+ get_logger("DTO").trace("Applying overlay `{}'...".format(overlay_name))
+ # TODO don't use this script
+ os.system("overlay add {}".format(overlay_name))
+
+def apply_overlay_safe(overlay_name):
+ """
+ Only apply an overlay if it's not yet applied.
+ """
+ if overlay_name in list_overlays(applied_only=True).keys():
+ get_logger("DTO").debug(
+ "Overlay `{}' was already applied, not applying again.".format(
+ overlay_name
+ )
+ )
+ else:
+ apply_overlay(overlay_name)
+
+def rm_overlay(overlay_name):
+ """
+ Removes the given overlay. Does not check if the overlay is loaded.
+ """
+ get_logger("DTO").trace("Removing overlay `{}'...".format(overlay_name))
+ # TODO don't use this script
+ os.system("overlay rm {}".format(overlay_name))
+
+def rm_overlay_safe(overlay_name):
+ """
+ Only remove an overlay if it's already applied.
+ """
+ if overlay_name in list_overlays(applied_only=True).keys():
+ rm_overlay(overlay_name)
+ else:
+ get_logger("DTO").debug(
+ "Overlay `{}' was not loaded, not removing.".format(overlay_name)
+ )
+
diff --git a/mpm/python/usrp_mpm/periph_manager/base.py b/mpm/python/usrp_mpm/periph_manager/base.py
index 022464476..a9259f304 100644
--- a/mpm/python/usrp_mpm/periph_manager/base.py
+++ b/mpm/python/usrp_mpm/periph_manager/base.py
@@ -25,6 +25,7 @@ from ..mpmlog import get_logger
from .udev import get_eeprom_paths
from .udev import get_spidev_nodes
from usrp_mpm import net
+from usrp_mpm import dtoverlay
EEPROM_DEFAULT_HEADER = struct.Struct("!I I")
@@ -340,11 +341,15 @@ class PeriphManagerBase(object):
if db_class is None:
self.log.warning("Could not identify daughterboard class for PID {:04X}!".format(db_pid))
continue
+ self.log.trace("Dboard requires device tree overlays: {}".format(
+ db_class.dt_overlays
+ ))
+ for overlay in db_class.dt_overlays:
+ # FIXME don't hardcode XG
+ dtoverlay.apply_overlay_safe(overlay.format(sfp="XG"))
self.dboards.append(db_class(dboard_idx, **dboard_info))
self.log.info("Found {} daughterboard(s).".format(len(self.dboards)))
- # self.overlays = ""
-
def _init_interfaces(self):
"""
Initialize the list of network interfaces