当前位置:网站首页>[21-day learning challenge - kernel notes] (5) - devmem read and write register debugging

[21-day learning challenge - kernel notes] (5) - devmem read and write register debugging

2022-08-11 00:02:00 light chases rain


活动地址:CSDN21天学习挑战赛

学习的最大理由是想摆脱平庸,早一天就多一份人生的精彩;迟一天就多一天平庸的困扰.各位小伙伴,如果您:
想系统/深入学习某技术知识点…
一个人摸索学习很难坚持,想组团高效学习…
想写博客但无从下手,急需写作干货注入能量…
热爱写作,愿意让自己成为更好的人…

一、用途介绍

读写socthe value of the associated register,就是应用程序通过mmap函数对/dev/mem驱动中的mmap方法的使用,映射了设备的内存到用户空间,实现对这些物理地址的读写操作

二、配置

内核中对devmem的支持,进行如下配置
读取socthe value of the associated register,The value of some registers cannot be read,So an error occurs when reading
Symbol: DEVMEM [=y]                                                                      │
  │ Type  : bool                                                                             │
  │ Prompt: /dev/mem virtual device support                                                  │
  │   Location:                                                                              │
  │     -> Device Drivers                                                                    │
  │ (1)   -> Character devices                                                               │
  │   Defined at drivers/char/Kconfig:10

备注: The kernel configures this option:CONFIG_DEVMEM=y,Verify that the configuration is successful or not will be generated/dev/mem节点

busybox中对devmem的支持,进行如下配置:
Symbol: DEVMEM [=y]                                                                      │
  │ Prompt: devmem (2.5 kb)                                                                  │
  │   Defined at miscutils/Config.in:326                                                     │
  │   Location:                                                                              │
  │     -> Miscellaneous Utilities

备注: busyboxconfigure this optionCONFIG_DEVMEM=y,Verifying that the configuration was successful generates the applicationdevmem

三、读和写

读取:在地址0x97000000读取32bit值(WIDTH默认等于32, 可选值为[8, 16, 32, 64])
/dev # devmem 0x97000000
0x11111111
读取:在地址0x97000000读取16bit值
/dev # devmem 0x97000000 16
0x1111

写入:在地址0x97000000写入32bit值0x7777ABCD
/dev # devmem 0x97000000 32 0x7777ABCD
/dev # devmem 0x97000000
0x7777ABCD

注意:如果/dev下没有mem这个node,会出现错误:
/dev # devmem 0x97000000
devmem: can’t open ‘/dev/mem’: No such file or directory

这时可以在Host系统中手动创建一个(例如在NFS root filesystem模式):
[email protected]:~/embedded/tftpboot/nfsroot/dev$ sudo mknod mem -m666 c 1 1
注意这里的权限是666,允许任何人任意读写,可以很好的配合程序debug.

devmem的使用方式
语法: devmem ADDRESS [WIDTH [VALUE]]
●ADDRESS :The address to read and write directly
●WIDTH :Specifies the number of bits to read and write data(8/16/32...
●VALUE :data to write
读
●读32: devmem 0x98000000
●读16: devmem 0x98000000 16
●读8: devmem 0x98000000 8
写
●写32: devmem 0x98000000 32 0x12345678
●写16: devmem 0x98000000 16 0x1234
●写8: devmem 0x98000000 8 0x12

参考文章:
RK3399平台开发系列讲解(内核调试篇)2.6、devmem直接读写寄存器进行调试

devmem

/dev/mem可没那么简单

Two small tools useful for driver debugging(devmem2、devkmem)

devmemRead and write physical memory and devkmemRead kernel virtual memory

原网站

版权声明
本文为[light chases rain]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/222/202208102340298469.html