Rockchip RK3588 硬件watchdog使用方法

Rockchip RK3588 打开硬件watchdog

kernel开启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 
/*
 * Copyright (C) 2012 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/*
 * Copyright (C) 2012 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <errno.h>
#include <fcntl.h>
#include <linux/watchdog.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include <android-base/logging.h>

#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);
    }
}

测试watchdog是否生效

  1. 关掉系统panic重启
echo 0 > /sys/module/kernel/parameters/panic
  1. 人为制作一个panic使系统卡住
echo c > proc/sysrq-trigger
  1. 等待30s看系统是否重启,如果重启则表示watchdog正常工作了
  • 1
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Rockchip RK3588是一款高性能的芯片,主要用于移动设备和嵌入式系统。它支持USB接口,可以用于连接外部设备,并进行数据传输和通信。 关于Rockchip RK3588 USB开发指南,以下是一些建议和指导: 1. 创建USB连接:首先,需要在嵌入式系统中创建一个USB连接。这可以通过配置硬件和软件来完成。硬件方面,需要确保RK3588芯片和USB接口的正确连接。软件方面,可以使用相应的驱动程序和库来管理和控制USB连接。 2. USB驱动程序开发:为了实现与外部设备的数据交换,需要编写USB驱动程序。这些驱动程序可以通过使用底层的USB协议和API来完成。可以选择使用已有的USB驱动程序框架,如libusb等,也可以根据具体需求自行编写驱动程序。 3. 数据传输和通信:一旦USB连接建立并配置完毕,就可以通过USB接口进行数据传输和通信。可以使用USB的各种传输模式,如批量传输、中断传输或等时传输,根据实际需求选择合适的模式。 4. USB设备接口开发:如果需要将RK3588芯片作为USB设备使用,还需要进行USB设备接口开发。可以根据设备规范和需求,设计并实现相应的USB接口。 5. 软件开发工具:为了更便捷地进行Rockchip RK3588 USB开发,可以使用相应的软件开发工具。Rockchip提供了开发工具包(SDK)和调试工具,可以加快开发过程,并提供调试和优化的功能。 总之,Rockchip RK3588 USB开发指南涵盖了创建USB连接、USB驱动程序开发、数据传输和通信、USB设备接口开发等内容。通过合理的设计和开发,可以充分利用RK3588的强大性能和USB接口的灵活性,实现丰富的移动设备和嵌入式系统功能。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

loitawu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值