Zynq Linux Watchdog Configuration Guide

This guide covers how to configure and use the hardware watchdog timer(what is a watchdog?) on Xilinx Zynq SoCs (including Zynq-7000 and Zynq UltraScale+ MPSoC) in a Linux environment. 1. Understanding Zynq Watchdog Timers Zynq devices contain two types of watchdogs: System Watchdog Timer (SWDT) - Part of the Processing System (PS) Programmable Logic Watchdog - Can be implemented in PL (if available) This guide focuses on the PS watchdog (SWDT). 2. Kernel Configuration Ensure watchdog support is enabled in your kernel: bash CONFIG_XILINX_WATCHDOG=y CONFIG_WATCHDOG=y CONFIG_WATCHDOG_CORE=y For Petalinux: bash petalinux-config -c kernel Navigate to: Device Drivers → Watchdog Timer Support → Xilinx Watchdog 3. Device Tree Configuration Add watchdog node to your device tree (system-user.dtsi): dts / { wdt: watchdog@f8005000 { compatible = "xlnx,zynq-wdt"; reg = ; interrupts = ; clocks = ; timeout-sec = ; /* Default timeout */ }; }; For Zynq UltraScale+: dts wdt: watchdog@ff150000 { compatible = "xlnx,zynqmp-wdt"; reg = ; interrupts = ; clocks = ; timeout-sec = ; }; 4. Userspace Configuration Using the watchdog Check if watchdog device exists: bash ls /dev/watchdog* Basic usage with wdctl: bash wdctl /dev/watchdog0 To start and maintain the watchdog: bash echo 1 > /dev/watchdog0 # Start watchdog while true; do echo > /dev/watchdog0; sleep 5; done # Keep feeding Using systemd (recommended) Create a service file /etc/systemd/system/watchdog.service: ini [Unit] Description=Watchdog service After=multi-user.target [Service] Type=simple ExecStart=/usr/bin/wd_keepalive /dev/watchdog0 [Install] WantedBy=multi-user.target Create /usr/bin/wd_keepalive: bash #!/bin/sh while true; do echo > /dev/watchdog0 sleep 5 done Make it executable: bash chmod +x /usr/bin/wd_keepalive systemctl enable watchdog.service systemctl start watchdog.service 5. Advanced Configuration Setting Timeout At runtime: bash echo 30 > /sys/class/watchdog/watchdog0/timeout Kernel Panic Behavior To enable reboot on watchdog timeout: bash echo 1 > /proc/sys/kernel/panic_on_wdt echo 10 > /proc/sys/kernel/panic # Reboot after 10 seconds Testing Watchdog Start the watchdog: bash echo 1 > /dev/watchdog0 Stop feeding it (system should reboot after timeout) 6. Debugging Check watchdog status: bash cat /proc/interrupts | grep wdt dmesg | grep watchdog 7. Custom Watchdog Daemon Example Here's a simple C program to handle watchdog: c #include #include #include int main() { int fd = open("/dev/watchdog0", O_WRONLY); if (fd == -1) { perror("Watchdog"); return 1; } while (1) { write(fd, "\0", 1); // Feed the watchdog fsync(fd); sleep(5); // Feed interval } close(fd); return 0; } Compile with: bash gcc watchdog_daemon.c -o watchdog_daemon 8. Important Notes The Zynq watchdog cannot be stopped once started (only reset by feeding) Default timeout is 60 seconds (configurable) Always test watchdog behavior in a controlled environment For critical systems, implement a multi-level monitoring approach 9. References Xilinx PG114 (Zynq TRM) Linux kernel documentation: Documentation/watchdog/ systemd.watchdog man page This configuration ensures your Zynq-based system can automatically recover from hangs or catastrophic software failures.

May 12, 2025 - 08:50
 0
Zynq Linux Watchdog Configuration Guide

This guide covers how to configure and use the hardware watchdog timer(what is a watchdog?) on Xilinx Zynq SoCs (including Zynq-7000 and Zynq UltraScale+ MPSoC) in a Linux environment.

Image description

1. Understanding Zynq Watchdog Timers
Zynq devices contain two types of watchdogs:

  • System Watchdog Timer (SWDT) - Part of the Processing System (PS)
  • Programmable Logic Watchdog - Can be implemented in PL (if available)

This guide focuses on the PS watchdog (SWDT).

2. Kernel Configuration
Ensure watchdog support is enabled in your kernel:

bash
CONFIG_XILINX_WATCHDOG=y
CONFIG_WATCHDOG=y
CONFIG_WATCHDOG_CORE=y

For Petalinux:

bash
petalinux-config -c kernel

Navigate to:

Device Drivers → Watchdog Timer Support → Xilinx Watchdog

3. Device Tree Configuration
Add watchdog node to your device tree (system-user.dtsi):

dts
/ {
    wdt: watchdog@f8005000 {
        compatible = "xlnx,zynq-wdt";
        reg = <0xf8005000 0x1000>;
        interrupts = <0 9 1>;
        clocks = <&clkc 45>;
        timeout-sec = <10>;  /* Default timeout */
    };
};

For Zynq UltraScale+:

dts
wdt: watchdog@ff150000 {
    compatible = "xlnx,zynqmp-wdt";
    reg = <0x0 0xff150000 0x0 0x1000>;
    interrupts = <0 113 1>;
    clocks = <&clk 71>;
    timeout-sec = <10>;
};

4. Userspace Configuration
Using the watchdog

  1. Check if watchdog device exists:
bash
ls /dev/watchdog*
  1. Basic usage with wdctl:
bash
wdctl /dev/watchdog0
  1. To start and maintain the watchdog:
bash
echo 1 > /dev/watchdog0  # Start watchdog
while true; do echo > /dev/watchdog0; sleep 5; done  # Keep feeding

Using systemd (recommended)
Create a service file /etc/systemd/system/watchdog.service:

ini
[Unit]
Description=Watchdog service
After=multi-user.target

[Service]
Type=simple
ExecStart=/usr/bin/wd_keepalive /dev/watchdog0

[Install]
WantedBy=multi-user.target

Create /usr/bin/wd_keepalive:

bash
#!/bin/sh
while true; do
    echo > /dev/watchdog0
    sleep 5
done

Make it executable:

bash
chmod +x /usr/bin/wd_keepalive
systemctl enable watchdog.service
systemctl start watchdog.service

5. Advanced Configuration
Setting Timeout
At runtime:

bash
echo 30 > /sys/class/watchdog/watchdog0/timeout

Kernel Panic Behavior
To enable reboot on watchdog timeout:

bash
echo 1 > /proc/sys/kernel/panic_on_wdt
echo 10 > /proc/sys/kernel/panic  # Reboot after 10 seconds

Testing Watchdog

  1. Start the watchdog:
bash
echo 1 > /dev/watchdog0
  1. Stop feeding it (system should reboot after timeout)

6. Debugging
Check watchdog status:

bash
cat /proc/interrupts | grep wdt
dmesg | grep watchdog

7. Custom Watchdog Daemon Example
Here's a simple C program to handle watchdog:

c
#include 
#include 
#include 

int main() {
    int fd = open("/dev/watchdog0", O_WRONLY);
    if (fd == -1) {
        perror("Watchdog");
        return 1;
    }

    while (1) {
        write(fd, "\0", 1);  // Feed the watchdog
        fsync(fd);
        sleep(5);  // Feed interval
    }

    close(fd);
    return 0;
}

Compile with:

bash
gcc watchdog_daemon.c -o watchdog_daemon

8. Important Notes

  1. The Zynq watchdog cannot be stopped once started (only reset by feeding)
  2. Default timeout is 60 seconds (configurable)
  3. Always test watchdog behavior in a controlled environment
  4. For critical systems, implement a multi-level monitoring approach

9. References

  • Xilinx PG114 (Zynq TRM)
  • Linux kernel documentation: Documentation/watchdog/
  • systemd.watchdog man page

This configuration ensures your Zynq-based system can automatically recover from hangs or catastrophic software failures.