Watchdog device always busy

Hello!

I’m working with a imx8m-plus board with Torizon 5.5

I need to write an application that will use the /dev/watchdog device

But the application always fails to open the device, it says that the resource is busy. I’m trying to open it like this:

api_watchdog_fd = open("/dev/watchdog", O_RDWR);

This is the output from fuser:

sudo fuser -v /dev/watchdog
** USER PID ACCESS COMMAND**
/dev/watchdog: root 1 F… systemd

It looks like systemd is using the watchdog? That’s why my application can’t open the /dev/watchdog device?

I’ve googled around a bit and I’ve tried removing all the watchdog related entries from the /etc/systemd/system.conf file, and rebooting the board, but that had no effect.

This is the dmesg output related to watchdog:

dmesg | grep watchdog
[ 1.352157] imx2-wdt 30280000.watchdog: timeout 60 sec (nowayout=0)
[ 9.168780] systemd[1]: Hardware watchdog ‘imx2+ watchdog’, version 0
[ 9.168801] systemd[1]: Set hardware watchdog to 30s.

And the Torizon version:

uname -r
5.4.161-5.5.0-devel+git.bfe277fce128

Question is: how can I disable the watchdog from being used by another process, so my application can open it?

Greetings @jose_au_zone,

You are on the right track but the method is a bit different. We store our config files for systemd here:

sudo ls /usr/lib/systemd/system.conf.d
00-systemd-conf.conf  10-systemd-conf.conf

Inside the file 10-systemd-conf.conf is where we set the systemd-watchdog usage:

[Manager]
# Change CtrlAltDelBurstAction from default of `reboot-force` to `none`.
# Disable the immediate reboot which occurs when Ctrl+Alt+Del is pressed more
# than 7 times per 2s
# https://www.freedesktop.org/software/systemd/man/systemd.html#SIGINT
CtrlAltDelBurstAction=none
DefaultEnvironment="MACHINE=verdin-imx8mp"
RuntimeWatchdogSec=30s

Unfortunately this is in a read-only part of the filesystem so you can’t trivially modify this file to remove the RuntimeWatchdogSec=30s line. However you can create another similar file to overwrite this. Create the following file /etc/systemd/system.conf.d/10-systemd-conf.conf. As for the contents it’s the exact same as the first file minus the last line regarding the watchdog. This file in /etc should now overwrite the one in /usr/lib. After a quick reboot you should see that the watchdog is not used by systemd anymore:

verdin-imx8mp-06849059:~$ dmesg | grep watchdog
[    1.323643] imx2-wdt 30280000.watchdog: timeout 60 sec (nowayout=0)
verdin-imx8mp-06849059:~$ sudo fuser -v /dev/watchdog
verdin-imx8mp-06849059:~$

Please give this a try and see if you can now use the watchdog for your needs.

Best Regards,
Jeremias

Thanks Jeremias, it worked!

Now my application can open the watchdog file descriptor just fine

Glad to hear it worked. Just one more thing, this might be obvious but please exercise caution now that the watchdog isn’t being used to monitor the kernel/systemd.

Best Regards,
Jeremias

I have a follow up question now, I can create a new topic to ask this if it is better.

I want our Yocto build to add this file automatically.

Currently we are doing our modifications with a .bbappend file named “linux-toradex_%.bbappend” and all of our changes are being applied correctly

To add this file I added those lines to the bbappend:

SRC_URI += "file://10-systemd-conf.conf"

do_install_append() {

install -d ${D}${sysconfdir}/systemd/system.conf.d/

install -m 0755 ${WORKDIR}/10-systemd-conf.conf ${D}${sysconfdir}/systemd/system.conf.d/

}

FILES_${PN} += "${sysconfdir}/systemd/"
FILES_${PN} += "${sysconfdir}/systemd/system.conf.d"
FILES_${PN} += "${sysconfdir}/systemd/system.conf.d/10-systemd-conf.conf"

I`ve added the last 3 lines after googling one error that I was having, which is:

ERROR: linux-toradex-5.4.129+gitAUTOINC+6e59391f91_828ec42a6a-r0 do_package: QA Issue: linux-toradex: Files/directories were installed but not shipped in any package:
/etc/systemd
/etc/systemd/system.conf.d
/etc/systemd/system.conf.d/10-systemd-conf.conf

But even after adding that line the error persists. Do you have any guidance on how to properly do this?

Thanks

Wait you’re doing this all in an append file for the linux-toradex recipe? I’m not sure how well that would work to be honest.

For reference we add our 10-systemd-conf.conf file in this bbappend in our layer: meta-toradex-torizon/systemd-conf_%.bbappend at dunfell-5.x.y · toradex/meta-toradex-torizon · GitHub

Which is a bbappend to the original recipe here: systemd-conf_244.3.bb\systemd\recipes-core\meta - openembedded-core - OpenEmbedded Core layer

Perhaps you can try a new separate bbappend in your own layer modeling that.

As an alternative you can also add this file using torizoncore-builder and making an image with that. See this for reference: Capturing Changes in the Configuration of a Board on TorizonCore

Best Regards,
Jeremias

Thank you so much!

Creating another bbappend for the systemd-conf in our layer and just copying the relevant code there worked!

Glad it worked out!