Zynq Linux Watchdog Configuration Guide
Hedy

Hedy @carolineee

About: Publish some interesting electronic articles

Joined:
Dec 18, 2023

Zynq Linux Watchdog Configuration Guide

Publish Date: May 12
0 0

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
Enter fullscreen mode Exit fullscreen mode

For Petalinux:

bash
petalinux-config -c kernel
Enter fullscreen mode Exit fullscreen mode

Navigate to:

Device Drivers → Watchdog Timer Support → Xilinx Watchdog
Enter fullscreen mode Exit fullscreen mode

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 */
    };
};
Enter fullscreen mode Exit fullscreen mode

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>;
};
Enter fullscreen mode Exit fullscreen mode

4. Userspace Configuration
Using the watchdog

  1. Check if watchdog device exists:
bash
ls /dev/watchdog*
Enter fullscreen mode Exit fullscreen mode
  1. Basic usage with wdctl:
bash
wdctl /dev/watchdog0
Enter fullscreen mode Exit fullscreen mode
  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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Create /usr/bin/wd_keepalive:

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

Make it executable:

bash
chmod +x /usr/bin/wd_keepalive
systemctl enable watchdog.service
systemctl start watchdog.service
Enter fullscreen mode Exit fullscreen mode

5. Advanced Configuration
Setting Timeout
At runtime:

bash
echo 30 > /sys/class/watchdog/watchdog0/timeout
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Testing Watchdog

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

6. Debugging
Check watchdog status:

bash
cat /proc/interrupts | grep wdt
dmesg | grep watchdog
Enter fullscreen mode Exit fullscreen mode

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

c
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>

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;
}
Enter fullscreen mode Exit fullscreen mode

Compile with:

bash
gcc watchdog_daemon.c -o watchdog_daemon
Enter fullscreen mode Exit fullscreen mode

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.

Comments 0 total

    Add comment