From ede9640c576af7b8f4095301612a128ddd020de4 Mon Sep 17 00:00:00 2001 From: Samuel Angebault Date: Mon, 1 Oct 2018 14:20:48 -0700 Subject: [PATCH] [arista] Backport watchdog support for all products --- .../confs/gardena-watchdog-stop.service | 2 +- .../debian/rules | 2 +- .../debian/sonic-platform-arista.init | 2 +- ...rista-gardena-watchdog => arista-watchdog} | 39 ++++++++++++++++--- 4 files changed, 36 insertions(+), 9 deletions(-) rename platform/broadcom/sonic-platform-modules-arista/utils/{arista-gardena-watchdog => arista-watchdog} (78%) mode change 100644 => 100755 diff --git a/platform/broadcom/sonic-platform-modules-arista/confs/gardena-watchdog-stop.service b/platform/broadcom/sonic-platform-modules-arista/confs/gardena-watchdog-stop.service index af912ce7cee9..249550112f6c 100644 --- a/platform/broadcom/sonic-platform-modules-arista/confs/gardena-watchdog-stop.service +++ b/platform/broadcom/sonic-platform-modules-arista/confs/gardena-watchdog-stop.service @@ -10,7 +10,7 @@ Type=oneshot RemainAfterExit=true ExecStart= -ExecStart=/usr/bin/arista-gardena-watchdog --stop +ExecStart=/usr/bin/arista-watchdog -l --stop ExecStop= diff --git a/platform/broadcom/sonic-platform-modules-arista/debian/rules b/platform/broadcom/sonic-platform-modules-arista/debian/rules index e12a638d8742..c0468223ee46 100755 --- a/platform/broadcom/sonic-platform-modules-arista/debian/rules +++ b/platform/broadcom/sonic-platform-modules-arista/debian/rules @@ -7,7 +7,7 @@ include /usr/share/dpkg/pkg-info.mk export INSTALL_MOD_DIR:=extra SCRIPT_FILES := reset -BIN_FILES := arista boot-eos arista-gardena-watchdog +BIN_FILES := arista boot-eos arista-watchdog SERVICE_FILES := gardena-watchdog-stop.service KVERSION ?= $(shell uname -r) diff --git a/platform/broadcom/sonic-platform-modules-arista/debian/sonic-platform-arista.init b/platform/broadcom/sonic-platform-modules-arista/debian/sonic-platform-arista.init index 7042efadabc3..eafd0d11cc9c 100755 --- a/platform/broadcom/sonic-platform-modules-arista/debian/sonic-platform-arista.init +++ b/platform/broadcom/sonic-platform-modules-arista/debian/sonic-platform-arista.init @@ -17,7 +17,7 @@ drivers_start() { if grep -q sid=Gardena /proc/cmdline; then timeout=600 echo "Enabling watchdog for $timeout seconds" - /usr/bin/arista-gardena-watchdog -o $timeout + /usr/bin/arista-watchdog -l -o $timeout fi /usr/bin/arista --syslog -l /var/log/arista.log setup --reset --background echo "done." diff --git a/platform/broadcom/sonic-platform-modules-arista/utils/arista-gardena-watchdog b/platform/broadcom/sonic-platform-modules-arista/utils/arista-watchdog old mode 100644 new mode 100755 similarity index 78% rename from platform/broadcom/sonic-platform-modules-arista/utils/arista-gardena-watchdog rename to platform/broadcom/sonic-platform-modules-arista/utils/arista-watchdog index 3f028156859b..a05279aa0c7f --- a/platform/broadcom/sonic-platform-modules-arista/utils/arista-gardena-watchdog +++ b/platform/broadcom/sonic-platform-modules-arista/utils/arista-watchdog @@ -100,6 +100,29 @@ def status( scd ): "timeout": timeout, } +def getCmdline(): + data = {} + with open( '/proc/cmdline' ) as f: + for entry in f.read().split(): + idx = entry.find( '=' ) + if idx == -1: + data[ entry ] = None + else: + data[ entry[ :idx ] ] = entry[ idx + 1: ] + return data + +def getResource(): + cmdline = getCmdline() + platform = cmdline.get( 'platform' ) + if platform == 'rook': + return '/sys/bus/pci/devices/0000:06:00.0/resource0' + if platform == 'crow': + return '/sys/bus/pci/devices/0000:02:00.0/resource0' + if platform == 'raven': + return '/sys/bus/pci/devices/0000:04:00.0/resource0' + assert False, "Failed to detect platform" + return None + def main(): parser = argparse.ArgumentParser() parser.add_argument( '-o', '--arm', type=int, @@ -108,15 +131,18 @@ def main(): help='Disable the watchdog' ) parser.add_argument( '--status', action='store_true', help='Show watchdog status' ) + parser.add_argument( '-l', '--klog', action='store_true', + help='Print the events in the dmesg' ) args = parser.parse_args() if not args.arm and not args.stop and not args.status: print( 'No option specified' ) sys.exit( 1 ) - busName = "/sys/bus/pci/devices/0000:06:00.0/resource0" - subprocess.call( [ 'modprobe', 'scd' ] ) - scd = MmapResource( busName ) + if not os.path.isdir( '/sys/module/scd' ): + subprocess.call( [ 'modprobe', 'scd' ] ) + + scd = MmapResource( getResource() ) scdScrRegTest( scd ) @@ -126,17 +152,18 @@ def main(): print( 'watchdog: %s' % kv ) sys.exit( 0 ) - time = 0 if args.arm: - klog( 'watchdog: arm for %ds' % args.arm ) + if args.klog: + klog( 'watchdog: arm for %ds' % args.arm ) # Tens of milliseconds time = args.arm * 100 if time >= 65536: print( 'Error Time value is too big' ) sys.exit( 1 ) else: - klog( 'watchdog: disable' ) + if args.klog: + klog( 'watchdog: disable' ) arm( scd, time )