驱动调试工具整理


随时更新记录

驱动工具

驱动工具备注
开机时间prelink生成excel查看每个脚本的时间
开机时间systemd-analyze blame查看systemd启动每个服务消耗的时间
内存/proc/meminfo查看内存信息
内存devmem可以用来访问和修改物理内存
内存devkmem可以用来访问虚拟内存,不可以修改
串口minicom
i2cI2c-toolsi2cdetect:检测挂在系统上的设备总线。
i2cI2c-toolsi2cdump:查看寄存器的值
i2cI2c-toolsi2cget:读取寄存器值
i2cI2c-toolsi2cset:设置寄存器值
cancan-utilscansend:发送数据
cancan-utilscandump:接受数据
spispi-toolsspi-config:设置spi模式速度等属性
spispidev_testspidev_test:spi发送和接受数据
usbusbutilslsusb:查看usb设备信息
usbusbutilsusbhid-dump:监听usb设备
usbusbmon/sys/kernel/debug/usb/usbmon
GPIO子系统/sys/class/gpio
网口驱动ethtool
网口驱动Miimtr
nand nor flashmtd-utils
声卡alsa-utilsarecord:录音
声卡alsa-utilsaplay:播放音乐
声卡alsa-utilsamixer:调节音量等控制
声卡alsa-utilsalsamixer:图形化调节音量等控制,更好用
声卡pavucontrolpavucontrol :图形化调节音量
声卡audacity查看声音波形
摄像头xawtvxawtv
spispidev_test
wifiwireless_toolsiwconfig、iwpriv、 iwevent
wifiwpa_supplicantwpa_supplicant、wpa_cli、wpa_passphrase
蓝牙BLE调试助手bluetoothctl
触摸屏evtestevtest
鼠标evtestevtest
键盘evtestevtest

从proc文件系统中导出dts的方法:

dtc -I fs -O dts -o device_tree.dts /proc/device-tree

实时性测试:

  1. latencytop
  2. ftrace的preemptirqsoff测试最大关中断时间,
  3. ftrace的timerlat osnoise测试调度延迟时间
  4. cyclictest
  5. 打开CONFIG_SCHED_DEBUG选项

网络PHY调试:

/sys/devices/platform/eth0/mdio/stmmac/phy_register
查看机器占用的网络端口号:netstat -tlunp

麒麟系统修改不启动UKUI界面:

sudo systemctl set-default multi-user.target 

麒麟系统修改恢复启动UKUI界面:

sudo systemctl set-default graphical.target

使用 nmcli 命令来操作 Wi-Fi:

  1. 查看可用的 Wi-Fi 网络
nmcli device wifi list

这条命令将列出附近可用的 Wi-Fi 网络及其相关信息,例如 SSID、信号强度等。

  1. 连接到 Wi-Fi 网络
nmcli device wifi connect <SSID> password <密码>

<SSID> 替换为你要连接的 Wi-Fi 网络的名称,<密码> 替换为网络的密码。如果该网络不需要密码,则不需要使用 password 参数。

  1. 断开当前 Wi-Fi 连接
nmcli device disconnect <WIFI_INTERFACE>

<WIFI_INTERFACE> 替换为当前 Wi-Fi 网卡的接口名,可以通过运行 nmcli device status 命令查看接口名。

  1. 查看当前网络连接状态
nmcli connection show

这条命令将列出当前系统中所有的网络连接,包括有线和 Wi-Fi 连接。

  1. 开启和关闭 Wi-Fi 网卡
nmcli radio wifi on   # 开启 Wi-Fi 网卡
nmcli radio wifi off  # 关闭 Wi-Fi 网卡

使用 bluetoothctl 命令来操作蓝牙设备:

  1. 启动蓝牙服务
sudo systemctl start bluetooth
  1. 停止蓝牙服务
sudo systemctl stop bluetooth
  1. 重启蓝牙服务
sudo systemctl restart bluetooth
  1. 检查蓝牙状态
sudo systemctl status bluetooth
  1. 启用蓝牙
bluetoothctl power on
  1. 关闭蓝牙
bluetoothctl power off
  1. 扫描附近的蓝牙设备
bluetoothctl scan on
  1. 停止扫描
bluetoothctl scan off
  1. 连接到蓝牙设备
bluetoothctl connect <设备MAC地址>

<设备MAC地址> 替换为你要连接的蓝牙设备的 MAC 地址。

  1. 断开蓝牙设备的连接
bluetoothctl disconnect <设备MAC地址>

<设备MAC地址> 替换为你要断开连接的蓝牙设备的 MAC 地址。

  1. 显示已配对的设备
bluetoothctl paired-devices
  1. 显示已连接的设备
bluetoothctl devices

获取UEFI的ACPI信息:

apt install acpidump
acpidump -o acpidump.bin
acpixtract -a acpidump.bin
iasl -d *.dat

使用vim打开dsdt.dsl文件就行

系统假死,鼠标键盘串口都没有信息的时候使用:
sysrq

打印输出的方法

1.printk()
最原始的打印 api,与之相关的是启动参数 loglevel,它决定了可以被打印出来的信息的最低优先级。
2.pr_()
pr_emerg(), pr_alert(), pr_crit(), pr_err(), pr_warning(), pr_notice(), pr_info(), pr_cont(), pr_debug()等函数,
用法和printk()相同。
3.dev_
()
dev_emerg(), dev_alert(), dev_crit(), dev_err(), dev_warn(), dev_notice(), dev_info(), dev_dbg()
它们的最大特点是需要传入一个 struct device 的参数,并且会打印出这个 device 的名字,一边是在驱动相关的代码里使用。
用法:dev_info(&pdev->dev, “is ok\n”);
开关:CONFIG_DEBUG_FS 和 CONFIG_DYNAMIC_DEBUG

echo -n 'file drivers/power/supply/cw2017_battery.c +p' > /sys/kernel/debug/dynamic_debug/control

4.addr2line
可以将函数地址解析为函数名
5.WARN_ON(1)
这个函数可以打印出当前的函数调用栈。
6.devmem
这个开源程序可以在应用层直接读写cpu的内存和寄存器,非常方便我们debug
7.kgdb
这个可以像gdb一样进行内核代码的debug
8.ftrace
帮助开发人员了解 Linux 内核的运行时行为,以便进行故障调试或性能分析。
9.kprobe
它可以在任意的位置放置探测点,提供了探测点的调用前、调用后和内存访问出错3种回调方式来调试。
10.perf
Linux性能剖析工具,但是我也没用过,但是听说很强大。

开启DEBUG_SECTION_MISMATCH 这个选项,内核编译的时候可以取消内联优化,让debug更加轻松。

pwm测试脚本:

echo 1 > /sys/class/pwm/pwmchip0/export
echo 1000000 > /sys/class/pwm/pwmchip0/pwm1/period
echo 200000 > /sys/class/pwm/pwmchip0/pwm1/duty_cycle
echo 1 > /sys/class/pwm/pwmchip0/pwm1/enable

can测试:

#1.设置波特率
ip link set can0 type can bitrate 500000 dbitrate 2000000 berr-reporting on fd on
ip link set can1 type can bitrate 500000 dbitrate 2000000 berr-reporting on fd on
#2.开启can设备
ip link set up can0
ip link set up can1
#3.新开控制台接受数据
candump can1
#4.新开控制台发送数据
cansend can0 123#abcdabcd

看门狗测试:

1.加载看门狗驱动
2.输入命令

echo 1 > /dev/watchdog

3.等待1分钟,如果会自动关机说明看门狗ok
4.使能systemd自动喂狗功能,修改1./etc/systemd/system.conf文件:

RuntimeWatchdogSec= 60

5.输入命令:

echo 1 > /dev/watchdog

6.如果显示设备忙说明开启了systemd自动喂狗功能

或者使用喂狗程序:

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

int main(void)
{
int fd = open("/dev/watchdog", O_WRONLY);
int ret = 0;
if (fd == -1) {
perror("watchdog");
exit(EXIT_FAILURE);
}
while (1) {
ret = write(fd, "\0", 1);
if (ret != 1) {
ret = -1;
break;
}
sleep(10);
}
close(fd);
return ret;
}

gdb ko

kylin@kylin-kvmvirtualmachine:~/fuqiang/kfocal/debian/build/build-generic$ gdb  ./drivers/parport/parport_pc.ko
...
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./drivers/parport/parport_pc.ko...
(gdb) list *(parport_pc_probe_port+0x5d0)
0x2180 is in parport_pc_probe_port (/home/kylin/fuqiang/kfocal/include/linux/parport_pc.h:105).
100     #if defined(CONFIG_ARM64)
101             if (used_lpc)
102                     return readb(lpc_base+addr);
103             else
104     #endif
105                     return inb(addr);
106     }
107
108     static __inline__ void parport_pc_readsb(unsigned long addr, void *buf,
109                     unsigned int count)
(gdb) q
kylin@kylin

或者

jian@jian:~$ gdb vmlinux
...
Reading symbols from vmlinux...
(gdb) list *(xhci_cleanup_halted_endpoint+0xa8/0x178)
0xffffffc0108391b0 is in xhci_cleanup_halted_endpoint (/home/kylin/fuqiang/kfocal/drivers/usb/host/xhci-ring.c:1846).
1841    static void xhci_cleanup_halted_endpoint(struct xhci_hcd *xhci,
1842                    unsigned int slot_id, unsigned int ep_index,
1843                    unsigned int stream_id, struct xhci_td *td,
1844                    enum xhci_ep_reset_type reset_type)
1845    {
1846            struct xhci_virt_ep *ep = &xhci->devs[slot_id]->eps[ep_index];
1847            struct xhci_command *command;
1848
1849            /*
1850             * Avoid resetting endpoint if link is inactive. Can cause host hang.

反汇编vmlinux

objdump -d -j .text vmlinux > ./objdump

反汇编模块

objdump -S test.ko > test.s

ESR寄存器

查看笨叔v8.6的D13.2.36
在这里插入图片描述
我们经常看到0x96000210等等的96、95、94开头的都是数据终止。

在这里插入图片描述
其中96开头表示内核态发生数据终止,95和94表示用户态程序发生数据终止。点击ISSxxx这个链接看就对了。

PSTATE寄存器

查看笨叔v8.6的D1.7 Process state, PSTATE
在这里插入图片描述
当PAN=1时,在特权模式下访问用户模式下的地址会触发一个 permission fault。
当UAO=1时,在EL1中执行非特权模式下的ldr/str指令,这时候的内存访问权限会根据正在执行的EL的权限来分,而不是EL0的访问权限。

在这里插入图片描述

cpu问题排查

isolcpus=2,3  nohz_full=2,3

调试信息添加

  1. /etc/default/grub文件的GRUB_CMDLINE_LINUX_DEFAULT行去掉 quiet, 在双引号""中添加如下:
debug initcall_debug=1 loglevel=8 sysrq_always_enabled console=ttyAMA1,115200

然后执行update-grub命令。

  1. 在/etc/sysctl.conf # 文件末尾追加下面两行:
kernel.printk = 8 7 7 7 
kernel.sysrq = 1

sysctl -p # 查看是否生效
reboot # 重启

网口直连配置

ifconfig Lan1 192.168.10.152
route add -host 192.168.10.153 dev Lan1
systemctl stop NetworkManager.service

  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

小坚学Linux

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

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

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

打赏作者

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

抵扣说明:

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

余额充值