How to update a hardware watchdog from boot?

224 views Asked by At

I have set up a Linux system using Yocto on a Zynq-7000 with Petalinux 2021.1. My current task involves resetting a hardware watchdog every 2 seconds. Resetting the watchdog once my system is already up and running is not an issue. However, I am facing a challenge in resetting the watchdog during the boot process.

My understanding is that the u-boot phase takes less than 2 seconds, so resetting the watchdog at that moment is unnecessary. However, there is a significant gap of approximately 40 seconds between the kernel launch and the user connection.

Does anyone have any ideas or suggestions on how to tackle this issue?

I tried to launch a service at beginning of Kernel but without success.

Your assistance would be greatly appreciated!

Boune.

2

There are 2 answers

4
Alex On

Sounds like a job for a kernel module. Check if one of these modules is something that you are looking for:
https://xilinx-wiki.atlassian.net/wiki/spaces/A/pages/18842055/Cadence+WDT+Driver
https://xilinx-wiki.atlassian.net/wiki/spaces/A/pages/18841776/Axi+Watchdog

If not, you can write a small kernel module and put it into the initrd/initramfs so it will be loaded on start.

https://docs.xilinx.com/r/2021.2-English/ug1144-petalinux-tools-reference-guide/Creating-and-Adding-Custom-Kernel-Modules

initramfs also supports running some shell scripts on the start but I'm not sure how it works on Petalinux.

If the time is still too late you could build the kernel with the module included (as built-in). There is a mechanism named initcall which controls the order of the built-in modules' initialization. https://0xax.gitbooks.io/linux-insides/content/Concepts/linux-cpu-3.html

1
Theodore On

I have a ZYNQ(7020) board with hardware watchdog too. My board's HW watchdog feed time is 125ms control with gpio, my solution is:

  1. add gpio watchdog in kernel kernel support gpio watchdog , when image jump from uboot to kernel ,kernel will feed hw watch dog, just open gpio watchdog, kernel will feed hw watchdog always. add gpio watch dog to your defconfig ,locate in Device Drivers → Watchdog Timer Support → Watchdog device controlled through GPIO-line

  2. add gpio watchdog to dts add gpio watchdog to amba node &amba {

     watchdog {      
    
     compatible = "linux,wdt-gpio";
    
     gpios = <&gpio0 44 0>;
    
     hw_algo = "toggle";
    
     hw_margin_ms = <200>;
    
     always-running;
    

    }; };

    1. check watchdog After kernel start you will found hw watchdog in /sys/class/watchdog/

ls -alh /sys/class/watchdog/ total 0 drwxr-xr-x 2 root root 0 Jul 26 07:27 . drwxr-xr-x 34 root root 0 Jul 26

06:45 .. lrwxrwxrwx 1 root root 0 Jul 26 07:27 watchdog0 -> ../../devices/soc0/amba/amba:watchdog/watchdog/watchdog0 lrwxrwxrwx 1 root root 0 Jul 26 07:27 watchdog1 -> ../../devices/soc0/amba/f8005000.watchdog/watchdog/watchdog1

watchdog0: hw watchdog watchdog1: software watchdog for app