diff --git a/platform/marvell-armhf/sonic-platform-nokia/7215/scripts/cpu_wdt.py b/platform/marvell-armhf/sonic-platform-nokia/7215/scripts/cpu_wdt.py new file mode 100755 index 000000000000..60f75b4f2e50 --- /dev/null +++ b/platform/marvell-armhf/sonic-platform-nokia/7215/scripts/cpu_wdt.py @@ -0,0 +1,46 @@ +#!/usr/bin/python + +from sonic_platform.chassis import Chassis +from sonic_py_common import logger +import time +import os +import signal +import sys + + +TIMEOUT=170 +KEEPALIVE=55 +sonic_logger = logger.Logger('Watchdog') +sonic_logger.set_min_log_priority_info() +time.sleep(60) +chassis = Chassis() +watchdog = chassis.get_watchdog() + +def stopWdtService(signal, frame): + watchdog._disablewatchdog() + sonic_logger.log_notice("CPUWDT Disabled: watchdog armed=%s" % watchdog.is_armed() ) + sys.exit() + +def main(): + + signal.signal(signal.SIGHUP, signal.SIG_IGN) + signal.signal(signal.SIGINT, stopWdtService) + signal.signal(signal.SIGTERM, stopWdtService) + + watchdog.arm(TIMEOUT) + sonic_logger.log_notice("CPUWDT Enabled: watchdog armed=%s" % watchdog.is_armed() ) + + + while True: + time.sleep(KEEPALIVE) + watchdog._keepalive() + sonic_logger.log_info("CPUWDT keepalive") + done + + stopWdtService + + return + + +if __name__ == '__main__': + main() diff --git a/platform/marvell-armhf/sonic-platform-nokia/7215/service/cpu_wdt.service b/platform/marvell-armhf/sonic-platform-nokia/7215/service/cpu_wdt.service new file mode 100644 index 000000000000..761deec569cc --- /dev/null +++ b/platform/marvell-armhf/sonic-platform-nokia/7215/service/cpu_wdt.service @@ -0,0 +1,8 @@ +[Unit] +Description=CPU WDT +After=nokia-7215init.service +[Service] +ExecStart=/usr/local/bin/cpu_wdt.py + +[Install] +WantedBy=multi-user.target diff --git a/platform/marvell-armhf/sonic-platform-nokia/7215/sonic_platform/watchdog.py b/platform/marvell-armhf/sonic-platform-nokia/7215/sonic_platform/watchdog.py index 903b6365dc48..03a8d9ecb4e7 100644 --- a/platform/marvell-armhf/sonic-platform-nokia/7215/sonic_platform/watchdog.py +++ b/platform/marvell-armhf/sonic-platform-nokia/7215/sonic_platform/watchdog.py @@ -8,7 +8,7 @@ import os import fcntl import array - +import time from sonic_platform_base.watchdog_base import WatchdogBase """ ioctl constants """ @@ -35,7 +35,7 @@ WDIOS_ENABLECARD = 0x0002 """ watchdog sysfs """ -WD_SYSFS_PATH = "/sys/class/watchdog/" +WD_SYSFS_PATH = "/sys/class/watchdog/watchdog0/" WD_COMMON_ERROR = -1 @@ -52,16 +52,32 @@ def __init__(self, wd_device_path): @param wd_device_path Path to watchdog device """ super(WatchdogImplBase, self).__init__() - + + self.watchdog="" self.watchdog_path = wd_device_path - self.watchdog = os.open(self.watchdog_path, os.O_WRONLY) - - # Opening a watchdog descriptor starts - # watchdog timer; by default it should be stopped - self._disablewatchdog() - self.armed = False + self.wd_state_reg = WD_SYSFS_PATH+"state" + self.wd_timeout_reg = WD_SYSFS_PATH+"timeout" + self.wd_timeleft_reg = WD_SYSFS_PATH+"timeleft" + self.timeout = self._gettimeout() + def _read_sysfs_file(self, sysfs_file): + # On successful read, returns the value read from given + # reg_name and on failure returns 'ERR' + rv = 'ERR' + + if (not os.path.isfile(sysfs_file)): + return rv + try: + with open(sysfs_file, 'r') as fd: + rv = fd.read() + except Exception as e: + rv = 'ERR' + + rv = rv.rstrip('\r\n') + rv = rv.lstrip(" ") + return rv + def _disablewatchdog(self): """ Turn off the watchdog timer @@ -102,11 +118,10 @@ def _gettimeout(self): Get watchdog timeout @return watchdog timeout """ + timeout=0 + timeout=self._read_sysfs_file(self.wd_timeout_reg) - req = array.array('I', [0]) - fcntl.ioctl(self.watchdog, WDIOC_GETTIMEOUT, req, True) - - return int(req[0]) + return timeout def _gettimeleft(self): """ @@ -127,15 +142,20 @@ def arm(self, seconds): ret = WD_COMMON_ERROR if seconds < 0: return ret - + + # Stop the watchdog service to gain access of watchdog file pointer + if self.is_armed(): + os.popen("systemctl stop cpu_wdt.service") + time.sleep(2) + if not self.watchdog: + self.watchdog = os.open(self.watchdog_path, os.O_WRONLY) try: if self.timeout != seconds: self.timeout = self._settimeout(seconds) - if self.armed: + if self.is_armed(): self._keepalive() else: self._enablewatchdog() - self.armed = True ret = self.timeout except IOError: pass @@ -150,13 +170,17 @@ def disarm(self): A boolean, True if watchdog is disarmed successfully, False if not """ - - try: - self._disablewatchdog() - self.armed = False - self.timeout = 0 - except IOError: - return False + + if self.is_armed(): + os.popen("systemctl stop cpu_wdt.service") + time.sleep(2) + if not self.watchdog: + self.watchdog = os.open(self.watchdog_path, os.O_WRONLY) + try: + self._disablewatchdog() + self.timeout = 0 + except IOError: + return False return True @@ -164,8 +188,13 @@ def is_armed(self): """ Implements is_armed WatchdogBase API """ + status = False + + state = self._read_sysfs_file(self.wd_state_reg) + if (state != 'inactive'): + status = True - return self.armed + return status def get_remaining_time(self): """ @@ -174,10 +203,7 @@ def get_remaining_time(self): timeleft = WD_COMMON_ERROR - if self.armed: - try: - timeleft = self._gettimeleft() - except IOError: - pass + if self.is_armed(): + timeleft=self._read_sysfs_file(self.wd_timeleft_reg) - return timeleft + return int(timeleft) diff --git a/platform/marvell-armhf/sonic-platform-nokia/debian/sonic-platform-nokia-7215.install b/platform/marvell-armhf/sonic-platform-nokia/debian/sonic-platform-nokia-7215.install index 8ce8d1726524..bca328306eab 100644 --- a/platform/marvell-armhf/sonic-platform-nokia/debian/sonic-platform-nokia-7215.install +++ b/platform/marvell-armhf/sonic-platform-nokia/debian/sonic-platform-nokia-7215.install @@ -1,6 +1,8 @@ nokia-7215_plt_setup.sh usr/sbin 7215/scripts/nokia-7215init.sh usr/local/bin +7215/scripts/cpu_wdt.py usr/local/bin 7215/service/nokia-7215init.service etc/systemd/system +7215/service/cpu_wdt.service etc/systemd/system 7215/service/fstrim.timer/timer-override.conf /lib/systemd/system/fstrim.timer.d 7215/sonic_platform-1.0-py3-none-any.whl usr/share/sonic/device/armhf-nokia_ixs7215_52x-r0 inband_mgmt.sh etc/ diff --git a/platform/marvell-armhf/sonic-platform-nokia/debian/sonic-platform-nokia-7215.postinst b/platform/marvell-armhf/sonic-platform-nokia/debian/sonic-platform-nokia-7215.postinst index de91cedb4ec7..76d40865a0ac 100644 --- a/platform/marvell-armhf/sonic-platform-nokia/debian/sonic-platform-nokia-7215.postinst +++ b/platform/marvell-armhf/sonic-platform-nokia/debian/sonic-platform-nokia-7215.postinst @@ -7,5 +7,8 @@ sh /usr/sbin/nokia-7215_plt_setup.sh systemctl enable nokia-7215init.service systemctl start nokia-7215init.service +systemctl enable cpu_wdt.service +systemctl start cpu_wdt.service + exit 0