首页 前端知识 linux 的devmem2 调式使用说明

linux 的devmem2 调式使用说明

2024-11-04 09:11:44 前端知识 前端哥 752 918 我要收藏

devmem2的方式是提供给驱动开发人员,在应用层能够侦测内存地址中的数据变化,以此来检测驱动中对内存或者相关配置的正确性验证。基本原理通过设备文件/dev/mem 实现对物理内存的读写,如果没有dev/mem,这时需要安装devmem2。

1,安装devmem2:

sudo apt install devmem2

lark@ubuntu:~$ devmem2 

Usage:    devmem2 { address } [ type [ data ] ]
 address : memory address to act upon
type    : access operation type : [b]yte, [h]alfword, [w]ord
data    : data to be written

安装成功后会有/dev/mem 这个目录。

lark@ubuntu:~$ ls /dev/mem 
/dev/mem

2,读写测试

a,读数据:

devmem2 reg-addr b/h/w(1/2/4) 

b,写数据:

devmem2 reg-addr b/h/w(1/2/value

(1)单字节读写(8位):

lark@ubuntu:~$ sudo devmem2 0x1234 b 0x11
/dev/mem opened.
Memory mapped at address 0x7f659293d000.
Value at address 0x1234 (0x7f659293d234): 0x78
Written 0x11; readback 0x11


lark@ubuntu:~$ sudo devmem2 0x1234 b 
/dev/mem opened.
Memory mapped at address 0x7fd47bed1000.
Value at address 0x1234 (0x7fd47bed1234): 0x11

(2)双字节读写(16位):

lark@ubuntu:~$ sudo devmem2 0x1234 b 
/dev/mem opened.
Memory mapped at address 0x7fd47bed1000.
Value at address 0x1234 (0x7fd47bed1234): 0x11
lark@ubuntu:~$ sudo devmem2 0x1234 h 0x1122
/dev/mem opened.
Memory mapped at address 0x7f218fb9b000.
Value at address 0x1234 (0x7f218fb9b234): 0x5611
Written 0x1122; readback 0x1122


lark@ubuntu:~$ sudo devmem2 0x1234 h
/dev/mem opened.
Memory mapped at address 0x7feaa9be3000.
Value at address 0x1234 (0x7feaa9be3234): 0x1122
 

(3)四字节速写(四字节):

lark@ubuntu:~$ sudo devmem2 0x1234 w 0x12345678
/dev/mem opened.
Memory mapped at address 0x7f2d21327000.
Value at address 0x1234 (0x7f2d21327234): 0xBC614E
Written 0x12345678; readback 0x12345678


lark@ubuntu:~$ sudo devmem2 0x1234 w
/dev/mem opened.
Memory mapped at address 0x7f31ad806000.
Value at address 0x1234 (0x7f31ad806234): 0x12345678

lark@ubuntu:~$ sudo devmem2 0x1234 h
/dev/mem opened.
Memory mapped at address 0x7fd131870000.
Value at address 0x1234 (0x7fd131870234): 0x5678


lark@ubuntu:~$ sudo devmem2 0x1234 b
/dev/mem opened.
Memory mapped at address 0x7f2fe1866000.
Value at address 0x1234 (0x7f2fe1866234): 0x78

转载请注明出处或者链接地址:https://www.qianduange.cn//article/19894.html
标签
评论
发布的文章

在C#中使用JSON

2024-11-04 10:11:05

JSON串

2024-11-04 10:11:57

JSON教程(非常详细)

2024-05-08 10:05:36

大家推荐的文章
会员中心 联系我 留言建议 回顶部
复制成功!