- Rockchip RK3588 打开硬件watchdog
- kernel开启watchdog模块
- Android层启动watchdogd进程
- 测试watchdog是否生效
RK3588 硬件watchdog默认 没有开启,如果需要打开watchdog功能,可以在dts中打开wdt节点即可:
--- a/arch/arm64/boot/dts/rockchip/rk3588-evb1-lp4.dtsi
+++ b/arch/arm64/boot/dts/rockchip/rk3588-evb1-lp4.dtsi
@@ -735,3 +735,7 @@
&usbhost_dwc3_0 {
status = "disabled";
};
+
+&wdt {
+ status = "okay";
+};
开启后用如下命令可以测试watchdog是否生效
输入如下命令后系统不再喂狗,watchdog会自动重启。
echo A > /dev/watchdog , 这里写入的是除大写V以外的任意字符。Android层启动watchdogd进程
Android层的watchdog进程默认也没有启动,按如下修改可以启动watchdogd进程,当系统卡住时会停止喂狗来触发系统重启
@sys2_206:~/3_Android12_29_debug/device/rockchip/common$ git diff
diff --git a/rootdir/init.rockchip.rc b/rootdir/init.rockchip.rc
index 0ce612a8..b5e05069 100755
--- a/rootdir/init.rockchip.rc
+++ b/rootdir/init.rockchip.rc
@@ -27,9 +27,9 @@ service charger /system/bin/charger
file /proc/last_kmsg r
# Set watchdog timer to 30 seconds and pet it every 10 seconds to get a 20 second margin
-service watchdogd /sbin/watchdogd 10 20
+service watchdogd system/bin/watchdogd 10 20 //这里10 20表示喂狗的超时时间是10s+20s=30s
class core
- disabled
+# disabled
seclabel u:r:watchdogd:s0
android上面watchdogd的代码实现,可以参考这个代码在自己的应用中使用watchdog
@sys2_206:~/3_Android12_29_debug$ vim system/core/watchdogd/watchdogd.cpp #include测试watchdog是否生效#include #include #include #include #include #include #define DEV_NAME "/dev/watchdog" int main(int argc, char** argv) { android::base::InitLogging(argv, &android::base::KernelLogger); int interval = 10; if (argc >= 2) interval = atoi(argv[1]); int margin = 10; if (argc >= 3) margin = atoi(argv[2]); LOG(INFO) << "watchdogd started (interval " << interval << ", margin " << margin << ")!"; int fd = open(DEV_NAME, O_RDWR | O_CLOEXEC); if (fd == -1) { PLOG(ERROR) << "Failed to open " << DEV_NAME; return 1; } int timeout = interval + margin; int ret = ioctl(fd, WDIOC_SETTIMEOUT, &timeout); if (ret) { PLOG(ERROR) << "Failed to set timeout to " << timeout; ret = ioctl(fd, WDIOC_GETTIMEOUT, &timeout); if (ret) { PLOG(ERROR) << "Failed to get timeout"; } else { if (timeout > margin) { interval = timeout - margin; } else { interval = 1; } LOG(WARNING) << "Adjusted interval to timeout returned by driver: " << "timeout " << timeout << ", interval " << interval << ", margin " << margin; } } while (true) { write(fd, "", 1); sleep(interval); } }
- 关掉系统panic重启
echo 0 > /sys/module/kernel/parameters/panic
- 人为制作一个panic使系统卡住
echo c > proc/sysrq-trigger
- 等待30s看系统是否重启,如果重启则表示watchdog正常工作了



