Linux内核watchdog

2022-05-08  本文已影响0人  小田BSP

本文基于RockPi 4A单板Linux 4.4内核介绍RK3399看门狗(watchdog)的调试方法。

一、驱动文件

RK3399 watchdog用的是新思(Synopsys)的IP,在watchdog驱动程序加载时,会注册misc设备,节点为/dev/watchdog

驱动文件:drivers/watchdog/dw_wdt.c

二、DTS配置

配置文件:arch/arm64/boot/dts/rockchip/rk3399.dtsi

watchdog具体配置如下:

watchdog@ff848000 {
        compatible = "snps,dw-wdt";
        reg = <0x0 0xff848000 0x0 0x100>; ## watchdog寄存器基地址和映射长度
        clocks = <&cru PCLK_WDT>; ## watchdog时钟
        interrupts = <GIC_SPI 120 IRQ_TYPE_LEVEL_HIGH 0>; ## watchdog中断号和触发方式
};

三、调试方法

1、关闭看门狗

echo A > watchdog

写入除大写V以外的任意字符,不再喂狗,一段时间后系统会重启。

## drivers/watchdog/watchdog_dev.c
/*
 *  watchdog_write: writes to the watchdog.
 *  A write to a watchdog device is defined as a keepalive ping.
 *  Writing the magic 'V' sequence allows the next close to turn
 *  off the watchdog (if 'nowayout' is not set).
 */

static ssize_t watchdog_write(struct file *file, const char __user *data,
                        size_t len, loff_t *ppos)
{
    ...
}

例:

## 关闭看门狗后,等待一段时间后重启
root@linaro-alip:/dev# echo A > watchdog
[ 1502.302824] dw_wdt: unexpected close, system will reboot soon
root@linaro-alip:/dev# DDR Version 1.20 20190314  ## 系统重启
In
soft reset

2、打开卡门狗

echo V > watchdog

写入大写V,继续喂狗,系统不再重启。

例:

## 打开看门狗
root@linaro-alip:/dev# echo V > watchdog
root@linaro-alip:/dev#

3、CONFIG_WATCHDOG_NOWAYOUT

watchdog驱动程序中,需要关注宏CONFIG_WATCHDOG_NOWAYOUT。使用如下:

static bool nowayout = WATCHDOG_NOWAYOUT;
module_param(nowayout, bool, 0);
MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started "
         "(default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");

如果配置了CONFIG_WATCHDOG_NOWAYOUT,通过echo命令写入任何字符,都不会关闭喂狗。

root@ubuntu:/home/run/code/rockchip-bsp/kernel/arch/arm64/configs# git diff rockchip_linux_defconfig
diff --git a/arch/arm64/configs/rockchip_linux_defconfig b/arch/arm64/configs/rockchip_linux_defconfig
index cfbc7774a15f..80265bdcd598 100644
--- a/arch/arm64/configs/rockchip_linux_defconfig
+++ b/arch/arm64/configs/rockchip_linux_defconfig
 CONFIG_WATCHDOG=y
 CONFIG_DW_WATCHDOG=y
+CONFIG_WATCHDOG_NOWAYOUT=y
 CONFIG_MFD_CROS_EC=y

例:

## 写入任何字符,都不会关闭喂狗
root@linaro-alip:~# echo A > watchdog
root@linaro-alip:~#

注:

使用./build/mk-kernel.sh rockpi4a编译内核时,即使修改了rockchip_linux_defconfig文件,编译时,相关配置也不会生效。需要在编译前make distclean或删除内核根目录下的.config文件后,重新编译内核。

上一篇下一篇

猜你喜欢

热点阅读