summaryrefslogtreecommitdiffstats
path: root/pytools
diff options
context:
space:
mode:
authorAdriana Kobylak <anoo@us.ibm.com>2018-09-24 11:01:42 -0500
committerAdriana Kobylak <anoo@us.ibm.com>2018-09-24 11:09:37 -0500
commit7e48038afc79c10c4314433572276ada7e2e20ac (patch)
tree9baaeecb1eee30bf1242aba631f3b77038b64add /pytools
parent52efa6594b8c99ef44c19d7323424ab2e4d2191c (diff)
downloadtalos-skeleton-7e48038afc79c10c4314433572276ada7e2e20ac.tar.gz
talos-skeleton-7e48038afc79c10c4314433572276ada7e2e20ac.zip
pytools: Remove dependency to obmc.system
The system manager (obmc.system) is being deprecated and the GPIOs has moved out of D-Bus (see openbmc/openbmc#3332). The pytools still depend on the convertGpio function provided by system manager, so copy that function into the tools that use it to remove the dependency. Tested: obmcutil power functions still work, and gpioutil -l and -p work the same. Change-Id: Ia09f95312438040908eb15f93ff6d525665f5ab3 Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
Diffstat (limited to 'pytools')
-rw-r--r--pytools/gpioutil35
-rw-r--r--pytools/obmcutil31
2 files changed, 60 insertions, 6 deletions
diff --git a/pytools/gpioutil b/pytools/gpioutil
index 6589060..d06a9a4 100644
--- a/pytools/gpioutil
+++ b/pytools/gpioutil
@@ -3,8 +3,9 @@
import sys
import os
import getopt
+from glob import glob
+from os.path import join
import obmc_system_config as System
-import obmc.system
def printUsage():
@@ -25,6 +26,32 @@ sys.argv.pop(0)
GPIO_SYSFS = '/sys/class/gpio/'
+
+def find_gpio_base(path="/sys/class/gpio/"):
+ pattern = "gpiochip*"
+ for gc in glob(join(path, pattern)):
+ with open(join(gc, "label")) as f:
+ label = f.readline().strip()
+ if label == "1e780000.gpio":
+ with open(join(gc, "base")) as f:
+ return int(f.readline().strip())
+ # trigger a file not found exception
+ open(join(path, "gpiochip"))
+
+
+GPIO_BASE = find_gpio_base()
+
+
+def convertGpio(name):
+ offset = int(''.join(list(filter(str.isdigit, name))))
+ port = list(filter(str.isalpha, name.upper()))
+ a = ord(port[-1]) - ord('A')
+ if len(port) > 1:
+ a += 26
+ base = a * 8 + GPIO_BASE
+ return base + offset
+
+
class Gpio:
def __init__(self,gpio_num):
self.gpio_num = str(gpio_num)
@@ -116,9 +143,9 @@ if __name__ == '__main__':
elif opt in ("-v"):
value = arg
elif opt in ("-p"):
- gpio_name = obmc.system.convertGpio(arg)
+ gpio_name = convertGpio(arg)
elif opt in ("-l"):
- gpio_name = obmc.system.convertGpio(arg)
+ gpio_name = convertGpio(arg)
print gpio_name
exit(0)
@@ -135,7 +162,7 @@ if __name__ == '__main__':
if (gpio_info.has_key('gpio_num')):
gpio_name = str(gpio_info['gpio_num'])
else:
- gpio_name = str(obmc.system.convertGpio(gpio_info['gpio_pin']))
+ gpio_name = str(convertGpio(gpio_info['gpio_pin']))
print "GPIO ID: "+gpio_name+"; DIRECTION: "+direction
diff --git a/pytools/obmcutil b/pytools/obmcutil
index 0a0d8d1..0aa40a9 100644
--- a/pytools/obmcutil
+++ b/pytools/obmcutil
@@ -10,10 +10,11 @@ import json
import os
import signal
import time
+from glob import glob
+from os.path import join
from subprocess import Popen
import obmc_system_config
-import obmc.system
descriptors = {
'power': {
@@ -83,6 +84,32 @@ descriptors = {
GPIO_DEFS_FILE = '/etc/default/obmc/gpio/gpio_defs.json'
+
+def find_gpio_base(path="/sys/class/gpio/"):
+ pattern = "gpiochip*"
+ for gc in glob(join(path, pattern)):
+ with open(join(gc, "label")) as f:
+ label = f.readline().strip()
+ if label == "1e780000.gpio":
+ with open(join(gc, "base")) as f:
+ return int(f.readline().strip())
+ # trigger a file not found exception
+ open(join(path, "gpiochip"))
+
+
+GPIO_BASE = find_gpio_base()
+
+
+def convertGpio(name):
+ offset = int(''.join(list(filter(str.isdigit, name))))
+ port = list(filter(str.isalpha, name.upper()))
+ a = ord(port[-1]) - ord('A')
+ if len(port) > 1:
+ a += 26
+ base = a * 8 + GPIO_BASE
+ return base + offset
+
+
def run_set_property(dbus_bus, dbus_iface, descriptor, args):
mainloop = gobject.MainLoop()
@@ -186,7 +213,7 @@ def run_all_commands(dbus_bus, recipe, args):
return True
def gpio_set_value(gpio_name, active_low, asserted):
- gpio_id = obmc.system.convertGpio(gpio_name)
+ gpio_id = convertGpio(gpio_name)
gpio_value_path = "/sys/class/gpio/gpio{}/value".format(gpio_id)
with open(gpio_value_path, 'w') as gpio:
OpenPOWER on IntegriCloud