Jump to content

How to install, enable and start watchdog in H3


Go to solution Solved by rufik,

Recommended Posts

Posted

I've an OrangePI PC.

I would like install, enable and start watchdog.

 

I installed watchdog using apt-get install watchdog.

But install seems to require some tweaks.

I tried to googling but until now nothing works.

 

Any hints ?

 

Thanks!

Posted

try: echo 1 > /dev/watchdog, then see what happens.

if there is a reaction, the kernel module works.

 

then check /etc/default/watchdog

 

int top there should be a process watchdog, killing it would produce

a process wd_keepalive, killing that should reboot.

 

best, gnasch

Posted

If I try

echo 1 > /dev/watchdog

after some second the machine reboot.

Looking in /var/log/messages I see:

Nov 17 16:17:09 localhost kernel: [    3.249893] sunxi_wdt_init_module: sunxi WatchDog Timer Driver v1.0
Nov 17 16:17:09 localhost kernel: [    3.259938] sunxi_wdt_probe: devm_ioremap return wdt_reg 0xf1c20ca0, res->start 0x01c20ca0, res->end 0x01c20cbf
Nov 17 16:17:09 localhost kernel: [    3.271394] sunxi_wdt_probe: initialized (g_timeout=16s, g_nowayout=0)
Nov 17 16:17:09 localhost kernel: [    3.284826] wdt_enable, write reg 0xf1c20cb8 val 0x00000000
Nov 17 16:17:09 localhost kernel: [    3.294179] timeout_to_interv, line 167
Nov 17 16:17:09 localhost kernel: [    3.301540] interv_to_timeout, line 189
Nov 17 16:17:09 localhost kernel: [    3.308824] wdt_set_tmout, write 0x000000b0 to mode reg 0xf1c20cb8, actual timeout 16 sec

 

It seems watchdog module... Isn't it ?

 

Looking at /etc/default/watchdog

# Start watchdog at boot time? 0 or 1
run_watchdog=1
# Start wd_keepalive after stopping watchdog? 0 or 1
run_wd_keepalive=1
# Load module before starting watchdog
watchdog_module="none"
# Specify additional watchdog options here (see manpage).

 

(I've non manpages...)

I tried even adding in that file:

watchdog_options=" -F -v "

without any results.

 

I don't find any process watchdog except [watchdog], nor wd_keepalive.

I'm running Armbian 5.23 (Legacy/default server).

 

Any suggestion ?

Posted (edited)

If it reboots after "echo" , then watchdog is present and active in kernel.

 

i have 4 watchdog processes, one per processor.

root@orangepipcplus:/etc/init.d# ps aux |grep watch
root         7  0.0  0.0      0     0 ?        S    Nov17   0:01 [watchdog/0]
root        11  0.0  0.0      0     0 ?        S    Nov17   0:01 [watchdog/1]
root        15  0.0  0.0      0     0 ?        S    Nov17   0:01 [watchdog/2]
root        19  0.0  0.0      0     0 ?        S    Nov17   0:01 [watchdog/3]
root     19080  0.0  0.0   3924   760 pts/1    S+   14:45   0:00 grep watch
root@orangepipcplus:/etc/init.d# 

my /etc/watchdog.conf is this:

#ping			= 172.31.14.1
#ping			= 172.26.1.255
#interface		= eth0
#file			= /var/log/messages
#change			= 1407

# Uncomment to enable test. Setting one of these values to '0' disables it.
# These values will hopefully never reboot your machine during normal use
# (if your machine is really hung, the loadavg will go much higher than 25)
#max-load-1		= 24
#max-load-5		= 18
#max-load-15		= 12

# Note that this is the number of pages!
# To get the real size, check how large the pagesize is on your machine.
#min-memory		= 1
#allocatable-memory	= 1

#repair-binary		= /usr/sbin/repair
#repair-timeout		= 
#test-binary		= 
#test-timeout		= 

watchdog-device	= /dev/watchdog

# Defaults compiled into the binary
temperature-device	=/sys/class/thermal/thermal_zone0/temp
max-temperature	= 120

# Defaults compiled into the binary
#admin			= root
interval		= 1
logtick                = 60
log-dir		= /var/log/watchdog

# This greatly decreases the chance that watchdog won't be scheduled before
# your machine is really loaded
realtime		= yes
priority		= 1

# Check if rsyslogd is still running by enabling the following line
#pidfile		= /var/run/rsyslogd.pid   


and in /etc/init.d/watchdog it looks like that:

Spoiler

 


#!/bin/sh
#/etc/init.d/watchdog: start watchdog daemon.

### BEGIN INIT INFO
# Provides:          watchdog
# Short-Description: Start software watchdog daemon
# Required-Start:    $all
# Required-Stop:     $all
# Should-Start:      
# Should-Stop:       
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
### END INIT INFO

PATH=/bin:/usr/bin:/sbin:/usr/sbin

test -x /usr/sbin/watchdog || exit 0

# For configuration of the init script use the file
# /etc/default/watchdog, do not edit this init script.

# Set run_watchdog to 1 to start watchdog or 0 to disable it.
run_watchdog=0

# Specify additional watchdog options here (see manpage).
watchdog_options=""

# Specify module to load
watchdog_module="none"

# Set run_wd_keepalive to 1 to start wd_keepalive after stopping watchdog or 0
# to disable it. Running it is the default.
run_wd_keepalive=1

[ -e /etc/default/watchdog ] && . /etc/default/watchdog

NAME=watchdog
KEEPALIVE_NAME=wd_keepalive

DAEMON=/usr/sbin/watchdog
KEEPALIVE_DAEMON=/usr/sbin/wd_keepalive

STOP_RETRY_SCHEDULE='TERM/10/forever/KILL/1'

# Get lsb functions
. /lib/lsb/init-functions

case "$1" in
  start)
    if [ $run_watchdog = 1 ]
    then
    	# do we have to load a module?
	[ "${watchdog_module:-none}" != "none" ] && /sbin/modprobe $watchdog_module
	# make sure that wd_keepalive is stopped
	log_begin_msg "Stopping watchdog keepalive daemon..."
        start-stop-daemon --stop --quiet --oknodo --retry $STOP_RETRY_SCHEDULE \
            --pidfile /var/run/$KEEPALIVE_NAME.pid
        log_end_msg $?

	# also remove the sendsigs omit file
	rm -f /run/sendsigs.omit.d/$KEEPALIVE_NAME.pid

	# Unconditionally start watchdog daemon because we want to run it even
	# if wd_keepalive wasn't running
	log_begin_msg "Starting watchdog daemon..."
	start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
             --exec $DAEMON -- $watchdog_options
	log_end_msg $?
    fi
    ;;

  stop)
    if [ $run_watchdog = 1 ]
    then
	log_begin_msg "Stopping watchdog daemon..."
	start-stop-daemon --stop --quiet --retry $STOP_RETRY_SCHEDULE \
	    --pidfile /var/run/$NAME.pid
	log_end_msg $?
	if [ $run_wd_keepalive = 1 ]
	then
	    # make sure that wd_keepalive is started if instructed to do so
	    log_begin_msg "Starting watchdog keepalive daemon..."
	    start-stop-daemon --start --quiet --pidfile /var/run/$KEEPALIVE_NAME.pid \
		--exec $KEEPALIVE_DAEMON -- $watchdog_options
	    log_end_msg $?

	    # and tell sendsigs to ignore it
	    ln -s /var/run/$KEEPALIVE_NAME.pid /run/sendsigs.omit.d/$KEEPALIVE_NAME.pid
	fi
    fi
    ;;

  restart)
    $0 force-reload
    ;;

  force-reload)
    if [ $run_watchdog = 0 ]; then exit 0; fi
    log_daemon_msg "Restarting $NAME"
    log_progress_msg "Stopping $NAME daemon..."
    start-stop-daemon --stop --pidfile /var/run/$NAME.pid --quiet \
	--retry $STOP_RETRY_SCHEDULE || log_end_msg $?
    log_progress_msg "Starting $NAME daemon..."
    start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
	--exec $DAEMON -- $watchdog_options
    log_end_msg $?
    ;;

  status)
    status_of_proc "$DAEMON" watchdog
    ;;

  *)
    echo "Usage: /etc/init.d/watchdog {start|stop|restart|force-reload|status}"
    exit 1

esac

exit 0

Hope this helps

Edited by Tido
added spoiler
Posted

I have no idea about H2+

 

H2+ is just a crippled H3 (no GbE MAC exposed, no 4K HDMI support):

 

root@orangepizero:~# echo 1 > /dev/watchdog

root@orangepizero:~# Write failed: Broken pipe

macbookpro-tk:~ tk$ slogin orangepizero.local

tk@orangepizero.local's password: 

  ___                               ____  _   _____              

 / _ \ _ __ __ _ _ __   __ _  ___  |  _ \(_) |__  /___ _ __ ___  

| | | | '__/ _` | '_ \ / _` |/ _ \ | |_) | |   / // _ \ '__/ _ \ 

| |_| | | | (_| | | | | (_| |  __/ |  __/| |  / /|  __/ | | (_) |

 \___/|_|  \__,_|_| |_|\__, |\___| |_|   |_| /____\___|_|  \___/ 

                       |___/                                     

 

Welcome to ARMBIAN Ubuntu 16.04.1 LTS 3.4.113-sun8i 

System load:   0.34            Up time:       2 min

Memory usage:  13 % of 241Mb  IP:            192.168.83.153

CPU temp:      30°C           

Usage of /:    9% of 15G    

 

 

[ 10 updates to install: apt-get upgrade ]

 

Last login: Thu Nov 17 06:20:41 2016 from 192.168.83.91

Posted

so every board got it and i can start to work with the hw one. What are the differences between the software watchdog and the hardware one, in addiction to the stability of the hw one? I've enabled only the software one in my project for compatibility, but i've never tested the hw watchdog, and don't know if it is compliant (for example in my app during the initial boot the watchdog first start with a certain configuration, then my application stop it, change the configuration, and then restart it), as i readed (but never tried) i can't stop the hw watchdog. 

Posted

I have a different problem: I'm trying to ping /dev/watchdog directly, without using the watchdog package.

The problem is that the watchdog resets the board (opi pc, legacy kernel) even if I keep writing to /dev/watchdog. If I write the magic char 'V' to /dev/watchdog before the timeout expires then it doesn't reset (and that's ok).

This is the test python script I'm using, I'm using chr(0) because that's what the sample program does, but anything (except 'V' for obvious reasons) should work:

 

import time
f=open('/dev/watchdog','w')

try:
  while True:
    time.sleep(1)
    print '.'
    f.write(chr(0))
    
except KeyboardInterrupt:
    print 'end'
    f.write('V')
    f.close()

 

 

Posted

Strangely enough the IOCTL interface works (strange because, looking at the source of sunxi_wdt in theory either writing to the device or using the ioctl should trigger the same function watchdog_kick)

 

import time
import fcntl
f=open('/dev/watchdog','w')
try:
  while True:
    time.sleep(1)
    print '.'
    fcntl.ioctl(f,0x80045705) #WDIOC_KEEPALIVE
    
except KeyboardInterrupt:
    print 'end'
    f.write('V')
    f.close()

 

 

 

 

Posted

I've just tested the watchdog on Orange Pi Zero (H2+) with Linus 4.15-rc1 and it works fine:

 

sunxi-wdt 1c20ca0.watchdog: Watchdog enabled (timeout=16 sec, nowayout=1)
 

(I have compiled Linux with the nowayout option).

 

If I open /dev/watchdog it starts, and if don't open it/write whithin 16s it reboots the board.

 

Is there a way to permanently enable the watchdog, from power-on, or at least from u-boot?

 

Also is there a way to adjust the timeout to a larger value?

 

Thanks!

Posted

Hi - easiest way i found

 

1) In /etc/systemd/system.conf set\uncomment

(max seconds on H3 you can see in g_timeout in 'dmesg | grep "sunxi_wdt_probe"'.

On H2 'dmesg | grep "watchdog"'.

Its ok to set to 16 - it try to send "pings" every half of seted timer)

 

RuntimeWatchdogSec=16
ShutdownWatchdogSec=10min

 

2) reboot, after it check output of "sudo lsof | grep /dev/watchdog" - if it say about systemd - all work

 

3) (DONT RUN THIS ON PRODUCTION SERVERS) test with fork-bomb with and without

 

P.S. - work ok on H2\H3

 

Posted

Hi gents, 

 

Was attempting to fiddle with the H3 watchdog on a system running the legacy 3.4.113 kernel. The sunxi_wdt driver is not compiled by default and I was wondering if it might be possible to use this as a LKM with /dev/watchdog? Have managed to get it compiled as a .ko but trying to load it with insmod returns a generic "insmod: ERROR: could not insert module sunxi_wdt.ko: Invalid parameters" 

 

Is it even possible to use a LKM for this? and if so, how would I redirect /dev/watchdog from softdog to this?

 

Thanks

Posted

So it looks like by default only softdog.ko is installed, not the hw version that is present on the H2/3. How would we enable to hardware watchdog?

Posted
On 1/15/2019 at 12:14 AM, cabled said:

to fiddle with the H3 watchdog

Hi, try the searchbox in the right hand corner with:  watchdog

Posted
32 minutes ago, Tido said:

Thanks, already saw those threads otherwise I wouldn't be asking this question. Those have nothing to do with how to install the hardware watchdog driver on the mainline kernel (or to enable it if it does come with the kernel). 

Posted

All you need is just to install watchdog service and set some parameter in armbianenv.txt file - I can't recall it right now, I'll try to search my notes later and post the solution.

Posted
12 hours ago, jstefanop said:

saw those threads

it is not enough wit looking at it...

 

On 12/3/2017 at 12:15 PM, Nuno Goncalves said:

with Linus 4.15-rc1 and it works fine:

 

Posted
5 hours ago, Tido said:

it is not enough wit looking at it...

 

 

 

How is some guy that compiled a custom kernel with it helpful? If I knew how to do that I would have already done it.  

 

Im trying to figure out how I would go about installing it on the mainline kernel. From what I can tell the option is already turned on in the mainline source compiler options, so it might be a matter of enabling it via ArmbianEnv.txt or through some other mechanism I dont know about. 

 

This is why I am asking the question since Im sure more experienced amrbian users would know the answer. 

Posted
9 hours ago, rufik said:

All you need is just to install watchdog service and set some parameter in armbianenv.txt file - I can't recall it right now, I'll try to search my notes later and post the solution.

 

Thanks! Let me know if you find it. I dont see the .ko installed in the mainline system anywhere though so I still think the source needs to be compiled and installed into the kernel. 

 

I am also running kernel version 4.14 Armbian 5.60 (Ubuntu 16.04.4) if that matters. 

Posted

FYI If anyone has some experience around this or knows how to enable this from mainline armbian build im more than willing to pay for someone's time. 

Posted

To make watchdog performing hard reset you need to add this param to /boot/armbianEnv.txt :

extraarg=sunxi_wdt.nowayout=1

 

But I can't really recall if some quotation should be used (like extraarg="sunxi_wdt.nowayout=1") or not. Just try it yourself.

This argument is required if you want your watchdog to perform hard reset SBC. And of course just install watchdog package using apt-get.

 

Posted
On 1/21/2019 at 5:37 AM, rufik said:

To make watchdog performing hard reset you need to add this param to /boot/armbianEnv.txt :


extraarg=sunxi_wdt.nowayout=1

 

But I can't really recall if some quotation should be used (like extraarg="sunxi_wdt.nowayout=1") or not. Just try it yourself.

This argument is required if you want your watchdog to perform hard reset SBC. And of course just install watchdog package using apt-get.

 

Awesome thanks! Looks like this worked.

 

Kernel loads: sunxi_wdt_probe: initialized (g_timeout=16s, g_nowayout=0)

 

What does the nowayout option do? Even though I have it set to "1" in ArmbianEnv kernel still seems to load 0.

 

There are also two watchdog file (/dev/watchdog and /dev/watchdog0)

 

Im assuming one is for the software and the other for the hardware...anyone know which is which?

Posted

https://www.kernel.org/doc/Documentation/watchdog/watchdog-api.txt

 

 

When the device is closed, the watchdog is disabled, unless the "Magic Close" feature is supported (see below). This is not always such a good idea, since if there is a bug in the watchdog daemon and it crashes the system will not reboot. Because of this, some of the drivers support the configuration option "Disable watchdog shutdown on close", CONFIG_WATCHDOG_NOWAYOUT. If it is set to Y when compiling the kernel, there is no way of disabling the watchdog once it has been started. So, if the watchdog daemon crashes, the system will reboot after the timeout has passed. Watchdog devices also usually support the nowayout module parameter so that this option can be controlled at runtime. 

 

So it's required to set it up. Try some quoting. Maybe this should be the last line in armbianenv.txt file? I can't remember exactly but there was some issue about it...

 

 

Posted

Ok so some further research it looks like the sunxi hardware watchdog IS installed and compiled directly into the kernel....I was looking for the sunxi_wtd.ko module and thought just the software watchdog was installed.

 

That option only disables the Magic Close feature, so it has nothing to do with enabling the hardware watchdog. I need that feature anyway since there are instances where we disable the internal controller software and dont want the system to reboot in that case. 

Posted

Is anyone using watchdog on OrangePi H3 family? I've tried to set it up on OPI 2 (almost the same as OPI PC but with wifi) and I'm getting some trouble with watchdog service startup: cannot set scheduler (errno = 1 = 'Operation not permitted')

May 10 09:29:23 opi2 systemd[1]: Starting watchdog daemon...
May 10 09:29:23 opi2 watchdog[12308]: String 'watchdog-device' found as '/dev/watchdog'
May 10 09:29:23 opi2 watchdog[12308]: String 'admin' found as 'root'
May 10 09:29:23 opi2 watchdog[12310]: starting daemon (5.15):
May 10 09:29:23 opi2 watchdog[12310]: int=7s realtime=yes sync=no load=0,0,0 soft=no
[cut!]
May 10 09:29:23 opi2 watchdog[12310]: watchdog now set to 16 seconds
May 10 09:29:23 opi2 watchdog[12310]: hardware watchdog identity: sunxi-wdt
May 10 09:29:23 opi2 watchdog[12310]: cannot set scheduler (errno = 1 = 'Operation not permitted')
May 10 09:29:23 opi2 systemd[1]: Started watchdog daemon.

I'm using latest armbian: Welcome to ARMBIAN 5.85 stable Ubuntu 18.04.2 LTS 4.19.38-sunxi

 

It looks like problem with realtime schduling: https://www.freedesktop.org/wiki/Software/systemd/MyServiceCantGetRealtime and I've tried to add Delegate=cpu option to watchdog.service file but still no-go. Anyone was facing this issue?

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines