Liunx下的常用工具及使用方法


1.sf工具:

用途:查看SPI flash;用法:sf --h;举例:sf read 0x81000000  0x1f00000 0x10000 (把spi的31M位置64KB的数据读到内存0x81000000处) ,    md  0x81000000 0x10000 打印这64KB的数据到串口);


2.mtd_debug工具:

用途:操作flash设备;用法:mtd_debug  -h; 举例:mtd_debug read /dev/mtdblock2  0x10000 0x10  dst.bin (将设备mtdblock2中偏移0x10000位置,长度为16字节的数据读到文件dst.bin中);


3.查看文件夹下的各个文件大小:

du -h –max-depth=1 *


4. i2c操作工具:
  1. 查看i2c4总线挂载的设备地址:i2cdetect -y -r 4
  2. dump 出 i2c4 总线上从设备 0x50 上的寄存器的值:i2cdump -f -y 4 0x50
  3. i2c4 地址为 0x50 的从设备上往 0x2 的地址上写数据 0x66:i2cset -f -y 4 0x50 0x2 0x66
  4. 读取16位寄存器地址的数据:
  5. i2ctransfer -y -f 4 w1@0x29 0x08 r1 。其中2是i2c总线号,0x29为i2c上的slave设备地址,w1是让其读取8位寄存器地址,0x08 为寄存器地址,r1表⽰只读取1个字节(r2就表⽰读取2个字节)。
  6. i2ctransfer -y -f 4 w2@0x29 0x08 0xa9 r1 。其中2是i2c总线号,0x29为i2c上的slave设备地址,w2是让其读取16位寄存器地址,0x08 0xa9
  7. 为寄存器地址0x08a9,r1表⽰只读取1个字节(r2就表⽰读取2个字节)写⼊16位寄存器地址的数据.

写⼊16位寄存器地址的数据:i2ctransfer -y -f 2 w3@0x29 0x08 0xa9 0xc8 。其中2是i2c总线号,0x29为i2c上的slave设备地址,w3标识寄存器(0x08a9)和写⼊值(0xc8)总⻓度为3字节,0x08 0xa9 为寄存器地址0x08a9,0xc8表⽰写⼊的字节。


注意:i2cdetect 扫描设备树的时候,如果显示UU表示的是绑定在设备树,如果直接显示16进制数,则表示该设备并没有绑定在设备树。


5. df -h :

以更易读的方式显示目前磁盘空间和使用情况;


6. 动态打印:

在defconfig中新增:CONFIG_DYNAMIC_DEBUG=y ,(另外确保还要有 CONFIG_DEBUG_FS=y 这一项) ;完成后重新编译
1. mkdir /mnt/dbg     // 创建一个dbg文件夹,用于后续挂载debugfs

2. echo  8 4 1 7 > /proc/sys/kernel/printk     // 更改打印级别,因为动态打印的打印级别为7

3. cat   /proc/sys/kernel/printk       // 查看打印级别,确保更改成功

4. mount -t debugfs none  /mnt/dbg     //挂载debugfs
5.cd   /mnt/dbg/         //如果动态打印可用且挂载成功,则这下面会有各个模块的动态打印表,否则这个目录下为空;


6. cat /mnt/dbg/dynamic_debug/control | grep "i2s module"       //查看属性是否是+p,

7. cat /mnt/dbg/dynamic_debug/control | grep "pr_debug in module clk"

8. cat /mnt/dbg/dynamic_debug/control | grep "pr_debug in module clocksource."

9. cat /mnt/dbg/dynamic_debug/control | grep "pr_debug in module dma."

10. cat /mnt/dbg/dynamic_debug/control | grep "pr_debug in module i2c."

11. echo -n "module  bst_i2s +pfmlt" > /mnt/dbg/dynamic_debug/control     //打开打印开关

    echo -n "module  bst_i2s -fmlt" > /mnt/dbg/dynamic_debug/control       //取消格式打印,只打印消息

备注:

1. "+pmfl"这个参数打印的是最全的。

    如果要打印,"+p"一定是要有的,"fmlt"可以根据需要任选。

    其中, m 表示把模块名也打印出来;

    f 表示把调用pr_debug的函数名也打印出来;

     l 表示把pr_debug的行号也打印出来;

     t 表示把进程号打印出来; 

2. 控制某个文件所有 dev_dbg(),echo -n "file xxx.c +p" > /mnt/dbg/dynamic_debug/control

3. 控制某个函数所有 dev_dbg(),echo -n "func xxx +p" > /mnt/dbg/dynamic_debug/control

4. 早期控制:@1.Makefile:ccflags-y := -DDEBUG 

            ccflags-y += -DVERBOSE_DEBUG

            @2.在内核commandline中添加"module.dyndbg=+pflt": rdinit=/linuxrc console=ttyAMA0 loglevel=8 module.dyndbg=+plft


7. 驱动开发寄存器调试工具:devmem2:


读数据:devmem2  0x000c0004                          读地址 0x000c0008 处的值
写数据:devmem2  0x000c0008  w  0xffffffff        往 0x000c0008 地址写入值 0xffffffff 


8. grep 搜索的时候,忽略某一目录的方法:

grep -nR --exclude-dir=build "2c7c"     (当前目录下查找字符串"2c7c",但是忽略build目录)

9.linux内核驱动代码检查工具


1. linux代码风格简介:https://www.kernel.org/doc/html/v4.15/translations/zh_CN/coding-style.html
2. scripts/checkpatch.pl -f  a.c
此命令检查a.c文件的代码风格是否符合linux 内核代码风格;
3.scripts/Lindent a.c
此命令自动修改a.c文件里面的缩进问题;
前提:此命令需要系统安装 ident 工具,比如ubuntu系统:apt install rcs   和   apt install indent


10. linux优化启动时间:

参考网址:https://blog.csdn.net/hpu11/article/details/80522774

11. linux终端下的文件比较工具: meld
12.底行模式输入:w !sudo tee %,然后q!推出就可以强制修改文件;
13.dtb反编译成dts:dtc  -I  dtb  -O  dts  -o  temp.dts  bsta1000b-fada.dtb
14.Taskset可以将进程绑定到任意核上运行,示例:taskset  -pc 5  id (表示把进程号为id的进程绑定到第5个核上)。
15.uboot模式下追加环境变量:setenv extra_bootargs "loglevel=8”
16.解压缩:

.tar.gz:(解压  tar -zxvf  filename.tar.gz     压缩:tar -zcvf  filename.tar.gz  filename);

.zip(解压: unzip  filename.zip);

.tar.bz2(解压: tar  -jxvf filename.tar.bz2);

.tar.xz(解压: tar -Jxvf filename.tar.xz  注意J是大写);  

.tar(解压xxx.tar:  tar -xvf xxx.tar    压缩成xxx.tar文件:tar -cvf  xxx.tar  filename);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值