aboutsummaryrefslogtreecommitdiffstats
path: root/mpm/python
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2017-05-23 16:11:07 -0700
committerMartin Braun <martin.braun@ettus.com>2017-12-22 15:03:53 -0800
commit5926f1b9d9f67856dac2849e9ce9961220e4e0c1 (patch)
treeb1476e19cb75a31bf4129062b8bf3b5cbf235a82 /mpm/python
parent245b96a777afbeb84990ebb377def658879c2fa1 (diff)
downloaduhd-5926f1b9d9f67856dac2849e9ce9961220e4e0c1.tar.gz
uhd-5926f1b9d9f67856dac2849e9ce9961220e4e0c1.tar.bz2
uhd-5926f1b9d9f67856dac2849e9ce9961220e4e0c1.zip
mpm: dt overlay handling: Better error handling, fewer FIXMEs
Diffstat (limited to 'mpm/python')
-rw-r--r--mpm/python/usrp_mpm/dtoverlay.py28
-rw-r--r--mpm/python/usrp_mpm/periph_manager/base.py20
2 files changed, 33 insertions, 15 deletions
diff --git a/mpm/python/usrp_mpm/dtoverlay.py b/mpm/python/usrp_mpm/dtoverlay.py
index 65b350a04..a16b8a40e 100644
--- a/mpm/python/usrp_mpm/dtoverlay.py
+++ b/mpm/python/usrp_mpm/dtoverlay.py
@@ -42,6 +42,17 @@ def get_overlay_attrs(overlay_name):
attrs[attr_name] = attr_val
return attrs
+def is_applied(overlay_name):
+ """
+ Returns True if the overlay is already applied, False if not.
+ """
+ try:
+ return open(
+ os.path.join(SYSFS_OVERLAY_BASE_DIR, overlay_name, 'status')
+ ).read().strip() == 'applied'
+ except IOError:
+ return False
+
def list_overlays(applied_only=False):
"""
List all registered kernel modules. Returns a dict of dicts:
@@ -74,14 +85,20 @@ 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))
+ overlay_path = os.path.join(SYSFS_OVERLAY_BASE_DIR, overlay_name)
+ if not os.path.exists(overlay_path):
+ os.mkdir(overlay_path)
+ open(
+ os.path.join(SYSFS_OVERLAY_BASE_DIR, overlay_name, 'path'), 'w'
+ ).write("{}.dtbo".format(overlay_name))
def apply_overlay_safe(overlay_name):
"""
Only apply an overlay if it's not yet applied.
+
+ Finally, checks that the overlay was applied and throws an exception if not.
"""
- if overlay_name in list_overlays(applied_only=True).keys():
+ if is_applied(overlay_name):
get_logger("DTO").debug(
"Overlay `{}' was already applied, not applying again.".format(
overlay_name
@@ -89,14 +106,15 @@ def apply_overlay_safe(overlay_name):
)
else:
apply_overlay(overlay_name)
+ if not is_applied(overlay_name):
+ raise RuntimeError("Failed to apply overlay `{}'".format(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))
+ os.rmdir(os.path.join(SYSFS_OVERLAY_BASE_DIR, overlay_name))
def rm_overlay_safe(overlay_name):
"""
diff --git a/mpm/python/usrp_mpm/periph_manager/base.py b/mpm/python/usrp_mpm/periph_manager/base.py
index a9259f304..143243f7a 100644
--- a/mpm/python/usrp_mpm/periph_manager/base.py
+++ b/mpm/python/usrp_mpm/periph_manager/base.py
@@ -324,6 +324,16 @@ class PeriphManagerBase(object):
self.log.warning("No dboard PID found!")
else:
self.log.debug("Found dboard PID in EEPROM: 0x{:04X}".format(db_pid))
+ db_class = get_dboard_class_from_pid(db_pid)
+ 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"))
if len(self.dboard_spimaster_addrs) > dboard_idx:
spi_nodes = sorted(get_spidev_nodes(self.dboard_spimaster_addrs[dboard_idx]))
self.log.debug("Found spidev nodes: {0}".format(spi_nodes))
@@ -337,16 +347,6 @@ class PeriphManagerBase(object):
'spi_nodes': spi_nodes,
}
# This will actually instantiate the dboard class:
- db_class = get_dboard_class_from_pid(db_pid)
- 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)))