AMD-Xilinx MPSoC的器件里,提供了内置的Watchdog。在Vivado里选择Watchdog,并在设备树里使能Watchdog,还不能在Linux中正常使用。
pmu-firmware修改
如果要在Linux中使用Watchdog,需要在project-spec/meta-user/recipes-bsp/embeddedsw/pmu-firmware_%.bbappend中添加如下内容:
2021.1以前的版本:
# pmu-firmware_%.bbappend content
YAML_COMPILER_FLAGS_append = " -DENABLE_EM -DENABLE_SCHEDULER"
2022.1及以后的版本:
# pmu-firmware_%.bbappend content
YAML_COMPILER_FLAGS:append = " -DENABLE_EM -DENABLE_SCHEDULER"
Devicetree
检查Devicetree,确保其中的status为"okay", 也有属性reset-on-timeout。
watchdog@fd4d0000 {
clocks = <0x03 0x4b>;
compatible = "cdns,wdt-r1p2";
interrupt-parent = <0x04>;
interrupts = <0x00 0x71 0x01>;
phandle = <0x76>;
reg = <0x00 0xfd4d0000 0x00 0x1000>;
reset-on-timeout;
status = "okay";
timeout-sec = <0x3c>;
};
watchdog@ff150000 {
clocks = <0x03 0x70>;
compatible = "cdns,wdt-r1p2";
interrupt-parent = <0x04>;
interrupts = <0x00 0x34 0x01>;
phandle = <0x77>;
reg = <0x00 0xff150000 0x00 0x1000>;
status = "okay";
timeout-sec = <0x0a>;
};
启动信息
使用命令“dmesg”检查启动信息,有如下信息。
# dmesg -c | grep watchdog
[ 539.845269] watchdog: watchdog0: watchdog did not stop!
[ 691.897271] watchdog: watchdog1: watchdog did not stop!
[ 702.136679] cdns-wdt ff150000.watchdog: Watchdog timed out. Internal reset not enabled
通过设备节点控制Watchdog
通过设备节点“/dev/watchdog0”可以控制Watchdog。
执行命令“echo s > /dev/watchdog0”,能启动Watchdog,但是没有清狗操作。时间久了,单板会自动重启动。
# echo s > /dev/watchdog0
[ 154.773229] watchdog: watchdog0: watchdog did not stop!
# dmesg -c | tail -n 20
[ 154.773229] watchdog: watchdog0: watchdog did not stop!
# dmesg -c | tail -n 20
# cat /proc/uptime
193.70 738.72
# Xilinx Zynq MP First Stage Boot Loader
Release 2022.1 Apr 11 2022 - 09:29:50
NOTICE: BL31: v2.6(release):v1.1-9207-g67ca59c67
执行命令“echo 'V' > /dev/watchdog0”,能停止Watchdog,单板再也不会自动重启动。
# echo s > /dev/watchdog0 && cat /proc/uptime
[ 1850.817370] watchdog: watchdog0: watchdog did not stop!
1850.69 7364.03
# sleep 1
# echo 'V' > /dev/watchdog0 && cat /proc/uptime
1852.40 7370.84
# cat /proc/uptime
1887.11 7509.61
# cat /proc/uptime
1971.67 7847.72
# cat /proc/uptime
2159.96 8600.54
通过应用程序控制Watchdog
Linux也提供了应用程序watchdog控制Watchdog,启动Watchdog并清狗。下面是启动Watchdog的示例。如果由于特殊原因,应用程序watchdog异常退出,就会导致单板复位。下面的例子中,使用kill命令杀死了应用程序watchdog的进程,导致单板复位。
# watchdog -T 10 -t 3 /dev/watchdog0
# ps -A | grep watchdog
95 ? 00:00:00 watchdogd
1159 ? 00:00:00 watchdog
# cat /proc/uptime
1880.18 7481.78
# cat /proc/uptime
1895.65 7543.65
# kill -9 1159
# [ 1904.549498] watchdog: watchdog0: watchdog did not stop!
# Xilinx Zynq MP First Stage Boot Loader
Release 2022.1 Apr 11 2022 - 09:29:50
NOTICE: BL31: v2.6(release):v1.1-9207-g67ca59c67
通过系统脚本启动Watchdog并清狗
Linux也提供系统脚本/etc/init.d/watchdog-init控制Watchdog。
系统脚本/etc/init.d/watchdog-init也使用了应用程序控制Watchdog。如果使用kill命令杀死应用程序watchdog的进程,也会导致单板复位。
# /etc/init.d/watchdog-init start && cat /proc/uptime
Set healthy bit
/etc/init.d/watchdog-init: line 92: /sys/firmware/zynqmp/health_status: Permission denied
Starting WDT
2199.54 8758.78
# ps -A | grep watchdog
95 ? 00:00:00 watchdogd
1110 ? 00:00:00 watchdog
# sleep 5
# /etc/init.d/watchdog-init stop && cat /proc/uptime
Stoping WDT
2204.62 8779.08
# cat /proc/uptime
2299.32 9157.71
# cat /proc/uptime
2628.22 10472.73
参考文档
测试单板
KV260 2022.1 BSP
标签:MPSoC,00,watchdog0,Linux,AMD,uptime,Watchdog,watchdog,proc From: https://www.cnblogs.com/hankfu/p/17141471.html