Enable Watchdog on the C1

Post Reply
Jens
Posts: 18
Joined: Mon Jan 26, 2015 5:55 am
languages_spoken: english
ODROIDs: C1
Contact:

Enable Watchdog on the C1

Unread post by Jens » Sat Jan 31, 2015 7:31 am

Hi everyone,

form the bootleg in /var/log/dmesg it seems that the C1 comes with a watchdog driver but it appears to be disabled:

Code: Select all

[ 2.137483@0] aml_wdt_driver_init,301
[ 2.141057@0] ** disable watchdog
any ideas what I need to do to enable it?

Cheers,
Jens
Cheers,
Jens

mlinuxguy
Posts: 840
Joined: Thu Feb 28, 2013 10:28 am
languages_spoken: english
ODROIDs: X, X2, XU, XU3, XU4, C1, C1+, C2, N1, USB-IO
Contact:

Re: Enable Watchdog on the C1

Unread post by mlinuxguy » Sun Feb 01, 2015 2:53 am

easy, you might want to set some values for it in the dts file first however:
Mine are:

Code: Select all

    amlogic-watchdog {
        compatible = "amlogic,aml-wdt";
        default_timeout=<10>;
        reset_watchdog_method=<1>;//0:sysfs,1:kernel
        reset_watchdog_time=<2>;
        shutdown_timeout=<10>;
        firmware_timeout=<6>;
        suspend_timeout=<6>;
    };
Then run top and verify the watchdog processes are sleeping
To start them up:

Code: Select all

# echo 0 > /proc/sys/kernel/watchdog
Check with TOP and you will a 'R' showing they are now running

To shut them down:

Code: Select all

# echo 1 > /proc/sys/kernel/watchdog
Though honestly I'm not sure who is running that... there is a linux watchdog also
However its normally in: /dev/watchdog and /var/run/watchdog.pid which are empty.. so perhaps this is the aml_wdt running

Jens
Posts: 18
Joined: Mon Jan 26, 2015 5:55 am
languages_spoken: english
ODROIDs: C1
Contact:

Re: Enable Watchdog on the C1

Unread post by Jens » Sun Feb 01, 2015 3:08 am

thanks for the quick reply.

can you tell me where I can find the dts file? I have to admit I'm just getting started with linux :-)
Cheers,
Jens

mlinuxguy
Posts: 840
Joined: Thu Feb 28, 2013 10:28 am
languages_spoken: english
ODROIDs: X, X2, XU, XU3, XU4, C1, C1+, C2, N1, USB-IO
Contact:

Re: Enable Watchdog on the C1

Unread post by mlinuxguy » Sun Feb 01, 2015 3:13 am

You need to have the Linux source code checked out to make changes to it...

Code: Select all

# ll /usr/src/linux/arch/arm/boot/dts/meson8b_odroidc.dts
-rwxr-xr-x 1 root root 37069 Jan 31 12:01 /usr/src/linux/arch/arm/boot/dts/meson8b_odroidc.dts*
It has decent defaults, just enable it and see how it works out for you.

Jens
Posts: 18
Joined: Mon Jan 26, 2015 5:55 am
languages_spoken: english
ODROIDs: C1
Contact:

Re: Enable Watchdog on the C1

Unread post by Jens » Sun Feb 01, 2015 3:26 am

ok I tried

echo 0 > /proc/sys/kernel/watchdog

and that appears to start four watchdogs (according to top) but I still can't see the "/dev/watchdog" file that normally use to "kick" the watchdog, I expected this to appear once the watchdog driver is running. Am I missing something?

Also I expected the command line above to work from any user account with sudo but strangely I had to be root to run it.
Cheers,
Jens

mlinuxguy
Posts: 840
Joined: Thu Feb 28, 2013 10:28 am
languages_spoken: english
ODROIDs: X, X2, XU, XU3, XU4, C1, C1+, C2, N1, USB-IO
Contact:

Re: Enable Watchdog on the C1

Unread post by mlinuxguy » Sun Feb 01, 2015 3:43 am

I don't see in the driver where they create that...
To do that as a normal user you will have to chmod that file in /etc/rc.local

Jens
Posts: 18
Joined: Mon Jan 26, 2015 5:55 am
languages_spoken: english
ODROIDs: C1
Contact:

Re: Enable Watchdog on the C1

Unread post by Jens » Sun Feb 01, 2015 4:09 am

maybe we are talking about two different things? What I'm looking for is to enable a watchdog driver for the standard linux watchdog API (i.e. https://www.kernel.org/doc/Documentatio ... og-api.txt) this normally creates a file /dev/watchdog

I'm not sure what the four watchdog threads that I started by writing into /proc/sys/kernel/watchdog do, but they don't seem to be what I'm looking for, or I'm still doing something wrong.
Cheers,
Jens

mlinuxguy
Posts: 840
Joined: Thu Feb 28, 2013 10:28 am
languages_spoken: english
ODROIDs: X, X2, XU, XU3, XU4, C1, C1+, C2, N1, USB-IO
Contact:

Re: Enable Watchdog on the C1

Unread post by mlinuxguy » Sun Feb 01, 2015 4:34 am

This appears to be amlogic's own interpretation of what a watchdog timer does.

Jens
Posts: 18
Joined: Mon Jan 26, 2015 5:55 am
languages_spoken: english
ODROIDs: C1
Contact:

Re: Enable Watchdog on the C1

Unread post by Jens » Sun Feb 01, 2015 7:37 am

not cool :-)

do you think there may be another amlogic watchdog driver that's more standard conform? Or is futile to continue to look for one?
Cheers,
Jens

mlinuxguy
Posts: 840
Joined: Thu Feb 28, 2013 10:28 am
languages_spoken: english
ODROIDs: X, X2, XU, XU3, XU4, C1, C1+, C2, N1, USB-IO
Contact:

Re: Enable Watchdog on the C1

Unread post by mlinuxguy » Sun Feb 01, 2015 8:54 am

Some google searches indicated amlogic watchdog's for their other chipsets, but my guess is its all the same code originally

tfjgeorge
Posts: 2
Joined: Wed Feb 04, 2015 6:45 pm
languages_spoken: english
Contact:

Re: Enable Watchdog on the C1

Unread post by tfjgeorge » Fri Feb 06, 2015 1:32 am

Hello,

I am facing the same issue of using the watchdog.
I don't quite understand what to do with these watchdog processes.
In the driver there are functions like "static int aml_wdt_ping(struct watchdog_device *wdog)" or "unsigned int aml_wdt_get_timeleft(struct watchdog_device *wdog)" but how to access them in userspace or is it even possible ?

Thanks for any help.

mlinuxguy
Posts: 840
Joined: Thu Feb 28, 2013 10:28 am
languages_spoken: english
ODROIDs: X, X2, XU, XU3, XU4, C1, C1+, C2, N1, USB-IO
Contact:

Re: Enable Watchdog on the C1

Unread post by mlinuxguy » Fri Feb 06, 2015 1:15 pm

One method would be via sysfs

Code: Select all

        reset_watchdog_method=<1>;//0:sysfs,1:kernel
(notice it is set to kernel in the device tree entry)

You would need to setup a script to tickle the sysfs entry, perhaps in /etc/rc.local or earlier in the boot process
Have your shell script sleep for 5 seconds (or the appropriate length of time to what you have set the watchdog at ex: 10 seconds)
before tickling the watchdog.

Once you have enabled the watchdog in the DTS file, compiled it, copied it to /media/boot, rebooted you will see:

Code: Select all

# ls /dev/w*
/dev/watchdog  /dev/watchdog0 
and

Code: Select all

    /sys/class/watchdog 
# ll /sys/class/watchdog/
total 0
drwxr-xr-x  2 root root 0 Dec 31  1969 ./
drwxr-xr-x 77 root root 0 Dec 31  1969 ../
lrwxrwxrwx  1 root root 0 Dec 31  1969 watchdog0 -> ../../devices/virtual/watchdog/watchdog0/
https://embeddedfreak.wordpress.com/201 ... -watchdog/
============
The other option would be to tickle it via a user-space C program:

Code: Select all

	while (1) {
		ioctl(fd, WDIOC_KEEPALIVE, 0);
		sleep(10);
	}
the argument to the ioctl is ignored.
From the code to aml_wdt:

Code: Select all

static const struct watchdog_info aml_wdt_info = {
    .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
    .identity = "aml Watchdog",
};
They appear to support both pinging and setting a new timeout value.

My dmesg with watchdog enabled:

Code: Select all

[  533.301793@0] ** reset watchdog
[  535.301748@0] ** reset watchdog
[  537.301707@0] ** reset watchdog
[  539.301672@0] ** reset watchdog
[  541.301635@0] ** reset watchdog
[  543.301581@0] ** reset watchdog
[  544.171967@2] ** enable watchdog
[  544.172013@2] ** reset watchdog
[  544.172030@2] ** disable watchdog
[  545.301533@0] ** reset watchdog
root@odroid-c2:~# echo V > /dev/watchdog

Jens
Posts: 18
Joined: Mon Jan 26, 2015 5:55 am
languages_spoken: english
ODROIDs: C1
Contact:

Re: Enable Watchdog on the C1

Unread post by Jens » Mon Mar 09, 2015 6:33 am

Please excuse me, but I don't quite understand your reply. I'm having trouble understanding your first suggestion to add

Code: Select all

reset_watchdog_method=<1>;//0:sysfs,1:kernel
to my dts file. Where exactly should I add this line? Doing a quick google search I found the following dts file (https://github.com/codesnake/linux-amlo ... 102_1G.dtd) and tried it, but adding the watchdog section to my dts file and compiling it and restarting the system did not change anything (I tried method 0 and 1 and also status enable and disable).
Cheers,
Jens

boopet
Posts: 1
Joined: Sun May 03, 2015 10:05 pm
languages_spoken: english
ODROIDs: C1
Contact:

Re: Enable Watchdog on the C1

Unread post by boopet » Tue May 05, 2015 11:50 pm

The dts file in my /boot directory has no watchdog entry.
The system behaves as if there were no hardware watchog, except this message during boot:

[ 7.988141@0] aml_wdt_driver_init,301
[ 7.991612@0] ** disable watchdog


There is neither a /dev/watchdog nor entries in /sys/class/watchdog. :cry:

Is there a way to enable the watchdog without recompiling the kernel? I would like to have standard update mechanisms working.
A step-by-step manual would be highly appreciated.

Thanks,

boopet

pwrozycki
Posts: 1
Joined: Mon Jun 01, 2015 7:26 pm
languages_spoken: english
ODROIDs: odroid c1
Contact:

Re: Enable Watchdog on the C1

Unread post by pwrozycki » Mon Jun 01, 2015 7:37 pm

To get /dev/watchdog* devices you have to recompile kernel

You have to follow instructions:
http://odroid.com/dokuwiki/doku.php?id= ... ing_kernel

prior to building kernel modify

Code: Select all

./arch/arm/boot/dts/meson8b_odroidc.dts
to include section

Code: Select all

amlogic-watchdog{
	compatible = "amlogic,aml-wdt";
	default_timeout=<10>;
	reset_watchdog_method=<1>;//0:sysfs,1:kernel
	reset_watchdog_time=<2>;
	shutdown_timeout=<10>;
	firmware_timeout=<6>;
	suspend_timeout=<6>;
};
(I don't think it is significant under which line you place it - i added it under cpufreq-meson{})

Then follow instructions, and copy uImage, meson8b*{dts,dtb} files to boot partition (first one)
and generated modules to /lib/modules on odroid root partition (second one).

alipak
Posts: 4
Joined: Sun Mar 29, 2015 4:44 pm
languages_spoken: english
ODROIDs: c1, u3, xu, xu3
Contact:

Re: Enable Watchdog on the C1

Unread post by alipak » Mon Aug 24, 2015 9:50 pm

Hi Odroidians;
I need to enable C1 watchdog to improve my project Stability.
I read above posts and try every suggestions but it seems that I cannot enable it yet.
What I try are:
- I add this code to meson8b_odroidc.dts and build kernel

Code: Select all

amlogic-watchdog{
   compatible = "amlogic,aml-wdt";
   default_timeout=<10>;
   reset_watchdog_method=<1>;//0:sysfs,1:kernel
   reset_watchdog_time=<2>;
   shutdown_timeout=<10>;
   firmware_timeout=<6>;
   suspend_timeout=<6>;
};
- I try to start watchdog by below code and it change watchdog1, watchdog1, watchdog2 and watchdog3 from sleep to run.

Code: Select all

# echo 0 > /proc/sys/kernel/watchdog
- I comment a line in aml_wdt.c that is disabled watchdog and compile kernel
- …
Now the question is that how can I check if the watchdog is really enabled? (I use my own check. When I detach keyboard from board it become freeze, so I use this technic to test watchdog that if it still stay in freeze mode or it will reset itself. The answer is always is it still become freeze so from my point of view I cannot enable watchdog yet! )

According to the Amlogic S805 datasheet that is available in C1 page under Technical Details, there are two watchdog timers that we can use it. How can I use this two watchdogs manually when writing c program?

Can anyone suggest a C1 image with enabled watchdog? (It seems to be useful option in many cases because no one interest in a freeze C1 and because it seems that it was not a routine way to enable it.)

joerg
Posts: 853
Joined: Tue Apr 01, 2014 2:14 am
languages_spoken: german, english, español
ODROIDs: C1, C1+, C2
Location: Germany
Contact:

Re: Enable Watchdog on the C1

Unread post by joerg » Sat Sep 05, 2015 2:42 am

Hello,

I also need to enable watchdog, because my Odroid C1 severall times freezed caused by app Sygic. As I supply my Odroid C1 with own build ups I cannot reset so easy, I have to open the case and disconnect the lipo. So I tried this what has written mrlinuxguy and had success.
Compiled meson8b_odroidc.dtb: 'make dtbs'.

Code: Select all

   amlogic-watchdog {
        compatible = "amlogic,aml-wdt";
        default_timeout=<10>;
        reset_watchdog_method=<0>;//0:sysfs,1:kernel
        reset_watchdog_time=<2>;
        shutdown_timeout=<10>;
        firmware_timeout=<6>;
        suspend_timeout=<6>;
    };
Pushed with fastboot to Odroid C1: 'sudo fastboot flash dtb arch/arm/boot/dts/meson8b_odroidc.dtb'.
And compiled demo from https://embeddedfreak.wordpress.com/201 ... -watchdog/.
The demo only works if there is 'reset_watchdog_method=<0>' in meson8b_odroidc.dtb.

Code: Select all

adb remount
adb push watchdog system/bin/
adb shell
# /bin/watchdog
Current watchdog interval is -1
Last boot is caused by : Power-On-Reset
Use:
 <w> to kick through writing over device file
 <i> to kick through IOCTL
 <x> to exit the program
i
Kick watchdog through IOCTL
i
Kick watchdog through IOCTL
i
....
Next step is to implement this to my shutdown prog, hopyfully it reboots my Odroid C1if Sygic again make it freeze.
Attachments
watchdog.zip
Watchdog demo
(5.52 KiB) Downloaded 118 times

joerg
Posts: 853
Joined: Tue Apr 01, 2014 2:14 am
languages_spoken: german, english, español
ODROIDs: C1, C1+, C2
Location: Germany
Contact:

Re: Enable Watchdog on the C1

Unread post by joerg » Sun Sep 06, 2015 3:11 am

Update. I implemented watchdog in my shudown prog and I had success. 10s after Sygic made C1 freeze (there was also terrible sound from hdmi audio) watchdog made my C1 rebooting.

Jens
Posts: 18
Joined: Mon Jan 26, 2015 5:55 am
languages_spoken: english
ODROIDs: C1
Contact:

Re: Enable Watchdog on the C1

Unread post by Jens » Sun Sep 06, 2015 3:23 am

It's great to hear that there is a way to enable the watchdog, but is rebuilding the kernel really the only solution? I mean, I don't appreciate having to redo this every time a new kernel is released.
Last edited by Jens on Thu Feb 04, 2016 3:48 pm, edited 1 time in total.
Cheers,
Jens

joerg
Posts: 853
Joined: Tue Apr 01, 2014 2:14 am
languages_spoken: german, english, español
ODROIDs: C1, C1+, C2
Location: Germany
Contact:

Re: Enable Watchdog on the C1

Unread post by joerg » Sun Sep 06, 2015 1:30 pm

We could ask HK developers if they overtake it permanent to kernel source. It 's only a small change in dtb.

User avatar
rooted
Posts: 6436
Joined: Fri Dec 19, 2014 9:12 am
languages_spoken: english
Location: Gulf of Mexico, US
Contact:

Re: Enable Watchdog on the C1

Unread post by rooted » Sun Sep 06, 2015 2:03 pm

joerg wrote:We could ask HK developers if they overtake it permanent to kernel source. It 's only a small change in dtb.
If you create a pull request it will likely be implemented.

Jens
Posts: 18
Joined: Mon Jan 26, 2015 5:55 am
languages_spoken: english
ODROIDs: C1
Contact:

Re: Enable Watchdog on the C1

Unread post by Jens » Thu Feb 04, 2016 8:30 am

So it seems the HK folks have enabled the watchdog in the latest kernel (see http://odroid.com/dokuwiki/doku.php?id= ... hdog_timer) that's great news! Thanks.

So the good news is I can see the

/dev/watchdog

device. Yeah!

Unfortunately there is one issue, the default interval for the timeout is -1 seconds. I guess that requires some configuration. The documentation above says "Watchdog driver aml_wdt is configurable for Odroid C1/C1+." but unfortunately it does not mention how.

Any hints how to setup the interval are greatly appreciated.
Last edited by Jens on Thu Feb 04, 2016 3:48 pm, edited 1 time in total.
Cheers,
Jens

User avatar
odroid
Site Admin
Posts: 30028
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID
Contact:

Re: Enable Watchdog on the C1

Unread post by odroid » Thu Feb 04, 2016 12:10 pm

Which version of kernel do you use?
The WDT nodes (/dev/watchdog and /dev/watchdog0) should be available if you update the kernel with "apt-get distupgrade".

Jens
Posts: 18
Joined: Mon Jan 26, 2015 5:55 am
languages_spoken: english
ODROIDs: C1
Contact:

Re: Enable Watchdog on the C1

Unread post by Jens » Thu Feb 04, 2016 3:43 pm

I see /dev/watchdog and /dev/watchdog0 that is not the problem. But using the standard linux dog API call

int interval;
int fd = open("/dev/watchdog", O_RDWR);
ioctl(fd, WDIOC_GETTIMEOUT, &interval);

gives me -1 as interval.

I use Ubuntu 14.04.3 LTS (GNU/Linux 3.10.80-141 armv7l) I guess that should be the most recent version.

if you look closely at the out from the demo program joerg posted above (on Fri Sep 04, 2015 6:42 pm) you can see that this code also returns -1 as interval.
Cheers,
Jens

moon.linux
Posts: 1162
Joined: Thu Oct 02, 2014 11:42 pm
languages_spoken: english
Contact:

Re: Enable Watchdog on the C1

Unread post by moon.linux » Thu Feb 04, 2016 10:43 pm

Need to debug if the timer is being set by the watchdog demon.

Jens
Posts: 18
Joined: Mon Jan 26, 2015 5:55 am
languages_spoken: english
ODROIDs: C1
Contact:

Re: Enable Watchdog on the C1

Unread post by Jens » Mon Feb 08, 2016 7:50 pm

I don't think it's the watchdog daemon, I'm not running that.
Cheers,
Jens

moon.linux
Posts: 1162
Joined: Thu Oct 02, 2014 11:42 pm
languages_spoken: english
Contact:

Re: Enable Watchdog on the C1

Unread post by moon.linux » Tue Feb 09, 2016 4:10 am

It's the usersapce demon try to set the timeout for watchdog, once the timer is set the watchdog device is kept busy until timer expires.
Most of the watchog demon keep resetting the timer for WDIOC_KEEPALIVE.
If any fault occurs the software will kick start a reboot. But I have not seen this happen.

General testing of watchog demon is you start watchdog demon and then kill that demon, the board should reboot.
Or even if you try to write into the device file it should trigger reboot.

Jens
Posts: 18
Joined: Mon Jan 26, 2015 5:55 am
languages_spoken: english
ODROIDs: C1
Contact:

Re: Enable Watchdog on the C1

Unread post by Jens » Tue Feb 09, 2016 4:17 am

The watchdog feature itself works fine (enable it and stop kicking the system will reboot a after a few seconds). I just get a strange default value of -1 at startup when I query the timeout though I tested it and it appears to be 8 seconds.
I can change the timeout and after that the value it reports is correct. So I guess t's only the boot time default is broken.

[Edited this message to reflect that I can now change the timeout]
Cheers,
Jens

moon.linux
Posts: 1162
Joined: Thu Oct 02, 2014 11:42 pm
languages_spoken: english
Contact:

Re: Enable Watchdog on the C1

Unread post by moon.linux » Wed Feb 17, 2016 9:40 pm

Looks like the amlogic watchdog demon is writing some core registers in the back-end,
read routine for WDIOC_GETTIMEOUT ioctl is not able to extract the value.

Need look into the driver more closely, because it immediately reboot's it's bit difficult,
but I will give it a try to find the solution to the problem.

Edit: As we try to set some timer, watchdog enable and then disable.

Code: Select all

[  133.704554@2] ** enable watchdog
[  133.704979@2] ** disable watchdog

Koxx
Posts: 103
Joined: Tue Jun 16, 2015 6:04 am
languages_spoken: english, french
ODROIDs: C1
Contact:

Re: Enable Watchdog on the C1

Unread post by Koxx » Mon Mar 28, 2016 6:07 pm

Hi,
any status update ?
I'd like to know how I can enable easily the watchdog with the most recent kernel.
thanks.

moon.linux
Posts: 1162
Joined: Thu Oct 02, 2014 11:42 pm
languages_spoken: english
Contact:

Re: Enable Watchdog on the C1

Unread post by moon.linux » Mon Mar 28, 2016 9:16 pm

Actually no timer information is stored in the register for watchdog, It's just enable and disable periodically.
Unless we have some information on where the timer values are getting updated and read/write.
we cannot really have correct watchdog feature.

Most resent kernel have meson watchdog, but I dont have any idea on that.

Koxx
Posts: 103
Joined: Tue Jun 16, 2015 6:04 am
languages_spoken: english, french
ODROIDs: C1
Contact:

Re: Enable Watchdog on the C1

Unread post by Koxx » Tue Mar 29, 2016 2:09 am

ok ...

I didn't manage to start the watch from rc.local...

so, I added a dirty thing in the crontab :

Code: Select all

@reboot echo 0 > /proc/sys/kernel/watchdog
I can see the watchdog running :

Code: Select all

root@odroid:/home/odroid# ps -ax |grep watchdog
   11 ?        R      0:00 [watchdog/0]
   12 ?        R      0:00 [watchdog/1]
   17 ?        R      0:00 [watchdog/2]
   22 ?        R      0:00 [watchdog/3]
 6503 pts/7    S+     0:00 grep --color=auto watchdog
So, is everything ok ? should my odroid reboot in case of freeze (often once a week) ?

moon.linux
Posts: 1162
Joined: Thu Oct 02, 2014 11:42 pm
languages_spoken: english
Contact:

Re: Enable Watchdog on the C1

Unread post by moon.linux » Tue Mar 29, 2016 11:10 am

Can you be specific on the how you CPU freezes (board)?
Watchdog should be able to reboot in case of board hang.
But need to test this functionality.

Koxx
Posts: 103
Joined: Tue Jun 16, 2015 6:04 am
languages_spoken: english, french
ODROIDs: C1
Contact:

Re: Enable Watchdog on the C1

Unread post by Koxx » Wed Mar 30, 2016 3:09 pm

moon.linux wrote:Can you be specific on the how you CPU freezes (board)?
Watchdog should be able to reboot in case of board hang.
But need to test this functionality.
I don't have any idea of the cause.
It happen without any different software running than usual : kodi + transmission + openvpn + subliminal + autofs + fw.
The hearthbeat led is KO.
Nothing in logs (syslog or others).
Running ubuntu, fully updated.

I check the uptime every day. I'll let you know if the watchdog work in my case ;)

Marszczak
Posts: 44
Joined: Thu Oct 01, 2015 10:15 pm
Contact:

Enable Watchdog on the C1

Unread post by Marszczak » Wed Mar 30, 2016 5:04 pm

I'm also having similar hangs for no reason - however this happens on Ubuntu. Running for example Volumio it doesn't hang at all.
I'd love to implement auto reboot based an watchdog.
Common software is Kodi and deluge - maybe I'll disable BitTorrent for a while...

Marszczak
Posts: 44
Joined: Thu Oct 01, 2015 10:15 pm
Contact:

Re: Enable Watchdog on the C1

Unread post by Marszczak » Mon Apr 11, 2016 2:32 pm

Ok so I'm running HW watchdog successfully in c1+. If anybody would be interested- I can explain in detail the process.

Koxx
Posts: 103
Joined: Tue Jun 16, 2015 6:04 am
languages_spoken: english, french
ODROIDs: C1
Contact:

Re: Enable Watchdog on the C1

Unread post by Koxx » Mon Apr 11, 2016 2:57 pm

Marszczak wrote:Ok so I'm running HW watchdog successfully in c1+. If anybody would be interested- I can explain in detail the process.
I am interested !

are you using the /proc/sys/kernel/watchdog ?

It's not working for me. The board still hang ... and no reboot.

moon.linux
Posts: 1162
Joined: Thu Oct 02, 2014 11:42 pm
languages_spoken: english
Contact:

Re: Enable Watchdog on the C1

Unread post by moon.linux » Mon Apr 11, 2016 3:05 pm

Great please share the details. I would like to know more. :D

joerg
Posts: 853
Joined: Tue Apr 01, 2014 2:14 am
languages_spoken: german, english, español
ODROIDs: C1, C1+, C2
Location: Germany
Contact:

Re: Enable Watchdog on the C1

Unread post by joerg » Tue Apr 12, 2016 2:55 am

Hi,
as above explained, I post here again a sample code. This is working on my C1/Android, on Linux should also do. Maybe the includes are to modify.
It opens the watchdog, kicks the watchdog and after 10s not any more. About 8s later device reboots.
Possible, that one can do it also with bash script, I never tried.

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <getopt.h>
#include <string.h>
#include <linux/watchdog.h>

#define WATCHDOGDEV "/dev/watchdog"


/* main */
int main(int argc, char **argv) {

    /* sets up the watchdog */
    int fd;         /* File handler for watchdog */
    char *dev;      /* Watchdog default device file */
    int i;
 
    /* Watchdog init variables */
    dev = WATCHDOGDEV;
    i=0;

    /* Once the watchdog device file is open, the watchdog will be activated by the driver */
    fd = open(dev, O_RDWR);
    if (-1 == fd) {
        fprintf(stderr, "Error: %s\n", strerror(errno));
        exit(EXIT_FAILURE);
    }

    /* loop every second. */
    while ( 1 ) {

        /*kick the watchdog*/
        if (i < 10) {
            ioctl(fd, WDIOC_KEEPALIVE, NULL);
            fprintf(stdout, "Kick watchdog through IOCTL\n");
        } else {
            fprintf(stdout, "Timeout, device should reboot\n");
        }
        i++;
        sleep(1); 
    }
    return 0;
}

Koxx
Posts: 103
Joined: Tue Jun 16, 2015 6:04 am
languages_spoken: english, french
ODROIDs: C1
Contact:

Re: Enable Watchdog on the C1

Unread post by Koxx » Tue Apr 12, 2016 4:22 am

weird ... I get this

Code: Select all

odroid@odroid:~$ sudo  ./watchdog
Kick watchdog through IOCTL
Kick watchdog through IOCTL
Kick watchdog through IOCTL
Kick watchdog through IOCTL
Kick watchdog through IOCTL
Kick watchdog through IOCTL
Kick watchdog through IOCTL
Kick watchdog through IOCTL
Kick watchdog through IOCTL
Kick watchdog through IOCTL
Timeout, device should reboot
Timeout, device should reboot
Timeout, device should reboot
Timeout, device should reboot
Timeout, device should reboot
Timeout, device should reboot
Timeout, device should reboot
Timeout, device should reboot

Koxx
Posts: 103
Joined: Tue Jun 16, 2015 6:04 am
languages_spoken: english, french
ODROIDs: C1
Contact:

Re: Enable Watchdog on the C1

Unread post by Koxx » Tue Apr 12, 2016 4:32 am

ok ... I think I am missing something in your code.
'i' is never reset. Is it normal ?

I simpilifed the code, and it seems to work :

on droid account :

Code: Select all

nano watchdog.c
paste this :

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <getopt.h>
#include <string.h>
#include <linux/watchdog.h>

#define WATCHDOGDEV "/dev/watchdog"


/* main */
int main(int argc, char **argv) {

    /* sets up the watchdog */
    int fd;         /* File handler for watchdog */
    char *dev;      /* Watchdog default device file */
    int i;
 
    /* Watchdog init variables */
    dev = WATCHDOGDEV;
    i=0;

    /* Once the watchdog device file is open, the watchdog will be activated by the driver */
    fd = open(dev, O_RDWR);
    if (-1 == fd) {
        fprintf(stderr, "Error: %s\n", strerror(errno));
        exit(EXIT_FAILURE);
    }

    /* loop every second. */
    while ( 1 ) {
            ioctl(fd, WDIOC_KEEPALIVE, NULL);
            sleep(6);
    }
    return 0;
}
compile :

Code: Select all

gcc watchdog.c -o watchdog; chmod +x watchdog
then autostart:

Code: Select all

sudo crontb -e
and paste this line at the end :

Code: Select all

@reboot /home/odroid/watchdog
everything seems ok :p

moon.linux
Posts: 1162
Joined: Thu Oct 02, 2014 11:42 pm
languages_spoken: english
Contact:

Re: Enable Watchdog on the C1

Unread post by moon.linux » Tue Apr 12, 2016 11:41 am

Well WDIOC_KEEPALIVE keeps the watchdog driver busy and stop it's from reboot.
In case this WDIOC_KEEPALIVE fails it should break and exit the program. Which eventually reboot the system.

joerg
Posts: 853
Joined: Tue Apr 01, 2014 2:14 am
languages_spoken: german, english, español
ODROIDs: C1, C1+, C2
Location: Germany
Contact:

Re: Enable Watchdog on the C1

Unread post by joerg » Tue Apr 12, 2016 1:06 pm

@Koxx: Fine that you improved. Ahh... after reboot I found 'i' was reset. ;) Of course I made only a sample code yesterday, when I saw here are some unanswered questions. To demonstrate that is really rebooting when watchdog not any more served. I forgot the explaination, that this part must be removed.

Koxx
Posts: 103
Joined: Tue Jun 16, 2015 6:04 am
languages_spoken: english, french
ODROIDs: C1
Contact:

Re: Enable Watchdog on the C1

Unread post by Koxx » Tue Apr 12, 2016 2:58 pm

joerg wrote:@Koxx: Fine that you improved. Ahh... after reboot I found 'i' was reset. ;) Of course I made only a sample code yesterday, when I saw here are some unanswered questions. To demonstrate that is really rebooting when watchdog not any more served. I forgot the explaination, that this part must be removed.
hehehe :p
I understood after a second reading ;)

Post Reply

Return to “Hardware and peripherals”

Who is online

Users browsing this forum: No registered users and 1 guest